peer-or-repo: build a repo directly in the `repo` function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 29 Nov 2022 22:21:19 +0100
changeset 49805 ebb5e38fdafc
parent 49804 c0acf5440fe1
child 49806 c4731eee1c8f
peer-or-repo: build a repo directly in the `repo` function We skip the ambiguous _peerorrepo function to explicitly build a repo within the dedicated function. The peer scheme are therefore no longer considered to build the object.
mercurial/hg.py
--- a/mercurial/hg.py	Tue Nov 29 22:04:23 2022 +0100
+++ b/mercurial/hg.py	Tue Nov 29 22:21:19 2022 +0100
@@ -231,19 +231,22 @@
     createopts=None,
 ):
     """return a repository object for the specified path"""
-    peer = _peerorrepo(
+    scheme = urlutil.url(path).scheme
+    if scheme is None:
+        scheme = b'file'
+    cls = repo_schemes.get(scheme)
+    if cls is None:
+        if scheme in peer_schemes:
+            raise error.Abort(_(b"repository '%s' is not local") % path)
+        cls = LocalFactory
+    repo = cls.instance(
         ui,
         path,
         create,
-        presetupfuncs=presetupfuncs,
         intents=intents,
         createopts=createopts,
     )
-    repo = peer.local()
-    if not repo:
-        raise error.Abort(
-            _(b"repository '%s' is not local") % (path or peer.url())
-        )
+    _setup_repo_or_peer(ui, repo, presetupfuncs=presetupfuncs)
     return repo.filtered(b'visible')