[PATCH 9 of 9] teach the branch cache about closed branches
Alexis S. L. Carvalho
alexis at cecm.usp.br
Sun Mar 2 13:01:31 CST 2008
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1204481759 10800
# Node ID 3e6c59ad95dbf5583a37f5dc6ef17b1872d3cfce
# Parent efbc14991a6e45cd59514c74abae4765e19d0cd0
teach the branch cache about closed branches
If extra['closebranch'] == 'foo' and bin(extra['closebranchnodes']) is
a head of branch 'foo', that head is considered closed (i.e. doesn't
appear in the branch cache.
The branch cache file is moved to <store>/cache/branches .
diff -r efbc14991a6e -r 3e6c59ad95db mercurial/localrepo.py
--- a/mercurial/localrepo.py Sun Mar 02 15:15:59 2008 -0300
+++ b/mercurial/localrepo.py Sun Mar 02 15:15:59 2008 -0300
@@ -384,7 +384,7 @@ class localrepository(repo.repository):
def _readbranchcache(self):
partial = {}
try:
- f = self.sopener("cache.branch")
+ f = self.sopener("cache/branches")
lines = f.read().split('\n')
f.close()
except (IOError, OSError):
@@ -416,7 +416,7 @@ class localrepository(repo.repository):
def _writebranchcache(self, branches, tip, tiprev):
try:
- f = self.sopener("cache.branch", "w", atomictemp=True)
+ f = self.sopener("cache/branches", "w", atomictemp=True)
f.write("%s %s\n" % (hex(tip), tiprev))
for label, nodes in branches.iteritems():
for n in nodes:
@@ -452,6 +452,24 @@ class localrepository(repo.repository):
if p in heads:
heads.remove(p)
heads.append(n)
+ # see if we have to close some branch head
+ extra = c.extra()
+ if 'closebranch' in extra:
+ closename = extra['closebranch']
+ try:
+ closenode = bin(extra['closebranchnodes'])
+ heads = partial[closename]
+ except (KeyError, TypeError):
+ continue
+ if closenode in heads:
+ heads.remove(closenode)
+ else:
+ for i in xrange(0, len(closenode)//20):
+ cnode = closenode[i*20:(i+1)*20]
+ if cnode in heads:
+ heads.remove(cnode)
+ if not heads:
+ del partial[closename]
# For each multi-headed branch, scan the DAG to make sure that one
# head is not an ancestor of the other. This is required to handle
diff -r efbc14991a6e -r 3e6c59ad95db tests/test-inherit-mode.out
--- a/tests/test-inherit-mode.out Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-inherit-mode.out Sun Mar 02 15:15:59 2008 -0300
@@ -45,7 +45,8 @@ 00770 ../push/.hg/store/
00770 ../push/.hg/store/
00660 ../push/.hg/store/00changelog.i
00660 ../push/.hg/store/00manifest.i
-00660 ../push/.hg/store/cache.branch
+00770 ../push/.hg/store/cache/
+00660 ../push/.hg/store/cache/branches
00770 ../push/.hg/store/data/
00770 ../push/.hg/store/data/dir/
00660 ../push/.hg/store/data/dir/bar.i
diff -r efbc14991a6e -r 3e6c59ad95db tests/test-mq-caches
--- a/tests/test-mq-caches Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-mq-caches Sun Mar 02 15:15:59 2008 -0300
@@ -1,6 +1,6 @@
#!/bin/sh
-branches=.hg/store/cache.branch
+branches=.hg/store/cache/branches
echo '[extensions]' >> $HGRCPATH
echo 'hgext.mq=' >> $HGRCPATH
diff -r efbc14991a6e -r 3e6c59ad95db tests/test-newbranch
--- a/tests/test-newbranch Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-newbranch Sun Mar 02 15:15:59 2008 -0300
@@ -1,6 +1,6 @@
#!/bin/sh
-branchcache='.hg/store/cache.branch'
+branchcache='.hg/store/cache/branches'
hg init t
cd t
@@ -83,5 +83,6 @@ hg commit -m'Merge ff into foo' -d '1000
hg commit -m'Merge ff into foo' -d '1000000 0'
hg parents --debug
hg manifest
+hg branches
exit 0
diff -r efbc14991a6e -r 3e6c59ad95db tests/test-newbranch.out
--- a/tests/test-newbranch.out Sun Mar 02 15:15:59 2008 -0300
+++ b/tests/test-newbranch.out Sun Mar 02 15:15:59 2008 -0300
@@ -72,10 +72,8 @@ summary: initial
foo 5:5321a81a517f
default 3:a78f15a8bec6 (inactive)
-bar 2:67ec16bde7f1 (inactive)
foo
default
-bar
% test for invalid branch cache
rolling back last transaction
changeset: 4:4909a3732169
@@ -105,7 +103,6 @@ 4909a3732169c0c20011c4f4b8fdff4e3d89b23f
4909a3732169c0c20011c4f4b8fdff4e3d89b23f 4
a78f15a8bec6b186583cf0e7992b9dee7943d1b5 default
4909a3732169c0c20011c4f4b8fdff4e3d89b23f foo
-67ec16bde7f1575d523313b9bca000f6a6f12dca bar
% push should update the branch cache
% pushing just rev 0
be8523e69bf892e25817fc97187516b3c0804ae4 0
@@ -114,7 +111,6 @@ 4909a3732169c0c20011c4f4b8fdff4e3d89b23f
4909a3732169c0c20011c4f4b8fdff4e3d89b23f 4
a78f15a8bec6b186583cf0e7992b9dee7943d1b5 default
4909a3732169c0c20011c4f4b8fdff4e3d89b23f foo
-67ec16bde7f1575d523313b9bca000f6a6f12dca bar
% update with no arguments: tipmost revision of the current branch
a78f15a8bec6
4909a3732169 (foo) tip
@@ -147,3 +143,5 @@ Merge ff into foo
a
ff
+foo 6:999d9aa54cfd
+default 3:a78f15a8bec6
More information about the Mercurial-devel
mailing list