##// END OF EJS Templates
bundle2.bundlepart: make mandatory part flag explicit in API...
Eric Sumner -
r23590:4440c7cc default
parent child Browse files
Show More
@@ -350,7 +350,8 b' def _processpart(op, part):'
350 if output is not None:
350 if output is not None:
351 output = op.ui.popbuffer()
351 output = op.ui.popbuffer()
352 if output:
352 if output:
353 outpart = op.reply.newpart('b2x:output', data=output)
353 outpart = op.reply.newpart('b2x:output', data=output,
354 mandatory=False)
354 outpart.addparam('in-reply-to', str(part.id), mandatory=False)
355 outpart.addparam('in-reply-to', str(part.id), mandatory=False)
355 finally:
356 finally:
356 # consume the part content to not corrupt the stream.
357 # consume the part content to not corrupt the stream.
@@ -588,7 +589,7 b' class bundlepart(object):'
588 """
589 """
589
590
590 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
591 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
591 data=''):
592 data='', mandatory=True):
592 self.id = None
593 self.id = None
593 self.type = parttype
594 self.type = parttype
594 self._data = data
595 self._data = data
@@ -605,6 +606,7 b' class bundlepart(object):'
605 # - False: currently generated,
606 # - False: currently generated,
606 # - True: generation done.
607 # - True: generation done.
607 self._generated = None
608 self._generated = None
609 self.mandatory = mandatory
608
610
609 # methods used to defines the part content
611 # methods used to defines the part content
610 def __setdata(self, data):
612 def __setdata(self, data):
@@ -642,9 +644,13 b' class bundlepart(object):'
642 raise RuntimeError('part can only be consumed once')
644 raise RuntimeError('part can only be consumed once')
643 self._generated = False
645 self._generated = False
644 #### header
646 #### header
647 if self.mandatory:
648 parttype = self.type.upper()
649 else:
650 parttype = self.type.lower()
645 ## parttype
651 ## parttype
646 header = [_pack(_fparttypesize, len(self.type)),
652 header = [_pack(_fparttypesize, len(parttype)),
647 self.type, _pack(_fpartid, self.id),
653 parttype, _pack(_fpartid, self.id),
648 ]
654 ]
649 ## parameters
655 ## parameters
650 # count
656 # count
@@ -681,7 +687,8 b' class bundlepart(object):'
681 # backup exception data for later
687 # backup exception data for later
682 exc_info = sys.exc_info()
688 exc_info = sys.exc_info()
683 msg = 'unexpected error: %s' % exc
689 msg = 'unexpected error: %s' % exc
684 interpart = bundlepart('b2x:error:abort', [('message', msg)])
690 interpart = bundlepart('b2x:error:abort', [('message', msg)],
691 mandatory=False)
685 interpart.id = 0
692 interpart.id = 0
686 yield _pack(_fpayloadsize, -1)
693 yield _pack(_fpayloadsize, -1)
687 for chunk in interpart.getchunks():
694 for chunk in interpart.getchunks():
@@ -930,7 +937,7 b' def handlechangegroup(op, inpart):'
930 if op.reply is not None:
937 if op.reply is not None:
931 # This is definitely not the final form of this
938 # This is definitely not the final form of this
932 # return. But one need to start somewhere.
939 # return. But one need to start somewhere.
933 part = op.reply.newpart('b2x:reply:changegroup')
940 part = op.reply.newpart('b2x:reply:changegroup', mandatory=False)
934 part.addparam('in-reply-to', str(inpart.id), mandatory=False)
941 part.addparam('in-reply-to', str(inpart.id), mandatory=False)
935 part.addparam('return', '%i' % ret, mandatory=False)
942 part.addparam('return', '%i' % ret, mandatory=False)
936 assert not inpart.read()
943 assert not inpart.read()
@@ -55,7 +55,8 b' Create an extension to test bundle2 API'
55 > op.ui.write('received ping request (id %i)\n' % part.id)
55 > op.ui.write('received ping request (id %i)\n' % part.id)
56 > if op.reply is not None and 'ping-pong' in op.reply.capabilities:
56 > if op.reply is not None and 'ping-pong' in op.reply.capabilities:
57 > op.ui.write_err('replying to ping request (id %i)\n' % part.id)
57 > op.ui.write_err('replying to ping request (id %i)\n' % part.id)
58 > op.reply.newpart('test:pong', [('in-reply-to', str(part.id))])
58 > op.reply.newpart('test:pong', [('in-reply-to', str(part.id))],
59 > mandatory=False)
59 >
60 >
60 > @bundle2.parthandler('test:debugreply')
61 > @bundle2.parthandler('test:debugreply')
61 > def debugreply(op, part):
62 > def debugreply(op, part):
@@ -108,32 +109,34 b' Create an extension to test bundle2 API'
108 > headcommon = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)]
109 > headcommon = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)]
109 > outgoing = discovery.outgoing(repo.changelog, headcommon, headmissing)
110 > outgoing = discovery.outgoing(repo.changelog, headcommon, headmissing)
110 > cg = changegroup.getlocalchangegroup(repo, 'test:bundle2', outgoing, None)
111 > cg = changegroup.getlocalchangegroup(repo, 'test:bundle2', outgoing, None)
111 > bundler.newpart('b2x:changegroup', data=cg.getchunks())
112 > bundler.newpart('b2x:changegroup', data=cg.getchunks(),
113 > mandatory=False)
112 >
114 >
113 > if opts['parts']:
115 > if opts['parts']:
114 > bundler.newpart('test:empty')
116 > bundler.newpart('test:empty', mandatory=False)
115 > # add a second one to make sure we handle multiple parts
117 > # add a second one to make sure we handle multiple parts
116 > bundler.newpart('test:empty')
118 > bundler.newpart('test:empty', mandatory=False)
117 > bundler.newpart('test:song', data=ELEPHANTSSONG)
119 > bundler.newpart('test:song', data=ELEPHANTSSONG, mandatory=False)
118 > bundler.newpart('test:debugreply')
120 > bundler.newpart('test:debugreply', mandatory=False)
119 > mathpart = bundler.newpart('test:math')
121 > mathpart = bundler.newpart('test:math')
120 > mathpart.addparam('pi', '3.14')
122 > mathpart.addparam('pi', '3.14')
121 > mathpart.addparam('e', '2.72')
123 > mathpart.addparam('e', '2.72')
122 > mathpart.addparam('cooking', 'raw', mandatory=False)
124 > mathpart.addparam('cooking', 'raw', mandatory=False)
123 > mathpart.data = '42'
125 > mathpart.data = '42'
126 > mathpart.mandatory = False
124 > # advisory known part with unknown mandatory param
127 > # advisory known part with unknown mandatory param
125 > bundler.newpart('test:song', [('randomparam','')])
128 > bundler.newpart('test:song', [('randomparam','')], mandatory=False)
126 > if opts['unknown']:
129 > if opts['unknown']:
127 > bundler.newpart('test:UNKNOWN', data='some random content')
130 > bundler.newpart('test:UNKNOWN', data='some random content')
128 > if opts['unknownparams']:
131 > if opts['unknownparams']:
129 > bundler.newpart('test:SONG', [('randomparams', '')])
132 > bundler.newpart('test:SONG', [('randomparams', '')])
130 > if opts['parts']:
133 > if opts['parts']:
131 > bundler.newpart('test:ping')
134 > bundler.newpart('test:ping', mandatory=False)
132 > if opts['genraise']:
135 > if opts['genraise']:
133 > def genraise():
136 > def genraise():
134 > yield 'first line\n'
137 > yield 'first line\n'
135 > raise RuntimeError('Someone set up us the bomb!')
138 > raise RuntimeError('Someone set up us the bomb!')
136 > bundler.newpart('b2x:output', data=genraise())
139 > bundler.newpart('b2x:output', data=genraise(), mandatory=False)
137 >
140 >
138 > if path is None:
141 > if path is None:
139 > file = sys.stdout
142 > file = sys.stdout
General Comments 0
You need to be logged in to leave comments. Login now