changeset 23129:eb315418224c stable

hook: protect commit hooks against stripping of temporary commit (issue4422) History rewriting commands like histedit tend to use temporary commits. They may schedule hook execution on these temporary commits for after the lock has been released. But temporary commits are likely to have been stripped before the lock is released (and the hook run). Hook executed for missing revisions leads to various crashes. We disable hooks execution for revision missing in the repo. This provides a dirty but simple fix to user issues.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 01 Nov 2014 23:17:50 +0000
parents b6f7cf47f5d1
children ced632394371
files mercurial/localrepo.py tests/test-histedit-fold.t
diffstat 2 files changed, 47 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Sat Nov 01 22:59:37 2014 +0000
+++ b/mercurial/localrepo.py	Sat Nov 01 23:17:50 2014 +0000
@@ -1370,7 +1370,11 @@
             wlock.release()
 
         def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
-            self.hook("commit", node=node, parent1=parent1, parent2=parent2)
+            # hack for command that use a temporary commit (eg: histedit)
+            # temporary commit got stripped before hook release
+            if node in self:
+                self.hook("commit", node=node, parent1=parent1,
+                          parent2=parent2)
         self._afterlock(commithook)
         return ret
 
--- a/tests/test-histedit-fold.t	Sat Nov 01 22:59:37 2014 +0000
+++ b/tests/test-histedit-fold.t	Sat Nov 01 23:17:50 2014 +0000
@@ -446,3 +446,45 @@
   0:6c795aa153cb a
 
   $ cd ..
+
+Folding with swapping
+---------------------
+
+This is an excuse to test hook with histedit temporary commit (issue4422)
+
+
+  $ hg init issue4422
+  $ cd issue4422
+  $ echo a > a.txt
+  $ hg add a.txt
+  $ hg commit -m a
+  $ echo b > b.txt
+  $ hg add b.txt
+  $ hg commit -m b
+  $ echo c > c.txt
+  $ hg add c.txt
+  $ hg commit -m c
+
+  $ hg logt
+  2:a1a953ffb4b0 c
+  1:199b6bb90248 b
+  0:6c795aa153cb a
+
+  $ hg histedit 6c795aa153cb --config hooks.commit="echo commit \$HG_NODE" --commands - 2>&1 << EOF | fixbundle
+  > pick 199b6bb90248 b
+  > fold a1a953ffb4b0 c
+  > pick 6c795aa153cb a
+  > EOF
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  commit 9599899f62c05f4377548c32bf1c9f1a39634b0c
+
+  $ hg logt
+  1:9599899f62c0 a
+  0:79b99e9c8e49 b
+
+  $ cd ..