480
480
raise NotImplementedError(self.open_workingtree)
482
def has_branch(self):
483
"""Tell if this bzrdir contains a branch.
485
Note: if you're going to open the branch, you should just go ahead
486
and try, and not ask permission first. (This method just opens the
487
branch and discards it, and that's somewhat expensive.)
492
except errors.NotBranchError:
495
def has_workingtree(self):
496
"""Tell if this bzrdir contains a working tree.
498
This will still raise an exception if the bzrdir has a workingtree that
499
is remote & inaccessible.
501
Note: if you're going to open the working tree, you should just go ahead
502
and try, and not ask permission first. (This method just opens the
503
workingtree and discards it, and that's somewhat expensive.)
506
self.open_workingtree()
508
except errors.NoWorkingTree:
511
482
def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
512
483
"""Create a copy of this bzrdir prepared for use as a new line of
585
556
"""See BzrDir.clone()."""
586
557
from bzrlib.workingtree import WorkingTreeFormat2
587
558
self._make_tail(url)
588
result = self._format._initialize_for_clone(url)
559
result = self._format.initialize(url, _cloning=True)
589
560
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
590
561
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
591
562
self.open_branch().clone(result, revision_id=revision_id)
673
644
"""See BzrDir.sprout()."""
674
645
from bzrlib.workingtree import WorkingTreeFormat2
675
646
self._make_tail(url)
676
result = self._format._initialize_for_clone(url)
647
result = self._format.initialize(url, _cloning=True)
677
648
basis_repo, basis_branch, basis_tree = self._get_basis_components(basis)
679
650
self.open_repository().clone(result, revision_id=revision_id, basis=basis_repo)
769
740
from bzrlib.workingtree import WorkingTreeFormat
770
741
return WorkingTreeFormat.get_default_format().initialize(self, revision_id)
772
def _get_mkdir_mode(self):
773
"""Figure out the mode to use when creating a bzrdir subdir."""
774
temp_control = LockableFiles(self.transport, '', TransportLock)
775
return temp_control._dir_mode
777
743
def get_branch_transport(self, branch_format):
778
744
"""See BzrDir.get_branch_transport()."""
779
745
if branch_format is None:
783
749
except NotImplementedError:
784
750
raise errors.IncompatibleFormat(branch_format, self._format)
786
self.transport.mkdir('branch', mode=self._get_mkdir_mode())
752
self.transport.mkdir('branch')
787
753
except errors.FileExists:
789
755
return self.transport.clone('branch')
797
763
except NotImplementedError:
798
764
raise errors.IncompatibleFormat(repository_format, self._format)
800
self.transport.mkdir('repository', mode=self._get_mkdir_mode())
766
self.transport.mkdir('repository')
801
767
except errors.FileExists:
803
769
return self.transport.clone('repository')
811
777
except NotImplementedError:
812
778
raise errors.IncompatibleFormat(workingtree_format, self._format)
814
self.transport.mkdir('checkout', mode=self._get_mkdir_mode())
780
self.transport.mkdir('checkout')
815
781
except errors.FileExists:
817
783
return self.transport.clone('checkout')
904
870
"""Return the ASCII format string that identifies this format."""
905
871
raise NotImplementedError(self.get_format_string)
907
def get_format_description(self):
908
"""Return the short description for this format."""
909
raise NotImplementedError(self.get_format_description)
911
873
def get_converter(self, format=None):
912
874
"""Return the converter to use to convert bzrdirs needing converts.
923
885
raise NotImplementedError(self.get_converter)
925
887
def initialize(self, url):
926
"""Create a bzr control dir at this url and return an opened copy.
928
Subclasses should typically override initialize_on_transport
929
instead of this method.
931
return self.initialize_on_transport(get_transport(url))
933
def initialize_on_transport(self, transport):
934
"""Initialize a new bzrdir in the base directory of a Transport."""
935
# Since we don'transport have a .bzr directory, inherit the
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
936
890
# mode from the root directory
937
temp_control = LockableFiles(transport, '', TransportLock)
891
t = get_transport(url)
892
temp_control = LockableFiles(t, '', TransportLock)
938
893
temp_control._transport.mkdir('.bzr',
939
894
# FIXME: RBC 20060121 dont peek under
941
896
mode=temp_control._dir_mode)
942
897
file_mode = temp_control._file_mode
944
mutter('created control directory in ' + transport.base)
945
control = transport.clone('.bzr')
899
mutter('created control directory in ' + t.base)
900
control = t.clone('.bzr')
946
901
utf8_files = [('README',
947
902
"This is a Bazaar-NG control directory.\n"
948
903
"Do not change any files in this directory.\n"),
949
904
('branch-format', self.get_format_string()),
951
906
# NB: no need to escape relative paths that are url safe.
952
control_files = LockableFiles(control, self._lock_file_name,
907
control_files = LockableFiles(control, self._lock_file_name, self._lock_class)
954
908
control_files.create_lock()
955
909
control_files.lock_write()
958
912
control_files.put_utf8(file, content)
960
914
control_files.unlock()
961
return self.open(transport, _found=True)
915
return self.open(t, _found=True)
963
917
def is_supported(self):
964
918
"""Is this format supported?
1023
977
"""See BzrDirFormat.get_format_string()."""
1024
978
return "Bazaar-NG branch, format 0.0.4\n"
1026
def get_format_description(self):
1027
"""See BzrDirFormat.get_format_description()."""
1028
return "All-in-one format 4"
1030
980
def get_converter(self, format=None):
1031
981
"""See BzrDirFormat.get_converter()."""
1032
982
# there is one and only one upgrade path here.
1033
983
return ConvertBzrDir4To5()
1035
def initialize_on_transport(self, transport):
985
def initialize(self, url):
1036
986
"""Format 4 branches cannot be created."""
1037
987
raise errors.UninitializableFormat(self)
1073
1023
"""See BzrDirFormat.get_format_string()."""
1074
1024
return "Bazaar-NG branch, format 5\n"
1076
def get_format_description(self):
1077
"""See BzrDirFormat.get_format_description()."""
1078
return "All-in-one format 5"
1080
1026
def get_converter(self, format=None):
1081
1027
"""See BzrDirFormat.get_converter()."""
1082
1028
# there is one and only one upgrade path here.
1083
1029
return ConvertBzrDir5To6()
1085
def _initialize_for_clone(self, url):
1086
return self.initialize_on_transport(get_transport(url), _cloning=True)
1088
def initialize_on_transport(self, transport, _cloning=False):
1031
def initialize(self, url, _cloning=False):
1089
1032
"""Format 5 dirs always have working tree, branch and repository.
1091
1034
Except when they are being cloned.
1093
1036
from bzrlib.branch import BzrBranchFormat4
1094
1037
from bzrlib.repository import RepositoryFormat5
1095
1038
from bzrlib.workingtree import WorkingTreeFormat2
1096
result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1039
result = super(BzrDirFormat5, self).initialize(url)
1097
1040
RepositoryFormat5().initialize(result, _internal=True)
1098
1041
if not _cloning:
1099
1042
BzrBranchFormat4().initialize(result)
1127
1070
"""See BzrDirFormat.get_format_string()."""
1128
1071
return "Bazaar-NG branch, format 6\n"
1130
def get_format_description(self):
1131
"""See BzrDirFormat.get_format_description()."""
1132
return "All-in-one format 6"
1134
1073
def get_converter(self, format=None):
1135
1074
"""See BzrDirFormat.get_converter()."""
1136
1075
# there is one and only one upgrade path here.
1137
1076
return ConvertBzrDir6ToMeta()
1139
def _initialize_for_clone(self, url):
1140
return self.initialize_on_transport(get_transport(url), _cloning=True)
1142
def initialize_on_transport(self, transport, _cloning=False):
1078
def initialize(self, url, _cloning=False):
1143
1079
"""Format 6 dirs always have working tree, branch and repository.
1145
1081
Except when they are being cloned.
1147
1083
from bzrlib.branch import BzrBranchFormat4
1148
1084
from bzrlib.repository import RepositoryFormat6
1149
1085
from bzrlib.workingtree import WorkingTreeFormat2
1150
result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1086
result = super(BzrDirFormat6, self).initialize(url)
1151
1087
RepositoryFormat6().initialize(result, _internal=True)
1152
1088
if not _cloning:
1153
1089
BzrBranchFormat4().initialize(result)
1196
1132
"""See BzrDirFormat.get_format_string()."""
1197
1133
return "Bazaar-NG meta directory, format 1\n"
1199
def get_format_description(self):
1200
"""See BzrDirFormat.get_format_description()."""
1201
return "Meta directory format 1"
1203
1135
def _open(self, transport):
1204
1136
"""See BzrDirFormat._open."""
1205
1137
return BzrDirMeta1(transport, self)
1221
1153
BzrDirFormat.register_format(BzrDirFormat4())
1222
1154
BzrDirFormat.register_format(BzrDirFormat5())
1223
BzrDirFormat.register_format(BzrDirFormat6())
1224
__default_format = BzrDirMetaFormat1()
1155
BzrDirFormat.register_format(BzrDirMetaFormat1())
1156
__default_format = BzrDirFormat6()
1225
1157
BzrDirFormat.register_format(__default_format)
1226
1158
BzrDirFormat.set_default_format(__default_format)
1613
1545
return BzrDir.open(self.bzrdir.root_transport.base)
1615
1547
def _convert_to_prefixed(self):
1616
from bzrlib.store import TransportStore
1548
from bzrlib.store import hash_prefix
1617
1549
self.bzrdir.transport.delete('branch-format')
1618
1550
for store_name in ["weaves", "revision-store"]:
1619
self.pb.note("adding prefixes to %s" % store_name)
1551
self.pb.note("adding prefixes to %s" % store_name)
1620
1552
store_transport = self.bzrdir.transport.clone(store_name)
1621
store = TransportStore(store_transport, prefixed=True)
1622
1553
for urlfilename in store_transport.list_dir('.'):
1623
1554
filename = urlunescape(urlfilename)
1624
1555
if (filename.endswith(".weave") or
1627
1558
file_id = os.path.splitext(filename)[0]
1629
1560
file_id = filename
1630
prefix_dir = store.hash_prefix(file_id)
1561
prefix_dir = hash_prefix(file_id)
1631
1562
# FIXME keep track of the dirs made RBC 20060121
1633
1564
store_transport.move(filename, prefix_dir + '/' + filename)
1660
1591
# find out whats there
1661
1592
self.step('Finding branch files')
1662
last_revision = self.bzrdir.open_branch().last_revision()
1593
last_revision = self.bzrdir.open_workingtree().last_revision()
1663
1594
bzrcontents = self.bzrdir.transport.list_dir('.')
1664
1595
for name in bzrcontents:
1665
1596
if name.startswith('basis-inventory.'):