556
556
"""See BzrDir.clone()."""
557
557
from bzrlib.workingtree import WorkingTreeFormat2
558
558
self._make_tail(url)
559
result = self._format.initialize(url, _cloning=True)
559
result = self._format._initialize_for_clone(url)
560
560
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
561
561
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
562
562
self.open_branch().clone(result, revision_id=revision_id)
644
644
"""See BzrDir.sprout()."""
645
645
from bzrlib.workingtree import WorkingTreeFormat2
646
646
self._make_tail(url)
647
result = self._format.initialize(url, _cloning=True)
647
result = self._format._initialize_for_clone(url)
648
648
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
650
650
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
870
870
"""Return the ASCII format string that identifies this format."""
871
871
raise NotImplementedError(self.get_format_string)
873
def get_format_description(self):
874
"""Return the short description for this format."""
875
raise NotImplementedError(self.get_format_description)
873
877
def get_converter(self, format=None):
874
878
"""Return the converter to use to convert bzrdirs needing converts.
885
889
raise NotImplementedError(self.get_converter)
887
891
def initialize(self, url):
888
"""Create a bzr control dir at this url and return an opened copy."""
889
# Since we don't have a .bzr directory, inherit the
892
"""Create a bzr control dir at this url and return an opened copy.
894
Subclasses should typically override initialize_on_transport
895
instead of this method.
897
return self.initialize_on_transport(get_transport(url))
899
def initialize_on_transport(self, transport):
900
"""Initialize a new bzrdir in the base directory of a Transport."""
901
# Since we don'transport have a .bzr directory, inherit the
890
902
# mode from the root directory
891
t = get_transport(url)
892
temp_control = LockableFiles(t, '', TransportLock)
903
temp_control = LockableFiles(transport, '', TransportLock)
893
904
temp_control._transport.mkdir('.bzr',
894
905
# FIXME: RBC 20060121 dont peek under
896
907
mode=temp_control._dir_mode)
897
908
file_mode = temp_control._file_mode
899
mutter('created control directory in ' + t.base)
900
control = t.clone('.bzr')
910
mutter('created control directory in ' + transport.base)
911
control = transport.clone('.bzr')
901
912
utf8_files = [('README',
902
913
"This is a Bazaar-NG control directory.\n"
903
914
"Do not change any files in this directory.\n"),
904
915
('branch-format', self.get_format_string()),
906
917
# NB: no need to escape relative paths that are url safe.
907
control_files = LockableFiles(control, self._lock_file_name, self._lock_class)
918
control_files = LockableFiles(control, self._lock_file_name,
908
920
control_files.create_lock()
909
921
control_files.lock_write()
912
924
control_files.put_utf8(file, content)
914
926
control_files.unlock()
915
return self.open(t, _found=True)
927
return self.open(transport, _found=True)
917
929
def is_supported(self):
918
930
"""Is this format supported?
977
989
"""See BzrDirFormat.get_format_string()."""
978
990
return "Bazaar-NG branch, format 0.0.4\n"
992
def get_format_description(self):
993
"""See BzrDirFormat.get_format_description()."""
994
return "All-in-one format 4"
980
996
def get_converter(self, format=None):
981
997
"""See BzrDirFormat.get_converter()."""
982
998
# there is one and only one upgrade path here.
983
999
return ConvertBzrDir4To5()
985
def initialize(self, url):
1001
def initialize_on_transport(self, transport):
986
1002
"""Format 4 branches cannot be created."""
987
1003
raise errors.UninitializableFormat(self)
1023
1039
"""See BzrDirFormat.get_format_string()."""
1024
1040
return "Bazaar-NG branch, format 5\n"
1042
def get_format_description(self):
1043
"""See BzrDirFormat.get_format_description()."""
1044
return "All-in-one format 5"
1026
1046
def get_converter(self, format=None):
1027
1047
"""See BzrDirFormat.get_converter()."""
1028
1048
# there is one and only one upgrade path here.
1029
1049
return ConvertBzrDir5To6()
1051
def _initialize_for_clone(self, url):
1052
return self.initialize_on_transport(get_transport(url), _cloning=True)
1031
def initialize(self, url, _cloning=False):
1054
def initialize_on_transport(self, transport, _cloning=False):
1032
1055
"""Format 5 dirs always have working tree, branch and repository.
1034
1057
Except when they are being cloned.
1036
1059
from bzrlib.branch import BzrBranchFormat4
1037
1060
from bzrlib.repository import RepositoryFormat5
1038
1061
from bzrlib.workingtree import WorkingTreeFormat2
1039
result = super(BzrDirFormat5, self).initialize(url)
1062
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1040
1063
RepositoryFormat5().initialize(result, _internal=True)
1041
1064
if not _cloning:
1042
1065
BzrBranchFormat4().initialize(result)
1070
1093
"""See BzrDirFormat.get_format_string()."""
1071
1094
return "Bazaar-NG branch, format 6\n"
1096
def get_format_description(self):
1097
"""See BzrDirFormat.get_format_description()."""
1098
return "All-in-one format 6"
1073
1100
def get_converter(self, format=None):
1074
1101
"""See BzrDirFormat.get_converter()."""
1075
1102
# there is one and only one upgrade path here.
1076
1103
return ConvertBzrDir6ToMeta()
1078
def initialize(self, url, _cloning=False):
1105
def _initialize_for_clone(self, url):
1106
return self.initialize_on_transport(get_transport(url), _cloning=True)
1108
def initialize_on_transport(self, transport, _cloning=False):
1079
1109
"""Format 6 dirs always have working tree, branch and repository.
1081
1111
Except when they are being cloned.
1083
1113
from bzrlib.branch import BzrBranchFormat4
1084
1114
from bzrlib.repository import RepositoryFormat6
1085
1115
from bzrlib.workingtree import WorkingTreeFormat2
1086
result = super(BzrDirFormat6, self).initialize(url)
1116
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1087
1117
RepositoryFormat6().initialize(result, _internal=True)
1088
1118
if not _cloning:
1089
1119
BzrBranchFormat4().initialize(result)
1132
1162
"""See BzrDirFormat.get_format_string()."""
1133
1163
return "Bazaar-NG meta directory, format 1\n"
1165
def get_format_description(self):
1166
"""See BzrDirFormat.get_format_description()."""
1167
return "Meta directory format 1"
1135
1169
def _open(self, transport):
1136
1170
"""See BzrDirFormat._open."""
1137
1171
return BzrDirMeta1(transport, self)
1545
1579
return BzrDir.open(self.bzrdir.root_transport.base)
1547
1581
def _convert_to_prefixed(self):
1548
from bzrlib.store import hash_prefix
1582
from bzrlib.store import TransportStore
1549
1583
self.bzrdir.transport.delete('branch-format')
1550
1584
for store_name in ["weaves", "revision-store"]:
1551
self.pb.note("adding prefixes to %s" % store_name)
1585
self.pb.note("adding prefixes to %s" % store_name)
1552
1586
store_transport = self.bzrdir.transport.clone(store_name)
1587
store = TransportStore(store_transport, prefixed=True)
1553
1588
for urlfilename in store_transport.list_dir('.'):
1554
1589
filename = urlunescape(urlfilename)
1555
1590
if (filename.endswith(".weave") or
1558
1593
file_id = os.path.splitext(filename)[0]
1560
1595
file_id = filename
1561
prefix_dir = hash_prefix(file_id)
1596
prefix_dir = store.hash_prefix(file_id)
1562
1597
# FIXME keep track of the dirs made RBC 20060121
1564
1599
store_transport.move(filename, prefix_dir + '/' + filename)