~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Packman
  • Date: 2012-01-05 10:37:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105103758-wzftnmsip5iv9n2g
Revert addition of get_message_encoding function

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    transport as _mod_transport,
47
47
    ui,
48
48
    urlutils,
 
49
    vf_search,
49
50
    win32utils,
50
51
    workingtree_3,
51
52
    workingtree_4,
55
56
    do_catching_redirections,
56
57
    local,
57
58
    )
 
59
from bzrlib.i18n import gettext
58
60
""")
59
61
 
60
62
from bzrlib.trace import (
65
67
from bzrlib import (
66
68
    config,
67
69
    controldir,
68
 
    hooks,
69
70
    registry,
70
71
    )
71
72
from bzrlib.symbol_versioning import (
200
201
                if (result_repo.user_url == result.user_url
201
202
                    and not require_stacking and
202
203
                    revision_id is not None):
203
 
                    fetch_spec = graph.PendingAncestryResult(
 
204
                    fetch_spec = vf_search.PendingAncestryResult(
204
205
                        [revision_id], local_repo)
205
206
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
206
207
                else:
221
222
            # the tree and fail.
222
223
            result.root_transport.local_abspath('.')
223
224
            if result_repo is None or result_repo.make_working_trees():
224
 
                self.open_workingtree().clone(result)
 
225
                self.open_workingtree().clone(result, revision_id=revision_id)
225
226
        except (errors.NoWorkingTree, errors.NotLocalUrl):
226
227
            pass
227
228
        return result
232
233
        t = _mod_transport.get_transport(url)
233
234
        t.ensure_base()
234
235
 
235
 
    @staticmethod
236
 
    def find_bzrdirs(transport, evaluate=None, list_current=None):
237
 
        """Find bzrdirs recursively from current location.
238
 
 
239
 
        This is intended primarily as a building block for more sophisticated
240
 
        functionality, like finding trees under a directory, or finding
241
 
        branches that use a given repository.
242
 
 
243
 
        :param evaluate: An optional callable that yields recurse, value,
244
 
            where recurse controls whether this bzrdir is recursed into
245
 
            and value is the value to yield.  By default, all bzrdirs
246
 
            are recursed into, and the return value is the bzrdir.
247
 
        :param list_current: if supplied, use this function to list the current
248
 
            directory, instead of Transport.list_dir
249
 
        :return: a generator of found bzrdirs, or whatever evaluate returns.
250
 
        """
251
 
        if list_current is None:
252
 
            def list_current(transport):
253
 
                return transport.list_dir('')
254
 
        if evaluate is None:
255
 
            def evaluate(bzrdir):
256
 
                return True, bzrdir
257
 
 
258
 
        pending = [transport]
259
 
        while len(pending) > 0:
260
 
            current_transport = pending.pop()
261
 
            recurse = True
262
 
            try:
263
 
                bzrdir = BzrDir.open_from_transport(current_transport)
264
 
            except (errors.NotBranchError, errors.PermissionDenied):
265
 
                pass
266
 
            else:
267
 
                recurse, value = evaluate(bzrdir)
268
 
                yield value
269
 
            try:
270
 
                subdirs = list_current(current_transport)
271
 
            except (errors.NoSuchFile, errors.PermissionDenied):
272
 
                continue
273
 
            if recurse:
274
 
                for subdir in sorted(subdirs, reverse=True):
275
 
                    pending.append(current_transport.clone(subdir))
276
 
 
277
 
    @staticmethod
278
 
    def find_branches(transport):
279
 
        """Find all branches under a transport.
280
 
 
281
 
        This will find all branches below the transport, including branches
282
 
        inside other branches.  Where possible, it will use
283
 
        Repository.find_branches.
284
 
 
285
 
        To list all the branches that use a particular Repository, see
286
 
        Repository.find_branches
287
 
        """
288
 
        def evaluate(bzrdir):
289
 
            try:
290
 
                repository = bzrdir.open_repository()
291
 
            except errors.NoRepositoryPresent:
292
 
                pass
293
 
            else:
294
 
                return False, ([], repository)
295
 
            return True, (bzrdir.list_branches(), None)
296
 
        ret = []
297
 
        for branches, repo in BzrDir.find_bzrdirs(transport,
298
 
                                                  evaluate=evaluate):
299
 
            if repo is not None:
300
 
                ret.extend(repo.find_branches())
301
 
            if branches is not None:
302
 
                ret.extend(branches)
303
 
        return ret
304
 
 
305
 
    @staticmethod
306
 
    def create_branch_and_repo(base, force_new_repo=False, format=None):
307
 
        """Create a new BzrDir, Branch and Repository at the url 'base'.
308
 
 
309
 
        This will use the current default BzrDirFormat unless one is
310
 
        specified, and use whatever
311
 
        repository format that that uses via bzrdir.create_branch and
312
 
        create_repository. If a shared repository is available that is used
313
 
        preferentially.
314
 
 
315
 
        The created Branch object is returned.
316
 
 
317
 
        :param base: The URL to create the branch at.
318
 
        :param force_new_repo: If True a new repository is always created.
319
 
        :param format: If supplied, the format of branch to create.  If not
320
 
            supplied, the default is used.
321
 
        """
322
 
        bzrdir = BzrDir.create(base, format)
323
 
        bzrdir._find_or_create_repository(force_new_repo)
324
 
        return bzrdir.create_branch()
325
 
 
326
236
    def determine_repository_policy(self, force_new_repo=False, stack_on=None,
327
237
                                    stack_on_pwd=None, require_stacking=False):
328
238
        """Return an object representing a policy to use.
461
371
        if revision_id is not None:
462
372
            fetch_spec_factory.add_revision_ids([revision_id])
463
373
            fetch_spec_factory.source_branch_stop_revision_id = revision_id
 
374
        if possible_transports is None:
 
375
            possible_transports = []
 
376
        else:
 
377
            possible_transports = list(possible_transports) + [
 
378
                self.root_transport]
464
379
        target_transport = _mod_transport.get_transport(url,
465
380
            possible_transports)
466
381
        target_transport.ensure_base()
467
382
        cloning_format = self.cloning_metadir(stacked)
468
383
        # Create/update the result branch
469
 
        result = cloning_format.initialize_on_transport(target_transport)
 
384
        try:
 
385
            result = controldir.ControlDir.open_from_transport(target_transport)
 
386
        except errors.NotBranchError:
 
387
            result = cloning_format.initialize_on_transport(target_transport)
470
388
        source_branch, source_repository = self._find_source_repo(
471
389
            add_cleanup, source_branch)
472
390
        fetch_spec_factory.source_branch = source_branch
478
396
            stacked_branch_url = None
479
397
        repository_policy = result.determine_repository_policy(
480
398
            force_new_repo, stacked_branch_url, require_stacking=stacked)
481
 
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
399
        result_repo, is_new_repo = repository_policy.acquire_repository(
 
400
            possible_transports=possible_transports)
482
401
        add_cleanup(result_repo.lock_write().unlock)
483
402
        fetch_spec_factory.source_repo = source_repository
484
403
        fetch_spec_factory.target_repo = result_repo
505
424
        mutter("created new branch %r" % (result_branch,))
506
425
 
507
426
        # Create/update the result working tree
508
 
        if (create_tree_if_local and
 
427
        if (create_tree_if_local and not result.has_workingtree() and
509
428
            isinstance(target_transport, local.LocalTransport) and
510
429
            (result_repo is None or result_repo.make_working_trees())):
511
430
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
543
462
                    stacked=stacked)
544
463
        return result
545
464
 
546
 
 
547
 
 
548
 
    @staticmethod
549
 
    def create_branch_convenience(base, force_new_repo=False,
550
 
                                  force_new_tree=None, format=None,
551
 
                                  possible_transports=None):
552
 
        """Create a new BzrDir, Branch and Repository at the url 'base'.
553
 
 
554
 
        This is a convenience function - it will use an existing repository
555
 
        if possible, can be told explicitly whether to create a working tree or
556
 
        not.
557
 
 
558
 
        This will use the current default BzrDirFormat unless one is
559
 
        specified, and use whatever
560
 
        repository format that that uses via bzrdir.create_branch and
561
 
        create_repository. If a shared repository is available that is used
562
 
        preferentially. Whatever repository is used, its tree creation policy
563
 
        is followed.
564
 
 
565
 
        The created Branch object is returned.
566
 
        If a working tree cannot be made due to base not being a file:// url,
567
 
        no error is raised unless force_new_tree is True, in which case no
568
 
        data is created on disk and NotLocalUrl is raised.
569
 
 
570
 
        :param base: The URL to create the branch at.
571
 
        :param force_new_repo: If True a new repository is always created.
572
 
        :param force_new_tree: If True or False force creation of a tree or
573
 
                               prevent such creation respectively.
574
 
        :param format: Override for the bzrdir format to create.
575
 
        :param possible_transports: An optional reusable transports list.
576
 
        """
577
 
        if force_new_tree:
578
 
            # check for non local urls
579
 
            t = _mod_transport.get_transport(base, possible_transports)
580
 
            if not isinstance(t, local.LocalTransport):
581
 
                raise errors.NotLocalUrl(base)
582
 
        bzrdir = BzrDir.create(base, format, possible_transports)
583
 
        repo = bzrdir._find_or_create_repository(force_new_repo)
584
 
        result = bzrdir.create_branch()
585
 
        if force_new_tree or (repo.make_working_trees() and
586
 
                              force_new_tree is None):
587
 
            try:
588
 
                bzrdir.create_workingtree()
589
 
            except errors.NotLocalUrl:
590
 
                pass
591
 
        return result
592
 
 
593
 
    @staticmethod
594
 
    def create_standalone_workingtree(base, format=None):
595
 
        """Create a new BzrDir, WorkingTree, Branch and Repository at 'base'.
596
 
 
597
 
        'base' must be a local path or a file:// url.
598
 
 
599
 
        This will use the current default BzrDirFormat unless one is
600
 
        specified, and use whatever
601
 
        repository format that that uses for bzrdirformat.create_workingtree,
602
 
        create_branch and create_repository.
603
 
 
604
 
        :param format: Override for the bzrdir format to create.
605
 
        :return: The WorkingTree object.
606
 
        """
607
 
        t = _mod_transport.get_transport(base)
608
 
        if not isinstance(t, local.LocalTransport):
609
 
            raise errors.NotLocalUrl(base)
610
 
        bzrdir = BzrDir.create_branch_and_repo(base,
611
 
                                               force_new_repo=True,
612
 
                                               format=format).bzrdir
613
 
        return bzrdir.create_workingtree()
614
 
 
615
465
    @deprecated_method(deprecated_in((2, 3, 0)))
616
466
    def generate_backup_name(self, base):
617
467
        return self._available_backup_name(base)
634
484
            old_path = self.root_transport.abspath('.bzr')
635
485
            backup_dir = self._available_backup_name('backup.bzr')
636
486
            new_path = self.root_transport.abspath(backup_dir)
637
 
            ui.ui_factory.note('making backup of %s\n  to %s'
638
 
                               % (old_path, new_path,))
 
487
            ui.ui_factory.note(gettext('making backup of {0}\n  to {1}').format(
 
488
                urlutils.unescape_for_display(old_path, 'utf-8'),
 
489
                urlutils.unescape_for_display(new_path, 'utf-8')))
639
490
            self.root_transport.copy_tree('.bzr', backup_dir)
640
491
            return (old_path, new_path)
641
492
        finally:
656
507
            try:
657
508
                to_path = '.bzr.retired.%d' % i
658
509
                self.root_transport.rename('.bzr', to_path)
659
 
                note("renamed %s to %s"
660
 
                    % (self.root_transport.abspath('.bzr'), to_path))
 
510
                note(gettext("renamed {0} to {1}").format(
 
511
                    self.root_transport.abspath('.bzr'), to_path))
661
512
                return
662
513
            except (errors.TransportError, IOError, errors.PathError):
663
514
                i += 1
690
541
                return None
691
542
            # find the next containing bzrdir
692
543
            try:
