changeset 41391:bc843e251134

unshare: use context manager for locks Differential Revision: https://phab.mercurial-scm.org/D5695
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 17 Jan 2019 09:18:48 -0800
parents 91ec3d9a97f2
children b80af0707066
files mercurial/hg.py
diffstat 1 files changed, 8 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Fri Jan 25 21:23:16 2019 -0500
+++ b/mercurial/hg.py	Thu Jan 17 09:18:48 2019 -0800
@@ -282,25 +282,20 @@
     called.
     """
 
-    destlock = None
-    lock = repo.lock()
-    try:
+    with repo.lock():
         # we use locks here because if we race with commit, we
         # can end up with extra data in the cloned revlogs that's
         # not pointed to by changesets, thus causing verify to
         # fail
-
         destlock = copystore(ui, repo, repo.path)
-
-        sharefile = repo.vfs.join('sharedpath')
-        util.rename(sharefile, sharefile + '.old')
+        with destlock or util.nullcontextmanager():
 
-        repo.requirements.discard('shared')
-        repo.requirements.discard('relshared')
-        repo._writerequirements()
-    finally:
-        destlock and destlock.release()
-        lock and lock.release()
+            sharefile = repo.vfs.join('sharedpath')
+            util.rename(sharefile, sharefile + '.old')
+
+            repo.requirements.discard('shared')
+            repo.requirements.discard('relshared')
+            repo._writerequirements()
 
     # Removing share changes some fundamental properties of the repo instance.
     # So we instantiate a new repo object and operate on it rather than