Mercurial > public > mercurial-scm > hg-stable
diff mercurial/configuration/rcutil.py @ 52457:22129ce9f86d
config: include the component level when returning them
This will be useful when modifying them.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 23 Oct 2024 01:32:33 +0200 |
parents | 3e79ca017157 |
children | 8c509a70b6fa |
line wrap: on
line diff
--- a/mercurial/configuration/rcutil.py Wed Oct 23 00:43:17 2024 +0200 +++ b/mercurial/configuration/rcutil.py Wed Oct 23 01:32:33 2024 +0200 @@ -100,25 +100,29 @@ list of (section, name, value, source) that should fill the config directly. If type is 'resource', obj is a tuple of (package name, resource name). """ - envrc = (b'items', envrcitems()) + envrc = (conf_mod.LEVEL_ENV_OVERWRITE, b'items', envrcitems()) + + _rccomponents = [] + comp = _rccomponents.append if b'HGRCPATH' in encoding.environ: # assume HGRCPATH is all about user configs so environments can be # overridden. - _rccomponents = [envrc] + comp(envrc) for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): if not p: continue - _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) + for p in _expandrcpath(p): + comp((conf_mod.LEVEL_ENV_OVERWRITE, b'path', p)) else: - _rccomponents = [(b'resource', r) for r in default_rc_resources()] + for r in default_rc_resources(): + comp((conf_mod.LEVEL_BUNDLED_RESOURCE, b'resource', r)) - normpaths = lambda paths: [ - (b'path', os.path.normpath(p)) for p in paths - ] - _rccomponents.extend(normpaths(systemrcpath())) - _rccomponents.append(envrc) - _rccomponents.extend(normpaths(userrcpath())) + for p in systemrcpath(): + comp((conf_mod.LEVEL_GLOBAL, b'path', os.path.normpath(p))) + comp(envrc) + for p in userrcpath(): + comp((conf_mod.LEVEL_USER, b'path', os.path.normpath(p))) return _rccomponents @@ -147,10 +151,24 @@ def repo_components(repo_path: bytes) -> List[ComponentT]: """return the list of config file to read for a repository""" components = [] - components.extend(_shared_source_component(repo_path)) - components.append(os.path.join(repo_path, b".hg", b"hgrc")) - components.append(os.path.join(repo_path, b".hg", b"hgrc-not-shared")) - return [(b'path', c) for c in components] + comp = components.append + for p in _shared_source_component(repo_path): + comp((conf_mod.LEVEL_SHARED, b'path', p)) + comp( + ( + conf_mod.LEVEL_LOCAL, + b'path', + os.path.join(repo_path, b".hg", b"hgrc"), + ) + ) + comp( + ( + conf_mod.LEVEL_NON_SHARED, + b'path', + os.path.join(repo_path, b".hg", b"hgrc-not-shared"), + ) + ) + return components def defaultpagerenv() -> Dict[bytes, bytes]: