~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2008-10-20 23:58:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3787.
  • Revision ID: mbp@sourcefrog.net-20081020235812-itg90mk0u4dez92z
lp-upload-release now handles names like bzr-1.8.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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,
41
40
    config,
42
41
    errors,
43
42
    graph,
45
44
    lockdir,
46
45
    osutils,
47
46
    remote,
48
 
    repository,
49
47
    revision as _mod_revision,
50
48
    ui,
51
49
    urlutils,
59
57
from bzrlib.osutils import (
60
58
    sha_string,
61
59
    )
62
 
from bzrlib.push import (
63
 
    PushResult,
64
 
    )
65
 
from bzrlib.repofmt import pack_repo
66
60
from bzrlib.smart.client import _SmartClient
67
61
from bzrlib.store.versioned import WeaveStore
68
62
from bzrlib.transactions import WriteTransaction
77
71
from bzrlib.trace import (
78
72
    mutter,
79
73
    note,
80
 
    warning,
81
74
    )
82
75
 
83
76
from bzrlib import (
84
 
    hooks,
85
77
    registry,
86
78
    symbol_versioning,
87
79
    )
89
81
 
90
82
class BzrDir(object):
91
83
    """A .bzr control diretory.
92
 
 
 
84
    
93
85
    BzrDir instances let you create or open any of the things that can be
94
86
    found within .bzr - checkouts, branches and repositories.
95
 
 
 
87
    
96
88
    :ivar transport:
97
89
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
98
90
    :ivar root_transport:
100
92
        (i.e. the parent directory holding the .bzr directory).
101
93
 
102
94
    Everything in the bzrdir should have the same file permissions.
103
 
 
104
 
    :cvar hooks: An instance of BzrDirHooks.
105
95
    """
106
96
 
107
97
    def break_lock(self):
129
119
        return True
130
120
 
131
121
    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.
135
122
        target_repo_format = target_format.repository_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
 
123
        source_repo_format = self._format.repository_format
 
124
        source_repo_format.check_conversion_target(target_repo_format)
142
125
 
143
126
    @staticmethod
144
127
    def _check_supported(format, allow_unsupported,
146
129
        basedir=None):
147
130
        """Give an error or warning on old formats.
148
131
 
149
 
        :param format: may be any kind of format - workingtree, branch,
 
132
        :param format: may be any kind of format - workingtree, branch, 
150
133
        or repository.
151
134
 
152
 
        :param allow_unsupported: If true, allow opening
153
 
        formats that are strongly deprecated, and which may
 
135
        :param allow_unsupported: If true, allow opening 
 
136
        formats that are strongly deprecated, and which may 
154
137
        have limited functionality.
155
138
 
156
139
        :param recommend_upgrade: If true (default), warn
188
171
                                       preserve_stacking=preserve_stacking)
189
172
 
190
173
    def clone_on_transport(self, transport, revision_id=None,
191
 
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
192
 
        create_prefix=False, use_existing_dir=True):
 
174
                           force_new_repo=False, preserve_stacking=False,
 
175
                           stacked_on=None):
193
176
        """Clone this bzrdir and its contents to transport verbatim.
194
177
 
195
178
        :param transport: The transport for the location to produce the clone
201
184
                               even if one is available.
202
185
        :param preserve_stacking: When cloning a stacked branch, stack the
203
186
            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.
207
187
        """
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:
 
188
        transport.ensure_base()
213
189
        require_stacking = (stacked_on is not None)
214
 
        format = self.cloning_metadir(require_stacking)
215
 
        
216
 
        # Figure out what objects we want:
 
190
        metadir = self.cloning_metadir(require_stacking)
 
191
        result = metadir.initialize_on_transport(transport)
 
192
        repository_policy = None
217
193
        try:
218
194
            local_repo = self.find_repository()
219
195
        except errors.NoRepositoryPresent:
233
209
                        errors.UnstackableRepositoryFormat,
234
210
                        errors.NotStacked):
235
211
                    pass
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.
 
212
 
239
213
        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)
240
218
            make_working_trees = local_repo.make_working_trees()
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)
 
219
            result_repo = repository_policy.acquire_repository(
 
220
                make_working_trees, local_repo.is_shared())
 
221
            result_repo.fetch(local_repo, revision_id=revision_id)
 
222
        else:
 
223
            result_repo = None
276
224
        # 1 if there is a branch present
277
225
        #   make sure its content is available in the target repository
278
226
        #   clone it.
279
227
        if local_branch is not None:
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():
 
228
            result_branch = local_branch.clone(result, revision_id=revision_id)
 
229
            if repository_policy is not None:
 
230
                repository_policy.configure_branch(result_branch)
 
231
        if result_repo is None or result_repo.make_working_trees():
 
232
            try:
287
233
                self.open_workingtree().clone(result)
288
 
        except (errors.NoWorkingTree, errors.NotLocalUrl):
289
 
            pass
 
234
            except (errors.NoWorkingTree, errors.NotLocalUrl):
 
235
                pass
290
236
        return result
291
237
 
292
238
    # TODO: This should be given a Transport, and should chdir up; otherwise
298
244
    @classmethod
299
245
    def create(cls, base, format=None, possible_transports=None):
300
246
        """Create a new BzrDir at the url 'base'.
301
 
 
 
247
        
302
248
        :param format: If supplied, the format of branch to create.  If not
303
249
            supplied, the default is used.
304
 
        :param possible_transports: If supplied, a list of transports that
 
250
        :param possible_transports: If supplied, a list of transports that 
305
251
            can be reused to share a remote connection.
306
252
        """
307
253
        if cls is not BzrDir:
407
353
        """Create a new BzrDir, Branch and Repository at the url 'base'.
408
354
 
409
355
        This will use the current default BzrDirFormat unless one is
410
 
        specified, and use whatever
 
356
        specified, and use whatever 
411
357
        repository format that that uses via bzrdir.create_branch and
412
358
        create_repository. If a shared repository is available that is used
413
359
        preferentially.
427
373
                                    stack_on_pwd=None, require_stacking=False):
428
374
        """Return an object representing a policy to use.
429
375
 
430
 
        This controls whether a new repository is created, and the format of
431
 
        that repository, or some existing shared repository used instead.
 
376
        This controls whether a new repository is created, or a shared
 
377
        repository used instead.
432
378
 
433
379
        If stack_on is supplied, will not seek a containing shared repo.
434
380
 
443
389
            stack_on_pwd = None
444
390
            config = found_bzrdir.get_config()
445
391
            stop = False
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
 
392
            if config is not None:
 
393
                stack_on = config.get_default_stack_on()
 
394
                if stack_on is not None:
 
395
                    stack_on_pwd = found_bzrdir.root_transport.base
 
396
                    stop = True
 
397
                    note('Using default stacking branch %s at %s', stack_on,
 
398
                         stack_on_pwd)
450
399
            # does it have a repository ?
451
400
            try:
452
401
                repository = found_bzrdir.open_repository()
455
404
            else:
456
405
                if ((found_bzrdir.root_transport.base !=
457
406
                     self.root_transport.base) and not repository.is_shared()):
458
 
                    # Don't look higher, can't use a higher shared repo.
459
407
                    repository = None
460
 
                    stop = True
461
408
                else:
462
409
                    stop = True
463
410
            if not stop:
487
434
    def _find_or_create_repository(self, force_new_repo):
488
435
        """Create a new repository if needed, returning the repository."""
489
436
        policy = self.determine_repository_policy(force_new_repo)
490
 
        return policy.acquire_repository()[0]
 
437
        return policy.acquire_repository()
491
438
 
492
439
    @staticmethod
493
440
    def create_branch_convenience(base, force_new_repo=False,
500
447
        not.
501
448
 
502
449
        This will use the current default BzrDirFormat unless one is
503
 
        specified, and use whatever
 
450
        specified, and use whatever 
504
451
        repository format that that uses via bzrdir.create_branch and
505
452
        create_repository. If a shared repository is available that is used
506
453
        preferentially. Whatever repository is used, its tree creation policy
508
455
 
509
456
        The created Branch object is returned.
510
457
        If a working tree cannot be made due to base not being a file:// url,
511
 
        no error is raised unless force_new_tree is True, in which case no
 
458
        no error is raised unless force_new_tree is True, in which case no 
512
459
        data is created on disk and NotLocalUrl is raised.
513
460
 
514
461
        :param base: The URL to create the branch at.
515
462
        :param force_new_repo: If True a new repository is always created.
516
 
        :param force_new_tree: If True or False force creation of a tree or
 
463
        :param force_new_tree: If True or False force creation of a tree or 
517
464
                               prevent such creation respectively.
518
465
        :param format: Override for the bzrdir format to create.
519
466
        :param possible_transports: An optional reusable transports list.
541
488
        'base' must be a local path or a file:// url.
542
489
 
543
490
        This will use the current default BzrDirFormat unless one is
544
 
        specified, and use whatever
 
491
        specified, and use whatever 
545
492
        repository format that that uses for bzrdirformat.create_workingtree,
546
493
        create_branch and create_repository.
547
494
 
559
506
    def create_workingtree(self, revision_id=None, from_branch=None,
560
507
        accelerator_tree=None, hardlink=False):
561
508
        """Create a working tree at this BzrDir.
