changeset 3491:23cffef5d424

Split branchtags into two additional functions. This makes it easier to override only parts of the cache saving process.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 23 Oct 2006 23:32:56 -0300
parents c3345b0f2fcd
children fbf8320f25c8
files mercurial/localrepo.py
diffstat 1 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Mon Oct 23 14:56:51 2006 +0200
+++ b/mercurial/localrepo.py	Mon Oct 23 23:32:56 2006 -0300
@@ -295,6 +295,18 @@
 
         self.branchcache = {} # avoid recursion in changectx
 
+        partial, last, lrev = self._readbranchcache()
+
+        tiprev = self.changelog.count() - 1
+        if lrev != tiprev:
+            self._updatebranchcache(partial, lrev+1, tiprev+1)
+            self._writebranchcache(partial, self.changelog.tip(), tiprev)
+
+        self.branchcache = partial
+        return self.branchcache
+
+    def _readbranchcache(self):
+        partial = {}
         try:
             f = self.opener("branches.cache")
             last, lrev = f.readline().rstrip().split(" ", 1)
@@ -303,34 +315,30 @@
                 self.changelog.node(lrev) == last): # sanity check
                 for l in f:
                     node, label = l.rstrip().split(" ", 1)
-                    self.branchcache[label] = bin(node)
+                    partial[label] = bin(node)
             else: # invalidate the cache
                 last, lrev = nullid, -1
             f.close()
         except IOError:
             last, lrev = nullid, -1
+        return partial, last, lrev
 
-        tip = self.changelog.count() - 1
-        if lrev != tip:
-            for r in xrange(lrev + 1, tip + 1):
-                c = self.changectx(r)
-                b = c.branch()
-                if b:
-                    self.branchcache[b] = c.node()
-            self._writebranchcache()
-
-        return self.branchcache
-
-    def _writebranchcache(self):
+    def _writebranchcache(self, branches, tip, tiprev):
         try:
             f = self.opener("branches.cache", "w")
-            t = self.changelog.tip()
-            f.write("%s %s\n" % (hex(t), self.changelog.count() - 1))
-            for label, node in self.branchcache.iteritems():
+            f.write("%s %s\n" % (hex(tip), tiprev))
+            for label, node in branches.iteritems():
                 f.write("%s %s\n" % (hex(node), label))
         except IOError:
             pass
 
+    def _updatebranchcache(self, partial, start, end):
+        for r in xrange(start, end):
+            c = self.changectx(r)
+            b = c.branch()
+            if b:
+                partial[b] = c.node()
+
     def lookup(self, key):
         if key == '.':
             key = self.dirstate.parents()[0]