int git_commit_create_buffer(git_buf *out, git_repository *repo, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message, const git_tree *tree, size_t parent_count, const git_commit *parents[]) { int error; commit_parent_data data = { parent_count, parents, repo }; git_array_oid_t parents_arr = GIT_ARRAY_INIT; const git_oid *tree_id; assert(tree && git_tree_owner(tree) == repo); tree_id = git_tree_id(tree); if ((error = validate_tree_and_parents(&parents_arr, repo, tree_id, commit_parent_from_array, &data, NULL, true)) < 0) return error; error = git_commit__create_buffer_internal( out, author, committer, message_encoding, message, tree_id, &parents_arr); git_array_clear(parents_arr); return error; }
static int git_commit__create_internal( git_oid *id, git_repository *repo, const char *update_ref, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message, const git_oid *tree, git_commit_parent_callback parent_cb, void *parent_payload, bool validate) { int error; git_odb *odb; git_reference *ref = NULL; git_buf buf = GIT_BUF_INIT; const git_oid *current_id = NULL; git_array_oid_t parents = GIT_ARRAY_INIT; if (update_ref) { error = git_reference_lookup_resolved(&ref, repo, update_ref, 10); if (error < 0 && error != GIT_ENOTFOUND) return error; } giterr_clear(); if (ref) current_id = git_reference_target(ref); if ((error = validate_tree_and_parents(&parents, repo, tree, parent_cb, parent_payload, current_id, validate)) < 0) goto cleanup; error = git_commit__create_buffer_internal(&buf, author, committer, message_encoding, message, tree, &parents); if (error < 0) goto cleanup; if (git_repository_odb__weakptr(&odb, repo) < 0) goto cleanup; if (git_odb_write(id, odb, buf.ptr, buf.size, GIT_OBJ_COMMIT) < 0) goto cleanup; if (update_ref != NULL) { error = git_reference__update_for_commit( repo, ref, update_ref, id, "commit"); goto cleanup; } cleanup: git_array_clear(parents); git_reference_free(ref); git_buf_free(&buf); return error; }