Rev 6417: Change set/remove to require a lock for the branch config files. in file:///home/vila/src/bzr/experimental/cached-branch-store/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Jan 18 14:09:20 UTC 2012


At file:///home/vila/src/bzr/experimental/cached-branch-store/

------------------------------------------------------------
revno: 6417
revision-id: v.ladeuil+lp at free.fr-20120118140919-rlvdrhpc0nq1lbwi
parent: v.ladeuil+lp at free.fr-20120109205507-2i3en5r4w4ohdchj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: cached-branch-store
timestamp: Wed 2012-01-18 15:09:19 +0100
message:
  Change set/remove to require a lock for the branch config files.
  
  This means that tests (or any plugin for that matter) do not requires an
  explicit lock on the branch anymore to change a single option. This also
  means the optimisation becomes "opt-in" and as such won't be as
  spectacular as it may be and/or harder to get right (nothing fails
  anymore).
  
  This reduces the diff by ~300 lines.
  
  Code/tests that were updating more than one config option is still taking
  a lock to at least avoid some IOs and demonstrate the benefits through
  the decreased number of hpss calls.
  
  The duplication between BranchStack and BranchOnlyStack will be removed
  once the same sharing is in place for local config files, at which point
  the Stack class itself may be able to host the changes.
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/branch.py	2012-01-18 14:09:19 +0000
@@ -3262,11 +3262,7 @@
 
     def convert(self, branch):
         format = BzrBranchFormat7()
-        branch.lock_write()
-        try:
-            branch._set_config_location('stacked_on_location', '')
-        finally:
-            branch.unlock()
+        branch._set_config_location('stacked_on_location', '')
         # update target format
         branch._transport.put_bytes('format', format.as_string())
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/builtins.py	2012-01-18 14:09:19 +0000
@@ -1118,13 +1118,9 @@
             # Remembers if asked explicitly or no previous location is set
             if (remember
                 or (remember is None and branch_to.get_parent() is None)):
-                branch_to.lock_write()
-                try:
-                    # FIXME: This shouldn't be done before the pull
-                    # succeeds... -- vila 2012-01-02
-                    branch_to.set_parent(branch_from.base)
-                finally:
-                    branch_to.unlock()
+                # FIXME: This shouldn't be done before the pull
+                # succeeds... -- vila 2012-01-02
+                branch_to.set_parent(branch_from.base)
 
         if revision is not None:
             revision_id = revision.as_revision_id(branch_from)
@@ -2017,11 +2013,7 @@
                 a_bzrdir.create_workingtree()
         if append_revisions_only:
             try:
-                branch.lock_write()
-                try:
-                    branch.set_append_revisions_only(True)
-                finally:
-                    branch.unlock()
+                branch.set_append_revisions_only(True)
             except errors.UpgradeRequired:
                 raise errors.BzrCommandError(gettext('This branch format cannot be set'
                     ' to append-revisions-only.  Try --default.'))
@@ -5603,11 +5595,7 @@
             public_branch = stored_public_branch
         elif stored_public_branch is None:
             # FIXME: Should be done only if we succeed ? -- vila 2012-01-03
-            branch.lock_write()
-            try:
-                branch.set_public_branch(public_branch)
-            finally:
-                branch.unlock()
+            branch.set_public_branch(public_branch)
         if not include_bundle and public_branch is None:
             raise errors.BzrCommandError(gettext('No public branch specified or'
                                          ' known'))

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/config.py	2012-01-18 14:09:19 +0000
@@ -3875,6 +3875,24 @@
             bstore)
         self.branch = branch
 
+    def lock_write(self, token=None):
+        return self.branch.lock_write(token)
+
+    def unlock(self):
+        return self.branch.unlock()
+
+    @needs_write_lock
+    def set(self, name, value):
+        super(BranchStack, self).set(name, value)
+        # Force a write to persistent storage
+        self.store.save_changes()
+
+    @needs_write_lock
+    def remove(self, name):
+        super(BranchStack, self).remove(name)
+        # Force a write to persistent storage
+        self.store.save_changes()
+
 
 class RemoteControlStack(_CompatibleStack):
     """Remote control-only options stack."""
@@ -3905,6 +3923,24 @@
             bstore)
         self.branch = branch
 
