@matheusbsbs / matheus-bagliano / commits / 9a7a9ed10d
Fork 0

bloom: use provided 'struct bloom_filter_settings'

When 'get_or_compute_bloom_filter()' needs to compute a Bloom filter from scratch, it looks to the default 'struct bloom_filter_settings' in order to determine the maximum number of changed paths, number of bits per entry, and so on. All of these values have so far been constant, and so there was no need to pass in a pointer from the caller (eg., the one that is stored in the 'struct write_commit_graph_context'). Start passing in a 'struct bloom_filter_settings *' instead of using the default values to respect graph-specific settings (eg., in the case of setting 'GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS'). In order to have an initialized value for these settings, move its initialization to earlier in the commit-graph write. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Sep 16, 2020 at 14:07 UTC 9a7a9ed10d56d6c22a0f16d7baf3f9895c47d693
4 files changed +19 -19
bloom.c
+6 -7
@@ -180,13 +180,12 @@ static int pathmap_cmp(const void *hashmap_cmp_fn_data,
180 struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
181 struct commit *c,
182 int compute_if_not_present,
183 + const struct bloom_filter_settings *settings,
184 enum bloom_filter_computed *computed)
185 {
186 struct bloom_filter *filter;
186 - struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
187 int i;
188 struct diff_options diffopt;
189 - int max_changes = 512;
189
190 if (computed)
191 *computed = BLOOM_NOT_COMPUTED;
@@ -211,7 +210,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
210 repo_diff_setup(r, &diffopt);
211 diffopt.flags.recursive = 1;
212 diffopt.detect_rename = 0;
214 - diffopt.max_changes = max_changes;
213 + diffopt.max_changes = settings->max_changed_paths;
214 diff_setup_done(&diffopt);
215
216 /* ensure commit is parsed so we have parent information */
@@ -223,7 +222,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
222 diff_tree_oid(NULL, &c->object.oid, "", &diffopt);
223 diffcore_std(&diffopt);
224
226 - if (diffopt.num_changes <= max_changes) {
225 + if (diffopt.num_changes <= settings->max_changed_paths) {
226 struct hashmap pathmap;
227 struct pathmap_hash_entry *e;
228 struct hashmap_iter iter;
@@ -260,13 +259,13 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
259 diff_free_filepair(diff_queued_diff.queue[i]);
260 }
261
263 - filter->len = (hashmap_get_size(&pathmap) * settings.bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;
262 + filter->len = (hashmap_get_size(&pathmap) * settings->bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;
263 filter->data = xcalloc(filter->len, sizeof(unsigned char));
264
265 hashmap_for_each_entry(&pathmap, &iter, e, entry) {
266 struct bloom_key key;
268 - fill_bloom_key(e->path, strlen(e->path), &key, &settings);
269 - add_key_to_filter(&key, filter, &settings);
267 + fill_bloom_key(e->path, strlen(e->path), &key, settings);
268 + add_key_to_filter(&key, filter, settings);
269 }
270
271 hashmap_free_entries(&pathmap, struct pathmap_hash_entry, entry);
bloom.h
+2 -1
@@ -98,10 +98,11 @@ enum bloom_filter_computed {
98 struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
99 struct commit *c,
100 int compute_if_not_present,
101 + const struct bloom_filter_settings *settings,
102 enum bloom_filter_computed *computed);
103
104 #define get_bloom_filter(r, c) get_or_compute_bloom_filter( \
104 - (r), (c), 0, NULL)
105 + (r), (c), 0, NULL, NULL)
106
107 int bloom_filter_contains(const struct bloom_filter *filter,
108 const struct bloom_key *key,
commit-graph.c
+10 -11
@@ -1428,6 +1428,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1428 ctx->r,
1429 c,
1430 1,
1431 + ctx->bloom_settings,
1432 &computed);
1433 if (computed & BLOOM_COMPUTED) {
1434 ctx->count_bloom_filter_computed++;
@@ -1685,17 +1686,6 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1686 int num_chunks = 3;
1687 uint64_t chunk_offset;
1688 struct object_id file_hash;
1688 - struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
1689 -
1690 - if (!ctx->bloom_settings) {
1691 - bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
1692 - bloom_settings.bits_per_entry);
1693 - bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES",
1694 - bloom_settings.num_hashes);
1695 - bloom_settings.max_changed_paths = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS",
1696 - bloom_settings.max_changed_paths);
1697 - ctx->bloom_settings = &bloom_settings;
1698 - }
1689
1690 if (ctx->split) {
1691 struct strbuf tmp_file = STRBUF_INIT;
@@ -2141,6 +2131,7 @@ int write_commit_graph(struct object_directory *odb,
2131 uint32_t i, count_distinct = 0;
2132 int res = 0;
2133 int replace = 0;
2134 + struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
2135
2136 if (!commit_graph_compatible(the_repository))
2137 return 0;
@@ -2154,6 +2145,14 @@ int write_commit_graph(struct object_directory *odb,
2145 ctx->split_opts = split_opts;
2146 ctx->total_bloom_filter_data_size = 0;
2147
2148 + bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
2149 + bloom_settings.bits_per_entry);
2150 + bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES",
2151 + bloom_settings.num_hashes);
2152 + bloom_settings.max_changed_paths = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS",
2153 + bloom_settings.max_changed_paths);
2154 + ctx->bloom_settings = &bloom_settings;
2155 +
2156 if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
2157 ctx->changed_paths = 1;
2158 if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
t/helper/test-bloom.c
+1
@@ -40,6 +40,7 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid)
40 setup_git_directory();
41 c = lookup_commit(the_repository, commit_oid);
42 filter = get_or_compute_bloom_filter(the_repository, c, 1,
43 + &settings,
44 NULL);
45 print_bloom_filter(filter);
46 }