| 10 | #include "strbuf.h" |
| 11 | |
| 12 | void create_notes_commit(struct repository *r, |
| 13 | struct notes_tree *t, |
| 14 | const struct commit_list *parents, |
| 15 | const char *msg, size_t msg_len, |
| 16 | struct object_id *result_oid) |
| 17 | { |
| 18 | struct commit_list *parents_to_free = NULL; |
| 19 | struct object_id tree_oid; |
| 20 | |
| 21 | assert(t->initialized); |
| 22 | |
| 23 | if (write_notes_tree(t, &tree_oid)) |
| 24 | die("Failed to write notes tree to database"); |
| 25 | |
| 26 | if (!parents) { |
| 27 | /* Deduce parent commit from t->ref */ |
| 28 | struct object_id parent_oid; |
| 29 | if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) { |
| 30 | struct commit *parent = lookup_commit(r, &parent_oid); |
| 31 | if (repo_parse_commit(r, parent)) |
| 32 | die("Failed to find/parse commit %s", t->ref); |
| 33 | commit_list_insert(parent, &parents_to_free); |
| 34 | parents = parents_to_free; |
| 35 | } |
| 36 | /* else: t->ref points to nothing, assume root/orphan commit */ |
| 37 | } |
| 38 | |
| 39 | if (commit_tree(msg, msg_len, &tree_oid, parents, result_oid, NULL, |
| 40 | NULL)) |
| 41 | die("Failed to commit notes tree to database"); |
| 42 | |
| 43 | commit_list_free(parents_to_free); |
| 44 | } |
| 45 | |
| 46 | void commit_notes(struct repository *r, struct notes_tree *t, const char *msg) |
| 47 | { |
no test coverage detected