~ubuntu-branches/ubuntu/maverick/bzr/maverick-proposed

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-02-17 17:47:40 UTC
  • mfrom: (1.4.5 upstream) (9.2.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100217174740-35yh6t5rjnztg9z6
Tags: 2.1.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
class SmartServerRequestOpenBzrDir(SmartServerRequest):
35
35
 
36
36
    def do(self, path):
37
 
        from bzrlib.bzrdir import BzrDirFormat
38
37
        try:
39
38
            t = self.transport_from_client_path(path)
40
39
        except errors.PathNotChild:
56
55
        return SuccessfulSmartServerResponse((answer,))
57
56
 
58
57
 
 
58
class SmartServerRequestOpenBzrDir_2_1(SmartServerRequest):
 
59
 
 
60
    def do(self, path):
 
61
        """Is there a BzrDir present, and if so does it have a working tree?
 
62
 
 
63
        New in 2.1.
 
64
        """
 
65
        try:
 
66
            t = self.transport_from_client_path(path)
 
67
        except errors.PathNotChild:
 
68
            # The client is trying to ask about a path that they have no access
 
69
            # to.
 
70
            return SuccessfulSmartServerResponse(('no',))
 
71
        try:
 
72
            bd = BzrDir.open_from_transport(t)
 
73
        except errors.NotBranchError:
 
74
            answer = ('no',)
 
75
        else:
 
76
            answer = ('yes',)
 
77
            if bd.has_workingtree():
 
78
                answer += ('yes',)
 
79
            else:
 
80
                answer += ('no',)
 
81
        return SuccessfulSmartServerResponse(answer)
 
82
 
 
83
 
59
84
class SmartServerRequestBzrDir(SmartServerRequest):
60
85
 
61
86
    def do(self, path, *args):
63
88
        try:
64
89
            self._bzrdir = BzrDir.open_from_transport(
65
90
                self.transport_from_client_path(path))
66
 
        except errors.NotBranchError:
67
 
            return FailedSmartServerResponse(('nobranch', ))
 
91
        except errors.NotBranchError, e:
 
92
            return FailedSmartServerResponse(('nobranch',))
68
93
        return self.do_bzrdir_request(*args)
69
94
 
70
95
    def _boolean_to_yes_no(self, a_boolean):
440
465
                return SuccessfulSmartServerResponse(('ok', ''))
441
466
            else:
442
467
                return SuccessfulSmartServerResponse(('ok', reference_url))
443
 
        except errors.NotBranchError:
444
 
            return FailedSmartServerResponse(('nobranch', ))
 
468
        except errors.NotBranchError, e:
 
469
            return FailedSmartServerResponse(('nobranch',))
445
470
 
446
471
 
447
472
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
456
481
                return SuccessfulSmartServerResponse(('branch', format))
457
482
            else:
458
483
                return SuccessfulSmartServerResponse(('ref', reference_url))
459
 
        except errors.NotBranchError:
460
 
            return FailedSmartServerResponse(('nobranch', ))
 
484
        except errors.NotBranchError, e:
 
485
            return FailedSmartServerResponse(('nobranch',))
 
486
 
 
487
 
 
488
class SmartServerRequestOpenBranchV3(SmartServerRequestBzrDir):
 
489
 
 
490
    def do_bzrdir_request(self):
 
491
        """Open a branch at path and return the reference or format.
 
492
        
 
493
        This version introduced in 2.1.
 
494
 
 
495
        Differences to SmartServerRequestOpenBranchV2:
 
496
          * can return 2-element ('nobranch', extra), where 'extra' is a string
 
497
            with an explanation like 'location is a repository'.  Previously
 
498
            a 'nobranch' response would never have more than one element.
 
499
        """
 
500
        try:
 
501
            reference_url = self._bzrdir.get_branch_reference()
 
502
            if reference_url is None:
 
503
                br = self._bzrdir.open_branch(ignore_fallbacks=True)
 
504
                format = br._format.network_name()
 
505
                return SuccessfulSmartServerResponse(('branch', format))
 
506
            else:
 
507
                return SuccessfulSmartServerResponse(('ref', reference_url))
 
508
        except errors.NotBranchError, e:
 
509
            # Stringify the exception so that its .detail attribute will be
 
510
            # filled out.
 
511
            str(e)
 
512
            resp = ('nobranch',)
 
513
            detail = e.detail
 
514
            if detail:
 
515
                if detail.startswith(': '):
 
516
                    detail = detail[2:]
 
517
                resp += (detail,)
 
518
            return FailedSmartServerResponse(resp)
 
519