Skip to content

Commit ade246e

Browse files
dschogitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6cf873 commit ade246e

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 {
@@ -1006,6 +1006,7 @@ static size_t display_hunks(struct add_p_state *s,
10061006
static const char help_patch_text[] =
10071007
N_("y - stage this hunk\n"
10081008
"n - do not stage this hunk\n"
1009+
"q - quit; do not stage this hunk or any of the remaining ones\n"
10091010
"a - stage this and all the remaining hunks\n"
10101011
"d - do not stage this hunk nor any of the remaining hunks\n"
10111012
"j - leave this hunk undecided, see next undecided hunk\n"
@@ -1026,7 +1027,7 @@ static int patch_update_file(struct add_p_state *s,
10261027
struct hunk *hunk;
10271028
char ch;
10281029
struct child_process cp = CHILD_PROCESS_INIT;
1029-
int colored = !!s->colored.len;
1030+
int colored = !!s->colored.len, quit = 0;
10301031
enum prompt_mode_type prompt_mode_type;
10311032

10321033
if (!file_diff->hunk_nr)
@@ -1115,12 +1116,16 @@ static int patch_update_file(struct add_p_state *s,
11151116
if (hunk->use == UNDECIDED_HUNK)
11161117
hunk->use = USE_HUNK;
11171118
}
1118-
} else if (ch == 'd') {
1119+
} else if (ch == 'd' || ch == 'q') {
11191120
for (; hunk_index < file_diff->hunk_nr; hunk_index++) {
11201121
hunk = file_diff->hunk + hunk_index;
11211122
if (hunk->use == UNDECIDED_HUNK)
11221123
hunk->use = SKIP_HUNK;
11231124
}
1125+
if (ch == 'q') {
1126+
quit = 1;
1127+
break;
1128+
}
11241129
} else if (s->answer.buf[0] == 'K') {
11251130
if (hunk_index)
11261131
hunk_index--;
@@ -1267,7 +1272,7 @@ static int patch_update_file(struct add_p_state *s,
12671272
}
12681273

12691274
putchar('\n');
1270-
return 0;
1275+
return quit;
12711276
}
12721277

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

0 commit comments

Comments
 (0)