55#include "diffcore.h"
66#include "quote.h"
77#include "xdiff-interface.h"
8+ #include "log-tree.h"
89
910static int uninteresting (struct diff_filepair * p )
1011{
@@ -584,10 +585,20 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
584585 sline -> p_lno [i ] = sline -> p_lno [j ];
585586}
586587
588+ static void dump_quoted_path (const char * prefix , const char * path )
589+ {
590+ fputs (prefix , stdout );
591+ if (quote_c_style (path , NULL , NULL , 0 ))
592+ quote_c_style (path , NULL , stdout , 0 );
593+ else
594+ printf ("%s" , path );
595+ putchar ('\n' );
596+ }
597+
587598static int show_patch_diff (struct combine_diff_path * elem , int num_parent ,
588- int dense , const char * header ,
589- struct diff_options * opt )
599+ int dense , struct rev_info * rev )
590600{
601+ struct diff_options * opt = & rev -> diffopt ;
591602 unsigned long result_size , cnt , lno ;
592603 char * result , * cp ;
593604 struct sline * sline ; /* survived lines */
@@ -688,16 +699,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
688699 if (show_hunks || mode_differs || working_tree_file ) {
689700 const char * abb ;
690701
691- if (header ) {
692- shown_header ++ ;
693- printf ("%s%c" , header , opt -> line_termination );
694- }
695- printf ("diff --%s " , dense ? "cc" : "combined" );
696- if (quote_c_style (elem -> path , NULL , NULL , 0 ))
697- quote_c_style (elem -> path , NULL , stdout , 0 );
698- else
699- printf ("%s" , elem -> path );
700- putchar ('\n' );
702+ if (rev -> loginfo )
703+ show_log (rev , rev -> loginfo , "\n" );
704+ dump_quoted_path (dense ? "diff --cc " : "diff --combined " , elem -> path );
701705 printf ("index " );
702706 for (i = 0 ; i < num_parent ; i ++ ) {
703707 abb = find_unique_abbrev (elem -> parent [i ].sha1 ,
@@ -728,6 +732,8 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
728732 }
729733 putchar ('\n' );
730734 }
735+ dump_quoted_path ("--- a/" , elem -> path );
736+ dump_quoted_path ("+++ b/" , elem -> path );
731737 dump_sline (sline , cnt , num_parent );
732738 }
733739 free (result );
@@ -749,8 +755,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
749755
750756#define COLONS "::::::::::::::::::::::::::::::::"
751757
752- static void show_raw_diff (struct combine_diff_path * p , int num_parent , const char * header , struct diff_options * opt )
758+ static void show_raw_diff (struct combine_diff_path * p , int num_parent , struct rev_info * rev )
753759{
760+ struct diff_options * opt = & rev -> diffopt ;
754761 int i , offset ;
755762 const char * prefix ;
756763 int line_termination , inter_name_termination ;
@@ -760,8 +767,8 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
760767 if (!line_termination )
761768 inter_name_termination = 0 ;
762769
763- if (header )
764- printf ( "%s%c" , header , line_termination );
770+ if (rev -> loginfo )
771+ show_log ( rev , rev -> loginfo , "\n" );
765772
766773 if (opt -> output_format == DIFF_FORMAT_RAW ) {
767774 offset = strlen (COLONS ) - num_parent ;
@@ -802,40 +809,44 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
802809 }
803810}
804811
805- int show_combined_diff (struct combine_diff_path * p ,
812+ void show_combined_diff (struct combine_diff_path * p ,
806813 int num_parent ,
807814 int dense ,
808- const char * header ,
809- struct diff_options * opt )
815+ struct rev_info * rev )
810816{
817+ struct diff_options * opt = & rev -> diffopt ;
811818 if (!p -> len )
812- return 0 ;
819+ return ;
813820 switch (opt -> output_format ) {
814821 case DIFF_FORMAT_RAW :
815822 case DIFF_FORMAT_NAME_STATUS :
816823 case DIFF_FORMAT_NAME :
817- show_raw_diff (p , num_parent , header , opt );
818- return 1 ;
819-
820- default :
824+ show_raw_diff (p , num_parent , rev );
825+ return ;
821826 case DIFF_FORMAT_PATCH :
822- return show_patch_diff (p , num_parent , dense , header , opt );
827+ show_patch_diff (p , num_parent , dense , rev );
828+ return ;
829+ default :
830+ return ;
823831 }
824832}
825833
826- const char * diff_tree_combined_merge (const unsigned char * sha1 ,
827- const char * header , int dense ,
828- struct diff_options * opt )
834+ void diff_tree_combined_merge (const unsigned char * sha1 ,
835+ int dense , struct rev_info * rev )
829836{
837+ struct diff_options * opt = & rev -> diffopt ;
830838 struct commit * commit = lookup_commit (sha1 );
831839 struct diff_options diffopts ;
832840 struct commit_list * parents ;
833841 struct combine_diff_path * p , * paths = NULL ;
834842 int num_parent , i , num_paths ;
843+ int do_diffstat ;
835844
845+ do_diffstat = (opt -> output_format == DIFF_FORMAT_DIFFSTAT ||
846+ opt -> with_stat );
836847 diffopts = * opt ;
837- diffopts .output_format = DIFF_FORMAT_NO_OUTPUT ;
838848 diffopts .with_raw = 0 ;
849+ diffopts .with_stat = 0 ;
839850 diffopts .recursive = 1 ;
840851
841852 /* count parents */
@@ -849,11 +860,24 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
849860 parents ;
850861 parents = parents -> next , i ++ ) {
851862 struct commit * parent = parents -> item ;
863+ /* show stat against the first parent even
864+ * when doing combined diff.
865+ */
866+ if (i == 0 && do_diffstat )
867+ diffopts .output_format = DIFF_FORMAT_DIFFSTAT ;
868+ else
869+ diffopts .output_format = DIFF_FORMAT_NO_OUTPUT ;
852870 diff_tree_sha1 (parent -> object .sha1 , commit -> object .sha1 , "" ,
853871 & diffopts );
854872 diffcore_std (& diffopts );
855873 paths = intersect_paths (paths , i , num_parent );
874+
875+ if (do_diffstat && rev -> loginfo )
876+ show_log (rev , rev -> loginfo ,
877+ opt -> with_stat ? "---\n" : "\n" );
856878 diff_flush (& diffopts );
879+ if (opt -> with_stat )
880+ putchar ('\n' );
857881 }
858882
859883 /* find out surviving paths */
@@ -866,17 +890,13 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
866890 int saved_format = opt -> output_format ;
867891 opt -> output_format = DIFF_FORMAT_RAW ;
868892 for (p = paths ; p ; p = p -> next ) {
869- if (show_combined_diff (p , num_parent , dense ,
870- header , opt ))
871- header = NULL ;
893+ show_combined_diff (p , num_parent , dense , rev );
872894 }
873895 opt -> output_format = saved_format ;
874896 putchar (opt -> line_termination );
875897 }
876898 for (p = paths ; p ; p = p -> next ) {
877- if (show_combined_diff (p , num_parent , dense ,
878- header , opt ))
879- header = NULL ;
899+ show_combined_diff (p , num_parent , dense , rev );
880900 }
881901 }
882902
@@ -886,5 +906,4 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
886906 paths = paths -> next ;
887907 free (tmp );
888908 }
889- return header ;
890909}
0 commit comments