~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

(jelmer) Use 'development-subtree' format rather than
 'dirstate-with-subtree' in tests. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
objects returned.
26
26
"""
27
27
 
 
28
from __future__ import absolute_import
 
29
 
28
30
import sys
29
31
 
30
32
from bzrlib.lazy_import import lazy_import
46
48
    transport as _mod_transport,
47
49
    ui,
48
50
    urlutils,
 
51
    vf_search,
49
52
    win32utils,
50
53
    workingtree_3,
51
54
    workingtree_4,
200
203
                if (result_repo.user_url == result.user_url
201
204
                    and not require_stacking and
202
205
                    revision_id is not None):
203
 
                    fetch_spec = graph.PendingAncestryResult(
 
206
                    fetch_spec = vf_search.PendingAncestryResult(
204
207
                        [revision_id], local_repo)
205
208
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
206
209
                else:
370
373
        if revision_id is not None:
371
374
            fetch_spec_factory.add_revision_ids([revision_id])
372
375
            fetch_spec_factory.source_branch_stop_revision_id = revision_id
 
376
        if possible_transports is None:
 
377
            possible_transports = []
 
378
        else:
 
379
            possible_transports = list(possible_transports) + [
 
380
                self.root_transport]
373
381
        target_transport = _mod_transport.get_transport(url,
374
382
            possible_transports)
375
383
        target_transport.ensure_base()
376
384
        cloning_format = self.cloning_metadir(stacked)
377
385
        # Create/update the result branch
378
 
        result = cloning_format.initialize_on_transport(target_transport)
 
386
        try:
 
387
            result = controldir.ControlDir.open_from_transport(target_transport)
 
388
        except errors.NotBranchError:
 
389
            result = cloning_format.initialize_on_transport(target_transport)
379
390
        source_branch, source_repository = self._find_source_repo(
380
391
            add_cleanup, source_branch)
381
392
        fetch_spec_factory.source_branch = source_branch
387
398
            stacked_branch_url = None
388
399
        repository_policy = result.determine_repository_policy(
389
400
            force_new_repo, stacked_branch_url, require_stacking=stacked)
390
 
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
401
        result_repo, is_new_repo = repository_policy.acquire_repository(
 
402
            possible_transports=possible_transports)
391
403
        add_cleanup(result_repo.lock_write().unlock)
392
404
        fetch_spec_factory.source_repo = source_repository
393
405
        fetch_spec_factory.target_repo = result_repo
414
426
        mutter("created new branch %r" % (result_branch,))
415
427
 
416
428
        # Create/update the result working tree
417
 
        if (create_tree_if_local and
 
429
        if (create_tree_if_local and not result.has_workingtree() and
418
430
            isinstance(target_transport, local.LocalTransport) and
419
431
            (result_repo is None or result_repo.make_working_trees())):
420
432
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
771
783
        return controldir.ControlDir.create(base, format=format,
772
784
                possible_transports=possible_transports)
773
785
 
 
786
    def __repr__(self):
 
787
        return "<%s at %r>" % (self.__class__.__name__, self.user_url)
 
788
 
 
789
    def update_feature_flags(self, updated_flags):
 
790
        """Update the features required by this bzrdir.
 
791
 
 
792
        :param updated_flags: Dictionary mapping feature names to necessities
 
793
            A necessity can be None to indicate the feature should be removed
 
794
        """
 
795
        self.control_files.lock_write()
 
796
        try:
 
797
            self._format._update_feature_flags(updated_flags)
 
798
            self.transport.put_bytes('branch-format', self._format.as_string())
 
799
        finally:
 
800
            self.control_files.unlock()
 
801
 
774
802
 
775
803
class BzrDirMeta1(BzrDir):
776
804
    """A .bzr meta version 1 control object.
781
809
    present within a BzrDir.
