changeset 38442:36edfbac7281

relink: use context manager for lock management
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 24 Mar 2017 00:33:35 -0400
parents e219e355e088
children e6b643ccf87d
files hgext/relink.py
diffstat 1 files changed, 4 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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)