diff mercurial/templatekw.py @ 41300:66102f6fa10a stable

templatekw: fix crash on multiple latesttags resolution at wdir (issue6055) It appears not easy to fix only() to support wdir(), so this patch works around the issue by getlatesttags(). The "+1" after len(changes) doesn't matter since ctx never changes while sorting. It's just for clarity.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 20 Jan 2019 11:51:21 +0900
parents 074c72a38423
children 0bd56c291359
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sun Jan 20 11:39:16 2019 +0900
+++ b/mercurial/templatekw.py	Sun Jan 20 11:51:21 2019 +0900
@@ -81,8 +81,15 @@
                     pdate, pdist, ptag = max(ptags)
                 else:
                     def key(x):
-                        changessincetag = len(repo.revs('only(%d, %s)',
-                                                        ctx.rev(), x[2][0]))
+                        tag = x[2][0]
+                        if ctx.rev() is None:
+                            # only() doesn't support wdir
+                            prevs = [c.rev() for c in ctx.parents()]
+                            changes = repo.revs('only(%ld, %s)', prevs, tag)
+                            changessincetag = len(changes) + 1
+                        else:
+                            changes = repo.revs('only(%d, %s)', ctx.rev(), tag)
+                            changessincetag = len(changes)
                         # Smallest number of changes since tag wins. Date is
                         # used as tiebreaker.
                         return [-changessincetag, x[0]]