Patchwork D7844: nodemap: code to parse a serialized nodemap

login
register
mail settings
Submitter phabricator
Date Jan. 15, 2020, 2:55 p.m.
Message ID <1952ea49965eb68d990363da78faa334@localhost.localdomain>
Download mbox | patch
Permalink /patch/44370/
State Not Applicable
Headers show

Comments

phabricator - Jan. 15, 2020, 2:55 p.m.
marmoute updated this revision to Diff 19298.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7844?vs=19181&id=19298

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7844/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7844

AFFECTED FILES
  mercurial/revlogutils/nodemap.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -311,3 +311,33 @@ 
         return block_map[id(item)]
     else:
         return _transform_rev(item)
+
+
+def parse_data(data):
+    """parse serialized 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 = {}
+    for i in range(0, len(data), S_BLOCK.size):
+        block = _parse_block(block_map, data[i : i + S_BLOCK.size])
+    return block
+
+
+def _parse_block(block_map, block_data):
+    """Parse the serialization of an individual block
+    """
+    block = Block()
+    ondisk_id = len(block_map)
+    block_map[ondisk_id] = block
+    values = S_BLOCK.unpack(block_data)
+    for idx, v in enumerate(values):
+        if v == NO_ENTRY:
+            continue
+        elif v >= 0:
+            block[idx] = block_map[v]
+        else:
+            block[idx] = _transform_rev(v)
+    return block