[Updated] D8906: templater: restructure open_template() a little to prepare for relative paths
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Aug 7 00:34:23 UTC 2020
Closed by commit rHG735756ecda8c: templater: restructure open_template() a little to prepare for relative paths (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/D8906?vs=22316&id=22320
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8906/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8906
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
@@ -1091,18 +1091,25 @@
will be read from the mercurial.templates package instead. The returned path
will then be the relative path.
'''
+ # Does the name point directly to a map file?
+ if os.path.isabs(name):
+ return name, open(name, mode='rb')
+
+ # Does the name point to a template in the provided templatepath, or
+ # in mercurial/templates/ if no path was provided?
if templatepath is None:
templatepath = templatedir()
- if templatepath is not None or os.path.isabs(name):
+ if templatepath is not None:
f = os.path.join(templatepath, name)
return f, open(f, mode='rb')
- else:
- name_parts = pycompat.sysstr(name).split('/')
- package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1])
- return (
- name,
- resourceutil.open_resource(package_name, name_parts[-1]),
- )
+
+ # Otherwise try to read it using the resources API
+ name_parts = pycompat.sysstr(name).split('/')
+ package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1])
+ return (
+ name,
+ resourceutil.open_resource(package_name, name_parts[-1]),
+ )
def try_open_template(name, templatepath=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/20200807/6fb6d8d3/attachment-0002.html>
More information about the Mercurial-patches
mailing list