@@ -238,6 +238,7 @@ struct hunk_header {
238
238
* include the newline.
239
239
*/
240
240
size_t extra_start , extra_end , colored_extra_start , colored_extra_end ;
241
+ unsigned suppress_colored_line_range :1 ;
241
242
};
242
243
243
244
struct hunk {
@@ -358,15 +359,14 @@ static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk)
358
359
if (!eol )
359
360
eol = s -> colored .buf + s -> colored .len ;
360
361
p = memmem (line , eol - line , "@@ -" , 4 );
361
- if (! p )
362
- return error ( _ ( "could not parse colored hunk header '%.*s'" ),
363
- ( int )( eol - line ), line );
364
- p = memmem ( p + 4 , eol - p - 4 , " @@" , 3 );
365
- if (! p )
366
- return error ( _ ( "could not parse colored hunk header '%.*s'" ),
367
- ( int )( eol - line ), line );
362
+ if (p && ( p = memmem ( p + 4 , eol - p - 4 , " @@" , 3 ))) {
363
+ header -> colored_extra_start = p + 3 - s -> colored . buf ;
364
+ } else {
365
+ /* could not parse colored hunk header, leave as-is */
366
+ header -> colored_extra_start = hunk -> colored_start ;
367
+ header -> suppress_colored_line_range = 1 ;
368
+ }
368
369
hunk -> colored_start = eol - s -> colored .buf + (* eol == '\n' );
369
- header -> colored_extra_start = p + 3 - s -> colored .buf ;
370
370
header -> colored_extra_end = hunk -> colored_start ;
371
371
372
372
return 0 ;
@@ -419,7 +419,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
419
419
}
420
420
color_arg_index = args .nr ;
421
421
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
422
- strvec_pushl (& args , "--no-color" , "-p" , "--" , NULL );
422
+ strvec_pushl (& args , "--no-color" , "--ignore-submodules=dirty" , "-p" ,
423
+ "--" , NULL );
423
424
for (i = 0 ; i < ps -> nr ; i ++ )
424
425
strvec_push (& args , ps -> items [i ].original );
425
426
@@ -592,7 +593,10 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
592
593
if (colored_eol )
593
594
colored_p = colored_eol + 1 ;
594
595
else if (p != pend )
595
- /* colored shorter than non-colored? */
596
+ /* non-colored has more lines? */
597
+ goto mismatched_output ;
598
+ else if (colored_p == colored_pend )
599
+ /* last line has no matching colored one? */
596
600
goto mismatched_output ;
597
601
else
598
602
colored_p = colored_pend ;
@@ -656,6 +660,15 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
656
660
if (!colored ) {
657
661
p = s -> plain .buf + header -> extra_start ;
658
662
len = header -> extra_end - header -> extra_start ;
663
+ } else if (header -> suppress_colored_line_range ) {
664
+ strbuf_add (out ,
665
+ s -> colored .buf + header -> colored_extra_start ,
666
+ header -> colored_extra_end -
667
+ header -> colored_extra_start );
668
+
669
+ strbuf_add (out , s -> colored .buf + hunk -> colored_start ,
670
+ hunk -> colored_end - hunk -> colored_start );
671
+ return ;
659
672
} else {
660
673
strbuf_addstr (out , s -> s .fraginfo_color );
661
674
p = s -> colored .buf + header -> colored_extra_start ;
0 commit comments