diff options
author | Russell Belfer <rb@github.com> | 2013-07-07 21:56:11 -0700 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-07-10 20:50:32 +0200 |
commit | 9abc78ae6157167682f061b4f73eea51ab7d7342 (patch) | |
tree | e037ab6838882697af78b930dcbf1da828943d3e /src/commit.c | |
parent | bc6f0839ebd5794c99d5b488d431188a162a064d (diff) | |
download | libgit2-9abc78ae6157167682f061b4f73eea51ab7d7342.tar.gz |
Convert commit->parent_ids to git_array_t
This converts the array of parent SHAs from a git_vector where
each SHA has to be separately allocated to a git_array_t where
all the SHAs can be kept in one block. Since the two collections
have almost identical APIs, there isn't much involved in making
the change. I did add an API to git_array_t so that it could be
allocated at a precise initial size.
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/commit.c b/src/commit.c index cf50c2d37..cc912a7be 100644 --- a/src/commit.c +++ b/src/commit.c @@ -19,24 +19,11 @@ #include <stdarg.h> -static void clear_parents(git_commit *commit) -{ - size_t i; - - for (i = 0; i < commit->parent_ids.length; ++i) { - git_oid *parent = git_vector_get(&commit->parent_ids, i); - git__free(parent); - } - - git_vector_clear(&commit->parent_ids); -} - void git_commit__free(void *_commit) { git_commit *commit = _commit; - clear_parents(commit); - git_vector_free(&commit->parent_ids); + git_array_clear(commit->parent_ids); git_signature_free(commit->author); git_signature_free(commit->committer); @@ -44,6 +31,7 @@ void git_commit__free(void *_commit) git__free(commit->raw_header); git__free(commit->message); git__free(commit->message_encoding); + git__free(commit); } @@ -198,8 +186,8 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) if (parent_count < 1) parent_count = 1; - if (git_vector_init(&commit->parent_ids, parent_count, NULL) < 0) - return -1; + git_array_init_to_size(commit->parent_ids, parent_count); + GITERR_CHECK_ARRAY(commit->parent_ids); if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0) goto bad_buffer; @@ -209,13 +197,10 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) */ while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) { - git_oid *new_id = git__malloc(sizeof(git_oid)); + git_oid *new_id = git_array_alloc(commit->parent_ids); GITERR_CHECK_ALLOC(new_id); git_oid_cpy(new_id, &parent_id); - - if (git_vector_insert(&commit->parent_ids, new_id) < 0) - return -1; } commit->author = git__malloc(sizeof(git_signature)); @@ -284,7 +269,7 @@ GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding) GIT_COMMIT_GETTER(const char *, raw_header, commit->raw_header) GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time) GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset) -GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)commit->parent_ids.length) +GIT_COMMIT_GETTER(unsigned int, parentcount, (unsigned int)git_array_size(commit->parent_ids)) GIT_COMMIT_GETTER(const git_oid *, tree_id, &commit->tree_id); int git_commit_tree(git_tree **tree_out, const git_commit *commit) @@ -298,7 +283,7 @@ const git_oid *git_commit_parent_id( { assert(commit); - return git_vector_get(&commit->parent_ids, n); + return git_array_get(commit->parent_ids, n); } int git_commit_parent( |