GIT Packfile claims to have more objects, inaccessable

As mentioned in "Problems with corrupt git repo", and its associated discussion:

Many of these objects are then packed together into a packfile to save space. You corrupted these packfiles by changing their content – even worse: changing the length of their content.
git fsck does not actually fix anything about a git repository, it just checks for errors and reports them.
git unpack-objects on the other hand is able to unpack as much as possible from a corrupted packfile, but you will still have errors in your repo, as git fsck --full will report.
See "How to fix a broken repository?" or "How to remove all broken refs from a repository?".


Note that with Git 2.4.3 (June 2015), there is no more warning packfile .git/objects/pack/pack-xxx.pack cannot be accessed.
That allows to focus on the actual errors only.

See commit 319b678 [31 Mar 2015] by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 3c91e99, 05 Jun 2015)

As usual with Peff, the explanation is enlightening:

sha1_file: squelch "packfile cannot be accessed" warnings

When we find an object in a packfile index, we make sure we can still open the packfile itself (or that it is already open), as it might have been deleted by a simultaneous repack.
If we can't access the packfile, we print a warning for the user and tell the caller that we don't have the object (we can then look in other packfiles, or find a loose version, before giving up).

The warning we print to the user isn't really accomplishing anything, and it is potentially confusing to users.

In the normal case, it is complete noise; we find the object elsewhere, and the user does not have to care that we racily saw a packfile index that became stale. It didn't affect the operation at all.

A possibly more interesting case is when we later can't find the object, and report failure to the user. In this case the warning could be considered a clue toward that ultimate failure. But it's not really a useful clue in practice. We wouldn't even print it consistently (since we are racing with another process, we might not even see the .idx file, or we might win the race and open the packfile, completing the operation).

This patch drops the warning entirely (not only from the fill_pack_entry site, but also from an identical use in pack-objects).
If we did find the warning interesting in the error case, we could stuff it away and reveal it to the user when we later die() due to the broken object. But that complexity just isn't worth it.


And with Git 2.22.1 (Q3 2019), "git update-server-info" used to leave stale packfiles in its output, which has been corrected.

See commit e941c48 (23 May 2019) by Eric Wong (ele828).
Helped-by: Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 776d668, 25 Jul 2019)

server-info: do not list unlinked packs

Having non-existent packs in objects/info/packs causes dumb HTTP clients to abort.

v2: use single loop with ALLOC_GROW as suggested by Jeff King