comparison mercurial/wireproto.py @ 36535:1c16324fdf05

wireproto: use named arguments for commandentry We'll be adding more arguments in upcoming commits. Using named arguments will make the code easier to read. Differential Revision: https://phab.mercurial-scm.org/D2481
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 27 Feb 2018 14:21:29 -0800
parents 33c6f8f0388d
children abc3b9801563
comparison
equal deleted inserted replaced
36534:5faeabb07cf5 36535:1c16324fdf05
602 This is called when a caller using the old 2-tuple API attempts 602 This is called when a caller using the old 2-tuple API attempts
603 to replace an instance. The incoming values are merged with 603 to replace an instance. The incoming values are merged with
604 data not captured by the 2-tuple and a new instance containing 604 data not captured by the 2-tuple and a new instance containing
605 the union of the two objects is returned. 605 the union of the two objects is returned.
606 """ 606 """
607 return commandentry(func, args) 607 return commandentry(func, args=args)
608 608
609 # Old code treats instances as 2-tuples. So expose that interface. 609 # Old code treats instances as 2-tuples. So expose that interface.
610 def __iter__(self): 610 def __iter__(self):
611 yield self.func 611 yield self.func
612 yield self.args 612 yield self.args
638 # doing this aren't aware of the new API that uses objects to store 638 # doing this aren't aware of the new API that uses objects to store
639 # command entries, we automatically merge old state with new. 639 # command entries, we automatically merge old state with new.
640 if k in self: 640 if k in self:
641 v = self[k]._merge(v[0], v[1]) 641 v = self[k]._merge(v[0], v[1])
642 else: 642 else:
643 v = commandentry(v[0], v[1]) 643 v = commandentry(v[0], args=v[1])
644 else: 644 else:
645 raise ValueError('command entries must be commandentry instances ' 645 raise ValueError('command entries must be commandentry instances '
646 'or 2-tuples') 646 'or 2-tuples')
647 647
648 return super(commanddict, self).__setitem__(k, v) 648 return super(commanddict, self).__setitem__(k, v)
662 662
663 ``args`` is a space-delimited list of named arguments that the command 663 ``args`` is a space-delimited list of named arguments that the command
664 accepts. ``*`` is a special value that says to accept all arguments. 664 accepts. ``*`` is a special value that says to accept all arguments.
665 """ 665 """
666 def register(func): 666 def register(func):
667 commands[name] = commandentry(func, args) 667 commands[name] = commandentry(func, args=args)
668 return func 668 return func
669 return register 669 return register
670 670
671 @wireprotocommand('batch', 'cmds *') 671 @wireprotocommand('batch', 'cmds *')
672 def batch(repo, proto, cmds, others): 672 def batch(repo, proto, cmds, others):