[Updated] D8891: templater: start passing resource to read from into _readmapfile()
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Thu Aug 6 00:48:33 UTC 2020
Closed by commit rHGdc10bcd5c08d: templater: start passing resource to read from into _readmapfile() (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/D8891?vs=22273&id=22289
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8891/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8891
AFFECTED FILES
mercurial/templater.py
CHANGE DETAILS
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -814,14 +814,17 @@
return b", ".join(sorted(stylelist))
-def _readmapfile(mapfile):
+def _open_mapfile(mapfile):
+ if os.path.exists(mapfile):
+ return util.posixfile(mapfile, b'rb')
+ raise error.Abort(
+ _(b"style '%s' not found") % mapfile,
+ hint=_(b"available styles: %s") % stylelist(),
+ )
+
+
+def _readmapfile(fp, mapfile):
"""Load template elements from the given map file"""
- if not os.path.exists(mapfile):
- raise error.Abort(
- _(b"style '%s' not found") % mapfile,
- hint=_(b"available styles: %s") % stylelist(),
- )
-
base = os.path.dirname(mapfile)
conf = config.config()
@@ -838,7 +841,7 @@
)
break
- data = util.posixfile(mapfile, b'rb').read()
+ data = fp.read()
conf.parse(mapfile, data, remap={b'': b'templates'}, include=include)
cache = {}
@@ -862,7 +865,8 @@
if os.path.isfile(p3):
path = p3
- cache, tmap, aliases = _readmapfile(path)
+ fp = _open_mapfile(path)
+ cache, tmap, aliases = _readmapfile(fp, path)
for key, val in conf[b'templates'].items():
if not val:
@@ -999,7 +1003,8 @@
):
"""Create templater from the specified map file"""
t = cls(filters, defaults, resources, cache, [], minchunk, maxchunk)
- cache, tmap, aliases = _readmapfile(mapfile)
+ fp = _open_mapfile(mapfile)
+ cache, tmap, aliases = _readmapfile(fp, mapfile)
t._loader.cache.update(cache)
t._loader._map = tmap
t._loader._aliasmap = _aliasrules.buildmap(aliases)
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/eb5148ec/attachment-0002.html>
More information about the Mercurial-patches
mailing list