Skip to content

Commit b23ea97

Browse files
derrickstoleegitster
authored andcommitted
tests: write commit-graph with Bloom filters
The GIT_TEST_COMMIT_GRAPH environment variable updates the commit- graph file whenever "git commit" is run, ensuring that we always have an updated commit-graph throughout the test suite. The GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS environment variable was introduced to write the changed-path Bloom filters whenever "git commit-graph write" is run. However, the GIT_TEST_COMMIT_GRAPH trick doesn't launch a separate process and instead writes it directly. To expand the number of tests that have commits in the commit-graph file, add a helper method that computes the commit-graph and place that helper inside "git commit" and "git merge". In the helper method, check GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS to ensure we are writing changed-path Bloom filters whenever possible. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8918e37 commit b23ea97

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

builtin/commit.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,9 +1700,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17001700
"new_index file. Check that disk is not full and quota is\n"
17011701
"not exceeded, and then \"git restore --staged :/\" to recover."));
17021702

1703-
if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
1704-
write_commit_graph_reachable(the_repository->objects->odb, 0, NULL))
1705-
return 1;
1703+
git_test_write_commit_graph_or_die();
17061704

17071705
repo_rerere(the_repository, 0);
17081706
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);

builtin/merge.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "branch.h"
4141
#include "commit-reach.h"
4242
#include "wt-status.h"
43+
#include "commit-graph.h"
4344

4445
#define DEFAULT_TWOHEAD (1<<0)
4546
#define DEFAULT_OCTOPUS (1<<1)
@@ -1673,9 +1674,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16731674
head_commit);
16741675
}
16751676

1676-
if (squash)
1677+
if (squash) {
16771678
finish(head_commit, remoteheads, NULL, NULL);
1678-
else
1679+
1680+
git_test_write_commit_graph_or_die();
1681+
} else
16791682
write_merge_state(remoteheads);
16801683

16811684
if (merge_was_ok)

commit-graph.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
#include "bloom.h"
2020
#include "commit-slab.h"
2121

22+
void git_test_write_commit_graph_or_die(void)
23+
{
24+
int flags = 0;
25+
if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
26+
return;
27+
28+
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
29+
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
30+
31+
if (write_commit_graph_reachable(the_repository->objects->odb,
32+
flags, NULL))
33+
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
34+
}
35+
2236
#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
2337
#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
2438
#define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */

commit-graph.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
#define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD"
1212
#define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
1313

14+
/*
15+
* This method is only used to enhance coverage of the commit-graph
16+
* feature in the test suite with the GIT_TEST_COMMIT_GRAPH and
17+
* GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS environment variables. Do not
18+
* call this method oustide of a builtin, and only if you know what
19+
* you are doing!
20+
*/
21+
void git_test_write_commit_graph_or_die(void);
22+
1423
struct commit;
1524
struct bloom_filter_settings;
1625

0 commit comments

Comments
 (0)