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

calculating a git packfile sha1 checksum in java

From
Mmadmarcos <fru574@my.utsa.edu>
Date
Mar 22, 2011, 09:27 UTC
Message-ID
<1300786044816-6195501.post@n2.nabble.com>

I am learning about the Git packfile and currently trying to reproduce (in Java) what I believe to be the SHA1 20-byte checksum for the entire packfile. I take the byte array from, and including, the "PACK" 4-byte header to the end of the last packaged object's compressed data. Everything I have read indicates that the next 20 bytes is the SHA1 checksum for the entire packfile.

The 20-byte checksum that is part of the byte array received from Git is: B910248BF9B63AC53595E3835CA57BDAF08DA830

I use the following to calculate my own SHA1 checksum: crypt = MessageDigest.getInstance("SHA-1"); crypt.reset(); crypt.update(testData); byte [] result = crypt.digest();

My result ends up as: B910248BF9B63AC53595E3835CA57BDAF08DA813

I am baffled at how only the last byte of my result can be different from Git's (if I am using the correct part of the byte stream). If the only problem was the range of data passed to digest() then the entire calculated checksum would most likely look different.

Any ideas?
Note: I use the same code to generate test SHA1 ids for each contained
object and they match the references in the tree objects. This problem
currently only involves calculating the checksum over the entire packfile.

-- View this message in context: http://git.661346.n2.nabble.com/calculating-a-git-packfile-sha1-checksum-in-java-tp6195501p6195501.html Sent from the git mailing list archive at Nabble.com.

Next: Shawn Pearce
Message 1 of 4 in “calculating a git packfile sha1 checksum in java”
  1. madmarcosMar 22, 2011
  2. Shawn PearceMar 22, 2011
  3. madmarcosMar 22, 2011
  4. Nicolas PitreMar 22, 2011

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.