2358
2358
def set_branch_format(self, format):
2359
2359
self._branch_format = format
2361
def require_stacking(self):
2361
def require_stacking(self, stack_on=None, possible_transports=None):
2362
"""We have a request to stack, try to ensure the formats support it.
2364
:param stack_on: If supplied, it is the URL to a branch that we want to
2365
stack on. Check to see if that format supports stacking before
2368
# Stacking is desired. requested by the target, but does the place it
2369
# points at support stacking? If it doesn't then we should
2370
# not implicitly upgrade. We check this here.
2371
new_repo_format = None
2372
new_branch_format = None
2374
# a bit of state for get_target_branch so that we don't try to open it
2375
# 2 times, for both repo *and* branch
2376
target = [None, False, None] # target_branch, checked, upgrade anyway
2377
def get_target_branch():
2379
# We've checked, don't check again
2381
if stack_on is None:
2382
# No target format, that means we want to force upgrading
2383
target[:] = [None, True, True]
2386
target_dir = BzrDir.open(stack_on,
2387
possible_transports=possible_transports)
2388
except errors.NotBranchError:
2389
# Nothing there, don't change formats
2390
target[:] = [None, True, False]
2392
except errors.JailBreak:
2393
# JailBreak, JFDI and upgrade anyway
2394
target[:] = [None, True, True]
2397
target_branch = target_dir.open_branch()
2398
except errors.NotBranchError:
2399
# No branch, don't upgrade formats
2400
target[:] = [None, True, False]
2402
target[:] = [target_branch, True, False]
2405
if not (self.repository_format.supports_external_lookups):
2406
# We need to upgrade the Repository.
2407
target_branch, _, do_upgrade = get_target_branch()
2408
if target_branch is None:
2409
# We don't have a target branch, should we upgrade anyway?
2411
# stack_on is inaccessible, JFDI.
2412
# TODO: bad monkey, hard-coded formats...
2413
if self.repository_format.rich_root_data:
2414
new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2416
new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2418
# If the target already supports stacking, then we know the
2419
# project is already able to use stacking, so auto-upgrade
2421
new_repo_format = target_branch.repository._format
2422
if not new_repo_format.supports_external_lookups:
2423
# target doesn't, source doesn't, so don't auto upgrade
2425
new_repo_format = None
2426
if new_repo_format is not None:
2427
self.repository_format = new_repo_format
2428
note('Source repository format does not support stacking,'
2429
' using format:\n %s',
2430
new_repo_format.get_format_description())
2362
2432
if not self.get_branch_format().supports_stacking():
2363
# We need to make a stacked branch, but the default format for the
2364
# target doesn't support stacking. So force a branch that *can*
2366
from bzrlib.branch import BzrBranchFormat7
2367
branch_format = BzrBranchFormat7()
2368
self.set_branch_format(branch_format)
2369
mutter("using %r for stacking" % (branch_format,))
2370
from bzrlib.repofmt import pack_repo
2371
if self.repository_format.rich_root_data:
2372
bzrdir_format_name = '1.6.1-rich-root'
2373
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2433
# We just checked the repo, now lets check if we need to
2434
# upgrade the branch format
2435
target_branch, _, do_upgrade = get_target_branch()
2436
if target_branch is None:
2438
# TODO: bad monkey, hard-coded formats...
2439
new_branch_format = branch.BzrBranchFormat7()
2375
bzrdir_format_name = '1.6'
2376
repo_format = pack_repo.RepositoryFormatKnitPack5()
2377
note('Source format does not support stacking, using format:'
2379
bzrdir_format_name, repo_format.get_format_description())
2380
self.repository_format = repo_format
2441
new_branch_format = target_branch._format
2442
if not new_branch_format.supports_stacking():
2443
new_branch_format = None
2444
if new_branch_format is not None:
2445
# Does support stacking, use its format.
2446
self.set_branch_format(new_branch_format)
2447
note('Source branch format does not support stacking,'
2448
' using format:\n %s',
2449
new_branch_format.get_format_description())
2382
2451
def get_converter(self, format=None):
2383
2452
"""See BzrDirFormat.get_converter()."""
3115
3187
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3116
3188
make_working_trees=make_working_trees, shared_repo=shared_repo,
3190
return self._initialize_on_transport_ex_rpc(client, path, transport,
3191
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3192
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
3194
def _initialize_on_transport_ex_rpc(self, client, path, transport,
3195
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3196
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3119
3198
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3120
3199
args.append(self._serialize_NoneTrueFalse(create_prefix))
3521
3602
stack_on = self._get_full_stack_on()
3523
# Stacking is desired. requested by the target, but does the place it
3524
# points at support stacking? If it doesn't then we should
3525
# not implicitly upgrade. We check this here.
3526
3604
format = self._bzrdir._format
3527
if not (format.repository_format.supports_external_lookups
3528
and format.get_branch_format().supports_stacking()):
3529
# May need to upgrade - but only do if the target also
3530
# supports stacking. Note that this currently wastes
3531
# network round trips to check - but we only do this
3532
# when the source can't stack so it will fade away
3533
# as people do upgrade.
3534
branch_format = None
3537
target_dir = BzrDir.open(stack_on,
3538
possible_transports=[self._bzrdir.root_transport])
3539
except errors.NotBranchError:
3540
# Nothing there, don't change formats
3542
except errors.JailBreak:
3543
# stack_on is inaccessible, JFDI.
3544
if format.repository_format.rich_root_data:
3545
repo_format = pack_repo.RepositoryFormatKnitPack6RichRoot()
3547
repo_format = pack_repo.RepositoryFormatKnitPack6()
3548
branch_format = branch.BzrBranchFormat7()
3551
target_branch = target_dir.open_branch()
3552
except errors.NotBranchError:
3553
# No branch, don't change formats
3556
branch_format = target_branch._format
3557
repo_format = target_branch.repository._format
3558
if not (branch_format.supports_stacking()
3559
and repo_format.supports_external_lookups):
3560
# Doesn't stack itself, don't force an upgrade
3561
branch_format = None
3563
if branch_format and repo_format:
3564
# Does support stacking, use its format.
3565
format.repository_format = repo_format
3566
format.set_branch_format(branch_format)
3567
note('Source format does not support stacking, '
3568
'using format: \'%s\'\n %s\n',
3569
branch_format.get_format_description(),
3570
repo_format.get_format_description())
3605
format.require_stacking(stack_on=stack_on,
3606
possible_transports=[self._bzrdir.root_transport])
3571
3607
if not self._require_stacking:
3572
3608
# We have picked up automatic stacking somewhere.
3573
3609
note('Using default stacking branch %s at %s', self._stack_on,