Patchwork [2,of,2] relink: use context manager for lock management

login
register
mail settings
Submitter Matt Harbison
Date June 23, 2018, 3:36 a.m.
Message ID <d0df45902a8ce983a2f5.1529724997@Envy>
Download mbox | patch
Permalink /patch/32387/
State Accepted
Headers show

Comments

Matt Harbison - June 23, 2018, 3:36 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1490330015 14400
#      Fri Mar 24 00:33:35 2017 -0400
# Node ID d0df45902a8ce983a2f55a0c4e4acb5d41c753fe
# Parent  c68fcc8aa06b71d87439efceeea3c0ac55b93614
relink: use context manager for lock management

Patch

diff --git a/hgext/relink.py b/hgext/relink.py
--- a/hgext/relink.py
+++ b/hgext/relink.py
@@ -70,17 +70,10 @@  def relink(ui, repo, origin=None, **opts
         # 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)