67
63
create_prefix=False, force_new_repo=False, stacked_on=None,
68
64
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
69
65
shared_repo=False):
70
"""See ControlDir.initialize_on_transport_ex."""
66
"""See BzrDirFormat.initialize_on_transport_ex."""
71
67
require_stacking = (stacked_on is not None)
72
68
# Format 5 cannot stack, but we've been asked to - actually init
84
80
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
85
81
make_working_trees=make_working_trees, shared_repo=shared_repo)
88
def from_string(cls, format_string):
89
if format_string != cls.get_format_string():
90
raise AssertionError("unexpected format string %r" % format_string)
94
84
class BzrDirFormat5(BzrDirFormatAllInOne):
95
85
"""Bzr control format 5.
107
97
def __eq__(self, other):
108
98
return type(self) == type(other)
111
def get_format_string(cls):
100
def get_format_string(self):
112
101
"""See BzrDirFormat.get_format_string()."""
113
102
return "Bazaar-NG branch, format 5\n"
117
106
return BzrBranchFormat4()
119
108
def get_format_description(self):
120
"""See ControlDirFormat.get_format_description()."""
109
"""See BzrDirFormat.get_format_description()."""
121
110
return "All-in-one format 5"
123
112
def get_converter(self, format=None):
124
"""See ControlDirFormat.get_converter()."""
113
"""See BzrDirFormat.get_converter()."""
125
114
# there is one and only one upgrade path here.
126
115
return ConvertBzrDir5To6()
171
160
def __eq__(self, other):
172
161
return type(self) == type(other)
175
def get_format_string(cls):
163
def get_format_string(self):
176
164
"""See BzrDirFormat.get_format_string()."""
177
165
return "Bazaar-NG branch, format 6\n"
179
167
def get_format_description(self):
180
"""See ControlDirFormat.get_format_description()."""
168
"""See BzrDirFormat.get_format_description()."""
181
169
return "All-in-one format 6"
183
171
def get_branch_format(self):
185
173
return BzrBranchFormat4()
187
175
def get_converter(self, format=None):
188
"""See ControlDirFormat.get_converter()."""
176
"""See BzrDirFormat.get_converter()."""
189
177
# there is one and only one upgrade path here.
190
178
return ConvertBzrDir6ToMeta()
234
222
"""See Converter.convert()."""
235
223
self.bzrdir = to_convert
236
224
if pb is not None:
237
warnings.warn(gettext("pb parameter to convert() is deprecated"))
225
warnings.warn("pb parameter to convert() is deprecated")
238
226
self.pb = ui.ui_factory.nested_progress_bar()
240
ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
228
ui.ui_factory.note('starting upgrade from format 4 to 5')
241
229
if isinstance(self.bzrdir.transport, local.LocalTransport):
242
230
self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
243
231
self._convert_to_weaves()
244
return ControlDir.open(self.bzrdir.user_url)
232
return BzrDir.open(self.bzrdir.user_url)
246
234
self.pb.finished()
248
236
def _convert_to_weaves(self):
249
ui.ui_factory.note(gettext(
250
'note: upgrade may be faster if all store files are ungzipped first'))
237
ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
252
239
# TODO permissions
253
240
stat = self.bzrdir.transport.stat('weaves')
263
250
self.bzrdir.transport.delete('branch-format')
264
251
self.branch = self.bzrdir.open_branch()
265
252
self._convert_working_inv()
266
rev_history = self.branch._revision_history()
253
rev_history = self.branch.revision_history()
267
254
# to_read is a stack holding the revisions we still need to process;
268
255
# appending to it adds new highest-priority revisions
269
256
self.known_revisions = set(rev_history)
277
264
to_import = self._make_order()
278
265
for i, rev_id in enumerate(to_import):
279
self.pb.update(gettext('converting revision'), i, len(to_import))
266
self.pb.update('converting revision', i, len(to_import))
280
267
self._convert_one_rev(rev_id)
282
269
self._write_all_weaves()
283
270
self._write_all_revs()
284
ui.ui_factory.note(gettext('upgraded to weaves:'))
285
ui.ui_factory.note(' ' + gettext('%6d revisions and inventories') %
287
ui.ui_factory.note(' ' + gettext('%6d revisions not present') %
288
len(self.absent_revisions))
289
ui.ui_factory.note(' ' + gettext('%6d texts') % self.text_count)
271
ui.ui_factory.note('upgraded to weaves:')
272
ui.ui_factory.note(' %6d revisions and inventories' % len(self.revisions))
273
ui.ui_factory.note(' %6d revisions not present' % len(self.absent_revisions))
274
ui.ui_factory.note(' %6d texts' % self.text_count)
290
275
self._cleanup_spare_files_after_format4()
291
276
self.branch._transport.put_bytes(
324
309
for file_id, file_weave in self.text_weaves.items():
325
self.pb.update(gettext('writing weave'), i,
326
len(self.text_weaves))
310
self.pb.update('writing weave', i, len(self.text_weaves))
327
311
weaves._put_weave(file_id, file_weave, transaction)
329
self.pb.update(gettext('inventory'), 0, 1)
313
self.pb.update('inventory', 0, 1)
330
314
controlweaves._put_weave('inventory', self.inv_weave, transaction)
331
self.pb.update(gettext('inventory'), 1, 1)
315
self.pb.update('inventory', 1, 1)
345
329
lambda:True, lambda:True)
347
331
for i, rev_id in enumerate(self.converted_revs):
348
self.pb.update(gettext('write revision'), i,
349
len(self.converted_revs))
332
self.pb.update('write revision', i, len(self.converted_revs))
350
333
text = serializer_v5.write_revision_to_string(
351
334
self.revisions[rev_id])
360
343
Any parents not either loaded or abandoned get queued to be
362
self.pb.update(gettext('loading revision'),
345
self.pb.update('loading revision',
363
346
len(self.revisions),
364
347
len(self.known_revisions))
365
348
if not self.branch.repository.has_revision(rev_id):
367
ui.ui_factory.note(gettext('revision {%s} not present in branch; '
368
'will be converted as a ghost') %
350
ui.ui_factory.note('revision {%s} not present in branch; '
351
'will be converted as a ghost' %
370
353
self.absent_revisions.add(rev_id)
504
487
self.bzrdir = to_convert
505
488
pb = ui.ui_factory.nested_progress_bar()
507
ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
490
ui.ui_factory.note('starting upgrade from format 5 to 6')
508
491
self._convert_to_prefixed()
509
return ControlDir.open(self.bzrdir.user_url)
492
return BzrDir.open(self.bzrdir.user_url)
514
497
from bzrlib.store import TransportStore
515
498
self.bzrdir.transport.delete('branch-format')
516
499
for store_name in ["weaves", "revision-store"]:
517
ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
500
ui.ui_factory.note("adding prefixes to %s" % store_name)
518
501
store_transport = self.bzrdir.transport.clone(store_name)
519
502
store = TransportStore(store_transport, prefixed=True)
520
503
for urlfilename in store_transport.list_dir('.'):
545
528
def convert(self, to_convert, pb):
546
529
"""See Converter.convert()."""
547
530
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
548
from bzrlib.branchfmt.fullhistory import BzrBranchFormat5
531
from bzrlib.branch import BzrBranchFormat5
549
532
self.bzrdir = to_convert
550
533
self.pb = ui.ui_factory.nested_progress_bar()
554
537
self.dir_mode = self.bzrdir._get_dir_mode()
555
538
self.file_mode = self.bzrdir._get_file_mode()
557
ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
540
ui.ui_factory.note('starting upgrade from format 6 to metadir')
558
541
self.bzrdir.transport.put_bytes(
560
543
"Converting to format 6",
562
545
# its faster to move specific files around than to open and use the apis...
563
546
# first off, nuke ancestry.weave, it was never used.
565
self.step(gettext('Removing ancestry.weave'))
548
self.step('Removing ancestry.weave')
566
549
self.bzrdir.transport.delete('ancestry.weave')
567
550
except errors.NoSuchFile:
569
552
# find out whats there
570
self.step(gettext('Finding branch files'))
553
self.step('Finding branch files')
571
554
last_revision = self.bzrdir.open_branch().last_revision()
572
555
bzrcontents = self.bzrdir.transport.list_dir('.')
573
556
for name in bzrcontents:
577
560
repository_names = [('inventory.weave', True),
578
561
('revision-store', True),
579
562
('weaves', True)]
580
self.step(gettext('Upgrading repository') + ' ')
563
self.step('Upgrading repository ')
581
564
self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
582
565
self.make_lock('repository')
583
566
# we hard code the formats here because we are converting into
587
570
for entry in repository_names:
588
571
self.move_entry('repository', entry)
590
self.step(gettext('Upgrading branch') + ' ')
573
self.step('Upgrading branch ')
591
574
self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
592
575
self.make_lock('branch')
593
576
self.put_format('branch', BzrBranchFormat5())
611
594
has_checkout = True
612
595
if not has_checkout:
613
ui.ui_factory.note(gettext('No working tree.'))
596
ui.ui_factory.note('No working tree.')
614
597
# If some checkout files are there, we may as well get rid of them.
615
598
for name, mandatory in checkout_files:
616
599
if name in bzrcontents:
617
600
self.bzrdir.transport.delete(name)
619
602
from bzrlib.workingtree_3 import WorkingTreeFormat3
620
self.step(gettext('Upgrading working tree'))
603
self.step('Upgrading working tree')
621
604
self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
622
605
self.make_lock('checkout')
634
617
BzrDirMetaFormat1().get_format_string(),
635
618
mode=self.file_mode)
636
619
self.pb.finished()
637
return ControlDir.open(self.bzrdir.user_url)
620
return BzrDir.open(self.bzrdir.user_url)
639
622
def make_lock(self, name):
640
623
"""Make a lock for the new control dir name."""
641
self.step(gettext('Make %s lock') % name)
624
self.step('Make %s lock' % name)
642
625
ld = lockdir.LockDir(self.bzrdir.transport,
643
626
'%s/lock' % name,
644
627
file_modebits=self.file_mode,
649
632
"""Move then entry name into new_dir."""
651
634
mandatory = entry[1]
652
self.step(gettext('Moving %s') % name)
635
self.step('Moving %s' % name)
654
637
self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
655
638
except errors.NoSuchFile:
680
663
def __eq__(self, other):
681
664
return type(self) == type(other)
684
def get_format_string(cls):
666
def get_format_string(self):
685
667
"""See BzrDirFormat.get_format_string()."""
686
668
return "Bazaar-NG branch, format 0.0.4\n"
688
670
def get_format_description(self):
689
"""See ControlDirFormat.get_format_description()."""
671
"""See BzrDirFormat.get_format_description()."""
690
672
return "All-in-one format 4"
692
674
def get_converter(self, format=None):
693
"""See ControlDirFormat.get_converter()."""
675
"""See BzrDirFormat.get_converter()."""
694
676
# there is one and only one upgrade path here.
695
677
return ConvertBzrDir4To5()
720
702
return RepositoryFormat4()
721
703
repository_format = property(__return_repository_format)
724
def from_string(cls, format_string):
725
if format_string != cls.get_format_string():
726
raise AssertionError("unexpected format string %r" % format_string)
730
706
class BzrDirPreSplitOut(BzrDir):
731
707
"""A common class for the all-in-one formats."""
733
709
def __init__(self, _transport, _format):
734
"""See ControlDir.__init__."""
710
"""See BzrDir.__init__."""
735
711
super(BzrDirPreSplitOut, self).__init__(_transport, _format)
736
712
self._control_files = lockable_files.LockableFiles(
737
713
self.get_branch_transport(None),
751
727
def clone(self, url, revision_id=None, force_new_repo=False,
752
728
preserve_stacking=False):
753
"""See ControlDir.clone().
729
"""See BzrDir.clone().
755
731
force_new_repo has no effect, since this family of formats always
756
732
require a new repository.
771
747
tree.clone(result)
774
def create_branch(self, name=None, repository=None,
775
append_revisions_only=None):
776
"""See ControlDir.create_branch."""
750
def create_branch(self, name=None, repository=None):
751
"""See BzrDir.create_branch."""
777
752
if repository is not None:
778
753
raise NotImplementedError(
779
754
"create_branch(repository=<not None>) on %r" % (self,))
780
return self._format.get_branch_format().initialize(self, name=name,
781
append_revisions_only=append_revisions_only)
755
return self._format.get_branch_format().initialize(self, name=name)
783
757
def destroy_branch(self, name=None):
784
"""See ControlDir.destroy_branch."""
758
"""See BzrDir.destroy_branch."""
785
759
raise errors.UnsupportedOperation(self.destroy_branch, self)
787
761
def create_repository(self, shared=False):
788
"""See ControlDir.create_repository."""
762
"""See BzrDir.create_repository."""
790
764
raise errors.IncompatibleFormat('shared repository', self._format)
791
765
return self.open_repository()
793
767
def destroy_repository(self):
794
"""See ControlDir.destroy_repository."""
768
"""See BzrDir.destroy_repository."""
795
769
raise errors.UnsupportedOperation(self.destroy_repository, self)
797
771
def create_workingtree(self, revision_id=None, from_branch=None,
798
772
accelerator_tree=None, hardlink=False):
799
"""See ControlDir.create_workingtree."""
773
"""See BzrDir.create_workingtree."""
800
774
# The workingtree is sometimes created when the bzrdir is created,
801
775
# but not when cloning.
834
808
self.transport, self._control_files._file_mode)
836
810
def destroy_workingtree(self):
837
"""See ControlDir.destroy_workingtree."""
811
"""See BzrDir.destroy_workingtree."""
838
812
raise errors.UnsupportedOperation(self.destroy_workingtree, self)
840
814
def destroy_workingtree_metadata(self):
841
"""See ControlDir.destroy_workingtree_metadata."""
815
"""See BzrDir.destroy_workingtree_metadata."""
842
816
raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
875
849
raise errors.IncompatibleFormat(workingtree_format, self._format)
877
851
def needs_format_conversion(self, format=None):
878
"""See ControlDir.needs_format_conversion()."""
852
"""See BzrDir.needs_format_conversion()."""
879
853
# if the format is not the same as the system default,
880
854
# an upgrade is needed.
881
855
if format is None:
885
859
return not isinstance(self._format, format.__class__)
887
861
def open_branch(self, name=None, unsupported=False,
888
ignore_fallbacks=False, possible_transports=None):
889
"""See ControlDir.open_branch."""
862
ignore_fallbacks=False):
863
"""See BzrDir.open_branch."""
890
864
from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
891
865
format = BzrBranchFormat4()
892
866
format.check_support_status(unsupported)
893
return format.open(self, name, _found=True,
894
possible_transports=possible_transports)
867
return format.open(self, name, _found=True)
896
869
def sprout(self, url, revision_id=None, force_new_repo=False,
897
870
possible_transports=None, accelerator_tree=None,
898
871
hardlink=False, stacked=False, create_tree_if_local=True,
899
872
source_branch=None):
900
"""See ControlDir.sprout()."""
873
"""See BzrDir.sprout()."""
901
874
if source_branch is not None:
902
875
my_branch = self.open_branch()
903
876
if source_branch.base != my_branch.base:
928
901
hardlink=hardlink)
931
def set_branch_reference(self, target_branch, name=None):
932
from bzrlib.branch import BranchReferenceFormat
934
raise errors.NoColocatedBranchSupport(self)
935
raise errors.IncompatibleFormat(BranchReferenceFormat, self._format)
938
905
class BzrDir4(BzrDirPreSplitOut):
939
906
"""A .bzr version 4 control object.
944
911
def create_repository(self, shared=False):
945
"""See ControlDir.create_repository."""
912
"""See BzrDir.create_repository."""
946
913
return self._format.repository_format.initialize(self, shared)
948
915
def needs_format_conversion(self, format=None):
955
922
def open_repository(self):
956
"""See ControlDir.open_repository."""
923
"""See BzrDir.open_repository."""
957
924
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
958
925
return RepositoryFormat4().open(self, _found=True)
967
934
def has_workingtree(self):
968
"""See ControlDir.has_workingtree."""
935
"""See BzrDir.has_workingtree."""
971
938
def open_repository(self):
972
"""See ControlDir.open_repository."""
939
"""See BzrDir.open_repository."""
973
940
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
974
941
return RepositoryFormat5().open(self, _found=True)
976
def open_workingtree(self, unsupported=False,
943
def open_workingtree(self, _unsupported=False,
977
944
recommend_upgrade=True):
978
"""See ControlDir.create_workingtree."""
945
"""See BzrDir.create_workingtree."""
979
946
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
980
947
wt_format = WorkingTreeFormat2()
981
948
# we don't warn here about upgrades; that ought to be handled for the
992
959
def has_workingtree(self):
993
"""See ControlDir.has_workingtree."""
960
"""See BzrDir.has_workingtree."""
996
963
def open_repository(self):
997
"""See ControlDir.open_repository."""
964
"""See BzrDir.open_repository."""
998
965
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
999
966
return RepositoryFormat6().open(self, _found=True)
1001
def open_workingtree(self, unsupported=False, recommend_upgrade=True):
1002
"""See ControlDir.create_workingtree."""
968
def open_workingtree(self, _unsupported=False,
969
recommend_upgrade=True):
970
"""See BzrDir.create_workingtree."""
1003
971
# we don't warn here about upgrades; that ought to be handled for the
1004
972
# bzrdir as a whole
1005
973
from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2