/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

  • Committer: John Arbash Meinel
  • Date: 2009-07-08 14:37:25 UTC
  • mfrom: (4516 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4517.
  • Revision ID: john@arbash-meinel.com-20090708143725-sc9sjy3mz4cxwxzz
Merge bzr.dev 4516

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    do_catching_redirections,
71
71
    get_transport,
72
72
    local,
73
 
    remote as remote_transport,
74
73
    )
75
74
from bzrlib.weave import Weave
76
75
""")
2358
2357
    def set_branch_format(self, format):
2359
2358
        self._branch_format = format
2360
2359
 
2361
 
    def require_stacking(self):
 
2360
    def require_stacking(self, stack_on=None, possible_transports=None,
 
2361
            _skip_repo=False):
 
2362
        """We have a request to stack, try to ensure the formats support it.
 
2363
 
 
2364
        :param stack_on: If supplied, it is the URL to a branch that we want to
 
2365
            stack on. Check to see if that format supports stacking before
 
2366
            forcing an upgrade.
 
2367
        """
 
2368
        # Stacking is desired. requested by the target, but does the place it
 
2369
        # points at support stacking? If it doesn't then we should
 
2370
        # not implicitly upgrade. We check this here.
 
2371
        new_repo_format = None
 
2372
        new_branch_format = None
 
2373
 
 
2374
        # a bit of state for get_target_branch so that we don't try to open it
 
2375
        # 2 times, for both repo *and* branch
 
2376
        target = [None, False, None] # target_branch, checked, upgrade anyway
 
2377
        def get_target_branch():
 
2378
            if target[1]:
 
2379
                # We've checked, don't check again
 
2380
                return target
 
2381
            if stack_on is None:
 
2382
                # No target format, that means we want to force upgrading
 
2383
                target[:] = [None, True, True]
 
2384
                return target
 
2385
            try:
 
2386
                target_dir = BzrDir.open(stack_on,
 
2387
                    possible_transports=possible_transports)
 
2388
            except errors.NotBranchError:
 
2389
                # Nothing there, don't change formats
 
2390
                target[:] = [None, True, False]
 
2391
                return target
 
2392
            except errors.JailBreak:
 
2393
                # JailBreak, JFDI and upgrade anyway
 
2394
                target[:] = [None, True, True]
 
2395
                return target
 
2396
            try:
 
2397
                target_branch = target_dir.open_branch()
 
2398
            except errors.NotBranchError:
 
2399
                # No branch, don't upgrade formats
 
2400
                target[:] = [None, True, False]
 
2401
                return target
 
2402
            target[:] = [target_branch, True, False]
 
2403
            return target
 
2404
 
 
2405
        if (not _skip_repo and
 
2406
                 not self.repository_format.supports_external_lookups):
 
2407
            # We need to upgrade the Repository.
 
2408
            target_branch, _, do_upgrade = get_target_branch()
 
2409
            if target_branch is None:
 
2410
                # We don't have a target branch, should we upgrade anyway?
 
2411
                if do_upgrade:
 
2412
                    # stack_on is inaccessible, JFDI.
 
2413
                    # TODO: bad monkey, hard-coded formats...
 
2414
                    if self.repository_format.rich_root_data:
 
2415
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2416
                    else:
 
2417
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
 
2418
            else:
 
2419
                # If the target already supports stacking, then we know the
 
2420
                # project is already able to use stacking, so auto-upgrade
 
2421
                # for them
 
2422
                new_repo_format = target_branch.repository._format
 
2423
                if not new_repo_format.supports_external_lookups:
 
2424
                    # target doesn't, source doesn't, so don't auto upgrade
 
2425
                    # repo
 
2426
                    new_repo_format = None
 
2427
            if new_repo_format is not None:
 
2428
                self.repository_format = new_repo_format
 
2429
                note('Source repository format does not support stacking,'
 
2430
                     ' using format:\n  %s',
 
2431
                     new_repo_format.get_format_description())
 
2432
 
2362
2433
        if not self.get_branch_format().supports_stacking():
2363
 
            # We need to make a stacked branch, but the default format for the
2364
 
            # target doesn't support stacking.  So force a branch that *can*
2365
 
            # support stacking.
2366
 
            from bzrlib.branch import BzrBranchFormat7
2367
 
            branch_format = BzrBranchFormat7()
2368
 
            self.set_branch_format(branch_format)
2369
 
            mutter("using %r for stacking" % (branch_format,))
2370
 
            from bzrlib.repofmt import pack_repo
2371
 
            if self.repository_format.rich_root_data:
2372
 
                bzrdir_format_name = '1.6.1-rich-root'
2373
 
                repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
 
2434
            # We just checked the repo, now lets check if we need to
 
2435
            # upgrade the branch format
 
2436
            target_branch, _, do_upgrade = get_target_branch()
 
2437
            if target_branch is None:
 
2438
                if do_upgrade:
 
2439
                    # TODO: bad monkey, hard-coded formats...
 
2440
                    new_branch_format = branch.BzrBranchFormat7()
2374
2441
            else:
2375
 
                bzrdir_format_name = '1.6'
2376
 
                repo_format = pack_repo.RepositoryFormatKnitPack5()
2377
 
            note('Source format does not support stacking, using format:'
2378
 
                 ' \'%s\'\n  %s\n',
2379
 
                 bzrdir_format_name, repo_format.get_format_description())
2380
 
            self.repository_format = repo_format
 
2442
                new_branch_format = target_branch._format
 
2443
                if not new_branch_format.supports_stacking():
 
2444
                    new_branch_format = None
 
2445
            if new_branch_format is not None:
 
2446
                # Does support stacking, use its format.
 
2447
                self.set_branch_format(new_branch_format)
 
2448
                note('Source branch format does not support stacking,'
 
2449
                     ' using format:\n  %s',
 
2450
                     new_branch_format.get_format_description())
2381
2451
 
2382
2452
    def get_converter(self, format=None):
2383
2453
        """See BzrDirFormat.get_converter()."""
2699
2769
        del ie.text_id
2700
2770
 
2701
2771
    def get_parent_map(self, revision_ids):
2702
 
        """See graph._StackedParentsProvider.get_parent_map"""
 
2772
        """See graph.StackedParentsProvider.get_parent_map"""
2703
2773
        return dict((revision_id, self.revisions[revision_id])
2704
2774
                    for revision_id in revision_ids
2705
2775
                     if revision_id in self.revisions)
3049
3119
            return local_dir_format.initialize_on_transport(transport)
3050
3120
        client = _SmartClient(client_medium)
3051
3121
        path = client.remote_path_from_transport(transport)
3052
 
        response = client.call('BzrDirFormat.initialize', path)
 
3122
        try:
 
3123
            response = client.call('BzrDirFormat.initialize', path)
 
3124
        except errors.ErrorFromSmartServer, err:
 
3125
            remote._translate_error(err, path=path)
3053
3126
        if response[0] != 'ok':
3054
3127
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
3055
3128
        format = RemoteBzrDirFormat()
3103
3176
        if not do_vfs:
3104
3177
            client = _SmartClient(client_medium)
3105
3178
            path = client.remote_path_from_transport(transport)
3106
 
            if client_medium._is_remote_before((1, 15)):
 
3179
            if client_medium._is_remote_before((1, 16)):
3107
3180
                do_vfs = True
3108
3181
        if do_vfs:
3109
3182
            # TODO: lookup the local format from a server hint.
3115
3188
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3116
3189
                make_working_trees=make_working_trees, shared_repo=shared_repo,
3117
3190
                vfs_only=True)
 
3191
        return self._initialize_on_transport_ex_rpc(client, path, transport,
 
3192
            use_existing_dir, create_prefix, force_new_repo, stacked_on,
 
3193
            stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
 
3194
 
 
3195
    def _initialize_on_transport_ex_rpc(self, client, path, transport,
 
3196
        use_existing_dir, create_prefix, force_new_repo, stacked_on,
 
3197
        stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3118
3198
        args = []
3119
3199
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3120
3200
        args.append(self._serialize_NoneTrueFalse(create_prefix))
3136
3216
            self._network_name = \
3137
3217
            BzrDirFormat.get_default_format().network_name()
3138
3218
        try:
3139
 
            response = client.call('BzrDirFormat.initialize_ex',
 
3219
            response = client.call('BzrDirFormat.initialize_ex_1.16',
3140
3220
                self.network_name(), path, *args)
3141
3221
        except errors.UnknownSmartMethod:
 
3222
            client._medium._remember_remote_is_before((1,16))
3142
3223
            local_dir_format = BzrDirMetaFormat1()
3143
3224
            self._supply_sub_formats_to(local_dir_format)
3144
3225
            return local_dir_format.initialize_on_transport_ex(transport,
3147
3228
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3148
3229
                make_working_trees=make_working_trees, shared_repo=shared_repo,
3149
3230
                vfs_only=True)
 
3231
        except errors.ErrorFromSmartServer, err:
 
3232
            remote._translate_error(err, path=path)
3150
3233
        repo_path = response[0]
3151
3234
        bzrdir_name = response[6]
3152
3235
        require_stacking = response[7]
3168
3251
                repo_bzr = bzrdir
3169
3252
            final_stack = response[8] or None
3170
3253
            final_stack_pwd = response[9] or None
 
3254
            if final_stack_pwd:
 
3255
                final_stack_pwd = urlutils.join(
 
3256
                    transport.base, final_stack_pwd)
3171
3257
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3172
3258
            if len(response) > 10:
3173
3259
                # Updated server verb that locks remotely.
3183
3269
        else:
3184
3270
            remote_repo = None
3185
3271
            policy = None
 
3272
        if require_stacking:
 
3273
            # The repo has already been created, but we need to make sure that
 
3274
            # we'll make a stackable branch.
 
3275
            bzrdir._format.require_stacking(_skip_repo=True)
3186
3276
        return remote_repo, bzrdir, require_stacking, policy
3187
3277
 
3188
3278
    def _open(self, transport):
3364
3454
            if info.native:
3365
3455
                help = '(native) ' + help
3366
3456
            return ':%s:\n%s\n\n' % (key,
3367
 
                    textwrap.fill(help, initial_indent='    ',
3368
 
                    subsequent_indent='    '))
 
3457
                textwrap.fill(help, initial_indent='    ',
 
3458
                    subsequent_indent='    ',
 
3459
                    break_long_words=False))
3369
3460
        if default_realkey is not None:
3370
3461
            output += wrapped(default_realkey, '(default) %s' % default_help,
3371
3462
                              self.get_info('default'))
3520
3611
        """
