Added some mercurial support

This is a follow-up to https://github.com/composer/composer/pull/1503, because I crashed my repo and had to start over.

Compared to the original PR, this one contains the matching implementation for hg nad moves the rather complicated fuzzy logic into a separate method.