7
7
#include "argv-array.h"
8
8
#include "parse-options.h"
9
9
#include "dir.h"
10
+ #include "commit-slab.h"
10
11
11
12
static const char * show_branch_usage [] = {
12
13
N_ ("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
@@ -59,15 +60,27 @@ struct commit_name {
59
60
int generation ; /* how many parents away from head_name */
60
61
};
61
62
63
+ define_commit_slab (commit_name_slab , struct commit_name * );
64
+ static struct commit_name_slab name_slab ;
65
+
66
+ static struct commit_name * commit_to_name (struct commit * commit )
67
+ {
68
+ return * commit_name_slab_at (& name_slab , commit );
69
+ }
70
+
71
+
62
72
/* Name the commit as nth generation ancestor of head_name;
63
73
* we count only the first-parent relationship for naming purposes.
64
74
*/
65
75
static void name_commit (struct commit * commit , const char * head_name , int nth )
66
76
{
67
77
struct commit_name * name ;
68
- if (!commit -> util )
69
- commit -> util = xmalloc (sizeof (struct commit_name ));
70
- name = commit -> util ;
78
+
79
+ name = * commit_name_slab_at (& name_slab , commit );
80
+ if (!name ) {
81
+ name = xmalloc (sizeof (* name ));
82
+ * commit_name_slab_at (& name_slab , commit ) = name ;
83
+ }
71
84
name -> head_name = head_name ;
72
85
name -> generation = nth ;
73
86
}
@@ -79,8 +92,8 @@ static void name_commit(struct commit *commit, const char *head_name, int nth)
79
92
*/
80
93
static void name_parent (struct commit * commit , struct commit * parent )
81
94
{
82
- struct commit_name * commit_name = commit -> util ;
83
- struct commit_name * parent_name = parent -> util ;
95
+ struct commit_name * commit_name = commit_to_name ( commit ) ;
96
+ struct commit_name * parent_name = commit_to_name ( parent ) ;
84
97
if (!commit_name )
85
98
return ;
86
99
if (!parent_name ||
@@ -94,12 +107,12 @@ static int name_first_parent_chain(struct commit *c)
94
107
int i = 0 ;
95
108
while (c ) {
96
109
struct commit * p ;
97
- if (!c -> util )
110
+ if (!commit_to_name ( c ) )
98
111
break ;
99
112
if (!c -> parents )
100
113
break ;
101
114
p = c -> parents -> item ;
102
- if (!p -> util ) {
115
+ if (!commit_to_name ( p ) ) {
103
116
name_parent (c , p );
104
117
i ++ ;
105
118
}
@@ -122,7 +135,7 @@ static void name_commits(struct commit_list *list,
122
135
/* First give names to the given heads */
123
136
for (cl = list ; cl ; cl = cl -> next ) {
124
137
c = cl -> item ;
125
- if (c -> util )
138
+ if (commit_to_name ( c ) )
126
139
continue ;
127
140
for (i = 0 ; i < num_rev ; i ++ ) {
128
141
if (rev [i ] == c ) {
@@ -148,17 +161,17 @@ static void name_commits(struct commit_list *list,
148
161
struct commit_name * n ;
149
162
int nth ;
150
163
c = cl -> item ;
151
- if (!c -> util )
164
+ if (!commit_to_name ( c ) )
152
165
continue ;
153
- n = c -> util ;
166
+ n = commit_to_name ( c ) ;
154
167
parents = c -> parents ;
155
168
nth = 0 ;
156
169
while (parents ) {
157
170
struct commit * p = parents -> item ;
158
171
struct strbuf newname = STRBUF_INIT ;
159
172
parents = parents -> next ;
160
173
nth ++ ;
161
- if (p -> util )
174
+ if (commit_to_name ( p ) )
162
175
continue ;
163
176
switch (n -> generation ) {
164
177
case 0 :
@@ -271,7 +284,7 @@ static void show_one_commit(struct commit *commit, int no_name)
271
284
{
272
285
struct strbuf pretty = STRBUF_INIT ;
273
286
const char * pretty_str = "(unavailable)" ;
274
- struct commit_name * name = commit -> util ;
287
+ struct commit_name * name = commit_to_name ( commit ) ;
275
288
276
289
if (commit -> object .parsed ) {
277
290
pp_commit_easy (CMIT_FMT_ONELINE , commit , & pretty );
@@ -660,6 +673,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
660
673
OPT_END ()
661
674
};
662
675
676
+ init_commit_name_slab (& name_slab );
677
+
663
678
git_config (git_show_branch_config , NULL );
664
679
665
680
/* If nothing is specified, try the default first */
0 commit comments