Skip to content

Commit e5dcd78

Browse files
ttaylorrgitster
authored andcommitted
pack-revindex.c: avoid direct revindex access in 'offset_to_pack_pos()'
To prepare for on-disk reverse indexes, remove a spot in 'offset_to_pack_pos()' that looks at the 'revindex' array in 'struct packed_git'. Even though this use of the revindex pointer is within pack-revindex.c, this clean up is still worth doing. Since the 'revindex' pointer will be NULL when reading from an on-disk reverse index (instead the 'revindex_data' pointer will be mmaped to the 'pack-*.rev' file), this call-site would have to include a conditional to lookup the offset for position 'mi' each iteration through the search. So instead of open-coding 'pack_pos_to_offset()', call it directly from within 'offset_to_pack_pos()'. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5bc7c6 commit e5dcd78

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pack-revindex.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,21 @@ int load_pack_revindex(struct packed_git *p)
177177
int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
178178
{
179179
unsigned lo, hi;
180-
const struct revindex_entry *revindex;
181180

182181
if (load_pack_revindex(p) < 0)
183182
return -1;
184183

185184
lo = 0;
186185
hi = p->num_objects + 1;
187-
revindex = p->revindex;
188186

189187
do {
190188
const unsigned mi = lo + (hi - lo) / 2;
191-
if (revindex[mi].offset == ofs) {
189+
off_t got = pack_pos_to_offset(p, mi);
190+
191+
if (got == ofs) {
192192
*pos = mi;
193193
return 0;
194-
} else if (ofs < revindex[mi].offset)
194+
} else if (ofs < got)
195195
hi = mi;
196196
else
197197
lo = mi + 1;

0 commit comments

Comments
 (0)