]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: change test to die on parse, not load
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 23 Jun 2020 17:47:01 +0000 (17:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jun 2020 00:12:08 +0000 (17:12 -0700)
43d3561 (commit-graph write: don't die if the existing graph is corrupt,
2019-03-25) introduced the GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD environment
variable. This was created to verify that commit-graph was not loaded
when writing a new non-incremental commit-graph.

An upcoming change wants to load a commit-graph in some valuable cases,
but we want to maintain that we don't trust the commit-graph data when
writing our new file. Instead of dying on load, instead die if we ever
try to parse a commit from the commit-graph. This functionally verifies
the same intended behavior, but allows a more advanced feature in the
next change.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
commit-graph.h
t/t5318-commit-graph.sh

index d0fedcd9b1fe4fd3b2b921d05ca0f168803a75a4..6a28d4a5a6df24d2508d9ca9182ab628346295f6 100644 (file)
@@ -564,10 +564,6 @@ static int prepare_commit_graph(struct repository *r)
                return !!r->objects->commit_graph;
        r->objects->commit_graph_attempted = 1;
 
-       if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0))
-               die("dying as requested by the '%s' variable on commit-graph load!",
-                   GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD);
-
        prepare_repo_settings(r);
 
        if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
@@ -790,6 +786,14 @@ static int parse_commit_in_graph_one(struct repository *r,
 
 int parse_commit_in_graph(struct repository *r, struct commit *item)
 {
+       static int checked_env = 0;
+
+       if (!checked_env &&
+           git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE, 0))
+               die("dying as requested by the '%s' variable on commit-graph parse!",
+                   GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE);
+       checked_env = 1;
+
        if (!prepare_commit_graph(r))
                return 0;
        return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
index 881c9b46e57f0eff83e9eb86f26abdc6702b661a..f0fb13e3f28440a18b9afa4c65ede57b73fb9f60 100644 (file)
@@ -5,7 +5,7 @@
 #include "object-store.h"
 
 #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
-#define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD"
+#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 1073f9e3cf2c31c5ca33580d7c94bfe59ea73415..5ec01abdaa91f691ce454e4646890db729d2ae8d 100755 (executable)
@@ -436,7 +436,7 @@ corrupt_graph_verify() {
                cp $objdir/info/commit-graph commit-graph-pre-write-test
        fi &&
        git status --short &&
-       GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
+       GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git commit-graph write &&
        git commit-graph verify
 }