From e18872b2f0fba4cb860c9350bb8b8d8680dfc83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 1 May 2012 19:10:14 +0200 Subject: diff --stat: report mode-only changes for binary files like text files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mode-only changes to binary files without content change were reported as if they were rewritten, but text files in the same situation were reported as "unchanged". Let's treat binary files like text files here, and simply say that they are unchanged. Output of --shortstat is modified in the same way. Reported-by: Martin Mareš Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- diff.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 22288b0106..e61ccd1123 100644 --- a/diff.c +++ b/diff.c @@ -1583,8 +1583,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) if (data->files[i]->is_binary) { fprintf(options->file, "%s", line_prefix); show_name(options->file, prefix, name, len); - fprintf(options->file, " Bin "); - fprintf(options->file, "%s%"PRIuMAX"%s", + fprintf(options->file, " Bin"); + if (!added && !deleted) { + putc('\n', options->file); + continue; + } + fprintf(options->file, " %s%"PRIuMAX"%s", del_c, deleted, reset); fprintf(options->file, " -> "); fprintf(options->file, "%s%"PRIuMAX"%s", @@ -1657,17 +1661,16 @@ static void show_shortstats(struct diffstat_t *data, struct diff_options *option return; for (i = 0; i < data->nr; i++) { - if (!data->files[i]->is_binary && - !data->files[i]->is_unmerged) { - int added = data->files[i]->added; - int deleted= data->files[i]->deleted; - if (!data->files[i]->is_renamed && - (added + deleted == 0)) { - total_files--; - } else { - adds += added; - dels += deleted; - } + int added = data->files[i]->added; + int deleted= data->files[i]->deleted; + + if (data->files[i]->is_unmerged) + continue; + if (!data->files[i]->is_renamed && (added + deleted == 0)) { + total_files--; + } else { + adds += added; + dels += deleted; } } if (options->output_prefix) { @@ -2377,8 +2380,13 @@ static void builtin_diffstat(const char *name_a, const char *name_b, if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) { data->is_binary = 1; - data->added = diff_filespec_size(two); - data->deleted = diff_filespec_size(one); + if (!hashcmp(one->sha1, two->sha1)) { + data->added = 0; + data->deleted = 0; + } else { + data->added = diff_filespec_size(two); + data->deleted = diff_filespec_size(one); + } } else if (complete_rewrite) { -- cgit v1.2.3