~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Max Bowsher
  • Date: 2011-02-09 04:08:25 UTC
  • mfrom: (0.5074.6 lucid)
  • Revision ID: maxb@f2s.com-20110209040825-7jqm4i78b8ojoy9z
Merge beta-ppa into ppa upon release of 2.3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
34
34
from bzrlib.lazy_import import lazy_import
35
35
lazy_import(globals(), """
36
36
from stat import S_ISDIR
37
 
import textwrap
38
37
 
39
38
import bzrlib
40
39
from bzrlib import (
41
40
    branch,
42
41
    config,
 
42
    controldir,
43
43
    errors,
44
44
    graph,
45
45
    lockable_files,
46
46
    lockdir,
47
47
    osutils,
 
48
    pyutils,
48
49
    remote,
49
50
    repository,
50
51
    revision as _mod_revision,
 
52
    transport as _mod_transport,
51
53
    ui,
52
54
    urlutils,
53
55
    versionedfile,
69
71
from bzrlib.transactions import WriteTransaction
70
72
from bzrlib.transport import (
71
73
    do_catching_redirections,
72
 
    get_transport,
73
74
    local,
74
75
    )
75
76
from bzrlib.weave import Weave
86
87
    registry,
87
88
    symbol_versioning,
88
89
    )
89
 
    
90
 
    
91
 
class ControlComponent(object):
92
 
    """Abstract base class for control directory components.
93
 
    
94
 
    This provides interfaces that are common across bzrdirs, 
95
 
    repositories, branches, and workingtree control directories.
96
 
    
97
 
    They all expose two urls and transports: the *user* URL is the 
98
 
    one that stops above the control directory (eg .bzr) and that 
99
 
    should normally be used in messages, and the *control* URL is
100
 
    under that in eg .bzr/checkout and is used to read the control
101
 
    files.
102
 
    
103
 
    This can be used as a mixin and is intended to fit with 
104
 
    foreign formats.
105
 
    """
106
 
    
107
 
    @property
108
 
    def control_transport(self):
109
 
        raise NotImplementedError
110
 
   
111
 
    @property
112
 
    def control_url(self):
113
 
        return self.control_transport.base
114
 
    
115
 
    @property
116
 
    def user_transport(self):
117
 
        raise NotImplementedError
118
 
        
119
 
    @property
120
 
    def user_url(self):
121
 
        return self.user_transport.base
122
 
    
123
 
 
124
 
class BzrDir(ControlComponent):
 
90
from bzrlib.symbol_versioning import (
 
91
    deprecated_in,
 
92
    deprecated_method,
 
93
    )
 
94
 
 
95
 
 
96
class BzrDir(controldir.ControlDir):
125
97
    """A .bzr control diretory.
126
98
 
127
99
    BzrDir instances let you create or open any of the things that can be
158
130
                    return
159
131
        thing_to_unlock.break_lock()
160
132
 
161
 
    def can_convert_format(self):
162
 
        """Return true if this bzrdir is one whose format we can convert from."""
163
 
        return True
164
 
 
165
133
    def check_conversion_target(self, target_format):
166
134
        """Check that a bzrdir as a whole can be converted to a new format."""
167
135
        # The only current restriction is that the repository content can be 
202
170
                format.get_format_description(),
203
171
                basedir)
204
172
 
205
 
    def clone(self, url, revision_id=None, force_new_repo=False,
206
 
              preserve_stacking=False):
207
 
        """Clone this bzrdir and its contents to url verbatim.
208
 
 
209
 
        :param url: The url create the clone at.  If url's last component does
210
 
            not exist, it will be created.
211
 
        :param revision_id: The tip revision-id to use for any branch or
212
 
            working tree.  If not None, then the clone operation may tune
213
 
            itself to download less data.
214
 
        :param force_new_repo: Do not use a shared repository for the target
215
 
                               even if one is available.
216
 
        :param preserve_stacking: When cloning a stacked branch, stack the
217
 
            new branch on top of the other branch's stacked-on branch.
218
 
        """
219
 
        return self.clone_on_transport(get_transport(url),
220
 
                                       revision_id=revision_id,
221
 
                                       force_new_repo=force_new_repo,
222
 
                                       preserve_stacking=preserve_stacking)
223
 
 
224
173
    def clone_on_transport(self, transport, revision_id=None,
225
174
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
226
 
        create_prefix=False, use_existing_dir=True):
 
175
        create_prefix=False, use_existing_dir=True, no_tree=False):
227
176
        """Clone this bzrdir and its contents to transport verbatim.
228
177
 
229
178
        :param transport: The transport for the location to produce the clone
241
190
        """
242
191
        # Overview: put together a broad description of what we want to end up
243
192
        # with; then make as few api calls as possible to do it.
244
 
        
 
193
 
245
194
        # We may want to create a repo/branch/tree, if we do so what format
246
195
        # would we want for each:
247
196
        require_stacking = (stacked_on is not None)
248
197
        format = self.cloning_metadir(require_stacking)
249
 
        
 
198
 
250
199
        # Figure out what objects we want:
251
200
        try:
252
201
            local_repo = self.find_repository()
271
220
        # we should look up the policy needs first, or just use it as a hint,
272
221
        # or something.
273
222
        if local_repo:
274
 
            make_working_trees = local_repo.make_working_trees()
 
223
            make_working_trees = local_repo.make_working_trees() and not no_tree
275
224
            want_shared = local_repo.is_shared()
276
225
            repo_format_name = format.repository_format.network_name()
277
226
        else:
326
275
    # TODO: This should be given a Transport, and should chdir up; otherwise
327
276
    # this will open a new connection.
328
277
    def _make_tail(self, url):
329
 
        t = get_transport(url)
330
 
        t.ensure_base()
331
 
 
332
 
    @classmethod
333
 
    def create(cls, base, format=None, possible_transports=None):
334
 
        """Create a new BzrDir at the url 'base'.
335
 
 
336
 
        :param format: If supplied, the format of branch to create.  If not
337
 
            supplied, the default is used.
338
 
        :param possible_transports: If supplied, a list of transports that
339
 
            can be reused to share a remote connection.
340
 
        """
341
 
        if cls is not BzrDir:
342
 
            raise AssertionError("BzrDir.create always creates the default"
343
 
                " format, not one of %r" % cls)
344
 
        t = get_transport(base, possible_transports)
345
 
        t.ensure_base()
346
 
        if format is None:
347
 
            format = BzrDirFormat.get_default_format()
348
 
        return format.initialize_on_transport(t)
 
278
        t = _mod_transport.get_transport(url)
 
279
        t.ensure_base()
349
280
 
350
281
    @staticmethod
351
282
    def find_bzrdirs(transport, evaluate=None, list_current=None):
388
319
                for subdir in sorted(subdirs, reverse=True):
389
320
                    pending.append(current_transport.clone(subdir))
390
321
 
391
 
    def list_branches(self):
392
 
        """Return a sequence of all branches local to this control directory.
393
 
 
394
 
        """
395
 
        try:
396
 
            return [self.open_branch()]
397
 
        except (errors.NotBranchError, errors.NoRepositoryPresent):
398
 
            return []
399
 
 
400
322
    @staticmethod
401
323
    def find_branches(transport):
402
324
        """Find all branches under a transport.
425
347
                ret.extend(branches)
426
348
        return ret
427
349
 
428
 
    def destroy_repository(self):
429
 
        """Destroy the repository in this BzrDir"""
430
 
        raise NotImplementedError(self.destroy_repository)
431
 
 
432
 
    def create_branch(self, name=None):
433
 
        """Create a branch in this BzrDir.
434
 
 
435
 
        :param name: Name of the colocated branch to create, None for
436
 
            the default branch.
437
 
 
438
 
        The bzrdir's format will control what branch format is created.
439
 
        For more control see BranchFormatXX.create(a_bzrdir).
440
 
        """
441
 
        raise NotImplementedError(self.create_branch)
442
 
 
443
 
    def destroy_branch(self, name=None):
444
 
        """Destroy a branch in this BzrDir.
445
 
        
446
 
        :param name: Name of the branch to destroy, None for the default 
447
 
            branch.
448
 
        """
449
 
        raise NotImplementedError(self.destroy_branch)
450
 
 
451
350
    @staticmethod
452
351
    def create_branch_and_repo(base, force_new_repo=False, format=None):
453
352
        """Create a new BzrDir, Branch and Repository at the url 'base'.
566
465
        """
567
466
        if force_new_tree:
568
467
            # check for non local urls
569
 
            t = get_transport(base, possible_transports)
 
468
            t = _mod_transport.get_transport(base, possible_transports)
570
469
            if not isinstance(t, local.LocalTransport):
571
470
                raise errors.NotLocalUrl(base)
572
471
        bzrdir = BzrDir.create(base, format, possible_transports)
594
493
        :param format: Override for the bzrdir format to create.
595
494
        :return: The WorkingTree object.
596
495
        """
