~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-11 21:41:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080711214124-qi09irlj7pd5cuzg
Shortcut the case when one revision is in the ancestry of the other.

At the cost of a heads() check, when one parent supersedes, we don't have to extract
the text for the other. Changes merge time from 3m37s => 3m21s. Using a
CachingParentsProvider would drop the time down to 3m11s.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
 
28
28
# TODO: Move old formats into a plugin to make this file smaller.
29
29
 
 
30
from cStringIO import StringIO
30
31
import os
31
32
import sys
32
33
 
34
35
lazy_import(globals(), """
35
36
from stat import S_ISDIR
36
37
import textwrap
 
38
from warnings import warn
37
39
 
38
40
import bzrlib
39
41
from bzrlib import (
40
 
    config,
41
42
    errors,
42
43
    graph,
43
44
    lockable_files,
44
45
    lockdir,
45
46
    osutils,
 
47
    registry,
46
48
    remote,
47
49
    revision as _mod_revision,
 
50
    symbol_versioning,
48
51
    ui,
49
52
    urlutils,
50
53
    versionedfile,
55
58
    xml5,
56
59
    )
57
60
from bzrlib.osutils import (
 
61
    sha_strings,
58
62
    sha_string,
59
63
    )
60
64
from bzrlib.smart.client import _SmartClient
 
65
from bzrlib.smart import protocol
61
66
from bzrlib.store.versioned import WeaveStore
62
67
from bzrlib.transactions import WriteTransaction
63
68
from bzrlib.transport import (
64
69
    do_catching_redirections,
65
70
    get_transport,
66
 
    local,
67
71
    )
68
72
from bzrlib.weave import Weave
69
73
""")
72
76
    mutter,
73
77
    note,
74
78
    )
75
 
 
76
 
from bzrlib import (
77
 
    registry,
78
 
    symbol_versioning,
 
79
from bzrlib.transport.local import LocalTransport
 
80
from bzrlib.symbol_versioning import (
 
81
    deprecated_function,
 
82
    deprecated_method,
79
83
    )
80
84
 
81
85
 
151
155
                format.get_format_description(),
152
156
                basedir)
153
157
 
154
 
    def clone(self, url, revision_id=None, force_new_repo=False,
155
 
              preserve_stacking=False):
 
158
    def clone(self, url, revision_id=None, force_new_repo=False):
156
159
        """Clone this bzrdir and its contents to url verbatim.
157
160
 
158
 
        :param url: The url create the clone at.  If url's last component does
159
 
            not exist, it will be created.
160
 
        :param revision_id: The tip revision-id to use for any branch or
161
 
            working tree.  If not None, then the clone operation may tune
 
161
        If url's last component does not exist, it will be created.
 
162
 
 
163
        if revision_id is not None, then the clone operation may tune
162
164
            itself to download less data.
163
 
        :param force_new_repo: Do not use a shared repository for the target
 
165
        :param force_new_repo: Do not use a shared repository for the target 
164
166
                               even if one is available.
165
 
        :param preserve_stacking: When cloning a stacked branch, stack the
166
 
            new branch on top of the other branch's stacked-on branch.
167
167
        """
168
168
        return self.clone_on_transport(get_transport(url),
169
169
                                       revision_id=revision_id,
170
 
                                       force_new_repo=force_new_repo,
171
 
                                       preserve_stacking=preserve_stacking)
 
170
                                       force_new_repo=force_new_repo)
172
171
 
173
172
    def clone_on_transport(self, transport, revision_id=None,
174
 
                           force_new_repo=False, preserve_stacking=False,
175
 
                           stacked_on=None):
 
173
                           force_new_repo=False):
176
174
        """Clone this bzrdir and its contents to transport verbatim.
177
175
 
178
 
        :param transport: The transport for the location to produce the clone
179
 
            at.  If the target directory does not exist, it will be created.
180
 
        :param revision_id: The tip revision-id to use for any branch or
181
 
            working tree.  If not None, then the clone operation may tune
 
176
        If the target directory does not exist, it will be created.
 
177
 
 
178
        if revision_id is not None, then the clone operation may tune
182
179
            itself to download less data.
183
 
        :param force_new_repo: Do not use a shared repository for the target,
 
180
        :param force_new_repo: Do not use a shared repository for the target 
184
181
                               even if one is available.
185
 
        :param preserve_stacking: When cloning a stacked branch, stack the
186
 
            new branch on top of the other branch's stacked-on branch.
187
182
        """
188
183
        transport.ensure_base()
189
 
        require_stacking = (stacked_on is not None)
190
 
        metadir = self.cloning_metadir(require_stacking)
191
 
        result = metadir.initialize_on_transport(transport)
 
184
        result = self.cloning_metadir().initialize_on_transport(transport)
192
185
        repository_policy = None
193
186
        try:
194
187
            local_repo = self.find_repository()
195
188
        except errors.NoRepositoryPresent:
196
189
            local_repo = None
197
 
        try:
198
 
            local_branch = self.open_branch()
199
 
        except errors.NotBranchError:
200
 
            local_branch = None
201
 
        else:
202
 
            # enable fallbacks when branch is not a branch reference
203
 
            if local_branch.repository.has_same_location(local_repo):
204
 
                local_repo = local_branch.repository
205
 
            if preserve_stacking:
206
 
                try:
207
 
                    stacked_on = local_branch.get_stacked_on_url()
208
 
                except (errors.UnstackableBranchFormat,
209
 
                        errors.UnstackableRepositoryFormat,
210
 
                        errors.NotStacked):
211
 
                    pass
212
 
 
213
190
        if local_repo:
214
191
            # may need to copy content in
215
192
            repository_policy = result.determine_repository_policy(
216
 
                force_new_repo, stacked_on, self.root_transport.base,
217
 
                require_stacking=require_stacking)
 
193
                force_new_repo)
218
194
            make_working_trees = local_repo.make_working_trees()
219
195
            result_repo = repository_policy.acquire_repository(
220
196
                make_working_trees, local_repo.is_shared())
221
 
            if not require_stacking and repository_policy._require_stacking:
222
 
                require_stacking = True
223
 
                result._format.require_stacking()
224
197
            result_repo.fetch(local_repo, revision_id=revision_id)
225
 
        else:
226
 
            result_repo = None
227
198
        # 1 if there is a branch present
228
199
        #   make sure its content is available in the target repository
229
200
        #   clone it.
230
 
        if local_branch is not None:
 
201
        try:
 
202
            local_branch = self.open_branch()
 
203
        except errors.NotBranchError:
 
204
            pass
 
205
        else:
231
206
            result_branch = local_branch.clone(result, revision_id=revision_id)
232
207
            if repository_policy is not None:
233
208
                repository_policy.configure_branch(result_branch)
 
209
        try:
 
210
            result_repo = result.find_repository()
 
211
        except errors.NoRepositoryPresent:
 
212
            result_repo = None
234
213
        if result_repo is None or result_repo.make_working_trees():
235
214
            try:
236
215
                self.open_workingtree().clone(result)
