~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 00:45:11 UTC
  • mto: This revision was merged to the branch mainline in revision 4304.
  • Revision ID: robertc@robertcollins.net-20090424004511-8oszlwmvehlqwrla
Start building up a BzrDir.initialize_ex verb for the smart server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1859
1859
        shared_repo=False):
1860
1860
        """Create this format on transport.
1861
1861
 
 
1862
        The directory to initialize will be created.
 
1863
 
1862
1864
        :param force_new_repo: Do not use a shared repository for the target,
1863
1865
                               even if one is available.
1864
1866
        :param create_prefix: Create any missing directories leading up to
2956
2958
        return to_convert
2957
2959
 
2958
2960
 
2959
 
# This is not in remote.py because it's small, and needs to be registered.
2960
 
# Putting it in remote.py creates a circular import problem.
 
2961
# This is not in remote.py because it's relatively small, and needs to be
 
2962
# registered. Putting it in remote.py creates a circular import problem.
2961
2963
# we can make it a lazy object if the control formats is turned into something
2962
2964
# like a registry.
2963
2965
class RemoteBzrDirFormat(BzrDirMetaFormat1):
3020
3022
        self._supply_sub_formats_to(format)
3021
3023
        return remote.RemoteBzrDir(transport, format)
3022
3024
 
 
3025
    def _serialize_NoneTrueFalse(self, arg):
 
3026
        if arg is False:
 
3027
            return 'False'
 
3028
        if arg:
 
3029
            return 'True'
 
3030
        return ''
 
3031
 
 
3032
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
 
3033
        create_prefix=False, force_new_repo=False, stacked_on=None,
 
3034
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
3035
        shared_repo=False):
 
3036
        try:
 
3037
            # hand off the request to the smart server
 
3038
            client_medium = transport.get_smart_medium()
 
3039
        except errors.NoSmartMedium:
 
3040
            # TODO: lookup the local format from a server hint.
 
3041
            local_dir_format = BzrDirMetaFormat1()
 
3042
            self._supply_sub_formats_to(local_dir_format)
 
3043
            return local_dir_format.initialize_on_transport_ex(transport,
 
3044
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3045
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3046
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3047
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
3048
        client = _SmartClient(client_medium)
 
3049
        path = client.remote_path_from_transport(transport)
 
3050
        if client_medium._is_remote_before((1, 15)):
 
3051
            local_dir_format = BzrDirMetaFormat1()
 
3052
            self._supply_sub_formats_to(local_dir_format)
 
3053
            return local_dir_format.initialize_on_transport_ex(transport,
 
3054
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3055
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3056
                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)
 
3068
        args = []
 
3069
        args.append(self._serialize_NoneTrueFalse(use_existing_dir))
 
3070
        try:
 
3071
            response = client.call('BzrDirFormat.initialize_ex', path, *args)
 
3072
        except errors.UnknownSmartMethod:
 
3073
            local_dir_format = BzrDirMetaFormat1()
 
3074
            self._supply_sub_formats_to(local_dir_format)
 
3075
            return local_dir_format.initialize_on_transport_ex(transport,
 
3076
                use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
3077
                force_new_repo=force_new_repo, stacked_on=stacked_on,
 
3078
                stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
3079
                make_working_trees=make_working_trees, shared_repo=shared_repo)
 
3080
        format = RemoteBzrDirFormat()
 
3081
        self._supply_sub_formats_to(format)
 
3082
        return None, remote.RemoteBzrDir(transport, format), None, None
 
3083
 
3023
3084
    def _open(self, transport):
3024
3085
        return remote.RemoteBzrDir(transport, self)
3025
3086