1880
}
1881
}
1882
1883
-enum todo_item_flags {
1884
- TODO_EDIT_MERGE_MSG = (1 << 0),
1885
- TODO_REPLACE_FIXUP_MSG = (1 << 1),
1886
- TODO_EDIT_FIXUP_MSG = (1 << 2),
1887
-};
1888
-
1883
static const char first_commit_msg_str[] = N_("This is the 1st commit message:");
1884
static const char nth_commit_msg_fmt[] = N_("This is the commit message #%d:");
1885
static const char skip_first_commit_msg_str[] = N_("The 1st commit message will be skipped:");
1886
static const char skip_nth_commit_msg_fmt[] = N_("The commit message #%d will be skipped:");
1887
static const char combined_commit_msg_fmt[] = N_("This is a combination of %d commits.");
1888
1889
+void add_squash_combination_header(struct strbuf *buf, int n)
1890
+{
1891
+ strbuf_addf(buf, "%s ", comment_line_str);
1892
+ strbuf_addf(buf, _(combined_commit_msg_fmt), n);
1893
+}
1894
+
1895
+void add_squash_message_header(struct strbuf *buf, int n, int skip)
1896
+{
1897
+ strbuf_addf(buf, "%s ", comment_line_str);
1898
+ if (n == 1)
1899
+ strbuf_addstr(buf, skip ? _(skip_first_commit_msg_str) :
1900
+ _(first_commit_msg_str));
1901
+ else
1902
+ strbuf_addf(buf, skip ? _(skip_nth_commit_msg_fmt) :
1903
+ _(nth_commit_msg_fmt), n);
1904
+}
1905
+
1906
+size_t squash_subject_comment_len(const char *body, int squashing)
1907
+{
1908
+ if (starts_with(body, "amend!") ||
1909
+ (squashing && (starts_with(body, "squash!") ||
1910
+ starts_with(body, "fixup!"))))
1911
+ return commit_subject_length(body);
1912
+ return 0;
1913
+}
1914
+
1915
static int is_fixup_flag(enum todo_command command, unsigned flag)
1916
{
1917
return command == TODO_FIXUP && ((flag & TODO_REPLACE_FIXUP_MSG) ||
2025
{
2026
struct replay_ctx *ctx = opts->ctx;
2027
const char *fixup_msg;
2008
- size_t commented_len = 0, fixup_off;
2009
- /*
2010
- * amend is non-interactive and not normally used with fixup!
2011
- * or squash! commits, so only comment out those subjects when
2012
- * squashing commit messages.
2013
- */
2014
- if (starts_with(body, "amend!") ||
2015
- ((command == TODO_SQUASH || seen_squash(ctx)) &&
2016
- (starts_with(body, "squash!") || starts_with(body, "fixup!"))))
2017
- commented_len = commit_subject_length(body);
2028
+ size_t commented_len, fixup_off;
2029
+
2030
+ commented_len = squash_subject_comment_len(body,
2031
+ command == TODO_SQUASH || seen_squash(ctx));
2032
2019
- strbuf_addf(buf, "\n%s ", comment_line_str);
2020
- strbuf_addf(buf, _(nth_commit_msg_fmt),
2021
- ++ctx->current_fixup_count + 1);
2033
+ strbuf_addch(buf, '\n');
2034
+ add_squash_message_header(buf, ++ctx->current_fixup_count + 1, 0);
2035
strbuf_addstr(buf, "\n\n");
2036
strbuf_add_commented_lines(buf, body, commented_len, comment_line_str);
2037
/* buf->buf may be reallocated so store an offset into the buffer */
2096
eol = !starts_with(buf.buf, comment_line_str) ?
2097
buf.buf : strchrnul(buf.buf, '\n');
2098
2086
- strbuf_addf(&header, "%s ", comment_line_str);
2087
- strbuf_addf(&header, _(combined_commit_msg_fmt),
2088
- ctx->current_fixup_count + 2);
2099
+ add_squash_combination_header(&header,
2100
+ ctx->current_fixup_count + 2);
2101
strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
2102
strbuf_release(&header);
2103
if (is_fixup_flag(command, flag) && !seen_squash(ctx))
2121
repo_unuse_commit_buffer(r, head_commit, head_message);
2122
return error(_("cannot write '%s'"), rebase_path_fixup_msg());
2123
}
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));
2124
+ add_squash_combination_header(&buf, 2);
2125
+ strbuf_addch(&buf, '\n');
2126
+ add_squash_message_header(&buf, 1, is_fixup_flag(command, flag));
2127
strbuf_addstr(&buf, "\n\n");
2128
if (is_fixup_flag(command, flag))
2129
strbuf_add_commented_lines(&buf, body, strlen(body),
2142
if (command == TODO_SQUASH || is_fixup_flag(command, flag)) {
2143
res = append_squash_message(&buf, body, command, opts, flag);
2144
} else if (command == TODO_FIXUP) {
2136
- strbuf_addf(&buf, "\n%s ", comment_line_str);
2137
- strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
2138
- ++ctx->current_fixup_count + 1);
2145
+ strbuf_addch(&buf, '\n');
2146
+ add_squash_message_header(&buf, ++ctx->current_fixup_count + 1, 1);
2147
strbuf_addstr(&buf, "\n\n");
2148
strbuf_add_commented_lines(&buf, body, strlen(body),
2149
comment_line_str);