@@ -526,7 +526,8 @@ static void show_line_to_eol(const char *line, int len, const char *reset)
526526 saw_cr_at_eol ? "\r" : "" );
527527}
528528
529- static void dump_sline (struct sline * sline , unsigned long cnt , int num_parent ,
529+ static void dump_sline (struct sline * sline , const char * line_prefix ,
530+ unsigned long cnt , int num_parent ,
530531 int use_color , int result_deleted )
531532{
532533 unsigned long mark = (1UL <<num_parent );
@@ -582,7 +583,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
582583 rlines -= null_context ;
583584 }
584585
585- fputs ( c_frag , stdout );
586+ printf ( "%s%s" , line_prefix , c_frag );
586587 for (i = 0 ; i <= num_parent ; i ++ ) putchar (combine_marker );
587588 for (i = 0 ; i < num_parent ; i ++ )
588589 show_parent_lno (sline , lno , hunk_end , i , null_context );
@@ -614,7 +615,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
614615 struct sline * sl = & sline [lno ++ ];
615616 ll = (sl -> flag & no_pre_delete ) ? NULL : sl -> lost_head ;
616617 while (ll ) {
617- fputs ( c_old , stdout );
618+ printf ( "%s%s" , line_prefix , c_old );
618619 for (j = 0 ; j < num_parent ; j ++ ) {
619620 if (ll -> parent_map & (1UL <<j ))
620621 putchar ('-' );
@@ -627,6 +628,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,
627628 if (cnt < lno )
628629 break ;
629630 p_mask = 1 ;
631+ fputs (line_prefix , stdout );
630632 if (!(sl -> flag & (mark - 1 ))) {
631633 /*
632634 * This sline was here to hang the
@@ -680,11 +682,13 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
680682static void dump_quoted_path (const char * head ,
681683 const char * prefix ,
682684 const char * path ,
685+ const char * line_prefix ,
683686 const char * c_meta , const char * c_reset )
684687{
685688 static struct strbuf buf = STRBUF_INIT ;
686689
687690 strbuf_reset (& buf );
691+ strbuf_addstr (& buf , line_prefix );
688692 strbuf_addstr (& buf , c_meta );
689693 strbuf_addstr (& buf , head );
690694 quote_two_c_style (& buf , prefix , path , 0 );
@@ -696,6 +700,7 @@ static void show_combined_header(struct combine_diff_path *elem,
696700 int num_parent ,
697701 int dense ,
698702 struct rev_info * rev ,
703+ const char * line_prefix ,
699704 int mode_differs ,
700705 int show_file_header )
701706{
@@ -714,8 +719,8 @@ static void show_combined_header(struct combine_diff_path *elem,
714719 show_log (rev );
715720
716721 dump_quoted_path (dense ? "diff --cc " : "diff --combined " ,
717- "" , elem -> path , c_meta , c_reset );
718- printf ("%sindex " , c_meta );
722+ "" , elem -> path , line_prefix , c_meta , c_reset );
723+ printf ("%s% sindex " , line_prefix , c_meta );
719724 for (i = 0 ; i < num_parent ; i ++ ) {
720725 abb = find_unique_abbrev (elem -> parent [i ].sha1 ,
721726 abbrev );
@@ -734,11 +739,12 @@ static void show_combined_header(struct combine_diff_path *elem,
734739 DIFF_STATUS_ADDED )
735740 added = 0 ;
736741 if (added )
737- printf ("%snew file mode %06o" ,
738- c_meta , elem -> mode );
742+ printf ("%s% snew file mode %06o" ,
743+ line_prefix , c_meta , elem -> mode );
739744 else {
740745 if (deleted )
741- printf ("%sdeleted file " , c_meta );
746+ printf ("%s%sdeleted file " ,
747+ line_prefix , c_meta );
742748 printf ("mode " );
743749 for (i = 0 ; i < num_parent ; i ++ ) {
744750 printf ("%s%06o" , i ? "," : "" ,
@@ -755,16 +761,16 @@ static void show_combined_header(struct combine_diff_path *elem,
755761
756762 if (added )
757763 dump_quoted_path ("--- " , "" , "/dev/null" ,
758- c_meta , c_reset );
764+ line_prefix , c_meta , c_reset );
759765 else
760766 dump_quoted_path ("--- " , a_prefix , elem -> path ,
761- c_meta , c_reset );
767+ line_prefix , c_meta , c_reset );
762768 if (deleted )
763769 dump_quoted_path ("+++ " , "" , "/dev/null" ,
764- c_meta , c_reset );
770+ line_prefix , c_meta , c_reset );
765771 else
766772 dump_quoted_path ("+++ " , b_prefix , elem -> path ,
767- c_meta , c_reset );
773+ line_prefix , c_meta , c_reset );
768774}
769775
770776static void show_patch_diff (struct combine_diff_path * elem , int num_parent ,
@@ -782,6 +788,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
782788 struct userdiff_driver * userdiff ;
783789 struct userdiff_driver * textconv = NULL ;
784790 int is_binary ;
791+ const char * line_prefix = diff_line_prefix (opt );
785792
786793 context = opt -> context ;
787794 userdiff = userdiff_find_by_path (elem -> path );
@@ -901,7 +908,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
901908 }
902909 if (is_binary ) {
903910 show_combined_header (elem , num_parent , dense , rev ,
904- mode_differs , 0 );
911+ line_prefix , mode_differs , 0 );
905912 printf ("Binary files differ\n" );
906913 free (result );
907914 return ;
@@ -962,8 +969,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
962969
963970 if (show_hunks || mode_differs || working_tree_file ) {
964971 show_combined_header (elem , num_parent , dense , rev ,
965- mode_differs , 1 );
966- dump_sline (sline , cnt , num_parent ,
972+ line_prefix , mode_differs , 1 );
973+ dump_sline (sline , line_prefix , cnt , num_parent ,
967974 opt -> use_color , result_deleted );
968975 }
969976 free (result );
@@ -986,6 +993,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
986993{
987994 struct diff_options * opt = & rev -> diffopt ;
988995 int line_termination , inter_name_termination , i ;
996+ const char * line_prefix = diff_line_prefix (opt );
989997
990998 line_termination = opt -> line_termination ;
991999 inter_name_termination = '\t' ;
@@ -995,7 +1003,10 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
9951003 if (rev -> loginfo && !rev -> no_commit_id )
9961004 show_log (rev );
9971005
1006+
9981007 if (opt -> output_format & DIFF_FORMAT_RAW ) {
1008+ printf ("%s" , line_prefix );
1009+
9991010 /* As many colons as there are parents */
10001011 for (i = 0 ; i < num_parent ; i ++ )
10011012 putchar (':' );
@@ -1033,6 +1044,7 @@ void show_combined_diff(struct combine_diff_path *p,
10331044 struct rev_info * rev )
10341045{
10351046 struct diff_options * opt = & rev -> diffopt ;
1047+
10361048 if (!p -> len )
10371049 return ;
10381050 if (opt -> output_format & (DIFF_FORMAT_RAW |
@@ -1143,8 +1155,10 @@ void diff_tree_combined(const unsigned char *sha1,
11431155
11441156 if (show_log_first && i == 0 ) {
11451157 show_log (rev );
1158+
11461159 if (rev -> verbose_header && opt -> output_format )
1147- putchar (opt -> line_termination );
1160+ printf ("%s%c" , diff_line_prefix (opt ),
1161+ opt -> line_termination );
11481162 }
11491163 diff_flush (& diffopts );
11501164 }
@@ -1172,7 +1186,8 @@ void diff_tree_combined(const unsigned char *sha1,
11721186
11731187 if (opt -> output_format & DIFF_FORMAT_PATCH ) {
11741188 if (needsep )
1175- putchar (opt -> line_termination );
1189+ printf ("%s%c" , diff_line_prefix (opt ),
1190+ opt -> line_termination );
11761191 for (p = paths ; p ; p = p -> next ) {
11771192 if (p -> len )
11781193 show_patch_diff (p , num_parent , dense ,
0 commit comments