597
 
        t = get_transport(base)
 
496
        t = _mod_transport.get_transport(base)
598
497
        if not isinstance(t, local.LocalTransport):
599
498
            raise errors.NotLocalUrl(base)
600
499
        bzrdir = BzrDir.create_branch_and_repo(base,
602
501
                                               format=format).bzrdir
603
502
        return bzrdir.create_workingtree()
604
503
 
605
 
    def create_workingtree(self, revision_id=None, from_branch=None,
606
 
        accelerator_tree=None, hardlink=False):
607
 
        """Create a working tree at this BzrDir.
608
 
 
609
 
        :param revision_id: create it as of this revision id.
610
 
        :param from_branch: override bzrdir branch (for lightweight checkouts)
611
 
        :param accelerator_tree: A tree which can be used for retrieving file
612
 
            contents more quickly than the revision tree, i.e. a workingtree.
613
 
            The revision tree will be used for cases where accelerator_tree's
614
 
            content is different.
 
504
    @deprecated_method(deprecated_in((2, 3, 0)))
 
505
    def generate_backup_name(self, base):
 
506
        return self._available_backup_name(base)
 
507
 
 
508
    def _available_backup_name(self, base):
 
509
        """Find a non-existing backup file name based on base.
 
510
 
 
511
        See bzrlib.osutils.available_backup_name about race conditions.
615
512
        """
616
 
        raise NotImplementedError(self.create_workingtree)
 
513
        return osutils.available_backup_name(base, self.root_transport.has)
617
514
 
618
515
    def backup_bzrdir(self):
619
516
        """Backup this bzr control directory.
620
517
 
621
518
        :return: Tuple with old path name and new path name
622
519
        """
623
 
        def name_gen(base='backup.bzr'):
624
 
            counter = 1
625
 
            name = "%s.~%d~" % (base, counter)
626
 
            while self.root_transport.has(name):
627
 
                counter += 1
628
 
                name = "%s.~%d~" % (base, counter)
629
 
            return name
630
520
 
631
 
        backup_dir=name_gen()
632
521
        pb = ui.ui_factory.nested_progress_bar()
633
522
        try:
634
 
            # FIXME: bug 300001 -- the backup fails if the backup directory
635
 
            # already exists, but it should instead either remove it or make
636
 
            # a new backup directory.
637
 
            #
638
523
            old_path = self.root_transport.abspath('.bzr')
 
524
            backup_dir = self._available_backup_name('backup.bzr')
639
525
            new_path = self.root_transport.abspath(backup_dir)
640
 
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
 
526
            ui.ui_factory.note('making backup of %s\n  to %s'
 
527
                               % (old_path, new_path,))
641
528
            self.root_transport.copy_tree('.bzr', backup_dir)
642
529
            return (old_path, new_path)
643
530
        finally:
668
555
                else:
669
556
                    pass
670
557
 
671
 
    def destroy_workingtree(self):
672
 
        """Destroy the working tree at this BzrDir.
673
 
 
674
 
        Formats that do not support this may raise UnsupportedOperation.
675
 
        """
676
 
        raise NotImplementedError(self.destroy_workingtree)
677
 
 
678
 
    def destroy_workingtree_metadata(self):
679
 
        """Destroy the control files for the working tree at this BzrDir.
680
 
 
681
 
        The contents of working tree files are not affected.
682
 
        Formats that do not support this may raise UnsupportedOperation.
683
 
        """
684
 
        raise NotImplementedError(self.destroy_workingtree_metadata)
685
 
 
686
558
    def _find_containing(self, evaluate):
687
559
        """Find something in a containing control directory.
688
560
 
737
609
            raise errors.NoRepositoryPresent(self)
738
610
        return found_repo
739
611
 
740
 
    def get_branch_reference(self, name=None):
741
 
        """Return the referenced URL for the branch in this bzrdir.
742
 
 
743
 
        :param name: Optional colocated branch name
744
 
        :raises NotBranchError: If there is no Branch.
745
 
        :raises NoColocatedBranchSupport: If a branch name was specified
746
 
            but colocated branches are not supported.
747
 
        :return: The URL the branch in this bzrdir references if it is a
748
 
            reference branch, or None for regular branches.
749
 
        """
750
 
        if name is not None:
751
 
            raise errors.NoColocatedBranchSupport(self)
752
 
        return None
753
 
 
754
 
    def get_branch_transport(self, branch_format, name=None):
755
 
        """Get the transport for use by branch format in this BzrDir.
756
 
 
757
 
        Note that bzr dirs that do not support format strings will raise
758
 
        IncompatibleFormat if the branch format they are given has
759
 
        a format string, and vice versa.
760
 
 
761
 
        If branch_format is None, the transport is returned with no
762
 
        checking. If it is not None, then the returned transport is
763
 
        guaranteed to point to an existing directory ready for use.
764
 
        """
765
 
        raise NotImplementedError(self.get_branch_transport)
766
 
 
767
612
    def _find_creation_modes(self):
768
613
        """Determine the appropriate modes for files and directories.
769
614
 
808
653
            self._find_creation_modes()
809
654
        return self._dir_mode
810
655
 
811
 
    def get_repository_transport(self, repository_format):
812
 
        """Get the transport for use by repository format in this BzrDir.
813
 
 
814
 
        Note that bzr dirs that do not support format strings will raise
815
 
        IncompatibleFormat if the repository format they are given has
816
 
        a format string, and vice versa.
817
 
 
818
 
        If repository_format is None, the transport is returned with no
819
 
        checking. If it is not None, then the returned transport is
820
 
        guaranteed to point to an existing directory ready for use.
821
 
        """
822
 
        raise NotImplementedError(self.get_repository_transport)
823
 
 
824
 
    def get_workingtree_transport(self, tree_format):
825
 
        """Get the transport for use by workingtree format in this BzrDir.
826
 
 
827
 
        Note that bzr dirs that do not support format strings will raise
828
 
        IncompatibleFormat if the workingtree format they are given has a
829
 
        format string, and vice versa.
830
 
 
831
 
        If workingtree_format is None, the transport is returned with no
832
 
        checking. If it is not None, then the returned transport is
833
 
        guaranteed to point to an existing directory ready for use.
834
 
        """
835
 
        raise NotImplementedError(self.get_workingtree_transport)
836
 
 
837
656
    def get_config(self):
838
657
        """Get configuration for this BzrDir."""
839
658
        return config.BzrDirConfig(self)
857
676
        self.transport = _transport.clone('.bzr')
858
677
        self.root_transport = _transport
859
678
        self._mode_check_done = False
860
 
        
 
679
 
861
680
    @property 
862
681
    def user_transport(self):
863
682
        return self.root_transport
864
 
        
 
683
 
865
684
    @property
866
685
    def control_transport(self):
867
686
        return self.transport
873
692
 
874
693
        This is true IF and ONLY IF the filename is part of the namespace reserved
875
694
        for bzr control dirs. Currently this is the '.bzr' directory in the root
876
 
        of the root_transport. it is expected that plugins will need to extend
877
 
        this in the future - for instance to make bzr talk with svn working
878
 
        trees.
 
695
        of the root_transport. 
879
696
        """
880
697
        # this might be better on the BzrDirFormat class because it refers to
881
698
        # all the possible bzrdir disk formats.
885
702
        # add new tests for it to the appropriate place.
886
703
        return filename == '.bzr' or filename.startswith('.bzr/')
887
704
 
888
 
    def needs_format_conversion(self, format=None):
889
 
        """Return true if this bzrdir needs convert_format run on it.
890
 
 
891
 
        For instance, if the repository format is out of date but the
892
 
        branch and working tree are not, this should return True.
893
 
 
894
 
        :param format: Optional parameter indicating a specific desired
895
 
                       format we plan to arrive at.
896
 
        """
897
 
        raise NotImplementedError(self.needs_format_conversion)
898
 
 
899
705
    @staticmethod
900
706
    def open_unsupported(base):
901
707
        """Open a branch which is not supported."""
907
713
 
908
714
        :param _unsupported: a private parameter to the BzrDir class.
909
715
        """
910
 
        t = get_transport(base, possible_transports=possible_transports)
 
716
        t = _mod_transport.get_transport(base, possible_transports)
911
717
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
912
718
 
913
719
    @staticmethod
924
730
        # the redirections.
925
731
        base = transport.base
926
732
        def find_format(transport):
927
 
            return transport, BzrDirFormat.find_format(
 
733
            return transport, controldir.ControlDirFormat.find_format(
928
734
                transport, _server_formats=_server_formats)
929
735
 
930
736
        def redirected(transport, e, redirection_notice):
945
751
        BzrDir._check_supported(format, _unsupported)
946
752
        return format.open(transport, _found=True)
947
753
 
948
 
    def open_branch(self, name=None, unsupported=False,
949
 
                    ignore_fallbacks=False):
950
 
        """Open the branch object at this BzrDir if one is present.
