From: Junio C Hamano Date: Tue, 30 May 2017 02:16:39 +0000 (+0900) Subject: Merge branch 'jc/name-rev-lw-tag' X-Git-Tag: v2.14.0-rc0~148 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/78089b71da60fcf846b2e7029a90db492f1d3a9d Merge branch 'jc/name-rev-lw-tag' "git describe --contains" penalized light-weight tags so much that they were almost never considered. Instead, give them about the same chance to be considered as an annotated tag that is the same age as the underlying commit would. * jc/name-rev-lw-tag: name-rev: favor describing with tags and use committer date to tiebreak name-rev: refactor logic to see if a new candidate is a better name --- 78089b71da60fcf846b2e7029a90db492f1d3a9d diff --cc builtin/name-rev.c index b7afffef73,bf7ed015ae..663e26ebbd --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@@ -10,9 -10,10 +10,10 @@@ typedef struct rev_name { const char *tip_name; - unsigned long taggerdate; + timestamp_t taggerdate; int generation; int distance; + int from_tag; } rev_name; static long cutoff = LONG_MAX; @@@ -20,9 -21,47 +21,47 @@@ /* 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, ++ timestamp_t taggerdate, + int generation, + int distance, + int from_tag) + { + /* + * When comparing names based on tags, prefer names + * based on the older tag, even if it is farther away. + */ + if (from_tag && name->from_tag) + return (name->taggerdate > taggerdate || + (name->taggerdate == taggerdate && + name->distance > distance)); + + /* + * We know that at least one of them is a non-tag at this point. + * favor a tag over a non-tag. + */ + if (name->from_tag != from_tag) + return from_tag; + + /* + * We are now looking at two non-tags. Tiebreak to favor + * shorter hops. + */ + if (name->distance != distance) + return name->distance > distance; + + /* ... or tiebreak to favor older date */ + if (name->taggerdate != taggerdate) + return name->taggerdate > taggerdate; + + /* keep the current one if we cannot decide */ + return 0; + } + static void name_rev(struct commit *commit, - const char *tip_name, unsigned long taggerdate, + const char *tip_name, timestamp_t taggerdate, - int generation, int distance, + int generation, int distance, int from_tag, int deref) { struct rev_name *name = (struct rev_name *)commit->util; @@@ -54,10 -91,9 +92,11 @@@ copy_data name->taggerdate = taggerdate; name->generation = generation; name->distance = distance; + name->from_tag = from_tag; - } else + } else { + free(to_free); return; + } for (parents = commit->parents; parents;