Patchwork D3256: httppeer: basic implementation of capabilities interface

login
register
mail settings
Submitter phabricator
Date April 12, 2018, 10:23 p.m.
Message ID <1f532a84c587c0a7a90dcbd4d556a984@localhost.localdomain>
Download mbox | patch
Permalink /patch/30839/
State Not Applicable
Headers show

Comments

phabricator - April 12, 2018, 10:23 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGae8730877371: httppeer: basic implementation of capabilities interface (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3256?vs=8022&id=8097

REVISION DETAIL
  https://phab.mercurial-scm.org/D3256

AFFECTED FILES
  mercurial/httppeer.py
  tests/test-check-interfaces.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

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
@@ -94,6 +94,8 @@ 
 
     ziverify.verifyClass(repository.ipeerconnection,
                          httppeer.httpv2peer)
+    ziverify.verifyClass(repository.ipeercapabilities,
+                         httppeer.httpv2peer)
     checkzobject(httppeer.httpv2peer(None, '', None, None, None, None))
 
     ziverify.verifyClass(repository.ipeerbase,
diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -517,7 +517,7 @@ 
         raise exception
 
 # TODO implement interface for version 2 peers
-@zi.implementer(repository.ipeerconnection)
+@zi.implementer(repository.ipeerconnection, repository.ipeercapabilities)
 class httpv2peer(object):
     def __init__(self, ui, repourl, apipath, opener, requestbuilder,
                  apidescriptor):
@@ -552,6 +552,33 @@ 
 
     # End of ipeerconnection.
 
+    # Start of ipeercapabilities.
+
+    def capable(self, name):
+        # The capabilities used internally historically map to capabilities
+        # advertised from the "capabilities" wire protocol command. However,
+        # version 2 of that command works differently.
+
+        # Maps to commands that are available.
+        if name in ('branchmap', 'getbundle', 'known', 'lookup', 'pushkey'):
+            return True
+
+        # Other concepts.
+        if name in ('bundle2',):
+            return True
+
+        return False
+
+    def requirecap(self, name, purpose):
+        if self.capable(name):
+            return
+
+        raise error.CapabilityError(
+            _('cannot %s; client or remote repository does not support the %r '
+              'capability') % (purpose, name))
+
+    # End of ipeercapabilities.
+
     # TODO require to be part of a batched primitive, use futures.
     def _call(self, name, **args):
         """Call a wire protocol command with arguments."""