/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
import sys
31
31
 
32
 
from ..lazy_import import lazy_import
 
32
from bzrlib.lazy_import import lazy_import
33
33
lazy_import(globals(), """
34
 
import breezy
35
 
from breezy import (
 
34
import bzrlib
 
35
from bzrlib import (
36
36
    branch as _mod_branch,
37
37
    cleanup,
 
38
    errors,
38
39
    fetch,
39
40
    graph,
40
41
    lockable_files,
41
42
    lockdir,
42
43
    osutils,
43
44
    pyutils,
 
45
    remote,
44
46
    repository,
45
47
    revision as _mod_revision,
46
48
    transport as _mod_transport,
47
49
    ui,
48
50
    urlutils,
 
51
    vf_search,
49
52
    win32utils,
50
 
    )
51
 
from breezy.bzr import (
52
 
    branch as _mod_bzrbranch,
53
 
    remote,
54
 
    vf_search,
55
53
    workingtree_3,
56
54
    workingtree_4,
57
55
    )
58
 
from breezy.bzr import fullhistory as fullhistorybranch
59
 
from breezy.bzr import knitpack_repo
60
 
from breezy.transport import (
 
56
from bzrlib.branchfmt import fullhistory as fullhistorybranch
 
57
from bzrlib.repofmt import knitpack_repo
 
58
from bzrlib.transport import (
61
59
    do_catching_redirections,
62
60
    local,
63
61
    )
64
 
from breezy.i18n import gettext
 
62
from bzrlib.i18n import gettext
65
63
""")
66
64
 
67
 
from ..trace import (
 
65
from bzrlib.trace import (
68
66
    mutter,
69
67
    note,
70
68
    )
71
69
 
72
 
from .. import (
 
70
from bzrlib import (
73
71
    config,
74
72
    controldir,
75
 
    errors,
76
73
    registry,
77
74
    )
78
 
 
79
 
 
80
 
class MissingFeature(errors.BzrError):
81
 
 
82
 
    _fmt = ("Missing feature %(feature)s not provided by this "
83
 
            "version of Bazaar or any plugin.")
84
 
 
85
 
    def __init__(self, feature):
86
 
        self.feature = feature
87
 
 
88
 
 
89
 
class FeatureAlreadyRegistered(errors.BzrError):
90
 
 
91
 
    _fmt = 'The feature %(feature)s has already been registered.'
92
 
 
93
 
    def __init__(self, feature):
94
 
        self.feature = feature
 
75
from bzrlib.symbol_versioning import (
 
76
    deprecated_in,
 
77
    deprecated_method,
 
78
    )
95
79
 
96
80
 
97
81
class BzrDir(controldir.ControlDir):
186
170
            if preserve_stacking:
187
171
                try:
188
172
                    stacked_on = local_branch.get_stacked_on_url()
189
 
                except (_mod_branch.UnstackableBranchFormat,
 
173
                except (errors.UnstackableBranchFormat,
190
174
                        errors.UnstackableRepositoryFormat,
191
175
                        errors.NotStacked):
192
176
                    pass
305
289
                    return policy
306
290
            else:
307
291
                try:
308
 
                    return UseExistingRepository(
309
 
                            self.open_repository(), stack_on, stack_on_pwd,
310
 
                            require_stacking=require_stacking)
 
292
                    return UseExistingRepository(self.open_repository(),
 
293
                        stack_on, stack_on_pwd,
 
294
                        require_stacking=require_stacking)
311
295
                except errors.NoRepositoryPresent:
312
296
                    pass
313
297
        return CreateRepository(self, stack_on, stack_on_pwd,
348
332
    def sprout(self, url, revision_id=None, force_new_repo=False,
349
333
               recurse='down', possible_transports=None,
350
334
               accelerator_tree=None, hardlink=False, stacked=False,
351
 
               source_branch=None, create_tree_if_local=True,
352
 
               lossy=False):
 
335
               source_branch=None, create_tree_if_local=True):
353
336
        """Create a copy of this controldir prepared for use as a new line of
354
337
        development.
355
338
 
386
369
    def _sprout(self, op, url, revision_id=None, force_new_repo=False,
387
370
               recurse='down', possible_transports=None,
388
371
               accelerator_tree=None, hardlink=False, stacked=False,
389
 
               source_branch=None, create_tree_if_local=True, lossy=False):
 
372
               source_branch=None, create_tree_if_local=True):
390
373
        add_cleanup = op.add_cleanup
391
374
        fetch_spec_factory = fetch.FetchSpecFactory()
392
375
        if revision_id is not None:
452
435
                hardlink=hardlink, from_branch=result_branch)
453
436
            wt.lock_write()
454
437
            try:
455
 
                if not wt.is_versioned(''):
 
438
                if wt.path2id('') is None:
456
439
                    try:
457
440
                        wt.set_root_id(self.open_workingtree.get_root_id())
458
441
                    except errors.NoWorkingTree:
476
459
                subtrees = []
477
460
            for path, file_id in subtrees:
478
461
                target = urlutils.join(url, urlutils.escape(path))
479
 
                sublocation = source_branch.reference_parent(path, file_id)
480
 
                sublocation.controldir.sprout(target,
481
 
                    basis.get_reference_revision(path, file_id),
 
462
                sublocation = source_branch.reference_parent(file_id, path)
 
463
                sublocation.bzrdir.sprout(target,
 
464
                    basis.get_reference_revision(file_id, path),
482
465
                    force_new_repo=force_new_repo, recurse=recurse,
483
466
                    stacked=stacked)
484
467
        return result
486
469
    def _available_backup_name(self, base):
487
470
        """Find a non-existing backup file name based on base.
488
471
 
489
 
        See breezy.osutils.available_backup_name about race conditions.
 
472
        See bzrlib.osutils.available_backup_name about race conditions.
490
473
        """
491
474
        return osutils.available_backup_name(base, self.root_transport.has)
492
475
 
496
479
        :return: Tuple with old path name and new path name
497
480
        """
498
481
 
499
 
        with ui.ui_factory.nested_progress_bar() as pb:
 
482
        pb = ui.ui_factory.nested_progress_bar()
 
483
        try:
500
484
            old_path = self.root_transport.abspath('.bzr')
501
485
            backup_dir = self._available_backup_name('backup.bzr')
502
486
            new_path = self.root_transport.abspath(backup_dir)
505
489
                urlutils.unescape_for_display(new_path, 'utf-8')))
506
490
            self.root_transport.copy_tree('.bzr', backup_dir)
507
491
            return (old_path, new_path)
 
492
        finally:
 
493
            pb.finished()
508
494
 
509
495
    def retire_bzrdir(self, limit=10000):
510
496
        """Permanently disable the bzrdir.
606
592
            # directories and files are read-write for this user. This is
607
593
            # mostly a workaround for filesystems which lie about being able to
608
594
            # write to a directory (cygwin & win32)
609
 
            if (st.st_mode & 0o7777 == 00000):
 
595
            if (st.st_mode & 07777 == 00000):
610
596
                # FTP allows stat but does not return dir/file modes
611
597
                self._dir_mode = None
612
598
                self._file_mode = None
613
599
            else:
614
 
                self._dir_mode = (st.st_mode & 0o7777) | 0o0700
 
600
                self._dir_mode = (st.st_mode & 07777) | 00700
615
601
                # Remove the sticky and execute bits for files
616
 
                self._file_mode = self._dir_mode & ~0o7111
 
602
                self._file_mode = self._dir_mode & ~07111
617
603
 
618
604
    def _get_file_mode(self):
619
605
        """Return Unix mode for newly created files, or None.
735
721
                return format
736
722
            # We have a repository, so set a working tree? (Why? This seems to
737
723
            # contradict the stated return value in the docstring).
738
 
            tree_format = repository._format._matchingcontroldir.workingtree_format
 
724
            tree_format = repository._format._matchingbzrdir.workingtree_format
739
725
            format.workingtree_format = tree_format.__class__()
740
726
        if require_stacking:
741
727
            format.require_stacking()
848
834
        ret = []
849
835
        try:
850
836
            for name in f:
851
 
                ret.append(name.rstrip(b"\n"))
 
837
                ret.append(name.rstrip("\n"))
852
838
        finally:
853
839
            f.close()
854
840
        return ret
900
886
            self.transport.delete_tree(path)
901
887
        except errors.NoSuchFile:
902
888
            raise errors.NotBranchError(path=urlutils.join(self.transport.base,
903
 
                path), controldir=self)
 
889
                path), bzrdir=self)
