-1

I'm trying to create a Mercurial repository with a changegroup or pretxnchangegroup hook that inspects the commit, possibly makes some changes to it, then commits the changes. My hook does something similar to this:

#!/bin/sh
if ! grep -q foobar foobar; then
  echo foobar >> foobar
  hg add foobar
  hg commit -m 'added foobar to foobar'
fi

But when I push to the remote repository which has the hook it hangs waiting on a lock and I have to kill it:

$ hg push
pushing to /tmp/a
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
foobar already tracked!
waiting for lock on repository /tmp/a held by 'duck:18140'
^Ctransaction abort!
rollback completed
interrupted!
interrupted!

This makes sense because I understand that the changegroup must hold a write lock on the repository, and so must the commit that is inside of the hook. But how can I work around this problem?

I can think of two methods that might work, but don't know if they are possible:

  1. If there was a hook that runs after the changegroup is complete and the locks are released, I could run the commit there.
  2. Append a changeset to the incoming changegroup.
Scott Duckworth
  • 627
  • 4
  • 13

2 Answers2

0

You shouldn't try to modify a changeset in a hook since it is a external process that couldn't handle conflicts etc. Besides, I think that it isn't even possible or desirable. The original changeset would remain intact and it would cause duplication problems some day.

What you can do is approve or not a incoming changeset based in some criteria. If a changeset isn't approved, it's up to the developer modify it in his repository and then push it again.

andref
  • 750
  • 5
  • 20
  • I wasn't trying to modify a changeset, only append a changeset to a changegroup, or commit a new changeset. I would tend to agree with your comment that it's not desirable to modify commits with arbitrary code, but in this case I'm dealing with structured YAML documents, and was mainly interested in filling in missing fields in the hook. I was able to do this in the changegroup hook by adding a new commit. – Scott Duckworth May 23 '13 at 14:31
0

I figured out that only the pretxnchangegroup hook locks the repository. The changegroup hook does not lock the repository, and performing a commit in that hook is okay.

Scott Duckworth
  • 627
  • 4
  • 13