@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
862862 const char * arg = av [0 ];
863863 if (!strcmp (arg , "-p" ) || !strcmp (arg , "-u" ))
864864 options -> output_format = DIFF_FORMAT_PATCH ;
865+ else if (!strcmp (arg , "--patch-with-raw" )) {
866+ options -> output_format = DIFF_FORMAT_PATCH ;
867+ options -> with_raw = 1 ;
868+ }
865869 else if (!strcmp (arg , "-z" ))
866870 options -> line_termination = 0 ;
867871 else if (!strncmp (arg , "-l" , 2 ))
@@ -1048,13 +1052,13 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
10481052static void diff_flush_raw (struct diff_filepair * p ,
10491053 int line_termination ,
10501054 int inter_name_termination ,
1051- struct diff_options * options )
1055+ struct diff_options * options ,
1056+ int output_format )
10521057{
10531058 int two_paths ;
10541059 char status [10 ];
10551060 int abbrev = options -> abbrev ;
10561061 const char * path_one , * path_two ;
1057- int output_format = options -> output_format ;
10581062
10591063 path_one = p -> one -> path ;
10601064 path_two = p -> two -> path ;
@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(void)
12701274 diff_debug_queue ("resolve-rename-copy done" , q );
12711275}
12721276
1273- void diff_flush (struct diff_options * options )
1277+ static void flush_one_pair (struct diff_filepair * p ,
1278+ int diff_output_format ,
1279+ struct diff_options * options )
12741280{
1275- struct diff_queue_struct * q = & diff_queued_diff ;
1276- int i ;
12771281 int inter_name_termination = '\t' ;
1278- int diff_output_format = options -> output_format ;
12791282 int line_termination = options -> line_termination ;
1280-
12811283 if (!line_termination )
12821284 inter_name_termination = 0 ;
12831285
1284- for (i = 0 ; i < q -> nr ; i ++ ) {
1285- struct diff_filepair * p = q -> queue [i ];
1286-
1287- switch (p -> status ) {
1288- case DIFF_STATUS_UNKNOWN :
1286+ switch (p -> status ) {
1287+ case DIFF_STATUS_UNKNOWN :
1288+ break ;
1289+ case 0 :
1290+ die ("internal error in diff-resolve-rename-copy" );
1291+ break ;
1292+ default :
1293+ switch (diff_output_format ) {
1294+ case DIFF_FORMAT_PATCH :
1295+ diff_flush_patch (p , options );
12891296 break ;
1290- case 0 :
1291- die ("internal error in diff-resolve-rename-copy" );
1297+ case DIFF_FORMAT_RAW :
1298+ case DIFF_FORMAT_NAME_STATUS :
1299+ diff_flush_raw (p , line_termination ,
1300+ inter_name_termination ,
1301+ options , diff_output_format );
1302+ break ;
1303+ case DIFF_FORMAT_NAME :
1304+ diff_flush_name (p ,
1305+ inter_name_termination ,
1306+ line_termination );
1307+ break ;
1308+ case DIFF_FORMAT_NO_OUTPUT :
12921309 break ;
1293- default :
1294- switch (diff_output_format ) {
1295- case DIFF_FORMAT_PATCH :
1296- diff_flush_patch (p , options );
1297- break ;
1298- case DIFF_FORMAT_RAW :
1299- case DIFF_FORMAT_NAME_STATUS :
1300- diff_flush_raw (p , line_termination ,
1301- inter_name_termination ,
1302- options );
1303- break ;
1304- case DIFF_FORMAT_NAME :
1305- diff_flush_name (p ,
1306- inter_name_termination ,
1307- line_termination );
1308- break ;
1309- case DIFF_FORMAT_NO_OUTPUT :
1310- break ;
1311- }
13121310 }
1311+ }
1312+ }
1313+
1314+ void diff_flush (struct diff_options * options )
1315+ {
1316+ struct diff_queue_struct * q = & diff_queued_diff ;
1317+ int i ;
1318+ int diff_output_format = options -> output_format ;
1319+
1320+ if (options -> with_raw ) {
1321+ for (i = 0 ; i < q -> nr ; i ++ ) {
1322+ struct diff_filepair * p = q -> queue [i ];
1323+ flush_one_pair (p , DIFF_FORMAT_RAW , options );
1324+ }
1325+ }
1326+ for (i = 0 ; i < q -> nr ; i ++ ) {
1327+ struct diff_filepair * p = q -> queue [i ];
1328+ flush_one_pair (p , diff_output_format , options );
13131329 diff_free_filepair (p );
13141330 }
13151331 free (q -> queue );
0 commit comments