951
 
 
952
 
        If unsupported is True, then no longer supported branch formats can
953
 
        still be opened.
954
 
 
955
 
        TODO: static convenience version of this?
956
 
        """
957
 
        raise NotImplementedError(self.open_branch)
958
 
 
959
754
    @staticmethod
960
755
    def open_containing(url, possible_transports=None):
961
756
        """Open an existing branch which contains url.
963
758
        :param url: url to search from.
964
759
        See open_containing_from_transport for more detail.
965
760
        """
966
 
        transport = get_transport(url, possible_transports)
 
761
        transport = _mod_transport.get_transport(url, possible_transports)
967
762
        return BzrDir.open_containing_from_transport(transport)
968
763
 
969
764
    @staticmethod
999
794
                raise errors.NotBranchError(path=url)
1000
795
            a_transport = new_t
1001
796
 
1002
 
    def _get_tree_branch(self, name=None):
1003
 
        """Return the branch and tree, if any, for this bzrdir.
1004
 
 
1005
 
        :param name: Name of colocated branch to open.
1006
 
 
1007
 
        Return None for tree if not present or inaccessible.
1008
 
        Raise NotBranchError if no branch is present.
1009
 
        :return: (tree, branch)
1010
 
        """
1011
 
        try:
1012
 
            tree = self.open_workingtree()
1013
 
        except (errors.NoWorkingTree, errors.NotLocalUrl):
1014
 
            tree = None
1015
 
            branch = self.open_branch(name=name)
1016
 
        else:
1017
 
            if name is not None:
1018
 
                branch = self.open_branch(name=name)
1019
 
            else:
1020
 
                branch = tree.branch
1021
 
        return tree, branch
1022
 
 
1023
797
    @classmethod
1024
798
    def open_tree_or_branch(klass, location):
1025
799
        """Return the branch and working tree at a location.
1071
845
                raise errors.NotBranchError(location)
1072
846
        return tree, branch, branch.repository, relpath
1073
847
 
1074
 
    def open_repository(self, _unsupported=False):
1075
 
        """Open the repository object at this BzrDir if one is present.
1076
 
 
1077
 
        This will not follow the Branch object pointer - it's strictly a direct
1078
 
        open facility. Most client code should use open_branch().repository to
1079
 
        get at a repository.
1080
 
 
1081
 
        :param _unsupported: a private parameter, not part of the api.
1082
 
        TODO: static convenience version of this?
1083
 
        """
1084
 
        raise NotImplementedError(self.open_repository)
1085
 
 
1086
 
    def open_workingtree(self, _unsupported=False,
1087
 
                         recommend_upgrade=True, from_branch=None):
1088
 
        """Open the workingtree object at this BzrDir if one is present.
1089
 
 
1090
 
        :param recommend_upgrade: Optional keyword parameter, when True (the
1091
 
            default), emit through the ui module a recommendation that the user
1092
 
            upgrade the working tree when the workingtree being opened is old
1093
 
            (but still fully supported).
1094
 
        :param from_branch: override bzrdir branch (for lightweight checkouts)
1095
 
        """
1096
 
        raise NotImplementedError(self.open_workingtree)
1097
 
 
1098
 
    def has_branch(self, name=None):
1099
 
        """Tell if this bzrdir contains a branch.
1100
 
 
1101
 
        Note: if you're going to open the branch, you should just go ahead
1102
 
        and try, and not ask permission first.  (This method just opens the
1103
 
        branch and discards it, and that's somewhat expensive.)
1104
 
        """
1105
 
        try:
1106
 
            self.open_branch(name)
1107
 
            return True
1108
 
        except errors.NotBranchError:
1109
 
            return False
1110
 
 
1111
 
    def has_workingtree(self):
1112
 
        """Tell if this bzrdir contains a working tree.
1113
 
 
1114
 
        This will still raise an exception if the bzrdir has a workingtree that
1115
 
        is remote & inaccessible.
1116
 
 
1117
 
        Note: if you're going to open the working tree, you should just go ahead
1118
 
        and try, and not ask permission first.  (This method just opens the
1119
 
        workingtree and discards it, and that's somewhat expensive.)
1120
 
        """
1121
 
        try:
1122
 
            self.open_workingtree(recommend_upgrade=False)
1123
 
            return True
1124
 
        except errors.NoWorkingTree:
1125
 
            return False
1126
 
 
1127
848
    def _cloning_metadir(self):
1128
849
        """Produce a metadir suitable for cloning with.
1129
850
 
1187
908
            format.require_stacking()
1188
909
        return format
1189
910
 
1190
 
    def checkout_metadir(self):
1191
 
        return self.cloning_metadir()
1192
 
 
1193
 
    def sprout(self, url, revision_id=None, force_new_repo=False,
1194
 
               recurse='down', possible_transports=None,
1195
 
               accelerator_tree=None, hardlink=False, stacked=False,
1196
 
               source_branch=None, create_tree_if_local=True):
1197
 
        """Create a copy of this bzrdir prepared for use as a new line of
1198
 
        development.
1199
 
 
1200
 
        If url's last component does not exist, it will be created.
1201
 
 
1202
 
        Attributes related to the identity of the source branch like
1203
 
        branch nickname will be cleaned, a working tree is created
1204
 
        whether one existed before or not; and a local branch is always
1205
 
        created.
1206
 
 
1207
 
        if revision_id is not None, then the clone operation may tune
1208
 
            itself to download less data.
1209
 
        :param accelerator_tree: A tree which can be used for retrieving file
1210
 
            contents more quickly than the revision tree, i.e. a workingtree.
1211
 
            The revision tree will be used for cases where accelerator_tree's
1212
 
            content is different.
1213
 
        :param hardlink: If true, hard-link files from accelerator_tree,
1214
 
            where possible.
1215
 
        :param stacked: If true, create a stacked branch referring to the
1216
 
            location of this control directory.
1217
 
        :param create_tree_if_local: If true, a working-tree will be created
1218
 
            when working locally.
 
911
    @classmethod
 
912
    def create(cls, base, format=None, possible_transports=None):
 
913
        """Create a new BzrDir at the url 'base'.
 
914
 
 
915
        :param format: If supplied, the format of branch to create.  If not
 
916
            supplied, the default is used.
 
917
        :param possible_transports: If supplied, a list of transports that
 
918
            can be reused to share a remote connection.
1219
919
        """
1220
 
        target_transport = get_transport(url, possible_transports)
1221
 
        target_transport.ensure_base()
1222
 
        cloning_format = self.cloning_metadir(stacked)
1223
 
        # Create/update the result branch
1224
 
        result = cloning_format.initialize_on_transport(target_transport)
1225
 
        # if a stacked branch wasn't requested, we don't create one
1226
 
        # even if the origin was stacked
1227
 
        stacked_branch_url = None
1228
 
        if source_branch is not None:
1229
 
            if stacked:
1230
 
                stacked_branch_url = self.root_transport.base
1231
 
            source_repository = source_branch.repository
1232
 
        else:
1233
 
            try:
1234
 
                source_branch = self.open_branch()
1235
 
                source_repository = source_branch.repository
1236
 
                if stacked:
1237
 
                    stacked_branch_url = self.root_transport.base
1238
 
            except errors.NotBranchError:
1239
 
                source_branch = None
1240
 
                try:
1241
 
                    source_repository = self.open_repository()
1242
 
                except errors.NoRepositoryPresent:
1243
 
                    source_repository = None
1244
 
        repository_policy = result.determine_repository_policy(
1245
 
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1246
 
        result_repo, is_new_repo = repository_policy.acquire_repository()
1247
 
        is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
1248
 
        if is_new_repo and revision_id is not None and not is_stacked:
1249
 
            fetch_spec = graph.PendingAncestryResult(
1250
 
                [revision_id], source_repository)
1251
 
        else:
1252
 
            fetch_spec = None
1253
 
        if source_repository is not None:
1254
 
            # Fetch while stacked to prevent unstacked fetch from
1255
 
            # Branch.sprout.
1256
 
            if fetch_spec is None:
1257
 
                result_repo.fetch(source_repository, revision_id=revision_id)
1258
 
            else:
1259
 
                result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1260
 
 
1261
 
        if source_branch is None:
1262
 
            # this is for sprouting a bzrdir without a branch; is that
1263
 
            # actually useful?
1264
 
            # Not especially, but it's part of the contract.
1265
 
            result_branch = result.create_branch()
1266
 
        else:
1267
 
            result_branch = source_branch.sprout(result,
1268
 
                revision_id=revision_id, repository_policy=repository_policy)
1269
 
        mutter("created new branch %r" % (result_branch,))
1270
 
 
1271
 
        # Create/update the result working tree
1272
 
        if (create_tree_if_local and
1273
 
            isinstance(target_transport, local.LocalTransport) and
1274
 
            (result_repo is None or result_repo.make_working_trees())):
1275
 
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1276
 
                hardlink=hardlink)