372
351
        bzrdir._find_or_create_repository(force_new_repo)
373
352
        return bzrdir.create_branch()
374
353
 
375
 
    def determine_repository_policy(self, force_new_repo=False, stack_on=None,
376
 
                                    stack_on_pwd=None, require_stacking=False):
 
354
    def determine_repository_policy(self, force_new_repo=False):
377
355
        """Return an object representing a policy to use.
378
356
 
379
357
        This controls whether a new repository is created, or a shared
380
358
        repository used instead.
381
 
 
382
 
        If stack_on is supplied, will not seek a containing shared repo.
383
 
 
384
 
        :param force_new_repo: If True, require a new repository to be created.
385
 
        :param stack_on: If supplied, the location to stack on.  If not
386
 
            supplied, a default_stack_on location may be used.
387
 
        :param stack_on_pwd: If stack_on is relative, the location it is
388
 
            relative to.
389
359
        """
390
360
        def repository_policy(found_bzrdir):
391
 
            stack_on = None
392
 
            stack_on_pwd = None
393
 
            config = found_bzrdir.get_config()
394
361
            stop = False
395
 
            if config is not None:
396
 
                stack_on = config.get_default_stack_on()
397
 
                if stack_on is not None:
398
 
                    stack_on_pwd = found_bzrdir.root_transport.base
399
 
                    stop = True
400
 
                    note('Using default stacking branch %s at %s', stack_on,
401
 
                         stack_on_pwd)
402
362
            # does it have a repository ?
403
363
            try:
404
364
                repository = found_bzrdir.open_repository()
413
373
            if not stop:
414
374
                return None, False
415
375
            if repository:
416
 
                return UseExistingRepository(repository, stack_on,
417
 
                    stack_on_pwd, require_stacking=require_stacking), True
 
376
                return UseExistingRepository(repository), True
418
377
            else:
419
 
                return CreateRepository(self, stack_on, stack_on_pwd,
420
 
                    require_stacking=require_stacking), True
 
378
                return CreateRepository(self), True
421
379
 
422
380
        if not force_new_repo:
423
 
            if stack_on is None:
424
 
                policy = self._find_containing(repository_policy)
425
 
                if policy is not None:
426
 
                    return policy
427
 
            else:
428
 
                try:
429
 
                    return UseExistingRepository(self.open_repository(),
430
 
                        stack_on, stack_on_pwd,
431
 
                        require_stacking=require_stacking)
432
 
                except errors.NoRepositoryPresent:
433
 
                    pass
434
 
        return CreateRepository(self, stack_on, stack_on_pwd,
435
 
                                require_stacking=require_stacking)
 
381
            policy = self._find_containing(repository_policy)
 
382
            if policy is not None:
 
383
                return policy
 
384
        return CreateRepository(self)
436
385
 
437
386
    def _find_or_create_repository(self, force_new_repo):
438
387
        """Create a new repository if needed, returning the repository."""
471
420
        if force_new_tree:
472
421
            # check for non local urls
473
422
            t = get_transport(base, possible_transports)
474
 
            if not isinstance(t, local.LocalTransport):
 
423
            if not isinstance(t, LocalTransport):
475
424
                raise errors.NotLocalUrl(base)
476
425
        bzrdir = BzrDir.create(base, format, possible_transports)
477
426
        repo = bzrdir._find_or_create_repository(force_new_repo)
499
448
        :return: The WorkingTree object.
500
449
        """
501
450
        t = get_transport(base)
502
 
        if not isinstance(t, local.LocalTransport):
 
451
        if not isinstance(t, LocalTransport):
503
452
            raise errors.NotLocalUrl(base)
504
453
        bzrdir = BzrDir.create_branch_and_repo(base,
505
454
                                               force_new_repo=True,
519
468
        """
520
469
        raise NotImplementedError(self.create_workingtree)
521
470
 
522
 
    def backup_bzrdir(self):
523
 
        """Backup this bzr control directory.
524
 
        
525
 
        :return: Tuple with old path name and new path name
526
 
        """
527
 
        pb = ui.ui_factory.nested_progress_bar()
528
 
        try:
529
 
            # FIXME: bug 300001 -- the backup fails if the backup directory
530
 
            # already exists, but it should instead either remove it or make
531
 
            # a new backup directory.
532
 
            #
533
 
            # FIXME: bug 262450 -- the backup directory should have the same 
534
 
            # permissions as the .bzr directory (probably a bug in copy_tree)
535
 
            old_path = self.root_transport.abspath('.bzr')
536
 
            new_path = self.root_transport.abspath('backup.bzr')
537
 
            pb.note('making backup of %s' % (old_path,))
538
 
            pb.note('  to %s' % (new_path,))
539
 
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
540
 
            return (old_path, new_path)
541
 
        finally:
542
 
            pb.finished()
543
 
 
544
471
    def retire_bzrdir(self, limit=10000):
545
472
        """Permanently disable the bzrdir.
546
473
 
659
586
 
660
587
    def _find_creation_modes(self):
661
588
        """Determine the appropriate modes for files and directories.
662
 
 
 
589
        
663
590
        They're always set to be consistent with the base directory,
664
591
        assuming that this transport allows setting modes.
665
592
        """
678
605
            # directories and files are read-write for this user. This is
679
606
            # mostly a workaround for filesystems which lie about being able to
680
607
            # write to a directory (cygwin & win32)
681
 
            if (st.st_mode & 07777 == 00000):
682
 
                # FTP allows stat but does not return dir/file modes
683
 
                self._dir_mode = None
684
 
                self._file_mode = None
685
 
            else:
686
 
                self._dir_mode = (st.st_mode & 07777) | 00700
687
 
                # Remove the sticky and execute bits for files
688
 
                self._file_mode = self._dir_mode & ~07111
 
608
            self._dir_mode = (st.st_mode & 07777) | 00700
 
609
            # Remove the sticky and execute bits for files
 
610
            self._file_mode = self._dir_mode & ~07111
689
611
 
690
612
    def _get_file_mode(self):
691
613
        """Return Unix mode for newly created files, or None.
726
648
        guaranteed to point to an existing directory ready for use.
727
649
        """
728
650
        raise NotImplementedError(self.get_workingtree_transport)
729
 
 
730
 
    def get_config(self):
731
 
        if getattr(self, '_get_config', None) is None:
732
 
            return None
733
 
        return self._get_config()
734
 
 
 
651
        
735
652
    def __init__(self, _transport, _format):
736
653
        """Initialize a Bzr control dir object.
737
654
        
798
715
        :param transport: Transport containing the bzrdir.
799
716
        :param _unsupported: private.
