Patchwork [1,of,6] cmdutil: factor out helper to create changeset_templater with literal template

login
register
mail settings
Submitter Yuya Nishihara
Date June 15, 2017, 2:52 p.m.
Message ID <06aa02920b896e50e6fc.1497538347@mimosa>
Download mbox | patch
Permalink /patch/21388/
State Accepted
Headers show

Comments

Yuya Nishihara - June 15, 2017, 2:52 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1492854123 -32400
#      Sat Apr 22 18:42:03 2017 +0900
# Node ID 06aa02920b896e50e6fc18709bd42522d32e68bd
# Parent  9d76812f9b0bdd0af9b4ea68bb16765c591d9b4a
cmdutil: factor out helper to create changeset_templater with literal template

changeset_templater has lots of arguments, but most callers only need to
specify a literal template 'tmpl'.

"hg debugtemplate" has no diff option, which means 'opts' were effectively {},
so dropped opts.

Patch

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -32,9 +32,6 @@  command = registrar.command(cmdtable)
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
-def maketemplater(ui, repo, tmpl):
-    return cmdutil.changeset_templater(ui, repo, False, None, tmpl, None, False)
-
 def changedlines(ui, repo, ctx1, ctx2, fns):
     added, removed = 0, 0
     fmatch = scmutil.matchfiles(repo, fns)
@@ -55,7 +52,7 @@  def countrate(ui, repo, amap, *pats, **o
             return date.strftime(opts['dateformat'])
     else:
         tmpl = opts.get('oldtemplate') or opts.get('template')
-        tmpl = maketemplater(ui, repo, tmpl)
+        tmpl = cmdutil.makelogtemplater(ui, repo, tmpl)
         def getkey(ctx):
             ui.pushbuffer()
             tmpl.show(ctx)
diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -239,8 +239,8 @@  class kwtemplater(object):
         '''Replaces keywords in data with expanded template.'''
         def kwsub(mobj):
             kw = mobj.group(1)
-            ct = cmdutil.changeset_templater(self.ui, self.repo, False, None,
-                                             self.templates[kw], '', False)
+            ct = cmdutil.makelogtemplater(self.ui, self.repo,
+                                          self.templates[kw])
             self.ui.pushbuffer()
             ct.show(ctx, root=self.repo.root, file=path)
             ekw = templatefilters.firstline(self.ui.popbuffer())
diff --git a/hgext/show.py b/hgext/show.py
--- a/hgext/show.py
+++ b/hgext/show.py
@@ -196,9 +196,8 @@  def showwork(ui, repo, fm):
     revs = repo.revs('sort(_underway(), topo)')
 
     revdag = graphmod.dagwalker(repo, revs)
-    displayer = cmdutil.changeset_templater(ui, repo, None, None,
-                                            tmpl=fm._t.load(fm._topic),
-                                            mapfile=None, buffered=True)
+    tmpl = fm._t.load(fm._topic)
+    displayer = cmdutil.makelogtemplater(ui, repo, tmpl, buffered=True)
 
     ui.setconfig('experimental', 'graphshorten', True)
     cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges)
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1674,6 +1674,11 @@  def _lookuplogtemplate(ui, tmpl, style):
 
     return formatter.lookuptemplate(ui, 'changeset', tmpl)
 
+def makelogtemplater(ui, repo, tmpl, buffered=False):
+    """Create a changeset_templater from a literal template 'tmpl'"""
+    return changeset_templater(ui, repo, matchfn=None, diffopts={},
+                               tmpl=tmpl, mapfile=None, buffered=buffered)
+
 def show_changeset(ui, repo, opts, buffered=False):
     """show one changeset using template or regular display.
 
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2120,14 +2120,12 @@  def debugtemplate(ui, repo, tmpl, **opts
         if newtree != tree:
             ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n')
 
-    mapfile = None
     if revs is None:
         k = 'debugtemplate'
         t = formatter.maketemplater(ui, k, tmpl)
         ui.write(templater.stringify(t(k, ui=ui, **props)))
     else:
-        displayer = cmdutil.changeset_templater(ui, repo, None, opts, tmpl,
-                                                mapfile, buffered=False)
+        displayer = cmdutil.makelogtemplater(ui, repo, tmpl)
         for r in revs:
             displayer.show(repo[r], **props)
         displayer.close()