~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

(gz) Fix deprecations of win32utils path function unicode wrappers (Martin
 Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
objects returned.
26
26
"""
27
27
 
 
28
from __future__ import absolute_import
 
29
 
28
30
import sys
29
31
 
30
32
from bzrlib.lazy_import import lazy_import
46
48
    transport as _mod_transport,
47
49
    ui,
48
50
    urlutils,
 
51
    vf_search,
49
52
    win32utils,
50
53
    workingtree_3,
51
54
    workingtree_4,
55
58
    do_catching_redirections,
56
59
    local,
57
60
    )
 
61
from bzrlib.i18n import gettext
58
62
""")
59
63
 
60
64
from bzrlib.trace import (
65
69
from bzrlib import (
66
70
    config,
67
71
    controldir,
68
 
    hooks,
69
72
    registry,
70
73
    )
71
74
from bzrlib.symbol_versioning import (
200
203
                if (result_repo.user_url == result.user_url
201
204
                    and not require_stacking and
202
205
                    revision_id is not None):
203
 
                    fetch_spec = graph.PendingAncestryResult(
 
206
                    fetch_spec = vf_search.PendingAncestryResult(
204
207
                        [revision_id], local_repo)
205
208
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
206
209
                else:
221
224
            # the tree and fail.
222
225
            result.root_transport.local_abspath('.')
223
226
            if result_repo is None or result_repo.make_working_trees():
224
 
                self.open_workingtree().clone(result)
 
227
                self.open_workingtree().clone(result, revision_id=revision_id)
225
228
        except (errors.NoWorkingTree, errors.NotLocalUrl):
226
229
            pass
227
230
        return result
232
235
        t = _mod_transport.get_transport(url)
233
236
        t.ensure_base()
234
237
 
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
238
    def determine_repository_policy(self, force_new_repo=False, stack_on=None,
327
239
                                    stack_on_pwd=None, require_stacking=False):
328
240
        """Return an object representing a policy to use.
461
373
        if revision_id is not None:
462
374
            fetch_spec_factory.add_revision_ids([revision_id])
463
375
            fetch_spec_factory.source_branch_stop_revision_id = revision_id
 
376
        if possible_transports is None:
 
377
            possible_transports = []
 
378
        else:
 
379
            possible_transports = list(possible_transports) + [
 
380
                self.root_transport]
464
381
        target_transport = _mod_transport.get_transport(url,
465
382
            possible_transports)
466
383
        target_transport.ensure_base()
467
384
        cloning_format = self.cloning_metadir(stacked)
468
385
        # Create/update the result branch
469
 
        result = cloning_format.initialize_on_transport(target_transport)
 
386
        try:
 
387
            result = controldir.ControlDir.open_from_transport(target_transport)
 
388
        except errors.NotBranchError:
 
389
            result = cloning_format.initialize_on_transport(target_transport)
470
390
        source_branch, source_repository = self._find_source_repo(
471
391
            add_cleanup, source_branch)
472
392
        fetch_spec_factory.source_branch = source_branch
478
398
            stacked_branch_url = None
479
399
        repository_policy = result.determine_repository_policy(
480
400
            force_new_repo, stacked_branch_url, require_stacking=stacked)
481
 
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
401
        result_repo, is_new_repo = repository_policy.acquire_repository(
 
402
            possible_transports=possible_transports)
482
403
        add_cleanup(result_repo.lock_write().unlock)
483
404
        fetch_spec_factory.source_repo = source_repository
484
405
        fetch_spec_factory.target_repo = result_repo
505
426
        mutter("created new branch %r" % (result_branch,))
506
427
 
507
428
        # Create/update the result working tree
508
 
        if (create_tree_if_local and
 
429
        if (create_tree_if_local and not result.has_workingtree() and
509
430
            isinstance(target_transport, local.LocalTransport) and
510
431
            (result_repo is None or result_repo.make_working_trees())):
511
432
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
543
464
                    stacked=stacked)
544
465
        return result
545
466
 
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
467
    @deprecated_method(deprecated_in((2, 3, 0)))
616
468
    def generate_backup_name(self, base):
617
469
        return self._available_backup_name(base)
634
486
            old_path = self.root_transport.abspath('.bzr')
635
487
            backup_dir = self._available_backup_name('backup.bzr')
636
488
            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,))
 
489
            ui.ui_factory.note(gettext('making backup of {0}\n  to {1}').format(
 
490
                urlutils.unescape_for_display(old_path, 'utf-8'),
 
491
                urlutils.unescape_for_display(new_path, 'utf-8')))
639
492
            self.root_transport.copy_tree('.bzr', backup_dir)
640
493
            return (old_path, new_path)
641
494
        finally:
656
509
            try:
657
510
                to_path = '.bzr.retired.%d' % i
658
511
                self.root_transport.rename('.bzr', to_path)
659
 
                note("renamed %s to %s"
660
 
                    % (self.root_transport.abspath('.bzr'), to_path))
 
512
                note(gettext("renamed {0} to {1}").format(
 
513
                    self.root_transport.abspath('.bzr'), to_path))
661
514
                return
662
515
            except (errors.TransportError, IOError, errors.PathError):
663
516
                i += 1
690
543
                return None
691
544
            # find the next containing bzrdir
692
545
            try:
693
 
                found_bzrdir = BzrDir.open_containing_from_transport(
 
546
                found_bzrdir = self.open_containing_from_transport(
694
547
                    next_transport)[0]
695
548
            except errors.NotBranchError:
696
549
                return None
813
666
        # add new tests for it to the appropriate place.
814
667
        return filename == '.bzr' or filename.startswith('.bzr/')
815
668
 
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
669
    def _cloning_metadir(self):
961
670
        """Produce a metadir suitable for cloning with.
962
671
 
1002
711
 
1003
712
        :require_stacking: If True, non-stackable formats will be upgraded
1004
713
            to similar stackable formats.
1005
 
        :returns: a BzrDirFormat with all component formats either set
 
714
        :returns: a ControlDirFormat with all component formats either set
1006
715
            appropriately or set to None if that component should not be
1007
716
            created.
1008
717
        """
1020
729
            format.require_stacking()
1021
730
        return format
1022
731
 
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
732
    def get_branch_transport(self, branch_format, name=None):
1042
733
        """Get the transport for use by branch format in this BzrDir.
1043
734
 
1077
768
        """
1078
769
        raise NotImplementedError(self.get_workingtree_transport)
1079
770
 
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
 
771
    @classmethod
 
772
    def create(cls, base, format=None, possible_transports=None):
 
773
        """Create a new BzrDir at the url 'base'.
 
774
 
 
775
        :param format: If supplied, the format of branch to create.  If not
 
776
            supplied, the default is used.
 
777
        :param possible_transports: If supplied, a list of transports that
 
778
            can be reused to share a remote connection.
1118
779
        """
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__
 
780
        if cls is not BzrDir:
 
781
            raise AssertionError("BzrDir.create always creates the "
 
782
                "default format, not one of %r" % cls)
 
783
        return controldir.ControlDir.create(base, format=format,
 
784
                possible_transports=possible_transports)
1126
785
 
1127
786
    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)
 
787
        return "<%s at %r>" % (self.__class__.__name__, self.user_url)
1134
788
 
1135
789
 
1136
790
class BzrDirMeta1(BzrDir):
1146
800
        """See BzrDir.can_convert_format()."""
1147
801
        return True
1148
802
 
1149
 
    def create_branch(self, name=None, repository=None):
 
803
    def create_branch(self, name=None, repository=None,
 
804
            append_revisions_only=None):
1150
805
        """See BzrDir.create_branch."""
 
806
        if name is None:
 
807
            name = self._get_selected_branch()
1151
808
        return self._format.get_branch_format().initialize(self, name=name,
1152
 
                repository=repository)
 
809
                repository=repository,
 
810
                append_revisions_only=append_revisions_only)
1153
811
 
1154
812
    def destroy_branch(self, name=None):
1155
813
        """See BzrDir.create_branch."""
1163
821
 
1164
822
    def destroy_repository(self):
1165
823
        """See BzrDir.destroy_repository."""
1166
 
        self.transport.delete_tree('repository')
 
824
        try:
 
825
            self.transport.delete_tree('repository')
 
826
        except errors.NoSuchFile:
 
827
            raise errors.NoRepositoryPresent(self)
1167
828
 
1168
829
    def create_workingtree(self, revision_id=None, from_branch=None,
1169
830
                           accelerator_tree=None, hardlink=False):
1191
852
 
1192
853
        This might be a synthetic object for e.g. RemoteBranch and SVN.
1193
854
        """
1194
 
        from bzrlib.branch import BranchFormat
1195
 
        return BranchFormat.find_format(self, name=name)
 
855
        from bzrlib.branch import BranchFormatMetadir
 
856
        return BranchFormatMetadir.find_format(self, name=name)
1196
857
 
1197
858
    def _get_mkdir_mode(self):
1198
859
        """Figure out the mode to use when creating a bzrdir subdir."""
1202
863
 
1203
864
    def get_branch_reference(self, name=None):
1204
865
        """See BzrDir.get_branch_reference()."""
1205
 
        from bzrlib.branch import BranchFormat
1206
 
        format = BranchFormat.find_format(self, name=name)
 
866
        from bzrlib.branch import BranchFormatMetadir
 
867
        format = BranchFormatMetadir.find_format(self, name=name)
1207
868
        return format.get_reference(self, name=name)
1208
869
 
1209
870
    def get_branch_transport(self, branch_format, name=None):
1258
919
        Note: if you're going to open the working tree, you should just go
1259
920
        ahead and try, and not ask permission first.
1260
921
        """
1261
 
        from bzrlib.workingtree import WorkingTreeFormat
 
922
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
1262
923
        try:
1263
 
            WorkingTreeFormat.find_format_string(self)
 
924
            WorkingTreeFormatMetaDir.find_format_string(self)
1264
925
        except errors.NoWorkingTree:
1265
926
            return False
1266
927
        return True
1267
928
 
1268
929
    def needs_format_conversion(self, format):
1269
930
        """See BzrDir.needs_format_conversion()."""
1270
 
        if not isinstance(self._format, format.__class__):
 
931
        if (not isinstance(self._format, format.__class__) or
 
932
            self._format.get_format_string() != format.get_format_string()):
1271
933
            # it is not a meta dir format, conversion is needed.
1272
934
            return True
1273
935
        # we might want to push this down to the repository?
1294
956
        return False
1295
957
 
1296
958
    def open_branch(self, name=None, unsupported=False,
1297
 
                    ignore_fallbacks=False):
1298
 
        """See BzrDir.open_branch."""
 
959
                    ignore_fallbacks=False, possible_transports=None):
 
960
        """See ControlDir.open_branch."""
 
961
        if name is None:
 
962
            name = self._get_selected_branch()
1299
963
        format = self.find_branch_format(name=name)
1300
964
        format.check_support_status(unsupported)
1301
965
        return format.open(self, name=name,
1302
 
            _found=True, ignore_fallbacks=ignore_fallbacks)
 
966
            _found=True, ignore_fallbacks=ignore_fallbacks,
 
967
            possible_transports=possible_transports)
1303
968
 
1304
969
    def open_repository(self, unsupported=False):
1305
970
        """See BzrDir.open_repository."""
1306
 
        from bzrlib.repository import RepositoryFormat
1307
 
        format = RepositoryFormat.find_format(self)
 
971
        from bzrlib.repository import RepositoryFormatMetaDir
 
972
        format = RepositoryFormatMetaDir.find_format(self)
1308
973
        format.check_support_status(unsupported)
1309
974
        return format.open(self, _found=True)
1310
975
 
1311
976
    def open_workingtree(self, unsupported=False,
1312
977
            recommend_upgrade=True):
1313
978
        """See BzrDir.open_workingtree."""
1314
 
        from bzrlib.workingtree import WorkingTreeFormat
1315
 
        format = WorkingTreeFormat.find_format(self)
 
979
        from bzrlib.workingtree import WorkingTreeFormatMetaDir
 
980
        format = WorkingTreeFormatMetaDir.find_format(self)
1316
981
        format.check_support_status(unsupported, recommend_upgrade,
1317
982
            basedir=self.root_transport.base)
1318
983
        return format.open(self, _found=True)
1321
986
        return config.TransportConfig(self.transport, 'control.conf')
1322
987
 
1323
988
 
 
989
class BzrDirMeta1Colo(BzrDirMeta1):
 
990
    """BzrDirMeta1 with support for colocated branches.
 
991
 
 
992
    This format is experimental, and will eventually be merged back into
 
993
    BzrDirMeta1.
 
994
    """
 
995
 
 
996
    def __init__(self, _transport, _format):
 
997
        super(BzrDirMeta1Colo, self).__init__(_transport, _format)
 
998
        self.control_files = lockable_files.LockableFiles(self.control_transport,
 
999
            self._format._lock_file_name, self._format._lock_class)
 
1000
 
 
1001
    def _get_branch_path(self, name):
 
1002
        """Obtain the branch path to use.
 
1003
 
 
1004
        This uses the API specified branch name first, and then falls back to
 
1005
        the branch name specified in the URL. If neither of those is specified,
 
1006
        it uses the default branch.
 
1007
 
 
1008
        :param name: Optional branch name to use
 
1009
        :return: Relative path to branch
 
1010
        """
 
1011
        if name is None:
 
1012
            return 'branch'
 
1013
        return urlutils.join('branches', name.encode("utf-8"))
 
1014
 
 
1015
    def _read_branch_list(self):
 
1016
        """Read the branch list.
 
1017
 
 
1018
        :return: List of utf-8 encoded branch names.
 
1019
        """
 
1020
        try:
 
1021
            f = self.control_transport.get('branch-list')
 
1022
        except errors.NoSuchFile:
 
1023
            return []
 
1024
 
 
1025
        ret = []
 
1026
        try:
 
1027
            for name in f:
 
1028
                ret.append(name.rstrip("\n"))
 
1029
        finally:
 
1030
            f.close()
 
1031
        return ret
 
1032
 
 
1033
    def _write_branch_list(self, branches):
 
1034
        """Write out the branch list.
 
1035
 
 
1036
        :param branches: List of utf-8 branch names to write
 
1037
        """
 
1038
        self.transport.put_bytes('branch-list',
 
1039
            "".join([name+"\n" for name in branches]))
 
1040
 
 
1041
    def destroy_branch(self, name=None):
 
1042
        """See BzrDir.create_branch."""
 
1043
        if name is None:
 
1044
            name = self._get_selected_branch()
 
1045
        path = self._get_branch_path(name)
 
1046
        if name is not None:
 
1047
            self.control_files.lock_write()
 
1048
            try:
 
1049
                branches = self._read_branch_list()
 
1050
                try:
 
1051
                    branches.remove(name.encode("utf-8"))
 
1052
                except ValueError:
 
1053
                    raise errors.NotBranchError(name)
 
1054
                self._write_branch_list(branches)
 
1055
            finally:
 
1056
                self.control_files.unlock()
 
1057
        self.transport.delete_tree(path)
 
1058
 
 
1059
    def get_branches(self):
 
1060
        """See ControlDir.get_branches."""
 
1061
        ret = {}
 
1062
        try:
 
1063
            ret[None] = self.open_branch()
 
1064
        except (errors.NotBranchError, errors.NoRepositoryPresent):
 
1065
            pass
 
1066
 
 
1067
        for name in self._read_branch_list():
 
1068
            ret[name] = self.open_branch(name.decode('utf-8'))
 
1069
 
 
1070
        return ret
 
1071
 
 
1072
    def get_branch_transport(self, branch_format, name=None):
 
1073
        """See BzrDir.get_branch_transport()."""
 
1074
        path = self._get_branch_path(name)
 
1075
        # XXX: this shouldn't implicitly create the directory if it's just
 
1076
        # promising to get a transport -- mbp 20090727
 
1077
        if branch_format is None:
 
1078
            return self.transport.clone(path)
 
1079
        try:
 
1080
            branch_format.get_format_string()
 
1081
        except NotImplementedError:
 
1082
            raise errors.IncompatibleFormat(branch_format, self._format)
 
1083
        if name is not None:
 
1084
            try:
 
1085
                self.transport.mkdir('branches', mode=self._get_mkdir_mode())
 
1086
            except errors.FileExists:
 
1087
                pass
 
1088
            branches = self._read_branch_list()
 
1089
            utf8_name = name.encode("utf-8")
 
1090
            if not utf8_name in branches:
 
1091
                self.control_files.lock_write()
 
1092
                try:
 
1093
                    branches = self._read_branch_list()
 
1094
                    branches.append(utf8_name)
 
1095
                    self._write_branch_list(branches)
 
1096
                finally:
 
1097
                    self.control_files.unlock()
 
1098
        try:
 
1099
            self.transport.mkdir(path, mode=self._get_mkdir_mode())
 
1100
        except errors.FileExists:
 
1101
            pass
 
1102
        return self.transport.clone(path)
 
1103
 
 
1104
 
 
1105
class BzrDirMetaComponentFormat(controldir.ControlComponentFormat):
 
1106
    """Base class for all formats of things living in metadirs.
 
1107
 
 
1108
    This class manages the format string that is stored in the 'format'
 
1109
    or 'branch-format' file.
 
1110
 
 
1111
    All classes for (branch-, repository-, workingtree-) formats that
 
1112
    live in meta directories and have their own 'format' file
 
1113
    (i.e. different from .bzr/branch-format) derive from this class,
 
1114
    as well as the relevant base class for their kind
 
1115
    (BranchFormat, WorkingTreeFormat, RepositoryFormat).
 
1116
    """
 
1117
 
 
1118
    @classmethod
 
1119
    def get_format_string(cls):
 
1120
        """Return the ASCII format string that identifies this format."""
 
1121
        raise NotImplementedError(cls.get_format_string)
 
1122
 
 
1123
    @classmethod
 
1124
    def from_string(cls, format_string):
 
1125
        if format_string != cls.get_format_string():
 
1126
            raise ValueError("Invalid format header %r" % format_string)
 
1127
        return cls()
 
1128
 
 
1129
    @classmethod
 
1130
    def _find_format(klass, registry, kind, format_string):
 
1131
        try:
 
1132
            cls = registry.get(format_string)
 
1133
        except KeyError:
 
1134
            raise errors.UnknownFormatError(format=format_string, kind=kind)
 
1135
        return cls
 
1136
 
 
1137
    def network_name(self):
 
1138
        """A simple byte string uniquely identifying this format for RPC calls.
 
1139
 
 
1140
        Metadir branch formats use their format string.
 
1141
        """
 
1142
        return self.get_format_string()
 
1143
 
 
1144
    def __eq__(self, other):
 
1145
        return (self.__class__ is other.__class__)
 
1146
 
 
1147
 
1324
1148
class BzrProber(controldir.Prober):
1325
1149
    """Prober for formats that use a .bzr/ control directory."""
1326
1150
 
1345
1169
        except errors.NoSuchFile:
1346
1170
            raise errors.NotBranchError(path=transport.base)
1347
1171
        try:
1348
 
            return klass.formats.get(format_string)
 
1172
            cls = klass.formats.get(format_string)
1349
1173
        except KeyError:
1350
1174
            raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
 
1175
        return cls.from_string(format_string)
1351
1176
 
1352
1177
    @classmethod
1353
1178
    def known_formats(cls):
1609
1434
        :return: None.
1610
1435
        """
1611
1436
 
 
1437
    def supports_transport(self, transport):
 
1438
        # bzr formats can be opened over all known transports
 
1439
        return True
 
1440
 
1612
1441
 
1613
1442
class BzrDirMetaFormat1(BzrDirFormat):
1614
1443
    """Bzr meta control format 1
1627
1456
 
1628
1457
    fixed_components = False
1629
1458
 
 
1459
    colocated_branches = False
 
1460
 
1630
1461
    def __init__(self):
1631
1462
        self._workingtree_format = None
1632
1463
        self._branch_format = None
1722
1553
                    new_repo_format = None
1723
1554
            if new_repo_format is not None:
1724
1555
                self.repository_format = new_repo_format
1725
 
                note('Source repository format does not support stacking,'
1726
 
                     ' using format:\n  %s',
 
1556
                note(gettext('Source repository format does not support stacking,'
 
1557
                     ' using format:\n  %s'),
1727
1558
                     new_repo_format.get_format_description())
1728
1559
 
1729
1560
        if not self.get_branch_format().supports_stacking():
1742
1573
            if new_branch_format is not None:
1743
1574
                # Does support stacking, use its format.
1744
1575
                self.set_branch_format(new_branch_format)
1745
 
                note('Source branch format does not support stacking,'
1746
 
                     ' using format:\n  %s',
 
1576
                note(gettext('Source branch format does not support stacking,'
 
1577
                     ' using format:\n  %s'),
1747
1578
                     new_branch_format.get_format_description())
1748
1579
 
1749
1580
    def get_converter(self, format=None):
1750
1581
        """See BzrDirFormat.get_converter()."""
1751
1582
        if format is None:
1752
1583
            format = BzrDirFormat.get_default_format()
 
1584
        if (type(self) is BzrDirMetaFormat1 and
 
1585
            type(format) is BzrDirMetaFormat1Colo):
 
1586
            return ConvertMetaToColo(format)
 
1587
        if (type(self) is BzrDirMetaFormat1Colo and
 
1588
            type(format) is BzrDirMetaFormat1):
 
1589
            return ConvertMetaRemoveColo(format)
1753
1590
        if not isinstance(self, format.__class__):
1754
1591
            # converting away from metadir is not implemented
1755
1592
            raise NotImplementedError(self.get_converter)
1764
1601
        """See BzrDirFormat.get_format_description()."""
1765
1602
        return "Meta directory format 1"
1766
1603
 
 
1604
    @classmethod
 
1605
    def from_string(cls, format_string):
 
1606
        if format_string != cls.get_format_string():
 
1607
            raise ValueError("Invalid format string %r" % format_string)
 
1608
        return cls()
 
1609
 
1767
1610
    def network_name(self):
1768
1611
        return self.get_format_string()
1769
1612
 
1819
1662
    def __set_workingtree_format(self, wt_format):
1820
1663
        self._workingtree_format = wt_format
1821
1664
 
 
1665
    def __repr__(self):
 
1666
        return "<%r>" % (self.__class__.__name__,)
 
1667
 
1822
1668
    workingtree_format = property(__get_workingtree_format,
1823
1669
                                  __set_workingtree_format)
1824
1670
 
1829
1675
controldir.ControlDirFormat._default_format = BzrDirMetaFormat1()
1830
1676
 
1831
1677
 
 
1678
class BzrDirMetaFormat1Colo(BzrDirMetaFormat1):
 
1679
    """BzrDirMeta1 format with support for colocated branches."""
 
1680
 
 
1681
    colocated_branches = True
 
1682
 
 
1683
    @classmethod
 
1684
    def get_format_string(cls):
 
1685
        """See BzrDirFormat.get_format_string()."""
 
1686
        return "Bazaar meta directory, format 1 (with colocated branches)\n"
 
1687
 
 
1688
    def get_format_description(self):
 
1689
        """See BzrDirFormat.get_format_description()."""
 
1690
        return "Meta directory format 1 with support for colocated branches"
 
1691
 
 
1692
    def _open(self, transport):
 
1693
        """See BzrDirFormat._open."""
 
1694
        # Create a new format instance because otherwise initialisation of new
 
1695
        # metadirs share the global default format object leading to alias
 
1696
        # problems.
 
1697
        format = BzrDirMetaFormat1Colo()
 
1698
        self._supply_sub_formats_to(format)
 
1699
        return BzrDirMeta1Colo(transport, format)
 
1700
 
 
1701
 
 
1702
BzrProber.formats.register(BzrDirMetaFormat1Colo.get_format_string(),
 
1703
    BzrDirMetaFormat1Colo)
 
1704
 
 
1705
 
1832
1706
class ConvertMetaToMeta(controldir.Converter):
1833
1707
    """Converts the components of metadirs."""
1834
1708
 
1853
1727
        else:
1854
1728
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
1855
1729
                from bzrlib.repository import CopyConverter
1856
 
                ui.ui_factory.note('starting repository conversion')
 
1730
                ui.ui_factory.note(gettext('starting repository conversion'))
1857
1731
                converter = CopyConverter(self.target_format.repository_format)
1858
1732
                converter.convert(repo, pb)
1859
1733
        for branch in self.bzrdir.list_branches():
1907
1781
        return to_convert
1908
1782
 
1909
1783
 
 
1784
class ConvertMetaToColo(controldir.Converter):
 
1785
    """Add colocated branch support."""
 
1786
 
 
1787
    def __init__(self, target_format):
 
1788
        """Create a converter.that upgrades a metadir to the colo format.
 
1789
 
 
1790
        :param target_format: The final metadir format that is desired.
 
1791
        """
 
1792
        self.target_format = target_format
 
1793
 
 
1794
    def convert(self, to_convert, pb):
 
1795
        """See Converter.convert()."""
 
1796
        to_convert.transport.put_bytes('branch-format',
 
1797
            self.target_format.get_format_string())
 
1798
        return BzrDir.open_from_transport(to_convert.root_transport)
 
1799
 
 
1800
 
 
1801
class ConvertMetaRemoveColo(controldir.Converter):
 
1802
    """Remove colocated branch support from a bzrdir."""
 
1803
 
 
1804
    def __init__(self, target_format):
 
1805
        """Create a converter.that downgrades a colocated branch metadir
 
1806
        to a regular metadir.
 
1807
 
 
1808
        :param target_format: The final metadir format that is desired.
 
1809
        """
 
1810
        self.target_format = target_format
 
1811
 
 
1812
    def convert(self, to_convert, pb):
 
1813
        """See Converter.convert()."""
 
1814
        to_convert.control_files.lock_write()
 
1815
        try:
 
1816
            branches = to_convert.list_branches()
 
1817
            if len(branches) > 1:
 
1818
                raise errors.BzrError("remove all but a single "
 
1819
                    "colocated branch when downgrading")
 
1820
        finally:
 
1821
            to_convert.control_files.unlock()
 
1822
        to_convert.transport.put_bytes('branch-format',
 
1823
            self.target_format.get_format_string())
 
1824
        return BzrDir.open_from_transport(to_convert.root_transport)
 
1825
 
 
1826
 
1910
1827
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
1911
1828
 
1912
1829
 
1989
1906
        else:
1990
1907
            self._require_stacking = True
1991
1908
 
1992
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
1909
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1910
            possible_transports=None):
1993
1911
        """Acquire a repository for this bzrdir.
1994
1912
 
1995
1913
        Implementations may create a new repository or use a pre-exising
2020
1938
                                             require_stacking)
2021
1939
        self._bzrdir = bzrdir
2022
1940
 
2023
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
1941
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1942
            possible_transports=None):
2024
1943
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
2025
1944
 
2026
1945
        Creates the desired repository in the bzrdir we already have.
2027
1946
        """
 
1947
        if possible_transports is None:
 
1948
            possible_transports = []
 
1949
        else:
 
1950
            possible_transports = list(possible_transports)
 
1951
        possible_transports.append(self._bzrdir.root_transport)
2028
1952
        stack_on = self._get_full_stack_on()
2029
1953
        if stack_on:
2030
1954
            format = self._bzrdir._format
2031
1955
            format.require_stacking(stack_on=stack_on,
2032
 
                                    possible_transports=[self._bzrdir.root_transport])
 
1956
                                    possible_transports=possible_transports)
2033
1957
            if not self._require_stacking:
2034
1958
                # We have picked up automatic stacking somewhere.
2035
 
                note('Using default stacking branch %s at %s', self._stack_on,
2036
 
                    self._stack_on_pwd)
 
1959
                note(gettext('Using default stacking branch {0} at {1}').format(
 
1960
                    self._stack_on, self._stack_on_pwd))
2037
1961
        repository = self._bzrdir.create_repository(shared=shared)
2038
1962
        self._add_fallback(repository,
2039
 
                           possible_transports=[self._bzrdir.transport])
 
1963
                           possible_transports=possible_transports)
2040
1964
        if make_working_trees is not None:
2041
1965
            repository.set_make_working_trees(make_working_trees)
2042
1966
        return repository, True
2058
1982
                                             require_stacking)
2059
1983
        self._repository = repository
2060
1984
 
2061
 
    def acquire_repository(self, make_working_trees=None, shared=False):
 
1985
    def acquire_repository(self, make_working_trees=None, shared=False,
 
1986
            possible_transports=None):
2062
1987
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
2063
1988
 
2064
1989
        Returns an existing repository to use.
2065
1990
        """
 
1991
        if possible_transports is None:
 
1992
            possible_transports = []
 
1993
        else:
 
1994
            possible_transports = list(possible_transports)
 
1995
        possible_transports.append(self._repository.bzrdir.transport)
2066
1996
        self._add_fallback(self._repository,
2067
 
                       possible_transports=[self._repository.bzrdir.transport])
 
1997
                       possible_transports=possible_transports)
