Patchwork D6207: branchcache: add functions to validate changelog nodes

login
register
mail settings
Submitter phabricator
Date April 15, 2019, 11:41 p.m.
Message ID <7fba5c3355b2d683544b37287f16c5cc@localhost.localdomain>
Download mbox | patch
Permalink /patch/39619/
State Not Applicable
Headers show

Comments

phabricator - April 15, 2019, 11:41 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2f8147521e59: branchcache: add functions to validate changelog nodes (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6207?vs=14676&id=14750

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

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -126,6 +126,10 @@ 
     def clear(self):
         self._per_filter.clear()
 
+def _unknownnode(node):
+    """ raises ValueError when branchcache found a node which does not exists
+    """
+    raise ValueError(r'node %s does not exist' % pycompat.sysstr(hex(node)))
 
 class branchcache(object):
     """A dict like object that hold branches heads cache.
@@ -173,6 +177,32 @@ 
         if self._hasnode is None:
             self._hasnode = lambda x: True
 
+    def _verifyclosed(self):
+        """ verify the closed nodes we have """
+        if self._closedverified:
+            return
+        for node in self._closednodes:
+            if not self._hasnode(node):
+                _unknownnode(node)
+
+        self._closedverified = True
+
+    def _verifybranch(self, branch):
+        """ verify head nodes for the given branch. If branch is None, verify
+        for all the branches """
+        if branch not in self._entries or branch in self._verifiedbranches:
+            return
+        for n in self._entries[branch]:
+            if not self._hasnode(n):
+                _unknownnode(n)
+
+        self._verifiedbranches.add(branch)
+
+    def _verifyall(self):
+        """ verifies nodes of all the branches """
+        for b in self._entries:
+            self._verifybranch(b)
+
     def __iter__(self):
         return iter(self._entries)