/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: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
objects returned.
26
26
"""
27
27
 
28
 
# TODO: Move old formats into a plugin to make this file smaller.
29
 
 
30
 
import os
31
28
import sys
32
 
import warnings
33
29
 
34
30
from bzrlib.lazy_import import lazy_import
35
31
lazy_import(globals(), """
36
 
from stat import S_ISDIR
37
 
 
38
32
import bzrlib
39
33
from bzrlib import (
40
 
    branch,
41
 
    config,
42
 
    controldir,
 
34
    branch as _mod_branch,
 
35
    cleanup,
43
36
    errors,
 
37
    fetch,
44
38
    graph,
45
39
    lockable_files,
46
40
    lockdir,
52
46
    transport as _mod_transport,
53
47
    ui,
54
48
    urlutils,
55
 
    versionedfile,
56
49
    win32utils,
57
 
    workingtree,
 
50
    workingtree_3,
58
51
    workingtree_4,
59
 
    xml4,
60
 
    xml5,
61
 
    )
62
 
from bzrlib.osutils import (
63
 
    sha_string,
64
 
    )
65
 
from bzrlib.push import (
66
 
    PushResult,
67
 
    )
68
 
from bzrlib.repofmt import pack_repo
69
 
from bzrlib.smart.client import _SmartClient
70
 
from bzrlib.store.versioned import WeaveStore
71
 
from bzrlib.transactions import WriteTransaction
 
52
    )
 
53
from bzrlib.repofmt import knitpack_repo
72
54
from bzrlib.transport import (
73
55
    do_catching_redirections,
74
56
    local,
75
57
    )
76
 
from bzrlib.weave import Weave
77
58
""")
78
59
 
79
60
from bzrlib.trace import (
80
61
    mutter,
81
62
    note,
82
 
    warning,
83
63
    )
84
64
 
85
65
from bzrlib import (
 
66
    config,
 
67
    controldir,
86
68
    hooks,
87
69
    registry,
88
 
    symbol_versioning,
89
70
    )
90
71
from bzrlib.symbol_versioning import (
91
72
    deprecated_in,
142
123
            # No repo, no problem.
143
124
            pass
144
125
 
145
 
    @staticmethod
146
 
    def _check_supported(format, allow_unsupported,
147
 
        recommend_upgrade=True,
148
 
        basedir=None):
149
 
        """Give an error or warning on old formats.
150
 
 
151
 
        :param format: may be any kind of format - workingtree, branch,
152
 
        or repository.
153
 
 
154
 
        :param allow_unsupported: If true, allow opening
155
 
        formats that are strongly deprecated, and which may
156
 
        have limited functionality.
157
 
 
158
 
        :param recommend_upgrade: If true (default), warn
159
 
        the user through the ui object that they may wish
160
 
        to upgrade the object.
161
 
        """
162
 
        # TODO: perhaps move this into a base Format class; it's not BzrDir
163
 
        # specific. mbp 20070323
164
 
        if not allow_unsupported and not format.is_supported():
165
 
            # see open_downlevel to open legacy branches.
166
 
            raise errors.UnsupportedFormatError(format=format)
167
 
        if recommend_upgrade \
168
 
            and getattr(format, 'upgrade_recommended', False):
169
 
            ui.ui_factory.recommend_upgrade(
170
 
                format.get_format_description(),
171
 
                basedir)
172
 
 
173
126
    def clone_on_transport(self, transport, revision_id=None,
174
127
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
175
128
        create_prefix=False, use_existing_dir=True, no_tree=False):
187
140
        :param create_prefix: Create any missing directories leading up to
188
141
            to_transport.
189
142
        :param use_existing_dir: Use an existing directory if one exists.
 
143
        :param no_tree: If set to true prevents creation of a working tree.
190
144
        """
191
145
        # Overview: put together a broad description of what we want to end up
192
146
        # with; then make as few api calls as possible to do it.
285
239
        This is intended primarily as a building block for more sophisticated
286
240
        functionality, like finding trees under a directory, or finding
287
241
        branches that use a given repository.
 
242
 
288
243
        :param evaluate: An optional callable that yields recurse, value,
289
244
            where recurse controls whether this bzrdir is recursed into
290
245
            and value is the value to yield.  By default, all bzrdirs
434
389
        policy = self.determine_repository_policy(force_new_repo)
435
390
        return policy.acquire_repository()[0]
436
391
 
 
392
    def _find_source_repo(self, add_cleanup, source_branch):
 
393
        """Find the source branch and repo for a sprout operation.
 
394
        
 
395
        This is helper intended for use by _sprout.
 
396
 
 
397
        :returns: (source_branch, source_repository).  Either or both may be
 
398
            None.  If not None, they will be read-locked (and their unlock(s)
 
399
            scheduled via the add_cleanup param).
 
400
        """
 
401
        if source_branch is not None:
 
402
            add_cleanup(source_branch.lock_read().unlock)
 
403
            return source_branch, source_branch.repository
 
404
        try:
 
405
            source_branch = self.open_branch()
 
406
            source_repository = source_branch.repository
 
407
        except errors.NotBranchError:
 
408
            source_branch = None
 
409
            try:
 
410
                source_repository = self.open_repository()
 
411
            except errors.NoRepositoryPresent:
 
412
                source_repository = None
 
413
            else:
 
414
                add_cleanup(source_repository.lock_read().unlock)
 
415
        else:
 
416
            add_cleanup(source_branch.lock_read().unlock)
 
417
        return source_branch, source_repository
 
418
 
 
419
    def sprout(self, url, revision_id=None, force_new_repo=False,
 
420
               recurse='down', possible_transports=None,
 
421
               accelerator_tree=None, hardlink=False, stacked=False,
 
422
               source_branch=None, create_tree_if_local=True):
 
423
        """Create a copy of this controldir prepared for use as a new line of
 
424
        development.
 
425
 
 
426
        If url's last component does not exist, it will be created.
 
427
 
 
428
        Attributes related to the identity of the source branch like
 
429
        branch nickname will be cleaned, a working tree is created
 
430
        whether one existed before or not; and a local branch is always
 
431
        created.
 
432
 
 
433
        if revision_id is not None, then the clone operation may tune
 
434
            itself to download less data.
 
435
 
 
436
        :param accelerator_tree: A tree which can be used for retrieving file
 
437
            contents more quickly than the revision tree, i.e. a workingtree.
 
438
            The revision tree will be used for cases where accelerator_tree's
 
439
            content is different.
 
440
        :param hardlink: If true, hard-link files from accelerator_tree,
 
441
            where possible.
 
442
        :param stacked: If true, create a stacked branch referring to the
 
443
            location of this control directory.
 
444
        :param create_tree_if_local: If true, a working-tree will be created
 
445
            when working locally.
 
446
        """
 
447
        operation = cleanup.OperationWithCleanups(self._sprout)
 
448
        return operation.run(url, revision_id=revision_id,
 
449
            force_new_repo=force_new_repo, recurse=recurse,
 
450
            possible_transports=possible_transports,
 
451
            accelerator_tree=accelerator_tree, hardlink=hardlink,
 
452
            stacked=stacked, source_branch=source_branch,
 
453
            create_tree_if_local=create_tree_if_local)
 
454
 
 
455
    def _sprout(self, op, url, revision_id=None, force_new_repo=False,
 
456
               recurse='down', possible_transports=None,
 
457
               accelerator_tree=None, hardlink=False, stacked=False,
 
458
               source_branch=None, create_tree_if_local=True):
 
459
        add_cleanup = op.add_cleanup
 
460
        fetch_spec_factory = fetch.FetchSpecFactory()
 
461
        if revision_id is not None:
 
462
            fetch_spec_factory.add_revision_ids([revision_id])
 
463
            fetch_spec_factory.source_branch_stop_revision_id = revision_id
 
464
        target_transport = _mod_transport.get_transport(url,
 
465
            possible_transports)
 
466
        target_transport.ensure_base()
 
467
        cloning_format = self.cloning_metadir(stacked)
 
468
        # Create/update the result branch
 
469
        result = cloning_format.initialize_on_transport(target_transport)
 
470
        source_branch, source_repository = self._find_source_repo(
 
471
            add_cleanup, source_branch)
 
472
        fetch_spec_factory.source_branch = source_branch
 
473
        # if a stacked branch wasn't requested, we don't create one
 
474
        # even if the origin was stacked
 
475
        if stacked and source_branch is not None:
 
476
            stacked_branch_url = self.root_transport.base
 
477
        else:
 
478
            stacked_branch_url = None
 
479
        repository_policy = result.determine_repository_policy(
 
480
            force_new_repo, stacked_branch_url, require_stacking=stacked)
 
481
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
482
        add_cleanup(result_repo.lock_write().unlock)
 
483
        fetch_spec_factory.source_repo = source_repository
 
484
        fetch_spec_factory.target_repo = result_repo
 
485
        if stacked or (len(result_repo._fallback_repositories) != 0):
 
486
            target_repo_kind = fetch.TargetRepoKinds.STACKED
 
487
        elif is_new_repo:
 
488
            target_repo_kind = fetch.TargetRepoKinds.EMPTY
 
489
        else:
 
490
            target_repo_kind = fetch.TargetRepoKinds.PREEXISTING
 
491
        fetch_spec_factory.target_repo_kind = target_repo_kind
 
492
        if source_repository is not None:
 
493
            fetch_spec = fetch_spec_factory.make_fetch_spec()
 
494
            result_repo.fetch(source_repository, fetch_spec=fetch_spec)
 
495
 
 
496
        if source_branch is None:
 
497
            # this is for sprouting a controldir without a branch; is that
 
498
            # actually useful?
 
499
            # Not especially, but it's part of the contract.
 
500
            result_branch = result.create_branch()
 
501
        else:
 
502
            result_branch = source_branch.sprout(result,
 
503
                revision_id=revision_id, repository_policy=repository_policy,
 
504
                repository=result_repo)
 
505
        mutter("created new branch %r" % (result_branch,))
 
506
 
 
507
        # Create/update the result working tree
 
508
        if (create_tree_if_local and
 
509
            isinstance(target_transport, local.LocalTransport) and
 
510
            (result_repo is None or result_repo.make_working_trees())):
 
511
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
 
512
                hardlink=hardlink, from_branch=result_branch)
 
513
            wt.lock_write()
 
514
            try:
 
515
                if wt.path2id('') is None:
 
516
                    try:
 
517
                        wt.set_root_id(self.open_workingtree.get_root_id())
 
518
                    except errors.NoWorkingTree:
 
519
                        pass
 
520
            finally:
 
521
                wt.unlock()
 
522
        else:
 
523
            wt = None
 
524
        if recurse == 'down':
 
525
            basis = None
 
526
            if wt is not None:
 
527
                basis = wt.basis_tree()
 
528
            elif result_branch is not None:
 
529
                basis = result_branch.basis_tree()
 
530
            elif source_branch is not None:
 
531
                basis = source_branch.basis_tree()
 
532
            if basis is not None:
 
533
                add_cleanup(basis.lock_read().unlock)
 
534
                subtrees = basis.iter_references()
 
535
            else:
 
536
                subtrees = []
 
537
            for path, file_id in subtrees:
 
538
                target = urlutils.join(url, urlutils.escape(path))
 
539
                sublocation = source_branch.reference_parent(file_id, path)
 
