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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

marmoute (Pierre-Yves David)
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
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel