]> git.ipfire.org Git - thirdparty/git.git/commitdiff
built-in add -p: show different prompts for mode changes and deletions
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 13 Dec 2019 08:07:57 +0000 (08:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Dec 2019 20:37:14 +0000 (12:37 -0800)
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-patch.c

index 2007f55e0431cfc43c69827105dd87ebf7d915d4..171025b08d6a4e61a8069637ff938886965a09b1 100644 (file)
@@ -7,6 +7,16 @@
 #include "color.h"
 #include "diff.h"
 
+enum prompt_mode_type {
+       PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_HUNK
+};
+
+static const char *prompt_mode[] = {
+       N_("Stage mode change [y,n,a,d%s,?]? "),
+       N_("Stage deletion [y,n,a,d%s,?]? "),
+       N_("Stage this hunk [y,n,a,d%s,?]? ")
+};
+
 struct hunk_header {
        unsigned long old_offset, old_count, new_offset, new_count;
        /*
@@ -422,6 +432,7 @@ static int patch_update_file(struct add_p_state *s,
        char ch;
        struct child_process cp = CHILD_PROCESS_INIT;
        int colored = !!s->colored.len;
+       enum prompt_mode_type prompt_mode_type;
 
        if (!file_diff->hunk_nr)
                return 0;
@@ -466,13 +477,20 @@ static int patch_update_file(struct add_p_state *s,
                        strbuf_addstr(&s->buf, ",j");
                if (hunk_index + 1 < file_diff->hunk_nr)
                        strbuf_addstr(&s->buf, ",J");
+
+               if (file_diff->deleted)
+                       prompt_mode_type = PROMPT_DELETION;
+               else if (file_diff->mode_change && !hunk_index)
+                       prompt_mode_type = PROMPT_MODE_CHANGE;
+               else
+                       prompt_mode_type = PROMPT_HUNK;
+
                color_fprintf(stdout, s->s.prompt_color,
                              "(%"PRIuMAX"/%"PRIuMAX") ",
                              (uintmax_t)hunk_index + 1,
                              (uintmax_t)file_diff->hunk_nr);
                color_fprintf(stdout, s->s.prompt_color,
-                             _("Stage this hunk [y,n,a,d%s,?]? "),
-                             s->buf.buf);
+                             _(prompt_mode[prompt_mode_type]), s->buf.buf);
                fflush(stdout);
                if (strbuf_getline(&s->answer, stdin) == EOF)
                        break;