Skip to content

Commit

Permalink
pack-objects: learn about pack index version 2
Browse files Browse the repository at this point in the history
This is the reading part only.  No creation of index v2 is provided.

(extracted from commit c553ca2)

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nicolas Pitre authored and Junio C Hamano committed Jul 16, 2008
1 parent 852f96b commit 3339e9f
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions builtin-pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,33 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
int i;
const char *index = p->index_data;

index += 4 * 256;
rix->revindex = xmalloc(sizeof(*rix->revindex) * (num_ent + 1));
for (i = 0; i < num_ent; i++) {
uint32_t hl = *((uint32_t *)(index + 24 * i));
rix->revindex[i].offset = ntohl(hl);
rix->revindex[i].nr = i;
index += 4 * 256;

if (p->index_version > 1) {
const uint32_t *off_32 =
(uint32_t *)(index + 8 + p->num_objects * (20 + 4));
const uint32_t *off_64 = off_32 + p->num_objects;
for (i = 0; i < num_ent; i++) {
uint32_t off = ntohl(*off_32++);
if (!(off & 0x80000000)) {
rix->revindex[i].offset = off;
} else {
rix->revindex[i].offset =
((uint64_t)ntohl(*off_64++)) << 32;
rix->revindex[i].offset |=
ntohl(*off_64++);
}
rix->revindex[i].nr = i;
}
} else {
for (i = 0; i < num_ent; i++) {
uint32_t hl = *((uint32_t *)(index + 24 * i));
rix->revindex[i].offset = ntohl(hl);
rix->revindex[i].nr = i;
}
}

/* This knows the pack format -- the 20-byte trailer
* follows immediately after the last object data.
*/
Expand Down

0 comments on commit 3339e9f

Please sign in to comment.