Mercurial > hg-stable
changeset 22474:9da0ef363861
formatter: extract function that encode values to json string
This is the stub for tuple support, which will be used to encode ctx.date()
in the same manner as jsonchangeset printer.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 17 Sep 2014 21:15:43 +0900 |
parents | ca85306b3eb2 |
children | 17eeda31e52b |
files | mercurial/formatter.py |
diffstat | 1 files changed, 7 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/formatter.py Fri Sep 12 21:38:52 2014 -0400 +++ b/mercurial/formatter.py Wed Sep 17 21:15:43 2014 +0900 @@ -88,6 +88,12 @@ baseformatter.end(self) self._ui.write(cPickle.dumps(self._data)) +def _jsonifyobj(v): + if isinstance(v, int): + return '%d' % v + else: + return '"%s"' % encoding.jsonescape(v) + class jsonformatter(baseformatter): def __init__(self, ui, topic, opts): baseformatter.__init__(self, ui, topic, opts) @@ -106,10 +112,7 @@ first = False else: self._ui.write(",\n") - if isinstance(v, int): - self._ui.write(' "%s": %d' % (k, v)) - else: - self._ui.write(' "%s": "%s"' % (k, encoding.jsonescape(v))) + self._ui.write(' "%s": %s' % (k, _jsonifyobj(v))) self._ui.write("\n }") def end(self): baseformatter.end(self)