aboutsummaryrefslogtreecommitdiffstats
path: root/refs/iterator.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-10-30 11:38:42 +0100
committerJunio C Hamano <gitster@pobox.com>2025-10-30 07:09:53 -0700
commit0d0e4b5954e97fcdfd0a4120e17e2c570497981a (patch)
tree387d04f43ff2522d03248f58e20c63c864a7fff4 /refs/iterator.c
parentpackfile: fix approximation of object counts (diff)
downloadgit-0d0e4b5954e97fcdfd0a4120e17e2c570497981a.tar.gz
git-0d0e4b5954e97fcdfd0a4120e17e2c570497981a.zip
builtin/pack-objects: simplify logic to find kept or nonlocal objects
The function `has_sha1_pack_kept_or_nonlocal()` takes an object ID and then searches through packed objects to figure out whether the object exists in a kept or non-local pack. As a performance optimization we remember the packfile that contains a given object ID so that the next call to the function first checks that same packfile again. The way this is written is rather hard to follow though, as the caching mechanism is intertwined with the loop that iterates through the packs. Consequently, we need to do some gymnastics to re-start the iteration if the cached pack does not contain the objects. Refactor this so that we check the cached packfile at the beginning. We don't have to re-verify whether the packfile meets the properties as we have already verified those when storing the pack in `last_found` in the first place. So all we need to do is to use `find_pack_entry_one()` to check whether the pack contains the object ID, and to skip the cached pack in the loop so that we don't search it twice. Furthermore, stop using the `(void *)1` sentinel value and instead use a simple `NULL` pointer to indicate that we don't have a last-found pack yet. This refactoring significantly simplifies the logic and makes it much easier to follow. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/iterator.c')
0 files changed, 0 insertions, 0 deletions