summaryrefslogtreecommitdiff
path: root/builtin/name-rev.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-03-29 14:39:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-29 17:53:30 (GMT)
commit0041bf6544b9b46022b6362eae834a36505d7baa (patch)
treed6a89a7da27a0ffd8a84006c1b81322e9ea79128 /builtin/name-rev.c
parent7d5a38b61fad51b765117ae6dae9117db74dac3d (diff)
downloadgit-0041bf6544b9b46022b6362eae834a36505d7baa.zip
git-0041bf6544b9b46022b6362eae834a36505d7baa.tar.gz
git-0041bf6544b9b46022b6362eae834a36505d7baa.tar.bz2
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>
Diffstat (limited to 'builtin/name-rev.c')
-rw-r--r--builtin/name-rev.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 8bdc3ea..7890f82 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -20,6 +20,17 @@ static long cutoff = LONG_MAX;
/* How many generations are maximally preferred over _one_ merge traversal? */
#define MERGE_TRAVERSAL_WEIGHT 65535
+static int is_better_name(struct rev_name *name,
+ const char *tip_name,
+ unsigned long taggerdate,
+ int generation,
+ int distance)
+{
+ return (name->taggerdate > taggerdate ||
+ (name->taggerdate == taggerdate &&
+ name->distance > distance));
+}
+
static void name_rev(struct commit *commit,
const char *tip_name, unsigned long taggerdate,
int generation, int distance,
@@ -45,9 +56,8 @@ static void name_rev(struct commit *commit,
name = xmalloc(sizeof(rev_name));
commit->util = name;
goto copy_data;
- } else if (name->taggerdate > taggerdate ||
- (name->taggerdate == taggerdate &&
- name->distance > distance)) {
+ } else if (is_better_name(name, tip_name, taggerdate,
+ generation, distance)) {
copy_data:
name->tip_name = tip_name;
name->taggerdate = taggerdate;