~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-23 05:12:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4474.
  • Revision ID: mnordhoff@mattnordhoff.com-20090623051207-fksdtbzkwtnrw9dd
Update _add_text docstrings that still referred to add_text.

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,
73
74
    )
74
75
from bzrlib.weave import Weave
75
76
""")
77
78
from bzrlib.trace import (
78
79
    mutter,
79
80
    note,
80
 
    warning,
81
81
    )
82
82
 
83
83
from bzrlib import (
129
129
        return True
130
130
 
131
131
    def check_conversion_target(self, target_format):
132
 
        """Check that a bzrdir as a whole can be converted to a new format."""
133
 
        # The only current restriction is that the repository content can be 
134
 
        # fetched compatibly with the target.
135
132
        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
 
133
        source_repo_format = self._format.repository_format
 
134
        source_repo_format.check_conversion_target(target_repo_format)
142
135
 
143
136
    @staticmethod
144
137
    def _check_supported(format, allow_unsupported,
1241
1234
        return result
1242
1235
 
1243
1236
    def push_branch(self, source, revision_id=None, overwrite=False, 
1244
 
        remember=False, create_prefix=False):
 
1237
        remember=False):
1245
1238
        """Push the source branch into this BzrDir."""
1246
1239
        br_to = None
1247
1240
        # If we can open a branch, use its direct repository, otherwise see
1392
1385
        # that can do wonky stuff here, and that only
1393
1386
        # happens for creating checkouts, which cannot be
1394
1387
        # done on this format anyway. So - acceptable wart.
1395
 
        if hardlink:
1396
 
            warning("can't support hardlinked working trees in %r"
1397
 
                % (self,))
1398
1388
        try:
1399
1389
            result = self.open_workingtree(recommend_upgrade=False)
1400
1390
        except errors.NoSuchFile:
1641
1631
 
1642
1632
    def get_branch_transport(self, branch_format):
1643
1633
        """See BzrDir.get_branch_transport()."""
1644
 
        # XXX: this shouldn't implicitly create the directory if it's just
1645
 
        # promising to get a transport -- mbp 20090727
1646
1634
        if branch_format is None:
1647
1635
            return self.transport.clone('branch')
1648
1636
        try:
2370
2358
    def set_branch_format(self, format):
2371
2359
        self._branch_format = format
2372
2360
 
2373
 
    def require_stacking(self, stack_on=None, possible_transports=None,
2374
 
            _skip_repo=False):
2375
 
        """We have a request to stack, try to ensure the formats support it.
2376
 
 
2377
 
        :param stack_on: If supplied, it is the URL to a branch that we want to
2378
 
            stack on. Check to see if that format supports stacking before
2379
 
            forcing an upgrade.
