Skip to content

Commit 590a241

Browse files
committed
built-in add -p: show different prompts for mode changes and deletions
Just like the Perl version, we now helpfully ask the user whether they want to stage a mode change, or a deletion. Note that we define the prompts in an array, in preparation for a later patch that changes those prompts to yet different versions for `git reset -p`, `git stash -p` and `git checkout -p` (which all call the `git add -p` machinery to do the actual work). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 21be306 commit 590a241

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

add-patch.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
#include "color.h"
88
#include "diff.h"
99

10+
enum prompt_mode_type {
11+
PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_HUNK
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,?]? ")
18+
};
19+
1020
struct hunk_header {
1121
unsigned long old_offset, old_count, new_offset, new_count;
1222
/*
@@ -389,6 +399,7 @@ static int patch_update_file(struct add_p_state *s,
389399
char ch;
390400
struct child_process cp = CHILD_PROCESS_INIT;
391401
int colored = !!s->colored.len;
402+
enum prompt_mode_type prompt_mode_type;
392403

393404
if (!file_diff->hunk_nr)
394405
return 0;
@@ -433,9 +444,16 @@ static int patch_update_file(struct add_p_state *s,
433444
strbuf_addstr(&s->buf, ",j");
434445
if (hunk_index + 1 < file_diff->hunk_nr)
435446
strbuf_addstr(&s->buf, ",J");
447+
448+
if (file_diff->deleted)
449+
prompt_mode_type = PROMPT_DELETION;
450+
else if (file_diff->mode_change && !hunk_index)
451+
prompt_mode_type = PROMPT_MODE_CHANGE;
452+
else
453+
prompt_mode_type = PROMPT_HUNK;
454+
436455
color_fprintf(stdout, s->s.prompt_color,
437-
_("Stage this hunk [y,n,a,d%s,?]? "),
438-
s->buf.buf);
456+
_(prompt_mode[prompt_mode_type]), s->buf.buf);
439457
fflush(stdout);
440458
if (strbuf_getline(&s->answer, stdin) == EOF)
441459
break;

0 commit comments

Comments
 (0)