pack-objects: extract `stdin_packs_add_all_pack_entries()`

Extract the pack enumeration loop from stdin_packs_add_pack_entries() into a separate stdin_packs_add_all_pack_entries() helper, and have the caller dispatch to it based on the stdin_packs_mode. This prepares for a subsequent commit which will introduce an alternate code path for '--stdin-packs=follow-reachable' that determines the set of objects to include via a reachability walk rather than eagerly adding all objects from included packs. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jun 26, 2026 at 15:02 UTC 806cd59ba235c0b19261019c039a22392cc6fc04
1 file changed +28 -21
builtin/pack-objects.c
+28 -21
@@ -3933,30 +3933,12 @@ static int stdin_packs_include_check(struct commit *commit, void *data)
3933 return stdin_packs_include_check_obj((struct object *)commit, data);
3934 }
3935
3936 -static void stdin_packs_add_pack_entries(struct strmap *packs,
3937 - struct rev_info *revs)
3936 +static void stdin_packs_add_all_pack_entries(struct string_list *keys,
3937 + struct rev_info *revs)
3938 {
3939 - struct string_list keys = STRING_LIST_INIT_NODUP;
3939 struct string_list_item *item;
3941 - struct hashmap_iter iter;
3942 - struct strmap_entry *entry;
3943 -
3944 - strmap_for_each_entry(packs, &iter, entry) {
3945 - struct stdin_pack_info *info = entry->value;
3946 - if (!info->p)
3947 - die(_("could not find pack '%s'"), entry->key);
3948 -
3949 - string_list_append(&keys, entry->key)->util = info;
3950 - }
3940
3952 - /*
3953 - * Order packs by ascending mtime; use QSORT directly to access the
3954 - * string_list_item's ->util pointer, which string_list_sort() does not
3955 - * provide.
3956 - */
3957 - QSORT(keys.items, keys.nr, pack_mtime_cmp);
3958 -
3959 - for_each_string_list_item(item, &keys) {
3941 + for_each_string_list_item(item, keys) {
3942 struct stdin_pack_info *info = item->util;
3943
3944 if (info->kind & STDIN_PACK_EXCLUDE_OPEN) {
@@ -3977,6 +3959,31 @@ static void stdin_packs_add_pack_entries(struct strmap *packs,
3959 revs,
3960 ODB_FOR_EACH_OBJECT_PACK_ORDER);
3961 }
3962 +}
3963 +
3964 +static void stdin_packs_add_pack_entries(struct strmap *packs,
3965 + struct rev_info *revs)
3966 +{
3967 + struct string_list keys = STRING_LIST_INIT_NODUP;
3968 + struct hashmap_iter iter;
3969 + struct strmap_entry *entry;
3970 +
3971 + strmap_for_each_entry(packs, &iter, entry) {
3972 + struct stdin_pack_info *info = entry->value;
3973 + if (!info->p)
3974 + die(_("could not find pack '%s'"), entry->key);
3975 +
3976 + string_list_append(&keys, entry->key)->util = info;
3977 + }
3978 +
3979 + /*
3980 + * Order packs by ascending mtime; use QSORT directly to access the
3981 + * string_list_item's ->util pointer, which string_list_sort() does not
3982 + * provide.
3983 + */
3984 + QSORT(keys.items, keys.nr, pack_mtime_cmp);
3985 +
3986 + stdin_packs_add_all_pack_entries(&keys, revs);
3987
3988 string_list_clear(&keys, 0);
3989 }