# HG changeset patch # User Pierre-Yves David # Date 2021-03-23 22:55:33 # Node ID 1ecf082386b707d80d06caba6a9d3e75bdbe43b5 # Parent 83b0a5c0dfec1509edf6b450a1c8c03bbe057f14 path: forbid chaining `path://` definitions To have `path://xxx` referencing paths that use `path://` too, we need to analyze dependencies to initialize them in the right order (and to detect cycle). I don't want to deal with that right now, so I just disallow it for now. Differential Revision: https://phab.mercurial-scm.org/D10264 diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -2317,6 +2317,8 @@ class path(object): u.fragment = None self.url = u + # the url from the config/command line before dealing with `path://` + self.raw_url = u.copy() self.branch = branch self.name = name @@ -2338,6 +2340,10 @@ class path(object): if self.url.scheme == b'path': assert self.url.path is None subpath = paths[self.url.host] + if subpath.raw_url.scheme == b'path': + m = _('cannot use `%s`, "%s" is also define as a `path://`') + m %= (self.rawloc, self.url.host) + raise error.Abort(m) self.url = subpath.url self.rawloc = subpath.rawloc self.loc = subpath.loc diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -3144,6 +3144,21 @@ class url(object): if v is not None: setattr(self, a, urlreq.unquote(v)) + def copy(self): + u = url(b'temporary useless value') + u.path = self.path + u.scheme = self.scheme + u.user = self.user + u.passwd = self.passwd + u.host = self.host + u.path = self.path + u.query = self.query + u.fragment = self.fragment + u._localpath = self._localpath + u._hostport = self._hostport + u._origpath = self._origpath + return u + @encoding.strmethod def __repr__(self): attrs = [] diff --git a/tests/test-paths.t b/tests/test-paths.t --- a/tests/test-paths.t +++ b/tests/test-paths.t @@ -334,3 +334,39 @@ test inheritance of the suboptions adding manifests adding file changes added 5 changesets with 0 changes to 0 files (+1 heads) + +Test chaining path:// definition +-------------------------------- + +This is currently unsupported, but feel free to implement the necessary +dependency detection. + + $ cat << EOF >> .hg/hgrc + > chain_path=path://other_default + > EOF + + $ hg id + 000000000000 + $ hg path + abort: cannot use `path://other_default`, "other_default" is also define as a `path://` + [255] + $ hg pull chain_path + abort: cannot use `path://other_default`, "other_default" is also define as a `path://` + [255] + +Doing an actual circle should always be an issue + + $ cat << EOF >> .hg/hgrc + > rock=path://cissors + > cissors=path://paper + > paper=://rock + > EOF + + $ hg id + 000000000000 + $ hg path + abort: cannot use `path://other_default`, "other_default" is also define as a `path://` + [255] + $ hg pull chain_path + abort: cannot use `path://other_default`, "other_default" is also define as a `path://` + [255]