~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""BzrDir logic. The BzrDir is the basic control directory used by bzr.
18
18
 
27
27
 
28
28
# TODO: Move old formats into a plugin to make this file smaller.
29
29
 
30
 
from cStringIO import StringIO
31
30
import os
32
31
import sys
33
32
 
35
34
lazy_import(globals(), """
36
35
from stat import S_ISDIR
37
36
import textwrap
38
 
from warnings import warn
39
37
 
40
38
import bzrlib
41
39
from bzrlib import (
 
40
    branch,
42
41
    config,
43
42
    errors,
44
43
    graph,
45
44
    lockable_files,
46
45
    lockdir,
47
46
    osutils,
48
 
    registry,
49
47
    remote,
 
48
    repository,
50
49
    revision as _mod_revision,
51
 
    symbol_versioning,
52
50
    ui,
53
51
    urlutils,
54
52
    versionedfile,
59
57
    xml5,
60
58
    )
61
59
from bzrlib.osutils import (
62
 
    sha_strings,
63
60
    sha_string,
64
61
    )
65
 
from bzrlib.repository import Repository
 
62
from bzrlib.push import (
 
63
    PushResult,
 
64
    )
 
65
from bzrlib.repofmt import pack_repo
66
66
from bzrlib.smart.client import _SmartClient
67
 
from bzrlib.smart import protocol
68
67
from bzrlib.store.versioned import WeaveStore
69
68
from bzrlib.transactions import WriteTransaction
70
69
from bzrlib.transport import (
71
70
    do_catching_redirections,
72
71
    get_transport,
 
72
    local,
73
73
    )
74
74
from bzrlib.weave import Weave
75
75
""")
77
77
from bzrlib.trace import (
78
78
    mutter,
79
79
    note,
 
80
    warning,
80
81
    )
81
 
from bzrlib.transport.local import LocalTransport
82
 
from bzrlib.symbol_versioning import (
83
 
    deprecated_function,
84
 
    deprecated_method,
 
82
 
 
83
from bzrlib import (
 
84
    hooks,
 
85
    registry,
 
86
    symbol_versioning,
85
87
    )
86
88
 
87
89
 
88
90
class BzrDir(object):
89
91
    """A .bzr control diretory.
90
 
    
 
92
 
91
93
    BzrDir instances let you create or open any of the things that can be
92
94
    found within .bzr - checkouts, branches and repositories.
93
 
    
 
95
 
94
96
    :ivar transport:
95
97
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
96
98
    :ivar root_transport:
98
100
        (i.e. the parent directory holding the .bzr directory).
99
101
 
100
102
    Everything in the bzrdir should have the same file permissions.
 
103
 
 
104
    :cvar hooks: An instance of BzrDirHooks.
101
105
    """
102
106
 
103
107
    def break_lock(self):
125
129
        return True
126
130
 
127
131
    def check_conversion_target(self, target_format):
 
132
        """Check that a bzrdir as a whole can be converted to a new format."""
 
133
        # The only current restriction is that the repository content can be 
 
134
        # fetched compatibly with the target.
128
135
        target_repo_format = target_format.repository_format
129
 
        source_repo_format = self._format.repository_format
130
 
        source_repo_format.check_conversion_target(target_repo_format)
 
136
        try:
 
137
            self.open_repository()._format.check_conversion_target(
 
138
                target_repo_format)
 
139
        except errors.NoRepositoryPresent:
 
140
            # No repo, no problem.
 
141
            pass
131
142
 
132
143
    @staticmethod
133
144
    def _check_supported(format, allow_unsupported,
135
146
        basedir=None):
136
147
        """Give an error or warning on old formats.
137
148
 
138
 
        :param format: may be any kind of format - workingtree, branch, 
 
149
        :param format: may be any kind of format - workingtree, branch,
139
150
        or repository.
140
151
 
141
 
        :param allow_unsupported: If true, allow opening 
142
 
        formats that are strongly deprecated, and which may 
 
152
        :param allow_unsupported: If true, allow opening
 
153
        formats that are strongly deprecated, and which may
143
154
        have limited functionality.
144
155
 
145
156
        :param recommend_upgrade: If true (default), warn
177
188
                                       preserve_stacking=preserve_stacking)
178
189
 
179
190
    def clone_on_transport(self, transport, revision_id=None,
180
 
                           force_new_repo=False, preserve_stacking=False,
181
 
                           stacked_on=None):
 
191
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
 
192
        create_prefix=False, use_existing_dir=True):
182
193
        """Clone this bzrdir and its contents to transport verbatim.
183
194
 
184
195
        :param transport: The transport for the location to produce the clone
190
201
                               even if one is available.
191
202
        :param preserve_stacking: When cloning a stacked branch, stack the
192
203
            new branch on top of the other branch's stacked-on branch.
 
204
        :param create_prefix: Create any missing directories leading up to
 
205
            to_transport.
 
206
        :param use_existing_dir: Use an existing directory if one exists.
193
207
        """
194
 
        transport.ensure_base()
 
208
        # Overview: put together a broad description of what we want to end up
 
209
        # with; then make as few api calls as possible to do it.
 
210
        
 
211
        # We may want to create a repo/branch/tree, if we do so what format
 
212
        # would we want for each:
195
213
        require_stacking = (stacked_on is not None)
196
 
        metadir = self.cloning_metadir(require_stacking)
197
 
        result = metadir.initialize_on_transport(transport)
198
 
        repository_policy = None
 
214
        format = self.cloning_metadir(require_stacking)
 
215
        
 
216
        # Figure out what objects we want:
199
217
        try:
200
218
            local_repo = self.find_repository()
201
219
        except errors.NoRepositoryPresent:
215
233
                        errors.UnstackableRepositoryFormat,
216
234
                        errors.NotStacked):
217
235
                    pass
218
 
 
 
236
        # Bug: We create a metadir without knowing if it can support stacking,
 
237
        # we should look up the policy needs first, or just use it as a hint,
 
238
        # or something.
219
239
        if local_repo:
220
 
            # may need to copy content in
221
 
            repository_policy = result.determine_repository_policy(
222
 
                force_new_repo, stacked_on, self.root_transport.base,
223
 
                require_stacking=require_stacking)
224
240
            make_working_trees = local_repo.make_working_trees()
225
 
            result_repo = repository_policy.acquire_repository(
226
 
                make_working_trees, local_repo.is_shared())
227
 
            result_repo.fetch(local_repo, revision_id=revision_id)
228
 
        else:
229
 
            result_repo = None
 
241
            want_shared = local_repo.is_shared()
 
242
            repo_format_name = format.repository_format.network_name()
 
243
        else:
 
244
            make_working_trees = False
 
245
            want_shared = False
 
246
            repo_format_name = None
 
247
 
 
248
        result_repo, result, require_stacking, repository_policy = \
 
249
            format.initialize_on_transport_ex(transport,
 
250
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
251
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
252
            stack_on_pwd=self.root_transport.base,
 
253
            repo_format_name=repo_format_name,
 
254
            make_working_trees=make_working_trees, shared_repo=want_shared)
 
255
        if repo_format_name:
 
256
            try:
 
257
                # If the result repository is in the same place as the
 
258
                # resulting bzr dir, it will have no content, further if the
 
259
                # result is not stacked then we know all content should be
 
260
                # copied, and finally if we are copying up to a specific
 
261
                # revision_id then we can use the pending-ancestry-result which
 
262
                # does not require traversing all of history to describe it.
 
263
                if (result_repo.bzrdir.root_transport.base ==
 
264
                    result.root_transport.base and not require_stacking and
 
265
                    revision_id is not None):
 
266
                    fetch_spec = graph.PendingAncestryResult(
 
267
                        [revision_id], local_repo)
 
268
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
 
269
                else:
 
270
                    result_repo.fetch(local_repo, revision_id=revision_id)
 
271
            finally:
 
272
                result_repo.unlock()
 
273
        else:
 
274
            if result_repo is not None:
 
275
                raise AssertionError('result_repo not None(%r)' % result_repo)
230
276
        # 1 if there is a branch present
231
277
        #   make sure its content is available in the target repository
232
278
        #   clone it.
233
279
        if local_branch is not None:
234
 
            result_branch = local_branch.clone(result, revision_id=revision_id)
235
 
            if repository_policy is not None:
236
 
                repository_policy.configure_branch(result_branch)
237
 
        if result_repo is None or result_repo.make_working_trees():
238
 
            try:
 
280
            result_branch = local_branch.clone(result, revision_id=revision_id,
 
281
                repository_policy=repository_policy)
 
282
        try:
 
283
            # Cheaper to check if the target is not local, than to try making
 
284
            # the tree and fail.
 
285
            result.root_transport.local_abspath('.')
 
286
            if result_repo is None or result_repo.make_working_trees():
239
287
                self.open_workingtree().clone(result)
240
 
            except (errors.NoWorkingTree, errors.NotLocalUrl):
241
 
                pass
 
288
        except (errors.NoWorkingTree, errors.NotLocalUrl):
 
289
            pass
242
290
        return result
243
291
 
244
292
    # TODO: This should be given a Transport, and should chdir up; otherwise
250
298
    @classmethod
251
299
    def create(cls, base, format=None, possible_transports=None):
252
300
        """Create a new BzrDir at the url 'base'.
253
 
        
 
301
 
254
302
        :param format: If supplied, the format of branch to create.  If not
255
303
            supplied, the default is used.
256
 
        :param possible_transports: If supplied, a list of transports that 
 
304
        :param possible_transports: If supplied, a list of transports that
257
305
            can be reused to share a remote connection.
258
306
        """
259
307
        if cls is not BzrDir:
359
407
        """Create a new BzrDir, Branch and Repository at the url 'base'.
360
408
 
361
409
        This will use the current default BzrDirFormat unless one is
362
 
        specified, and use whatever 
 
410
        specified, and use whatever
363
411
        repository format that that uses via bzrdir.create_branch and
364
412
        create_repository. If a shared repository is available that is used
365
413
        preferentially.
379
427
                                    stack_on_pwd=None, require_stacking=False):
380
428
        """Return an object representing a policy to use.
381
429
 
382
 
        This controls whether a new repository is created, or a shared
383
 
        repository used instead.
 
430
        This controls whether a new repository is created, and the format of
 
431
        that repository, or some existing shared repository used instead.
384
432
 
385
433
        If stack_on is supplied, will not seek a containing shared repo.
386
434
 
395
443
            stack_on_pwd = None
396
444
            config = found_bzrdir.get_config()
397
445
            stop = False
398
 
            if config is not None:
399
 
                stack_on = config.get_default_stack_on()
400
 
                if stack_on is not None:
401
 
                    stack_on_pwd = found_bzrdir.root_transport.base
402
 
                    stop = True
403
 
                    note('Using default stacking branch %s at %s', stack_on,
404
 
                         stack_on_pwd)
 
446
            stack_on = config.get_default_stack_on()
 
447
            if stack_on is not None:
 
448
                stack_on_pwd = found_bzrdir.root_transport.base
 
449
                stop = True
405
450
            # does it have a repository ?
406
451
            try:
407
452
                repository = found_bzrdir.open_repository()
410
455
            else:
411
456
                if ((found_bzrdir.root_transport.base !=
412
457
                     self.root_transport.base) and not repository.is_shared()):
 
458
                    # Don't look higher, can't use a higher shared repo.
413
459
                    repository = None
 
460
                    stop = True
414
461
                else:
415
462
                    stop = True
416
463
            if not stop:
440
487
    def _find_or_create_repository(self, force_new_repo):
441
488
        """Create a new repository if needed, returning the repository."""
442
489
        policy = self.determine_repository_policy(force_new_repo)
443
 
        return policy.acquire_repository()
 
490
        return policy.acquire_repository()[0]
444
491
 
445
492
    @staticmethod
446
493
    def create_branch_convenience(base, force_new_repo=False,
453
500
        not.
454
501
 
455
502
        This will use the current default BzrDirFormat unless one is
456
 
        specified, and use whatever 
 
503
        specified, and use whatever
457
504
        repository format that that uses via bzrdir.create_branch and
458
505
        create_repository. If a shared repository is available that is used
459
506
        preferentially. Whatever repository is used, its tree creation policy
461
508
 
462
509
        The created Branch object is returned.
463
510
        If a working tree cannot be made due to base not being a file:// url,
464
 
        no error is raised unless force_new_tree is True, in which case no 
 
511
        no error is raised unless force_new_tree is True, in which case no
465
512
        data is created on disk and NotLocalUrl is raised.
466
513
 
467
514
        :param base: The URL to create the branch at.
468
515
        :param force_new_repo: If True a new repository is always created.
469
 
        :param force_new_tree: If True or False force creation of a tree or 
 
516
        :param force_new_tree: If True or False force creation of a tree or
470
517
                               prevent such creation respectively.
471
518
        :param format: Override for the bzrdir format to create.
472
519
        :param possible_transports: An optional reusable transports list.
474
521
        if force_new_tree:
475
522
            # check for non local urls
476
523
            t = get_transport(base, possible_transports)
477
 
            if not isinstance(t, LocalTransport):
 
524
            if not isinstance(t, local.LocalTransport):
478
525
                raise errors.NotLocalUrl(base)
479
526
        bzrdir = BzrDir.create(base, format, possible_transports)
480
527
        repo = bzrdir._find_or_create_repository(force_new_repo)
494
541
        'base' must be a local path or a file:// url.
495
542
 
496
543
        This will use the current default BzrDirFormat unless one is
497
 
        specified, and use whatever 
 
544
        specified, and use whatever
498
545
        repository format that that uses for bzrdirformat.create_workingtree,
499
546
        create_branch and create_repository.
500
547
 
502
549
        :return: The WorkingTree object.
503
550
        """