1277
 
            wt.lock_write()
1278
 
            try:
1279
 
                if wt.path2id('') is None:
1280
 
                    try:
1281
 
                        wt.set_root_id(self.open_workingtree.get_root_id())
1282
 
                    except errors.NoWorkingTree:
1283
 
                        pass
1284
 
            finally:
1285
 
                wt.unlock()
1286
 
        else:
1287
 
            wt = None
1288
 
        if recurse == 'down':
1289
 
            if wt is not None:
1290
 
                basis = wt.basis_tree()
1291
 
                basis.lock_read()
1292
 
                subtrees = basis.iter_references()
1293
 
            elif result_branch is not None:
1294
 
                basis = result_branch.basis_tree()
1295
 
                basis.lock_read()
1296
 
                subtrees = basis.iter_references()
1297
 
            elif source_branch is not None:
1298
 
                basis = source_branch.basis_tree()
1299
 
                basis.lock_read()
1300
 
                subtrees = basis.iter_references()
1301
 
            else:
1302
 
                subtrees = []
1303
 
                basis = None
1304
 
            try:
1305
 
                for path, file_id in subtrees:
1306
 
                    target = urlutils.join(url, urlutils.escape(path))
1307
 
                    sublocation = source_branch.reference_parent(file_id, path)
1308
 
                    sublocation.bzrdir.sprout(target,
1309
 
                        basis.get_reference_revision(file_id, path),
1310
 
                        force_new_repo=force_new_repo, recurse=recurse,
1311
 
                        stacked=stacked)
1312
 
            finally:
1313
 
                if basis is not None:
1314
 
                    basis.unlock()
1315
 
        return result
1316
 
 
1317
 
    def push_branch(self, source, revision_id=None, overwrite=False, 
1318
 
        remember=False, create_prefix=False):
1319
 
        """Push the source branch into this BzrDir."""
1320
 
        br_to = None
1321
 
        # If we can open a branch, use its direct repository, otherwise see
1322
 
        # if there is a repository without a branch.
1323
 
        try:
1324
 
            br_to = self.open_branch()
1325
 
        except errors.NotBranchError:
1326
 
            # Didn't find a branch, can we find a repository?
1327
 
            repository_to = self.find_repository()
1328
 
        else:
1329
 
            # Found a branch, so we must have found a repository
1330
 
            repository_to = br_to.repository
1331
 
 
1332
 
        push_result = PushResult()
1333
 
        push_result.source_branch = source
1334
 
        if br_to is None:
1335
 
            # We have a repository but no branch, copy the revisions, and then
1336
 
            # create a branch.
1337
 
            repository_to.fetch(source.repository, revision_id=revision_id)
1338
 
            br_to = source.clone(self, revision_id=revision_id)
1339
 
            if source.get_push_location() is None or remember:
1340
 
                source.set_push_location(br_to.base)
1341
 
            push_result.stacked_on = None
1342
 
            push_result.branch_push_result = None
1343
 
            push_result.old_revno = None
1344
 
            push_result.old_revid = _mod_revision.NULL_REVISION
1345
 
            push_result.target_branch = br_to
1346
 
            push_result.master_branch = None
1347
 
            push_result.workingtree_updated = False
1348
 
        else:
1349
 
            # We have successfully opened the branch, remember if necessary:
1350
 
            if source.get_push_location() is None or remember:
1351
 
                source.set_push_location(br_to.base)
1352
 
            try:
1353
 
                tree_to = self.open_workingtree()
1354
 
            except errors.NotLocalUrl:
1355
 
                push_result.branch_push_result = source.push(br_to, 
1356
 
                    overwrite, stop_revision=revision_id)
1357
 
                push_result.workingtree_updated = False
1358
 
            except errors.NoWorkingTree:
1359
 
                push_result.branch_push_result = source.push(br_to,
1360
 
                    overwrite, stop_revision=revision_id)
1361
 
                push_result.workingtree_updated = None # Not applicable
1362
 
            else:
1363
 
                tree_to.lock_write()
1364
 
                try:
1365
 
                    push_result.branch_push_result = source.push(
1366
 
                        tree_to.branch, overwrite, stop_revision=revision_id)
1367
 
                    tree_to.update()
1368
 
                finally:
1369
 
                    tree_to.unlock()
1370
 
                push_result.workingtree_updated = True
1371
 
            push_result.old_revno = push_result.branch_push_result.old_revno
1372
 
            push_result.old_revid = push_result.branch_push_result.old_revid
1373
 
            push_result.target_branch = \
1374
 
                push_result.branch_push_result.target_branch
1375
 
        return push_result
 
920
        if cls is not BzrDir:
 
921
            raise AssertionError("BzrDir.create always creates the"
 
922
                "default format, not one of %r" % cls)
 
923
        t = _mod_transport.get_transport(base, possible_transports)
 
924
        t.ensure_base()
 
925
        if format is None:
 
926
            format = controldir.ControlDirFormat.get_default_format()
 
927
        return format.initialize_on_transport(t)
1376
928
 
1377
929
 
1378
930
class BzrDirHooks(hooks.Hooks):
1448
1000
    def cloning_metadir(self, require_stacking=False):
1449
1001
        """Produce a metadir suitable for cloning with."""
1450
1002
        if require_stacking:
1451
 
            return format_registry.make_bzrdir('1.6')
 
1003
            return controldir.format_registry.make_bzrdir('1.6')
1452
1004
        return self._format.__class__()
1453
1005
 
