~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""BzrDir logic. The BzrDir is the basic control directory used by bzr.
18
18
 
37
37
 
38
38
import bzrlib
39
39
from bzrlib import (
 
40
    branch,
40
41
    config,
41
42
    errors,
42
43
    graph,
44
45
    lockdir,
45
46
    osutils,
46
47
    remote,
 
48
    repository,
47
49
    revision as _mod_revision,
48
50
    ui,
49
51
    urlutils,
57
59
from bzrlib.osutils import (
58
60
    sha_string,
59
61
    )
 
62
from bzrlib.push import (
 
63
    PushResult,
 
64
    )
 
65
from bzrlib.repofmt import pack_repo
60
66
from bzrlib.smart.client import _SmartClient
61
67
from bzrlib.store.versioned import WeaveStore
62
68
from bzrlib.transactions import WriteTransaction
71
77
from bzrlib.trace import (
72
78
    mutter,
73
79
    note,
 
80
    warning,
74
81
    )
75
82
 
76
83
from bzrlib import (
 
84
    hooks,
77
85
    registry,
78
86
    symbol_versioning,
79
87
    )
81
89
 
82
90
class BzrDir(object):
83
91
    """A .bzr control diretory.
84
 
    
 
92
 
85
93
    BzrDir instances let you create or open any of the things that can be
86
94
    found within .bzr - checkouts, branches and repositories.
87
 
    
 
95
 
88
96
    :ivar transport:
89
97
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
90
98
    :ivar root_transport:
92
100
        (i.e. the parent directory holding the .bzr directory).
93
101
 
94
102
    Everything in the bzrdir should have the same file permissions.
 
103
 
 
104
    :cvar hooks: An instance of BzrDirHooks.
95
105
    """
96
106
 
97
107
    def break_lock(self):
119
129
        return True
120
130
 
121
131
    def check_conversion_target(self, target_format):
 
132
        """Check that a bzrdir as a whole can be converted to a new format."""
 
133
        # The only current restriction is that the repository content can be 
 
134
        # fetched compatibly with the target.
122
135
        target_repo_format = target_format.repository_format
123
 
        source_repo_format = self._format.repository_format
124
 
        source_repo_format.check_conversion_target(target_repo_format)
 
136
        try:
 
137
            self.open_repository()._format.check_conversion_target(
 
138
                target_repo_format)
 
139
        except errors.NoRepositoryPresent:
 
140
            # No repo, no problem.
 
141
            pass
125
142
 
126
143
    @staticmethod
127
144
    def _check_supported(format, allow_unsupported,
129
146
        basedir=None):
130
147
        """Give an error or warning on old formats.
131
148
 
132
 
        :param format: may be any kind of format - workingtree, branch, 
 
149
        :param format: may be any kind of format - workingtree, branch,
133
150
        or repository.
134
151
 
135
 
        :param allow_unsupported: If true, allow opening 
136
 
        formats that are strongly deprecated, and which may 
 
152
        :param allow_unsupported: If true, allow opening
 
153
        formats that are strongly deprecated, and which may
137
154
        have limited functionality.
138
155
 
139
156
        :param recommend_upgrade: If true (default), warn
171
188
                                       preserve_stacking=preserve_stacking)
172
189
 
173
190
    def clone_on_transport(self, transport, revision_id=None,
174
 
                           force_new_repo=False, preserve_stacking=False,
175
 
                           stacked_on=None):
 
191
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
 
192
        create_prefix=False, use_existing_dir=True):
176
193
        """Clone this bzrdir and its contents to transport verbatim.
177
194
 
178
195
        :param transport: The transport for the location to produce the clone
184
201
                               even if one is available.
185
202
        :param preserve_stacking: When cloning a stacked branch, stack the
186
203
            new branch on top of the other branch's stacked-on branch.
 
204
        :param create_prefix: Create any missing directories leading up to
 
205
            to_transport.
 
206
        :param use_existing_dir: Use an existing directory if one exists.
187
207
        """
188
 
        transport.ensure_base()
 
208
        # Overview: put together a broad description of what we want to end up
 
209
        # with; then make as few api calls as possible to do it.
 
210
        
 
211
        # We may want to create a repo/branch/tree, if we do so what format
 
212
        # would we want for each:
189
213
        require_stacking = (stacked_on is not None)
190
 
        metadir = self.cloning_metadir(require_stacking)
191
 
        result = metadir.initialize_on_transport(transport)
192
 
        repository_policy = None
 
214
        format = self.cloning_metadir(require_stacking)
 
215
        
 
216
        # Figure out what objects we want:
193
217
        try:
194
218
            local_repo = self.find_repository()
195
219
        except errors.NoRepositoryPresent:
209
233
                        errors.UnstackableRepositoryFormat,
210
234
                        errors.NotStacked):
211
235
                    pass
212
 
 
 
236
        # Bug: We create a metadir without knowing if it can support stacking,
 
237
        # we should look up the policy needs first, or just use it as a hint,
 
238
        # or something.
213
239
        if local_repo:
214
 
            # may need to copy content in
215
 
            repository_policy = result.determine_repository_policy(
216
 
                force_new_repo, stacked_on, self.root_transport.base,
217
 
                require_stacking=require_stacking)
218
240
            make_working_trees = local_repo.make_working_trees()
219
 
            result_repo = repository_policy.acquire_repository(
220
 
                make_working_trees, local_repo.is_shared())
221
 
            if not require_stacking and repository_policy._require_stacking:
222
 
                require_stacking = True
223
 
                result._format.require_stacking()
224
 
            result_repo.fetch(local_repo, revision_id=revision_id)
225
 
        else:
226
 
            result_repo = None
 
241
            want_shared = local_repo.is_shared()
 
242
            repo_format_name = format.repository_format.network_name()
 
243
        else:
 
244
            make_working_trees = False
 
245
            want_shared = False
 
246
            repo_format_name = None
 
247
 
 
248
        result_repo, result, require_stacking, repository_policy = \
 
249
            format.initialize_on_transport_ex(transport,
 
250
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
251
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
252
            stack_on_pwd=self.root_transport.base,
 
253
            repo_format_name=repo_format_name,
 
254
            make_working_trees=make_working_trees, shared_repo=want_shared)
 
255
        if repo_format_name:
 
256
            try:
 
257
                # If the result repository is in the same place as the
 
258
                # resulting bzr dir, it will have no content, further if the
 
259
                # result is not stacked then we know all content should be
 
260
                # copied, and finally if we are copying up to a specific
 
261
                # revision_id then we can use the pending-ancestry-result which
 
262
                # does not require traversing all of history to describe it.
 
263
                if (result_repo.bzrdir.root_transport.base ==
 
264
                    result.root_transport.base and not require_stacking and
 
265
                    revision_id is not None):
 
266
                    fetch_spec = graph.PendingAncestryResult(
 
267
                        [revision_id], local_repo)
 
268
                    result_repo.fetch(local_repo, fetch_spec=fetch_spec)
 
269
                else:
 
270
                    result_repo.fetch(local_repo, revision_id=revision_id)
 
271
            finally:
 
272
                result_repo.unlock()
 
273
        else:
 
274
            if result_repo is not None:
 
275
                raise AssertionError('result_repo not None(%r)' % result_repo)
227
276
        # 1 if there is a branch present
228
277
        #   make sure its content is available in the target repository
229
278
        #   clone it.
230
279
        if local_branch is not None:
231
 
            result_branch = local_branch.clone(result, revision_id=revision_id)
232
 
            if repository_policy is not None:
233
 
                repository_policy.configure_branch(result_branch)
234
 
        if result_repo is None or result_repo.make_working_trees():
235
 
            try:
 
280
            result_branch = local_branch.clone(result, revision_id=revision_id,
 
281
                repository_policy=repository_policy)
 
282
        try:
 
283
            # Cheaper to check if the target is not local, than to try making
 
284
            # the tree and fail.
 
285
            result.root_transport.local_abspath('.')
 
286
            if result_repo is None or result_repo.make_working_trees():
236
287
                self.open_workingtree().clone(result)
237
 
            except (errors.NoWorkingTree, errors.NotLocalUrl):
238
 
                pass
 
288
        except (errors.NoWorkingTree, errors.NotLocalUrl):
 
289
            pass
239
290
        return result
240
291
 
241
292
    # TODO: This should be given a Transport, and should chdir up; otherwise
247
298
    @classmethod
248
299
    def create(cls, base, format=None, possible_transports=None):
249
300
        """Create a new BzrDir at the url 'base'.
250
 
        
 
301
 
251
302
        :param format: If supplied, the format of branch to create.  If not
252
303
            supplied, the default is used.
253
 
        :param possible_transports: If supplied, a list of transports that 
 
304
        :param possible_transports: If supplied, a list of transports that
254
305
            can be reused to share a remote connection.
255
306
        """
256
307
        if cls is not BzrDir:
356
407
        """Create a new BzrDir, Branch and Repository at the url 'base'.
357
408
 
358
409
        This will use the current default BzrDirFormat unless one is
359
 
        specified, and use whatever 
 
410
        specified, and use whatever
360
411
        repository format that that uses via bzrdir.create_branch and
361
412
        create_repository. If a shared repository is available that is used
362
413
        preferentially.
376
427
                                    stack_on_pwd=None, require_stacking=False):
377
428
        """Return an object representing a policy to use.
378
429
 
379
 
        This controls whether a new repository is created, or a shared
380
 
        repository used instead.
 
430
        This controls whether a new repository is created, and the format of
 
431
        that repository, or some existing shared repository used instead.
381
432
 
382
433
        If stack_on is supplied, will not seek a containing shared repo.
383
434
 
392
443
            stack_on_pwd = None
393
444
            config = found_bzrdir.get_config()
394
445
            stop = False
395
 
            if config is not None:
396
 
                stack_on = config.get_default_stack_on()
397
 
                if stack_on is not None:
398
 
                    stack_on_pwd = found_bzrdir.root_transport.base
399
 
                    stop = True
400
 
                    note('Using default stacking branch %s at %s', stack_on,
401
 
                         stack_on_pwd)
 
446
            stack_on = config.get_default_stack_on()
 
447
            if stack_on is not None:
 
448
                stack_on_pwd = found_bzrdir.root_transport.base
 
449
                stop = True
402
450
            # does it have a repository ?
403
451
            try:
404
452
                repository = found_bzrdir.open_repository()
407
455
            else:
408
456
                if ((found_bzrdir.root_transport.base !=
409
457
                     self.root_transport.base) and not repository.is_shared()):
 
458
                    # Don't look higher, can't use a higher shared repo.
410
459
                    repository = None
 
460
                    stop = True
411
461
                else:
412
462
                    stop = True
413
463
            if not stop:
437
487
    def _find_or_create_repository(self, force_new_repo):
438
488
        """Create a new repository if needed, returning the repository."""
439
489
        policy = self.determine_repository_policy(force_new_repo)
440
 
        return policy.acquire_repository()
 
490
        return policy.acquire_repository()[0]
441
491
 
442
492
    @staticmethod
443
493
    def create_branch_convenience(base, force_new_repo=False,
450
500
        not.
451
501
 
452
502
        This will use the current default BzrDirFormat unless one is
453
 
        specified, and use whatever 
 
503
        specified, and use whatever
454
504
        repository format that that uses via bzrdir.create_branch and
455
505
        create_repository. If a shared repository is available that is used
456
506
        preferentially. Whatever repository is used, its tree creation policy
458
508
 
459
509
        The created Branch object is returned.
460
510
        If a working tree cannot be made due to base not being a file:// url,
461
 
        no error is raised unless force_new_tree is True, in which case no 
 
511
        no error is raised unless force_new_tree is True, in which case no
462
512
        data is created on disk and NotLocalUrl is raised.
463
513
 
464
514
        :param base: The URL to create the branch at.
465
515
        :param force_new_repo: If True a new repository is always created.
466
 
        :param force_new_tree: If True or False force creation of a tree or 
 
516
        :param force_new_tree: If True or False force creation of a tree or
467
517
                               prevent such creation respectively.
468
518
        :param format: Override for the bzrdir format to create.
469
519
        :param possible_transports: An optional reusable transports list.
491
541
        'base' must be a local path or a file:// url.
492
542
 
493
543
        This will use the current default BzrDirFormat unless one is
494
 
        specified, and use whatever 
 
544
        specified, and use whatever
495
545
        repository format that that uses for bzrdirformat.create_workingtree,
496
546
        create_branch and create_repository.
497
547
 
509
559
    def create_workingtree(self, revision_id=None, from_branch=None,
510
560
        accelerator_tree=None, hardlink=False):
511
561
        """Create a working tree at this BzrDir.
