| 99 | }; |
| 100 | |
| 101 | static int commit_tree_ext(struct repository *repo, |
| 102 | const char *action, |
| 103 | struct commit *commit_with_message, |
| 104 | const struct commit_list *parents, |
| 105 | const struct object_id *old_tree, |
| 106 | const struct object_id *new_tree, |
| 107 | struct commit **out, |
| 108 | enum commit_tree_flags flags) |
| 109 | { |
| 110 | const char *exclude_gpgsig[] = { |
| 111 | /* We reencode the message, so the encoding needs to be stripped. */ |
| 112 | "encoding", |
| 113 | /* We need to strip signatures as those will become invalid. */ |
| 114 | "gpgsig", |
| 115 | "gpgsig-sha256", |
| 116 | NULL, |
| 117 | }; |
| 118 | const char *original_message, *original_body, *ptr; |
| 119 | struct commit_extra_header *original_extra_headers = NULL; |
| 120 | struct strbuf commit_message = STRBUF_INIT; |
| 121 | struct object_id rewritten_commit_oid; |
| 122 | char *original_author = NULL; |
| 123 | size_t len; |
| 124 | int ret; |
| 125 | |
| 126 | /* We retain authorship of the original commit. */ |
| 127 | original_message = repo_logmsg_reencode(repo, commit_with_message, NULL, NULL); |
| 128 | ptr = find_commit_header(original_message, "author", &len); |
| 129 | if (ptr) |
| 130 | original_author = xmemdupz(ptr, len); |
| 131 | find_commit_subject(original_message, &original_body); |
| 132 | |
| 133 | if (flags & COMMIT_TREE_EDIT_MESSAGE) { |
| 134 | ret = fill_commit_message(repo, old_tree, new_tree, |
| 135 | original_body, action, &commit_message); |
| 136 | if (ret < 0) |
| 137 | goto out; |
| 138 | } else { |
| 139 | strbuf_addstr(&commit_message, original_body); |
| 140 | } |
| 141 | |
| 142 | original_extra_headers = read_commit_extra_headers(commit_with_message, |
| 143 | exclude_gpgsig); |
| 144 | |
| 145 | ret = commit_tree_extended(commit_message.buf, commit_message.len, new_tree, |
| 146 | parents, &rewritten_commit_oid, original_author, |
| 147 | NULL, NULL, original_extra_headers); |
| 148 | if (ret < 0) |
| 149 | goto out; |
| 150 | |
| 151 | *out = lookup_commit_or_die(&rewritten_commit_oid, "rewritten commit"); |
| 152 | |
| 153 | out: |
| 154 | free_commit_extra_headers(original_extra_headers); |
| 155 | strbuf_release(&commit_message); |
| 156 | free(original_author); |
| 157 | return ret; |
| 158 | } |
no test coverage detected