904
890
 
905
891
    def create_repository(self, shared=False):
906
892
        """See BzrDir.create_repository."""
939
925
 
940
926
        This might be a synthetic object for e.g. RemoteBranch and SVN.
941
927
        """
942
 
        from .branch import BranchFormatMetadir
 
928
        from bzrlib.branch import BranchFormatMetadir
943
929
        return BranchFormatMetadir.find_format(self, name=name)
944
930
 
945
931
    def _get_mkdir_mode(self):
950
936
 
951
937
    def get_branch_reference(self, name=None):
952
938
        """See BzrDir.get_branch_reference()."""
953
 
        from .branch import BranchFormatMetadir
 
939
        from bzrlib.branch import BranchFormatMetadir
954
940
        format = BranchFormatMetadir.find_format(self, name=name)
955
941
        return format.get_reference(self, name=name)
956
942
 
957
943
    def set_branch_reference(self, target_branch, name=None):
958
 
        format = _mod_bzrbranch.BranchReferenceFormat()
959
 
        if (self.control_url == target_branch.controldir.control_url and
960
 
            name == target_branch.name):
961
 
            raise controldir.BranchReferenceLoop(target_branch)
 
944
        format = _mod_branch.BranchReferenceFormat()
962
945
        return format.initialize(self, target_branch=target_branch, name=name)
963
946
 
964
947
    def get_branch_transport(self, branch_format, name=None):
1048
1031
        Note: if you're going to open the working tree, you should just go
1049
1032
        ahead and try, and not ask permission first.
1050
1033
        """
1051
 
        from .workingtree import WorkingTreeFormatMetaDir
 
1034
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
1052
1035
        try:
1053
1036
            WorkingTreeFormatMetaDir.find_format_string(self)
1054
1037
        except errors.NoWorkingTree:
1097
1080
 
1098
1081
    def open_repository(self, unsupported=False):
1099
1082
        """See BzrDir.open_repository."""
1100
 
        from .repository import RepositoryFormatMetaDir
 
1083
        from bzrlib.repository import RepositoryFormatMetaDir
1101
1084
        format = RepositoryFormatMetaDir.find_format(self)
1102
1085
        format.check_support_status(unsupported)
1103
1086
        return format.open(self, _found=True)
1105
1088
    def open_workingtree(self, unsupported=False,
1106
1089
            recommend_upgrade=True):
1107
1090
        """See BzrDir.open_workingtree."""
1108
 
        from .workingtree import WorkingTreeFormatMetaDir
 
1091
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
1109
1092
        format = WorkingTreeFormatMetaDir.find_format(self)
1110
1093
        format.check_support_status(unsupported, recommend_upgrade,
1111
1094
            basedir=self.root_transport.base)
1148
1131
 
1149
1132
        :param name: Name of the feature