504
551
        t = get_transport(base)
505
 
        if not isinstance(t, LocalTransport):
 
552
        if not isinstance(t, local.LocalTransport):
506
553
            raise errors.NotLocalUrl(base)
507
554
        bzrdir = BzrDir.create_branch_and_repo(base,
508
555
                                               force_new_repo=True,
512
559
    def create_workingtree(self, revision_id=None, from_branch=None,
513
560
        accelerator_tree=None, hardlink=False):
514
561
        """Create a working tree at this BzrDir.
515
 
        
 
562
 
516
563
        :param revision_id: create it as of this revision id.
517
564
        :param from_branch: override bzrdir branch (for lightweight checkouts)
518
565
        :param accelerator_tree: A tree which can be used for retrieving file
522
569
        """
523
570
        raise NotImplementedError(self.create_workingtree)
524
571
 
 
572
    def backup_bzrdir(self):
 
573
        """Backup this bzr control directory.
 
574
 
 
575
        :return: Tuple with old path name and new path name
 
576
        """
 
577
        pb = ui.ui_factory.nested_progress_bar()
 
578
        try:
 
579
            # FIXME: bug 300001 -- the backup fails if the backup directory
 
580
            # already exists, but it should instead either remove it or make
 
581
            # a new backup directory.
 
582
            #
 
583
            # FIXME: bug 262450 -- the backup directory should have the same
 
584
            # permissions as the .bzr directory (probably a bug in copy_tree)
 
585
            old_path = self.root_transport.abspath('.bzr')
 
586
            new_path = self.root_transport.abspath('backup.bzr')
 
587
            pb.note('making backup of %s' % (old_path,))
 
588
            pb.note('  to %s' % (new_path,))
 
589
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
 
590
            return (old_path, new_path)
 
591
        finally:
 
592
            pb.finished()
 
593
 
525
594
    def retire_bzrdir(self, limit=10000):
526
595
        """Permanently disable the bzrdir.
527
596
 
632
701
        IncompatibleFormat if the branch format they are given has
633
702
        a format string, and vice versa.
634
703
 
635
 
        If branch_format is None, the transport is returned with no 
 
704
        If branch_format is None, the transport is returned with no
636
705
        checking. If it is not None, then the returned transport is
637
706
        guaranteed to point to an existing directory ready for use.
638
707
        """
681
750
        if not self._mode_check_done:
682
751
            self._find_creation_modes()
683
752
        return self._dir_mode
684
 
        
 
753
 
685
754
    def get_repository_transport(self, repository_format):
686
755
        """Get the transport for use by repository format in this BzrDir.
687
756
 
689
758
        IncompatibleFormat if the repository format they are given has
690
759
        a format string, and vice versa.
691
760
 
692
 
        If repository_format is None, the transport is returned with no 
 
761
        If repository_format is None, the transport is returned with no
693
762
        checking. If it is not None, then the returned transport is
694
763
        guaranteed to point to an existing directory ready for use.
695
764
        """
696
765
        raise NotImplementedError(self.get_repository_transport)
697
 
        
 
766
 
698
767
    def get_workingtree_transport(self, tree_format):
699
768
        """Get the transport for use by workingtree format in this BzrDir.
700
769
 
702
771
        IncompatibleFormat if the workingtree format they are given has a
703
772
        format string, and vice versa.
704
773
 
705
 
        If workingtree_format is None, the transport is returned with no 
 
774
        If workingtree_format is None, the transport is returned with no
706
775
        checking. If it is not None, then the returned transport is
707
776
        guaranteed to point to an existing directory ready for use.
708
777
        """
709
778
        raise NotImplementedError(self.get_workingtree_transport)
710
779
 
711
780
    def get_config(self):
712
 
        if getattr(self, '_get_config', None) is None:
713
 
            return None
714
 
        return self._get_config()
 
781
        """Get configuration for this BzrDir."""
 
782
        return config.BzrDirConfig(self)
 
783
 
 
784
    def _get_config(self):
 
785
        """By default, no configuration is available."""
 
786
        return None
715
787
 
716
788
    def __init__(self, _transport, _format):
717
789
        """Initialize a Bzr control dir object.
718
 
        
 
790
 
719
791
        Only really common logic should reside here, concrete classes should be
720
792
        made with varying behaviours.
721
793
 
729
801
 
730
802
    def is_control_filename(self, filename):
731
803
        """True if filename is the name of a path which is reserved for bzrdir's.
732
 
        
 
804
 
733
805
        :param filename: A filename within the root transport of this bzrdir.
734
806
 
735
807
        This is true IF and ONLY IF the filename is part of the namespace reserved
738
810
        this in the future - for instance to make bzr talk with svn working
739
811
        trees.
740
812
        """
741
 
        # this might be better on the BzrDirFormat class because it refers to 
742
 
        # all the possible bzrdir disk formats. 
743
 
        # This method is tested via the workingtree is_control_filename tests- 
 
813
        # this might be better on the BzrDirFormat class because it refers to
 
814
        # all the possible bzrdir disk formats.
 
815
        # This method is tested via the workingtree is_control_filename tests-
744
816
        # it was extracted from WorkingTree.is_control_filename. If the method's
745
817
        # contract is extended beyond the current trivial implementation, please
746
818
        # add new tests for it to the appropriate place.
748
820
 
749
821
    def needs_format_conversion(self, format=None):
750
822
        """Return true if this bzrdir needs convert_format run on it.
751
 
        
752
 
        For instance, if the repository format is out of date but the 
 
823
 
 
824
        For instance, if the repository format is out of date but the
753
825
        branch and working tree are not, this should return True.
754
826
 
755
827
        :param format: Optional parameter indicating a specific desired
761
833
    def open_unsupported(base):
762
834
        """Open a branch which is not supported."""
763
835
        return BzrDir.open(base, _unsupported=True)
764
 
        
 
836
 
765
837
    @staticmethod
766
838
    def open(base, _unsupported=False, possible_transports=None):
767
839
        """Open an existing bzrdir, rooted at 'base' (url).
768
 
        
 
840
 
769
841
        :param _unsupported: a private parameter to the BzrDir class.
770
842
        """
771
843
        t = get_transport(base, possible_transports=possible_transports)
779
851
        :param transport: Transport containing the bzrdir.
780
852
        :param _unsupported: private.
781
853
        """
 
854
        for hook in BzrDir.hooks['pre_open']:
 
855
            hook(transport)
 
856
        # Keep initial base since 'transport' may be modified while following
 
857
        # the redirections.
782
858
        base = transport.base
783
 
 
784
859
        def find_format(transport):
785
860
            return transport, BzrDirFormat.find_format(
786
861
                transport, _server_formats=_server_formats)
787
862
 
788
863
        def redirected(transport, e, redirection_notice):
789
 
            qualified_source = e.get_source_url()
790
 
            relpath = transport.relpath(qualified_source)
791
 
            if not e.target.endswith(relpath):
792
 
                # Not redirected to a branch-format, not a branch
793
 
                raise errors.NotBranchError(path=e.target)
794
 
            target = e.target[:-len(relpath)]
 
864
            redirected_transport = transport._redirected_to(e.source, e.target)
 
865
            if redirected_transport is None:
 
866
                raise errors.NotBranchError(base)
795
867
            note('%s is%s redirected to %s',
796
 
                 transport.base, e.permanently, target)
797
 
            # Let's try with a new transport
798
 
            # FIXME: If 'transport' has a qualifier, this should
799
 
            # be applied again to the new transport *iff* the
800
 
            # schemes used are the same. Uncomment this code
801
 
            # once the function (and tests) exist.
802
 
            # -- vila20070212
803
 
            #target = urlutils.copy_url_qualifiers(original, target)
804
 
            return get_transport(target)
 
868
                 transport.base, e.permanently, redirected_transport.base)
 
869
            return redirected_transport
805
870
 
806
871
        try:
807
872
            transport, format = do_catching_redirections(find_format,
813
878
        BzrDir._check_supported(format, _unsupported)
814
879
        return format.open(transport, _found=True)
815
880
 
816
 
    def open_branch(self, unsupported=False):
 
881
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
817
882
        """Open the branch object at this BzrDir if one is present.
818
883
 
819
884
        If unsupported is True, then no longer supported branch formats can
820
885
        still be opened.
821
 
        
 
886
 
822
887
        TODO: static convenience version of this?
823
888
        """
824
889
        raise NotImplementedError(self.open_branch)
826
891
    @staticmethod
827
892
    def open_containing(url, possible_transports=None):
828
893
        """Open an existing branch which contains url.
829
 
        
 
894
 
830
895
        :param url: url to search from.
831
896
        See open_containing_from_transport for more detail.
832
897
        """
833
898
        transport = get_transport(url, possible_transports)
834
899
        return BzrDir.open_containing_from_transport(transport)
835
 
    
 
900
 
836
901
    @staticmethod
837
902
    def open_containing_from_transport(a_transport):
838
903
        """Open an existing branch which contains a_transport.base.
841
906
 
842
907
        Basically we keep looking up until we find the control directory or
843
908
        run into the root.  If there isn't one, raises NotBranchError.
844
 
        If there is one and it is either an unrecognised format or an unsupported 
 
909
        If there is one and it is either an unrecognised format or an unsupported
845
910
        format, UnknownFormatError or UnsupportedFormatError are raised.
846
911
        If there is one, it is returned, along with the unused portion of url.
847
912
 
848
 
        :return: The BzrDir that contains the path, and a Unicode path 
 
913
        :return: The BzrDir that contains the path, and a Unicode path
849
914
                for the rest of the URL.
850
915
        """
851
916
        # this gets the normalised url back. I.e. '.' -> the full path.
959
1024
 
960
1025
    def has_branch(self):
961
1026
        """Tell if this bzrdir contains a branch.
962
 
        
 
1027
 
963
1028
        Note: if you're going to open the branch, you should just go ahead
964
 
        and try, and not ask permission first.  (This method just opens the 
965
 
        branch and discards it, and that's somewhat expensive.) 
 
1029
        and try, and not ask permission first.  (This method just opens the
 
1030
        branch and discards it, and that's somewhat expensive.)
966
1031
        """
967
1032
        try:
968
1033
            self.open_branch()
975
1040
 
976
1041
        This will still raise an exception if the bzrdir has a workingtree that
977
1042
        is remote & inaccessible.
978
 
        
 
1043
 
979
1044
        Note: if you're going to open the working tree, you should just go ahead
980
 
        and try, and not ask permission first.  (This method just opens the 
981
 
        workingtree and discards it, and that's somewhat expensive.) 
 
1045
        and try, and not ask permission first.  (This method just opens the
 
1046
        workingtree and discards it, and that's somewhat expensive.)
982
1047
        """
983
1048
        try:
984
1049
            self.open_workingtree(recommend_upgrade=False)
988
1053
 
989
1054
    def _cloning_metadir(self):
990
1055
        """Produce a metadir suitable for cloning with.
991
 
        
 
1056
 
992
1057
        :returns: (destination_bzrdir_format, source_repository)
993
1058
        """
994
1059
        result_format = self._format.__class__()
995
1060
        try:
996
1061
            try:
997
 
                branch = self.open_branch()
 
1062
                branch = self.open_branch(ignore_fallbacks=True)
998
1063
                source_repository = branch.repository
999
1064
                result_format._branch_format = branch._format
1000
1065
            except errors.NotBranchError:
1007
1072
            # the fix recommended in bug # 103195 - to delegate this choice the
1008
1073
            # repository itself.
1009
1074
            repo_format = source_repository._format
1010
 
            if not isinstance(repo_format, remote.RemoteRepositoryFormat):
1011
 
                result_format.repository_format = repo_format
 
1075
            if isinstance(repo_format, remote.RemoteRepositoryFormat):
 
1076
                source_repository._ensure_real()
 
1077
                repo_format = source_repository._real_repository._format
 
1078
            result_format.repository_format = repo_format
1012
1079
        try:
1013
1080
            # TODO: Couldn't we just probe for the format in these cases,
1014
1081
            # rather than opening the whole tree?  It would be a little
1035
1102
        """
1036
1103
        format, repository = self._cloning_metadir()
1037
1104
        if format._workingtree_format is None:
 
1105
            # No tree in self.
1038
1106
            if repository is None:
 
1107
                # No repository either
1039
1108
                return format
 
1109
            # We have a repository, so set a working tree? (Why? This seems to
 
1110
            # contradict the stated return value in the docstring).
1040
1111
            tree_format = repository._format._matchingbzrdir.workingtree_format
1041
1112
            format.workingtree_format = tree_format.__class__()
1042
 
        if (require_stacking and not
1043
 
            format.get_branch_format().supports_stacking()):
1044
 
            # We need to make a stacked branch, but the default format for the
1045
 
            # target doesn't support stacking.  So force a branch that *can*
1046
 
            # support stacking.
1047
 
            from bzrlib.branch import BzrBranchFormat7
1048
 
            format._branch_format = BzrBranchFormat7()
1049
 
            mutter("using %r for stacking" % (format._branch_format,))
1050
 
            from bzrlib.repofmt import pack_repo
1051
 
            if format.repository_format.rich_root_data:
1052
 
                bzrdir_format_name = '1.6.1-rich-root'
1053
 
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
1054
 
            else:
1055
 
                bzrdir_format_name = '1.6'
1056
 
                repo_format = pack_repo.RepositoryFormatKnitPack5()
1057
 
            note('Source format does not support stacking, using format:'
1058
 
                 ' \'%s\'\n  %s\n',
1059
 
                 bzrdir_format_name, repo_format.get_format_description())
1060
 
            format.repository_format = repo_format
 
1113
        if require_stacking:
 
1114
            format.require_stacking()
1061
1115
        return format
1062
1116
 
1063
1117
    def checkout_metadir(self):
1065
1119
 
1066
1120
    def sprout(self, url, revision_id=None, force_new_repo=False,
1067
1121
               recurse='down', possible_transports=None,
1068
 
               accelerator_tree=None, hardlink=False, stacked=False):
 
1122
               accelerator_tree=None, hardlink=False, stacked=False,
 
1123
               source_branch=None, create_tree_if_local=True):
1069
1124
        """Create a copy of this bzrdir prepared for use as a new line of
1070
1125
        development.
1071
1126
 
1086
1141
            where possible.
1087
1142
        :param stacked: If true, create a stacked branch referring to the
1088
1143
            location of this control directory.
 
1144
        :param create_tree_if_local: If true, a working-tree will be created
 
1145
            when working locally.
1089
1146
        """
1090
1147
        target_transport = get_transport(url, possible_transports)
1091
1148
        target_transport.ensure_base()
1092
1149
        cloning_format = self.cloning_metadir(stacked)
1093
1150
        # Create/update the result branch
1094
1151
        result = cloning_format.initialize_on_transport(target_transport)
1095
 
        try:
1096
 
            source_branch = self.open_branch()
1097
 
            source_repository = source_branch.repository
 
1152
        # if a stacked branch wasn't requested, we don't create one
 
1153
        # even if the origin was stacked
 
1154
        stacked_branch_url = None
 
1155
        if source_branch is not None:
1098
1156
            if stacked:
1099
1157
                stacked_branch_url = self.root_transport.base
1100
 
            else:
1101
 
                # if a stacked branch wasn't requested, we don't create one
1102
 
                # even if the origin was stacked
1103
 
                stacked_branch_url = None
1104
 
        except errors.NotBranchError:
1105
 
            source_branch = None
 
1158
            source_repository = source_branch.repository
 
1159
        else:
1106
1160
            try:
1107
 
                source_repository = self.open_repository()
1108
 
            except errors.NoRepositoryPresent:
1109
 
                source_repository = None
1110
 
            stacked_branch_url = None
 
1161
                source_branch = self.open_branch()
 
1162
                source_repository = source_branch.repository
 
1163
                if stacked:
 
1164
                    stacked_branch_url = self.root_transport.base
 
1165
            except errors.NotBranchError:
 
1166
                source_branch = None
 
1167
                try:
 
1168
                    source_repository = self.open_repository()
 
1169
                except errors.NoRepositoryPresent:
 
1170
                    source_repository = None
1111
1171
        repository_policy = result.determine_repository_policy(
1112
1172
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1113
 
        result_repo = repository_policy.acquire_repository()
 
1173
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
1174
        if is_new_repo and revision_id is not None and not stacked:
 
1175
            fetch_spec = graph.PendingAncestryResult(
 
1176
                [revision_id], source_repository)
 
1177
        else:
 
1178
            fetch_spec = None
1114
1179
        if source_repository is not None:
1115
1180
            # Fetch while stacked to prevent unstacked fetch from
1116
1181
            # Branch.sprout.
1117
 
            result_repo.fetch(source_repository, revision_id=revision_id)
 
1182
            if fetch_spec is None:
 
1183
                result_repo.fetch(source_repository, revision_id=revision_id)
 
1184
            else:
 
1185
                result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1118
1186
 
1119
1187
        if source_branch is None:
1120
1188
            # this is for sprouting a bzrdir without a branch; is that
1122
1190
            # Not especially, but it's part of the contract.
1123
1191
            result_branch = result.create_branch()
1124
1192
        else:
1125
 
            # Force NULL revision to avoid using repository before stacking
1126
 
            # is configured.
1127
 
            result_branch = source_branch.sprout(
1128
 
                result, revision_id=_mod_revision.NULL_REVISION)
1129
 
            parent_location = result_branch.get_parent()
 
1193
            result_branch = source_branch.sprout(result,
 
1194
                revision_id=revision_id, repository_policy=repository_policy)
1130
1195
        mutter("created new branch %r" % (result_branch,))
1131
 
        repository_policy.configure_branch(result_branch)
1132
 
        if source_branch is not None:
1133
 
            source_branch.copy_content_into(result_branch, revision_id)
1134
 
            # Override copy_content_into
1135
 
            result_branch.set_parent(parent_location)
1136
1196
 
1137
1197
        # Create/update the result working tree
1138
 
        if isinstance(target_transport, LocalTransport) and (
1139
 
            result_repo is None or result_repo.make_working_trees()):
 
1198
        if (create_tree_if_local and
 
1199
            isinstance(target_transport, local.LocalTransport) and
 
1200
            (result_repo is None or result_repo.make_working_trees())):
1140
1201
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1141
1202
                hardlink=hardlink)
1142
1203
            wt.lock_write()
1155
1216
                basis = wt.basis_tree()
1156
1217
                basis.lock_read()
1157
1218
                subtrees = basis.iter_references()
 
1219
            elif result_branch is not None:
 
1220
                basis = result_branch.basis_tree()
 
1221
                basis.lock_read()
 
1222
                subtrees = basis.iter_references()
1158
1223
            elif source_branch is not None:
1159
1224
                basis = source_branch.basis_tree()
1160
1225
                basis.lock_read()
1175
1240
                    basis.unlock()
1176
1241
        return result
1177
1242
 
 
1243
    def push_branch(self, source, revision_id=None, overwrite=False, 
 
1244
        remember=False, create_prefix=False):
 
1245
        """Push the source branch into this BzrDir."""
 
1246
        br_to = None
 
1247
        # If we can open a branch, use its direct repository, otherwise see
 
1248
        # if there is a repository without a branch.
 
1249
        try:
 
1250
            br_to = self.open_branch()
 
1251
        except errors.NotBranchError:
 
1252
            # Didn't find a branch, can we find a repository?
 
1253
            repository_to = self.find_repository()
 
1254
        else:
 
1255
            # Found a branch, so we must have found a repository
 
1256
            repository_to = br_to.repository
 
1257
 
 
1258
        push_result = PushResult()
 
1259
        push_result.source_branch = source
 
1260
        if br_to is None:
 
1261
            # We have a repository but no branch, copy the revisions, and then
 
1262
            # create a branch.
 
1263
            repository_to.fetch(source.repository, revision_id=revision_id)
 
1264
            br_to = source.clone(self, revision_id=revision_id)
 
1265
            if source.get_push_location() is None or remember:
 
1266
                source.set_push_location(br_to.base)
 
1267
            push_result.stacked_on = None
 
1268
            push_result.branch_push_result = None
 
1269
            push_result.old_revno = None
 
1270
            push_result.old_revid = _mod_revision.NULL_REVISION
 
1271
            push_result.target_branch = br_to
 
1272
            push_result.master_branch = None
 
1273
            push_result.workingtree_updated = False
 
1274
        else:
 
1275
            # We have successfully opened the branch, remember if necessary:
 
1276
            if source.get_push_location() is None or remember:
 
1277
                source.set_push_location(br_to.base)
 
1278
            try:
 
1279
                tree_to = self.open_workingtree()
 
1280
            except errors.NotLocalUrl:
 
1281
                push_result.branch_push_result = source.push(br_to, 
 
1282
                    overwrite, stop_revision=revision_id)
 
1283
                push_result.workingtree_updated = False
 
1284
            except errors.NoWorkingTree:
 
1285
                push_result.branch_push_result = source.push(br_to,
 
1286
                    overwrite, stop_revision=revision_id)
 
1287
                push_result.workingtree_updated = None # Not applicable
 
1288
            else:
 
1289
                tree_to.lock_write()
 
1290
                try:
 
1291
                    push_result.branch_push_result = source.push(
 
1292
                        tree_to.branch, overwrite, stop_revision=revision_id)
 
1293
                    tree_to.update()
 
1294
                finally:
 
1295
                    tree_to.unlock()
 
1296
                push_result.workingtree_updated = True
 
1297
            push_result.old_revno = push_result.branch_push_result.old_revno
 
1298
            push_result.old_revid = push_result.branch_push_result.old_revid
 
1299
            push_result.target_branch = \
 
1300
                push_result.branch_push_result.target_branch
 
1301
        return push_result
 
1302
 
 
1303
 
 
1304
class BzrDirHooks(hooks.Hooks):
 
1305
    """Hooks for BzrDir operations."""
 
1306
 
 
1307
    def __init__(self):
 
1308
        """Create the default hooks."""
 
1309
        hooks.Hooks.__init__(self)
 
1310
        self.create_hook(hooks.HookPoint('pre_open',
 
1311
            "Invoked before attempting to open a BzrDir with the transport "
 
1312
            "that the open will use.", (1, 14), None))
 
1313
 
 
1314
# install the default hooks
 
1315
BzrDir.hooks = BzrDirHooks()
 
1316
 
1178
1317
 
1179
1318
class BzrDirPreSplitOut(BzrDir):
1180
1319
    """A common class for the all-in-one formats."""
1251
1390
        # and that will have set it for us, its only
1252
1391
        # specific uses of create_workingtree in isolation
1253
1392
        # that can do wonky stuff here, and that only
1254
 
        # happens for creating checkouts, which cannot be 
 
1393
        # happens for creating checkouts, which cannot be
1255
1394
        # done on this format anyway. So - acceptable wart.
 
1395
        if hardlink:
 
1396
            warning("can't support hardlinked working trees in %r"
 
1397
                % (self,))
1256
1398
        try:
1257
1399
            result = self.open_workingtree(recommend_upgrade=False)
1258
1400
        except errors.NoSuchFile:
1280
1422
 
1281
1423
    def destroy_workingtree_metadata(self):
1282
1424
        """See BzrDir.destroy_workingtree_metadata."""
1283
 
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
1425
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1284
1426
                                          self)
1285
1427
 
1286
1428
    def get_branch_transport(self, branch_format):
1318
1460
        # if the format is not the same as the system default,
1319
1461
        # an upgrade is needed.
1320
1462
        if format is None:
 
1463
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
 
1464
                % 'needs_format_conversion(format=None)')
1321
1465
            format = BzrDirFormat.get_default_format()
1322
1466
        return not isinstance(self._format, format.__class__)
1323
1467
 
1324
 
    def open_branch(self, unsupported=False):
 
1468
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1325
1469
        """See BzrDir.open_branch."""
1326
1470
        from bzrlib.branch import BzrBranchFormat4
1327
1471
        format = BzrBranchFormat4()
1330
1474
 
1331
1475
    def sprout(self, url, revision_id=None, force_new_repo=False,
1332
1476
               possible_transports=None, accelerator_tree=None,
1333
 
               hardlink=False, stacked=False):
 
1477
               hardlink=False, stacked=False, create_tree_if_local=True,
 
1478
               source_branch=None):
1334
1479
        """See BzrDir.sprout()."""
 
1480
        if source_branch is not None:
 
1481
            my_branch = self.open_branch()
 
1482
            if source_branch.base != my_branch.base:
 
1483
                raise AssertionError(
 
1484
                    "source branch %r is not within %r with branch %r" %
 
1485
                    (source_branch, self, my_branch))
1335
1486
        if stacked:
1336
1487
            raise errors.UnstackableBranchFormat(
1337
1488
                self._format, self.root_transport.base)
 
1489
        if not create_tree_if_local:
 
1490
            raise errors.MustHaveWorkingTree(
 
1491
                self._format, self.root_transport.base)
1338
1492
        from bzrlib.workingtree import WorkingTreeFormat2
1339
1493
        self._make_tail(url)
1340
1494
        result = self._format._initialize_for_clone(url)
1346
1500
            self.open_branch().sprout(result, revision_id=revision_id)
1347
1501
        except errors.NotBranchError:
1348
1502
            pass
 
1503
 
1349
1504
        # we always want a working tree
1350
1505
        WorkingTreeFormat2().initialize(result,
1351
1506
                                        accelerator_tree=accelerator_tree,
1355
1510
 
1356
1511
class BzrDir4(BzrDirPreSplitOut):
1357
1512
    """A .bzr version 4 control object.
1358
 
    
 
1513
 
1359
1514
    This is a deprecated format and may be removed after sept 2006.
1360
1515
    """
1361
1516
 
1365
1520
 
1366
1521
    def needs_format_conversion(self, format=None):
1367
1522
        """Format 4 dirs are always in need of conversion."""
 
1523
        if format is None:
 
1524
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
 
1525
                % 'needs_format_conversion(format=None)')
1368
1526
        return True
1369
1527
 
1370
1528
    def open_repository(self):
1416
1574
 
1417
1575
class BzrDirMeta1(BzrDir):
1418
1576
    """A .bzr meta version 1 control object.
1419
 
    
1420
 
    This is the first control object where the 
 
1577
 
 
1578
    This is the first control object where the
1421
1579
    individual aspects are really split out: there are separate repository,
1422
1580
    workingtree and branch subdirectories and any subset of the three can be
1423
1581
    present within a BzrDir.
1483
1641
 
1484
1642
    def get_branch_transport(self, branch_format):
1485
1643
        """See BzrDir.get_branch_transport()."""
 
1644
        # XXX: this shouldn't implicitly create the directory if it's just
 
1645
        # promising to get a transport -- mbp 20090727
1486
1646
        if branch_format is None:
1487
1647
            return self.transport.clone('branch')
1488
1648
        try:
1526
1686
    def needs_format_conversion(self, format=None):
1527
1687
        """See BzrDir.needs_format_conversion()."""
1528
1688
        if format is None:
 
1689
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
 
1690
                % 'needs_format_conversion(format=None)')
 
1691
        if format is None:
1529
1692
            format = BzrDirFormat.get_default_format()
1530
1693
        if not isinstance(self._format, format.__class__):
1531
1694
            # it is not a meta dir format, conversion is needed.
1555
1718
            pass
1556
1719
        return False
1557
1720
 
1558
 
    def open_branch(self, unsupported=False):
 
1721
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1559
1722
        """See BzrDir.open_branch."""
1560
1723
        format = self.find_branch_format()
1561
1724
        self._check_supported(format, unsupported)
1562
 
        return format.open(self, _found=True)
 
1725
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1563
1726
 
1564
1727
    def open_repository(self, unsupported=False):
1565
1728
        """See BzrDir.open_repository."""
1579
1742
        return format.open(self, _found=True)
1580
1743
 
1581
1744
    def _get_config(self):
1582
 
        return config.BzrDirConfig(self.transport)
 
1745
        return config.TransportConfig(self.transport, 'control.conf')
1583
1746
 
1584
1747
 
1585
1748
class BzrDirFormat(object):
1590
1753
     * a format string,
1591
1754
     * an open routine.
1592
1755
 
1593
 
    Formats are placed in a dict by their format string for reference 
 
1756
    Formats are placed in a dict by their format string for reference
1594
1757
    during bzrdir opening. These should be subclasses of BzrDirFormat
1595
1758
    for consistency.
1596
1759
 
1597
1760
    Once a format is deprecated, just deprecate the initialize and open
1598
 
    methods on the format class. Do not deprecate the object, as the 
 
1761
    methods on the format class. Do not deprecate the object, as the
1599
1762
    object will be created every system load.
1600
1763
    """
1601
1764
 
1607
1770
 
1608
1771
    _control_formats = []
1609
1772
    """The registered control formats - .bzr, ....
1610
 
    
 
1773
 
1611
1774
    This is a list of BzrDirFormat objects.
1612
1775
    """
1613
1776
 
1672
1835
        current default format. In the case of plugins we can/should provide
1673
1836
        some means for them to extend the range of returnable converters.
1674
1837
 
1675
 
        :param format: Optional format to override the default format of the 
 
1838
        :param format: Optional format to override the default format of the
1676
1839
                       library.
1677
1840
        """
1678
1841
        raise NotImplementedError(self.get_converter)
1679
1842
 
1680
1843
    def initialize(self, url, possible_transports=None):
1681
1844
        """Create a bzr control dir at this url and return an opened copy.
1682
 
        
 
1845
 
 
1846
        While not deprecated, this method is very specific and its use will
 
1847
        lead to many round trips to setup a working environment. See
 
1848
        initialize_on_transport_ex for a [nearly] all-in-one method.
 
1849
 
1683
1850
        Subclasses should typically override initialize_on_transport
1684
1851
        instead of this method.
1685
1852
        """
1688
1855
 
1689
1856
    def initialize_on_transport(self, transport):
1690
1857
        """Initialize a new bzrdir in the base directory of a Transport."""
1691
 
        # Since we don't have a .bzr directory, inherit the
 
1858
        try:
 
1859
            # can we hand off the request to the smart server rather than using
 
1860
            # vfs calls?
 
1861
            client_medium = transport.get_smart_medium()
 
1862
        except errors.NoSmartMedium:
 
1863
            return self._initialize_on_transport_vfs(transport)
 
1864
        else:
 
1865
            # Current RPC's only know how to create bzr metadir1 instances, so
 
1866
            # we still delegate to vfs methods if the requested format is not a
 
1867
            # metadir1
 
1868
            if type(self) != BzrDirMetaFormat1:
 
1869
                return self._initialize_on_transport_vfs(transport)
 
1870
            remote_format = RemoteBzrDirFormat()
 
1871
            self._supply_sub_formats_to(remote_format)
 
1872
            return remote_format.initialize_on_transport(transport)
 
1873
 
 
1874
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
1875
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
1876
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
1877
        shared_repo=False, vfs_only=False):
 
1878
        """Create this format on transport.
 
1879
 
 
1880
        The directory to initialize will be created.
 
1881
 
 
1882
        :param force_new_repo: Do not use a shared repository for the target,
 
1883
                               even if one is available.
 
1884
        :param create_prefix: Create any missing directories leading up to
 
1885
            to_transport.
 
1886
        :param use_existing_dir: Use an existing directory if one exists.
 
1887
        :param stacked_on: A url to stack any created branch on, None to follow
 
1888
            any target stacking policy.
 
1889
        :param stack_on_pwd: If stack_on is relative, the location it is
 
1890
            relative to.
 
1891
        :param repo_format_name: If non-None, a repository will be
 
1892
            made-or-found. Should none be found, or if force_new_repo is True
 
1893
            the repo_format_name is used to select the format of repository to
 
1894
            create.
 
1895
        :param make_working_trees: Control the setting of make_working_trees
 
1896
            for a new shared repository when one is made. None to use whatever
 
1897
            default the format has.
 
1898
        :param shared_repo: Control whether made repositories are shared or
 
1899
            not.
 
1900
        :param vfs_only: If True do not attempt to use a smart server
 
1901
        :return: repo, bzrdir, require_stacking, repository_policy. repo is
 
1902
            None if none was created or found, bzrdir is always valid.
 
1903
            require_stacking is the result of examining the stacked_on
 
1904
            parameter and any stacking policy found for the target.
 
1905
        """
 
1906
        if not vfs_only:
 
1907
            # Try to hand off to a smart server 
 
1908
            try:
 
1909
                client_medium = transport.get_smart_medium()
 
1910
            except errors.NoSmartMedium:
 
1911
                pass
 
1912
            else:
 
1913
                # TODO: lookup the local format from a server hint.
 
1914
                remote_dir_format = RemoteBzrDirFormat()
 
1915
                remote_dir_format._network_name = self.network_name()
 
1916
                self._supply_sub_formats_to(remote_dir_format)
 
1917
                return remote_dir_format.initialize_on_transport_ex(transport,
 
1918
                    use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
1919
                    force_new_repo=force_new_repo, stacked_on=stacked_on,
 
1920
                    stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
1921
                    make_working_trees=make_working_trees, shared_repo=shared_repo)
 
1922
        # XXX: Refactor the create_prefix/no_create_prefix code into a
 
1923
        #      common helper function
 
1924
        # The destination may not exist - if so make it according to policy.
 
1925
        def make_directory(transport):
 
1926
            transport.mkdir('.')
 
1927
            return transport
 
1928
        def redirected(transport, e, redirection_notice):
 
1929
            note(redirection_notice)
 
1930
            return transport._redirected_to(e.source, e.target)
 
1931
        try:
 
1932
            transport = do_catching_redirections(make_directory, transport,
 
1933
                redirected)
 
1934
        except errors.FileExists:
 
1935
            if not use_existing_dir:
 
1936
                raise
 
1937
        except errors.NoSuchFile:
 
1938
            if not create_prefix:
 
1939
                raise
 
1940
            transport.create_prefix()
 
1941
 
 
1942
        require_stacking = (stacked_on is not None)
 
1943
        # Now the target directory exists, but doesn't have a .bzr
 
1944
        # directory. So we need to create it, along with any work to create
 
1945
        # all of the dependent branches, etc.
 
1946
 
 
1947
        result = self.initialize_on_transport(transport)
 
1948
        if repo_format_name:
 
1949
            try:
 
1950
                # use a custom format
 
1951
                result._format.repository_format = \
 
1952
                    repository.network_format_registry.get(repo_format_name)
 
1953
            except AttributeError:
 
1954
                # The format didn't permit it to be set.
 
1955
                pass
 
1956
            # A repository is desired, either in-place or shared.
 
1957
            repository_policy = result.determine_repository_policy(
 
1958
                force_new_repo, stacked_on, stack_on_pwd,
 
1959
                require_stacking=require_stacking)
 
1960
            result_repo, is_new_repo = repository_policy.acquire_repository(
 
1961
                make_working_trees, shared_repo)
 
1962
            if not require_stacking and repository_policy._require_stacking:
 
1963
                require_stacking = True
 
1964
                result._format.require_stacking()
 
1965
            result_repo.lock_write()
 
1966
        else:
 
1967
            result_repo = None
 
1968
            repository_policy = None
 
1969
        return result_repo, result, require_stacking, repository_policy
 
1970
 
 
1971
    def _initialize_on_transport_vfs(self, transport):
 
1972
        """Initialize a new bzrdir using VFS calls.
 
1973
 
 
1974
        :param transport: The transport to create the .bzr directory in.
 
1975
        :return: A
 
1976
        """
 
1977
        # Since we are creating a .bzr directory, inherit the
1692
1978
        # mode from the root directory
1693
1979
        temp_control = lockable_files.LockableFiles(transport,
1694
1980
                            '', lockable_files.TransportLock)
1696
1982
                                      # FIXME: RBC 20060121 don't peek under
1697
1983
                                      # the covers
1698
1984
                                      mode=temp_control._dir_mode)
