git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] hash binary sha1 into patch id

From
Clemens Buchacher <drizzd@aon.at>
Date
Aug 15, 2010, 07:20 UTC
Message-ID
<20100815072043.GA368@localhost>
In-Reply-To
<20100813215801.GA24534@localhost>

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>
---

I am again attaching the corresponding test script. Since it mostly tests performance, I am not sure how to incorporate it into the main test suite.

 diff.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index 17873f3..f4a23ab 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;
-- 
1.7.2.1.1.g202c
Previous: Clemens BuchacherNext: Jonathan Nieder
Message 6 of 13 in “hash binary sha1 into patch id”
  1. hash binary sha1 into patch idClemens Buchacher, Aug 13, 2010
  2. Jonathan NiederAug 13, 2010
  3. Clemens BuchacherAug 13, 2010
  4. Jonathan NiederAug 13, 2010
  5. Clemens BuchacherAug 13, 2010
  6. hash binary sha1 into patch idClemens Buchacher, Aug 15, 2010
  7. Jonathan NiederAug 15, 2010
  8. Marat RadchenkoSep 10, 2010
  9. Clemens BuchacherSep 10, 2010
  10. Marat RadchenkoOct 13, 2010
  11. Marat RadchenkoOct 13, 2010
  12. Clemens BuchacherOct 13, 2010
  13. Marat RadchenkoOct 14, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.