This also updates all applicable callers so we get some testing of it.
Note that rebase and histedit can't be fixed yet because they call
cleanupnodes() only at the end and the phase may have been changed by
the user when the rebase/histedit was interrupted (due to merge
conflicts).
Also not that amend can't rely on cleanupnodes, because it allows the
phase to be overridden on the command line (using `hg amend
--secret`).