commit-graph: change test to die on parse, not load
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>
Derrick Stolee committed
Jun 23, 2020 at 17:47 UTC
7b671f8c2b6b7de511fd2f6587e4540c25764b61
3 files changed
+10
-6
commit-graph.c
+8
-4
@@ -564,10 +564,6 @@ static int prepare_commit_graph(struct repository *r)
564
return !!r->objects->commit_graph;
565
r->objects->commit_graph_attempted = 1;
566
567
- if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0))
568
- die("dying as requested by the '%s' variable on commit-graph load!",
569
- GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD);
570
-
567
prepare_repo_settings(r);
568
569
if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
@@ -790,6 +786,14 @@ static int parse_commit_in_graph_one(struct repository *r,
786
787
int parse_commit_in_graph(struct repository *r, struct commit *item)
788
{
789
+ static int checked_env = 0;
790
+
791
+ if (!checked_env &&
792
+ git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE, 0))
793
+ die("dying as requested by the '%s' variable on commit-graph parse!",
794
+ GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE);
795
+ checked_env = 1;
796
+
797
if (!prepare_commit_graph(r))
798
return 0;
799
return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
commit-graph.h
+1
-1
@@ -5,7 +5,7 @@
5
#include "object-store.h"
6
7
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
8
-#define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD"
8
+#define GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE "GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE"
9
#define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
10
11
/*
t/t5318-commit-graph.sh
+1
-1
@@ -436,7 +436,7 @@ corrupt_graph_verify() {
436
cp $objdir/info/commit-graph commit-graph-pre-write-test
437
fi &&
438
git status --short &&
439
- GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
439
+ GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git commit-graph write &&
440
git commit-graph verify
441
}
442