Rev 4290: Create a server verb for doing BzrDir.get_config() in http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips

Robert Collins robertc at robertcollins.net
Tue Apr 14 05:33:56 BST 2009


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

------------------------------------------------------------
revno: 4290
revision-id: robertc at robertcollins.net-20090414043341-wirhw8dgd28nmcq1
parent: robertc at robertcollins.net-20090414023507-935t0u7ab2rt7kfk
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Tue 2009-04-14 14:33:41 +1000
message:
  Create a server verb for doing BzrDir.get_config()
=== modified file 'NEWS'
--- a/NEWS	2009-04-14 02:35:07 +0000
+++ b/NEWS	2009-04-14 04:33:41 +0000
@@ -52,7 +52,9 @@
 
 * ``bzrlib.bzrdir.BzrDir._get_config`` now returns a ``TransportConfig``
   or similar when the dir supports configuration settings. The base class
-  defaults to None. (Robert Collins)
+  defaults to None. There is a matching new server verb
+  ``BzrDir.get-config_file`` to reduce roundtrips for getting BzrDir
+  configuration. (Robert Collins)
 
 * ``bzrlib.tests.ExtendedTestResult`` has new methods ``startTests``
   called before the first test is started, ``done`` called after the last

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2009-04-14 02:35:07 +0000
+++ b/bzrlib/config.py	2009-04-14 04:33:41 +0000
@@ -1425,12 +1425,14 @@
             configobj.setdefault(section, {})[name] = value
         self._set_configobj(configobj)
 
+    def _get_config_file(self):
+        try:
+            return self._transport.get(self._filename)
+        except errors.NoSuchFile:
+            return StringIO()
+
     def _get_configobj(self):
-        try:
-            return ConfigObj(self._transport.get(self._filename),
-                             encoding='utf-8')
-        except errors.NoSuchFile:
-            return ConfigObj(encoding='utf-8')
+        return ConfigObj(self._get_config_file(), encoding='utf-8')
 
     def _set_configobj(self, configobj):
         out_file = StringIO()

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2009-04-14 02:35:07 +0000
+++ b/bzrlib/remote.py	2009-04-14 04:33:41 +0000
@@ -2414,7 +2414,7 @@
             return self._vfs_get_option(name, section, default)
 
     def _response_to_configobj(self, response):
-        if response[0][0] != 'ok':
+        if len(response[0]) and response[0][0] != 'ok':
             raise UnexpectedSmartServerResponse(response)
         lines = response[1].read_body_bytes().splitlines()
         return config.ConfigObj(lines, encoding='utf-8')

=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py	2009-04-04 02:50:01 +0000
+++ b/bzrlib/smart/bzrdir.py	2009-04-14 04:33:41 +0000
@@ -297,6 +297,21 @@
             return FailedSmartServerResponse(('norepository', ))
 
 
+class SmartServerBzrDirRequestConfigFile(SmartServerRequestBzrDir):
+
+    def do_bzrdir_request(self):
+        """Get the configuration bytes for a config file in bzrdir.
+        
+        The body is not utf8 decoded - it is the literal bytestream from disk.
+        """
+        config = self._bzrdir._get_config()
+        if config is None:
+            content = ''
+        else:
+            content = config._get_config_file().read()
+        return SuccessfulSmartServerResponse((), content)
+
+
 class SmartServerRequestInitializeBzrDir(SmartServerRequest):
 
     def do(self, path):

