bloom: annotate filters with hash version

In subsequent commits, we will want to load existing Bloom filters out of a commit-graph, even when the hash version they were computed with does not match the value of `commitGraph.changedPathVersion`. In order to differentiate between the two, add a "version" field to each Bloom filter. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jun 25, 2024 at 13:39 UTC 5b5d5b598ccb8d5eb8a1de3abbf7b5829f9ac4fe
2 files changed +9 -3
bloom.c
+8 -3
@@ -88,6 +88,7 @@ int load_bloom_filter_from_graph(struct commit_graph *g,
88 filter->data = (unsigned char *)(g->chunk_bloom_data +
89 sizeof(unsigned char) * start_index +
90 BLOOMDATA_CHUNK_HEADER_SIZE);
91 + filter->version = g->bloom_filter_settings->hash_version;
92
93 return 1;
94 }
@@ -210,11 +211,13 @@ static int pathmap_cmp(const void *hashmap_cmp_fn_data UNUSED,
211 return strcmp(e1->path, e2->path);
212 }
213
213 -static void init_truncated_large_filter(struct bloom_filter *filter)
214 +static void init_truncated_large_filter(struct bloom_filter *filter,
215 + int version)
216 {
217 filter->data = xmalloc(1);
218 filter->data[0] = 0xFF;
219 filter->len = 1;
220 + filter->version = version;
221 }
222
223 struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
@@ -299,13 +302,15 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
302 }
303
304 if (hashmap_get_size(&pathmap) > settings->max_changed_paths) {
302 - init_truncated_large_filter(filter);
305 + init_truncated_large_filter(filter,
306 + settings->hash_version);
307 if (computed)
308 *computed |= BLOOM_TRUNC_LARGE;
309 goto cleanup;
310 }
311
312 filter->len = (hashmap_get_size(&pathmap) * settings->bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;
313 + filter->version = settings->hash_version;
314 if (!filter->len) {
315 if (computed)
316 *computed |= BLOOM_TRUNC_EMPTY;
@@ -325,7 +330,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
330 } else {
331 for (i = 0; i < diff_queued_diff.nr; i++)
332 diff_free_filepair(diff_queued_diff.queue[i]);
328 - init_truncated_large_filter(filter);
333 + init_truncated_large_filter(filter, settings->hash_version);
334
335 if (computed)
336 *computed |= BLOOM_TRUNC_LARGE;
bloom.h
+1
@@ -53,6 +53,7 @@ struct bloom_filter_settings {
53 struct bloom_filter {
54 unsigned char *data;
55 size_t len;
56 + int version;
57 };
58
59 /*