]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ds/commit-graph-generation-config'
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Mar 2021 21:00:23 +0000 (14:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Mar 2021 21:00:23 +0000 (14:00 -0700)
A new configuration variable has been introduced to allow choosing
which version of the generation number gets used in the
commit-graph file.

* ds/commit-graph-generation-config:
  commit-graph: use config to specify generation type
  commit-graph: create local repository pointer

Documentation/config/commitgraph.txt
commit-graph.c
commit-graph.h
t/README
t/t5318-commit-graph.sh
t/t5324-split-commit-graph.sh
t/t6600-test-reach.sh

index 4582c39fc462757b05a9b1c3871d29e1c373c605..30604e4a4c296783f55dd3644d866b8775796db2 100644 (file)
@@ -1,3 +1,9 @@
+commitGraph.generationVersion::
+       Specifies the type of generation number version to use when writing
+       or reading the commit-graph file. If version 1 is specified, then
+       the corrected commit dates will not be written or read. Defaults to
+       2.
+
 commitGraph.maxNewFilters::
        Specifies the default value for the `--max-new-filters` option of `git
        commit-graph write` (c.f., linkgit:git-commit-graph[1]).
index e21eeea42b96d5cd20b62b031def7aebe2a96272..f18380b922c12208cbceae92fce98e2e6b42e6ed 100644 (file)
@@ -96,6 +96,13 @@ define_commit_slab(commit_graph_data_slab, struct commit_graph_data);
 static struct commit_graph_data_slab commit_graph_data_slab =
        COMMIT_SLAB_INIT(1, commit_graph_data_slab);
 
+static int get_configured_generation_version(struct repository *r)
+{
+       int version = 2;
+       repo_config_get_int(r, "commitgraph.generationversion", &version);
+       return version;
+}
+
 uint32_t commit_graph_position(const struct commit *c)
 {
        struct commit_graph_data *data =
@@ -394,10 +401,13 @@ struct commit_graph *parse_commit_graph(struct repository *r,
        pair_chunk(cf, GRAPH_CHUNKID_DATA, &graph->chunk_commit_data);
        pair_chunk(cf, GRAPH_CHUNKID_EXTRAEDGES, &graph->chunk_extra_edges);
        pair_chunk(cf, GRAPH_CHUNKID_BASE, &graph->chunk_base_graphs);
-       pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
-                  &graph->chunk_generation_data);
-       pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW,
-                  &graph->chunk_generation_data_overflow);
+
+       if (get_configured_generation_version(r) >= 2) {
+               pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
+                       &graph->chunk_generation_data);
+               pair_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW,
+                       &graph->chunk_generation_data_overflow);
+       }
 
        if (r->settings.commit_graph_read_changed_paths) {
                pair_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES,
@@ -1839,8 +1849,6 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
        add_chunk(cf, GRAPH_CHUNKID_DATA, (hashsz + 16) * ctx->commits.nr,
                  write_graph_chunk_data);
 
-       if (git_env_bool(GIT_TEST_COMMIT_GRAPH_NO_GDAT, 0))
-               ctx->write_generation_data = 0;
        if (ctx->write_generation_data)
                add_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
                          sizeof(uint32_t) * ctx->commits.nr,
@@ -2223,6 +2231,7 @@ int write_commit_graph(struct object_directory *odb,
                       enum commit_graph_write_flags flags,
                       const struct commit_graph_opts *opts)
 {
+       struct repository *r = the_repository;
        struct write_commit_graph_context *ctx;
        uint32_t i;
        int res = 0;
@@ -2230,23 +2239,23 @@ int write_commit_graph(struct object_directory *odb,
        struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
        struct topo_level_slab topo_levels;
 
-       prepare_repo_settings(the_repository);
-       if (!the_repository->settings.core_commit_graph) {
+       prepare_repo_settings(r);
+       if (!r->settings.core_commit_graph) {
                warning(_("attempting to write a commit-graph, but 'core.commitGraph' is disabled"));
                return 0;
        }
-       if (!commit_graph_compatible(the_repository))
+       if (!commit_graph_compatible(r))
                return 0;
 
        CALLOC_ARRAY(ctx, 1);
-       ctx->r = the_repository;
+       ctx->r = r;
        ctx->odb = odb;
        ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
        ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
        ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
        ctx->opts = opts;
        ctx->total_bloom_filter_data_size = 0;
-       ctx->write_generation_data = 1;
+       ctx->write_generation_data = (get_configured_generation_version(r) == 2);
        ctx->num_generation_data_overflows = 0;
 
        bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
index 97f3497c2790c5bca0f9c73dd069291c95456895..96c24fb5777de48ccb5d5144543b3c2ff6f7efae 100644 (file)
@@ -6,7 +6,6 @@
 #include "oidset.h"
 
 #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
-#define GIT_TEST_COMMIT_GRAPH_NO_GDAT "GIT_TEST_COMMIT_GRAPH_NO_GDAT"
 #define GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE "GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE"
 #define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
 
index 593d4a4e270cc07b0f8e7d93e0da4d3c0b73eebd..fd9375b146d199b076b22d6b3b0ad8a9c1a9e4a6 100644 (file)
--- a/t/README
+++ b/t/README
@@ -387,9 +387,6 @@ GIT_TEST_COMMIT_GRAPH=<boolean>, when true, forces the commit-graph to
 be written after every 'git commit' command, and overrides the
 'core.commitGraph' setting to true.
 
-GIT_TEST_COMMIT_GRAPH_NO_GDAT=<boolean>, when true, forces the
-commit-graph to be written without generation data chunk.
-
 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=<boolean>, when true, forces
 commit-graph write to compute and write changed path Bloom filters for
 every 'git commit-graph write', as if the `--changed-paths` option was
index edeb6d6d3114c33b56f268788ebfa23a7bfbaf82..af88f805aa275b6cd7a0ef4c50819a8538d7b0d1 100755 (executable)
@@ -475,7 +475,7 @@ test_expect_success 'lower layers have overflow chunk' '
 
 test_expect_success 'git commit-graph verify' '
        cd "$TRASH_DIRECTORY/full" &&
-       git rev-parse commits/8 | GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --stdin-commits &&
+       git rev-parse commits/8 | git -c commitGraph.generationVersion=1 commit-graph write --stdin-commits &&
        git commit-graph verify >output &&
        graph_read_expect 9 extra_edges
 '
index 8e90f3423b8f23397d1a7dd86405215d1d8502fd..587226ed10320cb57ea0f6da8ac333572e847f56 100755 (executable)
@@ -489,7 +489,7 @@ test_expect_success 'setup repo for mixed generation commit-graph-chain' '
                        test_commit $i &&
                        git branch commits/$i || return 1
                done &&
-               git commit-graph write --reachable --split &&
+               git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
                graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
                test_line_count = 1 $graphdir/commit-graph-chain &&
                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' '
                        test_commit $i &&
                        git branch commits/$i || return 1
                done &&
-               GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --reachable --split=no-merge &&
+               git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
                test_line_count = 2 $graphdir/commit-graph-chain &&
                test-tool read-graph >output &&
                cat >expect <<-EOF &&
index e2d33a8a4c46124fcdf2c3ee69554c5ecf2af774..3d7a62ddab61729d37c183fe327a9d8997f96c1c 100755 (executable)
@@ -55,7 +55,7 @@ test_expect_success 'setup' '
        git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
        mv .git/objects/info/commit-graph commit-graph-half &&
        chmod u+w commit-graph-half &&
-       GIT_TEST_COMMIT_GRAPH_NO_GDAT=1 git commit-graph write --reachable &&
+       git -c commitGraph.generationVersion=1 commit-graph write --reachable &&
        mv .git/objects/info/commit-graph commit-graph-no-gdat &&
        chmod u+w commit-graph-no-gdat &&
        git config core.commitGraph true