~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-11 05:58:22 UTC
  • mto: This revision was merged to the branch mainline in revision 4965.
  • Revision ID: andrew.bennetts@canonical.com-20100111055822-npdkf88i86i1g54h
Fix HPSS tests; pass 'location is a repository' message via smart server when possible (adds BzrDir.open_branchV3 verb).

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
            self._bzrdir = BzrDir.open_from_transport(
90
90
                self.transport_from_client_path(path))
91
91
        except errors.NotBranchError, e:
92
 
            if e.detail is None:
93
 
                return FailedSmartServerResponse(('nobranch',))
94
 
            return FailedSmartServerResponse(('nobranch', e.detail))
 
92
            return FailedSmartServerResponse(('nobranch',))
95
93
        return self.do_bzrdir_request(*args)
96
94
 
97
95
    def _boolean_to_yes_no(self, a_boolean):
468
466
            else:
469
467
                return SuccessfulSmartServerResponse(('ok', reference_url))
470
468
        except errors.NotBranchError, e:
471
 
            if e.detail is None:
472
 
                return FailedSmartServerResponse(('nobranch',))
473
 
            return FailedSmartServerResponse(('nobranch', e.detail))
 
469
            return FailedSmartServerResponse(('nobranch',))
474
470
 
475
471
 
476
472
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
486
482
            else:
487
483
                return SuccessfulSmartServerResponse(('ref', reference_url))
488
484
        except errors.NotBranchError, e:
489
 
            if e.detail is None:
490
 
                return FailedSmartServerResponse(('nobranch',))
491
 
            return FailedSmartServerResponse(('nobranch', e.detail))
 
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
            str(e)
 
510
            resp = ('nobranch',)
 
511
            detail = e.detail
 
512
            if detail:
 
513
                if detail.startswith(': '):
 
514
                    detail = detail[2:]
 
515
                resp += (detail,)
 
516
            return FailedSmartServerResponse(resp)
 
517