1699
 
        if sys.platform == 'win32' and isinstance(transport, LocalTransport):
 
1985
        if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
1700
1986
            win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1701
1987
        file_mode = temp_control._file_mode
1702
1988
        del temp_control
1724
2010
        """Is this format supported?
1725
2011
 
1726
2012
        Supported formats must be initializable and openable.
1727
 
        Unsupported formats may not support initialization or committing or 
 
2013
        Unsupported formats may not support initialization or committing or
1728
2014
        some other features depending on the reason for not being supported.
1729
2015
        """
1730
2016
        return True
1731
2017
 
 
2018
    def network_name(self):
 
2019
        """A simple byte string uniquely identifying this format for RPC calls.
 
2020
 
 
2021
        Bzr control formats use thir disk format string to identify the format
 
2022
        over the wire. Its possible that other control formats have more
 
2023
        complex detection requirements, so we permit them to use any unique and
 
2024
        immutable string they desire.
 
2025
        """
 
2026
        raise NotImplementedError(self.network_name)
 
2027
 
1732
2028
    def same_model(self, target_format):
1733
 
        return (self.repository_format.rich_root_data == 
 
2029
        return (self.repository_format.rich_root_data ==
1734
2030
            target_format.rich_root_data)
1735
2031
 
1736
2032
    @classmethod
1737
2033
    def known_formats(klass):
1738
2034
        """Return all the known formats.
1739
 
        
 
2035
 
1740
2036
        Concrete formats should override _known_formats.
1741
2037
        """
1742
 
        # There is double indirection here to make sure that control 
1743
 
        # formats used by more than one dir format will only be probed 
 
2038
        # There is double indirection here to make sure that control
 
2039
        # formats used by more than one dir format will only be probed
1744
2040
        # once. This can otherwise be quite expensive for remote connections.
1745
2041
        result = set()
1746
2042
        for format in klass._control_formats:
1747
2043
            result.update(format._known_formats())
1748
2044
        return result
1749
 
    
 
2045
 
1750
2046
    @classmethod
1751
2047
    def _known_formats(klass):
1752
2048
        """Return the known format instances for this control format."""
1754
2050
 
1755
2051
    def open(self, transport, _found=False):
1756
2052
        """Return an instance of this format for the dir transport points at.
1757
 
        
 
2053
 
1758
2054
        _found is a private parameter, do not use it.
1759
2055
        """
1760
2056
        if not _found:
1761
2057
            found_format = BzrDirFormat.find_format(transport)
1762
2058
            if not isinstance(found_format, self.__class__):
1763
2059
                raise AssertionError("%s was asked to open %s, but it seems to need "
1764
 
                        "format %s" 
 
2060
                        "format %s"
1765
2061
                        % (self, transport, found_format))
 
2062
            # Allow subclasses - use the found format.
 
2063
            self._supply_sub_formats_to(found_format)
 
2064
            return found_format._open(transport)
1766
2065
        return self._open(transport)
1767
2066
 
1768
2067
    def _open(self, transport):
1776
2075
    @classmethod
1777
2076
    def register_format(klass, format):
1778
2077
        klass._formats[format.get_format_string()] = format
 
2078
        # bzr native formats have a network name of their format string.
 
2079
        network_format_registry.register(format.get_format_string(), format.__class__)
1779
2080
 
1780
2081
    @classmethod
1781
2082
    def register_control_format(klass, format):
1782
2083
        """Register a format that does not use '.bzr' for its control dir.
1783
2084
 
1784
2085
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1785
 
        which BzrDirFormat can inherit from, and renamed to register_format 
 
2086
        which BzrDirFormat can inherit from, and renamed to register_format
1786
2087
        there. It has been done without that for now for simplicity of
1787
2088
        implementation.
1788
2089
        """
1806
2107
 
1807
2108
    def __str__(self):
1808
2109
        # Trim the newline
1809
 
        return self.get_format_string().rstrip()
 
2110
        return self.get_format_description().rstrip()
 
2111
 
 
2112
    def _supply_sub_formats_to(self, other_format):
 
2113
        """Give other_format the same values for sub formats as this has.
 
2114
 
 
2115
        This method is expected to be used when parameterising a
 
2116
        RemoteBzrDirFormat instance with the parameters from a
 
2117
        BzrDirMetaFormat1 instance.
 
2118
 
 
2119
        :param other_format: other_format is a format which should be
 
2120
            compatible with whatever sub formats are supported by self.
 
2121
        :return: None.
 
2122
        """
1810
2123
 
1811
2124
    @classmethod
1812
2125
    def unregister_format(klass, format):
1844
2157
        """See BzrDirFormat.get_converter()."""
1845
2158
        # there is one and only one upgrade path here.
1846
2159
        return ConvertBzrDir4To5()
1847
 
        
 
2160
 
1848
2161
    def initialize_on_transport(self, transport):
1849
2162
        """Format 4 branches cannot be created."""
1850
2163
        raise errors.UninitializableFormat(self)
1853
2166
        """Format 4 is not supported.
1854
2167
 
1855
2168
        It is not supported because the model changed from 4 to 5 and the
1856
 
        conversion logic is expensive - so doing it on the fly was not 
 
2169
        conversion logic is expensive - so doing it on the fly was not
1857
2170
        feasible.
1858
2171
        """
1859
2172
        return False
1860
2173
 
 
2174
    def network_name(self):
 
2175
        return self.get_format_string()
 
2176
 
1861
2177
    def _open(self, transport):
1862
2178
        """See BzrDirFormat._open."""
1863
2179
        return BzrDir4(transport, self)
1869
2185
    repository_format = property(__return_repository_format)
1870
2186
 
1871
2187
 
1872
 
class BzrDirFormat5(BzrDirFormat):
 
2188
class BzrDirFormatAllInOne(BzrDirFormat):
 
2189
    """Common class for formats before meta-dirs."""
 
2190
 
 
2191
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
2192
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
2193
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
2194
        shared_repo=False):
 