512
 
        
 
562
 
513
563
        :param revision_id: create it as of this revision id.
514
564
        :param from_branch: override bzrdir branch (for lightweight checkouts)
515
565
        :param accelerator_tree: A tree which can be used for retrieving file
521
571
 
522
572
    def backup_bzrdir(self):
523
573
        """Backup this bzr control directory.
524
 
        
 
574
 
525
575
        :return: Tuple with old path name and new path name
526
576
        """
527
577
        pb = ui.ui_factory.nested_progress_bar()
530
580
            # already exists, but it should instead either remove it or make
531
581
            # a new backup directory.
532
582
            #
533
 
            # FIXME: bug 262450 -- the backup directory should have the same 
 
583
            # FIXME: bug 262450 -- the backup directory should have the same
534
584
            # permissions as the .bzr directory (probably a bug in copy_tree)
535
585
            old_path = self.root_transport.abspath('.bzr')
536
586
            new_path = self.root_transport.abspath('backup.bzr')
537
 
            pb.note('making backup of %s' % (old_path,))
538
 
            pb.note('  to %s' % (new_path,))
 
587
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
539
588
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
540
589
            return (old_path, new_path)
541
590
        finally:
651
700
        IncompatibleFormat if the branch format they are given has
652
701
        a format string, and vice versa.
653
702
 
654
 
        If branch_format is None, the transport is returned with no 
 
703
        If branch_format is None, the transport is returned with no
655
704
        checking. If it is not None, then the returned transport is
656
705
        guaranteed to point to an existing directory ready for use.
657
706
        """
700
749
        if not self._mode_check_done:
701
750
            self._find_creation_modes()
702
751
        return self._dir_mode
703
 
        
 
752
 
704
753
    def get_repository_transport(self, repository_format):
705
754
        """Get the transport for use by repository format in this BzrDir.
706
755
 
708
757
        IncompatibleFormat if the repository format they are given has
709
758
        a format string, and vice versa.
710
759
 
711
 
        If repository_format is None, the transport is returned with no 
 
760
        If repository_format is None, the transport is returned with no
712
761
        checking. If it is not None, then the returned transport is
713
762
        guaranteed to point to an existing directory ready for use.
714
763
        """
715
764
        raise NotImplementedError(self.get_repository_transport)
716
 
        
 
765
 
717
766
    def get_workingtree_transport(self, tree_format):
718
767
        """Get the transport for use by workingtree format in this BzrDir.
719
768
 
721
770
        IncompatibleFormat if the workingtree format they are given has a
722
771
        format string, and vice versa.
723
772
 
724
 
        If workingtree_format is None, the transport is returned with no 
 
773
        If workingtree_format is None, the transport is returned with no
725
774
        checking. If it is not None, then the returned transport is
726
775
        guaranteed to point to an existing directory ready for use.
727
776
        """
728
777
        raise NotImplementedError(self.get_workingtree_transport)
729
778
 
730
779
    def get_config(self):
731
 
        if getattr(self, '_get_config', None) is None:
732
 
            return None
733
 
        return self._get_config()
 
780
        """Get configuration for this BzrDir."""
 
781
        return config.BzrDirConfig(self)
 
782
 
 
783
    def _get_config(self):
 
784
        """By default, no configuration is available."""
 
785
        return None
734
786
 
735
787
    def __init__(self, _transport, _format):
736
788
        """Initialize a Bzr control dir object.
737
 
        
 
789
 
738
790
        Only really common logic should reside here, concrete classes should be
739
791
        made with varying behaviours.
740
792
 
748
800
 
749
801
    def is_control_filename(self, filename):
750
802
        """True if filename is the name of a path which is reserved for bzrdir's.
751
 
        
 
803
 
752
804
        :param filename: A filename within the root transport of this bzrdir.
753
805
 
754
806
        This is true IF and ONLY IF the filename is part of the namespace reserved
757
809
        this in the future - for instance to make bzr talk with svn working
758
810
        trees.
759
811
        """
760
 
        # this might be better on the BzrDirFormat class because it refers to 
761
 
        # all the possible bzrdir disk formats. 
762
 
        # This method is tested via the workingtree is_control_filename tests- 
 
812
        # this might be better on the BzrDirFormat class because it refers to
 
813
        # all the possible bzrdir disk formats.
 
814
        # This method is tested via the workingtree is_control_filename tests-
763
815
        # it was extracted from WorkingTree.is_control_filename. If the method's
764
816
        # contract is extended beyond the current trivial implementation, please
765
817
        # add new tests for it to the appropriate place.
767
819
 
768
820
    def needs_format_conversion(self, format=None):
769
821
        """Return true if this bzrdir needs convert_format run on it.
770
 
        
771
 
        For instance, if the repository format is out of date but the 
 
822
 
 
823
        For instance, if the repository format is out of date but the
772
824
        branch and working tree are not, this should return True.
773
825
 
774
826
        :param format: Optional parameter indicating a specific desired
780
832
    def open_unsupported(base):
781
833
        """Open a branch which is not supported."""
782
834
        return BzrDir.open(base, _unsupported=True)
783
 
        
 
835
 
784
836
    @staticmethod
785
837
    def open(base, _unsupported=False, possible_transports=None):
786
838
        """Open an existing bzrdir, rooted at 'base' (url).
787
 
        
 
839
 
788
840
        :param _unsupported: a private parameter to the BzrDir class.
789
841
        """
790
842
        t = get_transport(base, possible_transports=possible_transports)
798
850
        :param transport: Transport containing the bzrdir.
799
851
        :param _unsupported: private.
800
852
        """
 
853
        for hook in BzrDir.hooks['pre_open']:
 
854
            hook(transport)
801
855
        # Keep initial base since 'transport' may be modified while following
802
856
        # the redirections.
803
857
        base = transport.base
823
877
        BzrDir._check_supported(format, _unsupported)
824
878
        return format.open(transport, _found=True)
825
879
 
826
 
    def open_branch(self, unsupported=False):
 
880
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
827
881
        """Open the branch object at this BzrDir if one is present.
828
882
 
829
883
        If unsupported is True, then no longer supported branch formats can
830
884
        still be opened.
831
 
        
 
885
 
832
886
        TODO: static convenience version of this?
833
887
        """
834
888
        raise NotImplementedError(self.open_branch)
836
890
    @staticmethod
837
891
    def open_containing(url, possible_transports=None):
838
892
        """Open an existing branch which contains url.
839
 
        
 
893
 
840
894
        :param url: url to search from.
841
895
        See open_containing_from_transport for more detail.
842
896
        """
843
897
        transport = get_transport(url, possible_transports)
844
898
        return BzrDir.open_containing_from_transport(transport)
845
 
    
 
899
 
846
900
    @staticmethod
847
901
    def open_containing_from_transport(a_transport):
848
902
        """Open an existing branch which contains a_transport.base.
851
905
 
852
906
        Basically we keep looking up until we find the control directory or
853
907
        run into the root.  If there isn't one, raises NotBranchError.
854
 
        If there is one and it is either an unrecognised format or an unsupported 
 
908
        If there is one and it is either an unrecognised format or an unsupported
855
909
        format, UnknownFormatError or UnsupportedFormatError are raised.
856
910
        If there is one, it is returned, along with the unused portion of url.
857
911
 
858
 
        :return: The BzrDir that contains the path, and a Unicode path 
 
912
        :return: The BzrDir that contains the path, and a Unicode path
859
913
                for the rest of the URL.
860
914
        """
861
915
        # this gets the normalised url back. I.e. '.' -> the full path.
969
1023
 
970
1024
    def has_branch(self):
971
1025
        """Tell if this bzrdir contains a branch.
972
 
        
 
1026
 
973
1027
        Note: if you're going to open the branch, you should just go ahead
974
 
        and try, and not ask permission first.  (This method just opens the 
975
 
        branch and discards it, and that's somewhat expensive.) 
 
1028
        and try, and not ask permission first.  (This method just opens the
 
1029
        branch and discards it, and that's somewhat expensive.)
976
1030
        """
977
1031
        try:
978
1032
            self.open_branch()
985
1039
 
986
1040
        This will still raise an exception if the bzrdir has a workingtree that
987
1041
        is remote & inaccessible.
988
 
        
 
1042
 
989
1043
        Note: if you're going to open the working tree, you should just go ahead
990
 
        and try, and not ask permission first.  (This method just opens the 
991
 
        workingtree and discards it, and that's somewhat expensive.) 
 
1044
        and try, and not ask permission first.  (This method just opens the
 
1045
        workingtree and discards it, and that's somewhat expensive.)
992
1046
        """
993
1047
        try:
994
1048
            self.open_workingtree(recommend_upgrade=False)
998
1052
 
999
1053
    def _cloning_metadir(self):
1000
1054
        """Produce a metadir suitable for cloning with.
1001
 
        
 
1055
 
1002
1056
        :returns: (destination_bzrdir_format, source_repository)
1003
1057
        """
1004
1058
        result_format = self._format.__class__()
1005
1059
        try:
1006
1060
            try:
1007
 
                branch = self.open_branch()
 
1061
                branch = self.open_branch(ignore_fallbacks=True)
1008
1062
                source_repository = branch.repository
1009
1063
                result_format._branch_format = branch._format
1010
1064
            except errors.NotBranchError:
1047
1101
        """
1048
1102
        format, repository = self._cloning_metadir()
1049
1103
        if format._workingtree_format is None:
 
1104
            # No tree in self.
1050
1105
            if repository is None:
 
1106
                # No repository either
1051
1107
                return format
 
1108
            # We have a repository, so set a working tree? (Why? This seems to
 
1109
            # contradict the stated return value in the docstring).
1052
1110
            tree_format = repository._format._matchingbzrdir.workingtree_format
1053
1111
            format.workingtree_format = tree_format.__class__()
1054
1112
        if require_stacking:
1061
1119
    def sprout(self, url, revision_id=None, force_new_repo=False,
1062
1120
               recurse='down', possible_transports=None,
1063
1121
               accelerator_tree=None, hardlink=False, stacked=False,
1064
 
               source_branch=None):
 
1122
               source_branch=None, create_tree_if_local=True):
1065
1123
        """Create a copy of this bzrdir prepared for use as a new line of
1066
1124
        development.
1067
1125
 
1082
1140
            where possible.
1083
1141
        :param stacked: If true, create a stacked branch referring to the
1084
1142
            location of this control directory.
 
1143
        :param create_tree_if_local: If true, a working-tree will be created
 
1144
            when working locally.
1085
1145
        """
1086
1146
        target_transport = get_transport(url, possible_transports)
1087
1147
        target_transport.ensure_base()
1109
1169
                    source_repository = None
1110
1170
        repository_policy = result.determine_repository_policy(
1111
1171
            force_new_repo, stacked_branch_url, require_stacking=stacked)
1112
 
        result_repo = repository_policy.acquire_repository()
 
1172
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
1173
        if is_new_repo and revision_id is not None and not stacked:
 
1174
            fetch_spec = graph.PendingAncestryResult(
 
1175
                [revision_id], source_repository)
 
1176
        else:
 
1177
            fetch_spec = None
1113
1178
        if source_repository is not None:
1114
1179
            # Fetch while stacked to prevent unstacked fetch from
1115
1180
            # Branch.sprout.
1116
 
            result_repo.fetch(source_repository, revision_id=revision_id)
 
1181
            if fetch_spec is None:
 
1182
                result_repo.fetch(source_repository, revision_id=revision_id)
 
1183
            else:
 
1184
                result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1117
1185
 
1118
1186
        if source_branch is None:
1119
1187
            # this is for sprouting a bzrdir without a branch; is that
1121
1189
            # Not especially, but it's part of the contract.
1122
1190
            result_branch = result.create_branch()
1123
1191
        else:
1124
 
            # Force NULL revision to avoid using repository before stacking
1125
 
            # is configured.
1126
 
            result_branch = source_branch.sprout(
1127
 
                result, revision_id=_mod_revision.NULL_REVISION)
1128
 
            parent_location = result_branch.get_parent()
 
1192
            result_branch = source_branch.sprout(result,
 
1193
                revision_id=revision_id, repository_policy=repository_policy)
1129
1194
        mutter("created new branch %r" % (result_branch,))
1130
 
        repository_policy.configure_branch(result_branch)
1131
 
        if source_branch is not None:
1132
 
            source_branch.copy_content_into(result_branch, revision_id)
1133
 
            # Override copy_content_into
1134
 
            result_branch.set_parent(parent_location)
1135
1195
 
1136
1196
        # Create/update the result working tree
1137
 
        if isinstance(target_transport, local.LocalTransport) and (
1138
 
            result_repo is None or result_repo.make_working_trees()):
 
1197
        if (create_tree_if_local and
 
1198
            isinstance(target_transport, local.LocalTransport) and
 
1199
            (result_repo is None or result_repo.make_working_trees())):
1139
1200
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1140
1201
                hardlink=hardlink)
