~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-29 22:03:03 UTC
  • mfrom: (5416.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
(mbp) Add 'break-lock --force'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
22
22
    BzrDir,
23
23
    BzrDirFormat,
24
24
    BzrDirMetaFormat1,
 
25
    BzrProber,
 
26
    )
 
27
from bzrlib.controldir import (
25
28
    network_format_registry,
26
29
    )
27
30
from bzrlib.smart.request import (
34
37
class SmartServerRequestOpenBzrDir(SmartServerRequest):
35
38
 
36
39
    def do(self, path):
37
 
        from bzrlib.bzrdir import BzrDirFormat
38
40
        try:
39
41
            t = self.transport_from_client_path(path)
40
42
        except errors.PathNotChild:
45
47
            # clients that don't anticipate errors from this method.
46
48
            answer = 'no'
47
49
        else:
48
 
            default_format = BzrDirFormat.get_default_format()
49
 
            real_bzrdir = default_format.open(t, _found=True)
 
50
            bzr_prober = BzrProber()
50
51
            try:
51
 
                real_bzrdir._format.probe_transport(t)
 
52
                bzr_prober.probe_transport(t)
52
53
            except (errors.NotBranchError, errors.UnknownFormatError):
53
54
                answer = 'no'
54
55
            else:
56
57
        return SuccessfulSmartServerResponse((answer,))
57
58
 
58
59
 
 
60
class SmartServerRequestOpenBzrDir_2_1(SmartServerRequest):
 
61
 
 
62
    def do(self, path):
 
63
        """Is there a BzrDir present, and if so does it have a working tree?
 
64
 
 
65
        New in 2.1.
 
66
        """
 
67
        try:
 
68
            t = self.transport_from_client_path(path)
 
69
        except errors.PathNotChild:
 
70
            # The client is trying to ask about a path that they have no access
 
71
            # to.
 
72
            return SuccessfulSmartServerResponse(('no',))
 
73
        try:
 
74
            bd = BzrDir.open_from_transport(t)
 
75
        except errors.NotBranchError:
 
76
            answer = ('no',)
 
77
        else:
 
78
            answer = ('yes',)
 
79
            if bd.has_workingtree():
 
80
                answer += ('yes',)
 
81
            else:
 
82
                answer += ('no',)
 
83
        return SuccessfulSmartServerResponse(answer)
 
84
 
 
85
 
59
86
class SmartServerRequestBzrDir(SmartServerRequest):
60
87
 
61
88
    def do(self, path, *args):
63
90
        try:
64
91
            self._bzrdir = BzrDir.open_from_transport(
65
92
                self.transport_from_client_path(path))
66
 
        except errors.NotBranchError:
67
 
            return FailedSmartServerResponse(('nobranch', ))
 
93
        except errors.NotBranchError, e:
 
94
            return FailedSmartServerResponse(('nobranch',))
68
95
        return self.do_bzrdir_request(*args)
69
96
 
70
97
    def _boolean_to_yes_no(self, a_boolean):
85
112
        """Get the relative path for repository from current_transport."""
86
113
        # the relpath of the bzrdir in the found repository gives us the
87
114
        # path segments to pop-out.
88
 
        relpath = repository.bzrdir.root_transport.relpath(
 
115
        relpath = repository.user_transport.relpath(
89
116
            current_transport.base)
90
117
        if len(relpath):
91
118
            segments = ['..'] * len(relpath.split('/'))
404
431
            # It is returned locked, but we need to do the lock to get the lock
405
432
            # token.
406
433
            repo.unlock()
407
 
            repo_lock_token = repo.lock_write() or ''
 
434
            repo_lock_token = repo.lock_write().repository_token or ''
408
435
            if repo_lock_token:
409
436
                repo.leave_lock_in_place()
410
437
            repo.unlock()
440
467
                return SuccessfulSmartServerResponse(('ok', ''))
441
468
            else:
442
469
                return SuccessfulSmartServerResponse(('ok', reference_url))
443
 
        except errors.NotBranchError:
444
 
            return FailedSmartServerResponse(('nobranch', ))
 
470
        except errors.NotBranchError, e:
 
471
            return FailedSmartServerResponse(('nobranch',))
445
472
 
446
473
 
447
474
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
456
483
                return SuccessfulSmartServerResponse(('branch', format))
457
484
            else:
458
485
                return SuccessfulSmartServerResponse(('ref', reference_url))
459
 
        except errors.NotBranchError:
460
 
            return FailedSmartServerResponse(('nobranch', ))
 
486
        except errors.NotBranchError, e:
 
487
            return FailedSmartServerResponse(('nobranch',))
 
488
 
 
489
 
 
490
class SmartServerRequestOpenBranchV3(SmartServerRequestBzrDir):
 
491
 
 
492
    def do_bzrdir_request(self):
 
493
        """Open a branch at path and return the reference or format.
 
494
        
 
495
        This version introduced in 2.1.
 
496
 
 
497
        Differences to SmartServerRequestOpenBranchV2:
 
498
          * can return 2-element ('nobranch', extra), where 'extra' is a string
 
499
            with an explanation like 'location is a repository'.  Previously
 
500
            a 'nobranch' response would never have more than one element.
 
501
        """
 
502
        try:
 
503
            reference_url = self._bzrdir.get_branch_reference()
 
504
            if reference_url is None:
 
505
                br = self._bzrdir.open_branch(ignore_fallbacks=True)
 
506
                format = br._format.network_name()
 
507
                return SuccessfulSmartServerResponse(('branch', format))
 
508
            else:
 
509
                return SuccessfulSmartServerResponse(('ref', reference_url))
 
510
        except errors.NotBranchError, e:
 
511
            # Stringify the exception so that its .detail attribute will be
 
512
            # filled out.
 
513
            str(e)
 
514
            resp = ('nobranch',)
 
515
            detail = e.detail
 
516
            if detail:
 
517
                if detail.startswith(': '):
 
518
                    detail = detail[2:]
 
519
                resp += (detail,)
 
520
            return FailedSmartServerResponse(resp)
 
521