800
717
        """
801
 
        # Keep initial base since 'transport' may be modified while following
802
 
        # the redirections.
803
718
        base = transport.base
 
719
 
804
720
        def find_format(transport):
805
721
            return transport, BzrDirFormat.find_format(
806
722
                transport, _server_formats=_server_formats)
807
723
 
808
724
        def redirected(transport, e, redirection_notice):
809
 
            redirected_transport = transport._redirected_to(e.source, e.target)
810
 
            if redirected_transport is None:
811
 
                raise errors.NotBranchError(base)
 
725
            qualified_source = e.get_source_url()
 
726
            relpath = transport.relpath(qualified_source)
 
727
            if not e.target.endswith(relpath):
 
728
                # Not redirected to a branch-format, not a branch
 
729
                raise errors.NotBranchError(path=e.target)
 
730
            target = e.target[:-len(relpath)]
812
731
            note('%s is%s redirected to %s',
813
 
                 transport.base, e.permanently, redirected_transport.base)
814
 
            return redirected_transport
 
732
                 transport.base, e.permanently, target)
 
733
            # Let's try with a new transport
 
734
            # FIXME: If 'transport' has a qualifier, this should
 
735
            # be applied again to the new transport *iff* the
 
736
            # schemes used are the same. Uncomment this code
 
737
            # once the function (and tests) exist.
 
738
            # -- vila20070212
 
739
            #target = urlutils.copy_url_qualifiers(original, target)
 
740
            return get_transport(target)
815
741
 
816
742
        try:
817
743
            transport, format = do_catching_redirections(find_format,
918
844
        tree, branch = bzrdir._get_tree_branch()
919
845
        return tree, branch, relpath
920
846
 
921
 
    @classmethod
922
 
    def open_containing_tree_branch_or_repository(klass, location):
923
 
        """Return the working tree, branch and repo contained by a location.
924
 
 
925
 
        Returns (tree, branch, repository, relpath).
926
 
        If there is no tree containing the location, tree will be None.
927
 
        If there is no branch containing the location, branch will be None.
928
 
        If there is no repository containing the location, repository will be
929
 
        None.
930
 
        relpath is the portion of the path that is contained by the innermost
931
 
        BzrDir.
932
 
 
933
 
        If no tree, branch or repository is found, a NotBranchError is raised.
934
 
        """
935
 
        bzrdir, relpath = klass.open_containing(location)
936
 
        try:
937
 
            tree, branch = bzrdir._get_tree_branch()
938
 
        except errors.NotBranchError:
939
 
            try:
940
 
                repo = bzrdir.find_repository()
941
 
                return None, None, repo, relpath
942
 
            except (errors.NoRepositoryPresent):
943
 
                raise errors.NotBranchError(location)
944
 
        return tree, branch, branch.repository, relpath
945
 
 
946
847
    def open_repository(self, _unsupported=False):
947
848
        """Open the repository object at this BzrDir if one is present.
948
849
 
997
898
            return False
998
899
 
999
900
    def _cloning_metadir(self):
1000
 
        """Produce a metadir suitable for cloning with.
1001
 
        
1002
 
        :returns: (destination_bzrdir_format, source_repository)
1003
 
        """
 
901
        """Produce a metadir suitable for cloning with."""
1004
902
        result_format = self._format.__class__()
1005
903
        try:
1006
904
            try:
1007
905
                branch = self.open_branch()
1008
906
                source_repository = branch.repository
1009
 
                result_format._branch_format = branch._format
1010
907
            except errors.NotBranchError:
1011
908
                source_branch = None
1012
909
                source_repository = self.open_repository()
1017
914
            # the fix recommended in bug # 103195 - to delegate this choice the
1018
915
            # repository itself.
1019
916
            repo_format = source_repository._format
1020
 
            if isinstance(repo_format, remote.RemoteRepositoryFormat):
1021
 
                source_repository._ensure_real()
1022
 
                repo_format = source_repository._real_repository._format
1023
 
            result_format.repository_format = repo_format
 
917
            if not isinstance(repo_format, remote.RemoteRepositoryFormat):
 
918
                result_format.repository_format = repo_format
1024
919
        try:
1025
920
            # TODO: Couldn't we just probe for the format in these cases,
1026
921
            # rather than opening the whole tree?  It would be a little
1032
927
            result_format.workingtree_format = tree._format.__class__()
1033
928
        return result_format, source_repository
1034
929
 
1035
 
    def cloning_metadir(self, require_stacking=False):
 
930
    def cloning_metadir(self):
1036
931
        """Produce a metadir suitable for cloning or sprouting with.
1037
932
 
1038
933
        These operations may produce workingtrees (yes, even though they're
1039
934
        "cloning" something that doesn't have a tree), so a viable workingtree
1040
935
        format must be selected.
1041
 
 
1042
 
        :require_stacking: If True, non-stackable formats will be upgraded
1043
 
            to similar stackable formats.
1044
 
        :returns: a BzrDirFormat with all component formats either set
1045
 
            appropriately or set to None if that component should not be
1046
 
            created.
1047
936
        """
1048
937
        format, repository = self._cloning_metadir()
1049
938
        if format._workingtree_format is None:
1051
940
                return format
1052
941
            tree_format = repository._format._matchingbzrdir.workingtree_format
1053
942
            format.workingtree_format = tree_format.__class__()
1054
 
        if require_stacking:
1055
 
            format.require_stacking()
1056
943
        return format
1057
944
 
1058
945
    def checkout_metadir(self):
1060
947
 
1061
948
    def sprout(self, url, revision_id=None, force_new_repo=False,
1062
949
               recurse='down', possible_transports=None,
1063
 
               accelerator_tree=None, hardlink=False, stacked=False,
1064
 
               source_branch=None, create_tree_if_local=True):
 
950
               accelerator_tree=None, hardlink=False):
1065
951
        """Create a copy of this bzrdir prepared for use as a new line of
1066
952
        development.
1067
953
 
1080
966
            content is different.
1081
967
        :param hardlink: If true, hard-link files from accelerator_tree,
1082
968
            where possible.
1083
 
        :param stacked: If true, create a stacked branch referring to the
1084
 
            location of this control directory.
1085
 
        :param create_tree_if_local: If true, a working-tree will be created
1086
 
            when working locally.
1087
969
        """
1088
970
        target_transport = get_transport(url, possible_transports)
1089
971
        target_transport.ensure_base()
1090
 
        cloning_format = self.cloning_metadir(stacked)
1091
 
        # Create/update the result branch
 
972
        cloning_format = self.cloning_metadir()
1092
973
        result = cloning_format.initialize_on_transport(target_transport)
1093
 
        # if a stacked branch wasn't requested, we don't create one
1094
 
        # even if the origin was stacked
1095
 
        stacked_branch_url = None
1096
 
        if source_branch is not None:
1097
 
            if stacked:
1098
 
                stacked_branch_url = self.root_transport.base
 
974
        try:
 
975
            source_branch = self.open_branch()
1099
976
            source_repository = source_branch.repository
1100
 
        else:
1101
 
            try:
1102
 
                source_branch = self.open_branch()
1103
 
                source_repository = source_branch.repository
1104
 
                if stacked:
1105
 
                    stacked_branch_url = self.root_transport.base
1106
 
            except errors.NotBranchError:
1107
 
                source_branch = None
1108
 
                try:
1109
 
                    source_repository = self.open_repository()
1110
 
                except errors.NoRepositoryPresent:
1111
 
                    source_repository = None
