Patchwork [6,of,9] templater: factor out function that creates templater from string template

login
register
mail settings
Submitter Yuya Nishihara
Date April 15, 2016, 1:15 p.m.
Message ID <3f45dae15bb24e63c373.1460726145@mimosa>
Download mbox | patch
Permalink /patch/14645/
State Accepted
Headers show

Comments

Yuya Nishihara - April 15, 2016, 1:15 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1460276589 -32400
#      Sun Apr 10 17:23:09 2016 +0900
# Node ID 3f45dae15bb24e63c37330352b37f8b4a53f43f6
# Parent  8831af8116bb1e10506529c39ace09bde10566fc
templater: factor out function that creates templater from string template

This function will host loading of template aliases. It is not defined at
templater, but at formatter, since formatter is the module handling ui stuff
in front of templater.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1492,9 +1492,9 @@  class changeset_templater(changeset_prin
             self.t = templater.templater.frommapfile(mapfile, filters=filters,
                                                      cache=defaulttempl)
         else:
-            self.t = templater.templater(filters=filters, cache=defaulttempl)
-            if tmpl:
-                self.t.cache['changeset'] = tmpl
+            self.t = formatter.maketemplater(ui, 'changeset', tmpl,
+                                             filters=filters,
+                                             cache=defaulttempl)
 
         self.cache = {}
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -46,6 +46,7 @@  from . import (
     exchange,
     extensions,
     fileset,
+    formatter,
     graphmod,
     hbisect,
     help,
@@ -3681,8 +3682,7 @@  def debugtemplate(ui, repo, tmpl, **opts
     mapfile = None
     if revs is None:
         k = 'debugtemplate'
-        t = templater.templater()
-        t.cache[k] = tmpl
+        t = formatter.maketemplater(ui, k, tmpl)
         ui.write(templater.stringify(t(k, **props)))
     else:
         displayer = cmdutil.changeset_templater(ui, repo, None, opts, tmpl,
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -17,6 +17,7 @@  from .node import nullid, short
 
 from . import (
     error,
+    formatter,
     match,
     scmutil,
     simplemerge,
@@ -526,7 +527,7 @@  def _formatlabels(repo, fcd, fco, fca, l
 
     ui = repo.ui
     template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker)
-    tmpl = templater.templater(cache={'conflictmarker': template})
+    tmpl = formatter.maketemplater(ui, 'conflictmarker', template)
 
     pad = max(len(l) for l in labels)
 
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -193,7 +193,11 @@  def gettemplater(ui, topic, spec):
     assert not (tmpl and mapfile)
     if mapfile:
         return templater.templater.frommapfile(mapfile)
-    t = templater.templater()
+    return maketemplater(ui, topic, tmpl)
+
+def maketemplater(ui, topic, tmpl, filters=None, cache=None):
+    """Create a templater from a string template 'tmpl'"""
+    t = templater.templater(filters=filters, cache=cache)
     if tmpl:
         t.cache[topic] = tmpl
     return t