782
810
    """
783
811
 
 
812
    def __init__(self, _transport, _format):
 
813
        super(BzrDirMeta1, self).__init__(_transport, _format)
 
814
        self.control_files = lockable_files.LockableFiles(self.control_transport,
 
815
            self._format._lock_file_name, self._format._lock_class)
 
816
 
784
817
    def can_convert_format(self):
785
818
        """See BzrDir.can_convert_format()."""
786
819
        return True
788
821
    def create_branch(self, name=None, repository=None,
789
822
            append_revisions_only=None):
790
823
        """See BzrDir.create_branch."""
 
824
        if name is None:
 
825
            name = self._get_selected_branch()
791
826
        return self._format.get_branch_format().initialize(self, name=name,
792
827
                repository=repository,
793
828
                append_revisions_only=append_revisions_only)
794
829
 
795
830
    def destroy_branch(self, name=None):
796
831
        """See BzrDir.create_branch."""
797
 
        if name is not None:
 
832
        if name is None:
 
833
            name = self._get_selected_branch()
 
834
        if name != "":
798
835
            raise errors.NoColocatedBranchSupport(self)
799
836
        self.transport.delete_tree('branch')
800
837
 
804
841
 
805
842
    def destroy_repository(self):
806
843
        """See BzrDir.destroy_repository."""
807
 
        self.transport.delete_tree('repository')
 
844
        try:
 
845
            self.transport.delete_tree('repository')
 
846
        except errors.NoSuchFile:
 
847
            raise errors.NoRepositoryPresent(self)
808
848
 
809
849
    def create_workingtree(self, revision_id=None, from_branch=None,
810
850
                           accelerator_tree=None, hardlink=False):
832
872
 
833
873
        This might be a synthetic object for e.g. RemoteBranch and SVN.
834
874
        """
835
 
        from bzrlib.branch import BranchFormat
836
 
        return BranchFormat.find_format(self, name=name)
 
875
        from bzrlib.branch import BranchFormatMetadir
 
876
        return BranchFormatMetadir.find_format(self, name=name)
837
877
 
838
878
    def _get_mkdir_mode(self):
839
879
        """Figure out the mode to use when creating a bzrdir subdir."""
843
883
 
844
884
    def get_branch_reference(self, name=None):
845
885
        """See BzrDir.get_branch_reference()."""
846
 
        from bzrlib.branch import BranchFormat
847
 
        format = BranchFormat.find_format(self, name=name)
 
886
        from bzrlib.branch import BranchFormatMetadir
 
887
        format = BranchFormatMetadir.find_format(self, name=name)
848
888
        return format.get_reference(self, name=name)
849
889
 
 
890
    def set_branch_reference(self, target_branch, name=None):
 
891
        format = _mod_branch.BranchReferenceFormat()
 
892
        return format.initialize(self, target_branch=target_branch, name=name)
 
893
 
850
894
    def get_branch_transport(self, branch_format, name=None):
851
895
        """See BzrDir.get_branch_transport()."""
852
 
        if name is not None:
 
896
        if name is None:
 
897
            name = self._get_selected_branch()
 
898
        if name != "":
853
899
            raise errors.NoColocatedBranchSupport(self)
854
900
        # XXX: this shouldn't implicitly create the directory if it's just
855
901
        # promising to get a transport -- mbp 20090727
899
945
        Note: if you're going to open the working tree, you should just go
900
946
        ahead and try, and not ask permission first.
901
947
        """
902
 
        from bzrlib.workingtree import WorkingTreeFormat
 
948
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
903
949
        try:
904
 
            WorkingTreeFormat.find_format_string(self)
 
950
            WorkingTreeFormatMetaDir.find_format_string(self)
905
951
        except errors.NoWorkingTree:
906
952
            return False
907
953
        return True
936
982
        return False
937
983
 
938
984
    def open_branch(self, name=None, unsupported=False,
939
 
                    ignore_fallbacks=False):
940
 
        """See BzrDir.open_branch."""
 
985
                    ignore_fallbacks=False, possible_transports=None):
 
986
        """See ControlDir.open_branch."""
 
987
        if name is None:
 
988
            name = self._get_selected_branch()
941
989
        format = self.find_branch_format(name=name)
942
990
        format.check_support_status(unsupported)
943
991
        return format.open(self, name=name,
944
 
            _found=True, ignore_fallbacks=ignore_fallbacks)
 
992
            _found=True, ignore_fallbacks=ignore_fallbacks,
 
993
            possible_transports=possible_transports)
945
994
 
946
995
    def open_repository(self, unsupported=False):
947
996
        """See BzrDir.open_repository."""
948
 
        from bzrlib.repository import RepositoryFormat
949
 
        format = RepositoryFormat.find_format(self)
 
997
        from bzrlib.repository import RepositoryFormatMetaDir
 
998
        format = RepositoryFormatMetaDir.find_format(self)
950
999
        format.check_support_status(unsupported)
951
1000
        return format.open(self, _found=True)
952
1001
 
953
1002
    def open_workingtree(self, unsupported=False,
954
1003
            recommend_upgrade=True):
955
1004
        """See BzrDir.open_workingtree."""
956
 
        from bzrlib.workingtree import WorkingTreeFormat
957
 
        format = WorkingTreeFormat.find_format(self)
 
1005
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
 
1006
        format = WorkingTreeFormatMetaDir.find_format(self)
958
1007
        format.check_support_status(unsupported, recommend_upgrade,
959
1008
            basedir=self.root_transport.base)
960
1009
        return format.open(self, _found=True)
970
1019
    BzrDirMeta1.
971
1020
    """
