~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Robert Collins
  • Date: 2009-04-24 05:08:51 UTC
  • mto: This revision was merged to the branch mainline in revision 4304.
  • Revision ID: robertc@robertcollins.net-20090424050851-sdfonaqerfs386t0
Reduce round trips pushing new branches substantially.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
import bzrlib
39
39
from bzrlib import (
 
40
    branch,
40
41
    config,
41
42
    errors,
42
43
    graph,
61
62
from bzrlib.push import (
62
63
    PushResult,
63
64
    )
 
65
from bzrlib.repofmt import pack_repo
64
66
from bzrlib.smart.client import _SmartClient
65
67
from bzrlib.store.versioned import WeaveStore
66
68
from bzrlib.transactions import WriteTransaction
1856
1858
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1857
1859
        create_prefix=False, force_new_repo=False, stacked_on=None,
1858
1860
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1859
 
        shared_repo=False):
 
1861
        shared_repo=False, vfs_only=False):
1860
1862
        """Create this format on transport.
1861
1863
 
1862
1864
        The directory to initialize will be created.
1879
1881
            default the format has.
1880
1882
        :param shared_repo: Control whether made repositories are shared or
1881
1883
            not.
 
1884
        :param vfs_only: If True do not attempt to use a smart server
1882
1885
        :return: repo, bzrdir, require_stacking, repository_policy. repo is
1883
1886
            None if none was created or found, bzrdir is always valid.
1884
1887
            require_stacking is the result of examining the stacked_on
1885
1888
            parameter and any stacking policy found for the target.
1886
1889
        """
 
1890
        if not vfs_only:
 
1891
            # Try to hand off to a smart server 
 
1892
            try:
 
1893
                client_medium = transport.get_smart_medium()
 
1894
            except errors.NoSmartMedium:
 
1895
                pass
 
1896
            else:
 
1897
                # TODO: lookup the local format from a server hint.
 
1898
                remote_dir_format = RemoteBzrDirFormat()
 
1899
                remote_dir_format._network_name = self.network_name()
 
1900
                self._supply_sub_formats_to(remote_dir_format)
 
1901
                return remote_dir_format.initialize_on_transport_ex(transport,
 
1902
                    use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
1903
                    force_new_repo=force_new_repo, stacked_on=stacked_on,
 
1904
                    stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
1905
                    make_working_trees=make_working_trees, shared_repo=shared_repo)
1887
1906
        # XXX: Refactor the create_prefix/no_create_prefix code into a
1888
1907
        #      common helper function
1889
1908
        # The destination may not exist - if so make it according to policy.
3022
3041
        self._supply_sub_formats_to(format)
3023
3042
        return remote.RemoteBzrDir(transport, format)
3024
3043
 
 
3044
    def parse_NoneTrueFalse(self, arg):
 
3045
        if not arg:
 
3046
            return None
 
3047
        if arg == 'False':
 
3048
            return False
 
3049
        if arg == 'True':
 
3050
            return True
 
3051
        raise AssertionError("invalid arg %r" % arg)
 
3052
 
3025
3053
    def _serialize_NoneTrueFalse(self, arg):
3026
3054
        if arg is False:
3027
3055
            return 'False'
3029
3057
            return 'True'
3030
3058
        return ''
3031
3059
 
 
3060
    def _serialize_NoneString(self, arg):
 
3061
        return arg or ''
 
3062
 
3032
3063
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3033
3064
        create_prefix=False, force_new_repo=False, stacked_on=None,
3034
3065
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3054
3085
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3055
3086
                force_new_repo=force_new_repo, stacked_on=stacked_on,
3056
3087
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3057
 
                make_working_trees=make_working_trees, shared_repo=shared_repo)
3058
 
        if not (create_prefix is False and force_new_repo is False and
3059
 
            stacked_on is None and stack_on_pwd is None and repo_format_name is
3060
 
            None and make_working_trees is None and shared_repo is False):
3061
 
            local_dir_format = BzrDirMetaFormat1()
3062
 
            self._supply_sub_formats_to(local_dir_format)
3063
 
            return local_dir_format.initialize_on_transport_ex(transport,
3064
 
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3065
 
                force_new_repo=force_new_repo, stacked_on=stacked_on,
3066
 
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3067
 
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
3088
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3089
                vfs_only=True)
3068
3090
        args = []
3069
3091
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
 
3092
        args.append(self._serialize_NoneTrueFalse(create_prefix))
 
3093
        args.append(self._serialize_NoneTrueFalse(force_new_repo))
 
3094
        args.append(self._serialize_NoneString(stacked_on))
 
3095
        # stack_on_pwd is often/usually our transport
 
3096
        if stack_on_pwd:
 
3097
            try:
 
3098
                stack_on_pwd = transport.relpath(stack_on_pwd)
 
3099
                if not stack_on_pwd:
 
3100
                    stack_on_pwd = '.'
 
3101
            except errors.PathNotChild:
 
3102
                pass
 
3103
        args.append(self._serialize_NoneString(stack_on_pwd))
 
3104
        args.append(self._serialize_NoneString(repo_format_name))
 
3105
        args.append(self._serialize_NoneTrueFalse(make_working_trees))
 
3106
        args.append(self._serialize_NoneTrueFalse(shared_repo))
 
3107
        if self._network_name is None:
 
3108
            self._network_name = \
 
3109
            BzrDirFormat.get_default_format().network_name()
3070
3110
        try:
3071
 
            response = client.call('BzrDirFormat.initialize_ex', path, *args)
 
3111
            response = client.call('BzrDirFormat.initialize_ex',
 
3112
                self.network_name(), path, *args)
3072
3113
        except errors.UnknownSmartMethod:
3073
3114
            local_dir_format = BzrDirMetaFormat1()
3074
3115
            self._supply_sub_formats_to(local_dir_format)
3076
3117
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3077
3118
                force_new_repo=force_new_repo, stacked_on=stacked_on,
3078
3119
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3079
 
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
3120
                make_working_trees=make_working_trees, shared_repo=shared_repo,
 
3121
                vfs_only=True)
 
3122
        repo_path = response[0]
 
3123
        bzrdir_name = response[6]
 
3124
        require_stacking = response[7]
 
3125
        require_stacking = self.parse_NoneTrueFalse(require_stacking)
3080
3126
        format = RemoteBzrDirFormat()
 
3127
        format._network_name = bzrdir_name
3081
3128
        self._supply_sub_formats_to(format)
3082
 
        return None, remote.RemoteBzrDir(transport, format), None, None
 
3129
        bzrdir = remote.RemoteBzrDir(transport, format)
 
3130
        if repo_path:
 
3131
            repo_format = remote.response_tuple_to_repo_format(response[1:])
 
3132
            if repo_path == '.':
 
3133
                repo_path = ''
 
3134
            if repo_path:
 
3135
                repo_bzrdir_format = RemoteBzrDirFormat()
 
3136
                repo_bzrdir_format._network_name = response[5]
 
3137
                repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
 
3138
                    repo_bzrdir_format)
 
3139
            else:
 
3140
                repo_bzr = bzrdir
 
3141
            final_stack = response[8] or None
 
3142
            final_stack_pwd = response[9] or None
 
3143
            remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
 
3144
            policy = UseExistingRepository(remote_repo, final_stack,
 
3145
                final_stack_pwd, require_stacking)
 
3146
            policy.acquire_repository()
 
3147
        else:
 
3148
            remote_repo = None
 
3149
            policy = None
 
3150
        return remote_repo, bzrdir, require_stacking, policy
3083
3151
 
3084
3152
    def _open(self, transport):
3085
3153
        return remote.RemoteBzrDir(transport, self)
3360
3428
        stack_on = self._get_full_stack_on()
3361
3429
        if stack_on is None:
3362
3430
            return
3363
 
        stacked_dir = BzrDir.open(stack_on,
3364
 
                                  possible_transports=possible_transports)
 
3431
        try:
 
3432
            stacked_dir = BzrDir.open(stack_on,
 
3433
                                      possible_transports=possible_transports)
 
3434
        except errors.JailBreak:
 
3435
            # We keep the stacking details, but we are in the server code so
 
3436
            # actually stacking is not needed.
 
3437
            return
3365
3438
        try:
3366
3439
            stacked_repo = stacked_dir.open_branch().repository
3367
3440
        except errors.NotBranchError:
3422
3495
                # network round trips to check - but we only do this
3423
3496
                # when the source can't stack so it will fade away
3424
3497
                # as people do upgrade.
 
3498
                branch_format = None
 
3499
                repo_format = None
3425
3500
                try:
3426
3501
                    target_dir = BzrDir.open(stack_on,
3427
3502
                        possible_transports=[self._bzrdir.root_transport])
3428
3503
                except errors.NotBranchError:
3429
3504
                    # Nothing there, don't change formats
3430
3505
                    pass
 
3506
                except errors.JailBreak:
 
3507
                    # stack_on is inaccessible, JFDI.
 
3508
                    if format.repository_format.rich_root_data:
 
3509
                        repo_format = pack_repo.RepositoryFormatKnitPack6RichRoot()
 
3510
                    else:
 
3511
                        repo_format = pack_repo.RepositoryFormatKnitPack6()
 
3512
                    branch_format = branch.BzrBranchFormat7()
3431
3513
                else:
3432
3514
                    try:
3433
3515
                        target_branch = target_dir.open_branch()
3440
3522
                        if not (branch_format.supports_stacking()
3441
3523
                            and repo_format.supports_external_lookups):
3442
3524
                            # Doesn't stack itself, don't force an upgrade
3443
 
                            pass
3444
 
                        else:
3445
 
                            # Does support stacking, use its format.
3446
 
                            format.repository_format = repo_format
3447
 
                            format.set_branch_format(branch_format)
3448
 
                            note('Source format does not support stacking, '
3449
 
                                'using format: \'%s\'\n  %s\n',
3450
 
                                branch_format.get_format_description(),
3451
 
                                repo_format.get_format_description())
 
3525
                            branch_format = None
 
3526
                            repo_format = None
 
3527
                if branch_format and repo_format:
 
3528
                    # Does support stacking, use its format.
 
3529
                    format.repository_format = repo_format
 
3530
                    format.set_branch_format(branch_format)
 
3531
                    note('Source format does not support stacking, '
 
3532
                        'using format: \'%s\'\n  %s\n',
 
3533
                        branch_format.get_format_description(),
 
3534
                        repo_format.get_format_description())
3452
3535
            if not self._require_stacking:
3453
3536
                # We have picked up automatic stacking somewhere.
3454
3537
                note('Using default stacking branch %s at %s', self._stack_on,