# HG changeset patch # User Yuya Nishihara <y...@tcha.org> # Date 1497684740 -32400 # Sat Jun 17 16:32:20 2017 +0900 # Node ID b6219e719a2828ff9cf391c5d98bcb7688110236 # Parent 9f489b3ba5352bca1541618858da1724d1bb282c changeset_templater: backport separator template from formatter
As commented, this should be used with docheader and docfooter, not with header nor footer. That's one reason why no props are passed to templater when rendering a separator. (See map-cmdline.changelog to understand what the "header" is.) diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1587,7 +1587,8 @@ class changeset_templater(changeset_prin self._tref = tmplspec.ref self._parts = {'header': '', 'footer': '', tmplspec.ref: tmplspec.ref, - 'docheader': '', 'docfooter': ''} + 'docheader': '', 'docfooter': '', + 'separator': ''} if tmplspec.mapfile: # find correct templates for current mode, for backward # compatibility with 'log -v/-q/--debug' using a mapfile @@ -1621,11 +1622,17 @@ class changeset_templater(changeset_prin props['ctx'] = ctx props['repo'] = self.repo props['ui'] = self.repo.ui - props['index'] = next(self._counter) + props['index'] = index = next(self._counter) props['revcache'] = {'copies': copies} props['cache'] = self.cache props = pycompat.strkwargs(props) + # write separator, which wouldn't work well with the header part below + # since there's inherently a conflict between header (across items) and + # separator (per item) + if self._parts['separator'] and index > 0: + self.ui.write(templater.stringify(self.t(self._parts['separator']))) + # write header if self._parts['header']: h = templater.stringify(self.t(self._parts['header'], **props)) 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 @@ -257,6 +257,20 @@ Test template map inheritance summary: third +Test docheader, docfooter and separator in template map + + $ cat <<'EOF' > map-myjson + > docheader = '\{\n' + > docfooter = '\n}\n' + > separator = ',\n' + > changeset = ' {dict(rev, node|short)|json}' + > EOF + $ hg log -l2 -T./map-myjson + { + {"node": "95c24699272e", "rev": 8}, + {"node": "29114dbae42b", "rev": 7} + } + Template should precede style option $ hg log -l1 --style default -T '{rev}\n' _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel