# HG changeset patch # User Pierre-Yves David # Date 1616065321 -3600 # Node ID 83b0a5c0dfec1509edf6b450a1c8c03bbe057f14 # Parent 4821cb414a5c982876293cb6f41f98fc9473972a 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 diff -r 4821cb414a5c -r 83b0a5c0dfec mercurial/ui.py --- a/mercurial/ui.py Sun Mar 21 16:31:42 2021 +0100 +++ b/mercurial/ui.py Thu Mar 18 12:02:01 2021 +0100 @@ -2197,6 +2197,9 @@ loc, sub_opts = ui.configsuboptions(b'paths', name) self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts) + for name, p in sorted(self.items()): + p.chain_path(ui, self) + def getpath(self, ui, name, default=None): """Return a ``path`` from a string, falling back to default. @@ -2331,6 +2334,22 @@ self._apply_suboptions(ui, sub_opts) + def chain_path(self, ui, paths): + if self.url.scheme == b'path': + assert self.url.path is None + subpath = paths[self.url.host] + self.url = subpath.url + self.rawloc = subpath.rawloc + self.loc = subpath.loc + if self.branch is None: + self.branch = subpath.branch + else: + base = self.rawloc.rsplit(b'#', 1)[0] + self.rawloc = b'%s#%s' % (base, self.branch) + suboptions = subpath._all_sub_opts.copy() + suboptions.update(self._own_sub_opts) + self._apply_suboptions(ui, suboptions) + def _validate_path(self): # When given a raw location but not a symbolic name, validate the # location is valid. diff -r 4821cb414a5c -r 83b0a5c0dfec tests/test-paths.t --- a/tests/test-paths.t Sun Mar 21 16:31:42 2021 +0100 +++ b/tests/test-paths.t Thu Mar 18 12:02:01 2021 +0100 @@ -211,3 +211,126 @@ 000000000000 $ cd .. + +Testing path referencing other paths +==================================== + +basic setup +----------- + + $ ls -1 + a + b + gpath1 + suboptions + $ hg init chained_path + $ cd chained_path + $ cat << EOF > .hg/hgrc + > [paths] + > default=../a + > other_default=path://default + > path_with_branch=../branchy#foo + > other_branch=path://path_with_branch + > other_branched=path://path_with_branch#default + > pushdest=../push-dest + > pushdest:pushrev=default + > pushdest2=path://pushdest + > pushdest-overwrite=path://pushdest + > pushdest-overwrite:pushrev=foo + > EOF + + $ hg init ../branchy + $ hg init ../push-dest + $ hg debugbuilddag -R ../branchy '.:base+3