Skip to content

Commit dbd5c52

Browse files
ttaylorrgitster
authored andcommitted
pack-revindex: implement midx_pair_to_pack_pos()
Now that we have extracted the `midx_key_to_pack_pos()` function, we can implement the `midx_pair_to_pack_pos()` function which accepts (pack_id, offset) tuples and returns an index into the psuedo-pack order. This will be used in a following commit in order to figure out whether or not the MIDX chose a given delta's base object from the same pack as the delta resides in. It will do so by locating the base object's offset in the pack, and then performing a binary search using the same pack ID with the base object's offset. If (and only if) it finds a match (at any position) we can guarantee that the MIDX selected both halves of the delta/base pair from the same pack. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1bfe30 commit dbd5c52

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pack-revindex.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,14 @@ int midx_to_pack_pos(struct multi_pack_index *m, uint32_t at, uint32_t *pos)
564564

565565
return midx_key_to_pack_pos(m, &key, pos);
566566
}
567+
568+
int midx_pair_to_pack_pos(struct multi_pack_index *m, uint32_t pack_int_id,
569+
off_t ofs, uint32_t *pos)
570+
{
571+
struct midx_pack_key key = {
572+
.pack = pack_int_id,
573+
.offset = ofs,
574+
.midx = m,
575+
};
576+
return midx_key_to_pack_pos(m, &key, pos);
577+
}

pack-revindex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,7 @@ uint32_t pack_pos_to_midx(struct multi_pack_index *m, uint32_t pos);
142142
*/
143143
int midx_to_pack_pos(struct multi_pack_index *midx, uint32_t at, uint32_t *pos);
144144

145+
int midx_pair_to_pack_pos(struct multi_pack_index *midx, uint32_t pack_id,
146+
off_t ofs, uint32_t *pos);
147+
145148
#endif

0 commit comments

Comments
 (0)