diff mercurial/formatter.py @ 45331:f3481e4fcc3a

templater: pass opened file-like object to templatespec I think I said earlier that I planned to create a special templatespec variant for built-in templates. That was true (I planned that), but I ended up (in this patch) just adding a file-like object to the `mapfile_templatespec()` variant instead. Differential Revision: https://phab.mercurial-scm.org/D8893
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 04 Aug 2020 13:22:00 -0700
parents 65a812ed9e9f
children 4aa484efc926
line wrap: on
line diff
--- a/mercurial/formatter.py	Tue Aug 04 13:21:29 2020 -0700
+++ b/mercurial/formatter.py	Tue Aug 04 13:22:00 2020 -0700
@@ -540,6 +540,7 @@
     tmpl = attr.ib()
     mapfile = attr.ib()
     refargs = attr.ib(default=None)
+    fp = attr.ib(default=None)
 
 
 def empty_templatespec():
@@ -556,8 +557,8 @@
     return templatespec(b'', tmpl, None)
 
 
-def mapfile_templatespec(topic, mapfile):
-    return templatespec(topic, None, mapfile)
+def mapfile_templatespec(topic, mapfile, fp=None):
+    return templatespec(topic, None, mapfile, fp=fp)
 
 
 def lookuptemplate(ui, topic, tmpl):
@@ -603,7 +604,7 @@
             b'map-cmdline.' + tmpl
         ) or templater.open_template(tmpl)
         if mapname:
-            return mapfile_templatespec(topic, mapname)
+            return mapfile_templatespec(topic, mapname, fp)
 
     # perhaps it's a reference to [templates]
     if ui.config(b'templates', tmpl):
@@ -645,7 +646,11 @@
     assert not (spec.tmpl and spec.mapfile)
     if spec.mapfile:
         return templater.templater.frommapfile(
-            spec.mapfile, defaults=defaults, resources=resources, cache=cache
+            spec.mapfile,
+            spec.fp,
+            defaults=defaults,
+            resources=resources,
+            cache=cache,
         )
     return maketemplater(
         ui, spec.tmpl, defaults=defaults, resources=resources, cache=cache