From: Jeff King <peff@peff.net>
To: Farhan Khan <farhan@farhan.codes>
Cc: git@vger.kernel.org
Subject: Re: Understanding last ~28 bytes of index file
Date: Thu, 13 Jun 2019 13:09:41 -0400 [thread overview]
Message-ID: <20190613170941.GA13670@sigill.intra.peff.net> (raw)
In-Reply-To: <c7c9012143e0818d332d0a9967c1a3e6@farhan.codes>
On Thu, Jun 13, 2019 at 06:32:03AM +0000, Farhan Khan wrote:
> I am trying to understand how the index (.git/index) file works. When
> looking through extensions, it loops until it reaches the last 28
> bytes (SHA size + 8). This is referenced here.
> https://github.com/git/git/blob/master/read-cache.c#L1933
> What do the last 28 bytes consist of? Where in the source are bytes written?
It is not that the last 28 bytes are magical. It is that you must have
at least 28 bytes remaining in the file for there to be any extension.
20 of those are the trailing sha1 hash (which are written as part of the
hashfile code in csum-file.c).
And then for there to be an extension, it must have 8 bytes of name and
length, which will then be followed by however many bytes the length
indicated. After parsing that, we check to see if there are enough bytes
for another extension, and so on.
To find where the index extension blocks themselves are written, perhaps
grep for write_index_ext_header(), which should be called before writing
out the data for each.
-Peff
prev parent reply other threads:[~2019-06-13 17:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-13 6:32 Understanding last ~28 bytes of index file Farhan Khan
2019-06-13 17:09 ` Jeff King [this message]
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=20190613170941.GA13670@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).