Patchwork [4,of,4] logcmdutil: pass formatter to jsonchangeset as argument

login
register
mail settings
Submitter Yuya Nishihara
Date April 14, 2018, 4:21 a.m.
Message ID <611a3c98d1b68836b572.1523679678@mimosa>
Download mbox | patch
Permalink /patch/30965/
State Accepted
Headers show

Comments

Yuya Nishihara - April 14, 2018, 4:21 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1523628432 -32400
#      Fri Apr 13 23:07:12 2018 +0900
# Node ID 611a3c98d1b68836b5725a0d97c0ae1f0b3677f6
# Parent  60b88ab0b4238f95438c3ad2a3c9fc802da84d94
logcmdutil: pass formatter to jsonchangeset as argument

And rename the class. Now we can reuse it for 'log -Tcbor' (and '-Tpickle'
if we want.)

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -310,12 +310,13 @@  class changesetprinter(object):
         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 @@  def changesetdisplayer(ui, repo, opts, d
     """
     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'))