comparison mercurial/branchmap.py @ 42120:2f8147521e59

branchcache: add functions to validate changelog nodes This patch adds functions to validate closed nodes, validate nodes for a certain branch and for all the branches. These functions will be used in upcoming patches. Differential Revision: https://phab.mercurial-scm.org/D6207
author Pulkit Goyal <pulkit@yandex-team.ru>
date Tue, 19 Mar 2019 16:52:15 +0300
parents f0def07fa82f
children 6578654916ae
comparison
equal deleted inserted replaced
42119:2d428b859282 42120:2f8147521e59
124 return 124 return
125 125
126 def clear(self): 126 def clear(self):
127 self._per_filter.clear() 127 self._per_filter.clear()
128 128
129 def _unknownnode(node):
130 """ raises ValueError when branchcache found a node which does not exists
131 """
132 raise ValueError(r'node %s does not exist' % pycompat.sysstr(hex(node)))
129 133
130 class branchcache(object): 134 class branchcache(object):
131 """A dict like object that hold branches heads cache. 135 """A dict like object that hold branches heads cache.
132 136
133 This cache is used to avoid costly computations to determine all the 137 This cache is used to avoid costly computations to determine all the
170 # branches for which nodes are verified 174 # branches for which nodes are verified
171 self._verifiedbranches = set() 175 self._verifiedbranches = set()
172 self._hasnode = hasnode 176 self._hasnode = hasnode
173 if self._hasnode is None: 177 if self._hasnode is None:
174 self._hasnode = lambda x: True 178 self._hasnode = lambda x: True
179
180 def _verifyclosed(self):
181 """ verify the closed nodes we have """
182 if self._closedverified:
183 return
184 for node in self._closednodes:
185 if not self._hasnode(node):
186 _unknownnode(node)
187
188 self._closedverified = True
189
190 def _verifybranch(self, branch):
191 """ verify head nodes for the given branch. If branch is None, verify
192 for all the branches """
193 if branch not in self._entries or branch in self._verifiedbranches:
194 return
195 for n in self._entries[branch]:
196 if not self._hasnode(n):
197 _unknownnode(n)
198
199 self._verifiedbranches.add(branch)
200
201 def _verifyall(self):
202 """ verifies nodes of all the branches """
203 for b in self._entries:
204 self._verifybranch(b)
175 205
176 def __iter__(self): 206 def __iter__(self):
177 return iter(self._entries) 207 return iter(self._entries)
178 208
179 def __setitem__(self, key, value): 209 def __setitem__(self, key, value):