4 = pack-*.pack file has the following format:
6 - The header appears at the beginning and consists of the following:
9 The signature is: {'P', 'A', 'C', 'K'}
11 4-byte version number (network byte order):
12 GIT currently accepts version number 2 or 3 but
13 generates version 2 only.
15 4-byte number of objects contained in the pack (network byte order)
17 Observation: we cannot have more than 4G versions ;-) and
18 more than 4G objects in a pack.
20 - The header is followed by number of object entries, each of
21 which looks like this:
23 (undeltified representation)
24 n-byte type and length (3-bit type, (n-1)*7+4-bit length)
27 (deltified representation)
28 n-byte type and length (3-bit type, (n-1)*7+4-bit length)
29 20-byte base object name
32 Observation: length of each object is encoded in a variable
33 length format and is not constrained to 32-bit or anything.
35 - The trailer records 20-byte SHA1 checksum of all of the above.
37 = pack-*.idx file has the following format:
39 - The header consists of 256 4-byte network byte order
40 integers. N-th entry of this table records the number of
41 objects in the corresponding pack, the first byte of whose
42 object name are smaller than N. This is called the
43 'first-level fan-out' table.
45 Observation: we would need to extend this to an array of
46 8-byte integers to go beyond 4G objects per pack, but it is
47 not strictly necessary.
49 - The header is followed by sorted 24-byte entries, one entry
50 per object in the pack. Each entry is:
52 4-byte network byte order integer, recording where the
53 object is stored in the packfile as the offset from the
58 Observation: we would definitely need to extend this to
59 8-byte integer plus 20-byte object name to handle a packfile
60 that is larger than 4GB.
62 - The file is concluded with a trailer:
64 A copy of the 20-byte SHA1 checksum at the end of
65 corresponding packfile.
67 20-byte SHA1-checksum of all of the above.
72 +--------------------------------+
74 +--------------------------------+ |
76 +--------------------------------+ |
78 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
80 +--------------------------------+ |
82 index | object name 00XXXXXXXXXXXXXXXX | |
83 table +--------------------------------+ |
85 | object name 00XXXXXXXXXXXXXXXX | |
86 +--------------------------------+ |
88 | | object name 01XXXXXXXXXXXXXXXX |
89 | +--------------------------------+
91 | | object name 01XXXXXXXXXXXXXXXX |
92 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94 | | object name FFXXXXXXXXXXXXXXXX |
95 | +--------------------------------+
96 trailer | | packfile checksum |
97 | +--------------------------------+
98 | | idxfile checksum |
99 | +--------------------------------+
104 packed object header:
105 1-byte size extension bit (MSB)
108 n-byte sizeN (as long as MSB is set, each 7-bit)
109 size0..sizeN form 4+7+7+..+7 bit integer, size0
110 is the least significant part, and sizeN is the
111 most significant part.
113 If it is not DELTA, then deflated bytes (the size above
114 is the size before compression).
116 20-byte base object name SHA1 (the size above is the
117 size of the delta data that follows).
118 delta data, deflated.