changeset 47185:a2632ce1f15b

urlutil: add a `copy` method to `path This will be useful when inheriting from multiple path at the same time. Differential Revision: https://phab.mercurial-scm.org/D10445
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 15 Apr 2021 17:12:25 +0200
parents 9c4d30b079e0
children 26b3953ba1b0
files mercurial/utils/urlutil.py
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/urlutil.py	Thu Apr 15 12:33:05 2021 +0200
+++ b/mercurial/utils/urlutil.py	Thu Apr 15 17:12:25 2021 +0200
@@ -707,7 +707,7 @@
 class path(object):
     """Represents an individual path and its configuration."""
 
-    def __init__(self, ui, name, rawloc=None, suboptions=None):
+    def __init__(self, ui=None, name=None, rawloc=None, suboptions=None):
         """Construct a path from its config options.
 
         ``ui`` is the ``ui`` instance the path is coming from.
@@ -719,6 +719,13 @@
         filesystem path with a .hg directory or b) a URL. If not,
         ``ValueError`` is raised.
         """
+        if ui is None:
+            # used in copy
+            assert name is None
+            assert rawloc is None
+            assert suboptions is None
+            return
+
         if not rawloc:
             raise ValueError(b'rawloc must be defined')
 
@@ -774,6 +781,16 @@
             suboptions.update(self._own_sub_opts)
             self._apply_suboptions(ui, suboptions)
 
+    def copy(self):
+        """make a copy of this path object"""
+        new = self.__class__()
+        for k, v in self.__dict__.items():
+            new_copy = getattr(v, 'copy', None)
+            if new_copy is not None:
+                v = new_copy()
+            new.__dict__[k] = v
+        return new
+
     def _validate_path(self):
         # When given a raw location but not a symbolic name, validate the
         # location is valid.