974
974
def sprout(self, url, revision_id=None, force_new_repo=False,
975
975
recurse='down', possible_transports=None,
976
accelerator_tree=None, hardlink=False, stacked=False):
976
accelerator_tree=None, hardlink=False):
977
977
"""Create a copy of this bzrdir prepared for use as a new line of
992
992
content is different.
993
993
:param hardlink: If true, hard-link files from accelerator_tree,
995
:param stacked: If true, create a stacked branch referring to the
996
location of this control directory.
998
996
target_transport = get_transport(url, possible_transports)
999
997
target_transport.ensure_base()
1003
1001
source_branch = self.open_branch()
1004
1002
source_repository = source_branch.repository
1006
stacked_branch_url = self.root_transport.base
1009
stacked_branch_url = source_branch.get_stacked_on()
1010
except (errors.NotStacked, errors.UnstackableBranchFormat,
1011
errors.UnstackableRepositoryFormat):
1012
stacked_branch_url = None
1013
1003
except errors.NotBranchError:
1014
1004
source_branch = None
1016
1006
source_repository = self.open_repository()
1017
1007
except errors.NoRepositoryPresent:
1018
1008
source_repository = None
1019
stacked_branch_url = None
1020
1009
if force_new_repo:
1021
1010
result_repo = None
1024
1013
result_repo = result.find_repository()
1025
1014
except errors.NoRepositoryPresent:
1026
1015
result_repo = None
1028
# Create/update the result repository as required
1029
if source_repository is None:
1030
if result_repo is None:
1031
# no repo available, make a new one
1032
result.create_repository()
1033
elif stacked_branch_url is not None:
1034
if result_repo is None:
1035
result_repo = source_repository._format.initialize(result)
1036
stacked_dir = BzrDir.open(stacked_branch_url)
1038
stacked_repo = stacked_dir.open_branch().repository
1039
except errors.NotBranchError:
1040
stacked_repo = stacked_dir.open_repository()
1041
result_repo.add_fallback_repository(stacked_repo)
1042
result_repo.fetch(source_repository, revision_id=revision_id)
1043
elif result_repo is None:
1016
if source_repository is None and result_repo is not None:
1018
elif source_repository is None and result_repo is None:
1019
# no repo available, make a new one
1020
result.create_repository()
1021
elif source_repository is not None and result_repo is None:
1044
1022
# have source, and want to make a new target repo
1045
1023
result_repo = source_repository.sprout(result,
1046
1024
revision_id=revision_id)
1048
# Fetch needed content into target.
1049
# Would rather do it this way ...
1050
# source_repository.copy_content_into(result_repo,
1051
# revision_id=revision_id)
1052
# so we can override the copy method
1053
result_repo.fetch(source_repository, revision_id=revision_id)
1055
# Create/update the result branch
1026
# fetch needed content into target.
1027
if source_repository is not None:
1029
# source_repository.copy_content_into(result_repo,
1030
# revision_id=revision_id)
1031
# so we can override the copy method
1032
result_repo.fetch(source_repository, revision_id=revision_id)
1056
1033
if source_branch is not None:
1057
result_branch = source_branch.sprout(result,
1058
revision_id=revision_id)
1034
source_branch.sprout(result, revision_id=revision_id)
1060
result_branch = result.create_branch()
1061
if stacked_branch_url is not None:
1062
result_branch.set_stacked_on(stacked_branch_url)
1064
# Create/update the result working tree
1036
result.create_branch()
1065
1037
if isinstance(target_transport, LocalTransport) and (
1066
1038
result_repo is None or result_repo.make_working_trees()):
1067
1039
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1095
1069
sublocation = source_branch.reference_parent(file_id, path)
1096
1070
sublocation.bzrdir.sprout(target,
1097
1071
basis.get_reference_revision(file_id, path),
1098
force_new_repo=force_new_repo, recurse=recurse,
1072
force_new_repo=force_new_repo, recurse=recurse)
1101
1074
if basis is not None:
1237
1210
def sprout(self, url, revision_id=None, force_new_repo=False,
1238
1211
possible_transports=None, accelerator_tree=None,
1239
hardlink=False, stacked=False):
1240
1213
"""See BzrDir.sprout()."""
1242
raise errors.UnstackableBranchFormat(
1243
self._format, self.root_transport.base)
1244
1214
from bzrlib.workingtree import WorkingTreeFormat2
1245
1215
self._make_tail(url)
1246
1216
result = self._format._initialize_for_clone(url)
2465
2435
# TODO: conversions of Branch and Tree should be done by
2466
# InterXFormat lookups/some sort of registry.
2436
# InterXFormat lookups
2467
2437
# Avoid circular imports
2468
2438
from bzrlib import branch as _mod_branch
2469
old = branch._format.__class__
2470
new = self.target_format.get_branch_format().__class__
2472
if (old == _mod_branch.BzrBranchFormat5 and
2473
new in (_mod_branch.BzrBranchFormat6,
2474
_mod_branch.BzrBranchFormat7)):
2475
branch_converter = _mod_branch.Converter5to6()
2476
elif (old == _mod_branch.BzrBranchFormat6 and
2477
new == _mod_branch.BzrBranchFormat7):
2478
branch_converter = _mod_branch.Converter6to7()
2480
raise errors.BadConversionTarget("No converter", new)
2439
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2440
self.target_format.get_branch_format().__class__ is
2441
_mod_branch.BzrBranchFormat6):
2442
branch_converter = _mod_branch.Converter5to6()
2481
2443
branch_converter.convert(branch)
2482
branch = self.bzrdir.open_branch()
2483
old = branch._format.__class__
2485
2445
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2486
2446
except (errors.NoWorkingTree, errors.NotLocalUrl):
2873
2833
# The following two formats should always just be aliases.
2874
2834
format_registry.register_metadir('development',
2875
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
2835
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
2876
2836
help='Current development format. Can convert data to and from pack-0.92 '
2877
2837
'(and anything compatible with pack-0.92) format repositories. '
2878
'Repositories and branches in this format can only be read by bzr.dev. '
2838
'Repositories in this format can only be read by bzr.dev. '
2880
2840
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2882
branch_format='bzrlib.branch.BzrBranchFormat7',
2842
branch_format='bzrlib.branch.BzrBranchFormat6',
2883
2843
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2884
2844
experimental=True,
2887
2847
format_registry.register_metadir('development-subtree',
2888
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
2848
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
2889
2849
help='Current development format, subtree variant. Can convert data to and '
2890
'from pack-0.92-subtree (and anything compatible with '
2891
'pack-0.92-subtree) format repositories. Repositories and branches in '
2892
'this format can only be read by bzr.dev. Please read '
2850
'from pack-0.92 (and anything compatible with pack-0.92) format '
2851
'repositories. Repositories in this format can only be read by '
2852
'bzr.dev. Please read '
2893
2853
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2895
branch_format='bzrlib.branch.BzrBranchFormat7',
2855
branch_format='bzrlib.branch.BzrBranchFormat6',
2896
2856
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2897
2857
experimental=True,
2921
2881
experimental=True,
2923
format_registry.register_metadir('development1',
2924
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
2925
help='A branch and pack based repository that supports stacking. '
2927
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2929
branch_format='bzrlib.branch.BzrBranchFormat7',
2930
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2934
format_registry.register_metadir('development1-subtree',
2935
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
2936
help='A branch and pack based repository that supports stacking. '
2938
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2940
branch_format='bzrlib.branch.BzrBranchFormat7',
2941
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2945
# The current format that is made on 'bzr init'.
2946
2883
format_registry.set_default('pack-0.92')