Commit 0d0e4b5
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>1 parent 02a7f6f commit 0d0e4b5
1 file changed
+14
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4388 | 4388 | | |
4389 | 4389 | | |
4390 | 4390 | | |
4391 | | - | |
4392 | | - | |
| 4391 | + | |
4393 | 4392 | | |
4394 | 4393 | | |
4395 | | - | |
4396 | | - | |
| 4394 | + | |
| 4395 | + | |
4397 | 4396 | | |
4398 | | - | |
4399 | | - | |
4400 | | - | |
4401 | | - | |
| 4397 | + | |
| 4398 | + | |
| 4399 | + | |
| 4400 | + | |
| 4401 | + | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
4402 | 4407 | | |
4403 | 4408 | | |
4404 | 4409 | | |
4405 | | - | |
4406 | | - | |
4407 | | - | |
4408 | | - | |
4409 | | - | |
4410 | | - | |
4411 | 4410 | | |
| 4411 | + | |
4412 | 4412 | | |
4413 | 4413 | | |
4414 | 4414 | | |
| |||
0 commit comments