2195
        """See BzrDirFormat.initialize_on_transport_ex."""
 
2196
        require_stacking = (stacked_on is not None)
 
2197
        # Format 5 cannot stack, but we've been asked to - actually init
 
2198
        # a Meta1Dir
 
2199
        if require_stacking:
 
2200
            format = BzrDirMetaFormat1()
 
2201
            return format.initialize_on_transport_ex(transport,
 
2202
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
2203
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
2204
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
2205
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
2206
        return BzrDirFormat.initialize_on_transport_ex(self, transport,
 
2207
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
2208
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
2209
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
2210
            make_working_trees=make_working_trees, shared_repo=shared_repo)
 
2211
 
 
2212
 
 
2213
class BzrDirFormat5(BzrDirFormatAllInOne):
1873
2214
    """Bzr control format 5.
1874
2215
 
1875
2216
    This format is a combined format for working tree, branch and repository.
1876
2217
    It has:
1877
 
     - Format 2 working trees [always] 
1878
 
     - Format 4 branches [always] 
 
2218
     - Format 2 working trees [always]
 
2219
     - Format 4 branches [always]
1879
2220
     - Format 5 repositories [always]
1880
2221
       Unhashed stores in the repository.
1881
2222
    """
1901
2242
 
1902
2243
    def _initialize_for_clone(self, url):
1903
2244
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1904
 
        
 
2245
 
1905
2246
    def initialize_on_transport(self, transport, _cloning=False):
1906
2247
        """Format 5 dirs always have working tree, branch and repository.
1907
 
        
 
2248
 
1908
2249
        Except when they are being cloned.
1909
2250
        """
1910
2251
        from bzrlib.branch import BzrBranchFormat4
1916
2257
            result._init_workingtree()
1917
2258
        return result
1918
2259
 
 
2260
    def network_name(self):
 
2261
        return self.get_format_string()
 
2262
 
1919
2263
    def _open(self, transport):
1920
2264
        """See BzrDirFormat._open."""
1921
2265
        return BzrDir5(transport, self)
1927
2271
    repository_format = property(__return_repository_format)
1928
2272
 
1929
2273
 
1930
 
class BzrDirFormat6(BzrDirFormat):
 
2274
class BzrDirFormat6(BzrDirFormatAllInOne):
1931
2275
    """Bzr control format 6.
1932
2276
 
1933
2277
    This format is a combined format for working tree, branch and repository.
1934
2278
    It has:
1935
 
     - Format 2 working trees [always] 
1936
 
     - Format 4 branches [always] 
 
2279
     - Format 2 working trees [always]
 
2280
     - Format 4 branches [always]
1937
2281
     - Format 6 repositories [always]
1938
2282
    """
1939
2283
 
1955
2299
        """See BzrDirFormat.get_converter()."""
1956
2300
        # there is one and only one upgrade path here.
1957
2301
        return ConvertBzrDir6ToMeta()
1958
 
        
 
2302
 
1959
2303
    def _initialize_for_clone(self, url):
1960
2304
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1961
2305
 
1962
2306
    def initialize_on_transport(self, transport, _cloning=False):
1963
2307
        """Format 6 dirs always have working tree, branch and repository.
1964
 
        
 
2308
 
1965
2309
        Except when they are being cloned.
1966
2310
        """
1967
2311
        from bzrlib.branch import BzrBranchFormat4
1973
2317
            result._init_workingtree()
1974
2318
        return result
1975
2319
 
 
2320
    def network_name(self):
 
2321
        return self.get_format_string()
 
2322
 
1976
2323
    def _open(self, transport):
1977
2324
        """See BzrDirFormat._open."""
1978
2325
        return BzrDir6(transport, self)
2000
2347
    def __init__(self):
2001
2348
        self._workingtree_format = None
2002
2349
        self._branch_format = None
 
2350
        self._repository_format = None
2003
2351
 
2004
2352
    def __eq__(self, other):
2005
2353
        if other.__class__ is not self.__class__:
2022
2370
    def set_branch_format(self, format):
2023
2371
        self._branch_format = format
2024
2372
 
 
2373
    def require_stacking(self, stack_on=None, possible_transports=None,
 
2374
            _skip_repo=False):
 
2375
        """We have a request to stack, try to ensure the formats support it.
 
2376
 
 
2377
        :param stack_on: If supplied, it is the URL to a branch that we want to
 
2378
            stack on. Check to see if that format supports stacking before
 
2379
            forcing an upgrade.
 
2380
        """
 
2381
        # Stacking is desired. requested by the target, but does the place it
 
2382
        # points at support stacking? If it doesn't then we should
 
2383
        # not implicitly upgrade. We check this here.
 
2384
        new_repo_format = None
 
2385
        new_branch_format = None
 
2386
 
 
2387
        # a bit of state for get_target_branch so that we don't try to open it
 
2388
        # 2 times, for both repo *and* branch
 
2389
        target = [None, False, None] # target_branch, checked, upgrade anyway
 
2390
        def get_target_branch():
 
2391
            if target[1]:
 
2392
                # We've checked, don't check again
 
2393
                return target
 
2394
            if stack_on is None:
 
2395
                # No target format, that means we want to force upgrading
 
2396
                target[:] = [None, True, True]
 
2397
                return target
 
2398
            try:
 
2399
                target_dir = BzrDir.open(stack_on,
 
2400
                    possible_transports=possible_transports)
 
2401
            except errors.NotBranchError:
 
2402
                # Nothing there, don't change formats
 
2403
                target[:] = [None, True, False]
 
2404
                return target
 
2405
            except errors.JailBreak:
 
2406
                # JailBreak, JFDI and upgrade anyway
 
2407
                target[:] = [None, True, True]
 
2408
                return target
 
2409
            try:
 
2410
                target_branch = target_dir.open_branch()
 
2411
            except errors.NotBranchError:
 
2412
                # No branch, don't upgrade formats
 
2413
                target[:] = [None, True, False]
 
2414
                return target
 
2415
            target[:] = [target_branch, True, False]
 
2416
            return target
 
2417
 
 
2418
        if (not _skip_repo and
 
2419
                 not self.repository_format.supports_external_lookups):
 
2420
            # We need to upgrade the Repository.
 
2421
            target_branch, _, do_upgrade = get_target_branch()
 
2422
            if target_branch is None:
 
2423
                # We don't have a target branch, should we upgrade anyway?
 
2424
                if do_upgrade:
 
2425
                    # stack_on is inaccessible, JFDI.
 
2426
                    # TODO: bad monkey, hard-coded formats...
 
2427
                    if self.repository_format.rich_root_data:
 
2428
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2429
                    else:
 
2430
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
 
2431
            else:
 
2432
                # If the target already supports stacking, then we know the
 
2433
                # project is already able to use stacking, so auto-upgrade
 
2434
                # for them
 
2435
                new_repo_format = target_branch.repository._format
 
2436
                if not new_repo_format.supports_external_lookups:
 
2437
                    # target doesn't, source doesn't, so don't auto upgrade
 
2438
                    # repo
 
2439
                    new_repo_format = None
 
2440
            if new_repo_format is not None:
 
2441
                self.repository_format = new_repo_format
 
2442
                note('Source repository format does not support stacking,'
 
2443
                     ' using format:\n  %s',
 
2444
                     new_repo_format.get_format_description())
 
2445
 
 
2446
        if not self.get_branch_format().supports_stacking():
 
2447
            # We just checked the repo, now lets check if we need to
 
2448
            # upgrade the branch format
 
2449
            target_branch, _, do_upgrade = get_target_branch()
 
2450
            if target_branch is None:
 
2451
                if do_upgrade:
 
2452
                    # TODO: bad monkey, hard-coded formats...
 
2453
                    new_branch_format = branch.BzrBranchFormat7()
 
2454
            else:
 
2455
                new_branch_format = target_branch._format
 
2456
                if not new_branch_format.supports_stacking():
 
2457
                    new_branch_format = None
 
2458
            if new_branch_format is not None:
 
2459
                # Does support stacking, use its format.
 
2460
                self.set_branch_format(new_branch_format)
 
2461
                note('Source branch format does not support stacking,'
 
2462
                     ' using format:\n  %s',
 
2463
                     new_branch_format.get_format_description())
 
2464
 
2025
2465
    def get_converter(self, format=None):
2026
2466
        """See BzrDirFormat.get_converter()."""
2027
2467
        if format is None:
2039
2479
        """See BzrDirFormat.get_format_description()."""
2040
2480
        return "Meta directory format 1"
2041
2481
 
 
2482
    def network_name(self):
 
2483
        return self.get_format_string()
 
2484
 
2042
2485
    def _open(self, transport):
2043
2486
        """See BzrDirFormat._open."""
2044
 
        return BzrDirMeta1(transport, self)
 
2487
        # Create a new format instance because otherwise initialisation of new
 
2488
        # metadirs share the global default format object leading to alias
 
2489
        # problems.
 
2490
        format = BzrDirMetaFormat1()
 
2491
        self._supply_sub_formats_to(format)
 
2492
        return BzrDirMeta1(transport, format)
2045
2493
 
2046
2494
    def __return_repository_format(self):
2047
2495
        """Circular import protection."""
2048
 
        if getattr(self, '_repository_format', None):
 
2496
        if self._repository_format:
2049
2497
            return self._repository_format
2050
2498
        from bzrlib.repository import RepositoryFormat
2051
2499
        return RepositoryFormat.get_default_format()
2052
2500
 
2053
 
    def __set_repository_format(self, value):
 
2501
    def _set_repository_format(self, value):
2054
2502
        """Allow changing the repository format for metadir formats."""
2055
2503
        self._repository_format = value
2056
2504
 
2057
 
    repository_format = property(__return_repository_format, __set_repository_format)
 
2505
    repository_format = property(__return_repository_format,
 
2506
        _set_repository_format)
 
2507
 
 
2508
    def _supply_sub_formats_to(self, other_format):
 
2509
        """Give other_format the same values for sub formats as this has.
 
2510
 
 
2511
        This method is expected to be used when parameterising a
 
2512
        RemoteBzrDirFormat instance with the parameters from a
 
2513
        BzrDirMetaFormat1 instance.
 
2514
 
 
2515
        :param other_format: other_format is a format which should be
 
2516
            compatible with whatever sub formats are supported by self.
 
2517
        :return: None.
 
2518
        """
 
2519
        if getattr(self, '_repository_format', None) is not None:
 
2520
            other_format.repository_format = self.repository_format
 
2521
        if self._branch_format is not None:
 
2522
            other_format._branch_format = self._branch_format
 
2523
        if self._workingtree_format is not None:
 
2524
            other_format.workingtree_format = self.workingtree_format
2058
2525
 
2059
2526
    def __get_workingtree_format(self):
2060
2527
        if self._workingtree_format is None:
2069
2536
                                  __set_workingtree_format)
