midx: write object ids in a chunk
Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
fe1ed56f5e
commit
0d5b3a5ef7
@ -302,6 +302,10 @@ CHUNK DATA:
|
|||||||
name. This is the only chunk not guaranteed to be a multiple of four
|
name. This is the only chunk not guaranteed to be a multiple of four
|
||||||
bytes in length, so should be the last chunk for alignment reasons.
|
bytes in length, so should be the last chunk for alignment reasons.
|
||||||
|
|
||||||
|
OID Lookup (ID: {'O', 'I', 'D', 'L'})
|
||||||
|
The OIDs for all objects in the MIDX are stored in lexicographic
|
||||||
|
order in this chunk.
|
||||||
|
|
||||||
(This section intentionally left incomplete.)
|
(This section intentionally left incomplete.)
|
||||||
|
|
||||||
TRAILER:
|
TRAILER:
|
||||||
|
47
midx.c
47
midx.c
@ -18,9 +18,10 @@
|
|||||||
#define MIDX_HASH_LEN 20
|
#define MIDX_HASH_LEN 20
|
||||||
#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + MIDX_HASH_LEN)
|
#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + MIDX_HASH_LEN)
|
||||||
|
|
||||||
#define MIDX_MAX_CHUNKS 1
|
#define MIDX_MAX_CHUNKS 2
|
||||||
#define MIDX_CHUNK_ALIGNMENT 4
|
#define MIDX_CHUNK_ALIGNMENT 4
|
||||||
#define MIDX_CHUNKID_PACKNAMES 0x504e414d /* "PNAM" */
|
#define MIDX_CHUNKID_PACKNAMES 0x504e414d /* "PNAM" */
|
||||||
|
#define MIDX_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
|
||||||
#define MIDX_CHUNKLOOKUP_WIDTH (sizeof(uint32_t) + sizeof(uint64_t))
|
#define MIDX_CHUNKLOOKUP_WIDTH (sizeof(uint32_t) + sizeof(uint64_t))
|
||||||
|
|
||||||
static char *get_midx_filename(const char *object_dir)
|
static char *get_midx_filename(const char *object_dir)
|
||||||
@ -101,6 +102,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
|
|||||||
m->chunk_pack_names = m->data + chunk_offset;
|
m->chunk_pack_names = m->data + chunk_offset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MIDX_CHUNKID_OIDLOOKUP:
|
||||||
|
m->chunk_oid_lookup = m->data + chunk_offset;
|
||||||
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
die(_("terminating multi-pack-index chunk id appears earlier than expected"));
|
die(_("terminating multi-pack-index chunk id appears earlier than expected"));
|
||||||
break;
|
break;
|
||||||
@ -116,6 +121,8 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
|
|||||||
|
|
||||||
if (!m->chunk_pack_names)
|
if (!m->chunk_pack_names)
|
||||||
die(_("multi-pack-index missing required pack-name chunk"));
|
die(_("multi-pack-index missing required pack-name chunk"));
|
||||||
|
if (!m->chunk_oid_lookup)
|
||||||
|
die(_("multi-pack-index missing required OID lookup chunk"));
|
||||||
|
|
||||||
m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
|
m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
|
||||||
|
|
||||||
@ -382,6 +389,32 @@ static size_t write_midx_pack_names(struct hashfile *f,
|
|||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t write_midx_oid_lookup(struct hashfile *f, unsigned char hash_len,
|
||||||
|
struct pack_midx_entry *objects,
|
||||||
|
uint32_t nr_objects)
|
||||||
|
{
|
||||||
|
struct pack_midx_entry *list = objects;
|
||||||
|
uint32_t i;
|
||||||
|
size_t written = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < nr_objects; i++) {
|
||||||
|
struct pack_midx_entry *obj = list++;
|
||||||
|
|
||||||
|
if (i < nr_objects - 1) {
|
||||||
|
struct pack_midx_entry *next = list;
|
||||||
|
if (oidcmp(&obj->oid, &next->oid) >= 0)
|
||||||
|
BUG("OIDs not in order: %s >= %s",
|
||||||
|
oid_to_hex(&obj->oid),
|
||||||
|
oid_to_hex(&next->oid));
|
||||||
|
}
|
||||||
|
|
||||||
|
hashwrite(f, obj->oid.hash, (int)hash_len);
|
||||||
|
written += hash_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
int write_midx_file(const char *object_dir)
|
int write_midx_file(const char *object_dir)
|
||||||
{
|
{
|
||||||
unsigned char cur_chunk, num_chunks = 0;
|
unsigned char cur_chunk, num_chunks = 0;
|
||||||
@ -428,7 +461,7 @@ int write_midx_file(const char *object_dir)
|
|||||||
FREE_AND_NULL(midx_name);
|
FREE_AND_NULL(midx_name);
|
||||||
|
|
||||||
cur_chunk = 0;
|
cur_chunk = 0;
|
||||||
num_chunks = 1;
|
num_chunks = 2;
|
||||||
|
|
||||||
written = write_midx_header(f, num_chunks, packs.nr);
|
written = write_midx_header(f, num_chunks, packs.nr);
|
||||||
|
|
||||||
@ -436,9 +469,13 @@ int write_midx_file(const char *object_dir)
|
|||||||
chunk_offsets[cur_chunk] = written + (num_chunks + 1) * MIDX_CHUNKLOOKUP_WIDTH;
|
chunk_offsets[cur_chunk] = written + (num_chunks + 1) * MIDX_CHUNKLOOKUP_WIDTH;
|
||||||
|
|
||||||
cur_chunk++;
|
cur_chunk++;
|
||||||
chunk_ids[cur_chunk] = 0;
|
chunk_ids[cur_chunk] = MIDX_CHUNKID_OIDLOOKUP;
|
||||||
chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + packs.pack_name_concat_len;
|
chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + packs.pack_name_concat_len;
|
||||||
|
|
||||||
|
cur_chunk++;
|
||||||
|
chunk_ids[cur_chunk] = 0;
|
||||||
|
chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_HASH_LEN;
|
||||||
|
|
||||||
for (i = 0; i <= num_chunks; i++) {
|
for (i = 0; i <= num_chunks; i++) {
|
||||||
if (i && chunk_offsets[i] < chunk_offsets[i - 1])
|
if (i && chunk_offsets[i] < chunk_offsets[i - 1])
|
||||||
BUG("incorrect chunk offsets: %"PRIu64" before %"PRIu64,
|
BUG("incorrect chunk offsets: %"PRIu64" before %"PRIu64,
|
||||||
@ -468,6 +505,10 @@ int write_midx_file(const char *object_dir)
|
|||||||
written += write_midx_pack_names(f, packs.names, packs.nr);
|
written += write_midx_pack_names(f, packs.names, packs.nr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MIDX_CHUNKID_OIDLOOKUP:
|
||||||
|
written += write_midx_oid_lookup(f, MIDX_HASH_LEN, entries, nr_entries);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BUG("trying to write unknown chunk id %"PRIx32,
|
BUG("trying to write unknown chunk id %"PRIx32,
|
||||||
chunk_ids[i]);
|
chunk_ids[i]);
|
||||||
|
1
midx.h
1
midx.h
@ -15,6 +15,7 @@ struct multi_pack_index {
|
|||||||
uint32_t num_objects;
|
uint32_t num_objects;
|
||||||
|
|
||||||
const unsigned char *chunk_pack_names;
|
const unsigned char *chunk_pack_names;
|
||||||
|
const unsigned char *chunk_oid_lookup;
|
||||||
|
|
||||||
const char **pack_names;
|
const char **pack_names;
|
||||||
char object_dir[FLEX_ARRAY];
|
char object_dir[FLEX_ARRAY];
|
||||||
|
@ -22,6 +22,8 @@ static int read_midx_file(const char *object_dir)
|
|||||||
|
|
||||||
if (m->chunk_pack_names)
|
if (m->chunk_pack_names)
|
||||||
printf(" pack-names");
|
printf(" pack-names");
|
||||||
|
if (m->chunk_oid_lookup)
|
||||||
|
printf(" oid-lookup");
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ midx_read_expect () {
|
|||||||
NUM_PACKS=$1
|
NUM_PACKS=$1
|
||||||
{
|
{
|
||||||
cat <<-EOF &&
|
cat <<-EOF &&
|
||||||
header: 4d494458 1 1 $NUM_PACKS
|
header: 4d494458 1 2 $NUM_PACKS
|
||||||
chunks: pack-names
|
chunks: pack-names oid-lookup
|
||||||
packs:
|
packs:
|
||||||
EOF
|
EOF
|
||||||
if test $NUM_PACKS -ge 1
|
if test $NUM_PACKS -ge 1
|
||||||
|
Reference in New Issue
Block a user