comparison mercurial/ui.py @ 46734:e3f15c553522

paths: add a `*` special path to define default sub option Differential Revision: https://phab.mercurial-scm.org/D10163
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 11 Mar 2021 11:22:54 +0100
parents 66fb04552122
children d4ba4d51f85f
comparison
equal deleted inserted replaced
46733:66fb04552122 46734:e3f15c553522
2188 """ 2188 """
2189 2189
2190 def __init__(self, ui): 2190 def __init__(self, ui):
2191 dict.__init__(self) 2191 dict.__init__(self)
2192 2192
2193 _path, base_sub_options = ui.configsuboptions(b'paths', b'*')
2193 for name, loc in ui.configitems(b'paths', ignoresub=True): 2194 for name, loc in ui.configitems(b'paths', ignoresub=True):
2194 # No location is the same as not existing. 2195 # No location is the same as not existing.
2195 if not loc: 2196 if not loc:
2196 continue 2197 continue
2197 loc, sub = ui.configsuboptions(b'paths', name) 2198 loc, sub = ui.configsuboptions(b'paths', name)
2198 self[name] = path(ui, name, rawloc=loc, suboptions=sub) 2199 sub_opts = base_sub_options.copy()
2200 sub_opts.update(sub)
2201 self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts)
2202 self._default_sub_opts = base_sub_options
2199 2203
2200 def getpath(self, ui, name, default=None): 2204 def getpath(self, ui, name, default=None):
2201 """Return a ``path`` from a string, falling back to default. 2205 """Return a ``path`` from a string, falling back to default.
2202 2206
2203 ``name`` can be a named path or locations. Locations are filesystem 2207 ``name`` can be a named path or locations. Locations are filesystem
2228 return self[name] 2232 return self[name]
2229 except KeyError: 2233 except KeyError:
2230 # Try to resolve as a local path or URI. 2234 # Try to resolve as a local path or URI.
2231 try: 2235 try:
2232 # we pass the ui instance are warning might need to be issued 2236 # we pass the ui instance are warning might need to be issued
2233 return path(ui, None, rawloc=name) 2237 return path(
2238 ui, None, rawloc=name, suboptions=self._default_sub_opts
2239 )
2234 except ValueError: 2240 except ValueError:
2235 raise error.RepoError(_(b'repository %s does not exist') % name) 2241 raise error.RepoError(_(b'repository %s does not exist') % name)
2236 2242
2237 2243
2238 _pathsuboptions = {} 2244 _pathsuboptions = {}