@@ -34,6 +34,17 @@ struct add_p_state {
34
34
size_t hunk_nr , hunk_alloc ;
35
35
};
36
36
37
+ static void err (struct add_p_state * s , const char * fmt , ...)
38
+ {
39
+ va_list args ;
40
+
41
+ va_start (args , fmt );
42
+ fputs (s -> s .error_color , stderr );
43
+ vfprintf (stderr , fmt , args );
44
+ fputs (s -> s .reset_color , stderr );
45
+ fputc ('\n' , stderr );
46
+ }
47
+
37
48
static void setup_child_process (struct child_process * cp ,
38
49
struct add_p_state * s , ...)
39
50
{
@@ -364,17 +375,27 @@ static int patch_update_file(struct add_p_state *s)
364
375
if (hunk -> use == UNDECIDED_HUNK )
365
376
hunk -> use = SKIP_HUNK ;
366
377
}
367
- } else if (hunk_index && s -> answer .buf [0 ] == 'K' )
368
- hunk_index -- ;
369
- else if (hunk_index + 1 < s -> hunk_nr &&
370
- s -> answer .buf [0 ] == 'J' )
371
- hunk_index ++ ;
372
- else if (undecided_previous >= 0 &&
373
- s -> answer .buf [0 ] == 'k' )
374
- hunk_index = undecided_previous ;
375
- else if (undecided_next >= 0 && s -> answer .buf [0 ] == 'j' )
376
- hunk_index = undecided_next ;
377
- else
378
+ } else if (s -> answer .buf [0 ] == 'K' ) {
379
+ if (hunk_index )
380
+ hunk_index -- ;
381
+ else
382
+ err (s , _ ("No previous hunk" ));
383
+ } else if (s -> answer .buf [0 ] == 'J' ) {
384
+ if (hunk_index + 1 < s -> hunk_nr )
385
+ hunk_index ++ ;
386
+ else
387
+ err (s , _ ("No next hunk" ));
388
+ } else if (s -> answer .buf [0 ] == 'k' ) {
389
+ if (undecided_previous >= 0 )
390
+ hunk_index = undecided_previous ;
391
+ else
392
+ err (s , _ ("No previous hunk" ));
393
+ } else if (s -> answer .buf [0 ] == 'j' ) {
394
+ if (undecided_next >= 0 )
395
+ hunk_index = undecided_next ;
396
+ else
397
+ err (s , _ ("No next hunk" ));
398
+ } else
378
399
color_fprintf (stdout , s -> s .help_color ,
379
400
_ (help_patch_text ));
380
401
}
0 commit comments