Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ceab693
multi-pack-index: add design document
derrickstolee Jul 12, 2018
e0d1bcf
multi-pack-index: add format details
derrickstolee Jul 12, 2018
6a257f0
multi-pack-index: add builtin
derrickstolee Jul 12, 2018
a340773
multi-pack-index: add 'write' verb
derrickstolee Jul 12, 2018
fc59e74
midx: write header information to lockfile
derrickstolee Jul 12, 2018
4d80560
multi-pack-index: load into memory
derrickstolee Jul 12, 2018
2c38133
t5319: expand test data
derrickstolee Jul 12, 2018
9208e31
packfile: generalize pack directory list
derrickstolee Jul 12, 2018
396f257
multi-pack-index: read packfile list
derrickstolee Jul 12, 2018
32f3c54
multi-pack-index: write pack names in chunk
derrickstolee Jul 12, 2018
3227565
midx: read pack names into array
derrickstolee Jul 12, 2018
fe1ed56
midx: sort and deduplicate objects from packfiles
derrickstolee Jul 12, 2018
0d5b3a5
midx: write object ids in a chunk
derrickstolee Jul 12, 2018
d7cacf2
midx: write object id fanout chunk
derrickstolee Jul 12, 2018
662148c
midx: write object offsets
derrickstolee Jul 12, 2018
c4d2522
config: create core.multiPackIndex setting
derrickstolee Jul 12, 2018
3715a63
midx: read objects from multi-pack-index
derrickstolee Jul 12, 2018
8aac67a
midx: use midx in abbreviation calculations
derrickstolee Jul 12, 2018
a40498a
midx: use existing midx when writing new one
derrickstolee Jul 12, 2018
b8990fb
midx: use midx in approximate_object_count
derrickstolee Jul 12, 2018
f3a002b
midx: prevent duplicate packfile loads
derrickstolee Jul 12, 2018
17c35c8
packfile: skip loading index if in multi-pack-index
derrickstolee Jul 12, 2018
525e18c
midx: clear midx on repack
derrickstolee Jul 12, 2018
e1f1c62
Merge remote-tracking branch 'junio/ds/multi-pack-index' into jk/for-…
derrickstolee Aug 15, 2018
444e0dc
multi-pack-index: provide more helpful usage info
derrickstolee Aug 15, 2018
db8a956
multi-pack-index: store local property
derrickstolee Aug 15, 2018
75ce0c2
midx: mark bad packed objects
derrickstolee Aug 17, 2018
9855c10
midx: stop reporting garbage
derrickstolee Aug 17, 2018
6a4a56a
midx: fix bug that skips midx with alternates
derrickstolee Aug 17, 2018
ac27d0b
packfile: add all_packs list
derrickstolee Aug 17, 2018
8fe8697
treewide: use get_all_packs
derrickstolee Aug 17, 2018
f3bcdc6
midx: test a few commands that use get_all_packs
derrickstolee Aug 17, 2018
4eb5df3
pack-objects: consider packs in multi-pack-index
derrickstolee Aug 20, 2018
098dd1d
DO-NOT-MERGE: compute multi-pack-index on repack
derrickstolee Aug 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
midx: read objects from multi-pack-index
Signed-off-by: Derrick Stolee <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
derrickstolee authored and gitster committed Jul 20, 2018
commit 3715a6335c37367b4240b6bfa842dc64dedee34d
91 changes: 90 additions & 1 deletion midx.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "lockfile.h"
#include "packfile.h"
#include "object-store.h"
#include "packfile.h"
#include "sha1-lookup.h"
#include "midx.h"

#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
Expand Down Expand Up @@ -151,6 +151,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
m->num_objects = ntohl(m->chunk_oid_fanout[255]);

m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
m->packs = xcalloc(m->num_packs, sizeof(*m->packs));

cur_pack_name = (const char *)m->chunk_pack_names;
for (i = 0; i < m->num_packs; i++) {
Expand Down Expand Up @@ -178,6 +179,94 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
return NULL;
}

static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
{
struct strbuf pack_name = STRBUF_INIT;

if (pack_int_id >= m->num_packs)
BUG("bad pack-int-id");

if (m->packs[pack_int_id])
return 0;

strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
m->pack_names[pack_int_id]);

m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, 1);
strbuf_release(&pack_name);
return !m->packs[pack_int_id];
}

int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result)
{
return bsearch_hash(oid->hash, m->chunk_oid_fanout, m->chunk_oid_lookup,
MIDX_HASH_LEN, result);
}

static off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos)
{
const unsigned char *offset_data;
uint32_t offset32;

offset_data = m->chunk_object_offsets + pos * MIDX_CHUNK_OFFSET_WIDTH;
offset32 = get_be32(offset_data + sizeof(uint32_t));

if (m->chunk_large_offsets && offset32 & MIDX_LARGE_OFFSET_NEEDED) {
if (sizeof(offset32) < sizeof(uint64_t))
die(_("multi-pack-index stores a 64-bit offset, but off_t is too small"));

offset32 ^= MIDX_LARGE_OFFSET_NEEDED;
return get_be64(m->chunk_large_offsets + sizeof(uint64_t) * offset32);
}

return offset32;
}

static uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
{
return get_be32(m->chunk_object_offsets + pos * MIDX_CHUNK_OFFSET_WIDTH);
}

static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *e, uint32_t pos)
{
uint32_t pack_int_id;
struct packed_git *p;

if (pos >= m->num_objects)
return 0;

pack_int_id = nth_midxed_pack_int_id(m, pos);

if (prepare_midx_pack(m, pack_int_id))
die(_("error preparing packfile from multi-pack-index"));
p = m->packs[pack_int_id];

/*
* We are about to tell the caller where they can locate the
* requested object. We better make sure the packfile is
* still here and can be accessed before supplying that
* answer, as it may have been deleted since the MIDX was
* loaded!
*/
if (!is_pack_valid(p))
return 0;

e->offset = nth_midxed_offset(m, pos);
e->p = p;

return 1;
}

int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m)
{
uint32_t pos;

if (!bsearch_midx(oid, m, &pos))
return 0;

return nth_midxed_pack_entry(m, e, pos);
}

int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
{
struct multi_pack_index *m = r->objects->multi_pack_index;
Expand Down
3 changes: 3 additions & 0 deletions midx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ struct multi_pack_index {
const unsigned char *chunk_large_offsets;

const char **pack_names;
struct packed_git **packs;
char object_dir[FLEX_ARRAY];
};

struct multi_pack_index *load_multi_pack_index(const char *object_dir);
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);

int write_midx_file(const char *object_dir);
Expand Down
8 changes: 7 additions & 1 deletion packfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1902,11 +1902,17 @@ static int fill_pack_entry(const struct object_id *oid,
int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e)
{
struct list_head *pos;
struct multi_pack_index *m;

prepare_packed_git(r);
if (!r->objects->packed_git)
if (!r->objects->packed_git && !r->objects->multi_pack_index)
return 0;

for (m = r->objects->multi_pack_index; m; m = m->next) {
if (fill_midx_entry(oid, e, m))
return 1;
}

list_for_each(pos, &r->objects->packed_git_mru) {
struct packed_git *p = list_entry(pos, struct packed_git, mru);
if (fill_pack_entry(oid, e, p)) {
Expand Down