3521
3612
        stack_on = self._get_full_stack_on()
3522
3613
        if stack_on:
3523
 
            # Stacking is desired. requested by the target, but does the place it
3524
 
            # points at support stacking? If it doesn't then we should
3525
 
            # not implicitly upgrade. We check this here.
3526
3614
            format = self._bzrdir._format
3527
 
            if not (format.repository_format.supports_external_lookups
3528
 
                and format.get_branch_format().supports_stacking()):
3529
 
                # May need to upgrade - but only do if the target also
3530
 
                # supports stacking. Note that this currently wastes
3531
 
                # network round trips to check - but we only do this
3532
 
                # when the source can't stack so it will fade away
3533
 
                # as people do upgrade.
3534
 
                branch_format = None
3535
 
                repo_format = None
3536
 
                try:
3537
 
                    target_dir = BzrDir.open(stack_on,
3538
 
                        possible_transports=[self._bzrdir.root_transport])
3539
 
                except errors.NotBranchError:
3540
 
                    # Nothing there, don't change formats
3541
 
                    pass
3542
 
                except errors.JailBreak:
3543
 
                    # stack_on is inaccessible, JFDI.
3544
 
                    if format.repository_format.rich_root_data:
3545
 
                        repo_format = pack_repo.RepositoryFormatKnitPack6RichRoot()
