{"thread":{"id":"51301","subject":"Understanding last ~28 bytes of index file","startedAt":"2019-06-13T16:43:32Z","lastAt":"2019-06-13T17:09:47Z","messageCount":2,"participants":["Farhan Khan","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"377136","messageId":"c7c9012143e0818d332d0a9967c1a3e6@farhan.codes","threadId":"51301","inReplyTo":null,"subject":"Understanding last ~28 bytes of index file","fromName":"Farhan Khan","fromEmail":"farhan@farhan.codes","sentAt":"2019-06-13T06:32:03Z","receivedAt":"2019-06-13T16:43:32Z","isPatch":false,"sender":{"key":"farhan@farhan.codes","avatar":"https://gravatar.com/avatar/64c1dc837f48efeff1b51db4131f6ebe84b1d0c1caa43f73d8d45f2dee8e67ce?d=mp&s=160"},"body":"Hi all,\n\nI 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\nWhat do the last 28 bytes consist of? Where in the source are bytes written?\n\nI am trying to understand how to reproduce the index file and am not sure how this part works.\n\nThank you,\n---\nFarhan Khan\nPGP Fingerprint: 1312 89CE 663E 1EB2 179C  1C83 C41D 2281 F8DA C0DE\n"},{"id":"377151","messageId":"20190613170941.GA13670@sigill.intra.peff.net","threadId":"51301","inReplyTo":"c7c9012143e0818d332d0a9967c1a3e6@farhan.codes","subject":"Re: Understanding last ~28 bytes of index file","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-06-13T17:09:41Z","receivedAt":"2019-06-13T17:09:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jun 13, 2019 at 06:32:03AM +0000, Farhan Khan wrote:\n\n> I am trying to understand how the index (.git/index) file works. When\n> looking through extensions, it loops until it reaches the last 28\n> bytes (SHA size + 8). This is referenced here.\n> https://github.com/git/git/blob/master/read-cache.c#L1933\n> What do the last 28 bytes consist of? Where in the source are bytes written?\n\nIt is not that the last 28 bytes are magical. It is that you must have\nat least 28 bytes remaining in the file for there to be any extension.\n20 of those are the trailing sha1 hash (which are written as part of the\nhashfile code in csum-file.c).\n\nAnd then for there to be an extension, it must have 8 bytes of name and\nlength, which will then be followed by however many bytes the length\nindicated. After parsing that, we check to see if there are enough bytes\nfor another extension, and so on.\n\nTo find where the index extension blocks themselves are written, perhaps\ngrep for write_index_ext_header(), which should be called before writing\nout the data for each.\n\n-Peff\n"}]}