Move tree.c to the new error handling Signed-off-by: schu <schu-github@schulog.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/tree.c b/src/tree.c
index b7daf39..6f9fc86 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -151,15 +151,15 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
return GIT_ENOMEM;
if (git__strtol32((long *)&entry->attr, buffer, &buffer, 8) < GIT_SUCCESS)
- return GIT_EOBJCORRUPTED;
+ return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Can't parse attributes");
if (*buffer++ != ' ') {
- error = GIT_EOBJCORRUPTED;
+ error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
break;
}
if (memchr(buffer, 0, buffer_end - buffer) == NULL) {
- error = GIT_EOBJCORRUPTED;
+ error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
break;
}
@@ -274,7 +274,7 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index)
int error;
if (index->repository == NULL)
- return GIT_EBAREINDEX;
+ return git__throw(GIT_EBAREINDEX, "Failed to create tree. The index file is not backed up by an existing repository");
error = write_index(oid, index, "", 0, 0, git_index_entrycount(index));
return (error < GIT_SUCCESS) ? error : GIT_SUCCESS;
@@ -343,7 +343,7 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
assert(bld && id && filename);
if (!valid_attributes(attributes))
- return GIT_ERROR;
+ return git__throw(GIT_ERROR, "Failed to insert entry. Invalid atrributes");
if ((pos = git_vector_bsearch2(&bld->entries, entry_search_cmp, filename)) != GIT_ENOTFOUND) {
entry = git_vector_get(&bld->entries, pos);
@@ -400,7 +400,7 @@ int git_treebuilder_remove(git_treebuilder *bld, const char *filename)
git_tree_entry *remove_ptr = (git_tree_entry *)git_treebuilder_get(bld, filename);
if (remove_ptr == NULL || remove_ptr->removed)
- return GIT_ENOTFOUND;
+ return git__throw(GIT_ENOTFOUND, "Failed to remove entry. File isn't in the tree");
remove_ptr->removed = 1;
bld->entry_count--;
@@ -431,7 +431,7 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b
}
if ((error = git_odb_open_wstream(&stream, git_repository_database(repo), size, GIT_OBJ_TREE)) < GIT_SUCCESS)
- return error;
+ return git__rethrow(error, "Failed to write tree. Can't open write stream");
for (i = 0; i < bld->entries.length; ++i) {
git_tree_entry *entry = bld->entries.contents[i];