pseudo-merge: scaffolding for reads

Implement scaffolding within the new pseudo-merge compilation unit necessary to use the pseudo-merge API from within the pack-bitmap.c machinery. The core of this scaffolding is two-fold: - The `pseudo_merge` structure itself, which represents an individual pseudo-merge bitmap. It has fields for both bitmaps, as well as metadata about its position within the memory-mapped region, and a few extra bits indicating whether or not it is satisfied, and which bitmaps(s, if any) have been read, since they are initialized lazily. - The `pseudo_merge_map` structure, which holds an array of pseudo_merges, as well as a pointer to the memory-mapped region containing the pseudo-merge serialization from within a .bitmap file. Note that the `bitmap_index` structure is defined statically within the pack-bitmap.o compilation unit, so we can't take in a `struct bitmap_index *`. Instead, wrap the primary components necessary to read the pseudo-merges in this new structure to avoid exposing the implementation details of the `bitmap_index` structure. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 23, 2024 at 17:26 UTC 0f81b9cb2c5984ae1b090eb79d139e0a7d9ad8df
2 files changed +75
pseudo-merge.c
+10
@@ -454,3 +454,13 @@ void select_pseudo_merges(struct bitmap_writer *writer,
454
455 stop_progress(&progress);
456 }
457 +
458 +void free_pseudo_merge_map(struct pseudo_merge_map *pm)
459 +{
460 + uint32_t i;
461 + for (i = 0; i < pm->nr; i++) {
462 + ewah_pool_free(pm->v[i].commits);
463 + ewah_pool_free(pm->v[i].bitmap);
464 + }
465 + free(pm->v);
466 +}
pseudo-merge.h
+65
@@ -97,4 +97,69 @@ struct pseudo_merge_commit_idx {
97 void select_pseudo_merges(struct bitmap_writer *writer,
98 struct commit **commits, size_t commits_nr);
99
100 +/*
101 + * Represents a serialized view of a file containing pseudo-merge(s)
102 + * (see Documentation/technical/bitmap-format.txt for a specification
103 + * of the format).
104 + */
105 +struct pseudo_merge_map {
106 + /*
107 + * An array of pseudo-merge(s), lazily loaded from the .bitmap
108 + * file.
109 + */
110 + struct pseudo_merge *v;
111 + size_t nr;
112 + size_t commits_nr;
113 +
114 + /*
115 + * Pointers into a memory-mapped view of the .bitmap file:
116 + *
117 + * - map: the beginning of the .bitmap file
118 + * - commits: the beginning of the pseudo-merge commit index
119 + * - map_size: the size of the .bitmap file
120 + */
121 + const unsigned char *map;
122 + const unsigned char *commits;
123 +
124 + size_t map_size;
125 +};
126 +
127 +/*
128 + * An individual pseudo-merge, storing a pair of lazily-loaded
129 + * bitmaps:
130 + *
131 + * - commits: the set of commit(s) that are part of the pseudo-merge
132 + * - bitmap: the set of object(s) reachable from the above set of
133 + * commits.
134 + *
135 + * The `at` and `bitmap_at` fields are used to store the locations of
136 + * each of the above bitmaps in the .bitmap file.
137 + */
138 +struct pseudo_merge {
139 + struct ewah_bitmap *commits;
140 + struct ewah_bitmap *bitmap;
141 +
142 + off_t at;
143 + off_t bitmap_at;
144 +
145 + /*
146 + * `satisfied` indicates whether the given pseudo-merge has been
147 + * used.
148 + *
149 + * `loaded_commits` and `loaded_bitmap` indicate whether the
150 + * respective bitmaps have been loaded and read from the
151 + * .bitmap file.
152 + */
153 + unsigned satisfied : 1,
154 + loaded_commits : 1,
155 + loaded_bitmap : 1;
156 +};
157 +
158 +/*
159 + * Frees the given pseudo-merge map, releasing any memory held by (a)
160 + * parsed EWAH bitmaps, or (b) the array of pseudo-merges itself. Does
161 + * not free the memory-mapped view of the .bitmap file.
162 + */
163 +void free_pseudo_merge_map(struct pseudo_merge_map *pm);
164 +
165 #endif