@@ -18,6 +18,10 @@ typedef struct rev_name {
18
18
19
19
static timestamp_t cutoff = TIME_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 , timestamp_t 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 ;
@@ -76,6 +89,7 @@ static void name_rev(struct commit *commit,
76
89
77
90
if (deref ) {
78
91
tip_name = to_free = xstrfmt ("%s^0" , tip_name );
92
+ from_tag += 1 ;
79
93
80
94
if (generation )
81
95
die ("generation: %d, but deref?" , generation );
@@ -88,6 +102,36 @@ static void name_rev(struct commit *commit,
88
102
} else if (is_better_name (name , tip_name , taggerdate ,
89
103
generation , distance , from_tag )) {
90
104
copy_data :
105
+ if (data -> debug ) {
106
+ int i ;
107
+ static int label_width = -1 ;
108
+ static int name_width = -1 ;
109
+ if (label_width < 0 ) {
110
+ int w ;
111
+ for (i = 0 ; i < ARRAY_SIZE (prio_names ); i ++ ) {
112
+ w = strlen (_ (prio_names [i ]));
113
+ if (label_width < w )
114
+ label_width = w ;
115
+ }
116
+ }
117
+ if (name_width < 0 ) {
118
+ int w ;
119
+ for (i = 0 ; i < data -> revs -> nr ; i ++ ) {
120
+ w = strlen (data -> revs -> objects [i ].name );
121
+ if (name_width < w )
122
+ name_width = w ;
123
+ }
124
+ }
125
+ for (i = 0 ; i < data -> revs -> nr ; i ++ )
126
+ if (!oidcmp (& commit -> object .oid ,
127
+ & data -> revs -> objects [i ].item -> oid ))
128
+ fprintf (stderr , " %-*s %8d %-*s %s~%d\n" ,
129
+ label_width ,
130
+ _ (prio_names [from_tag ]),
131
+ distance , name_width ,
132
+ data -> revs -> objects [i ].name ,
133
+ tip_name , generation );
134
+ }
91
135
name -> tip_name = tip_name ;
92
136
name -> taggerdate = taggerdate ;
93
137
name -> generation = generation ;
@@ -115,11 +159,11 @@ static void name_rev(struct commit *commit,
115
159
116
160
name_rev (parents -> item , new_name , taggerdate , 0 ,
117
161
distance + MERGE_TRAVERSAL_WEIGHT ,
118
- from_tag , 0 );
162
+ from_tag , 0 , data );
119
163
} else {
120
164
name_rev (parents -> item , tip_name , taggerdate ,
121
165
generation + 1 , distance + 1 ,
122
- from_tag , 0 );
166
+ from_tag , 0 , data );
123
167
}
124
168
}
125
169
}
@@ -149,13 +193,6 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
149
193
return refname ;
150
194
}
151
195
152
- struct name_ref_data {
153
- int tags_only ;
154
- int name_only ;
155
- struct string_list ref_filters ;
156
- struct string_list exclude_filters ;
157
- };
158
-
159
196
static struct tip_table {
160
197
struct tip_table_entry {
161
198
struct object_id oid ;
@@ -239,7 +276,6 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
239
276
}
240
277
241
278
add_to_tip_table (oid , path , can_abbreviate_output );
242
-
243
279
while (o && o -> type == OBJ_TAG ) {
244
280
struct tag * t = (struct tag * ) o ;
245
281
if (!t -> tagged )
@@ -256,7 +292,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
256
292
taggerdate = ((struct commit * )o )-> date ;
257
293
path = name_ref_abbrev (path , can_abbreviate_output );
258
294
name_rev (commit , xstrdup (path ), taggerdate , 0 , 0 ,
259
- from_tag , deref );
295
+ from_tag , deref , data );
260
296
}
261
297
return 0 ;
262
298
}
@@ -389,7 +425,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
389
425
{
390
426
struct object_array revs = OBJECT_ARRAY_INIT ;
391
427
int all = 0 , transform_stdin = 0 , allow_undefined = 1 , always = 0 , peel_tag = 0 ;
392
- struct name_ref_data data = { 0 , 0 , STRING_LIST_INIT_NODUP , STRING_LIST_INIT_NODUP };
428
+ struct name_ref_data data = { 0 , 0 , 0 , STRING_LIST_INIT_NODUP , STRING_LIST_INIT_NODUP };
393
429
struct option opts [] = {
394
430
OPT_BOOL (0 , "name-only" , & data .name_only , N_ ("print only names (no SHA-1)" )),
395
431
OPT_BOOL (0 , "tags" , & data .tags_only , N_ ("only use tags to name the commits" )),
@@ -399,6 +435,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
399
435
N_ ("ignore refs matching <pattern>" )),
400
436
OPT_GROUP ("" ),
401
437
OPT_BOOL (0 , "all" , & all , N_ ("list all commits reachable from all refs" )),
438
+ OPT_BOOL (0 , "debug" , & data .debug , N_ ("debug search strategy on stderr" )),
402
439
OPT_BOOL (0 , "stdin" , & transform_stdin , N_ ("read from stdin" )),
403
440
OPT_BOOL (0 , "undefined" , & allow_undefined , N_ ("allow to print `undefined` names (default)" )),
404
441
OPT_BOOL (0 , "always" , & always ,
@@ -464,6 +501,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
464
501
465
502
if (cutoff )
466
503
cutoff = cutoff - CUTOFF_DATE_SLOP ;
504
+ data .revs = & revs ;
467
505
for_each_ref (name_ref , & data );
468
506
469
507
if (transform_stdin ) {
0 commit comments