[PATCH 5 of 8] formatter: factor out function to create templater from literal or map file
Yuya Nishihara
yuya at tcha.org
Wed Jun 14 09:40:36 EDT 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1492841166 -32400
# Sat Apr 22 15:06:06 2017 +0900
# Node ID 2e1a9d997e10ebbfba747ceacac0c514ea0a4524
# Parent 544bef6832aa25822fdfa7c93e8fe5f8371bcb80
formatter: factor out function to create templater from literal or map file
(tmpl, mapfile) will be packed into a named tuple later.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1580,15 +1580,8 @@ class changeset_templater(changeset_prin
def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered):
changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
- assert not (tmpl and mapfile)
- defaulttempl = templatekw.defaulttempl
- if mapfile:
- self.t = templater.templater.frommapfile(mapfile,
- cache=defaulttempl)
- else:
- self.t = formatter.maketemplater(ui, 'changeset', tmpl,
- cache=defaulttempl)
-
+ self.t = formatter.loadtemplater(ui, 'changeset', (tmpl, mapfile),
+ cache=templatekw.defaulttempl)
self._counter = itertools.count()
self.cache = {}
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -408,6 +408,12 @@ def lookuptemplate(ui, topic, tmpl):
def gettemplater(ui, topic, spec, cache=None):
tmpl, mapfile = lookuptemplate(ui, topic, spec)
+ return loadtemplater(ui, topic, (tmpl, mapfile), cache=cache)
+
+def loadtemplater(ui, topic, spec, cache=None):
+ """Create a templater from either a literal template or loading from
+ a map file"""
+ tmpl, mapfile = spec
assert not (tmpl and mapfile)
if mapfile:
return templater.templater.frommapfile(mapfile, cache=cache)
More information about the Mercurial-devel
mailing list