1112
 
        repository_policy = result.determine_repository_policy(
1113
 
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1114
 
        result_repo = repository_policy.acquire_repository()
1115
 
        if source_repository is not None:
1116
 
            # Fetch while stacked to prevent unstacked fetch from
1117
 
            # Branch.sprout.
1118
 
            result_repo.fetch(source_repository, revision_id=revision_id)
1119
 
 
1120
 
        if source_branch is None:
1121
 
            # this is for sprouting a bzrdir without a branch; is that
1122
 
            # actually useful?
1123
 
            # Not especially, but it's part of the contract.
1124
 
            result_branch = result.create_branch()
1125
 
        else:
1126
 
            # Force NULL revision to avoid using repository before stacking
1127
 
            # is configured.
1128
 
            result_branch = source_branch.sprout(
1129
 
                result, revision_id=_mod_revision.NULL_REVISION)
1130
 
            parent_location = result_branch.get_parent()
1131
 
        mutter("created new branch %r" % (result_branch,))
1132
 
        repository_policy.configure_branch(result_branch)
 
977
        except errors.NotBranchError:
 
978
            source_branch = None
 
979
            try:
 
980
                source_repository = self.open_repository()
 
981
            except errors.NoRepositoryPresent:
 
982
                source_repository = None
 
983
        if force_new_repo:
 
984
            result_repo = None
 
985
        else:
 
986
            try:
 
987
                result_repo = result.find_repository()
 
988
            except errors.NoRepositoryPresent:
 
989
                result_repo = None
 
990
        if source_repository is None and result_repo is not None:
 
991
            pass
 
992
        elif source_repository is None and result_repo is None:
 
993
            # no repo available, make a new one
 
994
            result.create_repository()
 
995
        elif source_repository is not None and result_repo is None:
 
996
            # have source, and want to make a new target repo
 
997
            result_repo = source_repository.sprout(result,
 
998
                                                   revision_id=revision_id)
 
999
        else:
 
1000
            # fetch needed content into target.
 
1001
            if source_repository is not None:
 
1002
                # would rather do 
 
1003
                # source_repository.copy_content_into(result_repo,
 
1004
                #                                     revision_id=revision_id)
 
1005
                # so we can override the copy method
 
1006
                result_repo.fetch(source_repository, revision_id=revision_id)
1133
1007
        if source_branch is not None:
1134
 
            source_branch.copy_content_into(result_branch, revision_id)
1135
 
            # Override copy_content_into
1136
 
            result_branch.set_parent(parent_location)
1137
 
 
1138
 
        # Create/update the result working tree
1139
 
        if (create_tree_if_local and
1140
 
            isinstance(target_transport, local.LocalTransport) and
1141
 
            (result_repo is None or result_repo.make_working_trees())):
 
1008
            source_branch.sprout(result, revision_id=revision_id)
 
1009
        else:
 
1010
            result.create_branch()
 
1011
        if isinstance(target_transport, LocalTransport) and (
 
1012
            result_repo is None or result_repo.make_working_trees()):
1142
1013
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1143
1014
                hardlink=hardlink)
1144
1015
            wt.lock_write()
1157
1028
                basis = wt.basis_tree()
1158
1029
                basis.lock_read()
1159
1030
                subtrees = basis.iter_references()
1160
 
            elif result_branch is not None:
1161
 
                basis = result_branch.basis_tree()
1162
 
                basis.lock_read()
1163
 
                subtrees = basis.iter_references()
 
1031
                recurse_branch = wt.branch
1164
1032
            elif source_branch is not None:
1165
1033
                basis = source_branch.basis_tree()
1166
1034
                basis.lock_read()
1167
1035
                subtrees = basis.iter_references()
 
1036
                recurse_branch = source_branch
1168
1037
            else:
1169
1038
                subtrees = []
1170
1039
                basis = None
1174
1043
                    sublocation = source_branch.reference_parent(file_id, path)
1175
1044
                    sublocation.bzrdir.sprout(target,
1176
1045
                        basis.get_reference_revision(file_id, path),
1177
 
                        force_new_repo=force_new_repo, recurse=recurse,
1178
 
                        stacked=stacked)
 
1046
                        force_new_repo=force_new_repo, recurse=recurse)
1179
1047
            finally:
1180
1048
                if basis is not None:
1181
1049
                    basis.unlock()
1197
1065
        """Pre-splitout bzrdirs do not suffer from stale locks."""
1198
1066
        raise NotImplementedError(self.break_lock)
1199
1067
 
1200
 
    def cloning_metadir(self, require_stacking=False):
 
1068
    def cloning_metadir(self):
1201
1069
        """Produce a metadir suitable for cloning with."""
1202
 
        if require_stacking:
1203
 
            return format_registry.make_bzrdir('1.6')
1204
1070
        return self._format.__class__()
1205
1071
 
1206
 
    def clone(self, url, revision_id=None, force_new_repo=False,
1207
 
              preserve_stacking=False):
1208
 
        """See BzrDir.clone().
1209
 
 
1210
 
        force_new_repo has no effect, since this family of formats always
1211
 
        require a new repository.
1212
 
        preserve_stacking has no effect, since no source branch using this
1213
 
        family of formats can be stacked, so there is no stacking to preserve.
1214
 
        """
 
1072
    def clone(self, url, revision_id=None, force_new_repo=False):
 
1073
        """See BzrDir.clone()."""
 
1074
        from bzrlib.workingtree import WorkingTreeFormat2
1215
1075
        self._make_tail(url)
1216
1076
        result = self._format._initialize_for_clone(url)
1217
1077
        self.open_repository().clone(result, revision_id=revision_id)
1218
1078
        from_branch = self.open_branch()
1219
1079
        from_branch.clone(result, revision_id=revision_id)
1220
1080
        try:
1221
 
            tree = self.open_workingtree()
 
1081
            self.open_workingtree().clone(result)
1222
1082
        except errors.NotLocalUrl:
1223
1083
            # make a new one, this format always has to have one.
1224
 
            result._init_workingtree()
1225
 
        else:
1226
 
            tree.clone(result)
 
1084
            try:
 
1085
                WorkingTreeFormat2().initialize(result)
 
1086
            except errors.NotLocalUrl:
 
1087
                # but we cannot do it for remote trees.
 
1088
                to_branch = result.open_branch()
 
1089
                WorkingTreeFormat2()._stub_initialize_remote(to_branch)
1227
1090
        return result
1228
1091
 
1229
1092
    def create_branch(self):
1230
1093
        """See BzrDir.create_branch."""
1231
 
        return self._format.get_branch_format().initialize(self)
 
1094
        return self.open_branch()
1232
1095
 
1233
1096
    def destroy_branch(self):
1234
1097
        """See BzrDir.destroy_branch."""
1247
1110
    def create_workingtree(self, revision_id=None, from_branch=None,
1248
1111
                           accelerator_tree=None, hardlink=False):
1249
1112
        """See BzrDir.create_workingtree."""
1250
 
        # The workingtree is sometimes created when the bzrdir is created,
1251
 
        # but not when cloning.
