Patchwork D8792: templater: do search for include of unqualified builtin outside of config code

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

Comments

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

REVISION SUMMARY
  Commit 081b08e4ea13 <https://phab.mercurial-scm.org/rHG081b08e4ea1350f5c501b0ae0915547b8acc5503> (templater: look for mapfiles in template paths,
  2015-05-15) added support for using things like `%include
  map-cmdline.default` to include built-in map files without using a
  valid path to them. This patch rewrites that support by moving it into
  `_readmapfile()` so it can later be adapted for reading from a
  non-file resource.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -823,11 +823,18 @@ 
         )
 
     base = os.path.dirname(mapfile)
-    conf = config.config(includepaths=[templatedir()])
+    conf = config.config()
 
     def include(rel, abs, remap, sections):
-        data = util.posixfile(abs, b'rb').read()
-        conf.parse(abs, data, sections=sections, remap=remap, include=include)
+        templatedirs = [base, templatedir()]
+        for dir in templatedirs:
+            abs = os.path.normpath(os.path.join(dir, rel))
+            if os.path.isfile(abs):
+                data = util.posixfile(abs, b'rb').read()
+                conf.parse(
+                    abs, data, sections=sections, remap=remap, include=include
+                )
+                break
 
     data = util.posixfile(mapfile, b'rb').read()
     conf.parse(mapfile, data, remap={b'': b'templates'}, include=include)