Skip to content

Commit a1e4760

Browse files
Nicolas Pitregitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa7b3c2 commit a1e4760

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

builtin-pack-objects.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,16 @@ static unsigned long write_object(struct sha1file *f,
245245
type = entry->type;
246246

247247
/* 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;
250258

251259
if (!entry->delta)
252260
usable_delta = 0; /* no delta */

t/t5300-pack-object.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,10 @@ test_expect_success 'index-pack with --strict' '
375375
)
376376
'
377377

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+
378384
test_done

0 commit comments

Comments
 (0)