diff options
| author | Vicent Martà <tanoku@gmail.com> | 2012-04-23 17:28:11 -0700 |
|---|---|---|
| committer | Vicent Martà <tanoku@gmail.com> | 2012-04-23 17:28:11 -0700 |
| commit | f9f2344bd4ba6c81a96959509ba59f8563b60265 (patch) | |
| tree | bb429dc1d066d433ab39076d3369cde56a48bc83 /src/revwalk.c | |
| parent | 4795807ad5b4827ff4bdb801641ce8a4d5a8557e (diff) | |
| parent | 26515e73a11b6f6c25e316ece2a6243aba7af9f5 (diff) | |
| download | libgit2-f9f2344bd4ba6c81a96959509ba59f8563b60265.tar.gz | |
Merge pull request #632 from arrbee/win64-cleanup
Code clean up, including fixing warnings on Windows 64-bit build
Diffstat (limited to 'src/revwalk.c')
| -rw-r--r-- | src/revwalk.c | 90 |
1 files changed, 39 insertions, 51 deletions
diff --git a/src/revwalk.c b/src/revwalk.c index c2c098cf8..a62576038 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -77,11 +77,10 @@ static int commit_time_cmp(void *a, void *b) static commit_list *commit_list_insert(commit_object *item, commit_list **list_p) { commit_list *new_list = git__malloc(sizeof(commit_list)); - if (new_list == NULL) - return NULL; - - new_list->item = item; - new_list->next = *list_p; + if (new_list != NULL) { + new_list->item = item; + new_list->next = *list_p; + } *list_p = new_list; return new_list; } @@ -143,8 +142,7 @@ static int alloc_chunk(git_revwalk *walk) void *chunk; chunk = git__calloc(COMMITS_PER_CHUNK, CHUNK_STEP); - if (chunk == NULL) - return GIT_ENOMEM; + GITERR_CHECK_ALLOC(chunk); walk->chunk_size = 0; return git_vector_insert(&walk->memory_alloc, chunk); @@ -155,7 +153,8 @@ static commit_object *alloc_commit(git_revwalk *walk) unsigned char *chunk; if (walk->chunk_size == COMMITS_PER_CHUNK) - alloc_chunk(walk); + if (alloc_chunk(walk) < 0) + return NULL; chunk = git_vector_get(&walk->memory_alloc, walk->memory_alloc.length - 1); chunk += (walk->chunk_size * CHUNK_STEP); @@ -186,7 +185,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid) git_oid_cpy(&commit->oid, oid); - if (git_hashtable_insert(walk->commits, &commit->oid, commit) < GIT_SUCCESS) { + if (git_hashtable_insert(walk->commits, &commit->oid, commit) < 0) { git__free(commit); return NULL; } @@ -196,7 +195,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid) static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw) { - const int parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1; + const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1; unsigned char *buffer = raw->data; unsigned char *buffer_end = buffer + raw->len; @@ -262,7 +261,7 @@ static int commit_parse(git_revwalk *walk, commit_object *commit) return 0; if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0) - return -1; + return error; if (obj->raw.type != GIT_OBJ_COMMIT) { git_odb_object_free(obj); @@ -432,6 +431,8 @@ static void mark_uninteresting(commit_object *commit) static int process_commit(git_revwalk *walk, commit_object *commit, int hide) { + int error; + if (hide) mark_uninteresting(commit); @@ -440,8 +441,8 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide) commit->seen = 1; - if (commit_parse(walk, commit) < 0) - return -1; + if ((error = commit_parse(walk, commit)) < 0) + return error; return walk->enqueue(walk, commit); } @@ -449,13 +450,12 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide) static int process_commit_parents(git_revwalk *walk, commit_object *commit) { unsigned short i; + int error = 0; - for (i = 0; i < commit->out_degree; ++i) { - if (process_commit(walk, commit->parents[i], commit->uninteresting) < 0) - return -1; - } + for (i = 0; i < commit->out_degree && !error; ++i) + error = process_commit(walk, commit->parents[i], commit->uninteresting); - return 0; + return error; } static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting) @@ -464,7 +464,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting) commit = commit_lookup(walk, oid); if (commit == NULL) - return -1; + return -1; /* error already reported by failed lookup */ commit->uninteresting = uninteresting; if (walk->one == NULL && !uninteresting) { @@ -492,21 +492,12 @@ int git_revwalk_hide(git_revwalk *walk, const git_oid *oid) static int push_ref(git_revwalk *walk, const char *refname, int hide) { - git_reference *ref, *resolved; - int error; - - if (git_reference_lookup(&ref, walk->repo, refname) < 0) - return -1; + git_oid oid; - error = git_reference_resolve(&resolved, ref); - git_reference_free(ref); - if (error < 0) + if (git_reference_name_to_oid(&oid, walk->repo, refname) < 0) return -1; - error = push_commit(walk, git_reference_oid(resolved), hide); - git_reference_free(resolved); - - return error; + return push_commit(walk, &oid, hide); } struct push_cb_data { @@ -558,7 +549,8 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide) data.glob = git_buf_cstr(&buf); data.hide = hide; - if (git_reference_foreach(walk->repo, GIT_REF_LISTALL, push_glob_cb, &data) < 0) + if (git_reference_foreach( + walk->repo, GIT_REF_LISTALL, push_glob_cb, &data) < 0) goto on_error; regfree(&preg); @@ -614,7 +606,7 @@ static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit) static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit) { - return commit_list_insert(commit, &walk->iterator_rand) ? GIT_SUCCESS : GIT_ENOMEM; + return commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1; } static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk) @@ -624,7 +616,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk) while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) { if ((error = process_commit_parents(walk, next)) < 0) - return -1; + return error; if (!next->uninteresting) { *object_out = next; @@ -642,7 +634,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk) while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) { if ((error = process_commit_parents(walk, next)) < 0) - return -1; + return error; if (!next->uninteresting) { *object_out = next; @@ -724,19 +716,19 @@ static int prepare_walk(git_revwalk *walk) } if (error != GIT_EREVWALKOVER) - return -1; + return error; walk->get_next = &revwalk_next_toposort; } if (walk->sorting & GIT_SORT_REVERSE) { - while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS) + while ((error = walk->get_next(&next, walk)) == 0) if (commit_list_insert(next, &walk->iterator_reverse) == NULL) return -1; if (error != GIT_EREVWALKOVER) - return -1; + return error; walk->get_next = &revwalk_next_reverse; } @@ -761,16 +753,13 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo) walk->commits = git_hashtable_alloc(64, object_table_hash, (git_hash_keyeq_ptr)git_oid_cmp); + GITERR_CHECK_ALLOC(walk->commits); - if (walk->commits == NULL) { - git__free(walk); + if (git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp) < 0 || + git_vector_init(&walk->memory_alloc, 8, NULL) < 0 || + git_vector_init(&walk->twos, 4, NULL) < 0 || + alloc_chunk(walk) < 0) return -1; - } - - git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp); - git_vector_init(&walk->memory_alloc, 8, NULL); - git_vector_init(&walk->twos, 4, NULL); - alloc_chunk(walk); walk->get_next = &revwalk_next_unsorted; walk->enqueue = &revwalk_enqueue_unsorted; @@ -849,7 +838,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk) if (!walk->walking) { if ((error = prepare_walk(walk)) < 0) - return -1; + return error; } error = walk->get_next(&next, walk); @@ -859,11 +848,10 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk) return GIT_EREVWALKOVER; } - if (error < 0) - return -1; + if (!error) + git_oid_cpy(oid, &next->oid); - git_oid_cpy(oid, &next->oid); - return 0; + return error; } void git_revwalk_reset(git_revwalk *walk) |
