[Updated] D8892: templater: replace templatepath() with function that also opens the file
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Thu Aug 6 00:50:09 UTC 2020
Closed by commit rHG65a812ed9e9f: templater: replace templatepath() with function that also opens the file (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/D8892?vs=22274&id=22290
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8892/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8892
AFFECTED FILES
mercurial/debugcommands.py
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
@@ -1071,12 +1071,15 @@
return path if os.path.isdir(path) else None
-def templatepath(name):
- '''return location of template file. returns None if not found.'''
- dir = templatedir()
- if dir is None:
- return None
- f = os.path.join(templatedir(), name)
- if f and os.path.isfile(f):
- return f
- return None
+def open_template(name):
+ '''returns a file-like object for the given template, and its full path'''
+ templatepath = templatedir()
+ if templatepath is not None or os.path.isabs(name):
+ f = os.path.join(templatepath, name)
+ try:
+ return f, open(f, mode='rb')
+ except EnvironmentError:
+ return None, None
+ else:
+ # TODO: read from resources here
+ return None, None
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -627,9 +627,9 @@
if not tmpl and style:
mapfile = style
if not os.path.split(mapfile)[0]:
- mapname = templater.templatepath(
+ (mapname, fp) = templater.open_template(
b'map-cmdline.' + mapfile
- ) or templater.templatepath(mapfile)
+ ) or templater.open_template(mapfile)
if mapname:
mapfile = mapname
return formatter.mapfile_templatespec(b'changeset', mapfile)
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -599,9 +599,9 @@
# perhaps a stock style?
if not os.path.split(tmpl)[0]:
- mapname = templater.templatepath(
+ (mapname, fp) = templater.open_template(
b'map-cmdline.' + tmpl
- ) or templater.templatepath(tmpl)
+ ) or templater.open_template(tmpl)
if mapname:
return mapfile_templatespec(topic, mapname)
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1672,7 +1672,7 @@
fm.write(b'templatedirs', b'checking templates (%s)...\n', p or b'')
fm.condwrite(not p, b'', _(b" no template directories found\n"))
if p:
- m = templater.templatepath(b"map-cmdline.default")
+ (m, fp) = templater.open_template(b"map-cmdline.default")
if m:
# template found, check if it is working
err = None
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/c67726c2/attachment-0002.html>
More information about the Mercurial-patches
mailing list