--- a/mercurial/formatter.py Wed Jul 29 10:42:09 2020 -0700
+++ b/mercurial/formatter.py Thu Jul 16 13:33:46 2020 -0700
@@ -542,6 +542,22 @@
refargs = attr.ib(default=None)
+def empty_templatespec():
+ return templatespec(None, None, None)
+
+
+def reference_templatespec(ref, refargs=None):
+ return templatespec(ref, None, None, refargs)
+
+
+def literal_templatespec(tmpl):
+ return templatespec(b'', tmpl, None)
+
+
+def mapfile_templatespec(topic, mapfile):
+ return templatespec(topic, None, mapfile)
+
+
def lookuptemplate(ui, topic, tmpl):
"""Find the template matching the given -T/--template spec 'tmpl'
@@ -563,21 +579,21 @@
"""
if not tmpl:
- return templatespec(None, None, None)
+ return empty_templatespec()
# looks like a literal template?
if b'{' in tmpl:
- return templatespec(b'', tmpl, None)
+ return literal_templatespec(tmpl)
# a reference to built-in (formatter) template
if tmpl in {b'cbor', b'json', b'pickle', b'debug'}:
- return templatespec(tmpl, None, None)
+ return reference_templatespec(tmpl)
# a function-style reference to built-in template
func, fsep, ftail = tmpl.partition(b'(')
if func in {b'cbor', b'json'} and fsep and ftail.endswith(b')'):
templater.parseexpr(tmpl) # make sure syntax errors are confined
- return templatespec(func, None, None, refargs=ftail[:-1])
+ return reference_templatespec(func, refargs=ftail[:-1])
# perhaps a stock style?
if not os.path.split(tmpl)[0]:
@@ -585,11 +601,11 @@
b'map-cmdline.' + tmpl
) or templater.templatepath(tmpl)
if mapname:
- return templatespec(topic, None, mapname)
+ return mapfile_templatespec(topic, mapname)
# perhaps it's a reference to [templates]
if ui.config(b'templates', tmpl):
- return templatespec(tmpl, None, None)
+ return reference_templatespec(tmpl)
if tmpl == b'list':
ui.write(_(b"available styles: %s\n") % templater.stylelist())
@@ -599,13 +615,13 @@
if (b'/' in tmpl or b'\\' in tmpl) and os.path.isfile(tmpl):
# is it a mapfile for a style?
if os.path.basename(tmpl).startswith(b"map-"):
- return templatespec(topic, None, os.path.realpath(tmpl))
+ return mapfile_templatespec(topic, os.path.realpath(tmpl))
with util.posixfile(tmpl, b'rb') as f:
tmpl = f.read()
- return templatespec(b'', tmpl, None)
+ return literal_templatespec(tmpl)
# constant string?
- return templatespec(b'', tmpl, None)
+ return literal_templatespec(tmpl)
def templatepartsmap(spec, t, partnames):