config: include the component level when returning them
This will be useful when modifying them.
--- a/mercurial/configuration/__init__.py Wed Oct 23 00:43:17 2024 +0200
+++ b/mercurial/configuration/__init__.py Wed Oct 23 01:32:33 2024 +0200
@@ -10,11 +10,15 @@
# keep typing simple for now
ConfigLevelT = str
-LEVEL_USER = 'user' # "user" is the default level and never passed explicitly
+LEVEL_BUNDLED_RESOURCE = 'RESOURCE'
+LEVEL_ENV_OVERWRITE = 'ENV-HGRCPATH'
+LEVEL_USER = 'user'
LEVEL_LOCAL = 'local'
LEVEL_GLOBAL = 'global'
LEVEL_SHARED = 'shared'
LEVEL_NON_SHARED = 'non_shared'
+# only include level that it make sense to edit
+# note: "user" is the default level and never passed explicitly
EDIT_LEVELS = (
LEVEL_USER,
LEVEL_LOCAL,
@@ -27,6 +31,7 @@
ResourceIDT = Tuple[bytes, bytes]
FileRCT = bytes
ComponentT = Tuple[
+ ConfigLevelT,
bytes,
Union[
List[ConfigItemT],
--- a/mercurial/configuration/command.py Wed Oct 23 00:43:17 2024 +0200
+++ b/mercurial/configuration/command.py Wed Oct 23 01:32:33 2024 +0200
@@ -111,7 +111,7 @@
XXX this skip over various source and ignore the repository config, so it
XXX is probably useless old code.
"""
- for t, f in rcutil.rccomponents():
+ for _lvl, t, f in rcutil.rccomponents():
if t == b'path':
ui.debug(b'read config from: %s\n' % f)
elif t == b'resource':
--- 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]:
--- a/mercurial/dispatch.py Wed Oct 23 00:43:17 2024 +0200
+++ b/mercurial/dispatch.py Wed Oct 23 01:32:33 2024 +0200
@@ -954,7 +954,7 @@
else:
lui = ui.copy()
if rcutil.use_repo_hgrc():
- for c_type, rc_path in rcutil.repo_components(path):
+ for __, c_type, rc_path in rcutil.repo_components(path):
assert c_type == b'path'
lui.readconfig(rc_path, root=path)
@@ -966,7 +966,7 @@
path = path_obj.rawloc
lui = ui.copy()
if rcutil.use_repo_hgrc():
- for c_type, rc_path in rcutil.repo_components(path):
+ for __, c_type, rc_path in rcutil.repo_components(path):
assert c_type == b'path'
lui.readconfig(rc_path, root=path)
--- a/mercurial/ui.py Wed Oct 23 00:43:17 2024 +0200
+++ b/mercurial/ui.py Wed Oct 23 01:32:33 2024 +0200
@@ -335,7 +335,7 @@
"""Create a ui and load global and user configs"""
u = cls()
# we always trust global config files and environment variables
- for t, f in rcutil.rccomponents():
+ for _lvl, t, f in rcutil.rccomponents():
if t == b'path':
u.readconfig(f, trust=True)
elif t == b'resource':