1141
1202
            wt.lock_write()
1178
1239
                    basis.unlock()
1179
1240
        return result
1180
1241
 
 
1242
    def push_branch(self, source, revision_id=None, overwrite=False, 
 
1243
        remember=False, create_prefix=False):
 
1244
        """Push the source branch into this BzrDir."""
 
1245
        br_to = None
 
1246
        # If we can open a branch, use its direct repository, otherwise see
 
1247
        # if there is a repository without a branch.
 
1248
        try:
 
1249
            br_to = self.open_branch()
 
1250
        except errors.NotBranchError:
 
1251
            # Didn't find a branch, can we find a repository?
 
1252
            repository_to = self.find_repository()
 
1253
        else:
 
1254
            # Found a branch, so we must have found a repository
 
1255
            repository_to = br_to.repository
 
1256
 
 
1257
        push_result = PushResult()
 
1258
        push_result.source_branch = source
 
1259
        if br_to is None:
 
1260
            # We have a repository but no branch, copy the revisions, and then
 
1261
            # create a branch.
 
1262
            repository_to.fetch(source.repository, revision_id=revision_id)
 
1263
            br_to = source.clone(self, revision_id=revision_id)
 
1264
            if source.get_push_location() is None or remember:
 
1265
                source.set_push_location(br_to.base)
 
1266
            push_result.stacked_on = None
 
1267
            push_result.branch_push_result = None
 
1268
            push_result.old_revno = None
 
1269
            push_result.old_revid = _mod_revision.NULL_REVISION
 
1270
            push_result.target_branch = br_to
 
1271
            push_result.master_branch = None
 
1272
            push_result.workingtree_updated = False
 
1273
        else:
 
1274
            # We have successfully opened the branch, remember if necessary:
 
1275
            if source.get_push_location() is None or remember:
 
1276
                source.set_push_location(br_to.base)
 
1277
            try:
 
1278
                tree_to = self.open_workingtree()
 
1279
            except errors.NotLocalUrl:
 
1280
                push_result.branch_push_result = source.push(br_to, 
 
1281
                    overwrite, stop_revision=revision_id)
 
1282
                push_result.workingtree_updated = False
 
1283
            except errors.NoWorkingTree:
 
1284
                push_result.branch_push_result = source.push(br_to,
 
1285
                    overwrite, stop_revision=revision_id)
 
1286
                push_result.workingtree_updated = None # Not applicable
 
1287
            else:
 
1288
                tree_to.lock_write()
 
1289
                try:
 
1290
                    push_result.branch_push_result = source.push(
 
1291
                        tree_to.branch, overwrite, stop_revision=revision_id)
 
1292
                    tree_to.update()
 
1293
                finally:
 
1294
                    tree_to.unlock()
 
1295
                push_result.workingtree_updated = True
 
1296
            push_result.old_revno = push_result.branch_push_result.old_revno
 
1297
            push_result.old_revid = push_result.branch_push_result.old_revid
 
1298
            push_result.target_branch = \
 
1299
                push_result.branch_push_result.target_branch
 
1300
        return push_result
 
1301
 
 
1302
 
 
1303
class BzrDirHooks(hooks.Hooks):
 
1304
    """Hooks for BzrDir operations."""
 
1305
 
 
1306
    def __init__(self):
 
1307
        """Create the default hooks."""
 
1308
        hooks.Hooks.__init__(self)
 
1309
        self.create_hook(hooks.HookPoint('pre_open',
 
1310
            "Invoked before attempting to open a BzrDir with the transport "
 
1311
            "that the open will use.", (1, 14), None))
 
1312
 
 
1313
# install the default hooks
 
1314
BzrDir.hooks = BzrDirHooks()
 
1315
 
1181
1316
 
1182
1317
class BzrDirPreSplitOut(BzrDir):
1183
1318
    """A common class for the all-in-one formats."""
1254
1389
        # and that will have set it for us, its only
1255
1390
        # specific uses of create_workingtree in isolation
1256
1391
        # that can do wonky stuff here, and that only
1257
 
        # happens for creating checkouts, which cannot be 
 
1392
        # happens for creating checkouts, which cannot be
1258
1393
        # done on this format anyway. So - acceptable wart.
 
1394
        if hardlink:
 
1395
            warning("can't support hardlinked working trees in %r"
 
1396
                % (self,))
1259
1397
        try:
1260
1398
            result = self.open_workingtree(recommend_upgrade=False)
1261
1399
        except errors.NoSuchFile:
1283
1421
 
1284
1422
    def destroy_workingtree_metadata(self):
1285
1423
        """See BzrDir.destroy_workingtree_metadata."""
1286
 
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
 
1424
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1287
1425
                                          self)
1288
1426
 
1289
1427
    def get_branch_transport(self, branch_format):
1326
1464
            format = BzrDirFormat.get_default_format()
1327
1465
        return not isinstance(self._format, format.__class__)
1328
1466
 
1329
 
    def open_branch(self, unsupported=False):
 
1467
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1330
1468
        """See BzrDir.open_branch."""
1331
1469
        from bzrlib.branch import BzrBranchFormat4
1332
1470
        format = BzrBranchFormat4()
1335
1473
 
1336
1474
    def sprout(self, url, revision_id=None, force_new_repo=False,
1337
1475
               possible_transports=None, accelerator_tree=None,
1338
 
               hardlink=False, stacked=False):
 
1476
               hardlink=False, stacked=False, create_tree_if_local=True,
 
1477
               source_branch=None):
1339
1478
        """See BzrDir.sprout()."""
 
1479
        if source_branch is not None:
 
1480
            my_branch = self.open_branch()
 
1481
            if source_branch.base != my_branch.base:
 
1482
                raise AssertionError(
 
1483
                    "source branch %r is not within %r with branch %r" %
 
1484
                    (source_branch, self, my_branch))
1340
1485
        if stacked:
1341
1486
            raise errors.UnstackableBranchFormat(
1342
1487
                self._format, self.root_transport.base)
 
1488
        if not create_tree_if_local:
 
1489
            raise errors.MustHaveWorkingTree(
 
1490
                self._format, self.root_transport.base)
1343
1491
        from bzrlib.workingtree import WorkingTreeFormat2
1344
1492
        self._make_tail(url)
1345
1493
        result = self._format._initialize_for_clone(url)
1351
1499
            self.open_branch().sprout(result, revision_id=revision_id)
1352
1500
        except errors.NotBranchError:
1353
1501
            pass
 
1502
 
1354
1503
        # we always want a working tree
