Rev 5807: Merge config-options into config-editor-option in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri May 27 21:47:12 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5807 [merge]
revision-id: v.ladeuil+lp at free.fr-20110527214712-4nxryc2mdnp92s3i
parent: v.ladeuil+lp at free.fr-20110525144722-b6yivw52ltj6atuo
parent: v.ladeuil+lp at free.fr-20110527214711-1511xj8t2b706g4n
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-editor-option
timestamp: Fri 2011-05-27 23:47:12 +0200
message:
  Merge config-options into config-editor-option
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-05-21 16:17:56 +0000
+++ b/bzrlib/config.py	2011-05-27 21:47:12 +0000
@@ -2419,11 +2419,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-21 16:17:56 +0000
+++ b/bzrlib/tests/test_config.py	2011-05-27 21:47:12 +0000
@@ -2111,6 +2111,8 @@
         return self.transport.has(store_basename)
 
     def test_save_empty_creates_no_file(self):
+        # FIXME: There should be a better way than relying on the test
+        # parametrization to identify branch.conf -- vila 2011-0526
         if self.store_id in ('branch', 'remote_branch'):
             raise tests.TestNotApplicable(
                 'branch.conf is *always* created when a branch is initialized')
@@ -2130,6 +2132,8 @@
         self.assertLength(0, sections)
 
     def test_save_with_content_succeeds(self):
+        # FIXME: There should be a better way than relying on the test
+        # parametrization to identify branch.conf -- vila 2011-0526
         if self.store_id in ('branch', 'remote_branch'):
             raise tests.TestNotApplicable(
                 'branch.conf is *always* created when a branch is initialized')
@@ -2237,6 +2241,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