Patchwork [2,of,5] formatter: pass in template spec to templateformatter as argument

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 6, 2019, 8 p.m.
Message ID <79c73a7a10457e10fa37.1570392013@mimosa>
Download mbox | patch
Permalink /patch/42041/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 6, 2019, 8 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1570331085 14400
#      Sat Oct 05 23:04:45 2019 -0400
# Node ID 79c73a7a10457e10fa370fe43b028ce54ca98bb7
# Parent  49e17f9f1885bd91aa2aa284ae4d1847b99adf59
formatter: pass in template spec to templateformatter as argument

Prepare for the next patch, which will unify handling of the formatter
names and the template names.

Patch

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -212,8 +212,8 @@  def _formatflags(ui, repo, rev, flags):
     if not tmpl:
         return b' '.join(flags)
     out = util.stringio()
-    opts = {b'template': templater.unquotestring(tmpl)}
-    with formatter.templateformatter(ui, out, b'patchbombflag', opts) as fm:
+    spec = formatter.templatespec(b'', templater.unquotestring(tmpl), None)
+    with formatter.templateformatter(ui, out, b'patchbombflag', {}, spec) as fm:
         fm.startitem()
         fm.context(ctx=repo[rev])
         fm.write(b'flags', b'%s', fm.formatlist(flags, name=b'flag'))
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -475,10 +475,9 @@  class _templateconverter(object):
 
 
 class templateformatter(baseformatter):
-    def __init__(self, ui, out, topic, opts):
+    def __init__(self, ui, out, topic, opts, spec):
         baseformatter.__init__(self, ui, topic, opts, _templateconverter)
         self._out = out
-        spec = lookuptemplate(ui, topic, opts.get(b'template', b''))
         self._tref = spec.ref
         self._t = loadtemplater(
             ui,
@@ -723,7 +722,8 @@  def formatter(ui, out, topic, opts):
     elif template == b"debug":
         return debugformatter(ui, out, topic, opts)
     elif template != b"":
-        return templateformatter(ui, out, topic, opts)
+        spec = lookuptemplate(ui, topic, opts.get(b'template', b''))
+        return templateformatter(ui, out, topic, opts, spec)
     # developer config: ui.formatdebug
     elif ui.configbool(b'ui', b'formatdebug'):
         return debugformatter(ui, out, topic, opts)