/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2007-03-23 01:41:37 UTC
  • mto: (2323.5.2 0.15)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: mbp@sourcefrog.net-20070323014137-7rvpygb42i2tyrfc
BzrDir._check_supported now also takes care of recommending upgrades, which
should be less disruptive to other workingtree formats.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    registry,
47
47
    revision as _mod_revision,
48
48
    symbol_versioning,
 
49
    ui,
49
50
    urlutils,
50
51
    xml4,
51
52
    xml5,
109
110
        source_repo_format.check_conversion_target(target_repo_format)
110
111
 
111
112
    @staticmethod
112
 
    def _check_supported(format, allow_unsupported):
113
 
        """Check whether format is a supported format.
114
 
 
115
 
        If allow_unsupported is True, this is a no-op.
 
113
    def _check_supported(format, allow_unsupported,
 
114
        recommend_upgrade=True,
 
115
        basedir=None):
 
116
        """Give an error or warning on old formats.
 
117
 
 
118
        :param format: may be any kind of format - workingtree, branch, 
 
119
        or repository.
 
120
 
 
121
        :param allow_unsupported: If true, allow opening 
 
122
        formats that are strongly deprecated, and which may 
 
123
        have limited functionality.
 
124
 
 
125
        :param recommend_upgrade: If true (default), warn
 
126
        the user through the ui object that they may wish
 
127
        to upgrade the object.
116
128
        """
 
129
        # TODO: perhaps move this into the format itself.
 
130
        # mbp 20070323
117
131
        if not allow_unsupported and not format.is_supported():
118
132
            # see open_downlevel to open legacy branches.
119
133
            raise errors.UnsupportedFormatError(format=format)
 
134
        if recommend_upgrade \
 
135
            and getattr(format, 'upgrade_recommended', False):
 
136
            ui.ui_factory.recommend_upgrade(
 
137
                format.get_format_description(),
 
138
                basedir)
120
139
 
121
140
    def clone(self, url, revision_id=None, basis=None, force_new_repo=False):
122
141
        """Clone this bzrdir and its contents to url verbatim.
527
546
        :param _unsupported: private.
528
547
        """
529
548
        format = BzrDirFormat.find_format(transport)
530
 
        BzrDir._check_supported(format, _unsupported)
 
549
        BzrDir._check_supported(format, _unsupported,
 
550
            basedir=transport.base)
531
551
        return format.open(transport, _found=True)
532
552
 
533
553
    def open_branch(self, unsupported=False):
641
661
        workingtree and discards it, and that's somewhat expensive.) 
642
662
        """
643
663
        try:
644
 
            self.open_workingtree()
 
664
            self.open_workingtree(recommend_upgrade=False)
645
665
            return True
646
666
        except errors.NoWorkingTree:
647
667
            return False
844
864
    def create_workingtree(self, revision_id=None):
845
865
        """See BzrDir.create_workingtree."""
846
866
        # this looks buggy but is not -really-
 
867
        # because this format creates the workingtree when the bzrdir is
 
868
        # created
847
869
        # clone and sprout will have set the revision_id
848
870
        # and that will have set it for us, its only
849
871
        # specific uses of create_workingtree in isolation
850
872
        # that can do wonky stuff here, and that only
851
873
        # happens for creating checkouts, which cannot be 
852
874
        # done on this format anyway. So - acceptable wart.
853
 
        result = self.open_workingtree()
 
875
        result = self.open_workingtree(recommend_upgrade=False)
854
876
        if revision_id is not None:
855
877
            if revision_id == _mod_revision.NULL_REVISION:
856
878
                result.set_parent_ids([])
962
984
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
963
985
        return RepositoryFormat5().open(self, _found=True)
964
986
 
965
 
    def open_workingtree(self, _unsupported=False):
 
987
    def open_workingtree(self, _unsupported=False,
 
988
            recommend_upgrade=True):
966
989
        """See BzrDir.create_workingtree."""
967
990
        from bzrlib.workingtree import WorkingTreeFormat2
968
 
        return WorkingTreeFormat2().open(self, _found=True)
 
991
        wt_format = WorkingTreeFormat2()
 
992
        # we don't warn here about upgrades; that ought to be handled for the
 
993
        # bzrdir as a whole
 
994
        return wt_format.open(self, _found=True)
969
995
 
970
996
 
971
997
class BzrDir6(BzrDirPreSplitOut):
979
1005
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
980
1006
        return RepositoryFormat6().open(self, _found=True)
981
1007
 
982
 
    def open_workingtree(self, _unsupported=False):
 
1008
    def open_workingtree(self, _unsupported=False,
 
1009
        recommend_upgrade=True):
983
1010
        """See BzrDir.create_workingtree."""
 
1011
        # we don't warn here about upgrades; that ought to be handled for the
 
1012
        # bzrdir as a whole
984
1013
        from bzrlib.workingtree import WorkingTreeFormat2
985
1014
        return WorkingTreeFormat2().open(self, _found=True)
986
1015
 
1013
1042
 
1014
1043
    def destroy_workingtree(self):
1015
1044
        """See BzrDir.destroy_workingtree."""
1016
 
        wt = self.open_workingtree()
 
1045
        wt = self.open_workingtree(recommend_upgrade=False)
1017
1046
        repository = wt.branch.repository
1018
1047
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1019
1048
        wt.revert([], old_tree=empty)
1093
1122
        except errors.NotBranchError:
1094
1123
            pass
1095
1124
        try:
1096
 
            if not isinstance(self.open_workingtree()._format,
 
1125
            my_wt = self.open_workingtree(recommend_upgrade=False)
 
1126
            if not isinstance(my_wt._format,
1097
1127
                              format.workingtree_format.__class__):
1098
1128
                # the workingtree needs an upgrade.
1099
1129
                return True
1115
1145
        self._check_supported(format, unsupported)
1116
1146
        return format.open(self, _found=True)
1117
1147
 
1118
 
    def open_workingtree(self, unsupported=False):
 
1148
    def open_workingtree(self, unsupported=False,
 
1149
            recommend_upgrade=True):
1119
1150
        """See BzrDir.open_workingtree."""
1120
1151
        from bzrlib.workingtree import WorkingTreeFormat
1121
1152
        format = WorkingTreeFormat.find_format(self)
1122
 
        self._check_supported(format, unsupported)
 
1153
        self._check_supported(format, unsupported,
 
1154
            recommend_upgrade,
 
1155
            basedir=self.transport.base)
1123
1156
        return format.open(self, _found=True)
1124
1157
 
1125
1158
 
2109
2142
                branch_converter = _mod_branch.Converter5to6()
2110
2143
                branch_converter.convert(branch)
2111
2144
        try:
2112
 
            tree = self.bzrdir.open_workingtree()
 
2145
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2113
2146
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2114
2147
            pass
2115
2148
        else: