[PATCH 5 of 8] formatter: add support for separator template
Yuya Nishihara
yuya at tcha.org
Tue Jun 20 11:57:27 EDT 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1492865451 -32400
# Sat Apr 22 21:50:51 2017 +0900
# Node ID 9f489b3ba5352bca1541618858da1724d1bb282c
# Parent 546b89efa96a23908d59ff76ef13dbe8604d1ae9
formatter: add support for separator template
This seems useful for writing JSON template.
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -351,7 +351,7 @@ class templateformatter(baseformatter):
self._tref = spec.ref
self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl)
self._parts = templatepartsmap(spec, self._t,
- ['docheader', 'docfooter'])
+ ['docheader', 'docfooter', 'separator'])
self._counter = itertools.count()
self._cache = {} # for templatekw/funcs to store reusable data
self._renderitem('docheader', {})
@@ -364,7 +364,9 @@ class templateformatter(baseformatter):
def _showitem(self):
item = self._item.copy()
- item['index'] = next(self._counter)
+ item['index'] = index = next(self._counter)
+ if index > 0:
+ self._renderitem('separator', {})
self._renderitem(self._tref, item)
def _renderitem(self, part, item):
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -533,7 +533,8 @@ template output:
$ cat <<'EOF' > "$TESTTMP/map-myjson"
> docheader = '\{\n'
> docfooter = '\n}\n'
- > branches = '{ifeq(index, 0, "", ",\n")} {dict(branch, node|short)|json}'
+ > separator = ',\n'
+ > branches = ' {dict(branch, node|short)|json}'
> EOF
$ hg branches -T "$TESTTMP/map-myjson"
{
More information about the Mercurial-devel
mailing list