From 13768117f5e174a7a0403607532e33a7dc40b969 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 25 Oct 2025 07:46:42 +0200 Subject: add-patch: quit without skipping undecided hunks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Option q implies d, i.e., it marks any undecided hunks towards the bottom of the hunk array as skipped. This is unnecessary; later code treats undecided and skipped hunks the same: The only functions that use UNDECIDED_HUNK and SKIP_HUNK are patch_update_file() itself (but not after its big for loop) and its helpers get_first_undecided() and display_hunks(). Streamline the handling of option q by quitting immediately. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- add-patch.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'add-patch.c') diff --git a/add-patch.c b/add-patch.c index ae9a20d8f2..a70def1f81 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1601,7 +1601,7 @@ soft_increment: } else if (hunk->use == UNDECIDED_HUNK) { hunk->use = USE_HUNK; } - } else if (ch == 'd' || ch == 'q') { + } else if (ch == 'd') { if (file_diff->hunk_nr) { for (; hunk_index < file_diff->hunk_nr; hunk_index++) { hunk = file_diff->hunk + hunk_index; @@ -1613,10 +1613,9 @@ soft_increment: } else if (hunk->use == UNDECIDED_HUNK) { hunk->use = SKIP_HUNK; } - if (ch == 'q') { - quit = 1; - break; - } + } else if (ch == 'q') { + quit = 1; + break; } else if (s->answer.buf[0] == 'K') { if (permitted & ALLOW_GOTO_PREVIOUS_HUNK) hunk_index = dec_mod(hunk_index, -- cgit v1.2.3 From e56f6dcd7b4c90192018e848d0810f091d092913 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 25 Oct 2025 07:48:28 +0200 Subject: add-patch: quit on EOF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we reach the end of the input, e.g. because the user pressed ctrl-D on Linux, there is no point in showing any more prompts, as we won't get any reply. Do the same as option 'q' would: Quit. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- add-patch.c | 4 +++- t/t3701-add-interactive.sh | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'add-patch.c') diff --git a/add-patch.c b/add-patch.c index a70def1f81..173a53241e 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1569,8 +1569,10 @@ static int patch_update_file(struct add_p_state *s, if (*s->s.reset_color_interactive) fputs(s->s.reset_color_interactive, stdout); fflush(stdout); - if (read_single_character(s) == EOF) + if (read_single_character(s) == EOF) { + quit = 1; break; + } if (!s->answer.len) continue; diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 851ca6dd91..4285314f35 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -1431,4 +1431,15 @@ test_expect_success 'invalid option s is rejected' ' test_cmp expect actual ' +test_expect_success 'EOF quits' ' + echo a >file && + echo a >file2 && + git add file file2 && + echo X >file && + echo X >file2 && + git add -p out && + test_grep file out && + test_grep ! file2 out +' + test_done -- cgit v1.2.3