| 2058 | } |
| 2059 | |
| 2060 | static int update_squash_messages(struct repository *r, |
| 2061 | enum todo_command command, |
| 2062 | struct commit *commit, |
| 2063 | struct replay_opts *opts, |
| 2064 | unsigned flag) |
| 2065 | { |
| 2066 | struct replay_ctx *ctx = opts->ctx; |
| 2067 | struct strbuf buf = STRBUF_INIT; |
| 2068 | int res = 0; |
| 2069 | const char *message, *body; |
| 2070 | const char *encoding = get_commit_output_encoding(); |
| 2071 | |
| 2072 | if (!is_fixup(command)) |
| 2073 | BUG("not a FIXUP or SQUASH %d", command); |
| 2074 | |
| 2075 | if (ctx->current_fixup_count > 0) { |
| 2076 | struct strbuf header = STRBUF_INIT; |
| 2077 | char *eol; |
| 2078 | |
| 2079 | if (strbuf_read_file(&buf, rebase_path_squash_msg(), 9) <= 0) |
| 2080 | return error(_("could not read '%s'"), |
| 2081 | rebase_path_squash_msg()); |
| 2082 | |
| 2083 | eol = !starts_with(buf.buf, comment_line_str) ? |
| 2084 | buf.buf : strchrnul(buf.buf, '\n'); |
| 2085 | |
| 2086 | strbuf_addf(&header, "%s ", comment_line_str); |
| 2087 | strbuf_addf(&header, _(combined_commit_msg_fmt), |
| 2088 | ctx->current_fixup_count + 2); |
| 2089 | strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len); |
| 2090 | strbuf_release(&header); |
| 2091 | if (is_fixup_flag(command, flag) && !seen_squash(ctx)) |
| 2092 | update_squash_message_for_fixup(&buf); |
| 2093 | } else { |
| 2094 | struct object_id head; |
| 2095 | struct commit *head_commit; |
| 2096 | const char *head_message, *body; |
| 2097 | |
| 2098 | if (repo_get_oid(r, "HEAD", &head)) |
| 2099 | return error(_("need a HEAD to fixup")); |
| 2100 | if (!(head_commit = lookup_commit_reference(r, &head))) |
| 2101 | return error(_("could not read HEAD")); |
| 2102 | if (!(head_message = repo_logmsg_reencode(r, head_commit, NULL, |
| 2103 | encoding))) |
| 2104 | return error(_("could not read HEAD's commit message")); |
| 2105 | |
| 2106 | find_commit_subject(head_message, &body); |
| 2107 | if (command == TODO_FIXUP && !flag && write_message(body, strlen(body), |
| 2108 | rebase_path_fixup_msg(), 0) < 0) { |
| 2109 | repo_unuse_commit_buffer(r, head_commit, head_message); |
| 2110 | return error(_("cannot write '%s'"), rebase_path_fixup_msg()); |
| 2111 | } |
| 2112 | strbuf_addf(&buf, "%s ", comment_line_str); |
| 2113 | strbuf_addf(&buf, _(combined_commit_msg_fmt), 2); |
| 2114 | strbuf_addf(&buf, "\n%s ", comment_line_str); |
| 2115 | strbuf_addstr(&buf, is_fixup_flag(command, flag) ? |
| 2116 | _(skip_first_commit_msg_str) : |
| 2117 | _(first_commit_msg_str)); |
no test coverage detected