=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py	2009-04-02 05:22:42 +0000
+++ b/bzrlib/smart/request.py	2009-04-14 04:33:41 +0000
@@ -481,9 +481,14 @@
     'BzrDir.find_repositoryV3', 'bzrlib.smart.bzrdir',
     'SmartServerRequestFindRepositoryV3')
 request_handlers.register_lazy(
+    'BzrDir.get_config_file', 'bzrlib.smart.bzrdir',
+    'SmartServerBzrDirRequestConfigFile')
+request_handlers.register_lazy(
     'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir',
     'SmartServerRequestInitializeBzrDir')
 request_handlers.register_lazy(
+    'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
+request_handlers.register_lazy(
     'BzrDir.open_branch', 'bzrlib.smart.bzrdir',
     'SmartServerRequestOpenBranch')
 request_handlers.register_lazy(
@@ -553,5 +558,3 @@
     'stat', 'bzrlib.smart.vfs', 'StatRequest')
 request_handlers.register_lazy(
     'Transport.is_readonly', 'bzrlib.smart.request', 'SmartServerIsReadonly')
-request_handlers.register_lazy(
-    'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2009-04-14 02:35:07 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2009-04-14 04:33:41 +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(54, 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-14 02:35:07 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-04-14 04:33:41 +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(21, self.hpss_calls)
+        self.assertLength(19, self.hpss_calls)
 
     def test_push_smart_stacked_streaming_acceptance(self):
         self.setup_smart_server_with_call_log()

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2009-04-14 02:35:07 +0000
+++ b/bzrlib/tests/test_remote.py	2009-04-14 04:33:41 +0000
@@ -1442,8 +1442,6 @@
     def test_set_option_uses_vfs(self):
         self.setup_smart_server_with_call_log()
         bzrdir = self.make_bzrdir('.')
-        verb = 'BzrDir.get_config_file'
-        # self.disable_verb(verb)
         self.reset_smart_call_log()
         config = bzrdir.get_config()
         config.set_default_stack_on('/')
@@ -1453,6 +1451,7 @@
         self.setup_smart_server_with_call_log()
         bzrdir = self.make_bzrdir('.')
         verb = 'BzrDir.get_config_file'
+        self.disable_verb(verb)
         self.reset_smart_call_log()
         self.assertEqual(None,
             bzrdir._get_config().get_option('default_stack_on'))
@@ -2450,7 +2449,7 @@
         try:
             # it should have an appropriate fallback repository, which should also
             # be a RemoteRepository
-            self.assertEquals(len(remote_repo._fallback_repositories), 1)
+            self.assertLength(1, remote_repo._fallback_repositories)
             self.assertIsInstance(remote_repo._fallback_repositories[0],
                 RemoteRepository)
             # and it has the revision committed to the underlying repository;

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2009-04-02 05:22:42 +0000
+++ b/bzrlib/tests/test_smart.py	2009-04-14 04:33:41 +0000
@@ -296,6 +296,29 @@
         self.assertEqual(result, request.execute(''))
 
 
+class TestSmartServerBzrDirRequestGetConfigFile(
+    tests.TestCaseWithMemoryTransport):
+    """Tests for BzrDir.get_config_file."""
+
+    def test_present(self):
+        backing = self.get_transport()
+        dir = self.make_bzrdir('.')
+        dir.get_config().set_default_stack_on("/")
+        local_result = dir._get_config()._get_config_file().read()
+        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
+        request = request_class(backing)
+        expected = SuccessfulSmartServerResponse((), local_result)
+        self.assertEqual(expected, request.execute(''))
+
+    def test_missing(self):
+        backing = self.get_transport()
+        dir = self.make_bzrdir('.')
+        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
+        request = request_class(backing)
+        expected = SuccessfulSmartServerResponse((), '')
+        self.assertEqual(expected, request.execute(''))
+
+
 class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
 
     def test_empty_dir(self):
@@ -1386,93 +1409,68 @@
         for key, item in smart.request.request_handlers.iteritems():
             pass
 
+    def assertHandlerEqual(self, verb, handler):
+        self.assertEqual(smart.request.request_handlers.get(verb), handler)
+
     def test_registered_methods(self):
         """Test that known methods are registered to the correct object."""
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.get_config_file'),
+        self.assertHandlerEqual('Branch.get_config_file',
             smart.branch.SmartServerBranchGetConfigFile)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.get_parent'),
+        self.assertHandlerEqual('Branch.get_parent',
             smart.branch.SmartServerBranchGetParent)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.get_tags_bytes'),
+        self.assertHandlerEqual('Branch.get_tags_bytes',
             smart.branch.SmartServerBranchGetTagsBytes)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.lock_write'),
+        self.assertHandlerEqual('Branch.lock_write',
             smart.branch.SmartServerBranchRequestLockWrite)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.last_revision_info'),
+        self.assertHandlerEqual('Branch.last_revision_info',
             smart.branch.SmartServerBranchRequestLastRevisionInfo)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.revision_history'),
+        self.assertHandlerEqual('Branch.revision_history',
             smart.branch.SmartServerRequestRevisionHistory)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.set_config_option'),
+        self.assertHandlerEqual('Branch.set_config_option',
             smart.branch.SmartServerBranchRequestSetConfigOption)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.set_last_revision'),
+        self.assertHandlerEqual('Branch.set_last_revision',
             smart.branch.SmartServerBranchRequestSetLastRevision)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.set_last_revision_info'),
+        self.assertHandlerEqual('Branch.set_last_revision_info',
             smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
-        self.assertEqual(
-            smart.request.request_handlers.get('Branch.unlock'),
+        self.assertHandlerEqual('Branch.unlock',
             smart.branch.SmartServerBranchRequestUnlock)
-        self.assertEqual(
-            smart.request.request_handlers.get('BzrDir.find_repository'),
+        self.assertHandlerEqual('BzrDir.find_repository',
             smart.bzrdir.SmartServerRequestFindRepositoryV1)
-        self.assertEqual(
-            smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
+        self.assertHandlerEqual('BzrDir.find_repositoryV2',
             smart.bzrdir.SmartServerRequestFindRepositoryV2)
-        self.assertEqual(
-            smart.request.request_handlers.get('BzrDirFormat.initialize'),
+        self.assertHandlerEqual('BzrDirFormat.initialize',
             smart.bzrdir.SmartServerRequestInitializeBzrDir)
-        self.assertEqual(
-            smart.request.request_handlers.get('BzrDir.cloning_metadir'),
+        self.assertHandlerEqual('BzrDir.cloning_metadir',
             smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
-        self.assertEqual(
-            smart.request.request_handlers.get('BzrDir.open_branch'),
+        self.assertHandlerEqual('BzrDir.get_config_file',
+            smart.bzrdir.SmartServerBzrDirRequestConfigFile)
+        self.assertHandlerEqual('BzrDir.open_branch',
             smart.bzrdir.SmartServerRequestOpenBranch)
-        self.assertEqual(
-            smart.request.request_handlers.get('BzrDir.open_branchV2'),
+        self.assertHandlerEqual('BzrDir.open_branchV2',
             smart.bzrdir.SmartServerRequestOpenBranchV2)
-        self.assertEqual(
-            smart.request.request_handlers.get('PackRepository.autopack'),
+        self.assertHandlerEqual('PackRepository.autopack',
             smart.packrepository.SmartServerPackRepositoryAutopack)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.gather_stats'),
+        self.assertHandlerEqual('Repository.gather_stats',
             smart.repository.SmartServerRepositoryGatherStats)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.get_parent_map'),
+        self.assertHandlerEqual('Repository.get_parent_map',
             smart.repository.SmartServerRepositoryGetParentMap)
-        self.assertEqual(
-            smart.request.request_handlers.get(
-                'Repository.get_revision_graph'),
+        self.assertHandlerEqual('Repository.get_revision_graph',
             smart.repository.SmartServerRepositoryGetRevisionGraph)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.get_stream'),
+        self.assertHandlerEqual('Repository.get_stream',
             smart.repository.SmartServerRepositoryGetStream)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.has_revision'),
+        self.assertHandlerEqual('Repository.has_revision',
             smart.repository.SmartServerRequestHasRevision)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.insert_stream'),
+        self.assertHandlerEqual('Repository.insert_stream',
             smart.repository.SmartServerRepositoryInsertStream)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.insert_stream_locked'),
+        self.assertHandlerEqual('Repository.insert_stream_locked',
             smart.repository.SmartServerRepositoryInsertStreamLocked)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.is_shared'),
+        self.assertHandlerEqual('Repository.is_shared',
             smart.repository.SmartServerRepositoryIsShared)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.lock_write'),
+        self.assertHandlerEqual('Repository.lock_write',
             smart.repository.SmartServerRepositoryLockWrite)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.tarball'),
+        self.assertHandlerEqual('Repository.tarball',
             smart.repository.SmartServerRepositoryTarball)
-        self.assertEqual(
-            smart.request.request_handlers.get('Repository.unlock'),
+        self.assertHandlerEqual('Repository.unlock',
             smart.repository.SmartServerRepositoryUnlock)
-        self.assertEqual(
-            smart.request.request_handlers.get('Transport.is_readonly'),
+        self.assertHandlerEqual('Transport.is_readonly',
             smart.request.SmartServerIsReadonly)




More information about the bazaar-commits mailing list