[PATCH 2 of 2 STABLE] templatekw: fix join format of parents keyword (issue5292)

Yuya Nishihara yuya at tcha.org
Fri Jul 22 10:55:07 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1469193132 -32400
#      Fri Jul 22 22:12:12 2016 +0900
# Branch stable
# Node ID 32a6d8ceee2189a9f019a43f7a2cfb9fecb4fdf0
# Parent  c95239e03e854d54ad0035490392c4c39e28a742
templatekw: fix join format of parents keyword (issue5292)

Since the default joinfmt() can't process a dict of multiple keywords, we
need a dedicated joinfmt for showparents().

Unlike revset(), parents are formatted as '{rev}:{node|formatnode}' by default.
We copy the default formatting just like showextras() and showfilecopies() do.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -119,6 +119,16 @@ def _showlist(name, values, plural=None,
     if endname in templ:
         yield templ(endname, **args)
 
+def _formatrevnode(ctx):
+    """Format changeset as '{rev}:{node|formatnode}', which is the default
+    template provided by cmdutil.changeset_templater"""
+    repo = ctx.repo()
+    if repo.ui.debugflag:
+        hexnode = ctx.hex()
+    else:
+        hexnode = ctx.hex()[:12]
+    return '%d:%s' % (scmutil.intrev(ctx.rev()), hexnode)
+
 def getfiles(repo, ctx, revcache):
     if 'files' not in revcache:
         revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
@@ -523,7 +533,8 @@ def showparents(**args):
                 ('phase', p.phasestr())]
                for p in pctxs]
     f = _showlist('parent', parents, **args)
-    return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}})
+    return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
+                   lambda d: _formatrevnode(d['ctx']))
 
 @templatekeyword('phase')
 def showphase(repo, ctx, templ, **args):
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
@@ -3438,6 +3438,16 @@ join() should pick '{rev}' from revset i
   $ hg log -R ../a -T '{join(revset("parents(%d)", rev), ", ")}\n' -r6
   4, 5
 
+on the other hand, parents are formatted as '{rev}:{node|formatnode}' by
+default. join() should agree with the default formatting:
+
+  $ hg log -R ../a -T '{join(parents, ", ")}\n' -r6
+  5:13207e5a10d9, 4:bbe44766e73d
+
+  $ hg log -R ../a -T '{join(parents, ",\n")}\n' -r6 --debug
+  5:13207e5a10d9fd28ec424934298e176197f2c67f,
+  4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
+
 Test active bookmark templating
 
   $ hg book foo


More information about the Mercurial-devel mailing list