2070
2537
 
2071
2538
 
 
2539
network_format_registry = registry.FormatRegistry()
 
2540
"""Registry of formats indexed by their network name.
 
2541
 
 
2542
The network name for a BzrDirFormat is an identifier that can be used when
 
2543
referring to formats with smart server operations. See
 
2544
BzrDirFormat.network_name() for more detail.
 
2545
"""
 
2546
 
 
2547
 
2072
2548
# Register bzr control format
2073
2549
BzrDirFormat.register_control_format(BzrDirFormat)
2074
2550
 
2106
2582
        self.absent_revisions = set()
2107
2583
        self.text_count = 0
2108
2584
        self.revisions = {}
2109
 
        
 
2585
 
2110
2586
    def convert(self, to_convert, pb):
2111
2587
        """See Converter.convert()."""
2112
2588
        self.bzrdir = to_convert
2113
2589
        self.pb = pb
2114
2590
        self.pb.note('starting upgrade from format 4 to 5')
2115
 
        if isinstance(self.bzrdir.transport, LocalTransport):
 
2591
        if isinstance(self.bzrdir.transport, local.LocalTransport):
2116
2592
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2117
2593
        self._convert_to_weaves()
2118
2594
        return BzrDir.open(self.bzrdir.root_transport.base)
2218
2694
                revision_store.add_lines(key, None, osutils.split_lines(text))
