blob: 484b185ba98bdc00efc147851abdcbe4958ee21f [file] [log] [blame]
Junio C Hamanoccb82522018-05-08 07:52:091Git commit graph format
2=======================
3
4The Git commit graph stores a list of commit OIDs and some associated
5metadata, including:
6
Junio C Hamanoa70c9882021-02-23 00:57:127- The generation number of the commit.
Junio C Hamanoccb82522018-05-08 07:52:098
9- The root tree OID.
10
11- The commit date.
12
13- The parents of the commit, stored using positional references within
14 the graph file.
15
Junio C Hamano864182b2020-05-01 21:53:5116- The Bloom filter of the commit carrying the paths that were changed between
17 the commit and its first parent, if requested.
18
Junio C Hamanoccb82522018-05-08 07:52:0919These positional references are stored as unsigned 32-bit integers
Junio C Hamanoea1ac8d2018-07-18 20:16:4820corresponding to the array position within the list of commit OIDs. Due
21to some special constants we use to track parents, we can store at most
22(1 << 30) + (1 << 29) + (1 << 28) - 1 (around 1.8 billion) commits.
Junio C Hamanoccb82522018-05-08 07:52:0923
24== Commit graph files have the following format:
25
26In order to allow extensions that add extra data to the graph, we organize
27the body into "chunks" and provide a binary lookup table at the beginning
28of the body. The header includes certain values, such as number of chunks
29and hash type.
30
Junio C Hamano28c33de2020-07-30 21:22:2631All multi-byte numbers are in network byte order.
Junio C Hamanoccb82522018-05-08 07:52:0932
33HEADER:
34
35 4-byte signature:
36 The signature is: {'C', 'G', 'P', 'H'}
37
38 1-byte version number:
39 Currently, the only valid version is 1.
40
Junio C Hamano779537c2020-08-19 23:48:5141 1-byte Hash Version
42 We infer the hash length (H) from this value:
431 => SHA-1
442 => SHA-256
45 If the hash type does not match the repository's hash algorithm, the
46 commit-graph file should be ignored with a warning presented to the
47 user.
Junio C Hamanoccb82522018-05-08 07:52:0948
49 1-byte number (C) of "chunks"
50
Junio C Hamanoa42e0332019-07-19 19:49:3751 1-byte number (B) of base commit-graphs
52 We infer the length (H*B) of the Base Graphs chunk
53 from this value.
Junio C Hamanoccb82522018-05-08 07:52:0954
55CHUNK LOOKUP:
56
57 (C + 1) * 12 bytes listing the table of contents for the chunks:
58 First 4 bytes describe the chunk id. Value 0 is a terminating label.
59 Other 8 bytes provide the byte-offset in current file for chunk to
60 start. (Chunks are ordered contiguously in the file, so you can infer
61 the length using the next chunk position if necessary.) Each chunk
62 ID appears at most once.
63
Junio C Hamanob66f8a52021-03-03 07:07:4964 The CHUNK LOOKUP matches the table of contents from
65 link:technical/chunk-format.html[the chunk-based file format].
66
Junio C Hamanoccb82522018-05-08 07:52:0967 The remaining data in the body is described one chunk at a time, and
68 these chunks may be given in any order. Chunks are required unless
69 otherwise specified.
70
71CHUNK DATA:
72
73 OID Fanout (ID: {'O', 'I', 'D', 'F'}) (256 * 4 bytes)
74 The ith entry, F[i], stores the number of OIDs with first
75 byte at most i. Thus F[255] stores the total
76 number of commits (N).
77
78 OID Lookup (ID: {'O', 'I', 'D', 'L'}) (N * H bytes)
79 The OIDs for all commits in the graph, sorted in ascending order.
80
Junio C Hamanoea1ac8d2018-07-18 20:16:4881 Commit Data (ID: {'C', 'D', 'A', 'T' }) (N * (H + 16) bytes)
Junio C Hamanoccb82522018-05-08 07:52:0982 * The first H bytes are for the OID of the root tree.
83 * The next 8 bytes are for the positions of the first two parents
Junio C Hamanob89e21b2020-09-22 20:14:5384 of the ith commit. Stores value 0x70000000 if no parent in that
Junio C Hamanoccb82522018-05-08 07:52:0985 position. If there are more than two parents, the second value
86 has its most-significant bit on and the other bits store an array
Junio C Hamano2567b322019-02-05 23:33:5687 position into the Extra Edge List chunk.
Junio C Hamanoa70c9882021-02-23 00:57:1288 * The next 8 bytes store the topological level (generation number v1)
89 of the commit and
Junio C Hamanoccb82522018-05-08 07:52:0990 the commit time in seconds since EPOCH. The generation number
91 uses the higher 30 bits of the first 4 bytes, while the commit
92 time uses the 32 bits of the second 4 bytes, along with the lowest
93 2 bits of the lowest byte, storing the 33rd and 34th bit of the
94 commit time.
95
Junio C Hamano14390e22022-03-17 01:11:1296 Generation Data (ID: {'G', 'D', 'A', '2' }) (N * 4 bytes) [Optional]
Junio C Hamanoa70c9882021-02-23 00:57:1297 * This list of 4-byte values store corrected commit date offsets for the
98 commits, arranged in the same order as commit data chunk.
99 * If the corrected commit date offset cannot be stored within 31 bits,
100 the value has its most-significant bit on and the other bits store
101 the position of corrected commit date into the Generation Data Overflow
102 chunk.
103 * Generation Data chunk is present only when commit-graph file is written
104 by compatible versions of Git and in case of split commit-graph chains,
105 the topmost layer also has Generation Data chunk.
106
Junio C Hamano14390e22022-03-17 01:11:12107 Generation Data Overflow (ID: {'G', 'D', 'O', '2' }) [Optional]
Junio C Hamanoa70c9882021-02-23 00:57:12108 * This list of 8-byte values stores the corrected commit date offsets
109 for commits with corrected commit date offsets that cannot be
110 stored within 31 bits.
111 * Generation Data Overflow chunk is present only when Generation Data
112 chunk is present and atleast one corrected commit date offset cannot
113 be stored within 31 bits.
114
Junio C Hamano2567b322019-02-05 23:33:56115 Extra Edge List (ID: {'E', 'D', 'G', 'E'}) [Optional]
Junio C Hamanoccb82522018-05-08 07:52:09116 This list of 4-byte values store the second through nth parents for
117 all octopus merges. The second parent value in the commit data stores
118 an array position within this list along with the most-significant bit
119 on. Starting at that array position, iterate through this list of commit
120 positions for the parents until reaching a value with the most-significant
121 bit on. The other bits correspond to the position of the last parent.
122
Junio C Hamano864182b2020-05-01 21:53:51123 Bloom Filter Index (ID: {'B', 'I', 'D', 'X'}) (N * 4 bytes) [Optional]
Junio C Hamano306e7632020-05-14 23:03:19124 * The ith entry, BIDX[i], stores the number of bytes in all Bloom filters
125 from commit 0 to commit i (inclusive) in lexicographic order. The Bloom
126 filter for the i-th commit spans from BIDX[i-1] to BIDX[i] (plus header
127 length), where BIDX[-1] is 0.
Junio C Hamano864182b2020-05-01 21:53:51128 * The BIDX chunk is ignored if the BDAT chunk is not present.
129
130 Bloom Filter Data (ID: {'B', 'D', 'A', 'T'}) [Optional]
131 * It starts with header consisting of three unsigned 32-bit integers:
132 - Version of the hash algorithm being used. We currently only support
133value 1 which corresponds to the 32-bit version of the murmur3 hash
134implemented exactly as described in
135https://en.wikipedia.org/wiki/MurmurHash#Algorithm and the double
136hashing technique using seed values 0x293ae76f and 0x7e646e2 as
137described in https://doi.org/10.1007/978-3-540-30494-4_26 "Bloom Filters
138in Probabilistic Verification"
139 - The number of times a path is hashed and hence the number of bit positions
140 that cumulatively determine whether a file is present in the commit.
141 - The minimum number of bits 'b' per entry in the Bloom filter. If the filter
142 contains 'n' entries, then the filter size is the minimum number of 64-bit
143 words that contain n*b bits.
144 * The rest of the chunk is the concatenation of all the computed Bloom
145 filters for the commits in lexicographic order.
146 * Note: Commits with no changes or more than 512 changes have Bloom filters
Junio C Hamano5880aee2020-09-29 21:51:22147 of length one, with either all bits set to zero or one respectively.
Junio C Hamano864182b2020-05-01 21:53:51148 * The BDAT chunk is present if and only if BIDX is present.
149
Junio C Hamanoa42e0332019-07-19 19:49:37150 Base Graphs List (ID: {'B', 'A', 'S', 'E'}) [Optional]
151 This list of H-byte hashes describe a set of B commit-graph files that
152 form a commit-graph chain. The graph position for the ith commit in this
153 file's OID Lookup chunk is equal to i plus the number of commits in all
154 base graphs. If B is non-zero, this chunk must exist.
155
Junio C Hamanoccb82522018-05-08 07:52:09156TRAILER:
157
158H-byte HASH-checksum of all of the above.
Junio C Hamano14390e22022-03-17 01:11:12159
160== Historical Notes:
161
162The Generation Data (GDA2) and Generation Data Overflow (GDO2) chunks have
163the number '2' in their chunk IDs because a previous version of Git wrote
164possibly erroneous data in these chunks with the IDs "GDAT" and "GDOV". By
165changing the IDs, newer versions of Git will silently ignore those older
166chunks and write the new information without trusting the incorrect data.