+    def lock_write(self, token=None):
+        return self.branch.lock_write(token)
+
+    def unlock(self):
+        return self.branch.unlock()
+
+    @needs_write_lock
+    def set(self, name, value):
+        super(BranchOnlyStack, self).set(name, value)
+        # Force a write to persistent storage
+        self.store.save_changes()
+
+    @needs_write_lock
+    def remove(self, name):
+        super(BranchOnlyStack, self).remove(name)
+        # Force a write to persistent storage
+        self.store.save_changes()
+
 
 # Use a an empty dict to initialize an empty configobj avoiding all
 # parsing and encoding checks

=== modified file 'bzrlib/controldir.py'
--- a/bzrlib/controldir.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/controldir.py	2012-01-18 14:09:19 +0000
@@ -394,11 +394,8 @@
             repository_to.fetch(source.repository, revision_id=revision_id)
             br_to = source.clone(self, revision_id=revision_id)
             if source.get_push_location() is None or remember:
-                source.lock_write()
-                try:
-                    source.set_push_location(br_to.base)
-                finally:
-                    source.unlock()
+                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
+                source.set_push_location(br_to.base)
             push_result.stacked_on = None
             push_result.branch_push_result = None
             push_result.old_revno = None
@@ -409,11 +406,8 @@
         else:
             # We have successfully opened the branch, remember if necessary:
             if source.get_push_location() is None or remember:
-                source.lock_write()
-                try:
-                    source.set_push_location(br_to.base)
-                finally:
-                    source.unlock()
+                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
+                source.set_push_location(br_to.base)
             try:
                 tree_to = self.open_workingtree()
             except errors.NotLocalUrl:

=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/foreign.py	2012-01-18 14:09:19 +0000
@@ -323,11 +323,8 @@
                     source_branch, target_branch))
             # We successfully created the target, remember it
             if source_branch.get_push_location() is None or remember:
-                source_branch.lock_write()
-                try:
-                    source_branch.set_push_location(target_branch.base)
-                finally:
-                    source_branch.unlock()
+                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
+                source_branch.set_push_location(target_branch.base)
             if not no_rebase:
                 old_last_revid = source_branch.last_revision()
                 source_branch.pull(target_branch, overwrite=True)

=== modified file 'bzrlib/plugins/launchpad/test_lp_open.py'
--- a/bzrlib/plugins/launchpad/test_lp_open.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_open.py	2012-01-18 14:09:19 +0000
@@ -44,23 +44,14 @@
     def test_non_launchpad_branch(self):
         branch = self.make_branch('non-lp')
         url = 'http://example.com/non-lp'
-        branch.lock_write()
-        try:
-            branch.set_public_branch(url)
-        finally:
-            branch.unlock()
+        branch.set_public_branch(url)
         self.assertEqual(
             ['bzr: ERROR: %s is not registered on Launchpad.' % url],
             self.run_open('non-lp', retcode=3))
 
     def test_launchpad_branch_with_public_location(self):
         branch = self.make_branch('lp')