2219
2695
        finally:
2220
2696
            self.pb.clear()
2221
 
            
 
2697
 
2222
2698
    def _load_one_rev(self, rev_id):
2223
2699
        """Load a revision object into memory.
2224
2700
 
2298
2774
        text_changed = False
2299
2775
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2300
2776
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2301
 
        # XXX: Note that this is unordered - and this is tolerable because 
 
2777
        # XXX: Note that this is unordered - and this is tolerable because
2302
2778
        # the previous code was also unordered.
2303
2779
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2304
2780
            in heads)
2305
2781
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2306
2782
        del ie.text_id
2307
2783
 
2308
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
2309
 
    def get_parents(self, revision_ids):
2310
 
        for revision_id in revision_ids:
2311
 
            yield self.revisions[revision_id].parent_ids
2312
 
 
2313
2784
    def get_parent_map(self, revision_ids):
2314
 
        """See graph._StackedParentsProvider.get_parent_map"""
 
2785
        """See graph.StackedParentsProvider.get_parent_map"""
2315
2786
        return dict((revision_id, self.revisions[revision_id])
2316
2787
                    for revision_id in revision_ids
2317
2788
                     if revision_id in self.revisions)
2321
2792
        # a call to:. This needs the path figured out. rather than a work_tree
2322
2793
        # a v4 revision_tree can be given, or something that looks enough like
2323
2794
        # one to give the file content to the entry if it needs it.
2324
 
        # and we need something that looks like a weave store for snapshot to 
 
2795
        # and we need something that looks like a weave store for snapshot to
2325
2796
        # save against.
2326
2797
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2327
2798
        if len(previous_revisions) == 1:
2443
2914
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2444
2915
        self.make_lock('repository')
2445
2916
        # we hard code the formats here because we are converting into
2446
 
        # the meta format. The meta format upgrader can take this to a 
 
2917
        # the meta format. The meta format upgrader can take this to a
2447
2918
        # future format within each component.
2448
2919
        self.put_format('repository', RepositoryFormat7())
2449
2920
        for entry in repository_names:
2564
3035
            while old != new:
2565
3036
                if (old == _mod_branch.BzrBranchFormat5 and
2566
3037
                    new in (_mod_branch.BzrBranchFormat6,
2567
 
                        _mod_branch.BzrBranchFormat7)):
 
3038
                        _mod_branch.BzrBranchFormat7,
 
3039
                        _mod_branch.BzrBranchFormat8)):
2568
3040
                    branch_converter = _mod_branch.Converter5to6()
2569
3041
                elif (old == _mod_branch.BzrBranchFormat6 and
2570
 
                    new == _mod_branch.BzrBranchFormat7):
 
3042
                    new in (_mod_branch.BzrBranchFormat7,
 
3043
                            _mod_branch.BzrBranchFormat8)):
2571
3044
                    branch_converter = _mod_branch.Converter6to7()
 
3045
                elif (old == _mod_branch.BzrBranchFormat7 and
 
3046
                      new is _mod_branch.BzrBranchFormat8):
 
3047
                    branch_converter = _mod_branch.Converter7to8()
2572
3048
                else:
2573
 
                    raise errors.BadConversionTarget("No converter", new)
 
3049
                    raise errors.BadConversionTarget("No converter", new,
 
3050
                        branch._format)
2574
3051
                branch_converter.convert(branch)
2575
3052
                branch = self.bzrdir.open_branch()
2576
3053
                old = branch._format.__class__
2582
3059
            # TODO: conversions of Branch and Tree should be done by
2583
3060
            # InterXFormat lookups
2584
3061
            if (isinstance(tree, workingtree.WorkingTree3) and
2585
 
                not isinstance(tree, workingtree_4.WorkingTree4) and
 
3062
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2586
3063
                isinstance(self.target_format.workingtree_format,
2587
 
                    workingtree_4.WorkingTreeFormat4)):
 
3064
                    workingtree_4.DirStateWorkingTreeFormat)):
2588
3065
                workingtree_4.Converter3to4().convert(tree)
 
3066
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
 
3067
                not isinstance(tree, workingtree_4.WorkingTree5) and
 
3068
                isinstance(self.target_format.workingtree_format,
 
3069
                    workingtree_4.WorkingTreeFormat5)):
 
3070
                workingtree_4.Converter4to5().convert(tree)
 
3071
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
 
3072
                not isinstance(tree, workingtree_4.WorkingTree6) and
 
3073
                isinstance(self.target_format.workingtree_format,
 
3074
                    workingtree_4.WorkingTreeFormat6)):
 
3075
                workingtree_4.Converter4or5to6().convert(tree)
2589
3076
        return to_convert
2590
3077
 
2591
3078
 
2592
 
# This is not in remote.py because it's small, and needs to be registered.
2593
 
# Putting it in remote.py creates a circular import problem.
 
3079
# This is not in remote.py because it's relatively small, and needs to be
 
3080
# registered. Putting it in remote.py creates a circular import problem.
2594
3081
# we can make it a lazy object if the control formats is turned into something
2595
3082
# like a registry.
2596
3083
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2597
3084
    """Format representing bzrdirs accessed via a smart server"""
2598
3085
 
 
3086
    def __init__(self):
 
3087
        BzrDirMetaFormat1.__init__(self)
 
3088
        self._network_name = None
 
3089
 
2599
3090
    def get_format_description(self):
2600
3091
        return 'bzr remote bzrdir'
2601
 
    
 
3092
 
 
3093
    def get_format_string(self):
 
3094
        raise NotImplementedError(self.get_format_string)
 
3095
 
 
3096
    def network_name(self):
 
3097
        if self._network_name:
 
3098
            return self._network_name
 
3099
        else:
 
3100
            raise AssertionError("No network name set.")
 
3101
 
2602
3102
    @classmethod
2603
3103
    def probe_transport(klass, transport):
2604
3104
        """Return a RemoteBzrDirFormat object if it looks possible."""
2633
3133
            return local_dir_format.initialize_on_transport(transport)
2634
3134
        client = _SmartClient(client_medium)
2635
3135
        path = client.remote_path_from_transport(transport)
2636
 
        response = client.call('BzrDirFormat.initialize', path)
 
3136
        try:
 
3137
            response = client.call('BzrDirFormat.initialize', path)
 
3138
        except errors.ErrorFromSmartServer, err:
 
3139
            remote._translate_error(err, path=path)
2637
3140
        if response[0] != 'ok':
2638
3141
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2639
 
        return remote.RemoteBzrDir(transport)
 
3142
        format = RemoteBzrDirFormat()
 
3143
        self._supply_sub_formats_to(format)
 
3144
        return remote.RemoteBzrDir(transport, format)
 
3145
 
 
3146
    def parse_NoneTrueFalse(self, arg):
 
3147
        if not arg:
 
3148
            return None
 
3149
        if arg == 'False':
 
3150
            return False
 
3151
        if arg == 'True':
 
3152
            return True
 
3153
        raise AssertionError("invalid arg %r" % arg)
 
3154
 
 
3155
    def _serialize_NoneTrueFalse(self, arg):
 
3156
        if arg is False:
 
3157
            return 'False'
 
3158
        if arg:
 
3159
            return 'True'
 
3160
        return ''
 
3161
 
 
3162
    def _serialize_NoneString(self, arg):
 
3163
        return arg or ''
 
3164
 
 
3165
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
3166
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
3167
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
3168
        shared_repo=False):
 
3169
        try:
 
3170
            # hand off the request to the smart server
 
3171
            client_medium = transport.get_smart_medium()
 
3172
        except errors.NoSmartMedium:
 
3173
            do_vfs = True
 
3174
        else:
 
3175
            # Decline to open it if the server doesn't support our required
 
3176
            # version (3) so that the VFS-based transport will do it.
 
3177
            if client_medium.should_probe():
 
3178
                try:
 
3179
                    server_version = client_medium.protocol_version()
 
3180
                    if server_version != '2':
 
3181
                        do_vfs = True
 
3182
                    else:
 
3183
                        do_vfs = False
 
3184
                except errors.SmartProtocolError:
 
3185
                    # Apparently there's no usable smart server there, even though
 
3186
                    # the medium supports the smart protocol.
 
3187
                    do_vfs = True
 
3188
            else:
 
3189
                do_vfs = False
 
3190
        if not do_vfs:
 
3191
            client = _SmartClient(client_medium)
 
3192
            path = client.remote_path_from_transport(transport)
 
3193
            if client_medium._is_remote_before((1, 16)):
 
3194
                do_vfs = True
 
3195
        if do_vfs:
 
3196
            # TODO: lookup the local format from a server hint.
 
3197
            local_dir_format = BzrDirMetaFormat1()
 
3198
            self._supply_sub_formats_to(local_dir_format)
 
3199
            return local_dir_format.initialize_on_transport_ex(transport,
 
3200
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3201
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3202
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3203
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3204
                vfs_only=True)
 
3205
        return self._initialize_on_transport_ex_rpc(client, path, transport,
 
3206
            use_existing_dir, create_prefix, force_new_repo, stacked_on,
 
3207
            stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
 
3208
 
 
3209
    def _initialize_on_transport_ex_rpc(self, client, path, transport,
 
3210
        use_existing_dir, create_prefix, force_new_repo, stacked_on,
 
3211
        stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
 
3212
        args = []
 
3213
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
 
3214
        args.append(self._serialize_NoneTrueFalse(create_prefix))
 
3215
        args.append(self._serialize_NoneTrueFalse(force_new_repo))
 
3216
        args.append(self._serialize_NoneString(stacked_on))
 
3217
        # stack_on_pwd is often/usually our transport
 
3218
        if stack_on_pwd:
 
3219
            try:
 
3220
                stack_on_pwd = transport.relpath(stack_on_pwd)
 
3221
                if not stack_on_pwd:
 
3222
                    stack_on_pwd = '.'
 
3223
            except errors.PathNotChild:
 
3224
                pass
 
3225
        args.append(self._serialize_NoneString(stack_on_pwd))
 
3226
        args.append(self._serialize_NoneString(repo_format_name))
 
3227
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
 
3228
        args.append(self._serialize_NoneTrueFalse(shared_repo))
 
3229
        if self._network_name is None:
 
3230
            self._network_name = \
 
3231
            BzrDirFormat.get_default_format().network_name()
 
3232
        try:
 
3233
            response = client.call('BzrDirFormat.initialize_ex_1.16',
 
3234
                self.network_name(), path, *args)
 
3235
        except errors.UnknownSmartMethod:
 
3236
            client._medium._remember_remote_is_before((1,16))
 
3237
            local_dir_format = BzrDirMetaFormat1()
 
3238
            self._supply_sub_formats_to(local_dir_format)
 
3239
            return local_dir_format.initialize_on_transport_ex(transport,
 
3240
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3241
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3242
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3243
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3244
                vfs_only=True)
 
3245
        except errors.ErrorFromSmartServer, err:
 
3246
            remote._translate_error(err, path=path)
 
3247
        repo_path = response[0]
 
3248
        bzrdir_name = response[6]
 
3249
        require_stacking = response[7]
 
3250
        require_stacking = self.parse_NoneTrueFalse(require_stacking)
 
3251
        format = RemoteBzrDirFormat()
 
3252
        format._network_name = bzrdir_name
 
3253
        self._supply_sub_formats_to(format)
 
3254
        bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
 
3255
        if repo_path:
 
3256
            repo_format = remote.response_tuple_to_repo_format(response[1:])
 
3257
            if repo_path == '.':
 
3258
                repo_path = ''
 
3259
            if repo_path:
 
3260
                repo_bzrdir_format = RemoteBzrDirFormat()
 
3261
                repo_bzrdir_format._network_name = response[5]
 
3262
                repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
 
3263
                    repo_bzrdir_format)
 
3264
            else:
 
3265
                repo_bzr = bzrdir
 
3266
            final_stack = response[8] or None
 
3267
            final_stack_pwd = response[9] or None
 
3268
            if final_stack_pwd:
 
3269
                final_stack_pwd = urlutils.join(
 
3270
                    transport.base, final_stack_pwd)
 
3271
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
 
3272
            if len(response) > 10:
 
3273
                # Updated server verb that locks remotely.
 
3274
                repo_lock_token = response[10] or None
 
3275
                remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
 
3276
                if repo_lock_token:
 
3277
                    remote_repo.dont_leave_lock_in_place()
 
3278
            else:
 
3279
                remote_repo.lock_write()
 
3280
            policy = UseExistingRepository(remote_repo, final_stack,
 
3281
                final_stack_pwd, require_stacking)
 
3282
            policy.acquire_repository()
 
3283
        else:
 
3284
            remote_repo = None
 
3285
            policy = None
 
3286
        bzrdir._format.set_branch_format(self.get_branch_format())
 
3287
        if require_stacking:
 
3288
            # The repo has already been created, but we need to make sure that
 
3289
            # we'll make a stackable branch.
 
3290
            bzrdir._format.require_stacking(_skip_repo=True)
 
3291
        return remote_repo, bzrdir, require_stacking, policy
2640
3292
 
2641
3293
    def _open(self, transport):
2642
 
        return remote.RemoteBzrDir(transport)
 
3294
        return remote.RemoteBzrDir(transport, self)
2643
3295
 
2644
3296
    def __eq__(self, other):
2645
3297
        if not isinstance(other, RemoteBzrDirFormat):
2646
3298
            return False
2647
3299
        return self.get_format_description() == other.get_format_description()
2648
3300
 
 
3301
    def __return_repository_format(self):
 
3302
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
 
3303
        # repository format has been asked for, tell the RemoteRepositoryFormat
 
3304
        # that it should use that for init() etc.
 
3305
        result = remote.RemoteRepositoryFormat()
 
3306
        custom_format = getattr(self, '_repository_format', None)
 
3307
        if custom_format:
 
3308
            if isinstance(custom_format, remote.RemoteRepositoryFormat):
 
3309
                return custom_format
 
3310
            else:
 
3311
                # We will use the custom format to create repositories over the
 
3312
                # wire; expose its details like rich_root_data for code to
 
3313
                # query
 
3314
                result._custom_format = custom_format
 
3315
        return result
 
3316
 
 
3317
    def get_branch_format(self):
 
3318
        result = BzrDirMetaFormat1.get_branch_format(self)
 
3319
        if not isinstance(result, remote.RemoteBranchFormat):
 
3320
            new_result = remote.RemoteBranchFormat()
 
3321
            new_result._custom_format = result
 
3322
            # cache the result
 
3323
            self.set_branch_format(new_result)
 
3324
            result = new_result
 
3325
        return result
 
3326
 
 
3327
    repository_format = property(__return_repository_format,
 
3328
        BzrDirMetaFormat1._set_repository_format) #.im_func)
 
3329
 
2649
3330
 
2650
3331
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2651
3332
 
2661
3342
 
2662
3343
class BzrDirFormatRegistry(registry.Registry):
2663
3344
    """Registry of user-selectable BzrDir subformats.
