[Updated] D8893: templater: pass opened file-like object to templatespec

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Thu Aug 6 00:49:23 UTC 2020


Closed by commit rHGf3481e4fcc3a: templater: pass opened file-like object to templatespec (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8893?vs=22275&id=22291

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8893/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8893

AFFECTED FILES
  mercurial/formatter.py
  mercurial/logcmdutil.py
  mercurial/templater.py

CHANGE DETAILS

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -994,6 +994,7 @@
     def frommapfile(
         cls,
         mapfile,
+        fp=None,
         filters=None,
         defaults=None,
         resources=None,
@@ -1003,7 +1004,8 @@
     ):
         """Create templater from the specified map file"""
         t = cls(filters, defaults, resources, cache, [], minchunk, maxchunk)
-        fp = _open_mapfile(mapfile)
+        if not fp:
+            fp = _open_mapfile(mapfile)
         cache, tmap, aliases = _readmapfile(fp, mapfile)
         t._loader.cache.update(cache)
         t._loader._map = tmap
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -626,13 +626,14 @@
 
     if not tmpl and style:
         mapfile = style
+        fp = None
         if not os.path.split(mapfile)[0]:
             (mapname, fp) = templater.open_template(
                 b'map-cmdline.' + mapfile
             ) or templater.open_template(mapfile)
             if mapname:
                 mapfile = mapname
-        return formatter.mapfile_templatespec(b'changeset', mapfile)
+        return formatter.mapfile_templatespec(b'changeset', mapfile, fp)
 
     return formatter.lookuptemplate(ui, b'changeset', tmpl)
 
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -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



To: martinvonz, #hg-reviewers, indygreg
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200806/94aa7cb3/attachment-0002.html>


More information about the Mercurial-patches mailing list