@@ -34,6 +34,18 @@ 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
+ va_end (args );
47
+ }
48
+
37
49
static void setup_child_process (struct child_process * cp ,
38
50
struct add_p_state * s , ...)
39
51
{
@@ -364,17 +376,27 @@ static int patch_update_file(struct add_p_state *s)
364
376
if (hunk -> use == UNDECIDED_HUNK )
365
377
hunk -> use = SKIP_HUNK ;
366
378
}
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
379
+ } else if (s -> answer .buf [0 ] == 'K' ) {
380
+ if (hunk_index )
381
+ hunk_index -- ;
382
+ else
383
+ err (s , _ ("No previous hunk" ));
384
+ } else if (s -> answer .buf [0 ] == 'J' ) {
385
+ if (hunk_index + 1 < s -> hunk_nr )
386
+ hunk_index ++ ;
387
+ else
388
+ err (s , _ ("No next hunk" ));
389
+ } else if (s -> answer .buf [0 ] == 'k' ) {
390
+ if (undecided_previous >= 0 )
391
+ hunk_index = undecided_previous ;
392
+ else
393
+ err (s , _ ("No previous hunk" ));
394
+ } else if (s -> answer .buf [0 ] == 'j' ) {
395
+ if (undecided_next >= 0 )
396
+ hunk_index = undecided_next ;
397
+ else
398
+ err (s , _ ("No next hunk" ));
399
+ } else
378
400
color_fprintf (stdout , s -> s .help_color ,
379
401
_ (help_patch_text ));
380
402
}
0 commit comments