From a25314c1ec4c16a14c4d444e0bdb3f30ce0a9620 Mon Sep 17 00:00:00 2001 From: Charvi Mendiratta Date: Tue, 9 Feb 2021 00:55:19 +0530 Subject: [PATCH 01/11] sequencer: fixup the datatype of the 'flag' argument As 'flag' is a combination of bits, so change its datatype from 'enum todo_item_flags' to 'unsigned'. Mentored-by: Christian Couder Mentored-by: Phillip Wood Helped-by: Eric Sunshine Signed-off-by: Charvi Mendiratta Signed-off-by: Junio C Hamano --- sequencer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index d09ce446b6..f3928cf45c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1744,8 +1744,7 @@ static const char skip_first_commit_msg_str[] = N_("The 1st commit message will 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 int check_fixup_flag(enum todo_command command, - enum todo_item_flags flag) +static int check_fixup_flag(enum todo_command command, unsigned flag) { return command == TODO_FIXUP && ((flag & TODO_REPLACE_FIXUP_MSG) || (flag & TODO_EDIT_FIXUP_MSG)); @@ -1850,7 +1849,7 @@ static void update_squash_message_for_fixup(struct strbuf *msg) static int append_squash_message(struct strbuf *buf, const char *body, enum todo_command command, struct replay_opts *opts, - enum todo_item_flags flag) + unsigned flag) { const char *fixup_msg; size_t commented_len = 0, fixup_off; @@ -1906,7 +1905,7 @@ static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit, struct replay_opts *opts, - enum todo_item_flags flag) + unsigned flag) { struct strbuf buf = STRBUF_INIT; int res = 0; From 1f9696019aee1539ce2fe025b659702926d7ceed Mon Sep 17 00:00:00 2001 From: Charvi Mendiratta Date: Tue, 9 Feb 2021 00:55:20 +0530 Subject: [PATCH 02/11] sequencer: rename a few functions Rename functions to make them more descriptive and while at it, remove unnecessary 'inline' of the skip_fixupish() function. Mentored-by: Christian Couder Mentored-by: Phillip Wood Helped-by: Eric Sunshine Signed-off-by: Charvi Mendiratta Signed-off-by: Junio C Hamano --- sequencer.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sequencer.c b/sequencer.c index f3928cf45c..abc6d5cdfd 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1744,7 +1744,7 @@ static const char skip_first_commit_msg_str[] = N_("The 1st commit message will 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 int check_fixup_flag(enum todo_command command, unsigned flag) +static int is_fixup_flag(enum todo_command command, unsigned flag) { return command == TODO_FIXUP && ((flag & TODO_REPLACE_FIXUP_MSG) || (flag & TODO_EDIT_FIXUP_MSG)); @@ -1873,7 +1873,7 @@ static int append_squash_message(struct strbuf *buf, const char *body, strbuf_addstr(buf, body + commented_len); /* fixup -C after squash behaves like squash */ - if (check_fixup_flag(command, flag) && !seen_squash(opts)) { + if (is_fixup_flag(command, flag) && !seen_squash(opts)) { /* * We're replacing the commit message so we need to * append the Signed-off-by: trailer if the user @@ -1928,7 +1928,7 @@ 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); - if (check_fixup_flag(command, flag) && !seen_squash(opts)) + if (is_fixup_flag(command, flag) && !seen_squash(opts)) update_squash_message_for_fixup(&buf); } else { struct object_id head; @@ -1951,11 +1951,11 @@ static int update_squash_messages(struct repository *r, strbuf_addf(&buf, "%c ", comment_line_char); strbuf_addf(&buf, _(combined_commit_msg_fmt), 2); strbuf_addf(&buf, "\n%c ", comment_line_char); - strbuf_addstr(&buf, check_fixup_flag(command, flag) ? + strbuf_addstr(&buf, is_fixup_flag(command, flag) ? _(skip_first_commit_msg_str) : _(first_commit_msg_str)); strbuf_addstr(&buf, "\n\n"); - if (check_fixup_flag(command, flag)) + if (is_fixup_flag(command, flag)) strbuf_add_commented_lines(&buf, body, strlen(body)); else strbuf_addstr(&buf, body); @@ -1968,7 +1968,7 @@ static int update_squash_messages(struct repository *r, oid_to_hex(&commit->object.oid)); find_commit_subject(message, &body); - if (command == TODO_SQUASH || check_fixup_flag(command, flag)) { + if (command == TODO_SQUASH || is_fixup_flag(command, flag)) { res = append_squash_message(&buf, body, command, opts, flag); } else if (command == TODO_FIXUP) { strbuf_addf(&buf, "\n%c ", comment_line_char); @@ -5661,7 +5661,7 @@ static int subject2item_cmp(const void *fndata, define_commit_slab(commit_todo_item, struct todo_item *); -static inline int skip_fixup_amend_squash(const char *subject, const char **p) { +static int skip_fixupish(const char *subject, const char **p) { return skip_prefix(subject, "fixup! ", p) || skip_prefix(subject, "amend! ", p) || skip_prefix(subject, "squash! ", p); @@ -5725,13 +5725,13 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) format_subject(&buf, subject, " "); subject = subjects[i] = strbuf_detach(&buf, &subject_len); unuse_commit_buffer(item->commit, commit_buffer); - if (skip_fixup_amend_squash(subject, &p)) { + if (skip_fixupish(subject, &p)) { struct commit *commit2; for (;;) { while (isspace(*p)) p++; - if (!skip_fixup_amend_squash(p, &p)) + if (!skip_fixupish(p, &p)) break; } From f07871d302c32777de25b3fde3c621be3b2e32c3 Mon Sep 17 00:00:00 2001 From: Charvi Mendiratta Date: Wed, 10 Feb 2021 17:06:43 +0530 Subject: [PATCH 03/11] rebase -i: clarify and fix 'fixup -c' rebase-todo help When `-c` says "edit the commit message" it's not clear what will be edited. The original's commit message or the replacement's message or a combination of the two. Word it such that it states more precisely what exactly will be edited. While at it, also drop the jarring period and capitalization, neither of which is otherwise present in the message. Mentored-by: Christian Couder Mentored-by: Phillip Wood Helped-by: Eric Sunshine Signed-off-by: Charvi Mendiratta Signed-off-by: Junio C Hamano --- rebase-interactive.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index c3bd02adee..b6cbd16a17 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -44,9 +44,10 @@ void append_todo_help(int command_count, "r, reword = use commit, but edit the commit message\n" "e, edit = use commit, but stop for amending\n" "s, squash = use commit, but meld into previous commit\n" -"f, fixup [-C | -c] = like \"squash\", but discard this\n" -" commit's log message. Use -C to replace with this\n" -" commit message or -c to edit the commit message\n" +"f, fixup [-C | -c] = like \"squash\" but keep only the previous\n" +" commit's log message, unless -C is used, in which case\n" +" keep only this commit's message; -c is same as -C but\n" +" opens the editor\n" "x, exec = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop = remove commit\n" @@ -55,7 +56,7 @@ void append_todo_help(int command_count, "m, merge [-C | -c ]