2380
 
        """
2381
 
        # Stacking is desired. requested by the target, but does the place it
2382
 
        # points at support stacking? If it doesn't then we should
2383
 
        # not implicitly upgrade. We check this here.
2384
 
        new_repo_format = None
2385
 
        new_branch_format = None
2386
 
 
2387
 
        # a bit of state for get_target_branch so that we don't try to open it
2388
 
        # 2 times, for both repo *and* branch
2389
 
        target = [None, False, None] # target_branch, checked, upgrade anyway
2390
 
        def get_target_branch():
2391
 
            if target[1]:
2392
 
                # We've checked, don't check again
2393
 
                return target
2394
 
            if stack_on is None:
2395
 
                # No target format, that means we want to force upgrading
2396
 
                target[:] = [None, True, True]
2397
 
                return target
2398
 
            try:
2399
 
                target_dir = BzrDir.open(stack_on,
2400
 
                    possible_transports=possible_transports)
2401
 
            except errors.NotBranchError:
2402
 
                # Nothing there, don't change formats
2403
 
                target[:] = [None, True, False]
2404
 
                return target
2405
 
            except errors.JailBreak:
2406
 
                # JailBreak, JFDI and upgrade anyway
2407
 
                target[:] = [None, True, True]
2408
 
                return target
2409
 
            try:
2410
 
                target_branch = target_dir.open_branch()
2411
 
            except errors.NotBranchError:
2412
 
                # No branch, don't upgrade formats
2413
 
                target[:] = [None, True, False]
2414
 
                return target
2415
 
            target[:] = [target_branch, True, False]
2416
 
            return target
2417
 
 
2418
 
        if (not _skip_repo and
2419
 
                 not self.repository_format.supports_external_lookups):
2420
 
            # We need to upgrade the Repository.
2421
 
            target_branch, _, do_upgrade = get_target_branch()
2422
 
            if target_branch is None:
2423
 
                # We don't have a target branch, should we upgrade anyway?
2424
 
                if do_upgrade:
2425
 
                    # stack_on is inaccessible, JFDI.
2426
 
                    # TODO: bad monkey, hard-coded formats...
2427
 
                    if self.repository_format.rich_root_data:
2428
 
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2429
 
                    else:
2430
 
                        new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2431
 
            else:
2432
 
                # If the target already supports stacking, then we know the
2433
 
                # project is already able to use stacking, so auto-upgrade
2434
 
                # for them
2435
 
                new_repo_format = target_branch.repository._format
2436
 
                if not new_repo_format.supports_external_lookups:
2437
 
                    # target doesn't, source doesn't, so don't auto upgrade
2438
 
                    # repo
2439
 
                    new_repo_format = None
2440
 
            if new_repo_format is not None:
2441
 
                self.repository_format = new_repo_format
2442
 
                note('Source repository format does not support stacking,'
2443
 
                     ' using format:\n  %s',
2444
 
                     new_repo_format.get_format_description())
2445
 
 
 
2361
    def require_stacking(self):
2446
2362
        if not self.get_branch_format().supports_stacking():
2447
 
            # We just checked the repo, now lets check if we need to
2448
 
            # upgrade the branch format
2449
 
            target_branch, _, do_upgrade = get_target_branch()
2450
 
            if target_branch is None:
2451
 
                if do_upgrade:
2452
 
                    # TODO: bad monkey, hard-coded formats...
2453
 
                    new_branch_format = branch.BzrBranchFormat7()
 
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()
2454
2374
            else:
2455
 
                new_branch_format = target_branch._format
2456
 
                if not new_branch_format.supports_stacking():
2457
 
                    new_branch_format = None
2458
 
            if new_branch_format is not None:
2459
 
                # Does support stacking, use its format.
2460
 
                self.set_branch_format(new_branch_format)
2461
 
                note('Source branch format does not support stacking,'
2462
 
                     ' using format:\n  %s',
2463
 
                     new_branch_format.get_format_description())
 
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
2464
2381
 
2465
2382
    def get_converter(self, format=None):
2466
2383
        """See BzrDirFormat.get_converter()."""
2782
2699
        del ie.text_id
2783
2700
 
2784
2701
    def get_parent_map(self, revision_ids):
2785
 
        """See graph.StackedParentsProvider.get_parent_map"""
 
2702
        """See graph._StackedParentsProvider.get_parent_map"""
2786
2703
        return dict((revision_id, self.revisions[revision_id])
2787
2704
                    for revision_id in revision_ids
2788
2705
                     if revision_id in self.revisions)
3046
2963
                      new is _mod_branch.BzrBranchFormat8):
3047
2964
                    branch_converter = _mod_branch.Converter7to8()
3048
2965
                else:
3049
 
                    raise errors.BadConversionTarget("No converter", new,
3050
 
                        branch._format)
 
2966
                    raise errors.BadConversionTarget("No converter", new)
3051
2967
                branch_converter.convert(branch)
3052
2968
                branch = self.bzrdir.open_branch()
3053
2969
                old = branch._format.__class__
3133
3049
            return local_dir_format.initialize_on_transport(transport)
3134
3050
        client = _SmartClient(client_medium)
3135
3051
        path = client.remote_path_from_transport(transport)
3136
 
        try:
3137
 
            response = client.call('BzrDirFormat.initialize', path)
3138
 
        except errors.ErrorFromSmartServer, err:
3139
 
            remote._translate_error(err, path=path)
 
3052
        response = client.call('BzrDirFormat.initialize', path)
3140
3053
        if response[0] != 'ok':
3141
3054
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
3142
3055
        format = RemoteBzrDirFormat()
3190
3103
        if not do_vfs:
3191
3104
            client = _SmartClient(client_medium)
3192
3105
            path = client.remote_path_from_transport(transport)
3193
 
            if client_medium._is_remote_before((1, 16)):
 
3106
            if client_medium._is_remote_before((1, 15)):
3194
3107
                do_vfs = True
3195
3108
        if do_vfs:
3196
3109
            # TODO: lookup the local format from a server hint.
3202
3115
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3203
3116
                make_working_trees=make_working_trees, shared_repo=shared_repo,
3204
3117
                vfs_only=True)
3205
 
        return self._initialize_on_transport_ex_rpc(client, path, transport,
3206
 
            use_existing_dir, create_prefix, force_new_repo, stacked_on,
3207
 
            stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
3208
 
 
3209
 
    def _initialize_on_transport_ex_rpc(self, client, path, transport,
3210
 
        use_existing_dir, create_prefix, force_new_repo, stacked_on,
3211
 
        stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3212
3118
        args = []
3213
3119
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3214
3120
        args.append(self._serialize_NoneTrueFalse(create_prefix))
3230
3136
            self._network_name = \
3231
3137
            BzrDirFormat.get_default_format().network_name()
3232
3138
        try:
3233
 
            response = client.call('BzrDirFormat.initialize_ex_1.16',
 
3139
            response = client.call('BzrDirFormat.initialize_ex',
3234
3140
                self.network_name(), path, *args)
3235
3141
        except errors.UnknownSmartMethod:
3236
 
            client._medium._remember_remote_is_before((1,16))
3237
3142
            local_dir_format = BzrDirMetaFormat1()
3238
3143
            self._supply_sub_formats_to(local_dir_format)
3239
3144
            return local_dir_format.initialize_on_transport_ex(transport,
3242
3147
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3243
3148
                make_working_trees=make_working_trees, shared_repo=shared_repo,
3244
3149
                vfs_only=True)
3245
 
        except errors.ErrorFromSmartServer, err:
3246
 
            remote._translate_error(err, path=path)
3247
3150
        repo_path = response[0]
3248
3151
        bzrdir_name = response[6]
3249
3152
        require_stacking = response[7]
3265
3168
                repo_bzr = bzrdir
3266
3169
            final_stack = response[8] or None
3267
3170
            final_stack_pwd = response[9] or None
3268
 
            if final_stack_pwd:
3269
 
                final_stack_pwd = urlutils.join(
3270
 
                    transport.base, final_stack_pwd)
3271
3171
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3272
3172
            if len(response) > 10:
3273
3173
                # Updated server verb that locks remotely.
3283
3183
        else:
3284
3184
            remote_repo = None
3285
3185
            policy = None
3286
 
        bzrdir._format.set_branch_format(self.get_branch_format())
3287
 
        if require_stacking:
3288
 
            # The repo has already been created, but we need to make sure that
3289
 
            # we'll make a stackable branch.
3290
 
            bzrdir._format.require_stacking(_skip_repo=True)
3291
3186
        return remote_repo, bzrdir, require_stacking, policy
3292
3187
 
3293
3188
    def _open(self, transport):
3469
3364
            if info.native:
3470
3365
                help = '(native) ' + help
3471
3366
            return ':%s:\n%s\n\n' % (key,
3472
 
                textwrap.fill(help, initial_indent='    ',
3473
 
                    subsequent_indent='    ',
3474
 
                    break_long_words=False))
 
3367
                    textwrap.fill(help, initial_indent='    ',
 
3368
                    subsequent_indent='    '))
3475
3369
        if default_realkey is not None:
3476
3370
            output += wrapped(default_realkey, '(default) %s' % default_help,
3477
3371
                              self.get_info('default'))
3556
3450
            if self._require_stacking:
3557
3451
                raise
3558
3452
 
3559
 
    def requires_stacking(self):
3560
 
        """Return True if this policy requires stacking."""
3561
 
        return self._stack_on is not None and self._require_stacking
3562
 
 
3563
3453
    def _get_full_stack_on(self):
3564
3454
        """Get a fully-qualified URL for the stack_on location."""
3565
3455
        if self._stack_on is None:
3630
3520
        """
