Add priority to VCS identification algorithm.

When nesting one repository inside another (e.g., when $HOME is
kept in a Git repository, but $HOME/some_hg_project is kept in
a Mercurial repository), priority is given to the more local
repository (Mercurial, in this case).

The concept of an exact match is retained by giving such matches
priority 1.