1454
1006
    def clone(self, url, revision_id=None, force_new_repo=False,
1474
1026
            tree.clone(result)
1475
1027
        return result
1476
1028
 
1477
 
    def create_branch(self, name=None):
 
1029
    def create_branch(self, name=None, repository=None):
1478
1030
        """See BzrDir.create_branch."""
 
1031
        if repository is not None:
 
1032
            raise NotImplementedError(
 
1033
                "create_branch(repository=<not None>) on %r" % (self,))
1479
1034
        return self._format.get_branch_format().initialize(self, name=name)
1480
1035
 
1481
1036
    def destroy_branch(self, name=None):
1711
1266
        """See BzrDir.can_convert_format()."""
1712
1267
        return True
1713
1268
 
1714
 
    def create_branch(self, name=None):
 
1269
    def create_branch(self, name=None, repository=None):
1715
1270
        """See BzrDir.create_branch."""
1716
 
        return self._format.get_branch_format().initialize(self, name=name)
 
1271
        return self._format.get_branch_format().initialize(self, name=name,
 
1272
                repository=repository)
1717
1273
 
1718
1274
    def destroy_branch(self, name=None):
1719
1275
        """See BzrDir.create_branch."""
1741
1297
        wt = self.open_workingtree(recommend_upgrade=False)
1742
1298
        repository = wt.branch.repository
1743
1299
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
1744
 
        wt.revert(old_tree=empty)
 
1300
        # We ignore the conflicts returned by wt.revert since we're about to
 
1301
        # delete the wt metadata anyway, all that should be left here are
 
1302
        # detritus. But see bug #634470 about subtree .bzr dirs.
 
1303
        conflicts = wt.revert(old_tree=empty)
1745
1304
        self.destroy_workingtree_metadata()
1746
1305
 
1747
1306
    def destroy_workingtree_metadata(self):
1891
1450
        return config.TransportConfig(self.transport, 'control.conf')
1892
1451
 
1893
1452
 
1894
 
class BzrDirFormat(object):
1895
 
    """An encapsulation of the initialization and open routines for a format.
1896
 
 
1897
 
    Formats provide three things:
1898
 
     * An initialization routine,
1899
 
     * a format string,
1900
 
     * an open routine.
 
1453
class BzrProber(controldir.Prober):
 
1454
    """Prober for formats that use a .bzr/ control directory."""
 
1455
 
 
1456
    _formats = {}
 
1457
    """The known .bzr formats."""
 
1458
 
 
1459
    @classmethod
 
1460
    def register_bzrdir_format(klass, format):
 
1461
        klass._formats[format.get_format_string()] = format
 
1462
 
 
1463
    @classmethod
 
1464
    def unregister_bzrdir_format(klass, format):
 
1465
        del klass._formats[format.get_format_string()]
 
1466
 
 
1467
    @classmethod
 
1468
    def probe_transport(klass, transport):
 
1469
        """Return the .bzrdir style format present in a directory."""
 
1470
        try:
 
1471
            format_string = transport.get_bytes(".bzr/branch-format")
 
1472
        except errors.NoSuchFile:
 
1473
            raise errors.NotBranchError(path=transport.base)
 
1474
        try:
 
1475
            return klass._formats[format_string]
 
1476
        except KeyError:
 
1477
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
 
1478
 
 
1479
 
 
1480
controldir.ControlDirFormat.register_prober(BzrProber)
 
1481
 
 
1482
 
 
1483
class RemoteBzrProber(controldir.Prober):
 
1484
    """Prober for remote servers that provide a Bazaar smart server."""
 
1485
 
 
1486
    @classmethod
 
1487
    def probe_transport(klass, transport):
 
1488
        """Return a RemoteBzrDirFormat object if it looks possible."""
 
1489
        try:
 
1490
            medium = transport.get_smart_medium()
 
1491
        except (NotImplementedError, AttributeError,
 
1492
                errors.TransportNotPossible, errors.NoSmartMedium,
 
1493
                errors.SmartProtocolError):
 
1494
            # no smart server, so not a branch for this format type.
 
1495
            raise errors.NotBranchError(path=transport.base)
 
1496
        else:
 
1497
            # Decline to open it if the server doesn't support our required
 
1498
            # version (3) so that the VFS-based transport will do it.
 
1499
            if medium.should_probe():
 
1500
                try:
 
1501
                    server_version = medium.protocol_version()
 
1502
                except errors.SmartProtocolError:
 
1503
                    # Apparently there's no usable smart server there, even though
 
1504
                    # the medium supports the smart protocol.
 
1505
                    raise errors.NotBranchError(path=transport.base)
 
1506
                if server_version != '2':
 
1507
                    raise errors.NotBranchError(path=transport.base)
 
1508
            return RemoteBzrDirFormat()
 
1509
 
 
1510
 
 
1511
class BzrDirFormat(controldir.ControlDirFormat):
 
1512
    """ControlDirFormat base class for .bzr/ directories.
1901
1513
 
1902
1514
    Formats are placed in a dict by their format string for reference
1903
1515
    during bzrdir opening. These should be subclasses of BzrDirFormat
1906
1518
    Once a format is deprecated, just deprecate the initialize and open
1907
1519
    methods on the format class. Do not deprecate the object, as the
1908
1520
    object will be created every system load.
1909
 
 
1910
 
    :cvar colocated_branches: Whether this formats supports colocated branches.
1911
 
    """
1912
 
 
1913
 
    _default_format = None
1914
 
    """The default format used for new .bzr dirs."""
1915
 
 
1916
 
    _formats = {}
1917
 
    """The known formats."""
1918
 
 
1919
 
    _control_formats = []
1920
 
    """The registered control formats - .bzr, ....
1921
 
 
1922
 
    This is a list of BzrDirFormat objects.
1923
 
    """
1924
 
 
1925
 
    _control_server_formats = []
1926
 
    """The registered control server formats, e.g. RemoteBzrDirs.
1927
 
 
1928
 
    This is a list of BzrDirFormat objects.
1929
1521
    """
1930
1522
 
1931
1523
    _lock_file_name = 'branch-lock'
1932
1524
 
1933
 
    colocated_branches = False
1934
 
    """Whether co-located branches are supported for this control dir format.
1935
 
    """
1936
 
 
1937
1525
    # _lock_class must be set in subclasses to the lock type, typ.
1938
1526
    # TransportLock or LockDir
1939
1527
 
1940
 
    @classmethod
1941
 
    def find_format(klass, transport, _server_formats=True):
1942
 
        """Return the format present at transport."""
1943
 
        if _server_formats:
1944
 
            formats = klass._control_server_formats + klass._control_formats
1945
 
        else:
1946
 
            formats = klass._control_formats
1947
 
        for format in formats:
1948
 
            try:
1949
 
                return format.probe_transport(transport)
1950
 
            except errors.NotBranchError:
1951
 
                # this format does not find a control dir here.
1952
 
                pass
1953
 
        raise errors.NotBranchError(path=transport.base)
1954
 
 
1955
 
    @classmethod
1956
 
    def probe_transport(klass, transport):
1957
 
        """Return the .bzrdir style format present in a directory."""
1958
 
        try:
1959
 
            format_string = transport.get_bytes(".bzr/branch-format")
1960
 
        except errors.NoSuchFile:
1961
 
            raise errors.NotBranchError(path=transport.base)
1962
 
        try:
1963
 
            return klass._formats[format_string]
1964
 
        except KeyError:
1965
 
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1966
 
 
1967
 
    @classmethod
1968
 
    def get_default_format(klass):
1969
 
        """Return the current default format."""
1970
 
        return klass._default_format
1971
 
 
1972
1528
    def get_format_string(self):
1973
1529
        """Return the ASCII format string that identifies this format."""
1974
1530
        raise NotImplementedError(self.get_format_string)
1975
1531
 
1976
 
    def get_format_description(self):
1977
 
        """Return the short description for this format."""
1978
 
        raise NotImplementedError(self.get_format_description)
1979
 
 
1980
 
    def get_converter(self, format=None):
1981
 
        """Return the converter to use to convert bzrdirs needing converts.
1982
 
 
1983
 
        This returns a bzrlib.bzrdir.Converter object.
1984
 
 
1985
 
        This should return the best upgrader to step this format towards the
1986
 
        current default format. In the case of plugins we can/should provide
1987
 
        some means for them to extend the range of returnable converters.
1988
 
 
1989
 
        :param format: Optional format to override the default format of the
1990
 
                       library.
1991
 
        """
1992
 
        raise NotImplementedError(self.get_converter)
1993
 
 
1994
 
    def initialize(self, url, possible_transports=None):
1995
 
        """Create a bzr control dir at this url and return an opened copy.
1996
 
 
1997
 
        While not deprecated, this method is very specific and its use will
1998
 
        lead to many round trips to setup a working environment. See
1999
 
        initialize_on_transport_ex for a [nearly] all-in-one method.
2000
 
 
2001
 
        Subclasses should typically override initialize_on_transport
2002
 
        instead of this method.
2003
 
        """
2004
 
        return self.initialize_on_transport(get_transport(url,
2005
 
                                                          possible_transports))
2006
 
 
2007
1532
    def initialize_on_transport(self, transport):
2008
1533
        """Initialize a new bzrdir in the base directory of a Transport."""
2009
1534
        try:
2141
1666
        utf8_files = [('README',
2142
1667
                       "This is a Bazaar control directory.\n"
2143
1668
                       "Do not change any files in this directory.\n"
2144
 
                       "See http://bazaar-vcs.org/ for more information about Bazaar.\n"),
 
1669
                       "See http://bazaar.canonical.com/ for more information about Bazaar.\n"),
2145
1670
                      ('branch-format', self.get_format_string()),
2146
1671
                      ]
2147
1672
        # NB: no need to escape relative paths that are url safe.
2157
1682
            control_files.unlock()
2158
1683
        return self.open(transport, _found=True)
2159
1684
 
2160
 
    def is_supported(self):
2161
 
        """Is this format supported?
2162
 
 
2163
 
        Supported formats must be initializable and openable.
2164
 
        Unsupported formats may not support initialization or committing or
2165
 
        some other features depending on the reason for not being supported.
2166
 
        """
2167
 
        return True
2168
 
 
2169
 
    def network_name(self):
2170
 
        """A simple byte string uniquely identifying this format for RPC calls.
2171
 
 
2172
 
        Bzr control formats use thir disk format string to identify the format
2173
 
        over the wire. Its possible that other control formats have more
2174
 
        complex detection requirements, so we permit them to use any unique and
2175
 
        immutable string they desire.
2176
 
        """
2177
 
        raise NotImplementedError(self.network_name)
2178
 
 
2179
 
    def same_model(self, target_format):
2180
 
        return (self.repository_format.rich_root_data ==
2181
 
            target_format.rich_root_data)
2182
 
 
2183
 
    @classmethod
2184
 
    def known_formats(klass):
2185
 
        """Return all the known formats.
2186
 
 
2187
 
        Concrete formats should override _known_formats.
2188
 
        """
2189
 
        # There is double indirection here to make sure that control
2190
 
        # formats used by more than one dir format will only be probed
2191
 
        # once. This can otherwise be quite expensive for remote connections.
2192
 
        result = set()
2193
 
        for format in klass._control_formats:
2194
 
            result.update(format._known_formats())
2195
 
        return result
2196
 
 
2197
 
    @classmethod
2198
 
    def _known_formats(klass):
2199
 
        """Return the known format instances for this control format."""
2200
 
        return set(klass._formats.values())
2201
 
 
2202
1685
    def open(self, transport, _found=False):
2203
1686
        """Return an instance of this format for the dir transport points at.
2204
1687
 
2205
1688
        _found is a private parameter, do not use it.
2206
1689
        """
2207
1690
        if not _found:
2208
 
            found_format = BzrDirFormat.find_format(transport)
 
1691
            found_format = controldir.ControlDirFormat.find_format(transport)
2209
1692
            if not isinstance(found_format, self.__class__):
2210
1693
                raise AssertionError("%s was asked to open %s, but it seems to need "
2211
1694
                        "format %s"
2225
1708
 
2226
1709
    @classmethod
2227
1710
    def register_format(klass, format):
2228
 
        klass._formats[format.get_format_string()] = format
 
1711
        BzrProber.register_bzrdir_format(format)
2229
1712
        # bzr native formats have a network name of their format string.
2230
 
        network_format_registry.register(format.get_format_string(), format.__class__)
2231
 
 
2232
 
    @classmethod
2233
 
    def register_control_format(klass, format):
2234
 
        """Register a format that does not use '.bzr' for its control dir.
2235
 
 
2236
 
        TODO: This should be pulled up into a 'ControlDirFormat' base class
2237
 
        which BzrDirFormat can inherit from, and renamed to register_format
2238
 
        there. It has been done without that for now for simplicity of
2239
 
        implementation.
2240
 
        """
2241
 
        klass._control_formats.append(format)
2242
 
 
2243
 
    @classmethod
2244
 
    def register_control_server_format(klass, format):
2245
 
        """Register a control format for client-server environments.
2246
 
 
2247
 
        These formats will be tried before ones registered with
2248
 
        register_control_format.  This gives implementations that decide to the
2249
 
        chance to grab it before anything looks at the contents of the format
2250
 
        file.
2251
 
        """
2252
 
        klass._control_server_formats.append(format)
2253
 
 
2254
 
    @classmethod
2255
 
    def _set_default_format(klass, format):
2256
 
        """Set default format (for testing behavior of defaults only)"""
2257
 
        klass._default_format = format
2258
 
 
2259
 
    def __str__(self):
2260
 
        # Trim the newline
2261
 
        return self.get_format_description().rstrip()
 
1713
        controldir.network_format_registry.register(format.get_format_string(), format.__class__)
 
1714
        controldir.ControlDirFormat.register_format(format)
2262
1715
 
2263
1716
    def _supply_sub_formats_to(self, other_format):
2264
1717
        """Give other_format the same values for sub formats as this has.
2274
1727
 
2275
1728
    @classmethod
2276
1729
    def unregister_format(klass, format):
2277
 
        del klass._formats[format.get_format_string()]
2278
 
 
2279
 
    @classmethod
2280
 
    def unregister_control_format(klass, format):
2281
 
        klass._control_formats.remove(format)
 
1730
        BzrProber.unregister_bzrdir_format(format)
 
1731
        controldir.ControlDirFormat.unregister_format(format)
 
1732
        controldir.network_format_registry.remove(format.get_format_string())
2282
1733
 
2283
1734
 
2284
1735
class BzrDirFormat4(BzrDirFormat):
2392
1843
        return ConvertBzrDir5To6()
2393
1844
 
2394
1845
    def _initialize_for_clone(self, url):
2395
 
        return self.initialize_on_transport(get_transport(url), _cloning=True)
 
1846
        return self.initialize_on_transport(
 
1847
            _mod_transport.get_transport(url), _cloning=True)
2396
1848
 
2397
1849
    def initialize_on_transport(self, transport, _cloning=False):
2398
1850
        """Format 5 dirs always have working tree, branch and repository.
2452
1904
        return ConvertBzrDir6ToMeta()
2453
1905
 
2454
1906
    def _initialize_for_clone(self, url):
2455
 
        return self.initialize_on_transport(get_transport(url), _cloning=True)
 
1907
        return self.initialize_on_transport(
 
1908
            _mod_transport.get_transport(url), _cloning=True)
2456
1909
 
2457
1910
    def initialize_on_transport(self, transport, _cloning=False):
2458
1911
        """Format 6 dirs always have working tree, branch and repository.
2687
2140
                                  __set_workingtree_format)
