diff options
author | Russell Belfer <rb@github.com> | 2013-04-15 11:05:44 +0400 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-04-22 18:51:40 +0400 |
commit | 786062639f05e361da977f3f1f6286141fa12fca (patch) | |
tree | 5dc63d86657681572376ef2bced9bb2cae8e2213 /src/tag.c | |
parent | 917f60c50bce09f789aeb927b45ba3bca5a23877 (diff) |
Add callback to git_objects_table
This adds create and free callback to the git_objects_table so
that more of the creation and destruction of objects can be table
driven instead of using switch statements. This also makes the
semantics of certain object creation functions consistent so that
we can make better use of function pointers. This also fixes a
theoretical error case where an object allocation fails and we
end up storing NULL into the cache.
Diffstat (limited to 'src/tag.c')
-rw-r--r-- | src/tag.c | 19 |
1 files changed, 6 insertions, 13 deletions
@@ -15,8 +15,9 @@ #include "git2/signature.h" #include "git2/odb_backend.h" -void git_tag__free(git_tag *tag) +void git_tag__free(void *_tag) { + git_tag *tag = _tag; git_signature_free(tag->tagger); git__free(tag->message); git__free(tag->tag_name); @@ -69,18 +70,17 @@ static int tag_error(const char *str) return -1; } -int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length) +int git_tag__parse(void *_tag, const char *buffer, const char *buffer_end) { static const char *tag_types[] = { NULL, "commit\n", "tree\n", "blob\n", "tag\n" }; + git_tag *tag = _tag; unsigned int i; size_t text_len; char *search; - const char *buffer_end = buffer + length; - if (git_oid__parse(&tag->target, &buffer, buffer_end, "object ") < 0) return tag_error("Object field invalid"); @@ -317,7 +317,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu return -1; /* validate the buffer */ - if (git_tag__parse_buffer(&tag, buffer, strlen(buffer)) < 0) + if (git_tag__parse(&tag, buffer, buffer + strlen(buffer)) < 0) return -1; /* validate the target */ @@ -390,15 +390,8 @@ int git_tag_delete(git_repository *repo, const char *tag_name) if ((error = git_reference_delete(tag_ref)) == 0) git_reference_free(tag_ref); - - return error; -} -int git_tag__parse(git_tag *tag, git_odb_object *obj) -{ - assert(tag); - return git_tag__parse_buffer( - tag, git_odb_object_data(obj), git_odb_object_size(obj)); + return error; } typedef struct { |