Patchwork D8895: templater: unroll loop over mapfile directories

login
register
mail settings
Submitter phabricator
Date Aug. 5, 2020, 5:10 p.m.
Message ID <differential-rev-PHID-DREV-l5s4wptjzdx2nj2i3rpa-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46994/
State Superseded
Headers show

Comments

phabricator - Aug. 5, 2020, 5:10 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8895

AFFECTED FILES
  mercurial/templater.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -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)