D5695: unshare: use context manager for locks
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Jan 25 20:31:51 UTC 2019
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5695
AFFECTED FILES
mercurial/hg.py
CHANGE DETAILS
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -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
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list