Get list of changesets in a changegroup (mercurial python hook)
I want a mercurial hook that will run JSLint/PyChecker/etc on all files that are modified. However, I do not have control over all hg clients, and want this to run on push to the master repository (which I have control), so a pretxnchangegroup hook on the master seems best.
How can I get a list of all changesets that are in the changegroup that is going to be committed?
I have seem other solutions that use a precommit hook, but these will not work for me because the clients may already have a commit that fails JSLint. In this case, they should be able to fix the errors in a new commit, and be a开发者_开发百科ble to push (both the bad and new commits) to the server successfully. The server just needs to check the most recent changeset on each branch, of every file that was modified in the changegroup.
You're right that you want a pretxnchangegroup hook, but you don't want to check all the new revisions -- because people will fix the errors you reject in subsequent changesets but if you're checking all changesets their work will never be accepted!
Instead either just check all files in all the heads, or use the hg status --rev x:y
syntax to get a list of the changed files between the revision you already have and the tip revision you're receiving, and check only those files only in the tip revision.
If you really want the list of all revisions you'd use a revset ( hg help revsets
) new in version 1.6, but you really only want to check the results, not all the revisions that get you there.
I just wrote a pretxnchangegroup hook that does exactly this. If you want all files that have changed in the current changegroup, you can get the union of the output of these two commands:
hg status --rev $HG_NODE:
(note the trailing colon)
and
hg status --change $HG_NODE
When pushing between two repositories on the same machine, the first command seems to be sufficient, but when pushing to a remote repository, the first command would miss files changed in the first changeset in the changegroup, which is where the second command comes in.
According to http://www.selenic.com/mercurial/hgrc.5.html, "ID of the first new changeset is in $HG_NODE."
Does my answer to this help at all? https://stackoverflow.com/a/8615156/1025457
It is the skeleton of a pretxnchangegroup hook that iterates over the nodes in the changegroup
精彩评论