##// END OF EJS Templates
bundle2: read the whole bundle from stream on abort...
Pierre-Yves David -
r20892:6fe95448 default
parent child Browse files
Show More
@@ -130,8 +130,11 b' The matching of a part to its handler is'
130 part type is used to know if a part is mandatory or advisory. If the Part type
130 part type is used to know if a part is mandatory or advisory. If the Part type
131 contains any uppercase char it is considered mandatory. When no handler is
131 contains any uppercase char it is considered mandatory. When no handler is
132 known for a Mandatory part, the process is aborted and an exception is raised.
132 known for a Mandatory part, the process is aborted and an exception is raised.
133 If the part is advisory and no handler is known, the part is ignored.
133 If the part is advisory and no handler is known, the part is ignored. When the
134
134 process is aborted, the full bundle is still read from the stream to keep the
135 channel usable. But none of the part read from an abort are processed. In the
136 future, dropping the stream may become an option for channel we do not care to
137 preserve.
135 """
138 """
136
139
137 import util
140 import util
@@ -205,23 +208,29 b' def processbundle(repo, stream):'
205 # - replace this is a init function soon.
208 # - replace this is a init function soon.
206 # - exception catching
209 # - exception catching
207 unbundler.params
210 unbundler.params
208 for part in unbundler:
211 iterparts = iter(unbundler)
209 parttype = part.type
212 try:
210 # part key are matched lower case
213 for part in iterparts:
211 key = parttype.lower()
214 parttype = part.type
212 try:
215 # part key are matched lower case
213 handler = parthandlermapping[key]
216 key = parttype.lower()
214 ui.debug('found an handler for part %r\n' % parttype)
217 try:
215 except KeyError:
218 handler = parthandlermapping[key]
216 if key != parttype: # mandatory parts
219 ui.debug('found an handler for part %r\n' % parttype)
220 except KeyError:
221 if key != parttype: # mandatory parts
222 # todo:
223 # - use a more precise exception
224 raise
225 ui.debug('ignoring unknown advisory part %r\n' % key)
217 # todo:
226 # todo:
218 # - use a more precise exception
227 # - consume the part once we use streaming
219 # - consume the bundle2 stream anyway.
228 continue
220 raise
229 handler(repo, part)
221 ui.debug('ignoring unknown advisory part %r\n' % key)
230 except Exception:
222 # todo: consume the part (once we use streamed parts)
231 for part in iterparts:
223 continue
232 pass # consume the bundle content
224 handler(repo, part)
233 raise
225
234
226 class bundle20(object):
235 class bundle20(object):
227 """represent an outgoing bundle2 container
236 """represent an outgoing bundle2 container
@@ -72,9 +72,13 b' Create an extension to test bundle2 API'
72 > def cmdunbundle2(ui, repo):
72 > def cmdunbundle2(ui, repo):
73 > """process a bundle2 stream from stdin on the current repo"""
73 > """process a bundle2 stream from stdin on the current repo"""
74 > try:
74 > try:
75 > bundle2.processbundle(repo, sys.stdin)
75 > try:
76 > except KeyError, exc:
76 > bundle2.processbundle(repo, sys.stdin)
77 > raise util.Abort('missing support for %s' % exc)
77 > except KeyError, exc:
78 > raise util.Abort('missing support for %s' % exc)
79 > finally:
80 > remains = sys.stdin.read()
81 > ui.write('%i unread bytes\n' % len(remains))
78 >
82 >
79 > @command('statbundle2', [], '')
83 > @command('statbundle2', [], '')
80 > def cmdstatbundle2(ui, repo):
84 > def cmdstatbundle2(ui, repo):
@@ -385,6 +389,7 b' Process the bundle'
385 ignoring unknown advisory part 'test:math'
389 ignoring unknown advisory part 'test:math'
386 part header size: 0
390 part header size: 0
387 end of bundle2 stream
391 end of bundle2 stream
392 0 unread bytes
388
393
389
394
390 $ hg bundle2 --parts --unknown ../unknown.hg2
395 $ hg bundle2 --parts --unknown ../unknown.hg2
@@ -394,5 +399,6 b' Process the bundle'
394 Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
399 Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
395 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
400 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
396 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
401 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
402 0 unread bytes
397 abort: missing support for 'test:unknown'
403 abort: missing support for 'test:unknown'
398 [255]
404 [255]
General Comments 0
You need to be logged in to leave comments. Login now