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 <me@ttaylorr.com> Helped-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Matt Cooper <vtbassmatt@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matt Cooper committed Feb 24, 2022 at 00:07 UTC 0cf5fbc2e4ee124b4dc583fac6f7ad697616a56a
2 files changed +14 -2
builtin/index-pack.c
+6 -2
@@ -323,8 +323,12 @@ static void use(int bytes)
323 if (signed_add_overflows(consumed_bytes, bytes))
324 die(_("pack too large for current definition of off_t"));
325 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 + }
332 }
333
334 static const char *open_pack_file(const char *pack_name)
t/t5302-pack-index.sh
+8
@@ -284,4 +284,12 @@ test_expect_success 'index-pack -v --stdin produces progress for both phases' '
284 test_i18ngrep "Resolving deltas" err
285 '
286
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 +
295 test_done