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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 13, 2019 at 08:08 UTC
ade246efed509a68348901e7a085ceb55915bfea
1 file changed
+11
-6
add-patch.c
+11
-6
@@ -12,9 +12,9 @@ enum prompt_mode_type {
12
};
13
14
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,?]? ")
18
};
19
20
struct hunk_header {
@@ -1006,6 +1006,7 @@ static size_t display_hunks(struct add_p_state *s,
1006
static const char help_patch_text[] =
1007
N_("y - stage this hunk\n"
1008
"n - do not stage this hunk\n"
1009
+ "q - quit; do not stage this hunk or any of the remaining ones\n"
1010
"a - stage this and all the remaining hunks\n"
1011
"d - do not stage this hunk nor any of the remaining hunks\n"
1012
"j - leave this hunk undecided, see next undecided hunk\n"
@@ -1026,7 +1027,7 @@ static int patch_update_file(struct add_p_state *s,
1027
struct hunk *hunk;
1028
char ch;
1029
struct child_process cp = CHILD_PROCESS_INIT;
1029
- int colored = !!s->colored.len;
1030
+ int colored = !!s->colored.len, quit = 0;
1031
enum prompt_mode_type prompt_mode_type;
1032
1033
if (!file_diff->hunk_nr)
@@ -1115,12 +1116,16 @@ soft_increment:
1116
if (hunk->use == UNDECIDED_HUNK)
1117
hunk->use = USE_HUNK;
1118
}
1118
- } else if (ch == 'd') {
1119
+ } else if (ch == 'd' || ch == 'q') {
1120
for (; hunk_index < file_diff->hunk_nr; hunk_index++) {
1121
hunk = file_diff->hunk + hunk_index;
1122
if (hunk->use == UNDECIDED_HUNK)
1123
hunk->use = SKIP_HUNK;
1124
}
1125
+ if (ch == 'q') {
1126
+ quit = 1;
1127
+ break;
1128
+ }
1129
} else if (s->answer.buf[0] == 'K') {
1130
if (hunk_index)
1131
hunk_index--;
@@ -1267,7 +1272,7 @@ soft_increment:
1272
}
1273
1274
putchar('\n');
1270
- return 0;
1275
+ return quit;
1276
}
1277
1278
int run_add_p(struct repository *r, const struct pathspec *ps)