~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2012-09-05 20:52:26 UTC
  • mfrom: (6549.3.1 dev_2.5_integration)
  • Revision ID: pqm@pqm.ubuntu.com-20120905205226-8s3bzolvduug3ifj
(gz) Merge 2.5 (Martin Packman)

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
    )
64
67
        create_prefix=False, force_new_repo=False, stacked_on=None,
65
68
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
66
69
        shared_repo=False):
67
 
        """See BzrDirFormat.initialize_on_transport_ex."""
 
70
        """See ControlDir.initialize_on_transport_ex."""
68
71
        require_stacking = (stacked_on is not None)
69
72
        # Format 5 cannot stack, but we've been asked to - actually init
70
73
        # a Meta1Dir
81
84
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
82
85
            make_working_trees=make_working_trees, shared_repo=shared_repo)
83
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
 
84
93
 
85
94
class BzrDirFormat5(BzrDirFormatAllInOne):
86
95
    """Bzr control format 5.
98
107
    def __eq__(self, other):
99
108
        return type(self) == type(other)
100
109
 
101
 
    def get_format_string(self):
 
110
    @classmethod
 
111
    def get_format_string(cls):
102
112
        """See BzrDirFormat.get_format_string()."""
103
113
        return "Bazaar-NG branch, format 5\n"
104
114
 
107
117
        return BzrBranchFormat4()
108
118
 
109
119
    def get_format_description(self):
110
 
        """See BzrDirFormat.get_format_description()."""
 
120
        """See ControlDirFormat.get_format_description()."""
111
121
        return "All-in-one format 5"
112
122
 
113
123
    def get_converter(self, format=None):
114
 
        """See BzrDirFormat.get_converter()."""
 
124
        """See ControlDirFormat.get_converter()."""
115
125
        # there is one and only one upgrade path here.
116
126
        return ConvertBzrDir5To6()
117
127
 
161
171
    def __eq__(self, other):
162
172
        return type(self) == type(other)
163
173
 
164
 
    def get_format_string(self):
 
174
    @classmethod
 
175
    def get_format_string(cls):
165
176
        """See BzrDirFormat.get_format_string()."""
166
177
        return "Bazaar-NG branch, format 6\n"
167
178
 
168
179
    def get_format_description(self):
169
 
        """See BzrDirFormat.get_format_description()."""
 
180
        """See ControlDirFormat.get_format_description()."""
170
181
        return "All-in-one format 6"
171
182
 
172
183
    def get_branch_format(self):
174
185
        return BzrBranchFormat4()
175
186
 
176
187
    def get_converter(self, format=None):
177
 
        """See BzrDirFormat.get_converter()."""
 
188
        """See ControlDirFormat.get_converter()."""
178
189
        # there is one and only one upgrade path here.
179
190
        return ConvertBzrDir6ToMeta()
180
191
 
230
241
            if isinstance(self.bzrdir.transport, local.LocalTransport):
231
242
                self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
232
243
            self._convert_to_weaves()
233
 
            return BzrDir.open(self.bzrdir.user_url)
 
244
            return ControlDir.open(self.bzrdir.user_url)
234
245
        finally:
235
246
            self.pb.finished()
236
247
 
495
506
        try:
496
507
            ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
497
508
            self._convert_to_prefixed()
498
 
            return BzrDir.open(self.bzrdir.user_url)
 
509
            return ControlDir.open(self.bzrdir.user_url)
499
510
        finally:
500
511
            pb.finished()
501
512
 
534
545
    def convert(self, to_convert, pb):
535
546
        """See Converter.convert()."""
536
547
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
537
 
        from bzrlib.branch import BzrBranchFormat5
 
548
        from bzrlib.branchfmt.fullhistory import BzrBranchFormat5
538
549
        self.bzrdir = to_convert
539
550
        self.pb = ui.ui_factory.nested_progress_bar()
540
551
        self.count = 0
623
634
            BzrDirMetaFormat1().get_format_string(),
624
635
            mode=self.file_mode)
625
636
        self.pb.finished()
626
 
        return BzrDir.open(self.bzrdir.user_url)
 
637
        return ControlDir.open(self.bzrdir.user_url)
627
638
 
628
639
    def make_lock(self, name):
629
640
        """Make a lock for the new control dir name."""
669
680
    def __eq__(self, other):
670
681
        return type(self) == type(other)
671
682
 
672
 
    def get_format_string(self):
 
683
    @classmethod
 
684
    def get_format_string(cls):
673
685
        """See BzrDirFormat.get_format_string()."""
674
686
        return "Bazaar-NG branch, format 0.0.4\n"
675
687
 
676
688
    def get_format_description(self):
677
 
        """See BzrDirFormat.get_format_description()."""
 
689
        """See ControlDirFormat.get_format_description()."""
678
690
        return "All-in-one format 4"
679
691
 
680
692
    def get_converter(self, format=None):
681
 
        """See BzrDirFormat.get_converter()."""
 
693
        """See ControlDirFormat.get_converter()."""
682
694
        # there is one and only one upgrade path here.
683
695
        return ConvertBzrDir4To5()
684
696
 
708
720
        return RepositoryFormat4()
709
721
    repository_format = property(__return_repository_format)
710
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
 
711
729
 
712
730
class BzrDirPreSplitOut(BzrDir):
713
731
    """A common class for the all-in-one formats."""
714
732
 
715
733
    def __init__(self, _transport, _format):
716
 
        """See BzrDir.__init__."""
 
734
        """See ControlDir.__init__."""
717
735
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
718
736
        self._control_files = lockable_files.LockableFiles(
719
737
                                            self.get_branch_transport(None),
732
750
 
733
751
    def clone(self, url, revision_id=None, force_new_repo=False,
734
752
              preserve_stacking=False):
735
 
        """See BzrDir.clone().
 