1252
 
 
1253
1113
        # this looks buggy but is not -really-
1254
1114
        # because this format creates the workingtree when the bzrdir is
1255
1115
        # created
1259
1119
        # that can do wonky stuff here, and that only
1260
1120
        # happens for creating checkouts, which cannot be 
1261
1121
        # done on this format anyway. So - acceptable wart.
1262
 
        try:
1263
 
            result = self.open_workingtree(recommend_upgrade=False)
1264
 
        except errors.NoSuchFile:
1265
 
            result = self._init_workingtree()
 
1122
        result = self.open_workingtree(recommend_upgrade=False)
1266
1123
        if revision_id is not None:
1267
1124
            if revision_id == _mod_revision.NULL_REVISION:
1268
1125
                result.set_parent_ids([])
1270
1127
                result.set_parent_ids([revision_id])
1271
1128
        return result
1272
1129
 
1273
 
    def _init_workingtree(self):
1274
 
        from bzrlib.workingtree import WorkingTreeFormat2
1275
 
        try:
1276
 
            return WorkingTreeFormat2().initialize(self)
1277
 
        except errors.NotLocalUrl:
1278
 
            # Even though we can't access the working tree, we need to
1279
 
            # create its control files.
1280
 
            return WorkingTreeFormat2()._stub_initialize_on_transport(
1281
 
                self.transport, self._control_files._file_mode)
1282
 
 
1283
1130
    def destroy_workingtree(self):
1284
1131
        """See BzrDir.destroy_workingtree."""
1285
1132
        raise errors.UnsupportedOperation(self.destroy_workingtree, self)
1324
1171
        # if the format is not the same as the system default,
1325
1172
        # an upgrade is needed.
1326
1173
        if format is None:
1327
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1328
 
                % 'needs_format_conversion(format=None)')
1329
1174
            format = BzrDirFormat.get_default_format()
1330
1175
        return not isinstance(self._format, format.__class__)
1331
1176
 
1338
1183
 
1339
1184
    def sprout(self, url, revision_id=None, force_new_repo=False,
1340
1185
               possible_transports=None, accelerator_tree=None,
1341
 
               hardlink=False, stacked=False, create_tree_if_local=True):
 
1186
               hardlink=False):
1342
1187
        """See BzrDir.sprout()."""
1343
 
        if stacked:
1344
 
            raise errors.UnstackableBranchFormat(
1345
 
                self._format, self.root_transport.base)
1346
 
        if not create_tree_if_local:
1347
 
            raise errors.MustHaveWorkingTree(
1348
 
                self._format, self.root_transport.base)
1349
1188
        from bzrlib.workingtree import WorkingTreeFormat2
1350
1189
        self._make_tail(url)
1351
1190
        result = self._format._initialize_for_clone(url)
1357
1196
            self.open_branch().sprout(result, revision_id=revision_id)
1358
1197
        except errors.NotBranchError:
1359
1198
            pass
1360
 
 
1361
1199
        # we always want a working tree
1362
1200
        WorkingTreeFormat2().initialize(result,
1363
1201
                                        accelerator_tree=accelerator_tree,
1377
1215
 
1378
1216
    def needs_format_conversion(self, format=None):
1379
1217
        """Format 4 dirs are always in need of conversion."""
1380
 
        if format is None:
1381
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1382
 
                % 'needs_format_conversion(format=None)')
1383
1218
        return True
1384
1219
 
1385
1220
    def open_repository(self):
1541
1376
    def needs_format_conversion(self, format=None):
1542
1377
        """See BzrDir.needs_format_conversion()."""
1543
1378
        if format is None:
1544
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1545
 
                % 'needs_format_conversion(format=None)')
1546
 
        if format is None:
1547
1379
            format = BzrDirFormat.get_default_format()
1548
1380
        if not isinstance(self._format, format.__class__):
1549
1381
            # it is not a meta dir format, conversion is needed.
1596
1428
            basedir=self.root_transport.base)
1597
1429
        return format.open(self, _found=True)
1598
1430
 
1599
 
    def _get_config(self):
1600
 
        return config.BzrDirConfig(self.transport)
1601
 
 
1602
1431
 
1603
1432
class BzrDirFormat(object):
1604
1433
    """An encapsulation of the initialization and open routines for a format.
1714
1543
                                      # FIXME: RBC 20060121 don't peek under
1715
1544
                                      # the covers
1716
1545
                                      mode=temp_control._dir_mode)
1717
 
        if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
 
1546
        if sys.platform == 'win32' and isinstance(transport, LocalTransport):
1718
1547
            win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1719
1548
        file_mode = temp_control._file_mode
1720
1549
        del temp_control
1904
1733
        """See BzrDirFormat.get_format_string()."""
1905
1734
        return "Bazaar-NG branch, format 5\n"
1906
1735
 
1907
 
    def get_branch_format(self):
1908
 
        from bzrlib import branch
1909
 
        return branch.BzrBranchFormat4()
1910
 
 
1911
1736
    def get_format_description(self):
1912
1737
        """See BzrDirFormat.get_format_description()."""
1913
1738
        return "All-in-one format 5"
1927
1752
        """
1928
1753
        from bzrlib.branch import BzrBranchFormat4
1929
1754
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
 
1755
        from bzrlib.workingtree import WorkingTreeFormat2
1930
1756
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1931
1757
        RepositoryFormat5().initialize(result, _internal=True)
1932
1758
        if not _cloning:
1933
1759
            branch = BzrBranchFormat4().initialize(result)
1934
 
            result._init_workingtree()
 
1760
            try:
 
1761
                WorkingTreeFormat2().initialize(result)
 
1762
            except errors.NotLocalUrl:
 
1763
                # Even though we can't access the working tree, we need to
 
1764
                # create its control files.
 
1765
                WorkingTreeFormat2()._stub_initialize_remote(branch)
1935
1766
        return result
1936
1767
 
1937
1768
    def _open(self, transport):
1965
1796
        """See BzrDirFormat.get_format_description()."""
1966
1797
        return "All-in-one format 6"
1967
1798
 
1968
 
    def get_branch_format(self):
1969
 
        from bzrlib import branch
1970
 
        return branch.BzrBranchFormat4()
1971
 
 
1972
1799
    def get_converter(self, format=None):
1973
1800
        """See BzrDirFormat.get_converter()."""
1974
1801
        # there is one and only one upgrade path here.