1355
1504
        WorkingTreeFormat2().initialize(result,
1356
1505
                                        accelerator_tree=accelerator_tree,
1360
1509
 
1361
1510
class BzrDir4(BzrDirPreSplitOut):
1362
1511
    """A .bzr version 4 control object.
1363
 
    
 
1512
 
1364
1513
    This is a deprecated format and may be removed after sept 2006.
1365
1514
    """
1366
1515
 
1387
1536
    This is a deprecated format and may be removed after sept 2006.
1388
1537
    """
1389
1538
 
 
1539
    def has_workingtree(self):
 
1540
        """See BzrDir.has_workingtree."""
 
1541
        return True
 
1542
    
1390
1543
    def open_repository(self):
1391
1544
        """See BzrDir.open_repository."""
1392
1545
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1408
1561
    This is a deprecated format and may be removed after sept 2006.
1409
1562
    """
1410
1563
 
 
1564
    def has_workingtree(self):
 
1565
        """See BzrDir.has_workingtree."""
 
1566
        return True
 
1567
    
1411
1568
    def open_repository(self):
1412
1569
        """See BzrDir.open_repository."""
1413
1570
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1424
1581
 
1425
1582
class BzrDirMeta1(BzrDir):
1426
1583
    """A .bzr meta version 1 control object.
1427
 
    
1428
 
    This is the first control object where the 
 
1584
 
 
1585
    This is the first control object where the
1429
1586
    individual aspects are really split out: there are separate repository,
1430
1587
    workingtree and branch subdirectories and any subset of the three can be
1431
1588
    present within a BzrDir.
1491
1648
 
1492
1649
    def get_branch_transport(self, branch_format):
1493
1650
        """See BzrDir.get_branch_transport()."""
 
1651
        # XXX: this shouldn't implicitly create the directory if it's just
 
1652
        # promising to get a transport -- mbp 20090727
1494
1653
        if branch_format is None:
1495
1654
            return self.transport.clone('branch')
1496
1655
        try:
1531
1690
            pass
1532
1691
        return self.transport.clone('checkout')
1533
1692
 
 
1693
    def has_workingtree(self):
 
1694
        """Tell if this bzrdir contains a working tree.
 
1695
 
 
1696
        This will still raise an exception if the bzrdir has a workingtree that
 
1697
        is remote & inaccessible.
 
1698
 
 
1699
        Note: if you're going to open the working tree, you should just go
 
1700
        ahead and try, and not ask permission first.
 
1701
        """
 
1702
        from bzrlib.workingtree import WorkingTreeFormat
 
1703
        try:
 
1704
            WorkingTreeFormat.find_format(self)
 
1705
        except errors.NoWorkingTree:
 
1706
            return False
 
1707
        return True
 
1708
 
1534
1709
    def needs_format_conversion(self, format=None):
1535
1710
        """See BzrDir.needs_format_conversion()."""
1536
1711
        if format is None:
1566
1741
            pass
1567
1742
        return False
1568
1743
 
1569
 
    def open_branch(self, unsupported=False):
 
1744
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1570
1745
        """See BzrDir.open_branch."""
1571
1746
        format = self.find_branch_format()
1572
1747
        self._check_supported(format, unsupported)
1573
 
        return format.open(self, _found=True)
 
1748
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1574
1749
 
1575
1750
    def open_repository(self, unsupported=False):
1576
1751
        """See BzrDir.open_repository."""
1590
1765
        return format.open(self, _found=True)
1591
1766
 
1592
1767
    def _get_config(self):
1593
 
        return config.BzrDirConfig(self.transport)
 
1768
        return config.TransportConfig(self.transport, 'control.conf')
1594
1769
 
1595
1770
 
1596
1771
class BzrDirFormat(object):
1601
1776
     * a format string,
1602
1777
     * an open routine.
1603
1778
 
1604
 
    Formats are placed in a dict by their format string for reference 
 
1779
    Formats are placed in a dict by their format string for reference
1605
1780
    during bzrdir opening. These should be subclasses of BzrDirFormat
1606
1781
    for consistency.
1607
1782
 
1608
1783
    Once a format is deprecated, just deprecate the initialize and open
1609
 
    methods on the format class. Do not deprecate the object, as the 
 
1784
    methods on the format class. Do not deprecate the object, as the
1610
1785
    object will be created every system load.
1611
1786
    """
1612
1787
 
1618
1793
 
1619
1794
    _control_formats = []
1620
1795
    """The registered control formats - .bzr, ....
1621
 
    
 
1796
 
1622
1797
    This is a list of BzrDirFormat objects.
1623
1798
    """
1624
1799
 
1652
1827
    def probe_transport(klass, transport):
1653
1828
        """Return the .bzrdir style format present in a directory."""
1654
1829
        try:
1655
 
            format_string = transport.get(".bzr/branch-format").read()
 
1830
            format_string = transport.get_bytes(".bzr/branch-format")
1656
1831
        except errors.NoSuchFile:
1657
1832
            raise errors.NotBranchError(path=transport.base)
1658
1833
 
1683
1858
        current default format. In the case of plugins we can/should provide
1684
1859
        some means for them to extend the range of returnable converters.
1685
1860
 
1686
 
        :param format: Optional format to override the default format of the 
 
1861
        :param format: Optional format to override the default format of the
1687
1862
                       library.
1688
1863
        """
1689
1864
        raise NotImplementedError(self.get_converter)
1690
1865
 
1691
1866
    def initialize(self, url, possible_transports=None):
1692
1867
        """Create a bzr control dir at this url and return an opened copy.
1693
 
        
 
1868
 
 
1869
        While not deprecated, this method is very specific and its use will
 
1870
        lead to many round trips to setup a working environment. See
 
1871
        initialize_on_transport_ex for a [nearly] all-in-one method.
 
1872
 
1694
1873
        Subclasses should typically override initialize_on_transport
1695
1874
        instead of this method.
1696
1875
        """
1699
1878
 
1700
1879
    def initialize_on_transport(self, transport):
1701
1880
        """Initialize a new bzrdir in the base directory of a Transport."""
1702
 
        # Since we don't have a .bzr directory, inherit the
 
1881
        try:
 
1882
            # can we hand off the request to the smart server rather than using
 
1883
            # vfs calls?
 
1884
            client_medium = transport.get_smart_medium()
 
1885
        except errors.NoSmartMedium:
 
1886
            return self._initialize_on_transport_vfs(transport)
 
1887
        else:
 
1888
            # Current RPC's only know how to create bzr metadir1 instances, so
 
1889
            # we still delegate to vfs methods if the requested format is not a
 
1890
            # metadir1
 
1891
            if type(self) != BzrDirMetaFormat1:
 
1892
                return self._initialize_on_transport_vfs(transport)
 
1893
            remote_format = RemoteBzrDirFormat()
 
1894
            self._supply_sub_formats_to(remote_format)
 
1895
            return remote_format.initialize_on_transport(transport)
 
1896
 
 
1897
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
1898
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
1899
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
1900
        shared_repo=False, vfs_only=False):
 
1901
        """Create this format on transport.
 
1902
 
 
1903
        The directory to initialize will be created.
 
1904
 
 
1905
        :param force_new_repo: Do not use a shared repository for the target,
 
1906
                               even if one is available.
 
1907
        :param create_prefix: Create any missing directories leading up to
 
1908
            to_transport.
 
1909
        :param use_existing_dir: Use an existing directory if one exists.
 
1910
        :param stacked_on: A url to stack any created branch on, None to follow
 
1911
            any target stacking policy.
 
1912
        :param stack_on_pwd: If stack_on is relative, the location it is
 
1913
            relative to.
 
1914
        :param repo_format_name: If non-None, a repository will be
 
1915
            made-or-found. Should none be found, or if force_new_repo is True
 
1916
            the repo_format_name is used to select the format of repository to
 
1917
            create.
 
1918
        :param make_working_trees: Control the setting of make_working_trees
 
1919
            for a new shared repository when one is made. None to use whatever
 
1920
            default the format has.
 
1921
        :param shared_repo: Control whether made repositories are shared or
 
1922
            not.
 
1923
        :param vfs_only: If True do not attempt to use a smart server
 
1924
        :return: repo, bzrdir, require_stacking, repository_policy. repo is
 
1925
            None if none was created or found, bzrdir is always valid.
 
1926
            require_stacking is the result of examining the stacked_on
 
1927
            parameter and any stacking policy found for the target.
 
1928
        """
 
1929
        if not vfs_only:
 
1930
            # Try to hand off to a smart server 
 
1931
            try:
 
1932
                client_medium = transport.get_smart_medium()
 
1933
            except errors.NoSmartMedium:
 
1934
                pass
 
1935
            else:
 
1936
                # TODO: lookup the local format from a server hint.
 
1937
                remote_dir_format = RemoteBzrDirFormat()
 
1938
                remote_dir_format._network_name = self.network_name()
 
1939
                self._supply_sub_formats_to(remote_dir_format)
 
1940
                return remote_dir_format.initialize_on_transport_ex(transport,
 
1941
                    use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
1942
                    force_new_repo=force_new_repo, stacked_on=stacked_on,
 
1943
                    stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
1944
                    make_working_trees=make_working_trees, shared_repo=shared_repo)
 
1945
        # XXX: Refactor the create_prefix/no_create_prefix code into a
 
1946
        #      common helper function
 
1947
        # The destination may not exist - if so make it according to policy.
 
1948
        def make_directory(transport):
 
1949
            transport.mkdir('.')
 
1950
            return transport
 
1951
        def redirected(transport, e, redirection_notice):
 
1952
            note(redirection_notice)
 
1953
            return transport._redirected_to(e.source, e.target)
 
1954
        try:
 
1955
            transport = do_catching_redirections(make_directory, transport,
 
1956
                redirected)
 
1957
        except errors.FileExists:
 
1958
            if not use_existing_dir:
 
1959
                raise
 
1960
        except errors.NoSuchFile:
 
1961
            if not create_prefix:
 
1962
                raise
 
1963
            transport.create_prefix()
 
1964
 
 
1965
        require_stacking = (stacked_on is not None)
 
1966
        # Now the target directory exists, but doesn't have a .bzr
 
1967
        # directory. So we need to create it, along with any work to create
 
1968
        # all of the dependent branches, etc.
 
1969
 
 
1970
        result = self.initialize_on_transport(transport)
 
1971
        if repo_format_name:
 
1972
            try:
 
1973
                # use a custom format
 
1974
                result._format.repository_format = \
 
1975
                    repository.network_format_registry.get(repo_format_name)
 
1976
            except AttributeError:
 
1977
                # The format didn't permit it to be set.
 
1978
                pass
 
1979
            # A repository is desired, either in-place or shared.
 
1980
            repository_policy = result.determine_repository_policy(
 
1981
                force_new_repo, stacked_on, stack_on_pwd,
 
1982
                require_stacking=require_stacking)
 
1983
            result_repo, is_new_repo = repository_policy.acquire_repository(
 
1984
                make_working_trees, shared_repo)
 
1985
            if not require_stacking and repository_policy._require_stacking:
 
1986
                require_stacking = True
 
1987
                result._format.require_stacking()
 
1988
            result_repo.lock_write()
 
1989
        else:
 
1990
            result_repo = None
 
1991
            repository_policy = None
 
1992
        return result_repo, result, require_stacking, repository_policy
 
1993
 
 
1994
    def _initialize_on_transport_vfs(self, transport):
 
1995
        """Initialize a new bzrdir using VFS calls.
 
1996
 
 
1997
        :param transport: The transport to create the .bzr directory in.
 
1998
        :return: A
 
1999
        """
 
2000
        # Since we are creating a .bzr directory, inherit the
1703
2001
        # mode from the root directory
1704
2002
        temp_control = lockable_files.LockableFiles(transport,
1705
2003
                            '', lockable_files.TransportLock)
1735
2033
        """Is this format supported?
1736
2034
 
1737
2035
        Supported formats must be initializable and openable.
1738
 
        Unsupported formats may not support initialization or committing or 
 
2036
        Unsupported formats may not support initialization or committing or
1739
2037
        some other features depending on the reason for not being supported.
1740
2038
        """
1741
2039
        return True
1742
2040
 
 
2041
    def network_name(self):
 
2042
        """A simple byte string uniquely identifying this format for RPC calls.
 
2043
 
 
2044
        Bzr control formats use thir disk format string to identify the format
 
2045
        over the wire. Its possible that other control formats have more
 
2046
        complex detection requirements, so we permit them to use any unique and
 
2047
        immutable string they desire.
 
2048
        """
 
2049
        raise NotImplementedError(self.network_name)
 
2050
 
1743
2051
    def same_model(self, target_format):
1744
 
        return (self.repository_format.rich_root_data == 
 
2052
        return (self.repository_format.rich_root_data ==
1745
2053
            target_format.rich_root_data)
1746
2054
 
1747
2055
    @classmethod
1748
2056
    def known_formats(klass):
1749
2057
        """Return all the known formats.
1750
 
        
 
2058
 
1751
2059
        Concrete formats should override _known_formats.
1752
2060
        """
1753
 
        # There is double indirection here to make sure that control 
1754
 
        # formats used by more than one dir format will only be probed 
 
2061
        # There is double indirection here to make sure that control
 
2062
        # formats used by more than one dir format will only be probed
1755
2063
        # once. This can otherwise be quite expensive for remote connections.
1756
2064
        result = set()
1757
2065
        for format in klass._control_formats:
1758
2066
            result.update(format._known_formats())
1759
2067
        return result
1760
 
    
 
2068
 
1761
2069
    @classmethod
1762
2070
    def _known_formats(klass):
1763
2071
        """Return the known format instances for this control format."""
1765
2073
 
1766
2074
    def open(self, transport, _found=False):
1767
2075
        """Return an instance of this format for the dir transport points at.
1768
 
        
 
2076
 
1769
2077
        _found is a private parameter, do not use it.
1770
2078
        """
1771
2079
        if not _found:
1772
2080
            found_format = BzrDirFormat.find_format(transport)
1773
2081
            if not isinstance(found_format, self.__class__):
1774
2082
                raise AssertionError("%s was asked to open %s, but it seems to need "
1775
 
                        "format %s" 
 
2083
                        "format %s"
1776
2084
                        % (self, transport, found_format))
 
2085
            # Allow subclasses - use the found format.
 
2086
            self._supply_sub_formats_to(found_format)
 
2087
            return found_format._open(transport)
1777
2088
        return self._open(transport)
1778
2089
 
1779
2090
    def _open(self, transport):
1787
2098
    @classmethod
1788
2099
    def register_format(klass, format):
1789
2100
        klass._formats[format.get_format_string()] = format
 
2101
        # bzr native formats have a network name of their format string.
 
2102
        network_format_registry.register(format.get_format_string(), format.__class__)
1790
2103
 
1791
2104
    @classmethod
1792
2105
    def register_control_format(klass, format):
1793
2106
        """Register a format that does not use '.bzr' for its control dir.
1794
2107
 
1795
2108
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1796
 
        which BzrDirFormat can inherit from, and renamed to register_format 
 
2109
        which BzrDirFormat can inherit from, and renamed to register_format
1797
2110
        there. It has been done without that for now for simplicity of
1798
2111
        implementation.
1799
2112
        """
1817
2130
 
1818
2131
    def __str__(self):
1819
2132
        # Trim the newline
1820
 
        return self.get_format_string().rstrip()
 
2133
        return self.get_format_description().rstrip()
 
2134
 
 
2135
    def _supply_sub_formats_to(self, other_format):
 
2136
        """Give other_format the same values for sub formats as this has.
 
2137
 
 
2138
        This method is expected to be used when parameterising a
 
2139
        RemoteBzrDirFormat instance with the parameters from a
 
2140
        BzrDirMetaFormat1 instance.
 
2141
 
 
2142
        :param other_format: other_format is a format which should be
 
2143
            compatible with whatever sub formats are supported by self.
 
2144
        :return: None.
 
2145
        """
1821
2146
 
1822
2147
    @classmethod
1823
2148
    def unregister_format(klass, format):
1855
2180
        """See BzrDirFormat.get_converter()."""
1856
2181
        # there is one and only one upgrade path here.
1857
2182
        return ConvertBzrDir4To5()
1858
 
        
 
2183
 
1859
2184
    def initialize_on_transport(self, transport):
1860
2185
        """Format 4 branches cannot be created."""
1861
2186
        raise errors.UninitializableFormat(self)
1864
2189
        """Format 4 is not supported.
1865
2190
 
1866
2191
        It is not supported because the model changed from 4 to 5 and the
1867
 
        conversion logic is expensive - so doing it on the fly was not 
 
2192
        conversion logic is expensive - so doing it on the fly was not
1868
2193
        feasible.
1869
2194
        """
1870
2195
        return False
1871
2196
 
 
2197
    def network_name(self):
 
2198
        return self.get_format_string()
 
2199
 
1872
2200
    def _open(self, transport):
1873
2201
        """See BzrDirFormat._open."""
1874
2202
        return BzrDir4(transport, self)
1880
2208
    repository_format = property(__return_repository_format)
1881
2209
 
1882
2210
 
1883
 
class BzrDirFormat5(BzrDirFormat):
 
2211
class BzrDirFormatAllInOne(BzrDirFormat):
 
2212
    """Common class for formats before meta-dirs."""
 
2213
 
 
2214
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
2215
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
2216
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
2217
        shared_repo=False):
 
2218
        """See BzrDirFormat.initialize_on_transport_ex."""
 
2219
        require_stacking = (stacked_on is not None)
 
2220
        # Format 5 cannot stack, but we've been asked to - actually init
 
2221
        # a Meta1Dir
 
2222
        if require_stacking:
 
2223
            format = BzrDirMetaFormat1()
 
2224
            return format.initialize_on_transport_ex(transport,
 
2225
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
2226
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
2227
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
2228
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
2229
        return BzrDirFormat.initialize_on_transport_ex(self, transport,
 
2230
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
2231
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
2232
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
2233
            make_working_trees=make_working_trees, shared_repo=shared_repo)
 
2234
 
 
2235
 
 
2236
class BzrDirFormat5(BzrDirFormatAllInOne):
1884
2237
    """Bzr control format 5.
1885
2238
 
1886
2239
    This format is a combined format for working tree, branch and repository.
1887
2240
    It has:
1888
 
     - Format 2 working trees [always] 
1889
 
     - Format 4 branches [always] 
 
2241
     - Format 2 working trees [always]
 
2242
     - Format 4 branches [always]
1890
2243
     - Format 5 repositories [always]
1891
2244
       Unhashed stores in the repository.
1892
2245
    """
1912
2265
 
1913
2266
    def _initialize_for_clone(self, url):
1914
2267
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1915
 
        
 
2268
 
1916
2269
    def initialize_on_transport(self, transport, _cloning=False):
1917
2270
        """Format 5 dirs always have working tree, branch and repository.
1918
 
        
 
2271
 
1919
2272
        Except when they are being cloned.
1920
2273
        """
1921
2274
        from bzrlib.branch import BzrBranchFormat4
1927
2280
            result._init_workingtree()
1928
2281
        return result
1929
2282
 
 
2283
    def network_name(self):
 
2284
        return self.get_format_string()
 
2285
 
1930
2286
    def _open(self, transport):
1931
2287
        """See BzrDirFormat._open."""
1932
2288
        return BzrDir5(transport, self)
1938
2294
    repository_format = property(__return_repository_format)
1939
2295
 
1940
2296
 
1941
 
class BzrDirFormat6(BzrDirFormat):
 
2297
class BzrDirFormat6(BzrDirFormatAllInOne):
1942
2298
    """Bzr control format 6.
1943
2299
 
1944
2300
    This format is a combined format for working tree, branch and repository.
1945
2301
    It has:
1946
 
     - Format 2 working trees [always] 
1947
 
     - Format 4 branches [always] 
 
2302
     - Format 2 working trees [always]
 
2303
     - Format 4 branches [always]
1948
2304
     - Format 6 repositories [always]
1949
2305
    """
1950
2306
 
1966
2322
        """See BzrDirFormat.get_converter()."""
1967
2323
        # there is one and only one upgrade path here.
1968
2324
        return ConvertBzrDir6ToMeta()
1969
 
        
 
2325
 
1970
2326
    def _initialize_for_clone(self, url):
1971
2327
        return self.initialize_on_transport(get_transport(url), _cloning=True)
1972
2328
 
1973
2329
    def initialize_on_transport(self, transport, _cloning=False):
1974
2330
        """Format 6 dirs always have working tree, branch and repository.
1975
 
        
 
2331
 
1976
2332
        Except when they are being cloned.
1977
2333
        """
1978
2334
        from bzrlib.branch import BzrBranchFormat4
1984
2340
            result._init_workingtree()
1985
2341
        return result
1986
2342
 
 
2343
    def network_name(self):
 
2344
        return self.get_format_string()
 
2345
 
1987
2346
    def _open(self, transport):
1988
2347
        """See BzrDirFormat._open."""
1989
2348
        return BzrDir6(transport, self)
2011
2370
    def __init__(self):
2012
2371
        self._workingtree_format = None
2013
2372
        self._branch_format = None
 
2373
        self._repository_format = None
2014
2374
 
2015
2375
    def __eq__(self, other):
2016
2376
        if other.__class__ is not self.__class__:
2033
2393
    def set_branch_format(self, format):
2034
2394
        self._branch_format = format
2035
2395
 
2036
 
    def require_stacking(self):
 
2396
    def require_stacking(self, stack_on=None, possible_transports=None,
 
2397
            _skip_repo=False):
 
2398
        """We have a request to stack, try to ensure the formats support it.
 
2399
 
 
2400
        :param stack_on: If supplied, it is the URL to a branch that we want to
 
2401
            stack on. Check to see if that format supports stacking before
 
2402
            forcing an upgrade.
 
2403
        """
 
2404
        # Stacking is desired. requested by the target, but does the place it
 
2405
        # points at support stacking? If it doesn't then we should
 
2406
        # not implicitly upgrade. We check this here.
 
2407
        new_repo_format = None
 
2408
        new_branch_format = None
 
2409
 
 
2410
        # a bit of state for get_target_branch so that we don't try to open it
 
2411
        # 2 times, for both repo *and* branch
 
2412
        target = [None, False, None] # target_branch, checked, upgrade anyway
 
2413
        def get_target_branch():
 
2414
            if target[1]:
 
2415
                # We've checked, don't check again
 
2416
                return target
 
2417
            if stack_on is None:
 
2418
                # No target format, that means we want to force upgrading
 
2419
                target[:] = [None, True, True]
 
2420
                return target
 
2421
            try:
 
2422
                target_dir = BzrDir.open(stack_on,
 
2423
                    possible_transports=possible_transports)
 
2424
            except errors.NotBranchError:
 
2425
                # Nothing there, don't change formats
 
2426
                target[:] = [None, True, False]
 
2427
                return target
 
2428
            except errors.JailBreak:
 
2429
                # JailBreak, JFDI and upgrade anyway
 
2430
                target[:] = [None, True, True]
 
2431
                return target
 
2432
            try:
 
2433
                target_branch = target_dir.open_branch()
 
2434
            except errors.NotBranchError:
 
2435
                # No branch, don't upgrade formats
 
2436
                target[:] = [None, True, False]
 
2437
                return target
 
2438
            target[:] = [target_branch, True, False]
 
2439
            return target
 
2440
 
 
2441
        if (not _skip_repo and
 
2442
                 not self.repository_format.supports_external_lookups):
 
2443
            # We need to upgrade the Repository.
 
2444
            target_branch, _, do_upgrade = get_target_branch()
 
2445
            if target_branch is None:
 
2446
                # We don't have a target branch, should we upgrade anyway?
 
2447
                if do_upgrade:
 
2448
                    # stack_on is inaccessible, JFDI.
 
2449
                    # TODO: bad monkey, hard-coded formats...
 
2450
                    if self.repository_format.rich_root_data:
 
2451
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2452
                    else:
 
2453
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
 
2454
            else:
 
2455
                # If the target already supports stacking, then we know the
 
2456
                # project is already able to use stacking, so auto-upgrade
 
2457
                # for them
 
2458
                new_repo_format = target_branch.repository._format
 
2459
                if not new_repo_format.supports_external_lookups:
 
2460
                    # target doesn't, source doesn't, so don't auto upgrade
 
2461
                    # repo
 
2462
                    new_repo_format = None
 
2463
            if new_repo_format is not None:
 
2464
                self.repository_format = new_repo_format
 
2465
                note('Source repository format does not support stacking,'
 
2466
                     ' using format:\n  %s',
 
2467
                     new_repo_format.get_format_description())
 
2468
 
2037
2469
        if not self.get_branch_format().supports_stacking():
2038
 
            # We need to make a stacked branch, but the default format for the
2039
 
            # target doesn't support stacking.  So force a branch that *can*
2040
 
            # support stacking.
2041
 
            from bzrlib.branch import BzrBranchFormat7
2042
 
            self._branch_format = BzrBranchFormat7()
2043
 
            mutter("using %r for stacking" % (self._branch_format,))
2044
 
            from bzrlib.repofmt import pack_repo
2045
 
            if self.repository_format.rich_root_data:
2046
 
                bzrdir_format_name = '1.6.1-rich-root'
2047
 
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2470
            # We just checked the repo, now lets check if we need to
 
2471
            # upgrade the branch format
 
2472
            target_branch, _, do_upgrade = get_target_branch()
 
2473
            if target_branch is None:
 
2474
                if do_upgrade:
 
2475
                    # TODO: bad monkey, hard-coded formats...
 
2476
                    new_branch_format = branch.BzrBranchFormat7()
2048
2477
            else:
2049
 
                bzrdir_format_name = '1.6'
2050
 
                repo_format = pack_repo.RepositoryFormatKnitPack5()
2051
 
            note('Source format does not support stacking, using format:'
2052
 
                 ' \'%s\'\n  %s\n',
2053
 
                 bzrdir_format_name, repo_format.get_format_description())
2054
 
            self.repository_format = repo_format
 
2478
                new_branch_format = target_branch._format
 
2479
                if not new_branch_format.supports_stacking():
 
2480
                    new_branch_format = None
 
2481
            if new_branch_format is not None:
 
2482
                # Does support stacking, use its format.
 
2483
                self.set_branch_format(new_branch_format)
 
2484
                note('Source branch format does not support stacking,'
 
2485
                     ' using format:\n  %s',
 
2486
                     new_branch_format.get_format_description())
2055
2487
 
2056
2488
    def get_converter(self, format=None):
2057
2489
        """See BzrDirFormat.get_converter()."""
2070
2502
        """See BzrDirFormat.get_format_description()."""
2071
2503
        return "Meta directory format 1"
2072
2504
 
 
2505
    def network_name(self):
 
2506
        return self.get_format_string()
 
2507
 
2073
2508
    def _open(self, transport):
2074
2509
        """See BzrDirFormat._open."""
2075
 
        return BzrDirMeta1(transport, self)
 
2510
        # Create a new format instance because otherwise initialisation of new
 
2511
        # metadirs share the global default format object leading to alias
 
2512
        # problems.
 
2513
        format = BzrDirMetaFormat1()
 
2514
        self._supply_sub_formats_to(format)
 
2515
        return BzrDirMeta1(transport, format)
2076
2516
 
2077
2517
    def __return_repository_format(self):
2078
2518
        """Circular import protection."""
2079
 
        if getattr(self, '_repository_format', None):
 
2519
        if self._repository_format:
2080
2520
            return self._repository_format
2081
2521
        from bzrlib.repository import RepositoryFormat
2082
2522
        return RepositoryFormat.get_default_format()
2083
2523
 
2084
 
    def __set_repository_format(self, value):
 
2524
    def _set_repository_format(self, value):
2085
2525
        """Allow changing the repository format for metadir formats."""
2086
2526
        self._repository_format = value
2087
2527
 
2088
 
    repository_format = property(__return_repository_format, __set_repository_format)
 
2528
    repository_format = property(__return_repository_format,
 
2529
        _set_repository_format)
 
2530
 
 
2531
    def _supply_sub_formats_to(self, other_format):
 
2532
        """Give other_format the same values for sub formats as this has.
 
2533
 
 
2534
        This method is expected to be used when parameterising a
 
2535
        RemoteBzrDirFormat instance with the parameters from a
 
2536
        BzrDirMetaFormat1 instance.
 
2537
 
 
2538
        :param other_format: other_format is a format which should be
 
2539
            compatible with whatever sub formats are supported by self.
 
2540
        :return: None.
 
2541
        """
 
2542
        if getattr(self, '_repository_format', None) is not None:
 
2543
            other_format.repository_format = self.repository_format
 
2544
        if self._branch_format is not None:
 
2545
            other_format._branch_format = self._branch_format
 
2546
        if self._workingtree_format is not None:
 
2547
            other_format.workingtree_format = self.workingtree_format
2089
2548
 
2090
2549
    def __get_workingtree_format(self):
2091
2550
        if self._workingtree_format is None:
2100
2559
                                  __set_workingtree_format)
2101
2560
 
2102
2561
 
 
2562
network_format_registry = registry.FormatRegistry()
 
2563
"""Registry of formats indexed by their network name.
 
2564
 
 
2565
The network name for a BzrDirFormat is an identifier that can be used when
 
2566
referring to formats with smart server operations. See
 
2567
BzrDirFormat.network_name() for more detail.
 
2568
"""
 
2569
 
 
2570
 
2103
2571
# Register bzr control format
2104
2572
BzrDirFormat.register_control_format(BzrDirFormat)
2105
2573
 
2137
2605
        self.absent_revisions = set()
2138
2606
        self.text_count = 0
2139
2607
        self.revisions = {}
2140
 
        
 
2608
 
2141
2609
    def convert(self, to_convert, pb):
2142
2610
        """See Converter.convert()."""
2143
2611
        self.bzrdir = to_convert
2144
2612
        self.pb = pb
2145
 
        self.pb.note('starting upgrade from format 4 to 5')
 
2613
        ui.ui_factory.note('starting upgrade from format 4 to 5')
2146
2614
        if isinstance(self.bzrdir.transport, local.LocalTransport):
2147
2615
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2148
2616
        self._convert_to_weaves()
2149
2617
        return BzrDir.open(self.bzrdir.root_transport.base)
2150
2618
 
2151
2619
    def _convert_to_weaves(self):
2152
 
        self.pb.note('note: upgrade may be faster if all store files are ungzipped first')
 
2620
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
2153
2621
        try:
2154
2622
            # TODO permissions
2155
2623
            stat = self.bzrdir.transport.stat('weaves')
2183
2651
        self.pb.clear()
2184
2652
        self._write_all_weaves()
2185
2653
        self._write_all_revs()
2186
 
        self.pb.note('upgraded to weaves:')
2187
 
        self.pb.note('  %6d revisions and inventories', len(self.revisions))
2188
 
        self.pb.note('  %6d revisions not present', len(self.absent_revisions))
2189
 
        self.pb.note('  %6d texts', self.text_count)
 
2654
        ui.ui_factory.note('upgraded to weaves:')
 
2655
        ui.ui_factory.note('  %6d revisions and inventories' % len(self.revisions))
 
2656
        ui.ui_factory.note('  %6d revisions not present' % len(self.absent_revisions))
 
2657
        ui.ui_factory.note('  %6d texts' % self.text_count)
2190
2658
        self._cleanup_spare_files_after_format4()
2191
2659
        self.branch._transport.put_bytes(
2192
2660
            'branch-format',
2249
2717
                revision_store.add_lines(key, None, osutils.split_lines(text))
2250
2718
        finally:
2251
2719
            self.pb.clear()
2252
 
            
 
2720
 
2253
2721
    def _load_one_rev(self, rev_id):
2254
2722
        """Load a revision object into memory.
2255
2723
 
2260
2728
                       len(self.known_revisions))
