diff 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
line wrap: on
line diff
--- a/mercurial/localrepo.py	Thu Dec 20 21:26:30 2012 +0100
+++ b/mercurial/localrepo.py	Thu Dec 20 11:52:50 2012 +0100
@@ -649,14 +649,37 @@
                 marks.append(bookmark)
         return sorted(marks)
 
+    def _cacheabletip(self):
+        """tip-most revision stable enought to used in persistent cache
+
+        This function is overwritten by MQ to ensure we do not write cache for
+        a part of the history that will likely change.
+
+        Efficient handling of filtered revision in branchcache should offer a
+        better alternative. But we are using this approach until it is ready.
+        """
+        cl = self.changelog
+        return cl.rev(cl.tip())
+
     def _branchtags(self, partial, lrev):
         # TODO: rename this function?
+        cl = self.changelog
+        catip = self._cacheabletip()
+        # if lrev == catip: cache is already up to date
+        # if lrev >  catip: we have uncachable element in `partial` can't write
+        #                   on disk
+        if lrev < catip:
+            ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
+            self._updatebranchcache(partial, ctxgen)
+            self._writebranchcache(partial, cl.node(catip), catip)
+            lrev = catip
+        # If cacheable tip were lower than actual tip, we need to update the
+        # cache up to tip. This update (from cacheable to actual tip) is not
+        # written to disk since it's not cacheable.
         tiprev = len(self) - 1
-        if lrev != tiprev:
-            ctxgen = (self[r] for r in self.changelog.revs(lrev + 1, tiprev))
+        if lrev < tiprev:
+            ctxgen = (self[r] for r in cl.revs(lrev + 1, tiprev))
             self._updatebranchcache(partial, ctxgen)
-            self._writebranchcache(partial, self.changelog.tip(), tiprev)
-
         return partial
 
     @unfilteredmethod # Until we get a smarter cache management