##// 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 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,7 +208,9 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)
212 try:
213 for part in iterparts:
209 parttype = part.type
214 parttype = part.type
210 # part key are matched lower case
215 # part key are matched lower case
211 key = parttype.lower()
216 key = parttype.lower()
@@ -216,12 +221,16 def processbundle(repo, stream):
216 if key != parttype: # mandatory parts
221 if key != parttype: # mandatory parts
217 # todo:
222 # todo:
218 # - use a more precise exception
223 # - use a more precise exception
219 # - consume the bundle2 stream anyway.
220 raise
224 raise
221 ui.debug('ignoring unknown advisory part %r\n' % key)
225 ui.debug('ignoring unknown advisory part %r\n' % key)
222 # todo: consume the part (once we use streamed parts)
226 # todo:
227 # - consume the part once we use streaming
223 continue
228 continue
224 handler(repo, part)
229 handler(repo, part)
230 except Exception:
231 for part in iterparts:
232 pass # consume the bundle content
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 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 > try:
75 > bundle2.processbundle(repo, sys.stdin)
76 > bundle2.processbundle(repo, sys.stdin)
76 > except KeyError, exc:
77 > except KeyError, exc:
77 > raise util.Abort('missing support for %s' % 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 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 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