Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/urlutil.py @ 49808: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 |
comparison
equal
deleted
inserted
replaced
49807:dd62eb4d2ea5 | 49808:0acefbbcc82a |
---|---|
865 raise ValueError(b'rawloc must be defined') | 865 raise ValueError(b'rawloc must be defined') |
866 | 866 |
867 self.name = name | 867 self.name = name |
868 | 868 |
869 # set by path variant to point to their "non-push" version | 869 # set by path variant to point to their "non-push" version |
870 self.main_path = None | |
870 self._setup_url(rawloc) | 871 self._setup_url(rawloc) |
871 | 872 |
872 if validate_path: | 873 if validate_path: |
873 self._validate_path() | 874 self._validate_path() |
874 | 875 |
903 for k, v in self.__dict__.items(): | 904 for k, v in self.__dict__.items(): |
904 new_copy = getattr(v, 'copy', None) | 905 new_copy = getattr(v, 'copy', None) |
905 if new_copy is not None: | 906 if new_copy is not None: |
906 v = new_copy() | 907 v = new_copy() |
907 new.__dict__[k] = v | 908 new.__dict__[k] = v |
909 return new | |
910 | |
911 @property | |
912 def is_push_variant(self): | |
913 """is this a path variant to be used for pushing""" | |
914 return self.main_path is not None | |
915 | |
916 def get_push_variant(self): | |
917 """get a "copy" of the path, but suitable for pushing | |
918 | |
919 This means using the value of the `pushurl` option (if any) as the url. | |
920 | |
921 The original path is available in the `main_path` attribute. | |
922 """ | |
923 if self.main_path: | |
924 return self | |
925 new = self.copy() | |
926 new.main_path = self | |
927 if self.pushloc: | |
928 new._setup_url(self.pushloc) | |
908 return new | 929 return new |
909 | 930 |
910 def _validate_path(self): | 931 def _validate_path(self): |
911 # When given a raw location but not a symbolic name, validate the | 932 # When given a raw location but not a symbolic name, validate the |
912 # location is valid. | 933 # location is valid. |