753
        """See ControlDir.clone().
736
754
 
737
755
        force_new_repo has no effect, since this family of formats always
738
756
        require a new repository.
755
773
 
756
774
    def create_branch(self, name=None, repository=None,
757
775
                      append_revisions_only=None):
758
 
        """See BzrDir.create_branch."""
 
776
        """See ControlDir.create_branch."""
759
777
        if repository is not None:
760
778
            raise NotImplementedError(
761
779
                "create_branch(repository=<not None>) on %r" % (self,))
763
781
            append_revisions_only=append_revisions_only)
764
782
 
765
783
    def destroy_branch(self, name=None):
766
 
        """See BzrDir.destroy_branch."""
 
784
        """See ControlDir.destroy_branch."""
767
785
        raise errors.UnsupportedOperation(self.destroy_branch, self)
768
786
 
769
787
    def create_repository(self, shared=False):
770
 
        """See BzrDir.create_repository."""
 
788
        """See ControlDir.create_repository."""
771
789
        if shared:
772
790
            raise errors.IncompatibleFormat('shared repository', self._format)
773
791
        return self.open_repository()
774
792
 
775
793
    def destroy_repository(self):
776
 
        """See BzrDir.destroy_repository."""
 
794
        """See ControlDir.destroy_repository."""
777
795
        raise errors.UnsupportedOperation(self.destroy_repository, self)
778
796
 
779
797
    def create_workingtree(self, revision_id=None, from_branch=None,
780
798
                           accelerator_tree=None, hardlink=False):
781
 
        """See BzrDir.create_workingtree."""
 
799
        """See ControlDir.create_workingtree."""
782
800
        # The workingtree is sometimes created when the bzrdir is created,
783
801
        # but not when cloning.
784
802
 
816
834
                self.transport, self._control_files._file_mode)
817
835
 
818
836
    def destroy_workingtree(self):
819
 
        """See BzrDir.destroy_workingtree."""
 
837
        """See ControlDir.destroy_workingtree."""
820
838
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
821
839
 
822
840
    def destroy_workingtree_metadata(self):
823
 
        """See BzrDir.destroy_workingtree_metadata."""
 
841
        """See ControlDir.destroy_workingtree_metadata."""
824
842
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
825
843
                                          self)
826
844
 
857
875
        raise errors.IncompatibleFormat(workingtree_format, self._format)
858
876
 
859
877
    def needs_format_conversion(self, format=None):
860
 
        """See BzrDir.needs_format_conversion()."""
 
878
        """See ControlDir.needs_format_conversion()."""
861
879
        # if the format is not the same as the system default,
862
880
        # an upgrade is needed.
863
881
        if format is None:
867
885
        return not isinstance(self._format, format.__class__)
868
886
 
869
887
    def open_branch(self, name=None, unsupported=False,
870
 
                    ignore_fallbacks=False):
871
 
        """See BzrDir.open_branch."""
 
888
                    ignore_fallbacks=False, possible_transports=None):
 
889
        """See ControlDir.open_branch."""
872
890
        from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
873
891
        format = BzrBranchFormat4()
874
892
        format.check_support_status(unsupported)
875
 
        return format.open(self, name, _found=True)
 
893
        return format.open(self, name, _found=True,
 
894
            possible_transports=possible_transports)
876
895
 
877
896
    def sprout(self, url, revision_id=None, force_new_repo=False,
878
897
               possible_transports=None, accelerator_tree=None,
879
898
               hardlink=False, stacked=False, create_tree_if_local=True,
880
899
               source_branch=None):
881
 
        """See BzrDir.sprout()."""
 
900
        """See ControlDir.sprout()."""
882
901
        if source_branch is not None:
883
902
            my_branch = self.open_branch()
884
903
            if source_branch.base != my_branch.base:
909
928
                                        hardlink=hardlink)
910
929
        return result
911
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
 
912
937
 
913
938
class BzrDir4(BzrDirPreSplitOut):
914
939
    """A .bzr version 4 control object.
