changeset 49696:0acefbbcc82a

path: add a method to retrieve a "push variant" of a path This gets you the same path, but using the `pushurl` as destination. This opens the way for a lot of different improvements, the one which interests us is having `peer` objects aware of the `path` they came from.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 01 Dec 2022 01:32:24 +0100
parents dd62eb4d2ea5
children 1fae401b3b14
files mercurial/utils/urlutil.py
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/urlutil.py	Thu Dec 01 01:27:47 2022 +0100
+++ b/mercurial/utils/urlutil.py	Thu Dec 01 01:32:24 2022 +0100
@@ -867,6 +867,7 @@
         self.name = name
 
         # set by path variant to point to their "non-push" version
+        self.main_path = None
         self._setup_url(rawloc)
 
         if validate_path:
@@ -907,6 +908,26 @@
             new.__dict__[k] = v
         return new
 
+    @property
+    def is_push_variant(self):
+        """is this a path variant to be used for pushing"""
+        return self.main_path is not None
+
+    def get_push_variant(self):
+        """get a "copy" of the path, but suitable for pushing
+
+        This means using the value of the `pushurl` option (if any) as the url.
+
+        The original path is available in the `main_path` attribute.
+        """
+        if self.main_path:
+            return self
+        new = self.copy()
+        new.main_path = self
+        if self.pushloc:
+            new._setup_url(self.pushloc)
+        return new
+
     def _validate_path(self):
         # When given a raw location but not a symbolic name, validate the
         # location is valid.