comparison mercurial/httppeer.py @ 37611:ae8730877371

httppeer: basic implementation of capabilities interface This is a bit crude. The capabilities mechanism for version 2 of the wire protocol is a bit different from version 1. And code in core is relying on strings passed to capable() matching strings advertised by the "capabilities" wire protocol command. I may refactor the internal checking mechanism to be a bit more abstract or based on interfaces. Time will tell... Differential Revision: https://phab.mercurial-scm.org/D3256
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 10 Apr 2018 19:09:35 -0700
parents 01bfe5ad0c53
children a81d02ea65db
comparison
equal deleted inserted replaced
37610:98861a2298b5 37611:ae8730877371
515 515
516 def _abort(self, exception): 516 def _abort(self, exception):
517 raise exception 517 raise exception
518 518
519 # TODO implement interface for version 2 peers 519 # TODO implement interface for version 2 peers
520 @zi.implementer(repository.ipeerconnection) 520 @zi.implementer(repository.ipeerconnection, repository.ipeercapabilities)
521 class httpv2peer(object): 521 class httpv2peer(object):
522 def __init__(self, ui, repourl, apipath, opener, requestbuilder, 522 def __init__(self, ui, repourl, apipath, opener, requestbuilder,
523 apidescriptor): 523 apidescriptor):
524 self.ui = ui 524 self.ui = ui
525 525
549 549
550 def close(self): 550 def close(self):
551 pass 551 pass
552 552
553 # End of ipeerconnection. 553 # End of ipeerconnection.
554
555 # Start of ipeercapabilities.
556
557 def capable(self, name):
558 # The capabilities used internally historically map to capabilities
559 # advertised from the "capabilities" wire protocol command. However,
560 # version 2 of that command works differently.
561
562 # Maps to commands that are available.
563 if name in ('branchmap', 'getbundle', 'known', 'lookup', 'pushkey'):
564 return True
565
566 # Other concepts.
567 if name in ('bundle2',):
568 return True
569
570 return False
571
572 def requirecap(self, name, purpose):
573 if self.capable(name):
574 return
575
576 raise error.CapabilityError(
577 _('cannot %s; client or remote repository does not support the %r '
578 'capability') % (purpose, name))
579
580 # End of ipeercapabilities.
554 581
555 # TODO require to be part of a batched primitive, use futures. 582 # TODO require to be part of a batched primitive, use futures.
556 def _call(self, name, **args): 583 def _call(self, name, **args):
557 """Call a wire protocol command with arguments.""" 584 """Call a wire protocol command with arguments."""
558 585