comparison 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
comparison
equal deleted inserted replaced
45207:4489e9a22763 45208:f7f142d74df3
166 166
167 for base in includepaths: 167 for base in includepaths:
168 inc = os.path.normpath(os.path.join(base, expanded)) 168 inc = os.path.normpath(os.path.join(base, expanded))
169 169
170 try: 170 try:
171 include(inc, remap=remap, sections=sections) 171 include(expanded, inc, remap=remap, sections=sections)
172 break 172 break
173 except IOError as inst: 173 except IOError as inst:
174 if inst.errno != errno.ENOENT: 174 if inst.errno != errno.ENOENT:
175 raise error.ParseError( 175 raise error.ParseError(
176 _(b"cannot include %s (%s)") 176 _(b"cannot include %s (%s)")
214 fp = util.posixfile(path, b'rb') 214 fp = util.posixfile(path, b'rb')
215 assert getattr(fp, 'mode', 'rb') == 'rb', ( 215 assert getattr(fp, 'mode', 'rb') == 'rb', (
216 b'config files must be opened in binary mode, got fp=%r mode=%r' 216 b'config files must be opened in binary mode, got fp=%r mode=%r'
217 % (fp, fp.mode,) 217 % (fp, fp.mode,)
218 ) 218 )
219
220 def include(rel, abs, remap, sections):
221 self.read(abs, remap=remap, sections=sections)
222
219 self.parse( 223 self.parse(
220 path, fp.read(), sections=sections, remap=remap, include=self.read 224 path, fp.read(), sections=sections, remap=remap, include=include
221 ) 225 )
222 226
223 227
224 def parselist(value): 228 def parselist(value):
225 """parse a configuration value as a list of comma/space separated strings 229 """parse a configuration value as a list of comma/space separated strings