Mercurial > public > mercurial-scm > hg
comparison mercurial/configuration/rcutil.py @ 52423:0b791c90280a
repo-config: move rc component of repository inside `rcutil`
This gather logic about where to find config file in the same location.
This also reduce the amount of logic we do in dispatch.py which is a win in
itself.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 22 Oct 2024 23:42:15 +0200 |
parents | 91f22b89ea05 |
children | e3b45916c375 |
comparison
equal
deleted
inserted
replaced
52422:8a52fd131d3b | 52423:0b791c90280a |
---|---|
17 Union, | 17 Union, |
18 ) | 18 ) |
19 | 19 |
20 from .. import ( | 20 from .. import ( |
21 encoding, | 21 encoding, |
22 localrepo, | |
22 pycompat, | 23 pycompat, |
24 requirements as requirementsmod, | |
23 util, | 25 util, |
26 vfs, | |
24 ) | 27 ) |
25 | 28 |
26 from ..utils import resourceutil | 29 from ..utils import resourceutil |
27 | 30 |
28 if pycompat.iswindows: | 31 if pycompat.iswindows: |
125 _rccomponents.append(envrc) | 128 _rccomponents.append(envrc) |
126 _rccomponents.extend(normpaths(userrcpath())) | 129 _rccomponents.extend(normpaths(userrcpath())) |
127 return _rccomponents | 130 return _rccomponents |
128 | 131 |
129 | 132 |
133 def _shared_source_component(path: bytes) -> List[FileRCT]: | |
134 """if the current repository is shared one, this tries to read | |
135 .hg/hgrc of shared source if we are in share-safe mode | |
136 | |
137 This should be called before reading .hg/hgrc or the main repo | |
138 as that overrides config set in shared source""" | |
139 try: | |
140 with open(os.path.join(path, b".hg", b"requires"), "rb") as fp: | |
141 requirements = set(fp.read().splitlines()) | |
142 if not ( | |
143 requirementsmod.SHARESAFE_REQUIREMENT in requirements | |
144 and requirementsmod.SHARED_REQUIREMENT in requirements | |
145 ): | |
146 return [] | |
147 hgvfs = vfs.vfs(os.path.join(path, b".hg")) | |
148 sharedvfs = localrepo._getsharedvfs(hgvfs, requirements) | |
149 return [sharedvfs.join(b"hgrc")] | |
150 except IOError: | |
151 pass | |
152 return [] | |
153 | |
154 | |
155 def repo_components(repo_path: bytes) -> List[FileRCT]: | |
156 """return the list of config file to read for a repository""" | |
157 components = [] | |
158 components.extend(_shared_source_component(repo_path)) | |
159 components.append(os.path.join(repo_path, b".hg", b"hgrc")) | |
160 components.append(os.path.join(repo_path, b".hg", b"hgrc-not-shared")) | |
161 return components | |
162 | |
163 | |
130 def defaultpagerenv() -> Dict[bytes, bytes]: | 164 def defaultpagerenv() -> Dict[bytes, bytes]: |
131 """return a dict of default environment variables and their values, | 165 """return a dict of default environment variables and their values, |
132 intended to be set before starting a pager. | 166 intended to be set before starting a pager. |
133 """ | 167 """ |
134 return {b'LESS': b'FRX', b'LV': b'-c'} | 168 return {b'LESS': b'FRX', b'LV': b'-c'} |