Skip to content

Commit 720c9f7

Browse files
npitregitster
authored andcommitted
Revert "pack-objects: fix pack generation when using pack_size_limit"
This reverts most of commit a2430dd. That commit made the situation better for repositories with relatively small number of objects. However with many objects and a small pack size limit, the time required to complete the repack tends towards O(n^2), or even much worse with long delta chains. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8051a03 commit 720c9f7

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

builtin-pack-objects.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,9 @@ static int write_one(struct sha1file *f,
445445
if (e->idx.offset || e->preferred_base)
446446
return -1;
447447

448-
/*
449-
* If we are deltified, attempt to write out base object first.
450-
* If that fails due to the pack size limit then the current
451-
* object might still possibly fit undeltified within that limit.
452-
*/
453-
if (e->delta)
454-
write_one(f, e->delta, offset);
448+
/* if we are deltified, write out base object first. */
449+
if (e->delta && !write_one(f, e->delta, offset))
450+
return 0;
455451

456452
e->idx.offset = *offset;
457453
size = write_object(f, e, *offset);
@@ -505,9 +501,11 @@ static void write_pack_file(void)
505501
sha1write(f, &hdr, sizeof(hdr));
506502
offset = sizeof(hdr);
507503
nr_written = 0;
508-
for (i = 0; i < nr_objects; i++)
509-
if (write_one(f, objects + i, &offset) == 1)
510-
display_progress(progress_state, written);
504+
for (; i < nr_objects; i++) {
505+
if (!write_one(f, objects + i, &offset))
506+
break;
507+
display_progress(progress_state, written);
508+
}
511509

512510
/*
513511
* Did we write the wrong # entries in the header?
@@ -582,7 +580,7 @@ static void write_pack_file(void)
582580
written_list[j]->offset = (off_t)-1;
583581
}
584582
nr_remaining -= nr_written;
585-
} while (nr_remaining);
583+
} while (nr_remaining && i < nr_objects);
586584

587585
free(written_list);
588586
stop_progress(&progress_state);

t/t5300-pack-object.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ test_expect_success 'verify resulting packs' '
389389
test_expect_success 'tolerate packsizelimit smaller than biggest object' '
390390
git config pack.packSizeLimit 1 &&
391391
packname_11=$(git pack-objects test-11 <obj-list) &&
392-
test 3 = $(ls test-11-*.pack | wc -l)
392+
test 5 = $(ls test-11-*.pack | wc -l)
393393
'
394394

395395
test_expect_success 'verify resulting packs' '

0 commit comments

Comments
 (0)