Skip to content

Commit b188258

Browse files
andyparkinsJunio C Hamano
authored andcommitted
Show binary file size change in diff --stat
Previously, a binary file in the diffstat would show as: some-binary-file.bin | Bin The space after the "Bin" was never used. This patch changes binary lines in the diffstat to be: some-binary-file.bin | Bin 12345 -> 123456 bytes The very nice "->" notation was suggested by Johannes Schindelin, and shows the before and after sizes more clearly than "+" and "-" would. If a size is 0 it's not shown (although it would probably be better to treat no-file differently from zero-byte-file). The user can see what changed in the binary file, and how big the new file is. This is in keeping with the information in the rest of the diffstat. The diffstat_t members "added" and "deleted" were unused when the file was binary, so this patch loads them with the file sizes in builtin_diffstat(). These figures are then read in show_stats() when the file is marked binary. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 566842f commit b188258

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

diff.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,12 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
811811

812812
if (data->files[i]->is_binary) {
813813
show_name(prefix, name, len, reset, set);
814-
printf(" Bin\n");
814+
printf(" Bin ");
815+
printf("%s%d%s", del_c, deleted, reset);
816+
printf(" -> ");
817+
printf("%s%d%s", add_c, added, reset);
818+
printf(" bytes");
819+
printf("\n");
815820
goto free_diffstat_file;
816821
}
817822
else if (data->files[i]->is_unmerged) {
@@ -1185,9 +1190,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
11851190
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
11861191
die("unable to read files to diff");
11871192

1188-
if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))
1193+
if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) {
11891194
data->is_binary = 1;
1190-
else {
1195+
data->added = mf2.size;
1196+
data->deleted = mf1.size;
1197+
} else {
11911198
/* Crazy xdl interfaces.. */
11921199
xpparam_t xpp;
11931200
xdemitconf_t xecfg;

0 commit comments

Comments
 (0)