Patchwork [1,of,6] cmdutil: use named arguments for changeset_templater.__init__

login
register
mail settings
Submitter Gregory Szorc
Date June 24, 2017, 10:13 p.m.
Message ID <a9a61dd1c43ba19856bd.1498342427@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/21676/
State Accepted
Headers show

Comments

Gregory Szorc - June 24, 2017, 10:13 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1498330046 25200
#      Sat Jun 24 11:47:26 2017 -0700
# Node ID a9a61dd1c43ba19856bd6e4943676663d56a7f00
# Parent  8e3021fd1a44e48a4720bb6fa4538fba399ad213
cmdutil: use named arguments for changeset_templater.__init__

This will make the API more extensible and easier to use.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1577,7 +1577,12 @@  class jsonchangeset(changeset_printer):
 class changeset_templater(changeset_printer):
     '''format changeset information.'''
 
-    def __init__(self, ui, repo, tmplspec, matchfn, diffopts, buffered):
+    # Arguments before "buffered" used to be positional. Consider not
+    # adding/removing arguments before "buffered" to not break callers.
+    def __init__(self, ui, repo, tmplspec, matchfn=None, diffopts=None,
+                 buffered=False):
+        diffopts = diffopts or {}
+
         changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
         self.t = formatter.loadtemplater(ui, tmplspec,
                                          cache=templatekw.defaulttempl)
@@ -1694,8 +1699,7 @@  def _lookuplogtemplate(ui, tmpl, style):
 def makelogtemplater(ui, repo, tmpl, buffered=False):
     """Create a changeset_templater from a literal template 'tmpl'"""
     spec = logtemplatespec(tmpl, None)
-    return changeset_templater(ui, repo, spec, matchfn=None, diffopts={},
-                               buffered=buffered)
+    return changeset_templater(ui, repo, spec, buffered=buffered)
 
 def show_changeset(ui, repo, opts, buffered=False):
     """show one changeset using template or regular display.