write_idx_file: need_large_offset() helper function
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
19
pack-write.c
19
pack-write.c
@ -16,6 +16,11 @@ static int sha1_compare(const void *_a, const void *_b)
|
|||||||
return hashcmp(a->sha1, b->sha1);
|
return hashcmp(a->sha1, b->sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int need_large_offset(off_t offset, const struct pack_idx_option *opts)
|
||||||
|
{
|
||||||
|
return (offset >> 31) || (opts->off32_limit < offset);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On entry *sha1 contains the pack content SHA1 hash, on exit it is
|
* On entry *sha1 contains the pack content SHA1 hash, on exit it is
|
||||||
* the SHA1 hash of sorted object names. The objects array passed in
|
* the SHA1 hash of sorted object names. The objects array passed in
|
||||||
@ -65,7 +70,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if last object's offset is >= 2^31 we should use index V2 */
|
/* if last object's offset is >= 2^31 we should use index V2 */
|
||||||
index_version = (last_obj_offset >> 31) ? 2 : opts->version;
|
index_version = need_large_offset(last_obj_offset, opts) ? 2 : opts->version;
|
||||||
|
|
||||||
/* index versions 2 and above need a header */
|
/* index versions 2 and above need a header */
|
||||||
if (index_version >= 2) {
|
if (index_version >= 2) {
|
||||||
@ -125,8 +130,11 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
|
|||||||
list = sorted_by_sha;
|
list = sorted_by_sha;
|
||||||
for (i = 0; i < nr_objects; i++) {
|
for (i = 0; i < nr_objects; i++) {
|
||||||
struct pack_idx_entry *obj = *list++;
|
struct pack_idx_entry *obj = *list++;
|
||||||
uint32_t offset = (obj->offset <= opts->off32_limit) ?
|
uint32_t offset;
|
||||||
obj->offset : (0x80000000 | nr_large_offset++);
|
|
||||||
|
offset = (need_large_offset(obj->offset, opts)
|
||||||
|
? (0x80000000 | nr_large_offset++)
|
||||||
|
: obj->offset);
|
||||||
offset = htonl(offset);
|
offset = htonl(offset);
|
||||||
sha1write(f, &offset, 4);
|
sha1write(f, &offset, 4);
|
||||||
}
|
}
|
||||||
@ -136,15 +144,16 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
|
|||||||
while (nr_large_offset) {
|
while (nr_large_offset) {
|
||||||
struct pack_idx_entry *obj = *list++;
|
struct pack_idx_entry *obj = *list++;
|
||||||
uint64_t offset = obj->offset;
|
uint64_t offset = obj->offset;
|
||||||
if (offset > opts->off32_limit) {
|
|
||||||
uint32_t split[2];
|
uint32_t split[2];
|
||||||
|
|
||||||
|
if (!need_large_offset(offset, opts))
|
||||||
|
continue;
|
||||||
split[0] = htonl(offset >> 32);
|
split[0] = htonl(offset >> 32);
|
||||||
split[1] = htonl(offset & 0xffffffff);
|
split[1] = htonl(offset & 0xffffffff);
|
||||||
sha1write(f, split, 8);
|
sha1write(f, split, 8);
|
||||||
nr_large_offset--;
|
nr_large_offset--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sha1write(f, sha1, 20);
|
sha1write(f, sha1, 20);
|
||||||
sha1close(f, NULL, ((opts->flags & WRITE_IDX_VERIFY)
|
sha1close(f, NULL, ((opts->flags & WRITE_IDX_VERIFY)
|
||||||
|
Reference in New Issue
Block a user