Rev 5951: (jameinel) Forget weakref for branch <-> config (Vincent Ladeuil) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 1 12:31:08 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5951 [merge]
revision-id: pqm at pqm.ubuntu.com-20110601123104-ldhru7h1z82ee5xv
parent: pqm at pqm.ubuntu.com-20110601113806-ekutxdri87ratrfg
parent: v.ladeuil+lp at free.fr-20110601090106-j6576yr7gv1xs1fs
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-06-01 12:31:04 +0000
message:
  (jameinel) Forget weakref for branch <-> config (Vincent Ladeuil)
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-05-31 21:08:52 +0000
+++ b/bzrlib/config.py	2011-06-01 12:31:04 +0000
@@ -2415,25 +2415,13 @@
     def __init__(self, branch):
         super(BranchStore, self).__init__(branch.control_transport,
                                           'branch.conf')
-        # We don't want to create a cycle here when the BranchStore becomes
-        # part of an object (roughly a Stack, directly or indirectly) that is
-        # an attribute of the branch object itself. Since the BranchStore
-        # 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
+        self.branch = branch
 
     def lock_write(self, token=None):
-        return self._get_branch().lock_write(token)
+        return self.branch.lock_write(token)
 
     def unlock(self):
-        return self._get_branch().unlock()
+        return self.branch.unlock()
 
     @needs_write_lock
     def save(self):

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-05-31 21:08:52 +0000
+++ b/bzrlib/tests/test_config.py	2011-06-01 12:31:04 +0000
@@ -108,26 +108,9 @@
         test.backing_branch = test.make_branch(relpath)
 
 
-def keep_branch_alive(test, b):
-    """Keep a branch alive for the duration of a test.
-
-    :param tests: the test that should hold the branch alive.
-
-    :param b: the branch that should be kept alive.
-
-    Several tests need to keep a reference to a branch object as they are
-    testing a Store which uses a weak reference. This is achieved by embedding
-    a reference to the branch object in a lambda passed to a cleanup. When the
-    test finish the cleanup method is deleted and so does the reference to the
-    branch.
-    """
-    test.addCleanup(lambda : b)
-
-
 def build_branch_store(test):
     build_backing_branch(test, 'branch')
     b = branch.Branch.open('branch')
-    keep_branch_alive(test, b)
     return config.BranchStore(b)
 config.test_store_builder_registry.register('branch', build_branch_store)
 
@@ -138,7 +121,6 @@
     (transport_class, server_class) = remote.get_test_permutations()[0]
     build_backing_branch(test, 'branch', transport_class, server_class)
     b = branch.Branch.open(test.get_url('branch'))
-    keep_branch_alive(test, b)
     return config.BranchStore(b)
 config.test_store_builder_registry.register('remote_branch',
                                             build_remote_branch_store)
@@ -153,7 +135,6 @@
 def build_branch_stack(test):
     build_backing_branch(test, 'branch')
     b = branch.Branch.open('branch')
-    keep_branch_alive(test, b)
     return config.BranchStack(b)
 config.test_stack_builder_registry.register('branch', build_branch_stack)
 
@@ -164,7 +145,6 @@
     (transport_class, server_class) = remote.get_test_permutations()[0]
     build_backing_branch(test, 'branch', transport_class, server_class)
     b = branch.Branch.open(test.get_url('branch'))
-    keep_branch_alive(test, b)
     return config.BranchStack(b)
 config.test_stack_builder_registry.register('remote_branch',
                                             build_remote_branch_stack)
@@ -2249,21 +2229,6 @@
         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):
     """Test that Stores properly handle conccurent updates.
 




More information about the bazaar-commits mailing list