uncommit: saner locking scheme
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 06 Aug 2014 17:08:51 -0700
changeset 1020 155949287628
parent 1019 0c733dab0036
child 1021 200f2d9b9f39
uncommit: saner locking scheme (and do it in the right order in the process)
hgext/evolve.py
--- a/hgext/evolve.py	Wed Aug 06 17:40:55 2014 -0700
+++ b/hgext/evolve.py	Wed Aug 06 17:08:51 2014 -0700
@@ -1953,44 +1953,43 @@
 
     Return 0 if changed files are uncommitted.
     """
-    lock = repo.lock()
+
+    wlock = lock = None
     try:
         wlock = repo.wlock()
-        try:
-            wctx = repo[None]
-            if len(wctx.parents()) <= 0:
-                raise util.Abort(_("cannot uncommit null changeset"))
-            if len(wctx.parents()) > 1:
-                raise util.Abort(_("cannot uncommit while merging"))
-            old = repo['.']
-            if old.phase() == phases.public:
-                raise util.Abort(_("cannot rewrite immutable changeset"))
-            if len(old.parents()) > 1:
-                raise util.Abort(_("cannot uncommit merge changeset"))
-            oldphase = old.phase()
-            updatebookmarks = _bookmarksupdater(repo, old.node())
-            # Recommit the filtered changeset
-            newid = None
-            if (pats or opts.get('include') or opts.get('exclude')
-                or opts.get('all')):
-                match = scmutil.match(old, pats, opts)
-                newid = _commitfiltered(repo, old, match)
-            if newid is None:
-                raise util.Abort(_('nothing to uncommit'),
-                                 hint=_("use --all to uncommit all files"))
-            # Move local changes on filtered changeset
-            createmarkers(repo, [(old, (repo[newid],))])
-            retractboundary(repo, oldphase, [newid])
-            repo.dirstate.setparents(newid, node.nullid)
-            _uncommitdirstate(repo, old, match)
-            updatebookmarks(newid)
-            if not repo[newid].files():
-                ui.warn(_("new changeset is empty\n"))
-                ui.status(_('(use "hg prune ." to remove it)\n'))
-        finally:
-            wlock.release()
+        lock = repo.lock()
+        wctx = repo[None]
+        if len(wctx.parents()) <= 0:
+            raise util.Abort(_("cannot uncommit null changeset"))
+        if len(wctx.parents()) > 1:
+            raise util.Abort(_("cannot uncommit while merging"))
+        old = repo['.']
+        if old.phase() == phases.public:
+            raise util.Abort(_("cannot rewrite immutable changeset"))
+        if len(old.parents()) > 1:
+            raise util.Abort(_("cannot uncommit merge changeset"))
+        oldphase = old.phase()
+        updatebookmarks = _bookmarksupdater(repo, old.node())
+        # Recommit the filtered changeset
+        newid = None
+        if (pats or opts.get('include') or opts.get('exclude')
+            or opts.get('all')):
+            match = scmutil.match(old, pats, opts)
+            newid = _commitfiltered(repo, old, match)
+        if newid is None:
+            raise util.Abort(_('nothing to uncommit'),
+                             hint=_("use --all to uncommit all files"))
+        # Move local changes on filtered changeset
+        createmarkers(repo, [(old, (repo[newid],))])
+        retractboundary(repo, oldphase, [newid])
+        repo.dirstate.setparents(newid, node.nullid)
+        _uncommitdirstate(repo, old, match)
+        updatebookmarks(newid)
+        if not repo[newid].files():
+            ui.warn(_("new changeset is empty\n"))
+            ui.status(_('(use "hg prune ." to remove it)\n'))
     finally:
-        lock.release()
+        lockmod.release(lock, wlock)
 
 @eh.wrapcommand('commit')
 def commitwrapper(orig, ui, repo, *arg, **kwargs):