def METHOD_NAME(repo, tree, changes):
    """
    Given a tree, and a nested dictionary of changes to be made to that tree, returns a modified copy of that tree.
    Each dicts keys are path components, and the leaf values must be the desired new value at that path -
    either pygit2.Tree, a pygi2.Blob, a bytes, or None (None means delete the data at the specified path).
    Conflicts are not detected.
    """
    if tree is None:
        tree = _empty_tree(repo)
    if not changes:
        return tree
    tree_builder = repo.TreeBuilder(tree)
    for name, new_value in changes.items():
        if isinstance(new_value, dict):
            try:
                subtree = tree / name
            except KeyError:
                subtree = None
            subtree = METHOD_NAME(repo, subtree, new_value)
            tree_builder.insert(name, subtree.oid, pygit2.GIT_FILEMODE_TREE)
        elif isinstance(new_value, pygit2.Tree):
            tree_builder.insert(name, new_value.oid, pygit2.GIT_FILEMODE_TREE)
        elif isinstance(new_value, pygit2.Blob):
            tree_builder.insert(name, new_value.oid, pygit2.GIT_FILEMODE_BLOB)
        elif isinstance(new_value, bytes):
            blob_oid = repo.create_blob(new_value)
            tree_builder.insert(name, blob_oid, pygit2.GIT_FILEMODE_BLOB)
        elif isinstance(new_value, bytearray):
            blob_oid = repo.create_blob(bytes(new_value))
            tree_builder.insert(name, blob_oid, pygit2.GIT_FILEMODE_BLOB)
        elif new_value is None:
            try:
                tree_builder.remove(name)
            except pygit2.GitError:
                pass  # Conflicts are not detected.
    tree_oid = tree_builder.write()
    tree = repo[tree_oid]
    return tree