Commit 0b726701f3d3c5a3a596b53d8db0b7a4b4032dfb

Vicent Marti 2013-04-30T13:13:38

object: Explicitly define helper API methods for all obj types

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