Skip to content

Commit 4f36440

Browse files
ttaylorrderrickstolee
authored andcommitted
commit-graph: introduce 'get_bloom_filter_settings()'
Many places in the code often need a pointer to the commit-graph's 'struct bloom_filter_settings', in which case they often take the value from the top-most commit-graph. In the non-split case, this works as expected. In the split case, however, things get a little tricky. Not all layers in a chain of incremental commit-graphs are required to themselves have Bloom data, and so whether or not some part of the code uses Bloom filters depends entirely on whether or not the top-most level of the commit-graph chain has Bloom filters. This has been the behavior since Bloom filters were introduced, and has been codified into the tests since a759bfa (t4216: add end to end tests for git log with Bloom filters, 2020-04-06). In fact, t4216.130 requires that Bloom filters are not used in exactly the case described earlier. There is no reason that this needs to be the case, since it is perfectly valid for commits in an earlier layer to have Bloom filters when commits in a newer layer do not. Since Bloom settings are guaranteed in practice to be the same for any layer in a chain that has Bloom data, it is sufficient to traverse the '->base_graph' pointer until either (1) a non-null 'struct bloom_filter_settings *' is found, or (2) until we are at the root of the commit-graph chain. Introduce a 'get_bloom_filter_settings()' function that does just this, and use it instead of purely dereferencing the top-most graph's '->bloom_filter_settings' pointer. While we're at it, add an additional test in t5324 to guard against code in the commit-graph writing machinery that doesn't correctly handle a NULL 'struct bloom_filter *'. Co-authored-by: Derrick Stolee <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc04167 commit 4f36440

File tree

7 files changed

+40
-12
lines changed

7 files changed

+40
-12
lines changed

blame.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,16 +2891,18 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb,
28912891
const char *path)
28922892
{
28932893
struct blame_bloom_data *bd;
2894+
struct bloom_filter_settings *bs;
28942895

28952896
if (!sb->repo->objects->commit_graph)
28962897
return;
28972898

2898-
if (!sb->repo->objects->commit_graph->bloom_filter_settings)
2899+
bs = get_bloom_filter_settings(sb->repo);
2900+
if (!bs)
28992901
return;
29002902

29012903
bd = xmalloc(sizeof(struct blame_bloom_data));
29022904

2903-
bd->settings = sb->repo->objects->commit_graph->bloom_filter_settings;
2905+
bd->settings = bs;
29042906

29052907
bd->alloc = 4;
29062908
bd->nr = 0;

bloom.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int load_bloom_filter_from_graph(struct commit_graph *g,
3838
while (graph_pos < g->num_commits_in_base)
3939
g = g->base_graph;
4040

41-
/* The commit graph commit 'c' lives in doesn't carry bloom filters. */
41+
/* The commit graph commit 'c' lives in doesn't carry Bloom filters. */
4242
if (!g->chunk_bloom_indexes)
4343
return 0;
4444

@@ -195,8 +195,8 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
195195
if (!filter->data) {
196196
load_commit_graph_info(r, c);
197197
if (commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH &&
198-
r->objects->commit_graph->chunk_bloom_indexes)
199-
load_bloom_filter_from_graph(r->objects->commit_graph, filter, c);
198+
load_bloom_filter_from_graph(r->objects->commit_graph, filter, c))
199+
return filter;
200200
}
201201

202202
if (filter->data)

commit-graph.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,17 @@ int generation_numbers_enabled(struct repository *r)
660660
return !!first_generation;
661661
}
662662

663+
struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
664+
{
665+
struct commit_graph *g = r->objects->commit_graph;
666+
while (g) {
667+
if (g->bloom_filter_settings)
668+
return g->bloom_filter_settings;
669+
g = g->base_graph;
670+
}
671+
return NULL;
672+
}
673+
663674
static void close_commit_graph_one(struct commit_graph *g)
664675
{
665676
if (!g)

commit-graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size);
8787
*/
8888
int generation_numbers_enabled(struct repository *r);
8989

90+
struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r);
91+
9092
enum commit_graph_write_flags {
9193
COMMIT_GRAPH_WRITE_APPEND = (1 << 0),
9294
COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),

revision.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,7 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
681681

682682
repo_parse_commit(revs->repo, revs->commits->item);
683683

684-
if (!revs->repo->objects->commit_graph)
685-
return;
686-
687-
revs->bloom_filter_settings = revs->repo->objects->commit_graph->bloom_filter_settings;
684+
revs->bloom_filter_settings = get_bloom_filter_settings(revs->repo);
688685
if (!revs->bloom_filter_settings)
689686
return;
690687

t/t4216-log-bloom.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ setup () {
6060

6161
test_bloom_filters_used () {
6262
log_args=$1
63-
bloom_trace_prefix="statistics:{\"filter_not_present\":0,\"maybe\""
63+
bloom_trace_prefix="statistics:{\"filter_not_present\":${2:-0},\"maybe\""
6464
setup "$log_args" &&
6565
grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" &&
6666
test_cmp log_wo_bloom log_w_bloom &&
@@ -134,8 +134,11 @@ test_expect_success 'setup - add commit-graph to the chain without Bloom filters
134134
test_line_count = 2 .git/objects/info/commit-graphs/commit-graph-chain
135135
'
136136

137-
test_expect_success 'Do not use Bloom filters if the latest graph does not have Bloom filters.' '
138-
test_bloom_filters_not_used "-- A/B"
137+
test_expect_success 'use Bloom filters even if the latest graph does not have Bloom filters' '
138+
# Ensure that the number of empty filters is equal to the number of
139+
# filters in the latest graph layer to prove that they are loaded (and
140+
# ignored).
141+
test_bloom_filters_used "-- A/B" 3
139142
'
140143

141144
test_expect_success 'setup - add commit-graph to the chain with Bloom filters' '

t/t5324-split-commit-graph.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,17 @@ done <<\EOF
425425
0600 -r--------
426426
EOF
427427

428+
test_expect_success '--split=replace with partial Bloom data' '
429+
rm -rf $graphdir $infodir/commit-graph &&
430+
git reset --hard commits/3 &&
431+
git rev-list -1 HEAD~2 >a &&
432+
git rev-list -1 HEAD~1 >b &&
433+
git commit-graph write --split=no-merge --stdin-commits --changed-paths <a &&
434+
git commit-graph write --split=no-merge --stdin-commits <b &&
435+
git commit-graph write --split=replace --stdin-commits --changed-paths <c &&
436+
ls $graphdir/graph-*.graph >graph-files &&
437+
test_line_count = 1 graph-files &&
438+
verify_chain_files_exist $graphdir
439+
'
440+
428441
test_done

0 commit comments

Comments
 (0)