-        branch.lock_write()
-        try:
-            branch.set_public_branch(
-                'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
-        finally:
-            branch.unlock()
+        branch.set_public_branch('bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
         self.assertEqual(
             ['Opening https://code.launchpad.net/~foo/bar/baz in web '
              'browser'],
@@ -85,12 +76,7 @@
         # lp-open falls back to the push location if it cannot find a public
         # location.
         branch = self.make_branch('lp')
-        branch.lock_write()
-        try:
-            branch.set_push_location(
-                'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
-        finally:
-            branch.unlock()
+        branch.set_push_location('bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
         self.assertEqual(
             ['Opening https://code.launchpad.net/~foo/bar/baz in web '
              'browser'],
@@ -108,12 +94,8 @@
     def test_launchpad_branch_subdirectory(self):
         # lp-open in a subdirectory of a registered branch should work
         wt = self.make_branch_and_tree('lp')
-        wt.branch.lock_write()
-        try:
-            wt.branch.set_push_location(
-                'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
-        finally:
-            wt.branch.unlock()
+        wt.branch.set_push_location(
+            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
         self.build_tree(['lp/a/'])
         self.assertEqual(
             ['Opening https://code.launchpad.net/~foo/bar/baz in web '

=== modified file 'bzrlib/plugins/launchpad/test_register.py'
--- a/bzrlib/plugins/launchpad/test_register.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/plugins/launchpad/test_register.py	2012-01-18 14:09:19 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2012 Canonical Ltd
+# Copyright (C) 2006-2011 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -175,11 +175,7 @@
 
     def test_register_no_url_in_published_branch_no_error(self):
         b = self.make_branch('.')
-        b.lock_write()
-        try:
-            b.set_public_branch('http://test-server.com/bzr/branch')
-        finally:
-            b.unlock()
+        b.set_public_branch('http://test-server.com/bzr/branch')
         out, err = self.run_bzr(['register-branch', '--dry-run'])
         self.assertEqual('Branch registered.\n', out)
         self.assertEqual('', err)

=== modified file 'bzrlib/push.py'
--- a/bzrlib/push.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/push.py	2012-01-18 14:09:19 +0000
@@ -135,11 +135,8 @@
         # Remembers if asked explicitly or no previous location is set
         if (remember
             or (remember is None and br_from.get_push_location() is None)):
-            br_from.lock_write()
-            try:
-                br_from.set_push_location(br_to.base)
-            finally:
-                br_from.unlock()
+            # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
+            br_from.set_push_location(br_to.base)
     else:
         if stacked_on is not None:
             warning("Ignoring request for a stacked branch as repository "

=== modified file 'bzrlib/tests/blackbox/test_add.py'
--- a/bzrlib/tests/blackbox/test_add.py	2012-01-05 17:56:30 +0000
+++ b/bzrlib/tests/blackbox/test_add.py	2012-01-18 14:09:19 +0000
@@ -247,11 +247,7 @@
         self.build_tree_contents([('small.txt', '0\n')])
         self.build_tree_contents([('big.txt', '01234567890123456789\n')])
         self.build_tree_contents([('big2.txt', '01234567890123456789\n')])
-        tree.branch.lock_write()
-        try:
-            tree.branch.get_config_stack().set('add.maximum_file_size', 5)
-        finally:
-            tree.branch.unlock()
+        tree.branch.get_config_stack().set('add.maximum_file_size', 5)
         out = self.run_bzr('add')[0]
         results = sorted(out.rstrip('\n').split('\n'))
         self.assertEquals(['adding small.txt'], results)
@@ -260,11 +256,7 @@
         results = sorted(out.rstrip('\n').split('\n'))
         self.assertEquals(['adding big2.txt'], results)
         self.assertEquals("", err)
-        tree.branch.lock_write()
-        try:
-            tree.branch.get_config_stack().set('add.maximum_file_size', 30)
-        finally:
-            tree.branch.unlock()
+        tree.branch.get_config_stack().set('add.maximum_file_size', 30)
         out = self.run_bzr('add')[0]
         results = sorted(out.rstrip('\n').split('\n'))
         self.assertEquals(['adding big.txt'], results)

=== modified file 'bzrlib/tests/blackbox/test_bound_branches.py'
--- a/bzrlib/tests/blackbox/test_bound_branches.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/blackbox/test_bound_branches.py	2012-01-18 14:09:19 +0000
@@ -132,6 +132,7 @@
         # Double binding succeeds, but committing to child2 should fail
         self.run_bzr('bind ../child', working_dir='child2')
 
+        # Refresh the child tree object as 'unbind' modified it
         child2_tree = bzrdir.BzrDir.open('child2').open_workingtree()
         self.assertRaises(errors.CommitToDoubleBoundBranch,
                 child2_tree.commit, message='child2', allow_pointless=True)

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2012-01-05 17:56:30 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2012-01-18 14:09:19 +0000
@@ -334,11 +334,7 @@
         builder = self.make_branch_builder('source')
         source = fixtures.build_branch_with_non_ancestral_rev(builder)
         source.tags.set_tag('tag-a', 'rev-2')
-        source.lock_write()
-        try:
-            source.get_config_stack().set('branch.fetch_tags', True)
-        finally:
-            source.unlock()
+        source.get_config_stack().set('branch.fetch_tags', True)
         # Now source has a tag not in its ancestry.  Make a branch from it.
         self.run_bzr('branch source new-branch')
         new_branch = branch.Branch.open('new-branch')

=== modified file 'bzrlib/tests/blackbox/test_dpush.py'
--- a/bzrlib/tests/blackbox/test_dpush.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/tests/blackbox/test_dpush.py	2012-01-18 14:09:19 +0000
@@ -146,12 +146,7 @@
 
     def set_config_push_strict(self, value):
         br = branch.Branch.open('local')
-        br.lock_write()
-        try:
-            conf = br.get_config_stack()
-            conf.set('dpush_strict', value)
-        finally:
-            br.unlock()
+        br.get_config_stack().set('dpush_strict', value)
 
     _default_command = ['dpush', '../to']
 

=== modified file 'bzrlib/tests/blackbox/test_merge_directive.py'
--- a/bzrlib/tests/blackbox/test_merge_directive.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/blackbox/test_merge_directive.py	2012-01-18 14:09:19 +0000
@@ -44,12 +44,8 @@
     def prepare_merge_directive(self):
         self.tree1 = self.make_branch_and_tree('tree1')
         self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\n')])
-        self.tree1.branch.lock_write()
-        try:
-            self.tree1.branch.get_config_stack().set(
-                'email', 'J. Random Hacker <jrandom at example.com>')
-        finally:
-            self.tree1.branch.unlock()
+        self.tree1.branch.get_config_stack().set(
+            'email', 'J. Random Hacker <jrandom at example.com>')
         self.tree1.add('file')
         self.tree1.commit('foo', rev_id='foo-id')
         self.tree2 = self.tree1.bzrdir.sprout('tree2').open_workingtree()
@@ -228,11 +224,7 @@
     def test_mail_uses_config(self):
         tree1, tree2 = self.prepare_merge_directive()
         br = tree1.branch
-        br.lock_write()
-        try:
-            br.get_config_stack().set('smtp_server', 'bogushost')
-        finally:
-            br.unlock()
+        br.get_config_stack().set('smtp_server', 'bogushost')
         md_text, errr, connect_calls, sendmail_calls =\
             self.run_bzr_fakemail('merge-directive --mail-to'
                                   ' pqm at example.com --plain ../tree2 .')

=== modified file 'bzrlib/tests/blackbox/test_pull.py'
--- a/bzrlib/tests/blackbox/test_pull.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/blackbox/test_pull.py	2012-01-18 14:09:19 +0000
@@ -144,11 +144,7 @@
         # Make a source, sprout a target off it
         builder = self.make_branch_builder('source')
         source = fixtures.build_branch_with_non_ancestral_rev(builder)
-        source.lock_write()
-        try:
-            source.get_config_stack().set('branch.fetch_tags', True)
-        finally:
-            source.unlock()
+        source.get_config_stack().set('branch.fetch_tags', True)
         target_bzrdir = source.bzrdir.sprout('target')
         source.tags.set_tag('tag-a', 'rev-2')
         # Pull from source
@@ -241,11 +237,7 @@
         # reset parent
         parent = branch_b.get_parent()
         branch_b = branch.Branch.open('branch_b')
-        branch_b.lock_write()
-        try:
-            branch_b.set_parent(None)
-        finally:
-            branch_b.unlock()
+        branch_b.set_parent(None)
         self.assertEqual(None, branch_b.get_parent())
         # test pull for failure without parent set
         out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
@@ -375,11 +367,7 @@
     def test_pull_verbose_uses_default_log(self):
         tree = self.example_branch('source')
         target = self.make_branch_and_tree('target')
-        target.branch.lock_write()
-        try:
-            target.branch.get_config_stack().set('log_format', 'short')
-        finally:
-            target.branch.unlock()
+        target.branch.get_config_stack().set('log_format', 'short')
         out = self.run_bzr('pull -v source -d target')[0]
         self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
         self.assertNotContainsRe(

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2012-01-18 14:09:19 +0000
@@ -514,11 +514,7 @@
         trunk_public.pull(trunk_tree.branch)
         trunk_public_url = self.get_readonly_url('public_trunk')
         br = trunk_tree.branch
-        br.lock_write()
-        try:
-            br.set_public_branch(trunk_public_url)
-        finally:
-            br.unlock()
+        br.set_public_branch(trunk_public_url)
         # now we do a stacked push, which should determine the public location
         # for us.
         out, err = self.run_bzr(['push', '--stacked',
@@ -716,12 +712,7 @@
 
     def set_config_push_strict(self, value):
         br = branch.Branch.open('local')
-        br.lock_write()
-        try:
-            conf = br.get_config_stack()
-            conf.set('push_strict', value)
-        finally:
-            br.unlock()
+        br.get_config_stack().set('push_strict', value)
 
     _default_command = ['push', '../to']
     _default_wd = 'local'

=== modified file 'bzrlib/tests/blackbox/test_send.py'
--- a/bzrlib/tests/blackbox/test_send.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/blackbox/test_send.py	2012-01-18 14:09:19 +0000
@@ -230,19 +230,11 @@
     def test_format_child_option(self):
         br = branch.Branch.open('parent')
         conf = br.get_config_stack()
-        br.lock_write()
-        try:
-            conf.set('child_submit_format', '4')
-        finally:
-            br.unlock()
+        conf.set('child_submit_format', '4')
         md = self.get_MD([])
         self.assertIs(merge_directive.MergeDirective2, md.__class__)
 
-        br.lock_write()
-        try:
-            conf.set('child_submit_format', '0.9')
-        finally:
-            br.unlock()
+        conf.set('child_submit_format', '0.9')
         md = self.get_MD([])
         self.assertFormatIs('# Bazaar revision bundle v0.9', md)
 
@@ -250,11 +242,7 @@
         self.assertFormatIs('# Bazaar revision bundle v0.9', md)
         self.assertIs(merge_directive.MergeDirective, md.__class__)
 
-        br.lock_write()
-        try:
-            conf.set('child_submit_format', '0.999')
-        finally:
-            br.unlock()
+        conf.set('child_submit_format', '0.999')
         self.run_bzr_error(["No such send format '0.999'"],
                             'send -f branch -o-')[0]
 
@@ -305,11 +293,7 @@
 
     def set_config_send_strict(self, value):
         br = branch.Branch.open('local')
-        br.lock_write()
-        try:
-            br.get_config_stack().set('send_strict', value)
-        finally:
-            br.unlock()
+        br.get_config_stack().set('send_strict', value)
 
     def assertSendFails(self, args):
         out, err = self.run_send(args, rc=3, err_re=self._default_errors)

=== modified file 'bzrlib/tests/blackbox/test_whoami.py'
--- a/bzrlib/tests/blackbox/test_whoami.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/blackbox/test_whoami.py	2012-01-18 14:09:19 +0000
@@ -52,11 +52,7 @@
         self.assertEquals("", out)
 
     def set_branch_email(self, b, email):
-        b.lock_write()
-        try:
-            b.get_config_stack().set('email', email)
-        finally:
-            b.unlock()
+        b.get_config_stack().set('email', email)
 
     def test_whoami_branch(self):
         """branch specific user identity works."""

=== modified file 'bzrlib/tests/per_branch/test_branch.py'
--- a/bzrlib/tests/per_branch/test_branch.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/tests/per_branch/test_branch.py	2012-01-18 14:09:19 +0000
@@ -205,7 +205,6 @@
     def test_public_branch(self):
         """public location can be queried and set"""
         branch = self.make_branch('branch')
-        self.addCleanup(branch.lock_write().unlock)
         self.assertEqual(branch.get_public_branch(), None)
         branch.set_public_branch('sftp://example.com')
         self.assertEqual(branch.get_public_branch(), 'sftp://example.com')
@@ -349,7 +348,6 @@
 
     def test_get_set_append_revisions_only(self):
         branch = self.make_branch('.')
-        self.addCleanup(branch.lock_write().unlock)
         if branch._format.supports_set_append_revisions_only():
             branch.set_append_revisions_only(True)
             self.assertTrue(branch.get_append_revisions_only())
@@ -640,7 +638,6 @@
 
     def test_set_push_location(self):
         branch = self.get_branch()
-        self.addCleanup(branch.lock_write().unlock)
         branch.set_push_location('foo')
         self.assertEqual('foo', branch.get_push_location())
 
@@ -654,7 +651,6 @@
 
     def test_get_child_submit_format(self):
         branch = self.get_branch()
-        self.addCleanup(branch.lock_write().unlock)
         branch.get_config_stack().set('child_submit_format', '10')
         branch = self.get_branch()
         self.assertEqual('10', branch.get_child_submit_format())
@@ -815,11 +811,7 @@
     def test_strict_history(self):
         tree1 = self.make_branch_and_tree('tree1')
         try:
-            tree1.branch.lock_write()
-            try:
-                tree1.branch.set_append_revisions_only(True)
-            finally:
-                tree1.branch.unlock()
+            tree1.branch.set_append_revisions_only(True)
         except errors.UpgradeRequired:
             raise tests.TestSkipped('Format does not support strict history')
         tree1.commit('empty commit')

=== modified file 'bzrlib/tests/per_branch/test_break_lock.py'
--- a/bzrlib/tests/per_branch/test_break_lock.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/tests/per_branch/test_break_lock.py	2012-01-18 14:09:19 +0000
@@ -79,11 +79,7 @@
         # unlock it.
         master = self.make_branch('master')
         try:
-            self.branch.lock_write()
-            try:
-                self.branch.bind(master)
-            finally:
-                self.branch.unlock()
+            self.branch.bind(master)
         except errors.UpgradeRequired:
             # this branch does not support binding.
             return

=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
--- a/bzrlib/tests/per_controldir/test_controldir.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/tests/per_controldir/test_controldir.py	2012-01-18 14:09:19 +0000
@@ -746,11 +746,7 @@
             source.tags.set_tag('tag-a', 'rev-2')
         except errors.TagsNotSupported:
             raise TestNotApplicable('Branch format does not support tags.')
-        source.lock_write()
-        try:
-            source.get_config_stack().set('branch.fetch_tags', True)
-        finally:
-            source.unlock()
+        source.get_config_stack().set('branch.fetch_tags', True)
         # Now source has a tag not in its ancestry.  Sprout its controldir.
         dir = source.bzrdir
         target = dir.sprout(self.get_url('target'))
@@ -829,11 +825,7 @@
             has_ghost_tag = False
         else:
             has_ghost_tag = True
-        source.lock_write()
-        try:
-            source.get_config_stack().set('branch.fetch_tags', True)
-        finally:
-            source.unlock()
+        source.get_config_stack().set('branch.fetch_tags', True)
         # And ask sprout for C2
         dir = source.bzrdir
         target = dir.sprout(self.get_url('target'), revision_id='rev-c2')

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/tests/test_branch.py	2012-01-18 14:09:19 +0000
@@ -352,7 +352,6 @@
     def test_config(self):
         """Ensure that all configuration data is stored in the branch"""
         branch = self.make_branch('a', format=self.get_format_name())
-        self.addCleanup(branch.lock_write().unlock)
         branch.set_parent('http://example.com')
         self.assertPathDoesNotExist('a/.bzr/branch/parent')
         self.assertEqual('http://example.com', branch.get_parent())
@@ -667,11 +666,7 @@
     def check_append_revisions_only(self, expected_value, value=None):
         """Set append_revisions_only in config and check its interpretation."""
         if value is not None:
-            self.branch.lock_write()
-            try:
-                self.config_stack.set('append_revisions_only', value)
-            finally:
-                self.branch.unlock()
+            self.config_stack.set('append_revisions_only', value)
         self.assertEqual(expected_value,
                          self.branch.get_append_revisions_only())
 

=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/tests/test_commit.py	2012-01-18 14:09:19 +0000
@@ -502,11 +502,7 @@
         master.create_workingtree()
         bound = master.sprout('bound')
         wt = bound.open_workingtree()
-        wt.branch.lock_write()
-        try:
-            wt.branch.set_bound_location(os.path.realpath('master'))
-        finally:
-            wt.branch.unlock()
+        wt.branch.set_bound_location(os.path.realpath('master'))
         master_branch.lock_write()
         try:
             self.assertRaises(LockContention, wt.commit, 'silly')

=== modified file 'bzrlib/tests/test_directory_service.py'
--- a/bzrlib/tests/test_directory_service.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/tests/test_directory_service.py	2012-01-18 14:09:19 +0000
@@ -70,11 +70,7 @@
         self.branch = self.make_branch('.')
 
     def assertAliasFromBranch(self, setter, value, alias):
-        self.branch.lock_write()
-        try:
-            setter(value)
-        finally:
-            self.branch.unlock()
+        setter(value)
         self.assertEquals(value, directories.dereference(alias))
 
     def test_lookup_parent(self):

=== modified file 'bzrlib/tests/test_merge_directive.py'
--- a/bzrlib/tests/test_merge_directive.py	2012-01-09 20:55:07 +0000
+++ b/bzrlib/tests/test_merge_directive.py	2012-01-18 14:09:19 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, 2008, 2009, 2011, 2012 Canonical Ltd
+# Copyright (C) 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -423,11 +423,7 @@
         md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 144,
             tree_b.branch.base, patch_type=None, public_branch=branch_c.base)
         self.assertEqual(md.target_branch, tree_b.branch.base)
-        tree_b.branch.lock_write()
-        try:
-            tree_b.branch.set_public_branch('http://example.com')
-        finally:
-            tree_b.branch.unlock()
+        tree_b.branch.set_public_branch('http://example.com')
         md2 = self.from_objects(
               tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
               patch_type=None, public_branch=branch_c.base)

=== modified file 'bzrlib/tests/test_reconfigure.py'
--- a/bzrlib/tests/test_reconfigure.py	2012-01-05 14:26:58 +0000
+++ b/bzrlib/tests/test_reconfigure.py	2012-01-18 14:09:19 +0000
@@ -147,19 +147,11 @@
         reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
         self.assertRaises(errors.NoBindLocation,
                           reconfiguration._select_bind_location)
-        branch.lock_write()
-        try:
-            branch.set_parent('http://parent')
-        finally:
-            branch.unlock()
+        branch.set_parent('http://parent')
         reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
         self.assertEqual('http://parent',
                          reconfiguration._select_bind_location())
-        branch.lock_write()
-        try:
-            branch.set_push_location('sftp://push')
-        finally:
-            branch.unlock()
+        branch.set_push_location('sftp://push')
         reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
         self.assertEqual('sftp://push',
                          reconfiguration._select_bind_location())
@@ -172,11 +164,7 @@
         reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
         self.assertEqual('bzr://foo/old-bound',
                          reconfiguration._select_bind_location())
-        branch.lock_write()
-        try:
-            branch.set_bound_location('bzr://foo/cur-bound')
-        finally:
-            branch.unlock()
+        branch.set_bound_location('bzr://foo/cur-bound')
         reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
         self.assertEqual('bzr://foo/cur-bound',
                          reconfiguration._select_bind_location())
@@ -200,11 +188,7 @@
         reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
         self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
         # setting a parent allows it to become a checkout
-        tree.branch.lock_write()
-        try:
-            tree.branch.set_parent(parent.base)
-        finally:
-            tree.branch.unlock()
+        tree.branch.set_parent(parent.base)
         reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
         reconfiguration.apply()
         # supplying a location allows it to become a checkout
@@ -223,11 +207,7 @@
             tree.bzrdir)
         self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
         # setting a parent allows it to become a checkout
-        tree.branch.lock_write()
-        try:
-            tree.branch.set_parent(parent.base)
-        finally:
-            tree.branch.unlock()
+        tree.branch.set_parent(parent.base)
         reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
             tree.bzrdir)
         reconfiguration.apply()

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2012-01-05 15:54:17 +0000
+++ b/bzrlib/tests/test_remote.py	2012-01-18 14:09:19 +0000
@@ -1273,11 +1273,7 @@
         self.reset_smart_call_log()
         verb = 'Branch.set_parent_location'
         self.disable_verb(verb)
-        branch.lock_write()
-        try:
-            branch.set_parent('http://foo/')
-        finally:
-            branch.unlock()
+        branch.set_parent('http://foo/')
         self.assertLength(14, self.hpss_calls)
 
 
@@ -1438,11 +1434,7 @@
 
     def test_backwards_compatible(self):
         br = self.make_branch_with_tags()
-        br.lock_write()
-        try:
-            br.get_config_stack().set('branch.fetch_tags', True)
-        finally:
-            br.unlock()
+        br.get_config_stack().set('branch.fetch_tags', True)
         self.addCleanup(br.lock_read().unlock)
         # Disable the heads_to_fetch verb
         verb = 'Branch.heads_to_fetch'
@@ -1456,11 +1448,7 @@
 
     def test_backwards_compatible_no_tags(self):
         br = self.make_branch_with_tags()
-        br.lock_write()
-        try:
-            br.get_config_stack().set('branch.fetch_tags', False)
-        finally:
-            br.unlock()
+        br.get_config_stack().set('branch.fetch_tags', False)
         self.addCleanup(br.lock_read().unlock)
         # Disable the heads_to_fetch verb
         verb = 'Branch.heads_to_fetch'
@@ -4151,12 +4139,8 @@
         self.bound_location = self.checkout.branch.get_bound_location()
 
     def assertUpdateSucceeds(self, new_location):
-        self.checkout.lock_write()
-        try:
-            self.checkout.branch.set_bound_location(new_location)
-            self.checkout.update()
-        finally:
-            self.checkout.unlock()
+        self.checkout.branch.set_bound_location(new_location)
+        self.checkout.update()
         self.assertEquals(self.last_revid, self.checkout.last_revision())
 
     def test_without_final_slash(self):



More information about the bazaar-commits mailing list