220 self._hasnode = hasnode |
220 self._hasnode = hasnode |
221 if self._hasnode is None: |
221 if self._hasnode is None: |
222 self._hasnode = lambda x: True |
222 self._hasnode = lambda x: True |
223 |
223 |
224 def _verifyclosed(self): |
224 def _verifyclosed(self): |
225 """ verify the closed nodes we have """ |
225 """verify the closed nodes we have""" |
226 if self._closedverified: |
226 if self._closedverified: |
227 return |
227 return |
228 for node in self._closednodes: |
228 for node in self._closednodes: |
229 if not self._hasnode(node): |
229 if not self._hasnode(node): |
230 _unknownnode(node) |
230 _unknownnode(node) |
231 |
231 |
232 self._closedverified = True |
232 self._closedverified = True |
233 |
233 |
234 def _verifybranch(self, branch): |
234 def _verifybranch(self, branch): |
235 """ verify head nodes for the given branch. """ |
235 """verify head nodes for the given branch.""" |
236 if branch not in self._entries or branch in self._verifiedbranches: |
236 if branch not in self._entries or branch in self._verifiedbranches: |
237 return |
237 return |
238 for n in self._entries[branch]: |
238 for n in self._entries[branch]: |
239 if not self._hasnode(n): |
239 if not self._hasnode(n): |
240 _unknownnode(n) |
240 _unknownnode(n) |
241 |
241 |
242 self._verifiedbranches.add(branch) |
242 self._verifiedbranches.add(branch) |
243 |
243 |
244 def _verifyall(self): |
244 def _verifyall(self): |
245 """ verifies nodes of all the branches """ |
245 """verifies nodes of all the branches""" |
246 needverification = set(self._entries.keys()) - self._verifiedbranches |
246 needverification = set(self._entries.keys()) - self._verifiedbranches |
247 for b in needverification: |
247 for b in needverification: |
248 self._verifybranch(b) |
248 self._verifybranch(b) |
249 |
249 |
250 def __iter__(self): |
250 def __iter__(self): |
267 yield k, v |
267 yield k, v |
268 |
268 |
269 items = iteritems |
269 items = iteritems |
270 |
270 |
271 def hasbranch(self, label): |
271 def hasbranch(self, label): |
272 """ checks whether a branch of this name exists or not """ |
272 """checks whether a branch of this name exists or not""" |
273 self._verifybranch(label) |
273 self._verifybranch(label) |
274 return label in self._entries |
274 return label in self._entries |
275 |
275 |
276 @classmethod |
276 @classmethod |
277 def fromfile(cls, repo): |
277 def fromfile(cls, repo): |
385 def iterbranches(self): |
385 def iterbranches(self): |
386 for bn, heads in pycompat.iteritems(self): |
386 for bn, heads in pycompat.iteritems(self): |
387 yield (bn, heads) + self._branchtip(heads) |
387 yield (bn, heads) + self._branchtip(heads) |
388 |
388 |
389 def iterheads(self): |
389 def iterheads(self): |
390 """ returns all the heads """ |
390 """returns all the heads""" |
391 self._verifyall() |
391 self._verifyall() |
392 return pycompat.itervalues(self._entries) |
392 return pycompat.itervalues(self._entries) |
393 |
393 |
394 def copy(self): |
394 def copy(self): |
395 """return an deep copy of the branchcache object""" |
395 """return an deep copy of the branchcache object""" |
784 finally: |
784 finally: |
785 if wlock is not None: |
785 if wlock is not None: |
786 wlock.release() |
786 wlock.release() |
787 |
787 |
788 def _writenames(self, repo): |
788 def _writenames(self, repo): |
789 """ write the new branch names to revbranchcache """ |
789 """write the new branch names to revbranchcache""" |
790 if self._rbcnamescount != 0: |
790 if self._rbcnamescount != 0: |
791 f = repo.cachevfs.open(_rbcnames, b'ab') |
791 f = repo.cachevfs.open(_rbcnames, b'ab') |
792 if f.tell() == self._rbcsnameslen: |
792 if f.tell() == self._rbcsnameslen: |
793 f.write(b'\0') |
793 f.write(b'\0') |
794 else: |
794 else: |
809 self._rbcsnameslen = f.tell() |
809 self._rbcsnameslen = f.tell() |
810 f.close() |
810 f.close() |
811 self._rbcnamescount = len(self._names) |
811 self._rbcnamescount = len(self._names) |
812 |
812 |
813 def _writerevs(self, repo, start): |
813 def _writerevs(self, repo, start): |
814 """ write the new revs to revbranchcache """ |
814 """write the new revs to revbranchcache""" |
815 revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) |
815 revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) |
816 with repo.cachevfs.open(_rbcrevs, b'ab') as f: |
816 with repo.cachevfs.open(_rbcrevs, b'ab') as f: |
817 if f.tell() != start: |
817 if f.tell() != start: |
818 repo.ui.debug( |
818 repo.ui.debug( |
819 b"truncating cache/%s to %d\n" % (_rbcrevs, start) |
819 b"truncating cache/%s to %d\n" % (_rbcrevs, start) |