[PATCH 1 of 4] store all heads of a branch in the branch cache

John Mulligan phlogistonjohn at asynchrono.us
Thu Dec 11 14:10:06 CST 2008


# HG changeset patch
# User John Mulligan <phlogistonjohn at asynchrono.us>
# Date 1228955389 18000
# Node ID 7903e526a9db7778b6a63049d7dad2af2a444b3e
# Parent  b95ff487870e3c15198017779125b7f400491d49
store all heads of a branch in the branch cache

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -385,12 +385,13 @@
             partial = self._ubranchcache
 
         self._branchtags(partial, lrev)
+        # this private cache holds all heads (not just tips)
+        self._ubranchcache = partial
 
         # the branch cache is stored on disk as UTF-8, but in the local
         # charset internally
         for k, v in partial.items():
-            self.branchcache[util.tolocal(k)] = v
-        self._ubranchcache = partial
+            self.branchcache[util.tolocal(k)] = v[-1]
         return self.branchcache
 
     def _readbranchcache(self):
@@ -411,7 +412,7 @@
             for l in lines:
                 if not l: continue
                 node, label = l.split(" ", 1)
-                partial[label.strip()] = bin(node)
+                partial.setdefault(label.strip(), []).append(bin(node))
         except (KeyboardInterrupt, util.SignalInterrupt):
             raise
         except Exception, inst:
@@ -424,8 +425,9 @@
         try:
             f = self.opener("branch.cache", "w", atomictemp=True)
             f.write("%s %s\n" % (hex(tip), tiprev))
-            for label, node in branches.iteritems():
-                f.write("%s %s\n" % (hex(node), label))
+            for label, nodes in branches.iteritems():
+                for node in nodes:
+                    f.write("%s %s\n" % (hex(node), label))
             f.rename()
         except (IOError, OSError):
             pass
@@ -434,7 +436,12 @@
         for r in xrange(start, end):
             c = self[r]
             b = c.branch()
-            partial[b] = c.node()
+            bheads = partial.setdefault(b, [])
+            bheads.append(c.node())
+            for p in c.parents():
+                pn = p.node()
+                if pn in bheads:
+                    bheads.remove(pn)
 
     def lookup(self, key):
         if isinstance(key, int):
diff --git a/tests/test-newbranch.out b/tests/test-newbranch.out
--- a/tests/test-newbranch.out
+++ b/tests/test-newbranch.out
@@ -81,6 +81,7 @@
 
 4:4909a3732169
 4909a3732169c0c20011c4f4b8fdff4e3d89b23f 4
+be8523e69bf892e25817fc97187516b3c0804ae4 default
 bf1bc2f45e834c75404d0ddab57d53beab56e2f8 default
 4909a3732169c0c20011c4f4b8fdff4e3d89b23f foo
 67ec16bde7f1575d523313b9bca000f6a6f12dca bar
@@ -90,6 +91,7 @@
 be8523e69bf892e25817fc97187516b3c0804ae4 default
 % pushing everything
 4909a3732169c0c20011c4f4b8fdff4e3d89b23f 4
+be8523e69bf892e25817fc97187516b3c0804ae4 default
 bf1bc2f45e834c75404d0ddab57d53beab56e2f8 default
 4909a3732169c0c20011c4f4b8fdff4e3d89b23f foo
 67ec16bde7f1575d523313b9bca000f6a6f12dca bar


More information about the Mercurial-devel mailing list