rewriteutil: check for divergence

Authored by martinvonz.


rewriteutil: check for divergence

This code is adapted from the code in the evolve extension. It seems
to be equivalent as far as the evolve extension's test suite can tell
(the only impact when making their precheck() delegate to our
version is that error messages are less detailed).

I had to change the error message to work with "change branch of"
being inserted as the action.

Differential Revision: https://phab.mercurial-scm.org/D10518