Patchwork D8790: config: pass both relative and absolute paths to `include` callback

login
register
mail settings
Submitter phabricator
Date July 22, 2020, 5:40 p.m.
Message ID <differential-rev-PHID-DREV-gyi5i32ngxza72ajlxwx-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46835/
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
  The `include` callback is responsible for loading configs from
  `%include` statements. The callback currently gets passed the absolute
  path [1] to the config to read. That is created by joining the dirname
  of the file that contains the `%include` statement. For PyOxidizer
  support, I'm trying to reduce dependence on paths. This patch helps
  with that by passing the relative path found in the `%include`
  statement (but with username expansion, etc.) to the `include`
  callback. It also turns out that the existing callers can easily adapt
  to using the relative path. Coming patches will clean that up and then
  we'll remove the absolute path from the callback.
  
  [1] The "absolute path" bit is a bit of a lie -- it's going to be an
   absolute path if the path that was passed into `config.parse()` was
   absolute.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/config.py
  mercurial/subrepoutil.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/subrepoutil.py b/mercurial/subrepoutil.py
--- a/mercurial/subrepoutil.py
+++ b/mercurial/subrepoutil.py
@@ -36,7 +36,7 @@ 
     p = config.config()
     repo = ctx.repo()
 
-    def read(f, sections=None, remap=None):
+    def read(rel, f, sections=None, remap=None):
         if f in ctx:
             try:
                 data = ctx[f].data()
@@ -56,7 +56,7 @@ 
             )
 
     if b'.hgsub' in ctx:
-        read(b'.hgsub')
+        read(b'.hgsub', b'.hgsub')
 
     for path, src in ui.configitems(b'subpaths'):
         p.set(b'subpaths', path, src, ui.configsource(b'subpaths', path))
diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -168,7 +168,7 @@ 
                     inc = os.path.normpath(os.path.join(base, expanded))
 
                     try:
-                        include(inc, remap=remap, sections=sections)
+                        include(expanded, inc, remap=remap, sections=sections)
                         break
                     except IOError as inst:
                         if inst.errno != errno.ENOENT:
@@ -216,8 +216,12 @@ 
             b'config files must be opened in binary mode, got fp=%r mode=%r'
             % (fp, fp.mode,)
         )
+
+        def include(rel, abs, remap, sections):
+            self.read(abs, remap=remap, sections=sections)
+
         self.parse(
-            path, fp.read(), sections=sections, remap=remap, include=self.read
+            path, fp.read(), sections=sections, remap=remap, include=include
         )