libgit2/libgit2 — pull request #1579 by arrbee (2013-05-13 23:19:43+00:00)
Title: Index entry dup and free

This is one possible way of addressing #1576 ("Memory management for `git_index_entry`?")

This adds functions to dup a `git_index_entry` and to free the copied value, plus it adds flags to the `flags_extended` in memory flags to track who allocated the structure.

This also updates the documentation for `git_index_get_bypath` and `git_index_get_byindex` to make it clear that the user should not modify the `const git_index_entry *` that is returned from those functions. I also updated the documentation for the bitmasks used to access the `flags` and `flags_extended` values because I thought it was a little unclear.

The approach I'm currently taking here may not be right. I allocate the path in the same block as the index entry itself so that it doesn't have to be freed separately and then added yet another flag that the binding can set if it wants `git_index_entry_free()` to call `free()` on the path (in case it sets it to a new value). This is a little odd, but I'm struggling to think of something obviously better. There are a number of other possible approaches enumerated in the comments on #1576.

Since `git_index_entry` is a public structure, I dismissed adding a `git_index_entry_copy` function because any binding can just use regular memcpy to do that and can deal more intelligently with the path string that I would know how to on its behalf.

Feedback wanted!