2068
1998
        return self._repository, False
2069
1999
 
2070
2000
 
2074
2004
         tree_format=None,
2075
2005
         hidden=False,
2076
2006
         experimental=False,
2077
 
         alias=False):
 
2007
         alias=False, bzrdir_format=None):
2078
2008
    """Register a metadir subformat.
2079
2009
 
2080
 
    These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2081
 
    by the Repository/Branch/WorkingTreeformats.
 
2010
    These all use a meta bzrdir, but can be parameterized by the
 
2011
    Repository/Branch/WorkingTreeformats.
2082
2012
 
2083
2013
    :param repository_format: The fully-qualified repository format class
2084
2014
        name as a string.
2087
2017
    :param tree_format: Fully-qualified tree format class name as
2088
2018
        a string.
2089
2019
    """
 
2020
    if bzrdir_format is None:
 
2021
        bzrdir_format = BzrDirMetaFormat1
2090
2022
    # This should be expanded to support setting WorkingTree and Branch
2091
 
    # formats, once BzrDirMetaFormat1 supports that.
 
2023
    # formats, once the API supports that.
2092
2024
    def _load(full_name):
2093
2025
        mod_name, factory_name = full_name.rsplit('.', 1)
2094
2026
        try:
2101
2033
        return factory()
2102
2034
 
