[PATCH 08 of 10] branchmap: make update responsible to update the cache key

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Dec 21 19:48:55 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1356138828 -3600
# Node ID 5122e7c79dff4185e290dd9847d8163ca5f64034
# Parent  3264d3ce53a0fe45c7b484509fbd380bbe82a805
branchmap: make update responsible to update the cache key

The update function have all necessary data to keep the branchcache key
up to date with its value.

This save assignation to cache key that each caller of update had to do by had.

The strip case is a bit more complicated to handles from inside the function but
I do not expect any impact.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -89,21 +89,43 @@ def update(repo, partial, ctxgen):
             ancestors = set(cl.ancestors([latest],
                                                      bheadrevs[0]))
             if ancestors:
                 bheadrevs = [b for b in bheadrevs if b not in ancestors]
         partial[branch] = [cl.node(rev) for rev in bheadrevs]
+        tiprev = max(bheadrevs)
+        if tiprev > partial.tiprev:
+            partial.tipnode = cl.node(tiprev)
+            partial.tiprev = tiprev
+
 
     # There may be branches that cease to exist when the last commit in the
     # branch was stripped.  This code filters them out.  Note that the
     # branch that ceased to exist may not be in newbranches because
     # newbranches is the set of candidate heads, which when you strip the
     # last commit in a branch will be the parent branch.
+    droppednodes = []
     for branch in partial.keys():
         nodes = [head for head in partial[branch]
                  if cl.hasnode(head)]
         if not nodes:
+            droppednodes.extend(nodes)
             del partial[branch]
+    try:
+        node = cl.node(partial.tiprev)
+    except IndexError:
+        node = None
+    if ((partial.tipnode != node)
+        or (partial.tipnode in droppednodes)):
+        # cache key are not valid anymore
+        partial.tipnode = nullid
+        partial.tiprev = nullrev
+        for heads in partial.values():
+            tiprev = max(cl.rev(node) for node in heads)
+            if tiprev > partial.tiprev:
+                partial.tipnode = cl.node(tiprev)
+                partial.tiprev = tiprev
+
 
 def updatecache(repo):
     repo = repo.unfiltered()  # Until we get a smarter cache management
     cl = repo.changelog
     tip = cl.tip()
@@ -119,22 +141,18 @@ def updatecache(repo):
     # if partial.tiprev >  catip: we have uncachable element in `partial` can't
     #                             write on disk
     if partial.tiprev < catip:
         ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, catip))
         update(repo, partial, ctxgen)
-        partial.tipnode = cl.node(catip)
-        partial.tiprev = catip
         partial.write(repo)
     # 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(repo) - 1
     if partial.tiprev < tiprev:
         ctxgen = (repo[r] for r in cl.revs(partial.tiprev + 1, tiprev))
         update(repo, partial, ctxgen)
-        partial.tipnode = cl.node(tiprev)
-        partial.tiprev = tiprev
     repo._branchcache = partial
 
 class branchcache(dict):
     """A dict like object that hold branches heads cache"""
 
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1436,12 +1436,10 @@ class localrepository(object):
         if newheadnodes:
             ctxgen = (self[node] for node in newheadnodes
                       if self.changelog.hasnode(node))
             cache = self._branchcache
             branchmap.update(self, cache, ctxgen)
-            cache.tipnode = self.changelog.tip()
-            cache.tiprev = self.changelog.rev(cache.tipnode)
             cache.write(self)
 
         # Ensure the persistent tag cache is updated.  Doing it now
         # means that the tag cache only has to worry about destroyed
         # heads immediately after a strip/rollback.  That in turn


More information about the Mercurial-devel mailing list