changeset 28955:78759f78a44e

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.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 10 Apr 2016 17:23:09 +0900
parents f97a0bcfd7a1
children eea98190ed73
files mercurial/cmdutil.py mercurial/commands.py mercurial/filemerge.py mercurial/formatter.py
diffstat 4 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun Apr 03 23:26:48 2016 +0900
+++ b/mercurial/cmdutil.py	Sun Apr 10 17:23:09 2016 +0900
@@ -1492,9 +1492,9 @@
             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 = {}
 
--- a/mercurial/commands.py	Sun Apr 03 23:26:48 2016 +0900
+++ b/mercurial/commands.py	Sun Apr 10 17:23:09 2016 +0900
@@ -46,6 +46,7 @@
     exchange,
     extensions,
     fileset,
+    formatter,
     graphmod,
     hbisect,
     help,
@@ -3681,8 +3682,7 @@
     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,
--- a/mercurial/filemerge.py	Sun Apr 03 23:26:48 2016 +0900
+++ b/mercurial/filemerge.py	Sun Apr 10 17:23:09 2016 +0900
@@ -17,6 +17,7 @@
 
 from . import (
     error,
+    formatter,
     match,
     scmutil,
     simplemerge,
@@ -526,7 +527,7 @@
 
     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)
 
--- a/mercurial/formatter.py	Sun Apr 03 23:26:48 2016 +0900
+++ b/mercurial/formatter.py	Sun Apr 10 17:23:09 2016 +0900
@@ -193,7 +193,11 @@
     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