@matheusbsbs / matheus-bagliano / commits / b23ea9790d
Fork 0

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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 16, 2020 at 20:14 UTC b23ea9790d30e80c7c79a77aab2e9d150a189463
4 files changed +29 -5
builtin/commit.c
+1 -3
@@ -1700,9 +1700,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1700 "new_index file. Check that disk is not full and quota is\n"
1701 "not exceeded, and then \"git restore --staged :/\" to recover."));
1702
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();
1704
1705 repo_rerere(the_repository, 0);
1706 run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
builtin/merge.c
+5 -2
@@ -40,6 +40,7 @@
40 #include "branch.h"
41 #include "commit-reach.h"
42 #include "wt-status.h"
43 +#include "commit-graph.h"
44
45 #define DEFAULT_TWOHEAD (1<<0)
46 #define DEFAULT_OCTOPUS (1<<1)
@@ -1673,9 +1674,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1674 head_commit);
1675 }
1676
1676 - if (squash)
1677 + if (squash) {
1678 finish(head_commit, remoteheads, NULL, NULL);
1678 - else
1679 +
1680 + git_test_write_commit_graph_or_die();
1681 + } else
1682 write_merge_state(remoteheads);
1683
1684 if (merge_was_ok)
commit-graph.c
+14
@@ -19,6 +19,20 @@
19 #include "bloom.h"
20 #include "commit-slab.h"
21
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 +
36 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
37 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
38 #define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
commit-graph.h
+9
@@ -11,6 +11,15 @@
11 #define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD"
12 #define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
13
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 +
23 struct commit;
24 struct bloom_filter_settings;
25