hgext/evolve.py
branchstable
changeset 1308 676d88a82d4a
parent 1307 677c5da57b9c
child 1309 b621e5da03e1
--- a/hgext/evolve.py	Thu Apr 30 14:40:36 2015 -0700
+++ b/hgext/evolve.py	Thu Apr 30 14:47:01 2015 -0700
@@ -2061,10 +2061,7 @@
                 repo._bookmarks.write()
         return result
     finally:
-        if lock is not None:
-            lock.release()
-        if wlock is not None:
-            wlock.release()
+        lockmod.release(lock, wlock)
 
 @command('^touch',
     [('r', 'rev', [], 'revision to update'),
@@ -2088,40 +2085,37 @@
         return 1
     if not duplicate and repo.revs('public() and %ld', revs):
         raise util.Abort("can't touch public revision")
-    wlock = lock = None
+    wlock = lock = tr = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
         tr = repo.transaction('touch')
         revs.sort() # ensure parent are run first
         newmapping = {}
-        try:
-            for r in revs:
-                ctx = repo[r]
-                extra = ctx.extra().copy()
-                extra['__touch-noise__'] = random.randint(0, 0xffffffff)
-                # search for touched parent
-                p1 = ctx.p1().node()
-                p2 = ctx.p2().node()
-                p1 = newmapping.get(p1, p1)
-                p2 = newmapping.get(p2, p2)
-                new, unusedvariable = rewrite(repo, ctx, [], ctx,
-                                              [p1, p2],
-                                              commitopts={'extra': extra})
-                # store touched version to help potential children
-                newmapping[ctx.node()] = new
-                if not duplicate:
-                    obsolete.createmarkers(repo, [(ctx, (repo[new],))])
-                phases.retractboundary(repo, tr, ctx.phase(), [new])
-                if ctx in repo[None].parents():
-                    repo.dirstate.beginparentchange()
-                    repo.dirstate.setparents(new, node.nullid)
-                    repo.dirstate.endparentchange()
-            tr.close()
-        finally:
-            tr.release()
+        for r in revs:
+            ctx = repo[r]
+            extra = ctx.extra().copy()
+            extra['__touch-noise__'] = random.randint(0, 0xffffffff)
+            # search for touched parent
+            p1 = ctx.p1().node()
+            p2 = ctx.p2().node()
+            p1 = newmapping.get(p1, p1)
+            p2 = newmapping.get(p2, p2)
+            new, unusedvariable = rewrite(repo, ctx, [], ctx,
+                                          [p1, p2],
+                                          commitopts={'extra': extra})
+            # store touched version to help potential children
+            newmapping[ctx.node()] = new
+            if not duplicate:
+                obsolete.createmarkers(repo, [(ctx, (repo[new],))])
+            phases.retractboundary(repo, tr, ctx.phase(), [new])
+            if ctx in repo[None].parents():
+                repo.dirstate.beginparentchange()
+                repo.dirstate.setparents(new, node.nullid)
+                repo.dirstate.endparentchange()
+        tr.close()
     finally:
-        lockmod.release(lock, wlock)
+        lockmod.release(tr, lock, wlock)
 
 @command('^fold|squash',
     [('r', 'rev', [], _("revision to fold")),
@@ -2574,18 +2568,16 @@
 @eh.addattr(localrepo.localpeer, 'evoext_pushobsmarkers_0')
 def local_pushobsmarkers(peer, obsfile):
     data = obsfile.read()
-    lock = peer._repo.lock()
+    tr = lock = None
     try:
+        lock = peer._repo.lock()
         tr = peer._repo.transaction('pushkey: obsolete markers')
-        try:
-            new = peer._repo.obsstore.mergemarkers(tr, data)
-            if new is not None:
-                obsexcmsg(peer._repo.ui, "%i obsolescence markers added\n" % new, True)
-            tr.close()
-        finally:
-            tr.release()
+        new = peer._repo.obsstore.mergemarkers(tr, data)
+        if new is not None:
+            obsexcmsg(peer._repo.ui, "%i obsolescence markers added\n" % new, True)
+        tr.close()
     finally:
-        lock.release()
+        lockmod.release(tr, lock)
     peer._repo.hook('evolve_pushobsmarkers')
 
 def srv_pushobsmarkers(repo, proto):
@@ -2595,18 +2587,16 @@
     proto.getfile(fp)
     data = fp.getvalue()
     fp.close()
-    lock = repo.lock()
+    tr = lock = None
     try:
+        lock = repo.lock()
         tr = repo.transaction('pushkey: obsolete markers')
-        try:
-            new = repo.obsstore.mergemarkers(tr, data)
-            if new is not None:
-                obsexcmsg(repo.ui, "%i obsolescence markers added\n" % new, True)
-            tr.close()
-        finally:
-            tr.release()
+        new = repo.obsstore.mergemarkers(tr, data)
+        if new is not None:
+            obsexcmsg(repo.ui, "%i obsolescence markers added\n" % new, True)
+        tr.close()
     finally:
-        lock.release()
+        lockmod.release(tr, lock)
     repo.hook('evolve_pushobsmarkers')
     return wireproto.pushres(0)