656
662
# directories and files are read-write for this user. This is
657
663
# mostly a workaround for filesystems which lie about being able to
658
664
# 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
665
if (st.st_mode & 07777 == 00000):
666
# FTP allows stat but does not return dir/file modes
667
self._dir_mode = None
668
self._file_mode = None
670
self._dir_mode = (st.st_mode & 07777) | 00700
671
# Remove the sticky and execute bits for files
672
self._file_mode = self._dir_mode & ~07111
663
674
def _get_file_mode(self):
664
675
"""Return Unix mode for newly created files, or None.
771
782
:param transport: Transport containing the bzrdir.
772
783
:param _unsupported: private.
785
# Keep initial base since 'transport' may be modified while following
774
787
base = transport.base
776
788
def find_format(transport):
777
789
return transport, BzrDirFormat.find_format(
778
790
transport, _server_formats=_server_formats)
780
792
def redirected(transport, e, redirection_notice):
781
qualified_source = e.get_source_url()
782
relpath = transport.relpath(qualified_source)
783
if not e.target.endswith(relpath):
784
# Not redirected to a branch-format, not a branch
785
raise errors.NotBranchError(path=e.target)
786
target = e.target[:-len(relpath)]
793
redirected_transport = transport._redirected_to(e.source, e.target)
794
if redirected_transport is None:
795
raise errors.NotBranchError(base)
787
796
note('%s is%s redirected to %s',
788
transport.base, e.permanently, target)
789
# Let's try with a new transport
790
# FIXME: If 'transport' has a qualifier, this should
791
# be applied again to the new transport *iff* the
792
# schemes used are the same. Uncomment this code
793
# once the function (and tests) exist.
795
#target = urlutils.copy_url_qualifiers(original, target)
796
return get_transport(target)
797
transport.base, e.permanently, redirected_transport.base)
798
return redirected_transport
799
801
transport, format = do_catching_redirections(find_format,
1011
1016
result_format.workingtree_format = tree._format.__class__()
1012
1017
return result_format, source_repository
1014
def cloning_metadir(self):
1019
def cloning_metadir(self, require_stacking=False):
1015
1020
"""Produce a metadir suitable for cloning or sprouting with.
1017
1022
These operations may produce workingtrees (yes, even though they're
1018
1023
"cloning" something that doesn't have a tree), so a viable workingtree
1019
1024
format must be selected.
1026
:require_stacking: If True, non-stackable formats will be upgraded
1027
to similar stackable formats.
1021
1028
:returns: a BzrDirFormat with all component formats either set
1022
appropriately or set to None if that component should not be
1029
appropriately or set to None if that component should not be
1025
1032
format, repository = self._cloning_metadir()
1029
1036
tree_format = repository._format._matchingbzrdir.workingtree_format
1030
1037
format.workingtree_format = tree_format.__class__()
1038
if (require_stacking and not
1039
format.get_branch_format().supports_stacking()):
1040
# We need to make a stacked branch, but the default format for the
1041
# target doesn't support stacking. So force a branch that *can*
1043
from bzrlib.branch import BzrBranchFormat7
1044
format._branch_format = BzrBranchFormat7()
1045
mutter("using %r for stacking" % (format._branch_format,))
1046
from bzrlib.repofmt import pack_repo
1047
if format.repository_format.rich_root_data:
1048
bzrdir_format_name = '1.6.1-rich-root'
1049
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1051
bzrdir_format_name = '1.6'
1052
repo_format = pack_repo.RepositoryFormatKnitPack5()
1053
note('Source format does not support stacking, using format:'
1055
bzrdir_format_name, repo_format.get_format_description())
1056
format.repository_format = repo_format
1033
1059
def checkout_metadir(self):
1060
1087
target_transport = get_transport(url, possible_transports)
1061
1088
target_transport.ensure_base()
1062
cloning_format = self.cloning_metadir()
1089
cloning_format = self.cloning_metadir(stacked)
1090
# Create/update the result branch
1063
1091
result = cloning_format.initialize_on_transport(target_transport)
1065
source_branch = self.open_branch()
1066
source_repository = source_branch.repository
1092
# if a stacked branch wasn't requested, we don't create one
1093
# even if the origin was stacked
1094
stacked_branch_url = None
1095
if source_branch is not None:
1068
1097
stacked_branch_url = self.root_transport.base
1070
# if a stacked branch wasn't requested, we don't create one
1071
# even if the origin was stacked
1072
stacked_branch_url = None
1073
except errors.NotBranchError:
1074
source_branch = None
1098
source_repository = source_branch.repository
1076
source_repository = self.open_repository()
1077
except errors.NoRepositoryPresent:
1078
source_repository = None
1079
stacked_branch_url = None
1101
source_branch = self.open_branch()
1102
source_repository = source_branch.repository
1104
stacked_branch_url = self.root_transport.base
1105
except errors.NotBranchError:
1106
source_branch = None
1108
source_repository = self.open_repository()
1109
except errors.NoRepositoryPresent:
1110
source_repository = None
1080
1111
repository_policy = result.determine_repository_policy(
1081
1112
force_new_repo, stacked_branch_url, require_stacking=stacked)
1082
1113
result_repo = repository_policy.acquire_repository()
1083
1114
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
1115
# Fetch while stacked to prevent unstacked fetch from
1086
1117
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:
1119
if source_branch is None:
1103
1120
# this is for sprouting a bzrdir without a branch; is that
1104
1121
# actually useful?
1122
# Not especially, but it's part of the contract.
1105
1123
result_branch = result.create_branch()
1125
# Force NULL revision to avoid using repository before stacking
1107
1127
result_branch = source_branch.sprout(
1108
result, revision_id=revision_id)
1128
result, revision_id=_mod_revision.NULL_REVISION)
1129
parent_location = result_branch.get_parent()
1109
1130
mutter("created new branch %r" % (result_branch,))
1110
1131
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)
1132
if source_branch is not None:
1133
source_branch.copy_content_into(result_branch, revision_id)
1134
# Override copy_content_into
1135
result_branch.set_parent(parent_location)
1118
1137
# Create/update the result working tree
1119
if isinstance(target_transport, LocalTransport) and (
1138
if isinstance(target_transport, local.LocalTransport) and (
1120
1139
result_repo is None or result_repo.make_working_trees()):
1121
1140
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1122
1141
hardlink=hardlink)
1185
1210
preserve_stacking has no effect, since no source branch using this
1186
1211
family of formats can be stacked, so there is no stacking to preserve.
1188
from bzrlib.workingtree import WorkingTreeFormat2
1189
1213
self._make_tail(url)
1190
1214
result = self._format._initialize_for_clone(url)
1191
1215
self.open_repository().clone(result, revision_id=revision_id)
1192
1216
from_branch = self.open_branch()
1193
1217
from_branch.clone(result, revision_id=revision_id)
1195
self.open_workingtree().clone(result)
1219
tree = self.open_workingtree()
1196
1220
except errors.NotLocalUrl:
1197
1221
# 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)
1222
result._init_workingtree()
1206
1227
def create_branch(self):
1207
1228
"""See BzrDir.create_branch."""
1208
return self.open_branch()
1229
return self._format.get_branch_format().initialize(self)
1210
1231
def destroy_branch(self):
1211
1232
"""See BzrDir.destroy_branch."""
1241
1268
result.set_parent_ids([revision_id])
1271
def _init_workingtree(self):
1272
from bzrlib.workingtree import WorkingTreeFormat2
1274
return WorkingTreeFormat2().initialize(self)
1275
except errors.NotLocalUrl:
1276
# Even though we can't access the working tree, we need to
1277
# create its control files.
1278
return WorkingTreeFormat2()._stub_initialize_on_transport(
1279
self.transport, self._control_files._file_mode)
1244
1281
def destroy_workingtree(self):
1245
1282
"""See BzrDir.destroy_workingtree."""
1246
1283
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1873
1914
from bzrlib.branch import BzrBranchFormat4
1874
1915
from bzrlib.repofmt.weaverepo import RepositoryFormat5
1875
from bzrlib.workingtree import WorkingTreeFormat2
1876
1916
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1877
1917
RepositoryFormat5().initialize(result, _internal=True)
1878
1918
if not _cloning:
1879
1919
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)
1920
result._init_workingtree()
1888
1923
def _open(self, transport):
1932
1971
from bzrlib.branch import BzrBranchFormat4
1933
1972
from bzrlib.repofmt.weaverepo import RepositoryFormat6
1934
from bzrlib.workingtree import WorkingTreeFormat2
1935
1973
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1936
1974
RepositoryFormat6().initialize(result, _internal=True)
1937
1975
if not _cloning:
1938
1976
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)
1977
result._init_workingtree()
1947
1980
def _open(self, transport):
2777
2814
experimental_pairs.append((key, help))
2779
2816
output += wrapped(key, help, info)
2817
output += "\nSee ``bzr help formats`` for more about storage formats."
2780
2819
if len(experimental_pairs) > 0:
2781
output += "Experimental formats are shown below.\n\n"
2820
other_output += "Experimental formats are shown below.\n\n"
2782
2821
for key, help in experimental_pairs:
2783
2822
info = self.get_info(key)
2784
output += wrapped(key, help, info)
2823
other_output += wrapped(key, help, info)
2826
"No experimental formats are available.\n\n"
2785
2827
if len(deprecated_pairs) > 0:
2786
output += "Deprecated formats are shown below.\n\n"
2828
other_output += "\nDeprecated formats are shown below.\n\n"
2787
2829
for key, help in deprecated_pairs:
2788
2830
info = self.get_info(key)
2789
output += wrapped(key, help, info)
2831
other_output += wrapped(key, help, info)
2834
"\nNo deprecated formats are available.\n\n"
2836
"\nSee ``bzr help formats`` for more about storage formats."
2838
if topic == 'other-formats':
2794
2844
class RepositoryAcquisitionPolicy(object):
2892
2942
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)
2944
repository = self._bzrdir.create_repository(shared=shared)
2917
2945
self._add_fallback(repository)
2918
2946
if make_working_trees is not None:
2919
2947
repository.set_make_working_trees(make_working_trees)
2945
2973
return self._repository
2976
# Please register new formats after old formats so that formats
2977
# appear in chronological order and format descriptions can build
2948
2979
format_registry = BzrDirFormatRegistry()
2949
2980
format_registry.register('weave', BzrDirFormat6,
2950
2981
'Pre-0.8 format. Slower than knit and does not'
2951
2982
' support checkouts or shared repositories.',
2952
2983
deprecated=True)
2953
format_registry.register_metadir('knit',
2954
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2955
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2956
branch_format='bzrlib.branch.BzrBranchFormat5',
2957
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2958
2984
format_registry.register_metadir('metaweave',
2959
2985
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2960
2986
'Transitional format in 0.8. Slower than knit.',
2961
2987
branch_format='bzrlib.branch.BzrBranchFormat5',
2962
2988
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2963
2989
deprecated=True)
2990
format_registry.register_metadir('knit',
2991
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2992
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2993
branch_format='bzrlib.branch.BzrBranchFormat5',
2994
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2964
2996
format_registry.register_metadir('dirstate',
2965
2997
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2966
2998
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2977
3009
' Incompatible with bzr < 0.15.',
2978
3010
branch_format='bzrlib.branch.BzrBranchFormat6',
2979
3011
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2981
3013
format_registry.register_metadir('rich-root',
2982
3014
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2983
3015
help='New in 1.0. Better handling of tree roots. Incompatible with'
2985
3017
branch_format='bzrlib.branch.BzrBranchFormat6',
2986
3018
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2988
3020
format_registry.register_metadir('dirstate-with-subtree',
2989
3021
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2990
3022
help='New in 0.15: Fast local operations and improved scaling for '
3022
3054
format_registry.register_metadir('rich-root-pack',
3023
3055
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3024
help='New in 1.0: Pack-based format with data compatible with '
3025
'rich-root format repositories. Incompatible with'
3056
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3057
'(needed for bzr-svn).',
3027
3058
branch_format='bzrlib.branch.BzrBranchFormat6',
3028
3059
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3030
3061
format_registry.register_metadir('1.6',
3031
3062
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3032
help='A branch and pack based repository that supports stacking. ',
3063
help='A format that allows a branch to indicate that there is another '
3064
'(stacked) repository that should be used to access data that is '
3065
'not present locally.',
3033
3066
branch_format='bzrlib.branch.BzrBranchFormat7',
3034
3067
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3036
format_registry.register_metadir('1.6-rich-root',
3069
format_registry.register_metadir('1.6.1-rich-root',
3037
3070
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3038
help='A branch and pack based repository that supports stacking '
3039
'and rich root data (needed for bzr-svn). ',
3071
help='A variant of 1.6 that supports rich-root data '
3072
'(needed for bzr-svn).',
3073
branch_format='bzrlib.branch.BzrBranchFormat7',
3074
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3076
format_registry.register_metadir('1.9',
3077
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3078
help='A repository format using B+tree indexes. These indexes '
3079
'are smaller in size, have smarter caching and provide faster '
3080
'performance for most operations.',
3081
branch_format='bzrlib.branch.BzrBranchFormat7',
3082
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3084
format_registry.register_metadir('1.9-rich-root',
3085
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3086
help='A variant of 1.9 that supports rich-root data '
3087
'(needed for bzr-svn).',
3040
3088
branch_format='bzrlib.branch.BzrBranchFormat7',
3041
3089
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3043
3091
# The following two formats should always just be aliases.
3044
3092
format_registry.register_metadir('development',
3045
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3093
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3046
3094
help='Current development format. Can convert data to and from pack-0.92 '
3047
3095
'(and anything compatible with pack-0.92) format repositories. '
3048
3096
'Repositories and branches in this format can only be read by bzr.dev. '
3067
3115
experimental=True,
3070
# 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
format_registry.register_metadir('development1',
3094
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3095
help='A branch and pack based repository that supports stacking. '
3118
# And the development formats above will have aliased one of the following:
3119
format_registry.register_metadir('development2',
3120
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3121
help='1.6.1 with B+Tree based index. '
3097
3123
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '