@@ -43,7 +43,8 @@ static char diff_colors[][COLOR_MAXLEN] = {
43
43
};
44
44
45
45
static void diff_filespec_load_driver (struct diff_filespec * one );
46
- static char * run_textconv (const char * , struct diff_filespec * , size_t * );
46
+ static size_t fill_textconv (const char * cmd ,
47
+ struct diff_filespec * df , char * * outbuf );
47
48
48
49
static int parse_diff_color_slot (const char * var , int ofs )
49
50
{
@@ -477,7 +478,7 @@ static void emit_rewrite_diff(const char *name_a,
477
478
const char * reset = diff_get_color (color_diff , DIFF_RESET );
478
479
static struct strbuf a_name = STRBUF_INIT , b_name = STRBUF_INIT ;
479
480
const char * a_prefix , * b_prefix ;
480
- const char * data_one , * data_two ;
481
+ char * data_one , * data_two ;
481
482
size_t size_one , size_two ;
482
483
struct emit_callback ecbdata ;
483
484
@@ -499,26 +500,8 @@ static void emit_rewrite_diff(const char *name_a,
499
500
quote_two_c_style (& a_name , a_prefix , name_a , 0 );
500
501
quote_two_c_style (& b_name , b_prefix , name_b , 0 );
501
502
502
- diff_populate_filespec (one , 0 );
503
- diff_populate_filespec (two , 0 );
504
- if (textconv_one ) {
505
- data_one = run_textconv (textconv_one , one , & size_one );
506
- if (!data_one )
507
- die ("unable to read files to diff" );
508
- }
509
- else {
510
- data_one = one -> data ;
511
- size_one = one -> size ;
512
- }
513
- if (textconv_two ) {
514
- data_two = run_textconv (textconv_two , two , & size_two );
515
- if (!data_two )
516
- die ("unable to read files to diff" );
517
- }
518
- else {
519
- data_two = two -> data ;
520
- size_two = two -> size ;
521
- }
503
+ size_one = fill_textconv (textconv_one , one , & data_one );
504
+ size_two = fill_textconv (textconv_two , two , & data_two );
522
505
523
506
memset (& ecbdata , 0 , sizeof (ecbdata ));
524
507
ecbdata .color_diff = color_diff ;
@@ -1717,20 +1700,8 @@ static void builtin_diff(const char *name_a,
1717
1700
strbuf_reset (& header );
1718
1701
}
1719
1702
1720
- if (textconv_one ) {
1721
- size_t size ;
1722
- mf1 .ptr = run_textconv (textconv_one , one , & size );
1723
- if (!mf1 .ptr )
1724
- die ("unable to read files to diff" );
1725
- mf1 .size = size ;
1726
- }
1727
- if (textconv_two ) {
1728
- size_t size ;
1729
- mf2 .ptr = run_textconv (textconv_two , two , & size );
1730
- if (!mf2 .ptr )
1731
- die ("unable to read files to diff" );
1732
- mf2 .size = size ;
1733
- }
1703
+ mf1 .size = fill_textconv (textconv_one , one , & mf1 .ptr );
1704
+ mf2 .size = fill_textconv (textconv_two , two , & mf2 .ptr );
1734
1705
1735
1706
pe = diff_funcname_pattern (one );
1736
1707
if (!pe )
@@ -3916,3 +3887,26 @@ static char *run_textconv(const char *pgm, struct diff_filespec *spec,
3916
3887
3917
3888
return strbuf_detach (& buf , outsize );
3918
3889
}
3890
+
3891
+ static size_t fill_textconv (const char * cmd ,
3892
+ struct diff_filespec * df ,
3893
+ char * * outbuf )
3894
+ {
3895
+ size_t size ;
3896
+
3897
+ if (!cmd ) {
3898
+ if (!DIFF_FILE_VALID (df )) {
3899
+ * outbuf = "" ;
3900
+ return 0 ;
3901
+ }
3902
+ if (diff_populate_filespec (df , 0 ))
3903
+ die ("unable to read files to diff" );
3904
+ * outbuf = df -> data ;
3905
+ return df -> size ;
3906
+ }
3907
+
3908
+ * outbuf = run_textconv (cmd , df , & size );
3909
+ if (!* outbuf )
3910
+ die ("unable to read files to diff" );
3911
+ return size ;
3912
+ }
0 commit comments