540
                sublocation.bzrdir.sprout(target,
 
541
                    basis.get_reference_revision(file_id, path),
 
542
                    force_new_repo=force_new_repo, recurse=recurse,
 
543
                    stacked=stacked)
 
544
        return result
 
545
 
 
546
 
 
547
 
437
548
    @staticmethod
438
549
    def create_branch_convenience(base, force_new_repo=False,
439
550
                                  force_new_tree=None, format=None,
748
859
        except errors.TooManyRedirections:
749
860
            raise errors.NotBranchError(base)
750
861
 
751
 
        BzrDir._check_supported(format, _unsupported)
 
862
        format.check_support_status(_unsupported)
752
863
        return format.open(transport, _found=True)
753
864
 
754
865
    @staticmethod
756
867
        """Open an existing branch which contains url.
757
868
 
758
869
        :param url: url to search from.
 
870
 
759
871
        See open_containing_from_transport for more detail.
760
872
        """
761
873
        transport = _mod_transport.get_transport(url, possible_transports)
926
1038
            format = controldir.ControlDirFormat.get_default_format()
927
1039
        return format.initialize_on_transport(t)
928
1040
 
 
1041
    def get_branch_transport(self, branch_format, name=None):
 
1042
        """Get the transport for use by branch format in this BzrDir.
 
1043
 
 
1044
        Note that bzr dirs that do not support format strings will raise
 
1045
        IncompatibleFormat if the branch format they are given has
 
1046
        a format string, and vice versa.
 
1047
 
 
1048
        If branch_format is None, the transport is returned with no
 
1049
        checking. If it is not None, then the returned transport is
 
1050
        guaranteed to point to an existing directory ready for use.
 
1051
        """
 
1052
        raise NotImplementedError(self.get_branch_transport)
 
1053
 
 
1054
    def get_repository_transport(self, repository_format):
 
1055
        """Get the transport for use by repository format in this BzrDir.
 
1056
 
 
1057
        Note that bzr dirs that do not support format strings will raise
 
1058
        IncompatibleFormat if the repository format they are given has
 
1059
        a format string, and vice versa.
 
1060
 
 
1061
        If repository_format is None, the transport is returned with no
 
1062
        checking. If it is not None, then the returned transport is
 
1063
        guaranteed to point to an existing directory ready for use.
 
1064
        """
 
1065
        raise NotImplementedError(self.get_repository_transport)
 
1066
 
 
1067
    def get_workingtree_transport(self, tree_format):
 
1068
        """Get the transport for use by workingtree format in this BzrDir.
 
1069
 
 
1070
        Note that bzr dirs that do not support format strings will raise
 
1071
        IncompatibleFormat if the workingtree format they are given has a
 
1072
        format string, and vice versa.
 
1073
 
 
1074
        If workingtree_format is None, the transport is returned with no
 
1075
        checking. If it is not None, then the returned transport is
 
1076
        guaranteed to point to an existing directory ready for use.
 
1077
        """
 
1078
        raise NotImplementedError(self.get_workingtree_transport)
 
1079
 
929
1080
 
930
1081
class BzrDirHooks(hooks.Hooks):
931
1082
    """Hooks for BzrDir operations."""
932
1083
 
933
1084
    def __init__(self):
934
1085
        """Create the default hooks."""
935
 
        hooks.Hooks.__init__(self)
936
 
        self.create_hook(hooks.HookPoint('pre_open',
 
1086
        hooks.Hooks.__init__(self, "bzrlib.bzrdir", "BzrDir.hooks")
 
1087
        self.add_hook('pre_open',
937
1088
            "Invoked before attempting to open a BzrDir with the transport "
938
 
            "that the open will use.", (1, 14), None))
939
 
        self.create_hook(hooks.HookPoint('post_repo_init',
 
1089
            "that the open will use.", (1, 14))
 
1090
        self.add_hook('post_repo_init',
940
1091
            "Invoked after a repository has been initialized. "
941
1092
            "post_repo_init is called with a "
942
1093
            "bzrlib.bzrdir.RepoInitHookParams.",
943
 
            (2, 2), None))
 
1094
            (2, 2))
944
1095
 
945
1096
# install the default hooks
946
1097
BzrDir.hooks = BzrDirHooks()
947
1098
 
948
1099
 
949
1100
class RepoInitHookParams(object):
950
 
    """Object holding parameters passed to *_repo_init hooks.
 
1101
    """Object holding parameters passed to `*_repo_init` hooks.
951
1102
 
952
1103
    There are 4 fields that hooks may wish to access:
953
1104
 
982
1133
                self.bzrdir)
983
1134
 
984
1135
 
985
 
class BzrDirPreSplitOut(BzrDir):
986
 
    """A common class for the all-in-one formats."""
987
 
 
988
 
    def __init__(self, _transport, _format):
989
 
        """See BzrDir.__init__."""
990
 
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
991
 
        self._control_files = lockable_files.LockableFiles(
992
 
                                            self.get_branch_transport(None),
993
 
                                            self._format._lock_file_name,
994
 
                                            self._format._lock_class)
995
 
 
996
 
    def break_lock(self):
997
 
        """Pre-splitout bzrdirs do not suffer from stale locks."""
998
 
        raise NotImplementedError(self.break_lock)
999
 
 
1000
 
    def cloning_metadir(self, require_stacking=False):
1001
 
        """Produce a metadir suitable for cloning with."""
1002
 
        if require_stacking:
1003
 
            return controldir.format_registry.make_bzrdir('1.6')
1004
 
        return self._format.__class__()
1005
 
 
1006
 
    def clone(self, url, revision_id=None, force_new_repo=False,
1007
 
              preserve_stacking=False):
1008
 
        """See BzrDir.clone().
1009
 
 
1010
 
        force_new_repo has no effect, since this family of formats always
1011
 
        require a new repository.
1012
 
        preserve_stacking has no effect, since no source branch using this
1013
 
        family of formats can be stacked, so there is no stacking to preserve.
1014
 
        """
1015
 
        self._make_tail(url)
1016
 
        result = self._format._initialize_for_clone(url)
1017
 
        self.open_repository().clone(result, revision_id=revision_id)
1018
 
        from_branch = self.open_branch()
1019
 
        from_branch.clone(result, revision_id=revision_id)
1020
 
        try:
1021
 
            tree = self.open_workingtree()
1022
 
        except errors.NotLocalUrl:
1023
 
            # make a new one, this format always has to have one.
1024
 
            result._init_workingtree()
1025
 
        else:
1026
 
            tree.clone(result)
1027
 
        return result
1028
 
 
1029
 
    def create_branch(self, name=None, repository=None):
1030
 
        """See BzrDir.create_branch."""
1031
 
        if repository is not None:
1032
 
            raise NotImplementedError(
1033
 
                "create_branch(repository=<not None>) on %r" % (self,))
1034
 
        return self._format.get_branch_format().initialize(self, name=name)
1035
 
 
1036
 
    def destroy_branch(self, name=None):
1037
 
        """See BzrDir.destroy_branch."""
1038
 
        raise errors.UnsupportedOperation(self.destroy_branch, self)
1039
 
 
1040
 
    def create_repository(self, shared=False):
1041
 
        """See BzrDir.create_repository."""
1042
 
        if shared:
1043
 
            raise errors.IncompatibleFormat('shared repository', self._format)
1044
 
        return self.open_repository()
1045
 
 
1046
 
    def destroy_repository(self):
1047
 
        """See BzrDir.destroy_repository."""
1048
 
        raise errors.UnsupportedOperation(self.destroy_repository, self)
1049
 
 
1050
 
    def create_workingtree(self, revision_id=None, from_branch=None,
1051
 
                           accelerator_tree=None, hardlink=False):
1052
 
        """See BzrDir.create_workingtree."""
1053
 
        # The workingtree is sometimes created when the bzrdir is created,
1054
 
        # but not when cloning.
1055
 
 
1056
 
        # this looks buggy but is not -really-
1057
 
        # because this format creates the workingtree when the bzrdir is
1058
 
        # created
1059
 
        # clone and sprout will have set the revision_id
1060
 
        # and that will have set it for us, its only
1061
 
        # specific uses of create_workingtree in isolation
1062
 
        # that can do wonky stuff here, and that only
1063
 
        # happens for creating checkouts, which cannot be
1064
 
        # done on this format anyway. So - acceptable wart.
1065
 
        if hardlink:
1066
 
            warning("can't support hardlinked working trees in %r"
1067
 
                % (self,))
1068
 
        try:
1069
 
            result = self.open_workingtree(recommend_upgrade=False)
1070
 
        except errors.NoSuchFile:
1071
 
            result = self._init_workingtree()
1072
 
        if revision_id is not None:
1073
 
            if revision_id == _mod_revision.NULL_REVISION:
1074
 
                result.set_parent_ids([])
1075
 
            else:
1076
 
                result.set_parent_ids([revision_id])
1077
 
        return result
1078
 
 
1079
 
    def _init_workingtree(self):
1080
 
        from bzrlib.workingtree import WorkingTreeFormat2
1081
 
        try:
1082
 
            return WorkingTreeFormat2().initialize(self)
1083
 
        except errors.NotLocalUrl:
1084
 
            # Even though we can't access the working tree, we need to
1085
 
            # create its control files.
1086
 
            return WorkingTreeFormat2()._stub_initialize_on_transport(
1087
 
                self.transport, self._control_files._file_mode)
1088
 
 
1089
 
    def destroy_workingtree(self):
1090
 
        """See BzrDir.destroy_workingtree."""
1091
 
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1092
 
 
1093
 
    def destroy_workingtree_metadata(self):
1094
 
        """See BzrDir.destroy_workingtree_metadata."""
1095
 
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1096
 
                                          self)
1097
 
 
1098
 
    def get_branch_transport(self, branch_format, name=None):
1099
 
        """See BzrDir.get_branch_transport()."""
1100
 
        if name is not None:
1101
 
            raise errors.NoColocatedBranchSupport(self)
1102
 
        if branch_format is None:
1103
 
            return self.transport
1104
 
        try:
1105
 
            branch_format.get_format_string()
1106
 
        except NotImplementedError:
1107
 
            return self.transport
1108
 
        raise errors.IncompatibleFormat(branch_format, self._format)
1109
 
 
1110
 
    def get_repository_transport(self, repository_format):
1111
 
        """See BzrDir.get_repository_transport()."""
1112
 
        if repository_format is None:
1113
 
            return self.transport
1114
 
        try:
1115
 
            repository_format.get_format_string()
1116
 
        except NotImplementedError:
1117
 
            return self.transport
1118
 
        raise errors.IncompatibleFormat(repository_format, self._format)
1119
 
 
1120
 
    def get_workingtree_transport(self, workingtree_format):
1121
 
        """See BzrDir.get_workingtree_transport()."""
1122
 
        if workingtree_format is None:
1123
 
            return self.transport
1124
 
        try:
1125
 
            workingtree_format.get_format_string()
1126
 
        except NotImplementedError:
1127
 
            return self.transport
1128
 
        raise errors.IncompatibleFormat(workingtree_format, self._format)
1129
 
 
1130
 
    def needs_format_conversion(self, format=None):
1131
 
        """See BzrDir.needs_format_conversion()."""
1132
 
        # if the format is not the same as the system default,
1133
 
        # an upgrade is needed.
1134
 
        if format is None:
