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,
65
69
from bzrlib.weave import Weave
68
from bzrlib.trace import mutter, note
72
from bzrlib.trace import (
69
76
from bzrlib.transport.local import LocalTransport
109
116
source_repo_format.check_conversion_target(target_repo_format)
112
def _check_supported(format, allow_unsupported):
113
"""Check whether format is a supported format.
115
If allow_unsupported is True, this is a no-op.
119
def _check_supported(format, allow_unsupported,
120
recommend_upgrade=True,
122
"""Give an error or warning on old formats.
124
:param format: may be any kind of format - workingtree, branch,
127
:param allow_unsupported: If true, allow opening
128
formats that are strongly deprecated, and which may
129
have limited functionality.
131
:param recommend_upgrade: If true (default), warn
132
the user through the ui object that they may wish
133
to upgrade the object.
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(),
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.
501
format = BzrDirFormat.find_format(transport)
526
base = transport.base
528
def find_format(transport):
529
return transport, BzrDirFormat.find_format(transport)
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
547
return get_transport(target)
550
transport, format = do_catching_redirections(find_format,
553
except errors.TooManyRedirections:
554
raise errors.NotBranchError(base)
502
556
BzrDir._check_supported(format, _unsupported)
503
557
return format.open(transport, _found=True)
631
685
except errors.NoRepositoryPresent:
632
686
source_repository = None
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
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
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)
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
987
return wt_format.open(self, _found=True)
927
990
class BzrDir6(BzrDirPreSplitOut):
935
998
from bzrlib.repofmt.weaverepo import RepositoryFormat6
936
999
return RepositoryFormat6().open(self, _found=True)
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
940
1006
from bzrlib.workingtree import WorkingTreeFormat2
941
1007
return WorkingTreeFormat2().open(self, _found=True)
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:
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.
1071
1138
self._check_supported(format, unsupported)
1072
1139
return format.open(self, _found=True)
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,
1148
basedir=self.root_transport.base)
1079
1149
return format.open(self, _found=True)
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.
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
1554
1620
__set_workingtree_format)
1623
# Register bzr control format
1624
BzrDirFormat.register_control_format(BzrDirFormat)
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)
2068
tree = self.bzrdir.open_workingtree()
2138
tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2069
2139
except (errors.NoWorkingTree, errors.NotLocalUrl):