Commits

Patrick Mézard committed ea66774

touch: simplify locking pattern

Comments (0)

Files changed (1)

 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
         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'),],