diff options
author | Taylor Blau <me@ttaylorr.com> | 2021-01-14 01:25:10 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-01-14 08:53:48 +0300 |
commit | e5dcd7841828fd4c03dfc8a5c52691ada979b7e2 (patch) | |
tree | 843c88476e50896f179d590fdff70ccd6c2ef9f0 /pack-revindex.c | |
parent | d5bc7c60c72ee239b5c5d3e4aa808d29412f78d8 (diff) |
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 <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-revindex.c')
-rw-r--r-- | pack-revindex.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/pack-revindex.c b/pack-revindex.c index a508d5f0a4..5e69bc7372 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -177,21 +177,21 @@ int load_pack_revindex(struct packed_git *p) int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos) { unsigned lo, hi; - const struct revindex_entry *revindex; if (load_pack_revindex(p) < 0) return -1; lo = 0; hi = p->num_objects + 1; - revindex = p->revindex; do { const unsigned mi = lo + (hi - lo) / 2; - if (revindex[mi].offset == ofs) { + off_t got = pack_pos_to_offset(p, mi); + + if (got == ofs) { *pos = mi; return 0; - } else if (ofs < revindex[mi].offset) + } else if (ofs < got) hi = mi; else lo = mi + 1; |