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

[PATCH] Document pack v4 format

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 27, 2013, 11:17 UTC
Message-ID
<1377602225-30439-1-git-send-email-pclouds@gmail.com>
In-Reply-To
<1377577567-27655-1-git-send-email-nico@fluxnic.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 For my education but may help people who are interested in the
 format. Most is gathered from commit messages, except the delta tree
 entries.
 
 .idx is not documented yet, but it does not change much and not the
 focus right now anyway.
 Documentation/technical/pack-format-v4.txt (new) | 110 +++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 Documentation/technical/pack-format-v4.txt
diff --git a/Documentation/technical/pack-format-v4.txt b/Documentation/technical/pack-format-v4.txt
new file mode 100644
index 0000000..9123a53
--- /dev/null
+++ b/Documentation/technical/pack-format-v4.txt
@@ -0,0 +1,110 @@
+Git pack v4 format
+==================
+
+== pack-*.pack files have the following format:
+
+   - A header appears at the beginning and consists of the following:
+
+     4-byte signature:
+	  The signature is: {'P', 'A', 'C', 'K'}
+
+     4-byte version number (network byte order): must be version
+     number 4
+
+     4-byte number of objects contained in the pack (network byte
+     order)
+
+   - (20 * nr_objects)-byte SHA-1 table: sorted in memcmp() order.
+
+   - Commit name dictionary: the uncompressed length in variable
+     encoding, followed by zlib-compressed dictionary. Each entry
+     consists of two prefix bytes storing timezone followed by a
+     NUL-terminated string.
+
+     Entries should be sorted by frequency so that the most frequent
+     entry has the smallest index, thus most efficient variable
+     encoding.
+
+   - Tree path dictionary: similar format to commit name
+     dictionary. Each entry consists of two prefix bytes storing entry
+     mode, then a NUL-terminated path name. Same sort order
+     recommendation applies.
+
+   - The header is followed by number of object entries, each of
+     which looks like this:
+
+     (undeltified representation)
+     n-byte type and length (4-bit type, (n-1)*7+4-bit length)
+     [uncompressed data]
+     [compressed data]
+
+     (deltified representation)
+     n-byte type and length (4-bit type, (n-1)*7+4-bit length)
+     base object name in SHA-1 reference encoding
+     compressed delta data
+
+     In undeltified format, blobs and tags do not have the
+     uncompressed data, all object content is compressed. Trees are
+     not compressed at all. Some headers in commits are stored
+     uncompressed, the rest is compressed.
+
+     All objects except trees are deltified and compressed the same
+     way in v3. Trees however are deltified differently and use
+     undeltified representation. See "Tree representation" below for
+     details.
+
+  - The trailer records 20-byte SHA-1 checksum of all of the above.
+
+=== Commit representation
+
+  - n-byte type and length (4-bit type, (n-1)*7+4-bit length)
+
+  - Tree SHA-1 in SHA-1 reference encoding
+
+  - Parent count in variable length encoding
+
+  - Parent SHA-1s in SHA-1 reference encoding
+
+  - Author reference: the index, in variable length encoding, to comit
+    name dictionary, which covers the name and also the time zone.
+
+  - Author timestamp in variable length encoding
+
+  - Committer reference: the index, in variable length encoding, to
+    comit name dictionary, which covers the name and also the time
+    zone.
+
+  - Committer timestamp in variable length encoding
+
+  - Compressed data of remaining header and the body
+
+=== Tree representation
+
+  - n-byte type and length (4-bit type, (n-1)*7+4-bit length)
+
+  - Number of trees in variable length encoding
+
+  - A number of trees, each consists of
+
+    Path component reference: an index, in variable length encoding,
+    into tree path dictionary, which also covers entry mode.
+
+    SHA-1 in SHA-1 reference encoding.
+
+Path component reference zero is an indicator of deltified portion and
+has the following format:
+
+  - path component reference: zero
+
+  - index of the entry to copy from, in variable length encoding
+
+  - number of entries in variable length encoding
+
+  - base tree in SHA-1 reference encoding
+
+=== SHA-1 reference encoding
+
+This encoding is used to encode SHA-1 efficiently if it's already in
+the SHA-1 table. It starts with an index number in variable length
+encoding. If it's not zero, its value minus one is the index in the
+SHA-1 table. If it's zero, 20 bytes of SHA-1 is followed.
-- 
1.8.2.83.gc99314b
Previous: Duy NguyenNext: Junio C Hamano
Message 50 of 83 in “Preliminary pack v4 support”
  1. 00/23 Preliminary pack v4 supportNicolas Pitre, Aug 27, 2013
  2. 01/23 pack v4: initial pack dictionary structure and codeNicolas Pitre, Aug 27, 2013
  3. Junio C HamanoAug 27, 2013
  4. Nicolas PitreAug 27, 2013
  5. 02/23 export packed_object_info()Nicolas Pitre, Aug 27, 2013
  6. 03/23 pack v4: scan tree objectsNicolas Pitre, Aug 27, 2013
  7. 04/23 pack v4: add tree entry mode support to dictionary entriesNicolas Pitre, Aug 27, 2013
  8. 05/23 pack v4: add commit object parsingNicolas Pitre, Aug 27, 2013
  9. Junio C HamanoAug 27, 2013
  10. Nicolas PitreAug 27, 2013
  11. Junio C HamanoAug 27, 2013
  12. 06/23 pack v4: split the object list and dictionary creationNicolas Pitre, Aug 27, 2013
  13. 07/23 pack v4: move to struct pack_idx_entry and get rid of our own struct idx_entryNicolas Pitre, Aug 27, 2013
  14. 08/23 pack v4: basic references encodingNicolas Pitre, Aug 27, 2013
  15. Junio C HamanoAug 27, 2013
  16. Nicolas PitreAug 27, 2013
  17. 09/23 pack v4: commit object encodingNicolas Pitre, Aug 27, 2013
  18. Junio C HamanoAug 27, 2013
  19. Nicolas PitreAug 27, 2013
  20. Nicolas PitreAug 27, 2013
  21. Junio C HamanoAug 27, 2013
  22. Nicolas PitreAug 27, 2013
  23. Duy NguyenSep 2, 2013
  24. Nicolas PitreSep 3, 2013
  25. Duy NguyenSep 3, 2013
  26. Nicolas PitreSep 5, 2013
  27. 10/23 pack v4: tree object encodingNicolas Pitre, Aug 27, 2013
  28. Junio C HamanoAug 27, 2013
  29. Nicolas PitreAug 27, 2013
  30. 11/23 pack v4: dictionary table outputNicolas Pitre, Aug 27, 2013
  31. 12/23 pack v4: creation codeNicolas Pitre, Aug 27, 2013
  32. Junio C HamanoAug 27, 2013
  33. Nicolas PitreAug 27, 2013
  34. 13/23 pack v4: object headersNicolas Pitre, Aug 27, 2013
  35. 14/23 pack v4: object data copyNicolas Pitre, Aug 27, 2013
  36. Junio C HamanoAug 27, 2013
  37. Nicolas PitreAug 27, 2013
  38. 15/23 pack v4: object writingNicolas Pitre, Aug 27, 2013
  39. 16/23 pack v4: tree object delta encodingNicolas Pitre, Aug 27, 2013
  40. 17/23 pack v4: load delta candidate for encoding tree objectsNicolas Pitre, Aug 27, 2013
  41. 18/23 pack v4: honor pack.compression config optionNicolas Pitre, Aug 27, 2013
  42. 19/23 pack v4: relax commit parsing a bitNicolas Pitre, Aug 27, 2013
  43. 20/23 pack index v3Nicolas Pitre, Aug 27, 2013
  44. 21/23 pack v4: normalize pack name to properly generate the pack index file nameNicolas Pitre, Aug 27, 2013
  45. 22/23 pack v4: add progress displayNicolas Pitre, Aug 27, 2013
  46. 23/23 initial pack index v3 support on the read sideNicolas Pitre, Aug 27, 2013
  47. Duy NguyenAug 31, 2013
  48. Nicolas PitreSep 3, 2013
  49. Duy NguyenSep 3, 2013
  50. Document pack v4 formatNguyễn Thái Ngọc Duy, Aug 27, 2013
  51. Junio C HamanoAug 27, 2013
  52. Nicolas PitreAug 27, 2013
  53. Document pack v4 formatNguyễn Thái Ngọc Duy, Aug 31, 2013
  54. Nicolas PitreSep 3, 2013
  55. Nicolas PitreSep 3, 2013
  56. Duy NguyenSep 3, 2013
  57. Duy NguyenSep 3, 2013
  58. Nicolas PitreSep 5, 2013
  59. Duy NguyenSep 5, 2013
  60. Nicolas PitreSep 5, 2013
  61. Duy NguyenSep 5, 2013
  62. Nicolas PitreSep 5, 2013
  63. Duy NguyenSep 5, 2013
  64. Nicolas PitreSep 5, 2013
  65. Junio C HamanoSep 5, 2013
  66. Nicolas PitreSep 5, 2013
  67. Duy NguyenSep 6, 2013
  68. Nicolas PitreSep 6, 2013
  69. Document pack v4 formatNguyễn Thái Ngọc Duy, Sep 6, 2013
  70. Nicolas PitreSep 6, 2013
  71. Duy NguyenSep 6, 2013
  72. Nicolas PitreSep 6, 2013
  73. Duy NguyenSep 6, 2013
  74. Nicolas PitreSep 6, 2013
  75. Nicolas PitreSep 7, 2013
  76. Nicolas PitreSep 7, 2013
  77. Duy NguyenSep 7, 2013
  78. Junio C HamanoAug 27, 2013
  79. Nicolas PitreAug 27, 2013
  80. Junio C HamanoAug 27, 2013
  81. Duy NguyenAug 28, 2013
  82. Nicolas PitreAug 28, 2013
  83. Duy NguyenAug 28, 2013

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.