917
942
    """
918
943
 
919
944
    def create_repository(self, shared=False):
920
 
        """See BzrDir.create_repository."""
 
945
        """See ControlDir.create_repository."""
921
946
        return self._format.repository_format.initialize(self, shared)
922
947
 
923
948
    def needs_format_conversion(self, format=None):
928
953
        return True
929
954
 
930
955
    def open_repository(self):
931
 
        """See BzrDir.open_repository."""
 
956
        """See ControlDir.open_repository."""
932
957
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
933
958
        return RepositoryFormat4().open(self, _found=True)
934
959
 
940
965
    """
941
966
 
942
967
    def has_workingtree(self):
943
 
        """See BzrDir.has_workingtree."""
 
968
        """See ControlDir.has_workingtree."""
944
969
        return True
945
970
    
946
971
    def open_repository(self):
947
 
        """See BzrDir.open_repository."""
 
972
        """See ControlDir.open_repository."""
948
973
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
949
974
        return RepositoryFormat5().open(self, _found=True)
950
975
 
951
 
    def open_workingtree(self, _unsupported=False,
 
976
    def open_workingtree(self, unsupported=False,
952
977
            recommend_upgrade=True):
953
 
        """See BzrDir.create_workingtree."""
 
978
        """See ControlDir.create_workingtree."""
954
979
        from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
955
980
        wt_format = WorkingTreeFormat2()
956
981
        # we don't warn here about upgrades; that ought to be handled for the
965
990
    """
966
991
 
967
992
    def has_workingtree(self):
968
 
        """See BzrDir.has_workingtree."""
 
993
        """See ControlDir.has_workingtree."""
969
994
        return True
970
995
 
971
996
    def open_repository(self):
972
 
        """See BzrDir.open_repository."""
 
997
        """See ControlDir.open_repository."""
973
998
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
974
999
        return RepositoryFormat6().open(self, _found=True)
975
1000
 
976
 
    def open_workingtree(self, _unsupported=False,
977
 
        recommend_upgrade=True):
978
 
        """See BzrDir.create_workingtree."""
 
1001
    def open_workingtree(self, unsupported=False, recommend_upgrade=True):
 
1002
        """See ControlDir.create_workingtree."""
979
1003
        # we don't warn here about upgrades; that ought to be handled for the
980
1004
        # bzrdir as a whole
981
1005
        from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2