562
 
 
 
509
        
563
510
        :param revision_id: create it as of this revision id.
564
511
        :param from_branch: override bzrdir branch (for lightweight checkouts)
565
512
        :param accelerator_tree: A tree which can be used for retrieving file
569
516
        """
570
517
        raise NotImplementedError(self.create_workingtree)
571
518
 
572
 
    def backup_bzrdir(self):
573
 
        """Backup this bzr control directory.
574
 
 
575
 
        :return: Tuple with old path name and new path name
576
 
        """
577
 
        pb = ui.ui_factory.nested_progress_bar()
578
 
        try:
579
 
            # FIXME: bug 300001 -- the backup fails if the backup directory
580
 
            # already exists, but it should instead either remove it or make
581
 
            # a new backup directory.
582
 
            #
583
 
            # FIXME: bug 262450 -- the backup directory should have the same
584
 
            # permissions as the .bzr directory (probably a bug in copy_tree)
585
 
            old_path = self.root_transport.abspath('.bzr')
586
 
            new_path = self.root_transport.abspath('backup.bzr')
587
 
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
588
 
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
589
 
            return (old_path, new_path)
590
 
        finally:
591
 
            pb.finished()
592
 
 
593
519
    def retire_bzrdir(self, limit=10000):
594
520
        """Permanently disable the bzrdir.
595
521
 
700
626
        IncompatibleFormat if the branch format they are given has
701
627
        a format string, and vice versa.
702
628
 
703
 
        If branch_format is None, the transport is returned with no
 
629
        If branch_format is None, the transport is returned with no 
704
630
        checking. If it is not None, then the returned transport is
705
631
        guaranteed to point to an existing directory ready for use.
706
632
        """
749
675
        if not self._mode_check_done:
750
676
            self._find_creation_modes()
751
677
        return self._dir_mode
752
 
 
 
678
        
753
679
    def get_repository_transport(self, repository_format):
754
680
        """Get the transport for use by repository format in this BzrDir.
755
681
 
757
683
        IncompatibleFormat if the repository format they are given has
758
684
        a format string, and vice versa.
759
685
 
760
 
        If repository_format is None, the transport is returned with no
 
686
        If repository_format is None, the transport is returned with no 
761
687
        checking. If it is not None, then the returned transport is
762
688
        guaranteed to point to an existing directory ready for use.
763
689
        """
764
690
        raise NotImplementedError(self.get_repository_transport)
765
 
 
 
691
        
766
692
    def get_workingtree_transport(self, tree_format):
767
693
        """Get the transport for use by workingtree format in this BzrDir.
768
694
 
770
696
        IncompatibleFormat if the workingtree format they are given has a
771
697
        format string, and vice versa.
772
698
 
773
 
        If workingtree_format is None, the transport is returned with no
 
699
        If workingtree_format is None, the transport is returned with no 
774
700
        checking. If it is not None, then the returned transport is
775
701
        guaranteed to point to an existing directory ready for use.
776
702
        """
777
703
        raise NotImplementedError(self.get_workingtree_transport)
778
704
 
779
705
    def get_config(self):
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
 
706
        if getattr(self, '_get_config', None) is None:
 
707
            return None
 
708
        return self._get_config()
786
709
 
787
710
    def __init__(self, _transport, _format):
788
711
        """Initialize a Bzr control dir object.
789
 
 
 
712
        
790
713
        Only really common logic should reside here, concrete classes should be
791
714
        made with varying behaviours.
792
715
 
800
723
 
801
724
    def is_control_filename(self, filename):
802
725
        """True if filename is the name of a path which is reserved for bzrdir's.
803
 
 
 
726
        
804
727
        :param filename: A filename within the root transport of this bzrdir.
805
728
 
806
729
        This is true IF and ONLY IF the filename is part of the namespace reserved
809
732
        this in the future - for instance to make bzr talk with svn working
810
733
        trees.
811
734
        """
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-
 
735
        # this might be better on the BzrDirFormat class because it refers to 
 
736
        # all the possible bzrdir disk formats. 
 
737
        # This method is tested via the workingtree is_control_filename tests- 
815
738
        # it was extracted from WorkingTree.is_control_filename. If the method's
816
739
        # contract is extended beyond the current trivial implementation, please
817
740
        # add new tests for it to the appropriate place.
819
742
 
820
743
    def needs_format_conversion(self, format=None):
821
744
        """Return true if this bzrdir needs convert_format run on it.
822
 
 
823
 
        For instance, if the repository format is out of date but the
 
745
        
 
746
        For instance, if the repository format is out of date but the 
824
747
        branch and working tree are not, this should return True.
825
748
 
826
749
        :param format: Optional parameter indicating a specific desired
832
755
    def open_unsupported(base):
833
756
        """Open a branch which is not supported."""
834
757
        return BzrDir.open(base, _unsupported=True)
835
 
 
 
758
        
836
759
    @staticmethod
837
760
    def open(base, _unsupported=False, possible_transports=None):
838
761
        """Open an existing bzrdir, rooted at 'base' (url).
839
 
 
 
762
        
840
763
        :param _unsupported: a private parameter to the BzrDir class.
841
764
        """
842
765
        t = get_transport(base, possible_transports=possible_transports)
850
773
        :param transport: Transport containing the bzrdir.
851
774
        :param _unsupported: private.
852
775
        """
853
 
        for hook in BzrDir.hooks['pre_open']:
854
 
            hook(transport)
855
 
        # Keep initial base since 'transport' may be modified while following
856
 
        # the redirections.
857
776
        base = transport.base
 
777
 
858
778
        def find_format(transport):
859
779
            return transport, BzrDirFormat.find_format(
860
780
                transport, _server_formats=_server_formats)
861
781
 
862
782
        def redirected(transport, e, redirection_notice):
863
 
            redirected_transport = transport._redirected_to(e.source, e.target)
864
 
            if redirected_transport is None:
865
 
                raise errors.NotBranchError(base)
 
783
            qualified_source = e.get_source_url()
 
784
            relpath = transport.relpath(qualified_source)
 
785
            if not e.target.endswith(relpath):
 
786
                # Not redirected to a branch-format, not a branch
 
787
                raise errors.NotBranchError(path=e.target)
 
788
            target = e.target[:-len(relpath)]
866
789
            note('%s is%s redirected to %s',
867
 
                 transport.base, e.permanently, redirected_transport.base)
868
 
            return redirected_transport
 
790
                 transport.base, e.permanently, target)
 
791
            # Let's try with a new transport
 
792
            # FIXME: If 'transport' has a qualifier, this should
 
793
            # be applied again to the new transport *iff* the
 
794
            # schemes used are the same. Uncomment this code
 
795
            # once the function (and tests) exist.
 
796
            # -- vila20070212
 
797
            #target = urlutils.copy_url_qualifiers(original, target)
 
798
            return get_transport(target)
869
799
 
870
800
        try:
