path: extract the path validation logic into its own submethod
We will need to re-use this logic for `path://` so we first extract it into its own method.
Differential Revision: https://phab.mercurial-scm.org/D10261
--- a/mercurial/ui.py Thu Mar 18 10:12:55 2021 +0100
+++ b/mercurial/ui.py Sun Mar 21 17:52:15 2021 +0100
@@ -2320,13 +2320,7 @@
self.rawloc = rawloc
self.loc = b'%s' % u
- # When given a raw location but not a symbolic name, validate the
- # location is valid.
- if not name and not u.scheme and not self._isvalidlocalpath(self.loc):
- raise ValueError(
- b'location is not a URL or path to a local '
- b'repo: %s' % rawloc
- )
+ self._validate_path()
_path, sub_opts = ui.configsuboptions(b'paths', b'*')
if suboptions is not None:
@@ -2343,6 +2337,19 @@
value = func(ui, self, sub_opts[suboption])
setattr(self, attr, value)
+ def _validate_path(self):
+ # When given a raw location but not a symbolic name, validate the
+ # location is valid.
+ if (
+ not self.name
+ and not self.url.scheme
+ and not self._isvalidlocalpath(self.loc)
+ ):
+ raise ValueError(
+ b'location is not a URL or path to a local '
+ b'repo: %s' % self.rawloc
+ )
+
def _isvalidlocalpath(self, path):
"""Returns True if the given path is a potentially valid repository.
This is its own function so that extensions can change the definition of