Patchwork D7846: nodemap: all check that revision and nodes match in the nodemap

login
register
mail settings
Submitter phabricator
Date Jan. 13, 2020, 3:09 p.m.
Message ID <differential-rev-PHID-DREV-ewmbqix6eh74qnrpgxpm-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44286/
State New
Headers show

Comments

phabricator - Jan. 13, 2020, 3:09 p.m.
marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  More check is always useful.

REPOSITORY
  rHG Mercurial

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

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
@@ -359,6 +359,19 @@ 
             ret = 1
         else:
             all_revs.remove(r)
+        nm_rev = _find_node(root, nodemod.hex(index[r][7]))
+        if nm_rev is None:
+            msg = b"  revision node does not match any entries: %d\n" % r
+            ui.write_err(msg)
+            ret = 1
+        elif nm_rev != r:
+            msg = (
+                b"  revision node does not match the expected revision: "
+                b"%d != %d\n" % (r, nm_rev)
+            )
+            ui.write_err(msg)
+            ret = 1
+
     if all_revs:
         for r in sorted(all_revs):
             msg = b"  extra revision in  nodemap: %d\n" % r
@@ -374,3 +387,11 @@ 
             if v is None or isinstance(v, Block):
                 continue
             yield v
+
+
+def _find_node(block, node):
+    """find the revision associated with a given node"""
+    entry = block.get(_to_int(node[0]))
+    if isinstance(entry, dict):
+        return _find_node(entry, node[1:])
+    return entry