871
801
            transport, format = do_catching_redirections(find_format,
877
807
        BzrDir._check_supported(format, _unsupported)
878
808
        return format.open(transport, _found=True)
879
809
 
880
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
810
    def open_branch(self, unsupported=False):
881
811
        """Open the branch object at this BzrDir if one is present.
882
812
 
883
813
        If unsupported is True, then no longer supported branch formats can
884
814
        still be opened.
885
 
 
 
815
        
886
816
        TODO: static convenience version of this?
887
817
        """
888
818
        raise NotImplementedError(self.open_branch)
890
820
    @staticmethod
891
821
    def open_containing(url, possible_transports=None):
892
822
        """Open an existing branch which contains url.
893
 
 
 
823
        
894
824
        :param url: url to search from.
895
825
        See open_containing_from_transport for more detail.
896
826
        """
897
827
        transport = get_transport(url, possible_transports)
898
828
        return BzrDir.open_containing_from_transport(transport)
899
 
 
 
829
    
900
830
    @staticmethod
901
831
    def open_containing_from_transport(a_transport):
902
832
        """Open an existing branch which contains a_transport.base.
905
835
 
906
836
        Basically we keep looking up until we find the control directory or
907
837
        run into the root.  If there isn't one, raises NotBranchError.
908
 
        If there is one and it is either an unrecognised format or an unsupported
 
838
        If there is one and it is either an unrecognised format or an unsupported 
909
839
        format, UnknownFormatError or UnsupportedFormatError are raised.
910
840
        If there is one, it is returned, along with the unused portion of url.
911
841
 
912
 
        :return: The BzrDir that contains the path, and a Unicode path
 
842
        :return: The BzrDir that contains the path, and a Unicode path 
913
843
                for the rest of the URL.
914
844
        """
915
845
        # this gets the normalised url back. I.e. '.' -> the full path.
1023
953
 
1024
954
    def has_branch(self):
1025
955
        """Tell if this bzrdir contains a branch.
1026
 
 
 
956
        
1027
957
        Note: if you're going to open the branch, you should just go ahead
1028
 
        and try, and not ask permission first.  (This method just opens the
1029
 
        branch and discards it, and that's somewhat expensive.)
 
958
        and try, and not ask permission first.  (This method just opens the 
 
959
        branch and discards it, and that's somewhat expensive.) 
1030
960
        """
1031
961
        try:
1032
962
            self.open_branch()
1039
969
 
1040
970
        This will still raise an exception if the bzrdir has a workingtree that
1041
971
        is remote & inaccessible.
1042
 
 
 
972
        
1043
973
        Note: if you're going to open the working tree, you should just go ahead
1044
 
        and try, and not ask permission first.  (This method just opens the
1045
 
        workingtree and discards it, and that's somewhat expensive.)
 
974
        and try, and not ask permission first.  (This method just opens the 
 
975
        workingtree and discards it, and that's somewhat expensive.) 
1046
976
        """
1047
977
        try:
1048
978
            self.open_workingtree(recommend_upgrade=False)
1052
982
 
1053
983
    def _cloning_metadir(self):
1054
984
        """Produce a metadir suitable for cloning with.
1055
 
 
 
985
        
1056
986
        :returns: (destination_bzrdir_format, source_repository)
1057
987
        """
1058
988
        result_format = self._format.__class__()
1059
989
        try:
1060
990
            try:
1061
 
                branch = self.open_branch(ignore_fallbacks=True)
 
991
                branch = self.open_branch()
1062
992
                source_repository = branch.repository
1063
993
                result_format._branch_format = branch._format
1064
994
            except errors.NotBranchError:
1101
1031
        """
1102
1032
        format, repository = self._cloning_metadir()
1103
1033
        if format._workingtree_format is None:
1104
 
            # No tree in self.
1105
1034
            if repository is None:
1106
 
                # No repository either
1107
1035
                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).
1110
1036
            tree_format = repository._format._matchingbzrdir.workingtree_format
1111
1037
            format.workingtree_format = tree_format.__class__()
1112
 
        if require_stacking:
1113
 
            format.require_stacking()
 
1038
        if (require_stacking and not
 
1039
            format.get_branch_format().supports_stacking()):
 
1040
            # We need to make a stacked branch, but the default format for the
 
1041
            # target doesn't support stacking.  So force a branch that *can*
 
1042
            # support stacking.
 
1043
            from bzrlib.branch import BzrBranchFormat7
 
1044
            format._branch_format = BzrBranchFormat7()
 
1045
            mutter("using %r for stacking" % (format._branch_format,))
 
1046
            from bzrlib.repofmt import pack_repo
 
1047
            if format.repository_format.rich_root_data:
 
1048
                bzrdir_format_name = '1.6.1-rich-root'
 
1049
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
1050
            else:
 
1051
                bzrdir_format_name = '1.6'
 
1052
                repo_format = pack_repo.RepositoryFormatKnitPack5()
 
1053
            note('Source format does not support stacking, using format:'
 
1054
                 ' \'%s\'\n  %s\n',
 
1055
                 bzrdir_format_name, repo_format.get_format_description())
 
1056
            format.repository_format = repo_format
1114
1057
        return format
1115
1058
 
1116
1059
    def checkout_metadir(self):
1118
1061
 
1119
1062
    def sprout(self, url, revision_id=None, force_new_repo=False,
1120
1063
               recurse='down', possible_transports=None,
1121
 
               accelerator_tree=None, hardlink=False, stacked=False,
1122
 
               source_branch=None, create_tree_if_local=True):
 
1064
               accelerator_tree=None, hardlink=False, stacked=False):
1123
1065
        """Create a copy of this bzrdir prepared for use as a new line of
1124
1066
        development.
1125
1067
 
1140
1082
            where possible.
1141
1083
        :param stacked: If true, create a stacked branch referring to the
1142
1084
            location of this control directory.
1143
 
        :param create_tree_if_local: If true, a working-tree will be created
1144
 
            when working locally.
1145
1085
        """
1146
1086
        target_transport = get_transport(url, possible_transports)
1147
1087
        target_transport.ensure_base()
1148
1088
        cloning_format = self.cloning_metadir(stacked)
1149
1089
        # Create/update the result branch
1150
1090
        result = cloning_format.initialize_on_transport(target_transport)
1151
 
        # if a stacked branch wasn't requested, we don't create one
1152
 
        # even if the origin was stacked
1153
 
        stacked_branch_url = None
1154
 
        if source_branch is not None:
 
1091
        try:
 
1092
            source_branch = self.open_branch()
 
1093
            source_repository = source_branch.repository
1155
1094
            if stacked:
1156
1095
                stacked_branch_url = self.root_transport.base
1157
 
            source_repository = source_branch.repository
1158
 
        else:
 
1096
            else:
 
1097
                # if a stacked branch wasn't requested, we don't create one
 
1098
                # even if the origin was stacked
 
1099
                stacked_branch_url = None
 
1100
        except errors.NotBranchError:
 
1101
            source_branch = None
1159
1102
            try:
1160
 
                source_branch = self.open_branch()
1161
 
                source_repository = source_branch.repository
1162
 
                if stacked:
1163
 
                    stacked_branch_url = self.root_transport.base
1164
 
            except errors.NotBranchError:
1165
 
                source_branch = None
1166
 
                try:
1167
 
                    source_repository = self.open_repository()
1168
 
                except errors.NoRepositoryPresent:
1169
 
                    source_repository = None
 
1103
                source_repository = self.open_repository()
 
1104
            except errors.NoRepositoryPresent:
 
1105
                source_repository = None
 
1106
            stacked_branch_url = None
1170
1107
        repository_policy = result.determine_repository_policy(
1171
1108
            force_new_repo, stacked_branch_url, require_stacking=stacked)
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
 
1109
        result_repo = repository_policy.acquire_repository()
1178
1110
        if source_repository is not None:
1179
1111
            # Fetch while stacked to prevent unstacked fetch from
1180
1112
            # Branch.sprout.
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)
 
1113
            result_repo.fetch(source_repository, revision_id=revision_id)
1185
1114
 
1186
1115
        if source_branch is None:
1187
1116
            # this is for sprouting a bzrdir without a branch; is that
1189
1118
            # Not especially, but it's part of the contract.
1190
1119
            result_branch = result.create_branch()
1191
1120
        else:
1192
 
            result_branch = source_branch.sprout(result,
1193
 
                revision_id=revision_id, repository_policy=repository_policy)
 
1121
            # Force NULL revision to avoid using repository before stacking
 
1122
            # is configured.
 
1123
            result_branch = source_branch.sprout(
 
1124
                result, revision_id=_mod_revision.NULL_REVISION)
 
1125
            parent_location = result_branch.get_parent()
1194
1126
        mutter("created new branch %r" % (result_branch,))
 
1127
        repository_policy.configure_branch(result_branch)
 
1128
        if source_branch is not None:
 
1129
            source_branch.copy_content_into(result_branch, revision_id)
 
1130
            # Override copy_content_into
 
1131
            result_branch.set_parent(parent_location)
1195
1132
 
1196
1133
        # Create/update the result working tree
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())):
 
1134
        if isinstance(target_transport, local.LocalTransport) and (
 
1135
            result_repo is None or result_repo.make_working_trees()):
1200
1136
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1201
1137
                hardlink=hardlink)
1202
1138
            wt.lock_write()
1239
1175
                    basis.unlock()
1240
1176
        return result
1241
1177
 
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
 
 
1316
1178
 
1317
1179
class BzrDirPreSplitOut(BzrDir):
1318
1180
    """A common class for the all-in-one formats."""
1389
1251
        # and that will have set it for us, its only
1390
1252
        # specific uses of create_workingtree in isolation
1391
1253
        # that can do wonky stuff here, and that only
1392
 
        # happens for creating checkouts, which cannot be
 
1254
        # happens for creating checkouts, which cannot be 
1393
1255
        # done on this format anyway. So - acceptable wart.
1394
 
        if hardlink:
1395
 
            warning("can't support hardlinked working trees in %r"
1396
 
                % (self,))
1397
1256
        try:
1398
1257
            result = self.open_workingtree(recommend_upgrade=False)
1399
1258
        except errors.NoSuchFile:
1421
1280
 
1422
1281
    def destroy_workingtree_metadata(self):
1423
1282
        """See BzrDir.destroy_workingtree_metadata."""
1424
 
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
 
1283
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata, 
1425
1284
                                          self)
1426
1285
 
1427
1286
    def get_branch_transport(self, branch_format):
1459
1318
        # if the format is not the same as the system default,
1460
1319
        # an upgrade is needed.
1461
1320
        if format is None:
1462
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1463
 
                % 'needs_format_conversion(format=None)')
1464
1321
            format = BzrDirFormat.get_default_format()
1465
1322
        return not isinstance(self._format, format.__class__)
1466
1323
 
1467
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
1324
    def open_branch(self, unsupported=False):
1468
1325
        """See BzrDir.open_branch."""
1469
1326
        from bzrlib.branch import BzrBranchFormat4
1470
1327
        format = BzrBranchFormat4()
1473
1330
 
1474
1331
    def sprout(self, url, revision_id=None, force_new_repo=False,
1475
1332
               possible_transports=None, accelerator_tree=None,
1476
 
               hardlink=False, stacked=False, create_tree_if_local=True,
1477
 
               source_branch=None):
 
