aboutsummaryrefslogtreecommitdiff
path: root/replace-object.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2026-02-24 14:00:17 -0500
committerJunio C Hamano <gitster@pobox.com>2026-02-24 11:16:33 -0800
commit4f8543255efc3cc1d5247fa16a9f7597ad565993 (patch)
treeb0cd46b03913e0221024ba3b9de6f9cd2e857172 /replace-object.c
parentb2ec8e90c201d2395b67f89f3bf38bb472e43460 (diff)
downloadgit-4f8543255efc3cc1d5247fa16a9f7597ad565993.tar.xz
midx-write.c: introduce `midx_pack_perm()` helper
The `ctx->pack_perm` array can be considered as a permutation between the original `pack_int_id` of some given pack to its position in the `ctx->info` array containing all packs. Today we can always index into this array with any known `pack_int_id`, since there is never a `pack_int_id` which is greater than or equal to the value `ctx->nr`. That is not necessarily the case with MIDX compaction. For example, suppose we have a MIDX chain with three layers, each containing three packs. The base of the MIDX chain will have packs with IDs 0, 1, and 2, the next layer 3, 4, and 5, and so on. If we are compacting the topmost two layers, we'll have input `pack_int_id` values between [3, 8], but `ctx->nr` will only be 6. In that example, if we want to know where the pack whose original `pack_int_id` value was, say, 7, we would compute `ctx->pack_perm[7]`, leading to an uninitialized read, since there are only 6 entries allocated in that array. To address this, there are a couple of options: - We could allocate enough entries in `ctx->pack_perm` to accommodate the largest `orig_pack_int_id` value. - Or, we could internally shift the input values by the number of packs in the base layer of the lower end of the MIDX compaction range. This patch prepare us to take the latter approach, since it does not allocate more memory than strictly necessary. (In our above example, the base of the lower end of the compaction range is the first MIDX layer (having three packs), so we would end up indexing `ctx->pack_perm[7-3]`, which is a valid read.) Note that this patch does not actually implement that approach yet, but merely performs a behavior-preserving refactoring which will make the change easier to carry out in the future. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'replace-object.c')
0 files changed, 0 insertions, 0 deletions