948
948
def sprout(self, url, revision_id=None, force_new_repo=False,
949
949
recurse='down', possible_transports=None,
950
accelerator_tree=None, hardlink=False):
950
accelerator_tree=None, hardlink=False, stacked=False):
951
951
"""Create a copy of this bzrdir prepared for use as a new line of
966
966
content is different.
967
967
:param hardlink: If true, hard-link files from accelerator_tree,
969
:param stacked: If true, create a stacked branch referring to the
970
location of this control directory.
970
972
target_transport = get_transport(url, possible_transports)
971
973
target_transport.ensure_base()
975
977
source_branch = self.open_branch()
976
978
source_repository = source_branch.repository
980
stacked_branch_url = self.root_transport.base
983
stacked_branch_url = source_branch.get_stacked_on()
984
except (errors.NotStacked, errors.UnstackableBranchFormat,
985
errors.UnstackableRepositoryFormat):
986
stacked_branch_url = None
977
987
except errors.NotBranchError:
978
988
source_branch = None
980
990
source_repository = self.open_repository()
981
991
except errors.NoRepositoryPresent:
982
992
source_repository = None
993
stacked_branch_url = None
983
994
if force_new_repo:
984
995
result_repo = None
987
998
result_repo = result.find_repository()
988
999
except errors.NoRepositoryPresent:
989
1000
result_repo = None
990
if source_repository is None and result_repo is not None:
992
elif source_repository is None and result_repo is None:
993
# no repo available, make a new one
994
result.create_repository()
995
elif source_repository is not None and result_repo is None:
1002
# Create/update the result repository as required
1003
if source_repository is None:
1004
if result_repo is None:
1005
# no repo available, make a new one
1006
result.create_repository()
1007
elif stacked_branch_url is not None:
1008
if result_repo is None:
1009
result_repo = source_repository._format.initialize(result)
1010
stacked_dir = BzrDir.open(stacked_branch_url)
1012
stacked_repo = stacked_dir.open_branch().repository
1013
except errors.NotBranchError:
1014
stacked_repo = stacked_dir.open_repository()
1015
result_repo.add_fallback_repository(stacked_repo)
1016
result_repo.fetch(source_repository, revision_id=revision_id)
1017
elif result_repo is None:
996
1018
# have source, and want to make a new target repo
997
1019
result_repo = source_repository.sprout(result,
998
1020
revision_id=revision_id)
1000
# fetch needed content into target.
1001
if source_repository is not None:
1003
# source_repository.copy_content_into(result_repo,
1004
# revision_id=revision_id)
1005
# so we can override the copy method
1006
result_repo.fetch(source_repository, revision_id=revision_id)
1022
# Fetch needed content into target.
1023
# Would rather do it this way ...
1024
# source_repository.copy_content_into(result_repo,
1025
# revision_id=revision_id)
1026
# so we can override the copy method
1027
result_repo.fetch(source_repository, revision_id=revision_id)
1029
# Create/update the result branch
1007
1030
if source_branch is not None:
1008
source_branch.sprout(result, revision_id=revision_id)
1031
result_branch = source_branch.sprout(result,
1032
revision_id=revision_id)
1010
result.create_branch()
1034
result_branch = result.create_branch()
1035
if stacked_branch_url is not None:
1036
result_branch.set_stacked_on(stacked_branch_url)
1038
# Create/update the result working tree
1011
1039
if isinstance(target_transport, LocalTransport) and (
1012
1040
result_repo is None or result_repo.make_working_trees()):
1013
1041
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1043
1069
sublocation = source_branch.reference_parent(file_id, path)
1044
1070
sublocation.bzrdir.sprout(target,
1045
1071
basis.get_reference_revision(file_id, path),
1046
force_new_repo=force_new_repo, recurse=recurse)
1072
force_new_repo=force_new_repo, recurse=recurse,
1048
1075
if basis is not None:
1184
1211
def sprout(self, url, revision_id=None, force_new_repo=False,
1185
1212
possible_transports=None, accelerator_tree=None,
1213
hardlink=False, stacked=False):
1187
1214
"""See BzrDir.sprout()."""
1216
raise errors.UnstackableBranchFormat(
1217
self._format, self.root_transport.base)
1188
1218
from bzrlib.workingtree import WorkingTreeFormat2
1189
1219
self._make_tail(url)
1190
1220
result = self._format._initialize_for_clone(url)
2409
2439
# TODO: conversions of Branch and Tree should be done by
2410
# InterXFormat lookups
2440
# InterXFormat lookups/some sort of registry.
2411
2441
# Avoid circular imports
2412
2442
from bzrlib import branch as _mod_branch
2413
if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
2414
self.target_format.get_branch_format().__class__ is
2415
_mod_branch.BzrBranchFormat6):
2416
branch_converter = _mod_branch.Converter5to6()
2443
old = branch._format.__class__
2444
new = self.target_format.get_branch_format().__class__
2446
if (old == _mod_branch.BzrBranchFormat5 and
2447
new in (_mod_branch.BzrBranchFormat6,
2448
_mod_branch.BzrBranchFormat7)):
2449
branch_converter = _mod_branch.Converter5to6()
2450
elif (old == _mod_branch.BzrBranchFormat6 and
2451
new == _mod_branch.BzrBranchFormat7):
2452
branch_converter = _mod_branch.Converter6to7()
2454
raise errors.BadConversionTarget("No converter", new)
2417
2455
branch_converter.convert(branch)
2456
branch = self.bzrdir.open_branch()
2457
old = branch._format.__class__
2419
2459
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2420
2460
except (errors.NoWorkingTree, errors.NotLocalUrl):
2807
2847
# The following two formats should always just be aliases.
2808
2848
format_registry.register_metadir('development',
2809
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
2849
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
2810
2850
help='Current development format. Can convert data to and from pack-0.92 '
2811
2851
'(and anything compatible with pack-0.92) format repositories. '
2812
'Repositories in this format can only be read by bzr.dev. '
2852
'Repositories and branches in this format can only be read by bzr.dev. '
2814
2854
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2816
branch_format='bzrlib.branch.BzrBranchFormat6',
2856
branch_format='bzrlib.branch.BzrBranchFormat7',
2817
2857
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2818
2858
experimental=True,
2821
2861
format_registry.register_metadir('development-subtree',
2822
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
2862
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
2823
2863
help='Current development format, subtree variant. Can convert data to and '
2824
'from pack-0.92 (and anything compatible with pack-0.92) format '
2825
'repositories. Repositories in this format can only be read by '
2826
'bzr.dev. Please read '
2864
'from pack-0.92-subtree (and anything compatible with '
2865
'pack-0.92-subtree) format repositories. Repositories and branches in '
2866
'this format can only be read by bzr.dev. Please read '
2827
2867
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2829
branch_format='bzrlib.branch.BzrBranchFormat6',
2869
branch_format='bzrlib.branch.BzrBranchFormat7',
2830
2870
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2831
2871
experimental=True,
2855
2895
experimental=True,
2897
format_registry.register_metadir('development1',
2898
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
2899
help='A branch and pack based repository that supports stacking. '
2901
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2903
branch_format='bzrlib.branch.BzrBranchFormat7',
2904
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2908
format_registry.register_metadir('development1-subtree',
2909
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
2910
help='A branch and pack based repository that supports stacking. '
2912
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
2914
branch_format='bzrlib.branch.BzrBranchFormat7',
2915
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2919
# The current format that is made on 'bzr init'.
2857
2920
format_registry.set_default('pack-0.92')