~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Robert Collins
  • Date: 2007-04-24 12:20:09 UTC
  • mto: (2432.3.5 hpss-vfs-fallback)
  • mto: This revision was merged to the branch mainline in revision 2463.
  • Revision ID: robertc@lifelesswks.robertcollins.net-20070424122009-8bb4dede6a298d93
Make using SuccessfulSmartServerResponse and FailedSmartServerResponse mandatory rather than optional in smart server logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from bzrlib import errors
21
21
from bzrlib.bzrdir import BzrDir
22
 
from bzrlib.smart.request import SmartServerRequest, SmartServerResponse
 
22
from bzrlib.smart.request import (
 
23
    FailedSmartServerResponse,
 
24
    SmartServerRequest,
 
25
    SuccessfulSmartServerResponse,
 
26
    )
23
27
 
24
28
 
25
29
class SmartServerBranchRequest(SmartServerRequest):
73
77
            content = branch.control_files.get('branch.conf').read()
74
78
        except errors.NoSuchFile:
75
79
            content = ''
76
 
        return SmartServerResponse( ('ok', ), content)
 
80
        return SuccessfulSmartServerResponse( ('ok', ), content)
77
81
 
78
82
 
79
83
class SmartServerRequestRevisionHistory(SmartServerBranchRequest):
84
88
        The revision list is returned as the body content,
85
89
        with each revision utf8 encoded and \x00 joined.
86
90
        """
87
 
        return SmartServerResponse(
 
91
        return SuccessfulSmartServerResponse(
88
92
            ('ok', ), ('\x00'.join(branch.revision_history())))
89
93
 
90
94
 
96
100
        The revno is encoded in decimal, the revision_id is encoded as utf8.
97
101
        """
98
102
        revno, last_revision = branch.last_revision_info()
99
 
        return SmartServerResponse(('ok', str(revno), last_revision))
 
103
        return SuccessfulSmartServerResponse(('ok', str(revno), last_revision))
100
104
 
101
105
 
102
106
class SmartServerBranchRequestSetLastRevision(SmartServerLockedBranchRequest):
106
110
            branch.set_revision_history([])
107
111
        else:
108
112
            if not branch.repository.has_revision(new_last_revision_id):
109
 
                return SmartServerResponse(
 
113
                return FailedSmartServerResponse(
110
114
                    ('NoSuchRevision', new_last_revision_id))
111
115
            branch.generate_revision_history(new_last_revision_id)
112
 
        return SmartServerResponse(('ok',))
 
116
        return SuccessfulSmartServerResponse(('ok',))
113
117
 
114
118
 
115
119
class SmartServerBranchRequestLockWrite(SmartServerBranchRequest):
126
130
            finally:
127
131
                branch.repository.unlock()
128
132
        except errors.LockContention:
129
 
            return SmartServerResponse(('LockContention',))
 
133
            return FailedSmartServerResponse(('LockContention',))
130
134
        except errors.TokenMismatch:
131
 
            return SmartServerResponse(('TokenMismatch',))
 
135
            return FailedSmartServerResponse(('TokenMismatch',))
132
136
        except errors.UnlockableTransport:
133
 
            return SmartServerResponse(('UnlockableTransport',))
 
137
            return FailedSmartServerResponse(('UnlockableTransport',))
134
138
        branch.repository.leave_lock_in_place()
135
139
        branch.leave_lock_in_place()
136
140
        branch.unlock()
137
 
        return SmartServerResponse(('ok', branch_token, repo_token))
 
141
        return SuccessfulSmartServerResponse(('ok', branch_token, repo_token))
138
142
 
139
143
 
140
144
class SmartServerBranchRequestUnlock(SmartServerBranchRequest):
147
151
            finally:
148
152
                branch.repository.unlock()
149
153
        except errors.TokenMismatch:
150
 
            return SmartServerResponse(('TokenMismatch',))
 
154
            return FailedSmartServerResponse(('TokenMismatch',))
151
155
        branch.repository.dont_leave_lock_in_place()
152
156
        branch.dont_leave_lock_in_place()
153
157
        branch.unlock()
154
 
        return SmartServerResponse(('ok',))
 
158
        return SuccessfulSmartServerResponse(('ok',))
155
159