Merge branch 'jc/name-rev-lw-tag'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 02:16:39 +0000 (11:16 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 02:16:40 +0000 (11:16 +0900)
"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

1  2 
builtin/name-rev.c
t/t4202-log.sh
index b7afffef73483ffda51dae87a8ae86f2677cef84,bf7ed015aebc07d2dd410745786fec269c28091f..663e26ebbdc49071d1fb6e2b289cd8f51841c688
  
  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;
  /* How many generations are maximally preferred over _one_ merge traversal? */
  #define MERGE_TRAVERSAL_WEIGHT 65535
  
 -                        unsigned long taggerdate,
+ static int is_better_name(struct rev_name *name,
+                         const char *tip_name,
++                        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;
 -      } else
+               name->from_tag = from_tag;
 +      } else {
 +              free(to_free);
                return;
 +      }
  
        for (parents = commit->parents;
                        parents;
diff --cc t/t4202-log.sh
Simple merge