693
 
                found_bzrdir = BzrDir.open_containing_from_transport(
 
544
                found_bzrdir = self.open_containing_from_transport(
694
545
                    next_transport)[0]
695
546
            except errors.NotBranchError:
696
547
                return None
813
664
        # add new tests for it to the appropriate place.
814
665
        return filename == '.bzr' or filename.startswith('.bzr/')
815
666
 
816
 
    @staticmethod
817
 
    def open_unsupported(base):
818
 
        """Open a branch which is not supported."""
819
 
        return BzrDir.open(base, _unsupported=True)
820
 
 
821
 
    @staticmethod
822
 
    def open(base, _unsupported=False, possible_transports=None):
823
 
        """Open an existing bzrdir, rooted at 'base' (url).
824
 
 
825
 
        :param _unsupported: a private parameter to the BzrDir class.
826
 
        """
827
 
        t = _mod_transport.get_transport(base, possible_transports)
828
 
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
829
 
 
830
 
    @staticmethod
831
 
    def open_from_transport(transport, _unsupported=False,
832
 
                            _server_formats=True):
833
 
        """Open a bzrdir within a particular directory.
834
 
 
835
 
        :param transport: Transport containing the bzrdir.
836
 
        :param _unsupported: private.
837
 
        """
838
 
        for hook in BzrDir.hooks['pre_open']:
839
 
            hook(transport)
840
 
        # Keep initial base since 'transport' may be modified while following
841
 
        # the redirections.
842
 
        base = transport.base
843
 
        def find_format(transport):
844
 
            return transport, controldir.ControlDirFormat.find_format(
845
 
                transport, _server_formats=_server_formats)
846
 
 
847
 
        def redirected(transport, e, redirection_notice):
848
 
            redirected_transport = transport._redirected_to(e.source, e.target)
849
 
            if redirected_transport is None:
850
 
                raise errors.NotBranchError(base)
851
 
            note('%s is%s redirected to %s',
852
 
                 transport.base, e.permanently, redirected_transport.base)
853
 
            return redirected_transport
854
 
 
855
 
        try:
856
 
            transport, format = do_catching_redirections(find_format,
857
 
                                                         transport,
858
 
                                                         redirected)
859
 
        except errors.TooManyRedirections:
860
 
            raise errors.NotBranchError(base)
861
 
 
862
 
        format.check_support_status(_unsupported)
863
 
        return format.open(transport, _found=True)
864
 
 
865
 
    @staticmethod
866
 
    def open_containing(url, possible_transports=None):
867
 
        """Open an existing branch which contains url.
868
 
 
869
 
        :param url: url to search from.
870
 
 
871
 
        See open_containing_from_transport for more detail.
872
 
        """
873
 
        transport = _mod_transport.get_transport(url, possible_transports)
874
 
        return BzrDir.open_containing_from_transport(transport)
875
 
 
876
 
    @staticmethod
877
 
    def open_containing_from_transport(a_transport):
878
 
        """Open an existing branch which contains a_transport.base.
879
 
 
880
 
        This probes for a branch at a_transport, and searches upwards from there.
881
 
 
882
 
        Basically we keep looking up until we find the control directory or
883
 
        run into the root.  If there isn't one, raises NotBranchError.
884
 
        If there is one and it is either an unrecognised format or an unsupported
885
 
        format, UnknownFormatError or UnsupportedFormatError are raised.
886
 
        If there is one, it is returned, along with the unused portion of url.
887
 
 
888
 
        :return: The BzrDir that contains the path, and a Unicode path
889
 
                for the rest of the URL.
890
 
        """
891
 
        # this gets the normalised url back. I.e. '.' -> the full path.
892
 
        url = a_transport.base
893
 
        while True:
894
 
            try:
895
 
                result = BzrDir.open_from_transport(a_transport)
896
 
                return result, urlutils.unescape(a_transport.relpath(url))
897
 
            except errors.NotBranchError, e:
898
 
                pass
899
 
            try:
900
 
                new_t = a_transport.clone('..')
901
 
            except errors.InvalidURLJoin:
902
 
                # reached the root, whatever that may be
903
 
                raise errors.NotBranchError(path=url)
904
 
            if new_t.base == a_transport.base:
905
 
                # reached the root, whatever that may be
906
 
                raise errors.NotBranchError(path=url)
907
 
            a_transport = new_t
908
 
 
909
 
    @classmethod
910
 
    def open_tree_or_branch(klass, location):
911
 
        """Return the branch and working tree at a location.
912
 
 
913
 
        If there is no tree at the location, tree will be None.
914
 
        If there is no branch at the location, an exception will be
915
 
        raised
916
 
        :return: (tree, branch)
917
 
        """
918
 
        bzrdir = klass.open(location)
919
 
        return bzrdir._get_tree_branch()
920
 
 
921
 
    @classmethod
922
 
    def open_containing_tree_or_branch(klass, location):
923
 
        """Return the branch and working tree contained by a location.
924
 
 
925
 
        Returns (tree, branch, relpath).
926
 
        If there is no tree at containing the location, tree will be None.
927
 
        If there is no branch containing the location, an exception will be
928
 
        raised
929
 
        relpath is the portion of the path that is contained by the branch.
930
 
        """
931
 
        bzrdir, relpath = klass.open_containing(location)
932
 
        tree, branch = bzrdir._get_tree_branch()
933
 
        return tree, branch, relpath
934
 
 
935
 
    @classmethod
936
 
    def open_containing_tree_branch_or_repository(klass, location):
937
 
        """Return the working tree, branch and repo contained by a location.
938
 
 
939
 
        Returns (tree, branch, repository, relpath).
940
 
        If there is no tree containing the location, tree will be None.
941
 
        If there is no branch containing the location, branch will be None.
942
 
        If there is no repository containing the location, repository will be
943
 
        None.
944
 
        relpath is the portion of the path that is contained by the innermost
945
 
        BzrDir.
946
 
 
947
 
        If no tree, branch or repository is found, a NotBranchError is raised.
948
 
        """
949
 
        bzrdir, relpath = klass.open_containing(location)
950
 
        try:
951
 
            tree, branch = bzrdir._get_tree_branch()
952
 
        except errors.NotBranchError:
953
 
            try:
954
 
                repo = bzrdir.find_repository()
955
 
                return None, None, repo, relpath
956
 
            except (errors.NoRepositoryPresent):
957
 
                raise errors.NotBranchError(location)
958
 
        return tree, branch, branch.repository, relpath
959
 
 
960
667
    def _cloning_metadir(self):
961
668
        """Produce a metadir suitable for cloning with.
962
669
 
1002
709
 
1003
710
        :require_stacking: If True, non-stackable formats will be upgraded
1004
711
            to similar stackable formats.
1005
 
        :returns: a BzrDirFormat with all component formats either set
 
712
        :returns: a ControlDirFormat with all component formats either set
1006
713
            appropriately or set to None if that component should not be
1007
714
            created.
1008
715
        """
1020
727
            format.require_stacking()
1021
728
        return format
1022
729
 
1023
 
    @classmethod
1024
 
    def create(cls, base, format=None, possible_transports=None):
1025
 
        """Create a new BzrDir at the url 'base'.
1026
 
 
1027
 
        :param format: If supplied, the format of branch to create.  If not
1028
 
            supplied, the default is used.
1029
 
        :param possible_transports: If supplied, a list of transports that
1030
 
            can be reused to share a remote connection.
1031
 
        """
1032
 
        if cls is not BzrDir:
1033
 
            raise AssertionError("BzrDir.create always creates the"
1034
 
                "default format, not one of %r" % cls)
1035
 
        t = _mod_transport.get_transport(base, possible_transports)
1036
 
        t.ensure_base()
1037
 
        if format is None:
1038
 
            format = controldir.ControlDirFormat.get_default_format()
1039
 
        return format.initialize_on_transport(t)
1040
 
 
1041
730
    def get_branch_transport(self, branch_format, name=None):
1042
731
        """Get the transport for use by branch format in this BzrDir.
1043
732
 
1077
766
        """
1078
767
        raise NotImplementedError(self.get_workingtree_transport)
1079
768
 
1080
 
 
1081
 
class BzrDirHooks(hooks.Hooks):
1082
 
    """Hooks for BzrDir operations."""
1083
 
 
1084
 
    def __init__(self):
1085
 
        """Create the default hooks."""
1086
 
        hooks.Hooks.__init__(self, "bzrlib.bzrdir", "BzrDir.hooks")
1087
 
        self.add_hook('pre_open',
1088
 
            "Invoked before attempting to open a BzrDir with the transport "
1089
 
            "that the open will use.", (1, 14))
1090
 
        self.add_hook('post_repo_init',
1091
 
            "Invoked after a repository has been initialized. "
1092
 
            "post_repo_init is called with a "
1093
 
            "bzrlib.bzrdir.RepoInitHookParams.",
1094
 
            (2, 2))
1095
 
 
1096
 
# install the default hooks
1097
 
BzrDir.hooks = BzrDirHooks()
1098
 
 
1099
 
 
1100
 
class RepoInitHookParams(object):
1101
 
    """Object holding parameters passed to `*_repo_init` hooks.
1102
 
 
1103
 
    There are 4 fields that hooks may wish to access:
1104
 
 
1105
 
    :ivar repository: Repository created
1106
 
    :ivar format: Repository format
1107
 
    :ivar bzrdir: The bzrdir for the repository
1108
 
    :ivar shared: The repository is shared
1109
 
    """
1110
 
 
1111
 
    def __init__(self, repository, format, a_bzrdir, shared):
1112
 
        """Create a group of RepoInitHook parameters.
1113
 
 
1114
 
        :param repository: Repository created
1115
 
        :param format: Repository format
1116
 
        :param bzrdir: The bzrdir for the repository
1117
 
        :param shared: The repository is shared
 
769
    @classmethod
 
770
    def create(cls, base, format=None, possible_transports=None):
 
771
        """Create a new BzrDir at the url 'base'.
 
772
 
 
773
        :param format: If supplied, the format of branch to create.  If not
 
774
            supplied, the default is used.
 
775
        :param possible_transports: If supplied, a list of transports that
 
776
            can be reused to share a remote connection.
1118
777
        """
1119
 
        self.repository = repository
1120
 
        self.format = format
1121
 
        self.bzrdir = a_bzrdir
1122
 
        self.shared = shared
1123
 
 
1124
 
    def __eq__(self, other):
1125
 
        return self.__dict__ == other.__dict__
 
778
        if cls is not BzrDir:
 
779
            raise AssertionError("BzrDir.create always creates the "
 
780
                "default format, not one of %r" % cls)
 
781
        return controldir.ControlDir.create(base, format=format,
 
782
                possible_transports=possible_transports)
1126
783
 
1127
784
    def __repr__(self):
1128
 
        if self.repository:
1129
 
            return "<%s for %s>" % (self.__class__.__name__,
1130
 
                self.repository)
1131
 
        else:
1132
 
            return "<%s for %s>" % (self.__class__.__name__,
1133
 
                self.bzrdir)
 
785
        return "<%s at %r>" % (self.__class__.__name__, self.user_url)
1134
786
 
1135
787
 
1136
788
class BzrDirMeta1(BzrDir):
1146
798
        """See BzrDir.can_convert_format()."""
1147
799
        return True
1148
800
 
1149
 
    def create_branch(self, name=None, repository=None):
 
801
    def create_branch(self, name=None, repository=None,
 
802
            append_revisions_only=None):
1150
803
        """See BzrDir.create_branch."""
 
804
        if name is None:
 
805
            name = self._get_selected_branch()
1151
806
        return self._format.get_branch_format().initialize(self, name=name,
1152
 
                repository=repository)
 
807
                repository=repository,
 
808
                append_revisions_only=append_revisions_only)
1153
809
 
1154
810
    def destroy_branch(self, name=None):
1155
811
        """See BzrDir.create_branch."""
1163
819
 
1164
820
    def destroy_repository(self):
1165
821
        """See BzrDir.destroy_repository."""
1166
 
        self.transport.delete_tree('repository')
 
822
        try:
 
823
            self.transport.delete_tree('repository')
 
824
        except errors.NoSuchFile:
 
825
            raise errors.NoRepositoryPresent(self)
1167
826
 
1168
827
    def create_workingtree(self, revision_id=None, from_branch=None,
1169
828
                           accelerator_tree=None, hardlink=False):
1191
850
 
1192
851
        This might be a synthetic object for e.g. RemoteBranch and SVN.
1193
852
        """
1194
 
        from bzrlib.branch import BranchFormat
1195
 
        return BranchFormat.find_format(self, name=name)
 
853
        from bzrlib.branch import BranchFormatMetadir
 
854
        return BranchFormatMetadir.find_format(self, name=name)
1196
855
 
1197
856
    def _get_mkdir_mode(self):
1198
857
        """Figure out the mode to use when creating a bzrdir subdir."""
1202
861
 
1203
862
    def get_branch_reference(self, name=None):
1204
863
        """See BzrDir.get_branch_reference()."""
1205
 
        from bzrlib.branch import BranchFormat
1206
 
        format = BranchFormat.find_format(self, name=name)
 
864
        from bzrlib.branch import BranchFormatMetadir
 
865
        format = BranchFormatMetadir.find_format(self, name=name)
1207
866
        return format.get_reference(self, name=name)
1208
867
 
1209
868
    def get_branch_transport(self, branch_format, name=None):
1258
917
        Note: if you're going to open the working tree, you should just go
1259
918
        ahead and try, and not ask permission first.
1260
919
        """
1261
 
        from bzrlib.workingtree import WorkingTreeFormat
 
920
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
1262
921
        try:
1263
 
            WorkingTreeFormat.find_format_string(self)
 
922
            WorkingTreeFormatMetaDir.find_format_string(self)
1264
923
        except errors.NoWorkingTree:
1265
924
            return False
1266
925
        return True
1267
926
 
1268
927
    def needs_format_conversion(self, format):
1269
928
        """See BzrDir.needs_format_conversion()."""
1270
 
        if not isinstance(self._format, format.__class__):
 
929
        if (not isinstance(self._format, format.__class__) or
 
930
            self._format.get_format_string() != format.get_format_string()):
1271
931
            # it is not a meta dir format, conversion is needed.
1272
932
            return True
1273
933
        # we might want to push this down to the repository?
1294
954
        return False
1295
955
 
1296
956
    def open_branch(self, name=None, unsupported=False,
1297
 
                    ignore_fallbacks=False):
1298
 
        """See BzrDir.open_branch."""
 
957
                    ignore_fallbacks=False, possible_transports=None):
 
958
        """See ControlDir.open_branch."""
 
959
        if name is None:
 
960
            name = self._get_selected_branch()
1299
961
        format = self.find_branch_format(name=name)
1300
962
        format.check_support_status(unsupported)
1301
963
        return format.open(self, name=name,
1302
 
            _found=True, ignore_fallbacks=ignore_fallbacks)
 
964
            _found=True, ignore_fallbacks=ignore_fallbacks,
 
965
            possible_transports=possible_transports)
1303
966
 
1304
967
    def open_repository(self, unsupported=False):
1305
968
        """See BzrDir.open_repository."""
1306
 
        from bzrlib.repository import RepositoryFormat
1307
 
        format = RepositoryFormat.find_format(self)
 
969
        from bzrlib.repository import RepositoryFormatMetaDir
 
970
        format = RepositoryFormatMetaDir.find_format(self)
1308
971
        format.check_support_status(unsupported)
1309
972
        return format.open(self, _found=True)
1310
973
 
1311
974
    def open_workingtree(self, unsupported=False,
1312
975
            recommend_upgrade=True):
1313
976
        """See BzrDir.open_workingtree."""
1314
 
        from bzrlib.workingtree import WorkingTreeFormat
1315
 
        format = WorkingTreeFormat.find_format(self)
 
977
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
 
978
        format = WorkingTreeFormatMetaDir.find_format(self)
1316
979
        format.check_support_status(unsupported, recommend_upgrade,
1317
980
            basedir=self.root_transport.base)
1318
981
        return format.open(self, _found=True)
1321
984
        return config.TransportConfig(self.transport, 'control.conf')
1322
985
 
1323
986
 
 
987
class BzrDirMeta1Colo(BzrDirMeta1):
 
988
    """BzrDirMeta1 with support for colocated branches.
 
989
 
 
990
    This format is experimental, and will eventually be merged back into
 
991
    BzrDirMeta1.
 
992
    """
 
993
 
 
994
    def __init__(self, _transport, _format):
 
995
        super(BzrDirMeta1Colo, self).__init__(_transport, _format)
 
996
        self.control_files = lockable_files.LockableFiles(self.control_transport,
 
997
            self._format._lock_file_name, self._format._lock_class)
 
998
 
 
999
    def _get_branch_path(self, name):
 
1000
        """Obtain the branch path to use.
 
1001
 
 
1002
        This uses the API specified branch name first, and then falls back to
 
1003
        the branch name specified in the URL. If neither of those is specified,
 
1004
        it uses the default branch.
 
1005
 
 
1006
        :param name: Optional branch name to use
 
1007
        :return: Relative path to branch
 
1008
        """
 
1009
        if name is None:
 
1010
            return 'branch'
 
1011
        return urlutils.join('branches', name.encode("utf-8"))
 
1012
 
 
1013
    def _read_branch_list(self):
 
1014
        """Read the branch list.
 
1015
 
 
1016
        :return: List of utf-8 encoded branch names.
 
1017
        """
 
1018
        try:
 
1019
            f = self.control_transport.get('branch-list')
 
1020
        except errors.NoSuchFile:
 
1021
            return []
 
1022
 
 
1023
        ret = []
 
1024
        try:
 
1025
            for name in f:
 
1026
                ret.append(name.rstrip("\n"))
 
1027
        finally:
 
1028
            f.close()
 
1029
        return ret
 
1030
 
 
1031
    def _write_branch_list(self, branches):
 
1032
        """Write out the branch list.
 
1033
 
 
1034
        :param branches: List of utf-8 branch names to write
 
1035
        """
 
1036
        self.transport.put_bytes('branch-list',
 
1037
            "".join([name+"\n" for name in branches]))
 
1038
 
 
1039
    def destroy_branch(self, name=None):
 
1040
        """See BzrDir.create_branch."""
 
1041
        if name is None:
 
1042
            name = self._get_selected_branch()
 
1043
        path = self._get_branch_path(name)
 
1044
        if name is not None:
 
1045
            self.control_files.lock_write()
 
1046
            try:
 
1047
                branches = self._read_branch_list()
 
1048
                try:
 
1049
                    branches.remove(name.encode("utf-8"))
 
1050
                except ValueError:
 
1051
                    raise errors.NotBranchError(name)
 
1052
                self._write_branch_list(branches)
 
1053
            finally:
 
1054
                self.control_files.unlock()
 
1055
        self.transport.delete_tree(path)
 
1056
 
 
1057
    def get_branches(self):
 
1058
        """See ControlDir.get_branches."""
 
1059
        ret = {}
 
1060
        try:
 
1061
            ret[None] = self.open_branch()
 
1062
        except (errors.NotBranchError, errors.NoRepositoryPresent):
 
1063
            pass
 
1064
 
 
1065
        for name in self._read_branch_list():
 
1066
            ret[name] = self.open_branch(name.decode('utf-8'))
 
1067
 
 
1068
        return ret
 
1069
 
 
1070
    def get_branch_transport(self, branch_format, name=None):
 
1071
        """See BzrDir.get_branch_transport()."""
 
1072
        path = self._get_branch_path(name)
 
1073
        # XXX: this shouldn't implicitly create the directory if it's just
 
1074
        # promising to get a transport -- mbp 20090727
 
1075
        if branch_format is None:
 
1076
            return self.transport.clone(path)
 
1077
        try:
 
1078
            branch_format.get_format_string()
 
1079
        except NotImplementedError:
 
1080
            raise errors.IncompatibleFormat(branch_format, self._format)
 
1081
        if name is not None:
 
1082
            try:
 
1083
                self.transport.mkdir('branches', mode=self._get_mkdir_mode())
 
1084
            except errors.FileExists:
 
1085
                pass
 
1086
            branches = self._read_branch_list()
 
1087
            utf8_name = name.encode("utf-8")
 
1088
            if not utf8_name in branches:
 
1089
                self.control_files.lock_write()
 
1090
                try:
 
1091
                    branches = self._read_branch_list()
 
1092
                    branches.append(utf8_name)
 
1093
                    self._write_branch_list(branches)
 
1094
                finally:
 
1095
                    self.control_files.unlock()
 
1096
        try:
 
1097
            self.transport.mkdir(path, mode=self._get_mkdir_mode())
 
1098
        except errors.FileExists:
 
1099
            pass
 
1100
        return self.transport.clone(path)
 
1101
 
 
1102
 
 
1103
class BzrDirMetaComponentFormat(controldir.ControlComponentFormat):
 
1104
    """Base class for all formats of things living in metadirs.
 
1105
 
 
1106
    This class manages the format string that is stored in the 'format'
 
1107
    or 'branch-format' file.
 
1108
 
 
1109
    All classes for (branch-, repository-, workingtree-) formats that
 
1110
    live in meta directories and have their own 'format' file
 
1111
    (i.e. different from .bzr/branch-format) derive from this class,
 
1112
    as well as the relevant base class for their kind
 
1113
    (BranchFormat, WorkingTreeFormat, RepositoryFormat).
 
1114
    """
 
1115
 
 
1116
    @classmethod
 
1117
    def get_format_string(cls):
 
1118
        """Return the ASCII format string that identifies this format."""
 
1119
        raise NotImplementedError(cls.get_format_string)
 
1120
 
 
1121
    @classmethod
 
1122
    def from_string(cls, format_string):
 
1123
        if format_string != cls.get_format_string():
 
1124
            raise ValueError("Invalid format header %r" % format_string)
 
1125
        return cls()
 
1126
 
 
1127
    @classmethod
 
1128
    def _find_format(klass, registry, kind, format_string):
 
1129
        try:
 
1130
            cls = registry.get(format_string)
 
1131
        except KeyError:
 
1132
            raise errors.UnknownFormatError(format=format_string, kind=kind)
 
1133
        return cls
 
1134
 
 
1135
    def network_name(self):
 
1136
        """A simple byte string uniquely identifying this format for RPC calls.
 
1137
 
 
1138
        Metadir branch formats use their format string.
 
1139
        """
 
1140
        return self.get_format_string()
 
1141
 
 
1142
    def __eq__(self, other):
 
1143
        return (self.__class__ is other.__class__)
 
1144
 
 
1145
 
1324
1146
class BzrProber(controldir.Prober):
1325
1147
    """Prober for formats that use a .bzr/ control directory."""
1326
1148
 
1345
1167
        except errors.NoSuchFile:
1346
1168
            raise errors.NotBranchError(path=transport.base)
1347
1169
        try:
1348
 
            return klass.formats.get(format_string)
 
1170
            cls = klass.formats.get(format_string)
1349
1171
        except KeyError:
1350
1172
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
 
1173
        return cls.from_string(format_string)
1351
1174
 
1352
1175
    @classmethod
1353
1176
    def known_formats(cls):
1609
1432
        :return: None.
1610
1433
        """
1611
1434
 
 
1435
    def supports_transport(self, transport):
 
1436
        # bzr formats can be opened over all known transports
 
1437
        return True
 
1438
 
1612
1439
 
1613
1440
class BzrDirMetaFormat1(BzrDirFormat):
1614
1441
    """Bzr meta control format 1
1627
1454
 
1628
1455
    fixed_components = False
1629
1456
 
 
1457
    colocated_branches = False
 
1458
 
1630
1459
    def __init__(self):
1631
1460
        self._workingtree_format = None
1632
1461
        self._branch_format = None
1722
1551
                    new_repo_format = None
1723
1552
            if new_repo_format is not None:
1724
1553
                self.repository_format = new_repo_format
1725
 
                note('Source repository format does not support stacking,'
1726
 
                     ' using format:\n  %s',
 
1554
                note(gettext('Source repository format does not support stacking,'
 
1555
                     ' using format:\n  %s'),
1727
1556
                     new_repo_format.get_format_description())
1728
1557
 
1729
1558
        if not self.get_branch_format().supports_stacking():
1742
1571
            if new_branch_format is not None:
1743
1572
                # Does support stacking, use its format.
1744
1573
                self.set_branch_format(new_branch_format)
1745
 
                note('Source branch format does not support stacking,'
1746
 
                     ' using format:\n  %s',
 
1574
                note(gettext('Source branch format does not support stacking,'
 
1575
                     ' using format:\n  %s'),
1747
1576
                     new_branch_format.get_format_description())
1748
1577
 
1749
1578
    def get_converter(self, format=None):
1750
1579
        """See BzrDirFormat.get_converter()."""
1751
1580
        if format is None:
1752
1581
            format = BzrDirFormat.get_default_format()
 
1582
        if (type(self) is BzrDirMetaFormat1 and
 
1583
            type(format) is BzrDirMetaFormat1Colo):
 
1584
            return ConvertMetaToColo(format)
 
1585
        if (type(self) is BzrDirMetaFormat1Colo and
 
1586
            type(format) is BzrDirMetaFormat1):
 
1587
            return ConvertMetaRemoveColo(format)
1753
1588
        if not isinstance(self, format.__class__):
1754
1589
            # converting away from metadir is not implemented
1755
1590
            raise NotImplementedError(self.get_converter)
1764
1599
        """See BzrDirFormat.get_format_description()."""
1765
1600
        return "Meta directory format 1"
1766
1601
 
 
1602
    @classmethod
 
1603
    def from_string(cls, format_string):
 
1604
        if format_string != cls.get_format_string():
 
1605
            raise ValueError("Invalid format string %r" % format_string)
 
1606
        return cls()
 
1607
 
1767
1608
    def network_name(self):
1768
1609
        return self.get_format_string()
1769
1610
 
1819
1660
    def __set_workingtree_format(self, wt_format):
1820
1661
        self._workingtree_format = wt_format
1821
1662
 
 
1663
    def __repr__(self):
 
1664
        return "<%r>" % (self.__class__.__name__,)
 
1665
 
1822
1666
    workingtree_format = property(__get_workingtree_format,
1823
1667
                                  __set_workingtree_format)
1824
1668
 
1829
1673
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
1830
1674
 
1831
1675
 
 
1676
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
 
1677
    """BzrDirMeta1 format with support for colocated branches."""
 
1678
 
 
1679
    colocated_branches = True
 
1680
 
 
1681
    @classmethod
 
1682
    def get_format_string(cls):
 
1683
        """See BzrDirFormat.get_format_string()."""
 
1684
        return "Bazaar meta directory, format 1 (with colocated branches)\n"
 
1685
 
 
1686
    def get_format_description(self):
 
1687
        """See BzrDirFormat.get_format_description()."""
 
1688
        return "Meta directory format 1 with support for colocated branches"
 
1689
 
 
1690
    def _open(self, transport):
 
1691
        """See BzrDirFormat._open."""
 
1692
        # Create a new format instance because otherwise initialisation of new
 
1693
        # metadirs share the global default format object leading to alias
 
1694
        # problems.
 
1695
        format = BzrDirMetaFormat1Colo()
 
1696
        self._supply_sub_formats_to(format)
 
1697
        return BzrDirMeta1Colo(transport, format)
 
1698
 
 
1699
 
 
1700
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
 
1701
    BzrDirMetaFormat1Colo)
 
1702
 
 
1703
 
1832
1704
class ConvertMetaToMeta(controldir.Converter):
1833
1705
    """Converts the components of metadirs."""
1834
1706
 
1853
1725
        else:
1854
1726
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
1855
1727
                from bzrlib.repository import CopyConverter
1856
 
                ui.ui_factory.note('starting repository conversion')
 
1728
                ui.ui_factory.note(gettext('starting repository conversion'))
1857
1729
                converter = CopyConverter(self.target_format.repository_format)
1858
1730
                converter.convert(repo, pb)
1859
1731
        for branch in self.bzrdir.list_branches():
1907
1779
        return to_convert
1908
1780
 
1909
1781
 
 
1782
class ConvertMetaToColo(controldir.Converter):
 
1783
    """Add colocated branch support."""
 
1784
 
 
1785
    def __init__(self, target_format):
 
1786
        """Create a converter.that upgrades a metadir to the colo format.
 
1787
 
 
1788
        :param target_format: The final metadir format that is desired.
 
1789
        """
 
1790
        self.target_format = target_format
 
1791
 
 
1792
    def convert(self, to_convert, pb):
 
1793
        """See Converter.convert()."""
 
1794
        to_convert.transport.put_bytes('branch-format',
 
1795
            self.target_format.get_format_string())
 
1796
        return BzrDir.open_from_transport(to_convert.root_transport)
 
1797
 
 
1798
 
 
1799
class ConvertMetaRemoveColo(controldir.Converter):
 
1800
    """Remove colocated branch support from a bzrdir."""
 
1801
 
 
1802
    def __init__(self, target_format):
 
1803
        """Create a converter.that downgrades a colocated branch metadir
 
1804
        to a regular metadir.
 
1805
 
 
1806
        :param target_format: The final metadir format that is desired.
 
1807
        """
 
1808
        self.target_format = target_format
 
1809
 
 
1810
    def convert(self, to_convert, pb):
 
1811
        """See Converter.convert()."""
 
1812
        to_convert.control_files.lock_write()
 
1813
        try:
 
1814
            branches = to_convert.list_branches()
 
1815
            if len(branches) > 1:
 
1816
                raise errors.BzrError("remove all but a single "
 
1817
                    "colocated branch when downgrading")
 
1818
        finally:
 
1819
            to_convert.control_files.unlock()
 
1820
        to_convert.transport.put_bytes('branch-format',
 
1821
            self.target_format.get_format_string())
 
1822
        return BzrDir.open_from_transport(to_convert.root_transport)
 
1823
 
 
1824
 
1910
1825
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
1911
1826
 
1912
1827
 
1989
1904
        else:
1990
1905
            self._require_stacking = True
1991
1906
 
1992
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
1907
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1908
            possible_transports=None):
1993
1909
        """Acquire a repository for this bzrdir.
1994
1910
 
1995
1911
        Implementations may create a new repository or use a pre-exising
2020
1936
                                             require_stacking)
