Mercurial > hg
comparison mercurial/revlogutils/sidedata.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | c348d829d23a |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
50 | 50 |
51 # internal format constant | 51 # internal format constant |
52 SIDEDATA_HEADER = struct.Struct(r'>H') | 52 SIDEDATA_HEADER = struct.Struct(r'>H') |
53 SIDEDATA_ENTRY = struct.Struct(r'>HL20s') | 53 SIDEDATA_ENTRY = struct.Struct(r'>HL20s') |
54 | 54 |
55 | |
55 def sidedatawriteprocessor(rl, text, sidedata): | 56 def sidedatawriteprocessor(rl, text, sidedata): |
56 sidedata = list(sidedata.items()) | 57 sidedata = list(sidedata.items()) |
57 sidedata.sort() | 58 sidedata.sort() |
58 rawtext = [SIDEDATA_HEADER.pack(len(sidedata))] | 59 rawtext = [SIDEDATA_HEADER.pack(len(sidedata))] |
59 for key, value in sidedata: | 60 for key, value in sidedata: |
62 for key, value in sidedata: | 63 for key, value in sidedata: |
63 rawtext.append(value) | 64 rawtext.append(value) |
64 rawtext.append(bytes(text)) | 65 rawtext.append(bytes(text)) |
65 return ''.join(rawtext), False | 66 return ''.join(rawtext), False |
66 | 67 |
68 | |
67 def sidedatareadprocessor(rl, text): | 69 def sidedatareadprocessor(rl, text): |
68 sidedata = {} | 70 sidedata = {} |
69 offset = 0 | 71 offset = 0 |
70 nbentry, = SIDEDATA_HEADER.unpack(text[:SIDEDATA_HEADER.size]) | 72 (nbentry,) = SIDEDATA_HEADER.unpack(text[: SIDEDATA_HEADER.size]) |
71 offset += SIDEDATA_HEADER.size | 73 offset += SIDEDATA_HEADER.size |
72 dataoffset = SIDEDATA_HEADER.size + (SIDEDATA_ENTRY.size * nbentry) | 74 dataoffset = SIDEDATA_HEADER.size + (SIDEDATA_ENTRY.size * nbentry) |
73 for i in range(nbentry): | 75 for i in range(nbentry): |
74 nextoffset = offset + SIDEDATA_ENTRY.size | 76 nextoffset = offset + SIDEDATA_ENTRY.size |
75 key, size, storeddigest = SIDEDATA_ENTRY.unpack(text[offset:nextoffset]) | 77 key, size, storeddigest = SIDEDATA_ENTRY.unpack(text[offset:nextoffset]) |
83 sidedata[key] = entrytext | 85 sidedata[key] = entrytext |
84 dataoffset = nextdataoffset | 86 dataoffset = nextdataoffset |
85 text = text[dataoffset:] | 87 text = text[dataoffset:] |
86 return text, True, sidedata | 88 return text, True, sidedata |
87 | 89 |
90 | |
88 def sidedatarawprocessor(rl, text): | 91 def sidedatarawprocessor(rl, text): |
89 # side data modifies rawtext and prevent rawtext hash validation | 92 # side data modifies rawtext and prevent rawtext hash validation |
90 return False | 93 return False |
94 | |
91 | 95 |
92 processors = ( | 96 processors = ( |
93 sidedatareadprocessor, | 97 sidedatareadprocessor, |
94 sidedatawriteprocessor, | 98 sidedatawriteprocessor, |
95 sidedatarawprocessor, | 99 sidedatarawprocessor, |