在线文档教程

pack format

pack-format

Pack-*.pack 文件具有以下格式:

  • 标题出现在开头,包含以下内容:4字节签名:签名是:{'P','A','C','K'}

4-byte version number (network byte order): Git currently accepts version number 2 or 3 but generates version 2 only.

包中包含4个字节的对象数(网络字节顺序)

观察:我们不能超过 4G 版本;-)和一个包中超过 4G 的对象。

  • 头部后面跟着一些对象条目,每条对象条目如下所示:(未分割表示)n 字节类型和长度(3位类型,(n-1)* 7 + 4位长度)压缩数据

(deltified representation) n-byte type and length (3-bit type, (n-1)\*7+4-bit length) 20-byte base object name if OBJ\_REF\_DELTA or a negative relative offset from the delta object's position in the pack if this is an OBJ\_OFS\_DELTA object compressed delta data

观察:每个对象的长度都是以可变长度格式编码的,并不限于32位或任何其他内容。

  • 预告片记录了上述所有内容的20字节 SHA-1 校验之和。

原始(版本1)pack-*.idx 文件具有以下格式:

  • 标题由256个4字节的网络字节顺序整数组成。此表的第 N 个条目记录对应包中对象的数量,其对象名称的第一个字节小于或等于 N 。这称为first-level fan-out表格。

20字节的对象名称。

  • 该文件以一个结尾结束:在相应的包文件末尾的20字节SHA-1校验和的副本。

上述所有的20字节 SHA-1 校验和。

包 Idx 文件:

-- +--------------------------------+ fanout | fanout[0] = 2 (for example) |-. table +--------------------------------+ | | fanout[1] | | +--------------------------------+ | | fanout[2] | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | fanout[255] = total objects |---. -- +--------------------------------+ | | 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 size extension bit (MSB) type (next 3 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 least significant part, and sizeN 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 REF_DELTA, then 20-byte base object name SHA-1 (the size above is the size of the delta data that follows). delta data, deflated. If it is OFS_DELTA, then n-byte offset (see below) interpreted as a negative offset from the type-byte of the header of the ofs-delta entry (the size above is the size of the delta data that follows). delta data, deflated.

offset encoding: n bytes with MSB set in all but the last one. The offset is then the number constructed by concatenating the lower 7 bit of each byte, and for n >= 2 adding 2^7 + 2^14 + ... + 2^(7*(n-1)) to the result.

版本2 pack-*.idx 文件支持包大于4 gib ,并且

have some other reorganizations. They have the format:

  • 一个4字节的幻数\377tOc,这是一个不合理的扇出值。

上述所有的20字节 SHA-1 校验和。