From 949197420e3da13c06c6a15fd4b4ed3120753c42 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Wed, 1 Jul 2020 13:27:23 +0000 Subject: bloom: fix logic in get_bloom_filter() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The get_bloom_filter() method is a bit complicated in some parts where it does not need to be. In particular, it needs to return a NULL filter only when compute_if_not_present is zero AND the filter data cannot be loaded from a commit-graph file. This currently happens by accident because the commit-graph does not load changed-path Bloom filters from an existing commit-graph when writing a new one. This will change in a later patch. Also clean up some style issues while we are here. One side-effect of returning a NULL filter is that the filters that are reported as "too large" will now be reported as NULL insead of length zero. This case was not properly covered before, so add a test. Further, remote the counting of the zero-length filters from revision.c and the trace2 logs. Helped-by: René Scharfe Helped-by: SZEDER Gábor Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- commit-graph.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'commit-graph.c') diff --git a/commit-graph.c b/commit-graph.c index 6a28d4a5a6..50ce039a53 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1098,7 +1098,8 @@ static void write_graph_chunk_bloom_indexes(struct hashfile *f, while (list < last) { struct bloom_filter *filter = get_bloom_filter(ctx->r, *list, 0); - cur_pos += filter->len; + size_t len = filter ? filter->len : 0; + cur_pos += len; display_progress(progress, ++i); hashwrite_be32(f, cur_pos); list++; @@ -1126,8 +1127,11 @@ static void write_graph_chunk_bloom_data(struct hashfile *f, while (list < last) { struct bloom_filter *filter = get_bloom_filter(ctx->r, *list, 0); + size_t len = filter ? filter->len : 0; display_progress(progress, ++i); - hashwrite(f, filter->data, filter->len * sizeof(unsigned char)); + + if (len) + hashwrite(f, filter->data, len * sizeof(unsigned char)); list++; } -- cgit v1.2.3