~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2007-04-01 06:19:16 UTC
  • mfrom: (2323.5.20 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: mbp@sourcefrog.net-20070401061916-plpgsxdf8g7gll9o
Merge 0.15 final release back to trunk, including: recommend upgrades of old workingtrees, handle multiple http redirections, some dirstate fixes, 

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,
61
62
from bzrlib.store.text import TextStore
62
63
from bzrlib.store.versioned import WeaveStore
63
64
from bzrlib.transactions import WriteTransaction
64
 
from bzrlib.transport import get_transport
 
65
from bzrlib.transport import (
 
66
    do_catching_redirections,
 
67
    get_transport,
 
68
    )
65
69
from bzrlib.weave import Weave
66
70
""")
67
71
 
68
 
from bzrlib.trace import mutter, note
 
72
from bzrlib.trace import (
 
73
    mutter,
 
74
    note,
 
75
    )
69
76
from bzrlib.transport.local import LocalTransport
70
77
 
71
78
 
109
116
        source_repo_format.check_conversion_target(target_repo_format)
110
117
 
111
118
    @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.
 
119
    def _check_supported(format, allow_unsupported,
 
120
        recommend_upgrade=True,
 
121
        basedir=None):
 
122
        """Give an error or warning on old formats.
 
123
 
 
124
        :param format: may be any kind of format - workingtree, branch, 
 
125
        or repository.
 
126
 
 
127
        :param allow_unsupported: If true, allow opening 
 
128
        formats that are strongly deprecated, and which may 
 
129
        have limited functionality.
 
130
 
 
131
        :param recommend_upgrade: If true (default), warn
 
132
        the user through the ui object that they may wish
 
133
        to upgrade the object.
116
134
        """
 
135
        # TODO: perhaps move this into a base Format class; it's not BzrDir
 
136
        # specific. mbp 20070323
117
137
        if not allow_unsupported and not format.is_supported():
118
138
            # see open_downlevel to open legacy branches.
119
139
            raise errors.UnsupportedFormatError(format=format)
 
140
        if recommend_upgrade \
 
141
            and getattr(format, 'upgrade_recommended', False):
 
142
            ui.ui_factory.recommend_upgrade(
 
143
                format.get_format_description(),
 
144
                basedir)
120
145
 
121
146
    def clone(self, url, revision_id=None, force_new_repo=False):
122
147
        """Clone this bzrdir and its contents to url verbatim.
498
523
        :param transport: Transport containing the bzrdir.
499
524
        :param _unsupported: private.
500
525
        """
501
 
        format = BzrDirFormat.find_format(transport)
 
526
        base = transport.base
 
527
 
 
528
        def find_format(transport):
 
529
            return transport, BzrDirFormat.find_format(transport)
 
530
 
 
531
        def redirected(transport, e, redirection_notice):
 
532
            qualified_source = e.get_source_url()
 
533
            relpath = transport.relpath(qualified_source)
 
534
            if not e.target.endswith(relpath):
 
535
                # Not redirected to a branch-format, not a branch
 
536
                raise errors.NotBranchError(path=e.target)
 
537
            target = e.target[:-len(relpath)]
 
538
            note('%s is%s redirected to %s',
 
539
                 transport.base, e.permanently, target)
 
540
            # Let's try with a new transport
 
541
            qualified_target = e.get_target_url()[:-len(relpath)]
 
542
            # FIXME: If 'transport' has a qualifier, this should
 
543
            # be applied again to the new transport *iff* the
 
544
            # schemes used are the same. It's a bit tricky to
 
545
            # verify, so I'll punt for now
 
546
            # -- vila20070212
 
547
            return get_transport(target)
 
548
 
 
549
        try:
 
550
            transport, format = do_catching_redirections(find_format,
 
551
                                                         transport,
 
552
                                                         redirected)
 
553
        except errors.TooManyRedirections:
 
554
            raise errors.NotBranchError(base)
 
555
 
502
556
        BzrDir._check_supported(format, _unsupported)
503
557
        return format.open(transport, _found=True)
504
558
 
613
667
        workingtree and discards it, and that's somewhat expensive.) 
614
668
        """
615
669
        try:
616
 
            self.open_workingtree()
 
670
            self.open_workingtree(recommend_upgrade=False)
617
671
            return True
618
672
        except errors.NoWorkingTree:
619
673
            return False
631
685
        except errors.NoRepositoryPresent:
632
686
            source_repository = None
633
687
        try:
634
 
            tree = self.open_workingtree()
 
688
            # TODO: Couldn't we just probe for the format in these cases,
 
689
            # rather than opening the whole tree?  It would be a little
 
690
            # faster. mbp 20070401
 
691
            tree = self.open_workingtree(recommend_upgrade=False)
635
692
        except (errors.NoWorkingTree, errors.NotLocalUrl):
636
693
            result_format.workingtree_format = None
637
694
        else:
801
858
    def create_workingtree(self, revision_id=None):
802
859
        """See BzrDir.create_workingtree."""
803
860
        # this looks buggy but is not -really-
 
861
        # because this format creates the workingtree when the bzrdir is
 
862
        # created
804
863
        # clone and sprout will have set the revision_id
805
864
        # and that will have set it for us, its only
806
865
        # specific uses of create_workingtree in isolation
807
866
        # that can do wonky stuff here, and that only
808
867
        # happens for creating checkouts, which cannot be 
809
868
        # done on this format anyway. So - acceptable wart.
810
 
        result = self.open_workingtree()
 
869
        result = self.open_workingtree(recommend_upgrade=False)
811
870
        if revision_id is not None:
812
871
            if revision_id == _mod_revision.NULL_REVISION:
813
872
                result.set_parent_ids([])
918
977
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
919
978
        return RepositoryFormat5().open(self, _found=True)
920
979
 
921
 
    def open_workingtree(self, _unsupported=False):
 
980
    def open_workingtree(self, _unsupported=False,
 
981
            recommend_upgrade=True):
922
982
        """See BzrDir.create_workingtree."""
923
983
        from bzrlib.workingtree import WorkingTreeFormat2
924
 
        return WorkingTreeFormat2().open(self, _found=True)
 
984
        wt_format = WorkingTreeFormat2()
 
985
        # we don't warn here about upgrades; that ought to be handled for the
 
986
        # bzrdir as a whole
 
987
        return wt_format.open(self, _found=True)
925
988
 
926
989
 
927
990
class BzrDir6(BzrDirPreSplitOut):
935
998
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
936
999
        return RepositoryFormat6().open(self, _found=True)
937
1000
 
938
 
    def open_workingtree(self, _unsupported=False):
 
1001
    def open_workingtree(self, _unsupported=False,
 
1002
        recommend_upgrade=True):
939
1003
        """See BzrDir.create_workingtree."""
 
1004
        # we don't warn here about upgrades; that ought to be handled for the
 
1005
        # bzrdir as a whole
940
1006
        from bzrlib.workingtree import WorkingTreeFormat2
941
1007
        return WorkingTreeFormat2().open(self, _found=True)
942
1008
 
969
1035
 
970
1036
    def destroy_workingtree(self):
971
1037
        """See BzrDir.destroy_workingtree."""
972
 
        wt = self.open_workingtree()
 
1038
        wt = self.open_workingtree(recommend_upgrade=False)
973
1039
        repository = wt.branch.repository
974
1040
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
975
1041
        wt.revert([], old_tree=empty)
1049
1115
        except errors.NotBranchError:
1050
1116
            pass
1051
1117
        try:
1052
 
            if not isinstance(self.open_workingtree()._format,
 
1118
            my_wt = self.open_workingtree(recommend_upgrade=False)
 
1119
            if not isinstance(my_wt._format,
1053
1120
                              format.workingtree_format.__class__):
1054
1121
                # the workingtree needs an upgrade.
1055
1122
                return True
1071
1138
        self._check_supported(format, unsupported)
1072
1139
        return format.open(self, _found=True)
1073
1140
 
1074
 
    def open_workingtree(self, unsupported=False):
 
1141
    def open_workingtree(self, unsupported=False,
 
1142
            recommend_upgrade=True):
1075
1143
        """See BzrDir.open_workingtree."""
1076
1144
        from bzrlib.workingtree import WorkingTreeFormat
1077
1145
        format = WorkingTreeFormat.find_format(self)
1078
 
        self._check_supported(format, unsupported)
 
1146
        self._check_supported(format, unsupported,
 
1147
            recommend_upgrade,
 
1148
            basedir=self.root_transport.base)
1079
1149
        return format.open(self, _found=True)
1080
1150
 
1081
1151
 
1262
1332
 
1263
1333
    @classmethod
1264
1334
    def register_control_format(klass, format):
1265
 
        """Register a format that does not use '.bzrdir' for its control dir.
 
1335
        """Register a format that does not use '.bzr' for its control dir.
1266
1336
 
1267
1337
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1268
1338
        which BzrDirFormat can inherit from, and renamed to register_format 
1294
1364
        klass._control_formats.remove(format)
1295
1365
 
1296
1366
 
1297
 
# register BzrDirFormat as a control format
1298
 
BzrDirFormat.register_control_format(BzrDirFormat)
1299
 
 
1300
 
 
1301
1367
class BzrDirFormat4(BzrDirFormat):
1302
1368
    """Bzr dir format 4.
1303
1369
 
1554
1620
                                  __set_workingtree_format)
1555
1621
 
1556
1622
 
 
1623
# Register bzr control format
 
1624
BzrDirFormat.register_control_format(BzrDirFormat)
 
1625
 
 
1626
# Register bzr formats
1557
1627
BzrDirFormat.register_format(BzrDirFormat4())
1558
1628
BzrDirFormat.register_format(BzrDirFormat5())
1559
1629
BzrDirFormat.register_format(BzrDirFormat6())
2065
2135
                branch_converter = _mod_branch.Converter5to6()
2066
2136
                branch_converter.convert(branch)
2067
2137
        try:
2068
 
            tree = self.bzrdir.open_workingtree()
 
2138
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2069
2139
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2070
2140
            pass
2071
2141
        else: