~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Weave-era BzrDir formats."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from bzrlib.bzrdir import (
22
20
    BzrDir,
23
21
    BzrDirFormat,
24
22
    BzrDirMetaFormat1,
25
23
    )
26
24
from bzrlib.controldir import (
27
 
    ControlDir,
28
25
    Converter,
29
26
    format_registry,
30
27
    )
47
44
    weave,
48
45
    xml5,
49
46
    )
50
 
from bzrlib.i18n import gettext
51
47
from bzrlib.store.versioned import VersionedFileStore
52
48
from bzrlib.transactions import WriteTransaction
53
49
from bzrlib.transport import (
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
73
69
        # a Meta1Dir
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)
86
82
 
87
 
    @classmethod
88
 
    def from_string(cls, format_string):
89
 
        if format_string != cls.get_format_string():
90
 
            raise AssertionError("unexpected format string %r" % format_string)
91
 
        return cls()
92
 
 
93
83
 
94
84
class BzrDirFormat5(BzrDirFormatAllInOne):
95
85
    """Bzr control format 5.
107
97
    def __eq__(self, other):
108
98
        return type(self) == type(other)
109
99
 
110
 
    @classmethod
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"
114
103
 
117
106
        return BzrBranchFormat4()
118
107
 
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"
122
111
 
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()
127
116
 
171
160
    def __eq__(self, other):
172
161
        return type(self) == type(other)
173
162
 
174
 
    @classmethod
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"
178
166
 
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"
182
170
 
183
171
    def get_branch_format(self):
185
173
        return BzrBranchFormat4()
186
174
 
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()
191
179
 
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()
239
227
        try:
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)
245
233
        finally:
246
234
            self.pb.finished()
247
235
 
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')
251
238
        try:
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)
276
263
        self.pb.clear()
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)
281
268
        self.pb.clear()
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') %
286
 
                                                        len(self.revisions))
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(
292
277
            'branch-format',
322
307
        try:
323
308
            i = 0
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)
328
312
                i += 1
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)
332
316
        finally:
333
317
            self.pb.clear()
334
318
 
345
329
            lambda:True, lambda:True)
346
330
        try:
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])
352
335
                key = (rev_id,)
359
342
 
360
343
        Any parents not either loaded or abandoned get queued to be
361
344
        loaded."""
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):
366
349
            self.pb.clear()
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' %
369
352
                         rev_id)
370
353
            self.absent_revisions.add(rev_id)
371
354
        else:
504
487
        self.bzrdir = to_convert
505
488
        pb = ui.ui_factory.nested_progress_bar()
506
489
        try:
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)
510
493
        finally:
511
494
            pb.finished()
512
495
 
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()
551
534
        self.count = 0
554
537
        self.dir_mode = self.bzrdir._get_dir_mode()
555
538
        self.file_mode = self.bzrdir._get_file_mode()
556
539
 
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(
559
542
                'branch-format',
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.
564
547
        try:
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:
568
551
            pass
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)
589
572
 
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())
610
593
        else:
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)
618
601
        else:
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')
623
606
            self.put_format(
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)
638
621
 
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."""
650
633
        name = entry[0]
651
634
        mandatory = entry[1]
652
 
        self.step(gettext('Moving %s') % name)
 
635
        self.step('Moving %s' % name)
653
636
        try:
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)
682
665
 
683
 
    @classmethod
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"
687
669
 
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"
691
673
 
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()
696
678
 
720
702
        return RepositoryFormat4()
721
703
    repository_format = property(__return_repository_format)
722
704
 
723
 
    @classmethod
724
 
    def from_string(cls, format_string):
725
 
        if format_string != cls.get_format_string():
726
 
            raise AssertionError("unexpected format string %r" % format_string)
727
 
        return cls()
728
 
 
729
705
 
730
706
class BzrDirPreSplitOut(BzrDir):
731
707
    """A common class for the all-in-one formats."""
732
708
 
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),
750
726
 
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().
754
730
 
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)
772
748
        return result
773
749
 
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)
782
756
 
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)
786
760
 
787
761
    def create_repository(self, shared=False):
788
 
        """See ControlDir.create_repository."""
 
762
        """See BzrDir.create_repository."""
789
763
        if shared:
790
764
            raise errors.IncompatibleFormat('shared repository', self._format)
791
765
        return self.open_repository()
792
766
 
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)
796
770
 
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.
802
776
 
834
808
                self.transport, self._control_files._file_mode)
835
809
 
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)
839
813
 
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,
843
817
                                          self)
844
818
 
875
849
        raise errors.IncompatibleFormat(workingtree_format, self._format)
876
850
 
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__)
886
860
 
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)
895
868
 
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)
929
902
        return result
930
903
 
931
 
    def set_branch_reference(self, target_branch, name=None):
932
 
        from bzrlib.branch import BranchReferenceFormat
933
 
        if name is not None:
934
 
            raise errors.NoColocatedBranchSupport(self)
935
 
        raise errors.IncompatibleFormat(BranchReferenceFormat, self._format)
936
 
 
937
904
 
938
905
class BzrDir4(BzrDirPreSplitOut):
939
906
    """A .bzr version 4 control object.
942
909
    """
943
910
 
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)
947
914
 
948
915
    def needs_format_conversion(self, format=None):
953
920
        return True
954
921
 
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)
959
926
 
965
932
    """
966
933
 
967
934
    def has_workingtree(self):
968
 
        """See ControlDir.has_workingtree."""
 
935
        """See BzrDir.has_workingtree."""
969
936
        return True
970
937
    
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)
975
942
 
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
990
957
    """
991
958
 
992
959
    def has_workingtree(self):
993
 
        """See ControlDir.has_workingtree."""
 
960
        """See BzrDir.has_workingtree."""
994
961
        return True
995
962
 
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)
1000
967
 
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