Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/sidedata.py @ 43034:294afb982a88
sidedata: add a function to read sidedata from revlog raw text
This implement the "reading" part of a `sidedata` flag processor.
Differential Revision: https://phab.mercurial-scm.org/D6890
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 04 Sep 2019 00:59:15 +0200 |
parents | 21025a4107d4 |
children | ea83abf95630 |
comparison
equal
deleted
inserted
replaced
43033:21025a4107d4 | 43034:294afb982a88 |
---|---|
30 This is a simple and effective format. It should be enought to experiment with | 30 This is a simple and effective format. It should be enought to experiment with |
31 the concept. | 31 the concept. |
32 """ | 32 """ |
33 | 33 |
34 from __future__ import absolute_import | 34 from __future__ import absolute_import |
35 | |
36 import hashlib | |
37 import struct | |
38 | |
39 from .. import error | |
40 | |
41 SIDEDATA_HEADER = struct.Struct('>H') | |
42 SIDEDATA_ENTRY = struct.Struct('>HL20s') | |
43 | |
44 def sidedatareadprocessor(rl, text): | |
45 sidedata = {} | |
46 offset = 0 | |
47 nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) | |
48 offset += SIDEDATA_HEADER.size | |
49 dataoffset = SIDEDATA_HEADER.size + (SIDEDATA_ENTRY.size * nbentry) | |
50 for i in range(nbentry): | |
51 nextoffset = offset + SIDEDATA_ENTRY.size | |
52 key, size, storeddigest = SIDEDATA_ENTRY.unpack(text[offset:nextoffset]) | |
53 offset = nextoffset | |
54 # read the data associated with that entry | |
55 nextdataoffset = dataoffset + size | |
56 entrytext = text[dataoffset:nextdataoffset] | |
57 readdigest = hashlib.sha1(entrytext).digest() | |
58 if storeddigest != readdigest: | |
59 raise error.SidedataHashError(key, storeddigest, readdigest) | |
60 sidedata[key] = entrytext | |
61 dataoffset = nextdataoffset | |
62 text = text[dataoffset:] | |
63 return text, True, sidedata |