]> git.ipfire.org Git - thirdparty/git.git/commitdiff
index-pack: clarify the breached limit
authorMatt Cooper <vtbassmatt@gmail.com>
Thu, 24 Feb 2022 00:07:20 +0000 (00:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 24 Feb 2022 01:41:10 +0000 (17:41 -0800)
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>
builtin/index-pack.c
t/t5302-pack-index.sh

index 3c2e6aee3cc67be5df9bc1b4b62f5cd8a5c26b86..c45273de3b124942553647ae0f216b4e6a3bb3d1 100644 (file)
@@ -323,8 +323,12 @@ static void use(int bytes)
        if (signed_add_overflows(consumed_bytes, bytes))
                die(_("pack too large for current definition of off_t"));
        consumed_bytes += bytes;
-       if (max_input_size && consumed_bytes > max_input_size)
-               die(_("pack exceeds maximum allowed size"));
+       if (max_input_size && consumed_bytes > max_input_size) {
+               struct strbuf size_limit = STRBUF_INIT;
+               strbuf_humanise_bytes(&size_limit, max_input_size);
+               die(_("pack exceeds maximum allowed size (%s)"),
+                   size_limit.buf);
+       }
 }
 
 static const char *open_pack_file(const char *pack_name)
index 8ee67df38f6c1c272834adcc3deef239eab6dd30..b0095ab41d30aadda45c7dd6e812fd0a5f40ab26 100755 (executable)
@@ -284,4 +284,12 @@ test_expect_success 'index-pack -v --stdin produces progress for both phases' '
        test_i18ngrep "Resolving deltas" err
 '
 
+test_expect_success 'too-large packs report the breach' '
+       pack=$(git pack-objects --all pack </dev/null) &&
+       sz="$(test_file_size pack-$pack.pack)" &&
+       test "$sz" -gt 20 &&
+       test_must_fail git index-pack --max-input-size=20 pack-$pack.pack 2>err &&
+       grep "maximum allowed size (20 bytes)" err
+'
+
 test_done