Repeatedly allocating and freeing the `git_index_entry` here seems wasteful to me. Could this loop not read, instead:

```c
for (i = 0; i < git_diff_num_deltas(diff); i++) {
    git_index_entry entry;

    if ((error = git_diff_get_patch(NULL, &delta, diff, i)) < 0)
        goto cleanup;

    memset(&entry, 0, sizeof(entry));
    entry->mode = delta->new_file.mode;
    entry->oid  = delta->new_file.oid;
    entry->path = delta->new_file.path;

    switch (delta->status) {
    ...
    }
}
```

Since the entry only has to exist for a moment in order to call `git_index_add()`, this would save two unnecessary alloc/frees per iteration of the loop. Additionally, if you were to do it this way, all the `git_index_entry__free()` exports could go away and the overall patch size would be reduced.