1333
               hardlink=False, stacked=False):
1478
1334
        """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))
1485
1335
        if stacked:
1486
1336
            raise errors.UnstackableBranchFormat(
1487
1337
                self._format, self.root_transport.base)
1488
 
        if not create_tree_if_local:
1489
 
            raise errors.MustHaveWorkingTree(
1490
 
                self._format, self.root_transport.base)
1491
1338
        from bzrlib.workingtree import WorkingTreeFormat2
1492
1339
        self._make_tail(url)
1493
1340
        result = self._format._initialize_for_clone(url)
1499
1346
            self.open_branch().sprout(result, revision_id=revision_id)
1500
1347
        except errors.NotBranchError:
1501
1348
            pass
1502
 
 
1503
1349
        # we always want a working tree
1504
1350
        WorkingTreeFormat2().initialize(result,
1505
1351
                                        accelerator_tree=accelerator_tree,
1509
1355
 
1510
1356
class BzrDir4(BzrDirPreSplitOut):
1511
1357
    """A .bzr version 4 control object.
1512
 
 
 
1358
    
1513
1359
    This is a deprecated format and may be removed after sept 2006.
1514
1360
    """
1515
1361
 
1519
1365
 
1520
1366
    def needs_format_conversion(self, format=None):
1521
1367
        """Format 4 dirs are always in need of conversion."""
1522
 
        if format is None:
1523
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1524
 
                % 'needs_format_conversion(format=None)')
1525
1368
        return True
1526
1369
 
1527
1370
    def open_repository(self):
1536
1379
    This is a deprecated format and may be removed after sept 2006.
1537
1380
    """
1538
1381
 
1539
 
    def has_workingtree(self):
1540
 
        """See BzrDir.has_workingtree."""
1541
 
        return True
1542
 
    
1543
1382
    def open_repository(self):
1544
1383
        """See BzrDir.open_repository."""
1545
1384
        from bzrlib.repofmt.weaverepo import RepositoryFormat5
1561
1400
    This is a deprecated format and may be removed after sept 2006.
1562
1401
    """
1563
1402
 
1564
 
    def has_workingtree(self):
1565
 
        """See BzrDir.has_workingtree."""
1566
 
        return True
1567
 
    
1568
1403
    def open_repository(self):
1569
1404
        """See BzrDir.open_repository."""
1570
1405
        from bzrlib.repofmt.weaverepo import RepositoryFormat6
1581
1416
 
1582
1417
class BzrDirMeta1(BzrDir):
1583
1418
    """A .bzr meta version 1 control object.
1584
 
 
1585
 
    This is the first control object where the
 
1419
    
 
1420
    This is the first control object where the 
1586
1421
    individual aspects are really split out: there are separate repository,
1587
1422
    workingtree and branch subdirectories and any subset of the three can be
1588
1423
    present within a BzrDir.
1648
1483
 
1649
1484
    def get_branch_transport(self, branch_format):
1650
1485
        """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
1653
1486
        if branch_format is None:
1654
1487
            return self.transport.clone('branch')
1655
1488
        try:
1690
1523
            pass
1691
1524
        return self.transport.clone('checkout')
1692
1525
 
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
 
 
1709
1526
    def needs_format_conversion(self, format=None):
1710
1527
        """See BzrDir.needs_format_conversion()."""
1711
1528
        if format is None:
1712
 
            symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1713
 
                % 'needs_format_conversion(format=None)')
1714
 
        if format is None:
1715
1529
            format = BzrDirFormat.get_default_format()
1716
1530
        if not isinstance(self._format, format.__class__):
1717
1531
            # it is not a meta dir format, conversion is needed.
1741
1555
            pass
1742
1556
        return False
1743
1557
 
1744
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
1558
    def open_branch(self, unsupported=False):
1745
1559
        """See BzrDir.open_branch."""
1746
1560
        format = self.find_branch_format()
1747
1561
        self._check_supported(format, unsupported)
1748
 
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
 
1562
        return format.open(self, _found=True)
1749
1563
 
1750
1564
    def open_repository(self, unsupported=False):
1751
1565
        """See BzrDir.open_repository."""
1765
1579
        return format.open(self, _found=True)
1766
1580
 
1767
1581
    def _get_config(self):
1768
 
        return config.TransportConfig(self.transport, 'control.conf')
 
1582
        return config.BzrDirConfig(self.transport)
1769
1583
 
1770
1584
 
1771
1585
class BzrDirFormat(object):
1776
1590
     * a format string,
1777
1591
     * an open routine.
1778
1592
 
1779
 
    Formats are placed in a dict by their format string for reference
 
1593
    Formats are placed in a dict by their format string for reference 
1780
1594
    during bzrdir opening. These should be subclasses of BzrDirFormat
1781
1595
    for consistency.
1782
1596
 
1783
1597
    Once a format is deprecated, just deprecate the initialize and open
1784
 
    methods on the format class. Do not deprecate the object, as the
 
1598
    methods on the format class. Do not deprecate the object, as the 
1785
1599
    object will be created every system load.
1786
1600
    """
1787
1601
 
1793
1607
 
1794
1608
    _control_formats = []
1795
1609
    """The registered control formats - .bzr, ....
1796
 
 
 
1610
    
1797
1611
    This is a list of BzrDirFormat objects.
1798
1612
    """
1799
1613
 
1827
1641
    def probe_transport(klass, transport):
1828
1642
        """Return the .bzrdir style format present in a directory."""
1829
1643
        try:
1830
 
            format_string = transport.get_bytes(".bzr/branch-format")
 
1644
            format_string = transport.get(".bzr/branch-format").read()
1831
1645
        except errors.NoSuchFile:
1832
1646
            raise errors.NotBranchError(path=transport.base)
1833
1647
 
1858
1672
        current default format. In the case of plugins we can/should provide
1859
1673
        some means for them to extend the range of returnable converters.
1860
1674
 
1861
 
        :param format: Optional format to override the default format of the
 
1675
        :param format: Optional format to override the default format of the 
1862
1676
                       library.
1863
1677
        """
1864
1678
        raise NotImplementedError(self.get_converter)
1865
1679
 
1866
1680
    def initialize(self, url, possible_transports=None):
1867
1681
        """Create a bzr control dir at this url and return an opened copy.
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
 
 
 
1682
        
1873
1683
        Subclasses should typically override initialize_on_transport
1874
1684
        instead of this method.
1875
1685
        """
1878
1688
 
1879
1689
    def initialize_on_transport(self, transport):
1880
1690
        """Initialize a new bzrdir in the base directory of a Transport."""
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
 
1691
        # Since we don't have a .bzr directory, inherit the
2001
1692
        # mode from the root directory
2002
1693
        temp_control = lockable_files.LockableFiles(transport,
2003
1694
                            '', lockable_files.TransportLock)
2033
1724
        """Is this format supported?
2034
1725
 
2035
1726
        Supported formats must be initializable and openable.
2036
 
        Unsupported formats may not support initialization or committing or
 
1727
        Unsupported formats may not support initialization or committing or 
2037
1728
        some other features depending on the reason for not being supported.
2038
1729
        """
2039
1730
        return True
2040
1731
 
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
 
 
2051
1732
    def same_model(self, target_format):
2052
 
        return (self.repository_format.rich_root_data ==
 
1733
        return (self.repository_format.rich_root_data == 
2053
1734
            target_format.rich_root_data)
2054
1735
 
2055
1736
    @classmethod
2056
1737
    def known_formats(klass):
2057
1738
        """Return all the known formats.
2058
 
 
 
1739
        
2059
1740
        Concrete formats should override _known_formats.
2060
1741
        """
2061
 
        # There is double indirection here to make sure that control
2062
 
        # formats used by more than one dir format will only be probed
 
1742
        # There is double indirection here to make sure that control 
 
1743
        # formats used by more than one dir format will only be probed 
2063
1744
        # once. This can otherwise be quite expensive for remote connections.
2064
1745
        result = set()
2065
1746
        for format in klass._control_formats:
2066
1747
            result.update(format._known_formats())
2067
1748
        return result
2068
 
 
 
1749
    
2069
1750
    @classmethod
2070
1751
    def _known_formats(klass):
2071
1752
        """Return the known format instances for this control format."""
2073
1754
 
2074
1755
    def open(self, transport, _found=False):
2075
1756
        """Return an instance of this format for the dir transport points at.
2076
 
 
 
1757
        
2077
1758
        _found is a private parameter, do not use it.
2078
1759
        """
2079
1760
        if not _found:
2080
1761
            found_format = BzrDirFormat.find_format(transport)
2081
1762
            if not isinstance(found_format, self.__class__):
2082
1763
                raise AssertionError("%s was asked to open %s, but it seems to need "
2083
 
                        "format %s"
 
1764
                        "format %s" 
2084
1765
                        % (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)
2088
1766
        return self._open(transport)
2089
1767
 
2090
1768
    def _open(self, transport):
2098
1776
    @classmethod
2099
1777
    def register_format(klass, format):
2100
1778
        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__)
2103
1779
 
2104
1780
    @classmethod
2105
1781
    def register_control_format(klass, format):
2106
1782
        """Register a format that does not use '.bzr' for its control dir.
