Mercurial > hg
comparison mercurial/tags.py @ 33537:709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
This will help sharing the cache between shares.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Sat, 15 Jul 2017 23:30:25 +0200 |
parents | ddacd0e453ae |
children | 2d80e078724a |
comparison
equal
deleted
inserted
replaced
33536:ddacd0e453ae | 33537:709dde1c5dd5 |
---|---|
615 for name in names: | 615 for name in names: |
616 repo.hook('tag', node=hex(node), tag=name, local=local) | 616 repo.hook('tag', node=hex(node), tag=name, local=local) |
617 | 617 |
618 return tagnode | 618 return tagnode |
619 | 619 |
620 _fnodescachefile = 'cache/hgtagsfnodes1' | 620 _fnodescachefile = 'hgtagsfnodes1' |
621 _fnodesrecsize = 4 + 20 # changeset fragment + filenode | 621 _fnodesrecsize = 4 + 20 # changeset fragment + filenode |
622 _fnodesmissingrec = '\xff' * 24 | 622 _fnodesmissingrec = '\xff' * 24 |
623 | 623 |
624 class hgtagsfnodescache(object): | 624 class hgtagsfnodescache(object): |
625 """Persistent cache mapping revisions to .hgtags filenodes. | 625 """Persistent cache mapping revisions to .hgtags filenodes. |
649 self.lookupcount = 0 | 649 self.lookupcount = 0 |
650 self.hitcount = 0 | 650 self.hitcount = 0 |
651 | 651 |
652 | 652 |
653 try: | 653 try: |
654 data = repo.vfs.read(_fnodescachefile) | 654 data = repo.cachevfs.read(_fnodescachefile) |
655 except (OSError, IOError): | 655 except (OSError, IOError): |
656 data = "" | 656 data = "" |
657 self._raw = bytearray(data) | 657 self._raw = bytearray(data) |
658 | 658 |
659 # The end state of self._raw is an array that is of the exact length | 659 # The end state of self._raw is an array that is of the exact length |
757 repo = self._repo | 757 repo = self._repo |
758 | 758 |
759 try: | 759 try: |
760 lock = repo.wlock(wait=False) | 760 lock = repo.wlock(wait=False) |
761 except error.LockError: | 761 except error.LockError: |
762 repo.ui.log('tagscache', | 762 repo.ui.log('tagscache', 'not writing .hg/cache/%s because ' |
763 'not writing .hg/%s because lock cannot be acquired\n' % | 763 'lock cannot be acquired\n' % (_fnodescachefile)) |
764 (_fnodescachefile)) | |
765 return | 764 return |
766 | 765 |
767 try: | 766 try: |
768 f = repo.vfs.open(_fnodescachefile, 'ab') | 767 f = repo.cachevfs.open(_fnodescachefile, 'ab') |
769 try: | 768 try: |
770 # if the file has been truncated | 769 # if the file has been truncated |
771 actualoffset = f.tell() | 770 actualoffset = f.tell() |
772 if actualoffset < self._dirtyoffset: | 771 if actualoffset < self._dirtyoffset: |
773 self._dirtyoffset = actualoffset | 772 self._dirtyoffset = actualoffset |
774 data = self._raw[self._dirtyoffset:] | 773 data = self._raw[self._dirtyoffset:] |
775 f.seek(self._dirtyoffset) | 774 f.seek(self._dirtyoffset) |
776 f.truncate() | 775 f.truncate() |
777 repo.ui.log('tagscache', | 776 repo.ui.log('tagscache', |
778 'writing %d bytes to %s\n' % ( | 777 'writing %d bytes to cache/%s\n' % ( |
779 len(data), _fnodescachefile)) | 778 len(data), _fnodescachefile)) |
780 f.write(data) | 779 f.write(data) |
781 self._dirtyoffset = None | 780 self._dirtyoffset = None |
782 finally: | 781 finally: |
783 f.close() | 782 f.close() |
784 except (IOError, OSError) as inst: | 783 except (IOError, OSError) as inst: |
785 repo.ui.log('tagscache', | 784 repo.ui.log('tagscache', |
786 "couldn't write %s: %s\n" % ( | 785 "couldn't write cache/%s: %s\n" % ( |
787 _fnodescachefile, inst)) | 786 _fnodescachefile, inst)) |
788 finally: | 787 finally: |
789 lock.release() | 788 lock.release() |