At http://people.ubuntu.com/~robertc/baz2.0/branch.roundtrips
------------------------------------------------------------ revno: 4073 revision-id: [email protected] parent: [email protected] committer: Robert Collins <[email protected]> branch nick: branch.roundtrips timestamp: Tue 2009-03-03 14:27:51 +1100 message: Get BzrDir.cloning_metadir working. === modified file 'NEWS' --- a/NEWS 2009-03-03 01:06:25 +0000 +++ b/NEWS 2009-03-03 03:27:51 +0000 @@ -140,6 +140,8 @@ plugins to have hooks called on non-stacked instances. (Robert Collins, #334187) + * ``BzrDir.cloning_metadir`` now has a RPC call. (Robert Collins) + * ``BzrDirFormat.__str__`` now uses the human readable description rather than the sometimes-absent disk label. (Robert Collins) === modified file 'bzrlib/bzrdir.py' --- a/bzrlib/bzrdir.py 2009-03-03 01:06:25 +0000 +++ b/bzrlib/bzrdir.py 2009-03-03 03:27:51 +0000 @@ -2086,6 +2086,7 @@ def __init__(self): self._workingtree_format = None self._branch_format = None + self._repository_format = None def __eq__(self, other): if other.__class__ is not self.__class__: @@ -2155,7 +2156,7 @@ def __return_repository_format(self): """Circular import protection.""" - if getattr(self, '_repository_format', None): + if self._repository_format: return self._repository_format from bzrlib.repository import RepositoryFormat return RepositoryFormat.get_default_format() === modified file 'bzrlib/remote.py' --- a/bzrlib/remote.py 2009-03-03 01:06:25 +0000 +++ b/bzrlib/remote.py 2009-03-03 03:27:51 +0000 @@ -112,7 +112,6 @@ raise errors.UnexpectedSmartServerResponse(response) if response == ('no',): raise errors.NotBranchError(path=transport.base) - self._ensure_real() def _ensure_real(self): """Ensure that there is a _real_bzrdir set. @@ -134,9 +133,36 @@ self._next_open_branch_result = None return BzrDir.break_lock(self) - def cloning_metadir(self, stacked=False): + def _vfs_cloning_metadir(self, require_stacking=False): self._ensure_real() - return self._real_bzrdir.cloning_metadir(stacked) + return self._real_bzrdir.cloning_metadir( + require_stacking=require_stacking) + + def cloning_metadir(self, require_stacking=False): + medium = self._client._medium + if medium._is_remote_before((1, 13)): + return self._vfs_cloning_metadir(require_stacking=require_stacking) + verb = 'BzrDir.cloning_metadir' + if require_stacking: + stacking = 'True' + else: + stacking = 'False' + path = self._path_for_remote_call(self._client) + try: + response = self._call(verb, path, stacking) + except errors.UnknownSmartMethod: + return self._vfs_cloning_metadir(require_stacking=require_stacking) + if len(response) != 3: + raise errors.UnexpectedSmartServerResponse(response) + control_name, repo_name, branch_name = response + format = bzrdir.network_format_registry.get(control_name) + if repo_name: + format.repository_format = repository.network_format_registry.get( + repo_name) + if branch_name: + format.set_branch_format( + branch.network_format_registry.get(branch_name)) + return format def create_repository(self, shared=False): # as per meta1 formats - just delegate to the format object which may === modified file 'bzrlib/smart/bzrdir.py' --- a/bzrlib/smart/bzrdir.py 2009-02-26 06:01:21 +0000 +++ b/bzrlib/smart/bzrdir.py 2009-03-03 03:27:51 +0000 @@ -18,7 +18,7 @@ from bzrlib import branch, errors, repository -from bzrlib.bzrdir import BzrDir, BzrDirFormat +from bzrlib.bzrdir import BzrDir, BzrDirFormat, BzrDirMetaFormat1 from bzrlib.smart.request import ( FailedSmartServerResponse, SmartServerRequest, @@ -53,6 +53,12 @@ class SmartServerRequestBzrDir(SmartServerRequest): + def do(self, path, *args): + """Open a BzrDir at path, and return self.do_bzrdir_request(*args).""" + self._bzrdir = BzrDir.open_from_transport( + self.transport_from_client_path(path)) + return self.do_bzrdir_request(*args) + def _boolean_to_yes_no(self, a_boolean): if a_boolean: return 'yes' @@ -80,6 +86,30 @@ return '/'.join(segments) +class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir): + + def do_bzrdir_request(self, require_stacking): + """Get the format that should be used when cloning from this dir.""" + if require_stacking == "True": + require_stacking = True + else: + require_stacking = False + control_format = self._bzrdir.cloning_metadir( + require_stacking=require_stacking) + control_name = control_format.network_name() + # XXX: Should be a method that tells us this, or delegated to the + # format, or something. + if isinstance(control_format, BzrDirMetaFormat1): + branch_name = control_format.get_branch_format().network_name() + repository_name = control_format.repository_format.network_name() + else: + # Only MetaDir has delegated formats today. + branch_name = '' + repository_name = '' + return SuccessfulSmartServerResponse((control_name, repository_name, + branch_name)) + + class SmartServerRequestCreateBranch(SmartServerRequestBzrDir): def do(self, path, network_name): === modified file 'bzrlib/smart/request.py' --- a/bzrlib/smart/request.py 2009-03-02 07:55:18 +0000 +++ b/bzrlib/smart/request.py 2009-03-03 03:27:51 +0000 @@ -408,6 +408,9 @@ request_handlers.register_lazy( 'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock') request_handlers.register_lazy( + 'BzrDir.cloning_metadir', 'bzrlib.smart.bzrdir', + 'SmartServerBzrDirRequestCloningMetaDir') +request_handlers.register_lazy( 'BzrDir.create_branch', 'bzrlib.smart.bzrdir', 'SmartServerRequestCreateBranch') request_handlers.register_lazy( 'BzrDir.create_repository', 'bzrlib.smart.bzrdir', 'SmartServerRequestCreateRepository') === modified file 'bzrlib/tests/blackbox/test_branch.py' --- a/bzrlib/tests/blackbox/test_branch.py 2009-03-02 03:38:07 +0000 +++ b/bzrlib/tests/blackbox/test_branch.py 2009-03-03 03:27:51 +0000 @@ -273,7 +273,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.assertEqual(99, rpc_count) + self.assertEqual(95, rpc_count) def test_branch_from_trivial_branch_streaming_acceptance(self): self.setup_smart_server_with_call_log() @@ -289,7 +289,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.assertEqual(25, rpc_count) + self.assertEqual(21, rpc_count) class TestRemoteBranch(TestCaseWithSFTPServer): === modified file 'bzrlib/tests/branch_implementations/test_push.py' --- a/bzrlib/tests/branch_implementations/test_push.py 2009-03-03 01:34:22 +0000 +++ b/bzrlib/tests/branch_implementations/test_push.py 2009-03-03 03:27:51 +0000 @@ -418,7 +418,6 @@ self.empty_branch.push(target) self.assertEqual( ['BzrDir.open', - 'get', 'BzrDir.open_branch', 'BzrDir.find_repositoryV3', 'Branch.get_stacked_on_url', === modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py' --- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2009-03-03 01:06:25 +0000 +++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2009-03-03 03:27:51 +0000 @@ -1169,8 +1169,6 @@ # All control formats must have a network name. dir = self.make_bzrdir('.') format = dir._format - network_name = format.network_name() - self.assertIsInstance(network_name, str) # We want to test that the network_name matches the actual format on # disk. For local control dirsthat means that using network_name as a # key in the registry gives back the same format. For remote obects @@ -1179,11 +1177,15 @@ if isinstance(format, bzrdir.RemoteBzrDirFormat): dir._ensure_real() real_dir = dir._real_bzrdir + network_name = format.network_name() self.assertEqual(real_dir._format.network_name(), network_name) else: registry = bzrdir.network_format_registry + network_name = format.network_name() looked_up_format = registry.get(network_name) self.assertEqual(format.__class__, looked_up_format.__class__) + # The network name must be a byte string. + self.assertIsInstance(network_name, str) def test_open_not_bzrdir(self): # test the formats specific behaviour for no-content or similar dirs. === modified file 'bzrlib/tests/test_remote.py' --- a/bzrlib/tests/test_remote.py 2009-02-26 06:01:21 +0000 +++ b/bzrlib/tests/test_remote.py 2009-03-03 03:27:51 +0000 @@ -349,6 +349,43 @@ AssertionError, client_medium._remember_remote_is_before, (1, 9)) +class TestBzrDirCloningMetaDir(TestRemote): + + def test_backwards_compat(self): + self.setup_smart_server_with_call_log() + a_dir = self.make_bzrdir('.') + self.reset_smart_call_log() + verb = 'BzrDir.cloning_metadir' + self.disable_verb(verb) + format = a_dir.cloning_metadir() + call_count = len([call for call in self.hpss_calls if + call[0].method == verb]) + self.assertEqual(1, call_count) + + def test_current_server(self): + transport = self.get_transport('.') + transport = transport.clone('quack') + self.make_bzrdir('quack') + client = FakeClient(transport.base) + reference_bzrdir_format = bzrdir.format_registry.get('default')() + control_name = reference_bzrdir_format.network_name() + client.add_expected_call( + 'BzrDir.cloning_metadir', ('quack/', 'False'), + 'success', (control_name, '', '')), + a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(), + _client=client) + result = a_bzrdir.cloning_metadir() + # We should have got a reference control dir with default branch and + # repository formats. + # This pokes a little, just to be sure. + self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result)) + self.assertEqual(reference_bzrdir_format.repository_format, + result._repository_format) + self.assertEqual(reference_bzrdir_format.get_branch_format(), + result._branch_format) + client.finished_test() + + class TestBzrDirOpenBranch(TestRemote): def test_branch_present(self): === modified file 'bzrlib/tests/test_smart.py' --- a/bzrlib/tests/test_smart.py 2009-03-02 07:13:41 +0000 +++ b/bzrlib/tests/test_smart.py 2009-03-03 03:27:51 +0000 @@ -38,7 +38,8 @@ ) from bzrlib.branch import Branch, BranchReferenceFormat import bzrlib.smart.branch -import bzrlib.smart.bzrdir +import bzrlib.smart.bzrdir, bzrlib.smart.bzrdir as smart_dir +import bzrlib.smart.packrepository import bzrlib.smart.repository from bzrlib.smart.request import ( FailedSmartServerResponse, @@ -162,6 +163,24 @@ request.transport_from_client_path('foo/').base) +class TestSmartServerBzrDirRequestCloningMetaDir( + tests.TestCaseWithMemoryTransport): + """Tests for BzrDir.cloning_metadir.""" + + def test_cloning_metadir(self): + """When there is a bzrdir present, the call succeeds.""" + backing = self.get_transport() + dir = self.make_bzrdir('.') + local_result = dir.cloning_metadir() + request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir + request = request_class(backing) + expected = SuccessfulSmartServerResponse( + (local_result.network_name(), + local_result.repository_format.network_name(), + local_result.get_branch_format().network_name())) + self.assertEqual(expected, request.execute('', 'False')) + + class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport): """Tests for BzrDir.create_repository.""" @@ -1176,6 +1195,9 @@ smart.request.request_handlers.get('BzrDirFormat.initialize'), smart.bzrdir.SmartServerRequestInitializeBzrDir) self.assertEqual( + smart.request.request_handlers.get('BzrDir.cloning_metadir'), + smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir) + self.assertEqual( smart.request.request_handlers.get('BzrDir.open_branch'), smart.bzrdir.SmartServerRequestOpenBranch) self.assertEqual( -- bazaar-commits mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/bazaar-commits