2107
1783
 
2108
1784
        TODO: This should be pulled up into a 'ControlDirFormat' base class
2109
 
        which BzrDirFormat can inherit from, and renamed to register_format
 
1785
        which BzrDirFormat can inherit from, and renamed to register_format 
2110
1786
        there. It has been done without that for now for simplicity of
2111
1787
        implementation.
2112
1788
        """
2130
1806
 
2131
1807
    def __str__(self):
2132
1808
        # Trim the newline
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
 
        """
 
1809
        return self.get_format_string().rstrip()
2146
1810
 
2147
1811
    @classmethod
2148
1812
    def unregister_format(klass, format):
2180
1844
        """See BzrDirFormat.get_converter()."""
2181
1845
        # there is one and only one upgrade path here.
2182
1846
        return ConvertBzrDir4To5()
2183
 
 
 
1847
        
2184
1848
    def initialize_on_transport(self, transport):
2185
1849
        """Format 4 branches cannot be created."""
2186
1850
        raise errors.UninitializableFormat(self)
2189
1853
        """Format 4 is not supported.
2190
1854
 
2191
1855
        It is not supported because the model changed from 4 to 5 and the
2192
 
        conversion logic is expensive - so doing it on the fly was not
 
1856
        conversion logic is expensive - so doing it on the fly was not 
2193
1857
        feasible.
2194
1858
        """
2195
1859
        return False
2196
1860
 
2197
 
    def network_name(self):
2198
 
        return self.get_format_string()
2199
 
 
2200
1861
    def _open(self, transport):
2201
1862
        """See BzrDirFormat._open."""
2202
1863
        return BzrDir4(transport, self)
2208
1869
    repository_format = property(__return_repository_format)
2209
1870
 
2210
1871
 
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):
 
1872
class BzrDirFormat5(BzrDirFormat):
2237
1873
    """Bzr control format 5.
2238
1874
 
2239
1875
    This format is a combined format for working tree, branch and repository.
2240
1876
    It has:
2241
 
     - Format 2 working trees [always]
2242
 
     - Format 4 branches [always]
 
1877
     - Format 2 working trees [always] 
 
1878
     - Format 4 branches [always] 
2243
1879
     - Format 5 repositories [always]
2244
1880
       Unhashed stores in the repository.
2245
1881
    """
2265
1901
 
2266
1902
    def _initialize_for_clone(self, url):
2267
1903
        return self.initialize_on_transport(get_transport(url), _cloning=True)
2268
 
 
 
1904
        
2269
1905
    def initialize_on_transport(self, transport, _cloning=False):
2270
1906
        """Format 5 dirs always have working tree, branch and repository.
2271
 
 
 
1907
        
2272
1908
        Except when they are being cloned.
2273
1909
        """
2274
1910
        from bzrlib.branch import BzrBranchFormat4
2280
1916
            result._init_workingtree()
2281
1917
        return result
2282
1918
 
2283
 
    def network_name(self):
2284
 
        return self.get_format_string()
2285
 
 
2286
1919
    def _open(self, transport):
2287
1920
        """See BzrDirFormat._open."""
2288
1921
        return BzrDir5(transport, self)
2294
1927
    repository_format = property(__return_repository_format)
2295
1928
 
2296
1929
 
2297
 
class BzrDirFormat6(BzrDirFormatAllInOne):
 
1930
class BzrDirFormat6(BzrDirFormat):
2298
1931
    """Bzr control format 6.
2299
1932
 
2300
1933
    This format is a combined format for working tree, branch and repository.
2301
1934
    It has:
2302
 
     - Format 2 working trees [always]
2303
 
     - Format 4 branches [always]
 
1935
     - Format 2 working trees [always] 
 
1936
     - Format 4 branches [always] 
2304
1937
     - Format 6 repositories [always]
2305
1938
    """
2306
1939
 
2322
1955
        """See BzrDirFormat.get_converter()."""
2323
1956
        # there is one and only one upgrade path here.
2324
1957
        return ConvertBzrDir6ToMeta()
2325
 
 
 
1958
        
2326
1959
    def _initialize_for_clone(self, url):
2327
1960
        return self.initialize_on_transport(get_transport(url), _cloning=True)
2328
1961
 
2329
1962
    def initialize_on_transport(self, transport, _cloning=False):
2330
1963
        """Format 6 dirs always have working tree, branch and repository.
2331
 
 
 
1964
        
2332
1965
        Except when they are being cloned.
2333
1966
        """
2334
1967
        from bzrlib.branch import BzrBranchFormat4
2340
1973
            result._init_workingtree()
2341
1974
        return result
2342
1975
 
2343
 
    def network_name(self):
2344
 
        return self.get_format_string()
2345
 
 
2346
1976
    def _open(self, transport):
2347
1977
        """See BzrDirFormat._open."""
2348
1978
        return BzrDir6(transport, self)
2370
2000
    def __init__(self):
2371
2001
        self._workingtree_format = None
2372
2002
        self._branch_format = None
2373
 
        self._repository_format = None
2374
2003
 
2375
2004
    def __eq__(self, other):
2376
2005
        if other.__class__ is not self.__class__:
2393
2022
    def set_branch_format(self, format):
2394
2023
        self._branch_format = format
2395
2024
 
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
 
 
2469
 
        if not self.get_branch_format().supports_stacking():
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()
2477
 
            else:
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())
2487
 
 
2488
2025
    def get_converter(self, format=None):
2489
2026
        """See BzrDirFormat.get_converter()."""
2490
2027
        if format is None:
2502
2039
        """See BzrDirFormat.get_format_description()."""
2503
2040
        return "Meta directory format 1"
2504
2041
 
2505
 
    def network_name(self):
2506
 
        return self.get_format_string()
2507
 
 
2508
2042
    def _open(self, transport):
2509
2043
        """See BzrDirFormat._open."""
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)
 
2044
        return BzrDirMeta1(transport, self)
2516
2045
 
2517
2046
    def __return_repository_format(self):
2518
2047
        """Circular import protection."""
2519
 
        if self._repository_format:
 
2048
        if getattr(self, '_repository_format', None):
2520
2049
            return self._repository_format
2521
2050
        from bzrlib.repository import RepositoryFormat
2522
2051
        return RepositoryFormat.get_default_format()
2523
2052
 
2524
 
    def _set_repository_format(self, value):
 
2053
    def __set_repository_format(self, value):
2525
2054
        """Allow changing the repository format for metadir formats."""
2526
2055
        self._repository_format = value
2527
2056
 
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
 
2057
    repository_format = property(__return_repository_format, __set_repository_format)
2548
2058
 
2549
2059
    def __get_workingtree_format(self):
2550
2060
        if self._workingtree_format is None:
2559
2069
                                  __set_workingtree_format)
2560
2070
 
2561
2071
 
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
 
 
2571
2072
# Register bzr control format
2572
2073
BzrDirFormat.register_control_format(BzrDirFormat)
2573
2074
 
2605
2106
        self.absent_revisions = set()
2606
2107
        self.text_count = 0
2607
2108
        self.revisions = {}
2608
 
 
 
2109
        
2609
2110
    def convert(self, to_convert, pb):
2610
2111
        """See Converter.convert()."""
2611
2112
        self.bzrdir = to_convert
2612
2113
        self.pb = pb
2613
 
        ui.ui_factory.note('starting upgrade from format 4 to 5')
 
2114
        self.pb.note('starting upgrade from format 4 to 5')
2614
2115
        if isinstance(self.bzrdir.transport, local.LocalTransport):
2615
2116
            self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
2616
2117
        self._convert_to_weaves()
2617
2118
        return BzrDir.open(self.bzrdir.root_transport.base)
2618
2119
 
2619
2120
    def _convert_to_weaves(self):
2620
 
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
 
2121
        self.pb.note('note: upgrade may be faster if all store files are ungzipped first')
2621
2122
        try:
2622
2123
            # TODO permissions
2623
2124
            stat = self.bzrdir.transport.stat('weaves')
2651
2152
        self.pb.clear()
2652
2153
        self._write_all_weaves()
2653
2154
        self._write_all_revs()
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)
 
2155
        self.pb.note('upgraded to weaves:')
 
2156
        self.pb.note('  %6d revisions and inventories', len(self.revisions))
 
2157
        self.pb.note('  %6d revisions not present', len(self.absent_revisions))
 
2158
        self.pb.note('  %6d texts', self.text_count)
2658
2159
        self._cleanup_spare_files_after_format4()
