Commit 575a54db by Vicent Marti

object: Export git_object_dup

parent 90431f1b
...@@ -188,6 +188,15 @@ GIT_EXTERN(int) git_object_peel( ...@@ -188,6 +188,15 @@ GIT_EXTERN(int) git_object_peel(
const git_object *object, const git_object *object,
git_otype target_type); git_otype target_type);
/**
* Create an in-memory copy of a Git object. The copy must be
* explicitly free'd or it will leak.
*
* @param dest Pointer to store the copy of the object
* @param source Original object to copy
*/
GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -578,7 +578,7 @@ int git_iterator_for_tree( ...@@ -578,7 +578,7 @@ int git_iterator_for_tree(
if (tree == NULL) if (tree == NULL)
return git_iterator_for_nothing(iter, flags, start, end); return git_iterator_for_nothing(iter, flags, start, end);
if ((error = git_tree__dup(&tree, tree)) < 0) if ((error = git_object_dup((git_object **)&tree, (git_object *)tree)) < 0)
return error; return error;
ITERATOR_BASE_INIT(ti, tree, TREE, git_tree_owner(tree)); ITERATOR_BASE_INIT(ti, tree, TREE, git_tree_owner(tree));
......
...@@ -360,7 +360,7 @@ int git_object_peel( ...@@ -360,7 +360,7 @@ int git_object_peel(
assert(object && peeled); assert(object && peeled);
if (git_object_type(object) == target_type) if (git_object_type(object) == target_type)
return git_object__dup(peeled, (git_object *)object); return git_object_dup(peeled, (git_object *)object);
source = (git_object *)object; source = (git_object *)object;
...@@ -396,3 +396,9 @@ int git_object_peel( ...@@ -396,3 +396,9 @@ int git_object_peel(
return error; return error;
} }
int git_object_dup(git_object **dest, git_object *source)
{
git_cached_obj_incref(source);
*dest = source;
return 0;
}
...@@ -17,13 +17,6 @@ struct git_object { ...@@ -17,13 +17,6 @@ struct git_object {
/* fully free the object; internal method, DO NOT EXPORT */ /* fully free the object; internal method, DO NOT EXPORT */
void git_object__free(void *object); void git_object__free(void *object);
GIT_INLINE(int) git_object__dup(git_object **dest, git_object *source)
{
git_cached_obj_incref(source);
*dest = source;
return 0;
}
int git_object__from_odb_object( int git_object__from_odb_object(
git_object **object_out, git_object **object_out,
git_repository *repo, git_repository *repo,
......
...@@ -934,7 +934,7 @@ int git_reference_peel( ...@@ -934,7 +934,7 @@ int git_reference_peel(
} }
if (target_type == GIT_OBJ_ANY && git_object_type(target) != GIT_OBJ_TAG) if (target_type == GIT_OBJ_ANY && git_object_type(target) != GIT_OBJ_TAG)
error = git_object__dup(peeled, target); error = git_object_dup(peeled, target);
else else
error = git_object_peel(peeled, target, target_type); error = git_object_peel(peeled, target, target_type);
......
...@@ -432,7 +432,7 @@ static int dereference_to_non_tag(git_object **out, git_object *obj) ...@@ -432,7 +432,7 @@ static int dereference_to_non_tag(git_object **out, git_object *obj)
if (git_object_type(obj) == GIT_OBJ_TAG) if (git_object_type(obj) == GIT_OBJ_TAG)
return git_tag_peel(out, (git_tag *)obj); return git_tag_peel(out, (git_tag *)obj);
return git_object__dup(out, obj); return git_object_dup(out, obj);
} }
static int handle_caret_parent_syntax(git_object **out, git_object *obj, int n) static int handle_caret_parent_syntax(git_object **out, git_object *obj, int n)
......
...@@ -30,11 +30,6 @@ struct git_treebuilder { ...@@ -30,11 +30,6 @@ struct git_treebuilder {
size_t entrycount; /* vector may contain "removed" entries */ size_t entrycount; /* vector may contain "removed" entries */
}; };
GIT_INLINE(int) git_tree__dup(git_tree **dest, git_tree *source)
{
return git_object__dup((git_object **)dest, (git_object *)source);
}
GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e) GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
{ {
return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr)); return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr));
......
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