Question

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.
Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top