[PATCH 2 of 7] formatter: have jsonformatter accept tuple as value

Yuya Nishihara yuya at tcha.org
Wed Sep 17 10:11:23 CDT 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1410957022 -32400
#      Wed Sep 17 21:30:22 2014 +0900
# Node ID 97d8605b1d91dad17643b7e34a740781c947a8af
# Parent  932109f051e8f29e986ef43b0af19c673eb50a96
formatter: have jsonformatter accept tuple as value

This is necessary for "annotate" to encode ctx.date() in the same manner
as jsonchangeset printer.

It doesn't support list object because keeping mutable object in _item could
be a source of hidden bugs.  Also, I can't think of the use case.

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -89,7 +89,9 @@ class pickleformatter(baseformatter):
         self._ui.write(cPickle.dumps(self._data))
 
 def _jsonifyobj(v):
-    if isinstance(v, int):
+    if isinstance(v, tuple):
+        return '[' + ', '.join(_jsonifyobj(e) for e in v) + ']'
+    elif isinstance(v, int):
         return '%d' % v
     else:
         return '"%s"' % encoding.jsonescape(v)


More information about the Mercurial-devel mailing list