1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
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."""
20
from bzrlib import errors
24
21
from bzrlib.bzrdir import BzrDir
25
22
from bzrlib.smart.request import (
26
23
FailedSmartServerResponse,
142
139
self.branch.unlock()
145
class SmartServerBranchHeadsToFetch(SmartServerBranchRequest):
147
def do_with_branch(self, branch):
148
"""Return the heads-to-fetch for a Branch as two bencoded lists.
150
See Branch.heads_to_fetch.
154
must_fetch, if_present_fetch = branch.heads_to_fetch()
155
return SuccessfulSmartServerResponse(
156
(list(must_fetch), list(if_present_fetch)))
159
142
class SmartServerBranchRequestGetStackedOnURL(SmartServerBranchRequest):
161
144
def do_with_branch(self, branch):
211
194
return SuccessfulSmartServerResponse(())
214
class SmartServerBranchRequestSetConfigOptionDict(SmartServerLockedBranchRequest):
215
"""Set an option in the branch configuration.
220
def do_with_locked_branch(self, branch, value_dict, name, section):
221
utf8_dict = bencode.bdecode(value_dict)
223
for key, value in utf8_dict.items():
224
value_dict[key.decode('utf8')] = value.decode('utf8')
227
branch._get_config().set_option(value_dict, name, section)
228
return SuccessfulSmartServerResponse(())
231
197
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
233
199
def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
234
200
if new_last_revision_id == 'null:':
235
branch._set_revision_history([])
201
branch.set_revision_history([])
237
203
if not branch.repository.has_revision(new_last_revision_id):
238
204
return FailedSmartServerResponse(
239
205
('NoSuchRevision', new_last_revision_id))
240
branch._set_revision_history(branch._lefthand_history(
206
branch.set_revision_history(branch._lefthand_history(
241
207
new_last_revision_id, None, None))
242
208
return SuccessfulSmartServerResponse(('ok',))
326
292
if repo_token == '':
327
293
repo_token = None
329
repo_token = branch.repository.lock_write(
330
token=repo_token).repository_token
295
repo_token = branch.repository.lock_write(token=repo_token)
332
branch_token = branch.lock_write(
333
token=branch_token).branch_token
297
branch_token = branch.lock_write(token=branch_token)
335
299
# this leaves the repository with 1 lock
336
300
branch.repository.unlock()