Skip to content

Commit 4bd3b36

Browse files
committed
Merge branch 'mg/name-rev-debug' into pu
"git describe --debug --contains" did not add any meaningful information, even though without "--contains" it did. * mg/name-rev-debug: describe: pass --debug down to name-rev name-rev: provide debug output
2 parents 8408c1b + 766f2f0 commit 4bd3b36

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

Documentation/git-name-rev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ OPTIONS
4242
--all::
4343
List all commits reachable from all refs
4444

45+
--debug::
46+
Verbosely display information about the searching strategy
47+
being employed to standard error. The symbolic name will still
48+
be printed to standard out.
49+
4550
--stdin::
4651
Transform stdin by substituting all the 40-character SHA-1
4752
hexes (say $hex) with "$hex ($rev_name)". When used with

builtin/describe.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
486486
NULL);
487487
if (always)
488488
argv_array_push(&args, "--always");
489+
if (debug)
490+
argv_array_push(&args, "--debug");
489491
if (!all) {
490492
argv_array_push(&args, "--tags");
491493
for_each_string_list_item(item, &patterns)

builtin/name-rev.c

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ typedef struct rev_name {
1818

1919
static timestamp_t cutoff = TIME_MAX;
2020

21+
static const char *prio_names[] = {
22+
N_("head"), N_("lightweight"), N_("annotated"),
23+
};
24+
2125
/* How many generations are maximally preferred over _one_ merge traversal? */
2226
#define MERGE_TRAVERSAL_WEIGHT 65535
2327

@@ -59,10 +63,19 @@ static int is_better_name(struct rev_name *name,
5963
return 0;
6064
}
6165

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+
6275
static void name_rev(struct commit *commit,
6376
const char *tip_name, timestamp_t taggerdate,
6477
int generation, int distance, int from_tag,
65-
int deref)
78+
int deref, struct name_ref_data *data)
6679
{
6780
struct rev_name *name = (struct rev_name *)commit->util;
6881
struct commit_list *parents;
@@ -76,6 +89,7 @@ static void name_rev(struct commit *commit,
7689

7790
if (deref) {
7891
tip_name = to_free = xstrfmt("%s^0", tip_name);
92+
from_tag += 1;
7993

8094
if (generation)
8195
die("generation: %d, but deref?", generation);
@@ -88,6 +102,36 @@ static void name_rev(struct commit *commit,
88102
} else if (is_better_name(name, tip_name, taggerdate,
89103
generation, distance, from_tag)) {
90104
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+
}
91135
name->tip_name = tip_name;
92136
name->taggerdate = taggerdate;
93137
name->generation = generation;
@@ -115,11 +159,11 @@ static void name_rev(struct commit *commit,
115159

116160
name_rev(parents->item, new_name, taggerdate, 0,
117161
distance + MERGE_TRAVERSAL_WEIGHT,
118-
from_tag, 0);
162+
from_tag, 0, data);
119163
} else {
120164
name_rev(parents->item, tip_name, taggerdate,
121165
generation + 1, distance + 1,
122-
from_tag, 0);
166+
from_tag, 0, data);
123167
}
124168
}
125169
}
@@ -149,13 +193,6 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
149193
return refname;
150194
}
151195

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-
159196
static struct tip_table {
160197
struct tip_table_entry {
161198
struct object_id oid;
@@ -239,7 +276,6 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
239276
}
240277

241278
add_to_tip_table(oid, path, can_abbreviate_output);
242-
243279
while (o && o->type == OBJ_TAG) {
244280
struct tag *t = (struct tag *) o;
245281
if (!t->tagged)
@@ -256,7 +292,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
256292
taggerdate = ((struct commit *)o)->date;
257293
path = name_ref_abbrev(path, can_abbreviate_output);
258294
name_rev(commit, xstrdup(path), taggerdate, 0, 0,
259-
from_tag, deref);
295+
from_tag, deref, data);
260296
}
261297
return 0;
262298
}
@@ -389,7 +425,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
389425
{
390426
struct object_array revs = OBJECT_ARRAY_INIT;
391427
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 };
393429
struct option opts[] = {
394430
OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
395431
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)
399435
N_("ignore refs matching <pattern>")),
400436
OPT_GROUP(""),
401437
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")),
402439
OPT_BOOL(0, "stdin", &transform_stdin, N_("read from stdin")),
403440
OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
404441
OPT_BOOL(0, "always", &always,
@@ -464,6 +501,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
464501

465502
if (cutoff)
466503
cutoff = cutoff - CUTOFF_DATE_SLOP;
504+
data.revs = &revs;
467505
for_each_ref(name_ref, &data);
468506

469507
if (transform_stdin) {

0 commit comments

Comments
 (0)