changeset 49750:f075a9463ee7

peer: use a dedicated name for the `peer` constructor We want to change the argument it takes, so we rather make them different function.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 02 Dec 2022 18:04:51 +0100
parents be3fcd9e5e52
children a6e2a668c746
files hgext/schemes.py mercurial/hg.py mercurial/httppeer.py mercurial/sshpeer.py mercurial/statichttprepo.py
diffstat 5 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/schemes.py	Fri Dec 02 18:04:37 2022 +0100
+++ b/hgext/schemes.py	Fri Dec 02 18:04:51 2022 +0100
@@ -80,6 +80,15 @@
     def __repr__(self):
         return b'<ShortRepository: %s>' % self.scheme
 
+    def make_peer(self, ui, url, *args, **kwargs):
+        url = self.resolve(url)
+        u = urlutil.url(url)
+        scheme = u.scheme or b'file'
+        cls = hg.peer_schemes.get(scheme)
+        if cls is not None:
+            return cls.make_peer(ui, url, *args, **kwargs)
+        return None
+
     def instance(self, ui, url, create, intents=None, createopts=None):
         url = self.resolve(url)
         u = urlutil.url(url)
--- a/mercurial/hg.py	Fri Dec 02 18:04:37 2022 +0100
+++ b/mercurial/hg.py	Fri Dec 02 18:04:51 2022 +0100
@@ -168,11 +168,12 @@
         scheme = u.scheme or b'file'
         if scheme in peer_schemes:
             cls = peer_schemes[scheme]
+            cls.make_peer  # make sure we load the module
         elif scheme in repo_schemes:
             cls = repo_schemes[scheme]
+            cls.instance  # make sure we load the module
         else:
             cls = LocalFactory
-        cls.instance  # make sure we load the module
         if util.safehasattr(cls, 'islocal'):
             return cls.islocal(repo)  # pytype: disable=module-attr
         return False
@@ -253,7 +254,7 @@
         scheme = urlutil.url(path).scheme
     if scheme in peer_schemes:
         cls = peer_schemes[scheme]
-        peer = cls.instance(
+        peer = cls.make_peer(
             rui,
             path,
             create,
--- a/mercurial/httppeer.py	Fri Dec 02 18:04:37 2022 +0100
+++ b/mercurial/httppeer.py	Fri Dec 02 18:04:51 2022 +0100
@@ -621,7 +621,7 @@
     )
 
 
-def instance(ui, path, create, intents=None, createopts=None):
+def make_peer(ui, path, create, intents=None, createopts=None):
     if create:
         raise error.Abort(_(b'cannot create new http repository'))
     try:
@@ -635,7 +635,7 @@
         return inst
     except error.RepoError as httpexception:
         try:
-            r = statichttprepo.instance(ui, b"static-" + path, create)
+            r = statichttprepo.make_peer(ui, b"static-" + path, create)
             ui.note(_(b'(falling back to static-http)\n'))
             return r
         except error.RepoError:
--- a/mercurial/sshpeer.py	Fri Dec 02 18:04:37 2022 +0100
+++ b/mercurial/sshpeer.py	Fri Dec 02 18:04:51 2022 +0100
@@ -607,7 +607,7 @@
         )
 
 
-def instance(ui, path, create, intents=None, createopts=None):
+def make_peer(ui, path, create, intents=None, createopts=None):
     """Create an SSH peer.
 
     The returned object conforms to the ``wireprotov1peer.wirepeer`` interface.
--- a/mercurial/statichttprepo.py	Fri Dec 02 18:04:37 2022 +0100
+++ b/mercurial/statichttprepo.py	Fri Dec 02 18:04:51 2022 +0100
@@ -259,7 +259,7 @@
         pass  # statichttprepository are read only
 
 
-def instance(ui, path, create, intents=None, createopts=None):
+def make_peer(ui, path, create, intents=None, createopts=None):
     if create:
         raise error.Abort(_(b'cannot create new static-http repository'))
     return statichttprepository(ui, path[7:]).peer()