# HG changeset patch # User Pierre-Yves David # Date 2020-01-15 14:48:47 # Node ID 78721bbdb2ab1f9fe7b994ed31d8dacb6f54e892 # Parent 55b12f2593c12debfcf231dfea3d3249d99469f0 nodemap: code to parse the persistent binary nodemap data We now have code to read back what we persisted. This will be put to use in later changesets. Differential Revision: https://phab.mercurial-scm.org/D7844 diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py --- a/mercurial/revlogutils/nodemap.py +++ b/mercurial/revlogutils/nodemap.py @@ -310,3 +310,30 @@ def _to_value(item, block_map): return block_map[id(item)] else: return _transform_rev(item) + + +def parse_data(data): + """parse parse nodemap data into a nodemap Trie""" + if (len(data) % S_BLOCK.size) != 0: + msg = "nodemap data size is not a multiple of block size (%d): %d" + raise error.Abort(msg % (S_BLOCK.size, len(data))) + if not data: + return Block() + block_map = {} + new_blocks = [] + for i in range(0, len(data), S_BLOCK.size): + block = Block() + ondisk_id = len(block_map) + block_map[ondisk_id] = block + block_data = data[i : i + S_BLOCK.size] + values = S_BLOCK.unpack(block_data) + new_blocks.append((block, values)) + for b, values in new_blocks: + for idx, v in enumerate(values): + if v == NO_ENTRY: + continue + elif v >= 0: + b[idx] = block_map[v] + else: + b[idx] = _transform_rev(v) + return block