mercurial/localrepo.py
changeset 18112 569091b938a9
parent 18106 2cf01eb74842
child 18113 da1714bd0250
--- 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