Fix pack.packSizeLimit and --max-pack-size handling
If the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Nov 12, 2008 at 13:23 UTC
a1e4760fcfece8eb9b556f35a04a521fdee3963c
2 files changed
+16
-2
builtin-pack-objects.c
+10
-2
@@ -245,8 +245,16 @@ static unsigned long write_object(struct sha1file *f,
245
type = entry->type;
246
247
/* write limit if limited packsize and not first object */
248
- limit = pack_size_limit && nr_written ?
249
- pack_size_limit - write_offset : 0;
248
+ if (!pack_size_limit || !nr_written)
249
+ limit = 0;
250
+ else if (pack_size_limit <= write_offset)
251
+ /*
252
+ * the earlier object did not fit the limit; avoid
253
+ * mistaking this with unlimited (i.e. limit = 0).
254
+ */
255
+ limit = 1;
256
+ else
257
+ limit = pack_size_limit - write_offset;
258
259
if (!entry->delta)
260
usable_delta = 0; /* no delta */
t/t5300-pack-object.sh
+6
@@ -375,4 +375,10 @@ test_expect_success 'index-pack with --strict' '
375
)
376
'
377
378
+test_expect_success 'tolerate absurdly small packsizelimit' '
379
+ git config pack.packSizeLimit 2 &&
380
+ packname_9=$(git pack-objects test-9 <obj-list) &&
381
+ test $(wc -l <obj-list) = $(ls test-9-*.pack | wc -l)
382
+'
383
+
384
test_done