1150
1133
        """
1151
 
        if b" " in name:
 
1134
        if " " in name:
1152
1135
            raise ValueError("spaces are not allowed in feature names")
1153
1136
        if name in cls._present_features:
1154
 
            raise FeatureAlreadyRegistered(name)
 
1137
            raise errors.FeatureAlreadyRegistered(name)
1155
1138
        cls._present_features.add(name)
1156
1139
 
1157
1140
    @classmethod
1161
1144
 
1162
1145
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1163
1146
            basedir=None):
1164
 
        for name, necessity in self.features.items():
 
1147
        for name, necessity in self.features.iteritems():
1165
1148
            if name in self._present_features:
1166
1149
                continue
1167
 
            if necessity == b"optional":
 
1150
            if necessity == "optional":
1168
1151
                mutter("ignoring optional missing feature %s", name)
1169
1152
                continue
1170
 
            elif necessity == b"required":
1171
 
                raise MissingFeature(name)
 
1153
            elif necessity == "required":
 
1154
                raise errors.MissingFeature(name)
1172
1155
            else:
1173
1156
                mutter("treating unknown necessity as require for %s",
1174
1157
                       name)
1175
 
                raise MissingFeature(name)
 
1158
                raise errors.MissingFeature(name)
1176
1159
 
1177
1160
    @classmethod
1178
1161
    def get_format_string(cls):
1188
1171
        ret = cls()
1189
1172
        for lineno, line in enumerate(lines):
1190
1173
            try:
1191
 
                (necessity, feature) = line.split(b" ", 1)
 
1174
                (necessity, feature) = line.split(" ", 1)
1192
1175
            except ValueError:
1193
1176
                raise errors.ParseFormatError(format=cls, lineno=lineno+2,
1194
1177
                    line=line, text=text)
1199
1182
        """Return the string representation of this format.
1200
1183
        """
1201
1184
        lines = [self.get_format_string()]
1202
 
        lines.extend([(item[1] + b" " + item[0] + b"\n")
1203
 
                      for item in self.features.items()])
1204
 
        return b"".join(lines)
 
1185
        lines.extend([("%s %s\n" % (item[1], item[0])) for item in
 
1186
            self.features.iteritems()])
 
1187
        return "".join(lines)
1205
1188
 
1206
1189
    @classmethod
1207
1190
    def _find_format(klass, registry, kind, format_string):
1208
1191
        try:
1209
 
            first_line = format_string[:format_string.index(b"\n")+1]
 
1192
            first_line = format_string[:format_string.index("\n")+1]
1210
1193
        except ValueError:
1211
1194
            first_line = format_string
1212
1195
        try:
1231
1214
 
1232
1215
        :param updated_flags: Updated feature flags
1233
1216
        """
1234
 
        for name, necessity in updated_flags.items():
 
1217
        for name, necessity in updated_flags.iteritems():
1235
1218
            if necessity is None:
1236
1219
                try:
1237
1220
                    del self.features[name]
1241
1224
                self.features[name] = necessity
1242
1225
 
1243
1226
 
 
1227
class BzrProber(controldir.Prober):
 
1228
    """Prober for formats that use a .bzr/ control directory."""
 
1229
 
 
1230
    formats = registry.FormatRegistry(controldir.network_format_registry)
 
1231
    """The known .bzr formats."""
 
1232
 
 
1233
    @classmethod
 
1234
    def probe_transport(klass, transport):
 
1235
        """Return the .bzrdir style format present in a directory."""
 
1236
        try:
 
1237
            format_string = transport.get_bytes(".bzr/branch-format")
 
1238
        except errors.NoSuchFile:
 
1239
            raise errors.NotBranchError(path=transport.base)
 
1240
        try:
 
1241
            first_line = format_string[:format_string.index("\n")+1]
 
1242
        except ValueError:
 
1243
            first_line = format_string
 
1244
        try:
 
1245
            cls = klass.formats.get(first_line)
 
1246
        except KeyError:
 
1247
            raise errors.UnknownFormatError(format=first_line, kind='bzrdir')
 
1248
        return cls.from_string(format_string)
 
1249
 
 
1250
    @classmethod
 
1251
    def known_formats(cls):
 
1252
        result = set()
 
1253
        for name, format in cls.formats.iteritems():
 
1254
            if callable(format):
 
1255
                format = format()
 
1256
            result.add(format)
 
1257
        return result
 
1258
 
 
1259
 
 
1260
controldir.ControlDirFormat.register_prober(BzrProber)
 
1261
 
 
1262
 
 
1263
class RemoteBzrProber(controldir.Prober):
 
1264
    """Prober for remote servers that provide a Bazaar smart server."""
 
1265
 
 
1266
    @classmethod
 
1267
    def probe_transport(klass, transport):
 
1268
        """Return a RemoteBzrDirFormat object if it looks possible."""
 
1269
        try:
 
1270
            medium = transport.get_smart_medium()
 
1271
        except (NotImplementedError, AttributeError,
 
1272
                errors.TransportNotPossible, errors.NoSmartMedium,
 
1273
                errors.SmartProtocolError):
 
1274
            # no smart server, so not a branch for this format type.
 
1275
            raise errors.NotBranchError(path=transport.base)
 
1276
        else:
 
1277
            # Decline to open it if the server doesn't support our required
 
1278
            # version (3) so that the VFS-based transport will do it.
 
1279
            if medium.should_probe():
 
1280
                try:
 
1281
                    server_version = medium.protocol_version()
 
1282
                except errors.SmartProtocolError:
 
1283
                    # Apparently there's no usable smart server there, even though
 
1284
                    # the medium supports the smart protocol.
 
1285
                    raise errors.NotBranchError(path=transport.base)
 
1286
                if server_version != '2':
 
1287
                    raise errors.NotBranchError(path=transport.base)
 
