~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2009-06-09 00:59:51 UTC
  • mto: (4443.1.1 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 4444.
  • Revision ID: jelmer@samba.org-20090609005951-apv900cdk35o2ygh
Move squashing of XML-invalid characters to XMLSerializer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 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
17
17
"""Server-side branch related request implmentations."""
18
18
 
19
19
 
20
 
from bzrlib import (
21
 
    bencode,
22
 
    errors,
23
 
    )
 
20
from bzrlib import errors
24
21
from bzrlib.bzrdir import BzrDir
25
22
from bzrlib.smart.request import (
26
23
    FailedSmartServerResponse,
106
103
        return SuccessfulSmartServerResponse((bytes,))
107
104
 
108
105
 
109
 
class SmartServerBranchSetTagsBytes(SmartServerLockedBranchRequest):
110
 
 
111
 
    def __init__(self, backing_transport, root_client_path='/', jail_root=None):
112
 
        SmartServerLockedBranchRequest.__init__(
113
 
            self, backing_transport, root_client_path, jail_root)
114
 
        self.locked = False
115
 
        
116
 
    def do_with_locked_branch(self, branch):
117
 
        """Call _set_tags_bytes for a branch.
118
 
 
119
 
        New in 1.18.
120
 
        """
121
 
        # We need to keep this branch locked until we get a body with the tags
122
 
        # bytes.
123
 
        self.branch = branch
124
 
        self.branch.lock_write()
125
 
        self.locked = True
126
 
 
127
 
    def do_body(self, bytes):
128
 
        self.branch._set_tags_bytes(bytes)
129
 
        return SuccessfulSmartServerResponse(())
130
 
 
131
 
    def do_end(self):
132
 
        # TODO: this request shouldn't have to do this housekeeping manually.
133
 
        # Some of this logic probably belongs in a base class.
134
 
        if not self.locked:
135
 
            # We never acquired the branch successfully in the first place, so
136
 
            # there's nothing more to do.
137
 
            return
138
 
        try:
139
 
            return SmartServerLockedBranchRequest.do_end(self)
140
 
        finally:
141
 
            # Only try unlocking if we locked successfully in the first place
142
 
            self.branch.unlock()
143
 
 
144
 
 
145
 
class SmartServerBranchHeadsToFetch(SmartServerBranchRequest):
146
 
 
147
 
    def do_with_branch(self, branch):
148
 
        """Return the heads-to-fetch for a Branch as two bencoded lists.
149
 
        
150
 
        See Branch.heads_to_fetch.
151
 
 
152
 
        New in 2.4.
153
 
        """
154
 
        must_fetch, if_present_fetch = branch.heads_to_fetch()
155
 
        return SuccessfulSmartServerResponse(
156
 
            (list(must_fetch), list(if_present_fetch)))
157
 
 
158
 
 
159
106
class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
160
107
 
161
108
    def do_with_branch(self, branch):
211
158
        return SuccessfulSmartServerResponse(())
212
159
 
213
160
 
214
 
class SmartServerBranchRequestSetConfigOptionDict(SmartServerLockedBranchRequest):
215
 
    """Set an option in the branch configuration.
216
 
    
217
 
    New in 2.2.
218
 
    """
219
 
 
220
 
    def do_with_locked_branch(self, branch, value_dict, name, section):
221
 
        utf8_dict = bencode.bdecode(value_dict)
222
 
        value_dict = {}
223
 
        for key, value in utf8_dict.items():
224
 
            value_dict[key.decode('utf8')] = value.decode('utf8')
225
 
        if not section:
226
 
            section = None
227
 
        branch._get_config().set_option(value_dict, name, section)
228
 
        return SuccessfulSmartServerResponse(())
229
 
 
230
 
 
231
161
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
232
162
 
233
163
    def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
234
164
        if new_last_revision_id == 'null:':
235
 
            branch._set_revision_history([])
 
165
            branch.set_revision_history([])
236
166
        else:
237
167
            if not branch.repository.has_revision(new_last_revision_id):
238
168
                return FailedSmartServerResponse(
239
169
                    ('NoSuchRevision', new_last_revision_id))
240
 
            branch._set_revision_history(branch._lefthand_history(
 
170
            branch.set_revision_history(branch._lefthand_history(
241
171
                new_last_revision_id, None, None))
242
172
        return SuccessfulSmartServerResponse(('ok',))
243
173
 
326
256
        if repo_token == '':
327
257
            repo_token = None
328
258
        try:
329
 
            repo_token = branch.repository.lock_write(
330
 
                token=repo_token).repository_token
 
259
            repo_token = branch.repository.lock_write(token=repo_token)
331
260
            try:
332
 
                branch_token = branch.lock_write(
333
 
                    token=branch_token).branch_token
 
261
                branch_token = branch.lock_write(token=branch_token)
334
262
            finally:
335
263
                # this leaves the repository with 1 lock
336
264
                branch.repository.unlock()