[PATCH 2 of 6 V2] localrepo: run commithook only if transaction is closed successfully

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Dec 16 11:50:50 CST 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1450287754 -32400
#      Thu Dec 17 02:42:34 2015 +0900
# Node ID 4210557127a602a91ce9958bb957e2a32493856b
# Parent  4c237821e543338dde6bfd395c28884f065399ec
localrepo: run commithook only if transaction is closed successfully

Before this patch, internal function "commithook()" is executed even
if transaction is aborted. Examination of 'changelog.hasnode()' in it
avoids actual making "commit" hooks run at failure of transaction.

But if transaction scope is nested, transaction is still active even
after 'transaction.close()' and may be aborted in subsequent
processing. If failure of transaction is known, instantiation of
'repo.changelog' itself is useless.

This patch runs 'commithook()' only if transaction is closed
successfully, by scheduling invocation of '_afterlock(commithook)' by
'transaction.addpostclose()'. This follows the style of
'cg1unpacker.apply()' for 'changegroup' hooks.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1616,18 +1616,21 @@ class localrepository(object):
             bookmarks.update(self, [p1, p2], ret)
             cctx.markcommitted(ret)
             ms.reset()
+
+            def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
+                # hack for command that use a temporary commit (eg: histedit)
+                # temporary commit got stripped before hook release
+                if self.changelog.hasnode(ret):
+                    self.hook("commit", node=node, parent1=parent1,
+                              parent2=parent2)
+            tr.addpostclose('run-hook-commit-%020i' % len(self.changelog),
+                            lambda tr: self._afterlock(commithook))
+
             tr.close()
 
         finally:
             lockmod.release(tr, lock, wlock)
 
-        def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
-            # hack for command that use a temporary commit (eg: histedit)
-            # temporary commit got stripped before hook release
-            if self.changelog.hasnode(ret):
-                self.hook("commit", node=node, parent1=parent1,
-                          parent2=parent2)
-        self._afterlock(commithook)
         return ret
 
     @unfilteredmethod


More information about the Mercurial-devel mailing list