1135
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1136
 
                % 'needs_format_conversion(format=None)')
1137
 
            format = BzrDirFormat.get_default_format()
1138
 
        return not isinstance(self._format, format.__class__)
1139
 
 
1140
 
    def open_branch(self, name=None, unsupported=False,
1141
 
                    ignore_fallbacks=False):
1142
 
        """See BzrDir.open_branch."""
1143
 
        from bzrlib.branch import BzrBranchFormat4
1144
 
        format = BzrBranchFormat4()
1145
 
        self._check_supported(format, unsupported)
1146
 
        return format.open(self, name, _found=True)
1147
 
 
1148
 
    def sprout(self, url, revision_id=None, force_new_repo=False,
1149
 
               possible_transports=None, accelerator_tree=None,
1150
 
               hardlink=False, stacked=False, create_tree_if_local=True,
1151
 
               source_branch=None):
1152
 
        """See BzrDir.sprout()."""
1153
 
        if source_branch is not None:
1154
 
            my_branch = self.open_branch()
1155
 
            if source_branch.base != my_branch.base:
1156
 
                raise AssertionError(
1157
 
                    "source branch %r is not within %r with branch %r" %
1158
 
                    (source_branch, self, my_branch))
1159
 
        if stacked:
1160
 
            raise errors.UnstackableBranchFormat(
1161
 
                self._format, self.root_transport.base)
1162
 
        if not create_tree_if_local:
1163
 
            raise errors.MustHaveWorkingTree(
1164
 
                self._format, self.root_transport.base)
1165
 
        from bzrlib.workingtree import WorkingTreeFormat2
1166
 
        self._make_tail(url)
1167
 
        result = self._format._initialize_for_clone(url)
1168
 
        try:
1169
 
            self.open_repository().clone(result, revision_id=revision_id)
1170
 
        except errors.NoRepositoryPresent:
1171
 
            pass
1172
 
        try:
1173
 
            self.open_branch().sprout(result, revision_id=revision_id)
1174
 
        except errors.NotBranchError:
1175
 
            pass
1176
 
 
1177
 
        # we always want a working tree
1178
 
        WorkingTreeFormat2().initialize(result,
1179
 
                                        accelerator_tree=accelerator_tree,
1180
 
                                        hardlink=hardlink)
1181
 
        return result
1182
 
 
1183
 
 
1184
 
class BzrDir4(BzrDirPreSplitOut):
1185
 
    """A .bzr version 4 control object.
1186
 
 
1187
 
    This is a deprecated format and may be removed after sept 2006.
1188
 
    """
1189
 
 
1190
 
    def create_repository(self, shared=False):
1191
 
        """See BzrDir.create_repository."""
1192
 
        return self._format.repository_format.initialize(self, shared)
1193
 
 
1194
 
    def needs_format_conversion(self, format=None):
1195
 
        """Format 4 dirs are always in need of conversion."""
1196
 
        if format is None:
1197
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1198
 
                % 'needs_format_conversion(format=None)')
1199
 
        return True
1200
 
 
1201
 
    def open_repository(self):
1202
 
        """See BzrDir.open_repository."""
1203
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat4
1204
 
        return RepositoryFormat4().open(self, _found=True)
1205
 
 
1206
 
 
1207
 
class BzrDir5(BzrDirPreSplitOut):
1208
 
    """A .bzr version 5 control object.
1209
 
 
1210
 
    This is a deprecated format and may be removed after sept 2006.
1211
 
    """
1212
 
 
1213
 
    def has_workingtree(self):
1214
 
        """See BzrDir.has_workingtree."""
1215
 
        return True
1216
 
    
1217
 
    def open_repository(self):
1218
 
        """See BzrDir.open_repository."""
1219
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1220
 
        return RepositoryFormat5().open(self, _found=True)
1221
 
 
1222
 
    def open_workingtree(self, _unsupported=False,
1223
 
            recommend_upgrade=True):
1224
 
        """See BzrDir.create_workingtree."""
1225
 
        from bzrlib.workingtree import WorkingTreeFormat2
1226
 
        wt_format = WorkingTreeFormat2()
1227
 
        # we don't warn here about upgrades; that ought to be handled for the
1228
 
        # bzrdir as a whole
1229
 
        return wt_format.open(self, _found=True)
1230
 
 
1231
 
 
1232
 
class BzrDir6(BzrDirPreSplitOut):
1233
 
    """A .bzr version 6 control object.
1234
 
 
1235
 
    This is a deprecated format and may be removed after sept 2006.
1236
 
    """
1237
 
 
1238
 
    def has_workingtree(self):
1239
 
        """See BzrDir.has_workingtree."""
1240
 
        return True
1241
 
    
1242
 
    def open_repository(self):
1243
 
        """See BzrDir.open_repository."""
1244
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1245
 
        return RepositoryFormat6().open(self, _found=True)
1246
 
 
1247
 
    def open_workingtree(self, _unsupported=False,
1248
 
        recommend_upgrade=True):
1249
 
        """See BzrDir.create_workingtree."""
1250
 
        # we don't warn here about upgrades; that ought to be handled for the
1251
 
        # bzrdir as a whole
1252
 
        from bzrlib.workingtree import WorkingTreeFormat2
1253
 
        return WorkingTreeFormat2().open(self, _found=True)
1254
 
 
1255
 
 
1256
1136
class BzrDirMeta1(BzrDir):
1257
1137
    """A .bzr meta version 1 control object.
1258
1138
 
1375
1255
    def has_workingtree(self):
1376
1256
        """Tell if this bzrdir contains a working tree.
1377
1257
 
1378
 
        This will still raise an exception if the bzrdir has a workingtree that
1379
 
        is remote & inaccessible.
1380
 
 
1381
1258
        Note: if you're going to open the working tree, you should just go
1382
1259
        ahead and try, and not ask permission first.
1383
1260
        """
1384
1261
        from bzrlib.workingtree import WorkingTreeFormat
1385
1262
        try:
1386
 
            WorkingTreeFormat.find_format(self)
 
1263
            WorkingTreeFormat.find_format_string(self)
1387
1264
        except errors.NoWorkingTree:
1388
1265
            return False
1389
1266
        return True
1390
1267
 
1391
 
    def needs_format_conversion(self, format=None):
 
1268
    def needs_format_conversion(self, format):
1392
1269
        """See BzrDir.needs_format_conversion()."""
1393
 
        if format is None:
1394
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1395
 
                % 'needs_format_conversion(format=None)')
1396
 
        if format is None:
1397
 
            format = BzrDirFormat.get_default_format()
1398
1270
        if not isinstance(self._format, format.__class__):
1399
1271
            # it is not a meta dir format, conversion is needed.
1400
1272
            return True
1425
1297
                    ignore_fallbacks=False):
1426
1298
        """See BzrDir.open_branch."""
1427
1299
        format = self.find_branch_format(name=name)
1428
 
        self._check_supported(format, unsupported)
 
1300
        format.check_support_status(unsupported)
1429
1301
        return format.open(self, name=name,
1430
1302
            _found=True, ignore_fallbacks=ignore_fallbacks)
1431
1303
 
1433
1305
        """See BzrDir.open_repository."""
1434
1306
        from bzrlib.repository import RepositoryFormat
1435
1307
        format = RepositoryFormat.find_format(self)
1436
 
        self._check_supported(format, unsupported)
 
1308
        format.check_support_status(unsupported)
1437
1309
        return format.open(self, _found=True)
1438
1310
 
1439
1311
    def open_workingtree(self, unsupported=False,
1441
1313
        """See BzrDir.open_workingtree."""
1442
1314
        from bzrlib.workingtree import WorkingTreeFormat
1443
1315
        format = WorkingTreeFormat.find_format(self)
1444
 
        self._check_supported(format, unsupported,
1445
 
            recommend_upgrade,
 
1316
        format.check_support_status(unsupported, recommend_upgrade,
1446
1317
            basedir=self.root_transport.base)
1447
1318
        return format.open(self, _found=True)
1448
1319
 
1453
1324
class BzrProber(controldir.Prober):
1454
1325
    """Prober for formats that use a .bzr/ control directory."""
1455
1326
 
1456
 
    _formats = {}
 
1327
    formats = registry.FormatRegistry(controldir.network_format_registry)
1457
1328
    """The known .bzr formats."""
1458
1329
 
1459
1330
    @classmethod
 
1331
    @deprecated_method(deprecated_in((2, 4, 0)))
1460
1332
    def register_bzrdir_format(klass, format):
1461
 
        klass._formats[format.get_format_string()] = format
 
1333
        klass.formats.register(format.get_format_string(), format)
1462
1334
 
1463
1335
    @classmethod
 
1336
    @deprecated_method(deprecated_in((2, 4, 0)))
1464
1337
    def unregister_bzrdir_format(klass, format):
1465
 
        del klass._formats[format.get_format_string()]
 
1338
        klass.formats.remove(format.get_format_string())
1466
1339
 
1467
1340
    @classmethod
1468
1341
    def probe_transport(klass, transport):
1472
1345
        except errors.NoSuchFile:
1473
1346
            raise errors.NotBranchError(path=transport.base)
1474
1347
        try:
1475
 
            return klass._formats[format_string]
 
1348
            return klass.formats.get(format_string)
1476
1349
        except KeyError:
1477
1350
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1478
1351
 
 
1352
    @classmethod
 
1353
    def known_formats(cls):
 
1354
        result = set()
 
1355
        for name, format in cls.formats.iteritems():
 
1356
            if callable(format):
 
1357
                format = format()
 
1358
            result.add(format)
 
1359
        return result
 
1360
 
1479
1361
 
1480
1362
controldir.ControlDirFormat.register_prober(BzrProber)
1481
1363
 
1505
1387
                    raise errors.NotBranchError(path=transport.base)
1506
1388
                if server_version != '2':
1507
1389
                    raise errors.NotBranchError(path=transport.base)
 
1390
            from bzrlib.remote import RemoteBzrDirFormat
1508
1391
            return RemoteBzrDirFormat()
1509
1392
 
 
1393
    @classmethod
 
1394
    def known_formats(cls):
 
1395
        from bzrlib.remote import RemoteBzrDirFormat
 
1396
        return set([RemoteBzrDirFormat()])
 
1397
 
1510
1398
 
1511
1399
class BzrDirFormat(controldir.ControlDirFormat):
1512
1400
    """ControlDirFormat base class for .bzr/ directories.
1525
1413
    # _lock_class must be set in subclasses to the lock type, typ.
1526
1414
    # TransportLock or LockDir
1527
1415
 
1528
 
    def get_format_string(self):
 
1416
    @classmethod
 
1417
    def get_format_string(cls):
1529
1418
        """Return the ASCII format string that identifies this format."""
1530
 
        raise NotImplementedError(self.get_format_string)
 
1419
        raise NotImplementedError(cls.get_format_string)
1531
1420
 
1532
1421
    def initialize_on_transport(self, transport):
1533
1422
        """Initialize a new bzrdir in the base directory of a Transport."""
1543
1432
            # metadir1
1544
1433
            if type(self) != BzrDirMetaFormat1:
1545
1434
                return self._initialize_on_transport_vfs(transport)
 
1435
            from bzrlib.remote import RemoteBzrDirFormat
1546
1436
            remote_format = RemoteBzrDirFormat()
1547
1437
            self._supply_sub_formats_to(remote_format)