972
1021
 
973
 
    def __init__(self, _transport, _format):
974
 
        super(BzrDirMeta1Colo, self).__init__(_transport, _format)
975
 
        self.control_files = lockable_files.LockableFiles(_transport,
976
 
            self._format._lock_file_name, self._format._lock_class)
977
 
 
978
1022
    def _get_branch_path(self, name):
979
1023
        """Obtain the branch path to use.
980
1024
 
983
1027
        it uses the default branch.
984
1028
 
985
1029
        :param name: Optional branch name to use
986
 
        :return: Relative path to branch, branch name
 
1030
        :return: Relative path to branch
987
1031
        """
988
 
        if name is None:
989
 
            name = self._get_selected_branch()
990
 
        if name is None:
991
 
            return 'branch', None
992
 
        return urlutils.join('branches', name), name
 
1032
        if name == "":
 
1033
            return 'branch'
 
1034
        return urlutils.join('branches', name.encode("utf-8"))
993
1035
 
994
1036
    def _read_branch_list(self):
995
1037
        """Read the branch list.
1019
1061
 
1020
1062
    def destroy_branch(self, name=None):
1021
1063
        """See BzrDir.create_branch."""
1022
 
        path, name = self._get_branch_path(name)
1023
 
        if name is not None:
 
1064
        if name is None:
 
1065
            name = self._get_selected_branch()
 
1066
        path = self._get_branch_path(name)
 
1067
        if name != "":
1024
1068
            self.control_files.lock_write()
1025
1069
            try:
1026
1070
                branches = self._read_branch_list()
1027
1071
                try:
1028
 
                    branches.remove(name)
 
1072
                    branches.remove(name.encode("utf-8"))
1029
1073
                except ValueError:
1030
1074
                    raise errors.NotBranchError(name)
1031
 
                self._write_branch_list(name)
 
1075
                self._write_branch_list(branches)
1032
1076
            finally:
1033
1077
                self.control_files.unlock()
1034
1078
        self.transport.delete_tree(path)
1035
1079
 
1036
 
    def list_branches(self):
1037
 
        """See ControlDir.list_branches."""
1038
 
        ret = []
1039
 
        # Default branch
 
1080
    def get_branches(self):
 
1081
        """See ControlDir.get_branches."""
 
1082
        ret = {}
1040
1083
        try:
1041
 
            ret.append(self.open_branch())
 
1084
            ret[""] = self.open_branch(name="")
1042
1085
        except (errors.NotBranchError, errors.NoRepositoryPresent):
1043
1086
            pass
1044
1087
 
1045
 
        # colocated branches
1046
 
        ret.extend([self.open_branch(name) for name in
1047
 
                    self._read_branch_list()])
 
1088
        for name in self._read_branch_list():
 
1089
            ret[name] = self.open_branch(name=name.decode('utf-8'))
1048
1090
 
1049
1091
        return ret
1050
1092
 
1051
1093
    def get_branch_transport(self, branch_format, name=None):
1052
1094
        """See BzrDir.get_branch_transport()."""
1053
 
        path, name = self._get_branch_path(name)
 
1095
        if name is None:
 
1096
            name = self._get_selected_branch()
 
1097
        path = self._get_branch_path(name)
1054
1098
        # XXX: this shouldn't implicitly create the directory if it's just
1055
1099
        # promising to get a transport -- mbp 20090727
1056
1100
        if branch_format is None:
1059
1103
            branch_format.get_format_string()
1060
1104
        except NotImplementedError:
1061
1105
            raise errors.IncompatibleFormat(branch_format, self._format)
1062
 
        if name is not None:
 
1106
        if name != "":
1063
1107
            try:
1064
1108
                self.transport.mkdir('branches', mode=self._get_mkdir_mode())
1065
1109
            except errors.FileExists:
1066
1110
                pass
1067
1111
            branches = self._read_branch_list()
1068
 
            if not name in branches:
 
1112
            utf8_name = name.encode("utf-8")
 
1113
            if not utf8_name in branches:
1069
1114
                self.control_files.lock_write()
1070
1115
                try:
1071
1116
                    branches = self._read_branch_list()
1072
 
                    branches.append(name)
 
1117
                    branches.append(utf8_name)
1073
1118
                    self._write_branch_list(branches)
1074
1119
                finally:
1075
1120
                    self.control_files.unlock()
1080
1125
        return self.transport.clone(path)
1081
1126
 
1082
1127
 
 
1128
class BzrFormat(object):
 
1129
    """Base class for all formats of things living in metadirs.
 
