Commit 363485a
midx-write.c: introduce
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>midx_pack_perm() helper1 parent 35364d7 commit 363485a
1 file changed
+12
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
| |||
509 | 515 | | |
510 | 516 | | |
511 | 517 | | |
512 | | - | |
| 518 | + | |
513 | 519 | | |
514 | 520 | | |
515 | 521 | | |
516 | 522 | | |
517 | | - | |
| 523 | + | |
518 | 524 | | |
519 | 525 | | |
520 | 526 | | |
| |||
615 | 621 | | |
616 | 622 | | |
617 | 623 | | |
618 | | - | |
| 624 | + | |
619 | 625 | | |
620 | 626 | | |
621 | 627 | | |
| |||
625 | 631 | | |
626 | 632 | | |
627 | 633 | | |
628 | | - | |
| 634 | + | |
629 | 635 | | |
630 | 636 | | |
631 | 637 | | |
| |||
686 | 692 | | |
687 | 693 | | |
688 | 694 | | |
689 | | - | |
| 695 | + | |
690 | 696 | | |
691 | 697 | | |
692 | 698 | | |
| |||
1285 | 1291 | | |
1286 | 1292 | | |
1287 | 1293 | | |
1288 | | - | |
| 1294 | + | |
1289 | 1295 | | |
1290 | 1296 | | |
1291 | 1297 | | |
| |||
0 commit comments