comparison mercurial/localrepo.py @ 18112:569091b938a9

branchmap: simplify _branchtags using a new _cacheabletip method The current _branchtags method is a remnant of an older, much larger function. Its only remaining role is to help MQ to alter the version of branchcache we store on disk. As MQ mutates the repository it ensures persistent cache does not contain anything it is likely to alter. This changeset makes explicit the stable vs volatile part of repository and reduces the MQ specific code to the computation of this limit. The main _branchtags code now handles this possible limit in all cases. This will help to extract the branchmap logic from the repository. The new code of _branchtags is a bit duplicated, but as I expect major refactoring of this section I'm not keen to setup factorisation function here.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 20 Dec 2012 11:52:50 +0100
parents 2cf01eb74842
children da1714bd0250
comparison
equal deleted inserted replaced
18111:d7c28954d901 18112:569091b938a9
647 for bookmark, n in self._bookmarks.iteritems(): 647 for bookmark, n in self._bookmarks.iteritems():
648 if n == node: 648 if n == node:
649 marks.append(bookmark) 649 marks.append(bookmark)
650 return sorted(marks) 650 return sorted(marks)
651 651
652 def _cacheabletip(self):
653 """tip-most revision stable enought to used in persistent cache
654
655 This function is overwritten by MQ to ensure we do not write cache for
656 a part of the history that will likely change.
657
658 Efficient handling of filtered revision in branchcache should offer a
659 better alternative. But we are using this approach until it is ready.
660 """
661 cl = self.changelog
662 return cl.rev(cl.tip())
663
652 def _branchtags(self, partial, lrev): 664 def _branchtags(self, partial, lrev):
653 # TODO: rename this function? 665 # TODO: rename this function?
666 cl = self.changelog
667 catip = self._cacheabletip()
668 # if lrev == catip: cache is already up to date
669 # if lrev > catip: we have uncachable element in `partial` can't write
670 # on disk
671 if lrev < catip:
672 ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
673 self._updatebranchcache(partial, ctxgen)
674 self._writebranchcache(partial, cl.node(catip), catip)
675 lrev = catip
676 # If cacheable tip were lower than actual tip, we need to update the
677 # cache up to tip. This update (from cacheable to actual tip) is not
678 # written to disk since it's not cacheable.
654 tiprev = len(self) - 1 679 tiprev = len(self) - 1
655 if lrev != tiprev: 680 if lrev < tiprev:
656 ctxgen = (self[r] for r in self.changelog.revs(lrev + 1, tiprev)) 681 ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev))
657 self._updatebranchcache(partial, ctxgen) 682 self._updatebranchcache(partial, ctxgen)
658 self._writebranchcache(partial, self.changelog.tip(), tiprev)
659
660 return partial 683 return partial
661 684
662 @unfilteredmethod # Until we get a smarter cache management 685 @unfilteredmethod # Until we get a smarter cache management
663 def updatebranchcache(self): 686 def updatebranchcache(self):
664 tip = self.changelog.tip() 687 tip = self.changelog.tip()