~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.bzrdir import (
22
22
    BzrDir,
23
23
    BzrDirFormat,
24
 
    BzrDirMetaFormat1,
25
24
    BzrProber,
26
25
    )
27
26
from bzrlib.controldir import (
86
85
class SmartServerRequestBzrDir(SmartServerRequest):
87
86
 
88
87
    def do(self, path, *args):
89
 
        """Open a BzrDir at path, and return self.do_bzrdir_request(*args)."""
 
88
        """Open a BzrDir at path, and return `self.do_bzrdir_request(*args)`."""
90
89
        try:
91
90
            self._bzrdir = BzrDir.open_from_transport(
92
91
                self.transport_from_client_path(path))
121
120
        return '/'.join(segments)
122
121
 
123
122
 
 
123
class SmartServerBzrDirRequestDestroyBranch(SmartServerRequestBzrDir):
 
124
 
 
125
    def do_bzrdir_request(self, name=None):
 
126
        """Destroy the branch with the specified name.
 
127
 
 
128
        New in 2.5.0.
 
129
        :return: On success, 'ok'.
 
130
        """
 
131
        try:
 
132
            self._bzrdir.destroy_branch(name)
 
133
        except errors.NotBranchError, e:
 
134
            return FailedSmartServerResponse(('nobranch',))
 
135
        return SuccessfulSmartServerResponse(('ok',))
 
136
 
 
137
 
 
138
class SmartServerBzrDirRequestHasWorkingTree(SmartServerRequestBzrDir):
 
139
 
 
140
    def do_bzrdir_request(self, name=None):
 
141
        """Check whether there is a working tree present.
 
142
 
 
143
        New in 2.5.0.
 
144
 
 
145
        :return: If there is a working tree present, 'yes'.
 
146
            Otherwise 'no'.
 
147
        """
 
148
        if self._bzrdir.has_workingtree():
 
149
            return SuccessfulSmartServerResponse(('yes', ))
 
150
        else:
 
151
            return SuccessfulSmartServerResponse(('no', ))
 
152
 
 
153
 
 
154
class SmartServerBzrDirRequestDestroyRepository(SmartServerRequestBzrDir):
 
155
 
 
156
    def do_bzrdir_request(self, name=None):
 
157
        """Destroy the repository.
 
158
 
 
159
        New in 2.5.0.
 
160
 
 
161
        :return: On success, 'ok'.
 
162
        """
 
163
        try:
 
164
            self._bzrdir.destroy_repository()
 
165
        except errors.NoRepositoryPresent, e:
 
166
            return FailedSmartServerResponse(('norepository',))
 
167
        return SuccessfulSmartServerResponse(('ok',))
 
168
 
 
169
 
124
170
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
125
171
 
126
172
    def do_bzrdir_request(self, require_stacking):
150
196
        control_format = self._bzrdir.cloning_metadir(
151
197
            require_stacking=require_stacking)
152
198
        control_name = control_format.network_name()
153
 
        # XXX: There should be a method that tells us that the format does/does
154
 
        # not have subformats.
155
 
        if isinstance(control_format, BzrDirMetaFormat1):
 
199
        if not control_format.fixed_components:
156
200
            branch_name = ('branch',
157
201
                control_format.get_branch_format().network_name())
158
202
            repository_name = control_format.repository_format.network_name()
164
208
            branch_name))
165
209
 
166
210
 
 
211
class SmartServerBzrDirRequestCheckoutMetaDir(SmartServerRequestBzrDir):
 
212
    """Get the format to use for checkouts.
 
213
 
 
214
    New in 2.5.
 
215
 
 
216
    :return: on success, a 3-tuple of network names for (control,
 
217
        repository, branch) directories, where '' signifies "not present".
 
218
        If this BzrDir contains a branch reference then this will fail with
 
219
        BranchReference; clients should resolve branch references before
 
220
        calling this RPC (they should not try to create a checkout of a
 
221
        checkout).
 
222
    """
 
223
 
 
224
    def do_bzrdir_request(self):
 
225
        try:
 
226
            branch_ref = self._bzrdir.get_branch_reference()
 
227
        except errors.NotBranchError:
 
228
            branch_ref = None
 
229
        if branch_ref is not None:
 
230
            # The server shouldn't try to resolve references, and it quite
 
231
            # possibly can't reach them anyway.  The client needs to resolve
 
232
            # the branch reference to determine the cloning_metadir.
 
233
            return FailedSmartServerResponse(('BranchReference',))
 
234
        control_format = self._bzrdir.checkout_metadir()
 
235
        control_name = control_format.network_name()
 
236
        if not control_format.fixed_components:
 
237
            branch_name = control_format.get_branch_format().network_name()
 
238
            repo_name = control_format.repository_format.network_name()
 
239
        else:
 
240
            branch_name = ''
 
241
            repo_name = ''
 
242
        return SuccessfulSmartServerResponse(
 
243
            (control_name, repo_name, branch_name))
 
244
 
 
245
 
167
246
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
168
247
 
169
248
    def do(self, path, network_name):
181
260
 
182
261
        :param path: The path to the bzrdir.
183
262
        :param network_name: The network name of the branch type to create.
184
 
        :return: (ok, network_name)
 
263
        :return: ('ok', branch_format, repo_path, rich_root, tree_ref,
 
264
            external_lookup, repo_format)
185
265
        """
186
266
        bzrdir = BzrDir.open_from_transport(
187
267
            self.transport_from_client_path(path))