1984
1811
        """
1985
1812
        from bzrlib.branch import BzrBranchFormat4
1986
1813
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
 
1814
        from bzrlib.workingtree import WorkingTreeFormat2
1987
1815
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1988
1816
        RepositoryFormat6().initialize(result, _internal=True)
1989
1817
        if not _cloning:
1990
1818
            branch = BzrBranchFormat4().initialize(result)
1991
 
            result._init_workingtree()
 
1819
            try:
 
1820
                WorkingTreeFormat2().initialize(result)
 
1821
            except errors.NotLocalUrl:
 
1822
                # Even though we can't access the working tree, we need to
 
1823
                # create its control files.
 
1824
                WorkingTreeFormat2()._stub_initialize_remote(branch)
1992
1825
        return result
1993
1826
 
1994
1827
    def _open(self, transport):
2040
1873
    def set_branch_format(self, format):
2041
1874
        self._branch_format = format
2042
1875
 
2043
 
    def require_stacking(self):
2044
 
        if not self.get_branch_format().supports_stacking():
2045
 
            # We need to make a stacked branch, but the default format for the
2046
 
            # target doesn't support stacking.  So force a branch that *can*
2047
 
            # support stacking.
2048
 
            from bzrlib.branch import BzrBranchFormat7
2049
 
            self._branch_format = BzrBranchFormat7()
2050
 
            mutter("using %r for stacking" % (self._branch_format,))
2051
 
            from bzrlib.repofmt import pack_repo
2052
 
            if self.repository_format.rich_root_data:
2053
 
                bzrdir_format_name = '1.6.1-rich-root'
2054
 
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2055
 
            else:
2056
 
                bzrdir_format_name = '1.6'
2057
 
                repo_format = pack_repo.RepositoryFormatKnitPack5()
2058
 
            note('Source format does not support stacking, using format:'
2059
 
                 ' \'%s\'\n  %s\n',
2060
 
                 bzrdir_format_name, repo_format.get_format_description())
2061
 
            self.repository_format = repo_format
2062
 
 
2063
1876
    def get_converter(self, format=None):
2064
1877
        """See BzrDirFormat.get_converter()."""
2065
1878
        if format is None:
2150
1963
        self.bzrdir = to_convert
2151
1964
        self.pb = pb
2152
1965
        self.pb.note('starting upgrade from format 4 to 5')
2153
 
        if isinstance(self.bzrdir.transport, local.LocalTransport):
 
1966
        if isinstance(self.bzrdir.transport, LocalTransport):
2154
1967
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2155
1968
        self._convert_to_weaves()
2156
1969
        return BzrDir.open(self.bzrdir.root_transport.base)
2594
2407
            pass
2595
2408
        else:
2596
2409
            # TODO: conversions of Branch and Tree should be done by
2597
 
            # InterXFormat lookups/some sort of registry.
 
2410
            # InterXFormat lookups
2598
2411
            # Avoid circular imports
2599
2412
            from bzrlib import branch as _mod_branch
2600
 
            old = branch._format.__class__
2601
 
            new = self.target_format.get_branch_format().__class__
2602
 
            while old != new:
2603
 
                if (old == _mod_branch.BzrBranchFormat5 and
2604
 
                    new in (_mod_branch.BzrBranchFormat6,
2605
 
                        _mod_branch.BzrBranchFormat7)):
2606
 
                    branch_converter = _mod_branch.Converter5to6()
2607
 
                elif (old == _mod_branch.BzrBranchFormat6 and
2608
 
                    new == _mod_branch.BzrBranchFormat7):
2609
 
                    branch_converter = _mod_branch.Converter6to7()
2610
 
                else:
2611
 
                    raise errors.BadConversionTarget("No converter", new)
 
2413
            if (branch._format.__class__ is _mod_branch.BzrBranchFormat5 and
 
2414
                self.target_format.get_branch_format().__class__ is
 
2415
                _mod_branch.BzrBranchFormat6):
 
2416
                branch_converter = _mod_branch.Converter5to6()
2612
2417
                branch_converter.convert(branch)
2613
 
                branch = self.bzrdir.open_branch()
2614
 
                old = branch._format.__class__
2615
2418
        try:
2616
2419
            tree = self.bzrdir.open_workingtree(recommend_upgrade=False)
2617
2420
        except (errors.NoWorkingTree, errors.NotLocalUrl):
2620
2423
            # TODO: conversions of Branch and Tree should be done by
2621
2424
            # InterXFormat lookups
2622
2425
            if (isinstance(tree, workingtree.WorkingTree3) and
2623
 
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
 
2426
                not isinstance(tree, workingtree_4.WorkingTree4) and
2624
2427
                isinstance(self.target_format.workingtree_format,
2625
 
                    workingtree_4.DirStateWorkingTreeFormat)):
 
2428
                    workingtree_4.WorkingTreeFormat4)):
2626
2429
                workingtree_4.Converter3to4().convert(tree)
2627
 
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
2628
 
                not isinstance(tree, workingtree_4.WorkingTree5) and
2629
 
                isinstance(self.target_format.workingtree_format,
2630
 
                    workingtree_4.WorkingTreeFormat5)):
2631
 
                workingtree_4.Converter4to5().convert(tree)
2632
2430
        return to_convert
2633
2431
 
2634
2432
 
2689
2487
            return False
2690
2488
        return self.get_format_description() == other.get_format_description()
2691
2489
 
2692
 
    @property
2693
 
    def repository_format(self):
2694
 
        # Using a property to avoid early loading of remote
2695
 
        return remote.RemoteRepositoryFormat()
2696
 
 
2697
2490
 
2698
2491
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2699
2492
 
2717
2510
    def __init__(self):
2718
2511
        """Create a BzrDirFormatRegistry."""
2719
2512
        self._aliases = set()
2720
 
        self._registration_order = list()
2721
2513
        super(BzrDirFormatRegistry, self).__init__()
2722
2514
 
2723
2515
    def aliases(self):
2785
2577
            BzrDirFormatInfo(native, deprecated, hidden, experimental))
2786
2578
        if alias:
2787
2579
            self._aliases.add(key)
2788
 
        self._registration_order.append(key)
2789
2580
 
2790
2581
    def register_lazy(self, key, module_name, member_name, help, native=True,
2791
2582
        deprecated=False, hidden=False, experimental=False, alias=False):
2793
2584
            help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2794
2585
        if alias:
2795
2586
            self._aliases.add(key)
2796
 
        self._registration_order.append(key)
2797
2587
 
2798
2588
    def set_default(self, key):
2799
2589
        """Set the 'default' key to be a clone of the supplied key.
2819
2609
        return self.get(key)()
2820
2610
 
2821
2611
    def help_topic(self, topic):
2822
 
        output = ""
 
2612
        output = textwrap.dedent("""\
 
2613
            These formats can be used for creating branches, working trees, and
 
2614
            repositories.
 
2615
 
 
2616
            """)
2823
2617
        default_realkey = None
2824
2618
        default_help = self.get_help('default')
2825
2619
        help_pairs = []
2826
 
        for key in self._registration_order:
 
2620
        for key in self.keys():
2827
2621
            if key == 'default':
2828
2622
                continue
2829
2623
            help = self.get_help(key)
2853
2647
                experimental_pairs.append((key, help))
2854
2648
            else:
2855
2649
                output += wrapped(key, help, info)
2856
 
        output += "\nSee ``bzr help formats`` for more about storage formats."
2857
 
        other_output = ""
2858
2650
        if len(experimental_pairs) > 0:
2859
 
            other_output += "Experimental formats are shown below.\n\n"
 
2651
            output += "Experimental formats are shown below.\n\n"
2860
2652
            for key, help in experimental_pairs:
2861
2653
                info = self.get_info(key)
