Patchwork [8,of,8] changeset_templater: backport parts map of [templates] section from formatter

login
register
mail settings
Submitter Yuya Nishihara
Date June 20, 2017, 3:57 p.m.
Message ID <4007733bfcb477654288.1497974250@mimosa>
Download mbox | patch
Permalink /patch/21540/
State Accepted
Headers show

Comments

Yuya Nishihara - June 20, 2017, 3:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1492863368 -32400
#      Sat Apr 22 21:16:08 2017 +0900
# Node ID 4007733bfcb477654288a9895817ba194709be6a
# Parent  c719e1db3d6e014bbf6ae3745c75c0f4e10d55be
changeset_templater: backport parts map of [templates] section from formatter
via Mercurial-devel - June 20, 2017, 10:59 p.m.
On Tue, Jun 20, 2017 at 8:57 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1492863368 -32400
> #      Sat Apr 22 21:16:08 2017 +0900
> # Node ID 4007733bfcb477654288a9895817ba194709be6a
> # Parent  c719e1db3d6e014bbf6ae3745c75c0f4e10d55be
> changeset_templater: backport parts map of [templates] section from formatter

Queued, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1603,6 +1603,10 @@  class changeset_templater(changeset_prin
                     cur = t + postfix
                     if mode and cur in self.t:
                         self._parts[t] = cur
+        else:
+            partnames = [p for p in self._parts.keys() if p != tmplspec.ref]
+            m = formatter.templatepartsmap(tmplspec, self.t, partnames)
+            self._parts.update(m)
 
         if self._parts['docheader']:
             self.ui.write(templater.stringify(self.t(self._parts['docheader'])))
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
@@ -271,6 +271,24 @@  Test docheader, docfooter and separator 
    {"node": "29114dbae42b", "rev": 7}
   }
 
+Test docheader, docfooter and separator in [templates] section
+
+  $ cat <<'EOF' >> .hg/hgrc
+  > [templates]
+  > myjson = ' {dict(rev, node|short)|json}'
+  > myjson:docheader = '\{\n'
+  > myjson:docfooter = '\n}\n'
+  > myjson:separator = ',\n'
+  > :docheader = 'should not be selected as a docheader for literal templates\n'
+  > EOF
+  $ hg log -l2 -Tmyjson
+  {
+   {"node": "95c24699272e", "rev": 8},
+   {"node": "29114dbae42b", "rev": 7}
+  }
+  $ hg log -l1 -T'{rev}\n'
+  8
+
 Template should precede style option
 
   $ hg log -l1 --style default -T '{rev}\n'