Update the repo to a given revision. Using clean passes -C to the hg up

def _update_repo(ret, name, target, clean, user, identity, rev, opts, update_head):
    '''
    Update the repo to a given revision. Using clean passes -C to the hg up
    '''
    log.debug('target %s is found, "hg pull && hg up is probably required"', target)

    current_rev = __salt__['hg.revision'](target, user=user, rev='.')
    if not current_rev:
        return _fail(
                ret,
                'Seems that {0} is not a valid hg repo'.format(target))

    if __opts__['test']:
        test_result = (
                'Repository {0} update is probably required (current '
                'revision is {1})').format(target, current_rev)
        return _neutral_test(
                ret,
                test_result)

    try:
        pull_out = __salt__['hg.pull'](target, user=user, identity=identity, opts=opts, repository=name)
    except CommandExecutionError as err:
        ret['result'] = False
        ret['comment'] = err
        return ret

    if update_head is False:
        changes = 'no changes found' not in pull_out
        if changes:
            ret['comment'] = 'Update is probably required but update_head=False so we will skip updating.'
        else:
            ret['comment'] = 'No changes found and update_head=False so will skip updating.'
        return ret

    if rev:
        try:
            __salt__['hg.update'](target, rev, force=clean, user=user)
        except CommandExecutionError as err:
            ret['result'] = False
            ret['comment'] = err
            return ret
    else:
        try:
            __salt__['hg.update'](target, 'tip', force=clean, user=user)
        except CommandExecutionError as err:
            ret['result'] = False
            ret['comment'] = err
            return ret

    new_rev = __salt__['hg.revision'](cwd=target, user=user, rev='.')

    if current_rev != new_rev:
        revision_text = '{0} => {1}'.format(current_rev, new_rev)
        log.info('Repository %s updated: %s', target, revision_text)
        ret['comment'] = 'Repository {0} updated.'.format(target)
        ret['changes']['revision'] = revision_text
    elif 'error:' in pull_out:
        return _fail(
            ret,
            'An error was thrown by hg:\n{0}'.format(pull_out)
        )
    return ret