Mercurial > hg
comparison mercurial/bundle2.py @ 21624:d61066d787c8
bundle2: declare supported parameters for all handlers
We now update all existing handlers with the supported parameters information.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 28 May 2014 11:40:07 -0700 |
parents | 5b26d82e4e2a |
children | 511f5fa63aa2 |
comparison
equal
deleted
inserted
replaced
21623:5b26d82e4e2a | 21624:d61066d787c8 |
---|---|
177 def parthandler(parttype, params=()): | 177 def parthandler(parttype, params=()): |
178 """decorator that register a function as a bundle2 part handler | 178 """decorator that register a function as a bundle2 part handler |
179 | 179 |
180 eg:: | 180 eg:: |
181 | 181 |
182 @parthandler('myparttype') | 182 @parthandler('myparttype', ('mandatory', 'param', 'handled')) |
183 def myparttypehandler(...): | 183 def myparttypehandler(...): |
184 '''process a part of type "my part".''' | 184 '''process a part of type "my part".''' |
185 ... | 185 ... |
186 """ | 186 """ |
187 def _decorator(func): | 187 def _decorator(func): |
785 part = op.reply.newpart('b2x:reply:changegroup') | 785 part = op.reply.newpart('b2x:reply:changegroup') |
786 part.addparam('in-reply-to', str(inpart.id), mandatory=False) | 786 part.addparam('in-reply-to', str(inpart.id), mandatory=False) |
787 part.addparam('return', '%i' % ret, mandatory=False) | 787 part.addparam('return', '%i' % ret, mandatory=False) |
788 assert not inpart.read() | 788 assert not inpart.read() |
789 | 789 |
790 @parthandler('b2x:reply:changegroup') | 790 @parthandler('b2x:reply:changegroup', ('return', 'in-reply-to')) |
791 def handlechangegroup(op, inpart): | 791 def handlechangegroup(op, inpart): |
792 ret = int(inpart.params['return']) | 792 ret = int(inpart.params['return']) |
793 replyto = int(inpart.params['in-reply-to']) | 793 replyto = int(inpart.params['in-reply-to']) |
794 op.records.add('changegroup', {'return': ret}, replyto) | 794 op.records.add('changegroup', {'return': ret}, replyto) |
795 | 795 |
822 The payload contains the capabilities information for the reply""" | 822 The payload contains the capabilities information for the reply""" |
823 caps = decodecaps(inpart.read()) | 823 caps = decodecaps(inpart.read()) |
824 if op.reply is None: | 824 if op.reply is None: |
825 op.reply = bundle20(op.ui, caps) | 825 op.reply = bundle20(op.ui, caps) |
826 | 826 |
827 @parthandler('b2x:error:abort') | 827 @parthandler('b2x:error:abort', ('message', 'hint')) |
828 def handlereplycaps(op, inpart): | 828 def handlereplycaps(op, inpart): |
829 """Used to transmit abort error over the wire""" | 829 """Used to transmit abort error over the wire""" |
830 raise util.Abort(inpart.params['message'], hint=inpart.params.get('hint')) | 830 raise util.Abort(inpart.params['message'], hint=inpart.params.get('hint')) |
831 | 831 |
832 @parthandler('b2x:error:unsupportedcontent') | 832 @parthandler('b2x:error:unsupportedcontent', ('parttype', 'params')) |
833 def handlereplycaps(op, inpart): | 833 def handlereplycaps(op, inpart): |
834 """Used to transmit unknown content error over the wire""" | 834 """Used to transmit unknown content error over the wire""" |
835 kwargs = {} | 835 kwargs = {} |
836 kwargs['parttype'] = inpart.params['parttype'] | 836 kwargs['parttype'] = inpart.params['parttype'] |
837 params = inpart.params.get('params') | 837 params = inpart.params.get('params') |