mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
pack-revindex: prepare for incremental MIDX bitmaps
Prepare the reverse index machinery to handle object lookups in an
incremental MIDX bitmap. These changes are broken out across a few
functions:
- load_midx_revindex() learns to use the appropriate MIDX filename
depending on whether the given 'struct multi_pack_index *' is
incremental or not.
- pack_pos_to_midx() and midx_to_pack_pos() now both take in a global
object position in the MIDX pseudo-pack order, and find the
earliest containing MIDX (similar to midx.c::midx_for_object().
- midx_pack_order_cmp() adjusts its call to pack_pos_to_midx() by the
number of objects in the base (since 'vb - midx->revindx_data' is
relative to the containing MIDX, and pack_pos_to_midx() expects a
global position).
Likewise, this function adjusts its output by adding
m->num_objects_in_base to return a global position out through the
`*pos` pointer.
Together, these changes are sufficient to use the multi-pack index's
reverse index format for incremental multi-pack reachability bitmaps.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
4887bdd4c7
commit
8331c17b79
@@ -383,8 +383,14 @@ int load_midx_revindex(struct multi_pack_index *m)
|
||||
trace2_data_string("load_midx_revindex", the_repository,
|
||||
"source", "rev");
|
||||
|
||||
get_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir,
|
||||
get_midx_checksum(m), MIDX_EXT_REV);
|
||||
if (m->has_chain)
|
||||
get_split_midx_filename_ext(m->repo->hash_algo, &revindex_name,
|
||||
m->object_dir, get_midx_checksum(m),
|
||||
MIDX_EXT_REV);
|
||||
else
|
||||
get_midx_filename_ext(m->repo->hash_algo, &revindex_name,
|
||||
m->object_dir, get_midx_checksum(m),
|
||||
MIDX_EXT_REV);
|
||||
|
||||
ret = load_revindex_from_disk(revindex_name.buf,
|
||||
m->num_objects,
|
||||
@@ -471,11 +477,15 @@ off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos)
|
||||
|
||||
uint32_t pack_pos_to_midx(struct multi_pack_index *m, uint32_t pos)
|
||||
{
|
||||
while (m && pos < m->num_objects_in_base)
|
||||
m = m->base_midx;
|
||||
if (!m)
|
||||
BUG("NULL multi-pack-index for object position: %"PRIu32, pos);
|
||||
if (!m->revindex_data)
|
||||
BUG("pack_pos_to_midx: reverse index not yet loaded");
|
||||
if (m->num_objects <= pos)
|
||||
if (m->num_objects + m->num_objects_in_base <= pos)
|
||||
BUG("pack_pos_to_midx: out-of-bounds object at %"PRIu32, pos);
|
||||
return get_be32(m->revindex_data + pos);
|
||||
return get_be32(m->revindex_data + pos - m->num_objects_in_base);
|
||||
}
|
||||
|
||||
struct midx_pack_key {
|
||||
@@ -491,7 +501,8 @@ static int midx_pack_order_cmp(const void *va, const void *vb)
|
||||
const struct midx_pack_key *key = va;
|
||||
struct multi_pack_index *midx = key->midx;
|
||||
|
||||
uint32_t versus = pack_pos_to_midx(midx, (uint32_t*)vb - (const uint32_t *)midx->revindex_data);
|
||||
size_t pos = (uint32_t *)vb - (const uint32_t *)midx->revindex_data;
|
||||
uint32_t versus = pack_pos_to_midx(midx, pos + midx->num_objects_in_base);
|
||||
uint32_t versus_pack = nth_midxed_pack_int_id(midx, versus);
|
||||
off_t versus_offset;
|
||||
|
||||
@@ -529,9 +540,9 @@ static int midx_key_to_pack_pos(struct multi_pack_index *m,
|
||||
{
|
||||
uint32_t *found;
|
||||
|
||||
if (key->pack >= m->num_packs)
|
||||
if (key->pack >= m->num_packs + m->num_packs_in_base)
|
||||
BUG("MIDX pack lookup out of bounds (%"PRIu32" >= %"PRIu32")",
|
||||
key->pack, m->num_packs);
|
||||
key->pack, m->num_packs + m->num_packs_in_base);
|
||||
/*
|
||||
* The preferred pack sorts first, so determine its identifier by
|
||||
* looking at the first object in pseudo-pack order.
|
||||
@@ -551,7 +562,8 @@ static int midx_key_to_pack_pos(struct multi_pack_index *m,
|
||||
if (!found)
|
||||
return -1;
|
||||
|
||||
*pos = found - m->revindex_data;
|
||||
*pos = (found - m->revindex_data) + m->num_objects_in_base;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -559,9 +571,13 @@ int midx_to_pack_pos(struct multi_pack_index *m, uint32_t at, uint32_t *pos)
|
||||
{
|
||||
struct midx_pack_key key;
|
||||
|
||||
while (m && at < m->num_objects_in_base)
|
||||
m = m->base_midx;
|
||||
if (!m)
|
||||
BUG("NULL multi-pack-index for object position: %"PRIu32, at);
|
||||
if (!m->revindex_data)
|
||||
BUG("midx_to_pack_pos: reverse index not yet loaded");
|
||||
if (m->num_objects <= at)
|
||||
if (m->num_objects + m->num_objects_in_base <= at)
|
||||
BUG("midx_to_pack_pos: out-of-bounds object at %"PRIu32, at);
|
||||
|
||||
key.pack = nth_midxed_pack_int_id(m, at);
|
||||
|
||||
Reference in New Issue
Block a user