281
291
value_dict[key.decode('utf8')] = value.decode('utf8')
285
section = section.decode('utf-8')
286
branch._get_config().set_option(value_dict, name.decode('utf-8'), section)
294
branch._get_config().set_option(value_dict, name, section)
287
295
return SuccessfulSmartServerResponse(())
290
298
class SmartServerBranchRequestSetLastRevision(SmartServerSetTipRequest):
292
300
def do_tip_change_with_locked_branch(self, branch, new_last_revision_id):
293
if new_last_revision_id == b'null:':
301
if new_last_revision_id == 'null:':
294
302
branch.set_last_revision_info(0, new_last_revision_id)
296
304
if not branch.repository.has_revision(new_last_revision_id):
297
305
return FailedSmartServerResponse(
298
(b'NoSuchRevision', new_last_revision_id))
306
('NoSuchRevision', new_last_revision_id))
299
307
branch.generate_revision_history(new_last_revision_id, None, None)
300
return SuccessfulSmartServerResponse((b'ok',))
308
return SuccessfulSmartServerResponse(('ok',))
303
311
class SmartServerBranchRequestSetLastRevisionEx(SmartServerSetTipRequest):
305
313
def do_tip_change_with_locked_branch(self, branch, new_last_revision_id,
306
allow_divergence, allow_overwrite_descendant):
314
allow_divergence, allow_overwrite_descendant):
307
315
"""Set the last revision of the branch.
334
342
relation = branch._revision_relations(
335
343
last_rev, new_last_revision_id, graph)
336
344
if relation == 'diverged' and not allow_divergence:
337
return FailedSmartServerResponse((b'Diverged',))
345
return FailedSmartServerResponse(('Diverged',))
338
346
if relation == 'a_descends_from_b' and do_not_overwrite_descendant:
339
347
return SuccessfulSmartServerResponse(
340
(b'ok', last_revno, last_rev))
348
('ok', last_revno, last_rev))
341
349
new_revno = graph.find_distance_to_null(
342
350
new_last_revision_id, [(last_rev, last_revno)])
343
351
branch.set_last_revision_info(new_revno, new_last_revision_id)
344
352
except errors.GhostRevisionsHaveNoRevno:
345
353
return FailedSmartServerResponse(
346
(b'NoSuchRevision', new_last_revision_id))
354
('NoSuchRevision', new_last_revision_id))
347
355
return SuccessfulSmartServerResponse(
348
(b'ok', new_revno, new_last_revision_id))
356
('ok', new_revno, new_last_revision_id))
351
359
class SmartServerBranchRequestSetLastRevisionInfo(SmartServerSetTipRequest):
352
360
"""Branch.set_last_revision_info. Sets the revno and the revision ID of
353
361
the specified branch.
358
366
def do_tip_change_with_locked_branch(self, branch, new_revno,
359
new_last_revision_id):
367
new_last_revision_id):
361
369
branch.set_last_revision_info(int(new_revno), new_last_revision_id)
362
370
except errors.NoSuchRevision:
363
371
return FailedSmartServerResponse(
364
(b'NoSuchRevision', new_last_revision_id))
365
return SuccessfulSmartServerResponse((b'ok',))
372
('NoSuchRevision', new_last_revision_id))
373
return SuccessfulSmartServerResponse(('ok',))
368
376
class SmartServerBranchRequestSetParentLocation(SmartServerLockedBranchRequest):
369
377
"""Set the parent location for a branch.
371
379
Takes a location to set, which must be utf8 encoded.
374
382
def do_with_locked_branch(self, branch, location):
375
branch._set_parent_location(location.decode('utf-8'))
383
branch._set_parent_location(location)
376
384
return SuccessfulSmartServerResponse(())
379
387
class SmartServerBranchRequestLockWrite(SmartServerBranchRequest):
381
def do_with_branch(self, branch, branch_token=b'', repo_token=b''):
382
if branch_token == b'':
389
def do_with_branch(self, branch, branch_token='', repo_token=''):
390
if branch_token == '':
383
391
branch_token = None
384
if repo_token == b'':
385
393
repo_token = None
387
395
repo_token = branch.repository.lock_write(
388
396
token=repo_token).repository_token
390
398
branch_token = branch.lock_write(
391
token=branch_token).token
399
token=branch_token).branch_token
393
401
# this leaves the repository with 1 lock
394
402
branch.repository.unlock()
395
403
except errors.LockContention:
396
return FailedSmartServerResponse((b'LockContention',))
404
return FailedSmartServerResponse(('LockContention',))
397
405
except errors.TokenMismatch:
398
return FailedSmartServerResponse((b'TokenMismatch',))
406
return FailedSmartServerResponse(('TokenMismatch',))
399
407
except errors.UnlockableTransport:
400
return FailedSmartServerResponse((b'UnlockableTransport',))
401
except errors.LockFailed as e:
402
return FailedSmartServerResponse((b'LockFailed',
403
str(e.lock).encode('utf-8'), str(e.why).encode('utf-8')))
408
return FailedSmartServerResponse(('UnlockableTransport',))
409
except errors.LockFailed, e:
410
return FailedSmartServerResponse(('LockFailed', str(e.lock), str(e.why)))
404
411
if repo_token is None:
407
414
branch.repository.leave_lock_in_place()
408
415
branch.leave_lock_in_place()
410
return SuccessfulSmartServerResponse((b'ok', branch_token, repo_token))
417
return SuccessfulSmartServerResponse(('ok', branch_token, repo_token))
413
420
class SmartServerBranchRequestUnlock(SmartServerBranchRequest):
415
422
def do_with_branch(self, branch, branch_token, repo_token):
417
with branch.repository.lock_write(token=repo_token):
424
branch.repository.lock_write(token=repo_token)
418
426
branch.lock_write(token=branch_token)
428
branch.repository.unlock()
419
429
except errors.TokenMismatch:
420
return FailedSmartServerResponse((b'TokenMismatch',))
430
return FailedSmartServerResponse(('TokenMismatch',))
422
432
branch.repository.dont_leave_lock_in_place()
423
433
branch.dont_leave_lock_in_place()
425
return SuccessfulSmartServerResponse((b'ok',))
435
return SuccessfulSmartServerResponse(('ok',))
428
438
class SmartServerBranchRequestGetPhysicalLockStatus(SmartServerBranchRequest):
434
444
def do_with_branch(self, branch):
435
445
if branch.get_physical_lock_status():
436
return SuccessfulSmartServerResponse((b'yes',))
446
return SuccessfulSmartServerResponse(('yes',))
438
return SuccessfulSmartServerResponse((b'no',))
441
class SmartServerBranchRequestGetAllReferenceInfo(SmartServerBranchRequest):
442
"""Get the reference information.
447
def do_with_branch(self, branch):
448
all_reference_info = branch._get_all_reference_info()
449
content = bencode.bencode([
450
(key, value[0].encode('utf-8'), value[1].encode('utf-8') if value[1] else b'')
451
for (key, value) in all_reference_info.items()])
452
return SuccessfulSmartServerResponse((b'ok', ), content)
448
return SuccessfulSmartServerResponse(('no',))