Patchwork D10446: urlutil: extract `chain_path` in a function

login
register
mail settings
Submitter phabricator
Date April 16, 2021, 12:03 a.m.
Message ID <differential-rev-PHID-DREV-fv2b3ibzs52rhp6lm34c-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48763/
State New
Headers show

Comments

phabricator - April 16, 2021, 12:03 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This will no longer modify `path` inplace so it does not make much sense as a method.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10446

AFFECTED FILES
  mercurial/utils/urlutil.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py
+++ b/mercurial/utils/urlutil.py
@@ -611,7 +611,7 @@ 
             self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts)
 
         for name, p in sorted(self.items()):
-            p.chain_path(ui, self)
+            self[name] = _chain_path(p, ui, self)
 
     def getpath(self, ui, name, default=None):
         """Return a ``path`` from a string, falling back to default.
@@ -704,6 +704,33 @@ 
     return value
 
 
+def _chain_path(path, ui, paths):
+    """return the result of "path://" logic applied on a given path"""
+    if path.url.scheme == b'path':
+        assert path.url.path is None
+        subpath = paths.get(path.url.host)
+        if subpath is None:
+            m = _(b'cannot use `%s`, "%s" is not a known path')
+            m %= (path.rawloc, path.url.host)
+            raise error.Abort(m)
+        if subpath.raw_url.scheme == b'path':
+            m = _(b'cannot use `%s`, "%s" is also defined as a `path://`')
+            m %= (path.rawloc, path.url.host)
+            raise error.Abort(m)
+        path.url = subpath.url
+        path.rawloc = subpath.rawloc
+        path.loc = subpath.loc
+        if path.branch is None:
+            path.branch = subpath.branch
+        else:
+            base = path.rawloc.rsplit(b'#', 1)[0]
+            path.rawloc = b'%s#%s' % (base, path.branch)
+        suboptions = subpath._all_sub_opts.copy()
+        suboptions.update(path._own_sub_opts)
+        path._apply_suboptions(ui, suboptions)
+    return path
+
+
 class path(object):
     """Represents an individual path and its configuration."""
 
@@ -756,31 +783,6 @@ 
 
         self._apply_suboptions(ui, sub_opts)
 
-    def chain_path(self, ui, paths):
-        if self.url.scheme == b'path':
-            assert self.url.path is None
-            try:
-                subpath = paths[self.url.host]
-            except KeyError:
-                m = _(b'cannot use `%s`, "%s" is not a known path')
-                m %= (self.rawloc, self.url.host)
-                raise error.Abort(m)
-            if subpath.raw_url.scheme == b'path':
-                m = _(b'cannot use `%s`, "%s" is also defined 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
-            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 copy(self):
         """make a copy of this path object"""
         new = self.__class__()