comparison mercurial/configuration/rcutil.py @ 52426: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
comparison
equal deleted inserted replaced
52425:3e79ca017157 52426:22129ce9f86d
98 type could be either 'path', 'items' or 'resource'. If type is 'path', 98 type could be either 'path', 'items' or 'resource'. If type is 'path',
99 obj is a string, and is the config file path. if type is 'items', obj is a 99 obj is a string, and is the config file path. if type is 'items', obj is a
100 list of (section, name, value, source) that should fill the config directly. 100 list of (section, name, value, source) that should fill the config directly.
101 If type is 'resource', obj is a tuple of (package name, resource name). 101 If type is 'resource', obj is a tuple of (package name, resource name).
102 """ 102 """
103 envrc = (b'items', envrcitems()) 103 envrc = (conf_mod.LEVEL_ENV_OVERWRITE, b'items', envrcitems())
104
105 _rccomponents = []
106 comp = _rccomponents.append
104 107
105 if b'HGRCPATH' in encoding.environ: 108 if b'HGRCPATH' in encoding.environ:
106 # assume HGRCPATH is all about user configs so environments can be 109 # assume HGRCPATH is all about user configs so environments can be
107 # overridden. 110 # overridden.
108 _rccomponents = [envrc] 111 comp(envrc)
109 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): 112 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep):
110 if not p: 113 if not p:
111 continue 114 continue
112 _rccomponents.extend((b'path', p) for p in _expandrcpath(p)) 115 for p in _expandrcpath(p):
116 comp((conf_mod.LEVEL_ENV_OVERWRITE, b'path', p))
113 else: 117 else:
114 _rccomponents = [(b'resource', r) for r in default_rc_resources()] 118 for r in default_rc_resources():
119 comp((conf_mod.LEVEL_BUNDLED_RESOURCE, b'resource', r))
115 120
116 normpaths = lambda paths: [ 121 for p in systemrcpath():
117 (b'path', os.path.normpath(p)) for p in paths 122 comp((conf_mod.LEVEL_GLOBAL, b'path', os.path.normpath(p)))
118 ] 123 comp(envrc)
119 _rccomponents.extend(normpaths(systemrcpath())) 124 for p in userrcpath():
120 _rccomponents.append(envrc) 125 comp((conf_mod.LEVEL_USER, b'path', os.path.normpath(p)))
121 _rccomponents.extend(normpaths(userrcpath()))
122 return _rccomponents 126 return _rccomponents
123 127
124 128
125 def _shared_source_component(path: bytes) -> List[FileRCT]: 129 def _shared_source_component(path: bytes) -> List[FileRCT]:
126 """if the current repository is shared one, this tries to read 130 """if the current repository is shared one, this tries to read
145 149
146 150
147 def repo_components(repo_path: bytes) -> List[ComponentT]: 151 def repo_components(repo_path: bytes) -> List[ComponentT]:
148 """return the list of config file to read for a repository""" 152 """return the list of config file to read for a repository"""
149 components = [] 153 components = []
150 components.extend(_shared_source_component(repo_path)) 154 comp = components.append
151 components.append(os.path.join(repo_path, b".hg", b"hgrc")) 155 for p in _shared_source_component(repo_path):
152 components.append(os.path.join(repo_path, b".hg", b"hgrc-not-shared")) 156 comp((conf_mod.LEVEL_SHARED, b'path', p))
153 return [(b'path', c) for c in components] 157 comp(
158 (
159 conf_mod.LEVEL_LOCAL,
160 b'path',
161 os.path.join(repo_path, b".hg", b"hgrc"),
162 )
163 )
164 comp(
165 (
166 conf_mod.LEVEL_NON_SHARED,
167 b'path',
168 os.path.join(repo_path, b".hg", b"hgrc-not-shared"),
169 )
170 )
171 return components
154 172
155 173
156 def defaultpagerenv() -> Dict[bytes, bytes]: 174 def defaultpagerenv() -> Dict[bytes, bytes]:
157 """return a dict of default environment variables and their values, 175 """return a dict of default environment variables and their values,
158 intended to be set before starting a pager. 176 intended to be set before starting a pager.