comparison mercurial/configuration/rcutil.py @ 52458: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
comparison
equal deleted inserted replaced
52457:22129ce9f86d 52458:8c509a70b6fa
85 if resourceutil.is_resource(b'mercurial.defaultrc', r) 85 if resourceutil.is_resource(b'mercurial.defaultrc', r)
86 and r.endswith(b'.rc') 86 and r.endswith(b'.rc')
87 ] 87 ]
88 88
89 89
90 def rccomponents() -> List[ComponentT]: 90 def rccomponents(use_hgrcpath=True) -> List[ComponentT]:
91 """return an ordered [(type, obj)] about where to load configs. 91 """return an ordered [(type, obj)] about where to load configs.
92 92
93 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is 93 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is
94 used. if $HGRCPATH is not set, the platform default will be used. 94 used. if $HGRCPATH is not set, the platform default will be used. If
95 `use_hgrcpath` is False, it is never used.
95 96
96 if a directory is provided, *.rc files under it will be used. 97 if a directory is provided, *.rc files under it will be used.
97 98
98 type could be either 'path', 'items' or 'resource'. If type is 'path', 99 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 100 obj is a string, and is the config file path. if type is 'items', obj is a
103 envrc = (conf_mod.LEVEL_ENV_OVERWRITE, b'items', envrcitems()) 104 envrc = (conf_mod.LEVEL_ENV_OVERWRITE, b'items', envrcitems())
104 105
105 _rccomponents = [] 106 _rccomponents = []
106 comp = _rccomponents.append 107 comp = _rccomponents.append
107 108
108 if b'HGRCPATH' in encoding.environ: 109 if b'HGRCPATH' in encoding.environ and use_hgrcpath:
109 # assume HGRCPATH is all about user configs so environments can be 110 # assume HGRCPATH is all about user configs so environments can be
110 # overridden. 111 # overridden.
111 comp(envrc) 112 comp(envrc)
112 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep): 113 for p in encoding.environ[b'HGRCPATH'].split(pycompat.ospathsep):
113 if not p: 114 if not p:
169 ) 170 )
170 ) 171 )
171 return components 172 return components
172 173
173 174
175 def all_rc_components(repo_path: Optional[bytes]):
176 components = []
177 components.extend(rccomponents(use_hgrcpath=False))
178 if repo_path is not None:
179 components.extend(repo_components(repo_path))
180 return components
181
182
174 def defaultpagerenv() -> Dict[bytes, bytes]: 183 def defaultpagerenv() -> Dict[bytes, bytes]:
175 """return a dict of default environment variables and their values, 184 """return a dict of default environment variables and their values,
176 intended to be set before starting a pager. 185 intended to be set before starting a pager.
177 """ 186 """
178 return {b'LESS': b'FRX', b'LV': b'-c'} 187 return {b'LESS': b'FRX', b'LV': b'-c'}