relink: use context manager for lock management
authorMatt Harbison <matt_harbison@yahoo.com>
Fri, 24 Mar 2017 00:33:35 -0400
changeset 38447 36edfbac7281
parent 38446 e219e355e088
child 38448 e6b643ccf87d
relink: use context manager for lock management
hgext/relink.py
--- a/hgext/relink.py	Fri Mar 24 00:32:31 2017 -0400
+++ b/hgext/relink.py	Fri Mar 24 00:33:35 2017 -0400
@@ -70,17 +70,10 @@
         # No point in continuing
         raise error.Abort(_('source and destination are on different devices'))
 
-    locallock = repo.lock()
-    try:
-        remotelock = src.lock()
-        try:
-            candidates = sorted(collect(src, ui))
-            targets = prune(candidates, src.store.path, repo.store.path, ui)
-            do_relink(src.store.path, repo.store.path, targets, ui)
-        finally:
-            remotelock.release()
-    finally:
-        locallock.release()
+    with repo.lock(), src.lock():
+        candidates = sorted(collect(src, ui))
+        targets = prune(candidates, src.store.path, repo.store.path, ui)
+        do_relink(src.store.path, repo.store.path, targets, ui)
 
 def collect(src, ui):
     seplen = len(os.path.sep)