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.
This commit is contained in:
Russell Belfer 2013-04-29 14:22:06 -07:00
parent b7f167da29
commit d77611022c
7 changed files with 47 additions and 65 deletions

View File

@ -29,10 +29,7 @@ GIT_BEGIN_DECL
* @param id identity of the blob to locate. * @param id identity of the blob to locate.
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id) GIT_EXTERN(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);
}
/** /**
* Lookup a blob object from a repository, * 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 * @param len the length of the short identifier
* @return 0 or an error code * @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) GIT_EXTERN(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);
}
/** /**
* Close an open blob * 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 * @param blob the blob to close
*/ */
GIT_EXTERN(void) git_blob_free(git_blob *blob);
GIT_INLINE(void) git_blob_free(git_blob *blob)
{
git_object_free((git_object *) blob);
}
/** /**
* Get the id of a 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. * @param blob a previously loaded blob.
* @return SHA1 hash for this blob. * @return SHA1 hash for this blob.
*/ */
GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob) GIT_EXTERN(const git_oid *) git_blob_id(const git_blob *blob);
{
return git_object_id((const git_object *)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. * Get a read-only buffer with the raw content of a blob.

View File

@ -30,12 +30,8 @@ GIT_BEGIN_DECL
* @param id identity of the tag to locate. * @param id identity of the tag to locate.
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_INLINE(int) git_tag_lookup( GIT_EXTERN(int) git_tag_lookup(
git_tag **out, git_repository *repo, const git_oid *id) git_tag **out, git_repository *repo, const git_oid *id);
{
return git_object_lookup(
(git_object **)out, repo, id, (git_otype)GIT_OBJ_TAG);
}
/** /**
* Lookup a tag object from the repository, * 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 * @param len the length of the short identifier
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_INLINE(int) git_tag_lookup_prefix( GIT_EXTERN(int) git_tag_lookup_prefix(
git_tag **out, git_repository *repo, const git_oid *id, size_t len) 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);
}
/** /**
* Close an open tag * Close an open tag
@ -66,12 +58,7 @@ GIT_INLINE(int) git_tag_lookup_prefix(
* *
* @param tag the tag to close * @param tag the tag to close
*/ */
GIT_EXTERN(void) git_tag_free(git_tag *tag);
GIT_INLINE(void) git_tag_free(git_tag *tag)
{
git_object_free((git_object *)tag);
}
/** /**
* Get the id of a tag. * Get the id of a tag.
@ -81,6 +68,14 @@ GIT_INLINE(void) git_tag_free(git_tag *tag)
*/ */
GIT_EXTERN(const git_oid *) git_tag_id(const 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 * Get the tagged object of a tag
* *

View File

@ -29,11 +29,8 @@ GIT_BEGIN_DECL
* @param id Identity of the tree to locate. * @param id Identity of the tree to locate.
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_INLINE(int) git_tree_lookup( GIT_EXTERN(int) git_tree_lookup(
git_tree **out, git_repository *repo, const git_oid *id) git_tree **out, git_repository *repo, const git_oid *id);
{
return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_TREE);
}
/** /**
* Lookup a tree object from the repository, * 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 * @param len the length of the short identifier
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_INLINE(int) git_tree_lookup_prefix( GIT_EXTERN(int) git_tree_lookup_prefix(
git_tree **out, git_tree **out,
git_repository *repo, git_repository *repo,
const git_oid *id, const git_oid *id,
size_t len) size_t len);
{
return git_object_lookup_prefix(
(git_object **)out, repo, id, len, GIT_OBJ_TREE);
}
/** /**
* Close an open tree * Close an open tree
@ -67,10 +60,7 @@ GIT_INLINE(int) git_tree_lookup_prefix(
* *
* @param tree The tree to close * @param tree The tree to close
*/ */
GIT_INLINE(void) git_tree_free(git_tree *tree) GIT_EXTERN(void) git_tree_free(git_tree *tree);
{
git_object_free((git_object *)tree);
}
/** /**
* Get the id of a tree. * Get the id of a tree.

View File

@ -15,6 +15,8 @@
#include "filter.h" #include "filter.h"
#include "buf_text.h" #include "buf_text.h"
GIT_OBJ_WRAPPER(git_blob, GIT_OBJ_BLOB)
const void *git_blob_rawcontent(const git_blob *blob) const void *git_blob_rawcontent(const git_blob *blob)
{ {
assert(blob); assert(blob);

View File

@ -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); 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 #endif

View File

@ -15,6 +15,8 @@
#include "git2/signature.h" #include "git2/signature.h"
#include "git2/odb_backend.h" #include "git2/odb_backend.h"
GIT_OBJ_WRAPPER(git_tag, GIT_OBJ_TAG)
void git_tag__free(void *_tag) void git_tag__free(void *_tag)
{ {
git_tag *tag = _tag; git_tag *tag = _tag;
@ -24,11 +26,6 @@ void git_tag__free(void *_tag)
git__free(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) int git_tag_target(git_object **target, const git_tag *t)
{ {
assert(t); assert(t);

View File

@ -11,6 +11,8 @@
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/object.h" #include "git2/object.h"
GIT_OBJ_WRAPPER(git_tree, GIT_OBJ_TREE)
#define DEFAULT_TREE_SIZE 16 #define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6 #define MAX_FILEMODE_BYTES 6
@ -232,16 +234,6 @@ void git_tree__free(void *_tree)
git__free(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) git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry)
{ {
return (git_filemode_t)entry->attr; return (git_filemode_t)entry->attr;