Skip to content

Commit 97ffa4f

Browse files
ttaylorrgitster
authored andcommitted
commit-graph.c: store maximum changed paths
For now, we assume that there is a fixed constant describing the maximum number of changed paths we are willing to store in a Bloom filter. Prepare for that to (at least partially) not be the case by making it a member of the 'struct bloom_filter_settings'. This will be helpful in the subsequent patches by reducing the size of test cases that exercise storing too many changed paths, as well as preparing for an eventual future in which this value might change. This patch alone does not cause newly generated Bloom filters to use a custom upper-bound on the maximum number of changed paths a single Bloom filter can hold, that will occur in a later patch. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b66d847 commit 97ffa4f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

bloom.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ struct bloom_filter_settings {
2828
* that contain n*b bits.
2929
*/
3030
uint32_t bits_per_entry;
31+
32+
/*
33+
* The maximum number of changed paths per commit
34+
* before declaring a Bloom filter to be too-large.
35+
*
36+
* Not written to the commit-graph file.
37+
*/
38+
uint32_t max_changed_paths;
3139
};
3240

33-
#define DEFAULT_BLOOM_FILTER_SETTINGS { 1, 7, 10 }
41+
#define DEFAULT_BLOOM_MAX_CHANGES 512
42+
#define DEFAULT_BLOOM_FILTER_SETTINGS { 1, 7, 10, DEFAULT_BLOOM_MAX_CHANGES }
3443
#define BITS_PER_WORD 8
3544
#define BLOOMDATA_CHUNK_HEADER_SIZE 3 * sizeof(uint32_t)
3645

commit-graph.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ struct commit_graph *parse_commit_graph(struct repository *r,
417417
graph->bloom_filter_settings->hash_version = hash_version;
418418
graph->bloom_filter_settings->num_hashes = get_be32(data + chunk_offset + 4);
419419
graph->bloom_filter_settings->bits_per_entry = get_be32(data + chunk_offset + 8);
420+
graph->bloom_filter_settings->max_changed_paths = DEFAULT_BLOOM_MAX_CHANGES;
420421
}
421422
break;
422423
}
@@ -1194,6 +1195,7 @@ static void trace2_bloom_filter_settings(struct write_commit_graph_context *ctx)
11941195
jw_object_intmax(&jw, "hash_version", ctx->bloom_settings->hash_version);
11951196
jw_object_intmax(&jw, "num_hashes", ctx->bloom_settings->num_hashes);
11961197
jw_object_intmax(&jw, "bits_per_entry", ctx->bloom_settings->bits_per_entry);
1198+
jw_object_intmax(&jw, "max_changed_paths", ctx->bloom_settings->max_changed_paths);
11971199
jw_end(&jw);
11981200

11991201
trace2_data_json("bloom", ctx->r, "settings", &jw);
@@ -1662,6 +1664,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
16621664
bloom_settings.bits_per_entry);
16631665
bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES",
16641666
bloom_settings.num_hashes);
1667+
bloom_settings.max_changed_paths = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS",
1668+
bloom_settings.max_changed_paths);
16651669
ctx->bloom_settings = &bloom_settings;
16661670
}
16671671

t/t4216-log-bloom.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ test_expect_success 'persist filter settings' '
169169
GIT_TEST_BLOOM_SETTINGS_NUM_HASHES=9 \
170170
GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY=15 \
171171
git commit-graph write --reachable --changed-paths &&
172-
grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15}" trace2.txt &&
172+
grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15,\"max_changed_paths\":512" trace2.txt &&
173173
GIT_TRACE2_EVENT="$(pwd)/trace2-auto.txt" \
174174
GIT_TRACE2_EVENT_NESTING=5 \
175175
git commit-graph write --reachable --changed-paths &&
176-
grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15}" trace2-auto.txt
176+
grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15,\"max_changed_paths\":512" trace2-auto.txt
177177
'
178178

179179
test_expect_success 'correctly report changes over limit' '

0 commit comments

Comments
 (0)