mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 18:11:43 +00:00
commit.c: Move to new error handling mechanism
This commit is contained in:
parent
adef992232
commit
726c6fd293
25
src/commit.c
25
src/commit.c
@ -102,6 +102,9 @@ int git_commit_create_v(
|
|||||||
tree_oid, parent_count, oids);
|
tree_oid, parent_count, oids);
|
||||||
|
|
||||||
free((void *)oids);
|
free((void *)oids);
|
||||||
|
|
||||||
|
if (error < GIT_SUCCESS)
|
||||||
|
return git__rethrow(error, "Failed to create commit");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +136,9 @@ int git_commit_create_ov(
|
|||||||
parent_count, oids);
|
parent_count, oids);
|
||||||
|
|
||||||
free((void *)oids);
|
free((void *)oids);
|
||||||
|
|
||||||
|
if (error < GIT_SUCCESS)
|
||||||
|
return git__rethrow(error, "Failed to create commit");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +167,9 @@ int git_commit_create_o(
|
|||||||
parent_count, oids);
|
parent_count, oids);
|
||||||
|
|
||||||
free((void *)oids);
|
free((void *)oids);
|
||||||
|
|
||||||
|
if (error < GIT_SUCCESS)
|
||||||
|
return git__rethrow(error, "Failed to create commit");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +206,7 @@ int git_commit_create(
|
|||||||
final_size += 1 + message_length;
|
final_size += 1 + message_length;
|
||||||
|
|
||||||
if ((error = git_odb_open_wstream(&stream, repo->db, final_size, GIT_OBJ_COMMIT)) < GIT_SUCCESS)
|
if ((error = git_odb_open_wstream(&stream, repo->db, final_size, GIT_OBJ_COMMIT)) < GIT_SUCCESS)
|
||||||
return error;
|
return git__rethrow(error, "Failed to create commit");
|
||||||
|
|
||||||
git__write_oid(stream, "tree", tree_oid);
|
git__write_oid(stream, "tree", tree_oid);
|
||||||
|
|
||||||
@ -222,12 +231,12 @@ int git_commit_create(
|
|||||||
|
|
||||||
error = git_reference_lookup(&head, repo, update_ref);
|
error = git_reference_lookup(&head, repo, update_ref);
|
||||||
if (error < GIT_SUCCESS)
|
if (error < GIT_SUCCESS)
|
||||||
return error;
|
return git__rethrow(error, "Failed to create commit");
|
||||||
|
|
||||||
error = git_reference_resolve(&head, head);
|
error = git_reference_resolve(&head, head);
|
||||||
if (error < GIT_SUCCESS) {
|
if (error < GIT_SUCCESS) {
|
||||||
if (error != GIT_ENOTFOUND)
|
if (error != GIT_ENOTFOUND)
|
||||||
return error;
|
return git__rethrow(error, "Failed to create commit");
|
||||||
/*
|
/*
|
||||||
* The target of the reference was not found. This can happen
|
* The target of the reference was not found. This can happen
|
||||||
* just after a repository has been initialized (the master
|
* just after a repository has been initialized (the master
|
||||||
@ -241,6 +250,8 @@ int git_commit_create(
|
|||||||
error = git_reference_set_oid(head, oid);
|
error = git_reference_set_oid(head, oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error < GIT_SUCCESS)
|
||||||
|
return git__rethrow(error, "Failed to create commit");
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +266,7 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
|
|||||||
git_vector_init(&commit->parent_oids, 4, NULL);
|
git_vector_init(&commit->parent_oids, 4, NULL);
|
||||||
|
|
||||||
if ((error = git__parse_oid(&commit->tree_oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS)
|
if ((error = git__parse_oid(&commit->tree_oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS)
|
||||||
return error;
|
return git__rethrow(error, "Failed to parse buffer");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: commit grafts!
|
* TODO: commit grafts!
|
||||||
@ -273,12 +284,12 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
|
|||||||
|
|
||||||
commit->author = git__malloc(sizeof(git_signature));
|
commit->author = git__malloc(sizeof(git_signature));
|
||||||
if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS)
|
if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS)
|
||||||
return error;
|
return git__rethrow(error, "Failed to parse buffer");
|
||||||
|
|
||||||
/* Always parse the committer; we need the commit time */
|
/* Always parse the committer; we need the commit time */
|
||||||
commit->committer = git__malloc(sizeof(git_signature));
|
commit->committer = git__malloc(sizeof(git_signature));
|
||||||
if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS)
|
if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS)
|
||||||
return error;
|
return git__rethrow(error, "Failed to parse buffer");
|
||||||
|
|
||||||
/* parse commit message */
|
/* parse commit message */
|
||||||
while (buffer <= buffer_end && *buffer == '\n')
|
while (buffer <= buffer_end && *buffer == '\n')
|
||||||
@ -343,7 +354,7 @@ int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
|
|||||||
|
|
||||||
parent_oid = git_vector_get(&commit->parent_oids, n);
|
parent_oid = git_vector_get(&commit->parent_oids, n);
|
||||||
if (parent_oid == NULL)
|
if (parent_oid == NULL)
|
||||||
return GIT_ENOTFOUND;
|
return git__throw(GIT_ENOTFOUND, "Failed to get parent. Parent does not exist");
|
||||||
|
|
||||||
return git_commit_lookup(parent, commit->object.repo, parent_oid);
|
return git_commit_lookup(parent, commit->object.repo, parent_oid);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user