changeset 37773:0f084741cd66

logcmdutil: pass formatter to jsonchangeset as argument And rename the class. Now we can reuse it for 'log -Tcbor' (and '-Tpickle' if we want.)
author Yuya Nishihara <yuya@tcha.org>
date Fri, 13 Apr 2018 23:07:12 +0900
parents 814151cd8c4a
children d6970628b95f
files mercurial/logcmdutil.py
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/logcmdutil.py	Fri Apr 13 22:47:14 2018 +0900
+++ b/mercurial/logcmdutil.py	Fri Apr 13 23:07:12 2018 +0900
@@ -310,12 +310,13 @@
         if stat or diff:
             self.ui.write("\n")
 
-class jsonchangeset(changesetprinter):
-    '''format changeset information.'''
+class changesetformatter(changesetprinter):
+    """Format changeset information by generic formatter"""
 
-    def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False):
+    def __init__(self, ui, repo, fm, differ=None, diffopts=None,
+                 buffered=False):
         changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
-        self._fm = formatter.jsonformatter(ui, ui, 'log', {})
+        self._fm = fm
 
     def close(self):
         self._fm.end()
@@ -519,7 +520,8 @@
     """
     postargs = (differ, opts, buffered)
     if opts.get('template') == 'json':
-        return jsonchangeset(ui, repo, *postargs)
+        fm = ui.formatter('log', opts)
+        return changesetformatter(ui, repo, fm, *postargs)
 
     spec = _lookuptemplate(ui, opts.get('template'), opts.get('style'))