2103
2035
    def helper():
2104
 
        bd = BzrDirMetaFormat1()
 
2036
        bd = bzrdir_format()
2105
2037
        if branch_format is not None:
2106
2038
            bd.set_branch_format(_load(branch_format))
2107
2039
        if tree_format is not None:
2121
2053
    deprecated=True)
2122
2054
register_metadir(controldir.format_registry, 'dirstate',
2123
2055
    '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.',
 
2056
    help='Format using dirstate for working trees. '
 
2057
        'Compatible with bzr 0.8 and '
 
2058
        'above when accessed over the network. Introduced in bzr 0.15.',
2126
2059
    branch_format='bzrlib.branch.BzrBranchFormat5',
2127
2060
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2128
2061
    hidden=True,
2129
2062
    deprecated=True)
2130
2063
register_metadir(controldir.format_registry, 'dirstate-tags',
2131
2064
    '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.',
 
2065
    help='Variant of dirstate with support for tags. '
 
2066
        'Introduced in bzr 0.15.',
2135
2067
    branch_format='bzrlib.branch.BzrBranchFormat6',
2136
2068
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2137
2069
    hidden=True,
2138
2070
    deprecated=True)
2139
2071
register_metadir(controldir.format_registry, 'rich-root',
2140
2072
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
2141
 
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
2142
 
        ' bzr < 1.0.',
 
2073
    help='Variant of dirstate with better handling of tree roots. '
 
2074
        'Introduced in bzr 1.0',
2143
2075
    branch_format='bzrlib.branch.BzrBranchFormat6',
2144
2076
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2145
2077
    hidden=True,
2146
2078
    deprecated=True)
