comparison mercurial/phases.py @ 27861:3315a9c2019c

with: use context manager for lock in pushphase
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 15 Jan 2016 13:14:49 -0800
parents e36118815a39
children 4ff0e2347ae6
comparison
equal deleted inserted replaced
27860:0da102e4f203 27861:3315a9c2019c
402 return keys 402 return keys
403 403
404 def pushphase(repo, nhex, oldphasestr, newphasestr): 404 def pushphase(repo, nhex, oldphasestr, newphasestr):
405 """List phases root for serialization over pushkey""" 405 """List phases root for serialization over pushkey"""
406 repo = repo.unfiltered() 406 repo = repo.unfiltered()
407 tr = None 407 with repo.lock():
408 lock = repo.lock()
409 try:
410 currentphase = repo[nhex].phase() 408 currentphase = repo[nhex].phase()
411 newphase = abs(int(newphasestr)) # let's avoid negative index surprise 409 newphase = abs(int(newphasestr)) # let's avoid negative index surprise
412 oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise 410 oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
413 if currentphase == oldphase and newphase < oldphase: 411 if currentphase == oldphase and newphase < oldphase:
414 tr = repo.transaction('pushkey-phase') 412 try:
415 advanceboundary(repo, tr, newphase, [bin(nhex)]) 413 tr = repo.transaction('pushkey-phase')
416 tr.close() 414 advanceboundary(repo, tr, newphase, [bin(nhex)])
415 tr.close()
416 finally:
417 tr.release()
417 return 1 418 return 1
418 elif currentphase == newphase: 419 elif currentphase == newphase:
419 # raced, but got correct result 420 # raced, but got correct result
420 return 1 421 return 1
421 else: 422 else:
422 return 0 423 return 0
423 finally:
424 if tr:
425 tr.release()
426 lock.release()
427 424
428 def analyzeremotephases(repo, subset, roots): 425 def analyzeremotephases(repo, subset, roots):
429 """Compute phases heads and root in a subset of node from root dict 426 """Compute phases heads and root in a subset of node from root dict
430 427
431 * subset is heads of the subset 428 * subset is heads of the subset