diff options
| author | Taylor Blau <me@ttaylorr.com> | 2026-02-24 14:00:21 -0500 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-02-24 11:16:34 -0800 |
| commit | 5f3e7f7279da72b20f99a2bcd26d146f7edaef9d (patch) | |
| tree | 3bc7113ec1f309e917e5c4966c75bd98e88c4ca1 | |
| parent | 4f8543255efc3cc1d5247fa16a9f7597ad565993 (diff) | |
| download | git-5f3e7f7279da72b20f99a2bcd26d146f7edaef9d.tar.xz | |
midx-write.c: extract `fill_pack_from_midx()`
When filling packs from an existing MIDX, `fill_packs_from_midx()`
handles preparing a MIDX'd pack, and reading out its pack name from the
existing MIDX.
MIDX compaction will want to perform an identical operation, though the
caller will look quite different than `fill_packs_from_midx()`. To
reduce any future code duplication, extract `fill_pack_from_midx()`
from `fill_packs_from_midx()` to prepare to call our new helper function
in a future change.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
| -rw-r--r-- | midx-write.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/midx-write.c b/midx-write.c index 9d345fb473..c54113cdc8 100644 --- a/midx-write.c +++ b/midx-write.c @@ -913,6 +913,21 @@ cleanup: return ret; } +static int fill_pack_from_midx(struct pack_info *info, + struct multi_pack_index *m, + uint32_t pack_int_id) +{ + if (prepare_midx_pack(m, pack_int_id)) + return error(_("could not load pack %d"), pack_int_id); + + fill_pack_info(info, + m->packs[pack_int_id - m->num_packs_in_base], + m->pack_names[pack_int_id - m->num_packs_in_base], + pack_int_id); + + return 0; +} + static int fill_packs_from_midx(struct write_midx_context *ctx) { struct multi_pack_index *m; @@ -921,13 +936,13 @@ static int fill_packs_from_midx(struct write_midx_context *ctx) uint32_t i; for (i = 0; i < m->num_packs; i++) { - if (prepare_midx_pack(m, m->num_packs_in_base + i)) - return error(_("could not load pack")); - ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc); - fill_pack_info(&ctx->info[ctx->nr++], m->packs[i], - m->pack_names[i], - m->num_packs_in_base + i); + + if (fill_pack_from_midx(&ctx->info[ctx->nr], m, + m->num_packs_in_base + i) < 0) + return -1; + + ctx->nr++; } } return 0; |
