1856
1858
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1857
1859
create_prefix=False, force_new_repo=False, stacked_on=None,
1858
1860
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1861
shared_repo=False, vfs_only=False):
1860
1862
"""Create this format on transport.
1862
1864
The directory to initialize will be created.
1879
1881
default the format has.
1880
1882
:param shared_repo: Control whether made repositories are shared or
1884
:param vfs_only: If True do not attempt to use a smart server
1882
1885
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1883
1886
None if none was created or found, bzrdir is always valid.
1884
1887
require_stacking is the result of examining the stacked_on
1885
1888
parameter and any stacking policy found for the target.
1891
# Try to hand off to a smart server
1893
client_medium = transport.get_smart_medium()
1894
except errors.NoSmartMedium:
1897
# TODO: lookup the local format from a server hint.
1898
remote_dir_format = RemoteBzrDirFormat()
1899
remote_dir_format._network_name = self.network_name()
1900
self._supply_sub_formats_to(remote_dir_format)
1901
return remote_dir_format.initialize_on_transport_ex(transport,
1902
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1903
force_new_repo=force_new_repo, stacked_on=stacked_on,
1904
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1905
make_working_trees=make_working_trees, shared_repo=shared_repo)
1887
1906
# XXX: Refactor the create_prefix/no_create_prefix code into a
1888
1907
# common helper function
1889
1908
# The destination may not exist - if so make it according to policy.
3022
3041
self._supply_sub_formats_to(format)
3023
3042
return remote.RemoteBzrDir(transport, format)
3044
def parse_NoneTrueFalse(self, arg):
3051
raise AssertionError("invalid arg %r" % arg)
3025
3053
def _serialize_NoneTrueFalse(self, arg):
3026
3054
if arg is False:
3060
def _serialize_NoneString(self, arg):
3032
3063
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3033
3064
create_prefix=False, force_new_repo=False, stacked_on=None,
3034
3065
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3054
3085
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3055
3086
force_new_repo=force_new_repo, stacked_on=stacked_on,
3056
3087
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3057
make_working_trees=make_working_trees, shared_repo=shared_repo)
3058
if not (create_prefix is False and force_new_repo is False and
3059
stacked_on is None and stack_on_pwd is None and repo_format_name is
3060
None and make_working_trees is None and shared_repo is False):
3061
local_dir_format = BzrDirMetaFormat1()
3062
self._supply_sub_formats_to(local_dir_format)
3063
return local_dir_format.initialize_on_transport_ex(transport,
3064
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3065
force_new_repo=force_new_repo, stacked_on=stacked_on,
3066
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3067
make_working_trees=make_working_trees, shared_repo=shared_repo)
3088
make_working_trees=make_working_trees, shared_repo=shared_repo,
3069
3091
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3092
args.append(self._serialize_NoneTrueFalse(create_prefix))
3093
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3094
args.append(self._serialize_NoneString(stacked_on))
3095
# stack_on_pwd is often/usually our transport
3098
stack_on_pwd = transport.relpath(stack_on_pwd)
3099
if not stack_on_pwd:
3101
except errors.PathNotChild:
3103
args.append(self._serialize_NoneString(stack_on_pwd))
3104
args.append(self._serialize_NoneString(repo_format_name))
3105
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3106
args.append(self._serialize_NoneTrueFalse(shared_repo))
3107
if self._network_name is None:
3108
self._network_name = \
3109
BzrDirFormat.get_default_format().network_name()
3071
response = client.call('BzrDirFormat.initialize_ex', path, *args)
3111
response = client.call('BzrDirFormat.initialize_ex',
3112
self.network_name(), path, *args)
3072
3113
except errors.UnknownSmartMethod:
3073
3114
local_dir_format = BzrDirMetaFormat1()
3074
3115
self._supply_sub_formats_to(local_dir_format)
3076
3117
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3077
3118
force_new_repo=force_new_repo, stacked_on=stacked_on,
3078
3119
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3079
make_working_trees=make_working_trees, shared_repo=shared_repo)
3120
make_working_trees=make_working_trees, shared_repo=shared_repo,
3122
repo_path = response[0]
3123
bzrdir_name = response[6]
3124
require_stacking = response[7]
3125
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3080
3126
format = RemoteBzrDirFormat()
3127
format._network_name = bzrdir_name
3081
3128
self._supply_sub_formats_to(format)
3082
return None, remote.RemoteBzrDir(transport, format), None, None
3129
bzrdir = remote.RemoteBzrDir(transport, format)
3131
repo_format = remote.response_tuple_to_repo_format(response[1:])
3132
if repo_path == '.':
3135
repo_bzrdir_format = RemoteBzrDirFormat()
3136
repo_bzrdir_format._network_name = response[5]
3137
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3141
final_stack = response[8] or None
3142
final_stack_pwd = response[9] or None
3143
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3144
policy = UseExistingRepository(remote_repo, final_stack,
3145
final_stack_pwd, require_stacking)
3146
policy.acquire_repository()
3150
return remote_repo, bzrdir, require_stacking, policy
3084
3152
def _open(self, transport):
3085
3153
return remote.RemoteBzrDir(transport, self)
3360
3428
stack_on = self._get_full_stack_on()
3361
3429
if stack_on is None:
3363
stacked_dir = BzrDir.open(stack_on,
3364
possible_transports=possible_transports)
3432
stacked_dir = BzrDir.open(stack_on,
3433
possible_transports=possible_transports)
3434
except errors.JailBreak:
3435
# We keep the stacking details, but we are in the server code so
3436
# actually stacking is not needed.
3366
3439
stacked_repo = stacked_dir.open_branch().repository
3367
3440
except errors.NotBranchError:
3422
3495
# network round trips to check - but we only do this
3423
3496
# when the source can't stack so it will fade away
3424
3497
# as people do upgrade.
3498
branch_format = None
3426
3501
target_dir = BzrDir.open(stack_on,
3427
3502
possible_transports=[self._bzrdir.root_transport])
3428
3503
except errors.NotBranchError:
3429
3504
# Nothing there, don't change formats
3506
except errors.JailBreak:
3507
# stack_on is inaccessible, JFDI.
3508
if format.repository_format.rich_root_data:
3509
repo_format = pack_repo.RepositoryFormatKnitPack6RichRoot()
3511
repo_format = pack_repo.RepositoryFormatKnitPack6()
3512
branch_format = branch.BzrBranchFormat7()
3433
3515
target_branch = target_dir.open_branch()
3440
3522
if not (branch_format.supports_stacking()
3441
3523
and repo_format.supports_external_lookups):
3442
3524
# Doesn't stack itself, don't force an upgrade
3445
# Does support stacking, use its format.
3446
format.repository_format = repo_format
3447
format.set_branch_format(branch_format)
3448
note('Source format does not support stacking, '
3449
'using format: \'%s\'\n %s\n',
3450
branch_format.get_format_description(),
3451
repo_format.get_format_description())
3525
branch_format = None
3527
if branch_format and repo_format:
3528
# Does support stacking, use its format.
3529
format.repository_format = repo_format
3530
format.set_branch_format(branch_format)
3531
note('Source format does not support stacking, '
3532
'using format: \'%s\'\n %s\n',
3533
branch_format.get_format_description(),
3534
repo_format.get_format_description())
3452
3535
if not self._require_stacking:
3453
3536
# We have picked up automatic stacking somewhere.
3454
3537
note('Using default stacking branch %s at %s', self._stack_on,