2659
2160
        self.branch._transport.put_bytes(
2660
2161
            'branch-format',
2717
2218
                revision_store.add_lines(key, None, osutils.split_lines(text))
2718
2219
        finally:
2719
2220
            self.pb.clear()
2720
 
 
 
2221
            
2721
2222
    def _load_one_rev(self, rev_id):
2722
2223
        """Load a revision object into memory.
2723
2224
 
2728
2229
                       len(self.known_revisions))
2729
2230
        if not self.branch.repository.has_revision(rev_id):
2730
2231
            self.pb.clear()
2731
 
            ui.ui_factory.note('revision {%s} not present in branch; '
2732
 
                         'will be converted as a ghost' %
 
2232
            self.pb.note('revision {%s} not present in branch; '
 
2233
                         'will be converted as a ghost',
2733
2234
                         rev_id)
2734
2235
            self.absent_revisions.add(rev_id)
2735
2236
        else:
2797
2298
        text_changed = False
2798
2299
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2799
2300
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2800
 
        # XXX: Note that this is unordered - and this is tolerable because
 
2301
        # XXX: Note that this is unordered - and this is tolerable because 
2801
2302
        # the previous code was also unordered.
2802
2303
        previous_entries = dict((head, parent_candiate_entries[head]) for head
2803
2304
            in heads)
2804
2305
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2805
2306
        del ie.text_id
2806
2307
 
 
2308
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
 
2309
    def get_parents(self, revision_ids):
 
2310
        for revision_id in revision_ids:
 
2311
            yield self.revisions[revision_id].parent_ids
 
2312
 
2807
2313
    def get_parent_map(self, revision_ids):
2808
 
        """See graph.StackedParentsProvider.get_parent_map"""
 
2314
        """See graph._StackedParentsProvider.get_parent_map"""
2809
2315
        return dict((revision_id, self.revisions[revision_id])
2810
2316
                    for revision_id in revision_ids
2811
2317
                     if revision_id in self.revisions)
2815
2321
        # a call to:. This needs the path figured out. rather than a work_tree
2816
2322
        # a v4 revision_tree can be given, or something that looks enough like
2817
2323
        # one to give the file content to the entry if it needs it.
2818
 
        # and we need something that looks like a weave store for snapshot to
 
2324
        # and we need something that looks like a weave store for snapshot to 
2819
2325
        # save against.
2820
2326
        #ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
2821
2327
        if len(previous_revisions) == 1:
2862
2368
        """See Converter.convert()."""
2863
2369
        self.bzrdir = to_convert
2864
2370
        self.pb = pb
2865
 
        ui.ui_factory.note('starting upgrade from format 5 to 6')
 
2371
        self.pb.note('starting upgrade from format 5 to 6')
2866
2372
        self._convert_to_prefixed()
2867
2373
        return BzrDir.open(self.bzrdir.root_transport.base)
2868
2374
 
2870
2376
        from bzrlib.store import TransportStore
2871
2377
        self.bzrdir.transport.delete('branch-format')
2872
2378
        for store_name in ["weaves", "revision-store"]:
2873
 
            ui.ui_factory.note("adding prefixes to %s" % store_name)
 
2379
            self.pb.note("adding prefixes to %s" % store_name)
2874
2380
            store_transport = self.bzrdir.transport.clone(store_name)
2875
2381
            store = TransportStore(store_transport, prefixed=True)
2876
2382
            for urlfilename in store_transport.list_dir('.'):
2910
2416
        self.dir_mode = self.bzrdir._get_dir_mode()
2911
2417
        self.file_mode = self.bzrdir._get_file_mode()
2912
2418
 
2913
 
        ui.ui_factory.note('starting upgrade from format 6 to metadir')
 
2419
        self.pb.note('starting upgrade from format 6 to metadir')
2914
2420
        self.bzrdir.transport.put_bytes(
2915
2421
                'branch-format',
2916
2422
                "Converting to format 6",
2937
2443
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
2938
2444
        self.make_lock('repository')
2939
2445
        # we hard code the formats here because we are converting into
2940
 
        # the meta format. The meta format upgrader can take this to a
 
2446
        # the meta format. The meta format upgrader can take this to a 
2941
2447
        # future format within each component.
2942
2448
        self.put_format('repository', RepositoryFormat7())
2943
2449
        for entry in repository_names:
2966
2472
        else:
2967
2473
            has_checkout = True
2968
2474
        if not has_checkout:
2969
 
            ui.ui_factory.note('No working tree.')
 
2475
            self.pb.note('No working tree.')
2970
2476
            # If some checkout files are there, we may as well get rid of them.
2971
2477
            for name, mandatory in checkout_files:
2972
2478
                if name in bzrcontents:
3041
2547
        else:
3042
2548
            if not isinstance(repo._format, self.target_format.repository_format.__class__):
3043
2549
                from bzrlib.repository import CopyConverter
3044
 
                ui.ui_factory.note('starting repository conversion')
 
2550
                self.pb.note('starting repository conversion')
3045
2551
                converter = CopyConverter(self.target_format.repository_format)
3046
2552
                converter.convert(repo, pb)
3047
2553
        try:
3058
2564
            while old != new:
3059
2565
                if (old == _mod_branch.BzrBranchFormat5 and
3060
2566
                    new in (_mod_branch.BzrBranchFormat6,
3061
 
                        _mod_branch.BzrBranchFormat7,
3062
 
                        _mod_branch.BzrBranchFormat8)):
 
2567
                        _mod_branch.BzrBranchFormat7)):
3063
2568
                    branch_converter = _mod_branch.Converter5to6()
3064
2569
                elif (old == _mod_branch.BzrBranchFormat6 and
3065
 
                    new in (_mod_branch.BzrBranchFormat7,
3066
 
                            _mod_branch.BzrBranchFormat8)):
 
2570
                    new == _mod_branch.BzrBranchFormat7):
3067
2571
                    branch_converter = _mod_branch.Converter6to7()
3068
 
                elif (old == _mod_branch.BzrBranchFormat7 and
3069
 
                      new is _mod_branch.BzrBranchFormat8):
3070
 
                    branch_converter = _mod_branch.Converter7to8()
3071
2572
                else:
3072
 
                    raise errors.BadConversionTarget("No converter", new,
3073
 
                        branch._format)
 
2573
                    raise errors.BadConversionTarget("No converter", new)
3074
2574
                branch_converter.convert(branch)
3075
2575
                branch = self.bzrdir.open_branch()
3076
2576
                old = branch._format.__class__
3082
2582
            # TODO: conversions of Branch and Tree should be done by
3083
2583
            # InterXFormat lookups
3084
2584
            if (isinstance(tree, workingtree.WorkingTree3) and
3085
 
                not isinstance(tree, workingtree_4.DirStateWorkingTree) and
 
2585
                not isinstance(tree, workingtree_4.WorkingTree4) and
3086
2586
                isinstance(self.target_format.workingtree_format,
3087
 
                    workingtree_4.DirStateWorkingTreeFormat)):
 
2587
                    workingtree_4.WorkingTreeFormat4)):
3088
2588
                workingtree_4.Converter3to4().convert(tree)
3089
 
            if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3090
 
                not isinstance(tree, workingtree_4.WorkingTree5) and
3091
 
                isinstance(self.target_format.workingtree_format,
3092
 
                    workingtree_4.WorkingTreeFormat5)):
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)
3099
2589
        return to_convert
3100
2590
 
3101
2591
 
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.
 
2592
# This is not in remote.py because it's small, and needs to be registered.
 
2593
# Putting it in remote.py creates a circular import problem.
3104
2594
# we can make it a lazy object if the control formats is turned into something
3105
2595
# like a registry.
3106
2596
class RemoteBzrDirFormat(BzrDirMetaFormat1):
3107
2597
    """Format representing bzrdirs accessed via a smart server"""
3108
2598
 
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
 
 
3121
2599
    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()
3125
2600
        return 'bzr remote bzrdir'
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
 
 
 
2601
    
3136
2602
    @classmethod
3137
2603
    def probe_transport(klass, transport):
3138
2604
        """Return a RemoteBzrDirFormat object if it looks possible."""
3167
2633
            return local_dir_format.initialize_on_transport(transport)
3168
2634
        client = _SmartClient(client_medium)
3169
2635
        path = client.remote_path_from_transport(transport)
3170
 
        try:
3171
 
            response = client.call('BzrDirFormat.initialize', path)
3172
 
        except errors.ErrorFromSmartServer, err:
3173
 
            remote._translate_error(err, path=path)
 
2636
        response = client.call('BzrDirFormat.initialize', path)
3174
2637
        if response[0] != 'ok':
3175
2638
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
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
 
2639
        return remote.RemoteBzrDir(transport)
3325
2640
 
3326
2641
    def _open(self, transport):
3327
 
        return remote.RemoteBzrDir(transport, self)
 
2642
        return remote.RemoteBzrDir(transport)
3328
2643
 
3329
2644
    def __eq__(self, other):
3330
2645
        if not isinstance(other, RemoteBzrDirFormat):
3331
2646
            return False
3332
2647
        return self.get_format_description() == other.get_format_description()
3333
2648
 
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)
3362
 
 
3363
2649
 
3364
2650
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
3365
2651
 
3375
2661
 
3376
2662
class BzrDirFormatRegistry(registry.Registry):
3377
2663
    """Registry of user-selectable BzrDir subformats.
3378
 
 
 
2664
    
3379
2665
    Differs from BzrDirFormat._control_formats in that it provides sub-formats,
3380
2666
    e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
3381
2667
    """
3383
2669
    def __init__(self):
3384
2670
        """Create a BzrDirFormatRegistry."""
3385
2671
        self._aliases = set()
3386
 
        self._registration_order = list()
3387
2672
        super(BzrDirFormatRegistry, self).__init__()
3388
2673
 
3389
2674
    def aliases(self):
3400
2685
        """Register a metadir subformat.
3401
2686
 
3402
2687
        These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3403
 
        by the Repository/Branch/WorkingTreeformats.
 
2688
        by the Repository format.
3404
2689
 
3405
2690
        :param repository_format: The fully-qualified repository format class
3406
2691
            name as a string.
3440
2725
    def register(self, key, factory, help, native=True, deprecated=False,
3441
2726
                 hidden=False, experimental=False, alias=False):
3442
2727
        """Register a BzrDirFormat factory.
3443
 
 
 
2728
        
3444
2729
        The factory must be a callable that takes one parameter: the key.
3445
2730
        It must produce an instance of the BzrDirFormat when called.
3446
2731
 
3451
2736
            BzrDirFormatInfo(native, deprecated, hidden, experimental))
3452
2737
        if alias:
3453
2738
            self._aliases.add(key)
3454
 
        self._registration_order.append(key)
3455
2739
 
3456
2740
    def register_lazy(self, key, module_name, member_name, help, native=True,
3457
2741
        deprecated=False, hidden=False, experimental=False, alias=False):
3459
2743
            help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
3460
2744
        if alias:
3461
2745
            self._aliases.add(key)
3462
 
        self._registration_order.append(key)
3463
2746
 
3464
2747
    def set_default(self, key):
3465
2748
        """Set the 'default' key to be a clone of the supplied key.
3466
 
 
 
2749
        
3467
2750
        This method must be called once and only once.
3468
2751
        """
3469
2752
        registry.Registry.register(self, 'default', self.get(key),
3472
2755
 
3473
2756
    def set_default_repository(self, key):
3474
2757
        """Set the FormatRegistry default and Repository default.
3475
 
 
 
2758
        
3476
2759
        This is a transitional method while Repository.set_default_format
3477
2760
        is deprecated.
3478
2761
        """
3485
2768
        return self.get(key)()
3486
2769
 
3487
2770
    def help_topic(self, topic):
3488
 
        output = ""
 
2771
        output = textwrap.dedent("""\
 
2772
            These formats can be used for creating branches, working trees, and
 
2773
            repositories.
 
2774
 
 
2775
            """)
3489
2776
        default_realkey = None
3490
2777
        default_help = self.get_help('default')
3491
2778
        help_pairs = []
3492
 
        for key in self._registration_order:
 
2779
        for key in self.keys():
3493
2780
            if key == 'default':
3494
2781
                continue
3495
2782
            help = self.get_help(key)
3501
2788
        def wrapped(key, help, info):
3502
2789
            if info.native:
3503
2790
                help = '(native) ' + help
3504
 
            return ':%s:\n%s\n\n' % (key,
3505
 
                textwrap.fill(help, initial_indent='    ',
3506
 
                    subsequent_indent='    ',
3507
 
                    break_long_words=False))
 
2791
            return ':%s:\n%s\n\n' % (key, 
 
2792
                    textwrap.fill(help, initial_indent='    ', 
 
2793
                    subsequent_indent='    '))
3508
2794
        if default_realkey is not None:
3509
2795
            output += wrapped(default_realkey, '(default) %s' % default_help,
3510
2796
                              self.get_info('default'))
3520
2806
                experimental_pairs.append((key, help))
3521
2807
            else:
3522
2808
                output += wrapped(key, help, info)
3523
 
        output += "\nSee :doc:`formats-help` for more about storage formats."
3524
 
        other_output = ""
3525
2809
        if len(experimental_pairs) > 0:
3526
 
            other_output += "Experimental formats are shown below.\n\n"
 
2810
            output += "Experimental formats are shown below.\n\n"
3527
2811
            for key, help in experimental_pairs:
3528
2812
                info = self.get_info(key)
3529
 
                other_output += wrapped(key, help, info)
3530
 
        else:
3531
 
            other_output += \
3532
 
                "No experimental formats are available.\n\n"
 
2813
                output += wrapped(key, help, info)
3533
2814
        if len(deprecated_pairs) > 0:
3534
 
            other_output += "\nDeprecated formats are shown below.\n\n"
 
2815
            output += "Deprecated formats are shown below.\n\n"
3535
2816
            for key, help in deprecated_pairs:
3536
2817
                info = self.get_info(key)
3537
 
                other_output += wrapped(key, help, info)
3538
 
        else:
3539
 
            other_output += \
3540
 
                "\nNo deprecated formats are available.\n\n"
3541
 
        other_output += \
3542
 
                "\nSee :doc:`formats-help` for more about storage formats."
 
2818
                output += wrapped(key, help, info)
3543
2819
 
3544
 
        if topic == 'other-formats':
3545
 
            return other_output
3546
 
        else:
3547
 
            return output
 
2820
        return output
3548
2821
 
3549
2822
 
3550
2823
class RepositoryAcquisitionPolicy(object):
3584
2857
                stack_on = self._get_full_stack_on()
3585
2858
        try:
3586
2859
            branch.set_stacked_on_url(stack_on)
3587
 
        except (errors.UnstackableBranchFormat,
3588
 
                errors.UnstackableRepositoryFormat):
 
2860
        except errors.UnstackableBranchFormat:
3589
2861
            if self._require_stacking:
3590
2862
                raise
3591
2863
 
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
 
 
3596
2864
    def _get_full_stack_on(self):
3597
2865
        """Get a fully-qualified URL for the stack_on location."""
3598
2866
        if self._stack_on is None:
3602
2870
        else:
3603
2871
            return urlutils.join(self._stack_on_pwd, self._stack_on)
3604
2872
 
3605
 
    def _add_fallback(self, repository, possible_transports=None):
 
2873
    def _add_fallback(self, repository):
3606
2874
        """Add a fallback to the supplied repository, if stacking is set."""
3607
2875
        stack_on = self._get_full_stack_on()
3608
2876
        if stack_on is None:
3609
2877
            return
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
 
2878
        stacked_dir = BzrDir.open(stack_on)
3617
2879
        try:
3618
2880
            stacked_repo = stacked_dir.open_branch().repository
3619
2881
        except errors.NotBranchError:
3623
2885
        except errors.UnstackableRepositoryFormat:
3624
2886
            if self._require_stacking:
3625
2887
                raise
3626
 
        else:
3627
 
            self._require_stacking = True
3628
2888
 
3629
2889
    def acquire_repository(self, make_working_trees=None, shared=False):
3630
2890
        """Acquire a repository for this bzrdir.
3634
2894
        :param make_working_trees: If creating a repository, set
3635
2895
            make_working_trees to this value (if non-None)
3636
2896
        :param shared: If creating a repository, make it shared if True
3637
 
        :return: A repository, is_new_flag (True if the repository was
3638
 
            created).
 
2897
        :return: A repository
3639
2898
        """
3640
2899
        raise NotImplemented(RepositoryAcquisitionPolicy.acquire_repository)
3641
2900
 
3661
2920
 
3662
2921
        Creates the desired repository in the bzrdir we already have.
3663
2922
        """
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)
3673
2923
        repository = self._bzrdir.create_repository(shared=shared)
