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

[FYI] pack idx format

From
Junio C Hamano <junkio@cox.net>
Date
Feb 15, 2006, 08:39 UTC
Message-ID
<7vd5hpm2x0.fsf@assigned-by-dhcp.cox.net>

This is still WIP but if anybody is interested... Once done, it should become Documentation/technical/pack-format.txt.

The reason I started doing this is to prototype this one:
	<7v4q3453qu.fsf@assigned-by-dhcp.cox.net>
-- >8 --
Idx file:

The idx file is to map object name SHA1 to offset into the corresponding pack file. There is the 'first-level fan-out' table at the beginning, and then the main part of the index follows. This is a table whose entries are sorted by their object name SHA1. The file ends with some trailer information.

The main part is a table of 24-byte entries, and each entry is:
	offset : 4-byte network byte order integer.
	SHA1   : 20-byte object name SHA1.

The data for the named object begins at byte offset "offset" in the corresponding pack file.

Before this main table, at the beginning of the idx file, there is a table of 256 4-byte network byte order integers. This is called "first-level fan-out". N-th entry of this table records the offset into the main index for the first object whose object name SHA1 starts with N+1. fanout[255] points at the end of main index. The offset is expressed in 24-bytes unit.

Example:
	idx
	    +--------------------------------+
	    | fanout[0] = 2                  |-.
	    +--------------------------------+ |
	    | fanout[1]                      | |
	    +--------------------------------+ |
	    | fanout[2]                      | |
	    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
	    | fanout[255]                    | |
	    +--------------------------------+ |
main	    | offset                         | |
index	    | object name 00XXXXXXXXXXXXXXXX | |
table	    +--------------------------------+ | 
	    | offset                         | |
	    | object name 00XXXXXXXXXXXXXXXX | |
	    +--------------------------------+ |
	  .-| offset                         |<+
	  | | object name 01XXXXXXXXXXXXXXXX |
	  | +--------------------------------+
	  | | offset                         |
	  | | object name 01XXXXXXXXXXXXXXXX |
	  | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  | | offset                         |
	  | | object name FFXXXXXXXXXXXXXXXX |
	  | +--------------------------------+
trailer	  | | packfile checksum              |
	  | +--------------------------------+
	  | | idxfile checksum               |
	  | +--------------------------------+
          .-------.      
                  |
Pack file entry: <+
     packed object header:
	1-byte type (upper 4-bit)
	       size0 (lower 4-bit) 
        n-byte sizeN (as long as MSB is set, each 7-bit)
		size0..sizeN form 4+7+7+..+7 bit integer, size0
		is the most significant part.
     packed object data:
        If it is not DELTA, then deflated bytes (the size above
		is the size before compression).
	If it is DELTA, then
	  20-byte base object name SHA1 (the size above is the
	  	size of the delta data that follows).
          delta data, deflated.
Next: Johannes Schindelin
Message 1 of 17 in “[FYI] pack idx format”
  1. Junio C HamanoFeb 15, 2006
  2. Johannes SchindelinFeb 15, 2006
  3. Nicolas PitreFeb 15, 2006
  4. Junio C HamanoFeb 16, 2006
  5. pack-objects: reuse data from existing pack.Junio C Hamano, Feb 16, 2006
  6. packed objects: minor cleanupJunio C Hamano, Feb 16, 2006
  7. Nicolas PitreFeb 16, 2006
  8. Junio C HamanoFeb 16, 2006
  9. Linus TorvaldsFeb 16, 2006
  10. Junio C HamanoFeb 16, 2006
  11. Andreas EricssonFeb 16, 2006
  12. Junio C HamanoFeb 16, 2006
  13. Junio C HamanoFeb 17, 2006
  14. pack-objects: finishing touches.Junio C Hamano, Feb 17, 2006
  15. pack-objects: avoid delta chains that are too long.Junio C Hamano, Feb 18, 2006
  16. Linus TorvaldsFeb 17, 2006
  17. Junio C HamanoFeb 17, 2006

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.