1548
1438
            return remote_format.initialize_on_transport(transport)
1586
1476
            except errors.NoSmartMedium:
1587
1477
                pass
1588
1478
            else:
 
1479
                from bzrlib.remote import RemoteBzrDirFormat
1589
1480
                # TODO: lookup the local format from a server hint.
1590
1481
                remote_dir_format = RemoteBzrDirFormat()
1591
1482
                remote_dir_format._network_name = self.network_name()
1706
1597
        """
1707
1598
        raise NotImplementedError(self._open)
1708
1599
 
1709
 
    @classmethod
1710
 
    def register_format(klass, format):
1711
 
        BzrProber.register_bzrdir_format(format)
1712
 
        # bzr native formats have a network name of their format string.
1713
 
        controldir.network_format_registry.register(format.get_format_string(), format.__class__)
1714
 
        controldir.ControlDirFormat.register_format(format)
1715
 
 
1716
1600
    def _supply_sub_formats_to(self, other_format):
1717
1601
        """Give other_format the same values for sub formats as this has.
1718
1602
 
1725
1609
        :return: None.
1726
1610
        """
1727
1611
 
1728
 
    @classmethod
1729
 
    def unregister_format(klass, format):
1730
 
        BzrProber.unregister_bzrdir_format(format)
1731
 
        controldir.ControlDirFormat.unregister_format(format)
1732
 
        controldir.network_format_registry.remove(format.get_format_string())
1733
 
 
1734
 
 
1735
 
class BzrDirFormat4(BzrDirFormat):
1736
 
    """Bzr dir format 4.
1737
 
 
1738
 
    This format is a combined format for working tree, branch and repository.
1739
 
    It has:
1740
 
     - Format 1 working trees [always]
1741
 
     - Format 4 branches [always]
1742
 
     - Format 4 repositories [always]
1743
 
 
1744
 
    This format is deprecated: it indexes texts using a text it which is
1745
 
    removed in format 5; write support for this format has been removed.
1746
 
    """
1747
 
 
1748
 
    _lock_class = lockable_files.TransportLock
1749
 
 
1750
 
    def get_format_string(self):
1751
 
        """See BzrDirFormat.get_format_string()."""
1752
 
        return "Bazaar-NG branch, format 0.0.4\n"
1753
 
 
1754
 
    def get_format_description(self):
1755
 
        """See BzrDirFormat.get_format_description()."""
1756
 
        return "All-in-one format 4"
1757
 
 
1758
 
    def get_converter(self, format=None):
1759
 
        """See BzrDirFormat.get_converter()."""
1760
 
        # there is one and only one upgrade path here.
1761
 
        return ConvertBzrDir4To5()
1762
 
 
1763
 
    def initialize_on_transport(self, transport):
1764
 
        """Format 4 branches cannot be created."""
1765
 
        raise errors.UninitializableFormat(self)
1766
 
 
1767
 
    def is_supported(self):
1768
 
        """Format 4 is not supported.
1769
 
 
1770
 
        It is not supported because the model changed from 4 to 5 and the
1771
 
        conversion logic is expensive - so doing it on the fly was not
1772
 
        feasible.
1773
 
        """
1774
 
        return False
1775
 
 
1776
 
    def network_name(self):
1777
 
        return self.get_format_string()
1778
 
 
1779
 
    def _open(self, transport):
1780
 
        """See BzrDirFormat._open."""
1781
 
        return BzrDir4(transport, self)
1782
 
 
1783
 
    def __return_repository_format(self):
1784
 
        """Circular import protection."""
1785
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat4
1786
 
        return RepositoryFormat4()
1787
 
    repository_format = property(__return_repository_format)
1788
 
 
1789
 
 
1790
 
class BzrDirFormatAllInOne(BzrDirFormat):
1791
 
    """Common class for formats before meta-dirs."""
1792
 
 
1793
 
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1794
 
        create_prefix=False, force_new_repo=False, stacked_on=None,
1795
 
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1796
 
        shared_repo=False):
1797
 
        """See BzrDirFormat.initialize_on_transport_ex."""
1798
 
        require_stacking = (stacked_on is not None)
1799
 
        # Format 5 cannot stack, but we've been asked to - actually init
1800
 
        # a Meta1Dir
1801
 
        if require_stacking:
1802
 
            format = BzrDirMetaFormat1()
1803
 
            return format.initialize_on_transport_ex(transport,
1804
 
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1805
 
                force_new_repo=force_new_repo, stacked_on=stacked_on,
1806
 
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1807
 
                make_working_trees=make_working_trees, shared_repo=shared_repo)
1808
 
        return BzrDirFormat.initialize_on_transport_ex(self, transport,
1809
 
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1810
 
            force_new_repo=force_new_repo, stacked_on=stacked_on,
1811
 
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1812
 
            make_working_trees=make_working_trees, shared_repo=shared_repo)
1813
 
 
1814
 
 
1815
 
class BzrDirFormat5(BzrDirFormatAllInOne):
1816
 
    """Bzr control format 5.
1817
 
 
1818
 
    This format is a combined format for working tree, branch and repository.
1819
 
    It has:
1820
 
     - Format 2 working trees [always]
1821
 
     - Format 4 branches [always]
1822
 
     - Format 5 repositories [always]
1823
 
       Unhashed stores in the repository.
1824
 
    """
1825
 
 
1826
 
    _lock_class = lockable_files.TransportLock
1827
 
 
1828
 
    def get_format_string(self):
1829
 
        """See BzrDirFormat.get_format_string()."""
1830
 
        return "Bazaar-NG branch, format 5\n"
1831
 
 
1832
 
    def get_branch_format(self):
1833
 
        from bzrlib import branch
1834
 
        return branch.BzrBranchFormat4()
1835
 
 
1836
 
    def get_format_description(self):
1837
 
        """See BzrDirFormat.get_format_description()."""
1838
 
        return "All-in-one format 5"
1839
 
 
1840
 
    def get_converter(self, format=None):
1841
 
        """See BzrDirFormat.get_converter()."""
1842
 
        # there is one and only one upgrade path here.
1843
 
        return ConvertBzrDir5To6()
1844
 
 
1845
 
    def _initialize_for_clone(self, url):
1846
 
        return self.initialize_on_transport(
1847
 
            _mod_transport.get_transport(url), _cloning=True)
1848
 
 
1849
 
    def initialize_on_transport(self, transport, _cloning=False):
1850
 
        """Format 5 dirs always have working tree, branch and repository.
1851
 
 
1852
 
        Except when they are being cloned.
1853
 
        """
1854
 
        from bzrlib.branch import BzrBranchFormat4
1855
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1856
 
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1857
 
        RepositoryFormat5().initialize(result, _internal=True)
1858
 
        if not _cloning:
1859
 
            branch = BzrBranchFormat4().initialize(result)
1860
 
            result._init_workingtree()
1861
 
        return result
1862
 
 
1863
 
    def network_name(self):
1864
 
        return self.get_format_string()
1865
 
 
1866
 
    def _open(self, transport):
1867
 
        """See BzrDirFormat._open."""
1868
 
        return BzrDir5(transport, self)
1869
 
 
1870
 
    def __return_repository_format(self):
1871
 
        """Circular import protection."""
1872
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1873
 
        return RepositoryFormat5()
1874
 
    repository_format = property(__return_repository_format)
1875
 
 
1876
 
 
1877
 
class BzrDirFormat6(BzrDirFormatAllInOne):
1878
 
    """Bzr control format 6.
1879
 
 
1880
 
    This format is a combined format for working tree, branch and repository.
1881
 
    It has:
1882
 
     - Format 2 working trees [always]
1883
 
     - Format 4 branches [always]
1884
 
     - Format 6 repositories [always]
1885
 
    """
1886
 
 
1887
 
    _lock_class = lockable_files.TransportLock
1888
 
 
1889
 
    def get_format_string(self):
1890
 
        """See BzrDirFormat.get_format_string()."""
1891
 
        return "Bazaar-NG branch, format 6\n"
1892
 
 
1893
 
    def get_format_description(self):
1894
 
        """See BzrDirFormat.get_format_description()."""
1895
 
        return "All-in-one format 6"
1896
 
 
1897
 
    def get_branch_format(self):
1898
 
        from bzrlib import branch
1899
 
        return branch.BzrBranchFormat4()
1900
 
 
1901
 
    def get_converter(self, format=None):
1902
 
        """See BzrDirFormat.get_converter()."""
1903
 
        # there is one and only one upgrade path here.
1904
 
        return ConvertBzrDir6ToMeta()
1905
 
 
1906
 
    def _initialize_for_clone(self, url):
1907
 
        return self.initialize_on_transport(
1908
 
            _mod_transport.get_transport(url), _cloning=True)
1909
 
 
1910
 
    def initialize_on_transport(self, transport, _cloning=False):
1911
 
        """Format 6 dirs always have working tree, branch and repository.
1912
 
 
1913
 
        Except when they are being cloned.
1914
 
        """
1915
 
        from bzrlib.branch import BzrBranchFormat4
1916
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1917
 
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1918
 
        RepositoryFormat6().initialize(result, _internal=True)
1919
 
        if not _cloning:
1920
 
            branch = BzrBranchFormat4().initialize(result)
1921
 
            result._init_workingtree()
1922
 
        return result
1923
 
 
1924
 
    def network_name(self):
1925
 
        return self.get_format_string()
1926
 
 
1927
 
    def _open(self, transport):
1928
 
        """See BzrDirFormat._open."""
1929
 
        return BzrDir6(transport, self)
1930
 
 
1931
 
    def __return_repository_format(self):
1932
 
        """Circular import protection."""
1933
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1934
 
        return RepositoryFormat6()
1935
 
    repository_format = property(__return_repository_format)
1936
 
 
1937
1612
 
1938
1613
class BzrDirMetaFormat1(BzrDirFormat):
1939
1614
    """Bzr meta control format 1
1940
1615
 
1941
1616
    This is the first format with split out working tree, branch and repository
1942
1617
    disk storage.
 
1618
 
1943
1619
    It has:
1944
 
     - Format 3 working trees [optional]
1945
 
     - Format 5 branches [optional]
1946
 
     - Format 7 repositories [optional]
 
1620
 
 
1621
    - Format 3 working trees [optional]
 
1622
    - Format 5 branches [optional]
 
1623
    - Format 7 repositories [optional]
