Show More
@@ -240,9 +240,31 class unbundle20(object): | |||
|
240 | 240 | |
|
241 | 241 | def _readpart(self): |
|
242 | 242 | """return None when an end of stream markers is reach""" |
|
243 | headersize = self._readexact(2) | |
|
244 | assert headersize == '\0\0' | |
|
243 | ||
|
244 | headersize = self._unpack(_fpartheadersize)[0] | |
|
245 | self.ui.debug('part header size: %i\n' % headersize) | |
|
246 | if not headersize: | |
|
245 | 247 | return None |
|
248 | headerblock = self._readexact(headersize) | |
|
249 | # some utility to help reading from the header block | |
|
250 | self._offset = 0 # layer violation to have something easy to understand | |
|
251 | def fromheader(size): | |
|
252 | """return the next <size> byte from the header""" | |
|
253 | offset = self._offset | |
|
254 | data = headerblock[offset:(offset + size)] | |
|
255 | self._offset = offset + size | |
|
256 | return data | |
|
257 | typesize = _unpack(_fparttypesize, fromheader(1))[0] | |
|
258 | parttype = fromheader(typesize) | |
|
259 | self.ui.debug('part type: "%s"\n' % parttype) | |
|
260 | current = part(parttype) | |
|
261 | assert fromheader(2) == '\0\0' # no option for now | |
|
262 | del self._offset # clean up layer, nobody saw anything. | |
|
263 | self.ui.debug('part parameters: 0\n') | |
|
264 | assert self._readexact(4) == '\0\0\0\0' #empty payload | |
|
265 | self.ui.debug('payload chunk size: 0\n') | |
|
266 | return current | |
|
267 | ||
|
246 | 268 | |
|
247 | 269 | class part(object): |
|
248 | 270 | """A bundle2 part contains application level payload |
@@ -251,8 +273,9 class part(object): | |||
|
251 | 273 | handler. |
|
252 | 274 | """ |
|
253 | 275 | |
|
254 | def __init__(self, parttype): | |
|
276 | def __init__(self, parttype, data=''): | |
|
255 | 277 | self.type = parttype |
|
278 | self.data = data | |
|
256 | 279 | |
|
257 | 280 | def getchunks(self): |
|
258 | 281 | ### header |
@@ -60,6 +60,8 Create an extension to test bundle2 API | |||
|
60 | 60 | > ui.write(' %s\n' % value) |
|
61 | 61 | > parts = list(unbundler) |
|
62 | 62 | > ui.write('parts count: %i\n' % len(parts)) |
|
63 | > for p in parts: | |
|
64 | > ui.write(' :%s:\n' % p.type) | |
|
63 | 65 | > EOF |
|
64 | 66 | $ cat >> $HGRCPATH << EOF |
|
65 | 67 | > [extensions] |
@@ -206,6 +208,7 unbundling debug | |||
|
206 | 208 | babar%#==tutu |
|
207 | 209 | - simple |
|
208 | 210 | start extraction of bundle2 parts |
|
211 | part header size: 0 | |
|
209 | 212 | end of bundle2 stream |
|
210 | 213 | parts count: 0 |
|
211 | 214 | |
@@ -243,3 +246,27 Test part | |||
|
243 | 246 | test:empty\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc) |
|
244 | 247 | |
|
245 | 248 | |
|
249 | $ hg unbundle2 < ../parts.hg2 | |
|
250 | options count: 0 | |
|
251 | parts count: 2 | |
|
252 | :test:empty: | |
|
253 | :test:empty: | |
|
254 | ||
|
255 | $ hg unbundle2 --debug < ../parts.hg2 | |
|
256 | start processing of HG20 stream | |
|
257 | reading bundle2 stream parameters | |
|
258 | options count: 0 | |
|
259 | start extraction of bundle2 parts | |
|
260 | part header size: 13 | |
|
261 | part type: "test:empty" | |
|
262 | part parameters: 0 | |
|
263 | payload chunk size: 0 | |
|
264 | part header size: 13 | |
|
265 | part type: "test:empty" | |
|
266 | part parameters: 0 | |
|
267 | payload chunk size: 0 | |
|
268 | part header size: 0 | |
|
269 | end of bundle2 stream | |
|
270 | parts count: 2 | |
|
271 | :test:empty: | |
|
272 | :test:empty: |
General Comments 0
You need to be logged in to leave comments.
Login now