Skip to content

Commit 917a54c

Browse files
ttaylorrgitster
authored andcommitted
Documentation: describe MIDX-based bitmaps
Update the technical documentation to describe the multi-pack bitmap format. This patch merely introduces the new format, and describes its high-level ideas. Git does not yet know how to read nor write these multi-pack variants, and so the subsequent patches will: - Introduce code to interpret multi-pack bitmaps, according to this document. - Then, introduce code to write multi-pack bitmaps from the 'git multi-pack-index write' sub-command. Finally, the implementation will gain tests in subsequent patches (as opposed to inline with the patch teaching Git how to write multi-pack bitmaps) to avoid a cyclic dependency. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d7f7f2 commit 917a54c

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

Documentation/technical/bitmap-format.txt

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
GIT bitmap v1 format
22
====================
33

4+
== Pack and multi-pack bitmaps
5+
6+
Bitmaps store reachability information about the set of objects in a packfile,
7+
or a multi-pack index (MIDX). The former is defined obviously, and the latter is
8+
defined as the union of objects in packs contained in the MIDX.
9+
10+
A bitmap may belong to either one pack, or the repository's multi-pack index (if
11+
it exists). A repository may have at most one bitmap.
12+
13+
An object is uniquely described by its bit position within a bitmap:
14+
15+
- If the bitmap belongs to a packfile, the __n__th bit corresponds to
16+
the __n__th object in pack order. For a function `offset` which maps
17+
objects to their byte offset within a pack, pack order is defined as
18+
follows:
19+
20+
o1 <= o2 <==> offset(o1) <= offset(o2)
21+
22+
- If the bitmap belongs to a MIDX, the __n__th bit corresponds to the
23+
__n__th object in MIDX order. With an additional function `pack` which
24+
maps objects to the pack they were selected from by the MIDX, MIDX order
25+
is defined as follows:
26+
27+
o1 <= o2 <==> pack(o1) <= pack(o2) /\ offset(o1) <= offset(o2)
28+
29+
The ordering between packs is done according to the MIDX's .rev file.
30+
Notably, the preferred pack sorts ahead of all other packs.
31+
32+
The on-disk representation (described below) of a bitmap is the same regardless
33+
of whether or not that bitmap belongs to a packfile or a MIDX. The only
34+
difference is the interpretation of the bits, which is described above.
35+
36+
Certain bitmap extensions are supported (see: Appendix B). No extensions are
37+
required for bitmaps corresponding to packfiles. For bitmaps that correspond to
38+
MIDXs, both the bit-cache and rev-cache extensions are required.
39+
40+
== On-disk format
41+
442
- A header appears at the beginning:
543

644
4-byte signature: {'B', 'I', 'T', 'M'}
@@ -14,17 +52,19 @@ GIT bitmap v1 format
1452
The following flags are supported:
1553

1654
- BITMAP_OPT_FULL_DAG (0x1) REQUIRED
17-
This flag must always be present. It implies that the bitmap
18-
index has been generated for a packfile with full closure
19-
(i.e. where every single object in the packfile can find
20-
its parent links inside the same packfile). This is a
21-
requirement for the bitmap index format, also present in JGit,
22-
that greatly reduces the complexity of the implementation.
55+
This flag must always be present. It implies that the
56+
bitmap index has been generated for a packfile or
57+
multi-pack index (MIDX) with full closure (i.e. where
58+
every single object in the packfile/MIDX can find its
59+
parent links inside the same packfile/MIDX). This is a
60+
requirement for the bitmap index format, also present in
61+
JGit, that greatly reduces the complexity of the
62+
implementation.
2363

2464
- BITMAP_OPT_HASH_CACHE (0x4)
2565
If present, the end of the bitmap file contains
2666
`N` 32-bit name-hash values, one per object in the
27-
pack. The format and meaning of the name-hash is
67+
pack/MIDX. The format and meaning of the name-hash is
2868
described below.
2969

3070
4-byte entry count (network byte order)
@@ -33,7 +73,8 @@ GIT bitmap v1 format
3373

3474
20-byte checksum
3575

36-
The SHA1 checksum of the pack this bitmap index belongs to.
76+
The SHA1 checksum of the pack/MIDX this bitmap index
77+
belongs to.
3778

3879
- 4 EWAH bitmaps that act as type indexes
3980

@@ -50,7 +91,7 @@ GIT bitmap v1 format
5091
- Tags
5192

5293
In each bitmap, the `n`th bit is set to true if the `n`th object
53-
in the packfile is of that type.
94+
in the packfile or multi-pack index is of that type.
5495

5596
The obvious consequence is that the OR of all 4 bitmaps will result
5697
in a full set (all bits set), and the AND of all 4 bitmaps will
@@ -62,8 +103,9 @@ GIT bitmap v1 format
62103
Each entry contains the following:
63104

64105
- 4-byte object position (network byte order)
65-
The position **in the index for the packfile** where the
66-
bitmap for this commit is found.
106+
The position **in the index for the packfile or
107+
multi-pack index** where the bitmap for this commit is
108+
found.
67109

68110
- 1-byte XOR-offset
69111
The xor offset used to compress this bitmap. For an entry
@@ -146,10 +188,11 @@ Name-hash cache
146188
---------------
147189

148190
If the BITMAP_OPT_HASH_CACHE flag is set, the end of the bitmap contains
149-
a cache of 32-bit values, one per object in the pack. The value at
191+
a cache of 32-bit values, one per object in the pack/MIDX. The value at
150192
position `i` is the hash of the pathname at which the `i`th object
151-
(counting in index order) in the pack can be found. This can be fed
152-
into the delta heuristics to compare objects with similar pathnames.
193+
(counting in index or multi-pack index order) in the pack/MIDX can be found.
194+
This can be fed into the delta heuristics to compare objects with similar
195+
pathnames.
153196

154197
The hash algorithm used is:
155198

Documentation/technical/multi-pack-index.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ Future Work
7171
still reducing the number of binary searches required for object
7272
lookups.
7373

74-
- The reachability bitmap is currently paired directly with a single
75-
packfile, using the pack-order as the object order to hopefully
76-
compress the bitmaps well using run-length encoding. This could be
77-
extended to pair a reachability bitmap with a multi-pack-index. If
78-
the multi-pack-index is extended to store a "stable object order"
74+
- If the multi-pack-index is extended to store a "stable object order"
7975
(a function Order(hash) = integer that is constant for a given hash,
80-
even as the multi-pack-index is updated) then a reachability bitmap
81-
could point to a multi-pack-index and be updated independently.
76+
even as the multi-pack-index is updated) then MIDX bitmaps could be
77+
updated independently of the MIDX.
8278

8379
- Packfiles can be marked as "special" using empty files that share
8480
the initial name but replace ".pack" with ".keep" or ".promisor".

0 commit comments

Comments
 (0)