# HG changeset patch # User Jun Wu <qu...@fb.com> # Date 1496595729 25200 # Sun Jun 04 10:02:09 2017 -0700 # Node ID 985b38cca3131ca81a961ba4ab2006a3ef23ebb0 # Parent 69870e8f6bc97775c47d363efc5c58bce33239c0 # Available At https://bitbucket.org/quark-zju/hg-draft # hg pull https://bitbucket.org/quark-zju/hg-draft -r 985b38cca313 obsstore: let read marker API take a range of offsets
This allows us to read a customized range of markers, instead of loading all of them. The condition of stop is made consistent across C and Python implementation so we will still read marker when offset=a, stop=a+1. diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -179,8 +179,7 @@ usingsha256 = 2 _fm0fnodesize = _calcsize(_fm0node) -def _fm0readmarkers(data, off): +def _fm0readmarkers(data, off, stop): # Loop on markers - l = len(data) - while off + _fm0fsize <= l: + while off < stop: # read fixed part cur = data[off:off + _fm0fsize] @@ -318,5 +317,5 @@ def _fm0decodemeta(data): _fm1metapairsize = _calcsize('BB') -def _fm1purereadmarkers(data, off): +def _fm1purereadmarkers(data, off, stop): # make some global constants local for performance noneflag = _fm1parentnone @@ -332,8 +331,7 @@ def _fm1purereadmarkers(data, off): # Loop on markers - stop = len(data) - _fm1fsize ufixed = struct.Struct(_fm1fixed).unpack - while off <= stop: + while off < stop: # read fixed part o1 = off + fsize @@ -429,9 +427,8 @@ def _fm1encodeonemarker(marker): return ''.join(data) -def _fm1readmarkers(data, off): +def _fm1readmarkers(data, off, stop): native = getattr(parsers, 'fm1readmarkers', None) if not native: - return _fm1purereadmarkers(data, off) - stop = len(data) - _fm1fsize + return _fm1purereadmarkers(data, off, stop) return native(data, off, stop) @@ -445,12 +442,15 @@ def _readmarkerversion(data): @util.nogc -def _readmarkers(data): +def _readmarkers(data, off=None, stop=None): """Read and enumerate markers from raw data""" diskversion = _readmarkerversion(data) - off = 1 + if not off: + off = 1 # skip 1 byte version number + if stop is None: + stop = len(data) if diskversion not in formats: msg = _('parsing obsolete marker: unknown version %r') % diskversion raise error.UnknownVersion(msg, version=diskversion) - return diskversion, formats[diskversion][0](data, off) + return diskversion, formats[diskversion][0](data, off, stop) def encodeheader(version=_fm0version): _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel