Rev 4232: Set branch config options via a smart method. in http://people.ubuntu.com/~robertc/baz2.0/pending/RemoteBranchConfig

Robert Collins robertc at robertcollins.net
Thu Apr 2 06:22:47 BST 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/RemoteBranchConfig

------------------------------------------------------------
revno: 4232
revision-id: robertc at robertcollins.net-20090402052242-k2u70zdxabxwh2il
parent: robertc at robertcollins.net-20090402033730-i0qrdiqnldwqke02
committer: Robert Collins <robertc at robertcollins.net>
branch nick: RemoteBranchConfig
timestamp: Thu 2009-04-02 16:22:42 +1100
message:
  Set branch config options via a smart method.
=== modified file 'NEWS'
--- a/NEWS	2009-04-02 03:37:30 +0000
+++ b/NEWS	2009-04-02 05:22:42 +0000
@@ -275,6 +275,11 @@
   handle existing svn properties that define a list of keywords to be
   expanded.  (Ian Clatworthy)
 
+* ``RemoteBranchConfig`` will use a new verb ``Branch.set_config_option``
+  to write config settings to smart servers that support this, saving
+  5 round trips on the stacked streaming acceptance test.
+  (Robert Collins, Andrew Bennetts)
+
 * ``RemoteBranch`` now provides ``_get_config`` for access to just the
   branch specific configuration from a remote server, which uses the 
   already existing ``Branch.get_config_file`` smart verb.

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2009-04-02 03:37:30 +0000
+++ b/bzrlib/remote.py	2009-04-02 05:22:42 +0000
@@ -2389,8 +2389,7 @@
         return section_obj.get(name, default)
 
     def _get_configobj(self):
-        path = self._branch.bzrdir._path_for_remote_call(
-            self._branch._client)
+        path = self._branch._remote_path()
         response = self._branch._client.call_expecting_body(
             'Branch.get_config_file', path)
         if response[0][0] != 'ok':
@@ -2405,7 +2404,19 @@
         :param name: The name of the value to set
         :param section: The section the option is in (if any)
         """
-        return self._vfs_set_option(value, name, section)
+        medium = self._branch._client._medium
+        if medium._is_remote_before((1, 14)):
+            return self._vfs_set_option(value, name, section)
+        try:
+            path = self._branch._remote_path()
+            response = self._branch._client.call('Branch.set_config_option',
+                path, self._branch._lock_token, self._branch._repo_lock_token,
+                value, name, section or '')
+        except errors.UnknownSmartMethod:
+            medium._remember_remote_is_before((1, 14))
+            return self._vfs_set_option(value, name, section)
+        if response != ():
+            raise errors.UnexpectedSmartServerResponse(response)
 
     def _vfs_set_option(self, value, name, section=None):
         self._branch._ensure_real()

=== modified file 'bzrlib/smart/branch.py'
--- a/bzrlib/smart/branch.py	2009-04-02 03:37:30 +0000
+++ b/bzrlib/smart/branch.py	2009-04-02 05:22:42 +0000
@@ -148,6 +148,16 @@
             return FailedSmartServerResponse(('TipChangeRejected', msg))
 
 
+class SmartServerBranchRequestSetConfigOption(SmartServerLockedBranchRequest):
+    """Set an option in the branch configuration."""
+
+    def do_with_locked_branch(self, branch, value, name, section):
+        if not section:
+            section = None
+        branch._get_config().set_option(value, name, section)
+        return SuccessfulSmartServerResponse(())
+
+
 class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
 
     def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2009-03-26 06:59:15 +0000
+++ b/bzrlib/smart/request.py	2009-04-02 05:22:42 +0000
@@ -448,10 +448,12 @@
     'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')
 request_handlers.register_lazy(
     'Branch.lock_write', 'bzrlib.smart.branch', 'SmartServerBranchRequestLockWrite')
-request_handlers.register_lazy(
-    'Branch.revision_history', 'bzrlib.smart.branch', 'SmartServerRequestRevisionHistory')
-request_handlers.register_lazy(
-    'Branch.set_last_revision', 'bzrlib.smart.branch', 'SmartServerBranchRequestSetLastRevision')
+request_handlers.register_lazy( 'Branch.revision_history',
+    'bzrlib.smart.branch', 'SmartServerRequestRevisionHistory')
+request_handlers.register_lazy( 'Branch.set_config_option',
+    'bzrlib.smart.branch', 'SmartServerBranchRequestSetConfigOption')
+request_handlers.register_lazy( 'Branch.set_last_revision',
+    'bzrlib.smart.branch', 'SmartServerBranchRequestSetLastRevision')
 request_handlers.register_lazy(
     'Branch.set_last_revision_info', 'bzrlib.smart.branch',
     'SmartServerBranchRequestSetLastRevisionInfo')

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2009-04-02 03:37:30 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2009-04-02 05:22:42 +0000
@@ -272,7 +272,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(52, self.hpss_calls)
+        self.assertLength(53, self.hpss_calls)
 
     def test_branch_from_trivial_branch_streaming_acceptance(self):
         self.setup_smart_server_with_call_log()

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2009-04-02 03:37:30 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-04-02 05:22:42 +0000
@@ -201,7 +201,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(18, self.hpss_calls)
+        self.assertLength(20, self.hpss_calls)
 
     def test_push_smart_stacked_streaming_acceptance(self):
         self.setup_smart_server_with_call_log()
@@ -217,7 +217,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(47, self.hpss_calls)
+        self.assertLength(42, self.hpss_calls)
         remote = Branch.open('public')
         self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
 

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2009-04-02 03:37:30 +0000
+++ b/bzrlib/tests/test_remote.py	2009-04-02 05:22:42 +0000
@@ -1332,16 +1332,9 @@
         self.assertEqual('rejection message', err.msg)
 
 
-class TestBranchControlGetBranchConf(RemoteBranchTestCase):
-    """Getting the branch configuration should use an abstract method not vfs.
-    """
+class TestBranchGetSetConfig(RemoteBranchTestCase):
 
     def test_get_branch_conf(self):
-        # We should see that branch.get_config() does a single rpc to get the
-        # remote configuration file, abstracting away where that is stored on
-        # the server.  However at the moment it always falls back to using the
-        # vfs, and this would need some changes in config.py.
-
         # in an empty branch we decode the response properly
         client = FakeClient()
         client.add_expected_call(
@@ -1357,6 +1350,41 @@
              ('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
             client._calls)
 
+    def test_set_option(self):
+        client = FakeClient()
+        client.add_expected_call(
+            'Branch.get_stacked_on_url', ('memory:///',),
+            'error', ('NotStacked',),)
+        client.add_expected_call(
+            'Branch.lock_write', ('memory:///', '', ''),
+            'success', ('ok', 'branch token', 'repo token'))
+        client.add_expected_call(
+            'Branch.set_config_option', ('memory:///', 'branch token',
+            'repo token', 'foo', 'bar', ''),
+            'success', ())
+        client.add_expected_call(
+            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
+            'success', ('ok',))
+        transport = MemoryTransport()
+        branch = self.make_remote_branch(transport, client)
+        branch.lock_write()
+        config = branch._get_config()
+        config.set_option('foo', 'bar')
+        branch.unlock()
+        client.finished_test()
+
+    def test_backwards_compat_set_option(self):
+        self.setup_smart_server_with_call_log()
+        branch = self.make_branch('.')
+        verb = 'Branch.set_config_option'
+        self.disable_verb(verb)
+        branch.lock_write()
+        self.addCleanup(branch.unlock)
+        self.reset_smart_call_log()
+        branch._get_config().set_option('value', 'name')
+        self.assertLength(10, self.hpss_calls)
+        self.assertEqual('value', branch._get_config().get_option('name'))
+
 
 class TestBranchLockWrite(RemoteBranchTestCase):
 

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2009-03-24 23:19:12 +0000
+++ b/bzrlib/tests/test_smart.py	2009-04-02 05:22:42 +0000
@@ -502,7 +502,41 @@
             request.execute(''))
 
 
-class SetLastRevisionTestBase(tests.TestCaseWithMemoryTransport):
+class TestLockedBranch(tests.TestCaseWithMemoryTransport):
+
+    def get_lock_tokens(self, branch):
+        branch_token = branch.lock_write()
+        repo_token = branch.repository.lock_write()
+        branch.repository.unlock()
+        return branch_token, repo_token
+
+
+class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
+
+    def test_value_name(self):
+        branch = self.make_branch('.')
+        request = smart.branch.SmartServerBranchRequestSetConfigOption(
+            branch.bzrdir.root_transport)
+        branch_token, repo_token = self.get_lock_tokens(branch)
+        config = branch._get_config()
+        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
+            '')
+        self.assertEqual(SuccessfulSmartServerResponse(()), result)
+        self.assertEqual('bar', config.get_option('foo'))
+
+    def test_value_name_section(self):
+        branch = self.make_branch('.')
+        request = smart.branch.SmartServerBranchRequestSetConfigOption(
+            branch.bzrdir.root_transport)
+        branch_token, repo_token = self.get_lock_tokens(branch)
+        config = branch._get_config()
+        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
+            'gam')
+        self.assertEqual(SuccessfulSmartServerResponse(()), result)
+        self.assertEqual('bar', config.get_option('foo', 'gam'))
+
+
+class SetLastRevisionTestBase(TestLockedBranch):
     """Base test case for verbs that implement set_last_revision."""
 
     def setUp(self):
@@ -512,11 +546,7 @@
         self.tree = self.make_branch_and_memory_tree('.')
 
     def lock_branch(self):
-        b = self.tree.branch
-        branch_token = b.lock_write()
-        repo_token = b.repository.lock_write()
-        b.repository.unlock()
-        return branch_token, repo_token
+        return self.get_lock_tokens(self.tree.branch)
 
     def unlock_branch(self):
         self.tree.branch.unlock()
@@ -1377,6 +1407,9 @@
             smart.request.request_handlers.get('Branch.revision_history'),
             smart.branch.SmartServerRequestRevisionHistory)
         self.assertEqual(
+            smart.request.request_handlers.get('Branch.set_config_option'),
+            smart.branch.SmartServerBranchRequestSetConfigOption)
+        self.assertEqual(
             smart.request.request_handlers.get('Branch.set_last_revision'),
             smart.branch.SmartServerBranchRequestSetLastRevision)
         self.assertEqual(




More information about the bazaar-commits mailing list