Given a url, try to guess what kind of VCS it's for.  Return None if we
    can't make a good guess.

def guess_url_vcs(url):
    """
    Given a url, try to guess what kind of VCS it's for.  Return None if we
    can't make a good guess.
    """
    parsed = urllib.parse.urlsplit(url)

    if parsed.scheme in ('git', 'svn'):
        return parsed.scheme
    elif parsed.path.endswith('.git'):
        return 'git'
    elif parsed.hostname == 'github.com':
        return 'git'

    # If it's an http url, we can try requesting it and guessing from the
    # contents.
    if parsed.scheme in ('http', 'https'):
        resp = requests.get(url)
        if re.match('basehttp.*python.*', resp.headers.get('server').lower()):
            # It's the mercurial http server
            return 'hg'
    return None