mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-17 16:22:08 +00:00
Move tree.c to the new error handling
Signed-off-by: schu <schu-github@schulog.org>
This commit is contained in:
parent
cbcaf0c09c
commit
d6de92b6fe
14
src/tree.c
14
src/tree.c
@ -151,15 +151,15 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
|
|||||||
return GIT_ENOMEM;
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
if (git__strtol32((long *)&entry->attr, buffer, &buffer, 8) < GIT_SUCCESS)
|
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++ != ' ') {
|
if (*buffer++ != ' ') {
|
||||||
error = GIT_EOBJCORRUPTED;
|
error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memchr(buffer, 0, buffer_end - buffer) == NULL) {
|
if (memchr(buffer, 0, buffer_end - buffer) == NULL) {
|
||||||
error = GIT_EOBJCORRUPTED;
|
error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index)
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (index->repository == NULL)
|
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));
|
error = write_index(oid, index, "", 0, 0, git_index_entrycount(index));
|
||||||
return (error < GIT_SUCCESS) ? error : GIT_SUCCESS;
|
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);
|
assert(bld && id && filename);
|
||||||
|
|
||||||
if (!valid_attributes(attributes))
|
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) {
|
if ((pos = git_vector_bsearch2(&bld->entries, entry_search_cmp, filename)) != GIT_ENOTFOUND) {
|
||||||
entry = git_vector_get(&bld->entries, pos);
|
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);
|
git_tree_entry *remove_ptr = (git_tree_entry *)git_treebuilder_get(bld, filename);
|
||||||
|
|
||||||
if (remove_ptr == NULL || remove_ptr->removed)
|
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;
|
remove_ptr->removed = 1;
|
||||||
bld->entry_count--;
|
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)
|
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) {
|
for (i = 0; i < bld->entries.length; ++i) {
|
||||||
git_tree_entry *entry = bld->entries.contents[i];
|
git_tree_entry *entry = bld->entries.contents[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user