# HG changeset patch # User Yuya Nishihara # Date 1460276589 -32400 # 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 -r f97a0bcfd7a1 -r 78759f78a44e mercurial/cmdutil.py --- 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 = {} diff -r f97a0bcfd7a1 -r 78759f78a44e mercurial/commands.py --- 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, diff -r f97a0bcfd7a1 -r 78759f78a44e mercurial/filemerge.py --- 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) diff -r f97a0bcfd7a1 -r 78759f78a44e mercurial/formatter.py --- 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