Browse Source

packfile: use get_be64() for large offsets

The pack-index version 2 format uses two 4-byte integers in
network-byte order to represent one 8-byte value. The current
implementation has several code clones for stitching these integers
together.

Use get_be64() to create an 8-byte integer from two 4-byte integers
represented this way.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Derrick Stolee 7 years ago committed by Junio C Hamano
parent
commit
ad622a256f
  1. 6
      pack-revindex.c
  2. 3
      packfile.c

6
pack-revindex.c

@ -134,10 +134,8 @@ static void create_pack_revindex(struct packed_git *p) @@ -134,10 +134,8 @@ static void create_pack_revindex(struct packed_git *p)
if (!(off & 0x80000000)) {
p->revindex[i].offset = off;
} else {
p->revindex[i].offset =
((uint64_t)ntohl(*off_64++)) << 32;
p->revindex[i].offset |=
ntohl(*off_64++);
p->revindex[i].offset = get_be64(off_64);
off_64 += 2;
}
p->revindex[i].nr = i;
}

3
packfile.c

@ -1702,8 +1702,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) @@ -1702,8 +1702,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
return off;
index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
check_pack_index_ptr(p, index);
return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
ntohl(*((uint32_t *)(index + 4)));
return get_be64(index);
}
}


Loading…
Cancel
Save