Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHGea83abf95630: sidedata: add a function to write sidedata into a raw text
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
durin42 |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/revlogutils/sidedata.py (12 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
1304f667ea1b | f66e98c9e817 | Pierre-Yves David | Sep 3 2019, 7:20 PM |
import hashlib | import hashlib | ||||
import struct | import struct | ||||
from .. import error | from .. import error | ||||
SIDEDATA_HEADER = struct.Struct('>H') | SIDEDATA_HEADER = struct.Struct('>H') | ||||
SIDEDATA_ENTRY = struct.Struct('>HL20s') | SIDEDATA_ENTRY = struct.Struct('>HL20s') | ||||
def sidedatawriteprocessor(rl, text, sidedata): | |||||
sidedata = list(sidedata.items()) | |||||
sidedata.sort() | |||||
rawtext = [SIDEDATA_HEADER.pack(len(sidedata))] | |||||
for key, value in sidedata: | |||||
digest = hashlib.sha1(value).digest() | |||||
rawtext.append(SIDEDATA_ENTRY.pack(key, len(value), digest)) | |||||
for key, value in sidedata: | |||||
rawtext.append(value) | |||||
rawtext.append(bytes(text)) | |||||
return ''.join(rawtext), False | |||||
def sidedatareadprocessor(rl, text): | def sidedatareadprocessor(rl, text): | ||||
sidedata = {} | sidedata = {} | ||||
offset = 0 | offset = 0 | ||||
nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) | nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) | ||||
offset += SIDEDATA_HEADER.size | offset += SIDEDATA_HEADER.size | ||||
dataoffset = SIDEDATA_HEADER.size + (SIDEDATA_ENTRY.size * nbentry) | dataoffset = SIDEDATA_HEADER.size + (SIDEDATA_ENTRY.size * nbentry) | ||||
for i in range(nbentry): | for i in range(nbentry): | ||||
nextoffset = offset + SIDEDATA_ENTRY.size | nextoffset = offset + SIDEDATA_ENTRY.size |