def METHOD_NAME(fallback):
    # $...$ strings can be overwitten by `git archive` if `.gitattributes`
    # is configured with `.../_version.py export-subst`
    # if commit is tagged, refnames contains `tag: <name>` pairs for each tag
    refnames = "$Format:%D$"
    if not refnames.startswith("$Format"):
        refs = refnames.split(", ")
        tags = [
            ref.split("tag: ")[1] for ref in refs if ref.startswith("tag:")
        ]
        # if there is a tag, we return the first one
        if tags:
            return tags[0]
    commit_hash = "$Format:%h$"
    if not commit_hash.startswith("$Format"):
        return f"{fallback}+g{commit_hash}"
    return None