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

Understanding Index Header

From
FKFarhan Khan <khanzf@gmail.com>
Date
Oct 6, 2018, 21:13 UTC
Message-ID
<CAFd4kYC5psSkXxrHVU11b5bufFFVr-qP=S_Fn9AegCyADLw+HA@mail.gmail.com>
Hi all,

I am writing a program that parses out the .git/index file. I am reading the git index header documentation, but I seem to be getting jibberish data. https://github.com/git/git/blob/master/Documentation/technical/index-format.txt

The first 12 bytes are the signature, version and entries. Great so far.

Afterwards, I try to read the extension signature, which the documentation says: "4-byte extension signature. If the first byte is 'A'..'Z' the extension is optional and can be ignored.". I am getting jibberish. Is this expected?

Then, the extension size comes back as 35560000 (after ntohl()). That seems extremely high. My structure is as follows:

struct _indexfile_hdr {
        unsigned char   sig[4];         /* Always "DIRC" */
        uint32_t        version;        /* Version Number */
        uint32_t        entries;        /* Number of extensions */
        unsigned char   extsig[4];      /* Extension signature */
        uint32_t        extsize;        /* Size of the extension */
        uint8_t         sha[8];         /* SHA1 of index before checksum */
} __packed;
Am I doing something wrong? Is there some offset or padding that I missed?

Thanks, -- Farhan Khan PGP Fingerprint: B28D 2726 E2BC A97E 3854 5ABE 9A9F 00BC D525 16EE

Next: Kevin Daudt
Message 1 of 2 in “Understanding Index Header”
  1. Farhan KhanOct 6, 2018
  2. Kevin DaudtOct 6, 2018

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.