Show More
@@ -608,51 +608,62 b' class revbranchcache(object):' | |||||
608 | wlock = None |
|
608 | wlock = None | |
609 | step = '' |
|
609 | step = '' | |
610 | try: |
|
610 | try: | |
|
611 | # write the new names | |||
611 | if self._rbcnamescount < len(self._names): |
|
612 | if self._rbcnamescount < len(self._names): | |
612 | step = ' names' |
|
|||
613 | wlock = repo.wlock(wait=False) |
|
613 | wlock = repo.wlock(wait=False) | |
614 | if self._rbcnamescount != 0: |
|
614 | step = ' names' | |
615 | f = repo.cachevfs.open(_rbcnames, 'ab') |
|
615 | self._writenames(repo) | |
616 | if f.tell() == self._rbcsnameslen: |
|
|||
617 | f.write('\0') |
|
|||
618 | else: |
|
|||
619 | f.close() |
|
|||
620 | repo.ui.debug("%s changed - rewriting it\n" % _rbcnames) |
|
|||
621 | self._rbcnamescount = 0 |
|
|||
622 | self._rbcrevslen = 0 |
|
|||
623 | if self._rbcnamescount == 0: |
|
|||
624 | # before rewriting names, make sure references are removed |
|
|||
625 | repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) |
|
|||
626 | f = repo.cachevfs.open(_rbcnames, 'wb') |
|
|||
627 | f.write('\0'.join(encoding.fromlocal(b) |
|
|||
628 | for b in self._names[self._rbcnamescount:])) |
|
|||
629 | self._rbcsnameslen = f.tell() |
|
|||
630 | f.close() |
|
|||
631 | self._rbcnamescount = len(self._names) |
|
|||
632 |
|
616 | |||
|
617 | # write the new revs | |||
633 | start = self._rbcrevslen * _rbcrecsize |
|
618 | start = self._rbcrevslen * _rbcrecsize | |
634 | if start != len(self._rbcrevs): |
|
619 | if start != len(self._rbcrevs): | |
635 | step = '' |
|
620 | step = '' | |
636 | if wlock is None: |
|
621 | if wlock is None: | |
637 | wlock = repo.wlock(wait=False) |
|
622 | wlock = repo.wlock(wait=False) | |
638 | revs = min(len(repo.changelog), |
|
623 | self._writerevs(repo, start) | |
639 | len(self._rbcrevs) // _rbcrecsize) |
|
624 | ||
640 | f = repo.cachevfs.open(_rbcrevs, 'ab') |
|
|||
641 | if f.tell() != start: |
|
|||
642 | repo.ui.debug("truncating cache/%s to %d\n" |
|
|||
643 | % (_rbcrevs, start)) |
|
|||
644 | f.seek(start) |
|
|||
645 | if f.tell() != start: |
|
|||
646 | start = 0 |
|
|||
647 | f.seek(start) |
|
|||
648 | f.truncate() |
|
|||
649 | end = revs * _rbcrecsize |
|
|||
650 | f.write(self._rbcrevs[start:end]) |
|
|||
651 | f.close() |
|
|||
652 | self._rbcrevslen = revs |
|
|||
653 | except (IOError, OSError, error.Abort, error.LockError) as inst: |
|
625 | except (IOError, OSError, error.Abort, error.LockError) as inst: | |
654 | repo.ui.debug("couldn't write revision branch cache%s: %s\n" |
|
626 | repo.ui.debug("couldn't write revision branch cache%s: %s\n" | |
655 | % (step, stringutil.forcebytestr(inst))) |
|
627 | % (step, stringutil.forcebytestr(inst))) | |
656 | finally: |
|
628 | finally: | |
657 | if wlock is not None: |
|
629 | if wlock is not None: | |
658 | wlock.release() |
|
630 | wlock.release() | |
|
631 | ||||
|
632 | def _writenames(self, repo): | |||
|
633 | """ write the new branch names to revbranchcache """ | |||
|
634 | if self._rbcnamescount != 0: | |||
|
635 | f = repo.cachevfs.open(_rbcnames, 'ab') | |||
|
636 | if f.tell() == self._rbcsnameslen: | |||
|
637 | f.write('\0') | |||
|
638 | else: | |||
|
639 | f.close() | |||
|
640 | repo.ui.debug("%s changed - rewriting it\n" % _rbcnames) | |||
|
641 | self._rbcnamescount = 0 | |||
|
642 | self._rbcrevslen = 0 | |||
|
643 | if self._rbcnamescount == 0: | |||
|
644 | # before rewriting names, make sure references are removed | |||
|
645 | repo.cachevfs.unlinkpath(_rbcrevs, ignoremissing=True) | |||
|
646 | f = repo.cachevfs.open(_rbcnames, 'wb') | |||
|
647 | f.write('\0'.join(encoding.fromlocal(b) | |||
|
648 | for b in self._names[self._rbcnamescount:])) | |||
|
649 | self._rbcsnameslen = f.tell() | |||
|
650 | f.close() | |||
|
651 | self._rbcnamescount = len(self._names) | |||
|
652 | ||||
|
653 | def _writerevs(self, repo, start): | |||
|
654 | """ write the new revs to revbranchcache """ | |||
|
655 | revs = min(len(repo.changelog), | |||
|
656 | len(self._rbcrevs) // _rbcrecsize) | |||
|
657 | f = repo.cachevfs.open(_rbcrevs, 'ab') | |||
|
658 | if f.tell() != start: | |||
|
659 | repo.ui.debug("truncating cache/%s to %d\n" | |||
|
660 | % (_rbcrevs, start)) | |||
|
661 | f.seek(start) | |||
|
662 | if f.tell() != start: | |||
|
663 | start = 0 | |||
|
664 | f.seek(start) | |||
|
665 | f.truncate() | |||
|
666 | end = revs * _rbcrecsize | |||
|
667 | f.write(self._rbcrevs[start:end]) | |||
|
668 | f.close() | |||
|
669 | self._rbcrevslen = revs |
General Comments 0
You need to be logged in to leave comments.
Login now