Skip to content

Commit 34597c1

Browse files
Clemens Buchachergitster
authored andcommitted
hash binary sha1 into patch id
Since commit 2f82f76 (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>
1 parent 64fdc08 commit 34597c1

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,6 +3758,13 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
37583758
len2, p->two->path);
37593759
git_SHA1_Update(&ctx, buffer, len1);
37603760

3761+
if (diff_filespec_is_binary(p->one) ||
3762+
diff_filespec_is_binary(p->two)) {
3763+
git_SHA1_Update(&ctx, sha1_to_hex(p->one->sha1), 40);
3764+
git_SHA1_Update(&ctx, sha1_to_hex(p->two->sha1), 40);
3765+
continue;
3766+
}
3767+
37613768
xpp.flags = 0;
37623769
xecfg.ctxlen = 3;
37633770
xecfg.flags = XDL_EMIT_FUNCNAMES;

0 commit comments

Comments
 (0)