/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

MergeĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""BzrDir logic. The BzrDir is the basic control directory used by bzr.
18
18
 
75
75
    )
76
76
 
77
77
from bzrlib import (
 
78
    hooks,
78
79
    registry,
79
80
    symbol_versioning,
80
81
    )
93
94
        (i.e. the parent directory holding the .bzr directory).
94
95
 
95
96
    Everything in the bzrdir should have the same file permissions.
 
97
 
 
98
    :cvar hooks: An instance of BzrDirHooks.
96
99
    """
97
100
 
98
101
    def break_lock(self):
189
192
        transport.ensure_base()
190
193
        require_stacking = (stacked_on is not None)
191
194
        format = self.cloning_metadir(require_stacking)
 
195
        # Bug: We create a metadir without knowing if it can support stacking,
 
196
        # we should look up the policy needs first.
192
197
        result = format.initialize_on_transport(transport)
193
198
        repository_policy = None
194
199
        try:
384
389
                                    stack_on_pwd=None, require_stacking=False):
385
390
        """Return an object representing a policy to use.
386
391
 
387
 
        This controls whether a new repository is created, or a shared
388
 
        repository used instead.
 
392
        This controls whether a new repository is created, and the format of
 
393
        that repository, or some existing shared repository used instead.
389
394
 
390
395
        If stack_on is supplied, will not seek a containing shared repo.
391
396
 
405
410
                if stack_on is not None:
406
411
                    stack_on_pwd = found_bzrdir.root_transport.base
407
412
                    stop = True
408
 
                    note('Using default stacking branch %s at %s', stack_on,
409
 
                         stack_on_pwd)
410
413
            # does it have a repository ?
411
414
            try:
412
415
                repository = found_bzrdir.open_repository()
415
418
            else:
416
419
                if ((found_bzrdir.root_transport.base !=
417
420
                     self.root_transport.base) and not repository.is_shared()):
 
421
                    # Don't look higher, can't use a higher shared repo.
418
422
                    repository = None
 
423
                    stop = True
419
424
                else:
420
425
                    stop = True
421
426
            if not stop:
806
811
        :param transport: Transport containing the bzrdir.
807
812
        :param _unsupported: private.
808
813
        """
 
814
        for hook in BzrDir.hooks['pre_open']:
 
815
            hook(transport)
809
816
        # Keep initial base since 'transport' may be modified while following
810
817
        # the redirections.
811
818
        base = transport.base
831
838
        BzrDir._check_supported(format, _unsupported)
832
839
        return format.open(transport, _found=True)
833
840
 
834
 
    def open_branch(self, unsupported=False):
 
841
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
835
842
        """Open the branch object at this BzrDir if one is present.
836
843
 
837
844
        If unsupported is True, then no longer supported branch formats can
1012
1019
        result_format = self._format.__class__()
1013
1020
        try:
1014
1021
            try:
1015
 
                branch = self.open_branch()
 
1022
                branch = self.open_branch(ignore_fallbacks=True)
1016
1023
                source_repository = branch.repository
1017
1024
                result_format._branch_format = branch._format
1018
1025
            except errors.NotBranchError:
1190
1197
        return result
1191
1198
 
1192
1199
 
 
1200
class BzrDirHooks(hooks.Hooks):
 
1201
    """Hooks for BzrDir operations."""
 
1202
 
 
1203
    def __init__(self):
 
1204
        """Create the default hooks."""
 
1205
        hooks.Hooks.__init__(self)
 
1206
        self.create_hook(hooks.HookPoint('pre_open',
 
1207
            "Invoked before attempting to open a BzrDir with the transport "
 
1208
            "that the open will use.", (1, 14), None))
 
1209
 
 
1210
# install the default hooks
 
1211
BzrDir.hooks = BzrDirHooks()
 
1212
 
 
1213
 
1193
1214
class BzrDirPreSplitOut(BzrDir):
1194
1215
    """A common class for the all-in-one formats."""
1195
1216
 
1337
1358
            format = BzrDirFormat.get_default_format()
1338
1359
        return not isinstance(self._format, format.__class__)
1339
1360
 
1340
 
    def open_branch(self, unsupported=False):
 
1361
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1341
1362
        """See BzrDir.open_branch."""
1342
1363
        from bzrlib.branch import BzrBranchFormat4
1343
1364
        format = BzrBranchFormat4()
1588
1609
            pass
1589
1610
        return False
1590
1611
 
1591
 
    def open_branch(self, unsupported=False):
 
1612
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1592
1613
        """See BzrDir.open_branch."""
1593
1614
        format = self.find_branch_format()
1594
1615
        self._check_supported(format, unsupported)
1595
 
        return format.open(self, _found=True)
 
1616
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1596
1617
 
1597
1618
    def open_repository(self, unsupported=False):
1598
1619
        """See BzrDir.open_repository."""
2449
2470
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2450
2471
        del ie.text_id
2451
2472
 
2452
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
2453
 
    def get_parents(self, revision_ids):
2454
 
        for revision_id in revision_ids:
2455
 
            yield self.revisions[revision_id].parent_ids
2456
 
 
2457
2473
    def get_parent_map(self, revision_ids):
2458
2474
        """See graph._StackedParentsProvider.get_parent_map"""
