Rev 4055: Actually make this branch work. in http://people.ubuntu.com/~robertc/baz2.0/RemoteRepository._format

Robert Collins robertc at robertcollins.net
Thu Feb 26 06:01:24 GMT 2009


At http://people.ubuntu.com/~robertc/baz2.0/RemoteRepository._format

------------------------------------------------------------
revno: 4055
revision-id: robertc at robertcollins.net-20090226060121-i33y7mbr72nqlvyv
parent: robertc at robertcollins.net-20090226042500-xl9urv7zcbvkfjvs
committer: Robert Collins <robertc at robertcollins.net>
branch nick: RemoteRepository._format
timestamp: Thu 2009-02-26 17:01:21 +1100
message:
  Actually make this branch work.
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2009-02-26 04:25:00 +0000
+++ b/bzrlib/remote.py	2009-02-26 06:01:21 +0000
@@ -243,6 +243,9 @@
 
     def _open_repo_v3(self, path):
         verb = 'BzrDir.find_repositoryV3'
+        medium = self._client._medium
+        if medium._is_remote_before((1, 13)):
+            raise errors.UnknownSmartMethod(verb)
         response = self._call(verb, path)
         if response[0] != 'ok':
             raise errors.UnexpectedSmartServerResponse(response)
@@ -780,8 +783,11 @@
         :param repository: The repository to fallback to for non-hpss
             implemented operations.
         """
-        if self._real_repository is not None:
-            raise AssertionError('_real_repository is already set')
+        # There was an assertion that this real repository was never replaced;
+        # However for down level serves we always open the real repository,
+        # which means that opening the branch ends up replacing it. Rather than
+        # write to real_branch.repository, we just allow the _real_repository
+        # object to be replaced.
         if isinstance(repository, RemoteRepository):
             raise AssertionError()
         self._real_repository = repository

=== modified file 'bzrlib/smart/bzrdir.py'
--- a/bzrlib/smart/bzrdir.py	2009-02-26 04:25:00 +0000
+++ b/bzrlib/smart/bzrdir.py	2009-02-26 06:01:21 +0000
@@ -156,9 +156,10 @@
 
         This operates precisely like 'bzrdir.find_repository'.
 
-        :return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
-            strings, relpath is a / prefixed path, and the other three are
-            either 'yes' or 'no'.
+        :return: (relpath, rich_root, tree_ref, external_lookup, network_name).
+            All are strings, relpath is a / prefixed path, the next three are
+            either 'yes' or 'no', and the last is a repository format network
+            name.
         :raises errors.NoRepositoryPresent: When there is no repository
             present.
         """
@@ -168,7 +169,8 @@
         path = self._repo_relpath(bzrdir.root_transport, repository)
         rich_root, tree_ref, external_lookup = self._format_to_capabilities(
             repository._format)
-        return path, rich_root, tree_ref, external_lookup
+        network_name = repository._format.network_name()
+        return path, rich_root, tree_ref, external_lookup, network_name
 
 
 class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):
@@ -188,7 +190,7 @@
         :return: norepository or ok, relpath.
         """
         try:
-            path, rich_root, tree_ref, external_lookup = self._find(path)
+            path, rich_root, tree_ref, external_lookup, name = self._find(path)
             return SuccessfulSmartServerResponse(('ok', path, rich_root, tree_ref))
         except errors.NoRepositoryPresent:
             return FailedSmartServerResponse(('norepository', ))
@@ -212,7 +214,7 @@
             external_lookup.
         """
         try:
-            path, rich_root, tree_ref, external_lookup = self._find(path)
+            path, rich_root, tree_ref, external_lookup, name = self._find(path)
             return SuccessfulSmartServerResponse(
                 ('ok', path, rich_root, tree_ref, external_lookup))
         except errors.NoRepositoryPresent:
@@ -236,9 +238,9 @@
             external_lookup, network_name.
         """
         try:
-            path, rich_root, tree_ref, external_lookup = self._find(path)
+            path, rich_root, tree_ref, external_lookup, name = self._find(path)
             return SuccessfulSmartServerResponse(
-                ('ok', path, rich_root, tree_ref, external_lookup))
+                ('ok', path, rich_root, tree_ref, external_lookup, name))
         except errors.NoRepositoryPresent:
             return FailedSmartServerResponse(('norepository', ))
 

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2009-02-26 04:25:00 +0000
+++ b/bzrlib/tests/test_remote.py	2009-02-26 06:01:21 +0000
@@ -262,6 +262,10 @@
 
 class TestRemote(tests.TestCaseWithMemoryTransport):
 
+    def get_repo_format(self):
+        reference_bzrdir_format = bzrdir.format_registry.get('default')()
+        return reference_bzrdir_format.repository_format
+
     def disable_verb(self, verb):
         """Disable a verb for one test."""
         request_handlers = smart.request.request_handlers
@@ -345,9 +349,11 @@
             AssertionError, client_medium._remember_remote_is_before, (1, 9))
 
 
-class TestBzrDirOpenBranch(tests.TestCase):
+class TestBzrDirOpenBranch(TestRemote):
 
     def test_branch_present(self):
+        reference_format = self.get_repo_format()
+        network_name = reference_format.network_name()
         transport = MemoryTransport()
         transport.mkdir('quack')
         transport = transport.clone('quack')
@@ -356,8 +362,8 @@
             'BzrDir.open_branch', ('quack/',),
             'success', ('ok', ''))
         client.add_expected_call(
-            'BzrDir.find_repositoryV2', ('quack/',),
-            'success', ('ok', '', 'no', 'no', 'no'))
+            'BzrDir.find_repositoryV3', ('quack/',),
+            'success', ('ok', '', 'no', 'no', 'no', network_name))
         client.add_expected_call(
             'Branch.get_stacked_on_url', ('quack/',),
             'error', ('NotStacked',))
@@ -404,12 +410,14 @@
         # transmitted as "~", not "%7E".
         transport = RemoteTCPTransport('bzr://localhost/~hello/')
         client = FakeClient(transport.base)
+        reference_format = self.get_repo_format()
+        network_name = reference_format.network_name()
         client.add_expected_call(
             'BzrDir.open_branch', ('~hello/',),
             'success', ('ok', ''))
         client.add_expected_call(
-            'BzrDir.find_repositoryV2', ('~hello/',),
-            'success', ('ok', '', 'no', 'no', 'no'))
+            'BzrDir.find_repositoryV3', ('~hello/',),
+            'success', ('ok', '', 'no', 'no', 'no', network_name))
         client.add_expected_call(
             'Branch.get_stacked_on_url', ('~hello/',),
             'error', ('NotStacked',))
@@ -419,6 +427,8 @@
         client.finished_test()
 
     def check_open_repository(self, rich_root, subtrees, external_lookup='no'):
+        reference_format = self.get_repo_format()
+        network_name = reference_format.network_name()
         transport = MemoryTransport()
         transport.mkdir('quack')
         transport = transport.clone('quack')
@@ -432,12 +442,13 @@
             subtree_response = 'no'
         client = FakeClient(transport.base)
         client.add_success_response(
-            'ok', '', rich_response, subtree_response, external_lookup)
+            'ok', '', rich_response, subtree_response, external_lookup,
+            network_name)
         bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
             _client=client)
         result = bzrdir.open_repository()
         self.assertEqual(
-            [('call', 'BzrDir.find_repositoryV2', ('quack/',))],
+            [('call', 'BzrDir.find_repositoryV3', ('quack/',))],
             client._calls)
         self.assertIsInstance(result, RemoteRepository)
         self.assertEqual(bzrdir, result.bzrdir)
@@ -534,10 +545,6 @@
 
 class TestBzrDirOpenRepository(TestRemote):
 
-    def get_repo_format(self):
-        reference_bzrdir_format = bzrdir.format_registry.get('default')()
-        return reference_bzrdir_format.repository_format
-
     def test_backwards_compat_1_2_3(self):
         # fallback all the way to the first version.
         reference_format = self.get_repo_format()
@@ -699,7 +706,7 @@
         self.assertEqual((2, revid), result)
 
 
-class TestBranch_get_stacked_on_url(tests.TestCaseWithMemoryTransport):
+class TestBranch_get_stacked_on_url(TestRemote):
     """Test Branch._get_stacked_on_url rpc"""
 
     def test_get_stacked_on_invalid_url(self):
@@ -739,8 +746,9 @@
             'BzrDir.open_branch', ('stacked/',),
             'success', ('ok', ''))
         client.add_expected_call(
-            'BzrDir.find_repositoryV2', ('stacked/',),
-            'success', ('ok', '', 'no', 'no', 'no'))
+            'BzrDir.find_repositoryV3', ('stacked/',),
+            'success', ('ok', '', 'no', 'no', 'no',
+                stacked_branch.repository._format.network_name()))
         # called twice, once from constructor and then again by us
         client.add_expected_call(
             'Branch.get_stacked_on_url', ('stacked/',),
@@ -766,13 +774,15 @@
         base_branch = self.make_branch('base', format='1.6')
         stacked_branch = self.make_branch('stacked', format='1.6')
         stacked_branch.set_stacked_on_url('../base')
+        reference_format = self.get_repo_format()
+        network_name = reference_format.network_name()
         client = FakeClient(self.get_url())
         client.add_expected_call(
             'BzrDir.open_branch', ('stacked/',),
             'success', ('ok', ''))
         client.add_expected_call(
-            'BzrDir.find_repositoryV2', ('stacked/',),
-            'success', ('ok', '', 'no', 'no', 'no'))
+            'BzrDir.find_repositoryV3', ('stacked/',),
+            'success', ('ok', '', 'no', 'no', 'no', network_name))
         # called twice, once from constructor and then again by us
         client.add_expected_call(
             'Branch.get_stacked_on_url', ('stacked/',),




More information about the bazaar-commits mailing list