1288
            from bzrlib.remote import RemoteBzrDirFormat
 
1289
            return RemoteBzrDirFormat()
 
1290
 
 
1291
    @classmethod
 
1292
    def known_formats(cls):
 
1293
        from bzrlib.remote import RemoteBzrDirFormat
 
1294
        return set([RemoteBzrDirFormat()])
 
1295
 
 
1296
 
1244
1297
class BzrDirFormat(BzrFormat, controldir.ControlDirFormat):
1245
1298
    """ControlDirFormat base class for .bzr/ directories.
1246
1299
 
1270
1323
            # Current RPC's only know how to create bzr metadir1 instances, so
1271
1324
            # we still delegate to vfs methods if the requested format is not a
1272
1325
            # metadir1
1273
 
            if not isinstance(self, BzrDirMetaFormat1):
 
1326
            if type(self) != BzrDirMetaFormat1:
1274
1327
                return self._initialize_on_transport_vfs(transport)
1275
 
            from .remote import RemoteBzrDirFormat
 
1328
            from bzrlib.remote import RemoteBzrDirFormat
1276
1329
            remote_format = RemoteBzrDirFormat()
1277
1330
            self._supply_sub_formats_to(remote_format)
1278
1331
            return remote_format.initialize_on_transport(transport)
1316
1369
            except errors.NoSmartMedium:
1317
1370
                pass
1318
1371
            else:
1319
 
                from .remote import RemoteBzrDirFormat
 
1372
                from bzrlib.remote import RemoteBzrDirFormat
1320
1373
                # TODO: lookup the local format from a server hint.
1321
1374
                remote_dir_format = RemoteBzrDirFormat()
1322
1375
                remote_dir_format._network_name = self.network_name()
1398
1451
        del temp_control
1399
1452
        bzrdir_transport = transport.clone('.bzr')
1400
1453
        utf8_files = [('README',
1401
 
                       b"This is a Bazaar control directory.\n"
1402
 
                       b"Do not change any files in this directory.\n"
1403
 
                       b"See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
 
1454
                       "This is a Bazaar control directory.\n"
 
1455
                       "Do not change any files in this directory.\n"
 
1456
                       "See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
1404
1457
                      ('branch-format', self.as_string()),
1405
1458
                      ]
1406
1459
        # NB: no need to escape relative paths that are url safe.
1507
1560
 
1508
1561
    def get_branch_format(self):
1509
1562
        if self._branch_format is None:
1510
 
            from .branch import format_registry as branch_format_registry
 
1563
            from bzrlib.branch import format_registry as branch_format_registry
1511
1564
            self._branch_format = branch_format_registry.get_default()
1512
1565
        return self._branch_format
1513
1566
 
1594
1647
            if target_branch is None:
1595
1648
                if do_upgrade:
1596
1649
                    # TODO: bad monkey, hard-coded formats...
1597
 
                    from .branch import BzrBranchFormat7
 
1650
                    from bzrlib.branch import BzrBranchFormat7
1598
1651
                    new_branch_format = BzrBranchFormat7()
1599
1652
            else:
1600
1653
                new_branch_format = target_branch._format
1611
1664
        """See BzrDirFormat.get_converter()."""
1612
1665
        if format is None:
1613
1666
            format = BzrDirFormat.get_default_format()
1614
 
        if (isinstance(self, BzrDirMetaFormat1) and
1615
 
            isinstance(format, BzrDirMetaFormat1Colo)):
 
1667
        if (type(self) is BzrDirMetaFormat1 and
 
1668
            type(format) is BzrDirMetaFormat1Colo):
1616
1669
            return ConvertMetaToColo(format)
1617
 
        if (isinstance(self, BzrDirMetaFormat1Colo) and
1618
 
            isinstance(format, BzrDirMetaFormat1)):
 
1670
        if (type(self) is BzrDirMetaFormat1Colo and
 
1671
            type(format) is BzrDirMetaFormat1):
1619
1672
            return ConvertMetaToColo(format)
1620
1673
        if not isinstance(self, format.__class__):
1621
1674
            # converting away from metadir is not implemented
1625
1678
    @classmethod
1626
1679
    def get_format_string(cls):
1627
1680
        """See BzrDirFormat.get_format_string()."""
1628
 
        return b"Bazaar-NG meta directory, format 1\n"
 
1681
        return "Bazaar-NG meta directory, format 1\n"
1629
1682
 
1630
1683
    def get_format_description(self):
1631
1684
        """See BzrDirFormat.get_format_description()."""
1644
1697
        """Circular import protection."""
1645
1698
        if self._repository_format:
1646
1699
            return self._repository_format
1647
 
        from .repository import format_registry
 
1700
        from bzrlib.repository import format_registry
1648
1701
        return format_registry.get_default()
1649
1702
 
1650
1703
    def _set_repository_format(self, value):
1675
1728
 
1676
1729
    def __get_workingtree_format(self):
1677
1730
        if self._workingtree_format is None:
1678
 
            from .workingtree import (
 
1731
            from bzrlib.workingtree import (
1679
1732
                format_registry as wt_format_registry,
1680
1733
                )
1681
1734
            self._workingtree_format = wt_format_registry.get_default()
1691
1744
                                  __set_workingtree_format)
1692
1745
 
1693
1746
 
 
1747
# Register bzr formats
 
1748
BzrProber.formats.register(BzrDirMetaFormat1.get_format_string(),
 
1749
    BzrDirMetaFormat1)
 
1750
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
 
1751
 
 
1752
 
1694
1753
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
1695
1754
    """BzrDirMeta1 format with support for colocated branches."""
1696
1755
 
1699
1758
    @classmethod
1700
1759
    def get_format_string(cls):
1701
1760
        """See BzrDirFormat.get_format_string()."""
1702
 
        return b"Bazaar meta directory, format 1 (with colocated branches)\n"
 
1761
        return "Bazaar meta directory, format 1 (with colocated branches)\n"
1703
1762
 
1704
1763
    def get_format_description(self):
1705
1764
        """See BzrDirFormat.get_format_description()."""
1715
1774
        return BzrDirMeta1(transport, format)
1716
1775
 
1717
1776
 
 
1777
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
 
1778
    BzrDirMetaFormat1Colo)
 
1779
 
 
1780
 
1718
1781
class ConvertMetaToMeta(controldir.Converter):
1719
1782
    """Converts the components of metadirs."""
1720
1783
 
1727
1790
 
1728
1791
    def convert(self, to_convert, pb):
1729
1792
        """See Converter.convert()."""
1730
 
        self.controldir = to_convert
 
1793
        self.bzrdir = to_convert
1731
1794
        self.pb = ui.ui_factory.nested_progress_bar()
1732
1795
        self.count = 0
1733
1796
        self.total = 1
1734
1797
        self.step('checking repository format')
1735
1798
        try:
1736
 
            repo = self.controldir.open_repository()
 
1799
            repo = self.bzrdir.open_repository()
1737
1800
        except errors.NoRepositoryPresent:
1738
1801
            pass
1739
1802
        else:
1740
 
            repo_fmt = self.target_format.repository_format
1741
 
            if not isinstance(repo._format, repo_fmt.__class__):
1742
 
                from ..repository import CopyConverter
 
1803
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
 
1804
                from bzrlib.repository import CopyConverter
1743
1805
                ui.ui_factory.note(gettext('starting repository conversion'))
1744
 
                if not repo_fmt.supports_overriding_transport:
1745
 
                    raise AssertionError(
1746
 
                            "Repository in metadir does not support "
1747
 
                            "overriding transport")
1748
1806
                converter = CopyConverter(self.target_format.repository_format)
1749
1807
                converter.convert(repo, pb)
1750
 
        for branch in self.controldir.list_branches():
 
1808
        for branch in self.bzrdir.list_branches():
1751
1809
            # TODO: conversions of Branch and Tree should be done by
1752
1810
            # InterXFormat lookups/some sort of registry.
1753
1811
            # Avoid circular imports
1755
1813
            new = self.target_format.get_branch_format().__class__
1756
1814
            while old != new:
1757
1815
                if (old == fullhistorybranch.BzrBranchFormat5 and
1758
 
                    new in (_mod_bzrbranch.BzrBranchFormat6,
1759
 
                        _mod_bzrbranch.BzrBranchFormat7,
1760
 
                        _mod_bzrbranch.BzrBranchFormat8)):
1761
 
                    branch_converter = _mod_bzrbranch.Converter5to6()
1762
 
                elif (old == _mod_bzrbranch.BzrBranchFormat6 and
1763
 
                    new in (_mod_bzrbranch.BzrBranchFormat7,
1764
 
                            _mod_bzrbranch.BzrBranchFormat8)):
1765
 
                    branch_converter = _mod_bzrbranch.Converter6to7()
1766
 
                elif (old == _mod_bzrbranch.BzrBranchFormat7 and
1767
 
                      new is _mod_bzrbranch.BzrBranchFormat8):
1768
 
                    branch_converter = _mod_bzrbranch.Converter7to8()
 
1816
                    new in (_mod_branch.BzrBranchFormat6,
 
1817
                        _mod_branch.BzrBranchFormat7,
 
1818
                        _mod_branch.BzrBranchFormat8)):
 
1819
                    branch_converter = _mod_branch.Converter5to6()
 
1820
                elif (old == _mod_branch.BzrBranchFormat6 and
 
1821
                    new in (_mod_branch.BzrBranchFormat7,
 
1822
                            _mod_branch.BzrBranchFormat8)):
 
1823
                    branch_converter = _mod_branch.Converter6to7()
 
1824
                elif (old == _mod_branch.BzrBranchFormat7 and
 
1825
                      new is _mod_branch.BzrBranchFormat8):
 
1826
                    branch_converter = _mod_branch.Converter7to8()
1769
1827
                else:
1770
1828
                    raise errors.BadConversionTarget("No converter", new,
1771
1829
                        branch._format)
1772
1830
                branch_converter.convert(branch)
1773
 
                branch = self.controldir.open_branch()
 
1831
                branch = self.bzrdir.open_branch()
1774
1832
                old = branch._format.__class__
1775
1833
        try:
1776
 
            tree = self.controldir.open_workingtree(recommend_upgrade=False)
 
1834
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
1777
1835
        except (errors.NoWorkingTree, errors.NotLocalUrl):
1778
1836
            pass
1779
1837
        else:
1833
1891
        return BzrDir.open_from_transport(to_convert.root_transport)
1834
1892
 
1835
1893
 
1836
 
class CreateRepository(controldir.RepositoryAcquisitionPolicy):
 
1894
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
 
1895
 
 
1896
 
 
1897
class RepositoryAcquisitionPolicy(object):
 
1898
    """Abstract base class for repository acquisition policies.
 
