Commit d7761102 by Russell Belfer

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.
parent b7f167da
......@@ -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.
......
......@@ -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
......
......@@ -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.
......
......@@ -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);
......
......@@ -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
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment