@matheusbsbs / matheus-bagliano / commits / 5476a8adcc
Fork 0

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 <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed May 30, 2007 at 21:43 UTC 5476a8adcc29985e5496dac7a340dfd178f43a17
1 file changed +11 -18
builtin-pack-objects.c
+11 -18
@@ -410,31 +410,24 @@ static unsigned long write_object(struct sha1file *f,
410 z_stream stream;
411 unsigned long maxsize;
412 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) {
418 size = entry->delta_size;
419 + buf = entry->delta_data;
420 + entry->delta_data = NULL;
421 obj_type = (allow_ofs_delta && entry->delta->offset) ?
422 OBJ_OFS_DELTA : OBJ_REF_DELTA;
423 } else {
424 buf = read_sha1_file(entry->sha1, &type, &size);
425 if (!buf)
426 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;
431 }
432 /* compress the data to store and put compressed length in datalen */
433 memset(&stream, 0, sizeof(stream));