From: Farhan Khan <farhan@farhan.codes>
To: git@vger.kernel.org
Subject: Calculating pack file SHA value
Date: Wed, 27 Mar 2019 21:06:20 -0400 [thread overview]
Message-ID: <a48b86698802006045ed0af060b4e822@farhan.codes> (raw)
Hi all,
I am trying to figure out how to calculate the SHA value of a pack file when you
run `git index-pack file.pack`. I am close, but having a bit of trouble at the
end. Here's my understanding so far.
Git buffers data to be processed and when its exhausted, updates the SHA
checksum with the previously read data. This is from builtin/index-pack.c,
specifically fill() which calls flush() to update the SHA value. My question is,
how does git determine how many bytes at a time to process?
The size of the buffer is the file-scope variable input_len. This size seems to
be 4096 several times until the very end where it reduces to less-than 4096
(obviously this depends on the pack file, but in my case its 1074 bytes).
Ordinarily I would think its a result of the read() call not receiving the full
4096 bytes, but there still are left over bytes in the file but my manual
verification shows there are still remaining bytes in the file which are not run
through the SHA checksum.
How does git calculate a pack file's SHA verification? How does it know what
size (number of bytes) to read when running flush() to update the buffer?
(typically 4096). How does it know when in the file to stop updating the SHA1
value?
I hope my questions are clear. Thanks!
---
Farhan Khan
PGP Fingerprint: 1312 89CE 663E 1EB2 179C 1C83 C41D 2281 F8DA C0DE
next reply other threads:[~2019-03-28 1:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-28 1:06 Farhan Khan [this message]
2019-03-28 2:02 ` Calculating pack file SHA value Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a48b86698802006045ed0af060b4e822@farhan.codes \
--to=farhan@farhan.codes \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.