1130
 
 
1131
    This class manages the format string that is stored in the 'format'
 
1132
    or 'branch-format' file.
 
1133
 
 
1134
    All classes for (branch-, repository-, workingtree-) formats that
 
1135
    live in meta directories and have their own 'format' file
 
1136
    (i.e. different from .bzr/branch-format) derive from this class,
 
1137
    as well as the relevant base class for their kind
 
1138
    (BranchFormat, WorkingTreeFormat, RepositoryFormat).
 
1139
 
 
1140
    Each format is identified by a "format" or "branch-format" file with a
 
1141
    single line containing the base format name and then an optional list of
 
1142
    feature flags.
 
1143
 
 
1144
    Feature flags are supported as of bzr 2.5. Setting feature flags on formats
 
1145
    will render them inaccessible to older versions of bzr.
 
1146
 
 
1147
    :ivar features: Dictionary mapping feature names to their necessity
 
1148
    """
 
1149
 
 
1150
    _present_features = set()
 
1151
 
 
1152
    def __init__(self):
 
1153
        self.features = {}
 
1154
 
 
1155
    @classmethod
 
1156
    def register_feature(cls, name):
 
1157
        """Register a feature as being present.
 
1158
 
 
1159
        :param name: Name of the feature
 
1160
        """
 
1161
        if " " in name:
 
1162
            raise ValueError("spaces are not allowed in feature names")
 
1163
        if name in cls._present_features:
 
1164
            raise errors.FeatureAlreadyRegistered(name)
 
1165
        cls._present_features.add(name)
 
1166
 
 
1167
    @classmethod
 
1168
    def unregister_feature(cls, name):
 
1169
        """Unregister a feature."""
 
1170
        cls._present_features.remove(name)
 
1171
 
 
1172
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
 
1173
            basedir=None):
 
1174
        for name, necessity in self.features.iteritems():
 
1175
            if name in self._present_features:
 
1176
                continue
 
1177
            if necessity == "optional":
 
1178
                mutter("ignoring optional missing feature %s", name)
 
1179
                continue
 
1180
            elif necessity == "required":
 
1181
                raise errors.MissingFeature(name)
 
1182
            else:
 
1183
                mutter("treating unknown necessity as require for %s",
 
1184
                       name)
 
1185
                raise errors.MissingFeature(name)
 
1186
 
 
1187
    @classmethod
 
1188
    def get_format_string(cls):
 
1189
        """Return the ASCII format string that identifies this format."""
 
1190
        raise NotImplementedError(cls.get_format_string)
 
1191
 
 
1192
    @classmethod
 
1193
    def from_string(cls, text):
 
1194
        format_string = cls.get_format_string()
 
1195
        if not text.startswith(format_string):
 
1196
            raise AssertionError("Invalid format header %r for %r" % (text, cls))
 
1197
        lines = text[len(format_string):].splitlines()
 
1198
        ret = cls()
 
1199
        for lineno, line in enumerate(lines):
 
1200
            try:
 
1201
                (necessity, feature) = line.split(" ", 1)
 
1202
            except ValueError:
 
1203
                raise errors.ParseFormatError(format=cls, lineno=lineno+2,
 
1204
                    line=line, text=text)
 
1205
            ret.features[feature] = necessity
 
1206
        return ret
 
1207
 
 
1208
    def as_string(self):
 
1209
        """Return the string representation of this format.
 
