mercurial/formatter.py
changeset 43100 90b9a7e06c2c
parent 43099 f1c5358f0d65
child 43101 1d12ae5096d1
--- a/mercurial/formatter.py	Sat Oct 05 23:04:45 2019 -0400
+++ b/mercurial/formatter.py	Sat Oct 05 23:20:35 2019 -0400
@@ -531,6 +531,7 @@
     'tmpl' can be any of the following:
 
      - a literal template (e.g. '{rev}')
+     - a reference to built-in template (i.e. formatter)
      - a map-file name or path (e.g. 'changelog')
      - a reference to [templates] in config file
      - a path to raw template file
@@ -544,10 +545,17 @@
     available as well as aliases in [templatealias].
     """
 
+    if not tmpl:
+        return templatespec(None, None, None)
+
     # looks like a literal template?
     if b'{' in tmpl:
         return templatespec(b'', tmpl, None)
 
+    # a reference to built-in (formatter) template
+    if tmpl in {b'cbor', b'json', b'pickle', b'debug'}:
+        return templatespec(tmpl, None, None)
+
     # perhaps a stock style?
     if not os.path.split(tmpl)[0]:
         mapname = templater.templatepath(
@@ -712,17 +720,16 @@
 
 
 def formatter(ui, out, topic, opts):
-    template = opts.get(b"template", b"")
-    if template == b"cbor":
+    spec = lookuptemplate(ui, topic, opts.get(b'template', b''))
+    if spec.ref == b"cbor":
         return cborformatter(ui, out, topic, opts)
-    elif template == b"json":
+    elif spec.ref == b"json":
         return jsonformatter(ui, out, topic, opts)
-    elif template == b"pickle":
+    elif spec.ref == b"pickle":
         return pickleformatter(ui, out, topic, opts)
-    elif template == b"debug":
+    elif spec.ref == b"debug":
         return debugformatter(ui, out, topic, opts)
-    elif template != b"":
-        spec = lookuptemplate(ui, topic, opts.get(b'template', b''))
+    elif spec.ref or spec.tmpl or spec.mapfile:
         return templateformatter(ui, out, topic, opts, spec)
     # developer config: ui.formatdebug
     elif ui.configbool(b'ui', b'formatdebug'):