2261
2729
        if not self.branch.repository.has_revision(rev_id):
2262
2730
            self.pb.clear()
2263
 
            self.pb.note('revision {%s} not present in branch; '
2264
 
                         'will be converted as a ghost',
 
2731
            ui.ui_factory.note('revision {%s} not present in branch; '
 
2732
                         'will be converted as a ghost' %
2265
2733
                         rev_id)
2266
2734
            self.absent_revisions.add(rev_id)
2267
2735
        else:
2329
2797
        text_changed = False
2330
2798
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2331
2799
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2332
 
        # XXX: Note that this is unordered - and this is tolerable because 
 
2800
        # XXX: Note that this is unordered - and this is tolerable because
2333
2801
        # the previous code was also unordered.
2334
2802
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2335
2803
            in heads)
2336
2804
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2337
2805
        del ie.text_id
2338
2806
 
2339
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
2340
 
    def get_parents(self, revision_ids):
2341
 
        for revision_id in revision_ids:
2342
 
            yield self.revisions[revision_id].parent_ids
2343
 
 
2344
2807
    def get_parent_map(self, revision_ids):
2345
 
        """See graph._StackedParentsProvider.get_parent_map"""
 
2808
        """See graph.StackedParentsProvider.get_parent_map"""
2346
2809
        return dict((revision_id, self.revisions[revision_id])
2347
2810
                    for revision_id in revision_ids
2348
2811
                     if revision_id in self.revisions)