1899
 
 
1900
    A repository acquisition policy decides how a BzrDir acquires a repository
 
1901
    for a branch that is being created.  The most basic policy decision is
 
1902
    whether to create a new repository or use an existing one.
 
1903
    """
 
1904
    def __init__(self, stack_on, stack_on_pwd, require_stacking):
 
1905
        """Constructor.
 
1906
 
 
1907
        :param stack_on: A location to stack on
 
1908
        :param stack_on_pwd: If stack_on is relative, the location it is
 
1909
            relative to.
 
1910
        :param require_stacking: If True, it is a failure to not stack.
 
1911
        """
 
1912
        self._stack_on = stack_on
 
1913
        self._stack_on_pwd = stack_on_pwd
 
1914
        self._require_stacking = require_stacking
 
1915
 
 
1916
    def configure_branch(self, branch):
 
1917
        """Apply any configuration data from this policy to the branch.
 
1918
 
 
1919
        Default implementation sets repository stacking.
 
1920
        """
 
1921
        if self._stack_on is None:
 
1922
            return
 
1923
        if self._stack_on_pwd is None:
 
1924
            stack_on = self._stack_on
 
1925
        else:
 
1926
            try:
 
1927
                stack_on = urlutils.rebase_url(self._stack_on,
 
1928
                    self._stack_on_pwd,
 
1929
                    branch.user_url)
 
1930
            except errors.InvalidRebaseURLs:
 
1931
                stack_on = self._get_full_stack_on()
 
1932
        try:
 
1933
            branch.set_stacked_on_url(stack_on)
 
1934
        except (errors.UnstackableBranchFormat,
 
1935
                errors.UnstackableRepositoryFormat):
 
1936
            if self._require_stacking:
 
1937
                raise
 
1938
 
 
1939
    def requires_stacking(self):
 
1940
        """Return True if this policy requires stacking."""
 
1941
        return self._stack_on is not None and self._require_stacking
 
1942
 
 
1943
    def _get_full_stack_on(self):
 
1944
        """Get a fully-qualified URL for the stack_on location."""
 
1945
        if self._stack_on is None:
 
1946
            return None
 
1947
        if self._stack_on_pwd is None:
 
1948
            return self._stack_on
 
1949
        else:
 
1950
            return urlutils.join(self._stack_on_pwd, self._stack_on)
 
1951
 
 
1952
    def _add_fallback(self, repository, possible_transports=None):
 
1953
        """Add a fallback to the supplied repository, if stacking is set."""
 
1954
        stack_on = self._get_full_stack_on()
 
1955
        if stack_on is None:
 
1956
            return
 
1957
        try:
 
1958
            stacked_dir = BzrDir.open(stack_on,
 
1959
                                      possible_transports=possible_transports)
 
1960
        except errors.JailBreak:
 
1961
            # We keep the stacking details, but we are in the server code so
 
1962
            # actually stacking is not needed.
 
1963
            return
 
1964
        try:
 
1965
            stacked_repo = stacked_dir.open_branch().repository
 
1966
        except errors.NotBranchError:
 
1967
            stacked_repo = stacked_dir.open_repository()
 
1968
        try:
 
1969
            repository.add_fallback_repository(stacked_repo)
 
1970
        except errors.UnstackableRepositoryFormat:
 
1971
            if self._require_stacking:
 
1972
                raise
 
1973
        else:
 
1974
            self._require_stacking = True
 
1975
 
 
1976
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1977
            possible_transports=None):
 
1978
        """Acquire a repository for this bzrdir.
 