2862
 
                other_output += wrapped(key, help, info)
2863
 
        else:
2864
 
            other_output += \
2865
 
                "No experimental formats are available.\n\n"
 
2654
                output += wrapped(key, help, info)
2866
2655
        if len(deprecated_pairs) > 0:
2867
 
            other_output += "\nDeprecated formats are shown below.\n\n"
 
2656
            output += "Deprecated formats are shown below.\n\n"
2868
2657
            for key, help in deprecated_pairs:
2869
2658
                info = self.get_info(key)
2870
 
                other_output += wrapped(key, help, info)
2871
 
        else:
2872
 
            other_output += \
2873
 
                "\nNo deprecated formats are available.\n\n"
2874
 
        other_output += \
2875
 
            "\nSee ``bzr help formats`` for more about storage formats."
 
2659
                output += wrapped(key, help, info)
2876
2660
 
2877
 
        if topic == 'other-formats':
2878
 
            return other_output
2879
 
        else:
2880
 
            return output
 
2661
        return output
2881
2662
 
2882
2663
 
2883
2664
class RepositoryAcquisitionPolicy(object):
2887
2668
    for a branch that is being created.  The most basic policy decision is
2888
2669
    whether to create a new repository or use an existing one.
2889
2670
    """
2890
 
    def __init__(self, stack_on, stack_on_pwd, require_stacking):
2891
 
        """Constructor.
2892
 
 
2893
 
        :param stack_on: A location to stack on
2894
 
        :param stack_on_pwd: If stack_on is relative, the location it is
2895
 
            relative to.
2896
 
        :param require_stacking: If True, it is a failure to not stack.
2897
 
        """
2898
 
        self._stack_on = stack_on
2899
 
        self._stack_on_pwd = stack_on_pwd
2900
 
        self._require_stacking = require_stacking
2901
2671
 
2902
2672
    def configure_branch(self, branch):
2903
2673
        """Apply any configuration data from this policy to the branch.
2904
2674
 
2905
 
        Default implementation sets repository stacking.
 
2675
        Default implementation does nothing.
2906
2676
        """
2907
 
        if self._stack_on is None:
2908
 
            return
2909
 
        if self._stack_on_pwd is None:
2910
 
            stack_on = self._stack_on
2911
 
        else:
2912
 
            try:
2913
 
                stack_on = urlutils.rebase_url(self._stack_on,
2914
 
                    self._stack_on_pwd,
2915
 
                    branch.bzrdir.root_transport.base)
2916
 
            except errors.InvalidRebaseURLs:
2917
 
                stack_on = self._get_full_stack_on()
2918
 
        try:
2919
 
            branch.set_stacked_on_url(stack_on)
2920
 
        except errors.UnstackableBranchFormat:
2921
 
            if self._require_stacking:
2922
 
                raise
2923
 
 
2924
 
    def _get_full_stack_on(self):
2925
 
        """Get a fully-qualified URL for the stack_on location."""
2926
 
        if self._stack_on is None:
2927
 
            return None
2928
 
        if self._stack_on_pwd is None:
2929
 
            return self._stack_on
2930
 
        else:
2931
 
            return urlutils.join(self._stack_on_pwd, self._stack_on)
2932
 
 
2933
 
    def _add_fallback(self, repository, possible_transports=None):
2934
 
        """Add a fallback to the supplied repository, if stacking is set."""
2935
 
        stack_on = self._get_full_stack_on()
2936
 
        if stack_on is None:
2937
 
            return
2938
 
        stacked_dir = BzrDir.open(stack_on,
2939
 
                                  possible_transports=possible_transports)
2940
 
        try:
2941
 
            stacked_repo = stacked_dir.open_branch().repository
2942
 
        except errors.NotBranchError:
2943
 
            stacked_repo = stacked_dir.open_repository()
2944
 
        try:
2945
 
            repository.add_fallback_repository(stacked_repo)
2946
 
        except errors.UnstackableRepositoryFormat:
2947
 
            if self._require_stacking:
2948
 
                raise
2949
 
        else:
2950
 
            self._require_stacking = True
 
2677
        pass
2951
2678
 
2952
2679
    def acquire_repository(self, make_working_trees=None, shared=False):
2953
2680
        """Acquire a repository for this bzrdir.
2965
2692
class CreateRepository(RepositoryAcquisitionPolicy):
2966
2693
    """A policy of creating a new repository"""
2967
2694
 
2968
 
    def __init__(self, bzrdir, stack_on=None, stack_on_pwd=None,
2969
 
                 require_stacking=False):
2970
 
        """
2971
 
        Constructor.
2972
 
        :param bzrdir: The bzrdir to create the repository on.
2973
 
        :param stack_on: A location to stack on
2974
 
        :param stack_on_pwd: If stack_on is relative, the location it is
2975
 
            relative to.
2976
 
        """
2977
 
        RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
2978
 
                                             require_stacking)
 
2695
    def __init__(self, bzrdir):
 
2696
        RepositoryAcquisitionPolicy.__init__(self)
2979
2697
        self._bzrdir = bzrdir
2980
2698
 
2981
2699
    def acquire_repository(self, make_working_trees=None, shared=False):
2984
2702
        Creates the desired repository in the bzrdir we already have.
2985
2703
        """
2986
2704
        repository = self._bzrdir.create_repository(shared=shared)
2987
 
        self._add_fallback(repository,
2988
 
                           possible_transports=[self._bzrdir.transport])
2989
2705
        if make_working_trees is not None:
2990
2706
            repository.set_make_working_trees(make_working_trees)
2991
2707
        return repository
2994
2710
class UseExistingRepository(RepositoryAcquisitionPolicy):
2995
2711
    """A policy of reusing an existing repository"""
2996
2712
 
2997
 
    def __init__(self, repository, stack_on=None, stack_on_pwd=None,
2998
 
                 require_stacking=False):
2999
 
        """Constructor.
3000
 
 
3001
 
        :param repository: The repository to use.
3002
 
        :param stack_on: A location to stack on
3003
 
        :param stack_on_pwd: If stack_on is relative, the location it is
3004
 
            relative to.
3005
 
        """
3006
 
        RepositoryAcquisitionPolicy.__init__(self, stack_on, stack_on_pwd,
3007
 
                                             require_stacking)
 
2713
    def __init__(self, repository):
 
2714
        RepositoryAcquisitionPolicy.__init__(self)
3008
2715
        self._repository = repository
3009
2716
 
3010
2717
    def acquire_repository(self, make_working_trees=None, shared=False):
3012
2719
 
3013
2720
        Returns an existing repository to use
3014
2721
        """
3015
 
        self._add_fallback(self._repository,
3016
 
                       possible_transports=[self._repository.bzrdir.transport])
3017
2722
        return self._repository
3018
2723
 
3019
2724
 
3020
 
# Please register new formats after old formats so that formats
3021
 
# appear in chronological order and format descriptions can build
3022
 