3546
 
                    else:
3547
 
                        repo_format = pack_repo.RepositoryFormatKnitPack6()
3548
 
                    branch_format = branch.BzrBranchFormat7()
3549
 
                else:
3550
 
                    try:
3551
 
                        target_branch = target_dir.open_branch()
3552
 
                    except errors.NotBranchError:
3553
 
                        # No branch, don't change formats
3554
 
                        pass
3555
 
                    else:
3556
 
                        branch_format = target_branch._format
3557
 
                        repo_format = target_branch.repository._format
3558
 
                        if not (branch_format.supports_stacking()
3559
 
                            and repo_format.supports_external_lookups):
3560
 
                            # Doesn't stack itself, don't force an upgrade
3561
 
                            branch_format = None
3562
 
                            repo_format = None
3563
 
                if branch_format and repo_format:
3564
 
                    # Does support stacking, use its format.
3565
 
                    format.repository_format = repo_format
3566
 
                    format.set_branch_format(branch_format)
3567
 
                    note('Source format does not support stacking, '
3568
 
                        'using format: \'%s\'\n  %s\n',
3569
 
                        branch_format.get_format_description(),
3570
 
                        repo_format.get_format_description())
 
3615
            format.require_stacking(stack_on=stack_on,
 
3616
                                    possible_transports=[self._bzrdir.root_transport])
3571
3617
            if not self._require_stacking:
3572
3618
                # We have picked up automatic stacking somewhere.
3573
3619
                note('Using default stacking branch %s at %s', self._stack_on,
3780
3826
    experimental=True,
3781
3827
    )
3782
3828
 
 
3829
format_registry.register_metadir('development7-rich-root',
 
3830
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
 
3831
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
 
3832
        'rich roots. Please read '
 
3833
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
 
3834
        'before use.',
 
3835
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3836
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3837
    hidden=True,
 
3838
    experimental=True,
 
3839
    )
 
3840
 
 
3841
format_registry.register_metadir('2a',
 
3842
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
 
3843
    help='First format for bzr 2.0 series.\n'
 
3844
        'Uses group-compress storage.\n'
 
3845
        'Provides rich roots which are a one-way transition.\n',
 
3846
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
 
3847
        # 'rich roots. Supported by bzr 1.16 and later.',
 
3848
    branch_format='bzrlib.branch.BzrBranchFormat7',
 
3849
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3850
    experimental=True,
 
3851
    )
 
3852
 
3783
3853
# The following format should be an alias for the rich root equivalent 
3784
3854
# of the default format
3785
3855
format_registry.register_metadir('default-rich-root',