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
--- a/mercurial/ui.py Thu Mar 18 12:02:01 2021 +0100
+++ b/mercurial/ui.py Tue Mar 23 23:55:33 2021 +0100
@@ -2317,6 +2317,8 @@
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 @@
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
--- a/mercurial/util.py Thu Mar 18 12:02:01 2021 +0100
+++ b/mercurial/util.py Tue Mar 23 23:55:33 2021 +0100
@@ -3144,6 +3144,21 @@
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 = []
--- a/tests/test-paths.t Thu Mar 18 12:02:01 2021 +0100
+++ b/tests/test-paths.t Tue Mar 23 23:55:33 2021 +0100
@@ -334,3 +334,39 @@
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]