Skip to content

Commit dccd0c2

Browse files
spearceJunio C Hamano
authored andcommitted
Always perfer annotated tags in git-describe.
Several people have suggested that its always better to describe a commit using an annotated tag, and to only use a lightweight tag if absolutely no annotated tag matches the input commit. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c14261e commit dccd0c2

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

builtin-describe.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static void describe(const char *arg, int last_one)
138138
commit_list_insert(cmit, &list);
139139
while (list) {
140140
struct commit *c = pop_commit(&list);
141+
struct commit_list *parents = c->parents;
141142
n = match(c);
142143
if (n) {
143144
struct possible_tag *p = xmalloc(sizeof(*p));
@@ -148,17 +149,17 @@ static void describe(const char *arg, int last_one)
148149
else
149150
all_matches = p;
150151
cur_match = p;
151-
} else {
152-
struct commit_list *parents = c->parents;
153-
while (parents) {
154-
struct commit *p = parents->item;
155-
parse_commit(p);
156-
if (!(p->object.flags & SEEN)) {
157-
p->object.flags |= SEEN;
158-
insert_by_date(p, &list);
159-
}
160-
parents = parents->next;
152+
if (n->prio == 2)
153+
continue;
154+
}
155+
while (parents) {
156+
struct commit *p = parents->item;
157+
parse_commit(p);
158+
if (!(p->object.flags & SEEN)) {
159+
p->object.flags |= SEEN;
160+
insert_by_date(p, &list);
161161
}
162+
parents = parents->next;
162163
}
163164
}
164165

@@ -181,7 +182,8 @@ static void describe(const char *arg, int last_one)
181182
while ((!min_match || cur_match->depth < min_match->depth)
182183
&& get_revision(&revs))
183184
cur_match->depth++;
184-
if (!min_match || cur_match->depth < min_match->depth)
185+
if (!min_match || (cur_match->depth < min_match->depth
186+
&& cur_match->name->prio >= min_match->name->prio))
185187
min_match = cur_match;
186188
free_commit_list(revs.commits);
187189
}

0 commit comments

Comments
 (0)