diff options
author | Vicent Marti <tanoku@gmail.com> | 2010-05-28 01:48:59 +0200 |
---|---|---|
committer | Andreas Ericsson <ae@op5.se> | 2010-06-02 10:32:07 +0200 |
commit | 6bb7aa1318f7f31a346c71ef81d2b33c6fd41600 (patch) | |
tree | 6fdccd49f442a7204399ca9b418f017322dbded8 /src/commit.c | |
parent | 0daa6cdcad92746551f78edfa93be0bc188d4f4a (diff) | |
download | libgit2-6bb7aa1318f7f31a346c71ef81d2b33c6fd41600.tar.gz |
Added new error codes. Improved error handling.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/commit.c b/src/commit.c index e740db6f3..46c7d0de2 100644 --- a/src/commit.c +++ b/src/commit.c @@ -81,7 +81,7 @@ int git_commit_parse_existing(git_commit *commit) return 0; if (git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id) < 0) - return -1; + return GIT_ENOTFOUND; if (commit_obj.type != GIT_OBJ_COMMIT) goto error_cleanup; @@ -128,27 +128,27 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id) int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer_end) { if (memcmp(buffer, "author ", 7) != 0) - return -1; + return GIT_EOBJCORRUPTED; buffer = memchr(buffer, '\n', buffer_end - buffer); if (buffer == 0 || ++buffer >= buffer_end) - return -1; + return GIT_EOBJCORRUPTED; if (memcmp(buffer, "committer ", 10) != 0) - return -1; + return GIT_EOBJCORRUPTED; buffer = memchr(buffer, '>', buffer_end - buffer); if (buffer == 0 || ++buffer >= buffer_end) - return -1; + return GIT_EOBJCORRUPTED; *commit_time = strtol(buffer, &buffer, 10); if (*commit_time == 0) - return -1; + return GIT_EOBJCORRUPTED; buffer = memchr(buffer, '\n', buffer_end - buffer); if (buffer == 0 || ++buffer >= buffer_end) - return -1; + return GIT_EOBJCORRUPTED; return (buffer < buffer_end) ? 0 : -1; } @@ -161,16 +161,16 @@ int git_commit__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_en char *buffer = *buffer_out; if (buffer + (header_len + sha_len + 1) > buffer_end) - return -1; + return GIT_EOBJCORRUPTED; if (memcmp(buffer, header, header_len) != 0) - return -1; + return GIT_EOBJCORRUPTED; if (buffer[header_len + sha_len] != '\n') - return -1; + return GIT_EOBJCORRUPTED; if (git_oid_mkstr(oid, buffer + header_len) < 0) - return -1; + return GIT_EOBJCORRUPTED; *buffer_out = buffer + (header_len + sha_len + 1); @@ -188,7 +188,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len) return 0; if (git_commit__parse_oid(&oid, &buffer, buffer_end, "tree ") < 0) - return -1; + return GIT_EOBJCORRUPTED; /* * TODO: load tree into commit object @@ -199,7 +199,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len) git_commit *parent; if ((parent = git_commit_lookup(commit->object.pool, &oid)) == NULL) - return -1; + return GIT_ENOTFOUND; // Inherit uninteresting flag if (commit->uninteresting) @@ -209,21 +209,21 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len) } if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0) - return -1; + return GIT_EOBJCORRUPTED; commit->parsed = 1; return 0; } -void git_commit_list_push_back(git_commit_list *list, git_commit *commit) +int git_commit_list_push_back(git_commit_list *list, git_commit *commit) { git_commit_node *node = NULL; node = git__malloc(sizeof(git_commit_list)); if (node == NULL) - return; + return GIT_ENOMEM; node->commit = commit; node->next = NULL; @@ -237,16 +237,17 @@ void git_commit_list_push_back(git_commit_list *list, git_commit *commit) } list->size++; + return 0; } -void git_commit_list_push_front(git_commit_list *list, git_commit *commit) +int git_commit_list_push_front(git_commit_list *list, git_commit *commit) { git_commit_node *node = NULL; node = git__malloc(sizeof(git_commit_list)); if (node == NULL) - return; + return GIT_ENOMEM; node->commit = commit; node->next = list->head; @@ -260,6 +261,7 @@ void git_commit_list_push_front(git_commit_list *list, git_commit *commit) } list->size++; + return 0; } |