Skip to content

Commit ea0024d

Browse files
ttaylorrgitster
authored andcommitted
repo-settings: introduce commitgraph.changedPathsVersion
A subsequent commit will introduce another version of the changed-path filter in the commit graph file. In order to control which version to write (and read), a config variable is needed. Therefore, introduce this config variable. For forwards compatibility, teach Git to not read commit graphs when the config variable is set to an unsupported version. Because we teach Git this, commitgraph.readChangedPaths is now redundant, so deprecate it and define its behavior in terms of the config variable we introduce. This commit does not change the behavior of writing (Git writes changed path filters when explicitly instructed regardless of any config variable), but a subsequent commit will restrict Git such that it will only write when commitgraph.changedPathsVersion is a recognized value. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08b6ae3 commit ea0024d

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

Documentation/config/commitgraph.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ commitGraph.maxNewFilters::
99
commit-graph write` (c.f., linkgit:git-commit-graph[1]).
1010

1111
commitGraph.readChangedPaths::
12-
If true, then git will use the changed-path Bloom filters in the
13-
commit-graph file (if it exists, and they are present). Defaults to
14-
true. See linkgit:git-commit-graph[1] for more information.
12+
Deprecated. Equivalent to commitGraph.changedPathsVersion=-1 if true, and
13+
commitGraph.changedPathsVersion=0 if false. (If commitGraph.changedPathVersion
14+
is also set, commitGraph.changedPathsVersion takes precedence.)
15+
16+
commitGraph.changedPathsVersion::
17+
Specifies the version of the changed-path Bloom filters that Git will read and
18+
write. May be -1, 0 or 1. Note that values greater than 1 may be
19+
incompatible with older versions of Git which do not yet understand
20+
those versions. Use caution when operating in a mixed-version
21+
environment.
22+
+
23+
Defaults to -1.
24+
+
25+
If -1, Git will use the version of the changed-path Bloom filters in the
26+
repository, defaulting to 1 if there are none.
27+
+
28+
If 0, Git will not read any Bloom filters, and will write version 1 Bloom
29+
filters when instructed to write.
30+
+
31+
If 1, Git will only read version 1 Bloom filters, and will write version 1
32+
Bloom filters.
33+
+
34+
See linkgit:git-commit-graph[1] for more information.

commit-graph.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
459459
graph->read_generation_data = 1;
460460
}
461461

462-
if (s->commit_graph_read_changed_paths) {
462+
if (s->commit_graph_changed_paths_version) {
463463
read_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES,
464464
graph_read_bloom_index, graph);
465465
read_chunk(cf, GRAPH_CHUNKID_BLOOMDATA,
@@ -555,7 +555,8 @@ static void validate_mixed_bloom_settings(struct commit_graph *g)
555555
}
556556

557557
if (g->bloom_filter_settings->bits_per_entry != settings->bits_per_entry ||
558-
g->bloom_filter_settings->num_hashes != settings->num_hashes) {
558+
g->bloom_filter_settings->num_hashes != settings->num_hashes ||
559+
g->bloom_filter_settings->hash_version != settings->hash_version) {
559560
g->chunk_bloom_indexes = NULL;
560561
g->chunk_bloom_data = NULL;
561562
FREE_AND_NULL(g->bloom_filter_settings);

oss-fuzz/fuzz-commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
1919
* possible.
2020
*/
2121
the_repository->settings.commit_graph_generation_version = 2;
22-
the_repository->settings.commit_graph_read_changed_paths = 1;
22+
the_repository->settings.commit_graph_changed_paths_version = 1;
2323
g = parse_commit_graph(&the_repository->settings, (void *)data, size);
2424
repo_clear(the_repository);
2525
free_commit_graph(g);

repo-settings.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void prepare_repo_settings(struct repository *r)
2323
int value;
2424
const char *strval;
2525
int manyfiles;
26+
int read_changed_paths;
2627

2728
if (!r->gitdir)
2829
BUG("Cannot add settings for uninitialized repository");
@@ -53,7 +54,10 @@ void prepare_repo_settings(struct repository *r)
5354
/* Commit graph config or default, does not cascade (simple) */
5455
repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
5556
repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2);
56-
repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1);
57+
repo_cfg_bool(r, "commitgraph.readchangedpaths", &read_changed_paths, 1);
58+
repo_cfg_int(r, "commitgraph.changedpathsversion",
59+
&r->settings.commit_graph_changed_paths_version,
60+
read_changed_paths ? -1 : 0);
5761
repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
5862
repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
5963

repository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct repo_settings {
2929

3030
int core_commit_graph;
3131
int commit_graph_generation_version;
32-
int commit_graph_read_changed_paths;
32+
int commit_graph_changed_paths_version;
3333
int gc_write_commit_graph;
3434
int fetch_write_commit_graph;
3535
int command_requires_full_index;

0 commit comments

Comments
 (0)