changeset 33805:f913e90f15a0

httppeer: use peer interface This is similar to what we did to sshpeer. Quirks and all. Differential Revision: https://phab.mercurial-scm.org/D337
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Aug 2017 18:00:19 -0700
parents 1f8460b55986
children dedab036215d
files mercurial/httppeer.py
diffstat 1 files changed, 35 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httppeer.py	Sun Aug 06 17:59:48 2017 -0700
+++ b/mercurial/httppeer.py	Sun Aug 06 18:00:19 2017 -0700
@@ -21,6 +21,7 @@
     error,
     httpconnection,
     pycompat,
+    repository,
     statichttprepo,
     url,
     util,
@@ -86,7 +87,7 @@
 
     resp.__class__ = readerproxy
 
-class httppeer(wireproto.wirepeer):
+class httppeer(wireproto.wirepeer, repository.legacypeer):
     def __init__(self, ui, path):
         self._path = path
         self._caps = None
@@ -100,12 +101,15 @@
         # urllib cannot handle URLs with embedded user or passwd
         self._url, authinfo = u.authinfo()
 
-        self.ui = ui
-        self.ui.debug('using %s\n' % self._url)
+        self._ui = ui
+        ui.debug('using %s\n' % self._url)
 
         self._urlopener = url.opener(ui, authinfo)
         self._requestbuilder = urlreq.request
 
+        # TODO remove once peerrepository isn't in inheritance.
+        self._capabilities = self.capabilities
+
     def __del__(self):
         urlopener = getattr(self, '_urlopener', None)
         if urlopener:
@@ -113,15 +117,32 @@
                 h.close()
                 getattr(h, "close_all", lambda : None)()
 
+    # Begin of _basepeer interface.
+
+    @util.propertycache
+    def ui(self):
+        return self._ui
+
     def url(self):
         return self._path
 
-    # look up capabilities only when needed
+    def local(self):
+        return None
+
+    def peer(self):
+        return self
+
+    def canpush(self):
+        return True
 
-    def _fetchcaps(self):
-        self._caps = set(self._call('capabilities').split())
+    def close(self):
+        pass
 
-    def _capabilities(self):
+    # End of _basepeer interface.
+
+    # Begin of _basewirepeer interface.
+
+    def capabilities(self):
         if self._caps is None:
             try:
                 self._fetchcaps()
@@ -131,6 +152,13 @@
                           (' '.join(self._caps or ['none'])))
         return self._caps
 
+    # End of _basewirepeer interface.
+
+    # look up capabilities only when needed
+
+    def _fetchcaps(self):
+        self._caps = set(self._call('capabilities').split())
+
     def _callstream(self, cmd, _compressible=False, **args):
         if cmd == 'pushkey':
             args['data'] = ''