2352
2815
        # a call to:. This needs the path figured out. rather than a work_tree
2353
2816
        # a v4 revision_tree can be given, or something that looks enough like
2354
2817
        # one to give the file content to the entry if it needs it.
2355
 
        # and we need something that looks like a weave store for snapshot to 
 
2818
        # and we need something that looks like a weave store for snapshot to
2356
2819
        # save against.
2357
2820
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2358
2821
        if len(previous_revisions) == 1:
2399
2862
        """See Converter.convert()."""
2400
2863
        self.bzrdir = to_convert
2401
2864
        self.pb = pb
2402
 
        self.pb.note('starting upgrade from format 5 to 6')
 
2865
        ui.ui_factory.note('starting upgrade from format 5 to 6')
2403
2866
        self._convert_to_prefixed()
2404
2867
        return BzrDir.open(self.bzrdir.root_transport.base)
2405
2868
 
2407
2870
        from bzrlib.store import TransportStore
2408
2871
        self.bzrdir.transport.delete('branch-format')
2409
2872
        for store_name in ["weaves", "revision-store"]:
2410
 
            self.pb.note("adding prefixes to %s" % store_name)
 
2873
            ui.ui_factory.note("adding prefixes to %s" % store_name)
2411
2874
            store_transport = self.bzrdir.transport.clone(store_name)
2412
2875
            store = TransportStore(store_transport, prefixed=True)
2413
2876
            for urlfilename in store_transport.list_dir('.'):
2447
2910
        self.dir_mode = self.bzrdir._get_dir_mode()
2448
2911
        self.file_mode = self.bzrdir._get_file_mode()
2449
2912
 
2450
 
        self.pb.note('starting upgrade from format 6 to metadir')
 
2913
        ui.ui_factory.note('starting upgrade from format 6 to metadir')
2451
2914
        self.bzrdir.transport.put_bytes(
2452
2915
                'branch-format',
2453
2916
                "Converting to format 6",
2474
2937
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2475
2938
        self.make_lock('repository')
2476
2939
        # we hard code the formats here because we are converting into
2477
 
        # the meta format. The meta format upgrader can take this to a 
 
2940
        # the meta format. The meta format upgrader can take this to a
2478
2941
        # future format within each component.
2479
2942
        self.put_format('repository', RepositoryFormat7())
2480
2943
        for entry in repository_names:
2503
2966
        else:
2504
2967
            has_checkout = True
2505
2968
        if not has_checkout:
2506
 
            self.pb.note('No working tree.')
 
2969
            ui.ui_factory.note('No working tree.')
2507
2970
            # If some checkout files are there, we may as well get rid of them.
2508
2971
            for name, mandatory in checkout_files:
2509
2972
                if name in bzrcontents:
2578
3041
        else:
2579
3042
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
2580
3043
                from bzrlib.repository import CopyConverter
2581
 
                self.pb.note('starting repository conversion')
 
3044
                ui.ui_factory.note('starting repository conversion')
2582
3045
                converter = CopyConverter(self.target_format.repository_format)
2583
3046
                converter.convert(repo, pb)
2584
3047
        try:
2595
3058
            while old != new:
2596
3059
                if (old == _mod_branch.BzrBranchFormat5 and
2597
3060
                    new in (_mod_branch.BzrBranchFormat6,
2598
 
                        _mod_branch.BzrBranchFormat7)):
 
3061
                        _mod_branch.BzrBranchFormat7,
 
3062
                        _mod_branch.BzrBranchFormat8)):
2599
3063
                    branch_converter = _mod_branch.Converter5to6()
2600
3064
                elif (old == _mod_branch.BzrBranchFormat6 and
2601
 
                    new == _mod_branch.BzrBranchFormat7):
 
3065
                    new in (_mod_branch.BzrBranchFormat7,
 
3066
                            _mod_branch.BzrBranchFormat8)):
2602
3067
                    branch_converter = _mod_branch.Converter6to7()
 
3068
                elif (old == _mod_branch.BzrBranchFormat7 and
 
3069
                      new is _mod_branch.BzrBranchFormat8):
 
3070
                    branch_converter = _mod_branch.Converter7to8()
2603
3071
                else:
2604
 
                    raise errors.BadConversionTarget("No converter", new)
 
3072
                    raise errors.BadConversionTarget("No converter", new,
 
3073
                        branch._format)
2605
3074
                branch_converter.convert(branch)
2606
3075
                branch = self.bzrdir.open_branch()
2607
3076
                old = branch._format.__class__
2622
3091
                isinstance(self.target_format.workingtree_format,
2623
3092
                    workingtree_4.WorkingTreeFormat5)):
2624
3093
                workingtree_4.Converter4to5().convert(tree)
 
3094
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
 
3095
                not isinstance(tree, workingtree_4.WorkingTree6) and
 
3096
                isinstance(self.target_format.workingtree_format,
 
3097
                    workingtree_4.WorkingTreeFormat6)):
 
3098
                workingtree_4.Converter4or5to6().convert(tree)
2625
3099
        return to_convert
2626
3100
 
2627
3101
 
2628
 
# This is not in remote.py because it's small, and needs to be registered.
2629
 
# Putting it in remote.py creates a circular import problem.
 
