touch: simplify locking pattern stable
authorPatrick Mezard <patrick@mezard.eu>
Sat, 25 Aug 2012 09:20:15 +0200
branchstable
changeset 514 ea667749ccd1
parent 513 4602104b190d
child 515 0b60c28d9c43
touch: simplify locking pattern
hgext/evolve.py
--- a/hgext/evolve.py	Sat Aug 25 08:51:37 2012 +0200
+++ b/hgext/evolve.py	Sat Aug 25 09:20:15 2012 +0200
@@ -39,6 +39,7 @@
 from mercurial import extensions
 from mercurial import hg
 from mercurial import localrepo
+from mercurial import lock as lockmod
 from mercurial import merge
 from mercurial import node
 from mercurial import phases
@@ -1992,30 +1993,28 @@
         return 1
     if repo.revs('public() and %ld', revs):
         raise util.Abort("can't touch public revision")
-    wlock = repo.wlock()
+    wlock = lock = None
     try:
+        wlock = repo.wlock()
         lock = repo.lock()
+        tr = repo.transaction('touch')
         try:
-            tr = repo.transaction('touch')
-            try:
-                for r in revs:
-                    ctx = repo[r]
-                    extra = ctx.extra().copy()
-                    extra['__touch-noise__'] = random.randint(0, 0xffffffff)
-                    new, _ = rewrite(repo, ctx, [], ctx,
-                                     [ctx.p1().node(), ctx.p2().node()],
-                                     commitopts={'extra': extra})
-                    createmarkers(repo, [(ctx, (repo[new],))])
-                    phases.retractboundary(repo, ctx.phase(), [new])
-                    if ctx in repo[None].parents():
-                        repo.dirstate.setparents(new, node.nullid)
-                tr.close()
-            finally:
-                tr.release()
+            for r in revs:
+                ctx = repo[r]
+                extra = ctx.extra().copy()
+                extra['__touch-noise__'] = random.randint(0, 0xffffffff)
+                new, _ = rewrite(repo, ctx, [], ctx,
+                                 [ctx.p1().node(), ctx.p2().node()],
+                                 commitopts={'extra': extra})
+                createmarkers(repo, [(ctx, (repo[new],))])
+                phases.retractboundary(repo, ctx.phase(), [new])
+                if ctx in repo[None].parents():
+                    repo.dirstate.setparents(new, node.nullid)
+            tr.close()
         finally:
-            lock.release()
+            tr.release()
     finally:
-        wlock.release()
+        lockmod.release(lock, wlock)
 
 @command('^fold',
     [('r', 'rev', [], 'revision to fold'),],