Skip to content

Commit abb371a

Browse files
peffgitster
authored andcommitted
diff: don't retrieve binary blobs for diffstat
We only need the size, which is much cheaper to get, especially if it is a big binary file. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ded0abc commit abb371a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

diff.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
235235
return 0;
236236
}
237237

238+
/* like fill_mmfile, but only for size, so we can avoid retrieving blob */
239+
static unsigned long diff_filespec_size(struct diff_filespec *one)
240+
{
241+
if (!DIFF_FILE_VALID(one))
242+
return 0;
243+
diff_populate_filespec(one, 1);
244+
return one->size;
245+
}
246+
238247
static int count_trailing_blank(mmfile_t *mf, unsigned ws_rule)
239248
{
240249
char *ptr = mf->ptr;
@@ -1813,11 +1822,9 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
18131822
}
18141823

18151824
if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
1816-
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
1817-
die("unable to read files to diff");
18181825
data->is_binary = 1;
1819-
data->added = mf2.size;
1820-
data->deleted = mf1.size;
1826+
data->added = diff_filespec_size(two);
1827+
data->deleted = diff_filespec_size(one);
18211828
}
18221829

18231830
else if (complete_rewrite) {

0 commit comments

Comments
 (0)