# HG changeset patch # User Pierre-Yves David # Date 2022-12-01 00:32:24 # Node ID 0acefbbcc82a9122582eb545c30fee7503a46829 # Parent dd62eb4d2ea55bd85b093704664ddcb83620c4d8 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. diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py --- a/mercurial/utils/urlutil.py +++ b/mercurial/utils/urlutil.py @@ -867,6 +867,7 @@ class path: 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 @@ class path: 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.