2021
1937
        self._bzrdir = bzrdir
2022
1938
 
2023
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
1939
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1940
            possible_transports=None):
2024
1941
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
2025
1942
 
2026
1943
        Creates the desired repository in the bzrdir we already have.
2027
1944
        """
 
1945
        if possible_transports is None:
 
1946
            possible_transports = []
 
1947
        else:
 
1948
            possible_transports = list(possible_transports)
 
1949
        possible_transports.append(self._bzrdir.root_transport)
2028
1950
        stack_on = self._get_full_stack_on()
2029
1951
        if stack_on:
2030
1952
            format = self._bzrdir._format
2031
1953
            format.require_stacking(stack_on=stack_on,
2032
 
                                    possible_transports=[self._bzrdir.root_transport])
 
1954
                                    possible_transports=possible_transports)
2033
1955
            if not self._require_stacking:
2034
1956
                # We have picked up automatic stacking somewhere.
2035
 
                note('Using default stacking branch %s at %s', self._stack_on,
2036
 
                    self._stack_on_pwd)
 
1957
                note(gettext('Using default stacking branch {0} at {1}').format(
 
1958
                    self._stack_on, self._stack_on_pwd))
2037
1959
        repository = self._bzrdir.create_repository(shared=shared)
2038
1960
        self._add_fallback(repository,
2039
 
                           possible_transports=[self._bzrdir.transport])
 
1961
                           possible_transports=possible_transports)
2040
1962
        if make_working_trees is not None:
2041
1963
            repository.set_make_working_trees(make_working_trees)
2042
1964
        return repository, True
2058
1980
                                             require_stacking)
2059
1981
        self._repository = repository
2060
1982
 
2061
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
1983
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1984
            possible_transports=None):
2062
1985
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
2063
1986
 
2064
1987
        Returns an existing repository to use.
2065
1988
        """
 
