]> git.ipfire.org Git - thirdparty/git.git/commit - commit.c
commit: don't lazy-fetch commits
authorJonathan Tan <jonathantanmy@google.com>
Wed, 14 Dec 2022 19:17:43 +0000 (11:17 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Dec 2022 00:05:55 +0000 (09:05 +0900)
commit7e2ad1cda2759a14f7b046c4c82e2418f8af878c
tree7b72fd4d3cbdf76ba4ec26b9b98b97688d92f0c7
parent9e59b38c88cdd79964cc92860906a0737bee3797
commit: don't lazy-fetch commits

When parsing commits, fail fast when the commit is missing or
corrupt, instead of attempting to fetch them. This is done by inlining
repo_read_object_file() and setting the flag that prevents fetching.

This is motivated by a situation in which through a bug (not necessarily
through Git), there was corruption in the object store of a partial
clone. In this particular case, the problem was exposed when "git gc"
tried to expire reflogs, which calls repo_parse_commit(), which triggers
fetches of the missing commits.

(There are other possible solutions to this problem including passing an
argument from "git gc" to "git reflog" to inhibit all lazy fetches, but
I think that this fix is at the wrong level - fixing "git reflog" means
that this particular command works fine, or so we think (it will fail if
it somehow needs to read a legitimately missing blob, say, a .gitmodules
file), but fixing repo_parse_commit() will fix a whole class of bugs.)

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c