

def name_to_object(repo, name, return_ref=False):
    '\n    :return: object specified by the given name, hexshas ( short and long )\n        as well as references are supported\n    :param return_ref: if name specifies a reference, we will return the reference\n        instead of the object. Otherwise it will raise BadObject or BadName\n    '
    hexsha = None
    if repo.re_hexsha_shortened.match(name):
        if (len(name) != 40):
            hexsha = short_to_long(repo.odb, name)
        else:
            hexsha = name
    if (hexsha is None):
        for base in ('%s', 'refs/%s', 'refs/tags/%s', 'refs/heads/%s', 'refs/remotes/%s', 'refs/remotes/%s/HEAD'):
            try:
                hexsha = SymbolicReference.dereference_recursive(repo, (base % repo))
                if return_ref:
                    return SymbolicReference(repo, (base % name))
                break
            except ValueError:
                pass
    if return_ref:
        raise BadObject(("Couldn't find reference named %r" % name))
    if (hexsha is None):
        raise BadName(name)
    return Object.new_from_sha(repo, hex_to_bin(hexsha))

dataset/ETHPy150Open gitpython-developers/GitPython/git/repo/fun.py name_to_object/VarMisuse@111/281 `name`->`repo`