1989
        if possible_transports is None:
 
1990
            possible_transports = []
 
1991
        else:
 
1992
            possible_transports = list(possible_transports)
 
1993
        possible_transports.append(self._repository.bzrdir.transport)
2066
1994
        self._add_fallback(self._repository,
2067
 
                       possible_transports=[self._repository.bzrdir.transport])
 
1995
                       possible_transports=possible_transports)
2068
1996
        return self._repository, False
2069
1997
 
2070
1998
 
2074
2002
         tree_format=None,
2075
2003
         hidden=False,
2076
2004
         experimental=False,
2077
 
         alias=False):
 
2005
         alias=False, bzrdir_format=None):
2078
2006
    """Register a metadir subformat.
2079
2007
 
2080
 
    These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2081
 
    by the Repository/Branch/WorkingTreeformats.
 
2008
    These all use a meta bzrdir, but can be parameterized by the
 
2009
    Repository/Branch/WorkingTreeformats.
2082
2010
 
2083
2011
    :param repository_format: The fully-qualified repository format class
2084
2012
        name as a string.
2087
2015
    :param tree_format: Fully-qualified tree format class name as
2088
2016
        a string.
2089
2017
    """
 
2018
    if bzrdir_format is None:
 
2019
        bzrdir_format = BzrDirMetaFormat1
