Skip to content

Commit

Permalink
diff --stat: do not run diff on indentical files
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Zbigniew Jędrzejewski-Szmek authored and Junio C Hamano committed May 2, 2012
1 parent e18872b commit 352ca4e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
{
mmfile_t mf1, mf2;
struct diffstat_file *data;
int same_contents;

data = diffstat_add(diffstat, name_a, name_b);

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

same_contents = !hashcmp(one->sha1, two->sha1);

if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
data->is_binary = 1;
if (!hashcmp(one->sha1, two->sha1)) {
if (same_contents) {
data->added = 0;
data->deleted = 0;
} else {
Expand All @@ -2396,7 +2399,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
data->added = count_lines(two->data, two->size);
}

else {
else if (!same_contents) {
/* Crazy xdl interfaces.. */
xpparam_t xpp;
xdemitconf_t xecfg;
Expand Down

0 comments on commit 352ca4e

Please sign in to comment.