2664
 
    
 
3345
 
2665
3346
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2666
3347
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
2667
3348
    """
2669
3350
    def __init__(self):
2670
3351
        """Create a BzrDirFormatRegistry."""
2671
3352
        self._aliases = set()
 
3353
        self._registration_order = list()
2672
3354
        super(BzrDirFormatRegistry, self).__init__()
2673
3355
 
2674
3356
    def aliases(self):
2685
3367
        """Register a metadir subformat.
2686
3368
 
2687
3369
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2688
 
        by the Repository format.
 
3370
        by the Repository/Branch/WorkingTreeformats.
2689
3371
 
2690
3372
        :param repository_format: The fully-qualified repository format class
2691
3373
            name as a string.
2725
3407
    def register(self, key, factory, help, native=True, deprecated=False,
2726
3408
                 hidden=False, experimental=False, alias=False):
2727
3409
        """Register a BzrDirFormat factory.
2728
 
        
 
3410
 
2729
3411
        The factory must be a callable that takes one parameter: the key.
2730
3412
        It must produce an instance of the BzrDirFormat when called.
2731
3413
 
2736
3418
            BzrDirFormatInfo(native, deprecated, hidden, experimental))
2737
3419
        if alias:
2738
3420
            self._aliases.add(key)
 
3421
        self._registration_order.append(key)
2739
3422
 
2740
3423
    def register_lazy(self, key, module_name, member_name, help, native=True,
2741
3424
        deprecated=False, hidden=False, experimental=False, alias=False):
2743
3426
            help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
2744
3427
        if alias:
2745
3428
            self._aliases.add(key)
 
3429
        self._registration_order.append(key)
2746
3430
 
2747
3431
    def set_default(self, key):
2748
3432
        """Set the 'default' key to be a clone of the supplied key.
2749
 
        
 
3433
 
2750
3434
        This method must be called once and only once.
2751
3435
        """
2752
3436
        registry.Registry.register(self, 'default', self.get(key),
2755
3439
 
2756
3440
    def set_default_repository(self, key):
2757
3441
        """Set the FormatRegistry default and Repository default.
2758
 
        
 
3442
 
2759
3443
        This is a transitional method while Repository.set_default_format
2760
3444
        is deprecated.
2761
3445
        """
2768
3452
        return self.get(key)()
2769
3453
 
2770
3454
    def help_topic(self, topic):
2771
 
        output = textwrap.dedent("""\
2772
 
            These formats can be used for creating branches, working trees, and
2773
 
            repositories.
2774
 
 
2775
 
            """)
 
3455
        output = ""
2776
3456
        default_realkey = None
2777
3457
        default_help = self.get_help('default')
2778
3458
        help_pairs = []
2779
 
        for key in self.keys():
 
3459
        for key in self._registration_order:
2780
3460
            if key == 'default':
2781
3461
                continue
2782
3462
            help = self.get_help(key)
2788
3468
        def wrapped(key, help, info):
2789
3469
            if info.native:
2790
3470
                help = '(native) ' + help
2791
 
            return ':%s:\n%s\n\n' % (key, 
2792
 
                    textwrap.fill(help, initial_indent='    ', 
2793
 
                    subsequent_indent='    '))
 
3471
            return ':%s:\n%s\n\n' % (key,
 
3472
                textwrap.fill(help, initial_indent='    ',
 
3473
                    subsequent_indent='    ',
 
3474
                    break_long_words=False))
2794
3475
        if default_realkey is not None:
2795
3476
            output += wrapped(default_realkey, '(default) %s' % default_help,
2796
3477
                              self.get_info('default'))
2806
3487
                experimental_pairs.append((key, help))
2807
3488
            else:
2808
3489
                output += wrapped(key, help, info)
 
3490
        output += "\nSee ``bzr help formats`` for more about storage formats."
 
3491
        other_output = ""
2809
3492
        if len(experimental_pairs) > 0:
2810
 
            output += "Experimental formats are shown below.\n\n"
 
3493
            other_output += "Experimental formats are shown below.\n\n"
2811
3494
            for key, help in experimental_pairs:
2812
3495
                info = self.get_info(key)
2813
 
                output += wrapped(key, help, info)
 
3496
                other_output += wrapped(key, help, info)
 
3497
        else:
 
3498
            other_output += \
 
3499
                "No experimental formats are available.\n\n"
2814
3500
        if len(deprecated_pairs) > 0:
2815
 
            output += "Deprecated formats are shown below.\n\n"
 
3501
            other_output += "\nDeprecated formats are shown below.\n\n"
2816
3502
            for key, help in deprecated_pairs:
2817
3503
                info = self.get_info(key)
2818
 
                output += wrapped(key, help, info)
 
3504
                other_output += wrapped(key, help, info)
 
3505
        else:
 
3506
            other_output += \
 
3507
                "\nNo deprecated formats are available.\n\n"
 
3508
        other_output += \
 
3509
            "\nSee ``bzr help formats`` for more about storage formats."
2819
3510
 
2820
 
        return output
 
3511
        if topic == 'other-formats':
 
3512
            return other_output
 
3513
        else:
 
3514
            return output
2821
3515
 
2822
3516
 
2823
3517
class RepositoryAcquisitionPolicy(object):
2857
3551
                stack_on = self._get_full_stack_on()
2858
3552
        try:
2859
3553
            branch.set_stacked_on_url(stack_on)
2860
 
        except errors.UnstackableBranchFormat:
 
3554
        except (errors.UnstackableBranchFormat,
 
3555
                errors.UnstackableRepositoryFormat):
2861
3556
            if self._require_stacking:
2862
3557
                raise
2863
3558
 
 
3559
    def requires_stacking(self):
 
3560
        """Return True if this policy requires stacking."""
 
3561
        return self._stack_on is not None and self._require_stacking
 
3562
 
2864
3563
    def _get_full_stack_on(self):
2865
3564
        """Get a fully-qualified URL for the stack_on location."""
2866
3565
        if self._stack_on is None:
2870
3569
        else:
2871
3570
            return urlutils.join(self._stack_on_pwd, self._stack_on)
2872
3571
 
2873
 
    def _add_fallback(self, repository):
 
3572
    def _add_fallback(self, repository, possible_transports=None):
2874
3573
        """Add a fallback to the supplied repository, if stacking is set."""
2875
3574
        stack_on = self._get_full_stack_on()
2876
3575
        if stack_on is None:
2877
3576
            return
2878
 
        stacked_dir = BzrDir.open(stack_on)
 
3577
        try:
 
3578
            stacked_dir = BzrDir.open(stack_on,
 
3579
                                      possible_transports=possible_transports)
 
3580
        except errors.JailBreak:
 
3581
            # We keep the stacking details, but we are in the server code so
 
3582
            # actually stacking is not needed.
 
3583
            return
2879
3584
        try:
2880
3585
            stacked_repo = stacked_dir.open_branch().repository
2881
3586
        except errors.NotBranchError:
2885
3590
        except errors.UnstackableRepositoryFormat:
2886
3591
            if self._require_stacking:
2887
3592
                raise
 
3593
        else:
 
3594
            self._require_stacking = True
2888
3595
 
2889
3596
    def acquire_repository(self, make_working_trees=None, shared=False):
2890
3597
        """Acquire a repository for this bzrdir.
