2695
2706
return to_convert
2698
# This is not in remote.py because it's relatively small, and needs to be
2699
# registered. Putting it in remote.py creates a circular import problem.
2700
# we can make it a lazy object if the control formats is turned into something
2702
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2703
"""Format representing bzrdirs accessed via a smart server"""
2705
supports_workingtrees = False
2708
BzrDirMetaFormat1.__init__(self)
2709
# XXX: It's a bit ugly that the network name is here, because we'd
2710
# like to believe that format objects are stateless or at least
2711
# immutable, However, we do at least avoid mutating the name after
2712
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
2713
self._network_name = None
2716
return "%s(_network_name=%r)" % (self.__class__.__name__,
2719
def get_format_description(self):
2720
if self._network_name:
2721
real_format = controldir.network_format_registry.get(self._network_name)
2722
return 'Remote: ' + real_format.get_format_description()
2723
return 'bzr remote bzrdir'
2725
def get_format_string(self):
2726
raise NotImplementedError(self.get_format_string)
2728
def network_name(self):
2729
if self._network_name:
2730
return self._network_name
2732
raise AssertionError("No network name set.")
2734
def initialize_on_transport(self, transport):
2736
# hand off the request to the smart server
2737
client_medium = transport.get_smart_medium()
2738
except errors.NoSmartMedium:
2739
# TODO: lookup the local format from a server hint.
2740
local_dir_format = BzrDirMetaFormat1()
2741
return local_dir_format.initialize_on_transport(transport)
2742
client = _SmartClient(client_medium)
2743
path = client.remote_path_from_transport(transport)
2745
response = client.call('BzrDirFormat.initialize', path)
2746
except errors.ErrorFromSmartServer, err:
2747
remote._translate_error(err, path=path)
2748
if response[0] != 'ok':
2749
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2750
format = RemoteBzrDirFormat()
2751
self._supply_sub_formats_to(format)
2752
return remote.RemoteBzrDir(transport, format)
2754
def parse_NoneTrueFalse(self, arg):
2761
raise AssertionError("invalid arg %r" % arg)
2763
def _serialize_NoneTrueFalse(self, arg):
2770
def _serialize_NoneString(self, arg):
2773
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2774
create_prefix=False, force_new_repo=False, stacked_on=None,
2775
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2778
# hand off the request to the smart server
2779
client_medium = transport.get_smart_medium()
2780
except errors.NoSmartMedium:
2783
# Decline to open it if the server doesn't support our required
2784
# version (3) so that the VFS-based transport will do it.
2785
if client_medium.should_probe():
2787
server_version = client_medium.protocol_version()
2788
if server_version != '2':
2792
except errors.SmartProtocolError:
2793
# Apparently there's no usable smart server there, even though
2794
# the medium supports the smart protocol.
2799
client = _SmartClient(client_medium)
2800
path = client.remote_path_from_transport(transport)
2801
if client_medium._is_remote_before((1, 16)):
2804
# TODO: lookup the local format from a server hint.
2805
local_dir_format = BzrDirMetaFormat1()
2806
self._supply_sub_formats_to(local_dir_format)
2807
return local_dir_format.initialize_on_transport_ex(transport,
2808
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2809
force_new_repo=force_new_repo, stacked_on=stacked_on,
2810
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2811
make_working_trees=make_working_trees, shared_repo=shared_repo,
2813
return self._initialize_on_transport_ex_rpc(client, path, transport,
2814
use_existing_dir, create_prefix, force_new_repo, stacked_on,
2815
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
2817
def _initialize_on_transport_ex_rpc(self, client, path, transport,
2818
use_existing_dir, create_prefix, force_new_repo, stacked_on,
2819
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
2821
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
2822
args.append(self._serialize_NoneTrueFalse(create_prefix))
2823
args.append(self._serialize_NoneTrueFalse(force_new_repo))
2824
args.append(self._serialize_NoneString(stacked_on))
2825
# stack_on_pwd is often/usually our transport
2828
stack_on_pwd = transport.relpath(stack_on_pwd)
2829
if not stack_on_pwd:
2831
except errors.PathNotChild:
2833
args.append(self._serialize_NoneString(stack_on_pwd))
2834
args.append(self._serialize_NoneString(repo_format_name))
2835
args.append(self._serialize_NoneTrueFalse(make_working_trees))
2836
args.append(self._serialize_NoneTrueFalse(shared_repo))
2837
request_network_name = self._network_name or \
2838
BzrDirFormat.get_default_format().network_name()
2840
response = client.call('BzrDirFormat.initialize_ex_1.16',
2841
request_network_name, path, *args)
2842
except errors.UnknownSmartMethod:
2843
client._medium._remember_remote_is_before((1,16))
2844
local_dir_format = BzrDirMetaFormat1()
2845
self._supply_sub_formats_to(local_dir_format)
2846
return local_dir_format.initialize_on_transport_ex(transport,
2847
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2848
force_new_repo=force_new_repo, stacked_on=stacked_on,
2849
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2850
make_working_trees=make_working_trees, shared_repo=shared_repo,
2852
except errors.ErrorFromSmartServer, err:
2853
remote._translate_error(err, path=path)
2854
repo_path = response[0]
2855
bzrdir_name = response[6]
2856
require_stacking = response[7]
2857
require_stacking = self.parse_NoneTrueFalse(require_stacking)
2858
format = RemoteBzrDirFormat()
2859
format._network_name = bzrdir_name
2860
self._supply_sub_formats_to(format)
2861
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
2863
repo_format = remote.response_tuple_to_repo_format(response[1:])
2864
if repo_path == '.':
2867
repo_bzrdir_format = RemoteBzrDirFormat()
2868
repo_bzrdir_format._network_name = response[5]
2869
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
2873
final_stack = response[8] or None
2874
final_stack_pwd = response[9] or None
2876
final_stack_pwd = urlutils.join(
2877
transport.base, final_stack_pwd)
2878
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
2879
if len(response) > 10:
2880
# Updated server verb that locks remotely.
2881
repo_lock_token = response[10] or None
2882
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
2884
remote_repo.dont_leave_lock_in_place()
2886
remote_repo.lock_write()
2887
policy = UseExistingRepository(remote_repo, final_stack,
2888
final_stack_pwd, require_stacking)
2889
policy.acquire_repository()
2893
bzrdir._format.set_branch_format(self.get_branch_format())
2894
if require_stacking:
2895
# The repo has already been created, but we need to make sure that
2896
# we'll make a stackable branch.
2897
bzrdir._format.require_stacking(_skip_repo=True)
2898
return remote_repo, bzrdir, require_stacking, policy
2900
def _open(self, transport):
2901
return remote.RemoteBzrDir(transport, self)
2903
def __eq__(self, other):
2904
if not isinstance(other, RemoteBzrDirFormat):
2906
return self.get_format_description() == other.get_format_description()
2908
def __return_repository_format(self):
2909
# Always return a RemoteRepositoryFormat object, but if a specific bzr
2910
# repository format has been asked for, tell the RemoteRepositoryFormat
2911
# that it should use that for init() etc.
2912
result = remote.RemoteRepositoryFormat()
2913
custom_format = getattr(self, '_repository_format', None)
2915
if isinstance(custom_format, remote.RemoteRepositoryFormat):
2916
return custom_format
2918
# We will use the custom format to create repositories over the
2919
# wire; expose its details like rich_root_data for code to
2921
result._custom_format = custom_format
2924
def get_branch_format(self):
2925
result = BzrDirMetaFormat1.get_branch_format(self)
2926
if not isinstance(result, remote.RemoteBranchFormat):
2927
new_result = remote.RemoteBranchFormat()
2928
new_result._custom_format = result
2930
self.set_branch_format(new_result)
2934
repository_format = property(__return_repository_format,
2935
BzrDirMetaFormat1._set_repository_format) #.im_func)
2938
2709
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)