Commit 529f342a by Arthur Schreiber

Align git_tree_entry_dup.

parent 29be3a6d
...@@ -150,10 +150,11 @@ GIT_EXTERN(int) git_tree_entry_bypath( ...@@ -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, * 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()`. * and must be freed explicitly with `git_tree_entry_free()`.
* *
* @param entry A tree entry to duplicate * @param dest pointer where to store the copy
* @return a copy of the original entry or NULL on error (alloc failure) * @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 * Free a user-owned tree entry
......
...@@ -204,22 +204,22 @@ void git_tree_entry_free(git_tree_entry *entry) ...@@ -204,22 +204,22 @@ void git_tree_entry_free(git_tree_entry *entry)
git__free(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; size_t total_size;
git_tree_entry *copy; 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); copy = git__malloc(total_size);
if (!copy) GITERR_CHECK_ALLOC(copy);
return NULL;
memcpy(copy, entry, total_size); memcpy(copy, source, total_size);
return copy; *dest = copy;
return 0;
} }
void git_tree__free(void *_tree) void git_tree__free(void *_tree)
...@@ -853,8 +853,7 @@ int git_tree_entry_bypath( ...@@ -853,8 +853,7 @@ int git_tree_entry_bypath(
case '\0': case '\0':
/* If there are no more components in the path, return /* If there are no more components in the path, return
* this entry */ * this entry */
*entry_out = git_tree_entry_dup(entry); return git_tree_entry_dup(entry_out, entry);
return 0;
} }
if (git_tree_lookup(&subtree, root->object.repo, &entry->oid) < 0) if (git_tree_lookup(&subtree, root->object.repo, &entry->oid) < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment