Skip to content

Commit db5b8fe

Browse files
committed
commit-graph: persist existence of changed-paths
The changed-path Bloom filters were released in v2.27.0, but have a significant drawback. A user can opt-in to writing the changed-path filters using the "--changed-paths" option to "git commit-graph write" but the next write will drop the filters unless that option is specified. This becomes even more important when considering the interaction with gc.writeCommitGraph (on by default) or fetch.writeCommitGraph (part of features.experimental). These config options trigger commit-graph writes that the user did not signal, and hence there is no --changed-paths option available. Allow a user that opts-in to the changed-path filters to persist the property of "my commit-graph has changed-path filters" automatically. A user can drop filters using the --no-changed-paths option. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 60bbc15 commit db5b8fe

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

Documentation/git-commit-graph.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ existing commit-graph file.
6060
With the `--changed-paths` option, compute and write information about the
6161
paths changed between a commit and it's first parent. This operation can
6262
take a while on large repositories. It provides significant performance gains
63-
for getting history of a directory or a file with `git log -- <path>`.
63+
for getting history of a directory or a file with `git log -- <path>`. If
64+
this option is given, future commit-graph writes will automatically assume
65+
that this option was intended. Use `--no-changed-paths` to stop storing this
66+
data.
6467
+
6568
With the `--split` option, write the commit-graph as a chain of multiple
6669
commit-graph files stored in `<dir>/info/commit-graphs`. The new commits

builtin/commit-graph.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static int graph_write(int argc, const char **argv)
151151
};
152152

153153
opts.progress = isatty(2);
154+
opts.enable_changed_paths = -1;
154155
split_opts.size_multiple = 2;
155156
split_opts.max_commits = 0;
156157
split_opts.expire_time = 0;
@@ -171,7 +172,9 @@ static int graph_write(int argc, const char **argv)
171172
flags |= COMMIT_GRAPH_WRITE_SPLIT;
172173
if (opts.progress)
173174
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
174-
if (opts.enable_changed_paths ||
175+
if (!opts.enable_changed_paths)
176+
flags |= COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS;
177+
if (opts.enable_changed_paths == 1 ||
175178
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
176179
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
177180

commit-graph.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,9 +1996,19 @@ int write_commit_graph(struct object_directory *odb,
19961996
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
19971997
ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
19981998
ctx->split_opts = split_opts;
1999-
ctx->changed_paths = flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS ? 1 : 0;
20001999
ctx->total_bloom_filter_data_size = 0;
20012000

2001+
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
2002+
ctx->changed_paths = 1;
2003+
else if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
2004+
prepare_commit_graph_one(ctx->r, ctx->odb);
2005+
2006+
/* We have changed-paths already. Keep them in the next graph */
2007+
if (ctx->r->objects->commit_graph &&
2008+
ctx->r->objects->commit_graph->chunk_bloom_data)
2009+
ctx->changed_paths = 1;
2010+
}
2011+
20022012
if (ctx->split) {
20032013
struct commit_graph *g;
20042014
prepare_commit_graph(ctx->r);

commit-graph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ enum commit_graph_write_flags {
9696
/* Make sure that each OID in the input is a valid commit OID. */
9797
COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3),
9898
COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 4),
99+
COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS = (1 << 5),
99100
};
100101

101102
struct split_commit_graph_opts {

t/t4216-log-bloom.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test_expect_success 'setup - add commit-graph to the chain without Bloom filters
126126
test_commit c14 A/anotherFile2 &&
127127
test_commit c15 A/B/anotherFile2 &&
128128
test_commit c16 A/B/C/anotherFile2 &&
129-
GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0 git commit-graph write --reachable --split &&
129+
git commit-graph write --reachable --split --no-changed-paths &&
130130
test_line_count = 2 .git/objects/info/commit-graphs/commit-graph-chain
131131
'
132132

0 commit comments

Comments
 (0)