diff mercurial/templatekw.py @ 33865:af20468eb0a4

merge with stable
author Sean Farley <sean@farley.io>
date Mon, 21 Aug 2017 21:35:06 -0700
parents 6f6c87888b22 fb672eac2702
children e278d6d2d7d2
line wrap: on
line diff
--- a/mercurial/templatekw.py	Fri Aug 11 01:34:11 2017 -0700
+++ b/mercurial/templatekw.py	Mon Aug 21 21:35:06 2017 -0700
@@ -208,10 +208,22 @@
             latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
             continue
         try:
-            # The tuples are laid out so the right one can be found by
-            # comparison.
-            pdate, pdist, ptag = max(
-                latesttags[p.rev()] for p in ctx.parents())
+            ptags = [latesttags[p.rev()] for p in ctx.parents()]
+            if len(ptags) > 1:
+                if ptags[0][2] == ptags[1][2]:
+                    # The tuples are laid out so the right one can be found by
+                    # comparison in this case.
+                    pdate, pdist, ptag = max(ptags)
+                else:
+                    def key(x):
+                        changessincetag = len(repo.revs('only(%d, %s)',
+                                                        ctx.rev(), x[2][0]))
+                        # Smallest number of changes since tag wins. Date is
+                        # used as tiebreaker.
+                        return [-changessincetag, x[0]]
+                    pdate, pdist, ptag = max(ptags, key=key)
+            else:
+                pdate, pdist, ptag = ptags[0]
         except KeyError:
             # Cache miss - recurse
             todo.append(rev)