rebase -i: add options to fixup command
cover rebase -i: add options to fixup command
Hi Everyone,
This patch series adds fixup [-C|-c] options to interactive rebase. In addition to amending the contents of the commit as the fixup command does now, fixup -C replaces the commit message of the original commit which we are fixing up with the message of the fixup commit. And to edit the fixup commit message before committing, fixup -c command is used instead of fixup -C. This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
This patch series also changes rebase -i --autosquash to rearrange commits whose message starts with "amend!" and replaces the pick command with fixup -C. The creation of "amend!" commits will be rebase -i: add options to fixup command added in another patch series.
This is done in reference to the issue opened by Dscho as here[1] and further discussed briefly[2]. Also, there is discussion[3] regarding the implementation of reword! commit. The past patches of Phillip Wood’s work[4], implements 'reword!' as 'amend!' in git rebase and these patches uses those as the initial base.
And to avoid the extra command in the interactive rebase, this patch series instead add options to the current fixup command in interactive rebase (fixup [-C | -c]) as discussed earlier[5].
Looking forward for the reviews.
Thanks and Regards,
Charvi
P.S - I thanks Christian and Phillip for mentoring in this project and happy to work in community.
[1] https://github.com/gitgitgadget/git/issues/259
[2] https://public-inbox.org/git/alpine.DEB.2.21.1.1710151754070.40514@virtualbox/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://github.com/phillipwood/git/commits/wip/rebase-amend
[5] https://lore.kernel.org/git/[email protected]/
Charvi Mendiratta (6):
sequencer: pass todo_item to do_pick_commit()
sequencer: use const variable for commit message comments rebase -i: add fixup [-C | -c] command
t3437: test script for fixup [-C|-c] options in interactive rebase rebase -i: teach --autosquash to work with amend! doc/git-rebase: add documentation for fixup [-C|-c] options
Phillip Wood (3):
rebase -i: only write fixup-message when it's needed
sequencer: factor out code to append squash message rebase -i: comment out squash!/fixup! subjects from squash message
Documentation/git-rebase.txt | 12 +- rebase-interactive.c | 4 +- sequencer.c | 307 +++++++++++++++++++++++++++----- t/lib-rebase.sh | 4 + t/t3415-rebase-autosquash.sh | 27 ++- t/t3437-rebase-fixup-options.sh | 202 +++++++++++++++++++++ t/t3437/expected-squash-message | 51 ++++++ t/t3900-i18n-commit.sh | 4 - 8 files changed, 549 insertions(+), 62 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-squash-message
--
2.29.0.rc1
RFC PATCH 1/9 rebase -i: only write fixup-message when it's needed
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
--- sequencer.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
sequencer.c +7 -5
@@ -1757,11 +1757,13 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) { -unuse_commit_buffer (head_commit, head_message); -return error (_ ("cannot write '%s'" ), -rebase_path_fixup_msg ()); +if (command ==TODO_FIXUP ) { +if (write_message (body,strlen (body), +rebase_path_fixup_msg (),0 )) { +unuse_commit_buffer (head_commit, head_message); +return error (_ ("cannot write '%s'" ), +rebase_path_fixup_msg ()); + } }strbuf_addf (&buf,"%c " , comment_line_char);
Signature · 1 line
2.29.0.rc1
Re: [RFC PATCH 1/9] rebase -i: only write fixup-message when it's needed
Quoted 22 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)sequencer.c +0
-2@@ -1757,11 +1757,13 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) {
sequencer.c static int update_squash_messages(struct repository *r, · line 1766
Quoted 10 lines
sequencer.c +7
-3-unuse_commit_buffer (head_commit, head_message); -return error (_ ("cannot write '%s'" ), -rebase_path_fixup_msg ()); +if (command ==TODO_FIXUP ) { +if (write_message (body,strlen (body), +rebase_path_fixup_msg (),0 )) { +unuse_commit_buffer (head_commit, head_message); +return error (_ ("cannot write '%s'" ), +rebase_path_fixup_msg ()); + }
I'm nit-picking here, but would this be clearer instead as:
if (command == TODO_FIXUP && write_message(...) < 0) {
unuse_commit_buffer(...);
// ...
}There are two changes there. One is two squash the two if-statements together, and the latter is to add a check that 'write_message()' returns an error. This explicit '< 0' checking was discussed recently in another thread[1], and I think makes the conditional here read more clearly.
Thanks,
Taylor
Re: [RFC PATCH 1/9] rebase -i: only write fixup-message when it's needed
Quoted 42 lines · Taylor Blau
Quoted 22 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)sequencer.c +0
-2@@ -1757,11 +1757,13 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) {sequencer.c static int update_squash_messages(struct repository *r, · line 1766
Quoted 10 lines
sequencer.c +7
-3-unuse_commit_buffer (head_commit, head_message); -return error (_ ("cannot write '%s'" ), -rebase_path_fixup_msg ()); +if (command ==TODO_FIXUP ) { +if (write_message (body,strlen (body), +rebase_path_fixup_msg (),0 )) { +unuse_commit_buffer (head_commit, head_message); +return error (_ ("cannot write '%s'" ), +rebase_path_fixup_msg ()); + }I'm nit-picking here, but would this be clearer instead as:
if (command == TODO_FIXUP && write_message(...) < 0) { unuse_commit_buffer(...); // ... }
Quoted 6 lines
There are two changes there. One is two squash the two if-statements together, and the latter is to add a check that '
write_message()' returns an error. This explicit '< 0' checking was discussed recently in another thread[1], and I think makes the conditional here read more clearly.
Okay, I got this and will change it.
Thanks and Regards,
Charvi
Quoted 4 lines
Thanks,
Taylor
Re: [RFC PATCH 1/9] rebase -i: only write fixup-message when it's needed
Hi Taylor and Charvi
Quoted 43 lines · Charvi Mendiratta
Quoted 42 lines · Taylor Blau
Quoted 22 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)sequencer.c +0
-2@@ -1757,11 +1757,13 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) {sequencer.c static int update_squash_messages(struct repository *r, · line 1766
Quoted 10 lines
sequencer.c +7
-3-unuse_commit_buffer (head_commit, head_message); -return error (_ ("cannot write '%s'" ), -rebase_path_fixup_msg ()); +if (command ==TODO_FIXUP ) { +if (write_message (body,strlen (body), +rebase_path_fixup_msg (),0 )) { +unuse_commit_buffer (head_commit, head_message); +return error (_ ("cannot write '%s'" ), +rebase_path_fixup_msg ()); + }I'm nit-picking here, but would this be clearer instead as:
if (command == TODO_FIXUP && write_message(...) < 0) { unuse_commit_buffer(...); // ... }
Quoted 5 lines
Quoted 5 lines
There are two changes there. One is two squash the two if-statements together, and the latter is to add a check that '
write_message()' returns an error. This explicit '< 0' checking was discussed recently in another thread[1], and I think makes the conditional here read more clearly.
I don't feel that strongly but the addition of '< 0' feels like it is adding an unrelated change to this commit. It also leaves a code base where most callers of write_message() do not check the sign of the return value but a couple do (there appears to be one that checks the sign already and a couple that completely ignore the return value). If we want to standardize on always checking the sign of the return value of functions when checking for errors even when they never return a positive value then I think someone in favor of that change should propose a patch to the coding guidelines so it is clear what our policy is. When I see a '< 0`' check I tend to think the positive value has a non-error meaning.
Best Wishes
Phillip
Quoted 9 lines
Okay, I got this and will change it.
Thanks and Regards,
CharviQuoted 4 lines
Thanks,
Taylor
Re: [RFC PATCH 1/9] rebase -i: only write fixup-message when it's needed
Quoted 53 lines · Phillip Wood
Hi Taylor and Charvi
Quoted 43 lines · Charvi Mendiratta
Quoted 42 lines · Taylor Blau
Quoted 22 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)sequencer.c +0
-2@@ -1757,11 +1757,13 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) {sequencer.c static int update_squash_messages(struct repository *r, · line 1766
Quoted 10 lines
sequencer.c +7
-3-unuse_commit_buffer (head_commit, head_message); -return error (_ ("cannot write '%s'" ), -rebase_path_fixup_msg ()); +if (command ==TODO_FIXUP ) { +if (write_message (body,strlen (body), +rebase_path_fixup_msg (),0 )) { +unuse_commit_buffer (head_commit, head_message); +return error (_ ("cannot write '%s'" ), +rebase_path_fixup_msg ()); + }I'm nit-picking here, but would this be clearer instead as:
if (command == TODO_FIXUP && write_message(...) < 0) { unuse_commit_buffer(...); // ... }Quoted 5 lines
Quoted 5 lines
There are two changes there. One is two squash the two if-statements together, and the latter is to add a check that '
write_message()' returns an error. This explicit '< 0' checking was discussed recently in another thread[1], and I think makes the conditional here read more clearly.
Quoted 12 lines
I don't feel that strongly but the addition of '< 0' feels like it is adding an unrelated change to this commit. It also leaves a code base where most callers of
write_message()do not check the sign of the return value but a couple do (there appears to be one that checks the sign already and a couple that completely ignore the return value). If we want to standardize on always checking the sign of the return value of functions when checking for errors even when they never return a positive value then I think someone in favor of that change should propose a patch to the coding guidelines so it is clear what our policy is. When I see a '< 0`' check I tend to think the positive value has a non-error meaning.
Okay, I looked into the write_message(...) and agree that it does not return a positive value and only returns non-zero for error case and zero for success. So, for this patch maybe we can ignore checking '< 0' here and later add another patch to make this function follow the convention of "negative is error".
Thanks and Regards,
Charvi
Quoted 14 lines
Best Wishes
Phillip
Quoted 9 lines
Okay, I got this and will change it.
Thanks and Regards,
CharviQuoted 4 lines
Thanks,
Taylor
Re: [RFC PATCH 1/9] rebase -i: only write fixup-message when it's needed
Quoted 5 lines · Charvi Mendiratta
Okay, I looked into the
write_message(...)and agree that it does not return a positive value and only returns non-zero for error case and zero for success. So, for this patch maybe we can ignore checking '< 0' here and later add another patch to make this function follow the convention of "negative is error".
Please don't. There is a higher cognitive cost to readers when you write
if (write_message(...)) {The reader is forced to look at its implementation to see if it returns positive in a non-error situation.
If you write it like so from the beginning
if (write_message(...) < 0) {the reader can trust that the code follows "negative is an error" convention. One fewer thing readers have to worry about.
Re: [RFC PATCH 1/9] rebase -i: only write fixup-message when it's needed
Hi Junio,
Quoted 16 lines · Junio C Hamano
Quoted 5 lines · Charvi Mendiratta
Okay, I looked into the
write_message(...)and agree that it does not return a positive value and only returns non-zero for error case and zero for success. So, for this patch maybe we can ignore checking '< 0' here and later add another patch to make this function follow the convention of "negative is error".Please don't. There is a higher cognitive cost to readers when you write
if (write_message(...)) {The reader is forced to look at its implementation to see if it returns positive in a non-error situation.
Quoted 6 lines
If you write it like so from the beginning
if (write_message(...) < 0) {the reader can trust that the code follows "negative is an error" convention. One fewer thing readers have to worry about.
I agree, earlier I was confused as there were many instances of write_message() without '< 0' in sequencer.c but considering the above I completely agree to follow the convention.
Thanks and Regards,
Charvi
RFC PATCH 2/9 sequencer: factor out code to append squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
This code is going to grow over the next two commits so move it to its own function.
--- sequencer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
sequencer.c +12 -6
@@ -1718,6 +1718,17 @@ static int is_pick_or_similar(enum todo_command command) } } +static void append_squash_message (struct strbuf *buf,const char *body, +struct replay_opts *opts) +{ +unlink (rebase_path_fixup_msg ()); +strbuf_addf (buf,"\n%c " , comment_line_char); +strbuf_addf (buf,_ ("This is the commit message #%d:" ), + ++opts->current_fixup_count +1 ); +strbuf_addstr (buf,"\n\n" ); +strbuf_addstr (buf, body); +} + static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit,
@@ -1782,12 +1793,7 @@ static int update_squash_messages(struct repository *r,find_commit_subject (message, &body);if (command ==TODO_SQUASH ) { -unlink (rebase_path_fixup_msg ()); -strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is the commit message #%d:" ), - ++opts->current_fixup_count +1 ); -strbuf_addstr (&buf,"\n\n" ); -strbuf_addstr (&buf, body); +append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
Signature · 1 line
2.29.0.rc1
RFC PATCH 3/9 rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
--- sequencer.c | 25 ++++++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 27 +++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 37 insertions(+), 19 deletions(-)
sequencer.c +24 -1
@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +} +static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len); } static int update_squash_messages(struct repository *r,
t/t3415-rebase-autosquash.sh +13 -14
@@ -81,8 +81,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" && git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&
@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -203,7 +202,7 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep "extra para" commit >actual && test_line_count = 1 actual '
@@ -213,7 +212,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git add -u && test_tick && oid=$(git rev-parse --short=11 HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-longshasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep "extra para" commit >actual && test_line_count = 1 actual '
@@ -233,7 +232,7 @@ test_auto_commit_flags () { echo 1 >file1 && git add -u && test_tick && - git commit --$1 first-commit && + git commit --$1 first-commit -m "extra para for first" && git tag final-commit-$1 && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -261,11 +260,11 @@ test_auto_fixup_fixup () { echo 1 >file1 && git add -u && test_tick && - git commit -m "$1! first" && + git commit -m "$1! first" -m "extra para for first" && echo 2 >file1 && git add -u && test_tick && - git commit -m "$1! $2! first" && + git commit -m "$1! $2! first" -m "second extra para for first" && git tag "final-$1-$2" && test_tick && (
@@ -326,12 +325,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para for first" && echo 1 >file1 && git add -u && test_tick && subject=$(git log -n 1 --format=%s HEAD~2) && - git commit -m "squash! $subject" && + git commit -m "squash! $subject" -m "second extra para for first" && git tag final-squash-instFmt && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -342,8 +341,8 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + grep first commit >actual && + test_line_count = 3 actual ' test_expect_success 'autosquash with empty custom instructionFormat' '
t/t3900-i18n-commit.sh +0 -4
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - if test $flag = squash; then - subject="$(head -1 expect)" && - printf "\nsquash! %s\n" "$subject" >>expect - fi && git cat-file commit HEAD^ >raw && (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && test_cmp expect actual
Signature · 1 line
2.29.0.rc1
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Quoted 35 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 25 ++++++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 27 +++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 37 insertions(+), 19 deletions(-)sequencer.c +8
-0@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line)
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1738
Quoted 10 lines
sequencer.c +10
-0+return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +} +
OK, so this gets the length of the subject in "body", which is defined as the run of characters before a newline and then a space character. So "foo bar\n\nbaz" would return 7, but "foo bar\nbaz" would return 11.
Makes sense. (Apologies for stating the obvious here, I just had to read this function to myself a couple of times to make sure that I understood what it was doing.)
Quoted 5 lines
sequencer.c +2
-0static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1752
Quoted 10 lines
sequencer.c +4
-1unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len);
Very nice; the subject gets commented when it starts with "squash!" or "fixup!", but the body remains uncommented. Makes sense to me.
sequencer.c test_expect_success 'auto squash that matches longer sha1' ' · line 228
Quoted 8 lines
sequencer.c +1
-1@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep"extra para" commit >actual && test_line_count = 1 actual '
Worth checking that "squash" doesn't appear in an uncommented part of actual? Or better yet, checking that "# squash ..." _does_ appear.
I.e., that we would leave this as:
- grep squash commit >actual &&
+ grep "^# squash" commit >actual &&
+ grep "extra para" commit >actual &&sequencer.c test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' · line 346
Quoted 9 lines
sequencer.c +2
-2@@ -342,8 +341,8 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + grep first commit >actual && + test_line_count = 3 actual '
Ditto.
Thanks,
Taylor
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Quoted 52 lines · Taylor Blau
Quoted 35 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 25 ++++++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 27 +++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 37 insertions(+), 19 deletions(-)sequencer.c +8
-0@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line)sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1738
Quoted 10 lines
sequencer.c +10
-0+return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +} +OK, so this gets the length of the subject in "body", which is defined as the run of characters before a newline and then a space character. So "foo bar\n\nbaz" would return 7, but "foo bar\nbaz" would return 11.
Quoted 4 lines
Makes sense. (Apologies for stating the obvious here, I just had to read this function to myself a couple of times to make sure that I understood what it was doing.)
Earlier while testing patch, I also went through in the same way and now got confirmed as you described here.
Quoted 16 lines
Quoted 5 lines
sequencer.c +2
-0static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1752
Quoted 10 lines
sequencer.c +4
-1unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len);
Quoted 3 lines
Very nice; the subject gets commented when it starts with "squash!" or "fixup!", but the body remains uncommented. Makes sense to me.
I agree and Thanks to Phillip, for the patch.
Quoted 18 lines
sequencer.c test_expect_success 'auto squash that matches longer sha1' ' · line 228
Quoted 8 lines
sequencer.c +1
-1@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep"extra para" commit >actual && test_line_count = 1 actual 'Worth checking that "squash" doesn't appear in an uncommented part of actual? Or better yet, checking that "# squash ..." _does_ appear.
I.e., that we would leave this as:
- grep squash commit >actual && + grep "^# squash" commit >actual && + grep "extra para" commit >actual &&
Quoted 11 lines
sequencer.c test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' · line 346
Quoted 9 lines
sequencer.c +2
-2@@ -342,8 +341,8 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + grep first commit >actual && + test_line_count = 3 actual 'Ditto.
Okay, I will add it .
Thanks and Regards,
Charvi
Quoted 3 lines
Thanks,
Taylor
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Charvi and Taylor
Quoted 43 lines · Charvi Mendiratta
Quoted 42 lines · Taylor Blau
Quoted 40 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 25 ++++++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 27 +++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 37 insertions(+), 19 deletions(-)sequencer.c +13
-0@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ;
Quoted 8 lines
Quoted 8 lines
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1738
Quoted 5 lines
sequencer.c +5
-0+ } + } +return blank_line ? len : i; +} +OK, so this gets the length of the subject in "body", which is defined as the run of characters before a newline and then a space character.
The length of the subject is the run of characters before a line containing only whitespace, "hello\n there" would return 13 "hello\n \nthere" would return 5. Looking again at my code there must be a way of writing that function that is easier to follow.
Quoted 27 lines
Quoted 7 lines
So
"foo bar\n\nbaz" would return 7, but "foo bar\nbaz" would return 11.Makes sense. (Apologies for stating the obvious here, I just had to read this function to myself a couple of times to make sure that I understood what it was doing.)
Earlier while testing patch, I also went through in the same way and now got confirmed as you described here.
Quoted 16 lines
Quoted 15 lines
sequencer.c +6
-1static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len);
Quoted 23 lines
Quoted 3 lines
Very nice; the subject gets commented when it starts with "squash!" or "fixup!", but the body remains uncommented. Makes sense to me.
I agree and Thanks to Phillip, for the patch.
Quoted 17 lines
sequencer.c test_expect_success 'auto squash that matches longer sha1' ' · line 228
Quoted 8 lines
sequencer.c +1
-1@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep"extra para" commit >actual && test_line_count = 1 actual 'Worth checking that "squash" doesn't appear in an uncommented part of actual? Or better yet, checking that "# squash ..." _does_ appear.
I.e., that we would leave this as:
- grep squash commit >actual && + grep "^# squash" commit >actual && + grep "extra para" commit >actual &&
This test is checking the message that gets committed, not the contents of the file passed to the editor. I like the idea of checking that the squash! line is indeed commented out, but we'd need to test it with
grep -v squash
Looking at the changes to the tests in this commit it highlights the fact that I don't think we ever check exactly what the user sees in their editor. We do add such a test for the new fixup -C functionality in a later patch but perhaps we should improve the test coverage of the squash message presented to the user before then.
Best Wishes
Phillip
Quoted 20 lines
Quoted 11 lines
sequencer.c test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' · line 346
Quoted 9 lines
sequencer.c +2
-2@@ -342,8 +341,8 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + grep first commit >actual && + test_line_count = 3 actual 'Ditto.
Okay, I will add it .
Thanks and Regards,
CharviQuoted 3 lines
Thanks,
Taylor
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Phillip,
Quoted 56 lines · Phillip Wood
Hi Charvi and Taylor
Quoted 43 lines · Charvi Mendiratta
Quoted 42 lines · Taylor Blau
Quoted 40 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
Signed-off-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 25 ++++++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 27 +++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 37 insertions(+), 19 deletions(-)sequencer.c +13
-0@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ;Quoted 8 lines
Quoted 8 lines
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1738
Quoted 5 lines
sequencer.c +5
-0+ } + } +return blank_line ? len : i; +} +OK, so this gets the length of the subject in "body", which is defined as the run of characters before a newline and then a space character.
Quoted 5 lines
The length of the subject is the run of characters before a line containing only whitespace, "hello\n there" would return 13 "hello\n \nthere" would return 5. Looking again at my code there must be a way of writing that function that is easier to follow.
Okay. I will look into it once, thanks for explaining.
Quoted 55 lines
Quoted 27 lines
Quoted 7 lines
So
"foo bar\n\nbaz" would return 7, but "foo bar\nbaz" would return 11.Makes sense. (Apologies for stating the obvious here, I just had to read this function to myself a couple of times to make sure that I understood what it was doing.)
Earlier while testing patch, I also went through in the same way and now got confirmed as you described here.
Quoted 16 lines
Quoted 15 lines
sequencer.c +6
-1static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len);Quoted 23 lines
Quoted 3 lines
Very nice; the subject gets commented when it starts with "squash!" or "fixup!", but the body remains uncommented. Makes sense to me.
I agree and Thanks to Phillip, for the patch.
Quoted 17 lines
sequencer.c test_expect_success 'auto squash that matches longer sha1' ' · line 228
Quoted 8 lines
sequencer.c +1
-1@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep"extra para" commit >actual && test_line_count = 1 actual 'Worth checking that "squash" doesn't appear in an uncommented part of actual? Or better yet, checking that "# squash ..." _does_ appear.
I.e., that we would leave this as:
- grep squash commit >actual && + grep "^# squash" commit >actual && + grep "extra para" commit >actual &&This test is checking the message that gets committed, not the contents of the file passed to the editor. I like the idea of checking that the squash! line is indeed commented out, but we'd need to test it with
Quoted 8 lines
grep -v squash
Looking at the changes to the tests in this commit it highlights the fact that I don't think we ever check exactly what the user sees in their editor. We do add such a test for the new
fixup -Cfunctionality in a later patch but perhaps we should improve the test coverage of the squash message presented to the user before then.
Okay and for checking "squash" I will add it in the above way.
Thanks and Regards,
Charvi
Quoted 25 lines
Best Wishes
Phillip
Quoted 20 lines
Quoted 11 lines
sequencer.c test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' · line 346
Quoted 9 lines
sequencer.c +2
-2@@ -342,8 +341,8 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + grep first commit >actual && + test_line_count = 3 actual 'Ditto.
Okay, I will add it .
Thanks and Regards,
CharviQuoted 3 lines
Thanks,
Taylor
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Charvi,
Quoted 29 lines · Charvi Mendiratta
Quoted 27 lines · Phillip Wood
Quoted 25 lines · Charvi Mendiratta
Quoted 24 lines · Taylor Blau
Quoted 9 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
sequencer.c +7
-0+static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) {sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1737
Quoted 10 lines
sequencer.c +10
-0+if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +}OK, so this gets the length of the subject in "body", which is defined as the run of characters before a newline and then a space character.
Quoted 6 lines
Quoted 4 lines
The length of the subject is the run of characters before a line containing only whitespace, "hello\n there" would return 13 "hello\n \nthere" would return 5. Looking again at my code there must be a way of writing that function that is easier to follow.
Okay. I will look into it once, thanks for explaining.
You may want to look at other places in the code where we deal with the subject. For example there is find_commit_subject() in commit.c and find_trailer_start() in trailer.c that might have interesting code for our purpose.
Best,
Christian.
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Christian,
Quoted 39 lines · Christian Couder
Hi Charvi,
Quoted 34 lines · Charvi Mendiratta
Quoted 31 lines · Phillip Wood
Quoted 17 lines · Charvi Mendiratta
Quoted 16 lines · Taylor Blau
Quoted 14 lines · Charvi Mendiratta
From: Phillip Wood <[email protected]>
sequencer.c +12
-0+static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) {Quoted 8 lines
Quoted 8 lines
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1737
Quoted 5 lines
sequencer.c +5
-0+ blank_line =0 ; + } + } +return blank_line ? len : i; +}OK, so this gets the length of the subject in "body", which is defined as the run of characters before a newline and then a space character.
The length of the subject is the run of characters before a line containing only whitespace, "hello\n there" would return 13 "hello\n \nthere" would return 5. Looking again at my code there must be a way of writing that function that is easier to follow.
Quoted 7 lines
Quoted 1 line
Okay. I will look into it once, thanks for explaining.
You may want to look at other places in the code where we deal with the subject. For example there is
find_commit_subject()incommit.candfind_trailer_start()intrailer.cthat might have interesting code for our purpose.
Thanks for the pointer, I will look at it.
Thanks and Regards,
Charvi
Quoted 2 lines
Best,
Christian.
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Phillip WoodHi Phillip and Taylor,
Quoted 19 lines
[...]
Quoted 12 lines
Quoted 12 lines
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches longer sha1' ' · line 228
Quoted 8 lines
t/t3415-rebase-autosquash.sh +1
-1@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep "extra para" commit >actual && test_line_count = 1 actual 'Worth checking that "squash" doesn't appear in an uncommented part of actual? Or better yet, checking that "# squash ..." _does_ appear.
Quoted 5 lines
Quoted 5 lines
I.e., that we would leave this as:
- grep squash commit >actual && + grep "^# squash" commit >actual && + grep "extra para" commit >actual &&
Quoted 6 lines
This test is checking the message that gets committed, not the contents of the file passed to the editor. I like the idea of checking that the squash! line is indeed commented out, but we'd need to test it with
grep -v squash
It seems to me that you suggest to use 'grep -v squash' instead of grep "^#squash". So I added to check the test as here:
- grep squash commit >actual &&
+ grep -v "squash" commit >actual &&
+ grep "extra para" commit >actual &&Quoted 5 lines
Looking at the changes to the tests in this commit it highlights the fact that I don't think we ever check exactly what the user sees in their editor. We do add such a test for the new
fixup -Cfunctionality in a later patch but perhaps we should improve the test coverage of the squash message presented to the user before then.
I agree and in this test it's now just checking if the commit message body of "squash!" i.e line "extra para", is added in commit message or not. So, I am doubtful if the above is the right way to test whether squash! line is commented out or not , as "grep "extra para" commit >actual &&" will rewrite the 'actual' file.
Thanks and Regards,
Charvi
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Charvi
Quoted 25 lines · Charvi Mendiratta
Hi Phillip and Taylor,
Quoted 23 lines
[...]
Quoted 12 lines
Quoted 12 lines
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches longer sha1' ' · line 228
Quoted 8 lines
t/t3415-rebase-autosquash.sh +1
-1@@ -224,7 +223,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep "extra para" commit >actual && test_line_count = 1 actual 'Worth checking that "squash" doesn't appear in an uncommented part of actual? Or better yet, checking that "# squash ..." _does_ appear.
Quoted 5 lines
Quoted 5 lines
I.e., that we would leave this as:
- grep squash commit >actual && + grep "^# squash" commit >actual && + grep "extra para" commit >actual &&This test is checking the message that gets committed, not the contents of the file passed to the editor. I like the idea of checking that the squash! line is indeed commented out, but we'd need to test it with
Quoted 5 lines
Quoted 2 lines
grep -v squash
It seems to me that you suggest to use 'grep -v squash' instead of grep "^#squash".
That's correct
Quoted 4 lines
So I added to check the test as here:
- grep squash commit >actual &&
+ grep -v "squash" commit >actual &&
There is no need to redirect the output of this one - we don't expect any output and the test will fail if there is so we want to see what the output is.
Quoted 8 lines
+ grep "extra para" commit >actual &&
Quoted 5 lines
Looking at the changes to the tests in this commit it highlights the fact that I don't think we ever check exactly what the user sees in their editor. We do add such a test for the new
fixup -Cfunctionality in a later patch but perhaps we should improve the test coverage of the squash message presented to the user before then.
Quoted 5 lines
I agree and in this test it's now just checking if the commit message body of "squash!" i.e line "extra para", is added in commit message or not. So, I am doubtful if the above is the right way to test whether squash! line is commented out or not , as "grep "extra para" commit >actual &&" will rewrite the 'actual' file.
The test above gives us reassurance that "squash! ..." does not make it into the commit message which is important. We'd want a separate test to check the message that is presented to the user however looking at patch 7 the test 'sequence of fixup, fixup -C & squash --signoff works' checks that a "squash! ..." subject line gets commented out so I wouldn't worry about an additional test here
Best Wishes
Phillip
Quoted 3 lines
Thanks and Regards,
Charvi
Re: [RFC PATCH 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Phillip,
Quoted 10 lines · Phillip Wood
[...]
Quoted 4 lines
So I added to check the test as here:
- grep squash commit >actual &&
+ grep -v "squash" commit >actual &&There is no need to redirect the output of this one - we don't expect any output and the test will fail if there is so we want to see what the output is.
Okay,
Quoted 14 lines
Quoted 8 lines
+ grep "extra para" commit >actual &&
Quoted 5 lines
Looking at the changes to the tests in this commit it highlights the fact that I don't think we ever check exactly what the user sees in their editor. We do add such a test for the new
fixup -Cfunctionality in a later patch but perhaps we should improve the test coverage of the squash message presented to the user before then.Quoted 5 lines
I agree and in this test it's now just checking if the commit message body of "squash!" i.e line "extra para", is added in commit message or not. So, I am doubtful if the above is the right way to test whether squash! line is commented out or not , as "grep "extra para" commit >actual &&" will rewrite the 'actual' file.
Quoted 6 lines
The test above gives us reassurance that "squash! ..." does not make it into the commit message which is important. We'd want a separate test to check the message that is presented to the user however looking at patch 7 the test 'sequence of fixup, fixup -C & squash --signoff works' checks that a "squash! ..." subject line gets commented out so I wouldn't worry about an additional test here
I agree, thanks for confirming.
Thanks and Regards,
Charvi
RFC PATCH 4/9 sequencer: pass todo_item to do_pick_commit()
In reply to Charvi MendirattaAs an additional member of the structure todo_item will be required in future commits pass the complete structure.
--- sequencer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
sequencer.c +11 -7
@@ -1884,8 +1884,7 @@ static void record_in_rewritten(struct object_id *oid, }static int do_pick_commit (struct repository *r, -enum todo_command command, -struct commit *commit, +struct todo_item *item,struct replay_opts *opts,int final_fixup,int *check_todo) {
@@ -1898,6 +1897,8 @@ static int do_pick_commit(struct repository *r,struct commit_message msg = {NULL ,NULL ,NULL ,NULL };struct strbuf msgbuf =STRBUF_INIT ;int res, unborn =0 , reword =0 , allow, drop_commit; +enum todo_command command = item->command; +struct commit *commit = item->commit;if (opts->no_commit) {/*
@@ -4147,8 +4148,8 @@ static int pick_commits(struct repository *r,setenv (GIT_REFLOG_ACTION ,reflog_message (opts,command_to_string (item->command),NULL ),1 ); - res =do_pick_commit (r, item->command, item->commit, - opts,is_final_fixup (todo_list), + res =do_pick_commit (r, item, opts, +is_final_fixup (todo_list), &check_todo);if (is_rebase_i (opts))setenv (GIT_REFLOG_ACTION , prev_reflog_action,1 );
@@ -4610,11 +4611,14 @@ static int single_pick(struct repository *r, struct replay_opts *opts) {int check_todo; +struct todo_item item; + + item.command = opts->action ==REPLAY_PICK ? +TODO_PICK :TODO_REVERT ; + item.commit = cmit;setenv (GIT_REFLOG_ACTION ,action_name (opts),0 ); -return do_pick_commit (r, opts->action ==REPLAY_PICK ? -TODO_PICK :TODO_REVERT , cmit, opts,0 , - &check_todo); +return do_pick_commit (r, &item, opts,0 , &check_todo); } int sequencer_pick_revisions(struct repository *r,
Signature · 1 line
2.29.0.rc1
RFC PATCH 5/9 sequencer: use const variable for commit message comments
In reply to Charvi MendirattaThis makes it easier to use and reuse the comments.
--- sequencer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
sequencer.c +14 -5
@@ -1736,6 +1736,15 @@ static size_t subject_length(const char *body)return blank_line ? len : i; } +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_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." ); +static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) {
@@ -1745,7 +1754,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" );strbuf_add_commented_lines (buf, body, commented_len);
@@ -1774,7 +1783,7 @@ static int update_squash_messages(struct repository *r, buf.buf : strchrnul(buf.buf, '\n');strbuf_addf (&header,"%c " , comment_line_char); -strbuf_addf (&header,_ ("This is a combination of %d commits." ), +strbuf_addf (&header,_ (combined_commit_msg_str), opts->current_fixup_count +2 );strbuf_splice (&buf,0 , eol - buf.buf, header.buf, header.len);strbuf_release (&header);
@@ -1801,9 +1810,9 @@ static int update_squash_messages(struct repository *r, }strbuf_addf (&buf,"%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is a combination of %d commits." ),2 ); +strbuf_addf (&buf,_ (combined_commit_msg_str),2 );strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addstr (&buf,_ ("This is the 1st commit message:" )); +strbuf_addstr (&buf,_ (first_commit_msg_str));strbuf_addstr (&buf,"\n\n" );strbuf_addstr (&buf, body);
@@ -1819,7 +1828,7 @@ static int update_squash_messages(struct repository *r,append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("The commit message #%d will be skipped:" ), +strbuf_addf (&buf,_ (skip_nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (&buf,"\n\n" );strbuf_add_commented_lines (&buf, body,strlen (body));
Signature · 1 line
2.29.0.rc1
Re: [RFC PATCH 5/9] sequencer: use const variable for commit message comments
Quoted 16 lines · Charvi Mendiratta
This makes it easier to use and reuse the comments.
Mentored-by Christian Couder <[email protected]>Mentored-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)sequencer.c +0
-0@@ -1736,6 +1736,15 @@ static size_t subject_length(const char *body)return blank_line ? len : i; }
sequencer.c static size_t subject_length(const char *body) · line 1747
Quoted 10 lines
sequencer.c +9
-0+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_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." ); +
Two nit-picks here. The line break after the '=' is a little awkward, since two of these lines are less than 80 characters combined, and the other two are just slightly longer than 80 characters. The other nitpick is that its typical to see 'char *foo' instead of 'char foo[]'.
So, I'd write these as:
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_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.");I also noticed that you suffix these with _fmt or _str depending on whether or not there are arguments that get filled in later on. That makes 'combined_commit_msg_str' labeled incorrectly (it should be 'combined_commit_msg_fmt').
I'm curious to see where down the road these messages will be used over again, but I'm sure that that is coming in subsequent patch(es).
static void append_squash_message(struct strbuf *buf, const char *body,
struct replay_opts *opts)
sequencer.c static void append_squash_message(struct strbuf *buf, const char *body, · line 1758
Quoted 10 lines
sequencer.c +1
-1static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) {@@ -1745,7 +1754,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );
This and the three below uses are good, since they still translate these messages. Nice.
Thanks,
Taylor
Re: [RFC PATCH 5/9] sequencer: use const variable for commit message comments
Quoted 11 lines · Taylor Blau
Two nit-picks here. The line break after the '=' is a little awkward, since two of these lines are less than 80 characters combined, and the other two are just slightly longer than 80 characters. The other nitpick is that its typical to see 'char *foo' instead of 'char foo[]'.
So, I'd write these as:
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_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.");
I actually am OK with []; it saves sizeof(char*) bytes from each of the variable, doesn't it?
Quoted 4 lines
I also noticed that you suffix these with
_fmtor_strdepending on whether or not there are arguments that get filled in later on. That makes 'combined_commit_msg_str' labeled incorrectly (it should be 'combined_commit_msg_fmt').
Good eyes.
Thanks.
Re: [RFC PATCH 5/9] sequencer: use const variable for commit message comments
Quoted 2 lines · Junio C Hamano
Taylor Blau <[email protected]> writes:
[...]
Quoted 5 lines
Quoted 5 lines
The other nitpick
is that its typical to see 'char *foo' instead of 'char foo[]'.So, I'd write these as:
Quoted 7 lines
Quoted 4 lines
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_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.");I actually am OK with []; it saves
sizeof(char*)bytes from each of the variable, doesn't it?
Yeah, that's my understanding too.
Re: [RFC PATCH 5/9] sequencer: use const variable for commit message comments
In reply to Taylor BlauQuoted 34 lines · Taylor Blau
Quoted 16 lines · Charvi Mendiratta
This makes it easier to use and reuse the comments.
Mentored-by Christian Couder <[email protected]>Mentored-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)sequencer.c +0
-0@@ -1736,6 +1736,15 @@ static size_t subject_length(const char *body)return blank_line ? len : i; }sequencer.c static size_t subject_length(const char *body) · line 1747
Quoted 10 lines
sequencer.c +9
-0+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_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." ); +Two nit-picks here. The line break after the '=' is a little awkward, since two of these lines are less than 80 characters combined, and the other two are just slightly longer than 80 characters. The other nitpick is that its typical to see 'char *foo' instead of 'char foo[]'.
Quoted 7 lines
So, I'd write these as:
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_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.");
Okay, I will change it and write in the same line,
Also, I agree with Junio and Christian to use array instead of pointer here as it will take the extra memory for pointer.
Quoted 5 lines
I also noticed that you suffix these with
_fmtor_strdepending on whether or not there are arguments that get filled in later on. That makes 'combined_commit_msg_str' labeled incorrectly (it should be 'combined_commit_msg_fmt').
I admit, I was not aware about the difference of _fmt or _str but now I got this and will change it.
Quoted 5 lines
I'm curious to see where down the road these messages will be used over again, but I'm sure that that is coming in subsequent patch(es).
static void append_squash_message(struct strbuf *buf, const char *body,
structreplay_opts*opts)
Quoted 14 lines
sequencer.c static void append_squash_message(struct strbuf *buf, const char *body, · line 1758
Quoted 10 lines
sequencer.c +1
-1static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) {@@ -1745,7 +1754,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );This and the three below uses are good, since they still translate these messages. Nice.
Thanks for the reviews,
Thanks and Regards,
Charvi
Quoted 2 lines
Thanks,
Taylor
RFC PATCH 6/9 rebase -i: add fixup [-C | -c] command
In reply to Charvi MendirattaAdd options to fixup command to fixup both the commit contents and message. fixup -C command is used to replace the original commit message and fixup -c, additionally allows to edit the commit message.
--- rebase-interactive.c | 4 +- sequencer.c | 212 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 196 insertions(+), 20 deletions(-)
rebase-interactive.c +3 -1
@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"r, reword <commit> = use commit, but edit the commit message\n" "e, edit <commit> = use commit, but stop for amending\n" "s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = 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" "x, exec <command> = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop <commit> = remove commit\n"
sequencer.c +193 -19
303 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
Re: [RFC PATCH 6/9] rebase -i: add fixup [-C | -c] command
Quoted 10 lines · Charvi Mendiratta
sequencer.c +2
-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." );
[...]
sequencer.c static const char first_commit_msg_str[] = · line 1794
Quoted 4 lines
sequencer.c +4
-0+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);
Should "_(...)" be used around "nth_commit_msg_fmt" here...
sequencer.c static const char first_commit_msg_str[] = · line 1797
Quoted 3 lines
sequencer.c +3
-0+strbuf_addch (buf1,'\n' ); +strbuf_setlen (buf2,2 ); +strbuf_addf (buf2, skip_nth_commit_msg_fmt, n);
...and around "skip_nth_commit_msg_fmt" here?
Quoted 2 lines
(quoted diff) +2
-0+ strbuf_addch(buf2, '\n'); +}
Re: [RFC PATCH 6/9] rebase -i: add fixup [-C | -c] command
Hi Christian,
Quoted 24 lines · Christian Couder
Quoted 10 lines · Charvi Mendiratta
sequencer.c +2
-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." );[...]
sequencer.c static const char first_commit_msg_str[] = · line 1794
Quoted 4 lines
sequencer.c +4
-0+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);Should "
_(...)" be used around "nth_commit_msg_fmt" here...
Quoted 6 lines
sequencer.c static const char first_commit_msg_str[] = · line 1797
Quoted 3 lines
sequencer.c +3
-0+strbuf_addch (buf1,'\n' ); +strbuf_setlen (buf2,2 ); +strbuf_addf (buf2, skip_nth_commit_msg_fmt, n);...and around "
skip_nth_commit_msg_fmt" here?
Yes, I forgot to put "_(...)" here for translation. I will add it, thanks.
Thanks and Regards,
Charvi
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2
-0+ strbuf_addch(buf2, '\n'); +}
RFC PATCH 7/9 t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Charvi Mendiratta--- t/lib-rebase.sh | 4 + t/t3437-rebase-fixup-options.sh | 190 ++++++++++++++++++++++++++++++++ t/t3437/expected-squash-message | 51 +++++++++ 3 files changed, 245 insertions(+) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-squash-message
t/lib-rebase.sh +4 -0
@@ -4,6 +4,7 @@ # # - override the commit message with $FAKE_COMMIT_MESSAGE # - amend the commit message with $FAKE_COMMIT_AMEND +# - copy the original commit message to a file with $FAKE_MESSAGE_COPY # - check that non-commit messages have a certain line count with $EXPECT_COUNT # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT # - rewrite a rebase -i script as directed by $FAKE_LINES.
@@ -33,6 +34,7 @@ set_fake_editor () { exit test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" exit ;; esac
@@ -51,6 +53,8 @@ set_fake_editor () { action="$line";; exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');; "#") echo '# comment' >> "$1";; ">")
t/t3437-rebase-fixup-options.sh new file +190 -0
190 lines not on this page · raw message
t/t3437/expected-squash-message new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
RFC PATCH 8/9 rebase -i: teach --autosquash to work with amend!
In reply to Charvi MendirattaIf the commit subject starts with "amend!" then rearrange it like a "fixup!" commit and replace pick command with fixup -C command, which is used to fixup up the content if any and replaces the original commit message with amend! commit's message.
--- sequencer.c | 23 ++++++++++++++++------- t/t3437-rebase-fixup-options.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-)
sequencer.c +16 -7
@@ -5672,6 +5672,12 @@ 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) { +return skip_prefix (subject,"fixup! " , p) || +skip_prefix (subject,"amend! " , p) || +skip_prefix (subject,"squash! " , p); +} +/* * Rearrange the todo list that has both "pick commit-id msg" and "pick * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -5730,15 +5736,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_prefix (subject,"fixup! " , &p) || -skip_prefix (subject,"squash! " , &p))) { +if (skip_fixup_amend_squash (subject, &p)) {struct commit *commit2;for (;;) {while (isspace (*p)) p++; -if (!skip_prefix (p,"fixup! " , &p) && - !skip_prefix (p,"squash! " , &p)) +if (!skip_fixup_amend_squash (p, &p))break ; }
@@ -5768,9 +5772,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) }if (i2 >=0 ) { rearranged =1 ; - todo_list->items[i].command = -starts_with (subject,"fixup!" ) ? -TODO_FIXUP :TODO_SQUASH ; +if (starts_with (subject,"fixup!" )) { + todo_list->items[i].command =TODO_FIXUP ; + }else if (starts_with (subject,"amend!" )) { + todo_list->items[i].command =TODO_FIXUP ; + todo_list->items[i].flags =TODO_REPLACE_FIXUP_MSG ; + }else { + todo_list->items[i].command =TODO_SQUASH ; + }if (tail[i2] <0 ) { next[i] = next[i2]; next[i2] = i;
t/t3437-rebase-fixup-options.sh +12 -0
@@ -187,4 +187,16 @@ test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fix test_commit_message HEAD expected-message ' +test_expect_success 'fixup -C works upon --autosquash with amend!' ' + git checkout --detach branch && + FAKE_COMMIT_AMEND=squashed \ + FAKE_MESSAGE_COPY=actual-squash-message \ + git -c commit.status=false rebase -ik --autosquash \ + --signoff A && + git diff-tree --exit-code --patch HEAD branch -- && + test_cmp_rev HEAD^ A && + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \ + actual-squash-message +' + test_done
Signature · 1 line
2.29.0.rc1
RFC PATCH 9/9 doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Charvi Mendiratta--- Documentation/git-rebase.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/git-rebase.txt +9 -3
@@ -887,9 +887,15 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is created as follows: + + - It is made using the commit message of a commit with the "fixup -C" + or "fixup -c" command. In the later case an editor is opened to edit + the commit message. + - Otherwise it's the concatenation of the commit messages of the first + commit and of those with the "squash" command. + - It omits the commit messages of commits with the "fixup" + (without -C or -c) command. 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
Signature · 1 line
2.29.0.rc1
v2 cover rebase -i: add options to fixup command
In reply to Charvi MendirattaThis patch series adds fixup [-C|-c] options to interactive rebase. In addition to amending the contents of the commit as the fixup command does now, fixup -C replaces the commit message of the original commit which we are fixing up with the message of the fixup commit. And to edit the fixup commit message before committing, fixup -c command is used instead of fixup -C. This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
This patch series also changes rebase -i --autosquash to rearrange commits whose message starts with "amend!" and replaces the pick command with fixup -C. The creation of "amend!" commits will be rebase -i: add options to fixup command added in another patch series.
This is done in reference to the issue opened by Dscho as here[1] and further discussed briefly[2]. Also, there is discussion[3] regarding the implementation of reword! commit. The past patches of Phillip Wood’s work[4], implements 'reword!' as 'amend!' in git rebase and these patches uses those as the initial base.
And to avoid the extra command in the interactive rebase, this patch series instead add options to the current fixup command in interactive rebase (fixup [-C | -c]) as discussed earlier[5].
Changes from v1 :
* added '< 0' to check that 'write_message()' returns an error
* checks if squash! line commented out in t3415-rebase-autosquash.sh
* removing line break and changing suffix from _str to _fmt in sequencer.c
[1] https://github.com/gitgitgadget/git/issues/259
[2] https://public-inbox.org/git/alpine.DEB.2.21.1.1710151754070.40514@virtualbox/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://github.com/phillipwood/git/commits/wip/rebase-amend
[5] https://lore.kernel.org/git/[email protected]/
Charvi Mendiratta (6):
sequencer: pass todo_item to do_pick_commit()
sequencer: use const variable for commit message comments rebase -i: add fixup [-C | -c] command
t3437: test script for fixup [-C|-c] options in interactive rebase rebase -i: teach --autosquash to work with amend! doc/git-rebase: add documentation for fixup [-C|-c] options
Phillip Wood (3):
rebase -i: only write fixup-message when it's needed
sequencer: factor out code to append squash message rebase -i: comment out squash!/fixup! subjects from squash message
Documentation/git-rebase.txt | 12 +- rebase-interactive.c | 4 +- sequencer.c | 297 +++++++++++++++++++++++++++----- t/lib-rebase.sh | 4 + t/t3415-rebase-autosquash.sh | 30 ++-- t/t3437-rebase-fixup-options.sh | 202 ++++++++++++++++++++++ t/t3437/expected-squash-message | 51 ++++++ t/t3900-i18n-commit.sh | 4 - 8 files changed, 543 insertions(+), 61 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-squash-message
--
2.29.0.rc1
v3 cover rebase -i: add options to fixup command
This patch series adds fixup [-C|-c] options to interactive rebase. In addition to amending the contents of the commit as the fixup command does now, fixup -C replaces the commit message of the original commit which we are fixing up with the message of the fixup commit. And to edit the fixup commit message before committing, fixup -c command is used instead of fixup -C. This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
This patch series also changes rebase -i --autosquash to rearrange commits whose message starts with "amend!" and replaces the pick command with fixup -C. The creation of "amend!" commits will be rebase -i: add options to fixup command added in another patch series.
This is done in reference to the issue opened by Dscho as here[1] and further discussed briefly[2]. Also, there is discussion[3] regarding the implementation of reword! commit. The past patches of Phillip Wood’s work[4], implements 'reword!' as 'amend!' in git rebase and these patches uses those as the initial base.
And to avoid the extra command in the interactive rebase, this patch series instead add options to the current fixup command in interactive rebase (fixup [-C | -c]) as discussed earlier[5].
Changes from v2 :
(Thanks to Junio C Hamano, Marc Branchaud, Christian Couder, Phillip Wood and Taylor Blau for the reviews and suggestions)
* Updated the Documentation/git-rebase.txt
* Added tests(t3437-rebase-fixup-options.sh) to check working of multiple fixup -c in rebase -i and related changes in sequencer.c
* Updated subject_length() function in sequencer.c and some corrections in t3415-rebase-autosquash.sh
[1] https://github.com/gitgitgadget/git/issues/259
[2] https://public-inbox.org/git/alpine.DEB.2.21.1.1710151754070.40514@virtualbox/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://github.com/phillipwood/git/commits/wip/rebase-amend
[5] https://lore.kernel.org/git/[email protected]/
Charvi Mendiratta (6):
sequencer: pass todo_item to do_pick_commit()
sequencer: use const variable for commit message comments rebase -i: add fixup [-C | -c] command
t3437: test script for fixup [-C|-c] options in interactive rebase rebase -i: teach --autosquash to work with amend! doc/git-rebase: add documentation for fixup [-C|-c] options
Phillip Wood (3):
rebase -i: only write fixup-message when it's needed
sequencer: factor out code to append squash message rebase -i: comment out squash!/fixup! subjects from squash message
Documentation/git-rebase.txt | 14 +- rebase-interactive.c | 4 +- sequencer.c | 295 ++++++++++++++++++++++++++---- t/lib-rebase.sh | 4 + t/t3415-rebase-autosquash.sh | 30 +-- t/t3437-rebase-fixup-options.sh | 225 +++++++++++++++++++++++ t/t3437/expected-combined-message | 21 +++ t/t3437/expected-squash-message | 51 ++++++ t/t3900-i18n-commit.sh | 4 - 9 files changed, 587 insertions(+), 61 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message create mode 100644 t/t3437/expected-squash-message
--
2.29.0.rc1
PATCH v3 1/9 rebase -i: only write fixup-message when it's needed
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
--- sequencer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sequencer.c +3 -4
@@ -1757,11 +1757,10 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) { +if (command ==TODO_FIXUP &&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 ()); +return error (_ ("cannot write '%s'" ),rebase_path_fixup_msg ()); }strbuf_addf (&buf,"%c " , comment_line_char);
Signature · 1 line
2.29.0.rc1
PATCH v3 2/9 sequencer: factor out code to append squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
This code is going to grow over the next two commits so move it to its own function.
--- sequencer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
sequencer.c +12 -6
@@ -1718,6 +1718,17 @@ static int is_pick_or_similar(enum todo_command command) } } +static void append_squash_message (struct strbuf *buf,const char *body, +struct replay_opts *opts) +{ +unlink (rebase_path_fixup_msg ()); +strbuf_addf (buf,"\n%c " , comment_line_char); +strbuf_addf (buf,_ ("This is the commit message #%d:" ), + ++opts->current_fixup_count +1 ); +strbuf_addstr (buf,"\n\n" ); +strbuf_addstr (buf, body); +} + static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit,
@@ -1779,12 +1790,7 @@ static int update_squash_messages(struct repository *r,find_commit_subject (message, &body);if (command ==TODO_SQUASH ) { -unlink (rebase_path_fixup_msg ()); -strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is the commit message #%d:" ), - ++opts->current_fixup_count +1 ); -strbuf_addstr (&buf,"\n\n" ); -strbuf_addstr (&buf, body); +append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
Signature · 1 line
2.29.0.rc1
PATCH v3 3/9 rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
--- sequencer.c | 21 ++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 30 ++++++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 36 insertions(+), 19 deletions(-)
sequencer.c +20 -1
@@ -1718,15 +1718,34 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +const char *p = body; +while (*p) { +const char *next =skip_blank_lines (p); +if (next != p) +break ; + p =strchrnul (p,'\n' ); +if (*p) + p++; + } +return p - body; +} +static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len); } static int update_squash_messages(struct repository *r,
t/t3415-rebase-autosquash.sh +16 -14
@@ -81,8 +81,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" && git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&
@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -203,7 +202,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep -v "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual '
@@ -213,7 +213,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git add -u && test_tick && oid=$(git rev-parse --short=11 HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-longshasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -224,7 +224,8 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep -v "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual '
@@ -233,7 +234,7 @@ test_auto_commit_flags () { echo 1 >file1 && git add -u && test_tick && - git commit --$1 first-commit && + git commit --$1 first-commit -m "extra para for first" && git tag final-commit-$1 && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -261,11 +262,11 @@ test_auto_fixup_fixup () { echo 1 >file1 && git add -u && test_tick && - git commit -m "$1! first" && + git commit -m "$1! first" -m "extra para for first" && echo 2 >file1 && git add -u && test_tick && - git commit -m "$1! $2! first" && + git commit -m "$1! $2! first" -m "second extra para for first" && git tag "final-$1-$2" && test_tick && (
@@ -326,12 +327,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para for first" && echo 1 >file1 && git add -u && test_tick && subject=$(git log -n 1 --format=%s HEAD~2) && - git commit -m "squash! $subject" && + git commit -m "squash! $subject" -m "second extra para for first" && git tag final-squash-instFmt && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -342,8 +343,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + ! grep -v "squash" commit && + grep first commit >actual && + test_line_count = 3 actual ' test_expect_success 'autosquash with empty custom instructionFormat' '
t/t3900-i18n-commit.sh +0 -4
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - if test $flag = squash; then - subject="$(head -1 expect)" && - printf "\nsquash! %s\n" "$subject" >>expect - fi && git cat-file commit HEAD^ >raw && (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && test_cmp expect actual
Signature · 1 line
2.29.0.rc1
PATCH v3 4/9 sequencer: pass todo_item to do_pick_commit()
In reply to Charvi MendirattaAs an additional member of the structure todo_item will be required in future commits pass the complete structure.
--- sequencer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
sequencer.c +11 -7
@@ -1877,8 +1877,7 @@ static void record_in_rewritten(struct object_id *oid, }static int do_pick_commit (struct repository *r, -enum todo_command command, -struct commit *commit, +struct todo_item *item,struct replay_opts *opts,int final_fixup,int *check_todo) {
@@ -1891,6 +1890,8 @@ static int do_pick_commit(struct repository *r,struct commit_message msg = {NULL ,NULL ,NULL ,NULL };struct strbuf msgbuf =STRBUF_INIT ;int res, unborn =0 , reword =0 , allow, drop_commit; +enum todo_command command = item->command; +struct commit *commit = item->commit;if (opts->no_commit) {/*
@@ -4140,8 +4141,8 @@ static int pick_commits(struct repository *r,setenv (GIT_REFLOG_ACTION ,reflog_message (opts,command_to_string (item->command),NULL ),1 ); - res =do_pick_commit (r, item->command, item->commit, - opts,is_final_fixup (todo_list), + res =do_pick_commit (r, item, opts, +is_final_fixup (todo_list), &check_todo);if (is_rebase_i (opts))setenv (GIT_REFLOG_ACTION , prev_reflog_action,1 );
@@ -4603,11 +4604,14 @@ static int single_pick(struct repository *r, struct replay_opts *opts) {int check_todo; +struct todo_item item; + + item.command = opts->action ==REPLAY_PICK ? +TODO_PICK :TODO_REVERT ; + item.commit = cmit;setenv (GIT_REFLOG_ACTION ,action_name (opts),0 ); -return do_pick_commit (r, opts->action ==REPLAY_PICK ? -TODO_PICK :TODO_REVERT , cmit, opts,0 , - &check_todo); +return do_pick_commit (r, &item, opts,0 , &check_todo); } int sequencer_pick_revisions(struct repository *r,
Signature · 1 line
2.29.0.rc1
PATCH v3 5/9 sequencer: use const variable for commit message comments
In reply to Charvi MendirattaThis makes it easier to use and reuse the comments.
--- sequencer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
sequencer.c +10 -5
@@ -1732,6 +1732,11 @@ static size_t subject_length(const char *body)return p - 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_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) {
@@ -1741,7 +1746,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" );strbuf_add_commented_lines (buf, body, commented_len);
@@ -1770,7 +1775,7 @@ static int update_squash_messages(struct repository *r, buf.buf : strchrnul(buf.buf, '\n');strbuf_addf (&header,"%c " , comment_line_char); -strbuf_addf (&header,_ ("This is a combination of %d commits." ), +strbuf_addf (&header,_ (combined_commit_msg_fmt), opts->current_fixup_count +2 );strbuf_splice (&buf,0 , eol - buf.buf, header.buf, header.len);strbuf_release (&header);
@@ -1794,9 +1799,9 @@ static int update_squash_messages(struct repository *r, }strbuf_addf (&buf,"%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is a combination of %d commits." ),2 ); +strbuf_addf (&buf,_ (combined_commit_msg_fmt),2 );strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addstr (&buf,_ ("This is the 1st commit message:" )); +strbuf_addstr (&buf,_ (first_commit_msg_str));strbuf_addstr (&buf,"\n\n" );strbuf_addstr (&buf, body);
@@ -1812,7 +1817,7 @@ static int update_squash_messages(struct repository *r,append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("The commit message #%d will be skipped:" ), +strbuf_addf (&buf,_ (skip_nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (&buf,"\n\n" );strbuf_add_commented_lines (&buf, body,strlen (body));
Signature · 1 line
2.29.0.rc1
PATCH v3 6/9 rebase -i: add fixup [-C | -c] command
In reply to Charvi MendirattaAdd options to fixup command to fixup both the commit contents and message. fixup -C command is used to replace the original commit message and fixup -c, additionally allows to edit the commit message.
--- rebase-interactive.c | 4 +- sequencer.c | 213 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 197 insertions(+), 20 deletions(-)
rebase-interactive.c +3 -1
@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"r, reword <commit> = use commit, but edit the commit message\n" "e, edit <commit> = use commit, but stop for amending\n" "s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = 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" "x, exec <command> = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop <commit> = remove commit\n"
sequencer.c +194 -19
300 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
PATCH v3 7/9 t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Charvi Mendiratta--- t/lib-rebase.sh | 4 + t/t3437-rebase-fixup-options.sh | 213 ++++++++++++++++++++++++++++++ t/t3437/expected-combined-message | 21 +++ t/t3437/expected-squash-message | 51 +++++++ 4 files changed, 289 insertions(+) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message create mode 100644 t/t3437/expected-squash-message
t/lib-rebase.sh +4 -0
@@ -4,6 +4,7 @@ # # - override the commit message with $FAKE_COMMIT_MESSAGE # - amend the commit message with $FAKE_COMMIT_AMEND +# - copy the original commit message to a file with $FAKE_MESSAGE_COPY # - check that non-commit messages have a certain line count with $EXPECT_COUNT # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT # - rewrite a rebase -i script as directed by $FAKE_LINES.
@@ -33,6 +34,7 @@ set_fake_editor () { exit test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" exit ;; esac
@@ -51,6 +53,8 @@ set_fake_editor () { action="$line";; exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');; "#") echo '# comment' >> "$1";; ">")
t/t3437-rebase-fixup-options.sh new file +213 -0
213 lines not on this page · raw message
t/t3437/expected-combined-message new file +21 -0
@@ -0,0 +1,21 @@ +# This is a combination of 4 commits. +# This is the 1st commit message: + +B + +# This is the commit message #2: + +# amend! B + +new subject + +new +body + +# The commit message #3 will be skipped: + +# A2 + +# This is the commit message #4: + +A3
t/t3437/expected-squash-message new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
PATCH v3 8/9 rebase -i: teach --autosquash to work with amend!
In reply to Charvi MendirattaIf the commit subject starts with "amend!" then rearrange it like a "fixup!" commit and replace pick command with fixup -C command, which is used to fixup up the content if any and replaces the original commit message with amend! commit's message.
--- sequencer.c | 23 ++++++++++++++++------- t/t3437-rebase-fixup-options.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-)
sequencer.c +16 -7
@@ -5662,6 +5662,12 @@ 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) { +return skip_prefix (subject,"fixup! " , p) || +skip_prefix (subject,"amend! " , p) || +skip_prefix (subject,"squash! " , p); +} +/* * Rearrange the todo list that has both "pick commit-id msg" and "pick * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -5720,15 +5726,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_prefix (subject,"fixup! " , &p) || -skip_prefix (subject,"squash! " , &p))) { +if (skip_fixup_amend_squash (subject, &p)) {struct commit *commit2;for (;;) {while (isspace (*p)) p++; -if (!skip_prefix (p,"fixup! " , &p) && - !skip_prefix (p,"squash! " , &p)) +if (!skip_fixup_amend_squash (p, &p))break ; }
@@ -5758,9 +5762,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) }if (i2 >=0 ) { rearranged =1 ; - todo_list->items[i].command = -starts_with (subject,"fixup!" ) ? -TODO_FIXUP :TODO_SQUASH ; +if (starts_with (subject,"fixup!" )) { + todo_list->items[i].command =TODO_FIXUP ; + }else if (starts_with (subject,"amend!" )) { + todo_list->items[i].command =TODO_FIXUP ; + todo_list->items[i].flags =TODO_REPLACE_FIXUP_MSG ; + }else { + todo_list->items[i].command =TODO_SQUASH ; + }if (tail[i2] <0 ) { next[i] = next[i2]; next[i2] = i;
t/t3437-rebase-fixup-options.sh +12 -0
@@ -210,4 +210,16 @@ test_expect_success 'sequence squash, fixup & fixup -c gives combined message' ' test_cmp_rev HEAD^ A ' +test_expect_success 'fixup -C works upon --autosquash with amend!' ' + git checkout --detach branch && + FAKE_COMMIT_AMEND=squashed \ + FAKE_MESSAGE_COPY=actual-squash-message \ + git -c commit.status=false rebase -ik --autosquash \ + --signoff A && + git diff-tree --exit-code --patch HEAD branch -- && + test_cmp_rev HEAD^ A && + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \ + actual-squash-message +' + test_done
Signature · 1 line
2.29.0.rc1
PATCH v3 9/9 doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Charvi Mendiratta--- Documentation/git-rebase.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/git-rebase.txt +11 -3
@@ -887,9 +887,17 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omitting the +messages of commits identified by "fixup" commands, unless "fixup -c" +is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the last last one is used. You can also use +"fixup -C" to get the same behavior as "fixup -c" except without opening +an editor. + 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
Signature · 1 line
2.29.0.rc1
v4 cover rebase -i: add options to fixup command
In reply to Charvi MendirattaThis patch series adds fixup [-C|-c] options to interactive rebase. In addition to amending the contents of the commit as the fixup command does now, fixup -C replaces the commit message of the original commit which we are fixing up with the message of the fixup commit. And to edit the fixup commit message before committing, fixup -c command is used instead of fixup -C. This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
This patch series also changes rebase -i --autosquash to rearrange commits whose message starts with "amend!" and replaces the pick command with fixup -C. The creation of "amend!" commits will be rebase -i: add options to fixup command added in another patch series.
This is done in reference to the issue opened by Dscho as here[1] and further discussed briefly[2]. Also, there is discussion[3] regarding the implementation of reword! commit. The past patches of Phillip Wood’s work[4], implements 'reword!' as 'amend!' in git rebase and these patches uses those as the initial base.
And to avoid the extra command in the interactive rebase, this patch series instead add options to the current fixup command in interactive rebase (fixup [-C | -c]) as discussed earlier[5].
Changes from v2 :
(Thanks to Junio C Hamano, Marc Branchaud, Christian Couder, Phillip Wood and Taylor Blau for the reviews and suggestions)
* Updated the Documentation/git-rebase.txt
* Added tests(t3437-rebase-fixup-options.sh) to check working of multiple fixup -c in rebase -i and related changes in sequencer.c
* Updated subject_length() function in sequencer.c and some corrections in t3415-rebase-autosquash.sh
Changes from v3 :
* Corrected a small bug in t3415-rebase-autosquash.sh
(Bymistake sent the patches of local branch, with error in test script in v3, corrected those in these patch series revision)
[1] https://github.com/gitgitgadget/git/issues/259
[2] https://public-inbox.org/git/alpine.DEB.2.21.1.1710151754070.40514@virtualbox/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://github.com/phillipwood/git/commits/wip/rebase-amend
[5] https://lore.kernel.org/git/[email protected]/
Charvi Mendiratta (6):
sequencer: pass todo_item to do_pick_commit()
sequencer: use const variable for commit message comments rebase -i: add fixup [-C | -c] command
t3437: test script for fixup [-C|-c] options in interactive rebase rebase -i: teach --autosquash to work with amend! doc/git-rebase: add documentation for fixup [-C|-c] options
Phillip Wood (3):
rebase -i: only write fixup-message when it's needed
sequencer: factor out code to append squash message rebase -i: comment out squash!/fixup! subjects from squash message
Documentation/git-rebase.txt | 14 +- rebase-interactive.c | 4 +- sequencer.c | 295 ++++++++++++++++++++++++++---- t/lib-rebase.sh | 4 + t/t3415-rebase-autosquash.sh | 30 +-- t/t3437-rebase-fixup-options.sh | 225 +++++++++++++++++++++++ t/t3437/expected-combined-message | 21 +++ t/t3437/expected-squash-message | 51 ++++++ t/t3900-i18n-commit.sh | 4 - 9 files changed, 587 insertions(+), 61 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message create mode 100644 t/t3437/expected-squash-message
--
2.29.0.rc1
PATCH v4 1/9 rebase -i: only write fixup-message when it's needed
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
--- sequencer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sequencer.c +3 -4
@@ -1757,11 +1757,10 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) { +if (command ==TODO_FIXUP &&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 ()); +return error (_ ("cannot write '%s'" ),rebase_path_fixup_msg ()); }strbuf_addf (&buf,"%c " , comment_line_char);
Signature · 1 line
2.29.0.rc1
PATCH v4 2/9 sequencer: factor out code to append squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
This code is going to grow over the next two commits so move it to its own function.
--- sequencer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
sequencer.c +12 -6
@@ -1718,6 +1718,17 @@ static int is_pick_or_similar(enum todo_command command) } } +static void append_squash_message (struct strbuf *buf,const char *body, +struct replay_opts *opts) +{ +unlink (rebase_path_fixup_msg ()); +strbuf_addf (buf,"\n%c " , comment_line_char); +strbuf_addf (buf,_ ("This is the commit message #%d:" ), + ++opts->current_fixup_count +1 ); +strbuf_addstr (buf,"\n\n" ); +strbuf_addstr (buf, body); +} + static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit,
@@ -1779,12 +1790,7 @@ static int update_squash_messages(struct repository *r,find_commit_subject (message, &body);if (command ==TODO_SQUASH ) { -unlink (rebase_path_fixup_msg ()); -strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is the commit message #%d:" ), - ++opts->current_fixup_count +1 ); -strbuf_addstr (&buf,"\n\n" ); -strbuf_addstr (&buf, body); +append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
Signature · 1 line
2.29.0.rc1
PATCH v4 3/9 rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
--- sequencer.c | 21 ++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 30 ++++++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 36 insertions(+), 19 deletions(-)
sequencer.c +20 -1
@@ -1718,15 +1718,34 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +const char *p = body; +while (*p) { +const char *next =skip_blank_lines (p); +if (next != p) +break ; + p =strchrnul (p,'\n' ); +if (*p) + p++; + } +return p - body; +} +static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len); } static int update_squash_messages(struct repository *r,
t/t3415-rebase-autosquash.sh +16 -14
@@ -84,8 +84,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" && git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&
@@ -142,7 +141,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -195,7 +194,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -206,7 +205,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual '
@@ -216,7 +216,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git add -u && test_tick && oid=$(git rev-parse --short=11 HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-longshasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -227,7 +227,8 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual '
@@ -236,7 +237,7 @@ test_auto_commit_flags () { echo 1 >file1 && git add -u && test_tick && - git commit --$1 first-commit && + git commit --$1 first-commit -m "extra para for first" && git tag final-commit-$1 && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -264,11 +265,11 @@ test_auto_fixup_fixup () { echo 1 >file1 && git add -u && test_tick && - git commit -m "$1! first" && + git commit -m "$1! first" -m "extra para for first" && echo 2 >file1 && git add -u && test_tick && - git commit -m "$1! $2! first" && + git commit -m "$1! $2! first" -m "second extra para for first" && git tag "final-$1-$2" && test_tick && (
@@ -329,12 +330,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para for first" && echo 1 >file1 && git add -u && test_tick && subject=$(git log -n 1 --format=%s HEAD~2) && - git commit -m "squash! $subject" && + git commit -m "squash! $subject" -m "second extra para for first" && git tag final-squash-instFmt && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -345,8 +346,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + ! grep "squash" commit && + grep first commit >actual && + test_line_count = 3 actual ' test_expect_success 'autosquash with empty custom instructionFormat' '
t/t3900-i18n-commit.sh +0 -4
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - if test $flag = squash; then - subject="$(head -1 expect)" && - printf "\nsquash! %s\n" "$subject" >>expect - fi && git cat-file commit HEAD^ >raw && (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && test_cmp expect actual
Signature · 1 line
2.29.0.rc1
PATCH v4 4/9 sequencer: pass todo_item to do_pick_commit()
In reply to Charvi MendirattaAs an additional member of the structure todo_item will be required in future commits pass the complete structure.
--- sequencer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
sequencer.c +11 -7
@@ -1877,8 +1877,7 @@ static void record_in_rewritten(struct object_id *oid, }static int do_pick_commit (struct repository *r, -enum todo_command command, -struct commit *commit, +struct todo_item *item,struct replay_opts *opts,int final_fixup,int *check_todo) {
@@ -1891,6 +1890,8 @@ static int do_pick_commit(struct repository *r,struct commit_message msg = {NULL ,NULL ,NULL ,NULL };struct strbuf msgbuf =STRBUF_INIT ;int res, unborn =0 , reword =0 , allow, drop_commit; +enum todo_command command = item->command; +struct commit *commit = item->commit;if (opts->no_commit) {/*
@@ -4140,8 +4141,8 @@ static int pick_commits(struct repository *r,setenv (GIT_REFLOG_ACTION ,reflog_message (opts,command_to_string (item->command),NULL ),1 ); - res =do_pick_commit (r, item->command, item->commit, - opts,is_final_fixup (todo_list), + res =do_pick_commit (r, item, opts, +is_final_fixup (todo_list), &check_todo);if (is_rebase_i (opts))setenv (GIT_REFLOG_ACTION , prev_reflog_action,1 );
@@ -4603,11 +4604,14 @@ static int single_pick(struct repository *r, struct replay_opts *opts) {int check_todo; +struct todo_item item; + + item.command = opts->action ==REPLAY_PICK ? +TODO_PICK :TODO_REVERT ; + item.commit = cmit;setenv (GIT_REFLOG_ACTION ,action_name (opts),0 ); -return do_pick_commit (r, opts->action ==REPLAY_PICK ? -TODO_PICK :TODO_REVERT , cmit, opts,0 , - &check_todo); +return do_pick_commit (r, &item, opts,0 , &check_todo); } int sequencer_pick_revisions(struct repository *r,
Signature · 1 line
2.29.0.rc1
PATCH v4 5/9 sequencer: use const variable for commit message comments
In reply to Charvi MendirattaThis makes it easier to use and reuse the comments.
--- sequencer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
sequencer.c +10 -5
@@ -1732,6 +1732,11 @@ static size_t subject_length(const char *body)return p - 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_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) {
@@ -1741,7 +1746,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" );strbuf_add_commented_lines (buf, body, commented_len);
@@ -1770,7 +1775,7 @@ static int update_squash_messages(struct repository *r, buf.buf : strchrnul(buf.buf, '\n');strbuf_addf (&header,"%c " , comment_line_char); -strbuf_addf (&header,_ ("This is a combination of %d commits." ), +strbuf_addf (&header,_ (combined_commit_msg_fmt), opts->current_fixup_count +2 );strbuf_splice (&buf,0 , eol - buf.buf, header.buf, header.len);strbuf_release (&header);
@@ -1794,9 +1799,9 @@ static int update_squash_messages(struct repository *r, }strbuf_addf (&buf,"%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is a combination of %d commits." ),2 ); +strbuf_addf (&buf,_ (combined_commit_msg_fmt),2 );strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addstr (&buf,_ ("This is the 1st commit message:" )); +strbuf_addstr (&buf,_ (first_commit_msg_str));strbuf_addstr (&buf,"\n\n" );strbuf_addstr (&buf, body);
@@ -1812,7 +1817,7 @@ static int update_squash_messages(struct repository *r,append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("The commit message #%d will be skipped:" ), +strbuf_addf (&buf,_ (skip_nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (&buf,"\n\n" );strbuf_add_commented_lines (&buf, body,strlen (body));
Signature · 1 line
2.29.0.rc1
PATCH v4 6/9 rebase -i: add fixup [-C | -c] command
In reply to Charvi MendirattaAdd options to fixup command to fixup both the commit contents and message. fixup -C command is used to replace the original commit message and fixup -c, additionally allows to edit the commit message.
--- rebase-interactive.c | 4 +- sequencer.c | 213 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 197 insertions(+), 20 deletions(-)
rebase-interactive.c +3 -1
@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"r, reword <commit> = use commit, but edit the commit message\n" "e, edit <commit> = use commit, but stop for amending\n" "s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = 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" "x, exec <command> = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop <commit> = remove commit\n"
sequencer.c +194 -19
300 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
Re: [PATCH v4 6/9] rebase -i: add fixup [-C | -c] command
Quoted 3 lines · Charvi Mendiratta
Add options to
fixupcommand to fixup both the commit contents and message.fixup -Ccommand is used to replace the original commit message andfixup -c, additionally allows to edit the commit message.
In the cover letter for this series, you had this additional information:
This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
which helps to explain the choice of -c and -C. It might be nice to include that explanation in this commit message, as well (but not itself worth a re-roll).
rebase-interactive.c void append_todo_help(int command_count, · line 47
Quoted 9 lines
Signed-off-by Charvi Mendiratta <[email protected]>---
rebase-interactive.c +3
-1@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = 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"
This change jarringly introduces the first and only use of a period and capitalized word in the to-do help text. Perhaps instead say:
... like \"squash\", but discard this commit's log message; use -C to replace with this commit message or -c to edit the commit message
When -c says "edit the commit message" it's not clear what will be edited. The original's commit message? The replacement's message? A combination of the two? If you can come up with a succinct way to word it such that it states more precisely what exactly will be edited, it would be nice, but not necessarily worth a re-roll.
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1722
Quoted 7 lines
sequencer.c +5
-0@@ -1718,6 +1718,12 @@ static int is_pick_or_similar(enum todo_command command) +enum todo_item_flags { +TODO_EDIT_MERGE_MSG = (1 <<0 ), +TODO_REPLACE_FIXUP_MSG = (1 <<1 ), +TODO_EDIT_FIXUP_MSG = (1 <<2 ), +};
I'm confused. These enumeration items are defined as bit flags, implying that they may be combined, however...
sequencer.c static size_t subject_length(const char *body) · line 1741
Quoted 3 lines
sequencer.c +2
-0@@ -1734,32 +1740,176 @@ static size_t subject_length(const char *body) +static int check_fixup_flag (enum todo_command command, +enum todo_item_flags flag)
...here and elsewhere, you declare the argument as a strict todo_item_flags enum item rather than unsigned which is the typical declaration when combining bit flag values. So, the picture thus far is confusing. Are the todo_item_flags values distinct unique values which will never be combined, or are they meant to be combined?
sequencer.c static size_t subject_length(const char *body) · line 1752
Quoted 4 lines
sequencer.c +4
-0+{ +return command ==TODO_FIXUP && ((flag &TODO_REPLACE_FIXUP_MSG ) || + (flag &TODO_EDIT_FIXUP_MSG )); +}
This code adds to the confusion. In the function argument list, flag has been declared as a single enum item, yet this code is treating flag as if it is a combination of bits. So, it's not clear what the intention is here. Is flag always going to be a specific enum item in this context or is it going to be a combination of bits? If it is only ever going to be a distinct enum item, then one would expect this code to be written like this:
return command == TODO_FIXUP &&
(flag == TODO_REPLACE_FIXUP_MSG ||
flag == TODO_EDIT_FIXUP_MSG);Otherwise, if flag will actually be a bag of bits, then the argument should be declared as such:
static int check_fixup_flag(enum todo_command command,
unsigned flag)
By the way, the function name check_fixup_flag() doesn't necessarily do a good job conveying the purpose of this function. Based upon the implementation, I gather that it is checking whether the command is a "fixup" command, so perhaps the name could reflect that. Perhaps is_fixup() or something?
sequencer.c static size_t subject_length(const char *body) · line 1865
Quoted 13 lines
sequencer.c +12
-0+static int append_squash_message (struct strbuf *buf,const char *body, +enum todo_command command,struct replay_opts *opts, +enum todo_item_flags flag) +{ +/* +* amend is non-interactive and not normally used with fixup! +* or squash! commits, so only comment out those subjects when +* squashing commit messages. +*/ +if (starts_with (body,"amend!" ) || + ((command ==TODO_SQUASH ||seen_squash (opts)) && + (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )))) commented_len =subject_length (body);
I understand from the cover letter that "amend!" is being added by this series, however, no patch up to this point, nor this patch itself, adds "amend!" functionality, so it's surprising to see it being tested here. As a reader, I would expect code/comments related to "amend!" to be added in the patch which actually introduces "amend!" rather than doing it here.
sequencer.c static size_t subject_length(const char *body) · line 1889
Quoted 9 lines
sequencer.c +9
-0+/* fixup -C after squash behaves like squash */ +if (check_fixup_flag (command, flag) && !seen_squash (opts)) { +if (opts->signoff) +append_signoff (buf,0 ,0 ); + +if ((command ==TODO_FIXUP ) && + (flag &TODO_REPLACE_FIXUP_MSG ) && + (file_exists (rebase_path_fixup_msg ()) || + !file_exists (rebase_path_squash_msg ()))) {
Is the expression command == TODO_FIXUP redundant here considering that the only way we got this far is if check_fixup_flag() returned true, in which case we know that command is TODO_FIXUP? Or am I missing something?
sequencer.c static int parse_insn_line(struct repository *r, struct todo_item *item, · line 2446
Quoted 12 lines
sequencer.c +11
-0@@ -2281,6 +2436,18 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, +if (item->command ==TODO_FIXUP ) { +if (skip_prefix (bol,"-C" , &bol) && + (*bol ==' ' || *bol =='\t' )) { + bol +=strspn (bol," \t" ); + item->flags |=TODO_REPLACE_FIXUP_MSG ; + }else if (skip_prefix (bol,"-c" , &bol) && + (*bol ==' ' || *bol =='\t' )) { + bol +=strspn (bol," \t" ); + item->flags |=TODO_EDIT_FIXUP_MSG ; + } + }
I was wondering if the above could be rephrased like this to avoid the repetition:
if (bol[0] == '-' && tolower(bol[1]) == 'c' &&
(bol[2] == ' ' || bol[2] == '\t') {
item->flags |= bol[1] == 'C' ?
TODO_REPLACE_FIXUP_MSG :
TODO_EDIT_FIXUP_MSG;
bol += 2 + strspn(bol + 2, " \t");
}but perhaps it's too magical and ugly.
Re: [PATCH v4 6/9] rebase -i: add fixup [-C | -c] command
Hi Eric,
Quoted 8 lines · Eric Sunshine
Quoted 3 lines · Charvi Mendiratta
Add options to
fixupcommand to fixup both the commit contents and message.fixup -Ccommand is used to replace the original commit message andfixup -c, additionally allows to edit the commit message.In the cover letter for this series, you had this additional information:
Quoted 8 lines
This convention is similar to the existing
mergecommand in the interactive rebase, that also supports-cand-Coptions with similar meanings.which helps to explain the choice of -c and -C. It might be nice to include that explanation in this commit message, as well (but not itself worth a re-roll).
Agree, I will include this in the commit message.
Quoted 13 lines
rebase-interactive.c void append_todo_help(int command_count, · line 47
Quoted 9 lines
Signed-off-by Charvi Mendiratta <[email protected]>---
rebase-interactive.c +3
-1@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = 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" This change jarringly introduces the first and only use of a period and capitalized word in the to-do help text. Perhaps instead say:
Quoted 4 lines
... like \"squash\", but discard this commit's log message; use -C to replace with this commit message or -c to edit the commit message
Okay, I will change it.
Quoted 6 lines
When
-csays "edit the commit message" it's not clear what will be edited. The original's commit message? The replacement's message? A combination of the two? If you can come up with a succinct way to word it such that it states more precisely what exactly will be edited, it would be nice, but not necessarily worth a re-roll.
Here the editor shows the commented out commit message of original commit and the replacement commit message (of fixup -c commit) is not commented out.
So maybe s/edit the commit message/edit this commit message is better.
Quoted 39 lines
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1722
Quoted 7 lines
sequencer.c +5
-0@@ -1718,6 +1718,12 @@ static int is_pick_or_similar(enum todo_command command) +enum todo_item_flags { +TODO_EDIT_MERGE_MSG = (1 <<0 ), +TODO_REPLACE_FIXUP_MSG = (1 <<1 ), +TODO_EDIT_FIXUP_MSG = (1 <<2 ), +};I'm confused. These enumeration items are defined as bit flags, implying that they may be combined, however...
sequencer.c static size_t subject_length(const char *body) · line 1741
Quoted 3 lines
sequencer.c +2
-0@@ -1734,32 +1740,176 @@ static size_t subject_length(const char *body) +static int check_fixup_flag (enum todo_command command, +enum todo_item_flags flag)...here and elsewhere, you declare the argument as a strict
todo_item_flagsenum item rather thanunsignedwhich is the typical declaration when combining bit flag values. So, the picture thus far is confusing. Are thetodo_item_flagsvalues distinct unique values which will never be combined, or are they meant to be combined?sequencer.c static size_t subject_length(const char *body) · line 1752
Quoted 4 lines
sequencer.c +4
-0+{ +return command ==TODO_FIXUP && ((flag &TODO_REPLACE_FIXUP_MSG ) || + (flag &TODO_EDIT_FIXUP_MSG )); +}This code adds to the confusion. In the function argument list,
flaghas been declared as a single enum item, yet this code is treatingflagas if it is a combination of bits. So, it's not clear what the intention is here. Isflagalways going to be a specific enum item in this context or is it going to be a combination of bits? If it is only ever going to be a distinct enum item, then one would expect this code to be written like this:return command == TODO_FIXUP && (flag == TODO_REPLACE_FIXUP_MSG || flag == TODO_EDIT_FIXUP_MSG);
Quoted 6 lines
Otherwise, if
flagwill actually be a bag of bits, then the argument should be declared as such:static int check_fixup_flag(enum
todo_commandcommand,
unsigned flag)
I admit it resulted in a bit of confusion. Here, its true that flag is always going to be specific enum item( as command can be merge -c, fixup -c, or fixup -C ) and I combined the bag of bits to denote
the specific enum item. So, maybe we can go with the first method?
Quoted 6 lines
By the way, the function name
check_fixup_flag()doesn't necessarily do a good job conveying the purpose of this function. Based upon the implementation, I gather that it is checking whether the command is a "fixup" command, so perhaps the name could reflect that. Perhapsis_fixup()or something?
Agree, here it's checking if the command is fixup and the flag value ( which implies either user has given command fixup -c or fixup -C ) So, I wonder if we can write is_fixup_flag() ?
Quoted 12 lines
Quoted 12 lines
sequencer.c +12
-0+static int append_squash_message (struct strbuf *buf,const char *body, +enum todo_command command,struct replay_opts *opts, +enum todo_item_flags flag) +{ +/* +* amend is non-interactive and not normally used with fixup! +* or squash! commits, so only comment out those subjects when +* squashing commit messages. +*/ +if (starts_with (body,"amend!" ) || + ((command ==TODO_SQUASH ||seen_squash (opts)) && + (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" ))))
Quoted 9 lines
sequencer.c static size_t subject_length(const char *body) · line 1865
Quoted 1 line
sequencer.c +0
-0commented_len =subject_length (body);I understand from the cover letter that "amend!" is being added by this series, however, no patch up to this point, nor this patch itself, adds "amend!" functionality, so it's surprising to see it being tested here. As a reader, I would expect code/comments related to "amend!" to be added in the patch which actually introduces "amend!" rather than doing it here.
This patch series does not include the implementation of amend! commit. I think to avoid the confusion I will remove this part from this patch series and add it in the next patch series for amend! commit.
Quoted 10 lines
sequencer.c static size_t subject_length(const char *body) · line 1889
Quoted 9 lines
sequencer.c +9
-0+/* fixup -C after squash behaves like squash */ +if (check_fixup_flag (command, flag) && !seen_squash (opts)) { +if (opts->signoff) +append_signoff (buf,0 ,0 ); + +if ((command ==TODO_FIXUP ) && + (flag &TODO_REPLACE_FIXUP_MSG ) && + (file_exists (rebase_path_fixup_msg ()) || + !file_exists (rebase_path_squash_msg ()))) {
Quoted 4 lines
Is the expression
command == TODO_FIXUPredundant here considering that the only way we got this far is ifcheck_fixup_flag()returned true, in which case we know that command isTODO_FIXUP? Or am I missing something?
Yes, it implies the same.
Quoted 25 lines
sequencer.c static int parse_insn_line(struct repository *r, struct todo_item *item, · line 2446
Quoted 13 lines
sequencer.c +11
-0@@ -2281,6 +2436,18 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, +if (item->command ==TODO_FIXUP ) { +if (skip_prefix (bol,"-C" , &bol) && + (*bol ==' ' || *bol =='\t' )) { + bol +=strspn (bol," \t" ); + item->flags |=TODO_REPLACE_FIXUP_MSG ; + }else if (skip_prefix (bol,"-c" , &bol) && + (*bol ==' ' || *bol =='\t' )) { + bol +=strspn (bol," \t" ); + item->flags |=TODO_EDIT_FIXUP_MSG ; + } + }I was wondering if the above could be rephrased like this to avoid the repetition:
if (bol[0] == '-' && tolower(bol[1]) == 'c' && (bol[2] == ' ' || bol[2] == '\t') { item->flags |= bol[1] == 'C' ? TODO_REPLACE_FIXUP_MSG : TODO_EDIT_FIXUP_MSG; bol += 2 + strspn(bol + 2, " \t"); }
Quoted 1 line
but perhaps it's too magical and ugly.
I agree, this [tolower(bol[1]) == 'c'] is actually doing all the magic, but I am not
sure if we should change it or not ? As in the source code just after this code we
are checking in a similar way for the 'merge' command. So, maybe implementing in a similar way is easier to read ?
Thanks and Regards,
Charvi
Re: [PATCH v4 6/9] rebase -i: add fixup [-C | -c] command
Quoted 11 lines · Charvi Mendiratta
Quoted 5 lines · Eric Sunshine
When
-csays "edit the commit message" it's not clear what will be edited. The original's commit message? The replacement's message? A combination of the two? If you can come up with a succinct way to word it such that it states more precisely what exactly will be edited, it would be nice, but not necessarily worth a re-roll.Here the editor shows the commented out commit message of original commit and the replacement commit message (of fixup -c commit) is not commented out.
So maybe s/edit the commit message/edit this commit message is better.
Yes, that would be clearer and is just as succinct.
Quoted 8 lines
Quoted 8 lines
This code adds to the confusion. In the function argument list,
flaghas been declared as a single enum item, yet this code is treatingflagas if it is a combination of bits. So, it's not clear what the intention is here. Isflagalways going to be a specific enum item in this context or is it going to be a combination of bits? If it is only ever going to be a distinct enum item, then one would expect this code to be written like this:
Quoted 8 lines
Quoted 3 lines
return command == TODO_FIXUP && (flag == TODO_REPLACE_FIXUP_MSG || flag == TODO_EDIT_FIXUP_MSG);I admit it resulted in a bit of confusion. Here, its true that flag is always going to be specific enum
item( as command can be merge -c, fixup -c, or fixup -C )and I combined the bag of bits to denote
the specific enum item. So, maybe we can go with the first method?
Sounds fine. It would clarify the intent.
Quoted 9 lines
Quoted 5 lines
By the way, the function name
check_fixup_flag()doesn't necessarily do a good job conveying the purpose of this function. Based upon the implementation, I gather that it is checking whether the command is a "fixup" command, so perhaps the name could reflect that. Perhapsis_fixup()or something?Agree, here it's checking if the command is fixup and the flag value ( which implies either user has given command fixup -c or fixup -C ) So, I wonder if we can write
is_fixup_flag()?
Reasonable.
Quoted 11 lines
Quoted 4 lines
I was wondering if the above could be rephrased like this to avoid the repetition:
[...]
but perhaps it's too magical and ugly.I agree, this [
tolower(bol[1])== 'c'] is actually doing all the magic, but I am not
sure if we should change it or not ? As in the source code just after this code we
are checking in a similar way for the 'merge' command. So, maybe implementing in a similar way is easier to read ?
Keeping it similar to nearby code makes sense.
Re: [PATCH v4 6/9] rebase -i: add fixup [-C | -c] command
Quoted 11 lines · Eric Sunshine
Quoted 8 lines
Quoted 3 lines
return command == TODO_FIXUP && (flag == TODO_REPLACE_FIXUP_MSG || flag == TODO_EDIT_FIXUP_MSG);I admit it resulted in a bit of confusion. Here, its true that flag is always going to be specific enum
item( as command can be merge -c, fixup -c, or fixup -C )and I combined the bag of bits to denote
the specific enum item. So, maybe we can go with the first method?Sounds fine. It would clarify the intent.
(Apology for confusion) After, looking again at the source code, as we are using the flag element of the structure todo_item of in sequencer.h. So, I think right
way is to let it be in binary only and change type from 'enum todo_item_flag' to 'unsigned' , as you suggested below (better than first method) :
Otherwise, if flag will actually be a bag of bits, then the argument should be declared as such:
static int check_fixup_flag(enum todo_command command,
unsigned flag)
Quoted 6 lines
Quoted 3 lines
Agree, here it's checking if the command is fixup and the flag value ( which implies either user has given command fixup -c or fixup -C ) So, I wonder if we can write
is_fixup_flag()?Reasonable.
[...]
Quoted 8 lines
Quoted 6 lines
I agree, this [
tolower(bol[1])== 'c'] is actually doing all the magic, but I am not
sure if we should change it or not ? As in the source code just after this code we
are checking in a similar way for the 'merge' command. So, maybe implementing in a similar way is easier to read ?Keeping it similar to nearby code makes sense.
Thanks for confirming!
Thanks and Regards,
Charvi
Re: [PATCH v4 6/9] rebase -i: add fixup [-C | -c] command
Quoted 5 lines · Charvi Mendiratta
Quoted 5 lines
Quoted 4 lines
I admit it resulted in a bit of confusion. Here, its true that flag is always going to be specific enum
item( as command can be merge -c, fixup -c, or fixup -C )and I combined the bag of bits to denote
the specific enum item. So, maybe we can go with the first method?
Quoted 7 lines
Quoted 1 line
Sounds fine. It would clarify the intent.
(Apology for confusion) After, looking again at the source code, as we are using the flag element of the structure
todo_itemof insequencer.h. So, I think right
way is to let it be in binary only and change type from 'enumtodo_item_flag' to 'unsigned' , as you suggested below (better than first method) :
That would be fine, as well. Thanks.
PATCH v4 7/9 t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Charvi Mendiratta--- t/lib-rebase.sh | 4 + t/t3437-rebase-fixup-options.sh | 213 ++++++++++++++++++++++++++++++ t/t3437/expected-combined-message | 21 +++ t/t3437/expected-squash-message | 51 +++++++ 4 files changed, 289 insertions(+) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message create mode 100644 t/t3437/expected-squash-message
t/lib-rebase.sh +4 -0
@@ -4,6 +4,7 @@ # # - override the commit message with $FAKE_COMMIT_MESSAGE # - amend the commit message with $FAKE_COMMIT_AMEND +# - copy the original commit message to a file with $FAKE_MESSAGE_COPY # - check that non-commit messages have a certain line count with $EXPECT_COUNT # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT # - rewrite a rebase -i script as directed by $FAKE_LINES.
@@ -33,6 +34,7 @@ set_fake_editor () { exit test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" exit ;; esac
@@ -51,6 +53,8 @@ set_fake_editor () { action="$line";; exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');; "#") echo '# comment' >> "$1";; ">")
t/t3437-rebase-fixup-options.sh new file +213 -0
213 lines not on this page · raw message
t/t3437/expected-combined-message new file +21 -0
@@ -0,0 +1,21 @@ +# This is a combination of 4 commits. +# This is the 1st commit message: + +B + +# This is the commit message #2: + +# amend! B + +new subject + +new +body + +# The commit message #3 will be skipped: + +# A2 + +# This is the commit message #4: + +A3
t/t3437/expected-squash-message new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
t/lib-rebase.sh set_fake_editor () { · line 56
Quoted 9 lines · Charvi Mendiratta
Mentored-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>---
t/lib-rebase.sh +2
-0@@ -51,6 +53,8 @@ set_fake_editor () { exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');;
What is "merge_" doing here? It doesn't seem to be used by this patch.
The function comment above this code may also need to be updated to reflect this change.
t/t3437-rebase-fixup-options.sh line 3
Quoted 5 lines
t/t3437-rebase-fixup-options.sh +3
-0@@ -0,0 +1,213 @@ +#!/bin/sh +# +# Copyright (c) 2018 Phillip Wood
Did Phillip write this script? Is this patch based upon an old patch from him?
t/t3437-rebase-fixup-options.sh line 32
Quoted 12 lines
t/t3437-rebase-fixup-options.sh +12
-0+test_commit_message () { + rev="$1" && # commit or tag we want to test + file="$2" && # test against the content of a file + git show --no-patch --pretty=format:%B "$rev" >actual-message && + if test "$2" = -m + then + str="$3" && # test against a string + printf "%s\n" "$str" >tmp-expected-message && + file="tmp-expected-message" + fi + test_cmp "$file" actual-message +}
By embedding comments in the function itself explaining $1, $2, and $3, anyone who adds tests to this script in the future is forced to read the function implementation to understand how to call it. Adding function documentation can remove that burden. For instance:
# test_commit_message <rev> -m <msg>
# test_commit_message <rev> <path>
# Verify that the commit message of <rev> matches
# <msg> or the content of <path>.
test_commit_message () {
...
}The implementation of test_commit_message() is a bit hard to follow. It might be simpler to write it more concisely and directly like this:
git show --no-patch --pretty=format:%B "$1" >actual &&
case "$2" in
-m) echo "$3" >expect && test_cmp expect actual ;;
*) test_cmp "$2" actual ;;
esact/t3437-rebase-fixup-options.sh line 47
Quoted 9 lines
t/t3437-rebase-fixup-options.sh +9
-0+test_expect_success 'setup' ' + cat >message <<-EOF && + amend! B + ${EMPTY} + new subject + ${EMPTY} + new + body + EOF
Style nit: In Git test scripts, the here-doc body and EOF are indented the same amount as the command which opened the here-doc:
cat >message <<-EOF &&
amend! B
...
body
EOFAlso, $EMPTY is perfectly fine; no need to write it as ${EMPTY}.
t/t3437-rebase-fixup-options.sh line 62
Quoted 9 lines
t/t3437-rebase-fixup-options.sh +9
-0+ ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" && + ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" && + GIT_AUTHOR_NAME="Amend Author" && + GIT_AUTHOR_EMAIL="[email protected]" && + test_commit "$(cat message)" A A1 A1 && + test_commit A2 A && + test_commit A3 A && + GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" && + GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
Are the timestamps of these commits meaningful in this context? If not, another way to do this would be to assign the new author name/email values in a subshell so that the values do not need to be restored manually. For instance:
(
GIT_AUTHOR_NAME="Amend Author" &&
GIT_AUTHOR_EMAIL="[email protected]" &&
test_commit "$(cat message)" A A1 A1 &&
test_commit A2 A &&
test_commit A3 A
) &&It's a matter of taste whether or not that is preferable, though.
t/t3437-rebase-fixup-options.sh line 71
Quoted 4 lines
t/t3437-rebase-fixup-options.sh +4
-0+ echo B1 >B && + test_tick && + git commit --fixup=HEAD -a && + test_tick &&
Same question about whether the commit timestamps have any significance in these tests. If not, then these test_tick() calls mislead the reader into thinking that the timestamps are significant, thus it would make sense to drop them.
t/t3437-rebase-fixup-options.sh line 115
Quoted 4 lines
t/t3437-rebase-fixup-options.sh +4
-0+test_expect_success 'simple fixup -C works' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A2 && + FAKE_LINES="1 fixup_-C 2" git rebase -i B &&
I see that you mirrored the implementation of FAKE_LINES handling of "exec" here for "fixup", but the cases are quite different. The argument to "exec" is arbitrary and can have any number of spaces embedded in it, which conflicts with the meaning of spaces in FAKE_LINES, which separate the individual commands in FAKE_LINES. Consequently, "_" was chosen as a placeholder in "exec" to mean "space".
However, "fixup" is a very different beast. Its arguments are not arbitrary at all, so there isn't a good reason to mirror the choice of "_" to represent a space, which leads to rather unsightly tokens such as "fixup_-C". It would work just as well to use simpler tokens such as "fixup-C" and "fixup-c", in which case t/lib-rebase.sh might parse them like this (note that I also dropped g from the sed action):
fixup-*)
action=$(echo "$line" | sed 's/-/ -/');;In fact, the recognized set of options following "fixup" is so small, that you could even get by with simpler tokens "fixupC" and "fixupc":
fixupC)
action="fixup -C";;
fixupc)
actions="fixup -c";;Though it's subjective whether or not "fixupC" and "fixupc" are nicer than "fixup-C" and "fixup-c", respectively.
t/t3437-rebase-fixup-options.sh line 143
Quoted 10 lines
t/t3437-rebase-fixup-options.sh +10
-0+test_expect_success 'fixup -C removes amend! from message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A1 && + FAKE_LINES="1 fixup_-C 2" git rebase -i A && + test_cmp_rev HEAD^ A && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_commit_message HEAD expected-message && + get_author HEAD >actual-author && + test_cmp expected-author actual-author +'
This test seems out of place. I would expect to see it added in the patch which adds "amend!" functionality.
Alternatively, if the intention really is to support "amend!" this early in the series in [6/9], then the commit message of [6/9] should talk about it.
t/t3437-rebase-fixup-options.sh line 53
Quoted 2 lines
t/t3437-rebase-fixup-options.sh +2
-0+test_expect_success 'fixup -C with conflicts gives correct message' ' + test_when_finished "test_might_fail git rebase --abort" &&
Is there a reason this isn't written as:
test_when_finished "reset_rebase" &&
which is more common? Is there something non-obvious which makes reset_rebase() inappropriate in these tests?
t/t3437-rebase-fixup-options.sh line 154
Quoted 8 lines
t/t3437-rebase-fixup-options.sh +8
-0+ git checkout --detach A1 && + test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts && + git checkout --theirs -- A && + git add A && + FAKE_COMMIT_AMEND=edited git rebase --continue && + test_cmp_rev HEAD^ conflicts && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_write_lines "" edited >>expected-message &&
It feels clunky and fragile for this test to be changing "expected-message" which was created in the "setup" test and used unaltered up to this point. If the content of "expected-message" is really going to change from test to test (as I see it changes again in a later test), then it would be easier to reason about the behavior if each test gives "expected-message" the precise content it should have in that local context. As it is currently implemented, it's too difficult to follow along and remember the value of "expected-message" from test to test. It also makes it difficult to extend tests or add new tests in between existing tests without negatively impacting other tests. If each test sets up "expected-message" to the precise content needed by the test, then both those problems go away.
t/t3437-rebase-fixup-options.sh line 200
Quoted 11 lines
t/t3437-rebase-fixup-options.sh +11
-0+test_expect_success 'multiple fixup -c opens editor once' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A3 && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_MESSAGE="Modified-A3" \ + FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test_cmp_rev $base HEAD^ && + test 1 = $(git show | grep Modified-A3 | wc -l) +'
These days, we would phrase the last part of the test as:
git show > raw &&
grep Modified-A3 raw >out &&
test_line_count = 1 outRe: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
Quoted 13 lines · Eric Sunshine
t/lib-rebase.sh set_fake_editor () { · line 56
Quoted 9 lines · Charvi Mendiratta
Mentored-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>---
t/lib-rebase.sh +2
-0@@ -51,6 +53,8 @@ set_fake_editor () { exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');;What is "
merge_" doing here? It doesn't seem to be used by this patch.
Yeah, it's not used, but it might be a good thing to add this for consistency while at it.
Quoted 2 lines
The function comment above this code may also need to be updated to reflect this change.
Yeah, good suggestion.
Quoted 7 lines
t/t3437-rebase-fixup-options.sh line 3
Quoted 5 lines
t/t3437-rebase-fixup-options.sh +3
-0@@ -0,0 +1,213 @@ +#!/bin/sh +# +# Copyright (c) 2018 Phillip WoodDid Phillip write this script? Is this patch based upon an old patch from him?
Yeah, it might be a good idea to add a "Based-on-patch-by: Phillip ..."
Quoted 18 lines
t/t3437-rebase-fixup-options.sh line 32
Quoted 12 lines
t/t3437-rebase-fixup-options.sh +12
-0+test_commit_message () { + rev="$1" && # commit or tag we want to test + file="$2" && # test against the content of a file + git show --no-patch --pretty=format:%B "$rev" >actual-message && + if test "$2" = -m + then + str="$3" && # test against a string + printf "%s\n" "$str" >tmp-expected-message && + file="tmp-expected-message" + fi + test_cmp "$file" actual-message +}By embedding comments in the function itself explaining $1, $2, and $3, anyone who adds tests to this script in the future is forced to read the function implementation to understand how to call it. Adding function documentation can remove that burden. For instance:
Quoted 7 lines
# test_commit_message <rev> -m <msg>
# test_commit_message <rev> <path>
# Verify that the commit message of <rev> matches
# <msg> or the content of <path>.
test_commit_message () {
...
}Good suggestion.
Quoted 6 lines
The implementation of
test_commit_message()is a bit hard to follow. It might be simpler to write it more concisely and directly like this:git show --no-patch --pretty=format:%B "$1" >actual && case "$2" in -m) echo "$3" >expect && test_cmp expect actual ;;
I think we try to avoid many commands on the same line.
Quoted 2 lines
*) test_cmp "$2" actual ;;
esacIn general I am not sure that using $1, $2, $3 directly makes things easier to understand, but yeah, with the function documentation that you suggest, it might be better to write the function using them directly.
Quoted 10 lines
t/t3437-rebase-fixup-options.sh line 47
Quoted 9 lines
t/t3437-rebase-fixup-options.sh +9
-0+test_expect_success 'setup' ' + cat >message <<-EOF && + amend! B + ${EMPTY} + new subject + ${EMPTY} + new + body + EOF
Quoted 2 lines
Style nit: In Git test scripts, the here-doc body and EOF are indented the same amount as the command which opened the here-doc:
I don't think we are very consistent with this and I didn't find anything about this in CodingGuidelines.
In t0008 and t0021 for example, the indentation is more like:
cat >message <<-EOF &&
amend! B
...
body
EOFand I like this style, as it seems clearer than the other styles.
[...]
Quoted 20 lines
t/t3437-rebase-fixup-options.sh line 115
Quoted 4 lines
t/t3437-rebase-fixup-options.sh +4
-0+test_expect_success 'simple fixup -C works' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A2 && + FAKE_LINES="1 fixup_-C 2" git rebase -i B &&I see that you mirrored the implementation of
FAKE_LINEShandling of "exec" here for "fixup", but the cases are quite different. The argument to "exec" is arbitrary and can have any number of spaces embedded in it, which conflicts with the meaning of spaces inFAKE_LINES, which separate the individual commands inFAKE_LINES. Consequently, "_" was chosen as a placeholder in "exec" to mean "space".However, "fixup" is a very different beast. Its arguments are not arbitrary at all, so there isn't a good reason to mirror the choice of "_" to represent a space, which leads to rather unsightly tokens such as "fixup_-C". It would work just as well to use simpler tokens such as "fixup-C" and "fixup-c", in which case
t/lib-rebase.shmight parse them like this (note that I also droppedgfrom thesedaction):
Quoted 2 lines
fixup-*)
action=$(echo "$line" | sed 's/-/ -/');;I agree that "fixup" arguments are not arbitrary at all, but I think it makes things simpler to just use one way to encode spaces instead of many different ways.
Quoted 10 lines
In fact, the recognized set of options following "fixup" is so small, that you could even get by with simpler tokens "fixupC" and "fixupc":
fixupC) action="fixup -C";; fixupc) actions="fixup -c";;Though it's subjective whether or not "fixupC" and "fixupc" are nicer than "fixup-C" and "fixup-c", respectively.
I don't think this would scale nicely when the number of options grows for both "fixup" and "merge".
Quoted 11 lines
t/t3437-rebase-fixup-options.sh line 143
Quoted 10 lines
t/t3437-rebase-fixup-options.sh +10
-0+test_expect_success 'fixup -C removes amend! from message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A1 && + FAKE_LINES="1 fixup_-C 2" git rebase -i A && + test_cmp_rev HEAD^ A && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_commit_message HEAD expected-message && + get_author HEAD >actual-author && + test_cmp expected-author actual-author +'
Quoted 6 lines
This test seems out of place. I would expect to see it added in the patch which adds "amend!" functionality.
Alternatively, if the intention really is to support "amend!" this early in the series in [6/9], then the commit message of [6/9] should talk about it.
Yeah, I think it might be better to just remove everything related to "amend!" in this series and put it into the next one.
[...]
Quoted 9 lines
t/t3437-rebase-fixup-options.sh line 154
Quoted 8 lines
t/t3437-rebase-fixup-options.sh +8
-0+ git checkout --detach A1 && + test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts && + git checkout --theirs -- A && + git add A && + FAKE_COMMIT_AMEND=edited git rebase --continue && + test_cmp_rev HEAD^ conflicts && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_write_lines "" edited >>expected-message &&
Quoted 12 lines
It feels clunky and fragile for this test to be changing "expected-message" which was created in the "setup" test and used unaltered up to this point. If the content of "expected-message" is really going to change from test to test (as I see it changes again in a later test), then it would be easier to reason about the behavior if each test gives "expected-message" the precise content it should have in that local context. As it is currently implemented, it's too difficult to follow along and remember the value of "expected-message" from test to test. It also makes it difficult to extend tests or add new tests in between existing tests without negatively impacting other tests. If each test sets up "expected-message" to the precise content needed by the test, then both those problems go away.
Yeah, perhaps the global "expected-message" could be renamed for example "global-expected-message", and tests which need a specific one could prepare and use a custom "expected-message" (maybe named "custom-expected-message") without ever changing "global-expected-message".
Thanks for your review!
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
Hi,
On Tue, 2 Feb 2021 at 15:32, Christian Couder
<[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 2 lines
The function comment above this code may also need to be updated to reflect this change.
Yeah, good suggestion.
Okay, I will add that .
Quoted 10 lines
Quoted 7 lines
t/t3437-rebase-fixup-options.sh line 3
Quoted 5 lines
t/t3437-rebase-fixup-options.sh +3
-0@@ -0,0 +1,213 @@ +#!/bin/sh +# +# Copyright (c) 2018 Phillip WoodDid Phillip write this script? Is this patch based upon an old patch from him?
Yeah, it might be a good idea to add a "Based-on-patch-by: Phillip ..."
Oops, I forgot to add the trailer in this patch and will add it.
Quoted 26 lines
Quoted 18 lines
t/t3437-rebase-fixup-options.sh line 32
Quoted 12 lines
t/t3437-rebase-fixup-options.sh +12
-0+test_commit_message () { + rev="$1" && # commit or tag we want to test + file="$2" && # test against the content of a file + git show --no-patch --pretty=format:%B "$rev" >actual-message && + if test "$2" = -m + then + str="$3" && # test against a string + printf "%s\n" "$str" >tmp-expected-message && + file="tmp-expected-message" + fi + test_cmp "$file" actual-message +}By embedding comments in the function itself explaining $1, $2, and $3, anyone who adds tests to this script in the future is forced to read the function implementation to understand how to call it. Adding function documentation can remove that burden. For instance:
Quoted 7 lines
# test_commit_message <rev> -m <msg> # test_commit_message <rev> <path> # Verify that the commit message of <rev> matches # <msg> or the content of <path>. test_commit_message () { ... }
Quoted 2 lines
Good suggestion.
Agree, I will add the comments.
Quoted 9 lines
Quoted 6 lines
The implementation of
test_commit_message()is a bit hard to follow. It might be simpler to write it more concisely and directly like this:git show --no-patch --pretty=format:%B "$1" >actual && case "$2" in -m) echo "$3" >expect && test_cmp expect actual ;;I think we try to avoid many commands on the same line.
Quoted 8 lines
Quoted 2 lines
*) test_cmp "$2" actual ;; esacIn general I am not sure that using $1, $2, $3 directly makes things easier to understand, but yeah, with the function documentation that you suggest, it might be better to write the function using them directly.
Okay, I will update it.
[...]
Quoted 14 lines
Quoted 14 lines
t/t3437-rebase-fixup-options.sh line 143
Quoted 10 lines
t/t3437-rebase-fixup-options.sh +10
-0+test_expect_success 'fixup -C removes amend! from message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A1 && + FAKE_LINES="1 fixup_-C 2" git rebase -i A && + test_cmp_rev HEAD^ A && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_commit_message HEAD expected-message && + get_author HEAD >actual-author && + test_cmp expected-author actual-author +'This test seems out of place. I would expect to see it added in the patch which adds "amend!" functionality.
Quoted 7 lines
Quoted 3 lines
Alternatively, if the intention really is to support "amend!" this early in the series in [6/9], then the commit message of [6/9] should talk about it.
Yeah, I think it might be better to just remove everything related to "amend!" in this series and put it into the next one.
Agree. Eric pointed at other patches also for amend! commit.
So I also admit that to avoid confusion, I will remove all these amend! part and will add to other patch series.
Quoted 11 lines
[...]
Quoted 9 lines
Quoted 8 lines
t/t3437-rebase-fixup-options.sh +8
-0+ git checkout --detach A1 && + test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts && + git checkout --theirs -- A && + git add A && + FAKE_COMMIT_AMEND=edited git rebase --continue && + test_cmp_rev HEAD^ conflicts && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_write_lines "" edited >>expected-message &&
Quoted 13 lines
Quoted 4 lines
It feels clunky and fragile for this test to be changing "expected-message" which was created in the "setup" test and used unaltered up to this point. If the content of "expected-message" is really going to change from test to test (as I see it changes again in
Quoted 8 lines
a later test), then it would be easier to reason about the behavior if each test gives "expected-message" the precise content it should have in that local context. As it is currently implemented, it's too difficult to follow along and remember the value of "expected-message" from test to test. It also makes it difficult to extend tests or add new tests in between existing tests without negatively impacting other tests. If each test sets up "expected-message" to the precise content needed by the test, then both those problems go away.
I agree with it ...
Quoted 6 lines
Yeah, perhaps the global "expected-message" could be renamed for example "global-expected-message", and tests which need a specific one could prepare and use a custom "expected-message" (maybe named "custom-expected-message") without ever changing "global-expected-message".
... Okay, I will change it.
Thanks Eric and Christian for the suggestions and reviews. I will include all the changes
in the next revision.
Thanks and Regards,
Charvi
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Christian CouderQuoted 9 lines · Christian Couder
Quoted 5 lines · Eric Sunshine
t/lib-rebase.sh set_fake_editor () { · line 57
Quoted 2 lines · Charvi Mendiratta
t/lib-rebase.sh +2
-0+ merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');;What is "
merge_" doing here? It doesn't seem to be used by this patch.Yeah, it's not used, but it might be a good thing to add this for consistency while at it.
It confuses readers (as it did to me), causing them to waste brain-cycles trying to figure out why it's present. Thus, it would be better to add it when it's actually needed. The waste of brain-cycles and time is especially important on a project like Git for which reviewers and reviewer time are limited resources.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+# Copyright (c) 2018 Phillip Wood
Did Phillip write this script? Is this patch based upon an old patch from him?
Yeah, it might be a good idea to add a "Based-on-patch-by: Phillip ..."
Agreed.
Quoted 8 lines
Quoted 6 lines
The implementation of
test_commit_message()is a bit hard to follow. It might be simpler to write it more concisely and directly like this:git show --no-patch --pretty=format:%B "$1" >actual && case "$2" in -m) echo "$3" >expect && test_cmp expect actual ;;I think we try to avoid many commands on the same line.
For something this minor, it's not likely to matter but, of course, it could be split over two lines:
-m) echo "$3" >expect &&
test_cmp expect actual ;;Quoted 7 lines
Quoted 2 lines
*) test_cmp "$2" actual ;; esacIn general I am not sure that using $1, $2, $3 directly makes things easier to understand, but yeah, with the function documentation that you suggest, it might be better to write the function using them directly.
The direct $1, $2, etc. was just an example. It's certainly possible to give them names even in the rewritten code I presented. One good reason, however, for just using $1, $2, etc. is that $2 is not well defined; sometimes it's a switch ("-m") and sometimes its a pathname, so it's hard to invent a suitable variable name for it. Also, this function becomes so simple (in the rewritten version) that explicit variable names don't add a lot of value (the cognitive load is quite low because the function is so short).
Quoted 8 lines
Quoted 2 lines
Style nit: In Git test scripts, the here-doc body and EOF are indented the same amount as the command which opened the here-doc:
I don't think we are very consistent with this and I didn't find anything about this in CodingGuidelines.
In t0008 and t0021 for example, the indentation is more like:
Quoted 7 lines
cat >message <<-EOF && amend! B ... body EOFand I like this style, as it seems clearer than the other styles.
I performed a quick survey of the heredoc styles in the tests. Here are the results[1] of my analysis on the 'seen' branch:
total-heredocs=4128
same-indent=3053 (<<EOF & body & EOF share indent)
cat >expect <<-\EOF
body
EOFbody-eof-indented=24 (body & EOF indented)
cat >expect <<-\EOF
body
EOFbody-indented=735 (body indented; EOF not)
cat >expect <<-\EOF
body
EOFleft-margin=316 (<<EOF indented; body & EOF not)
cat >expect <<\EOF
body
EOF
So, the indentation recommended in my review -- with 3053 instances out of 4128 heredocs -- is by far the most prevalent in the project.
[1]: Note that there is a miniscule amount of inaccuracy in the numbers because there are a few cases in which heredocs contain other heredocs, and some scripts build heredocs piecemeal when constructing other scripts, and I didn't bother making my analysis script handle those few cases. The inaccuracy is tiny, thus not meaningful to the overall picture.
Quoted 15 lines
Quoted 15 lines
I see that you mirrored the implementation of
FAKE_LINEShandling of "exec" here for "fixup", but the cases are quite different. The argument to "exec" is arbitrary and can have any number of spaces embedded in it, which conflicts with the meaning of spaces inFAKE_LINES, which separate the individual commands inFAKE_LINES. Consequently, "_" was chosen as a placeholder in "exec" to mean "space".However, "fixup" is a very different beast. Its arguments are not arbitrary at all, so there isn't a good reason to mirror the choice of "_" to represent a space, which leads to rather unsightly tokens such as "fixup_-C". It would work just as well to use simpler tokens such as "fixup-C" and "fixup-c", in which case
t/lib-rebase.shmight parse them like this (note that I also droppedgfrom thesedaction):
Quoted 6 lines
Quoted 2 lines
fixup-*) action=$(echo "$line" | sed 's/-/ -/');;I agree that "fixup" arguments are not arbitrary at all, but I think it makes things simpler to just use one way to encode spaces instead of many different ways.
Is that the intention here, though? Is the idea that some day fixup will accept arbitrary arguments thus needs to encode spaces? If not, then mirroring the treatment given to exec confuses readers into thinking that it will/should accept arbitrary arguments. I brought this up in my review specifically because it was confusing to a person (me) new to this topic and reading the patches for the first time. The more specific and exact the code can be, the less likely it will confuse readers in the future.
Anyhow, it's a minor point, not worth expending a lot of time discussing.
Quoted 13 lines
Quoted 4 lines
It feels clunky and fragile for this test to be changing "expected-message" which was created in the "setup" test and used unaltered up to this point. If the content of "expected-message" is really going to change from test to test (as I see it changes again in
Quoted 8 lines
a later test), then it would be easier to reason about the behavior if each test gives "expected-message" the precise content it should have in that local context. As it is currently implemented, it's too difficult to follow along and remember the value of "expected-message" from test to test. It also makes it difficult to extend tests or add new tests in between existing tests without negatively impacting other tests. If each test sets up "expected-message" to the precise content needed by the test, then both those problems go away.
Quoted 5 lines
Yeah, perhaps the global "expected-message" could be renamed for example "global-expected-message", and tests which need a specific one could prepare and use a custom "expected-message" (maybe named "custom-expected-message") without ever changing "global-expected-message".
That would be fine, though I wondered while reviewing the patch if a global "expect-message" file was even needed since it didn't seem like very many tests used it (but I didn't spend a lot of time counting the exact number of tests due to the high cognitive load tracing how that file might mutate as it passed through each test).
Another really good reason for avoiding having later tests depend upon mutations from earlier tests, if possible, is that it makes it easier to run tests selectively with --run or GIT_SKIP_TESTS.
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
Quoted 11 lines · Eric Sunshine
Quoted 4 lines
Quoted 1 line
What is "
merge_" doing here? It doesn't seem to be used by this patch.Yeah, it's not used, but it might be a good thing to add this for consistency while at it.
It confuses readers (as it did to me), causing them to waste brain-cycles trying to figure out why it's present. Thus, it would be better to add it when it's actually needed. The waste of brain-cycles and time is especially important on a project like Git for which reviewers and reviewer time are limited resources.
Okay, I will remove "merge_" from this patch series and maybe later will make separate patch for it and also adding its tests and updating t3430-rebase-merges.sh
Quoted 31 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+# Copyright (c) 2018 Phillip Wood
Did Phillip write this script? Is this patch based upon an old patch from him?
Yeah, it might be a good idea to add a "Based-on-patch-by: Phillip ..."
Agreed.
Quoted 8 lines
Quoted 6 lines
The implementation of
test_commit_message()is a bit hard to follow. It might be simpler to write it more concisely and directly like this:git show --no-patch --pretty=format:%B "$1" >actual && case "$2" in -m) echo "$3" >expect && test_cmp expect actual ;;I think we try to avoid many commands on the same line.
For something this minor, it's not likely to matter but, of course, it could be split over two lines:
-m) echo "$3" >expect && test_cmp expect actual ;;Quoted 7 lines
Quoted 2 lines
*) test_cmp "$2" actual ;; esacIn general I am not sure that using $1, $2, $3 directly makes things easier to understand, but yeah, with the function documentation that you suggest, it might be better to write the function using them directly.
Quoted 9 lines
The direct $1, $2, etc. was just an example. It's certainly possible to give them names even in the rewritten code I presented. One good reason, however, for just using $1, $2, etc. is that $2 is not well defined; sometimes it's a switch ("-m") and sometimes its a pathname, so it's hard to invent a suitable variable name for it. Also, this function becomes so simple (in the rewritten version) that explicit variable names don't add a lot of value (the cognitive load is quite low because the function is so short).
Agree, and will update it.
Quoted 48 lines
Quoted 8 lines
Quoted 2 lines
Style nit: In Git test scripts, the here-doc body and EOF are indented the same amount as the command which opened the here-doc:
I don't think we are very consistent with this and I didn't find anything about this in CodingGuidelines.
In t0008 and t0021 for example, the indentation is more like:
Quoted 7 lines
cat >message <<-EOF && amend! B ... body EOFand I like this style, as it seems clearer than the other styles.
I performed a quick survey of the heredoc styles in the tests. Here are the results[1] of my analysis on the 'seen' branch:
total-heredocs=4128
same-indent=3053 (<<EOF & body & EOF share indent)
cat >expect <<-\EOF body EOFbody-eof-indented=24 (body & EOF indented)
cat >expect <<-\EOF body EOFbody-indented=735 (body indented; EOF not)
cat >expect <<-\EOF body EOFleft-margin=316 (<<EOF indented; body & EOF not)
cat >expect <<\EOF
body
EOFSo, the indentation recommended in my review -- with 3053 instances out of 4128 heredocs -- is by far the most prevalent in the project.
Quoted 7 lines
[1]: Note that there is a miniscule amount of inaccuracy in the numbers because there are a few cases in which heredocs contain other heredocs, and some scripts build heredocs piecemeal when constructing other scripts, and I didn't bother making my analysis script handle those few cases. The inaccuracy is tiny, thus not meaningful to the overall picture.
Okay, will update the indentation.
[...]
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
fixup-*) action=$(echo "$line" | sed 's/-/ -/');;I agree that "fixup" arguments are not arbitrary at all, but I think it makes things simpler to just use one way to encode spaces instead of many different ways.
Quoted 9 lines
Is that the intention here, though? Is the idea that some day
fixupwill accept arbitrary arguments thus needs to encode spaces? If not, then mirroring the treatment given toexecconfuses readers into thinking that it will/should accept arbitrary arguments. I brought this up in my review specifically because it was confusing to a person (me) new to this topic and reading the patches for the first time. The more specific and exact the code can be, the less likely it will confuse readers in the future.
I also agree that fixup will not accept arbitrary arguments, So I think to go with the method using fixup-*) (as suggested above).
[...]
Quoted 12 lines
Quoted 5 lines
Yeah, perhaps the global "expected-message" could be renamed for example "global-expected-message", and tests which need a specific one could prepare and use a custom "expected-message" (maybe named "custom-expected-message") without ever changing "global-expected-message".
That would be fine, though I wondered while reviewing the patch if a global "expect-message" file was even needed since it didn't seem like very many tests used it (but I didn't spend a lot of time counting the exact number of tests due to the high cognitive load tracing how that file might mutate as it passed through each test).
Quoted 3 lines
Another really good reason for avoiding having later tests depend upon mutations from earlier tests, if possible, is that it makes it easier to run tests selectively with --run or
GIT_SKIP_TESTS.
Agree, also for this patch series I think to remove all tests for amend!, change the
test setup and will take care this time to remove the test dependency (in case of expected-message).
Thanks and Regards,
Charvi
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Eric SunshineHi Eric
Thanks for taking such a close look at this series.
Quoted 12 lines · Eric Sunshine
On Fri, Jan 29, 2021 at 1:25 PM Charvi Mendiratta <[email protected]> wrote:
[...]t/t3437-rebase-fixup-options.sh line 62
Quoted 9 lines
t/t3437-rebase-fixup-options.sh new file +9
-0+ ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" && + ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" && + GIT_AUTHOR_NAME="Amend Author" && + GIT_AUTHOR_EMAIL="[email protected]" && + test_commit "$(cat message)" A A1 A1 && + test_commit A2 A && + test_commit A3 A && + GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" && + GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
Quoted 1 line
Are the timestamps of these commits meaningful in this context?
I think we want to ensure that the timestamp of the commits created with the different author are different from the previous commits. We ought to be checking that the author date of the rebased commit matches the author date of the original commit and not the author date of the fixup commit created with the different author.
Quoted 14 lines
If not, another way to do this would be to assign the new author name/email values in a subshell so that the values do not need to be restored manually. For instance:
( GIT_AUTHOR_NAME="Amend Author" && GIT_AUTHOR_EMAIL="[email protected]" && test_commit "$(cat message)" A A1 A1 && test_commit A2 A && test_commit A3 A ) &&It's a matter of taste whether or not that is preferable, though.
Quoted 7 lines
t/t3437-rebase-fixup-options.sh line 71
Quoted 4 lines
t/t3437-rebase-fixup-options.sh new file +4
-0+ echo B1 >B && + test_tick && + git commit --fixup=HEAD -a && + test_tick &&Same question about whether the commit timestamps have any significance in these tests.
Same answer as above - we want different author dates so we can check the original author date is not modified.
I'm not sure that we are actually checking the dates yet though it looks like we only check the author name and email at the moment.
Best Wishes
Phillip
Quoted 106 lines
If not, then these
test_tick()calls
mislead the reader into thinking that the timestamps are significant, thus it would make sense to drop them.t/t3437-rebase-fixup-options.sh line 115
Quoted 4 lines
t/t3437-rebase-fixup-options.sh new file +4
-0+test_expect_success 'simple fixup -C works' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A2 && + FAKE_LINES="1 fixup_-C 2" git rebase -i B &&I see that you mirrored the implementation of
FAKE_LINEShandling of "exec" here for "fixup", but the cases are quite different. The argument to "exec" is arbitrary and can have any number of spaces embedded in it, which conflicts with the meaning of spaces inFAKE_LINES, which separate the individual commands inFAKE_LINES. Consequently, "_" was chosen as a placeholder in "exec" to mean "space".However, "fixup" is a very different beast. Its arguments are not arbitrary at all, so there isn't a good reason to mirror the choice of "_" to represent a space, which leads to rather unsightly tokens such as "fixup_-C". It would work just as well to use simpler tokens such as "fixup-C" and "fixup-c", in which case
t/lib-rebase.shmight parse them like this (note that I also droppedgfrom thesedaction):fixup-*) action=$(echo "$line" | sed 's/-/ -/');;In fact, the recognized set of options following "fixup" is so small, that you could even get by with simpler tokens "fixupC" and "fixupc":
fixupC) action="fixup -C";; fixupc) actions="fixup -c";;Though it's subjective whether or not "fixupC" and "fixupc" are nicer than "fixup-C" and "fixup-c", respectively.
t/t3437-rebase-fixup-options.sh line 143
Quoted 10 lines
t/t3437-rebase-fixup-options.sh new file +10
-0+test_expect_success 'fixup -C removes amend! from message' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A1 && + FAKE_LINES="1 fixup_-C 2" git rebase -i A && + test_cmp_rev HEAD^ A && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_commit_message HEAD expected-message && + get_author HEAD >actual-author && + test_cmp expected-author actual-author +'This test seems out of place. I would expect to see it added in the patch which adds "amend!" functionality.
Alternatively, if the intention really is to support "amend!" this early in the series in [6/9], then the commit message of [6/9] should talk about it.
Review
Quoted 2 lines
(quoted diff) +2
-0+test_expect_success 'fixup -C with conflicts gives correct message' ' + test_when_finished "test_might_fail git rebase --abort" &&Is there a reason this isn't written as:
test_when_finished "reset_rebase" &&which is more common? Is there something non-obvious which makes
reset_rebase()inappropriate in these tests?t/t3437-rebase-fixup-options.sh line 154
Quoted 8 lines
t/t3437-rebase-fixup-options.sh new file +8
-0+ git checkout --detach A1 && + test_must_fail env FAKE_LINES="1 fixup_-C 2" git rebase -i conflicts && + git checkout --theirs -- A && + git add A && + FAKE_COMMIT_AMEND=edited git rebase --continue && + test_cmp_rev HEAD^ conflicts && + test_cmp_rev HEAD^{tree} A1^{tree} && + test_write_lines "" edited >>expected-message &&It feels clunky and fragile for this test to be changing "expected-message" which was created in the "setup" test and used unaltered up to this point. If the content of "expected-message" is really going to change from test to test (as I see it changes again in a later test), then it would be easier to reason about the behavior if each test gives "expected-message" the precise content it should have in that local context. As it is currently implemented, it's too difficult to follow along and remember the value of "expected-message" from test to test. It also makes it difficult to extend tests or add new tests in between existing tests without negatively impacting other tests. If each test sets up "expected-message" to the precise content needed by the test, then both those problems go away.
t/t3437-rebase-fixup-options.sh line 200
Quoted 11 lines
t/t3437-rebase-fixup-options.sh new file +11
-0+test_expect_success 'multiple fixup -c opens editor once' ' + test_when_finished "test_might_fail git rebase --abort" && + git checkout --detach A3 && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_MESSAGE="Modified-A3" \ + FAKE_LINES="1 fixup_-C 2 fixup_-c 3 fixup_-c 4" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test_cmp_rev $base HEAD^ && + test 1 = $(git show | grep Modified-A3 | wc -l) +'These days, we would phrase the last part of the test as:
git show > raw && grep Modified-A3 raw >out && test_line_count = 1 out
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
Quoted 8 lines · Phillip Wood
Quoted 1 line · Eric Sunshine
Are the timestamps of these commits meaningful in this context?
I think we want to ensure that the timestamp of the commits created with the different author are different from the previous commits. We ought to be checking that the author date of the rebased commit matches the author date of the original commit and not the author date of the fixup commit created with the different author.
Such date-checking would indeed make sense and would remove any potential confusion a reader might have concerning the manual test_tick() calls. (It's not super important, but I still lean toward dropping the test_tick() calls until they are actually needed simply to avoid confusing readers. I asked about it in my review since their purpose was unclear and I was genuinely wondering if I was overlooking the reason for their presence. Future readers of the code may experience the same puzzlement without necessarily having ready access to the original author of the code from whom to receive an answer.)
Re: [PATCH v4 7/9] t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Eric SunshineHi Eric,
Quoted 10 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+test_expect_success 'fixup -C with conflicts gives correct message' ' + test_when_finished "test_might_fail git rebase --abort" &&Is there a reason this isn't written as:
test_when_finished "reset_rebase" &&which is more common? Is there something non-obvious which makes
reset_rebase()inappropriate in these tests?
I missed this earlier, but I confirmed before sending next version that as reset_rebase() removes the untracked files so we could not use this as otherwise it removes the fake-editor.sh file and will be required to set a fake editor for every
test and also removes other untracked files which may be used to debug. So, I think it's okay with:test_when_finished "test_might_fail git rebase --abort"
Thanks and regards,
Charvi
PATCH v4 8/9 rebase -i: teach --autosquash to work with amend!
In reply to Charvi MendirattaIf the commit subject starts with "amend!" then rearrange it like a "fixup!" commit and replace pick command with fixup -C command, which is used to fixup up the content if any and replaces the original commit message with amend! commit's message.
--- sequencer.c | 23 ++++++++++++++++------- t/t3437-rebase-fixup-options.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-)
sequencer.c +16 -7
@@ -5662,6 +5662,12 @@ 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) { +return skip_prefix (subject,"fixup! " , p) || +skip_prefix (subject,"amend! " , p) || +skip_prefix (subject,"squash! " , p); +} +/* * Rearrange the todo list that has both "pick commit-id msg" and "pick * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -5720,15 +5726,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_prefix (subject,"fixup! " , &p) || -skip_prefix (subject,"squash! " , &p))) { +if (skip_fixup_amend_squash (subject, &p)) {struct commit *commit2;for (;;) {while (isspace (*p)) p++; -if (!skip_prefix (p,"fixup! " , &p) && - !skip_prefix (p,"squash! " , &p)) +if (!skip_fixup_amend_squash (p, &p))break ; }
@@ -5758,9 +5762,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) }if (i2 >=0 ) { rearranged =1 ; - todo_list->items[i].command = -starts_with (subject,"fixup!" ) ? -TODO_FIXUP :TODO_SQUASH ; +if (starts_with (subject,"fixup!" )) { + todo_list->items[i].command =TODO_FIXUP ; + }else if (starts_with (subject,"amend!" )) { + todo_list->items[i].command =TODO_FIXUP ; + todo_list->items[i].flags =TODO_REPLACE_FIXUP_MSG ; + }else { + todo_list->items[i].command =TODO_SQUASH ; + }if (tail[i2] <0 ) { next[i] = next[i2]; next[i2] = i;
t/t3437-rebase-fixup-options.sh +12 -0
@@ -210,4 +210,16 @@ test_expect_success 'sequence squash, fixup & fixup -c gives combined message' ' test_cmp_rev HEAD^ A ' +test_expect_success 'fixup -C works upon --autosquash with amend!' ' + git checkout --detach branch && + FAKE_COMMIT_AMEND=squashed \ + FAKE_MESSAGE_COPY=actual-squash-message \ + git -c commit.status=false rebase -ik --autosquash \ + --signoff A && + git diff-tree --exit-code --patch HEAD branch -- && + test_cmp_rev HEAD^ A && + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \ + actual-squash-message +' + test_done
Signature · 1 line
2.29.0.rc1
Re: [PATCH v4 8/9] rebase -i: teach --autosquash to work with amend!
Quoted 10 lines · Charvi Mendiratta
If the commit subject starts with "amend!" then rearrange it like a "fixup!" commit and replace
pickcommand withfixup -Ccommand, which is used to fixup up the content if any and replaces the original commit message with amend! commit's message.Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 23 ++++++++++++++++------- t/t3437-rebase-fixup-options.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-)
Is this new behavior of recognizing "amend!" in the subject documented anywhere? I checked the documentation patch [9/9] but didn't see any mention of it.
sequencer.c static int subject2item_cmp(const void *fndata, · line 5666
Quoted 7 lines
sequencer.c +5
-0@@ -5662,6 +5662,12 @@ static int subject2item_cmp(const void *fndata, +static inline int skip_fixup_amend_squash (const char *subject,const char **p) { +return skip_prefix (subject,"fixup! " , p) || +skip_prefix (subject,"amend! " , p) || +skip_prefix (subject,"squash! " , p); +}
While the function name skip_fixup_amend_squash() may be accurate, it won't scale well. What happens when additional fixup-like prefixes are added in the future? Does the function name get extended to name them, as well? How about choosing a more generic, yet still meaningful, function name which doesn't suffer from this scaling problem. Perhaps skip_fixupish() or fix_squashlike() or something.
Also, making this function inline seems like a case of premature optimization.
Re: [PATCH v4 8/9] rebase -i: teach --autosquash to work with amend!
Quoted 13 lines · Eric Sunshine
Quoted 10 lines · Charvi Mendiratta
If the commit subject starts with "amend!" then rearrange it like a "fixup!" commit and replace
pickcommand withfixup -Ccommand, which is used to fixup up the content if any and replaces the original commit message with amend! commit's message.Signed-off-by Charvi Mendiratta <[email protected]>--- sequencer.c | 23 ++++++++++++++++------- t/t3437-rebase-fixup-options.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-)
Quoted 4 lines
Is this new behavior of recognizing "amend!" in the subject documented anywhere? I checked the documentation patch [9/9] but didn't see any mention of it.
No this patch series does not include that but included in the patch series of amend! commit implementation that is not sent to the mailing list yet. (Apology for the confusion)
Quoted 6 lines
Quoted 6 lines
sequencer.c +4
-0@@ -5662,6 +5662,12 @@ static int subject2item_cmp(const void *fndata, +static inline int skip_fixup_amend_squash (const char *subject,const char **p) { +return skip_prefix (subject,"fixup! " , p) || +skip_prefix (subject,"amend! " , p) || +skip_prefix (subject,"squash! " , p);
Quoted 9 lines
sequencer.c static int subject2item_cmp(const void *fndata, · line 5666
Quoted 1 line
sequencer.c +1
-0+}While the function name
skip_fixup_amend_squash()may be accurate, it won't scale well. What happens when additional fixup-like prefixes are added in the future? Does the function name get extended to name them, as well? How about choosing a more generic, yet still meaningful, function name which doesn't suffer from this scaling problem. Perhapsskip_fixupish()orfix_squashlike()or something.
I agree completely, and will change the function name to skip_fixupish().
Quoted 1 line
Also, making this function
inlineseems like a case of premature optimization.
Okay, will remove inline.
Thanks and Regards,
Charvi
PATCH v4 9/9 doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Charvi Mendiratta--- Documentation/git-rebase.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/git-rebase.txt +11 -3
@@ -887,9 +887,17 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omitting the +messages of commits identified by "fixup" commands, unless "fixup -c" +is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the last last one is used. You can also use +"fixup -C" to get the same behavior as "fixup -c" except without opening +an editor. + 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
Signature · 1 line
2.29.0.rc1
Re: [PATCH v4 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Quoted 7 lines · Charvi Mendiratta
Signed-off-by Charvi Mendiratta <[email protected]>---
Documentation/git-rebase.txt +0
-1@@ -887,9 +887,17 @@ If you want to fold two or more commits into one, replace the command If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 896
Quoted 10 lines
Documentation/git-rebase.txt +8
-2-messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omitting the +messages of commits identified by "fixup" commands, unless "fixup -c" +is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the last last one is used. You can also use
Erm, s/last last/last/ or even better s/last last/final/
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 903
Quoted 6 lines
Documentation/git-rebase.txt +3
-0+"fixup -C" to get the same behavior as "fixup -c" except without opening +an editor. + 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
It seems like an extra blank line sneaked in between the updated paragraph and the paragraph which follows it.
Re: [PATCH v4 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Quoted 13 lines · Eric Sunshine
Quoted 11 lines · Charvi Mendiratta
Signed-off-by Charvi Mendiratta <[email protected]>---
Documentation/git-rebase.txt +2
-3@@ -887,9 +887,17 @@ If you want to fold two or more commits into one, replace the command If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omitting the
Quoted 9 lines
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 897
Quoted 6 lines
Documentation/git-rebase.txt +6
-0+messages of commits identified by "fixup" commands, unless "fixup -c" +is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the last last one is used. You can also useErm, s/last last/last/ or even better s/last last/final/
Okay, I will correct it as s/last last/final
Quoted 9 lines
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 903
Quoted 6 lines
Documentation/git-rebase.txt +3
-0+"fixup -C" to get the same behavior as "fixup -c" except without opening +an editor. + 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editingIt seems like an extra blank line sneaked in between the updated paragraph and the paragraph which follows it.
Okay, I will remove it. Thanks for all the reviews!
Thanks and Regards,
Charvi
Re: [PATCH v4 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Eric SunshineQuoted 15 lines · Eric Sunshine
Quoted 14 lines · Charvi Mendiratta
Signed-off-by Charvi Mendiratta <[email protected]>---
Documentation/git-rebase.txt +0
-0@@ -887,9 +887,17 @@ If you want to fold two or more commits into one,replace the command
If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commitDocumentation/git-rebase.txt +2
-3-message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omittingthe
+messages of commits identified by "fixup" commands, unless "fixup -c"
Quoted 8 lines
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 897
Quoted 6 lines
Documentation/git-rebase.txt +5
-1+is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the last last one is used. You can also useErm, s/last last/last/ or even better s/last last/final/
I like "final", personally.
M.
Quoted 7 lines
Quoted 5 lines
+"fixup -C" to get the same behavior as "fixup -c" except without opening
Documentation/git-rebase.txt +2
-0+an editor. +'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
It seems like an extra blank line sneaked in between the updated paragraph and the paragraph which follows it.
v5 cover rebase -i: add options to fixup command
In reply to Charvi MendirattaThis patch series adds fixup [-C|-c] options to interactive rebase. In addition to amending the contents of the commit as the fixup command does now, fixup -C replaces the commit message of the original commit which we are fixing up with the message of the fixup commit. And to edit the fixup commit message before committing, fixup -c command is used instead of fixup -C. This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
Also, fixup -C is intended to support amend! commit upon --autosquash and it's working will be added in another patch series with the implementation of amend! commit.
Changes from v4 :
(Thanks to Eric Sunshine, Christian Couder and Phillip Wood for suggestions
and reviews)
The major change in this version is to remove the working of fixup -C with amend! commit and will include in the another patch series, in order to avoid the confusion. So there are following changes :
* removed the patch (rebase -i : teach --autosquash to work with amend!)
* updated the test script (t3437-*.sh), changed the test setup and removed two tests.
Earlier every test includes the commit message having subject starting with amend! So, now it includes a setup of different branch for testing fixup with options and also updated all the tests.
Removed the test - "skip fixup -C removes amend! from message" and also "sequence of fixup, fixup -C & squash --signoff works" as I think it would be better to test this also in the branch with amend! commit with different author. (Will add these tests with amend! commit implementation)
* changed the flag type from enum todo_item_flags to unsigned
* Removed amend! conditions from sequencer.c and
* Replaced fixup_-* with fixup-* in lib-rebase.sh
* fixup a small nit in Documentation
Charvi Mendiratta (5):
sequencer: pass todo_item to do_pick_commit()
sequencer: use const variable for commit message comments rebase -i: add fixup [-C | -c] command
t3437: test script for fixup [-C|-c] options in interactive rebase doc/git-rebase: add documentation for fixup [-C|-c] options
Phillip Wood (3):
rebase -i: only write fixup-message when it's needed
sequencer: factor out code to append squash message rebase -i: comment out squash!/fixup! subjects from squash message
Documentation/git-rebase.txt | 13 +- rebase-interactive.c | 4 +- sequencer.c | 270 ++++++++++++++++++++++++++---- t/lib-rebase.sh | 8 +- t/t3415-rebase-autosquash.sh | 30 ++-- t/t3437-rebase-fixup-options.sh | 133 +++++++++++++++ t/t3437/expected-combined-message | 19 +++ t/t3900-i18n-commit.sh | 4 - 8 files changed, 425 insertions(+), 56 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message
--
2.29.0.rc1
PATCH v5 1/8 rebase -i: only write fixup-message when it's needed
From: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
--- sequencer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sequencer.c +3 -4
@@ -1757,11 +1757,10 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) { +if (command ==TODO_FIXUP &&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 ()); +return error (_ ("cannot write '%s'" ),rebase_path_fixup_msg ()); }strbuf_addf (&buf,"%c " , comment_line_char);
Signature · 1 line
2.29.0.rc1
PATCH v5 2/8 sequencer: factor out code to append squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
This code is going to grow over the next two commits so move it to its own function.
--- sequencer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
sequencer.c +12 -6
@@ -1718,6 +1718,17 @@ static int is_pick_or_similar(enum todo_command command) } } +static void append_squash_message (struct strbuf *buf,const char *body, +struct replay_opts *opts) +{ +unlink (rebase_path_fixup_msg ()); +strbuf_addf (buf,"\n%c " , comment_line_char); +strbuf_addf (buf,_ ("This is the commit message #%d:" ), + ++opts->current_fixup_count +1 ); +strbuf_addstr (buf,"\n\n" ); +strbuf_addstr (buf, body); +} + static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit,
@@ -1779,12 +1790,7 @@ static int update_squash_messages(struct repository *r,find_commit_subject (message, &body);if (command ==TODO_SQUASH ) { -unlink (rebase_path_fixup_msg ()); -strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is the commit message #%d:" ), - ++opts->current_fixup_count +1 ); -strbuf_addstr (&buf,"\n\n" ); -strbuf_addstr (&buf, body); +append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
Signature · 1 line
2.29.0.rc1
PATCH v5 3/8 rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
--- sequencer.c | 21 ++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 30 ++++++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 36 insertions(+), 19 deletions(-)
sequencer.c +20 -1
@@ -1718,15 +1718,34 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +const char *p = body; +while (*p) { +const char *next =skip_blank_lines (p); +if (next != p) +break ; + p =strchrnul (p,'\n' ); +if (*p) + p++; + } +return p - body; +} +static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len); } static int update_squash_messages(struct repository *r,
t/t3415-rebase-autosquash.sh +16 -14
@@ -84,8 +84,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" && git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&
@@ -142,7 +141,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -195,7 +194,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -206,7 +205,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual '
@@ -216,7 +216,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git add -u && test_tick && oid=$(git rev-parse --short=11 HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-longshasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -227,7 +227,8 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + ! grep "squash" commit && + grep "^extra para" commit >actual && test_line_count = 1 actual '
@@ -236,7 +237,7 @@ test_auto_commit_flags () { echo 1 >file1 && git add -u && test_tick && - git commit --$1 first-commit && + git commit --$1 first-commit -m "extra para for first" && git tag final-commit-$1 && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -264,11 +265,11 @@ test_auto_fixup_fixup () { echo 1 >file1 && git add -u && test_tick && - git commit -m "$1! first" && + git commit -m "$1! first" -m "extra para for first" && echo 2 >file1 && git add -u && test_tick && - git commit -m "$1! $2! first" && + git commit -m "$1! $2! first" -m "second extra para for first" && git tag "final-$1-$2" && test_tick && (
@@ -329,12 +330,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para for first" && echo 1 >file1 && git add -u && test_tick && subject=$(git log -n 1 --format=%s HEAD~2) && - git commit -m "squash! $subject" && + git commit -m "squash! $subject" -m "second extra para for first" && git tag final-squash-instFmt && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -345,8 +346,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + ! grep "squash" commit && + grep first commit >actual && + test_line_count = 3 actual ' test_expect_success 'autosquash with empty custom instructionFormat' '
t/t3900-i18n-commit.sh +0 -4
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - if test $flag = squash; then - subject="$(head -1 expect)" && - printf "\nsquash! %s\n" "$subject" >>expect - fi && git cat-file commit HEAD^ >raw && (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && test_cmp expect actual
Signature · 1 line
2.29.0.rc1
PATCH v5 4/8 sequencer: pass todo_item to do_pick_commit()
In reply to Charvi MendirattaAs an additional member of the structure todo_item will be required in future commits pass the complete structure.
--- sequencer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
sequencer.c +11 -7
@@ -1877,8 +1877,7 @@ static void record_in_rewritten(struct object_id *oid, }static int do_pick_commit (struct repository *r, -enum todo_command command, -struct commit *commit, +struct todo_item *item,struct replay_opts *opts,int final_fixup,int *check_todo) {
@@ -1891,6 +1890,8 @@ static int do_pick_commit(struct repository *r,struct commit_message msg = {NULL ,NULL ,NULL ,NULL };struct strbuf msgbuf =STRBUF_INIT ;int res, unborn =0 , reword =0 , allow, drop_commit; +enum todo_command command = item->command; +struct commit *commit = item->commit;if (opts->no_commit) {/*
@@ -4140,8 +4141,8 @@ static int pick_commits(struct repository *r,setenv (GIT_REFLOG_ACTION ,reflog_message (opts,command_to_string (item->command),NULL ),1 ); - res =do_pick_commit (r, item->command, item->commit, - opts,is_final_fixup (todo_list), + res =do_pick_commit (r, item, opts, +is_final_fixup (todo_list), &check_todo);if (is_rebase_i (opts))setenv (GIT_REFLOG_ACTION , prev_reflog_action,1 );
@@ -4603,11 +4604,14 @@ static int single_pick(struct repository *r, struct replay_opts *opts) {int check_todo; +struct todo_item item; + + item.command = opts->action ==REPLAY_PICK ? +TODO_PICK :TODO_REVERT ; + item.commit = cmit;setenv (GIT_REFLOG_ACTION ,action_name (opts),0 ); -return do_pick_commit (r, opts->action ==REPLAY_PICK ? -TODO_PICK :TODO_REVERT , cmit, opts,0 , - &check_todo); +return do_pick_commit (r, &item, opts,0 , &check_todo); } int sequencer_pick_revisions(struct repository *r,
Signature · 1 line
2.29.0.rc1
PATCH v5 5/8 sequencer: use const variable for commit message comments
In reply to Charvi MendirattaThis makes it easier to use and reuse the comments.
--- sequencer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
sequencer.c +10 -5
@@ -1732,6 +1732,11 @@ static size_t subject_length(const char *body)return p - 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_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) {
@@ -1741,7 +1746,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" );strbuf_add_commented_lines (buf, body, commented_len);
@@ -1770,7 +1775,7 @@ static int update_squash_messages(struct repository *r, buf.buf : strchrnul(buf.buf, '\n');strbuf_addf (&header,"%c " , comment_line_char); -strbuf_addf (&header,_ ("This is a combination of %d commits." ), +strbuf_addf (&header,_ (combined_commit_msg_fmt), opts->current_fixup_count +2 );strbuf_splice (&buf,0 , eol - buf.buf, header.buf, header.len);strbuf_release (&header);
@@ -1794,9 +1799,9 @@ static int update_squash_messages(struct repository *r, }strbuf_addf (&buf,"%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is a combination of %d commits." ),2 ); +strbuf_addf (&buf,_ (combined_commit_msg_fmt),2 );strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addstr (&buf,_ ("This is the 1st commit message:" )); +strbuf_addstr (&buf,_ (first_commit_msg_str));strbuf_addstr (&buf,"\n\n" );strbuf_addstr (&buf, body);
@@ -1812,7 +1817,7 @@ static int update_squash_messages(struct repository *r,append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("The commit message #%d will be skipped:" ), +strbuf_addf (&buf,_ (skip_nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (&buf,"\n\n" );strbuf_add_commented_lines (&buf, body,strlen (body));
Signature · 1 line
2.29.0.rc1
PATCH v5 6/8 rebase -i: add fixup [-C | -c] command
In reply to Charvi MendirattaAdd options to fixup command to fixup both the commit contents and message. fixup -C command is used to replace the original commit message and fixup -c, additionally allows to edit the commit message.
This convention is similar to the existing merge command in the interactive rebase, that also supports -c and -C options with similar meanings.
--- rebase-interactive.c | 4 +- sequencer.c | 211 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 195 insertions(+), 20 deletions(-)
rebase-interactive.c +3 -1
@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"r, reword <commit> = use commit, but edit the commit message\n" "e, edit <commit> = use commit, but stop for amending\n" "s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = like \"squash\", but discard this\n" +" commit's log message; use -C to replace with this\n" +" commit message or -c to edit this commit message\n" "x, exec <command> = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop <commit> = remove commit\n"
sequencer.c +192 -19
298 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
PATCH v5 7/8 t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Charvi Mendiratta--- t/lib-rebase.sh | 8 +- t/t3437-rebase-fixup-options.sh | 133 ++++++++++++++++++++++++++++++ t/t3437/expected-combined-message | 19 +++++ 3 files changed, 158 insertions(+), 2 deletions(-) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-combined-message
t/lib-rebase.sh +6 -2
@@ -4,6 +4,7 @@ # # - override the commit message with $FAKE_COMMIT_MESSAGE # - amend the commit message with $FAKE_COMMIT_AMEND +# - copy the original commit message to a file with $FAKE_MESSAGE_COPY # - check that non-commit messages have a certain line count with $EXPECT_COUNT # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT # - rewrite a rebase -i script as directed by $FAKE_LINES.
@@ -14,8 +15,8 @@ # specified line. # # "<cmd> <lineno>" -- add a line with the specified command -# ("pick", "squash", "fixup", "edit", "reword" or "drop") and the -# SHA1 taken from the specified line. +# ("pick", "squash", "fixup"|"fixup-C"|"fixup-c", "edit", "reword" or "drop") +# and the SHA1 taken from the specified line. # # "exec_cmd_with_args" -- add an "exec cmd with args" line. #
@@ -33,6 +34,7 @@ set_fake_editor () { exit test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" exit ;; esac
@@ -51,6 +53,8 @@ set_fake_editor () { action="$line";; exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + fixup-*) + action=$(echo "$line" | sed 's/-/ -/');; "#") echo '# comment' >> "$1";; ">")
t/t3437-rebase-fixup-options.sh new file +133 -0
133 lines not on this page · raw message
t/t3437/expected-combined-message new file +19 -0
@@ -0,0 +1,19 @@ +# This is a combination of 4 commits. +# This is the 1st commit message: + +B + +# This is the commit message #2: + +new subject + +new +body + +# The commit message #3 will be skipped: + +# A2 + +# This is the commit message #4: + +A3
Signature · 1 line
2.29.0.rc1
PATCH v5 8/8 doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Charvi Mendiratta--- Documentation/git-rebase.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/git-rebase.txt +10 -3
@@ -887,9 +887,16 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is the concatenation of the first +commit's message with those identified by "squash" commands, omitting the +messages of commits identified by "fixup" commands, unless "fixup -c" +is used. In that case the suggested commit message is only the message +of the "fixup -c" commit, and an editor is opened allowing you to edit +the message. The contents (patch) of the "fixup -c" commit are still +incorporated into the folded commit. If there is more than one "fixup -c" +commit, the message from the final one is used. You can also use +"fixup -C" to get the same behavior as "fixup -c" except without opening +an editor. 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
Signature · 1 line
2.29.0.rc1
Quoted 3 lines · Charvi Mendiratta
Changes from v4 :
(Thanks to Eric Sunshine, Christian Couder and Phillip Wood for suggestions
and reviews)
Thanks for working on this and re-rolling. Unfortunately, it seems that v4 already landed in Junio's next branch which means that he won't be replacing v4 wholesale as would have been the case if it was still in the seen branch. Once patches are in next, improvements are made by building changes atop them (incrementally) rather than replacing them. Whether or not it makes sense for you to spend time re-doing these patches as incremental changes is not clear. In fact...
Quoted 7 lines
The major change in this version is to remove the working of
fixup -Cwith amend! commit and will include in the another patch series, in order to avoid the confusion. So there are following changes :
* removed the patch (rebase -i : teach --autosquash to work with amend!)
* updated the test script (t3437-*.sh), changed the test setup and removed two tests.
Quoted 7 lines
Earlier every test includes the commit message having subject starting with amend! So, now it includes a setup of different branch for testing fixup with options and also updated all the tests.
Removed the test - "skip fixup -C removes amend! from message" and also "sequence of fixup, fixup -C & squash --signoff works" as I think it would be better to test this also in the branch with amend! commit with different author. (Will add these tests with amend! commit implementation)
Despite these being nice cleanups to the standalone series, I'm not sure it's worth spending your time creating new patches to undo these from next. Removing them only to add them back later is not necessarily going to help "unconfuse" someone reading the commits in the permanent project history.
Quoted 3 lines
* changed the flag type from enum
todo_item_flagsto unsigned
* Replaced fixup_-* with fixup-* inlib-rebase.sh
* fixup a small nit in Documentation
These changes are still worthwhile and can easily be done incrementally atop what is already in next, I would think.
Anyhow, use your best judgment to decide how much work to devote to this.
Hi,
On Fri, 5 Feb 2021 at 13:00, Eric Sunshine <[email protected]> wrote:
[...]
Quoted 8 lines
Thanks for working on this and re-rolling. Unfortunately, it seems that v4 already landed in Junio's
nextbranch which means that he won't be replacing v4 wholesale as would have been the case if it was still in theseenbranch. Once patches are innext, improvements are made by building changes atop them (incrementally) rather than replacing them. Whether or not it makes sense for you to spend time re-doing these patches as incremental changes is not clear. In fact...
Okay, I admit I was not aware of this, before.
Quoted 15 lines
Quoted 7 lines
The major change in this version is to remove the working of
fixup -Cwith amend! commit and will include in the another patch series, in order to avoid the confusion. So there are following changes :
* removed the patch (rebase -i : teach --autosquash to work with amend!)
* updated the test script (t3437-*.sh), changed the test setup and removed two tests.Quoted 7 lines
Earlier every test includes the commit message having subject starting with amend! So, now it includes a setup of different branch for testing fixup with options and also updated all the tests.
Removed the test - "skip fixup -C removes amend! from message" and also "sequence of fixup, fixup -C & squash --signoff works" as I think it would be better to test this also in the branch with amend! commit with different author. (Will add these tests with amend! commit implementation)
Quoted 6 lines
Despite these being nice cleanups to the standalone series, I'm not sure it's worth spending your time creating new patches to undo these from
next. Removing them only to add them back later is not necessarily going to help "unconfuse" someone reading the commits in the permanent project history.
Yes, I was also thinking that let's not remove the working of fixup -C with amend! commit as it's true that it is intended to work like that way.
Quoted 7 lines
Quoted 3 lines
* changed the flag type from enum
todo_item_flagsto unsigned
* Replaced fixup_-* with fixup-* inlib-rebase.sh
* fixup a small nit in DocumentationThese changes are still worthwhile and can easily be done incrementally atop what is already in next, I would think.
I agree, these fixes are required. So, I am not sure but now to do these fixup shall I send another patch cleaning this patch series(v4) and rebase the patch on the 'next' branch ? Is it the right way ?
Thanks and Regards,
Charvi
Quoted 6 lines · Charvi Mendiratta
Quoted 4 lines · Eric Sunshine
Quoted 3 lines
* changed the flag type from enum
todo_item_flagsto unsigned
* Replaced fixup_-* with fixup-* inlib-rebase.sh
* fixup a small nit in Documentation
Quoted 6 lines
Quoted 2 lines
These changes are still worthwhile and can easily be done incrementally atop what is already in next, I would think.
I agree, these fixes are required. So, I am not sure but now to do these fixup shall I send another patch cleaning this patch series(v4) and rebase the patch on the 'next' branch ? Is it the right way ?
Yeah, I think you can send each of the above 3 changes in a different patch on top of the 'next' branch. That would create a new 3 patch long series, which you should give a new name and not consider v5 of the previous patch series.
Best,
Christian.
Quoted 5 lines · Christian Couder
Quoted 4 lines · Charvi Mendiratta
Quoted 2 lines · Eric Sunshine
These changes are still worthwhile and can easily be done incrementally atop what is already in next, I would think.
Quoted 8 lines
Quoted 3 lines
I agree, these fixes are required. So, I am not sure but now to do these fixup shall I send another patch cleaning this patch series(v4) and rebase the patch on the 'next' branch ? Is it the right way ?
Yeah, I think you can send each of the above 3 changes in a different patch on top of the 'next' branch. That would create a new 3 patch long series, which you should give a new name and not consider v5 of the previous patch series.
Yes, whatever issues from my reviews seem worth fixing atop the existing v4 can be included in this new patch series. (I think there may have been a few things beyond the three listed in the v5 cover letter, but I didn't bother doing a full audit of my review emails, so I could be wrong.) As Christian said, just make it a new series, though be sure to build it atop your v4 rather than building it atop "next". (The problem with building atop "next" is that your series then gets held hostage by _every_ series already in "next", which makes it nearly impossible for your series to graduate to "master" since it can't graduate until every other existing series in "next" graduates to "master".) The one other important thing is to mention in the cover letter that your new series is built atop "cm/rebase-i", which lets Junio know where to place the new series when he picks it up (and also lets reviewers know where to apply it if they want to test it themselves).
Quoted 17 lines · Eric Sunshine
Quoted 5 lines · Christian Couder
Quoted 4 lines · Charvi Mendiratta
Quoted 2 lines · Eric Sunshine
These changes are still worthwhile and can easily be done incrementally atop what is already in next, I would think.
Quoted 8 lines
Quoted 3 lines
I agree, these fixes are required. So, I am not sure but now to do these fixup shall I send another patch cleaning this patch series(v4) and rebase the patch on the 'next' branch ? Is it the right way ?
Yeah, I think you can send each of the above 3 changes in a different patch on top of the 'next' branch. That would create a new 3 patch long series, which you should give a new name and not consider v5 of the previous patch series.
Quoted 15 lines
Yes, whatever issues from my reviews seem worth fixing atop the existing v4 can be included in this new patch series. (I think there may have been a few things beyond the three listed in the v5 cover letter, but I didn't bother doing a full audit of my review emails, so I could be wrong.) As Christian said, just make it a new series, though be sure to build it atop your v4 rather than building it atop "next". (The problem with building atop "next" is that your series then gets held hostage by _every_ series already in "next", which makes it nearly impossible for your series to graduate to "master" since it can't graduate until every other existing series in "next" graduates to "master".) The one other important thing is to mention in the cover letter that your new series is built atop "cm/rebase-i", which lets Junio know where to place the new series when he picks it up (and also lets reviewers know where to apply it if they want to test it themselves).
Got it, Thanks !
Quoted 11 lines · Christian Couder
Quoted 9 lines · Charvi Mendiratta
Quoted 6 lines · Eric Sunshine
Quoted 3 lines
* changed the flag type from enum
todo_item_flagsto unsigned
* Replaced fixup_-* with fixup-* inlib-rebase.sh
* fixup a small nit in DocumentationThese changes are still worthwhile and can easily be done incrementally atop what is already in next, I would think.
Quoted 8 lines
Quoted 3 lines
I agree, these fixes are required. So, I am not sure but now to do these fixup shall I send another patch cleaning this patch series(v4) and rebase the patch on the 'next' branch ? Is it the right way ?
Yeah, I think you can send each of the above 3 changes in a different patch on top of the 'next' branch. That would create a new 3 patch long series, which you should give a new name and not consider v5 of the previous patch series.
Correct, except that it shouldn't be on top of the 'next' branch.
Please "git log --first-parent --oneline master..next" to find the tip of what got merged, and build on top of that instead. I.e.
$ git show -s --oneline \
"origin/next^{/ branch 'cm/rebase-i' into }"
4f9aa6cec3 Merge branch 'cm/rebase-i' into next
$ git checkout -b my-follow-up-topic 4f9aa6cec3^2
... work work work ...That is what we mean by "after getting merged to 'next', the topic gets polished incrementally".
Alternatively, you can have branches from the broken-out repository handy, e.g.
$ git remote add brokenout https://github.com/gitster/git
and you'd find the topic as I see it like so:
$ git fetch brokenout
$ git log --oneline brokenout/master..brokenout/cm/rebase-iHTH; thanks.
On Sat, 6 Feb 2021 at 00:43, Junio C Hamano <[email protected]> wrote:
[...]
Quoted 17 lines
Correct, except that it shouldn't be on top of the 'next' branch.
Please "git log --first-parent --oneline master..next" to find the tip of what got merged, and build on top of that instead. I.e.
$ git show -s --oneline \ "origin/next^{/ branch 'cm/rebase-i' into }" 4f9aa6cec3 Merge branch 'cm/rebase-i' into next $ git checkout -b my-follow-up-topic 4f9aa6cec3^2 ... work work work ...That is what we mean by "after getting merged to 'next', the topic gets polished incrementally".
Alternatively, you can have branches from the broken-out repository handy, e.g.
Quoted 7 lines
$ git remote add brokenout https://github.com/gitster/gitand you'd find the topic as I see it like so:
$ git fetch brokenout $ git log --oneline brokenout/master..brokenout/cm/rebase-i
Got it, thanks all for guiding. I will update soon.
Thanks and Regards,
Charvi
PATCH v2 1/9 rebase -i: only write fixup-message when it's needed
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
The file "$GIT_DIR/rebase-merge/fixup-message" is only used for fixup commands, there's no point in writing it for squash commands as it is immediately deleted.
--- sequencer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
sequencer.c +3 -4
@@ -1757,11 +1757,10 @@ static int update_squash_messages(struct repository *r,return error (_ ("could not read HEAD's commit message" ));find_commit_subject (head_message, &body); -if (write_message (body,strlen (body), -rebase_path_fixup_msg (),0 )) { +if (command ==TODO_FIXUP &&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 ()); +return error (_ ("cannot write '%s'" ),rebase_path_fixup_msg ()); }strbuf_addf (&buf,"%c " , comment_line_char);
Signature · 1 line
2.29.0.rc1
PATCH v2 2/9 sequencer: factor out code to append squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
This code is going to grow over the next two commits so move it to its own function.
--- sequencer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
sequencer.c +12 -6
@@ -1718,6 +1718,17 @@ static int is_pick_or_similar(enum todo_command command) } } +static void append_squash_message (struct strbuf *buf,const char *body, +struct replay_opts *opts) +{ +unlink (rebase_path_fixup_msg ()); +strbuf_addf (buf,"\n%c " , comment_line_char); +strbuf_addf (buf,_ ("This is the commit message #%d:" ), + ++opts->current_fixup_count +1 ); +strbuf_addstr (buf,"\n\n" ); +strbuf_addstr (buf, body); +} + static int update_squash_messages(struct repository *r, enum todo_command command, struct commit *commit,
@@ -1779,12 +1790,7 @@ static int update_squash_messages(struct repository *r,find_commit_subject (message, &body);if (command ==TODO_SQUASH ) { -unlink (rebase_path_fixup_msg ()); -strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is the commit message #%d:" ), - ++opts->current_fixup_count +1 ); -strbuf_addstr (&buf,"\n\n" ); -strbuf_addstr (&buf, body); +append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
Signature · 1 line
2.29.0.rc1
PATCH v2 3/9 rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Charvi MendirattaFrom: Phillip Wood <[email protected]>
When squashing commit messages the squash!/fixup! subjects are not of interest so comment them out to stop them becoming part of the final message.
This change breaks a bunch of --autosquash tests which rely on the "squash! <subject>" line appearing in the final commit message. This is addressed by adding a second line to the commit message of the "squash! ..." commits and testing for that.
--- sequencer.c | 25 ++++++++++++++++++++++++- t/t3415-rebase-autosquash.sh | 30 ++++++++++++++++-------------- t/t3900-i18n-commit.sh | 4 ---- 3 files changed, 40 insertions(+), 19 deletions(-)
sequencer.c +24 -1
@@ -1718,15 +1718,38 @@ static int is_pick_or_similar(enum todo_command command) } } +static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +} +static void append_squash_message (struct strbuf *buf,const char *body,struct replay_opts *opts) { +size_t commented_len =0 ; +unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len); +strbuf_addstr (buf, body + commented_len); } static int update_squash_messages(struct repository *r,
t/t3415-rebase-autosquash.sh +16 -14
@@ -81,8 +81,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" && git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&
@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -203,7 +202,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep -v "squash" commit && + grep "extra para" commit >actual && test_line_count = 1 actual '
@@ -213,7 +213,7 @@ test_expect_success 'auto squash that matches longer sha1' ' git add -u && test_tick && oid=$(git rev-parse --short=11 HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-longshasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -224,7 +224,8 @@ test_expect_success 'auto squash that matches longer sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep -v "squash" commit && + grep "extra para" commit >actual && test_line_count = 1 actual '
@@ -233,7 +234,7 @@ test_auto_commit_flags () { echo 1 >file1 && git add -u && test_tick && - git commit --$1 first-commit && + git commit --$1 first-commit -m "extra para for first" && git tag final-commit-$1 && test_tick && git rebase --autosquash -i HEAD^^^ &&
@@ -261,11 +262,11 @@ test_auto_fixup_fixup () { echo 1 >file1 && git add -u && test_tick && - git commit -m "$1! first" && + git commit -m "$1! first" -m "extra para for first" && echo 2 >file1 && git add -u && test_tick && - git commit -m "$1! $2! first" && + git commit -m "$1! $2! first" -m "second extra para for first" && git tag "final-$1-$2" && test_tick && (
@@ -326,12 +327,12 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para for first" && echo 1 >file1 && git add -u && test_tick && subject=$(git log -n 1 --format=%s HEAD~2) && - git commit -m "squash! $subject" && + git commit -m "squash! $subject" -m "second extra para for first" && git tag final-squash-instFmt && test_tick && git rebase --autosquash -i HEAD~4 &&
@@ -342,8 +343,9 @@ test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && - test_line_count = 2 actual + grep -v "squash" commit && + grep first commit >actual && + test_line_count = 3 actual ' test_expect_success 'autosquash with empty custom instructionFormat' '
t/t3900-i18n-commit.sh +0 -4
@@ -226,10 +226,6 @@ test_commit_autosquash_multi_encoding () { git rev-list HEAD >actual && test_line_count = 3 actual && iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect && - if test $flag = squash; then - subject="$(head -1 expect)" && - printf "\nsquash! %s\n" "$subject" >>expect - fi && git cat-file commit HEAD^ >raw && (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual && test_cmp expect actual
Signature · 1 line
2.29.0.rc1
Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Quoted 7 lines · Charvi Mendiratta
sequencer.c +7
-0+static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) {
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1737
Quoted 10 lines
sequencer.c +10
-0+if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +}
I cannot quite tell what this loop is trying to compute at the first glance.
- If body[0] == '\n', then i==0, c==LF, blank_line==1 and len==0 so len==0 is returned immediately.
- If the first line has only SP, HT, CR, etc. whitespace, blank_line stays 1 and at the end of the line when we see c=='\n', body[i] is pointing at that '\n', blank_line is true, so
len is returned from the previous iteration (e.g. body=" \n"
returns 0)
- If the first line has some non space, blank_line becomes false, so at the end of that line when we see c=='\n', body[i] is pointing at that '\n', len==i+1 becomes one past that LF and then we reset blank_line to true??? and go on to the next line.
So when we see LF, if we have seen any non whitespace byte on that line, blank_line is false. Only when we saw LF followed by zero or more whitespace before seeing another LF, we return len that was set when we saw the previous LF (which is one past that LF).
So... is this trying to find the first paragraph-break-looking line to find the end of the first paragraph. OK.
There must be an easier-to-read way to write all this, though, I would think (or don't we already have an existing code that is waiting to be factored out?).
In any case, let's keep reading.
Quoted 4 lines
static void append_squash_message(struct strbuf *buf, const char *body,
sequencer.c +1
-0struct replay_opts *opts) { +size_t commented_len =0 ;
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1751
Quoted 10 lines
sequencer.c +4
-1+unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len);
As add_commented_lines places the comment character at the beginning of each line, it is OK for body[0..commented_len) to contain more than one lines. Good.
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1752
Quoted 1 line
sequencer.c +1
-0+strbuf_addstr (buf, body + commented_len);
And we add everything after the beginning of the paragraph-break looking line. This code may add a line, immediately after the previous "commented out" block, bunch of whitespaces and then a LF. It will be cleaned up with stripspace most of the time, but depending on the end-user settings, it may be left behind. I am guessing that is what we want, but thought it would not hurt to double check.
t/t3415-rebase-autosquash.sh test_auto_squash () { · line 84
Quoted 11 lines
t/t3415-rebase-autosquash.sh +1
-2@@ -81,8 +81,7 @@ test_auto_squash () { echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" &&
It is not "extra"; that's the beginning of the "body" ;-).
Quoted 22 lines
t/t3415-rebase-autosquash.sh +2
-2git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches a sha1' ' · line 205
Quoted 5 lines
t/t3415-rebase-autosquash.sh +1
-1@@ -203,7 +202,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual && test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep -v "squash" commit &&
This says that the file must have at least one line that does not say "squash" or the test is a failure. It does not say "there should be no line that has "squash" on it". Intended?
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches a sha1' ' · line 206
Quoted 1 line
t/t3415-rebase-autosquash.sh +1
-0+ grep "extra para" commit >actual &&
I can tell that you want the "extra para" to still remain, but how does the grep that is not anchored guarantee that? Perhaps look for
grep "^extra para" commit
to ensure that you are not seeing a commented out but somehow failed to get stripspaced out?
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches a sha1' ' · line 208
Quoted 2 lines
t/t3415-rebase-autosquash.sh +0
-0test_line_count = 1 actual '
Thanks.
Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Junio,
Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Charvi Mendiratta
sequencer.c +12
-0+static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) {
Quoted 9 lines
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1737
Quoted 5 lines
sequencer.c +5
-0+ blank_line =0 ; + } + } +return blank_line ? len : i; +}I cannot quite tell what this loop is trying to compute at the first glance.
Oops, I think Phillip and Christian also pointed in the last revision to look for alternatives to make it easy. I mistook that point and forgot to look at it.
Quoted 9 lines
- If body[0] == '\n', then i==0, c==LF, blank_line==1 and len==0 so len==0 is returned immediately.
- If the first line has only SP, HT, CR, etc. whitespace,
blank_linestays 1 and at the end of the line when we see c=='\n', body[i] is pointing at that '\n',blank_lineis true, so
len is returned from the previous iteration (e.g. body=" \n"
returns 0)
yes, it returns the same result as given in this example (But I am not sure what you are taking " SP, HT, CR, etc " ? otherwise if its whitespace, then its works the same).
Quoted 5 lines
- If the first line has some non space,
blank_linebecomes false, so at the end of that line when we see c=='\n', body[i] is pointing at that '\n', len==i+1 becomes one past that LF and then we resetblank_lineto true??? and go on to the next line.
Quoted 8 lines
So when we see LF, if we have seen any non whitespace byte on that line,
blank_lineis false. Only when we saw LF followed by zero or more whitespace before seeing another LF, we return len that was set when we saw the previous LF (which is one past that LF).So... is this trying to find the first paragraph-break-looking line to find the end of the first paragraph. OK.
I followed and agreed with the above.
Quoted 4 lines
There must be an easier-to-read way to write all this, though, I would think (or don't we already have an existing code that is waiting to be factored out?).
I look into the code again and wonder if we can change this function like this :
static int subject_length(const char *body)
{
const char *p = body;
while (*p) {
if (*p == '\n' && p[1] =='\n') {
break;
} else {
p++;
}
}
return p - body;
}I think checking again '\n' will also serve the purpose as we separate the commit message subject and its body with the newline. Also, this is also
true that this function is only called when the message starts with (squash! or amend! or fixup!)
Quoted 23 lines
In any case, let's keep reading.
Quoted 4 lines
static void append_squash_message(struct strbuf *buf, const char *body,
structreplay_opts*opts)
{sequencer.c +1
-0+size_t commented_len =0 ;sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1751
Quoted 10 lines
sequencer.c +4
-1+unlink (rebase_path_fixup_msg ()); +if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) + commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char);strbuf_addf (buf,_ ("This is the commit message #%d:" ), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" ); -strbuf_addstr (buf, body); +strbuf_add_commented_lines (buf, body, commented_len);As
add_commented_linesplaces the comment character at the beginning of each line, it is OK for body[0..commented_len) to contain more than one lines. Good.Quoted 1 line
+
strbuf_addstr(buf, body + commented_len);
Quoted 8 lines
And we add everything after the beginning of the paragraph-break looking line. This code may add a line, immediately after the previous "commented out" block, bunch of whitespaces and then a LF. It will be cleaned up with stripspace most of the time, but depending on the end-user settings, it may be left behind. I am guessing that is what we want, but thought it would not hurt to double check.
I agree this working does the same and comments out the subject of the commit message starting with squash! or fixup! or amend!, upon squashing the two or more commits.
Quoted 5 lines
Quoted 5 lines
t/t3415-rebase-autosquash.sh +0
-0@@ -81,8 +81,7 @@ test_auto_squash () {
Quoted 9 lines
t/t3415-rebase-autosquash.sh test_auto_squash () { · line 84
Quoted 6 lines
t/t3415-rebase-autosquash.sh +1
-2echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && - + git commit -m "squash! first" -m "extra para for first" &&It is not "extra"; that's the beginning of the "body" ;-).
Okay, maybe we can use "message body" here.
Quoted 23 lines
Quoted 23 lines
t/t3415-rebase-autosquash.sh +2
-2git tag $1 && test_tick && git rebase $2 -i HEAD^^^ &&@@ -139,7 +138,7 @@ test_expect_success 'auto squash that matches 2 commits' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" && + git commit -m "squash! first" -m "extra para for first" && git tag final-multisquash && test_tick && git rebase --autosquash -i HEAD~4 &&@@ -192,7 +191,7 @@ test_expect_success 'auto squash that matches a sha1' ' git add -u && test_tick && oid=$(git rev-parse --short HEAD^) && - git commit -m "squash! $oid" && + git commit -m "squash! $oid" -m "extra para" && git tag final-shasquash && test_tick && git rebase --autosquash -i HEAD^^^ &&@@ -203,7 +202,8 @@ test_expect_success 'auto squash that matches a sha1' ' git cat-file blob HEAD^:file1 >actual &&
Quoted 9 lines
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches a sha1' ' · line 205
Quoted 4 lines
t/t3415-rebase-autosquash.sh +1
-1test_cmp expect actual && git cat-file commit HEAD^ >commit && - grep squash commit >actual && + grep -v "squash" commit &&This says that the file must have at least one line that does not say "squash" or the test is a failure. It does not say "there should be no line that has "squash" on it". Intended?
Ohh yes ..
Quoted 4 lines
t/t3415-rebase-autosquash.sh test_expect_success 'auto squash that matches a sha1' ' · line 206
Quoted 1 line
t/t3415-rebase-autosquash.sh +1
-0+ grep "extra para" commit >actual &&I can tell that you want the "extra para" to still remain, but how does the grep that is not anchored guarantee that?
.. but now I think to remove this grep -v "squash" commit as also discussed with Phillip earlier that in this test script we are not checking for the commented commit message.
Quoted 7 lines
Perhaps look for
grep "^extra para" commit
to ensure that you are not seeing a commented out but somehow failed to get stripspaced out?
I am not sure, what does failing to get stripspaced mean?
Thanks for the review !
Thanks and Regards,
Charvi
Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Quoted 29 lines · Charvi Mendiratta
Hi Junio,
Quoted 15 lines · Junio C Hamano
Quoted 12 lines · Charvi Mendiratta
sequencer.c +12
-0+static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) { +if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) {Quoted 9 lines
sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1737
Quoted 5 lines
sequencer.c +5
-0+ blank_line =0 ; + } + } +return blank_line ? len : i; +}I cannot quite tell what this loop is trying to compute at the first glance.
Quoted 3 lines
Oops, I think Phillip and Christian also pointed in the last revision to look for alternatives to make it easy. I mistook that point and forgot to look at it.
Yes, please take a look at find_commit_subject() in "commit.c".
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+ grep "extra para" commit >actual &&
I can tell that you want the "extra para" to still remain, but how does the grep that is not anchored guarantee that?
.. but now I think to remove this
grep -v "squash" commitas also discussed with Phillip earlier that in this test script we are not checking for the commented commit message.
Quoted 8 lines
Quoted 7 lines
Perhaps look for
grep "^extra para" commit
to ensure that you are not seeing a commented out but somehow failed to get stripspaced out?
I am not sure, what does failing to get stripspaced mean?
I think this refers to:
https://git-scm.com/docs/git-stripspace
Best,
Christian.
Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Hi Christian and Charvi
Quoted 30 lines · Christian Couder
Quoted 29 lines · Charvi Mendiratta
Hi Junio,
Quoted 24 lines · Junio C Hamano
Quoted 7 lines · Charvi Mendiratta
sequencer.c +7
-0+static size_t subject_length (const char *body) +{ +size_t i, len =0 ; +char c; +int blank_line =1 ; +for (i =0 , c = body[i]; c; c = body[++i]) { +if (c =='\n' ) {sequencer.c static int is_pick_or_similar(enum todo_command command) · line 1737
Quoted 10 lines
sequencer.c +10
-0+if (blank_line) +return len; + len = i +1 ; + blank_line =1 ; + }else if (!isspace (c)) { + blank_line =0 ; + } + } +return blank_line ? len : i; +}I cannot quite tell what this loop is trying to compute at the first glance.
Quoted 5 lines
Quoted 3 lines
Oops, I think Phillip and Christian also pointed in the last revision to look for alternatives to make it easy. I mistook that point and forgot to look at it.
Yes, please take a look at
find_commit_subject()in "commit.c".
That looks like it is taking the commit header and finding the start of the message. We have just the message, I think we probably want to use format_subject() in pretty.c which does what my hard to follow code does with the option to replace newlines in the subject with another character.
Best Wishes
Phillip
Quoted 25 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+ grep "extra para" commit >actual &&
I can tell that you want the "extra para" to still remain, but how does the grep that is not anchored guarantee that?
.. but now I think to remove this
grep -v "squash" commitas also discussed with Phillip earlier that in this test script we are not checking for the commented commit message.Quoted 8 lines
Quoted 7 lines
Perhaps look for
grep "^extra para" commit
to ensure that you are not seeing a commented out but somehow failed to get stripspaced out?
I am not sure, what does failing to get stripspaced mean?
I think this refers to:
https://git-scm.com/docs/git-stripspace
Best,
Christian.
Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Christian CouderQuoted 5 lines · Christian Couder
Quoted 3 lines
Oops, I think Phillip and Christian also pointed in the last revision to look for alternatives to make it easy. I mistook that point and forgot to look at it.
Yes, please take a look at
find_commit_subject()in "commit.c".
Yeah, it uses pretty.c::skip_blank_lines(), which is easy to use. so something like a loop that calls skip_blank_lines() to see if it returns a differnt result (which means the argument we fed it was at the beginning of a blank line, which is what this helper wants to return), and otherwise we advance by one line with strchrnul() and retry, perhaps.
while (*body) {
char *next = skip_blank_lines(body);
if (next != body)
break; /* found a blank line */
body = strchrnul(body, '\n');
if (*body)
body++;
}
/* body has the answer */Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
Quoted 16 lines · Junio C Hamano
Quoted 5 lines · Christian Couder
Quoted 3 lines
Oops, I think Phillip and Christian also pointed in the last revision to look for alternatives to make it easy. I mistook that point and forgot to look at it.
Yes, please take a look at
find_commit_subject()in "commit.c".Yeah, it uses
pretty.c::skip_blank_lines(), which is easy to use. so something like a loop that callsskip_blank_lines()to see if it returns a differnt result (which means the argument we fed it was at the beginning of a blank line, which is what this helper wants to return), and otherwise we advance by one line withstrchrnul()and retry, perhaps.
Quoted 9 lines
while (*body) {
char *next = skip_blank_lines(body);
if (next != body)
break; /* found a blank line */
body = strchrnul(body, '\n');
if (*body)
body++;
}
/* body has the answer */Thanks for all the pointers. I took time in looking into it, but now I got more cleared its actually looks for all the spaces in complete line which is considered
as a blank line and above function explains it more clearly. I will update the "subject
length" function as the above way and send in the next revision.
Thanks and Regards,
Charvi
Re: [PATCH v2 3/9] rebase -i: comment out squash!/fixup! subjects from squash message
In reply to Christian CouderHi,
On Thu, 21 Jan 2021 at 20:51, Christian Couder
<[email protected]> wrote:
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line
+ grep "extra para" commit >actual &&
I can tell that you want the "extra para" to still remain, but how does the grep that is not anchored guarantee that?
.. but now I think to remove this
grep -v "squash" commitas also discussed with Phillip earlier that in this test script we are not checking for the commented commit message.Quoted 4 lines
Perhaps look for
grep "^extra para" commit
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
to ensure that you are not seeing a commented out but somehow failed to get stripspaced out?
I am not sure, what does failing to get stripspaced mean?
I think this refers to:
Okay, thanks for referring and also here in this test script - so that the test does not fail
due to stripspace, it is using the test_line_count function. Also I agree with above
so maybe it is right to just replace with:
grep "^extra para" commit &&
grep "extra para" commit >actual &&
Thanks and Regards,
Charvi
PATCH v2 4/9 sequencer: pass todo_item to do_pick_commit()
In reply to Charvi MendirattaAs an additional member of the structure todo_item will be required in future commits pass the complete structure.
--- sequencer.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
sequencer.c +11 -7
@@ -1881,8 +1881,7 @@ static void record_in_rewritten(struct object_id *oid, }static int do_pick_commit (struct repository *r, -enum todo_command command, -struct commit *commit, +struct todo_item *item,struct replay_opts *opts,int final_fixup,int *check_todo) {
@@ -1895,6 +1894,8 @@ static int do_pick_commit(struct repository *r,struct commit_message msg = {NULL ,NULL ,NULL ,NULL };struct strbuf msgbuf =STRBUF_INIT ;int res, unborn =0 , reword =0 , allow, drop_commit; +enum todo_command command = item->command; +struct commit *commit = item->commit;if (opts->no_commit) {/*
@@ -4144,8 +4145,8 @@ static int pick_commits(struct repository *r,setenv (GIT_REFLOG_ACTION ,reflog_message (opts,command_to_string (item->command),NULL ),1 ); - res =do_pick_commit (r, item->command, item->commit, - opts,is_final_fixup (todo_list), + res =do_pick_commit (r, item, opts, +is_final_fixup (todo_list), &check_todo);if (is_rebase_i (opts))setenv (GIT_REFLOG_ACTION , prev_reflog_action,1 );
@@ -4607,11 +4608,14 @@ static int single_pick(struct repository *r, struct replay_opts *opts) {int check_todo; +struct todo_item item; + + item.command = opts->action ==REPLAY_PICK ? +TODO_PICK :TODO_REVERT ; + item.commit = cmit;setenv (GIT_REFLOG_ACTION ,action_name (opts),0 ); -return do_pick_commit (r, opts->action ==REPLAY_PICK ? -TODO_PICK :TODO_REVERT , cmit, opts,0 , - &check_todo); +return do_pick_commit (r, &item, opts,0 , &check_todo); } int sequencer_pick_revisions(struct repository *r,
Signature · 1 line
2.29.0.rc1
PATCH v2 5/9 sequencer: use const variable for commit message comments
In reply to Charvi MendirattaThis makes it easier to use and reuse the comments.
--- sequencer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
sequencer.c +10 -5
@@ -1736,6 +1736,11 @@ static size_t subject_length(const char *body)return blank_line ? len : i; } +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_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) {
@@ -1745,7 +1750,7 @@ static void append_squash_message(struct strbuf *buf, const char *body,if (starts_with (body,"squash!" ) ||starts_with (body,"fixup!" )) commented_len =subject_length (body);strbuf_addf (buf,"\n%c " , comment_line_char); -strbuf_addf (buf,_ ("This is the commit message #%d:" ), +strbuf_addf (buf,_ (nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (buf,"\n\n" );strbuf_add_commented_lines (buf, body, commented_len);
@@ -1774,7 +1779,7 @@ static int update_squash_messages(struct repository *r, buf.buf : strchrnul(buf.buf, '\n');strbuf_addf (&header,"%c " , comment_line_char); -strbuf_addf (&header,_ ("This is a combination of %d commits." ), +strbuf_addf (&header,_ (combined_commit_msg_fmt), opts->current_fixup_count +2 );strbuf_splice (&buf,0 , eol - buf.buf, header.buf, header.len);strbuf_release (&header);
@@ -1798,9 +1803,9 @@ static int update_squash_messages(struct repository *r, }strbuf_addf (&buf,"%c " , comment_line_char); -strbuf_addf (&buf,_ ("This is a combination of %d commits." ),2 ); +strbuf_addf (&buf,_ (combined_commit_msg_fmt),2 );strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addstr (&buf,_ ("This is the 1st commit message:" )); +strbuf_addstr (&buf,_ (first_commit_msg_str));strbuf_addstr (&buf,"\n\n" );strbuf_addstr (&buf, body);
@@ -1816,7 +1821,7 @@ static int update_squash_messages(struct repository *r,append_squash_message (&buf, body, opts); }else if (command ==TODO_FIXUP ) {strbuf_addf (&buf,"\n%c " , comment_line_char); -strbuf_addf (&buf,_ ("The commit message #%d will be skipped:" ), +strbuf_addf (&buf,_ (skip_nth_commit_msg_fmt), ++opts->current_fixup_count +1 );strbuf_addstr (&buf,"\n\n" );strbuf_add_commented_lines (&buf, body,strlen (body));
Signature · 1 line
2.29.0.rc1
PATCH v2 6/9 rebase -i: add fixup [-C | -c] command
In reply to Charvi MendirattaAdd options to fixup command to fixup both the commit contents and message. fixup -C command is used to replace the original commit message and fixup -c, additionally allows to edit the commit message.
--- rebase-interactive.c | 4 +- sequencer.c | 211 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 195 insertions(+), 20 deletions(-)
rebase-interactive.c +3 -1
@@ -44,7 +44,9 @@ void append_todo_help(int command_count,"r, reword <commit> = use commit, but edit the commit message\n" "e, edit <commit> = use commit, but stop for amending\n" "s, squash <commit> = use commit, but meld into previous commit\n" -"f, fixup <commit> = like \"squash\", but discard this commit's log message\n" +"f, fixup [-C | -c] <commit> = 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" "x, exec <command> = run command (the rest of the line) using shell\n" "b, break = stop here (continue rebase later with 'git rebase --continue')\n" "d, drop <commit> = remove commit\n"
sequencer.c +192 -19
298 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
PATCH v2 7/9 t3437: test script for fixup [-C|-c] options in interactive rebase
In reply to Charvi Mendiratta--- t/lib-rebase.sh | 4 + t/t3437-rebase-fixup-options.sh | 190 ++++++++++++++++++++++++++++++++ t/t3437/expected-squash-message | 51 +++++++++ 3 files changed, 245 insertions(+) create mode 100755 t/t3437-rebase-fixup-options.sh create mode 100644 t/t3437/expected-squash-message
t/lib-rebase.sh +4 -0
@@ -4,6 +4,7 @@ # # - override the commit message with $FAKE_COMMIT_MESSAGE # - amend the commit message with $FAKE_COMMIT_AMEND +# - copy the original commit message to a file with $FAKE_MESSAGE_COPY # - check that non-commit messages have a certain line count with $EXPECT_COUNT # - check the commit count in the commit message header with $EXPECT_HEADER_COUNT # - rewrite a rebase -i script as directed by $FAKE_LINES.
@@ -33,6 +34,7 @@ set_fake_editor () { exit test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" + test -z "$FAKE_MESSAGE_COPY" || cat "$1" >"$FAKE_MESSAGE_COPY" exit ;; esac
@@ -51,6 +53,8 @@ set_fake_editor () { action="$line";; exec_*|x_*|break|b) echo "$line" | sed 's/_/ /g' >> "$1";; + merge_*|fixup_*) + action=$(echo "$line" | sed 's/_/ /g');; "#") echo '# comment' >> "$1";; ">")
t/t3437-rebase-fixup-options.sh new file +190 -0
190 lines not on this page · raw message
t/t3437/expected-squash-message new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1
PATCH v2 8/9 rebase -i: teach --autosquash to work with amend!
In reply to Charvi MendirattaIf the commit subject starts with "amend!" then rearrange it like a "fixup!" commit and replace pick command with fixup -C command, which is used to fixup up the content if any and replaces the original commit message with amend! commit's message.
--- sequencer.c | 23 ++++++++++++++++------- t/t3437-rebase-fixup-options.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-)
sequencer.c +16 -7
@@ -5664,6 +5664,12 @@ 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) { +return skip_prefix (subject,"fixup! " , p) || +skip_prefix (subject,"amend! " , p) || +skip_prefix (subject,"squash! " , p); +} +/* * Rearrange the todo list that has both "pick commit-id msg" and "pick * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -5722,15 +5728,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_prefix (subject,"fixup! " , &p) || -skip_prefix (subject,"squash! " , &p))) { +if (skip_fixup_amend_squash (subject, &p)) {struct commit *commit2;for (;;) {while (isspace (*p)) p++; -if (!skip_prefix (p,"fixup! " , &p) && - !skip_prefix (p,"squash! " , &p)) +if (!skip_fixup_amend_squash (p, &p))break ; }
@@ -5760,9 +5764,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) }if (i2 >=0 ) { rearranged =1 ; - todo_list->items[i].command = -starts_with (subject,"fixup!" ) ? -TODO_FIXUP :TODO_SQUASH ; +if (starts_with (subject,"fixup!" )) { + todo_list->items[i].command =TODO_FIXUP ; + }else if (starts_with (subject,"amend!" )) { + todo_list->items[i].command =TODO_FIXUP ; + todo_list->items[i].flags =TODO_REPLACE_FIXUP_MSG ; + }else { + todo_list->items[i].command =TODO_SQUASH ; + }if (tail[i2] <0 ) { next[i] = next[i2]; next[i2] = i;
t/t3437-rebase-fixup-options.sh +12 -0
@@ -187,4 +187,16 @@ test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fix test_commit_message HEAD expected-message ' +test_expect_success 'fixup -C works upon --autosquash with amend!' ' + git checkout --detach branch && + FAKE_COMMIT_AMEND=squashed \ + FAKE_MESSAGE_COPY=actual-squash-message \ + git -c commit.status=false rebase -ik --autosquash \ + --signoff A && + git diff-tree --exit-code --patch HEAD branch -- && + test_cmp_rev HEAD^ A && + test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \ + actual-squash-message +' + test_done
Signature · 1 line
2.29.0.rc1
PATCH v2 9/9 doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Charvi Mendiratta--- Documentation/git-rebase.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/git-rebase.txt +9 -3
@@ -887,9 +887,15 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is created as follows: + + - It is made using the commit message of a commit with the "fixup -C" + or "fixup -c" command. In the later case an editor is opened to edit + the commit message. + - Otherwise it's the concatenation of the commit messages of the first + commit and of those with the "squash" command. + - It omits the commit messages of commits with the "fixup" + (without -C or -c) command. 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
Signature · 1 line
2.29.0.rc1
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Hi!
Quoted 13 lines · Charvi Mendiratta
Mentored-by Christian Couder <[email protected]>Mentored-by Phillip Wood <[email protected]>Signed-off-by Charvi Mendiratta <[email protected]>--- Documentation/git-rebase.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)Documentation/git-rebase.txt +0
-0@@ -887,9 +887,15 @@ If you want to fold two or more commits into one, replace the command "pick" for the second and subsequent commits with "squash" or "fixup".
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 894
Quoted 10 lines
Documentation/git-rebase.txt +5
-3If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit -message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command, -but omits the commit messages of commits with the "fixup" command. +message for the folded commit is created as follows: + + - It is made using the commit message of a commit with the "fixup -C" + or "fixup -c" command. In the later case an editor is opened to edit + the commit message.
s/later/latter/
What happens if there is more than one "fixup -C/-c" command?
Thanks for this work!
M.
Quoted 8 lines
Documentation/git-rebase.txt +4
-0+ - Otherwise it's the concatenation of the commit messages of the first + commit and of those with the "squash" command. + - It omits the commit messages of commits with the "fixup" + (without -C or -c) command. 'git rebase' will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Hi Marc,
On Tue, 19 Jan 2021 at 20:07, Marc Branchaud <[email protected]> wrote:
[...]
Quoted 5 lines
Quoted 5 lines
"pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit
Documentation/git-rebase.txt +0
-2-message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command,
Quoted 9 lines
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 894
Quoted 6 lines
Documentation/git-rebase.txt +5
-1-but omits the commit messages of commits with the "fixup" command. +message for the folded commit is created as follows: + + - It is made using the commit message of a commit with the "fixup -C" + or "fixup -c" command. In the later case an editor is opened to edit + the commit message.s/later/latter/
Thanks, will fix it.
Quoted 2 lines
What happens if there is more than one "fixup -C/-c" command?
Upon running interactive rebase, in todo list if we use for example sequence of commands like fixup -C, fixup -C , fixup -C then it will fixup content of all and
for commit message it will replace with the commit message of end fixup -C
Similarly, if we have sequence like fixup -c, fixup -c, fixup -c then also it will fixup
up all the content and here it allow user to edit the message, so opens the editor once
in this case and shows the commit msg of end fixup -c to edit and also contains
commented commit messages of complete fixup chain. So, for any sequence of fixup chains fixup -c works as similar to the squash command.
Hope it explains the working.
Thanks and Regards,
Charvi
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Quoted 38 lines · Charvi Mendiratta
Hi Marc,
On Tue, 19 Jan 2021 at 20:07, Marc Branchaud <[email protected]> wrote:
[...]Quoted 5 lines
Quoted 5 lines
"pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit
Documentation/git-rebase.txt +0
-2-message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command,Quoted 9 lines
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 894
Quoted 6 lines
Documentation/git-rebase.txt +5
-1-but omits the commit messages of commits with the "fixup" command. +message for the folded commit is created as follows: + + - It is made using the commit message of a commit with the "fixup -C" + or "fixup -c" command. In the later case an editor is opened to edit + the commit message.s/later/latter/
Thanks, will fix it.
Quoted 2 lines
What happens if there is more than one "fixup -C/-c" command?
Upon running interactive rebase, in todo list if we use for example sequence of commands like
fixup -C,fixup -C,fixup -Cthen it will fixup content of all and
for commit message it will replace with the commit message of endfixup -CSimilarly, if we have sequence like
fixup -c,fixup -c,fixup -cthen also it will fixup
up all the content and here it allow user to edit the message, so opens the editor once
in this case and shows the commit msg of endfixup -cto edit and also contains
commented commit messages of complete fixup chain. So, for any sequence of fixup chainsfixup -cworks as similar to thesquashcommand.
Quoted 1 line
Hope it explains the working.
Yes, that does explain things.
I'm also under the impression that the "fixup -C/-c" commit's patch is still incorporated into the folded commit. Is that right?
So I think the documentation could be improved. Assuming that a "fixup -C/-c" commit's patch is incorporated just like with plain "fixup", something like:
The suggested commit message for the folded commit is the concatenation of the first commit's message with those identified by "squash" commands, omitting the messages of commits identified by "fixup" commands, unless "fixup -c" is used. In that case the suggested commit message is only the message of the "fixup -c" commit, and an editor is opened allowing you to edit the message. The contents (patch) of the "fixup -c" commit are still incorporated into the folded commit.
If there is more than one "fixup -c" commit, the message from the last
last one is used. You can also use "fixup -C" to get the same behavior as "fixup -c" except without opening an editor.
Thanks!
M.
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
On Wed, 20 Jan 2021 at 03:35, Marc Branchaud <[email protected]> wrote:
[...]
Quoted 3 lines
I'm also under the impression that the "fixup -C/-c" commit's patch is still incorporated into the folded commit. Is that right?
yes, it's still incorporated into the folded commit, as it just adds options to the fixup command to replace or edit the commit message.
Quoted 4 lines
So I think the documentation could be improved. Assuming that a "fixup -C/-c" commit's patch is incorporated just like with plain "fixup", something like:
Quoted 11 lines
The suggested commit message for the folded commit is the concatenation of the first commit's message with those identified by "squash" commands, omitting the messages of commits identified by "fixup" commands,
unless"fixup -c" is used. In that case the suggested commit message isonlythe message of the "fixup -c" commit, and an editor is opened allowing you to edit the message. The contents (patch) of the "fixup -c" commit are still incorporated into the folded commit.
If there is more than one "fixup -c" commit, the message from the last
last one is used. You can also use "fixup -C" to get the same behavior as "fixup -c" except without opening an editor.
I agree, this is now more clear and explains for more than one fixup [-C|-c] or squash command also. Thanks for the suggestions, I will change this in the next revision.
Thanks and Regards,
Charvi
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
In reply to Charvi MendirattaHi Charvi
Quoted 29 lines · Charvi Mendiratta
Hi Marc,
On Tue, 19 Jan 2021 at 20:07, Marc Branchaud <[email protected]> wrote:
[...]Quoted 5 lines
Quoted 5 lines
"pick" for the second and subsequent commits with "squash" or "fixup". If the commits had different authors, the folded commit will be attributed to the author of the first commit. The suggested commit
Documentation/git-rebase.txt +0
-2-message for the folded commit is the concatenation of the commit -messages of the first commit and of those with the "squash" command,Quoted 9 lines
Documentation/git-rebase.txt If you want to fold two or more commits into one, replace the command · line 894
Quoted 6 lines
Documentation/git-rebase.txt +5
-1-but omits the commit messages of commits with the "fixup" command. +message for the folded commit is created as follows: + + - It is made using the commit message of a commit with the "fixup -C" + or "fixup -c" command. In the later case an editor is opened to edit + the commit message.s/later/latter/
Thanks, will fix it.
Quoted 2 lines
What happens if there is more than one "fixup -C/-c" command?
Upon running interactive rebase, in todo list if we use for example sequence of commands like
fixup -C,fixup -C,fixup -Cthen it will fixup content of all and
for commit message it will replace with the commit message of endfixup -C
Quoted 4 lines
Similarly, if we have sequence like
fixup -c,fixup -c,fixup -cthen also it will fixup
up all the content and here it allow user to edit the message, so opens the editor once
It is good that we only open the editor once in this case - I'd not thought about chains of fixup -c before reading this. Do we have a test to verify that the editor is only opened once?
Best Wishes
Phillip
Quoted 10 lines
in this case and shows the commit msg of end
fixup -cto edit and also contains
commented commit messages of complete fixup chain. So, for any sequence of fixup chainsfixup -cworks as similar to thesquashcommand.Hope it explains the working.
Thanks and Regards,
Charvi
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Hi Phillip,
Quoted 10 lines · Phillip Wood
Quoted 5 lines
[...]
Similarly, if we have sequence likefixup -c,fixup -c,fixup -cthen also it will fixup
up all the content and here it allow user to edit the message, so opens the editor onceIt is good that we only open the editor once in this case - I'd not thought about chains of
fixup -cbefore reading this. Do we have a test to verify that the editor is only opened once?
No, we don't. But I also agree, it's a good idea to add a test for it. I think may be one sequence with 'fixup -C', 'fixup -c', 'fixup -c' and the other 'squash' , 'fixup -C', 'fixup -c', is sufficient for testing. Or any other suggestions for testing it ?
Thanks and regards,
Charvi
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Hi Charvi
Quoted 15 lines · Charvi Mendiratta
Hi Phillip,
Quoted 10 lines · Phillip Wood
Quoted 5 lines
[...]
Similarly, if we have sequence likefixup -c,fixup -c,fixup -cthen also it will fixup
up all the content and here it allow user to edit the message, so opens the editor onceIt is good that we only open the editor once in this case - I'd not thought about chains of
fixup -cbefore reading this. Do we have a test to verify that the editor is only opened once?
Quoted 4 lines
No, we don't. But I also agree, it's a good idea to add a test for it. I think may be one sequence with 'fixup -C', 'fixup -c', 'fixup -c' and the other 'squash' , 'fixup -C', 'fixup -c', is sufficient for testing.
Those are both good sequences to test. I think we should check 'fixup -c' 'fixup' as well - with 'squash' 'fixup' we open the editor after the fixup so the user can see all the changes that will be committed when they edit the message, we should do the same for 'fixup -c' 'fixup'. Also 'fixup -c' 'squash' might be worth testing as well.
Best Wishes
Phillip
Or any other suggestions for testing it ?
Quoted 4 lines
Thanks and regards,
Charvi
Re: [PATCH v2 9/9] doc/git-rebase: add documentation for fixup [-C|-c] options
Quoted 24 lines · Phillip Wood
Hi Charvi
Quoted 15 lines · Charvi Mendiratta
Hi Phillip,
Quoted 10 lines · Phillip Wood
Quoted 5 lines
[...]
Similarly, if we have sequence likefixup -c,fixup -c,fixup -cthen also it will fixup
up all the content and here it allow user to edit the message, so opens the editor onceIt is good that we only open the editor once in this case - I'd not thought about chains of
fixup -cbefore reading this. Do we have a test to verify that the editor is only opened once?Quoted 4 lines
No, we don't. But I also agree, it's a good idea to add a test for it. I think may be one sequence with 'fixup -C', 'fixup -c', 'fixup -c' and the other 'squash' , 'fixup -C', 'fixup -c', is sufficient for testing.
Quoted 6 lines
Those are both good sequences to test. I think we should check 'fixup -c' 'fixup' as well - with 'squash' 'fixup' we open the editor after the fixup so the user can see all the changes that will be committed when they edit the message, we should do the same for 'fixup -c' 'fixup'. Also 'fixup -c' 'squash' might be worth testing as well.
Agree, I will add these two test cases also and send the next revision of patches.
Thanks for reviews!
Thanks and Regards,
Charvi