1979
 
 
1980
        Implementations may create a new repository or use a pre-exising
 
1981
        repository.
 
1982
 
 
1983
        :param make_working_trees: If creating a repository, set
 
1984
            make_working_trees to this value (if non-None)
 
1985
        :param shared: If creating a repository, make it shared if True
 
1986
        :return: A repository, is_new_flag (True if the repository was
 
1987
            created).
 
1988
        """
 
1989
        raise NotImplementedError(RepositoryAcquisitionPolicy.acquire_repository)
 
1990
 
 
1991
 
 
1992
class CreateRepository(RepositoryAcquisitionPolicy):
1837
1993
    """A policy of creating a new repository"""
1838
1994
 
1839
 
    def __init__(self, controldir, stack_on=None, stack_on_pwd=None,
 
1995
    def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
1840
1996
                 require_stacking=False):
1841
1997
        """Constructor.
1842
1998
 
1843
 
        :param controldir: The controldir to create the repository on.
 
1999
        :param bzrdir: The bzrdir to create the repository on.
1844
2000
        :param stack_on: A location to stack on
1845
2001
        :param stack_on_pwd: If stack_on is relative, the location it is
1846
2002
            relative to.
1847
2003
        """
1848
 
        super(CreateRepository, self).__init__(
1849
 
                stack_on, stack_on_pwd, require_stacking)
1850
 
        self._controldir = controldir
 
2004
        RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
 
2005
                                             require_stacking)
 
2006
        self._bzrdir = bzrdir
1851
2007
 
1852
2008
    def acquire_repository(self, make_working_trees=None, shared=False,
1853
2009
            possible_transports=None):
1854
2010
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
1855
2011
 
1856
 
        Creates the desired repository in the controldir we already have.
 
2012
        Creates the desired repository in the bzrdir we already have.
1857
2013
        """
1858
2014
        if possible_transports is None:
1859
2015
            possible_transports = []
1860
2016
        else:
1861
2017
            possible_transports = list(possible_transports)
1862
 
        possible_transports.append(self._controldir.root_transport)
 
2018
        possible_transports.append(self._bzrdir.root_transport)
1863
2019
        stack_on = self._get_full_stack_on()
1864
2020
        if stack_on:
1865
 
            format = self._controldir._format
 
2021
            format = self._bzrdir._format
1866
2022
            format.require_stacking(stack_on=stack_on,
1867
2023
                                    possible_transports=possible_transports)
1868
2024
            if not self._require_stacking:
1869
2025
                # We have picked up automatic stacking somewhere.
1870
2026
                note(gettext('Using default stacking branch {0} at {1}').format(
1871
2027
                    self._stack_on, self._stack_on_pwd))
1872
 
        repository = self._controldir.create_repository(shared=shared)
 
