peer-or-repo: build a peer directly in the `peer` function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 29 Nov 2022 22:04:23 +0100
changeset 49691 c0acf5440fe1
parent 49690 c37287340c00
child 49692 ebb5e38fdafc
peer-or-repo: build a peer directly in the `peer` function We skip the ambiguous _peerorrepo function to explicitly build a peer within the dedicated function. This mean explicitly getting a peer from an explicitly create repository when necessary.
mercurial/hg.py
--- a/mercurial/hg.py	Tue Nov 29 22:03:10 2022 +0100
+++ b/mercurial/hg.py	Tue Nov 29 22:04:23 2022 +0100
@@ -250,9 +250,28 @@
 def peer(uiorrepo, opts, path, create=False, intents=None, createopts=None):
     '''return a repository peer for the specified path'''
     rui = remoteui(uiorrepo, opts)
-    return _peerorrepo(
-        rui, path, create, intents=intents, createopts=createopts
-    ).peer()
+    scheme = urlutil.url(path).scheme
+    if scheme in peer_schemes:
+        cls = peer_schemes[scheme]
+        peer = cls.instance(
+            rui,
+            path,
+            create,
+            intents=intents,
+            createopts=createopts,
+        )
+        _setup_repo_or_peer(rui, peer)
+    else:
+        # this is a repository
+        repo = repository(
+            rui,
+            path,
+            create,
+            intents=intents,
+            createopts=createopts,
+        )
+        peer = repo.peer()
+    return peer
 
 
 def defaultdest(source):