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