Improved error handling on auxilirary functions.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
This commit is contained in:
Vicent Marti 2010-05-28 02:02:02 +02:00 committed by Andreas Ericsson
parent c2550609e3
commit de141d4bb9
3 changed files with 21 additions and 18 deletions

View File

@ -75,27 +75,27 @@ error_cleanup:
int git_commit_parse_existing(git_commit *commit)
{
int error = 0;
git_obj commit_obj;
if (commit->parsed)
return 0;
if (git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id) < 0)
return GIT_ENOTFOUND;
error = git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id);
if (error < 0)
return error;
if (commit_obj.type != GIT_OBJ_COMMIT)
goto error_cleanup;
{
error = GIT_EOBJTYPE;
goto cleanup;
}
if (git_commit__parse_buffer(commit, commit_obj.data, commit_obj.len) < 0)
goto error_cleanup;
error = git_commit__parse_buffer(commit, commit_obj.data, commit_obj.len);
cleanup:
git_obj_close(&commit_obj);
return 0;
error_cleanup:
git_obj_close(&commit_obj);
return -1;
return error;
}
git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
@ -205,7 +205,8 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
if (commit->uninteresting)
parent->uninteresting = 1;
git_commit_list_push_back(&commit->parents, parent);
if (git_commit_list_push_back(&commit->parents, parent))
return GIT_ENOMEM;
}
if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0)

View File

@ -74,14 +74,14 @@ int git_revpool_table_insert(git_revpool_table *table, git_revpool_object *objec
unsigned int index, hash;
if (table == NULL)
return -1;
return GIT_ERROR;
if (table->count + 1 > table->max_count)
git_revpool_table_resize(table);
node = git__malloc(sizeof(git_revpool_node));
if (node == NULL)
return -1;
return GIT_ENOMEM;
hash = git_revpool_table__hash(&object->id);
index = (hash & table->size_mask);

View File

@ -71,8 +71,9 @@ int gitrp_push(git_revpool *pool, git_commit *commit)
return GIT_ERROR;
if (!commit->parsed) {
if (git_commit_parse_existing(commit) < 0)
return GIT_EOBJCORRUPTED;
int error = git_commit_parse_existing(commit);
if (error < 0)
return error;
}
// Sanity check: make sure that if the commit
@ -105,8 +106,9 @@ int gitrp__enroot(git_revpool *pool, git_commit *commit)
return 0;
if (commit->parsed == 0) {
if (git_commit_parse_existing(commit))
return GIT_EOBJCORRUPTED;
error = git_commit_parse_existing(commit);
if (error < 0)
return error;
}
commit->seen = 1;