2090
2020
    # This should be expanded to support setting WorkingTree and Branch
2091
 
    # formats, once BzrDirMetaFormat1 supports that.
 
2021
    # formats, once the API supports that.
2092
2022
    def _load(full_name):
2093
2023
        mod_name, factory_name = full_name.rsplit('.', 1)
2094
2024
        try:
2101
2031
        return factory()
2102
2032
 
2103
2033
    def helper():
2104
 
        bd = BzrDirMetaFormat1()
 
2034
        bd = bzrdir_format()
2105
2035
        if branch_format is not None:
2106
2036
            bd.set_branch_format(_load(branch_format))
2107
2037
        if tree_format is not None:
2121
2051
    deprecated=True)
2122
2052
register_metadir(controldir.format_registry, 'dirstate',
2123
2053
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2124
 
    help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
2125
 
        'above when accessed over the network.',
 
2054
    help='Format using dirstate for working trees. '
 
2055
        'Compatible with bzr 0.8 and '
 
2056
        'above when accessed over the network. Introduced in bzr 0.15.',
2126
2057
    branch_format='bzrlib.branch.BzrBranchFormat5',
2127
2058
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2128
2059
    hidden=True,
2129
2060
    deprecated=True)
2130
2061
register_metadir(controldir.format_registry, 'dirstate-tags',
2131
2062
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2132
 
    help='New in 0.15: Fast local operations and improved scaling for '
2133
 
        'network operations. Additionally adds support for tags.'
2134
 
        ' Incompatible with bzr < 0.15.',
 
2063
    help='Variant of dirstate with support for tags. '
 
2064
        'Introduced in bzr 0.15.',
2135
2065
    branch_format='bzrlib.branch.BzrBranchFormat6',
2136
2066
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2137
2067
    hidden=True,
2138
2068
    deprecated=True)
