changeset 42007:b5511845f9d5

branchcache: have a hasnode function to validate nodes Upcoming patches will delay node validation until it's required. So we need to a way in branchcache class to check whether a node exists or node. Other options were making repo or changelog an attribute of branchcache object. But the branchcache depends on filters so I decided to pass a function object. Differential Revision: https://phab.mercurial-scm.org/D6157
author Pulkit Goyal <pulkit@yandex-team.ru>
date Tue, 19 Mar 2019 16:26:52 +0300
parents 111de135fc76
children 7f6b375a8903
files mercurial/branchmap.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Tue Mar 19 16:20:02 2019 +0300
+++ b/mercurial/branchmap.py	Tue Mar 19 16:26:52 2019 +0300
@@ -150,7 +150,10 @@
     """
 
     def __init__(self, entries=(), tipnode=nullid, tiprev=nullrev,
-                 filteredhash=None, closednodes=None):
+                 filteredhash=None, closednodes=None, hasnode=None):
+        """ hasnode is a function which can be used to verify whether changelog
+        has a given node or not. If it's not provided, we assume that every node
+        we have exists in changelog """
         self.tipnode = tipnode
         self.tiprev = tiprev
         self.filteredhash = filteredhash
@@ -166,6 +169,9 @@
         self._closedverified = False
         # branches for which nodes are verified
         self._verifiedbranches = set()
+        self._hasnode = hasnode
+        if self._hasnode is None:
+            self._hasnode = lambda x: True
 
     def __iter__(self):
         return iter(self._entries)
@@ -193,9 +199,11 @@
             last, lrev = cachekey[:2]
             last, lrev = bin(last), int(lrev)
             filteredhash = None
+            hasnode = repo.changelog.hasnode
             if len(cachekey) > 2:
                 filteredhash = bin(cachekey[2])
-            bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash)
+            bcache = cls(tipnode=last, tiprev=lrev, filteredhash=filteredhash,
+                         hasnode=hasnode)
             if not bcache.validfor(repo):
                 # invalidate the cache
                 raise ValueError(r'tip differs')