1210
        """
 
1211
        lines = [self.get_format_string()]
 
1212
        lines.extend([("%s %s\n" % (item[1], item[0])) for item in
 
1213
            self.features.iteritems()])
 
1214
        return "".join(lines)
 
1215
 
 
1216
    @classmethod
 
1217
    def _find_format(klass, registry, kind, format_string):
 
1218
        try:
 
1219
            first_line = format_string[:format_string.index("\n")+1]
 
1220
        except ValueError:
 
1221
            first_line = format_string
 
1222
        try:
 
1223
            cls = registry.get(first_line)
 
1224
        except KeyError:
 
1225
            raise errors.UnknownFormatError(format=first_line, kind=kind)
 
1226
        return cls.from_string(format_string)
 
1227
 
 
1228
    def network_name(self):
 
1229
        """A simple byte string uniquely identifying this format for RPC calls.
 
1230
 
 
1231
        Metadir branch formats use their format string.
 
1232
        """
 
1233
        return self.as_string()
 
1234
 
 
1235
    def __eq__(self, other):
 
1236
        return (self.__class__ is other.__class__ and
 
1237
                self.features == other.features)
 
1238
 
 
1239
    def _update_feature_flags(self, updated_flags):
 
1240
        """Update the feature flags in this format.
 
1241
 
 
1242
        :param updated_flags: Updated feature flags
 
1243
        """
 
1244
        for name, necessity in updated_flags.iteritems():
 
1245
            if necessity is None:
 
1246
                try:
 
1247
                    del self.features[name]
 
1248
                except KeyError:
 
1249
                    pass
 
1250
            else:
 
1251
                self.features[name] = necessity
 
1252
 
 
1253
 
1083
1254
class BzrProber(controldir.Prober):
1084
1255
    """Prober for formats that use a .bzr/ control directory."""
1085
1256
 
1104
1275
        except errors.NoSuchFile:
1105
1276
            raise errors.NotBranchError(path=transport.base)
1106
1277
        try:
1107
 
            return klass.formats.get(format_string)
 
1278
            first_line = format_string[:format_string.index("\n")+1]
 
1279
        except ValueError:
 
1280
            first_line = format_string
 
1281
        try:
 
1282
            cls = klass.formats.get(first_line)
1108
1283
        except KeyError:
1109
 
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
 
1284
            raise errors.UnknownFormatError(format=first_line, kind='bzrdir')
 
1285
        return cls.from_string(format_string)
1110
1286
 
1111
1287
    @classmethod
1112
1288
    def known_formats(cls):
1155
1331
        return set([RemoteBzrDirFormat()])
1156
1332
 
1157
1333
 
1158
 
class BzrDirFormat(controldir.ControlDirFormat):
 
1334
class BzrDirFormat(BzrFormat, controldir.ControlDirFormat):
1159
1335
    """ControlDirFormat base class for .bzr/ directories.
1160
1336
 
1161
1337
    Formats are placed in a dict by their format string for reference
1172
1348
    # _lock_class must be set in subclasses to the lock type, typ.
1173
1349
    # TransportLock or LockDir
1174
1350
 
1175
 
    @classmethod
1176
 
    def get_format_string(cls):
1177
 
        """Return the ASCII format string that identifies this format."""
1178
 
        raise NotImplementedError(cls.get_format_string)
1179
 
 
1180
1351
    def initialize_on_transport(self, transport):
1181
1352
        """Initialize a new bzrdir in the base directory of a Transport."""
1182
1353
        try:
1304
1475
        # mode from the root directory
1305
1476
        temp_control = lockable_files.LockableFiles(transport,
1306
1477
                            '', lockable_files.TransportLock)
1307
 
        temp_control._transport.mkdir('.bzr',
1308
 
                                      # FIXME: RBC 20060121 don't peek under
1309
 
                                      # the covers
1310
 
                                      mode=temp_control._dir_mode)
 
1478
        try:
 
1479
            temp_control._transport.mkdir('.bzr',
 
1480
                # FIXME: RBC 20060121 don't peek under
 
1481
                # the covers
 
1482
                mode=temp_control._dir_mode)
 
1483
        except errors.FileExists:
 
1484
            raise errors.AlreadyControlDirError(transport.base)
1311
1485
        if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
1312
1486
            win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1313
1487
        file_mode = temp_control._file_mode
1317
1491
                       "This is a Bazaar control directory.\n"
1318
1492
                       "Do not change any files in this directory.\n"
1319
1493
                       "See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
1320
 
                      ('branch-format', self.get_format_string()),
 
1494
                      ('branch-format', self.as_string()),