2459
2475
        return dict((revision_id, self.revisions[revision_id])
2814
2830
        # Always return a RemoteRepositoryFormat object, but if a specific bzr
2815
2831
        # repository format has been asked for, tell the RemoteRepositoryFormat
2816
2832
        # that it should use that for init() etc.
2817
 
        result =  remote.RemoteRepositoryFormat()
 
2833
        result = remote.RemoteRepositoryFormat()
2818
2834
        custom_format = getattr(self, '_repository_format', None)
2819
2835
        if custom_format:
2820
 
            # We will use the custom format to create repositories over the
2821
 
            # wire; expose its details like rich_root_data for code to query
2822
2836
            if isinstance(custom_format, remote.RemoteRepositoryFormat):
2823
 
                result._custom_format = custom_format._custom_format
 
2837
                return custom_format
2824
2838
            else:
 
2839
                # We will use the custom format to create repositories over the
 
2840
                # wire; expose its details like rich_root_data for code to
 
2841
                # query
2825
2842
                result._custom_format = custom_format
2826
2843
        return result
2827
2844
 
3129
3146
 
3130
3147
        Creates the desired repository in the bzrdir we already have.
3131
3148
        """
 
3149
        stack_on = self._get_full_stack_on()
 
3150
        if stack_on:
 
3151
            # Stacking is desired. requested by the target, but does the place it
 
3152
            # points at support stacking? If it doesn't then we should
 
3153
            # not implicitly upgrade. We check this here.
 
3154
            format = self._bzrdir._format
 
3155
            if not (format.repository_format.supports_external_lookups
 
3156
                and format.get_branch_format().supports_stacking()):
 
3157
                # May need to upgrade - but only do if the target also
 
3158
                # supports stacking. Note that this currently wastes
 
3159
                # network round trips to check - but we only do this
 
3160
                # when the source can't stack so it will fade away
 
3161
                # as people do upgrade.
 
3162
                try:
 
3163
                    target_dir = BzrDir.open(stack_on,
 
3164
                        possible_transports=[self._bzrdir.root_transport])
 
3165
                except errors.NotBranchError:
 
3166
                    # Nothing there, don't change formats
 
3167
                    pass
 
3168
                else:
 
3169
                    try:
 
3170
                        target_branch = target_dir.open_branch()
 
3171
                    except errors.NotBranchError:
 
3172
                        # No branch, don't change formats
 
3173
                        pass
 
3174
                    else:
 
3175
                        branch_format = target_branch._format
 
3176
                        repo_format = target_branch.repository._format
 
3177
                        if not (branch_format.supports_stacking()
 
3178
                            and repo_format.supports_external_lookups):
 
3179
                            # Doesn't stack itself, don't force an upgrade
 
3180
                            pass
 
3181
                        else:
 
3182
                            # Does support stacking, use its format.
 
3183
                            format.repository_format = repo_format
 
3184
                            format.set_branch_format(branch_format)
 
3185
                            note('Source format does not support stacking, '
 
3186
                                'using format: \'%s\'\n  %s\n',
 
3187
                                branch_format.get_format_description(),
 
3188
                                repo_format.get_format_description())
 
3189
            if not self._require_stacking:
 
3190
                # We have picked up automatic stacking somewhere.
 
3191
                note('Using default stacking branch %s at %s', self._stack_on,
 
3192
                    self._stack_on_pwd)
3132
3193
        repository = self._bzrdir.create_repository(shared=shared)
3133
3194
        self._add_fallback(repository,
3134
3195
                           possible_transports=[self._bzrdir.transport])
3247
3308
format_registry.register_metadir('rich-root-pack',
3248
3309
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3249
3310
    help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3250
 
         '(needed for bzr-svn).',
 
3311
         '(needed for bzr-svn and bzr-git).',
3251
3312
    branch_format='bzrlib.branch.BzrBranchFormat6',
3252
3313
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3253
3314
    )
3262
3323
format_registry.register_metadir('1.6.1-rich-root',
3263
3324
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3264
3325
    help='A variant of 1.6 that supports rich-root data '
3265
 
         '(needed for bzr-svn).',
 
3326
         '(needed for bzr-svn and bzr-git).',
3266
3327
    branch_format='bzrlib.branch.BzrBranchFormat7',
3267
3328
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3268
3329
    )
3277
3338
format_registry.register_metadir('1.9-rich-root',
3278
3339
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3279
3340
    help='A variant of 1.9 that supports rich-root data '
3280
 
         '(needed for bzr-svn).',
 
3341
         '(needed for bzr-svn and bzr-git).',
3281
3342
    branch_format='bzrlib.branch.BzrBranchFormat7',
3282
3343
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3283
3344
    )
3291
3352
format_registry.register_metadir('development-wt5-rich-root',
3292
3353
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3293
3354
    help='A variant of development-wt5 that supports rich-root data '
3294
 
         '(needed for bzr-svn).',
 
3355
         '(needed for bzr-svn and bzr-git).',
3295
3356
    branch_format='bzrlib.branch.BzrBranchFormat7',
3296
3357
    tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3297
3358
    experimental=True,
3346
3407
    hidden=True,
3347
3408
    experimental=True,
3348
3409
    )
 
3410
# The following format should be an alias for the rich root equivalent 
 
3411
# of the default format
 
3412
format_registry.register_metadir('default-rich-root',
 
3413
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
 
3414
    help='Default format, rich root variant. (needed for bzr-svn and bzr-git).',
 
3415
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
3416
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
 
3417
    alias=True,
 
3418
    )
3349
3419
# The current format that is made on 'bzr init'.
3350
3420
format_registry.set_default('pack-0.92')