Skip to content

Commit fdae5e5

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 7a8fea2 commit fdae5e5

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 {
@@ -953,6 +953,7 @@ static size_t display_hunks(struct add_p_state *s,
953953
static const char help_patch_text[] =
954954
N_("y - stage this hunk\n"
955955
"n - do not stage this hunk\n"
956+
"q - quit; do not stage this hunk or any of the remaining ones\n"
956957
"a - stage this and all the remaining hunks\n"
957958
"d - do not stage this hunk nor any of the remaining hunks\n"
958959
"j - leave this hunk undecided, see next undecided hunk\n"
@@ -973,7 +974,7 @@ static int patch_update_file(struct add_p_state *s,
973974
struct hunk *hunk;
974975
char ch;
975976
struct child_process cp = CHILD_PROCESS_INIT;
976-
int colored = !!s->colored.len;
977+
int colored = !!s->colored.len, quit = 0;
977978
enum prompt_mode_type prompt_mode_type;
978979

979980
if (!file_diff->hunk_nr)
@@ -1060,12 +1061,16 @@ static int patch_update_file(struct add_p_state *s,
10601061
if (hunk->use == UNDECIDED_HUNK)
10611062
hunk->use = USE_HUNK;
10621063
}
1063-
} else if (ch == 'd') {
1064+
} else if (ch == 'd' || ch == 'q') {
10641065
for (; hunk_index < file_diff->hunk_nr; hunk_index++) {
10651066
hunk = file_diff->hunk + hunk_index;
10661067
if (hunk->use == UNDECIDED_HUNK)
10671068
hunk->use = SKIP_HUNK;
10681069
}
1070+
if (ch == 'q') {
1071+
quit = 1;
1072+
break;
1073+
}
10691074
} else if (s->answer.buf[0] == 'K') {
10701075
if (hunk_index)
10711076
hunk_index--;
@@ -1207,7 +1212,7 @@ static int patch_update_file(struct add_p_state *s,
12071212
}
12081213

12091214
putchar('\n');
1210-
return 0;
1215+
return quit;
12111216
}
12121217

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

0 commit comments

Comments
 (0)