Re: [PATCH 2/2] add-patch: quit on EOF
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 25, 2025, 16:20 UTC
- Message-ID
- <xmqqfrb7nebp.fsf@gitster.g>
- In-Reply-To
- <13529bee-1e02-4c20-9461-6569312bfe4f@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 9 quoted lines
> 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 <l.s.r@web.de> > --- > add-patch.c | 4 +++- > t/t3701-add-interactive.sh | 11 +++++++++++ > 2 files changed, 14 insertions(+), 1 deletion(-)
The code breaks out of the loop (either with or without setting the 'quit' flag), after which there is "which hunks are going to be used?" check, followed by "apply the selected hunks". So the new ctrl-D behaviour does not change the end-result left in the files. The effect of the hunks chosen for application will not be abandoned.
If you are one of those unfortunate folks living dangeously with interactive.singlekey set to true, your ctrl-D would have given you
Unknown command '' (use '?' for help)
in the code before this change, so, this would give them strict improvement.
The current code happens to *work* for those without the single key setting, in the sense that when we move to subsequent files, the first call to read_single_character() in patfch_update_file() for them immediately return EOF, breaking out of the loop before any hunks for the file gets marked for application, so we'll iterate through the remaining files without doing anything to these files.
But we do show the first hunk of all of them before quitting. And this patch squelches these useless output.
OK. This makes sense and makes the change in this patch worthwhile.
I wonder if we want to 'echo" something in this case, though. If I say 'q', whether interactive.singlekey is active or not, I see
(1/1) Stage this hunk [y,n,q,a,d,s,e,p,P,?]? q
on the last line before getting the shell prompt back. With this change, I won't see anything after the prompt. Perhaps it is OK? I dunno. Perhaps we want to pretend as if 'q' were given instead of EOF, like the following? I dunno.
Will queue as-is.
Thanks.
add-patch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git c/add-patch.c w/add-patch.c index cd71a0359a..f201ead08e 100644 --- c/add-patch.c +++ w/add-patch.c @@ -1558,8 +1558,8 @@ static int patch_update_file(struct add_p_state *s, fputs(s->s.reset_color_interactive, stdout); fflush(stdout); if (read_single_character(s) == EOF) { - quit = 1; - break; + puts("q"); + strbuf_addch(&s->answer, 'q'); } if (!s->answer.len)