diff --stat: do not run diff on indentical files

If two objects are known to be equal, there is no point running the diff. Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Zbigniew Jędrzejewski-Szmek committed May 1, 2012 at 19:10 UTC 352ca4e105e6fb37cad97b80f2640d28b133ca9d
1 file changed +5 -2
diff.c
+5 -2
@@ -2370,6 +2370,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2370 {
2371 mmfile_t mf1, mf2;
2372 struct diffstat_file *data;
2373 + int same_contents;
2374
2375 data = diffstat_add(diffstat, name_a, name_b);
2376
@@ -2378,9 +2379,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2379 return;
2380 }
2381
2382 + same_contents = !hashcmp(one->sha1, two->sha1);
2383 +
2384 if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
2385 data->is_binary = 1;
2383 - if (!hashcmp(one->sha1, two->sha1)) {
2386 + if (same_contents) {
2387 data->added = 0;
2388 data->deleted = 0;
2389 } else {
@@ -2396,7 +2399,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2399 data->added = count_lines(two->data, two->size);
2400 }
2401
2399 - else {
2402 + else if (!same_contents) {
2403 /* Crazy xdl interfaces.. */
2404 xpparam_t xpp;
2405 xdemitconf_t xecfg;