Standardize cast versions of git_object accessors This removes the GIT_INLINE versions of the simple git_object accessors and standardizes them with a helper macro in src/object.h to build the function bodies.
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 0a2aa9d..8fca489 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -29,10 +29,7 @@ GIT_BEGIN_DECL
* @param id identity of the blob to locate.
* @return 0 or an error code
*/
-GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id)
-{
- return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB);
-}
+GIT_EXTERN(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id);
/**
* Lookup a blob object from a repository,
@@ -46,10 +43,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len)
-{
- return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB);
-}
+GIT_EXTERN(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, size_t len);
/**
* Close an open blob
@@ -62,11 +56,7 @@ GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, co
*
* @param blob the blob to close
*/
-
-GIT_INLINE(void) git_blob_free(git_blob *blob)
-{
- git_object_free((git_object *) blob);
-}
+GIT_EXTERN(void) git_blob_free(git_blob *blob);
/**
* Get the id of a blob.
@@ -74,11 +64,15 @@ GIT_INLINE(void) git_blob_free(git_blob *blob)
* @param blob a previously loaded blob.
* @return SHA1 hash for this blob.
*/
-GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob)
-{
- return git_object_id((const git_object *)blob);
-}
+GIT_EXTERN(const git_oid *) git_blob_id(const git_blob *blob);
+/**
+ * Get the repository that contains the blob.
+ *
+ * @param blob A previously loaded blob.
+ * @return Repository that contains this blob.
+ */
+GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
/**
* Get a read-only buffer with the raw content of a blob.
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 84c954c..469b1d7 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -30,12 +30,8 @@ GIT_BEGIN_DECL
* @param id identity of the tag to locate.
* @return 0 or an error code
*/
-GIT_INLINE(int) git_tag_lookup(
- git_tag **out, git_repository *repo, const git_oid *id)
-{
- return git_object_lookup(
- (git_object **)out, repo, id, (git_otype)GIT_OBJ_TAG);
-}
+GIT_EXTERN(int) git_tag_lookup(
+ git_tag **out, git_repository *repo, const git_oid *id);
/**
* Lookup a tag object from the repository,
@@ -49,12 +45,8 @@ GIT_INLINE(int) git_tag_lookup(
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(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_otype)GIT_OBJ_TAG);
-}
+GIT_EXTERN(int) git_tag_lookup_prefix(
+ git_tag **out, git_repository *repo, const git_oid *id, size_t len);
/**
* Close an open tag
@@ -66,12 +58,7 @@ GIT_INLINE(int) git_tag_lookup_prefix(
*
* @param tag the tag to close
*/
-
-GIT_INLINE(void) git_tag_free(git_tag *tag)
-{
- git_object_free((git_object *)tag);
-}
-
+GIT_EXTERN(void) git_tag_free(git_tag *tag);
/**
* Get the id of a tag.
@@ -82,6 +69,14 @@ GIT_INLINE(void) git_tag_free(git_tag *tag)
GIT_EXTERN(const git_oid *) git_tag_id(const git_tag *tag);
/**
+ * Get the repository that contains the tag.
+ *
+ * @param tag A previously loaded tag.
+ * @return Repository that contains this tag.
+ */
+GIT_EXTERN(git_repository *) git_tag_owner(const git_tag *tag);
+
+/**
* Get the tagged object of a tag
*
* This method performs a repository lookup for the
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 73bfc86..6ad7220 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -29,11 +29,8 @@ GIT_BEGIN_DECL
* @param id Identity of the tree to locate.
* @return 0 or an error code
*/
-GIT_INLINE(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_TREE);
-}
+GIT_EXTERN(int) git_tree_lookup(
+ git_tree **out, git_repository *repo, const git_oid *id);
/**
* Lookup a tree object from the repository,
@@ -47,15 +44,11 @@ GIT_INLINE(int) git_tree_lookup(
* @param len the length of the short identifier
* @return 0 or an error code
*/
-GIT_INLINE(int) git_tree_lookup_prefix(
+GIT_EXTERN(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_TREE);
-}
+ size_t len);
/**
* Close an open tree
@@ -67,10 +60,7 @@ GIT_INLINE(int) git_tree_lookup_prefix(
*
* @param tree The tree to close
*/
-GIT_INLINE(void) git_tree_free(git_tree *tree)
-{
- git_object_free((git_object *)tree);
-}
+GIT_EXTERN(void) git_tree_free(git_tree *tree);
/**
* Get the id of a tree.
diff --git a/src/blob.c b/src/blob.c
index a68c4cc..d656576 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -15,6 +15,8 @@
#include "filter.h"
#include "buf_text.h"
+GIT_OBJ_WRAPPER(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 d187c55..906d407 100644
--- a/src/object.h
+++ b/src/object.h
@@ -28,4 +28,16 @@ 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_OBJ_WRAPPER(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/tag.c b/src/tag.c
index b9a806c..ad3a8fd 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -15,6 +15,8 @@
#include "git2/signature.h"
#include "git2/odb_backend.h"
+GIT_OBJ_WRAPPER(git_tag, GIT_OBJ_TAG)
+
void git_tag__free(void *_tag)
{
git_tag *tag = _tag;
@@ -24,11 +26,6 @@ void git_tag__free(void *_tag)
git__free(tag);
}
-const git_oid *git_tag_id(const git_tag *c)
-{
- return git_object_id((const git_object *)c);
-}
-
int git_tag_target(git_object **target, const git_tag *t)
{
assert(t);
diff --git a/src/tree.c b/src/tree.c
index 58eb92f..67c9a06 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -11,6 +11,8 @@
#include "git2/repository.h"
#include "git2/object.h"
+GIT_OBJ_WRAPPER(git_tree, GIT_OBJ_TREE)
+
#define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6
@@ -232,16 +234,6 @@ void git_tree__free(void *_tree)
git__free(tree);
}
-const git_oid *git_tree_id(const git_tree *t)
-{
- return git_object_id((const git_object *)t);
-}
-
-git_repository *git_tree_owner(const git_tree *t)
-{
- return git_object_owner((const git_object *)t);
-}
-
git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry)
{
return (git_filemode_t)entry->attr;