object: Explicitly define helper API methods for all obj types
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
diff --git a/include/git2/commit.h b/include/git2/commit.h
index 0f76012..f536ac7 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -30,10 +30,7 @@ GIT_BEGIN_DECL
* an annotated tag it will be peeled back to the commit.
* @return 0 or an error code
*/
-GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id)
-{
- return git_object_lookup((git_object **)commit, repo, id, GIT_OBJ_COMMIT);
-}
+GIT_EXTERN(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id);
/**
* Lookup a commit object from a repository,
@@ -48,10 +45,7 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, size_t len)
-{
- return git_object_lookup_prefix((git_object **)commit, repo, id, len, GIT_OBJ_COMMIT);
-}
+GIT_EXTERN(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, size_t len);
/**
* Close an open commit
@@ -65,10 +59,7 @@ GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *re
* @param commit the commit to close
*/
-GIT_INLINE(void) git_commit_free(git_commit *commit)
-{
- git_object_free((git_object *) commit);
-}
+GIT_EXTERN(void) git_commit_free(git_commit *commit);
/**
* Get the id of a commit.
@@ -76,10 +67,7 @@ GIT_INLINE(void) git_commit_free(git_commit *commit)
* @param commit a previously loaded commit.
* @return object identity for the commit.
*/
-GIT_INLINE(const git_oid *) git_commit_id(const git_commit *commit)
-{
- return git_object_id((const git_object *)commit);
-}
+GIT_EXTERN(const git_oid *) git_commit_id(const git_commit *commit);
/**
* Get the encoding for the message of a commit,
diff --git a/src/blob.c b/src/blob.c
index 25ea0df..a68c4cc 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -15,8 +15,6 @@
#include "filter.h"
#include "buf_text.h"
-GIT_OBJECT__TYPED_FUNCTIONS(git_blob, GIT_OBJ_BLOB)
-
const void *git_blob_rawcontent(const git_blob *blob)
{
assert(blob);
diff --git a/src/object.h b/src/object.h
index 7b25fc3..d187c55 100644
--- a/src/object.h
+++ b/src/object.h
@@ -28,16 +28,4 @@ int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end
void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
-#define GIT_OBJECT__TYPED_FUNCTIONS(TYPE,OBJTYPE) \
- int TYPE##_lookup(TYPE **out, git_repository *repo, const git_oid *id) { \
- return git_object_lookup((git_object **)out, repo, id, OBJTYPE); } \
- int TYPE##_lookup_prefix(TYPE **out, git_repository *repo, const git_oid *id, size_t len) { \
- return git_object_lookup_prefix((git_object **)out, repo, id, len, OBJTYPE); } \
- void TYPE##_free(TYPE *obj) { \
- git_object_free((git_object *)obj); } \
- const git_oid *TYPE##_id(const TYPE *obj) { \
- return git_object_id((const git_object *)obj); } \
- git_repository *TYPE##_owner(const TYPE *obj) { \
- return git_object_owner((const git_object *)obj); }
-
#endif
diff --git a/src/object_api.c b/src/object_api.c
new file mode 100644
index 0000000..620617d
--- /dev/null
+++ b/src/object_api.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#include "git2/object.h"
+
+#include "common.h"
+#include "repository.h"
+
+#include "commit.h"
+#include "tree.h"
+#include "blob.h"
+#include "tag.h"
+
+/**
+ * Blob
+ */
+int git_commit_lookup(git_commit **out, git_repository *repo, const git_oid *id)
+{
+ return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_COMMIT);
+}
+
+int git_commit_lookup_prefix(git_commit **out, git_repository *repo, const git_oid *id, size_t len)
+{
+ return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_COMMIT);
+}
+
+void git_commit_free(git_commit *obj)
+{
+ git_object_free((git_object *)obj);
+}
+
+const git_oid *git_commit_id(const git_commit *obj)
+{
+ return git_object_id((const git_object *)obj);
+}
+
+git_repository *git_commit_owner(const git_commit *obj)
+{
+ return git_object_owner((const git_object *)obj);
+}
+
+
+/**
+ * Tree
+ */
+int git_tree_lookup(git_tree **out, git_repository *repo, const git_oid *id)
+{
+ return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_COMMIT);
+}
+
+int git_tree_lookup_prefix(git_tree **out, git_repository *repo, const git_oid *id, size_t len)
+{
+ return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_COMMIT);
+}
+
+void git_tree_free(git_tree *obj)
+{
+ git_object_free((git_object *)obj);
+}
+
+const git_oid *git_tree_id(const git_tree *obj)
+{
+ return git_object_id((const git_object *)obj);
+}
+
+git_repository *git_tree_owner(const git_tree *obj)
+{
+ return git_object_owner((const git_object *)obj);
+}
+
+
+/**
+ * Tag
+ */
+int git_tag_lookup(git_tag **out, git_repository *repo, const git_oid *id)
+{
+ return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_COMMIT);
+}
+
+int git_tag_lookup_prefix(git_tag **out, git_repository *repo, const git_oid *id, size_t len)
+{
+ return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_COMMIT);
+}
+
+void git_tag_free(git_tag *obj)
+{
+ git_object_free((git_object *)obj);
+}
+
+const git_oid *git_tag_id(const git_tag *obj)
+{
+ return git_object_id((const git_object *)obj);
+}
+
+git_repository *git_tag_owner(const git_tag *obj)
+{
+ return git_object_owner((const git_object *)obj);
+}
+
+/**
+ * Blob
+ */
+int git_blob_lookup(git_blob **out, git_repository *repo, const git_oid *id)
+{
+ return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_COMMIT);
+}
+
+int git_blob_lookup_prefix(git_blob **out, git_repository *repo, const git_oid *id, size_t len)
+{
+ return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_COMMIT);
+}
+
+void git_blob_free(git_blob *obj)
+{
+ git_object_free((git_object *)obj);
+}
+
+const git_oid *git_blob_id(const git_blob *obj)
+{
+ return git_object_id((const git_object *)obj);
+}
+
+git_repository *git_blob_owner(const git_blob *obj)
+{
+ return git_object_owner((const git_object *)obj);
+}
diff --git a/src/tag.c b/src/tag.c
index a0ecce1..a4f2e25 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -15,8 +15,6 @@
#include "git2/signature.h"
#include "git2/odb_backend.h"
-GIT_OBJECT__TYPED_FUNCTIONS(git_tag, GIT_OBJ_TAG)
-
void git_tag__free(void *_tag)
{
git_tag *tag = _tag;
diff --git a/src/tree.c b/src/tree.c
index 0a94aec..79cbcff 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -11,8 +11,6 @@
#include "git2/repository.h"
#include "git2/object.h"
-GIT_OBJECT__TYPED_FUNCTIONS(git_tree, GIT_OBJ_TREE)
-
#define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6