1947
1624
    """
1948
1625
 
1949
1626
    _lock_class = lockdir.LockDir
1950
1627
 
 
1628
    fixed_components = False
 
1629
 
1951
1630
    def __init__(self):
1952
1631
        self._workingtree_format = None
1953
1632
        self._branch_format = None
1967
1646
 
1968
1647
    def get_branch_format(self):
1969
1648
        if self._branch_format is None:
1970
 
            from bzrlib.branch import BranchFormat
1971
 
            self._branch_format = BranchFormat.get_default_format()
 
1649
            from bzrlib.branch import format_registry as branch_format_registry
 
1650
            self._branch_format = branch_format_registry.get_default()
1972
1651
        return self._branch_format
1973
1652
 
1974
1653
    def set_branch_format(self, format):
2029
1708
                    # stack_on is inaccessible, JFDI.
2030
1709
                    # TODO: bad monkey, hard-coded formats...
2031
1710
                    if self.repository_format.rich_root_data:
2032
 
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
1711
                        new_repo_format = knitpack_repo.RepositoryFormatKnitPack5RichRoot()
2033
1712
                    else:
2034
 
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
 
1713
                        new_repo_format = knitpack_repo.RepositoryFormatKnitPack5()
2035
1714
            else:
2036
1715
                # If the target already supports stacking, then we know the
2037
1716
                # project is already able to use stacking, so auto-upgrade
2054
1733
            if target_branch is None:
2055
1734
                if do_upgrade:
2056
1735
                    # TODO: bad monkey, hard-coded formats...
2057
 
                    new_branch_format = branch.BzrBranchFormat7()
 
1736
                    from bzrlib.branch import BzrBranchFormat7
 
1737
                    new_branch_format = BzrBranchFormat7()
2058
1738
            else:
2059
1739
                new_branch_format = target_branch._format
2060
1740
                if not new_branch_format.supports_stacking():
2075
1755
            raise NotImplementedError(self.get_converter)
2076
1756
        return ConvertMetaToMeta(format)
2077
1757
 
2078
 
    def get_format_string(self):
 
1758
    @classmethod
 
1759
    def get_format_string(cls):
2079
1760
        """See BzrDirFormat.get_format_string()."""
2080
1761
        return "Bazaar-NG meta directory, format 1\n"
2081
1762
 
2099
1780
        """Circular import protection."""
2100
1781
        if self._repository_format:
2101
1782
            return self._repository_format
2102
 
        from bzrlib.repository import RepositoryFormat
2103
 
        return RepositoryFormat.get_default_format()
 
1783
        from bzrlib.repository import format_registry
 
1784
        return format_registry.get_default()
2104
1785
 
2105
1786
    def _set_repository_format(self, value):
2106
1787
        """Allow changing the repository format for metadir formats."""
2129
1810
 
2130
1811
    def __get_workingtree_format(self):
2131
1812
        if self._workingtree_format is None:
2132
 
            from bzrlib.workingtree import WorkingTreeFormat
2133
 
            self._workingtree_format = WorkingTreeFormat.get_default_format()
 
1813
            from bzrlib.workingtree import (
 
1814
                format_registry as wt_format_registry,
 
1815
                )
 
1816
            self._workingtree_format = wt_format_registry.get_default()
2134
1817
        return self._workingtree_format
2135
1818
 
2136
1819
    def __set_workingtree_format(self, wt_format):
2141
1824
 
2142
1825
 
2143
1826
# Register bzr formats
2144
 
BzrDirFormat.register_format(BzrDirFormat4())
2145
 
BzrDirFormat.register_format(BzrDirFormat5())
2146
 
BzrDirFormat.register_format(BzrDirFormat6())
2147
 
__default_format = BzrDirMetaFormat1()
2148
 
BzrDirFormat.register_format(__default_format)
2149
 
controldir.ControlDirFormat._default_format = __default_format
2150
 
 
2151
 
 
2152
 
class Converter(object):
2153
 
    """Converts a disk format object from one format to another."""
2154
 
 
2155
 
    def convert(self, to_convert, pb):
2156
 
        """Perform the conversion of to_convert, giving feedback via pb.
2157
 
 
2158
 
        :param to_convert: The disk object to convert.
2159
 
        :param pb: a progress bar to use for progress information.
2160
 
        """
2161
 
 
2162
 
    def step(self, message):
2163
 
        """Update the pb by a step."""
2164
 
        self.count +=1
2165
 
        self.pb.update(message, self.count, self.total)
2166
 
 
2167
 
 
2168
 
class ConvertBzrDir4To5(Converter):
2169
 
    """Converts format 4 bzr dirs to format 5."""
2170
 
 
2171
 
    def __init__(self):
2172
 
        super(ConvertBzrDir4To5, self).__init__()
2173
 
        self.converted_revs = set()
2174
 
        self.absent_revisions = set()
2175
 
        self.text_count = 0
2176
 
        self.revisions = {}
2177
 
 
2178
 
    def convert(self, to_convert, pb):
2179
 
        """See Converter.convert()."""
2180
 
        self.bzrdir = to_convert
2181
 
        if pb is not None:
2182
 
            warnings.warn("pb parameter to convert() is deprecated")
2183
 
        self.pb = ui.ui_factory.nested_progress_bar()
2184
 
        try:
2185
 
            ui.ui_factory.note('starting upgrade from format 4 to 5')
2186
 
            if isinstance(self.bzrdir.transport, local.LocalTransport):
2187
 
                self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2188
 
            self._convert_to_weaves()
2189
 
            return BzrDir.open(self.bzrdir.user_url)
2190
 
        finally:
2191
 
            self.pb.finished()
2192
 
 
2193
 
    def _convert_to_weaves(self):
2194
 
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
2195
 
        try:
2196
 
            # TODO permissions
2197
 
            stat = self.bzrdir.transport.stat('weaves')
2198
 
            if not S_ISDIR(stat.st_mode):
2199
 
                self.bzrdir.transport.delete('weaves')
2200
 
                self.bzrdir.transport.mkdir('weaves')
2201
 
        except errors.NoSuchFile:
2202
 
            self.bzrdir.transport.mkdir('weaves')
2203
 
        # deliberately not a WeaveFile as we want to build it up slowly.
2204
 
        self.inv_weave = Weave('inventory')
2205
 
        # holds in-memory weaves for all files
2206
 
        self.text_weaves = {}
2207
 
        self.bzrdir.transport.delete('branch-format')
2208
 
        self.branch = self.bzrdir.open_branch()
2209
 
        self._convert_working_inv()
2210
 
        rev_history = self.branch.revision_history()
2211
 
        # to_read is a stack holding the revisions we still need to process;
2212
 
        # appending to it adds new highest-priority revisions
2213
 
        self.known_revisions = set(rev_history)
2214
 
        self.to_read = rev_history[-1:]
2215
 
        while self.to_read:
2216
 
            rev_id = self.to_read.pop()
2217
 
            if (rev_id not in self.revisions
2218
 
                and rev_id not in self.absent_revisions):
2219
 
                self._load_one_rev(rev_id)
2220
 
        self.pb.clear()
2221
 
        to_import = self._make_order()
2222
 
        for i, rev_id in enumerate(to_import):
2223
 
            self.pb.update('converting revision', i, len(to_import))
2224
 
            self._convert_one_rev(rev_id)
2225
 
        self.pb.clear()
2226
 
        self._write_all_weaves()
2227
 
        self._write_all_revs()
2228
 
        ui.ui_factory.note('upgraded to weaves:')
2229
 
        ui.ui_factory.note('  %6d revisions and inventories' % len(self.revisions))
2230
 
        ui.ui_factory.note('  %6d revisions not present' % len(self.absent_revisions))
2231
 
        ui.ui_factory.note('  %6d texts' % self.text_count)
2232
 
        self._cleanup_spare_files_after_format4()
2233
 
        self.branch._transport.put_bytes(
2234
 
            'branch-format',
2235
 
            BzrDirFormat5().get_format_string(),
2236
 
            mode=self.bzrdir._get_file_mode())
2237
 
 
2238
 
    def _cleanup_spare_files_after_format4(self):
2239
 
        # FIXME working tree upgrade foo.
2240
 
        for n in 'merged-patches', 'pending-merged-patches':
2241
 
            try:
2242
 
                ## assert os.path.getsize(p) == 0
2243
 
                self.bzrdir.transport.delete(n)
2244
 
            except errors.NoSuchFile:
2245
 
                pass
2246
 
        self.bzrdir.transport.delete_tree('inventory-store')
2247
 
        self.bzrdir.transport.delete_tree('text-store')
2248
 
 
2249
 
    def _convert_working_inv(self):
2250
 
        inv = xml4.serializer_v4.read_inventory(
2251
 
                self.branch._transport.get('inventory'))
2252
 
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
2253
 
        self.branch._transport.put_bytes('inventory', new_inv_xml,
2254
 
            mode=self.bzrdir._get_file_mode())
2255
 
 
2256
 
    def _write_all_weaves(self):
2257
 
        controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
2258
 
        weave_transport = self.bzrdir.transport.clone('weaves')
2259
 
        weaves = WeaveStore(weave_transport, prefixed=False)
2260
 
        transaction = WriteTransaction()
2261
 
 
2262
 
        try:
2263
 
            i = 0
2264
 
            for file_id, file_weave in self.text_weaves.items():
2265
 
                self.pb.update('writing weave', i, len(self.text_weaves))
2266
 
                weaves._put_weave(file_id, file_weave, transaction)
2267
 
                i += 1
2268
 
            self.pb.update('inventory', 0, 1)
2269
 
            controlweaves._put_weave('inventory', self.inv_weave, transaction)
2270
 
            self.pb.update('inventory', 1, 1)
2271
 
        finally:
2272
 
            self.pb.clear()
2273
 
 
2274
 
    def _write_all_revs(self):
2275
 
        """Write all revisions out in new form."""
2276
 
        self.bzrdir.transport.delete_tree('revision-store')
2277
 
        self.bzrdir.transport.mkdir('revision-store')
2278
 
        revision_transport = self.bzrdir.transport.clone('revision-store')
2279
 
        # TODO permissions
2280
 
        from bzrlib.xml5 import serializer_v5
2281
 
        from bzrlib.repofmt.weaverepo import RevisionTextStore
2282
 
        revision_store = RevisionTextStore(revision_transport,
2283
 
            serializer_v5, False, versionedfile.PrefixMapper(),
2284
 
            lambda:True, lambda:True)
2285
 
        try:
2286
 
            for i, rev_id in enumerate(self.converted_revs):
2287
 
                self.pb.update('write revision', i, len(self.converted_revs))
2288
 
                text = serializer_v5.write_revision_to_string(
2289
 
                    self.revisions[rev_id])
2290
 
                key = (rev_id,)
2291
 
                revision_store.add_lines(key, None, osutils.split_lines(text))
2292
 
        finally:
2293
 
            self.pb.clear()
2294
 
 
2295
 
    def _load_one_rev(self, rev_id):
2296
 
        """Load a revision object into memory.
2297
 
 
2298
 
        Any parents not either loaded or abandoned get queued to be
2299
 
        loaded."""
2300
 
        self.pb.update('loading revision',
2301
 
                       len(self.revisions),
2302
 
                       len(self.known_revisions))
2303
 
        if not self.branch.repository.has_revision(rev_id):
2304
 
            self.pb.clear()
2305
 
            ui.ui_factory.note('revision {%s} not present in branch; '
2306
 
                         'will be converted as a ghost' %
2307
 
                         rev_id)
2308
 
            self.absent_revisions.add(rev_id)
2309
 
        else:
2310
 
            rev = self.branch.repository.get_revision(rev_id)
2311
 
            for parent_id in rev.parent_ids:
2312
 
                self.known_revisions.add(parent_id)
2313
 
                self.to_read.append(parent_id)
2314
 
            self.revisions[rev_id] = rev
2315
 
 
2316
 
    def _load_old_inventory(self, rev_id):
2317
 
        f = self.branch.repository.inventory_store.get(rev_id)
2318
 
        try:
2319
 
            old_inv_xml = f.read()
2320
 
        finally:
2321
 
            f.close()
2322
 
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
2323
 
        inv.revision_id = rev_id
2324
 
        rev = self.revisions[rev_id]
2325
 
        return inv
2326
 
 
2327
 
    def _load_updated_inventory(self, rev_id):
2328
 
        inv_xml = self.inv_weave.get_text(rev_id)
2329
 
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
2330
 
        return inv
2331
 
 
2332
 
    def _convert_one_rev(self, rev_id):
2333
 
        """Convert revision and all referenced objects to new format."""
2334
 
        rev = self.revisions[rev_id]
2335
 
        inv = self._load_old_inventory(rev_id)
2336
 
        present_parents = [p for p in rev.parent_ids
2337
 
                           if p not in self.absent_revisions]
2338
 
        self._convert_revision_contents(rev, inv, present_parents)
2339
 
        self._store_new_inv(rev, inv, present_parents)
2340
 
        self.converted_revs.add(rev_id)
2341
 
 
2342
 
    def _store_new_inv(self, rev, inv, present_parents):
2343
 
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
2344
 
        new_inv_sha1 = sha_string(new_inv_xml)
2345
 
        self.inv_weave.add_lines(rev.revision_id,
2346
 
                                 present_parents,
2347
 
                                 new_inv_xml.splitlines(True))
2348
 
        rev.inventory_sha1 = new_inv_sha1
2349
 
 
2350
 
    def _convert_revision_contents(self, rev, inv, present_parents):
2351
 
        """Convert all the files within a revision.
2352
 
 
2353
 
        Also upgrade the inventory to refer to the text revision ids."""
2354
 
        rev_id = rev.revision_id
2355
 
        mutter('converting texts of revision {%s}',
2356
 
               rev_id)
2357
 
        parent_invs = map(self._load_updated_inventory, present_parents)
2358
 
        entries = inv.iter_entries()
2359
 
        entries.next()
2360
 
        for path, ie in entries:
2361
 
            self._convert_file_version(rev, ie, parent_invs)
2362
 
 
2363
 
    def _convert_file_version(self, rev, ie, parent_invs):
2364
 
        """Convert one version of one file.
2365
 
 
2366
 
        The file needs to be added into the weave if it is a merge
2367
 
        of >=2 parents or if it's changed from its parent.
2368
 
        """
2369
 
        file_id = ie.file_id
2370
 
        rev_id = rev.revision_id
2371
 
        w = self.text_weaves.get(file_id)
2372
 
        if w is None:
2373
 
            w = Weave(file_id)
2374
 
            self.text_weaves[file_id] = w
2375
 
        text_changed = False
2376
 
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2377
 
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2378
 
        # XXX: Note that this is unordered - and this is tolerable because
2379
 
        # the previous code was also unordered.
2380
 
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2381
 
            in heads)
2382
 
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2383
 
 
2384
 
    def get_parent_map(self, revision_ids):
2385
 
        """See graph.StackedParentsProvider.get_parent_map"""
2386
 
        return dict((revision_id, self.revisions[revision_id])
2387
 
                    for revision_id in revision_ids
2388
 
                     if revision_id in self.revisions)
2389
 
 
2390
 
    def snapshot_ie(self, previous_revisions, ie, w, rev_id):
2391
 
        # TODO: convert this logic, which is ~= snapshot to
2392
 
        # a call to:. This needs the path figured out. rather than a work_tree
2393
 
        # a v4 revision_tree can be given, or something that looks enough like
2394
 
        # one to give the file content to the entry if it needs it.
2395
 
        # and we need something that looks like a weave store for snapshot to
2396
 
        # save against.
2397
 
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2398
 
        if len(previous_revisions) == 1:
2399
 
            previous_ie = previous_revisions.values()[0]
2400
 
            if ie._unchanged(previous_ie):
2401
 
                ie.revision = previous_ie.revision
2402
 
                return
2403
 
        if ie.has_text():
2404
 
            f = self.branch.repository._text_store.get(ie.text_id)
2405
 
            try:
2406
 
                file_lines = f.readlines()
2407
 
            finally:
2408
 
                f.close()
2409
 
            w.add_lines(rev_id, previous_revisions, file_lines)
2410
 
            self.text_count += 1
2411
 
        else:
2412
 
            w.add_lines(rev_id, previous_revisions, [])
2413
 
        ie.revision = rev_id
2414
 
 
2415
 
    def _make_order(self):
2416
 
        """Return a suitable order for importing revisions.
2417
 
 
2418
 
        The order must be such that an revision is imported after all
2419
 
        its (present) parents.
