Bug 4422 - histedit: commit hook errors
Summary: histedit: commit hook errors
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: histedit (show other bugs)
Version: 3.2-rc
Hardware: PC Linux
: urgent bug
Assignee: Bugzilla
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2014-10-28 01:25 UTC by Alexander Drozdov
Modified: 2015-01-22 15:04 UTC (History)
4 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Drozdov 2014-10-28 01:25 UTC
I have a commit hook named showrev:

from mercurial.node import short

def print_commit(ui, repo, node=None, **kwargs):
  ctx = repo[node]
  ui.write("Committed revision %s:%s %s by %s\n" %
           (ctx.rev(), short(ctx.node()), ctx.branch(), ctx.user()))

When I use histedit to fold any revisions I get errors like:

error: commit.showrev hook raised an exception: unknown revision 'e4ddc3643fb10c110659f30b37759caac521cd08'

bisect shows that the bad revision is 4778f398ec83

Script to reproduce:

#!/bin/sh

rm -rf hg-temp
mkdir hg-temp
cd hg-temp
hg init
touch file1 && hg add file1
hg commit -m file1
touch file2 && hg add file2
hg commit -m file2
hg histedit 0
# fold two revisions
Comment 1 Siddharth Agarwal 2014-10-28 01:46 UTC
When does your hook run?
Comment 2 Siddharth Agarwal 2014-10-28 01:49 UTC
ah, it's a hook on 'commit', and I presume holding the lock for the duration of the histedit delays the commit. Not sure if this is BC breakage, but try a pretxncommit hook.
Comment 3 Alexander Drozdov 2014-10-28 02:12 UTC
With pretxncommit there are no errors.
Comment 4 Pierre-Yves David 2014-10-28 04:06 UTC
What (is probably happening) here is:


  lock:
    transaction is created:
      histedit create temporary commit
      "pretxncommit" hooks run
    transaction is closed: "commit" hook are scheduled for hook release
    temporary commit are stripped
  unlock: "commit" hook is run

It is going to be hard to craft a clean solution quickly. But this smell like a regression and we should probably offer and acceptable work around.
Comment 5 Matt Mackall 2014-10-28 04:09 UTC
regression -> urgent

Is this specific to (totally unsupported) internal Python hooks or does it also break with external hooks?

I think the commit hook(s) are getting deferred to lock release, at which time temporary commits may have disappeared?
Comment 6 Pierre-Yves David 2014-10-28 04:14 UTC
The internal hook crash because the revision is not found. External hook will be run with a HG_NODE containing an unknown hash.
Comment 7 HG Bot 2014-11-01 19:46 UTC
Fixed by http://selenic.com/repo/hg/rev/eb315418224c
Pierre-Yves David <pierre-yves.david@fb.com>
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.

(please test the fix)
Comment 8 Alexander Drozdov 2014-11-02 01:16 UTC
It looks to be fixed. Thanks!
Comment 9 Matt Mackall 2015-01-22 15:04 UTC
Bulk testing -> fixed