formatter: have jsonformatter accept tuple as value
authorYuya Nishihara <yuya@tcha.org>
Wed, 17 Sep 2014 21:30:22 +0900
changeset 22475 17eeda31e52b
parent 22474 9da0ef363861
child 22476 a0829ec34dbd
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.
mercurial/formatter.py
--- a/mercurial/formatter.py	Wed Sep 17 21:15:43 2014 +0900
+++ b/mercurial/formatter.py	Wed Sep 17 21:30:22 2014 +0900
@@ -89,7 +89,9 @@
         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)