Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/sidedata.py @ 43035:ea83abf95630
sidedata: add a function to write sidedata into a raw text
Differential Revision: https://phab.mercurial-scm.org/D6891
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 04 Sep 2019 01:20:54 +0200 |
parents | 294afb982a88 |
children | e8bc4c3d9a0b |
comparison
equal
deleted
inserted
replaced
43034:294afb982a88 | 43035:ea83abf95630 |
---|---|
39 from .. import error | 39 from .. import error |
40 | 40 |
41 SIDEDATA_HEADER = struct.Struct('>H') | 41 SIDEDATA_HEADER = struct.Struct('>H') |
42 SIDEDATA_ENTRY = struct.Struct('>HL20s') | 42 SIDEDATA_ENTRY = struct.Struct('>HL20s') |
43 | 43 |
44 def sidedatawriteprocessor(rl, text, sidedata): | |
45 sidedata = list(sidedata.items()) | |
46 sidedata.sort() | |
47 rawtext = [SIDEDATA_HEADER.pack(len(sidedata))] | |
48 for key, value in sidedata: | |
49 digest = hashlib.sha1(value).digest() | |
50 rawtext.append(SIDEDATA_ENTRY.pack(key, len(value), digest)) | |
51 for key, value in sidedata: | |
52 rawtext.append(value) | |
53 rawtext.append(bytes(text)) | |
54 return ''.join(rawtext), False | |
55 | |
44 def sidedatareadprocessor(rl, text): | 56 def sidedatareadprocessor(rl, text): |
45 sidedata = {} | 57 sidedata = {} |
46 offset = 0 | 58 offset = 0 |
47 nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) | 59 nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) |
48 offset += SIDEDATA_HEADER.size | 60 offset += SIDEDATA_HEADER.size |