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.
--- 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):