changeset 28270:650c9f69a744

templatekw: switch ctx of list expression to rev of {parents} (BC) This is the same semantics as revset() introduced at e4609ec959f8. Before this patch, {parents} provided nothing useful in new-style template. For example, '{parents % "{parent}"}' generated cryptic string like "rev12345node0123abcdef...". This patch drops {parent} variable since it was useless. We can get a revision number by '{parents % "{rev}"}'.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 12 Feb 2016 19:16:09 +0900
parents 6e3fdd98b277
children 5c454ab69558
files mercurial/templatekw.py tests/test-command-template.t
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Fri Feb 26 20:22:05 2016 +0900
+++ b/mercurial/templatekw.py	Fri Feb 12 19:16:09 2016 +0900
@@ -474,11 +474,14 @@
     revision) nothing is shown."""
     repo = args['repo']
     ctx = args['ctx']
+    pctxs = scmutil.meaningfulparents(repo, ctx)
+    prevs = [str(p.rev()) for p in pctxs]  # ifcontains() needs a list of str
     parents = [[('rev', p.rev()),
                 ('node', p.hex()),
                 ('phase', p.phasestr())]
-               for p in scmutil.meaningfulparents(repo, ctx)]
-    return showlist('parent', parents, **args)
+               for p in pctxs]
+    f = _showlist('parent', parents, **args)
+    return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}})
 
 def showphase(repo, ctx, templ, **args):
     """:phase: String. The changeset phase name."""
--- a/tests/test-command-template.t	Fri Feb 26 20:22:05 2016 +0900
+++ b/tests/test-command-template.t	Fri Feb 12 19:16:09 2016 +0900
@@ -3251,6 +3251,11 @@
   1 did not add a
   0 added a
 
+  $ hg log --debug -T '{rev}{ifcontains(1, parents, " is parent of 1")}\n'
+  2 is parent of 1
+  1
+  0
+
 Test revset function
 
   $ hg log --template '{rev} {ifcontains(rev, revset("."), "current rev", "not current rev")}\n'
@@ -3293,13 +3298,18 @@
   $ hg log --template '{revset("TIP"|lower)}\n' -l1
   2
 
- a list template is evaluated for each item of revset
+ a list template is evaluated for each item of revset/parents
 
   $ hg log -T '{rev} p: {revset("p1(%s)", rev) % "{rev}:{node|short}"}\n'
   2 p: 1:bcc7ff960b8e
   1 p: 0:f7769ec2ab97
   0 p: 
 
+  $ hg log --debug -T '{rev} p:{parents % " {rev}:{node|short}"}\n'
+  2 p: 1:bcc7ff960b8e -1:000000000000
+  1 p: 0:f7769ec2ab97 -1:000000000000
+  0 p: -1:000000000000 -1:000000000000
+
  therefore, 'revcache' should be recreated for each rev
 
   $ hg log -T '{rev} {file_adds}\np {revset("p1(%s)", rev) % "{file_adds}"}\n'
@@ -3310,6 +3320,14 @@
   0 a
   p 
 
+  $ hg log --debug -T '{rev} {file_adds}\np {parents % "{file_adds}"}\n'
+  2 aa b
+  p 
+  1 
+  p a
+  0 a
+  p 
+
 a revset item must be evaluated as an integer revision, not an offset from tip
 
   $ hg log -l 1 -T '{revset("null") % "{rev}:{node|short}"}\n'