We already know how to serialize and de-serialize and enty. So lets just do that
and modify the entry tuple directly.
This avoid having to duplicated binary operation in complicated code.
Alphare |
hg-reviewers |
We already know how to serialize and de-serialize and enty. So lets just do that
and modify the entry tuple directly.
This avoid having to duplicated binary operation in complicated code.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/pure/parsers.py (18 lines) |
Replace an existing index entry's sidedata offset and length with new | Replace an existing index entry's sidedata offset and length with new | ||||
ones. | ones. | ||||
This cannot be used outside of the context of sidedata rewriting, | This cannot be used outside of the context of sidedata rewriting, | ||||
inside the transaction that creates the revision `rev`. | inside the transaction that creates the revision `rev`. | ||||
""" | """ | ||||
if rev < 0: | if rev < 0: | ||||
raise KeyError | raise KeyError | ||||
self._check_index(rev) | self._check_index(rev) | ||||
sidedata_format = b">Qi" | if rev < self._lgt: | ||||
packed_size = struct.calcsize(sidedata_format) | |||||
if rev >= self._lgt: | |||||
packed = _pack(sidedata_format, sidedata_offset, sidedata_length) | |||||
old = self._extra[rev - self._lgt] | |||||
offset_flags = struct.pack(b">Q", offset_flags) | |||||
new = offset_flags + old[8:64] + packed + old[64 + packed_size :] | |||||
self._extra[rev - self._lgt] = new | |||||
else: | |||||
msg = b"cannot rewrite entries outside of this transaction" | msg = b"cannot rewrite entries outside of this transaction" | ||||
raise KeyError(msg) | raise KeyError(msg) | ||||
else: | |||||
entry = list(self[rev]) | |||||
entry[0] = offset_flags | |||||
entry[8] = sidedata_offset | |||||
entry[9] = sidedata_length | |||||
entry = tuple(entry) | |||||
new = self._pack_entry(entry) | |||||
self._extra[rev - self._lgt] = new | |||||
def _unpack_entry(self, data): | def _unpack_entry(self, data): | ||||
return self.index_format.unpack(data) | return self.index_format.unpack(data) | ||||
def _pack_entry(self, entry): | def _pack_entry(self, entry): | ||||
return self.index_format.pack(*entry) | return self.index_format.pack(*entry) | ||||
def entry_binary(self, rev): | def entry_binary(self, rev): |