~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

(gz) Never raise KnownFailure in tests,
 use knownFailure method instead (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib import (
21
21
    bencode,
22
22
    errors,
23
 
    revision as _mod_revision,
24
23
    )
25
 
from bzrlib.controldir import ControlDir
 
24
from bzrlib.bzrdir import BzrDir
26
25
from bzrlib.smart.request import (
27
26
    FailedSmartServerResponse,
28
27
    SmartServerRequest,
46
45
        :return: A SmartServerResponse from self.do_with_branch().
47
46
        """
48
47
        transport = self.transport_from_client_path(path)
49
 
        controldir = ControlDir.open_from_transport(transport)
50
 
        if controldir.get_branch_reference() is not None:
 
48
        bzrdir = BzrDir.open_from_transport(transport)
 
49
        if bzrdir.get_branch_reference() is not None:
51
50
            raise errors.NotBranchError(transport.base)
52
 
        branch = controldir.open_branch(ignore_fallbacks=True)
 
51
        branch = bzrdir.open_branch(ignore_fallbacks=True)
53
52
        return self.do_with_branch(branch, *args)
54
53
 
55
54
 
77
76
            branch.repository.unlock()
78
77
 
79
78
 
80
 
class SmartServerBranchBreakLock(SmartServerBranchRequest):
81
 
 
82
 
    def do_with_branch(self, branch):
83
 
        """Break a branch lock.
84
 
        """
85
 
        branch.break_lock()
86
 
        return SuccessfulSmartServerResponse(('ok', ), )
87
 
 
88
 
 
89
79
class SmartServerBranchGetConfigFile(SmartServerBranchRequest):
90
80
 
91
81
    def do_with_branch(self, branch):
94
84
        The body is not utf8 decoded - its the literal bytestream from disk.
95
85
        """
96
86
        try:
97
 
            content = branch.control_transport.get_bytes('branch.conf')
 
87
            content = branch._transport.get_bytes('branch.conf')
98
88
        except errors.NoSuchFile:
99
89
            content = ''
100
90
        return SuccessfulSmartServerResponse( ('ok', ), content)
101
91
 
102
92
 
103
 
class SmartServerBranchPutConfigFile(SmartServerBranchRequest):
104
 
    """Set the configuration data for a branch.
105
 
 
106
 
    New in 2.5.
107
 
    """
108
 
 
109
 
    def do_with_branch(self, branch, branch_token, repo_token):
110
 
        """Set the content of branch.conf.
111
 
 
112
 
        The body is not utf8 decoded - its the literal bytestream for disk.
113
 
        """
114
 
        self._branch = branch
115
 
        self._branch_token = branch_token
116
 
        self._repo_token = repo_token
117
 
        # Signal we want a body
118
 
        return None
119
 
 
120
 
    def do_body(self, body_bytes):
121
 
        self._branch.repository.lock_write(token=self._repo_token)
122
 
        try:
123
 
            self._branch.lock_write(token=self._branch_token)
124
 
            try:
125
 
                self._branch.control_transport.put_bytes(
126
 
                    'branch.conf', body_bytes)
127
 
            finally:
128
 
                self._branch.unlock()
129
 
        finally:
130
 
            self._branch.repository.unlock()
131
 
        return SuccessfulSmartServerResponse(('ok', ))
132
 
 
133
 
 
134
93
class SmartServerBranchGetParent(SmartServerBranchRequest):
135
94
 
136
95
    def do_with_branch(self, branch):
212
171
        The revision list is returned as the body content,
213
172
        with each revision utf8 encoded and \x00 joined.
214
173
        """
215
 
        branch.lock_read()
216
 
        try:
217
 
            graph = branch.repository.get_graph()
218
 
            stop_revisions = (None, _mod_revision.NULL_REVISION)
219
 
            history = list(graph.iter_lefthand_ancestry(
220
 
                branch.last_revision(), stop_revisions))
221
 
        finally:
222
 
            branch.unlock()
223
174
        return SuccessfulSmartServerResponse(
224
 
            ('ok', ), ('\x00'.join(reversed(history))))
 
175
            ('ok', ), ('\x00'.join(branch.revision_history())))
225
176
 
226
177
 
227
178
class SmartServerBranchRequestLastRevisionInfo(SmartServerBranchRequest):
235
186
        return SuccessfulSmartServerResponse(('ok', str(revno), last_revision))
236
187
 
237
188
 
238
 
class SmartServerBranchRequestRevisionIdToRevno(SmartServerBranchRequest):
239
 
 
240
 
    def do_with_branch(self, branch, revid):
241
 
        """Return branch.revision_id_to_revno().
242
 
 
243
 
        New in 2.5.
244
 
 
245
 
        The revno is encoded in decimal, the revision_id is encoded as utf8.
246
 
        """
247
 
        try:
248
 
            dotted_revno = branch.revision_id_to_dotted_revno(revid)
249
 
        except errors.NoSuchRevision:
250
 
            return FailedSmartServerResponse(('NoSuchRevision', revid))
251
 
        return SuccessfulSmartServerResponse(
252
 
            ('ok', ) + tuple(map(str, dotted_revno)))
253
 
 
254
 
 
255
189
class SmartServerSetTipRequest(SmartServerLockedBranchRequest):
256
190
    """Base class for handling common branch request logic for requests that
257
191
    update the branch tip.
434
368
        branch.unlock()
435
369
        return SuccessfulSmartServerResponse(('ok',))
436
370
 
437
 
 
438
 
class SmartServerBranchRequestGetPhysicalLockStatus(SmartServerBranchRequest):
439
 
    """Get the physical lock status for a branch.
440
 
 
441
 
    New in 2.5.
442
 
    """
443
 
 
444
 
    def do_with_branch(self, branch):
445
 
        if branch.get_physical_lock_status():
446
 
            return SuccessfulSmartServerResponse(('yes',))
447
 
        else:
448
 
            return SuccessfulSmartServerResponse(('no',))