Skip to content

Commit 214e5b1

Browse files
committed
built-in add -p: implement the 'q' ("quit") command
This command is actually very similar to the 'd' ("do not stage this hunk or any of the later hunks in the file") command: it just does something on top, namely leave the loop and return a value indicating that we're quittin'. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7fc8ca6 commit 214e5b1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

add-patch.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ enum prompt_mode_type {
1212
};
1313

1414
static const char *prompt_mode[] = {
15-
N_("Stage mode change [y,n,a,d%s,?]? "),
16-
N_("Stage deletion [y,n,a,d%s,?]? "),
17-
N_("Stage this hunk [y,n,a,d%s,?]? ")
15+
N_("Stage mode change [y,n,a,q,d%s,?]? "),
16+
N_("Stage deletion [y,n,a,q,d%s,?]? "),
17+
N_("Stage this hunk [y,n,a,q,d%s,?]? ")
1818
};
1919

2020
struct hunk_header {
@@ -954,6 +954,7 @@ static size_t display_hunks(struct add_p_state *s,
954954
static const char help_patch_text[] =
955955
N_("y - stage this hunk\n"
956956
"n - do not stage this hunk\n"
957+
"q - quit; do not stage this hunk or any of the remaining ones\n"
957958
"a - stage this and all the remaining hunks\n"
958959
"d - do not stage this hunk nor any of the remaining hunks\n"
959960
"j - leave this hunk undecided, see next undecided hunk\n"
@@ -974,7 +975,7 @@ static int patch_update_file(struct add_p_state *s,
974975
struct hunk *hunk;
975976
char ch;
976977
struct child_process cp = CHILD_PROCESS_INIT;
977-
int colored = !!s->colored.len;
978+
int colored = !!s->colored.len, quit = 0;
978979
enum prompt_mode_type prompt_mode_type;
979980

980981
if (!file_diff->hunk_nr)
@@ -1061,12 +1062,16 @@ static int patch_update_file(struct add_p_state *s,
10611062
if (hunk->use == UNDECIDED_HUNK)
10621063
hunk->use = USE_HUNK;
10631064
}
1064-
} else if (ch == 'd') {
1065+
} else if (ch == 'd' || ch == 'q') {
10651066
for (; hunk_index < file_diff->hunk_nr; hunk_index++) {
10661067
hunk = file_diff->hunk + hunk_index;
10671068
if (hunk->use == UNDECIDED_HUNK)
10681069
hunk->use = SKIP_HUNK;
10691070
}
1071+
if (ch == 'q') {
1072+
quit = 1;
1073+
break;
1074+
}
10701075
} else if (s->answer.buf[0] == 'K') {
10711076
if (hunk_index)
10721077
hunk_index--;
@@ -1208,7 +1213,7 @@ static int patch_update_file(struct add_p_state *s,
12081213
}
12091214

12101215
putchar('\n');
1211-
return 0;
1216+
return quit;
12121217
}
12131218

12141219
int run_add_p(struct repository *r, const struct pathspec *ps)

0 commit comments

Comments
 (0)