# HG changeset patch # User Gregory Szorc # Date 2018-10-03 20:07:28 # Node ID dac438b7346ee1becce5b26251b619fd8e1a906b # Parent f7ff5b4fe745369f24ac47fd0d758a57683b7557 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 diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -744,14 +744,12 @@ class httpv2executor(object): 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 @@ class httpv2peer(object): 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 @@ class httpv2peer(object): # 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 @@ class httpv2peer(object): 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. # diff --git a/mercurial/repository.py b/mercurial/repository.py --- a/mercurial/repository.py +++ b/mercurial/repository.py @@ -312,6 +312,12 @@ class ipeerbase(ipeerconnection, ipeerca 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.""" diff --git a/tests/test-check-interfaces.py b/tests/test-check-interfaces.py --- a/tests/test-check-interfaces.py +++ b/tests/test-check-interfaces.py @@ -106,10 +106,7 @@ def main(): 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,