diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-09-13 11:38:24 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-09-13 11:38:24 -0700 |
| commit | 655e49404792a302b16fa640e1fa6041052996f9 (patch) | |
| tree | cfab9f41c905fa92c86980693d9ca693462c218e | |
| parent | 8b2f027e2096848b32cd8e0daa362fe08e5276c4 (diff) | |
| parent | b27ccae34ba2cabbface87d6e0f80695316bcd59 (diff) | |
| download | git-655e49404792a302b16fa640e1fa6041052996f9.tar.xz | |
Merge branch 'jk/rev-list-verify-objects-fix'
"git rev-list --verify-objects" ought to inspect the contents of
objects and notice corrupted ones, but it didn't when the commit
graph is in use, which has been corrected.
* jk/rev-list-verify-objects-fix:
rev-list: disable commit graph with --verify-objects
lookup_commit_in_graph(): use prepare_commit_graph() to check for graph
| -rw-r--r-- | commit-graph.c | 2 | ||||
| -rw-r--r-- | revision.c | 1 | ||||
| -rwxr-xr-x | t/t1450-fsck.sh | 28 |
3 files changed, 30 insertions, 1 deletions
diff --git a/commit-graph.c b/commit-graph.c index f2a36032f8..aef076e145 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -901,7 +901,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje struct commit *commit; uint32_t pos; - if (!repo->objects->commit_graph) + if (!prepare_commit_graph(repo)) return NULL; if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos)) return NULL; diff --git a/revision.c b/revision.c index a04ebd6139..c516415c48 100644 --- a/revision.c +++ b/revision.c @@ -2418,6 +2418,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->tree_objects = 1; revs->blob_objects = 1; revs->verify_objects = 1; + disable_commit_graph(revs->repo); } else if (!strcmp(arg, "--unpacked")) { revs->unpacked = 1; } else if (starts_with(arg, "--unpacked=")) { diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 6410eff4e0..ace4556788 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -527,6 +527,34 @@ test_expect_success 'rev-list --verify-objects notices swapped commits' ' ) ' +test_expect_success 'set up repository with commit-graph' ' + git init corrupt-graph && + ( + cd corrupt-graph && + test_commit one && + test_commit two && + git commit-graph write --reachable + ) +' + +corrupt_graph_obj () { + oid=$(git -C corrupt-graph rev-parse "$1") && + obj=corrupt-graph/.git/objects/$(test_oid_to_path $oid) && + test_when_finished 'mv backup $obj' && + mv $obj backup && + echo garbage >$obj +} + +test_expect_success 'rev-list --verify-objects with commit graph (tip)' ' + corrupt_graph_obj HEAD && + test_must_fail git -C corrupt-graph rev-list --verify-objects HEAD +' + +test_expect_success 'rev-list --verify-objects with commit graph (parent)' ' + corrupt_graph_obj HEAD^ && + test_must_fail git -C corrupt-graph rev-list --verify-objects HEAD +' + test_expect_success 'force fsck to ignore double author' ' git cat-file commit HEAD >basis && sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors && |
