Mercurial support tweaks

Fixes for all the issues I brought up in your PR, plus a few bonus changes. If you'd prefer, I'm happy to open a PR with both of our commits directly to @bpinto's repo :)