2688
2141
 
2689
2142
 
2690
 
network_format_registry = registry.FormatRegistry()
2691
 
"""Registry of formats indexed by their network name.
2692
 
 
2693
 
The network name for a BzrDirFormat is an identifier that can be used when
2694
 
referring to formats with smart server operations. See
2695
 
BzrDirFormat.network_name() for more detail.
2696
 
"""
2697
 
 
2698
 
 
2699
 
# Register bzr control format
2700
 
BzrDirFormat.register_control_format(BzrDirFormat)
2701
 
 
2702
2143
# Register bzr formats
2703
2144
BzrDirFormat.register_format(BzrDirFormat4())
2704
2145
BzrDirFormat.register_format(BzrDirFormat5())
2705
2146
BzrDirFormat.register_format(BzrDirFormat6())
2706
2147
__default_format = BzrDirMetaFormat1()
2707
2148
BzrDirFormat.register_format(__default_format)
2708
 
BzrDirFormat._default_format = __default_format
 
2149
controldir.ControlDirFormat._default_format = __default_format
2709
2150
 
2710
2151
 
2711
2152
class Converter(object):
2939
2380
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2940
2381
            in heads)
2941
2382
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2942
 
        del ie.text_id
2943
2383
 
2944
2384
    def get_parent_map(self, revision_ids):
2945
2385
        """See graph.StackedParentsProvider.get_parent_map"""
3247
2687
class RemoteBzrDirFormat(BzrDirMetaFormat1):
3248
2688
    """Format representing bzrdirs accessed via a smart server"""
3249
2689
 
 
2690
    supports_workingtrees = False
 
2691
 
3250
2692
    def __init__(self):
3251
2693
        BzrDirMetaFormat1.__init__(self)
3252
2694
        # XXX: It's a bit ugly that the network name is here, because we'd
3261
2703
 
3262
2704
    def get_format_description(self):
3263
2705
        if self._network_name:
3264
 
            real_format = network_format_registry.get(self._network_name)
 
2706
            real_format = controldir.network_format_registry.get(self._network_name)
3265
2707
            return 'Remote: ' + real_format.get_format_description()
3266
2708
        return 'bzr remote bzrdir'
3267
2709
 
3274
2716
        else:
3275
2717
            raise AssertionError("No network name set.")
3276
2718
 
3277
 
    @classmethod
3278
 
    def probe_transport(klass, transport):
3279
 
        """Return a RemoteBzrDirFormat object if it looks possible."""
3280
 
        try:
3281
 
            medium = transport.get_smart_medium()
3282
 
        except (NotImplementedError, AttributeError,
3283
 
                errors.TransportNotPossible, errors.NoSmartMedium,
3284
 
                errors.SmartProtocolError):
3285
 
            # no smart server, so not a branch for this format type.
3286
 
            raise errors.NotBranchError(path=transport.base)
3287
 
        else:
3288
 
            # Decline to open it if the server doesn't support our required
3289
 
            # version (3) so that the VFS-based transport will do it.
3290
 
            if medium.should_probe():
3291
 
                try:
3292
 
                    server_version = medium.protocol_version()
3293
 
                except errors.SmartProtocolError:
3294
 
                    # Apparently there's no usable smart server there, even though
3295
 
                    # the medium supports the smart protocol.
3296
 
                    raise errors.NotBranchError(path=transport.base)
3297
 
                if server_version != '2':
3298
 
                    raise errors.NotBranchError(path=transport.base)
3299
 
            return klass()
3300
 
 
3301
2719
    def initialize_on_transport(self, transport):
3302
2720
        try:
3303
2721
            # hand off the request to the smart server
3502
2920
        BzrDirMetaFormat1._set_repository_format) #.im_func)
3503
2921
 
3504
2922
 
3505
 
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
3506
 
 
3507
 
 
3508
 
class BzrDirFormatInfo(object):
3509
 
 
3510
 
    def __init__(self, native, deprecated, hidden, experimental):
3511
 
        self.deprecated = deprecated
3512
 
        self.native = native
3513
 
        self.hidden = hidden
3514
 
        self.experimental = experimental
3515
 
 
3516
 
 
3517
 
class BzrDirFormatRegistry(registry.Registry):
3518
 
    """Registry of user-selectable BzrDir subformats.
3519
 
 
3520
 
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
3521
 
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
3522
 
    """
3523
 
 
3524
 
    def __init__(self):
3525
 
        """Create a BzrDirFormatRegistry."""
3526
 
        self._aliases = set()
3527
 
        self._registration_order = list()
3528
 
        super(BzrDirFormatRegistry, self).__init__()
3529
 
 
3530
 
    def aliases(self):
3531
 
        """Return a set of the format names which are aliases."""
3532
 
        return frozenset(self._aliases)
3533
 
 
3534
 
    def register_metadir(self, key,
3535
 
             repository_format, help, native=True, deprecated=False,
3536
 
             branch_format=None,
3537
 
             tree_format=None,
3538
 
             hidden=False,
3539
 
             experimental=False,
3540
 
             alias=False):
3541
 
        """Register a metadir subformat.
3542
 
 
3543
 
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3544
 
        by the Repository/Branch/WorkingTreeformats.
3545
 
 
3546
 
        :param repository_format: The fully-qualified repository format class
3547
 
            name as a string.
3548
 
        :param branch_format: Fully-qualified branch format class name as
3549
 
            a string.
3550
 
        :param tree_format: Fully-qualified tree format class name as
3551
 
            a string.
3552
 
        """
3553
 
        # This should be expanded to support setting WorkingTree and Branch
3554
 
        # formats, once BzrDirMetaFormat1 supports that.
