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

Yuya Nishihara yuya at tcha.org
Tue Jun 20 11:57:30 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at 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

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'


More information about the Mercurial-devel mailing list