目錄 搜尋
Guides gitattributes giteveryday gitglossary gitignore gitmodules gitrevisions gittutorial gitworkflows Administration git archive git bundle git clean git filter-branch git fsck git gc git instaweb git reflog Basic Snapshotting git add git commit git diff git mv git reset git rm git status Branching and Merging git branch git checkout git log git merge git mergetool git stash git tag Debugging git bisect git blame git grep Email git am git format-patch git request-pull git send-email External Systems git fast-import git svn Getting and Creating Projects git clone git init Git git annotate git archimport git bisect-lk2009 git check-attr git check-mailmap git check-ref-format git checkout-index git cherry git citool git column git credential git credential-cache git credential-store git cvsexportcommit git cvsimport git cvsserver git diff-files git diff-tree git difftool git fast-export git fetch-pack git fmt-merge-msg git get-tar-commit-id git gui git http-backend git http-fetch git http-push git imap-send git index-pack git interpret-trailers git ls-remote git ls-tree git mailinfo git mailsplit git merge-file git merge-index git merge-one-file git merge-tree git mktag git mktree git name-rev git notes git p4 git pack-objects git pack-redundant git pack-refs git parse-remote git patch-id git prune git prune-packed git quiltimport git receive-pack git remote-ext git remote-fd git remote-testgit git repack git replace git rerere git send-pack git sh-i18n git sh-setup git shell git show-branch git show-index git stripspace git unpack-file git unpack-objects git upload-archive git upload-pack git var git verify-commit git verify-tag git whatchanged git worktree Inspection and Comparison git describe git shortlog git show Miscellaneous api credentials api index gitcli gitcore tutorial gitcredentials gitcvs migration gitdiffcore githooks gitk gitnamespaces gitremote helpers gitrepository layout gitsubmodules gittutorial 2 gitweb gitweb.conf pack format User Manual Patching git apply git cherry-pick git rebase git revert Plumbing Commands git cat-file git check-ignore git commit-tree git count-objects git diff-index git for-each-ref git hash-object git ls-files git merge-base git read-tree git rev-list git rev-parse git show-ref git symbolic-ref git update-index git update-ref git verify-pack git write-tree Server Admin git daemon git update-server-info Setup and Config git git config git help Sharing and Updating Projects git fetch git pull git push git remote git submodule
文字

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表格。

  • 标题后面是已排序的24字节条目,每个对象包含一个条目。每个条目是:4字节的网络字节顺序整数,记录对象存储在 packfile 中的位置,作为从开始的偏移量。

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, andfor 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,这是一个不合理的扇出值。

  • 一个4字节的版本号(= 2)

  • 与 v1 一样,256个扇出扇出表。

  • 一个已排序的20字节 SHA-1 对象名称表。它们被打包在一起而没有偏移值,以减少特定对象名称的二进制搜索的高速缓存占用空间。

  • 打包对象数据的4字节 CRC 32值表。这是 v2 中的新功能,因此压缩数据可以在重新打包时直接从包中复制,而不会发生未检测到的数据损坏。

  • 一个4字节的偏移量值表(按照网络字节顺序)。这些通常是31位的打包文件偏移量,但大偏移量被编码为下一个带有 msbit 集的表中的索引。

  • 一个8字节的偏移量表(对于小于2 GiB 的包文件为空)。包文件使用大量使用的对象组织,因此大多数对象引用不需要引用此表。

  • 与 v1 包文件相同的尾部:对应包文件末尾的20字节 SHA-1 校验和副本。

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

上一篇: 下一篇: