Returns the long hash of a given identifier (hash, branch, tag, HEAD, etc)

    cwd
        The path to the Mercurial repository

    rev: tip
        The revision

    short: False
        Return an abbreviated commit hash

    user : None
        Run hg as a user other than what the minion runs as

    CLI Example:

    .. code-block:: bash

        salt '*' hg.revision /path/to/repo mybranch

def revision(cwd, rev='tip', short=False, user=None):
    '''
    Returns the long hash of a given identifier (hash, branch, tag, HEAD, etc)

    cwd
        The path to the Mercurial repository

    rev: tip
        The revision

    short: False
        Return an abbreviated commit hash

    user : None
        Run hg as a user other than what the minion runs as

    CLI Example:

    .. code-block:: bash

        salt '*' hg.revision /path/to/repo mybranch
    '''
    cmd = [
            'hg',
            'id',
            '-i',
            '--debug' if not short else '',
            '-r',
            '{0}'.format(rev)]

    result = __salt__['cmd.run_all'](
            cmd,
            cwd=cwd,
            runas=user,
            python_shell=False)

    if result['retcode'] == 0:
        return result['stdout']
    else:
        return ''