Patchwork D10261: path: extract the path validation logic into its own submethod

login
register
mail settings
Submitter phabricator
Date March 24, 2021, 8:52 a.m.
Message ID <differential-rev-PHID-DREV-7f2b3myt6uwtxfz4gcbk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48576/
State Superseded
Headers show

Comments

phabricator - March 24, 2021, 8:52 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We will need to re-use this logic for `path://` so we first extract it into its own method.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10261

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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