##// END OF EJS Templates
obsstore: let read marker API take a range of offsets...
Jun Wu -
r33504:5d3ba439 default
parent child Browse files
Show More
@@ -178,10 +178,9 b' usingsha256 = 2'
178 _fm0fsize = _calcsize(_fm0fixed)
178 _fm0fsize = _calcsize(_fm0fixed)
179 _fm0fnodesize = _calcsize(_fm0node)
179 _fm0fnodesize = _calcsize(_fm0node)
180
180
181 def _fm0readmarkers(data, off):
181 def _fm0readmarkers(data, off, stop):
182 # Loop on markers
182 # Loop on markers
183 l = len(data)
183 while off < stop:
184 while off + _fm0fsize <= l:
185 # read fixed part
184 # read fixed part
186 cur = data[off:off + _fm0fsize]
185 cur = data[off:off + _fm0fsize]
187 off += _fm0fsize
186 off += _fm0fsize
@@ -317,7 +316,7 b' def _fm0decodemeta(data):'
317 _fm1metapair = 'BB'
316 _fm1metapair = 'BB'
318 _fm1metapairsize = _calcsize('BB')
317 _fm1metapairsize = _calcsize('BB')
319
318
320 def _fm1purereadmarkers(data, off):
319 def _fm1purereadmarkers(data, off, stop):
321 # make some global constants local for performance
320 # make some global constants local for performance
322 noneflag = _fm1parentnone
321 noneflag = _fm1parentnone
323 sha2flag = usingsha256
322 sha2flag = usingsha256
@@ -331,10 +330,9 b' def _fm1purereadmarkers(data, off):'
331 unpack = _unpack
330 unpack = _unpack
332
331
333 # Loop on markers
332 # Loop on markers
334 stop = len(data) - _fm1fsize
335 ufixed = struct.Struct(_fm1fixed).unpack
333 ufixed = struct.Struct(_fm1fixed).unpack
336
334
337 while off <= stop:
335 while off < stop:
338 # read fixed part
336 # read fixed part
339 o1 = off + fsize
337 o1 = off + fsize
340 t, secs, tz, flags, numsuc, numpar, nummeta, prec = ufixed(data[off:o1])
338 t, secs, tz, flags, numsuc, numpar, nummeta, prec = ufixed(data[off:o1])
@@ -428,11 +426,10 b' def _fm1encodeonemarker(marker):'
428 data.append(value)
426 data.append(value)
429 return ''.join(data)
427 return ''.join(data)
430
428
431 def _fm1readmarkers(data, off):
429 def _fm1readmarkers(data, off, stop):
432 native = getattr(parsers, 'fm1readmarkers', None)
430 native = getattr(parsers, 'fm1readmarkers', None)
433 if not native:
431 if not native:
434 return _fm1purereadmarkers(data, off)
432 return _fm1purereadmarkers(data, off, stop)
435 stop = len(data) - _fm1fsize
436 return native(data, off, stop)
433 return native(data, off, stop)
437
434
438 # mapping to read/write various marker formats
435 # mapping to read/write various marker formats
@@ -444,14 +441,17 b' def _readmarkerversion(data):'
444 return _unpack('>B', data[0:1])[0]
441 return _unpack('>B', data[0:1])[0]
445
442
446 @util.nogc
443 @util.nogc
447 def _readmarkers(data):
444 def _readmarkers(data, off=None, stop=None):
448 """Read and enumerate markers from raw data"""
445 """Read and enumerate markers from raw data"""
449 diskversion = _readmarkerversion(data)
446 diskversion = _readmarkerversion(data)
450 off = 1
447 if not off:
448 off = 1 # skip 1 byte version number
449 if stop is None:
450 stop = len(data)
451 if diskversion not in formats:
451 if diskversion not in formats:
452 msg = _('parsing obsolete marker: unknown version %r') % diskversion
452 msg = _('parsing obsolete marker: unknown version %r') % diskversion
453 raise error.UnknownVersion(msg, version=diskversion)
453 raise error.UnknownVersion(msg, version=diskversion)
454 return diskversion, formats[diskversion][0](data, off)
454 return diskversion, formats[diskversion][0](data, off, stop)
455
455
456 def encodeheader(version=_fm0version):
456 def encodeheader(version=_fm0version):
457 return _pack('>B', version)
457 return _pack('>B', version)
General Comments 0
You need to be logged in to leave comments. Login now