@@ -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 );
@@ -990,6 +997,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
990997 int i , offset ;
991998 const char * prefix ;
992999 int line_termination , inter_name_termination ;
1000+ const char * line_prefix = diff_line_prefix (opt );
9931001
9941002 line_termination = opt -> line_termination ;
9951003 inter_name_termination = '\t' ;
@@ -1000,6 +1008,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
10001008 show_log (rev );
10011009
10021010 if (opt -> output_format & DIFF_FORMAT_RAW ) {
1011+ printf ("%s" , line_prefix );
10031012 offset = strlen (COLONS ) - num_parent ;
10041013 if (offset < 0 )
10051014 offset = 0 ;
@@ -1040,6 +1049,7 @@ void show_combined_diff(struct combine_diff_path *p,
10401049 struct rev_info * rev )
10411050{
10421051 struct diff_options * opt = & rev -> diffopt ;
1052+
10431053 if (!p -> len )
10441054 return ;
10451055 if (opt -> output_format & (DIFF_FORMAT_RAW |
@@ -1150,8 +1160,10 @@ void diff_tree_combined(const unsigned char *sha1,
11501160
11511161 if (show_log_first && i == 0 ) {
11521162 show_log (rev );
1163+
11531164 if (rev -> verbose_header && opt -> output_format )
1154- putchar (opt -> line_termination );
1165+ printf ("%s%c" , diff_line_prefix (opt ),
1166+ opt -> line_termination );
11551167 }
11561168 diff_flush (& diffopts );
11571169 }
@@ -1179,7 +1191,8 @@ void diff_tree_combined(const unsigned char *sha1,
11791191
11801192 if (opt -> output_format & DIFF_FORMAT_PATCH ) {
11811193 if (needsep )
1182- putchar (opt -> line_termination );
1194+ printf ("%s%c" , diff_line_prefix (opt ),
1195+ opt -> line_termination );
11831196 for (p = paths ; p ; p = p -> next ) {
11841197 if (p -> len )
11851198 show_patch_diff (p , num_parent , dense ,
0 commit comments