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

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Wed Mar 24 08:52:33 UTC 2021


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

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



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


More information about the Mercurial-devel mailing list