diff mercurial/config.py @ 45208:f7f142d74df3

config: pass both relative and absolute paths to `include` callback 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. Differential Revision: https://phab.mercurial-scm.org/D8790
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 21 Jul 2020 23:50:42 -0700
parents 9f70512ae2cf
children 3f54242781e9
line wrap: on
line diff
--- a/mercurial/config.py	Wed Jul 22 22:38:42 2020 -0700
+++ b/mercurial/config.py	Tue Jul 21 23:50:42 2020 -0700
@@ -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
         )