3102
# This is not in remote.py because it's relatively small, and needs to be
 
3103
# registered. Putting it in remote.py creates a circular import problem.
2630
3104
# we can make it a lazy object if the control formats is turned into something
2631
3105
# like a registry.
2632
3106
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2633
3107
    """Format representing bzrdirs accessed via a smart server"""
2634
3108
 
 
3109
    def __init__(self):
 
3110
        BzrDirMetaFormat1.__init__(self)
 
3111
        # XXX: It's a bit ugly that the network name is here, because we'd
 
3112
        # like to believe that format objects are stateless or at least
 
3113
        # immutable,  However, we do at least avoid mutating the name after
 
3114
        # it's returned.  See <https://bugs.edge.launchpad.net/bzr/+bug/504102>
 
3115
        self._network_name = None
 
3116
 
 
3117
    def __repr__(self):
 
3118
        return "%s(_network_name=%r)" % (self.__class__.__name__,
 
3119
            self._network_name)
 
3120
 
2635
3121
    def get_format_description(self):
 
3122
        if self._network_name:
 
3123
            real_format = network_format_registry.get(self._network_name)
 
3124
            return 'Remote: ' + real_format.get_format_description()
2636
3125
        return 'bzr remote bzrdir'
2637
 
    
 
3126
 
 
3127
    def get_format_string(self):
 
3128
        raise NotImplementedError(self.get_format_string)
 
3129
 
 
3130
    def network_name(self):
 
3131
        if self._network_name:
 
3132
            return self._network_name
 
3133
        else:
 
3134
            raise AssertionError("No network name set.")
 
3135
 
2638
3136
    @classmethod
2639
3137
    def probe_transport(klass, transport):
2640
3138
        """Return a RemoteBzrDirFormat object if it looks possible."""
2669
3167
            return local_dir_format.initialize_on_transport(transport)
2670
3168
        client = _SmartClient(client_medium)
2671
3169
        path = client.remote_path_from_transport(transport)
2672
 
        response = client.call('BzrDirFormat.initialize', path)
 
3170
        try:
 
3171
            response = client.call('BzrDirFormat.initialize', path)
 
3172
        except errors.ErrorFromSmartServer, err:
 
3173
            remote._translate_error(err, path=path)
2673
3174
        if response[0] != 'ok':
2674
3175
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2675
 
        return remote.RemoteBzrDir(transport)
 
3176
        format = RemoteBzrDirFormat()
 
3177
        self._supply_sub_formats_to(format)
 
3178
        return remote.RemoteBzrDir(transport, format)
 
3179
 
 
3180
    def parse_NoneTrueFalse(self, arg):
 
3181
        if not arg:
 
3182
            return None
 
3183
        if arg == 'False':
 
3184
            return False
 
3185
        if arg == 'True':
 
3186
            return True
 
3187
        raise AssertionError("invalid arg %r" % arg)
 
3188
 
 
3189
    def _serialize_NoneTrueFalse(self, arg):
 
3190
        if arg is False:
 
3191
            return 'False'
 
3192
        if arg:
 
3193
            return 'True'
 
3194
        return ''
 
3195
 
 
3196
    def _serialize_NoneString(self, arg):
 
3197
        return arg or ''
 
3198
 
 
3199
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
3200
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
3201
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
3202
        shared_repo=False):
 
3203
        try:
 
3204
            # hand off the request to the smart server
 
3205
            client_medium = transport.get_smart_medium()
 
3206
        except errors.NoSmartMedium:
 
3207
            do_vfs = True
 
3208
        else:
 
3209
            # Decline to open it if the server doesn't support our required
 
3210
            # version (3) so that the VFS-based transport will do it.
 
3211
            if client_medium.should_probe():
 
3212
                try:
 
3213
                    server_version = client_medium.protocol_version()
 
3214
                    if server_version != '2':
 
3215
                        do_vfs = True
 
3216
                    else:
 
3217
                        do_vfs = False
 
3218
                except errors.SmartProtocolError:
 
3219
                    # Apparently there's no usable smart server there, even though
 
3220
                    # the medium supports the smart protocol.
 
3221
                    do_vfs = True
 
3222
            else:
 
3223
                do_vfs = False
 
3224
        if not do_vfs:
 
3225
            client = _SmartClient(client_medium)
 
3226
            path = client.remote_path_from_transport(transport)
 
3227
            if client_medium._is_remote_before((1, 16)):
 
3228
                do_vfs = True
 
3229
        if do_vfs:
 
3230
            # TODO: lookup the local format from a server hint.
 
3231
            local_dir_format = BzrDirMetaFormat1()
 
3232
            self._supply_sub_formats_to(local_dir_format)
 
3233
            return local_dir_format.initialize_on_transport_ex(transport,
 
3234
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3235
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3236
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3237
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3238
                vfs_only=True)
 
