commit-graph: use config to specify generation type

We have two established generation number versions: 1: topological levels 2: corrected commit dates The corrected commit dates are enabled by default, but they also write extra data in the GDAT and GDOV chunks. Services that host Git data might want to have more control over when this feature rolls out than just updating the Git binaries. Add a new "commitGraph.generationVersion" config option that specifies the intended generation number version. If this value is less than 2, then the GDAT chunk is never written _or read_ from an existing file. This can replace our use of the GIT_TEST_COMMIT_GRAPH_NO_GDAT environment variable in the test suite. Remove it. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Feb 25, 2021 at 18:19 UTC 702110aac63556b4572d9c7b65c9123ec8038ebf
7 files changed +25 -15
Documentation/config/commitgraph.txt
+6
@@ -1,3 +1,9 @@
1 +commitGraph.generationVersion::
2 + Specifies the type of generation number version to use when writing
3 + or reading the commit-graph file. If version 1 is specified, then
4 + the corrected commit dates will not be written or read. Defaults to
5 + 2.
6 +
7 commitGraph.maxNewFilters::
8 Specifies the default value for the `--max-new-filters` option of `git
9 commit-graph write` (c.f., linkgit:git-commit-graph[1]).
commit-graph.c
+15 -7
@@ -96,6 +96,13 @@ define_commit_slab(commit_graph_data_slab, struct commit_graph_data);
96 static struct commit_graph_data_slab commit_graph_data_slab =
97 COMMIT_SLAB_INIT(1, commit_graph_data_slab);
98
99 +static int get_configured_generation_version(struct repository *r)
100 +{
101 + int version = 2;
102 + repo_config_get_int(r, "commitgraph.generationversion", &version);
103 + return version;
104 +}
105 +
106 uint32_t commit_graph_position(const struct commit *c)
107 {
108 struct commit_graph_data *data =
@@ -394,10 +401,13 @@ struct commit_graph *parse_commit_graph(struct repository *r,
401 pair_chunk(cf, GRAPH_CHUNKID_DATA, &graph->chunk_commit_data);
402 pair_chunk(cf, GRAPH_CHUNKID_EXTRAEDGES, &graph->chunk_extra_edges);
403 pair_chunk(cf, GRAPH_CHUNKID_BASE, &graph->chunk_base_graphs);
397 - pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
398 - &graph->chunk_generation_data);
399 - pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW,
400 - &graph->chunk_generation_data_overflow);
404 +
405 + if (get_configured_generation_version(r) >= 2) {
406 + pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
407 + &graph->chunk_generation_data);
408 + pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW,
409 + &graph->chunk_generation_data_overflow);
410 + }
411
412 if (r->settings.commit_graph_read_changed_paths) {
413 pair_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES,
@@ -1771,8 +1781,6 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1781 add_chunk(cf, GRAPH_CHUNKID_DATA, (hashsz + 16) * ctx->commits.nr,
1782 write_graph_chunk_data);
1783
1774 - if (git_env_bool(GIT_TEST_COMMIT_GRAPH_NO_GDAT, 0))
1775 - ctx->write_generation_data = 0;
1784 if (ctx->write_generation_data)
1785 add_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
1786 sizeof(uint32_t) * ctx->commits.nr,
@@ -2179,7 +2187,7 @@ int write_commit_graph(struct object_directory *odb,
2187 ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
2188 ctx->opts = opts;
2189 ctx->total_bloom_filter_data_size = 0;
2182 - ctx->write_generation_data = 1;
2190 + ctx->write_generation_data = (get_configured_generation_version(r) == 2);
2191 ctx->num_generation_data_overflows = 0;
2192
2193 bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
commit-graph.h
-1
@@ -6,7 +6,6 @@
6 #include "oidset.h"
7
8 #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
9 -#define GIT_TEST_COMMIT_GRAPH_NO_GDAT "GIT_TEST_COMMIT_GRAPH_NO_GDAT"
9 #define GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE "GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE"
10 #define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
11
t/README
-3
@@ -393,9 +393,6 @@ GIT_TEST_COMMIT_GRAPH=<boolean>, when true, forces the commit-graph to
393 be written after every 'git commit' command, and overrides the
394 'core.commitGraph' setting to true.
395
396 -GIT_TEST_COMMIT_GRAPH_NO_GDAT=<boolean>, when true, forces the
397 -commit-graph to be written without generation data chunk.
398 -
396 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=<boolean>, when true, forces
397 commit-graph write to compute and write changed path Bloom filters for
398 every 'git commit-graph write', as if the `--changed-paths` option was
t/t5318-commit-graph.sh
+1 -1
@@ -454,7 +454,7 @@ test_expect_success 'warn on improper hash version' '
454
455 test_expect_success 'git commit-graph verify' '
456 cd "$TRASH_DIRECTORY/full" &&
457 - git rev-parse commits/8 | GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --stdin-commits &&
457 + git rev-parse commits/8 | git -c commitGraph.generationVersion=1 commit-graph write --stdin-commits &&
458 git commit-graph verify >output &&
459 graph_read_expect 9 extra_edges
460 '
t/t5324-split-commit-graph.sh
+2 -2
@@ -489,7 +489,7 @@ test_expect_success 'setup repo for mixed generation commit-graph-chain' '
489 test_commit $i &&
490 git branch commits/$i || return 1
491 done &&
492 - git commit-graph write --reachable --split &&
492 + git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
493 graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
494 test_line_count = 1 $graphdir/commit-graph-chain &&
495 for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END)
@@ -497,7 +497,7 @@ test_expect_success 'setup repo for mixed generation commit-graph-chain' '
497 test_commit $i &&
498 git branch commits/$i || return 1
499 done &&
500 - GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --reachable --split=no-merge &&
500 + git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
501 test_line_count = 2 $graphdir/commit-graph-chain &&
502 test-tool read-graph >output &&
503 cat >expect <<-EOF &&
t/t6600-test-reach.sh
+1 -1
@@ -55,7 +55,7 @@ test_expect_success 'setup' '
55 git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
56 mv .git/objects/info/commit-graph commit-graph-half &&
57 chmod u+w commit-graph-half &&
58 - GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --reachable &&
58 + git -c commitGraph.generationVersion=1 commit-graph write --reachable &&
59 mv .git/objects/info/commit-graph commit-graph-no-gdat &&
60 chmod u+w commit-graph-no-gdat &&
61 git config core.commitGraph true