Skip to content

Commit 0cf5fbc

Browse files
vtbassmattgitster
authored andcommitted
index-pack: clarify the breached limit
As a small courtesy to users, report what limit was breached. This is especially useful when a push exceeds a server-defined limit, since the user is unlikely to have configured the limit (their host did). Also demonstrate the human-readable message in a test. Helped-by: Taylor Blau <[email protected]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Matt Cooper <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6ebfd0 commit 0cf5fbc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

builtin/index-pack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,12 @@ static void use(int bytes)
323323
if (signed_add_overflows(consumed_bytes, bytes))
324324
die(_("pack too large for current definition of off_t"));
325325
consumed_bytes += bytes;
326-
if (max_input_size && consumed_bytes > max_input_size)
327-
die(_("pack exceeds maximum allowed size"));
326+
if (max_input_size && consumed_bytes > max_input_size) {
327+
struct strbuf size_limit = STRBUF_INIT;
328+
strbuf_humanise_bytes(&size_limit, max_input_size);
329+
die(_("pack exceeds maximum allowed size (%s)"),
330+
size_limit.buf);
331+
}
328332
}
329333

330334
static const char *open_pack_file(const char *pack_name)

t/t5302-pack-index.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,12 @@ test_expect_success 'index-pack -v --stdin produces progress for both phases' '
284284
test_i18ngrep "Resolving deltas" err
285285
'
286286

287+
test_expect_success 'too-large packs report the breach' '
288+
pack=$(git pack-objects --all pack </dev/null) &&
289+
sz="$(test_file_size pack-$pack.pack)" &&
290+
test "$sz" -gt 20 &&
291+
test_must_fail git index-pack --max-input-size=20 pack-$pack.pack 2>err &&
292+
grep "maximum allowed size (20 bytes)" err
293+
'
294+
287295
test_done

0 commit comments

Comments
 (0)