1321
1495
                      ]
1322
1496
        # NB: no need to escape relative paths that are url safe.
1323
1497
        control_files = lockable_files.LockableFiles(bzrdir_transport,
1367
1541
            compatible with whatever sub formats are supported by self.
1368
1542
        :return: None.
1369
1543
        """
 
1544
        other_format.features = dict(self.features)
1370
1545
 
1371
1546
    def supports_transport(self, transport):
1372
1547
        # bzr formats can be opened over all known transports
1373
1548
        return True
1374
1549
 
 
1550
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
 
1551
            basedir=None):
 
1552
        controldir.ControlDirFormat.check_support_status(self,
 
1553
            allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
 
1554
            basedir=basedir)
 
1555
        BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
 
1556
            recommend_upgrade=recommend_upgrade, basedir=basedir)
 
1557
 
1375
1558
 
1376
1559
class BzrDirMetaFormat1(BzrDirFormat):
1377
1560
    """Bzr meta control format 1
1393
1576
    colocated_branches = False
1394
1577
 
1395
1578
    def __init__(self):
 
1579
        BzrDirFormat.__init__(self)
1396
1580
        self._workingtree_format = None
1397
1581
        self._branch_format = None
1398
1582
        self._repository_format = None
1404
1588
            return False
1405
1589
        if other.workingtree_format != self.workingtree_format:
1406
1590
            return False
 
1591
        if other.features != self.features:
 
1592
            return False
1407
1593
        return True
1408
1594
 
1409
1595
    def __ne__(self, other):
1535
1721
        """See BzrDirFormat.get_format_description()."""
1536
1722
        return "Meta directory format 1"
1537
1723
 
1538
 
    def network_name(self):
1539
 
        return self.get_format_string()
1540
 
 
1541
1724
    def _open(self, transport):
1542
1725
        """See BzrDirFormat._open."""
1543
1726
        # Create a new format instance because otherwise initialisation of new
1572
1755
            compatible with whatever sub formats are supported by self.
1573
1756
        :return: None.
1574
1757
        """
 
1758
        super(BzrDirMetaFormat1, self)._supply_sub_formats_to(other_format)
1575
1759
        if getattr(self, '_repository_format', None) is not None:
1576
1760
            other_format.repository_format = self.repository_format
1577
1761
        if self._branch_format is not None:
1590
1774
    def __set_workingtree_format(self, wt_format):
1591
1775
        self._workingtree_format = wt_format
1592
1776
 
 
1777
    def __repr__(self):
 
1778
        return "<%r>" % (self.__class__.__name__,)
 
1779
 
1593
1780
    workingtree_format = property(__get_workingtree_format,
1594
1781
                                  __set_workingtree_format)
1595
1782
 
1719
1906
    def convert(self, to_convert, pb):
1720
1907
        """See Converter.convert()."""
1721
1908
        to_convert.transport.put_bytes('branch-format',
1722
 
            self.target_format.get_format_string())
 
1909
            self.target_format.as_string())
1723
1910
        return BzrDir.open_from_transport(to_convert.root_transport)
1724
1911
 
1725
1912
 
1745
1932
        finally:
1746
1933
            to_convert.control_files.unlock()
1747
1934
        to_convert.transport.put_bytes('branch-format',
1748
 
            self.target_format.get_format_string())
 
1935
            self.target_format.as_string())
1749
1936
        return BzrDir.open_from_transport(to_convert.root_transport)
1750
1937
 
1751
1938
 
1831
2018
        else:
1832
2019
            self._require_stacking = True
1833
2020
 
1834
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
2021
    def acquire_repository(self, make_working_trees=None, shared=False,
 
2022
            possible_transports=None):
1835
2023
        """Acquire a repository for this bzrdir.
1836
2024
 
1837
2025
        Implementations may create a new repository or use a pre-exising
1843
2031
        :return: A repository, is_new_flag (True if the repository was
1844
2032
            created).
1845
2033
        """
1846
 
        raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
 
2034
        raise NotImplementedError(RepositoryAcquisitionPolicy.acquire_repository)
1847
2035
 
1848
2036
 
1849
2037
class CreateRepository(RepositoryAcquisitionPolicy):
1862
2050
                                             require_stacking)
1863
2051
        self._bzrdir = bzrdir
1864
2052
 
1865
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
2053
    def acquire_repository(self, make_working_trees=None, shared=False,
 
2054
            possible_transports=None):
1866
2055
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
1867
2056
 
1868
2057
        Creates the desired repository in the bzrdir we already have.
1869
2058
        """
 
2059
        if possible_transports is None:
 
2060
            possible_transports = []
 
2061
        else:
 
2062
            possible_transports = list(possible_transports)
 
2063
        possible_transports.append(self._bzrdir.root_transport)
1870
2064
        stack_on = self._get_full_stack_on()
1871
2065
        if stack_on:
1872
2066
            format = self._bzrdir._format
1873
2067
            format.require_stacking(stack_on=stack_on,
1874
 
                                    possible_transports=[self._bzrdir.root_transport])
 
2068
                                    possible_transports=possible_transports)
