git_object_dup: introduce typesafe versions
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
diff --git a/include/git2/blob.h b/include/git2/blob.h
index f451593..6377fc2 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -259,6 +259,15 @@ GIT_EXTERN(int) git_blob_create_frombuffer(
*/
GIT_EXTERN(int) git_blob_is_binary(const git_blob *blob);
+/**
+ * Create an in-memory copy of a blob. The copy must be explicitly
+ * free'd or it will leak.
+ *
+ * @param out Pointer to store the copy of the object
+ * @param source Original object to copy
+ */
+GIT_EXTERN(int) git_blob_dup(git_blob **out, git_blob *source);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/commit.h b/include/git2/commit.h
index f63a906..4cc6374 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -461,6 +461,15 @@ GIT_EXTERN(int) git_commit_create_with_signature(
const char *signature,
const char *signature_field);
+/**
+ * Create an in-memory copy of a commit. The copy must be explicitly
+ * free'd or it will leak.
+ *
+ * @param out Pointer to store the copy of the commit
+ * @param source Original commit to copy
+ */
+GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/tag.h b/include/git2/tag.h
index c822cee..cb95fb5 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -347,6 +347,15 @@ GIT_EXTERN(int) git_tag_peel(
git_object **tag_target_out,
const git_tag *tag);
+/**
+ * Create an in-memory copy of a tag. The copy must be explicitly
+ * free'd or it will leak.
+ *
+ * @param out Pointer to store the copy of the tag
+ * @param source Original tag to copy
+ */
+GIT_EXTERN(int) git_tag_dup(git_tag **out, git_tag *source);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 550a448..8a2be21 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -409,6 +409,15 @@ GIT_EXTERN(int) git_tree_walk(
git_treewalk_cb callback,
void *payload);
+/**
+ * Create an in-memory copy of a tree. The copy must be explicitly
+ * free'd or it will leak.
+ *
+ * @param out Pointer to store the copy of the tree
+ * @param source Original tree to copy
+ */
+GIT_EXTERN(int) git_tree_dup(git_tree **out, git_tree *source);
+
/** @} */
GIT_END_DECL
diff --git a/src/commit.c b/src/commit.c
index aaefacd..5456751 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -615,7 +615,7 @@ int git_commit_nth_gen_ancestor(
assert(ancestor && commit);
- if (git_object_dup((git_object **) ¤t, (git_object *) commit) < 0)
+ if (git_commit_dup(¤t, (git_commit *)commit) < 0)
return -1;
if (n == 0) {
diff --git a/src/describe.c b/src/describe.c
index 13ddad5..fc48fbd 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -197,7 +197,7 @@ static int commit_name_dup(struct commit_name **out, struct commit_name *in)
name->tag = NULL;
name->path = NULL;
- if (in->tag && git_object_dup((git_object **) &name->tag, (git_object *) in->tag) < 0)
+ if (in->tag && git_tag_dup(&name->tag, in->tag) < 0)
return -1;
name->path = git__strdup(in->path);
diff --git a/src/iterator.c b/src/iterator.c
index f7b87fc..14182a8 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -820,7 +820,7 @@ int git_iterator_for_tree(
if (tree == NULL)
return git_iterator_for_nothing(iter, options);
- if ((error = git_object_dup((git_object **)&tree, (git_object *)tree)) < 0)
+ if ((error = git_tree_dup(&tree, tree)) < 0)
return error;
ti = git__calloc(1, sizeof(tree_iterator));
@@ -1849,7 +1849,7 @@ int git_iterator_for_workdir_ext(
return error;
}
- if (tree && (error = git_object_dup((git_object **)&wi->tree, (git_object *)tree)) < 0)
+ if (tree && (error = git_tree_dup(&wi->tree, tree)) < 0)
return error;
wi->index = index;
diff --git a/src/object_api.c b/src/object_api.c
index 838bba3..e0d8760 100644
--- a/src/object_api.c
+++ b/src/object_api.c
@@ -15,7 +15,7 @@
#include "tag.h"
/**
- * Blob
+ * Commit
*/
int git_commit_lookup(git_commit **out, git_repository *repo, const git_oid *id)
{
@@ -42,6 +42,10 @@ git_repository *git_commit_owner(const git_commit *obj)
return git_object_owner((const git_object *)obj);
}
+int git_commit_dup(git_commit **out, git_commit *obj)
+{
+ return git_object_dup((git_object **)out, (git_object *)obj);
+}
/**
* Tree
@@ -71,6 +75,10 @@ git_repository *git_tree_owner(const git_tree *obj)
return git_object_owner((const git_object *)obj);
}
+int git_tree_dup(git_tree **out, git_tree *obj)
+{
+ return git_object_dup((git_object **)out, (git_object *)obj);
+}
/**
* Tag
@@ -100,6 +108,11 @@ git_repository *git_tag_owner(const git_tag *obj)
return git_object_owner((const git_object *)obj);
}
+int git_tag_dup(git_tag **out, git_tag *obj)
+{
+ return git_object_dup((git_object **)out, (git_object *)obj);
+}
+
/**
* Blob
*/
@@ -127,3 +140,8 @@ git_repository *git_blob_owner(const git_blob *obj)
{
return git_object_owner((const git_object *)obj);
}
+
+int git_blob_dup(git_blob **out, git_blob *obj)
+{
+ return git_object_dup((git_object **)out, (git_object *)obj);
+}