submodule: git submodule dup object dup has been added.
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
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index 139a0cb..e5bd4c7 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -224,11 +224,13 @@ GIT_EXTERN(int) git_submodule_lookup(
const char *name);
/**
- * Dup (retain) a submodule
+ * Create an in-memory copy of a submodule. The copy must be explicitly
+ * free'd or it will leak.
*
- * @param submodule Submodule object
+ * @param out Pointer to store the copy of the submodule
+ * @param source Original tag to copy
*/
-GIT_EXTERN(git_submodule *) git_submodule_dup(git_submodule *submodule);
+GIT_EXTERN(int) git_submodule_dup(git_submodule **out, git_submodule *source);
/**
* Release a submodule
diff --git a/src/submodule.c b/src/submodule.c
index b78bef2..598a24a 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1854,12 +1854,9 @@ static void submodule_release(git_submodule *sm)
git__free(sm);
}
-git_submodule* git_submodule_dup(git_submodule *sm)
+int git_submodule_dup(git_submodule **out, git_submodule *source)
{
- if (!sm)
- return NULL;
- GIT_REFCOUNT_INC(sm);
- return sm;
+ return git_object_dup((git_object **)out, (git_object *)source);
}
void git_submodule_free(git_submodule *sm)