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

Re: Understanding last ~28 bytes of index file

From
Jeff King <peff@peff.net>
Date
Jun 13, 2019, 17:09 UTC
Message-ID
<20190613170941.GA13670@sigill.intra.peff.net>
In-Reply-To
<c7c9012143e0818d332d0a9967c1a3e6@farhan.codes>
On Thu, Jun 13, 2019 at 06:32:03AM +0000, Farhan Khan wrote:
Show 5 quoted lines
> 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
Previous: Farhan Khan
Message 2 of 2 in “Understanding last ~28 bytes of index file”
  1. Farhan KhanJun 13, 2019
  2. Jeff KingJun 13, 2019

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.