]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/pack-objects.c: simplify add_objects_in_unpacked_packs()
authorTaylor Blau <me@ttaylorr.com>
Mon, 30 Aug 2021 02:48:54 +0000 (22:48 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Aug 2021 06:25:20 +0000 (23:25 -0700)
commita9fd2f207d0318cd7a4771f13c9fb4759d280f68
tree953b67c08bf870f7e7594138bcf26be685e29d04
parenta241878ac7b67b1894c14d3c3e33ed13f11ae253
builtin/pack-objects.c: simplify add_objects_in_unpacked_packs()

This function is used to implement `pack-objects`'s `--keep-unreachable`
option, but can be simplified in a couple of ways:

  - add_objects_in_unpacked_packs() iterates over all packs (and then
    all packed objects) itself, but could use for_each_packed_object()
    instead since the missing flags necessary were added in the previous
    commit

  - objects are added to an in_pack array which store (off_t, object)
    tuples, and then sorted in offset order when we could iterate
    objects in offset order.

    There is a slight behavior change here: before we would have added
    objects in sorted offset order among _all_ packs. Handing objects to
    create_object_entry() in pack order for each pack (instead of
    feeding objects from all packs simultaneously their offset relative
    to different packs) is much more reasonable, if different than how
    the code currently works.

  - objects in a single pack are iterated in index order and searched
    for in order to discover their offsets, which is much less efficient
    than using the on-disk reverse index

Simplify the function by addressing each of the above and moving the
core of the loop into a callback function that we then pass to
for_each_packed_object() instead of open-coding the latter function
ourselves.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c