Skip to content

Commit 0041bf6

Browse files
committed
name-rev: refactor logic to see if a new candidate is a better name
When we encounter a new ref that could describe the commit we are looking at, we compare the name that is formed using that ref and the name we found so far and pick a better one. Factor the comparison logic out to a separate helper function, while keeping the current logic the same (i.e. a name that is based on an older tag is better, and if two tags of the same age can reach the commit, the one with fewer number of hops to reach the commit is better). Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael J Gruber <git@grubix.eu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7d5a38b commit 0041bf6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

builtin/name-rev.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ static long cutoff = LONG_MAX;
2020
/* How many generations are maximally preferred over _one_ merge traversal? */
2121
#define MERGE_TRAVERSAL_WEIGHT 65535
2222

23+
static int is_better_name(struct rev_name *name,
24+
const char *tip_name,
25+
unsigned long taggerdate,
26+
int generation,
27+
int distance)
28+
{
29+
return (name->taggerdate > taggerdate ||
30+
(name->taggerdate == taggerdate &&
31+
name->distance > distance));
32+
}
33+
2334
static void name_rev(struct commit *commit,
2435
const char *tip_name, unsigned long taggerdate,
2536
int generation, int distance,
@@ -45,9 +56,8 @@ static void name_rev(struct commit *commit,
4556
name = xmalloc(sizeof(rev_name));
4657
commit->util = name;
4758
goto copy_data;
48-
} else if (name->taggerdate > taggerdate ||
49-
(name->taggerdate == taggerdate &&
50-
name->distance > distance)) {
59+
} else if (is_better_name(name, tip_name, taggerdate,
60+
generation, distance)) {
5161
copy_data:
5262
name->tip_name = tip_name;
5363
name->taggerdate = taggerdate;

0 commit comments

Comments
 (0)