3674
 
        self._add_fallback(repository,
3675
 
                           possible_transports=[self._bzrdir.transport])
 
2924
        self._add_fallback(repository)
3676
2925
        if make_working_trees is not None:
3677
2926
            repository.set_make_working_trees(make_working_trees)
3678
 
        return repository, True
 
2927
        return repository
3679
2928
 
3680
2929
 
3681
2930
class UseExistingRepository(RepositoryAcquisitionPolicy):
3697
2946
    def acquire_repository(self, make_working_trees=None, shared=False):
3698
2947
        """Implementation of RepositoryAcquisitionPolicy.acquire_repository
3699
2948
 
3700
 
        Returns an existing repository to use.
 
2949
        Returns an existing repository to use
3701
2950
        """
3702
 
        self._add_fallback(self._repository,
3703
 
                       possible_transports=[self._repository.bzrdir.transport])
3704
 
        return self._repository, False
3705
 
 
3706
 
 
3707
 
# Please register new formats after old formats so that formats
3708
 
# appear in chronological order and format descriptions can build
3709
 
# on previous ones.
 
2951
        self._add_fallback(self._repository)
 
2952
        return self._repository
 
2953
 
 
2954
 
3710
2955
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.
3714
2956
format_registry.register('weave', BzrDirFormat6,
3715
2957
    'Pre-0.8 format.  Slower than knit and does not'
3716
2958
    ' support checkouts or shared repositories.',
3717
 
    hidden=True,
3718
2959
    deprecated=True)
 
2960
format_registry.register_metadir('knit',
 
2961
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
2962
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
 
2963
    branch_format='bzrlib.branch.BzrBranchFormat5',
 
2964
    tree_format='bzrlib.workingtree.WorkingTreeFormat3')