2028
        repository = self._bzrdir.create_repository(shared=shared)
1873
2029
        self._add_fallback(repository,
1874
2030
                           possible_transports=possible_transports)
1875
2031
        if make_working_trees is not None:
1877
2033
        return repository, True
1878
2034
 
1879
2035
 
1880
 
class UseExistingRepository(controldir.RepositoryAcquisitionPolicy):
 
2036
class UseExistingRepository(RepositoryAcquisitionPolicy):
1881
2037
    """A policy of reusing an existing repository"""
1882
2038
 
1883
2039
    def __init__(self, repository, stack_on=None, stack_on_pwd=None,
1889
2045
        :param stack_on_pwd: If stack_on is relative, the location it is
1890
2046
            relative to.
1891
2047
        """
1892
 
        super(UseExistingRepository, self).__init__(
1893
 
                stack_on, stack_on_pwd, require_stacking)
 
2048
        RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
 
2049
                                             require_stacking)
1894
2050
        self._repository = repository
1895
2051
 
1896
2052
    def acquire_repository(self, make_working_trees=None, shared=False,
1903
2059
            possible_transports = []
1904
2060
        else:
1905
2061
            possible_transports = list(possible_transports)
1906
 
        possible_transports.append(self._repository.controldir.transport)
 
2062
        possible_transports.append(self._repository.bzrdir.transport)
1907
2063
        self._add_fallback(self._repository,
1908
2064
                       possible_transports=possible_transports)
1909
2065
        return self._repository, False
1910
2066
 
1911
2067
 
1912
 
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
 
2068
def register_metadir(registry, key,
 
2069
         repository_format, help, native=True, deprecated=False,
 
2070
         branch_format=None,
 
2071
         tree_format=None,
 
2072
         hidden=False,
 
2073
         experimental=False,
 
2074
         alias=False, bzrdir_format=None):
 
2075
    """Register a metadir subformat.
 
2076
 
 
2077
    These all use a meta bzrdir, but can be parameterized by the
 
2078
    Repository/Branch/WorkingTreeformats.
 
2079
 
 
2080
    :param repository_format: The fully-qualified repository format class
 
2081
        name as a string.
 
2082
    :param branch_format: Fully-qualified branch format class name as
 
2083
        a string.
 
2084
    :param tree_format: Fully-qualified tree format class name as
 
2085
        a string.
 
2086
    """
 
2087
    if bzrdir_format is None:
 
2088
        bzrdir_format = BzrDirMetaFormat1
 
2089
    # This should be expanded to support setting WorkingTree and Branch
 
2090
    # formats, once the API supports that.
 
2091
    def _load(full_name):
 
2092
        mod_name, factory_name = full_name.rsplit('.', 1)
 
2093
        try:
 
2094
            factory = pyutils.get_named_object(mod_name, factory_name)
 
2095
        except ImportError, e:
 
2096
            raise ImportError('failed to load %s: %s' % (full_name, e))
 
2097
        except AttributeError:
 
2098
            raise AttributeError('no factory %s in module %r'
 
2099
                % (full_name, sys.modules[mod_name]))
 
2100
        return factory()
 
2101
 
 
2102
    def helper():
 
2103
        bd = bzrdir_format()
 
2104
        if branch_format is not None:
 
2105
            bd.set_branch_format(_load(branch_format))
 
2106
        if tree_format is not None:
 
2107
            bd.workingtree_format = _load(tree_format)
 
2108
        if repository_format is not None:
 
2109
            bd.repository_format = _load(repository_format)
 
2110
        return bd
 
2111
    registry.register(key, helper, help, native, deprecated, hidden,
 
2112
        experimental, alias)
 
2113
 
 
2114
register_metadir(controldir.format_registry, 'knit',
 
2115
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
2116
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
 
2117
    branch_format='bzrlib.branchfmt.fullhistory.BzrBranchFormat5',
 
2118
    tree_format='bzrlib.workingtree_3.WorkingTreeFormat3',
 
2119
    hidden=True,
 
2120
    deprecated=True)
 
2121
register_metadir(controldir.format_registry, 'dirstate',
 
2122
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
2123
    help='Format using dirstate for working trees. '
 
2124
        'Compatible with bzr 0.8 and '
 
2125
        'above when accessed over the network. Introduced in bzr 0.15.',
 
2126
    branch_format='bzrlib.branchfmt.fullhistory.BzrBranchFormat5',
 
2127
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2128
    hidden=True,
 
2129
    deprecated=True)
 
2130
register_metadir(controldir.format_registry, 'dirstate-tags',
 
2131
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
2132
    help='Variant of dirstate with support for tags. '
 
2133
        'Introduced in bzr 0.15.',
 
2134
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2135
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2136
    hidden=True,
 
2137
    deprecated=True)
 
2138
register_metadir(controldir.format_registry, 'rich-root',
 
2139
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
 
2140
    help='Variant of dirstate with better handling of tree roots. '
 
2141
        'Introduced in bzr 1.0',
 
2142
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2143
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2144
    hidden=True,
 
2145
    deprecated=True)
 
2146
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
 
2147
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
 
2148
    help='Variant of dirstate with support for nested trees. '
 
2149
         'Introduced in 0.15.',
 
2150
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2151
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2152
    experimental=True,
 
2153
    hidden=True,
 
2154
    )
 
2155
register_metadir(controldir.format_registry, 'pack-0.92',
 
2156
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
 
2157
    help='Pack-based format used in 1.x series. Introduced in 0.92. '
 
2158
        'Interoperates with bzr repositories before 0.92 but cannot be '
 
2159
        'read by bzr < 0.92. '
 
2160
        ,
 
2161
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2162
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2163
    deprecated=True,
 
2164
    )
 
2165
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
 
2166
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
 
2167
    help='Pack-based format used in 1.x series, with subtree support. '
 
2168
        'Introduced in 0.92. Interoperates with '
 
2169
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
 
2170
        ,
 
2171
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2172
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2173
    hidden=True,
 
2174
    deprecated=True,
 
2175
    experimental=True,
 
2176
    )
 
2177
register_metadir(controldir.format_registry, 'rich-root-pack',
 
2178
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
 
2179
    help='A variant of pack-0.92 that supports rich-root data '
 
2180
         '(needed for bzr-svn and bzr-git). Introduced in 1.0.',
 
2181
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2182
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2183
    hidden=True,
 
2184
    deprecated=True,
 
2185
    )
 
2186
register_metadir(controldir.format_registry, '1.6',
 
2187
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
 
2188
    help='A format that allows a branch to indicate that there is another '
 
2189
         '(stacked) repository that should be used to access data that is '
 
2190
         'not present locally.',
 
2191
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2192
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2193
    hidden=True,
 
2194
    deprecated=True,
 
2195
    )
 
2196
register_metadir(controldir.format_registry, '1.6.1-rich-root',
 
2197
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
 
2198
    help='A variant of 1.6 that supports rich-root data '
 
2199
         '(needed for bzr-svn and bzr-git).',
 
2200
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2201
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2202
    hidden=True,
 
2203
    deprecated=True,
 
2204
    )
 
2205
register_metadir(controldir.format_registry, '1.9',
 
2206
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
 
2207
    help='A repository format using B+tree indexes. These indexes '
 
2208
         'are smaller in size, have smarter caching and provide faster '
 
2209
         'performance for most operations.',
 
2210
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2211
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2212
    hidden=True,
 
2213
    deprecated=True,
 
2214
    )
 
2215
register_metadir(controldir.format_registry, '1.9-rich-root',
 
2216
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
 
2217
    help='A variant of 1.9 that supports rich-root data '
 
2218
         '(needed for bzr-svn and bzr-git).',
 
2219
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2220
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2221
    hidden=True,
 
2222
    deprecated=True,
 
2223
    )
 
2224
register_metadir(controldir.format_registry, '1.14',
 
2225
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
 
2226
    help='A working-tree format that supports content filtering.',
 
2227
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2228
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2229
    hidden=True,
 
2230
    deprecated=True,
 
2231
    )
 
2232
register_metadir(controldir.format_registry, '1.14-rich-root',
 
2233
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
 
2234
    help='A variant of 1.14 that supports rich-root data '
 
2235
         '(needed for bzr-svn and bzr-git).',
 
2236
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2237
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2238
    hidden=True,
 
2239
    deprecated=True,
 
2240
    )
 
2241
# The following un-numbered 'development' formats should always just be aliases.
 
2242
register_metadir(controldir.format_registry, 'development-subtree',
 
2243
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
 
2244
    help='Current development format, subtree variant. Can convert data to and '
 
2245
        'from pack-0.92-subtree (and anything compatible with '
 
2246
        'pack-0.92-subtree) format repositories. Repositories and branches in '
 
2247
        'this format can only be read by bzr.dev. Please read '
 
2248
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
2249
        'before use.',
 
2250
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2251
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2252
    experimental=True,
 
2253
    hidden=True,
 
2254
    alias=False, # Restore to being an alias when an actual development subtree format is added
 
2255
                 # This current non-alias status is simply because we did not introduce a
 
2256
                 # chk based subtree format.
 
2257
    )
 
2258
register_metadir(controldir.format_registry, 'development5-subtree',
 
2259
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatPackDevelopment2Subtree',
 
2260
    help='Development format, subtree variant. Can convert data to and '
 
2261
        'from pack-0.92-subtree (and anything compatible with '
 
2262
        'pack-0.92-subtree) format repositories. Repositories and branches in '
 
2263
        'this format can only be read by bzr.dev. Please read '
 
2264
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
2265
        'before use.',
 
2266
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2267
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2268
    experimental=True,
 
2269
    hidden=True,
 
2270
    alias=False,
 
2271
    )
 
2272
 
 
2273
register_metadir(controldir.format_registry, 'development-colo',
 
2274
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
2275
    help='The 2a format with experimental support for colocated branches.\n',
 
2276
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2277
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2278
    experimental=True,
 
2279
    bzrdir_format=BzrDirMetaFormat1Colo,
 
2280
    )
 
2281
 
 
2282
 
 
2283
# And the development formats above will have aliased one of the following:
 
2284
 
 
2285
# Finally, the current format.
 
2286
register_metadir(controldir.format_registry, '2a',
 
2287
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
2288
    help='Format for the bzr 2.0 series.\n'
 
2289
        'Uses group-compress storage.\n'
 
2290
        'Provides rich roots which are a one-way transition.\n',
 
2291
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
 
2292
        # 'rich roots. Supported by bzr 1.16 and later.',
 
2293
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2294
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2295
    experimental=False,
 
2296
    )
 
2297
 
 
2298
# The following format should be an alias for the rich root equivalent 
 
2299
# of the default format
 
2300
register_metadir(controldir.format_registry, 'default-rich-root',
 
2301
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
2302
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2303
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2304
    alias=True,
 
2305
    hidden=True,
 
2306
    help='Same as 2a.')
 
2307
 
 
2308
# The current format that is made on 'bzr init'.
 
2309
format_name = config.GlobalStack().get('default_format')
 
2310
controldir.format_registry.set_default(format_name)
 
2311
 
 
2312
# XXX 2010-08-20 JRV: There is still a lot of code relying on
 
2313
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc
 
2314
# get changed to ControlDir.create/ControlDir.open/etc this should be removed.
 
2315
format_registry = controldir.format_registry