changeset 18125:ad194a8ab5c1

branchmap: add the tipnode (cache key) on the branchcache object Gathering data and cache key paves the way to a lot of simplification.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Sat, 22 Dec 2012 01:59:05 +0100
parents 79db6d40bced
children 090ada0acddb
files mercurial/branchmap.py mercurial/localrepo.py mercurial/statichttprepo.py
diffstat 3 files changed, 21 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/branchmap.py	Sat Dec 22 01:44:42 2012 +0100
+++ b/mercurial/branchmap.py	Sat Dec 22 01:59:05 2012 +0100
@@ -15,7 +15,7 @@
         lines = f.read().split('\n')
         f.close()
     except (IOError, OSError):
-        return branchcache(), nullid, nullrev
+        return branchcache(), nullrev
 
     try:
         last, lrev = lines.pop(0).split(" ", 1)
@@ -32,13 +32,14 @@
                 raise ValueError('invalidating branch cache because node '+
                                  '%s does not exist' % node)
             partial.setdefault(label, []).append(bin(node))
+        partial.tipnode = last
     except KeyboardInterrupt:
         raise
     except Exception, inst:
         if repo.ui.debugflag:
             repo.ui.warn(str(inst), '\n')
-        partial, last, lrev =  branchcache(), nullid, nullrev
-    return partial, last, lrev
+        partial, lrev = branchcache(), nullrev
+    return partial, lrev
 
 def write(repo, branches, tip, tiprev):
     try:
@@ -115,15 +116,14 @@
     repo = repo.unfiltered()  # Until we get a smarter cache management
     cl = repo.changelog
     tip = cl.tip()
-    if repo._branchcache is not None and repo._branchcachetip == tip:
+    partial = repo._branchcache
+    if partial is not None and partial.tipnode == tip:
         return
 
-    oldtip = repo._branchcachetip
-    if oldtip is None or oldtip not in cl.nodemap:
-        partial, last, lrev = read(repo)
+    if partial is None or partial.tipnode not in cl.nodemap:
+        partial, lrev = read(repo)
     else:
-        lrev = cl.rev(oldtip)
-        partial = repo._branchcache
+        lrev = cl.rev(partial.tipnode)
 
     catip = repo._cacheabletip()
     # if lrev == catip: cache is already up to date
@@ -132,7 +132,8 @@
     if lrev < catip:
         ctxgen = (repo[r] for r in cl.revs(lrev + 1, catip))
         update(repo, partial, ctxgen)
-        write(repo, partial, cl.node(catip), catip)
+        partial.tipnode = cl.node(catip)
+        write(repo, partial, partial.tipnode, 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
@@ -141,9 +142,12 @@
     if lrev < tiprev:
         ctxgen = (repo[r] for r in cl.revs(lrev + 1, tiprev))
         update(repo, partial, ctxgen)
+        partial.tipnode = cl.node(tiprev)
     repo._branchcache = partial
-    repo._branchcachetip = tip
 
 class branchcache(dict):
     """A dict like object that hold branches heads cache"""
 
+    def __init__(self, entries=(), tipnode=nullid):
+        super(branchcache, self).__init__(entries)
+        self.tipnode = tipnode
--- a/mercurial/localrepo.py	Sat Dec 22 01:44:42 2012 +0100
+++ b/mercurial/localrepo.py	Sat Dec 22 01:59:05 2012 +0100
@@ -229,7 +229,6 @@
 
 
         self._branchcache = None
-        self._branchcachetip = None
         self.filterpats = {}
         self._datafilters = {}
         self._transref = self._lockref = self._wlockref = None
@@ -979,7 +978,6 @@
             del self.__dict__['_tagscache']
 
         self.unfiltered()._branchcache = None # in UTF-8
-        self.unfiltered()._branchcachetip = None
         self.invalidatevolatilesets()
 
     def invalidatevolatilesets(self):
@@ -1440,7 +1438,8 @@
             ctxgen = (self[node] for node in newheadnodes
                       if self.changelog.hasnode(node))
             branchmap.update(self, self._branchcache, ctxgen)
-            branchmap.write(self, self._branchcache, self.changelog.tip(),
+            self._branchcache.tipnode = self.changelog.tip()
+            branchmap.write(self, self._branchcache, self._branchcache.tipnode,
                             tiprev)
 
         # Ensure the persistent tag cache is updated.  Doing it now
@@ -2495,9 +2494,10 @@
                 if rbheads:
                     rtiprev = max((int(self.changelog.rev(node))
                             for node in rbheads))
-                    self._branchcache = branchmap.branchcache(rbranchmap)
-                    rtipnode = self._branchcachetip = self[rtiprev].node()
-                    branchmap.write(self, self._branchcache, rtipnode, rtiprev)
+                    cache = branchmap.branchcache(rbranchmap,
+                                                  self[rtiprev].node())
+                    self._branchcache = cache
+                    branchmap.write(self, cache, cache.tipnode, rtiprev)
             self.invalidate()
             return len(self.heads()) + 1
         finally:
--- a/mercurial/statichttprepo.py	Sat Dec 22 01:44:42 2012 +0100
+++ b/mercurial/statichttprepo.py	Sat Dec 22 01:59:05 2012 +0100
@@ -135,7 +135,6 @@
         self._tags = None
         self.nodetagscache = None
         self._branchcache = None
-        self._branchcachetip = None
         self.encodepats = None
         self.decodepats = None