2147
2079
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
2148
2080
    '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.',
 
2081
    help='Variant of dirstate with support for nested trees. '
 
2082
         'Introduced in 0.15.',
2152
2083
    branch_format='bzrlib.branch.BzrBranchFormat6',
2153
2084
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2154
2085
    experimental=True,
2156
2087
    )
2157
2088
register_metadir(controldir.format_registry, 'pack-0.92',
2158
2089
    '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. '
 
2090
    help='Pack-based format used in 1.x series. Introduced in 0.92. '
 
2091
        'Interoperates with bzr repositories before 0.92 but cannot be '
 
2092
        'read by bzr < 0.92. '
2162
2093
        ,
2163
2094
    branch_format='bzrlib.branch.BzrBranchFormat6',
2164
2095
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
 
2096
    deprecated=True,
2165
2097
    )
2166
2098
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
2167
2099
    '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 '
 
2100
    help='Pack-based format used in 1.x series, with subtree support. '
 
2101
        'Introduced in 0.92. Interoperates with '
2170
2102
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
2171
2103
        ,
2172
2104
    branch_format='bzrlib.branch.BzrBranchFormat6',
2173
2105
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2174
2106
    hidden=True,
 
2107
    deprecated=True,
2175
2108
    experimental=True,
2176
2109
    )
