Patchwork [3,of,3] templatekw: switch ctx of list expression to rev of {parents} (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 20, 2016, 10:09 a.m.
Message ID <21b29d0fe625b13a4eaf.1455962966@mimosa>
Download mbox | patch
Permalink /patch/13271/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 20, 2016, 10:09 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1455272169 -32400
#      Fri Feb 12 19:16:09 2016 +0900
# Node ID 21b29d0fe625b13a4eaf5b69fc92f5ee505c92e0
# Parent  734094ea47c56da70c0d22d81cceba968f9b260f
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}"}'.
Sean Farley - Feb. 21, 2016, 6:57 a.m.
Yuya Nishihara <yuya@tcha.org> writes:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1455272169 -32400
> #      Fri Feb 12 19:16:09 2016 +0900
> # Node ID 21b29d0fe625b13a4eaf5b69fc92f5ee505c92e0
> # Parent  734094ea47c56da70c0d22d81cceba968f9b260f
> 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}"}'.

I like making things uniform so I'm fine with this series. Though, I
have a feeling the template engine needs more love, in general.
Pierre-Yves David - Feb. 27, 2016, 2:31 p.m.
On 02/20/2016 11:09 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1455272169 -32400
> #      Fri Feb 12 19:16:09 2016 +0900
> # Node ID 21b29d0fe625b13a4eaf5b69fc92f5ee505c92e0
> # Parent  734094ea47c56da70c0d22d81cceba968f9b260f
> 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}"}'.

This seems reasonable, the test update make a lot of sense and this have 
been on the list for a week.

I've pushed it to the clowncopter. Thanks.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -468,11 +468,14 @@  def showparents(**args):
     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."""
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3251,6 +3251,11 @@  Test ifcontains function
   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 @@  Test revset function
   $ 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 @@  Test revset function
   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'