summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorClemens Buchacher <drizzd@aon.at>2010-08-15 09:20:43 +0200
committerJunio C Hamano <gitster@pobox.com>2010-08-16 18:31:37 -0700
commit34597c1f5a77c710dae33092cb8a7cb01c6b21c1 (patch)
tree8d9ec7281371366dd225e639960118bc4d5a33a8 /diff.c
parent64fdc08dac6694d1e754580e7acb82dfa4988bb9 (diff)
downloadgit-34597c1f5a77c710dae33092cb8a7cb01c6b21c1.tar.gz
hash binary sha1 into patch id
Since commit 2f82f760 (Take binary diffs into account for "git rebase"), binary files are included in patch ID computation. Binary files are diffed using the text diff algorithm, however, which has a huge impact on performance. The following tests performance for a 50000 line file marked as binary in .gitattributes. $ git format-patch --stdout --ignore-if-in-upstream master real 0m0.367s user 0m0.354s sys 0m0.010s Instead of diffing the binary files, hash the pre- and post-image sha1, which is just as unique. As a result, performance is much improved. $ git format-patch --stdout --ignore-if-in-upstream master real 0m0.016s user 0m0.015s sys 0m0.001s Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/diff.c b/diff.c
index 17873f3d9e..f4a23ab1db 100644
--- a/diff.c
+++ b/diff.c
@@ -3758,6 +3758,13 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
len2, p->two->path);
git_SHA1_Update(&ctx, buffer, len1);
+ if (diff_filespec_is_binary(p->one) ||
+ diff_filespec_is_binary(p->two)) {
+ git_SHA1_Update(&ctx, sha1_to_hex(p->one->sha1), 40);
+ git_SHA1_Update(&ctx, sha1_to_hex(p->two->sha1), 40);
+ continue;
+ }
+
xpp.flags = 0;
xecfg.ctxlen = 3;
xecfg.flags = XDL_EMIT_FUNCNAMES;