Align git_tree_entry_dup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 4223656..6350ada 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -150,10 +150,11 @@ GIT_EXTERN(int) git_tree_entry_bypath(
* Create a copy of a tree entry. The returned copy is owned by the user,
* and must be freed explicitly with `git_tree_entry_free()`.
*
- * @param entry A tree entry to duplicate
- * @return a copy of the original entry or NULL on error (alloc failure)
+ * @param dest pointer where to store the copy
+ * @param entry tree entry to duplicate
+ * @return 0 or an error code
*/
-GIT_EXTERN(git_tree_entry *) git_tree_entry_dup(const git_tree_entry *entry);
+GIT_EXTERN(int) git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source);
/**
* Free a user-owned tree entry
diff --git a/src/tree.c b/src/tree.c
index 4d77ff7..fc105ed 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -204,22 +204,22 @@ void git_tree_entry_free(git_tree_entry *entry)
git__free(entry);
}
-git_tree_entry *git_tree_entry_dup(const git_tree_entry *entry)
+int git_tree_entry_dup(git_tree_entry **dest, const git_tree_entry *source)
{
size_t total_size;
git_tree_entry *copy;
- assert(entry);
+ assert(source);
- total_size = sizeof(git_tree_entry) + entry->filename_len + 1;
+ total_size = sizeof(git_tree_entry) + source->filename_len + 1;
copy = git__malloc(total_size);
- if (!copy)
- return NULL;
+ GITERR_CHECK_ALLOC(copy);
- memcpy(copy, entry, total_size);
+ memcpy(copy, source, total_size);
- return copy;
+ *dest = copy;
+ return 0;
}
void git_tree__free(void *_tree)
@@ -853,8 +853,7 @@ int git_tree_entry_bypath(
case '\0':
/* If there are no more components in the path, return
* this entry */
- *entry_out = git_tree_entry_dup(entry);
- return 0;
+ return git_tree_entry_dup(entry_out, entry);
}
if (git_tree_lookup(&subtree, root->object.repo, &entry->oid) < 0)