English ▾ 主题 ▾ 最新版本 ▾ gitformat-commit-graph 上次更新于 2.47.0

名称

gitformat-commit-graph - Git commit-graph 格式

概要

$GIT_DIR/objects/info/commit-graph
$GIT_DIR/objects/info/commit-graphs/*

描述

Git commit-graph 存储提交 OID 的列表和一些关联的元数据,包括

  • 提交的生成编号。

  • 根树 OID。

  • 提交日期。

  • 提交的父项,使用图形文件中的位置引用存储。

  • 提交的 Bloom 过滤器,包含提交及其第一个父项之间更改的路径(如果已请求)。

这些位置引用存储为无符号 32 位整数,对应于提交 OID 列表中的数组位置。 由于我们使用的一些特殊常量来跟踪父项,因此我们最多可以存储 (1 << 30) + (1 << 29) + (1 << 28) - 1 个提交(大约 18 亿个)。

Commit-graph 文件具有以下格式

为了允许添加额外数据的扩展,我们将正文组织成“块”,并在正文的开头提供一个二进制查找表。 标头包含某些值,例如块数和哈希类型。

所有多字节数字均采用网络字节顺序。

标头

4-byte signature:
    The signature is: {'C', 'G', 'P', 'H'}
1-byte version number:
    Currently, the only valid version is 1.
 1-byte Hash Version
     We infer the hash length (H) from this value:
1 => SHA-1
2 => SHA-256
     If the hash type does not match the repository's hash algorithm, the
     commit-graph file should be ignored with a warning presented to the
     user.
1-byte number (C) of "chunks"
1-byte number (B) of base commit-graphs
    We infer the length (H*B) of the Base Graphs chunk
    from this value.

块查找

(C + 1) * 12 bytes listing the table of contents for the chunks:
    First 4 bytes describe the chunk id. Value 0 is a terminating label.
    Other 8 bytes provide the byte-offset in current file for chunk to
    start. (Chunks are ordered contiguously in the file, so you can infer
    the length using the next chunk position if necessary.) Each chunk
    ID appears at most once.
The CHUNK LOOKUP matches the table of contents from
the chunk-based file format, see gitformat-chunk[5]
The remaining data in the body is described one chunk at a time, and
these chunks may be given in any order. Chunks are required unless
otherwise specified.

块数据

OID 扇出 (ID: {O, I, D, F}) (256 * 4 字节)

The ith entry, F[i], stores the number of OIDs with first
byte at most i. Thus F[255] stores the total
number of commits (N).

OID 查找 (ID: {O, I, D, L}) (N * H 字节)

The OIDs for all commits in the graph, sorted in ascending order.

提交数据 (ID: {C, D, A, T }) (N * (H + 16) 字节)

  • 前 H 个字节用于根树的 OID。

  • 接下来的 8 个字节用于第 i 个提交的前两个父项的位置。 如果该位置没有父项,则存储值 0x70000000。 如果有超过两个父项,则第二个值的最高有效位为开,而其他位存储到 Extra Edge List 块的数组位置。

  • 接下来的 8 个字节存储提交的拓扑级别(生成编号 v1)和自 EPOCH 以来以秒为单位的提交时间。 生成编号使用前 4 个字节的较高 30 位,而提交时间使用第二个 4 个字节的 32 位,以及最低字节的最低 2 位,存储提交时间的第 33 位和第 34 位。

生成数据 (ID: {G, D, A, 2 }) (N * 4 字节) [可选]

  • 此 4 字节值列表存储提交的更正提交日期偏移量,其排列顺序与提交数据块相同。

  • 如果无法在 31 位内存储更正的提交日期偏移量,则该值的最高有效位为开,而其他位存储更正的提交日期到 Generation Data Overflow 块中的位置。

  • 仅当 commit-graph 文件由兼容版本的 Git 写入时,并且在拆分 commit-graph 链的情况下,最顶层也具有 Generation Data 块,才存在 Generation Data 块。

Generation Data Overflow (ID: {G, D, O, 2 }) [可选]

  • 此 8 字节值列表存储无法在 31 位内存储的、具有更正的提交日期偏移量的提交的更正提交日期偏移量。

  • 仅当存在 Generation Data 块且至少一个更正的提交日期偏移量无法在 31 位内存储时,才存在 Generation Data Overflow 块。

Extra Edge List (ID: {E, D, G, E}) [可选]

This list of 4-byte values store the second through nth parents for
all octopus merges. The second parent value in the commit data stores
an array position within this list along with the most-significant bit
on. Starting at that array position, iterate through this list of commit
positions for the parents until reaching a value with the most-significant
bit on. The other bits correspond to the position of the last parent.

Bloom Filter Index (ID: {B, I, D, X}) (N * 4 字节) [可选]

  • 第 i 个条目 BIDX[i] 存储按字典顺序从提交 0 到提交 i(包括提交 i)的所有 Bloom 过滤器中的字节数。 第 i 个提交的 Bloom 过滤器的范围从 BIDX[i-1] 到 BIDX[i](加上标头长度),其中 BIDX[-1] 为 0。

  • 如果 BDAT 块不存在,则忽略 BIDX 块。

Bloom Filter Data (ID: {B, D, A, T}) [可选]

  • 它以包含三个无符号 32 位整数的标头开头

    • 正在使用的哈希算法的版本。 我们目前支持值 2,该值对应于 Murmur3 哈希的 32 位版本,其实现方式与 https://en.wikipedia.org/wiki/MurmurHash#Algorithm 中描述的完全一样,并且双重哈希技术使用种子值 0x293ae76f 和 0x7e646e2,如 https://doi.org/10.1007/978-3-540-30494-4_26 “概率验证中的 Bloom 过滤器”中所述。 版本 1 Bloom 过滤器存在一个错误,当 char 是有符号的且存储库的路径名具有字符 >= 0x80 时会出现该错误;Git 支持读取和写入它们,但此功能将在 Git 的未来版本中删除。

    • 路径被哈希的次数,因此位位置的数量累积地确定文件是否存在于提交中。

    • Bloom 过滤器中每个条目的最小位数 b。 如果过滤器包含 n 个条目,则过滤器大小是包含 n*b 位的最小 64 位字数。

  • 块的其余部分是按字典顺序排列的所有计算的提交的 Bloom 过滤器的串联。

  • 注意:没有更改或更改超过 512 个的提交的 Bloom 过滤器长度为 1,所有位分别设置为零或一。

  • 当且仅当存在 BIDX 时,才存在 BDAT 块。

Base Graphs List (ID: {B, A, S, E}) [可选]

This list of H-byte hashes describe a set of B commit-graph files that
form a commit-graph chain. The graph position for the ith commit in this
file's OID Lookup chunk is equal to i plus the number of commits in all
base graphs.  If B is non-zero, this chunk must exist.

TRAILER

H-byte HASH-checksum of all of the above.

历史记录

Generation Data (GDA2) 和 Generation Data Overflow (GDO2) 块的块 ID 中包含数字 2,因为以前版本的 Git 在这些块中写入了可能错误的数据,其 ID 为“GDAT”和“GDOV”。 通过更改 ID,较新版本的 Git 将静默忽略这些较旧的块,并写入新信息而不信任不正确的数据。

GIT

属于 git[1] 套件

scroll-to-top