2177
2110
register_metadir(controldir.format_registry, 'rich-root-pack',
2178
2111
    '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).',
 
2112
    help='A variant of pack-0.92 that supports rich-root data '
 
2113
         '(needed for bzr-svn and bzr-git). Introduced in 1.0.',
2181
2114
    branch_format='bzrlib.branch.BzrBranchFormat6',
2182
2115
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2183
2116
    hidden=True,
 
2117
    deprecated=True,
2184
2118
    )
2185
2119
register_metadir(controldir.format_registry, '1.6',
2186
2120
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5',
2190
2124
    branch_format='bzrlib.branch.BzrBranchFormat7',
2191
2125
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2192
2126
    hidden=True,
 
2127
    deprecated=True,
2193
2128
    )
2194
2129
register_metadir(controldir.format_registry, '1.6.1-rich-root',
2195
2130
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
2198
2133
    branch_format='bzrlib.branch.BzrBranchFormat7',
2199
2134
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2200
2135
    hidden=True,
 
2136
    deprecated=True,
2201
2137
    )
2202
2138
register_metadir(controldir.format_registry, '1.9',
2203
2139
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2207
2143
    branch_format='bzrlib.branch.BzrBranchFormat7',
2208
2144
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2209
2145
    hidden=True,
 
2146
    deprecated=True,
2210
2147
    )
2211
2148
register_metadir(controldir.format_registry, '1.9-rich-root',
2212
2149
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2215
2152
    branch_format='bzrlib.branch.BzrBranchFormat7',
2216
2153
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat4',
2217
2154
    hidden=True,
 
2155
    deprecated=True,
2218
2156
    )
2219
2157
register_metadir(controldir.format_registry, '1.14',
2220
2158
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6',
2221
2159
    help='A working-tree format that supports content filtering.',
2222
2160
    branch_format='bzrlib.branch.BzrBranchFormat7',
2223
2161
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2162
    hidden=True,
 
2163
    deprecated=True,
2224
2164
    )
2225
2165
register_metadir(controldir.format_registry, '1.14-rich-root',
2226
2166
    'bzrlib.repofmt.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
2228
2168
         '(needed for bzr-svn and bzr-git).',
2229
2169
    branch_format='bzrlib.branch.BzrBranchFormat7',
2230
2170
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
 
2171
    hidden=True,
 
2172
    deprecated=True,
2231
2173
    )
2232
2174
# The following un-numbered 'development' formats should always just be aliases.
2233
2175
register_metadir(controldir.format_registry, 'development-subtree',
2261
2203
    alias=False,
2262
2204
    )
2263
2205
 
 
2206
register_metadir(controldir.format_registry, 'development-colo',
 
2207
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
2208
    help='The 2a format with experimental support for colocated branches.\n',
 
2209
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
2210
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
2211
    experimental=True,
 
2212
    bzrdir_format=BzrDirMetaFormat1Colo,
 
2213
    )
 
2214
 
 
2215
 
2264
2216
# And the development formats above will have aliased one of the following:
2265
2217
 
2266
2218
# Finally, the current format.
2267
2219
register_metadir(controldir.format_registry, '2a',
2268
2220
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
2269
 
    help='First format for bzr 2.0 series.\n'
 
2221
    help='Format for the bzr 2.0 series.\n'
2270
2222
        'Uses group-compress storage.\n'
2271
2223
        'Provides rich roots which are a one-way transition.\n',
2272
2224
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
2287
2239
    help='Same as 2a.')
2288
2240
 
2289
2241
# 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)
 
2242
format_name = config.GlobalStack().get('default_format')
 
2243
controldir.format_registry.set_default(format_name)
2295
2244
 
2296
2245
# XXX 2010-08-20 JRV: There is still a lot of code relying on
2297
2246
# bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc