# HG changeset patch # User Yuya Nishihara # Date 2016-04-10 08:23:09 # Node ID 78759f78a44ed98637ae0c0ad4a26f95e0bcd4f1 # Parent f97a0bcfd7a1a5a8a8aba97529650c8cbd1fb4a0 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. 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