Commit 11aa20b0a28769aef959b1f8665b40aa5daadf0b

Dmitry Lobanov 2021-05-26T14:06:31

submodule: git submodule dup object dup has been added.

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)