@@ -18,6 +18,10 @@ typedef struct rev_name {
18
18
19
19
static long cutoff = LONG_MAX ;
20
20
21
+ static const char * prio_names [] = {
22
+ N_ ("head" ), N_ ("lightweight" ), N_ ("annotated" ),
23
+ };
24
+
21
25
/* How many generations are maximally preferred over _one_ merge traversal? */
22
26
#define MERGE_TRAVERSAL_WEIGHT 65535
23
27
@@ -59,10 +63,19 @@ static int is_better_name(struct rev_name *name,
59
63
return 0 ;
60
64
}
61
65
66
+ struct name_ref_data {
67
+ int tags_only ;
68
+ int name_only ;
69
+ int debug ;
70
+ struct string_list ref_filters ;
71
+ struct string_list exclude_filters ;
72
+ struct object_array * revs ;
73
+ };
74
+
62
75
static void name_rev (struct commit * commit ,
63
76
const char * tip_name , unsigned long taggerdate ,
64
77
int generation , int distance , int from_tag ,
65
- int deref )
78
+ int deref , struct name_ref_data * data )
66
79
{
67
80
struct rev_name * name = (struct rev_name * )commit -> util ;
68
81
struct commit_list * parents ;
@@ -75,6 +88,7 @@ static void name_rev(struct commit *commit,
75
88
76
89
if (deref ) {
77
90
tip_name = xstrfmt ("%s^0" , tip_name );
91
+ from_tag += 1 ;
78
92
79
93
if (generation )
80
94
die ("generation: %d, but deref?" , generation );
@@ -87,6 +101,36 @@ static void name_rev(struct commit *commit,
87
101
} else if (is_better_name (name , tip_name , taggerdate ,
88
102
generation , distance , from_tag )) {
89
103
copy_data :
104
+ if (data -> debug ) {
105
+ int i ;
106
+ static int label_width = -1 ;
107
+ static int name_width = -1 ;
108
+ if (label_width < 0 ) {
109
+ int w ;
110
+ for (i = 0 ; i < ARRAY_SIZE (prio_names ); i ++ ) {
111
+ w = strlen (_ (prio_names [i ]));
112
+ if (label_width < w )
113
+ label_width = w ;
114
+ }
115
+ }
116
+ if (name_width < 0 ) {
117
+ int w ;
118
+ for (i = 0 ; i < data -> revs -> nr ; i ++ ) {
119
+ w = strlen (data -> revs -> objects [i ].name );
120
+ if (name_width < w )
121
+ name_width = w ;
122
+ }
123
+ }
124
+ for (i = 0 ; i < data -> revs -> nr ; i ++ )
125
+ if (!oidcmp (& commit -> object .oid ,
126
+ & data -> revs -> objects [i ].item -> oid ))
127
+ fprintf (stderr , " %-*s %8d %-*s %s~%d\n" ,
128
+ label_width ,
129
+ _ (prio_names [from_tag ]),
130
+ distance , name_width ,
131
+ data -> revs -> objects [i ].name ,
132
+ tip_name , generation );
133
+ }
90
134
name -> tip_name = tip_name ;
91
135
name -> taggerdate = taggerdate ;
92
136
name -> generation = generation ;
@@ -112,11 +156,11 @@ static void name_rev(struct commit *commit,
112
156
113
157
name_rev (parents -> item , new_name , taggerdate , 0 ,
114
158
distance + MERGE_TRAVERSAL_WEIGHT ,
115
- from_tag , 0 );
159
+ from_tag , 0 , data );
116
160
} else {
117
161
name_rev (parents -> item , tip_name , taggerdate ,
118
162
generation + 1 , distance + 1 ,
119
- from_tag , 0 );
163
+ from_tag , 0 , data );
120
164
}
121
165
}
122
166
}
@@ -146,13 +190,6 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
146
190
return refname ;
147
191
}
148
192
149
- struct name_ref_data {
150
- int tags_only ;
151
- int name_only ;
152
- struct string_list ref_filters ;
153
- struct string_list exclude_filters ;
154
- };
155
-
156
193
static struct tip_table {
157
194
struct tip_table_entry {
158
195
unsigned char sha1 [20 ];
@@ -236,7 +273,6 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
236
273
}
237
274
238
275
add_to_tip_table (oid -> hash , path , can_abbreviate_output );
239
-
240
276
while (o && o -> type == OBJ_TAG ) {
241
277
struct tag * t = (struct tag * ) o ;
242
278
if (!t -> tagged )
@@ -253,7 +289,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
253
289
taggerdate = ((struct commit * )o )-> date ;
254
290
path = name_ref_abbrev (path , can_abbreviate_output );
255
291
name_rev (commit , xstrdup (path ), taggerdate , 0 , 0 ,
256
- from_tag , deref );
292
+ from_tag , deref , data );
257
293
}
258
294
return 0 ;
259
295
}
@@ -383,7 +419,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
383
419
{
384
420
struct object_array revs = OBJECT_ARRAY_INIT ;
385
421
int all = 0 , transform_stdin = 0 , allow_undefined = 1 , always = 0 , peel_tag = 0 ;
386
- struct name_ref_data data = { 0 , 0 , STRING_LIST_INIT_NODUP , STRING_LIST_INIT_NODUP };
422
+ struct name_ref_data data = { 0 , 0 , 0 , STRING_LIST_INIT_NODUP , STRING_LIST_INIT_NODUP };
387
423
struct option opts [] = {
388
424
OPT_BOOL (0 , "name-only" , & data .name_only , N_ ("print only names (no SHA-1)" )),
389
425
OPT_BOOL (0 , "tags" , & data .tags_only , N_ ("only use tags to name the commits" )),
@@ -393,6 +429,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
393
429
N_ ("ignore refs matching <pattern>" )),
394
430
OPT_GROUP ("" ),
395
431
OPT_BOOL (0 , "all" , & all , N_ ("list all commits reachable from all refs" )),
432
+ OPT_BOOL (0 , "debug" , & data .debug , N_ ("debug search strategy on stderr" )),
396
433
OPT_BOOL (0 , "stdin" , & transform_stdin , N_ ("read from stdin" )),
397
434
OPT_BOOL (0 , "undefined" , & allow_undefined , N_ ("allow to print `undefined` names (default)" )),
398
435
OPT_BOOL (0 , "always" , & always ,
@@ -458,6 +495,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
458
495
459
496
if (cutoff )
460
497
cutoff = cutoff - CUTOFF_DATE_SLOP ;
498
+ data .revs = & revs ;
461
499
for_each_ref (name_ref , & data );
462
500
463
501
if (transform_stdin ) {
0 commit comments