From: Abraham Samuel Adekunle Date: Fri, 23 Jan 2026 11:58:45 GMT Subject: [RFC PATCH 1/1] add-patch: Allow reworking with a file after deciding on all its hunks Message-ID: In-Reply-To: After deciding on all hunks in a file, the interactive session advances automatically to the next file if there is another, or the process ends. Allow for reworking with a file by introducing a what_now prompt which allows for navigating with J/K or advancing to the next file if there is one. Signed-off-by: Abraham Samuel Adekunle --- add-patch.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/add-patch.c b/add-patch.c index 173a53241e..1ac565b0ab 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1449,7 +1449,7 @@ static int patch_update_file(struct add_p_state *s, struct hunk *hunk; char ch; struct child_process cp = CHILD_PROCESS_INIT; - int colored = !!s->colored.len, quit = 0, use_pager = 0; + int colored = !!s->colored.len, quit = 0, use_pager = 0, skip_what_now = 0; enum prompt_mode_type prompt_mode_type; /* Empty added files have no hunks */ @@ -1498,12 +1498,61 @@ static int patch_update_file(struct add_p_state *s, /* Everything decided? */ if (undecided_previous < 0 && undecided_next < 0 && - hunk->use != UNDECIDED_HUNK) - break; + hunk->use != UNDECIDED_HUNK && !skip_what_now ) { + const char *prompt_whatnow; + /* Allow navigation between hunks or go to next file */ + if (s->file_diff_nr > 1) + prompt_whatnow = _("What now? [J,K,q,>]? "); + else + prompt_whatnow = _("What now? [J,K,q]? "); + printf("%s %s", + s->s.prompt_color, + prompt_whatnow); + if (*s->s.reset_color_interactive) + fputs(s->s.reset_color_interactive, stdout); + fflush(stdout); + if (read_single_character(s) == EOF) { + quit = 1; + break; + } + if (!s->answer.len) + continue; + if (s->answer.buf[0] == '>' && s->file_diff_nr > 1) { + skip_what_now = 0; + break; + } + else if (s->answer.buf[0] == 'K') { + if (file_diff->hunk_nr > 1) { + hunk_index = dec_mod(hunk_index, file_diff->hunk_nr); + skip_what_now = 1; + } + else + err(s, _("No other hunk")); + continue; + } + else if (s->answer.buf[0] == 'J') { + if (file_diff->hunk_nr > 1) { + hunk_index = inc_mod(hunk_index, file_diff->hunk_nr); + skip_what_now = 1; + } + else + err(s, _("No other hunk")); + continue; + } + else if (s->answer.buf[0] == 'q') { + skip_what_now = 0; + quit = 1; + break; + } + else { + err(s, _("All hunks decided (use '?' for help)")); + continue; + } + } strbuf_reset(&s->buf); if (file_diff->hunk_nr) { - if (rendered_hunk_index != hunk_index) { + if (rendered_hunk_index != hunk_index || skip_what_now == 1) { if (use_pager) { setup_pager(the_repository); sigchain_push(SIGPIPE, SIG_IGN); @@ -1586,12 +1635,18 @@ static int patch_update_file(struct add_p_state *s, if (ch == 'y') { hunk->use = USE_HUNK; soft_increment: - hunk_index = undecided_next < 0 ? - file_diff->hunk_nr : undecided_next; + if (skip_what_now) { + hunk_index = inc_mod(hunk_index, file_diff->hunk_nr); + skip_what_now = 0; + } else + hunk_index = undecided_next < 0 ? + file_diff->hunk_nr : undecided_next; } else if (ch == 'n') { hunk->use = SKIP_HUNK; goto soft_increment; } else if (ch == 'a') { + if (skip_what_now) + skip_what_now = 0; if (file_diff->hunk_nr) { for (; hunk_index < file_diff->hunk_nr; hunk_index++) { hunk = file_diff->hunk + hunk_index; @@ -1604,6 +1659,8 @@ static int patch_update_file(struct add_p_state *s, hunk->use = USE_HUNK; } } else if (ch == 'd') { + if (skip_what_now) + skip_what_now = 0; if (file_diff->hunk_nr) { for (; hunk_index < file_diff->hunk_nr; hunk_index++) { hunk = file_diff->hunk + hunk_index; @@ -1616,6 +1673,8 @@ static int patch_update_file(struct add_p_state *s, hunk->use = SKIP_HUNK; } } else if (ch == 'q') { + if (skip_what_now) + skip_what_now = 0; quit = 1; break; } else if (s->answer.buf[0] == 'K') { -- 2.39.5 (Apple Git-154)