Skip to content

Commit 655e494

Browse files
committed
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
2 parents 8b2f027 + b27ccae commit 655e494

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
901901
struct commit *commit;
902902
uint32_t pos;
903903

904-
if (!repo->objects->commit_graph)
904+
if (!prepare_commit_graph(repo))
905905
return NULL;
906906
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
907907
return NULL;

revision.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
24182418
revs->tree_objects = 1;
24192419
revs->blob_objects = 1;
24202420
revs->verify_objects = 1;
2421+
disable_commit_graph(revs->repo);
24212422
} else if (!strcmp(arg, "--unpacked")) {
24222423
revs->unpacked = 1;
24232424
} else if (starts_with(arg, "--unpacked=")) {

t/t1450-fsck.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,34 @@ test_expect_success 'rev-list --verify-objects notices swapped commits' '
527527
)
528528
'
529529

530+
test_expect_success 'set up repository with commit-graph' '
531+
git init corrupt-graph &&
532+
(
533+
cd corrupt-graph &&
534+
test_commit one &&
535+
test_commit two &&
536+
git commit-graph write --reachable
537+
)
538+
'
539+
540+
corrupt_graph_obj () {
541+
oid=$(git -C corrupt-graph rev-parse "$1") &&
542+
obj=corrupt-graph/.git/objects/$(test_oid_to_path $oid) &&
543+
test_when_finished 'mv backup $obj' &&
544+
mv $obj backup &&
545+
echo garbage >$obj
546+
}
547+
548+
test_expect_success 'rev-list --verify-objects with commit graph (tip)' '
549+
corrupt_graph_obj HEAD &&
550+
test_must_fail git -C corrupt-graph rev-list --verify-objects HEAD
551+
'
552+
553+
test_expect_success 'rev-list --verify-objects with commit graph (parent)' '
554+
corrupt_graph_obj HEAD^ &&
555+
test_must_fail git -C corrupt-graph rev-list --verify-objects HEAD
556+
'
557+
530558
test_expect_success 'force fsck to ignore double author' '
531559
git cat-file commit HEAD >basis &&
532560
sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&

0 commit comments

Comments
 (0)