Skip to content

Commit 352ca4e

Browse files
keszybzgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e18872b commit 352ca4e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

diff.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
23702370
{
23712371
mmfile_t mf1, mf2;
23722372
struct diffstat_file *data;
2373+
int same_contents;
23732374

23742375
data = diffstat_add(diffstat, name_a, name_b);
23752376

@@ -2378,9 +2379,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
23782379
return;
23792380
}
23802381

2382+
same_contents = !hashcmp(one->sha1, two->sha1);
2383+
23812384
if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
23822385
data->is_binary = 1;
2383-
if (!hashcmp(one->sha1, two->sha1)) {
2386+
if (same_contents) {
23842387
data->added = 0;
23852388
data->deleted = 0;
23862389
} else {
@@ -2396,7 +2399,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
23962399
data->added = count_lines(two->data, two->size);
23972400
}
23982401

2399-
else {
2402+
else if (!same_contents) {
24002403
/* Crazy xdl interfaces.. */
24012404
xpparam_t xpp;
24022405
xdemitconf_t xecfg;

0 commit comments

Comments
 (0)