2894
3601
        :param make_working_trees: If creating a repository, set
2895
3602
            make_working_trees to this value (if non-None)
2896
3603
        :param shared: If creating a repository, make it shared if True
2897
 
        :return: A repository
 
3604
        :return: A repository, is_new_flag (True if the repository was
 
3605
            created).
2898
3606
        """
2899
3607
        raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
2900
3608
 
2920
3628
 
2921
3629
        Creates the desired repository in the bzrdir we already have.
2922
3630
        """
 
3631
        stack_on = self._get_full_stack_on()
 
3632
        if stack_on:
 
3633
            format = self._bzrdir._format
 
3634
            format.require_stacking(stack_on=stack_on,
 
3635
                                    possible_transports=[self._bzrdir.root_transport])
 
3636
            if not self._require_stacking:
 
3637
                # We have picked up automatic stacking somewhere.
 
3638
                note('Using default stacking branch %s at %s', self._stack_on,
 
3639
                    self._stack_on_pwd)
2923
3640
        repository = self._bzrdir.create_repository(shared=shared)
2924
 
        self._add_fallback(repository)
 
3641
        self._add_fallback(repository,
 
3642
                           possible_transports=[self._bzrdir.transport])
2925
3643
        if make_working_trees is not None:
2926
3644
            repository.set_make_working_trees(make_working_trees)
2927
 
        return repository
 
3645
        return repository, True
2928
3646
 
2929
3647
 
2930
3648
class UseExistingRepository(RepositoryAcquisitionPolicy):
2946
3664
    def acquire_repository(self, make_working_trees=None, shared=False):
2947
3665
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
2948
3666
 
2949
 
        Returns an existing repository to use
 
3667
        Returns an existing repository to use.
2950
3668
        """
2951
 
        self._add_fallback(self._repository)
2952
 
        return self._repository
2953
 
 
2954
 
 
 
3669
        self._add_fallback(self._repository,
 
3670
                       possible_transports=[self._repository.bzrdir.transport])
 
3671
        return self._repository, False
 
3672
 
 
3673
 
 
3674
# Please register new formats after old formats so that formats
 
3675
# appear in chronological order and format descriptions can build
 
3676
# on previous ones.
2955
3677
format_registry = BzrDirFormatRegistry()
 
3678
# The pre-0.8 formats have their repository format network name registered in
 
3679
# repository.py. MetaDir formats have their repository format network name
 
3680
# inferred from their disk format string.
2956
3681
format_registry.register('weave', BzrDirFormat6,
2957
3682
    'Pre-0.8 format.  Slower than knit and does not'
2958
3683
    ' support checkouts or shared repositories.',
2959
3684
    deprecated=True)
2960
 
format_registry.register_metadir('knit',
2961
 
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2962
 
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
2963
 
    branch_format='bzrlib.branch.BzrBranchFormat5',
2964
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2965
3685
format_registry.register_metadir('metaweave',
2966
3686
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2967
3687
    'Transitional format in 0.8.  Slower than knit.',
2968
3688
    branch_format='bzrlib.branch.BzrBranchFormat5',
2969
3689
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2970
3690
    deprecated=True)
 
3691
format_registry.register_metadir('knit',
 
3692
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
3693
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
 
3694
    branch_format='bzrlib.branch.BzrBranchFormat5',
 
3695
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
 
3696
    deprecated=True)
2971
3697
format_registry.register_metadir('dirstate',
2972
3698
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2973
3699
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2976
3702
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
2977
3703
    # directly from workingtree_4 triggers a circular import.
2978
3704
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2979
 
    )
 
3705
    deprecated=True)
2980
3706
format_registry.register_metadir('dirstate-tags',
2981
3707
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2982
3708
    help='New in 0.15: Fast local operations and improved scaling for '
2984
3710
        ' Incompatible with bzr < 0.15.',
2985
3711
    branch_format='bzrlib.branch.BzrBranchFormat6',
2986
3712
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2987
 
    )
 
3713
    deprecated=True)
2988
3714
format_registry.register_metadir('rich-root',
2989
3715
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2990
3716
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
2991
 
        ' bzr < 1.0',
 
3717
        ' bzr < 1.0.',
2992
3718
    branch_format='bzrlib.branch.BzrBranchFormat6',
2993
3719
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
2994
 
    )
 
3720
    deprecated=True)
2995
3721
format_registry.register_metadir('dirstate-with-subtree',
2996
3722
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2997
3723
    help='New in 0.15: Fast local operations and improved scaling for '
3028
3754
    )
3029
3755
format_registry.register_metadir('rich-root-pack',
3030
3756
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3031
 
    help='New in 1.0: Pack-based format with data compatible with '
3032
 
        'rich-root format repositories. Incompatible with'
3033
 
        ' bzr < 1.0',
 
3757
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
 
3758
         '(needed for bzr-svn and bzr-git).',
3034
3759
    branch_format='bzrlib.branch.BzrBranchFormat6',
3035
3760
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3036
3761
    )
3037
3762
format_registry.register_metadir('1.6',
3038
3763
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3039
 
    help='A branch and pack based repository that supports stacking. ',
 
3764
    help='A format that allows a branch to indicate that there is another '
 
3765
         '(stacked) repository that should be used to access data that is '
 
3766
         'not present locally.',
3040
3767
    branch_format='bzrlib.branch.BzrBranchFormat7',
3041
3768
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3042
3769
    )
3043
3770
format_registry.register_metadir('1.6.1-rich-root',
3044
3771
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3045
 
    help='A branch and pack based repository that supports stacking '
3046
 
         'and rich root data (needed for bzr-svn). ',
3047
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3048
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3049
 
    )
3050
 
# The following two formats should always just be aliases.
3051
 
format_registry.register_metadir('development',
3052
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3053
 
    help='Current development format. Can convert data to and from pack-0.92 '
3054
 
        '(and anything compatible with pack-0.92) format repositories. '
3055
 
        'Repositories and branches in this format can only be read by bzr.dev. '
3056
 
        'Please read '
 
3772
    help='A variant of 1.6 that supports rich-root data '
 
3773
         '(needed for bzr-svn and bzr-git).',
 
3774
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3775
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3776
    )
 
3777
format_registry.register_metadir('1.9',
 
3778
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
 
3779
    help='A repository format using B+tree indexes. These indexes '
 
3780
         'are smaller in size, have smarter caching and provide faster '
 
3781
         'performance for most operations.',
 
3782
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3783
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3784
    )
 
3785
format_registry.register_metadir('1.9-rich-root',
 
3786
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
 
3787
    help='A variant of 1.9 that supports rich-root data '
 
3788
         '(needed for bzr-svn and bzr-git).',
 
3789
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3790
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3791
    )
 
3792
format_registry.register_metadir('1.14',
 
3793
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
 
3794
    help='A working-tree format that supports content filtering.',
 
3795
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3796
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
 
3797
    )
 
3798
format_registry.register_metadir('1.14-rich-root',
 
3799
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
 
3800
    help='A variant of 1.14 that supports rich-root data '
 
3801
         '(needed for bzr-svn and bzr-git).',
 
3802
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3803
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
 
3804
    )
 
3805
# The following un-numbered 'development' formats should always just be aliases.
 
3806
format_registry.register_metadir('development-rich-root',
 
3807
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
 
3808
    help='Current development format. Supports rich roots. Can convert data '
 
3809
        'to and from rich-root-pack (and anything compatible with '
 
3810
        'rich-root-pack) format repositories. Repositories and branches in '
 
3811
        'this format can only be read by bzr.dev. Please read '
3057
3812
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3058
3813
        'before use.',
3059
3814
    branch_format='bzrlib.branch.BzrBranchFormat7',
3060
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3815
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3061
3816
    experimental=True,
3062
3817
    alias=True,
3063
3818
    )
3064
3819
format_registry.register_metadir('development-subtree',
3065
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
 
3820
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3066
3821
    help='Current development format, subtree variant. Can convert data to and '
3067
3822
        'from pack-0.92-subtree (and anything compatible with '
3068
3823
        'pack-0.92-subtree) format repositories. Repositories and branches in '
3070
3825
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3071
3826
        'before use.',
3072
3827
    branch_format='bzrlib.branch.BzrBranchFormat7',
3073
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3074
 
    experimental=True,
 
3828
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3829
    experimental=True,
 
3830
    alias=False, # Restore to being an alias when an actual development subtree format is added
 
3831
                 # This current non-alias status is simply because we did not introduce a
 
3832
                 # chk based subtree format.
 
3833
    )
 
3834
 
 
3835
# And the development formats above will have aliased one of the following:
 
3836
format_registry.register_metadir('development6-rich-root',
 
3837
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
 
3838
    help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
 
3839
        'Please read '
 
3840
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3841
        'before use.',
 
3842
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3843
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3844
    hidden=True,
 
3845
    experimental=True,
 
3846
    )
 
3847
 
 
3848
format_registry.register_metadir('development7-rich-root',
 
3849
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
 
3850
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
 
3851
        'rich roots. Please read '
 
3852
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3853
        'before use.',
 
3854
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3855
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3856
    hidden=True,
 
3857
    experimental=True,
 
3858
    )
 
3859
 
 
3860
format_registry.register_metadir('2a',
 
3861
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
3862
    help='First format for bzr 2.0 series.\n'
 
3863
        'Uses group-compress storage.\n'
 
3864
        'Provides rich roots which are a one-way transition.\n',
 
3865
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
 
3866
        # 'rich roots. Supported by bzr 1.16 and later.',
 
3867
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3868
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3869
    experimental=True,
 
3870
    )
 
3871
 
 
3872
# The following format should be an alias for the rich root equivalent 
 
3873
# of the default format
 
3874
format_registry.register_metadir('default-rich-root',
 
3875
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
3876
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3877
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3075
3878
    alias=True,
3076
 
    )
3077
 
# And the development formats which the will have aliased one of follow:
3078
 
format_registry.register_metadir('development1',
3079
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1',
3080
 
    help='A branch and pack based repository that supports stacking. '
3081
 
        'Please read '
3082
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3083
 
        'before use.',
3084
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3085
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3086
 
    hidden=True,
3087
 
    experimental=True,
3088
 
    )
3089
 
format_registry.register_metadir('development1-subtree',
3090
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment1Subtree',
3091
 
    help='A branch and pack based repository that supports stacking. '
3092
 
        'Please read '
3093
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3094
 
        'before use.',
3095
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3096
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3097
 
    hidden=True,
3098
 
    experimental=True,
3099
 
    )
 
3879
    help='Same as 2a.')
 
3880
 
3100
3881
# The current format that is made on 'bzr init'.
3101
 
format_registry.set_default('pack-0.92')
 
3882
format_registry.set_default('2a')