Skip to content

Commit 5476a8a

Browse files
Nicolas PitreJunio C Hamano
authored andcommitted
fix repack with --max-pack-size
Two issues here: 1) git-repack -a --max-pack-size=10 on the GIT repo dies pretty quick. There is a lot of confusion about deltas that were suposed to be reused from another pack but that get stored undeltified due to pack limit and object size doesn't match entry->size anymore. This test is not really worth the complexity for determining when it is valid so get rid of it. 2) If pack limit is reached, the object buffer is freed, including when it comes from a cached delta data. In practice the object will be stored in a subsequent pack undeltified, but let's make sure no pointer to freed data subsists by clearing entry->delta_data. I also reorganized that code a bit to make it more readable. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3dfddb commit 5476a8a

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

builtin-pack-objects.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -410,31 +410,24 @@ static unsigned long write_object(struct sha1file *f,
410410
z_stream stream;
411411
unsigned long maxsize;
412412
void *out;
413-
if (entry->delta_data && usable_delta) {
414-
buf = entry->delta_data;
413+
if (!usable_delta) {
414+
buf = read_sha1_file(entry->sha1, &obj_type, &size);
415+
if (!buf)
416+
die("unable to read %s", sha1_to_hex(entry->sha1));
417+
} else if (entry->delta_data) {
415418
size = entry->delta_size;
419+
buf = entry->delta_data;
420+
entry->delta_data = NULL;
416421
obj_type = (allow_ofs_delta && entry->delta->offset) ?
417422
OBJ_OFS_DELTA : OBJ_REF_DELTA;
418423
} else {
419424
buf = read_sha1_file(entry->sha1, &type, &size);
420425
if (!buf)
421426
die("unable to read %s", sha1_to_hex(entry->sha1));
422-
if (size != entry->size)
423-
die("object %s size inconsistency (%lu vs %lu)",
424-
sha1_to_hex(entry->sha1), size, entry->size);
425-
if (usable_delta) {
426-
buf = delta_against(buf, size, entry);
427-
size = entry->delta_size;
428-
obj_type = (allow_ofs_delta && entry->delta->offset) ?
429-
OBJ_OFS_DELTA : OBJ_REF_DELTA;
430-
} else {
431-
/*
432-
* recover real object type in case
433-
* check_object() wanted to re-use a delta,
434-
* but we couldn't since base was in previous split pack
435-
*/
436-
obj_type = type;
437-
}
427+
buf = delta_against(buf, size, entry);
428+
size = entry->delta_size;
429+
obj_type = (allow_ofs_delta && entry->delta->offset) ?
430+
OBJ_OFS_DELTA : OBJ_REF_DELTA;
438431
}
439432
/* compress the data to store and put compressed length in datalen */
440433
memset(&stream, 0, sizeof(stream));

0 commit comments

Comments
 (0)