Rev 5799: Give up. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu May 26 12:41:55 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5799
revision-id: v.ladeuil+lp at free.fr-20110526124155-v1h2dow3hocu5u0f
parent: v.ladeuil+lp at free.fr-20110526062716-yisf1nu454175g2q
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-lock-remote
timestamp: Thu 2011-05-26 14:41:55 +0200
message:
Give up.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-05-21 16:14:39 +0000
+++ b/bzrlib/config.py 2011-05-26 12:41:55 +0000
@@ -2386,11 +2386,19 @@
# cannot exist without a branch, it's safe to make it a weakref.
self.branch_ref = weakref.ref(branch)
+ def _get_branch(self):
+ b = self.branch_ref()
+ if b is None:
+ # Programmer error, a branch store can't exist if the branch it
+ # refers to is dead.
+ raise AssertionError('Dead branch ref in %r' % (self,))
+ return b
+
def lock_write(self, token=None):
- return self.branch_ref().lock_write(token)
+ return self._get_branch().lock_write(token)
def unlock(self):
- return self.branch_ref().unlock()
+ return self._get_branch().unlock()
@needs_write_lock
def save(self):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-05-26 06:27:16 +0000
+++ b/bzrlib/tests/test_config.py 2011-05-26 12:41:55 +0000
@@ -2176,6 +2176,21 @@
self.assertPathExists('dir/subdir')
+class TestBranchStore(TestStore):
+
+ def test_dead_branch(self):
+ build_backing_branch(self, 'branch')
+ b = branch.Branch.open('branch')
+ store = config.BranchStore(b)
+ del b
+ # The only reliable way to trigger the error is to explicitly call the
+ # garbage collector.
+ import gc
+ gc.collect()
+ store.get_mutable_section(None).set('foo', 'bar')
+ self.assertRaises(AssertionError, store.save)
+
+
class TestConcurrentStoreUpdates(TestStore):
scenarios = [(key, {'get_stack': builder}) for key, builder
More information about the bazaar-commits
mailing list