~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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