changeset 40171:dac438b7346e

httppeer: expose API descriptor on httpv2peer The API descriptor in wireprotov2 is much more expressive than space-delimited tokens and it will be difficult to define methods to query it in all of the ways we'll want to query it. So let's just declare defeat and expose the API descriptor on the peer instance. As part of this, we define a new interface for version 2 peers, fulfilling a TODO in the process. Differential Revision: https://phab.mercurial-scm.org/D4974
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 03 Oct 2018 13:07:28 -0700
parents f7ff5b4fe745
children 30f70d11c224
files mercurial/httppeer.py mercurial/repository.py tests/test-check-interfaces.py
diffstat 3 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httppeer.py	Thu Oct 11 09:26:05 2018 +0200
+++ b/mercurial/httppeer.py	Wed Oct 03 13:07:28 2018 -0700
@@ -744,14 +744,12 @@
         while handler.readdata(resp):
             pass
 
-# TODO implement interface for version 2 peers
-@interfaceutil.implementer(repository.ipeerconnection,
-                           repository.ipeercapabilities,
-                           repository.ipeerrequests)
+@interfaceutil.implementer(repository.ipeerv2)
 class httpv2peer(object):
     def __init__(self, ui, repourl, apipath, opener, requestbuilder,
                  apidescriptor):
         self.ui = ui
+        self.apidescriptor = apidescriptor
 
         if repourl.endswith('/'):
             repourl = repourl[:-1]
@@ -761,7 +759,6 @@
         self._apiurl = '%s/%s' % (repourl, apipath)
         self._opener = opener
         self._requestbuilder = requestbuilder
-        self._descriptor = apidescriptor
 
         self._redirect = wireprotov2peer.supportedredirects(ui, apidescriptor)
 
@@ -806,7 +803,7 @@
 
         # Alias command-* to presence of command of that name.
         if name.startswith('command-'):
-            return name[len('command-'):] in self._descriptor['commands']
+            return name[len('command-'):] in self.apidescriptor['commands']
 
         return False
 
@@ -826,7 +823,7 @@
 
     def commandexecutor(self):
         return httpv2executor(self.ui, self._opener, self._requestbuilder,
-                              self._apiurl, self._descriptor, self._redirect)
+                              self._apiurl, self.apidescriptor, self._redirect)
 
 # Registry of API service names to metadata about peers that handle it.
 #
--- a/mercurial/repository.py	Thu Oct 11 09:26:05 2018 +0200
+++ b/mercurial/repository.py	Wed Oct 03 13:07:28 2018 -0700
@@ -312,6 +312,12 @@
     All peer instances must conform to this interface.
     """
 
+class ipeerv2(ipeerconnection, ipeercapabilities, ipeerrequests):
+    """Unified peer interface for wire protocol version 2 peers."""
+
+    apidescriptor = interfaceutil.Attribute(
+        """Data structure holding description of server API.""")
+
 @interfaceutil.implementer(ipeerbase)
 class peer(object):
     """Base class for peer repositories."""
--- a/tests/test-check-interfaces.py	Thu Oct 11 09:26:05 2018 +0200
+++ b/tests/test-check-interfaces.py	Wed Oct 03 13:07:28 2018 -0700
@@ -106,10 +106,7 @@
     ziverify.verifyClass(repository.ipeerbase, httppeer.httppeer)
     checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None, None))
 
-    ziverify.verifyClass(repository.ipeerconnection,
-                         httppeer.httpv2peer)
-    ziverify.verifyClass(repository.ipeercapabilities,
-                         httppeer.httpv2peer)
+    ziverify.verifyClass(repository.ipeerv2, httppeer.httpv2peer)
     checkzobject(httppeer.httpv2peer(None, b'', b'', None, None, None))
 
     ziverify.verifyClass(repository.ipeerbase,