--- vrfc
+++ v4
@@ -8,8 +8,8 @@
Signed-off-by: Charvi Mendiratta <charvi077@gmail.com>
---
rebase-interactive.c | 4 +-
- sequencer.c | 212 +++++++++++++++++++++++++++++++++++++++----
- 2 files changed, 196 insertions(+), 20 deletions(-)
+ sequencer.c | 213 +++++++++++++++++++++++++++++++++++++++----
+ 2 files changed, 197 insertions(+), 20 deletions(-)
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 762853bc7e..c3bd02adee 100644
@@ -27,7 +27,7 @@
"b, break = stop here (continue rebase later with 'git rebase --continue')\n"
"d, drop <commit> = remove commit\n"
diff --git a/sequencer.c b/sequencer.c
-index b9295b5a02..db016717d1 100644
+index 6d9a10afcf..46e11d20e8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1718,6 +1718,12 @@ static int is_pick_or_similar(enum todo_command command)
@@ -42,17 +42,14 @@
+
static size_t subject_length(const char *body)
{
- size_t i, len = 0;
-@@ -1740,34 +1746,177 @@ static const char first_commit_msg_str[] =
- N_("This is the 1st commit message:");
- static const char nth_commit_msg_fmt[] =
- N_("This is the commit message #%d:");
-+static const char skip_first_commit_msg_str[] =
-+N_("The 1st commit message will be skipped:");
- static const char skip_nth_commit_msg_fmt[] =
- N_("The commit message #%d will be skipped:");
- static const char combined_commit_msg_str[] =
- N_("This is a combination of %d commits.");
+ const char *p = body;
+@@ -1734,32 +1740,176 @@ static size_t subject_length(const char *body)
+
+ static const char first_commit_msg_str[] = N_("This is the 1st commit message:");
+ static const char nth_commit_msg_fmt[] = N_("This is the commit message #%d:");
++static const char skip_first_commit_msg_str[] = N_("The 1st commit message will be skipped:");
+ static const char skip_nth_commit_msg_fmt[] = N_("The commit message #%d will be skipped:");
+ static const char combined_commit_msg_fmt[] = N_("This is a combination of %d commits.");
-static void append_squash_message(struct strbuf *buf, const char *body,
- struct replay_opts *opts)
@@ -86,24 +83,24 @@
+
+/* Does the current fixup chain contain a squash command? */
+static int seen_squash(struct replay_opts *opts)
++{
++ return starts_with(opts->current_fixups.buf, "squash") ||
++ strstr(opts->current_fixups.buf, "\nsquash");
++}
++
++static void update_comment_bufs(struct strbuf *buf1, struct strbuf *buf2, int n)
{
- size_t commented_len = 0;
-+ return starts_with(opts->current_fixups.buf, "squash") ||
-+ strstr(opts->current_fixups.buf, "\nsquash");
++ strbuf_setlen(buf1, 2);
++ strbuf_addf(buf1, _(nth_commit_msg_fmt), n);
++ strbuf_addch(buf1, '\n');
++ strbuf_setlen(buf2, 2);
++ strbuf_addf(buf2, _(skip_nth_commit_msg_fmt), n);
++ strbuf_addch(buf2, '\n');
+}
- unlink(rebase_path_fixup_msg());
- if (starts_with(body, "squash!") || starts_with(body, "fixup!"))
-+static void update_comment_bufs(struct strbuf *buf1, struct strbuf *buf2, int n)
-+{
-+ strbuf_setlen(buf1, 2);
-+ strbuf_addf(buf1, nth_commit_msg_fmt, n);
-+ strbuf_addch(buf1, '\n');
-+ strbuf_setlen(buf2, 2);
-+ strbuf_addf(buf2, skip_nth_commit_msg_fmt, n);
-+ strbuf_addch(buf2, '\n');
-+}
-+
+/*
+ * Comment out any un-commented commit messages, updating the message comments
+ * to say they will be skipped but do not comment out the empty lines that
@@ -118,8 +115,8 @@
+ size_t orig_msg_len;
+ int i = 1;
+
-+ strbuf_addf(&buf1, "# %s\n", first_commit_msg_str);
-+ strbuf_addf(&buf2, "# %s\n", skip_first_commit_msg_str);
++ strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
++ strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
+ s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
+ while (s) {
+ const char *next;
@@ -199,10 +196,12 @@
+ append_signoff(buf, 0, 0);
+
+ if ((command == TODO_FIXUP) &&
-+ (flag & TODO_REPLACE_FIXUP_MSG)) {
++ (flag & TODO_REPLACE_FIXUP_MSG) &&
++ (file_exists(rebase_path_fixup_msg()) ||
++ !file_exists(rebase_path_squash_msg()))) {
+ fixup_msg = skip_blank_lines(buf->buf + fixup_off);
+ if (write_message(fixup_msg, strlen(fixup_msg),
-+ rebase_path_fixup_msg(), 0))
++ rebase_path_fixup_msg(), 0) < 0)
+ return error(_("cannot write '%s'"),
+ rebase_path_fixup_msg());
+ } else {
@@ -228,7 +227,7 @@
const char *message, *body;
const char *encoding = get_commit_output_encoding();
-@@ -1787,6 +1936,8 @@ static int update_squash_messages(struct repository *r,
+@@ -1779,6 +1929,8 @@ static int update_squash_messages(struct repository *r,
opts->current_fixup_count + 2);
strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
strbuf_release(&header);
@@ -237,22 +236,19 @@
} else {
struct object_id head;
struct commit *head_commit;
-@@ -1800,7 +1951,7 @@ static int update_squash_messages(struct repository *r,
+@@ -1792,18 +1944,22 @@ static int update_squash_messages(struct repository *r,
return error(_("could not read HEAD's commit message"));
find_commit_subject(head_message, &body);
-- if (command == TODO_FIXUP) {
-+ if (command == TODO_FIXUP && !flag) {
- if (write_message(body, strlen(body),
- rebase_path_fixup_msg(), 0)) {
- unuse_commit_buffer(head_commit, head_message);
-@@ -1808,13 +1959,17 @@ static int update_squash_messages(struct repository *r,
- rebase_path_fixup_msg());
- }
+- if (command == TODO_FIXUP && write_message(body, strlen(body),
++ if (command == TODO_FIXUP && !flag && write_message(body, strlen(body),
+ rebase_path_fixup_msg(), 0) < 0) {
+ unuse_commit_buffer(head_commit, head_message);
+ return error(_("cannot write '%s'"), rebase_path_fixup_msg());
}
-
strbuf_addf(&buf, "%c ", comment_line_char);
- strbuf_addf(&buf, _(combined_commit_msg_str), 2);
+ strbuf_addf(&buf, _(combined_commit_msg_fmt), 2);
strbuf_addf(&buf, "\n%c ", comment_line_char);
- strbuf_addstr(&buf, _(first_commit_msg_str));
+ strbuf_addstr(&buf, check_fixup_flag(command, flag) ?
@@ -267,7 +263,7 @@
unuse_commit_buffer(head_commit, head_message);
}
-@@ -1824,8 +1979,8 @@ static int update_squash_messages(struct repository *r,
+@@ -1813,8 +1969,8 @@ static int update_squash_messages(struct repository *r,
oid_to_hex(&commit->object.oid));
find_commit_subject(message, &body);
@@ -278,7 +274,7 @@
} else if (command == TODO_FIXUP) {
strbuf_addf(&buf, "\n%c ", comment_line_char);
strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
-@@ -1836,7 +1991,9 @@ static int update_squash_messages(struct repository *r,
+@@ -1825,7 +1981,9 @@ static int update_squash_messages(struct repository *r,
return error(_("unknown command: %d"), command);
unuse_commit_buffer(commit, message);
@@ -289,7 +285,7 @@
strbuf_release(&buf);
if (!res) {
-@@ -2037,7 +2194,8 @@ static int do_pick_commit(struct repository *r,
+@@ -2026,7 +2184,8 @@ static int do_pick_commit(struct repository *r,
if (command == TODO_REWORD)
reword = 1;
else if (is_fixup(command)) {
@@ -299,7 +295,7 @@
return -1;
flags |= AMEND_MSG;
if (!final_fixup)
-@@ -2202,10 +2360,6 @@ static int read_and_refresh_cache(struct repository *r,
+@@ -2191,10 +2350,6 @@ static int read_and_refresh_cache(struct repository *r,
return 0;
}
@@ -310,7 +306,7 @@
void todo_list_release(struct todo_list *todo_list)
{
strbuf_release(&todo_list->buf);
-@@ -2292,6 +2446,18 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
+@@ -2281,6 +2436,18 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
return 0;
}
@@ -329,7 +325,7 @@
if (item->command == TODO_MERGE) {
if (skip_prefix(bol, "-C", &bol))
bol += strspn(bol, " \t");
-@@ -5298,6 +5464,14 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
+@@ -5287,6 +5454,14 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
short_commit_name(item->commit) :
oid_to_hex(&item->commit->object.oid);