From a1e4760fcfece8eb9b556f35a04a521fdee3963c Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 12 Nov 2008 13:23:58 -0500 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 12 ++++++++++-- t/t5300-pack-object.sh | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b0dddbee4..8fe51244e 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -245,8 +245,16 @@ static unsigned long write_object(struct sha1file *f, type = entry->type; /* write limit if limited packsize and not first object */ - limit = pack_size_limit && nr_written ? - pack_size_limit - write_offset : 0; + if (!pack_size_limit || !nr_written) + limit = 0; + else if (pack_size_limit <= write_offset) + /* + * the earlier object did not fit the limit; avoid + * mistaking this with unlimited (i.e. limit = 0). + */ + limit = 1; + else + limit = pack_size_limit - write_offset; if (!entry->delta) usable_delta = 0; /* no delta */ diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 3a0ef8759..2852a0326 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -375,4 +375,10 @@ test_expect_success 'index-pack with --strict' ' ) ' +test_expect_success 'tolerate absurdly small packsizelimit' ' + git config pack.packSizeLimit 2 && + packname_9=$(git pack-objects test-9