# on previous ones.
3023
2725
format_registry = BzrDirFormatRegistry()
3024
2726
format_registry.register('weave', BzrDirFormat6,
3025
2727
    'Pre-0.8 format.  Slower than knit and does not'
3026
2728
    ' support checkouts or shared repositories.',
3027
2729
    deprecated=True)
 
2730
format_registry.register_metadir('knit',
 
2731
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
2732
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
 
2733
    branch_format='bzrlib.branch.BzrBranchFormat5',
 
2734
    tree_format='bzrlib.workingtree.WorkingTreeFormat3')
3028
2735
format_registry.register_metadir('metaweave',
3029
2736
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3030
2737
    'Transitional format in 0.8.  Slower than knit.',
3031
2738
    branch_format='bzrlib.branch.BzrBranchFormat5',
3032
2739
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3033
2740
    deprecated=True)
3034
 
format_registry.register_metadir('knit',
3035
 
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3036
 
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
3037
 
    branch_format='bzrlib.branch.BzrBranchFormat5',
3038
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3039
 
    deprecated=True)
3040
2741
format_registry.register_metadir('dirstate',
3041
2742
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3042
2743
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3045
2746
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
3046
2747
    # directly from workingtree_4 triggers a circular import.
3047
2748
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3048
 
    deprecated=True)
 
2749
    )
3049
2750
format_registry.register_metadir('dirstate-tags',
3050
2751
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3051
2752
    help='New in 0.15: Fast local operations and improved scaling for '
3053
2754
        ' Incompatible with bzr < 0.15.',
3054
2755
    branch_format='bzrlib.branch.BzrBranchFormat6',
3055
2756
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3056
 
    deprecated=True)
 
2757
    )
3057
2758
format_registry.register_metadir('rich-root',
3058
2759
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
3059
2760
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
3060
 
        ' bzr < 1.0.',
 
2761
        ' bzr < 1.0',
3061
2762
    branch_format='bzrlib.branch.BzrBranchFormat6',
3062
2763
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3063
 
    deprecated=True)
 
2764
    )
3064
2765
format_registry.register_metadir('dirstate-with-subtree',
3065
2766
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3066
2767
    help='New in 0.15: Fast local operations and improved scaling for '
3097
2798
    )
3098
2799
format_registry.register_metadir('rich-root-pack',
3099
2800
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3100
 
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3101
 
         '(needed for bzr-svn).',
 
2801
    help='New in 1.0: Pack-based format with data compatible with '
 
2802
        'rich-root format repositories. Incompatible with'
 
2803
        ' bzr < 1.0',
3102
2804
    branch_format='bzrlib.branch.BzrBranchFormat6',
3103
2805
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3104
2806
    )
3105
 
format_registry.register_metadir('1.6',
3106
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3107
 
    help='A format that allows a branch to indicate that there is another '
3108
 
         '(stacked) repository that should be used to access data that is '
3109
 
         'not present locally.',
3110
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3111
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3112
 
    )
3113
 
format_registry.register_metadir('1.6.1-rich-root',
3114
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3115
 
    help='A variant of 1.6 that supports rich-root data '
3116
 
         '(needed for bzr-svn).',
3117
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3118
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3119
 
    )
3120
 
format_registry.register_metadir('1.9',
3121
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3122
 
    help='A repository format using B+tree indexes. These indexes '
3123
 
         'are smaller in size, have smarter caching and provide faster '
3124
 
         'performance for most operations.',
3125
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3126
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3127
 
    )
3128
 
format_registry.register_metadir('1.9-rich-root',
3129
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3130
 
    help='A variant of 1.9 that supports rich-root data '
3131
 
         '(needed for bzr-svn).',
3132
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3133
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3134
 
    )
3135
 
format_registry.register_metadir('development-wt5',
3136
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3137
 
    help='A working-tree format that supports views and content filtering.',
3138
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3139
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3140
 
    experimental=True,
3141
 
    )
3142
 
format_registry.register_metadir('development-wt5-rich-root',
3143
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3144
 
    help='A variant of development-wt5 that supports rich-root data '
3145
 
         '(needed for bzr-svn).',
3146
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3147
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3148
 
    experimental=True,
3149
 
    )
3150
2807
# The following two formats should always just be aliases.
3151
2808
format_registry.register_metadir('development',
3152
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
 
2809
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
3153
2810
    help='Current development format. Can convert data to and from pack-0.92 '
3154
2811
        '(and anything compatible with pack-0.92) format repositories. '
3155
 
        'Repositories and branches in this format can only be read by bzr.dev. '
 
2812
        'Repositories in this format can only be read by bzr.dev. '
3156
2813
        'Please read '
3157
2814
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3158
2815
        'before use.',
3159
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2816
    branch_format='bzrlib.branch.BzrBranchFormat6',
3160
2817
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3161
2818
    experimental=True,
3162
2819
    alias=True,
3163
2820
    )
3164
2821
format_registry.register_metadir('development-subtree',
3165
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
2822
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
3166
2823
    help='Current development format, subtree variant. Can convert data to and '
3167
 
        'from pack-0.92-subtree (and anything compatible with '
3168
 
        'pack-0.92-subtree) format repositories. Repositories and branches in '
3169
 
        'this format can only be read by bzr.dev. Please read '
 
2824
        'from pack-0.92 (and anything compatible with pack-0.92) format '
 
2825
        'repositories. Repositories in this format can only be read by '
 
2826
        'bzr.dev. Please read '
3170
2827
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3171
2828
        'before use.',
3172
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2829
    branch_format='bzrlib.branch.BzrBranchFormat6',
3173
2830
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3174
2831
    experimental=True,
3175
2832
    alias=True,
3176
2833
    )
3177
 
# And the development formats above will have aliased one of the following:
3178
 
format_registry.register_metadir('development2',
3179
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3180
 
    help='1.6.1 with B+Tree based index. '
3181
 
        'Please read '
3182
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3183
 
        'before use.',
3184
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3185
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3186
 
    hidden=True,
3187
 
    experimental=True,
3188
 
    )
3189
 
format_registry.register_metadir('development2-subtree',
3190
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3191
 
    help='1.6.1-subtree with B+Tree based index. '
3192
 
        'Please read '
3193
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3194
 
        'before use.',
3195
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3196
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3197
 
    hidden=True,
3198
 
    experimental=True,
3199
 
    )
3200
 
# The current format that is made on 'bzr init'.
 
2834
# And the development formats which the will have aliased one of follow:
 
2835
format_registry.register_metadir('development0',
 
2836
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
 
2837
    help='Trivial rename of pack-0.92 to provide a development format. '
 
2838
        'Please read '
 
2839
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2840
        'before use.',
 
2841
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2842
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2843
    hidden=True,
 
2844
    experimental=True,
 
2845
    )
 
2846
format_registry.register_metadir('development0-subtree',
 
2847
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
 
2848
    help='Trivial rename of pack-0.92-subtree to provide a development format. '
 
2849
        'Please read '
 
2850
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
2851
        'before use.',
 
2852
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
2853
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
2854
    hidden=True,
 
2855
    experimental=True,
 
2856
    )
3201
2857
format_registry.set_default('pack-0.92')