I've encountered an interesting problem when integrating a Mercurial repository into Review Board via pretxnchangegroup hook.
The initial idea should have worked like this:
Client does a special "hg push dance" to review repository.
This push triggers a hook that creates review requests inside Review Board.
If review request creation fails for some reason, client can simply try that hg push dance again until it succeeds.
In order to satisfy the last requirement (retry the push to retry review request creation), I initially planned to use Mercurial's pretxnchangegroup hook.
That hook runs inside an unconfirmed isolated transaction that is not yet a part of main history.
If the hook returns a non-zero exit code, transaction is rolled back and repository remains unchanged, allowing a client to simply push again.
So far so good, but it turns out that in order to create a review request, Review Board needs to inspect a changeset inside Mercurial repository.
As that changeset is inside the isolated transaction, it's not visible to Review Board, so review request can not be created.
This is kind of chicken-and-egg problem: we need to confirm a transaction in order to create review request, but we can't confirm the transaction until review request is successfully created.
As a temporary workaround, I've switched from pretxnchangegroup hook to changegroup hook.
The downside is that if there was an error creating review request, client can't simply push again and expect that missing review requests will be created automatically.
We'd have to rewrite history inside changegroup hook to allow that and it could create more problems than it'd solve.
Actually, right now we have to use both pretxnchangegroup and changegroup hooks, because we have to validate the bug number and auth credentials in pretxnchangegroup hook, then actually try to create review requests in changegroup hook (and that can fail still).
I was looking for some low-level CLI commands for dealing with Mercurial transactions, but couldn't find anything online.
Eventually I figured out that Mercurial uses a special HG_PENDING env var to access changesets inside a pending transaction.
So we could patch Review Board to use this env var when inspecting the repository, but there may be some side effects that I haven't considered.
Any advice?
Thanks,
George