3631
3521
        stack_on = self._get_full_stack_on()
3632
3522
        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.
3633
3526
            format = self._bzrdir._format
3634
 
            format.require_stacking(stack_on=stack_on,
3635
 
                                    possible_transports=[self._bzrdir.root_transport])
 
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())
3636
3571
            if not self._require_stacking:
3637
3572
                # We have picked up automatic stacking somewhere.
3638
3573
                note('Using default stacking branch %s at %s', self._stack_on,
3845
3780
    experimental=True,
3846
3781
    )
3847
3782
 
3848
 
format_registry.register_metadir('development7-rich-root',
3849
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3850
 
    help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3851
 
        'rich roots. Please read '
3852
 
        'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3853
 
        'before use.',
3854
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3855
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3856
 
    hidden=True,
3857
 
    experimental=True,
3858
 
    )
3859
 
 
3860
 
format_registry.register_metadir('2a',
3861
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3862
 
    help='First format for bzr 2.0 series.\n'
3863
 
        'Uses group-compress storage.\n'
3864
 
        'Provides rich roots which are a one-way transition.\n',
3865
 
        # 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3866
 
        # 'rich roots. Supported by bzr 1.16 and later.',
3867
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3868
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3869
 
    experimental=True,
3870
 
    )
3871
 
 
3872
3783
# The following format should be an alias for the rich root equivalent 
3873
3784
# of the default format
3874
3785
format_registry.register_metadir('default-rich-root',
3875
 
    'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3876
 
    branch_format='bzrlib.branch.BzrBranchFormat7',
3877
 
    tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
3786
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
 
3787
    help='Default format, rich root variant. (needed for bzr-svn and bzr-git).',
 
3788
    branch_format='bzrlib.branch.BzrBranchFormat6',
 
3789
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3878
3790
    alias=True,
3879
 
    help='Same as 2a.')
3880
 
 
 
3791
    )
3881
3792
# The current format that is made on 'bzr init'.
3882
 
format_registry.set_default('2a')
 
3793
format_registry.set_default('pack-0.92')