2420
 
        """
2421
 
        todo = set(self.revisions.keys())
2422
 
        done = self.absent_revisions.copy()
2423
 
        order = []
2424
 
        while todo:
2425
 
            # scan through looking for a revision whose parents
2426
 
            # are all done
2427
 
            for rev_id in sorted(list(todo)):
2428
 
                rev = self.revisions[rev_id]
2429
 
                parent_ids = set(rev.parent_ids)
2430
 
                if parent_ids.issubset(done):
2431
 
                    # can take this one now
2432
 
                    order.append(rev_id)
2433
 
                    todo.remove(rev_id)
2434
 
                    done.add(rev_id)
2435
 
        return order
2436
 
 
2437
 
 
2438
 
class ConvertBzrDir5To6(Converter):
2439
 
    """Converts format 5 bzr dirs to format 6."""
2440
 
 
2441
 
    def convert(self, to_convert, pb):
2442
 
        """See Converter.convert()."""
2443
 
        self.bzrdir = to_convert
2444
 
        pb = ui.ui_factory.nested_progress_bar()
2445
 
        try:
2446
 
            ui.ui_factory.note('starting upgrade from format 5 to 6')
2447
 
            self._convert_to_prefixed()
2448
 
            return BzrDir.open(self.bzrdir.user_url)
2449
 
        finally:
2450
 
            pb.finished()
2451
 
 
2452
 
    def _convert_to_prefixed(self):
2453
 
        from bzrlib.store import TransportStore
2454
 
        self.bzrdir.transport.delete('branch-format')
2455
 
        for store_name in ["weaves", "revision-store"]:
2456
 
            ui.ui_factory.note("adding prefixes to %s" % store_name)
2457
 
            store_transport = self.bzrdir.transport.clone(store_name)
2458
 
            store = TransportStore(store_transport, prefixed=True)
2459
 
            for urlfilename in store_transport.list_dir('.'):
2460
 
                filename = urlutils.unescape(urlfilename)
2461
 
                if (filename.endswith(".weave") or
2462
 
                    filename.endswith(".gz") or
2463
 
                    filename.endswith(".sig")):
2464
 
                    file_id, suffix = os.path.splitext(filename)
2465
 
                else:
2466
 
                    file_id = filename
2467
 
                    suffix = ''
2468
 
                new_name = store._mapper.map((file_id,)) + suffix
2469
 
                # FIXME keep track of the dirs made RBC 20060121
2470
 
                try:
2471
 
                    store_transport.move(filename, new_name)
2472
 
                except errors.NoSuchFile: # catches missing dirs strangely enough
2473
 
                    store_transport.mkdir(osutils.dirname(new_name))
2474
 
                    store_transport.move(filename, new_name)
2475
 
        self.bzrdir.transport.put_bytes(
2476
 
            'branch-format',
2477
 
            BzrDirFormat6().get_format_string(),
2478
 
            mode=self.bzrdir._get_file_mode())
2479
 
 
2480
 
 
2481
 
class ConvertBzrDir6ToMeta(Converter):
2482
 
    """Converts format 6 bzr dirs to metadirs."""
2483
 
 
2484
 
    def convert(self, to_convert, pb):
2485
 
        """See Converter.convert()."""
2486
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat7
2487
 
        from bzrlib.branch import BzrBranchFormat5
2488
 
        self.bzrdir = to_convert
2489
 
        self.pb = ui.ui_factory.nested_progress_bar()
2490
 
        self.count = 0
2491
 
        self.total = 20 # the steps we know about
2492
 
        self.garbage_inventories = []
2493
 
        self.dir_mode = self.bzrdir._get_dir_mode()
2494
 
        self.file_mode = self.bzrdir._get_file_mode()
2495
 
 
2496
 
        ui.ui_factory.note('starting upgrade from format 6 to metadir')
2497
 
        self.bzrdir.transport.put_bytes(
2498
 
                'branch-format',
2499
 
                "Converting to format 6",
2500
 
                mode=self.file_mode)
2501
 
        # its faster to move specific files around than to open and use the apis...
2502
 
        # first off, nuke ancestry.weave, it was never used.
2503
 
        try:
2504
 
            self.step('Removing ancestry.weave')
2505
 
            self.bzrdir.transport.delete('ancestry.weave')
2506
 
        except errors.NoSuchFile:
2507
 
            pass
2508
 
        # find out whats there
2509
 
        self.step('Finding branch files')
2510
 
        last_revision = self.bzrdir.open_branch().last_revision()
2511
 
        bzrcontents = self.bzrdir.transport.list_dir('.')
2512
 
        for name in bzrcontents:
2513
 
            if name.startswith('basis-inventory.'):
2514
 
                self.garbage_inventories.append(name)
2515
 
        # create new directories for repository, working tree and branch
2516
 
        repository_names = [('inventory.weave', True),
2517
 
                            ('revision-store', True),
2518
 
                            ('weaves', True)]
2519
 
        self.step('Upgrading repository  ')
2520
 
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2521
 
        self.make_lock('repository')
2522
 
        # we hard code the formats here because we are converting into
2523
 
        # the meta format. The meta format upgrader can take this to a
2524
 
        # future format within each component.
2525
 
        self.put_format('repository', RepositoryFormat7())
2526
 
        for entry in repository_names:
2527
 
            self.move_entry('repository', entry)
2528
 
 
2529
 
        self.step('Upgrading branch      ')
2530
 
        self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
2531
 
        self.make_lock('branch')
2532
 
        self.put_format('branch', BzrBranchFormat5())
2533
 
        branch_files = [('revision-history', True),
2534
 
                        ('branch-name', True),
2535
 
                        ('parent', False)]
2536
 
        for entry in branch_files:
2537
 
            self.move_entry('branch', entry)
2538
 
 
2539
 
        checkout_files = [('pending-merges', True),
2540
 
                          ('inventory', True),
2541
 
                          ('stat-cache', False)]
2542
 
        # If a mandatory checkout file is not present, the branch does not have
2543
 
        # a functional checkout. Do not create a checkout in the converted
2544
 
        # branch.
2545
 
        for name, mandatory in checkout_files:
2546
 
            if mandatory and name not in bzrcontents:
2547
 
                has_checkout = False
2548
 
                break
2549
 
        else:
2550
 
            has_checkout = True
2551
 
        if not has_checkout:
2552
 
            ui.ui_factory.note('No working tree.')
2553
 
            # If some checkout files are there, we may as well get rid of them.
2554
 
            for name, mandatory in checkout_files:
2555
 
                if name in bzrcontents:
2556
 
                    self.bzrdir.transport.delete(name)
2557
 
        else:
2558
 
            from bzrlib.workingtree import WorkingTreeFormat3
2559
 
            self.step('Upgrading working tree')
2560
 
            self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
2561
 
            self.make_lock('checkout')
2562
 
            self.put_format(
2563
 
                'checkout', WorkingTreeFormat3())
2564
 
            self.bzrdir.transport.delete_multi(
2565
 
                self.garbage_inventories, self.pb)
2566
 
            for entry in checkout_files:
2567
 
                self.move_entry('checkout', entry)
2568
 
            if last_revision is not None:
2569
 
                self.bzrdir.transport.put_bytes(
2570
 
                    'checkout/last-revision', last_revision)
2571
 
        self.bzrdir.transport.put_bytes(
2572
 
            'branch-format',
2573
 
            BzrDirMetaFormat1().get_format_string(),
2574
 
            mode=self.file_mode)
2575
 
        self.pb.finished()
2576
 
        return BzrDir.open(self.bzrdir.user_url)
2577
 
 
2578
 
    def make_lock(self, name):
2579
 
        """Make a lock for the new control dir name."""
2580
 
        self.step('Make %s lock' % name)
2581
 
        ld = lockdir.LockDir(self.bzrdir.transport,
2582
 
                             '%s/lock' % name,
2583
 
                             file_modebits=self.file_mode,
2584
 
                             dir_modebits=self.dir_mode)
2585
 
        ld.create()
2586
 
 
2587
 
    def move_entry(self, new_dir, entry):
2588
 
        """Move then entry name into new_dir."""
2589
 
        name = entry[0]
2590
 
        mandatory = entry[1]
2591
 
        self.step('Moving %s' % name)
2592
 
        try:
2593
 
            self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
2594
 
        except errors.NoSuchFile:
2595
 
            if mandatory:
2596
 
                raise
2597
 
 
2598
 
    def put_format(self, dirname, format):
2599
 
        self.bzrdir.transport.put_bytes('%s/format' % dirname,
2600
 
            format.get_format_string(),
2601
 
            self.file_mode)
2602
 
 
2603
 
 
2604
 
class ConvertMetaToMeta(Converter):
 
1827
BzrProber.formats.register(BzrDirMetaFormat1.get_format_string(),
 
1828
    BzrDirMetaFormat1)
 
1829
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
 
1830
 
 
1831
 
 
1832
class ConvertMetaToMeta(controldir.Converter):
2605
1833
    """Converts the components of metadirs."""
2606
1834
 
2607
1835
    def __init__(self, target_format):
2632
1860
            # TODO: conversions of Branch and Tree should be done by
2633
1861
            # InterXFormat lookups/some sort of registry.
2634
1862
            # Avoid circular imports
2635
 
            from bzrlib import branch as _mod_branch
2636
1863
            old = branch._format.__class__
2637
1864
            new = self.target_format.get_branch_format().__class__
2638
1865
            while old != new:
2661
1888
        else:
2662
1889
            # TODO: conversions of Branch and Tree should be done by
2663
1890
            # InterXFormat lookups
2664
 
            if (isinstance(tree, workingtree.WorkingTree3) and
 
1891
            if (isinstance(tree, workingtree_3.WorkingTree3) and
2665
1892
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2666
1893
                isinstance(self.target_format.workingtree_format,
2667
1894
                    workingtree_4.DirStateWorkingTreeFormat)):
2680
1907
        return to_convert
2681
1908
 
2682
1909
 
2683
 
# This is not in remote.py because it's relatively small, and needs to be
2684
 
# registered. Putting it in remote.py creates a circular import problem.
2685
 
# we can make it a lazy object if the control formats is turned into something
2686
 
# like a registry.
2687
 
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2688
 
    """Format representing bzrdirs accessed via a smart server"""
2689
 
 
2690
 
    supports_workingtrees = False
2691
 
 
2692
 
    def __init__(self):
2693
 
        BzrDirMetaFormat1.__init__(self)
2694
 
        # XXX: It's a bit ugly that the network name is here, because we'd
2695
 
        # like to believe that format objects are stateless or at least
2696
 
        # immutable,  However, we do at least avoid mutating the name after
2697
 
        # it's returned.  See <https://bugs.launchpad.net/bzr/+bug/504102>
2698
 
        self._network_name = None
2699
 
 
2700
 
    def __repr__(self):
2701
 
        return "%s(_network_name=%r)" % (self.__class__.__name__,
2702
 
            self._network_name)
2703
 
 
2704
 
    def get_format_description(self):
2705
 
        if self._network_name:
2706
 
            real_format = controldir.network_format_registry.get(self._network_name)
2707
 
            return 'Remote: ' + real_format.get_format_description()
2708
 
        return 'bzr remote bzrdir'
2709
 
 
2710
 
    def get_format_string(self):
2711
 
        raise NotImplementedError(self.get_format_string)
2712
 
 
2713
 
    def network_name(self):
2714
 
        if self._network_name:
2715
 
            return self._network_name
2716
 
        else:
2717
 
            raise AssertionError("No network name set.")
2718
 
 
2719
 
    def initialize_on_transport(self, transport):
2720
 
        try:
2721
 
            # hand off the request to the smart server
2722
 
            client_medium = transport.get_smart_medium()
2723
 
        except errors.NoSmartMedium:
2724
 
            # TODO: lookup the local format from a server hint.
2725
 
            local_dir_format = BzrDirMetaFormat1()
2726
 
            return local_dir_format.initialize_on_transport(transport)
2727
 
        client = _SmartClient(client_medium)
2728
 
        path = client.remote_path_from_transport(transport)
2729
 
        try:
2730
 
            response = client.call('BzrDirFormat.initialize', path)
2731
 
        except errors.ErrorFromSmartServer, err:
2732
 
            remote._translate_error(err, path=path)
2733
 
        if response[0] != 'ok':
2734
 
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2735
 
        format = RemoteBzrDirFormat()
2736
 
        self._supply_sub_formats_to(format)
2737
 
        return remote.RemoteBzrDir(transport, format)
2738
 
 
2739
 
    def parse_NoneTrueFalse(self, arg):
2740
 
        if not arg:
2741
 
            return None
2742
 
        if arg == 'False':
2743
 
            return False
2744
 
        if arg == 'True':
2745
 
            return True
2746
 
        raise AssertionError("invalid arg %r" % arg)
2747
 
 
2748
 
    def _serialize_NoneTrueFalse(self, arg):
2749
 
        if arg is False:
2750
 
            return 'False'
2751
 
        if arg:
2752
 
            return 'True'
2753
 
        return ''
2754
 
 
2755
 
    def _serialize_NoneString(self, arg):
2756
 
        return arg or ''
2757
 
 
2758
 
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2759
 
        create_prefix=False, force_new_repo=False, stacked_on=None,
2760
 
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2761
 
        shared_repo=False):
2762
 
        try:
2763
 
            # hand off the request to the smart server
2764
 
            client_medium = transport.get_smart_medium()
2765
 
        except errors.NoSmartMedium:
2766
 
            do_vfs = True
2767
 
        else:
2768
 
            # Decline to open it if the server doesn't support our required
2769
 
            # version (3) so that the VFS-based transport will do it.
2770
 
            if client_medium.should_probe():
2771
 
                try:
2772
 
                    server_version = client_medium.protocol_version()
2773
 
                    if server_version != '2':
2774
 
                        do_vfs = True
2775
 
                    else:
2776
 
                        do_vfs = False
2777
 
                except errors.SmartProtocolError:
2778
 
                    # Apparently there's no usable smart server there, even though
2779
 
                    # the medium supports the smart protocol.
2780
 
                    do_vfs = True
2781
 
            else:
2782
 
                do_vfs = False
2783
 
        if not do_vfs:
2784
 
            client = _SmartClient(client_medium)
2785
 
            path = client.remote_path_from_transport(transport)
2786
 
            if client_medium._is_remote_before((1, 16)):
2787
 
                do_vfs = True
2788
 
        if do_vfs:
2789
 
            # TODO: lookup the local format from a server hint.
2790
 
            local_dir_format = BzrDirMetaFormat1()
2791
 
            self._supply_sub_formats_to(local_dir_format)
2792
 
            return local_dir_format.initialize_on_transport_ex(transport,
2793
 
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2794
 
                force_new_repo=force_new_repo, stacked_on=stacked_on,
2795
 
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2796
 
                make_working_trees=make_working_trees, shared_repo=shared_repo,
2797
 
                vfs_only=True)
2798
 
        return self._initialize_on_transport_ex_rpc(client, path, transport,
2799
 
            use_existing_dir, create_prefix, force_new_repo, stacked_on,
2800
 
            stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
2801
 
 
2802
 
    def _initialize_on_transport_ex_rpc(self, client, path, transport,
2803
 
        use_existing_dir, create_prefix, force_new_repo, stacked_on,
2804
 
        stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
2805
 
        args = []
2806
 
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
2807
 
        args.append(self._serialize_NoneTrueFalse(create_prefix))
2808
 
        args.append(self._serialize_NoneTrueFalse(force_new_repo))
2809
 
        args.append(self._serialize_NoneString(stacked_on))
2810
 
        # stack_on_pwd is often/usually our transport
2811
 
        if stack_on_pwd:
2812
 
            try:
2813
 
                stack_on_pwd = transport.relpath(stack_on_pwd)
2814
 
                if not stack_on_pwd:
2815
 
                    stack_on_pwd = '.'
2816
 
            except errors.PathNotChild:
2817
 
                pass
2818
 
        args.append(self._serialize_NoneString(stack_on_pwd))
2819
 
        args.append(self._serialize_NoneString(repo_format_name))
2820
 
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
2821
 
        args.append(self._serialize_NoneTrueFalse(shared_repo))
2822
 
        request_network_name = self._network_name or \
2823
 
            BzrDirFormat.get_default_format().network_name()
2824
 
        try:
2825
 
            response = client.call('BzrDirFormat.initialize_ex_1.16',
2826
 
                request_network_name, path, *args)
2827
 
        except errors.UnknownSmartMethod:
2828
 
            client._medium._remember_remote_is_before((1,16))
2829
 
            local_dir_format = BzrDirMetaFormat1()
2830
 
            self._supply_sub_formats_to(local_dir_format)
2831
 
            return local_dir_format.initialize_on_transport_ex(transport,
2832
 
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2833
 
                force_new_repo=force_new_repo, stacked_on=stacked_on,
2834
 
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2835
 
                make_working_trees=make_working_trees, shared_repo=shared_repo,
2836
 
                vfs_only=True)
2837
 
        except errors.ErrorFromSmartServer, err:
2838
 
            remote._translate_error(err, path=path)
2839
 
        repo_path = response[0]
2840
 
        bzrdir_name = response[6]
2841
 
        require_stacking = response[7]
2842
 
        require_stacking = self.parse_NoneTrueFalse(require_stacking)
2843
 
        format = RemoteBzrDirFormat()
2844
 
        format._network_name = bzrdir_name
2845
 
        self._supply_sub_formats_to(format)
2846
 
        bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
2847
 
        if repo_path:
2848
 
            repo_format = remote.response_tuple_to_repo_format(response[1:])
2849
 
            if repo_path == '.':
2850
 
                repo_path = ''
2851
 
            if repo_path:
2852
 
                repo_bzrdir_format = RemoteBzrDirFormat()
2853
 
                repo_bzrdir_format._network_name = response[5]
2854
 
                repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
2855
 
                    repo_bzrdir_format)
2856
 
            else:
2857
 
                repo_bzr = bzrdir
2858
 
            final_stack = response[8] or None
2859
 
            final_stack_pwd = response[9] or None
2860
 
            if final_stack_pwd:
2861
 
                final_stack_pwd = urlutils.join(
2862
 
                    transport.base, final_stack_pwd)
2863
 
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
2864
 
            if len(response) > 10:
2865
 
                # Updated server verb that locks remotely.
2866
 
                repo_lock_token = response[10] or None
2867
 
                remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
2868
 
                if repo_lock_token:
2869
 
                    remote_repo.dont_leave_lock_in_place()
2870
 
            else:
2871
 
                remote_repo.lock_write()
2872
 
            policy = UseExistingRepository(remote_repo, final_stack,
2873
 
                final_stack_pwd, require_stacking)
2874
 
            policy.acquire_repository()
2875
 
        else:
2876
 
            remote_repo = None
2877
 
            policy = None
2878
 
        bzrdir._format.set_branch_format(self.get_branch_format())
2879
 
        if require_stacking:
2880
 
            # The repo has already been created, but we need to make sure that
2881
 
            # we'll make a stackable branch.
2882
 
            bzrdir._format.require_stacking(_skip_repo=True)
2883
 
        return remote_repo, bzrdir, require_stacking, policy
2884
 
 
2885
 
    def _open(self, transport):
2886
 
        return remote.RemoteBzrDir(transport, self)
2887
 
 
2888
 
    def __eq__(self, other):
2889
 
        if not isinstance(other, RemoteBzrDirFormat):
2890
 
            return False
2891
 
        return self.get_format_description() == other.get_format_description()
2892
 
 
2893
 
    def __return_repository_format(self):
2894
 
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
2895
 
        # repository format has been asked for, tell the RemoteRepositoryFormat
2896
 
        # that it should use that for init() etc.
2897
 
        result = remote.RemoteRepositoryFormat()
2898
 
        custom_format = getattr(self, '_repository_format', None)
2899
 
        if custom_format:
2900
 
            if isinstance(custom_format, remote.RemoteRepositoryFormat):
2901
 
                return custom_format
2902
 
            else:
2903
 
                # We will use the custom format to create repositories over the
2904
 
                # wire; expose its details like rich_root_data for code to
2905
 
                # query
2906
 
                result._custom_format = custom_format
2907
 
        return result
2908
 
 
2909
 
    def get_branch_format(self):
2910
 
        result = BzrDirMetaFormat1.get_branch_format(self)
2911
 
        if not isinstance(result, remote.RemoteBranchFormat):
2912
 
            new_result = remote.RemoteBranchFormat()
2913
 
            new_result._custom_format = result
2914
 
            # cache the result
2915
 
            self.set_branch_format(new_result)
2916
 
            result = new_result
2917
 
        return result
2918
 
 
2919
 
    repository_format = property(__return_repository_format,
2920
 
        BzrDirMetaFormat1._set_repository_format) #.im_func)
2921
 
 
2922
 
 
2923
1910
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
2924
1911
 
2925
1912
 
3007
1994
 
3008
1995
        Implementations may create a new repository or use a pre-exising
3009
1996
        repository.
 
1997
 
3010
1998
        :param make_working_trees: If creating a repository, set
3011
1999
            make_working_trees to this value (if non-None)
3012
2000
        :param shared: If creating a repository, make it shared if True
3021
2009
 
3022
2010
    def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
3023
2011
                 require_stacking=False):
3024
 
        """
