/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-27 11:34:38 UTC
  • mto: This revision was merged to the branch mainline in revision 6216.
  • Revision ID: jelmer@samba.org-20110927113438-iaunzmkn9yscv0al
More test fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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 errors
 
20
from bzrlib import (
 
21
    bencode,
 
22
    errors,
 
23
    )
21
24
from bzrlib.bzrdir import BzrDir
22
25
from bzrlib.smart.request import (
23
26
    FailedSmartServerResponse,
139
142
            self.branch.unlock()
140
143
 
141
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
 
142
159
class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
143
160
 
144
161
    def do_with_branch(self, branch):
154
171
        The revision list is returned as the body content,
155
172
        with each revision utf8 encoded and \x00 joined.
156
173
        """
 
174
        history = list(branch.iter_reverse_revision_history())
157
175
        return SuccessfulSmartServerResponse(
158
 
            ('ok', ), ('\x00'.join(branch.revision_history())))
 
176
            ('ok', ), ('\x00'.join(reversed(history))))
159
177
 
160
178
 
161
179
class SmartServerBranchRequestLastRevisionInfo(SmartServerBranchRequest):
194
212
        return SuccessfulSmartServerResponse(())
195
213
 
196
214
 
 
215
class SmartServerBranchRequestSetConfigOptionDict(SmartServerLockedBranchRequest):
 
216
    """Set an option in the branch configuration.
 
217
    
 
218
    New in 2.2.
 
219
    """
 
220
 
 
221
    def do_with_locked_branch(self, branch, value_dict, name, section):
 
222
        utf8_dict = bencode.bdecode(value_dict)
 
223
        value_dict = {}
 
224
        for key, value in utf8_dict.items():
 
225
            value_dict[key.decode('utf8')] = value.decode('utf8')
 
226
        if not section:
 
227
            section = None
 
228
        branch._get_config().set_option(value_dict, name, section)
 
229
        return SuccessfulSmartServerResponse(())
 
230
 
 
231
 
197
232
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
198
233
 
199
234
    def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
200
235
        if new_last_revision_id == 'null:':
201
 
            branch.set_revision_history([])
 
236
            branch._set_revision_history([])
202
237
        else:
203
238
            if not branch.repository.has_revision(new_last_revision_id):
204
239
                return FailedSmartServerResponse(
205
240
                    ('NoSuchRevision', new_last_revision_id))
206
 
            branch.set_revision_history(branch._lefthand_history(
 
241
            branch._set_revision_history(branch._lefthand_history(
207
242
                new_last_revision_id, None, None))
208
243
        return SuccessfulSmartServerResponse(('ok',))
209
244
 
292
327
        if repo_token == '':
293
328
            repo_token = None
294
329
        try:
295
 
            repo_token = branch.repository.lock_write(token=repo_token)
 
330
            repo_token = branch.repository.lock_write(
 
331
                token=repo_token).repository_token
296
332
            try:
297
 
                branch_token = branch.lock_write(token=branch_token)
 
333
                branch_token = branch.lock_write(
 
334
                    token=branch_token).branch_token
298
335
            finally:
299
336
                # this leaves the repository with 1 lock
300
337
                branch.repository.unlock()