1875
2069
            if not self._require_stacking:
1876
2070
                # We have picked up automatic stacking somewhere.
1877
2071
                note(gettext('Using default stacking branch {0} at {1}').format(
1878
2072
                    self._stack_on, self._stack_on_pwd))
1879
2073
        repository = self._bzrdir.create_repository(shared=shared)
1880
2074
        self._add_fallback(repository,
1881
 
                           possible_transports=[self._bzrdir.transport])
 
2075
                           possible_transports=possible_transports)
1882
2076
        if make_working_trees is not None:
1883
2077
            repository.set_make_working_trees(make_working_trees)
1884
2078
        return repository, True
1900
2094
                                             require_stacking)
1901
2095
        self._repository = repository
1902
2096
 
1903
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
2097
    def acquire_repository(self, make_working_trees=None, shared=False,
 
2098
            possible_transports=None):
1904
2099
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
1905
2100
 
1906
2101
        Returns an existing repository to use.
1907
2102
        """
 
2103
        if possible_transports is None:
 
2104
            possible_transports = []
 
2105
        else:
 
2106
            possible_transports = list(possible_transports)
 
2107
        possible_transports.append(self._repository.bzrdir.transport)
1908
2108
        self._add_fallback(self._repository,
1909
 
                       possible_transports=[self._repository.bzrdir.transport])
 
2109
                       possible_transports=possible_transports)
1910
2110
        return self._repository, False
1911
2111
 
1912
2112
 
1965
2165
    deprecated=True)
1966
2166
register_metadir(controldir.format_registry, 'dirstate',
1967
2167
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
1968
 
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
1969
 
        'above when accessed over the network.',
 
2168
    help='Format using dirstate for working trees. '
 
2169
        'Compatible with bzr 0.8 and '
 
2170
        'above when accessed over the network. Introduced in bzr 0.15.',
1970
2171
    branch_format='bzrlib.branch.BzrBranchFormat5',
1971
2172
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1972
2173
    hidden=True,
1973
2174
    deprecated=True)
1974
2175
register_metadir(controldir.format_registry, 'dirstate-tags',
1975
2176
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
1976
 
    help='New in 0.15: Fast local operations and improved scaling for '
1977
 
        'network operations. Additionally adds support for tags.'
1978
 
        ' Incompatible with bzr < 0.15.',
 
2177
    help='Variant of dirstate with support for tags. '
 
2178
        'Introduced in bzr 0.15.',
1979
2179
    branch_format='bzrlib.branch.BzrBranchFormat6',
1980
2180
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1981
2181
    hidden=True,
1982
2182
    deprecated=True)
1983
2183
register_metadir(controldir.format_registry, 'rich-root',
1984
2184
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
1985
 
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
1986
 
        ' bzr < 1.0.',
 
2185
    help='Variant of dirstate with better handling of tree roots. '
 
2186
        'Introduced in bzr 1.0',
1987
2187
    branch_format='bzrlib.branch.BzrBranchFormat6',
1988
2188
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1989
2189
    hidden=True,
1990
2190
    deprecated=True)
1991
2191
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
1992
2192
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
1993
 
    help='New in 0.15: Fast local operations and improved scaling for '
1994
 
        'network operations. Additionally adds support for versioning nested '
1995
 
        'bzr branches. Incompatible with bzr < 0.15.',
 
2193
    help='Variant of dirstate with support for nested trees. '
 
2194
         'Introduced in 0.15.',
1996
2195
    branch_format='bzrlib.branch.BzrBranchFormat6',
1997
2196
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
1998
2197
    experimental=True,
2000
2199
    )
2001
2200
register_metadir(controldir.format_registry, 'pack-0.92',
2002
2201
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
2003
 
    help='New in 0.92: Pack-based format with data compatible with '
2004
 
        'dirstate-tags format repositories. Interoperates with '
2005
 
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
 
2202
    help='Pack-based format used in 1.x series. Introduced in 0.92. '
 
2203
        'Interoperates with bzr repositories before 0.92 but cannot be '
 
2204
        'read by bzr < 0.92. '
2006
2205
        ,
2007
2206
    branch_format='bzrlib.branch.BzrBranchFormat6',
2008
2207
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2208
    deprecated=True,
2009
2209
    )
2010
2210
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2011
2211
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
2012
 
    help='New in 0.92: Pack-based format with data compatible with '
2013
 
        'dirstate-with-subtree format repositories. Interoperates with '
 
2212
    help='Pack-based format used in 1.x series, with subtree support. '
 
2213
        'Introduced in 0.92. Interoperates with '
2014
2214
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2015
2215
        ,
2016
2216
    branch_format='bzrlib.branch.BzrBranchFormat6',
2017
2217
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2018
2218
    hidden=True,
 
2219
    deprecated=True,
2019
2220
    experimental=True,
2020
2221
    )
2021
2222
register_metadir(controldir.format_registry, 'rich-root-pack',
2022
2223
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
2023
 
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2024
 
         '(needed for bzr-svn and bzr-git).',
 
2224
    help='A variant of pack-0.92 that supports rich-root data '
 
2225
         '(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2025
2226
    branch_format='bzrlib.branch.BzrBranchFormat6',
2026
2227
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2027
2228
    hidden=True,
 
2229
    deprecated=True,
2028
2230
    )
2029
2231
register_metadir(controldir.format_registry, '1.6',
2030
2232
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2034
2236
    branch_format='bzrlib.branch.BzrBranchFormat7',
2035
2237
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2036
2238
    hidden=True,
 
2239
    deprecated=True,
2037
2240
    )
2038
2241
register_metadir(controldir.format_registry, '1.6.1-rich-root',
2039
2242
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
2042
2245
    branch_format='bzrlib.branch.BzrBranchFormat7',
2043
2246
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2044
2247
    hidden=True,
 
2248
    deprecated=True,
2045
2249
    )
2046
2250
register_metadir(controldir.format_registry, '1.9',
2047
2251
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2051
2255
    branch_format='bzrlib.branch.BzrBranchFormat7',
2052
2256
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2053
2257
    hidden=True,
 
2258
    deprecated=True,
2054
2259
    )
2055
2260
register_metadir(controldir.format_registry, '1.9-rich-root',
2056
2261
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2059
2264
    branch_format='bzrlib.branch.BzrBranchFormat7',
2060
2265
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2061
2266
    hidden=True,
 
2267
    deprecated=True,
2062
2268
    )
2063
2269
register_metadir(controldir.format_registry, '1.14',
2064
2270
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2065
2271
    help='A working-tree format that supports content filtering.',
2066
2272
    branch_format='bzrlib.branch.BzrBranchFormat7',
2067
2273
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2274
    hidden=True,
 
2275
    deprecated=True,
2068
2276
    )
2069
2277
register_metadir(controldir.format_registry, '1.14-rich-root',
2070
2278
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2072
2280
         '(needed for bzr-svn and bzr-git).',
2073
2281
    branch_format='bzrlib.branch.BzrBranchFormat7',
2074
2282
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2283
    hidden=True,
 
2284
    deprecated=True,
2075
2285
    )
2076
2286
# The following un-numbered 'development' formats should always just be aliases.
2077
2287
register_metadir(controldir.format_registry, 'development-subtree',
2110
2320
    help='The 2a format with experimental support for colocated branches.\n',
2111
2321
    branch_format='bzrlib.branch.BzrBranchFormat7',
2112
2322
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
2113
 
    experimental=False,
 
2323
    experimental=True,
2114
2324
    bzrdir_format=BzrDirMetaFormat1Colo,
2115
2325
    )
2116
2326
 
2120
2330
# Finally, the current format.
2121
2331
register_metadir(controldir.format_registry, '2a',
2122
2332
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2123
 
    help='First format for bzr 2.0 series.\n'
 
2333
    help='Format for the bzr 2.0 series.\n'
2124
2334
        'Uses group-compress storage.\n'
2125
2335
        'Provides rich roots which are a one-way transition.\n',
2126
2336
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '