Patchwork [2,of,3,STABLE] templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 20, 2019, 3:11 a.m.
Message ID <66102f6fa10aa533a658.1547953870@mimosa>
Download mbox | patch
Permalink /patch/37888/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 20, 2019, 3:11 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1547952681 -32400
#      Sun Jan 20 11:51:21 2019 +0900
# Branch stable
# Node ID 66102f6fa10aa533a658532b198cd6879a538406
# Parent  ff1222a7d714304b49b555ed779b2aadae5b1827
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.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -81,8 +81,15 @@  def getlatesttags(context, mapping, patt
                     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]]
diff --git a/tests/test-template-keywords.t b/tests/test-template-keywords.t
--- a/tests/test-template-keywords.t
+++ b/tests/test-template-keywords.t
@@ -1063,8 +1063,18 @@  Tags of working-directory parents (issue
   $ hg ci -qAm h3a
   $ hg merge -q 2
   $ hg log -Gr'::wdir()' -T "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n"
-  hg: parse error: invalid argument for revspec
-  [255]
+  o    2147483647: at3+2,3 t3+2,3
+  |\
+  | @  12: at3+1,1 t3+1,1
+  | |
+  | o  3: at3+0,0 t3+0,0
+  | |
+  @ |  2: t2+0,0
+  |/
+  o  1: t1+0,0
+  |
+  o  0: null+1,1
+  
 
   $ hg ci -m merge
   $ hg log -Gr'::.' -T "{rev}: {latesttag % '{tag}+{distance},{changes} '}\n"