@@ -572,6 +572,7 @@ enum diff_symbol {
572
572
DIFF_SYMBOL_STATS_LINE ,
573
573
DIFF_SYMBOL_WORD_DIFF ,
574
574
DIFF_SYMBOL_STAT_SEP ,
575
+ DIFF_SYMBOL_SUMMARY ,
575
576
DIFF_SYMBOL_SUBMODULE_ADD ,
576
577
DIFF_SYMBOL_SUBMODULE_DEL ,
577
578
DIFF_SYMBOL_SUBMODULE_UNTRACKED ,
@@ -648,6 +649,7 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
648
649
case DIFF_SYMBOL_SUBMODULE_ERROR :
649
650
case DIFF_SYMBOL_SUBMODULE_PIPETHROUGH :
650
651
case DIFF_SYMBOL_STATS_SUMMARY_INSERTS_DELETES :
652
+ case DIFF_SYMBOL_SUMMARY :
651
653
case DIFF_SYMBOL_STATS_LINE :
652
654
case DIFF_SYMBOL_BINARY_DIFF_BODY :
653
655
case DIFF_SYMBOL_CONTEXT_FRAGINFO :
@@ -4717,67 +4719,76 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
4717
4719
}
4718
4720
}
4719
4721
4720
- static void show_file_mode_name (FILE * file , const char * newdelete , struct diff_filespec * fs )
4722
+ static void show_file_mode_name (struct diff_options * opt , const char * newdelete , struct diff_filespec * fs )
4721
4723
{
4724
+ struct strbuf sb = STRBUF_INIT ;
4722
4725
if (fs -> mode )
4723
- fprintf ( file , " %s mode %06o " , newdelete , fs -> mode );
4726
+ strbuf_addf ( & sb , " %s mode %06o " , newdelete , fs -> mode );
4724
4727
else
4725
- fprintf (file , " %s " , newdelete );
4726
- write_name_quoted (fs -> path , file , '\n' );
4727
- }
4728
+ strbuf_addf (& sb , " %s " , newdelete );
4728
4729
4730
+ quote_c_style (fs -> path , & sb , NULL , 0 );
4731
+ strbuf_addch (& sb , '\n' );
4732
+ emit_diff_symbol (opt , DIFF_SYMBOL_SUMMARY ,
4733
+ sb .buf , sb .len , 0 );
4734
+ strbuf_release (& sb );
4735
+ }
4729
4736
4730
- static void show_mode_change (FILE * file , struct diff_filepair * p , int show_name ,
4731
- const char * line_prefix )
4737
+ static void show_mode_change (struct diff_options * opt , struct diff_filepair * p ,
4738
+ int show_name )
4732
4739
{
4733
4740
if (p -> one -> mode && p -> two -> mode && p -> one -> mode != p -> two -> mode ) {
4734
- fprintf (file , "%s mode change %06o => %06o%c" , line_prefix , p -> one -> mode ,
4735
- p -> two -> mode , show_name ? ' ' : '\n' );
4741
+ struct strbuf sb = STRBUF_INIT ;
4742
+ strbuf_addf (& sb , " mode change %06o => %06o" ,
4743
+ p -> one -> mode , p -> two -> mode );
4736
4744
if (show_name ) {
4737
- write_name_quoted (p -> two -> path , file , '\n' );
4745
+ strbuf_addch (& sb , ' ' );
4746
+ quote_c_style (p -> two -> path , & sb , NULL , 0 );
4738
4747
}
4748
+ emit_diff_symbol (opt , DIFF_SYMBOL_SUMMARY ,
4749
+ sb .buf , sb .len , 0 );
4750
+ strbuf_release (& sb );
4739
4751
}
4740
4752
}
4741
4753
4742
- static void show_rename_copy (FILE * file , const char * renamecopy , struct diff_filepair * p ,
4743
- const char * line_prefix )
4754
+ static void show_rename_copy (struct diff_options * opt , const char * renamecopy ,
4755
+ struct diff_filepair * p )
4744
4756
{
4757
+ struct strbuf sb = STRBUF_INIT ;
4745
4758
char * names = pprint_rename (p -> one -> path , p -> two -> path );
4746
-
4747
- fprintf ( file , " %s %s (%d%%)\n" , renamecopy , names , similarity_index (p ));
4759
+ strbuf_addf ( & sb , " %s %s (%d%%)\n" ,
4760
+ renamecopy , names , similarity_index (p ));
4748
4761
free (names );
4749
- show_mode_change (file , p , 0 , line_prefix );
4762
+ emit_diff_symbol (opt , DIFF_SYMBOL_SUMMARY ,
4763
+ sb .buf , sb .len , 0 );
4764
+ show_mode_change (opt , p , 0 );
4750
4765
}
4751
4766
4752
4767
static void diff_summary (struct diff_options * opt , struct diff_filepair * p )
4753
4768
{
4754
- FILE * file = opt -> file ;
4755
- const char * line_prefix = diff_line_prefix (opt );
4756
-
4757
4769
switch (p -> status ) {
4758
4770
case DIFF_STATUS_DELETED :
4759
- fputs (line_prefix , file );
4760
- show_file_mode_name (file , "delete" , p -> one );
4771
+ show_file_mode_name (opt , "delete" , p -> one );
4761
4772
break ;
4762
4773
case DIFF_STATUS_ADDED :
4763
- fputs (line_prefix , file );
4764
- show_file_mode_name (file , "create" , p -> two );
4774
+ show_file_mode_name (opt , "create" , p -> two );
4765
4775
break ;
4766
4776
case DIFF_STATUS_COPIED :
4767
- fputs (line_prefix , file );
4768
- show_rename_copy (file , "copy" , p , line_prefix );
4777
+ show_rename_copy (opt , "copy" , p );
4769
4778
break ;
4770
4779
case DIFF_STATUS_RENAMED :
4771
- fputs (line_prefix , file );
4772
- show_rename_copy (file , "rename" , p , line_prefix );
4780
+ show_rename_copy (opt , "rename" , p );
4773
4781
break ;
4774
4782
default :
4775
4783
if (p -> score ) {
4776
- fprintf (file , "%s rewrite " , line_prefix );
4777
- write_name_quoted (p -> two -> path , file , ' ' );
4778
- fprintf (file , "(%d%%)\n" , similarity_index (p ));
4784
+ struct strbuf sb = STRBUF_INIT ;
4785
+ strbuf_addstr (& sb , " rewrite " );
4786
+ quote_c_style (p -> two -> path , & sb , NULL , 0 );
4787
+ strbuf_addf (& sb , " (%d%%)\n" , similarity_index (p ));
4788
+ emit_diff_symbol (opt , DIFF_SYMBOL_SUMMARY ,
4789
+ sb .buf , sb .len , 0 );
4779
4790
}
4780
- show_mode_change (file , p , !p -> score , line_prefix );
4791
+ show_mode_change (opt , p , !p -> score );
4781
4792
break ;
4782
4793
}
4783
4794
}
0 commit comments