~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Patch Queue Manager
  • Date: 2015-12-17 18:39:00 UTC
  • mfrom: (6606.1.2 fix-float)
  • Revision ID: pqm@pqm.ubuntu.com-20151217183900-0719du2uv1kwu3lc
(vila) Inline testtools private method to fix an issue in xenial (the
 private implementation has changed in an backward incompatible way).
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Server-side bzrdir related request implmentations."""
18
18
 
 
19
from __future__ import absolute_import
19
20
 
20
 
from bzrlib import branch, errors, repository, urlutils
 
21
from bzrlib import (
 
22
    bencode,
 
23
    branch,
 
24
    errors,
 
25
    repository,
 
26
    urlutils,
 
27
    )
21
28
from bzrlib.bzrdir import (
22
29
    BzrDir,
23
30
    BzrDirFormat,
208
215
            branch_name))
209
216
 
210
217
 
 
218
class SmartServerBzrDirRequestCheckoutMetaDir(SmartServerRequestBzrDir):
 
219
    """Get the format to use for checkouts.
 
220
 
 
221
    New in 2.5.
 
222
 
 
223
    :return: on success, a 3-tuple of network names for (control,
 
224
        repository, branch) directories, where '' signifies "not present".
 
225
        If this BzrDir contains a branch reference then this will fail with
 
226
        BranchReference; clients should resolve branch references before
 
227
        calling this RPC (they should not try to create a checkout of a
 
228
        checkout).
 
229
    """
 
230
 
 
231
    def do_bzrdir_request(self):
 
232
        try:
 
233
            branch_ref = self._bzrdir.get_branch_reference()
 
234
        except errors.NotBranchError:
 
235
            branch_ref = None
 
236
        if branch_ref is not None:
 
237
            # The server shouldn't try to resolve references, and it quite
 
238
            # possibly can't reach them anyway.  The client needs to resolve
 
239
            # the branch reference to determine the cloning_metadir.
 
240
            return FailedSmartServerResponse(('BranchReference',))
 
241
        control_format = self._bzrdir.checkout_metadir()
 
242
        control_name = control_format.network_name()
 
243
        if not control_format.fixed_components:
 
244
            branch_name = control_format.get_branch_format().network_name()
 
245
            repo_name = control_format.repository_format.network_name()
 
246
        else:
 
247
            branch_name = ''
 
248
            repo_name = ''
 
249
        return SuccessfulSmartServerResponse(
 
250
            (control_name, repo_name, branch_name))
 
251
 
 
252
 
211
253
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
212
254
 
213
255
    def do(self, path, network_name):
232
274
            self.transport_from_client_path(path))
233
275
        format = branch.network_format_registry.get(network_name)
234
276
        bzrdir.branch_format = format
235
 
        result = format.initialize(bzrdir)
 
277
        result = format.initialize(bzrdir, name="")
236
278
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
237
279
            result.repository._format)
238
280
        branch_format = result._format.network_name()
389
431
        return SuccessfulSmartServerResponse((), content)
390
432
 
391
433
 
 
434
class SmartServerBzrDirRequestGetBranches(SmartServerRequestBzrDir):
 
435
 
 
436
    def do_bzrdir_request(self):
 
437
        """Get the branches in a control directory.
 
438
        
 
439
        The body is a bencoded dictionary, with values similar to the return
 
440
        value of the open branch request.
 
441
        """
 
442
        branches = self._bzrdir.get_branches()
 
443
        ret = {}
 
444
        for name, b in branches.iteritems():
 
445
            if name is None:
 
446
                name = ""
 
447
            ret[name] = ("branch", b._format.network_name())
 
448
        return SuccessfulSmartServerResponse(
 
449
            ("success", ), bencode.bencode(ret))
 
450
 
 
451
 
392
452
class SmartServerRequestInitializeBzrDir(SmartServerRequest):
393
453
 
394
454
    def do(self, path):