Handle invalid repositories with Mercurial.

Mercurial wasn't doing any repository validation, meaning a broken
repository path could be used. It also didn't catch the connection
attempts later, causing HTTP 500 errors.

We now have a check_repository that attempts to connect, and some sanity
checking when connecting later on, to make sure users see that something
is wrong.
Merge branch 'release-1.7.x'