9
9
#include "compat/terminal.h"
10
10
11
11
enum prompt_mode_type {
12
- PROMPT_MODE_CHANGE = 0 , PROMPT_DELETION , PROMPT_HUNK ,
12
+ PROMPT_MODE_CHANGE = 0 , PROMPT_DELETION , PROMPT_ADDITION , PROMPT_HUNK ,
13
13
PROMPT_MODE_MAX , /* must be last */
14
14
};
15
15
@@ -32,6 +32,7 @@ static struct patch_mode patch_mode_add = {
32
32
.prompt_mode = {
33
33
N_ ("Stage mode change [y,n,q,a,d%s,?]? " ),
34
34
N_ ("Stage deletion [y,n,q,a,d%s,?]? " ),
35
+ N_ ("Stage addition [y,n,q,a,d%s,?]? " ),
35
36
N_ ("Stage this hunk [y,n,q,a,d%s,?]? " )
36
37
},
37
38
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -53,6 +54,7 @@ static struct patch_mode patch_mode_stash = {
53
54
.prompt_mode = {
54
55
N_ ("Stash mode change [y,n,q,a,d%s,?]? " ),
55
56
N_ ("Stash deletion [y,n,q,a,d%s,?]? " ),
57
+ N_ ("Stash addition [y,n,q,a,d%s,?]? " ),
56
58
N_ ("Stash this hunk [y,n,q,a,d%s,?]? " ),
57
59
},
58
60
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -76,6 +78,7 @@ static struct patch_mode patch_mode_reset_head = {
76
78
.prompt_mode = {
77
79
N_ ("Unstage mode change [y,n,q,a,d%s,?]? " ),
78
80
N_ ("Unstage deletion [y,n,q,a,d%s,?]? " ),
81
+ N_ ("Unstage addition [y,n,q,a,d%s,?]? " ),
79
82
N_ ("Unstage this hunk [y,n,q,a,d%s,?]? " ),
80
83
},
81
84
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -98,6 +101,7 @@ static struct patch_mode patch_mode_reset_nothead = {
98
101
.prompt_mode = {
99
102
N_ ("Apply mode change to index [y,n,q,a,d%s,?]? " ),
100
103
N_ ("Apply deletion to index [y,n,q,a,d%s,?]? " ),
104
+ N_ ("Apply addition to index [y,n,q,a,d%s,?]? " ),
101
105
N_ ("Apply this hunk to index [y,n,q,a,d%s,?]? " ),
102
106
},
103
107
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -120,6 +124,7 @@ static struct patch_mode patch_mode_checkout_index = {
120
124
.prompt_mode = {
121
125
N_ ("Discard mode change from worktree [y,n,q,a,d%s,?]? " ),
122
126
N_ ("Discard deletion from worktree [y,n,q,a,d%s,?]? " ),
127
+ N_ ("Discard addition from worktree [y,n,q,a,d%s,?]? " ),
123
128
N_ ("Discard this hunk from worktree [y,n,q,a,d%s,?]? " ),
124
129
},
125
130
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -142,6 +147,7 @@ static struct patch_mode patch_mode_checkout_head = {
142
147
.prompt_mode = {
143
148
N_ ("Discard mode change from index and worktree [y,n,q,a,d%s,?]? " ),
144
149
N_ ("Discard deletion from index and worktree [y,n,q,a,d%s,?]? " ),
150
+ N_ ("Discard addition from index and worktree [y,n,q,a,d%s,?]? " ),
145
151
N_ ("Discard this hunk from index and worktree [y,n,q,a,d%s,?]? " ),
146
152
},
147
153
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -163,6 +169,7 @@ static struct patch_mode patch_mode_checkout_nothead = {
163
169
.prompt_mode = {
164
170
N_ ("Apply mode change to index and worktree [y,n,q,a,d%s,?]? " ),
165
171
N_ ("Apply deletion to index and worktree [y,n,q,a,d%s,?]? " ),
172
+ N_ ("Apply addition to index and worktree [y,n,q,a,d%s,?]? " ),
166
173
N_ ("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? " ),
167
174
},
168
175
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -185,6 +192,7 @@ static struct patch_mode patch_mode_worktree_head = {
185
192
.prompt_mode = {
186
193
N_ ("Discard mode change from index and worktree [y,n,q,a,d%s,?]? " ),
187
194
N_ ("Discard deletion from index and worktree [y,n,q,a,d%s,?]? " ),
195
+ N_ ("Discard addition from index and worktree [y,n,q,a,d%s,?]? " ),
188
196
N_ ("Discard this hunk from index and worktree [y,n,q,a,d%s,?]? " ),
189
197
},
190
198
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -206,6 +214,7 @@ static struct patch_mode patch_mode_worktree_nothead = {
206
214
.prompt_mode = {
207
215
N_ ("Apply mode change to index and worktree [y,n,q,a,d%s,?]? " ),
208
216
N_ ("Apply deletion to index and worktree [y,n,q,a,d%s,?]? " ),
217
+ N_ ("Apply addition to index and worktree [y,n,q,a,d%s,?]? " ),
209
218
N_ ("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? " ),
210
219
},
211
220
.edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
@@ -247,7 +256,7 @@ struct add_p_state {
247
256
struct hunk head ;
248
257
struct hunk * hunk ;
249
258
size_t hunk_nr , hunk_alloc ;
250
- unsigned deleted :1 , mode_change :1 ,binary :1 ;
259
+ unsigned deleted :1 , added : 1 , mode_change :1 ,binary :1 ;
251
260
} * file_diff ;
252
261
size_t file_diff_nr ;
253
262
@@ -441,7 +450,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
441
450
pend = p + plain -> len ;
442
451
while (p != pend ) {
443
452
char * eol = memchr (p , '\n' , pend - p );
444
- const char * deleted = NULL , * mode_change = NULL ;
453
+ const char * deleted = NULL , * added = NULL , * mode_change = NULL ;
445
454
446
455
if (!eol )
447
456
eol = pend ;
@@ -460,11 +469,12 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
460
469
} else if (p == plain -> buf )
461
470
BUG ("diff starts with unexpected line:\n"
462
471
"%.*s\n" , (int )(eol - p ), p );
463
- else if (file_diff -> deleted )
472
+ else if (file_diff -> deleted || file_diff -> added )
464
473
; /* keep the rest of the file in a single "hunk" */
465
474
else if (starts_with (p , "@@ " ) ||
466
475
(hunk == & file_diff -> head &&
467
- skip_prefix (p , "deleted file" , & deleted ))) {
476
+ (skip_prefix (p , "deleted file" , & deleted ) ||
477
+ skip_prefix (p , "new file" , & added )))) {
468
478
if (marker == '-' || marker == '+' )
469
479
/*
470
480
* Should not happen; previous hunk did not end
@@ -484,6 +494,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
484
494
485
495
if (deleted )
486
496
file_diff -> deleted = 1 ;
497
+ else if (added )
498
+ file_diff -> added = 1 ;
487
499
else if (parse_hunk_header (s , hunk ) < 0 )
488
500
return -1 ;
489
501
@@ -536,8 +548,10 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
536
548
starts_with (p , "Binary files " ))
537
549
file_diff -> binary = 1 ;
538
550
539
- if (file_diff -> deleted && file_diff -> mode_change )
540
- BUG ("diff contains delete *and* a mode change?!?\n%.*s" ,
551
+ if (!!file_diff -> deleted + !!file_diff -> added +
552
+ !!file_diff -> mode_change > 1 )
553
+ BUG ("diff can only contain delete *or* add *or* a "
554
+ "mode change?!?\n%.*s" ,
541
555
(int )(eol - (plain -> buf + file_diff -> head .start )),
542
556
plain -> buf + file_diff -> head .start );
543
557
@@ -1397,6 +1411,8 @@ static int patch_update_file(struct add_p_state *s,
1397
1411
1398
1412
if (file_diff -> deleted )
1399
1413
prompt_mode_type = PROMPT_DELETION ;
1414
+ else if (file_diff -> added )
1415
+ prompt_mode_type = PROMPT_ADDITION ;
1400
1416
else if (file_diff -> mode_change && !hunk_index )
1401
1417
prompt_mode_type = PROMPT_MODE_CHANGE ;
1402
1418
else
0 commit comments