mercurial/templater.py
changeset 45309 65a812ed9e9f
parent 45308 dc10bcd5c08d
child 45310 f3481e4fcc3a
--- a/mercurial/templater.py	Thu Jul 30 13:44:06 2020 -0700
+++ b/mercurial/templater.py	Tue Aug 04 13:21:29 2020 -0700
@@ -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