changeset 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 0da102e4f203
children b2145c195f24
files mercurial/phases.py
diffstat 1 files changed, 7 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/phases.py	Fri Jan 15 13:14:49 2016 -0800
+++ b/mercurial/phases.py	Fri Jan 15 13:14:49 2016 -0800
@@ -404,26 +404,23 @@
 def pushphase(repo, nhex, oldphasestr, newphasestr):
     """List phases root for serialization over pushkey"""
     repo = repo.unfiltered()
-    tr = None
-    lock = repo.lock()
-    try:
+    with repo.lock():
         currentphase = repo[nhex].phase()
         newphase = abs(int(newphasestr)) # let's avoid negative index surprise
         oldphase = abs(int(oldphasestr)) # let's avoid negative index surprise
         if currentphase == oldphase and newphase < oldphase:
-            tr = repo.transaction('pushkey-phase')
-            advanceboundary(repo, tr, newphase, [bin(nhex)])
-            tr.close()
+            try:
+                tr = repo.transaction('pushkey-phase')
+                advanceboundary(repo, tr, newphase, [bin(nhex)])
+                tr.close()
+            finally:
+                tr.release()
             return 1
         elif currentphase == newphase:
             # raced, but got correct result
             return 1
         else:
             return 0
-    finally:
-        if tr:
-            tr.release()
-        lock.release()
 
 def analyzeremotephases(repo, subset, roots):
     """Compute phases heads and root in a subset of node from root dict