Skip to content

Commit 5b5d5b5

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea0024d commit 5b5d5b5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

bloom.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int load_bloom_filter_from_graph(struct commit_graph *g,
8888
filter->data = (unsigned char *)(g->chunk_bloom_data +
8989
sizeof(unsigned char) * start_index +
9090
BLOOMDATA_CHUNK_HEADER_SIZE);
91+
filter->version = g->bloom_filter_settings->hash_version;
9192

9293
return 1;
9394
}
@@ -210,11 +211,13 @@ static int pathmap_cmp(const void *hashmap_cmp_fn_data UNUSED,
210211
return strcmp(e1->path, e2->path);
211212
}
212213

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)
214216
{
215217
filter->data = xmalloc(1);
216218
filter->data[0] = 0xFF;
217219
filter->len = 1;
220+
filter->version = version;
218221
}
219222

220223
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,
299302
}
300303

301304
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);
303307
if (computed)
304308
*computed |= BLOOM_TRUNC_LARGE;
305309
goto cleanup;
306310
}
307311

308312
filter->len = (hashmap_get_size(&pathmap) * settings->bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;
313+
filter->version = settings->hash_version;
309314
if (!filter->len) {
310315
if (computed)
311316
*computed |= BLOOM_TRUNC_EMPTY;
@@ -325,7 +330,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
325330
} else {
326331
for (i = 0; i < diff_queued_diff.nr; i++)
327332
diff_free_filepair(diff_queued_diff.queue[i]);
328-
init_truncated_large_filter(filter);
333+
init_truncated_large_filter(filter, settings->hash_version);
329334

330335
if (computed)
331336
*computed |= BLOOM_TRUNC_LARGE;

bloom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct bloom_filter_settings {
5353
struct bloom_filter {
5454
unsigned char *data;
5555
size_t len;
56+
int version;
5657
};
5758

5859
/*

0 commit comments

Comments
 (0)