3239
        return self._initialize_on_transport_ex_rpc(client, path, transport,
 
3240
            use_existing_dir, create_prefix, force_new_repo, stacked_on,
 
3241
            stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
 
3242
 
 
3243
    def _initialize_on_transport_ex_rpc(self, client, path, transport,
 
3244
        use_existing_dir, create_prefix, force_new_repo, stacked_on,
 
3245
        stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
 
3246
        args = []
 
3247
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
 
3248
        args.append(self._serialize_NoneTrueFalse(create_prefix))
 
3249
        args.append(self._serialize_NoneTrueFalse(force_new_repo))
 
3250
        args.append(self._serialize_NoneString(stacked_on))
 
3251
        # stack_on_pwd is often/usually our transport
 
3252
        if stack_on_pwd:
 
3253
            try:
 
3254
                stack_on_pwd = transport.relpath(stack_on_pwd)
 
3255
                if not stack_on_pwd:
 
3256
                    stack_on_pwd = '.'
 
3257
            except errors.PathNotChild:
 
3258
                pass
 
3259
        args.append(self._serialize_NoneString(stack_on_pwd))
 
3260
        args.append(self._serialize_NoneString(repo_format_name))
 
3261
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
 
3262
        args.append(self._serialize_NoneTrueFalse(shared_repo))
 
3263
        request_network_name = self._network_name or \
 
3264
            BzrDirFormat.get_default_format().network_name()
 
3265
        try:
 
3266
            response = client.call('BzrDirFormat.initialize_ex_1.16',
 
3267
                request_network_name, path, *args)
 
3268
        except errors.UnknownSmartMethod:
 
3269
            client._medium._remember_remote_is_before((1,16))
 
3270
            local_dir_format = BzrDirMetaFormat1()
 
3271
            self._supply_sub_formats_to(local_dir_format)
 
3272
            return local_dir_format.initialize_on_transport_ex(transport,
 
3273
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3274
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3275
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3276
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3277
                vfs_only=True)
 
3278
        except errors.ErrorFromSmartServer, err:
 
3279
            remote._translate_error(err, path=path)
 
3280
        repo_path = response[0]
 
3281
        bzrdir_name = response[6]
 
3282
        require_stacking = response[7]
 
3283
        require_stacking = self.parse_NoneTrueFalse(require_stacking)
 
3284
        format = RemoteBzrDirFormat()
 
3285
        format._network_name = bzrdir_name
 
3286
        self._supply_sub_formats_to(format)
 
3287
        bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
 
3288
        if repo_path:
 
3289
            repo_format = remote.response_tuple_to_repo_format(response[1:])
 
3290
            if repo_path == '.':
 
3291
                repo_path = ''
 
3292
            if repo_path:
 
3293
                repo_bzrdir_format = RemoteBzrDirFormat()
 
3294
                repo_bzrdir_format._network_name = response[5]
 
3295
                repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
 
3296
                    repo_bzrdir_format)
 
3297
            else:
 
3298
                repo_bzr = bzrdir
 
3299
            final_stack = response[8] or None
 
3300
            final_stack_pwd = response[9] or None
 
3301
            if final_stack_pwd:
 
3302
                final_stack_pwd = urlutils.join(
 
3303
                    transport.base, final_stack_pwd)
 
3304
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
 
3305
            if len(response) > 10:
 
3306
                # Updated server verb that locks remotely.
 
3307
                repo_lock_token = response[10] or None
 
3308
                remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
 
3309
                if repo_lock_token:
 
3310
                    remote_repo.dont_leave_lock_in_place()
 
3311
            else:
 
3312
                remote_repo.lock_write()
 
3313
            policy = UseExistingRepository(remote_repo, final_stack,
 
3314
                final_stack_pwd, require_stacking)
 
3315
            policy.acquire_repository()
 
3316
        else:
 
3317
            remote_repo = None
 
3318
            policy = None
 
3319
        bzrdir._format.set_branch_format(self.get_branch_format())
 
3320
        if require_stacking:
 
3321
            # The repo has already been created, but we need to make sure that
 
3322
            # we'll make a stackable branch.
 
3323
            bzrdir._format.require_stacking(_skip_repo=True)
 
3324
        return remote_repo, bzrdir, require_stacking, policy
2676
3325
 
2677
3326
    def _open(self, transport):
2678
 
        return remote.RemoteBzrDir(transport)
 
3327
        return remote.RemoteBzrDir(transport, self)
2679
3328
 
2680
3329
    def __eq__(self, other):
2681
3330
        if not isinstance(other, RemoteBzrDirFormat):
2682
3331
            return False
2683
3332
        return self.get_format_description() == other.get_format_description()
2684
3333
 
2685
 
    @property
2686
 
    def repository_format(self):
2687
 
        # Using a property to avoid early loading of remote
2688
 
        return remote.RemoteRepositoryFormat()
 
3334
    def __return_repository_format(self):
 
3335
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
 
3336
        # repository format has been asked for, tell the RemoteRepositoryFormat
 
3337
        # that it should use that for init() etc.
 
3338
        result = remote.RemoteRepositoryFormat()
 
3339
        custom_format = getattr(self, '_repository_format', None)
 
3340
        if custom_format:
 
3341
            if isinstance(custom_format, remote.RemoteRepositoryFormat):
 
3342
                return custom_format
 
3343
            else:
 
3344
                # We will use the custom format to create repositories over the
 
3345
                # wire; expose its details like rich_root_data for code to
 
3346
                # query
 
3347
                result._custom_format = custom_format
 
3348
        return result
 
3349
 
 
3350
    def get_branch_format(self):
 
3351
        result = BzrDirMetaFormat1.get_branch_format(self)
 
3352
        if not isinstance(result, remote.RemoteBranchFormat):
 
3353
            new_result = remote.RemoteBranchFormat()
 
3354
            new_result._custom_format = result
 
3355
            # cache the result
 
3356
            self.set_branch_format(new_result)
 
3357
            result = new_result
 
3358
        return result
 
3359
 
 
3360
    repository_format = property(__return_repository_format,
 
3361
        BzrDirMetaFormat1._set_repository_format) #.im_func)
2689
3362
 
2690
3363
 
2691
3364
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2702
3375
 
2703
3376
class BzrDirFormatRegistry(registry.Registry):
2704
3377
    """Registry of user-selectable BzrDir subformats.
2705
 
    
 
3378
 
2706
3379
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
2707
3380
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
2708
3381
    """
2727
3400
        """Register a metadir subformat.
2728
3401
 
2729
3402
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
2730
 
        by the Repository format.
 
3403
        by the Repository/Branch/WorkingTreeformats.
2731
3404
 
2732
3405
        :param repository_format: The fully-qualified repository format class
2733
3406
            name as a string.
2767
3440
    def register(self, key, factory, help, native=True, deprecated=False,
2768
3441
                 hidden=False, experimental=False, alias=False):
2769
3442
        """Register a BzrDirFormat factory.
2770
 
        
 
3443
 
2771
3444
        The factory must be a callable that takes one parameter: the key.
2772
3445
        It must produce an instance of the BzrDirFormat when called.
2773
3446
 
2790
3463
 
2791
3464
    def set_default(self, key):
2792
3465
        """Set the 'default' key to be a clone of the supplied key.
2793
 
        
 
3466
 
2794
3467
        This method must be called once and only once.
2795
3468
        """
2796
3469
        registry.Registry.register(self, 'default', self.get(key),
2799
3472
 
2800
3473
    def set_default_repository(self, key):
2801
3474
        """Set the FormatRegistry default and Repository default.
2802
 
        
 
3475
 
2803
3476
        This is a transitional method while Repository.set_default_format
2804
3477
        is deprecated.
2805
3478
        """
2828
3501
        def wrapped(key, help, info):
2829
3502
            if info.native:
2830
3503
                help = '(native) ' + help
2831
 
            return ':%s:\n%s\n\n' % (key, 
2832
 
                    textwrap.fill(help, initial_indent='    ', 
2833
 
                    subsequent_indent='    '))
 
3504
            return ':%s:\n%s\n\n' % (key,
 
3505
                textwrap.fill(help, initial_indent='    ',
 
3506
                    subsequent_indent='    ',
 
3507
                    break_long_words=False))
2834
3508
        if default_realkey is not None:
2835
3509
            output += wrapped(default_realkey, '(default) %s' % default_help,
2836
3510
                              self.get_info('default'))
2846
3520
                experimental_pairs.append((key, help))
2847
3521
            else:
2848
3522
                output += wrapped(key, help, info)
2849
 
        output += "\nSee ``bzr help formats`` for more about storage formats."
 
3523
        output += "\nSee :doc:`formats-help` for more about storage formats."
2850
3524
        other_output = ""
2851
3525
        if len(experimental_pairs) > 0:
2852
3526
            other_output += "Experimental formats are shown below.\n\n"
2865
3539
            other_output += \
2866
3540
                "\nNo deprecated formats are available.\n\n"
2867
3541
        other_output += \
2868
 
            "\nSee ``bzr help formats`` for more about storage formats."
 
3542
                "\nSee :doc:`formats-help` for more about storage formats."
2869
3543
 
2870
3544
        if topic == 'other-formats':
2871
3545
            return other_output
2910
3584
                stack_on = self._get_full_stack_on()
2911
3585
        try:
2912
3586
            branch.set_stacked_on_url(stack_on)
2913
 
        except errors.UnstackableBranchFormat:
 
3587
        except (errors.UnstackableBranchFormat,
 
3588
                errors.UnstackableRepositoryFormat):
2914
3589
            if self._require_stacking:
2915
3590
                raise
2916
3591
 
 
3592
    def requires_stacking(self):
 
3593
        """Return True if this policy requires stacking."""
 
3594
        return self._stack_on is not None and self._require_stacking
 
3595
 
2917
3596
    def _get_full_stack_on(self):
2918
3597
        """Get a fully-qualified URL for the stack_on location."""
2919
3598
        if self._stack_on is None:
2928
3607
        stack_on = self._get_full_stack_on()
2929
3608
        if stack_on is None:
2930
3609
            return
2931
 
        stacked_dir = BzrDir.open(stack_on,
2932
 
                                  possible_transports=possible_transports)
 
3610
        try:
 
3611
            stacked_dir = BzrDir.open(stack_on,
 
3612
                                      possible_transports=possible_transports)
 
3613
        except errors.JailBreak:
 
3614
            # We keep the stacking details, but we are in the server code so
 
3615
            # actually stacking is not needed.
 
3616
            return
2933
3617
        try:
2934
3618
            stacked_repo = stacked_dir.open_branch().repository
2935
3619
        except errors.NotBranchError:
2950
3634
        :param make_working_trees: If creating a repository, set
2951
3635
            make_working_trees to this value (if non-None)
2952
3636
        :param shared: If creating a repository, make it shared if True
2953
 
        :return: A repository
 
3637
        :return: A repository, is_new_flag (True if the repository was
 
3638
            created).
2954
3639
        """
2955
3640
        raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
2956
3641
 
2976
3661
 
2977
3662
        Creates the desired repository in the bzrdir we already have.
2978
3663
        """
 
3664
        stack_on = self._get_full_stack_on()
 
3665
        if stack_on:
 
3666
            format = self._bzrdir._format
 
3667
            format.require_stacking(stack_on=stack_on,
 
3668
                                    possible_transports=[self._bzrdir.root_transport])
 
3669
            if not self._require_stacking:
 
3670
                # We have picked up automatic stacking somewhere.
 
3671
                note('Using default stacking branch %s at %s', self._stack_on,
 
3672
                    self._stack_on_pwd)
2979
3673
        repository = self._bzrdir.create_repository(shared=shared)
2980
3674
        self._add_fallback(repository,
2981
3675
                           possible_transports=[self._bzrdir.transport])
2982
3676
        if make_working_trees is not None:
2983
3677
            repository.set_make_working_trees(make_working_trees)
2984
 
        return repository
 
3678
        return repository, True
2985
3679
 
2986
3680
 
2987
3681
class UseExistingRepository(RepositoryAcquisitionPolicy):
3003
3697
    def acquire_repository(self, make_working_trees=None, shared=False):
3004
3698
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
3005
3699
 
3006
 
        Returns an existing repository to use
 
3700
        Returns an existing repository to use.
3007
3701
        """
3008
3702
        self._add_fallback(self._repository,
3009
3703
                       possible_transports=[self._repository.bzrdir.transport])
3010
 
        return self._repository
 
3704
        return self._repository, False
3011
3705
 
3012
3706
 
3013
3707
# Please register new formats after old formats so that formats
3014
3708
# appear in chronological order and format descriptions can build
3015
3709
# on previous ones.
3016
3710
format_registry = BzrDirFormatRegistry()
 
3711
# The pre-0.8 formats have their repository format network name registered in
 
3712
# repository.py. MetaDir formats have their repository format network name
 
3713
# inferred from their disk format string.
3017
3714
format_registry.register('weave', BzrDirFormat6,
3018
3715
    'Pre-0.8 format.  Slower than knit and does not'
3019
3716
    ' support checkouts or shared repositories.',
3091
3788
format_registry.register_metadir('rich-root-pack',
3092
3789
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3093
3790
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3094
 
         '(needed for bzr-svn).',
 
3791
         '(needed for bzr-svn and bzr-git).',
3095
3792
    branch_format='bzrlib.branch.BzrBranchFormat6',
3096
3793
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3097
3794
    )
3106
3803
format_registry.register_metadir('1.6.1-rich-root',
3107
3804
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3108
3805
    help='A variant of 1.6 that supports rich-root data '
3109
 
         '(needed for bzr-svn).',
 
3806
         '(needed for bzr-svn and bzr-git).',
3110
3807
    branch_format='bzrlib.branch.BzrBranchFormat7',
3111
3808
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3112
3809
    )
3121
3818
format_registry.register_metadir('1.9-rich-root',
3122
3819
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3123
3820
    help='A variant of 1.9 that supports rich-root data '
3124
 
         '(needed for bzr-svn).',
 
3821
         '(needed for bzr-svn and bzr-git).',
3125
3822
    branch_format='bzrlib.branch.BzrBranchFormat7',
3126
3823
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3127
3824
    )
3128
 
format_registry.register_metadir('development-wt5',
 
3825
format_registry.register_metadir('1.14',
3129
3826
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3130
 
    help='A working-tree format that supports views and content filtering.',
 
3827
    help='A working-tree format that supports content filtering.',
3131
3828
    branch_format='bzrlib.branch.BzrBranchFormat7',
3132
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
3133
 
    experimental=True,
 
3829
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3134
3830
    )
3135
 
format_registry.register_metadir('development-wt5-rich-root',
 
3831
format_registry.register_metadir('1.14-rich-root',
3136
3832
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3137
 
    help='A variant of development-wt5 that supports rich-root data '
3138
 
         '(needed for bzr-svn).',
 
3833
    help='A variant of 1.14 that supports rich-root data '
 
3834
         '(needed for bzr-svn and bzr-git).',
3139
3835
    branch_format='bzrlib.branch.BzrBranchFormat7',
3140
 
    tree_format='bzrlib.workingtree_4.WorkingTreeFormat5',
3141
 
    experimental=True,
 
3836
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3142
3837
    )
3143
 
# The following two formats should always just be aliases.
3144
 
format_registry.register_metadir('development',
3145
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3146
 
    help='Current development format. Can convert data to and from pack-0.92 '
3147
 
        '(and anything compatible with pack-0.92) format repositories. '
3148
 
        'Repositories and branches in this format can only be read by bzr.dev. '
3149
 
        'Please read '
 
3838
# The following un-numbered 'development' formats should always just be aliases.
 
3839
format_registry.register_metadir('development-rich-root',
 
3840
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
 
3841
    help='Current development format. Supports rich roots. Can convert data '
 
3842
        'to and from rich-root-pack (and anything compatible with '
 
3843
        'rich-root-pack) format repositories. Repositories and branches in '
 
3844
        'this format can only be read by bzr.dev. Please read '
3150
3845
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3151
3846
        'before use.',
3152
3847
    branch_format='bzrlib.branch.BzrBranchFormat7',
3153
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3848
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3154
3849
    experimental=True,
3155
3850
    alias=True,
3156
3851
    )
3163
3858
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3164
3859
        'before use.',
3165
3860
    branch_format='bzrlib.branch.BzrBranchFormat7',
3166
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3861
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3167
3862
    experimental=True,
3168
 
    alias=True,
 
3863
    alias=False, # Restore to being an alias when an actual development subtree format is added
 
3864
                 # This current non-alias status is simply because we did not introduce a
 
3865
                 # chk based subtree format.
3169
3866
    )
 
3867
 
3170
3868
# And the development formats above will have aliased one of the following:
3171
 
format_registry.register_metadir('development2',
3172
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3173
 
    help='1.6.1 with B+Tree based index. '
3174
 
        'Please read '
3175
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3176
 
        'before use.',
3177
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3178
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3179
 
    hidden=True,
3180
 
    experimental=True,
3181
 
    )
3182
 
format_registry.register_metadir('development2-subtree',
3183
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3184
 
    help='1.6.1-subtree with B+Tree based index. '
3185
 
        'Please read '
3186
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3187
 
        'before use.',
3188
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3189
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3190
 
    hidden=True,
3191
 
    experimental=True,
3192
 
    )
 
3869
format_registry.register_metadir('development6-rich-root',
 
3870
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
 
3871
    help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
 
3872
        'Please read '
 
3873
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3874
        'before use.',
 
3875
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3876
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3877
    hidden=True,
 
3878
    experimental=True,
 
3879
    )
 
3880
 
 
3881
format_registry.register_metadir('development7-rich-root',
 
3882
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
 
3883
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
 
3884
        'rich roots. Please read '
 
3885
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3886
        'before use.',
 
3887
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3888
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3889
    hidden=True,
 
3890
    experimental=True,
 
3891
    )
 
3892
 
 
3893
format_registry.register_metadir('2a',
 
3894
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
3895
    help='First format for bzr 2.0 series.\n'
 
3896
        'Uses group-compress storage.\n'
 
3897
        'Provides rich roots which are a one-way transition.\n',
 
3898
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
 
3899
        # 'rich roots. Supported by bzr 1.16 and later.',
 
3900
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3901
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3902
    experimental=True,
 
3903
    )
 
3904
 
 
3905
# The following format should be an alias for the rich root equivalent 
 
3906
# of the default format
 
3907
format_registry.register_metadir('default-rich-root',
 
3908
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
3909
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3910
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3911
    alias=True,
 
3912
    help='Same as 2a.')
 
3913
 
3193
3914
# The current format that is made on 'bzr init'.
3194
 
format_registry.set_default('pack-0.92')
 
3915
format_registry.set_default('2a')