3025
 
        Constructor.
 
2012
        """Constructor.
 
2013
 
3026
2014
        :param bzrdir: The bzrdir to create the repository on.
3027
2015
        :param stack_on: A location to stack on
3028
2016
        :param stack_on_pwd: If stack_on is relative, the location it is
3124
2112
    registry.register(key, helper, help, native, deprecated, hidden,
3125
2113
        experimental, alias)
3126
2114
 
3127
 
# The pre-0.8 formats have their repository format network name registered in
3128
 
# repository.py. MetaDir formats have their repository format network name
3129
 
# inferred from their disk format string.
3130
 
controldir.format_registry.register('weave', BzrDirFormat6,
3131
 
    'Pre-0.8 format.  Slower than knit and does not'
3132
 
    ' support checkouts or shared repositories.',
3133
 
    hidden=True,
3134
 
    deprecated=True)
3135
 
register_metadir(controldir.format_registry, 'metaweave',
3136
 
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3137
 
    'Transitional format in 0.8.  Slower than knit.',
3138
 
    branch_format='bzrlib.branch.BzrBranchFormat5',
3139
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3140
 
    hidden=True,
3141
 
    deprecated=True)
3142
2115
register_metadir(controldir.format_registry, 'knit',
3143
2116
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3144
2117
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
3145
2118
    branch_format='bzrlib.branch.BzrBranchFormat5',
3146
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
 
2119
    tree_format='bzrlib.workingtree_3.WorkingTreeFormat3',
3147
2120
    hidden=True,
3148
2121
    deprecated=True)
3149
2122
register_metadir(controldir.format_registry, 'dirstate',
3151
2124
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3152
2125
        'above when accessed over the network.',
3153
2126
    branch_format='bzrlib.branch.BzrBranchFormat5',
3154
 
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
3155
 
    # directly from workingtree_4 triggers a circular import.
3156
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2127
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3157
2128
    hidden=True,
3158
2129
    deprecated=True)
3159
2130
register_metadir(controldir.format_registry, 'dirstate-tags',
3162
2133
        'network operations. Additionally adds support for tags.'
3163
2134
        ' Incompatible with bzr < 0.15.',
3164
2135
    branch_format='bzrlib.branch.BzrBranchFormat6',
3165
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2136
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3166
2137
    hidden=True,
3167
2138
    deprecated=True)
3168
2139
register_metadir(controldir.format_registry, 'rich-root',
3170
2141
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
3171
2142
        ' bzr < 1.0.',
3172
2143
    branch_format='bzrlib.branch.BzrBranchFormat6',
3173
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2144
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3174
2145
    hidden=True,
3175
2146
    deprecated=True)
3176
2147
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
3179
2150
        'network operations. Additionally adds support for versioning nested '
3180
2151
        'bzr branches. Incompatible with bzr < 0.15.',
3181
2152
    branch_format='bzrlib.branch.BzrBranchFormat6',
3182
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2153
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3183
2154
    experimental=True,
3184
2155
    hidden=True,
3185
2156
    )
3186
2157
register_metadir(controldir.format_registry, 'pack-0.92',
3187
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
 
2158
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
3188
2159
    help='New in 0.92: Pack-based format with data compatible with '
3189
2160
        'dirstate-tags format repositories. Interoperates with '
3190
2161
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3191
2162
        ,
3192
2163
    branch_format='bzrlib.branch.BzrBranchFormat6',
3193
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2164
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3194
2165
    )
3195
2166
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
3196
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
 
2167
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
3197
2168
    help='New in 0.92: Pack-based format with data compatible with '
3198
2169
        'dirstate-with-subtree format repositories. Interoperates with '
3199
2170
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3200
2171
        ,
3201
2172
    branch_format='bzrlib.branch.BzrBranchFormat6',
3202
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2173
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3203
2174
    hidden=True,
3204
2175
    experimental=True,
3205
2176
    )
3206
2177
register_metadir(controldir.format_registry, 'rich-root-pack',
3207
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
 
2178
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
3208
2179
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3209
2180
         '(needed for bzr-svn and bzr-git).',
3210
2181
    branch_format='bzrlib.branch.BzrBranchFormat6',
3211
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2182
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3212
2183
    hidden=True,
3213
2184
    )
3214
2185
register_metadir(controldir.format_registry, '1.6',
3215
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
 
2186
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
3216
2187
    help='A format that allows a branch to indicate that there is another '
3217
2188
         '(stacked) repository that should be used to access data that is '
3218
2189
         'not present locally.',
3219
2190
    branch_format='bzrlib.branch.BzrBranchFormat7',
3220
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2191
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3221
2192
    hidden=True,
3222
2193
    )
3223
2194
register_metadir(controldir.format_registry, '1.6.1-rich-root',
3224
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
 
2195
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
3225
2196
    help='A variant of 1.6 that supports rich-root data '
3226
2197
         '(needed for bzr-svn and bzr-git).',
3227
2198
    branch_format='bzrlib.branch.BzrBranchFormat7',
3228
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2199
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3229
2200
    hidden=True,
3230
2201
    )
3231
2202
register_metadir(controldir.format_registry, '1.9',
3232
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
 
2203
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
3233
2204
    help='A repository format using B+tree indexes. These indexes '
3234
2205
         'are smaller in size, have smarter caching and provide faster '
3235
2206
         'performance for most operations.',
3236
2207
    branch_format='bzrlib.branch.BzrBranchFormat7',
3237
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2208
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3238
2209
    hidden=True,
3239
2210
    )
3240
2211
register_metadir(controldir.format_registry, '1.9-rich-root',
3241
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
 
2212
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
3242
2213
    help='A variant of 1.9 that supports rich-root data '
3243
2214
         '(needed for bzr-svn and bzr-git).',
3244
2215
    branch_format='bzrlib.branch.BzrBranchFormat7',
3245
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2216
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
3246
2217
    hidden=True,
3247
2218
    )
3248
2219
register_metadir(controldir.format_registry, '1.14',
3249
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
 
2220
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
3250
2221
    help='A working-tree format that supports content filtering.',
3251
2222
    branch_format='bzrlib.branch.BzrBranchFormat7',
3252
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
 
2223
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
3253
2224
    )
3254
2225
register_metadir(controldir.format_registry, '1.14-rich-root',
3255
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
 
2226
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
3256
2227
    help='A variant of 1.14 that supports rich-root data '
3257
2228
         '(needed for bzr-svn and bzr-git).',
3258
2229
    branch_format='bzrlib.branch.BzrBranchFormat7',
3259
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
 
2230
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
3260
2231
    )
3261
2232
# The following un-numbered 'development' formats should always just be aliases.
3262
2233
register_metadir(controldir.format_registry, 'development-subtree',
3268
2239
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3269
2240
        'before use.',
3270
2241
    branch_format='bzrlib.branch.BzrBranchFormat7',
3271
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
2242
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
3272
2243
    experimental=True,
3273
2244
    hidden=True,
3274
2245
    alias=False, # Restore to being an alias when an actual development subtree format is added
3276
2247
                 # chk based subtree format.
3277
2248
    )
3278
2249
register_metadir(controldir.format_registry, 'development5-subtree',
3279
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
2250
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatPackDevelopment2Subtree',
3280
2251
    help='Development format, subtree variant. Can convert data to and '
3281
2252
        'from pack-0.92-subtree (and anything compatible with '
3282
2253
        'pack-0.92-subtree) format repositories. Repositories and branches in '
3284
2255
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3285
2256
        'before use.',
3286
2257
    branch_format='bzrlib.branch.BzrBranchFormat7',
3287
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
2258
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
3288
2259
    experimental=True,
3289
2260
    hidden=True,
3290
2261
    alias=False,
3301
2272
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3302
2273
        # 'rich roots. Supported by bzr 1.16 and later.',
3303
2274
    branch_format='bzrlib.branch.BzrBranchFormat7',
3304
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
2275
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
3305
2276
    experimental=False,
3306
2277
    )
3307
2278
 
3310
2281
register_metadir(controldir.format_registry, 'default-rich-root',
3311
2282
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3312
2283
    branch_format='bzrlib.branch.BzrBranchFormat7',
3313
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
2284
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
3314
2285
    alias=True,
3315
2286
    hidden=True,
3316
2287
    help='Same as 2a.')