comparison mercurial/ui.py @ 46826:83b0a5c0dfec

path: introduce a `path://` syntax to reference other path name This make it easier for a path to reuse the same location of another path with different parameter. This is useful to create path "alias" with common config option. This will become very useful to create path that reference a list of other path. This changeset focus on implemented the basic feature, future changesets will deal with various error management (and associated testing). Differential Revision: https://phab.mercurial-scm.org/D10263
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 18 Mar 2021 12:02:01 +0100
parents 4821cb414a5c
children 1ecf082386b7
comparison
equal deleted inserted replaced
46825:4821cb414a5c 46826:83b0a5c0dfec
2195 if not loc: 2195 if not loc:
2196 continue 2196 continue
2197 loc, sub_opts = ui.configsuboptions(b'paths', name) 2197 loc, sub_opts = ui.configsuboptions(b'paths', name)
2198 self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts) 2198 self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts)
2199 2199
2200 for name, p in sorted(self.items()):
2201 p.chain_path(ui, self)
2202
2200 def getpath(self, ui, name, default=None): 2203 def getpath(self, ui, name, default=None):
2201 """Return a ``path`` from a string, falling back to default. 2204 """Return a ``path`` from a string, falling back to default.
2202 2205
2203 ``name`` can be a named path or locations. Locations are filesystem 2206 ``name`` can be a named path or locations. Locations are filesystem
2204 paths or URIs. 2207 paths or URIs.
2328 self._own_sub_opts = suboptions.copy() 2331 self._own_sub_opts = suboptions.copy()
2329 sub_opts.update(suboptions) 2332 sub_opts.update(suboptions)
2330 self._all_sub_opts = sub_opts.copy() 2333 self._all_sub_opts = sub_opts.copy()
2331 2334
2332 self._apply_suboptions(ui, sub_opts) 2335 self._apply_suboptions(ui, sub_opts)
2336
2337 def chain_path(self, ui, paths):
2338 if self.url.scheme == b'path':
2339 assert self.url.path is None
2340 subpath = paths[self.url.host]
2341 self.url = subpath.url
2342 self.rawloc = subpath.rawloc
2343 self.loc = subpath.loc
2344 if self.branch is None:
2345 self.branch = subpath.branch
2346 else:
2347 base = self.rawloc.rsplit(b'#', 1)[0]
2348 self.rawloc = b'%s#%s' % (base, self.branch)
2349 suboptions = subpath._all_sub_opts.copy()
2350 suboptions.update(self._own_sub_opts)
2351 self._apply_suboptions(ui, suboptions)
2333 2352
2334 def _validate_path(self): 2353 def _validate_path(self):
2335 # When given a raw location but not a symbolic name, validate the 2354 # When given a raw location but not a symbolic name, validate the
2336 # location is valid. 2355 # location is valid.
2337 if ( 2356 if (