1798
1783
return to_convert
1801
# This is not in remote.py because it's relatively small, and needs to be
1802
# registered. Putting it in remote.py creates a circular import problem.
1803
# we can make it a lazy object if the control formats is turned into something
1805
class RemoteBzrDirFormat(BzrDirMetaFormat1):
1806
"""Format representing bzrdirs accessed via a smart server"""
1808
supports_workingtrees = False
1811
BzrDirMetaFormat1.__init__(self)
1812
# XXX: It's a bit ugly that the network name is here, because we'd
1813
# like to believe that format objects are stateless or at least
1814
# immutable, However, we do at least avoid mutating the name after
1815
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
1816
self._network_name = None
1819
return "%s(_network_name=%r)" % (self.__class__.__name__,
1822
def get_format_description(self):
1823
if self._network_name:
1824
real_format = controldir.network_format_registry.get(self._network_name)
1825
return 'Remote: ' + real_format.get_format_description()
1826
return 'bzr remote bzrdir'
1828
def get_format_string(self):
1829
raise NotImplementedError(self.get_format_string)
1831
def network_name(self):
1832
if self._network_name:
1833
return self._network_name
1835
raise AssertionError("No network name set.")
1837
def initialize_on_transport(self, transport):
1839
# hand off the request to the smart server
1840
client_medium = transport.get_smart_medium()
1841
except errors.NoSmartMedium:
1842
# TODO: lookup the local format from a server hint.
1843
local_dir_format = BzrDirMetaFormat1()
1844
return local_dir_format.initialize_on_transport(transport)
1845
client = _SmartClient(client_medium)
1846
path = client.remote_path_from_transport(transport)
1848
response = client.call('BzrDirFormat.initialize', path)
1849
except errors.ErrorFromSmartServer, err:
1850
remote._translate_error(err, path=path)
1851
if response[0] != 'ok':
1852
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
1853
format = RemoteBzrDirFormat()
1854
self._supply_sub_formats_to(format)
1855
return remote.RemoteBzrDir(transport, format)
1857
def parse_NoneTrueFalse(self, arg):
1864
raise AssertionError("invalid arg %r" % arg)
1866
def _serialize_NoneTrueFalse(self, arg):
1873
def _serialize_NoneString(self, arg):
1876
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1877
create_prefix=False, force_new_repo=False, stacked_on=None,
1878
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1881
# hand off the request to the smart server
1882
client_medium = transport.get_smart_medium()
1883
except errors.NoSmartMedium:
1886
# Decline to open it if the server doesn't support our required
1887
# version (3) so that the VFS-based transport will do it.
1888
if client_medium.should_probe():
1890
server_version = client_medium.protocol_version()
1891
if server_version != '2':
1895
except errors.SmartProtocolError:
1896
# Apparently there's no usable smart server there, even though
1897
# the medium supports the smart protocol.
1902
client = _SmartClient(client_medium)
1903
path = client.remote_path_from_transport(transport)
1904
if client_medium._is_remote_before((1, 16)):
1907
# TODO: lookup the local format from a server hint.
1908
local_dir_format = BzrDirMetaFormat1()
1909
self._supply_sub_formats_to(local_dir_format)
1910
return local_dir_format.initialize_on_transport_ex(transport,
1911
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1912
force_new_repo=force_new_repo, stacked_on=stacked_on,
1913
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1914
make_working_trees=make_working_trees, shared_repo=shared_repo,
1916
return self._initialize_on_transport_ex_rpc(client, path, transport,
1917
use_existing_dir, create_prefix, force_new_repo, stacked_on,
1918
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
1920
def _initialize_on_transport_ex_rpc(self, client, path, transport,
1921
use_existing_dir, create_prefix, force_new_repo, stacked_on,
1922
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
1924
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
1925
args.append(self._serialize_NoneTrueFalse(create_prefix))
1926
args.append(self._serialize_NoneTrueFalse(force_new_repo))
1927
args.append(self._serialize_NoneString(stacked_on))
1928
# stack_on_pwd is often/usually our transport
1931
stack_on_pwd = transport.relpath(stack_on_pwd)
1932
if not stack_on_pwd:
1934
except errors.PathNotChild:
1936
args.append(self._serialize_NoneString(stack_on_pwd))
1937
args.append(self._serialize_NoneString(repo_format_name))
1938
args.append(self._serialize_NoneTrueFalse(make_working_trees))
1939
args.append(self._serialize_NoneTrueFalse(shared_repo))
1940
request_network_name = self._network_name or \
1941
BzrDirFormat.get_default_format().network_name()
1943
response = client.call('BzrDirFormat.initialize_ex_1.16',
1944
request_network_name, path, *args)
1945
except errors.UnknownSmartMethod:
1946
client._medium._remember_remote_is_before((1,16))
1947
local_dir_format = BzrDirMetaFormat1()
1948
self._supply_sub_formats_to(local_dir_format)
1949
return local_dir_format.initialize_on_transport_ex(transport,
1950
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1951
force_new_repo=force_new_repo, stacked_on=stacked_on,
1952
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1953
make_working_trees=make_working_trees, shared_repo=shared_repo,
1955
except errors.ErrorFromSmartServer, err:
1956
remote._translate_error(err, path=path)
1957
repo_path = response[0]
1958
bzrdir_name = response[6]
1959
require_stacking = response[7]
1960
require_stacking = self.parse_NoneTrueFalse(require_stacking)
1961
format = RemoteBzrDirFormat()
1962
format._network_name = bzrdir_name
1963
self._supply_sub_formats_to(format)
1964
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
1966
repo_format = remote.response_tuple_to_repo_format(response[1:])
1967
if repo_path == '.':
1970
repo_bzrdir_format = RemoteBzrDirFormat()
1971
repo_bzrdir_format._network_name = response[5]
1972
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
1976
final_stack = response[8] or None
1977
final_stack_pwd = response[9] or None
1979
final_stack_pwd = urlutils.join(
1980
transport.base, final_stack_pwd)
1981
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
1982
if len(response) > 10:
1983
# Updated server verb that locks remotely.
1984
repo_lock_token = response[10] or None
1985
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
1987
remote_repo.dont_leave_lock_in_place()
1989
remote_repo.lock_write()
1990
policy = UseExistingRepository(remote_repo, final_stack,
1991
final_stack_pwd, require_stacking)
1992
policy.acquire_repository()
1996
bzrdir._format.set_branch_format(self.get_branch_format())
1997
if require_stacking:
1998
# The repo has already been created, but we need to make sure that
1999
# we'll make a stackable branch.
2000
bzrdir._format.require_stacking(_skip_repo=True)
2001
return remote_repo, bzrdir, require_stacking, policy
2003
def _open(self, transport):
2004
return remote.RemoteBzrDir(transport, self)
2006
def __eq__(self, other):
2007
if not isinstance(other, RemoteBzrDirFormat):
2009
return self.get_format_description() == other.get_format_description()
2011
def __return_repository_format(self):
2012
# Always return a RemoteRepositoryFormat object, but if a specific bzr
2013
# repository format has been asked for, tell the RemoteRepositoryFormat
2014
# that it should use that for init() etc.
2015
result = remote.RemoteRepositoryFormat()
2016
custom_format = getattr(self, '_repository_format', None)
2018
if isinstance(custom_format, remote.RemoteRepositoryFormat):
2019
return custom_format
2021
# We will use the custom format to create repositories over the
2022
# wire; expose its details like rich_root_data for code to
2024
result._custom_format = custom_format
2027
def get_branch_format(self):
2028
result = BzrDirMetaFormat1.get_branch_format(self)
2029
if not isinstance(result, remote.RemoteBranchFormat):
2030
new_result = remote.RemoteBranchFormat()
2031
new_result._custom_format = result
2033
self.set_branch_format(new_result)
2037
repository_format = property(__return_repository_format,
2038
BzrDirMetaFormat1._set_repository_format) #.im_func)
2041
1786
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)