2139
2069
register_metadir(controldir.format_registry, 'rich-root',
2140
2070
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2141
 
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
2142
 
        ' bzr < 1.0.',
 
2071
    help='Variant of dirstate with better handling of tree roots. '
 
2072
        'Introduced in bzr 1.0',
2143
2073
    branch_format='bzrlib.branch.BzrBranchFormat6',
2144
2074
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2145
2075
    hidden=True,
2146
2076
    deprecated=True)
2147
2077
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2148
2078
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
2149
 
    help='New in 0.15: Fast local operations and improved scaling for '
2150
 
        'network operations. Additionally adds support for versioning nested '
2151
 
        'bzr branches. Incompatible with bzr < 0.15.',
 
2079
    help='Variant of dirstate with support for nested trees. '
 
2080
         'Introduced in 0.15.',
2152
2081
    branch_format='bzrlib.branch.BzrBranchFormat6',
2153
2082
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2154
2083
    experimental=True,
2156
2085
    )
2157
2086
register_metadir(controldir.format_registry, 'pack-0.92',
2158
2087
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack1',
2159
 
    help='New in 0.92: Pack-based format with data compatible with '
2160
 
        'dirstate-tags format repositories. Interoperates with '
2161
 
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
 
2088
    help='Pack-based format used in 1.x series. Introduced in 0.92. '
 
2089
        'Interoperates with bzr repositories before 0.92 but cannot be '
 
2090
        'read by bzr < 0.92. '
2162
2091
        ,
2163
2092
    branch_format='bzrlib.branch.BzrBranchFormat6',
2164
2093
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2094
    deprecated=True,
2165
2095
    )
