summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-12-21 15:03:16 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-12-21 15:03:16 -0800
commit3f9d5059c66f45ac75dd701b0798d3891150c1e7 (patch)
tree209ca95c9b3c03cb6f9c234e87fba832033df890
parentMerge branch 'ak/protect-any-current-branch' (diff)
parentname-rev: prefer shorter names over following merges (diff)
downloadtgif-3f9d5059c66f45ac75dd701b0798d3891150c1e7.tar.xz
Merge branch 'en/name-rev-shorter-output'
"git name-rev" has been tweaked to give output that is shorter and easier to understand. * en/name-rev-shorter-output: name-rev: prefer shorter names over following merges
-rw-r--r--builtin/name-rev.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index b221d30014..27f60153a6 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -44,11 +44,20 @@ static struct rev_name *get_commit_rev_name(const struct commit *commit)
return is_valid_rev_name(name) ? name : NULL;
}
+static int effective_distance(int distance, int generation)
+{
+ return distance + (generation > 0 ? MERGE_TRAVERSAL_WEIGHT : 0);
+}
+
static int is_better_name(struct rev_name *name,
timestamp_t taggerdate,
+ int generation,
int distance,
int from_tag)
{
+ int name_distance = effective_distance(name->distance, name->generation);
+ int new_distance = effective_distance(distance, generation);
+
/*
* When comparing names based on tags, prefer names
* based on the older tag, even if it is farther away.
@@ -56,7 +65,7 @@ static int is_better_name(struct rev_name *name,
if (from_tag && name->from_tag)
return (name->taggerdate > taggerdate ||
(name->taggerdate == taggerdate &&
- name->distance > distance));
+ name_distance > new_distance));
/*
* We know that at least one of them is a non-tag at this point.
@@ -69,8 +78,8 @@ static int is_better_name(struct rev_name *name,
* We are now looking at two non-tags. Tiebreak to favor
* shorter hops.
*/
- if (name->distance != distance)
- return name->distance > distance;
+ if (name_distance != new_distance)
+ return name_distance > new_distance;
/* ... or tiebreak to favor older date */
if (name->taggerdate != taggerdate)
@@ -88,7 +97,7 @@ static struct rev_name *create_or_update_name(struct commit *commit,
struct rev_name *name = commit_rev_name_at(&rev_names, commit);
if (is_valid_rev_name(name)) {
- if (!is_better_name(name, taggerdate, distance, from_tag))
+ if (!is_better_name(name, taggerdate, generation, distance, from_tag))
return NULL;
/*