3719
2965
format_registry.register_metadir('metaweave',
3720
2966
    'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3721
2967
    'Transitional format in 0.8.  Slower than knit.',
3722
2968
    branch_format='bzrlib.branch.BzrBranchFormat5',
3723
2969
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3724
 
    hidden=True,
3725
 
    deprecated=True)
3726
 
format_registry.register_metadir('knit',
3727
 
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3728
 
    'Format using knits.  Recommended for interoperation with bzr <= 0.14.',
3729
 
    branch_format='bzrlib.branch.BzrBranchFormat5',
3730
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3731
 
    hidden=True,
3732
2970
    deprecated=True)
3733
2971
format_registry.register_metadir('dirstate',
3734
2972
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3738
2976
    # this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
3739
2977
    # directly from workingtree_4 triggers a circular import.
3740
2978
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3741
 
    hidden=True,
3742
 
    deprecated=True)
 
2979
    )
3743
2980
format_registry.register_metadir('dirstate-tags',
3744
2981
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3745
2982
    help='New in 0.15: Fast local operations and improved scaling for '
3747
2984
        ' Incompatible with bzr < 0.15.',
3748
2985
    branch_format='bzrlib.branch.BzrBranchFormat6',
3749
2986
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3750
 
    hidden=True,
3751
 
    deprecated=True)
 
2987
    )
3752
2988
format_registry.register_metadir('rich-root',
3753
2989
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
3754
2990
    help='New in 1.0.  Better handling of tree roots.  Incompatible with'
3755
 
        ' bzr < 1.0.',
 
2991
        ' bzr < 1.0',
3756
2992
    branch_format='bzrlib.branch.BzrBranchFormat6',
3757
2993
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3758
 
    hidden=True,
3759
 
    deprecated=True)
 
2994
    )
3760
2995
format_registry.register_metadir('dirstate-with-subtree',
3761
2996
    'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3762
2997
    help='New in 0.15: Fast local operations and improved scaling for '
3772
3007
    help='New in 0.92: Pack-based format with data compatible with '
3773
3008
        'dirstate-tags format repositories. Interoperates with '
3774
3009
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3775
 
        ,
 
3010
        'Previously called knitpack-experimental.  '
 
3011
        'For more information, see '
 
3012
        'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3776
3013
    branch_format='bzrlib.branch.BzrBranchFormat6',
3777
3014
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3778
3015
    )
3781
3018
    help='New in 0.92: Pack-based format with data compatible with '
3782
3019
        'dirstate-with-subtree format repositories. Interoperates with '
3783
3020
        'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3784
 
        ,
 
3021
        'Previously called knitpack-experimental.  '
 
3022
        'For more information, see '
 
3023
        'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3785
3024
    branch_format='bzrlib.branch.BzrBranchFormat6',
3786
3025
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3787
3026
    hidden=True,
3789
3028
    )
3790
3029
format_registry.register_metadir('rich-root-pack',
3791
3030
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3792
 
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3793
 
         '(needed for bzr-svn and bzr-git).',
 
3031
    help='New in 1.0: Pack-based format with data compatible with '
 
3032
        'rich-root format repositories. Incompatible with'
 
3033
        ' bzr < 1.0',
3794
3034
    branch_format='bzrlib.branch.BzrBranchFormat6',
3795
3035
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3796
 
    hidden=True,
3797
3036
    )
3798
3037
format_registry.register_metadir('1.6',
3799
3038
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3800
 
    help='A format that allows a branch to indicate that there is another '
3801
 
         '(stacked) repository that should be used to access data that is '
3802
 
         'not present locally.',
 
3039
    help='A branch and pack based repository that supports stacking. ',
3803
3040
    branch_format='bzrlib.branch.BzrBranchFormat7',
3804
3041
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3805
 
    hidden=True,
3806
3042
    )
3807
3043
format_registry.register_metadir('1.6.1-rich-root',
3808
3044
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3809
 
    help='A variant of 1.6 that supports rich-root data '
3810
 
         '(needed for bzr-svn and bzr-git).',
3811
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3812
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3813
 
    hidden=True,
3814
 
    )
3815
 
format_registry.register_metadir('1.9',
3816
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3817
 
    help='A repository format using B+tree indexes. These indexes '
3818
 
         'are smaller in size, have smarter caching and provide faster '
3819
 
         'performance for most operations.',
3820
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3821
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3822
 
    hidden=True,
3823
 
    )
3824
 
format_registry.register_metadir('1.9-rich-root',
3825
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3826
 
    help='A variant of 1.9 that supports rich-root data '
3827
 
         '(needed for bzr-svn and bzr-git).',
3828
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3829
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3830
 
    hidden=True,
3831
 
    )
3832
 
format_registry.register_metadir('1.14',
3833
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3834
 
    help='A working-tree format that supports content filtering.',
3835
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3836
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3837
 
    )
3838
 
format_registry.register_metadir('1.14-rich-root',
3839
 
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3840
 
    help='A variant of 1.14 that supports rich-root data '
3841
 
         '(needed for bzr-svn and bzr-git).',
3842
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3843
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3844
 
    )
3845
 
# The following un-numbered 'development' formats should always just be aliases.
3846
 
format_registry.register_metadir('development-rich-root',
3847
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3848
 
    help='Current development format. Supports rich roots. Can convert data '
3849
 
        'to and from rich-root-pack (and anything compatible with '
3850
 
        'rich-root-pack) format repositories. Repositories and branches in '
3851
 
        'this format can only be read by bzr.dev. Please read '
3852
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3045
    help='A branch and pack based repository that supports stacking '
 
3046
         'and rich root data (needed for bzr-svn). ',
 
3047
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3048
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3049
    )
 
3050
# The following two formats should always just be aliases.
 
3051
format_registry.register_metadir('development',
 
3052
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
 
3053
    help='Current development format. Can convert data to and from pack-0.92 '
 
3054
        '(and anything compatible with pack-0.92) format repositories. '
 
3055
        'Repositories and branches in this format can only be read by bzr.dev. '
 
3056
        'Please read '
 
3057
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3853
3058
        'before use.',
3854
3059
    branch_format='bzrlib.branch.BzrBranchFormat7',
3855
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3060
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3856
3061
    experimental=True,
3857
3062
    alias=True,
3858
 
    hidden=True,
3859
3063
    )
3860
3064
format_registry.register_metadir('development-subtree',
3861
3065
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3863
3067
        'from pack-0.92-subtree (and anything compatible with '
3864
3068
        'pack-0.92-subtree) format repositories. Repositories and branches in '
3865
3069
        'this format can only be read by bzr.dev. Please read '
3866
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
 
3070
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3867
3071
        'before use.',
3868
3072
    branch_format='bzrlib.branch.BzrBranchFormat7',
3869
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3073
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3870
3074
    experimental=True,
3871
 
    hidden=True,
3872
 
    alias=False, # Restore to being an alias when an actual development subtree format is added
3873
 
                 # This current non-alias status is simply because we did not introduce a
3874
 
                 # chk based subtree format.
 
3075
    alias=True,
3875
3076
    )
3876
 
 
3877
3077
# And the development formats above will have aliased one of the following:
3878
 
format_registry.register_metadir('development6-rich-root',
3879
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3880
 
    help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3881
 
        'Please read '
3882
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3883
 
        'before use.',
3884
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3885
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3886
 
    hidden=True,
3887
 
    experimental=True,
3888
 
    )
3889
 
 
3890
 
format_registry.register_metadir('development7-rich-root',
3891
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3892
 
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3893
 
        'rich roots. Please read '
3894
 
        'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3895
 
        'before use.',
3896
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3897
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3898
 
    hidden=True,
3899
 
    experimental=True,
3900
 
    )
3901
 
 
3902
 
format_registry.register_metadir('2a',
3903
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3904
 
    help='First format for bzr 2.0 series.\n'
3905
 
        'Uses group-compress storage.\n'
3906
 
        'Provides rich roots which are a one-way transition.\n',
3907
 
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3908
 
        # 'rich roots. Supported by bzr 1.16 and later.',
3909
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3910
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3911
 
    experimental=True,
3912
 
    )
3913
 
 
3914
 
# The following format should be an alias for the rich root equivalent 
3915
 
# of the default format
3916
 
format_registry.register_metadir('default-rich-root',
3917
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3918
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3919
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3920
 
    alias=True,
3921
 
    hidden=True,
3922
 
    help='Same as 2a.')
3923
 
 
 
3078
format_registry.register_metadir('development2',
 
3079
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
 
3080
    help='1.6.1 with B+Tree based index. '
 
3081
        'Please read '
 
3082
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3083
        'before use.',
 
3084
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3085
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3086
    hidden=True,
 
3087
    experimental=True,
 
3088
    )
 
3089
format_registry.register_metadir('development2-subtree',
 
3090
    'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
 
3091
    help='1.6.1-subtree with B+Tree based index. '
 
3092
        'Please read '
 
3093
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3094
        'before use.',
 
3095
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3096
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3097
    hidden=True,
 
3098
    experimental=True,
 
3099
    )
3924
3100
# The current format that is made on 'bzr init'.
3925
 
format_registry.set_default('2a')
 
3101
format_registry.set_default('pack-0.92')