177
177
preserve_stacking=preserve_stacking)
179
179
def clone_on_transport(self, transport, revision_id=None,
180
force_new_repo=False, preserve_stacking=False):
180
force_new_repo=False, preserve_stacking=False,
181
182
"""Clone this bzrdir and its contents to transport verbatim.
183
184
:param transport: The transport for the location to produce the clone
191
192
new branch on top of the other branch's stacked-on branch.
193
194
transport.ensure_base()
194
result = self.cloning_metadir().initialize_on_transport(transport)
195
require_stacking = (stacked_on is not None)
196
metadir = self.cloning_metadir(require_stacking)
197
result = metadir.initialize_on_transport(transport)
195
198
repository_policy = None
198
200
local_repo = self.find_repository()
199
201
except errors.NoRepositoryPresent:
218
220
# may need to copy content in
219
221
repository_policy = result.determine_repository_policy(
220
force_new_repo, stack_on, self.root_transport.base)
222
force_new_repo, stacked_on, self.root_transport.base,
223
require_stacking=require_stacking)
221
224
make_working_trees = local_repo.make_working_trees()
222
225
result_repo = repository_policy.acquire_repository(
223
226
make_working_trees, local_repo.is_shared())
656
659
# directories and files are read-write for this user. This is
657
660
# mostly a workaround for filesystems which lie about being able to
658
661
# write to a directory (cygwin & win32)
659
self._dir_mode = (st.st_mode & 07777) | 00700
660
# Remove the sticky and execute bits for files
661
self._file_mode = self._dir_mode & ~07111
662
if (st.st_mode & 07777 == 00000):
663
# FTP allows stat but does not return dir/file modes
664
self._dir_mode = None
665
self._file_mode = None
667
self._dir_mode = (st.st_mode & 07777) | 00700
668
# Remove the sticky and execute bits for files
669
self._file_mode = self._dir_mode & ~07111
663
671
def _get_file_mode(self):
664
672
"""Return Unix mode for newly created files, or None.
1011
1020
result_format.workingtree_format = tree._format.__class__()
1012
1021
return result_format, source_repository
1014
def cloning_metadir(self):
1023
def cloning_metadir(self, require_stacking=False):
1015
1024
"""Produce a metadir suitable for cloning or sprouting with.
1017
1026
These operations may produce workingtrees (yes, even though they're
1018
1027
"cloning" something that doesn't have a tree), so a viable workingtree
1019
1028
format must be selected.
1030
:require_stacking: If True, non-stackable formats will be upgraded
1031
to similar stackable formats.
1021
1032
:returns: a BzrDirFormat with all component formats either set
1022
appropriately or set to None if that component should not be
1033
appropriately or set to None if that component should not be
1025
1036
format, repository = self._cloning_metadir()
1029
1040
tree_format = repository._format._matchingbzrdir.workingtree_format
1030
1041
format.workingtree_format = tree_format.__class__()
1042
if (require_stacking and not
1043
format.get_branch_format().supports_stacking()):
1044
# We need to make a stacked branch, but the default format for the
1045
# target doesn't support stacking. So force a branch that *can*
1047
from bzrlib.branch import BzrBranchFormat7
1048
format._branch_format = BzrBranchFormat7()
1049
mutter("using %r for stacking" % (format._branch_format,))
1050
from bzrlib.repofmt import pack_repo
1051
if format.repository_format.rich_root_data:
1052
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1054
repo_format = pack_repo.RepositoryFormatKnitPack5()
1055
format.repository_format = repo_format
1033
1058
def checkout_metadir(self):
1060
1085
target_transport = get_transport(url, possible_transports)
1061
1086
target_transport.ensure_base()
1062
cloning_format = self.cloning_metadir()
1087
cloning_format = self.cloning_metadir(stacked)
1088
# Create/update the result branch
1063
1089
result = cloning_format.initialize_on_transport(target_transport)
1065
1091
source_branch = self.open_branch()
1081
1107
force_new_repo, stacked_branch_url, require_stacking=stacked)
1082
1108
result_repo = repository_policy.acquire_repository()
1083
1109
if source_repository is not None:
1084
# XXX: Isn't this redundant with the copy_content_into used below
1085
# after creating the branch? -- mbp 20080724
1110
# Fetch while stacked to prevent unstacked fetch from
1086
1112
result_repo.fetch(source_repository, revision_id=revision_id)
1088
# Create/update the result branch
1089
format_forced = False
1091
or repository_policy._require_stacking
1092
or repository_policy._stack_on)
1093
and not result._format.get_branch_format().supports_stacking()):
1094
# We need to make a stacked branch, but the default format for the
1095
# target doesn't support stacking. So force a branch that *can*
1097
from bzrlib.branch import BzrBranchFormat7
1098
format = BzrBranchFormat7()
1099
result_branch = format.initialize(result)
1100
mutter("using %r for stacking" % (format,))
1101
format_forced = True
1102
elif source_branch is None:
1114
if source_branch is None:
1103
1115
# this is for sprouting a bzrdir without a branch; is that
1104
1116
# actually useful?
1117
# Not especially, but it's part of the contract.
1105
1118
result_branch = result.create_branch()
1120
# Force NULL revision to avoid using repository before stacking
1107
1122
result_branch = source_branch.sprout(
1108
result, revision_id=revision_id)
1123
result, revision_id=_mod_revision.NULL_REVISION)
1124
parent_location = result_branch.get_parent()
1109
1125
mutter("created new branch %r" % (result_branch,))
1110
1126
repository_policy.configure_branch(result_branch)
1111
if source_branch is not None and format_forced:
1112
# XXX: this duplicates Branch.sprout(); it probably belongs on an
1113
# InterBranch method? -- mbp 20080724
1114
source_branch.copy_content_into(result_branch,
1115
revision_id=revision_id)
1116
result_branch.set_parent(self.root_transport.base)
1127
if source_branch is not None:
1128
source_branch.copy_content_into(result_branch, revision_id)
1129
# Override copy_content_into
1130
result_branch.set_parent(parent_location)
1118
1132
# Create/update the result working tree
1119
1133
if isinstance(target_transport, LocalTransport) and (
1172
1186
"""Pre-splitout bzrdirs do not suffer from stale locks."""
1173
1187
raise NotImplementedError(self.break_lock)
1175
def cloning_metadir(self):
1189
def cloning_metadir(self, require_stacking=False):
1176
1190
"""Produce a metadir suitable for cloning with."""
1191
if require_stacking:
1192
return format_registry.make_bzrdir('1.6')
1177
1193
return self._format.__class__()
1179
1195
def clone(self, url, revision_id=None, force_new_repo=False,
1185
1201
preserve_stacking has no effect, since no source branch using this
1186
1202
family of formats can be stacked, so there is no stacking to preserve.
1188
from bzrlib.workingtree import WorkingTreeFormat2
1189
1204
self._make_tail(url)
1190
1205
result = self._format._initialize_for_clone(url)
1191
1206
self.open_repository().clone(result, revision_id=revision_id)
1192
1207
from_branch = self.open_branch()
1193
1208
from_branch.clone(result, revision_id=revision_id)
1195
self.open_workingtree().clone(result)
1210
tree = self.open_workingtree()
1196
1211
except errors.NotLocalUrl:
1197
1212
# make a new one, this format always has to have one.
1199
WorkingTreeFormat2().initialize(result)
1200
except errors.NotLocalUrl:
1201
# but we cannot do it for remote trees.
1202
to_branch = result.open_branch()
1203
WorkingTreeFormat2()._stub_initialize_remote(to_branch)
1213
result._init_workingtree()
1206
1218
def create_branch(self):
1207
1219
"""See BzrDir.create_branch."""
1208
return self.open_branch()
1220
return self._format.get_branch_format().initialize(self)
1210
1222
def destroy_branch(self):
1211
1223
"""See BzrDir.destroy_branch."""
1224
1236
def create_workingtree(self, revision_id=None, from_branch=None,
1225
1237
accelerator_tree=None, hardlink=False):
1226
1238
"""See BzrDir.create_workingtree."""
1239
# The workingtree is sometimes created when the bzrdir is created,
1240
# but not when cloning.
1227
1242
# this looks buggy but is not -really-
1228
1243
# because this format creates the workingtree when the bzrdir is
1233
1248
# that can do wonky stuff here, and that only
1234
1249
# happens for creating checkouts, which cannot be
1235
1250
# done on this format anyway. So - acceptable wart.
1236
result = self.open_workingtree(recommend_upgrade=False)
1252
result = self.open_workingtree(recommend_upgrade=False)
1253
except errors.NoSuchFile:
1254
result = self._init_workingtree()
1237
1255
if revision_id is not None:
1238
1256
if revision_id == _mod_revision.NULL_REVISION:
1239
1257
result.set_parent_ids([])
1241
1259
result.set_parent_ids([revision_id])
1262
def _init_workingtree(self):
1263
from bzrlib.workingtree import WorkingTreeFormat2
1265
return WorkingTreeFormat2().initialize(self)
1266
except errors.NotLocalUrl:
1267
# Even though we can't access the working tree, we need to
1268
# create its control files.
1269
return WorkingTreeFormat2()._stub_initialize_on_transport(
1270
self.transport, self._control_files._file_mode)
1244
1272
def destroy_workingtree(self):
1245
1273
"""See BzrDir.destroy_workingtree."""
1246
1274
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1853
1881
"""See BzrDirFormat.get_format_string()."""
1854
1882
return "Bazaar-NG branch, format 5\n"
1884
def get_branch_format(self):
1885
from bzrlib import branch
1886
return branch.BzrBranchFormat4()
1856
1888
def get_format_description(self):
1857
1889
"""See BzrDirFormat.get_format_description()."""
1858
1890
return "All-in-one format 5"
1873
1905
from bzrlib.branch import BzrBranchFormat4
1874
1906
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1875
from bzrlib.workingtree import WorkingTreeFormat2
1876
1907
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1877
1908
RepositoryFormat5().initialize(result, _internal=True)
1878
1909
if not _cloning:
1879
1910
branch = BzrBranchFormat4().initialize(result)
1881
WorkingTreeFormat2().initialize(result)
1882
except errors.NotLocalUrl:
1883
# Even though we can't access the working tree, we need to
1884
# create its control files.
1885
WorkingTreeFormat2()._stub_initialize_remote(branch)
1911
result._init_workingtree()
1888
1914
def _open(self, transport):
1916
1942
"""See BzrDirFormat.get_format_description()."""
1917
1943
return "All-in-one format 6"
1945
def get_branch_format(self):
1946
from bzrlib import branch
1947
return branch.BzrBranchFormat4()
1919
1949
def get_converter(self, format=None):
1920
1950
"""See BzrDirFormat.get_converter()."""
1921
1951
# there is one and only one upgrade path here.
1932
1962
from bzrlib.branch import BzrBranchFormat4
1933
1963
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1934
from bzrlib.workingtree import WorkingTreeFormat2
1935
1964
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1936
1965
RepositoryFormat6().initialize(result, _internal=True)
1937
1966
if not _cloning:
1938
1967
branch = BzrBranchFormat4().initialize(result)
1940
WorkingTreeFormat2().initialize(result)
1941
except errors.NotLocalUrl:
1942
# Even though we can't access the working tree, we need to
1943
# create its control files.
1944
WorkingTreeFormat2()._stub_initialize_remote(branch)
1968
result._init_workingtree()
1947
1971
def _open(self, transport):
2892
2916
Creates the desired repository in the bzrdir we already have.
2894
if self._stack_on or self._require_stacking:
2895
# we may be coming from a format that doesn't support stacking,
2896
# but we require it in the destination, so force creation of a new
2899
# TODO: perhaps this should be treated as a distinct repository
2900
# acquisition policy?
2901
repository_format = self._bzrdir._format.repository_format
2902
if not repository_format.supports_external_lookups:
2903
# should possibly be controlled by the registry rather than
2905
from bzrlib.repofmt import pack_repo
2906
if repository_format.rich_root_data:
2907
repository_format = \
2908
pack_repo.RepositoryFormatKnitPack5RichRoot()
2910
repository_format = pack_repo.RepositoryFormatKnitPack5()
2911
note("using %r for stacking" % (repository_format,))
2912
repository = repository_format.initialize(self._bzrdir,
2916
repository = self._bzrdir.create_repository(shared=shared)
2918
repository = self._bzrdir.create_repository(shared=shared)
2917
2919
self._add_fallback(repository)
2918
2920
if make_working_trees is not None:
2919
2921
repository.set_make_working_trees(make_working_trees)
3033
3035
branch_format='bzrlib.branch.BzrBranchFormat7',
3034
3036
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3036
format_registry.register_metadir('1.6-rich-root',
3038
format_registry.register_metadir('1.6.1-rich-root',
3037
3039
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3038
3040
help='A branch and pack based repository that supports stacking '
3039
3041
'and rich root data (needed for bzr-svn). ',
3070
3072
# And the development formats which the will have aliased one of follow:
3071
format_registry.register_metadir('development0',
3072
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
3073
help='Trivial rename of pack-0.92 to provide a development format. '
3075
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3077
branch_format='bzrlib.branch.BzrBranchFormat6',
3078
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3082
format_registry.register_metadir('development0-subtree',
3083
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
3084
help='Trivial rename of pack-0.92-subtree to provide a development format. '
3086
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3088
branch_format='bzrlib.branch.BzrBranchFormat6',
3089
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3093
3073
format_registry.register_metadir('development1',
3094
3074
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3095
3075
help='A branch and pack based repository that supports stacking. '