Skip to content

Commit ad622a2

Browse files
derrickstoleegitster
authored andcommitted
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>
1 parent 2512f15 commit ad622a2

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

pack-revindex.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ static void create_pack_revindex(struct packed_git *p)
134134
if (!(off & 0x80000000)) {
135135
p->revindex[i].offset = off;
136136
} else {
137-
p->revindex[i].offset =
138-
((uint64_t)ntohl(*off_64++)) << 32;
139-
p->revindex[i].offset |=
140-
ntohl(*off_64++);
137+
p->revindex[i].offset = get_be64(off_64);
138+
off_64 += 2;
141139
}
142140
p->revindex[i].nr = i;
143141
}

packfile.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,8 +1702,7 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
17021702
return off;
17031703
index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
17041704
check_pack_index_ptr(p, index);
1705-
return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
1706-
ntohl(*((uint32_t *)(index + 4)));
1705+
return get_be64(index);
17071706
}
17081707
}
17091708

0 commit comments

Comments
 (0)