3555
 
        def _load(full_name):
3556
 
            mod_name, factory_name = full_name.rsplit('.', 1)
3557
 
            try:
3558
 
                mod = __import__(mod_name, globals(), locals(),
3559
 
                        [factory_name])
3560
 
            except ImportError, e:
3561
 
                raise ImportError('failed to load %s: %s' % (full_name, e))
3562
 
            try:
3563
 
                factory = getattr(mod, factory_name)
3564
 
            except AttributeError:
3565
 
                raise AttributeError('no factory %s in module %r'
3566
 
                    % (full_name, mod))
3567
 
            return factory()
3568
 
 
3569
 
        def helper():
3570
 
            bd = BzrDirMetaFormat1()
3571
 
            if branch_format is not None:
3572
 
                bd.set_branch_format(_load(branch_format))
3573
 
            if tree_format is not None:
3574
 
                bd.workingtree_format = _load(tree_format)
3575
 
            if repository_format is not None:
3576
 
                bd.repository_format = _load(repository_format)
3577
 
            return bd
3578
 
        self.register(key, helper, help, native, deprecated, hidden,
3579
 
            experimental, alias)
3580
 
 
3581
 
    def register(self, key, factory, help, native=True, deprecated=False,
3582
 
                 hidden=False, experimental=False, alias=False):
3583
 
        """Register a BzrDirFormat factory.
3584
 
 
3585
 
        The factory must be a callable that takes one parameter: the key.
3586
 
        It must produce an instance of the BzrDirFormat when called.
3587
 
 
3588
 
        This function mainly exists to prevent the info object from being
3589
 
        supplied directly.
3590
 
        """
3591
 
        registry.Registry.register(self, key, factory, help,
3592
 
            BzrDirFormatInfo(native, deprecated, hidden, experimental))
3593
 
        if alias:
3594
 
            self._aliases.add(key)
3595
 
        self._registration_order.append(key)
3596
 
 
3597
 
    def register_lazy(self, key, module_name, member_name, help, native=True,
3598
 
        deprecated=False, hidden=False, experimental=False, alias=False):