2166
2096
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2167
2097
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack3',
2168
 
    help='New in 0.92: Pack-based format with data compatible with '
2169
 
        'dirstate-with-subtree format repositories. Interoperates with '
 
2098
    help='Pack-based format used in 1.x series, with subtree support. '
 
2099
        'Introduced in 0.92. Interoperates with '
2170
2100
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2171
2101
        ,
2172
2102
    branch_format='bzrlib.branch.BzrBranchFormat6',
2173
2103
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2174
2104
    hidden=True,
 
2105
    deprecated=True,
2175
2106
    experimental=True,
2176
2107
    )
2177
2108
register_metadir(controldir.format_registry, 'rich-root-pack',
2178
2109
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack4',
2179
 
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
2180
 
         '(needed for bzr-svn and bzr-git).',
 
2110
    help='A variant of pack-0.92 that supports rich-root data '
 
2111
         '(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2181
2112
    branch_format='bzrlib.branch.BzrBranchFormat6',
2182
2113
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2183
2114
    hidden=True,
 
2115
    deprecated=True,
2184
2116
    )
2185
2117
register_metadir(controldir.format_registry, '1.6',
2186
2118
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2190
2122
    branch_format='bzrlib.branch.BzrBranchFormat7',
2191
2123
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2192
2124
    hidden=True,
 
2125
    deprecated=True,
2193
2126
    )
2194
2127
register_metadir(controldir.format_registry, '1.6.1-rich-root',
2195
2128
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
2198
2131
    branch_format='bzrlib.branch.BzrBranchFormat7',
2199
2132
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2200
2133
    hidden=True,
 
2134
    deprecated=True,
2201
2135
    )
2202
2136
register_metadir(controldir.format_registry, '1.9',
2203
2137
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2207
2141
    branch_format='bzrlib.branch.BzrBranchFormat7',
2208
2142
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2209
2143
    hidden=True,
 
2144
    deprecated=True,
2210
2145
    )
2211
2146
register_metadir(controldir.format_registry, '1.9-rich-root',
2212
2147
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2215
2150
    branch_format='bzrlib.branch.BzrBranchFormat7',
2216
2151
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2217
2152
    hidden=True,
 
2153
    deprecated=True,
2218
2154
    )
2219
2155
register_metadir(controldir.format_registry, '1.14',
2220
2156
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2221
2157
    help='A working-tree format that supports content filtering.',
2222
2158
    branch_format='bzrlib.branch.BzrBranchFormat7',
2223
2159
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2160
    hidden=True,
 
2161
    deprecated=True,
2224
2162
    )
2225
2163
register_metadir(controldir.format_registry, '1.14-rich-root',
2226
2164
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2228
2166
         '(needed for bzr-svn and bzr-git).',
2229
2167
    branch_format='bzrlib.branch.BzrBranchFormat7',
2230
2168
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2169
    hidden=True,
 
2170
    deprecated=True,
2231
2171
    )
2232
2172
# The following un-numbered 'development' formats should always just be aliases.
2233
2173
register_metadir(controldir.format_registry, 'development-subtree',
2261
2201
    alias=False,
2262
2202
    )
2263
2203
 
 
2204
register_metadir(controldir.format_registry, 'development-colo',
 
2205
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
2206
    help='The 2a format with experimental support for colocated branches.\n',
 
2207
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2208
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2209
    experimental=True,
 
2210
    bzrdir_format=BzrDirMetaFormat1Colo,
 
2211
    )
 
2212
 
 
2213
 
2264
2214
# And the development formats above will have aliased one of the following:
2265
2215
 
2266
2216
# Finally, the current format.
2267
2217
register_metadir(controldir.format_registry, '2a',
2268
2218
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2269
 
    help='First format for bzr 2.0 series.\n'
 
2219
    help='Format for the bzr 2.0 series.\n'
2270
2220
        'Uses group-compress storage.\n'
2271
2221
        'Provides rich roots which are a one-way transition.\n',
2272
2222
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
2287
2237
    help='Same as 2a.')
2288
2238
 
2289
2239
# The current format that is made on 'bzr init'.
2290
 
format_name = config.GlobalConfig().get_user_option('default_format')
2291
 
if format_name is None:
2292
 
    controldir.format_registry.set_default('2a')
2293
 
else:
2294
 
    controldir.format_registry.set_default(format_name)
 
2240
format_name = config.GlobalStack().get('default_format')
 
2241
controldir.format_registry.set_default(format_name)
2295
2242
 
2296
2243
# XXX 2010-08-20 JRV: There is still a lot of code relying on
2297
2244
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc