@@ -245,6 +245,15 @@ static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
245
245
return 0 ;
246
246
}
247
247
248
+ /* like fill_mmfile, but only for size, so we can avoid retrieving blob */
249
+ static unsigned long diff_filespec_size (struct diff_filespec * one )
250
+ {
251
+ if (!DIFF_FILE_VALID (one ))
252
+ return 0 ;
253
+ diff_populate_filespec (one , 1 );
254
+ return one -> size ;
255
+ }
256
+
248
257
static int count_trailing_blank (mmfile_t * mf , unsigned ws_rule )
249
258
{
250
259
char * ptr = mf -> ptr ;
@@ -2077,33 +2086,35 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2077
2086
data -> is_unmerged = 1 ;
2078
2087
return ;
2079
2088
}
2080
- if (complete_rewrite ) {
2089
+
2090
+ if (diff_filespec_is_binary (one ) || diff_filespec_is_binary (two )) {
2091
+ data -> is_binary = 1 ;
2092
+ data -> added = diff_filespec_size (two );
2093
+ data -> deleted = diff_filespec_size (one );
2094
+ }
2095
+
2096
+ else if (complete_rewrite ) {
2081
2097
diff_populate_filespec (one , 0 );
2082
2098
diff_populate_filespec (two , 0 );
2083
2099
data -> deleted = count_lines (one -> data , one -> size );
2084
2100
data -> added = count_lines (two -> data , two -> size );
2085
- goto free_and_return ;
2086
2101
}
2087
- if (fill_mmfile (& mf1 , one ) < 0 || fill_mmfile (& mf2 , two ) < 0 )
2088
- die ("unable to read files to diff" );
2089
2102
2090
- if (diff_filespec_is_binary (one ) || diff_filespec_is_binary (two )) {
2091
- data -> is_binary = 1 ;
2092
- data -> added = mf2 .size ;
2093
- data -> deleted = mf1 .size ;
2094
- } else {
2103
+ else {
2095
2104
/* Crazy xdl interfaces.. */
2096
2105
xpparam_t xpp ;
2097
2106
xdemitconf_t xecfg ;
2098
2107
2108
+ if (fill_mmfile (& mf1 , one ) < 0 || fill_mmfile (& mf2 , two ) < 0 )
2109
+ die ("unable to read files to diff" );
2110
+
2099
2111
memset (& xpp , 0 , sizeof (xpp ));
2100
2112
memset (& xecfg , 0 , sizeof (xecfg ));
2101
2113
xpp .flags = o -> xdl_opts ;
2102
2114
xdi_diff_outf (& mf1 , & mf2 , diffstat_consume , diffstat ,
2103
2115
& xpp , & xecfg );
2104
2116
}
2105
2117
2106
- free_and_return :
2107
2118
diff_free_filespec_data (one );
2108
2119
diff_free_filespec_data (two );
2109
2120
}
0 commit comments