~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Starr-Bochicchio
  • Date: 2014-03-30 17:59:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6592.
  • Revision ID: a.starr.b@gmail.com-20140330175929-rd97jstcbau2j1gy
Use LooseVersion from distutils to check Cython version in order to handle non-integers in the version string.

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:
868
886
 
869
887
    def open_branch(self, name=None, unsupported=False,
870
888
                    ignore_fallbacks=False, possible_transports=None):
871
 
        """See BzrDir.open_branch."""
 
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)
879
897
               possible_transports=None, accelerator_tree=None,
880
898
               hardlink=False, stacked=False, create_tree_if_local=True,
881
899
               source_branch=None):
882
 
        """See BzrDir.sprout()."""
 
900
        """See ControlDir.sprout()."""
883
901
        if source_branch is not None:
884
902
            my_branch = self.open_branch()
885
903
            if source_branch.base != my_branch.base:
910
928
                                        hardlink=hardlink)
911
929
        return result
912
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
 
913
937
 
914
938
class BzrDir4(BzrDirPreSplitOut):
915
939
    """A .bzr version 4 control object.
918
942
    """
919
943
 
920
944
    def create_repository(self, shared=False):
921
 
        """See BzrDir.create_repository."""
 
945
        """See ControlDir.create_repository."""
922
946
        return self._format.repository_format.initialize(self, shared)
923
947
 
924
948
    def needs_format_conversion(self, format=None):
929
953
        return True
930
954
 
931
955
    def open_repository(self):
932
 
        """See BzrDir.open_repository."""
 
956
        """See ControlDir.open_repository."""
933
957
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat4
934
958
        return RepositoryFormat4().open(self, _found=True)
935
959
 
941
965
    """
942
966
 
943
967
    def has_workingtree(self):
944
 
        """See BzrDir.has_workingtree."""
 
968
        """See ControlDir.has_workingtree."""
945
969
        return True
946
970
    
947
971
    def open_repository(self):
948
 
        """See BzrDir.open_repository."""
 
972
        """See ControlDir.open_repository."""
949
973
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
950
974
        return RepositoryFormat5().open(self, _found=True)
951
975
 
952
 
    def open_workingtree(self, _unsupported=False,
 
976
    def open_workingtree(self, unsupported=False,
953
977
            recommend_upgrade=True):
954
 
        """See BzrDir.create_workingtree."""
 
978
        """See ControlDir.create_workingtree."""
955
979
        from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
956
980
        wt_format = WorkingTreeFormat2()
957
981
        # we don't warn here about upgrades; that ought to be handled for the
966
990
    """
967
991
 
968
992
    def has_workingtree(self):
969
 
        """See BzrDir.has_workingtree."""
 
993
        """See ControlDir.has_workingtree."""
970
994
        return True
971
995
 
972
996
    def open_repository(self):
973
 
        """See BzrDir.open_repository."""
 
997
        """See ControlDir.open_repository."""
974
998
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
975
999
        return RepositoryFormat6().open(self, _found=True)
976
1000
 
977
 
    def open_workingtree(self, _unsupported=False,
978
 
        recommend_upgrade=True):
979
 
        """See BzrDir.create_workingtree."""
 
1001
    def open_workingtree(self, unsupported=False, recommend_upgrade=True):
 
1002
        """See ControlDir.create_workingtree."""
980
1003
        # we don't warn here about upgrades; that ought to be handled for the
981
1004
        # bzrdir as a whole
982
1005
        from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2