commit-graph-format.txt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. Git commit graph format
  2. =======================
  3. The Git commit graph stores a list of commit OIDs and some associated
  4. metadata, including:
  5. - The generation number of the commit. Commits with no parents have
  6. generation number 1; commits with parents have generation number
  7. one more than the maximum generation number of its parents. We
  8. reserve zero as special, and can be used to mark a generation
  9. number invalid or as "not computed".
  10. - The root tree OID.
  11. - The commit date.
  12. - The parents of the commit, stored using positional references within
  13. the graph file.
  14. - The Bloom filter of the commit carrying the paths that were changed between
  15. the commit and its first parent, if requested.
  16. These positional references are stored as unsigned 32-bit integers
  17. corresponding to the array position within the list of commit OIDs. Due
  18. to some special constants we use to track parents, we can store at most
  19. (1 << 30) + (1 << 29) + (1 << 28) - 1 (around 1.8 billion) commits.
  20. == Commit graph files have the following format:
  21. In order to allow extensions that add extra data to the graph, we organize
  22. the body into "chunks" and provide a binary lookup table at the beginning
  23. of the body. The header includes certain values, such as number of chunks
  24. and hash type.
  25. All multi-byte numbers are in network byte order.
  26. HEADER:
  27. 4-byte signature:
  28. The signature is: {'C', 'G', 'P', 'H'}
  29. 1-byte version number:
  30. Currently, the only valid version is 1.
  31. 1-byte Hash Version
  32. We infer the hash length (H) from this value:
  33. 1 => SHA-1
  34. 2 => SHA-256
  35. If the hash type does not match the repository's hash algorithm, the
  36. commit-graph file should be ignored with a warning presented to the
  37. user.
  38. 1-byte number (C) of "chunks"
  39. 1-byte number (B) of base commit-graphs
  40. We infer the length (H*B) of the Base Graphs chunk
  41. from this value.
  42. CHUNK LOOKUP:
  43. (C + 1) * 12 bytes listing the table of contents for the chunks:
  44. First 4 bytes describe the chunk id. Value 0 is a terminating label.
  45. Other 8 bytes provide the byte-offset in current file for chunk to
  46. start. (Chunks are ordered contiguously in the file, so you can infer
  47. the length using the next chunk position if necessary.) Each chunk
  48. ID appears at most once.
  49. The remaining data in the body is described one chunk at a time, and
  50. these chunks may be given in any order. Chunks are required unless
  51. otherwise specified.
  52. CHUNK DATA:
  53. OID Fanout (ID: {'O', 'I', 'D', 'F'}) (256 * 4 bytes)
  54. The ith entry, F[i], stores the number of OIDs with first
  55. byte at most i. Thus F[255] stores the total
  56. number of commits (N).
  57. OID Lookup (ID: {'O', 'I', 'D', 'L'}) (N * H bytes)
  58. The OIDs for all commits in the graph, sorted in ascending order.
  59. Commit Data (ID: {'C', 'D', 'A', 'T' }) (N * (H + 16) bytes)
  60. * The first H bytes are for the OID of the root tree.
  61. * The next 8 bytes are for the positions of the first two parents
  62. of the ith commit. Stores value 0x70000000 if no parent in that
  63. position. If there are more than two parents, the second value
  64. has its most-significant bit on and the other bits store an array
  65. position into the Extra Edge List chunk.
  66. * The next 8 bytes store the generation number of the commit and
  67. the commit time in seconds since EPOCH. The generation number
  68. uses the higher 30 bits of the first 4 bytes, while the commit
  69. time uses the 32 bits of the second 4 bytes, along with the lowest
  70. 2 bits of the lowest byte, storing the 33rd and 34th bit of the
  71. commit time.
  72. Extra Edge List (ID: {'E', 'D', 'G', 'E'}) [Optional]
  73. This list of 4-byte values store the second through nth parents for
  74. all octopus merges. The second parent value in the commit data stores
  75. an array position within this list along with the most-significant bit
  76. on. Starting at that array position, iterate through this list of commit
  77. positions for the parents until reaching a value with the most-significant
  78. bit on. The other bits correspond to the position of the last parent.
  79. Bloom Filter Index (ID: {'B', 'I', 'D', 'X'}) (N * 4 bytes) [Optional]
  80. * The ith entry, BIDX[i], stores the number of bytes in all Bloom filters
  81. from commit 0 to commit i (inclusive) in lexicographic order. The Bloom
  82. filter for the i-th commit spans from BIDX[i-1] to BIDX[i] (plus header
  83. length), where BIDX[-1] is 0.
  84. * The BIDX chunk is ignored if the BDAT chunk is not present.
  85. Bloom Filter Data (ID: {'B', 'D', 'A', 'T'}) [Optional]
  86. * It starts with header consisting of three unsigned 32-bit integers:
  87. - Version of the hash algorithm being used. We currently only support
  88. value 1 which corresponds to the 32-bit version of the murmur3 hash
  89. implemented exactly as described in
  90. https://en.wikipedia.org/wiki/MurmurHash#Algorithm and the double
  91. hashing technique using seed values 0x293ae76f and 0x7e646e2 as
  92. described in https://doi.org/10.1007/978-3-540-30494-4_26 "Bloom Filters
  93. in Probabilistic Verification"
  94. - The number of times a path is hashed and hence the number of bit positions
  95. that cumulatively determine whether a file is present in the commit.
  96. - The minimum number of bits 'b' per entry in the Bloom filter. If the filter
  97. contains 'n' entries, then the filter size is the minimum number of 64-bit
  98. words that contain n*b bits.
  99. * The rest of the chunk is the concatenation of all the computed Bloom
  100. filters for the commits in lexicographic order.
  101. * Note: Commits with no changes or more than 512 changes have Bloom filters
  102. of length one, with either all bits set to zero or one respectively.
  103. * The BDAT chunk is present if and only if BIDX is present.
  104. Base Graphs List (ID: {'B', 'A', 'S', 'E'}) [Optional]
  105. This list of H-byte hashes describe a set of B commit-graph files that
  106. form a commit-graph chain. The graph position for the ith commit in this
  107. file's OID Lookup chunk is equal to i plus the number of commits in all
  108. base graphs. If B is non-zero, this chunk must exist.
  109. TRAILER:
  110. H-byte HASH-checksum of all of the above.