/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/smart/bzrdir.py

merge bzr.dev r4054

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Server-side bzrdir related request implmentations."""
18
18
 
19
19
 
20
 
from bzrlib import errors
 
20
from bzrlib import branch, errors, repository
21
21
from bzrlib.bzrdir import BzrDir, BzrDirFormat
22
22
from bzrlib.smart.request import (
23
23
    FailedSmartServerResponse,
51
51
        return SuccessfulSmartServerResponse((answer,))
52
52
 
53
53
 
54
 
class SmartServerRequestFindRepository(SmartServerRequest):
 
54
class SmartServerRequestBzrDir(SmartServerRequest):
55
55
 
56
56
    def _boolean_to_yes_no(self, a_boolean):
57
57
        if a_boolean:
59
59
        else:
60
60
            return 'no'
61
61
 
 
62
    def _format_to_capabilities(self, repo_format):
 
63
        rich_root = self._boolean_to_yes_no(repo_format.rich_root_data)
 
64
        tree_ref = self._boolean_to_yes_no(
 
65
            repo_format.supports_tree_reference)
 
66
        external_lookup = self._boolean_to_yes_no(
 
67
            repo_format.supports_external_lookups)
 
68
        return rich_root, tree_ref, external_lookup
 
69
 
 
70
    def _repo_relpath(self, current_transport, repository):
 
71
        """Get the relative path for repository from current_transport."""
 
72
        # the relpath of the bzrdir in the found repository gives us the
 
73
        # path segments to pop-out.
 
74
        relpath = repository.bzrdir.root_transport.relpath(
 
75
            current_transport.base)
 
76
        if len(relpath):
 
77
            segments = ['..'] * len(relpath.split('/'))
 
78
        else:
 
79
            segments = []
 
80
        return '/'.join(segments)
 
81
 
 
82
 
 
83
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
 
84
 
 
85
    def do(self, path, network_name):
 
86
        """Create a branch in the bzr dir at path.
 
87
 
 
88
        This operates precisely like 'bzrdir.create_branch'.
 
89
 
 
90
        If a bzrdir is not present, an exception is propogated
 
91
        rather than 'no branch' because these are different conditions (and
 
92
        this method should only be called after establishing that a bzr dir
 
93
        exists anyway).
 
94
 
 
95
        This is the initial version of this method introduced to the smart
 
96
        server for 1.13.
 
97
 
 
98
        :param path: The path to the bzrdir.
 
99
        :param network_name: The network name of the branch type to create.
 
100
        :return: (ok, network_name)
 
101
        """
 
102
        bzrdir = BzrDir.open_from_transport(
 
103
            self.transport_from_client_path(path))
 
104
        format = branch.network_format_registry.get(network_name)
 
105
        bzrdir.branch_format = format
 
106
        result = format.initialize(bzrdir)
 
107
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
108
            result.repository._format)
 
109
        branch_format = result._format.network_name()
 
110
        repo_format = result.repository._format.network_name()
 
111
        repo_path = self._repo_relpath(bzrdir.root_transport,
 
112
            result.repository)
 
113
        # branch format, repo relpath, rich_root, tree_ref, external_lookup,
 
114
        # repo_network_name
 
115
        return SuccessfulSmartServerResponse(('ok', branch_format, repo_path,
 
116
            rich_root, tree_ref, external_lookup, repo_format))
 
117
 
 
118
 
 
119
class SmartServerRequestCreateRepository(SmartServerRequestBzrDir):
 
120
 
 
121
    def do(self, path, network_name, shared):
 
122
        """Create a repository in the bzr dir at path.
 
123
 
 
124
        This operates precisely like 'bzrdir.create_repository'.
 
125
 
 
126
        If a bzrdir is not present, an exception is propogated
 
127
        rather than 'no branch' because these are different conditions (and
 
128
        this method should only be called after establishing that a bzr dir
 
129
        exists anyway).
 
130
 
 
131
        This is the initial version of this method introduced to the smart
 
132
        server for 1.13.
 
133
 
 
134
        :param path: The path to the bzrdir.
 
135
        :param network_name: The network name of the repository type to create.
 
136
        :param shared: The value to pass create_repository for the shared
 
137
            parameter.
 
138
        :return: (ok, rich_root, tree_ref, external_lookup, network_name)
 
139
        """
 
140
        bzrdir = BzrDir.open_from_transport(
 
141
            self.transport_from_client_path(path))
 
142
        shared = shared == 'True'
 
143
        format = repository.network_format_registry.get(network_name)
 
144
        bzrdir.repository_format = format
 
145
        result = format.initialize(bzrdir, shared=shared)
 
146
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
147
            result._format)
 
148
        return SuccessfulSmartServerResponse(('ok', rich_root, tree_ref,
 
149
            external_lookup, result._format.network_name()))
 
150
 
 
151
 
 
152
class SmartServerRequestFindRepository(SmartServerRequestBzrDir):
 
153
 
62
154
    def _find(self, path):
63
155
        """try to find a repository from path upwards
64
 
        
 
156
 
65
157
        This operates precisely like 'bzrdir.find_repository'.
66
 
        
 
158
 
67
159
        :return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
68
160
            strings, relpath is a / prefixed path, and the other three are
69
161
            either 'yes' or 'no'.
73
165
        bzrdir = BzrDir.open_from_transport(
74
166
            self.transport_from_client_path(path))
75
167
        repository = bzrdir.find_repository()
76
 
        # the relpath of the bzrdir in the found repository gives us the 
77
 
        # path segments to pop-out.
78
 
        relpath = repository.bzrdir.root_transport.relpath(
79
 
            bzrdir.root_transport.base)
80
 
        if len(relpath):
81
 
            segments = ['..'] * len(relpath.split('/'))
82
 
        else:
83
 
            segments = []
84
 
        rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
85
 
        tree_ref = self._boolean_to_yes_no(
86
 
            repository._format.supports_tree_reference)
87
 
        external_lookup = self._boolean_to_yes_no(
88
 
            repository._format.supports_external_lookups)
89
 
        return '/'.join(segments), rich_root, tree_ref, external_lookup
 
168
        path = self._repo_relpath(bzrdir.root_transport, repository)
 
169
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
170
            repository._format)
 
171
        return path, rich_root, tree_ref, external_lookup
90
172
 
91
173
 
92
174
class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):
93
175
 
94
176
    def do(self, path):
95
177
        """try to find a repository from path upwards
96
 
        
 
178
 
97
179
        This operates precisely like 'bzrdir.find_repository'.
98
 
        
 
180
 
99
181
        If a bzrdir is not present, an exception is propogated
100
182
        rather than 'no branch' because these are different conditions.
101
183
 
116
198
 
117
199
    def do(self, path):
118
200
        """try to find a repository from path upwards
119
 
        
 
201
 
120
202
        This operates precisely like 'bzrdir.find_repository'.
121
 
        
 
203
 
122
204
        If a bzrdir is not present, an exception is propogated
123
205
        rather than 'no branch' because these are different conditions.
124
206
 
153
235
 
154
236
    def do(self, path):
155
237
        """try to open a branch at path and return ok/nobranch.
156
 
        
 
238
 
157
239
        If a bzrdir is not present, an exception is propogated
158
240
        rather than 'no branch' because these are different conditions.
159
241
        """