diff mercurial/configuration/rcutil.py @ 52427:8c509a70b6fa

config: gather the path to edit through rcutil Using the common logic helps to reduce potential error when it changes
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 23 Oct 2024 02:05:03 +0200
parents 22129ce9f86d
children 24ee91ba9aa8
line wrap: on
line diff
--- a/mercurial/configuration/rcutil.py	Wed Oct 23 01:32:33 2024 +0200
+++ b/mercurial/configuration/rcutil.py	Wed Oct 23 02:05:03 2024 +0200
@@ -87,11 +87,12 @@
     ]
 
 
-def rccomponents() -> List[ComponentT]:
+def rccomponents(use_hgrcpath=True) -> List[ComponentT]:
     """return an ordered [(type, obj)] about where to load configs.
 
     respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is
-    used. if $HGRCPATH is not set, the platform default will be used.
+    used. if $HGRCPATH is not set, the platform default will be used. If
+    `use_hgrcpath` is False, it is never used.
 
     if a directory is provided, *.rc files under it will be used.
 
@@ -105,7 +106,7 @@
     _rccomponents = []
     comp = _rccomponents.append
 
-    if b'HGRCPATH' in encoding.environ:
+    if b'HGRCPATH' in encoding.environ and use_hgrcpath:
         # assume HGRCPATH is all about user configs so environments can be
         # overridden.
         comp(envrc)
@@ -171,6 +172,14 @@
     return components
 
 
+def all_rc_components(repo_path: Optional[bytes]):
+    components = []
+    components.extend(rccomponents(use_hgrcpath=False))
+    if repo_path is not None:
+        components.extend(repo_components(repo_path))
+    return components
+
+
 def defaultpagerenv() -> Dict[bytes, bytes]:
     """return a dict of default environment variables and their values,
     intended to be set before starting a pager.