3599
 
        registry.Registry.register_lazy(self, key, module_name, member_name,
3600
 
            help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
3601
 
        if alias:
3602
 
            self._aliases.add(key)
3603
 
        self._registration_order.append(key)
3604
 
 
3605
 
    def set_default(self, key):
3606
 
        """Set the 'default' key to be a clone of the supplied key.
3607
 
 
3608
 
        This method must be called once and only once.
3609
 
        """
3610
 
        registry.Registry.register(self, 'default', self.get(key),
3611
 
            self.get_help(key), info=self.get_info(key))
3612
 
        self._aliases.add('default')
3613
 
 
3614
 
    def set_default_repository(self, key):
3615
 
        """Set the FormatRegistry default and Repository default.
3616
 
 
3617
 
        This is a transitional method while Repository.set_default_format
3618
 
        is deprecated.
3619
 
        """
3620
 
        if 'default' in self:
3621
 
            self.remove('default')
3622
 
        self.set_default(key)
3623
 
        format = self.get('default')()
3624
 
 
3625
 
    def make_bzrdir(self, key):
3626
 
        return self.get(key)()
3627
 
 
3628
 
    def help_topic(self, topic):
3629
 
        output = ""
3630
 
        default_realkey = None
3631
 
        default_help = self.get_help('default')
3632
 
        help_pairs = []
3633
 
        for key in self._registration_order:
3634
 
            if key == 'default':
3635
 
                continue
3636
 
            help = self.get_help(key)
3637
 
            if help == default_help:
3638
 
                default_realkey = key
3639
 
            else:
3640
 
                help_pairs.append((key, help))
3641
 
 
3642
 
        def wrapped(key, help, info):
3643
 
            if info.native:
3644
 
                help = '(native) ' + help
3645
 
            return ':%s:\n%s\n\n' % (key,
3646
 
                textwrap.fill(help, initial_indent='    ',
3647
 
                    subsequent_indent='    ',
3648
 
                    break_long_words=False))
3649
 
        if default_realkey is not None:
3650
 
            output += wrapped(default_realkey, '(default) %s' % default_help,
3651
 
                              self.get_info('default'))
3652
 
        deprecated_pairs = []
3653
 
        experimental_pairs = []
3654
 
        for key, help in help_pairs:
3655
 
            info = self.get_info(key)
3656
 
            if info.hidden:
3657
 
                continue
3658
 
            elif info.deprecated:
3659
 
                deprecated_pairs.append((key, help))
3660
 
            elif info.experimental:
3661
 
                experimental_pairs.append((key, help))
3662
 
            else:
3663
 
                output += wrapped(key, help, info)
3664
 
        output += "\nSee :doc:`formats-help` for more about storage formats."
3665
 
        other_output = ""
3666
 
        if len(experimental_pairs) > 0:
3667
 
            other_output += "Experimental formats are shown below.\n\n"
3668
 
            for key, help in experimental_pairs:
3669
 
                info = self.get_info(key)
3670
 
                other_output += wrapped(key, help, info)
3671
 
        else:
3672
 
            other_output += \
3673
 
                "No experimental formats are available.\n\n"
3674
 
        if len(deprecated_pairs) > 0:
3675
 
            other_output += "\nDeprecated formats are shown below.\n\n"
3676
 
            for key, help in deprecated_pairs:
3677
 
                info = self.get_info(key)
3678
 
                other_output += wrapped(key, help, info)
3679
 
        else:
3680
 
            other_output += \
3681
 
                "\nNo deprecated formats are available.\n\n"
3682
 
        other_output += \
3683
 
                "\nSee :doc:`formats-help` for more about storage formats."
3684
 
 
3685
 
        if topic == 'other-formats':
3686
 
            return other_output
3687
 
        else:
3688
 
            return output
 
2923
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
3689
2924
 
3690
2925
 
3691
2926
class RepositoryAcquisitionPolicy(object):
3845
3080
        return self._repository, False
3846
3081
 
3847
3082
 
3848
 
# Please register new formats after old formats so that formats
3849
 
# appear in chronological order and format descriptions can build
3850
 
# on previous ones.
3851
 
format_registry = BzrDirFormatRegistry()
 
3083
def register_metadir(registry, key,
 
3084
         repository_format, help, native=True, deprecated=False,
 
3085
         branch_format=None,
 
3086
         tree_format=None,
 
3087
         hidden=False,
 
3088
         experimental=False,
 
3089
         alias=False):
 
3090
    """Register a metadir subformat.
 
3091
 
 
3092
    These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
 
3093
    by the Repository/Branch/WorkingTreeformats.
 
3094
 
 
3095
    :param repository_format: The fully-qualified repository format class
 
3096
        name as a string.
 
3097
    :param branch_format: Fully-qualified branch format class name as
 
3098
        a string.
 
3099
    :param tree_format: Fully-qualified tree format class name as
 
3100
        a string.
 
3101
    """
 
3102
    # This should be expanded to support setting WorkingTree and Branch
 
3103
    # formats, once BzrDirMetaFormat1 supports that.
 
3104
    def _load(full_name):
 
3105
        mod_name, factory_name = full_name.rsplit('.', 1)
 
3106
        try:
 
3107
            factory = pyutils.get_named_object(mod_name, factory_name)
 
3108
        except ImportError, e:
 
3109
            raise ImportError('failed to load %s: %s' % (full_name, e))
 
3110
        except AttributeError:
 
3111
            raise AttributeError('no factory %s in module %r'
 
3112
                % (full_name, sys.modules[mod_name]))
 
3113
        return factory()
 
3114
 
 
3115
    def helper():
 
3116
        bd = BzrDirMetaFormat1()
 
3117
        if branch_format is not None:
 
3118
            bd.set_branch_format(_load(branch_format))
 
3119
        if tree_format is not None:
 
3120
            bd.workingtree_format = _load(tree_format)
 
3121
        if repository_format is not None:
 
3122
            bd.repository_format = _load(repository_format)
 
3123
        return bd
 
3124
    registry.register(key, helper, help, native, deprecated, hidden,
 
3125
        experimental, alias)
 
3126
 
3852
3127
# The pre-0.8 formats have their repository format network name registered in
3853
3128
# repository.py. MetaDir formats have their repository format network name
3854
3129
# inferred from their disk format string.
3855
 
format_registry.register('weave', BzrDirFormat6,
 
3130
controldir.format_registry.register('weave', BzrDirFormat6,
3856
3131
    'Pre-0.8 format.  Slower than knit and does not'
3857
3132
    ' support checkouts or shared repositories.',
3858
3133
    hidden=True,
3859
3134
    deprecated=True)
3860
 
format_registry.register_metadir('metaweave',
 
3135
register_metadir(controldir.format_registry, 'metaweave',
3861
3136
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3862
3137
    'Transitional format in 0.8.  Slower than knit.',
3863
3138
    branch_format='bzrlib.branch.BzrBranchFormat5',
3864
3139
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3865
3140
    hidden=True,
3866
3141
    deprecated=True)
3867
 
format_registry.register_metadir('knit',
 
3142
register_metadir(controldir.format_registry, 'knit',
3868
3143
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3869
3144
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
3870
3145
    branch_format='bzrlib.branch.BzrBranchFormat5',
3871
3146
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3872
3147
    hidden=True,
3873
3148
    deprecated=True)
3874
 
format_registry.register_metadir('dirstate',
 
3149
register_metadir(controldir.format_registry, 'dirstate',
3875
3150
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3876
3151
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3877
3152
        'above when accessed over the network.',
3881
3156
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3882
3157
    hidden=True,
3883
3158
    deprecated=True)
3884
 
format_registry.register_metadir('dirstate-tags',
 
3159
register_metadir(controldir.format_registry, 'dirstate-tags',
3885
3160
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3886
3161
    help='New in 0.15: Fast local operations and improved scaling for '
3887
3162
        'network operations. Additionally adds support for tags.'
3890
3165
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3891
3166
    hidden=True,
3892
3167
    deprecated=True)
3893
 
format_registry.register_metadir('rich-root',
 
3168
register_metadir(controldir.format_registry, 'rich-root',
3894
3169
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
3895
3170
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
3896
3171
        ' bzr < 1.0.',
3898
3173
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3899
3174
    hidden=True,
3900
3175
    deprecated=True)
3901
 
format_registry.register_metadir('dirstate-with-subtree',
 
3176
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
3902
3177
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3903
3178
    help='New in 0.15: Fast local operations and improved scaling for '
3904
3179
        'network operations. Additionally adds support for versioning nested '
3908
3183
    experimental=True,
3909
3184
    hidden=True,
3910
3185
    )
3911
 
format_registry.register_metadir('pack-0.92',
 
3186
register_metadir(controldir.format_registry, 'pack-0.92',
3912
3187
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
3913
3188
    help='New in 0.92: Pack-based format with data compatible with '
3914
3189
        'dirstate-tags format repositories. Interoperates with '
3917
3192
    branch_format='bzrlib.branch.BzrBranchFormat6',
3918
3193
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3919
3194
    )
3920
 
format_registry.register_metadir('pack-0.92-subtree',
 
3195
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
3921
3196
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
3922
3197
    help='New in 0.92: Pack-based format with data compatible with '
3923
3198
        'dirstate-with-subtree format repositories. Interoperates with '
3928
3203
    hidden=True,
3929
3204
    experimental=True,
3930
3205
    )
3931
 
format_registry.register_metadir('rich-root-pack',
 
3206
register_metadir(controldir.format_registry, 'rich-root-pack',
3932
3207
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3933
3208
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3934
3209
         '(needed for bzr-svn and bzr-git).',
3936
3211
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3937
3212
    hidden=True,
3938
3213
    )
3939
 
format_registry.register_metadir('1.6',
 
3214
register_metadir(controldir.format_registry, '1.6',
3940
3215
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3941
3216
    help='A format that allows a branch to indicate that there is another '
3942
3217
         '(stacked) repository that should be used to access data that is '
3945
3220
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3946
3221
    hidden=True,
3947
3222
    )
3948
 
format_registry.register_metadir('1.6.1-rich-root',
 
3223
register_metadir(controldir.format_registry, '1.6.1-rich-root',
3949
3224
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3950
3225
    help='A variant of 1.6 that supports rich-root data '
3951
3226
         '(needed for bzr-svn and bzr-git).',
3953
3228
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3954
3229
    hidden=True,
3955
3230
    )
3956
 
format_registry.register_metadir('1.9',
 
3231
register_metadir(controldir.format_registry, '1.9',
3957
3232
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3958
3233
    help='A repository format using B+tree indexes. These indexes '
3959
3234
         'are smaller in size, have smarter caching and provide faster '
3962
3237
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3963
3238
    hidden=True,
3964
3239
    )
3965
 
format_registry.register_metadir('1.9-rich-root',
 
3240
register_metadir(controldir.format_registry, '1.9-rich-root',
3966
3241
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3967
3242
    help='A variant of 1.9 that supports rich-root data '
3968
3243
         '(needed for bzr-svn and bzr-git).',
3970
3245
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3971
3246
    hidden=True,
3972
3247
    )
3973
 
format_registry.register_metadir('1.14',
 
3248
register_metadir(controldir.format_registry, '1.14',
3974
3249
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3975
3250
    help='A working-tree format that supports content filtering.',
3976
3251
    branch_format='bzrlib.branch.BzrBranchFormat7',
3977
3252
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3978
3253
    )
3979
 
format_registry.register_metadir('1.14-rich-root',
 
3254
register_metadir(controldir.format_registry, '1.14-rich-root',
3980
3255
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3981
3256
    help='A variant of 1.14 that supports rich-root data '
3982
3257
         '(needed for bzr-svn and bzr-git).',
3984
3259
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3985
3260
    )
3986
3261
# The following un-numbered 'development' formats should always just be aliases.
3987
 
format_registry.register_metadir('development-rich-root',
3988
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3989
 
    help='Current development format. Supports rich roots. Can convert data '
3990
 
        'to and from rich-root-pack (and anything compatible with '
3991
 
        'rich-root-pack) format repositories. Repositories and branches in '
3992
 
        'this format can only be read by bzr.dev. Please read '
3993
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3994
 
        'before use.',
3995
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3996
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3997
 
    experimental=True,
3998
 
    alias=True,
3999
 
    hidden=True,
4000
 
    )
4001
 
format_registry.register_metadir('development-subtree',
4002
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
3262
register_metadir(controldir.format_registry, 'development-subtree',
 
3263
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
4003
3264
    help='Current development format, subtree variant. Can convert data to and '
4004
3265
        'from pack-0.92-subtree (and anything compatible with '
4005
3266
        'pack-0.92-subtree) format repositories. Repositories and branches in '
4014
3275
                 # This current non-alias status is simply because we did not introduce a
4015
3276
                 # chk based subtree format.
4016
3277
    )
 
3278
register_metadir(controldir.format_registry, 'development5-subtree',
 
3279
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
3280
    help='Development format, subtree variant. Can convert data to and '
 
3281
        'from pack-0.92-subtree (and anything compatible with '
 
3282
        'pack-0.92-subtree) format repositories. Repositories and branches in '
 
3283
        'this format can only be read by bzr.dev. Please read '
 
3284
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3285
        'before use.',
 
3286
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3287
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3288
    experimental=True,
 
3289
    hidden=True,
 
3290
    alias=False,
 
3291
    )
4017
3292
 
4018
3293
# And the development formats above will have aliased one of the following:
4019
 
format_registry.register_metadir('development6-rich-root',
4020
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
4021
 
    help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
4022
 
        'Please read '
4023
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
4024
 
        'before use.',
4025
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
4026
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
4027
 
    hidden=True,
4028
 
    experimental=True,
4029
 
    )
4030
 
 
4031
 
format_registry.register_metadir('development7-rich-root',
4032
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
4033
 
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
4034
 
        'rich roots. Please read '
4035
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
4036
 
        'before use.',
4037
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
4038
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
4039
 
    hidden=True,
4040
 
    experimental=True,
4041
 
    )
4042
 
 
4043
 
format_registry.register_metadir('2a',
 
3294
 
 
3295
# Finally, the current format.
 
3296
register_metadir(controldir.format_registry, '2a',
4044
3297
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
4045
3298
    help='First format for bzr 2.0 series.\n'
4046
3299
        'Uses group-compress storage.\n'
4049
3302
        # 'rich roots. Supported by bzr 1.16 and later.',
4050
3303
    branch_format='bzrlib.branch.BzrBranchFormat7',
4051
3304
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
4052
 
    experimental=True,
 
3305
    experimental=False,
4053
3306
    )
4054
3307
 
4055
3308
# The following format should be an alias for the rich root equivalent 
4056
3309
# of the default format
4057
 
format_registry.register_metadir('default-rich-root',
 
3310
register_metadir(controldir.format_registry, 'default-rich-root',
4058
3311
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
4059
3312
    branch_format='bzrlib.branch.BzrBranchFormat7',
4060
3313
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
4063
3316
    help='Same as 2a.')
4064
3317
 
4065
3318
# The current format that is made on 'bzr init'.
4066
 
format_registry.set_default('2a')
 
3319
format_name = config.GlobalConfig().get_user_option('default_format')
 
3320
if format_name is None:
 
3321
    controldir.format_registry.set_default('2a')
 
3322
else:
 
3323
    controldir.format_registry.set_default(format_name)
 
3324
 
 
3325
# XXX 2010-08-20 JRV: There is still a lot of code relying on
 
3326
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc
 
3327
# get changed to ControlDir.create/ControlDir.open/etc this should be removed.
 
3328
format_registry = controldir.format_registry