changeset_templater: backport parts map of [templates] section from formatter
authorYuya Nishihara <yuya@tcha.org>
Sat, 22 Apr 2017 21:16:08 +0900
changeset 32953 6d79e9109908
parent 32952 61b60b28c381
child 32954 b5305a499dfc
changeset_templater: backport parts map of [templates] section from formatter
mercurial/cmdutil.py
tests/test-command-template.t
--- a/mercurial/cmdutil.py	Sat Apr 22 21:29:00 2017 +0900
+++ b/mercurial/cmdutil.py	Sat Apr 22 21:16:08 2017 +0900
@@ -1603,6 +1603,10 @@
                     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'])))
--- a/tests/test-command-template.t	Sat Apr 22 21:29:00 2017 +0900
+++ b/tests/test-command-template.t	Sat Apr 22 21:16:08 2017 +0900
@@ -271,6 +271,24 @@
    {"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'