| 1734 | } |
| 1735 | |
| 1736 | int commit_tree_extended(const char *msg, size_t msg_len, |
| 1737 | const struct object_id *tree, |
| 1738 | const struct commit_list *parents, struct object_id *ret, |
| 1739 | const char *author, const char *committer, |
| 1740 | const char *sign_commit, |
| 1741 | const struct commit_extra_header *extra) |
| 1742 | { |
| 1743 | struct repository *r = the_repository; |
| 1744 | int result = 0; |
| 1745 | int encoding_is_utf8; |
| 1746 | bool warned = false; |
| 1747 | struct strbuf buffer = STRBUF_INIT, compat_buffer = STRBUF_INIT; |
| 1748 | struct strbuf sig = STRBUF_INIT, compat_sig = STRBUF_INIT; |
| 1749 | struct object_id *parent_buf = NULL, *compat_oid = NULL; |
| 1750 | struct object_id compat_oid_buf; |
| 1751 | size_t i, nparents; |
| 1752 | |
| 1753 | /* Not having i18n.commitencoding is the same as having utf-8 */ |
| 1754 | encoding_is_utf8 = is_encoding_utf8(git_commit_encoding); |
| 1755 | |
| 1756 | odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE); |
| 1757 | |
| 1758 | if (memchr(msg, '\0', msg_len)) |
| 1759 | return error("a NUL byte in commit log message not allowed."); |
| 1760 | |
| 1761 | nparents = commit_list_count(parents); |
| 1762 | CALLOC_ARRAY(parent_buf, nparents); |
| 1763 | i = 0; |
| 1764 | for (const struct commit_list *p = parents; p; p = p->next) |
| 1765 | oidcpy(&parent_buf[i++], &p->item->object.oid); |
| 1766 | |
| 1767 | write_commit_tree(&buffer, msg, msg_len, tree, parent_buf, nparents, author, committer, extra); |
| 1768 | |
| 1769 | /* And check the encoding. */ |
| 1770 | if (encoding_is_utf8 && !ensure_utf8(&buffer)) { |
| 1771 | fprintf(stderr, _(commit_utf8_warn)); |
| 1772 | warned = true; |
| 1773 | } |
| 1774 | |
| 1775 | if (sign_commit && sign_buffer(&buffer, &sig, sign_commit, |
| 1776 | SIGN_BUFFER_USE_DEFAULT_KEY)) { |
| 1777 | result = -1; |
| 1778 | goto out; |
| 1779 | } |
| 1780 | if (r->compat_hash_algo) { |
| 1781 | struct commit_extra_header *compat_extra = NULL; |
| 1782 | struct object_id mapped_tree; |
| 1783 | struct object_id *mapped_parents; |
| 1784 | |
| 1785 | CALLOC_ARRAY(mapped_parents, nparents); |
| 1786 | |
| 1787 | if (repo_oid_to_algop(r, tree, r->compat_hash_algo, &mapped_tree)) { |
| 1788 | result = -1; |
| 1789 | free(mapped_parents); |
| 1790 | goto out; |
| 1791 | } |
| 1792 | for (i = 0; i < nparents; i++) |
| 1793 | if (repo_oid_to_algop(r, &parent_buf[i], r->compat_hash_algo, &mapped_parents[i])) { |
no test coverage detected