changeset 45333:d9a502a0a9ca

templater: unroll loop over mapfile directories I'll rewrite the handling of the `templatedir()` case in the next patch, so the two cases will be more different and the loop won't make as much sense. Differential Revision: https://phab.mercurial-scm.org/D8895
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 30 Jul 2020 15:29:06 -0700
parents 3b27ed8e324e
children fef64d7a4a84
files mercurial/templater.py
diffstat 1 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Tue Aug 04 10:51:25 2020 -0700
+++ b/mercurial/templater.py	Thu Jul 30 15:29:06 2020 -0700
@@ -829,17 +829,22 @@
     conf = config.config()
 
     def include(rel, remap, sections):
-        templatedirs = [base, templatedir()]
-        for dir in templatedirs:
-            if dir is None:
-                continue
-            abs = os.path.normpath(os.path.join(dir, rel))
+        subresource = None
+        if base:
+            abs = os.path.normpath(os.path.join(base, rel))
             if os.path.isfile(abs):
-                data = util.posixfile(abs, b'rb').read()
-                conf.parse(
-                    abs, data, sections=sections, remap=remap, include=include
-                )
-                break
+                subresource = util.posixfile(abs, b'rb')
+        if not subresource:
+            dir = templatedir()
+            if dir:
+                abs = os.path.normpath(os.path.join(dir, rel))
+                if os.path.isfile(abs):
+                    subresource = util.posixfile(abs, b'rb')
+        if subresource:
+            data = subresource.read()
+            conf.parse(
+                abs, data, sections=sections, remap=remap, include=include,
+            )
 
     data = fp.read()
     conf.parse(mapfile, data, remap={b'': b'templates'}, include=include)