index-pack: --fsck-objects to take an optional argument for fsck msgs

git-index-pack has a --strict option that can take an optional argument to provide a list of fsck issues to change their severity. --fsck-objects does not have such a utility, which would be useful if one would like to be more lenient or strict on data integrity in a repository. Like --strict, allow --fsck-objects to also take a list of fsck msgs to change the severity. Remove the "For internal use only" note for --fsck-objects, and document the option. This won't often be used by the normal end user, but it turns out it is useful for Git forges like GitLab. Reviewed-by: Christian Couder <christian.couder@gmail.com> Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Cai committed Feb 1, 2024 at 01:38 UTC 0f8edf7317c7eb152bf045ed99b46072439088a6
3 files changed +38 -13
Documentation/git-index-pack.txt
+11 -6
@@ -96,13 +96,18 @@ default and "Indexing objects" when `--stdin` is specified.
96 --check-self-contained-and-connected::
97 Die if the pack contains broken links. For internal use only.
98
99 ---fsck-objects::
100 - For internal use only.
99 +--fsck-objects[=<msg-id>=<severity>...]::
100 + Die if the pack contains broken objects, but unlike `--strict`, don't
101 + choke on broken links. If the pack contains a tree pointing to a
102 + .gitmodules blob that does not exist, prints the hash of that blob
103 + (for the caller to check) after the hash that goes into the name of the
104 + pack/idx file (see "Notes").
105 +
102 -Die if the pack contains broken objects. If the pack contains a tree
103 -pointing to a .gitmodules blob that does not exist, prints the hash of
104 -that blob (for the caller to check) after the hash that goes into the
105 -name of the pack/idx file (see "Notes").
106 +An optional comma-separated list of `<msg-id>=<severity>` can be passed to
107 +change the severity of some possible issues, e.g.,
108 +`--fsck-objects="missingEmail=ignore,badTagName=ignore"`. See the entry for the
109 +`fsck.<msg-id>` configuration options in linkgit:git-fsck[1] for more
110 +information on the possible values of `<msg-id>` and `<severity>`.
111
112 --threads=<n>::
113 Specifies the number of threads to spawn when resolving
builtin/index-pack.c
+3 -2
@@ -26,7 +26,7 @@
26 #include "setup.h"
27
28 static const char index_pack_usage[] =
29 -"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict[=<msg-id>=<severity>...]] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
29 +"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict[=<msg-id>=<severity>...]] [--fsck-objects[=<msg-id>=<severity>...]] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
30
31 struct object_entry {
32 struct pack_idx_entry idx;
@@ -1785,8 +1785,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1785 } else if (!strcmp(arg, "--check-self-contained-and-connected")) {
1786 strict = 1;
1787 check_self_contained_and_connected = 1;
1788 - } else if (!strcmp(arg, "--fsck-objects")) {
1788 + } else if (skip_to_optional_arg(arg, "--fsck-objects", &arg)) {
1789 do_fsck_object = 1;
1790 + fsck_set_msg_types(&fsck_options, arg);
1791 } else if (!strcmp(arg, "--verify")) {
1792 verify = 1;
1793 } else if (!strcmp(arg, "--verify-stat")) {
t/t5300-pack-object.sh
+24 -5
@@ -441,8 +441,7 @@ test_expect_success 'index-pack with --strict' '
441 )
442 '
443
444 -test_expect_success 'index-pack with --strict downgrading fsck msgs' '
445 - test_when_finished rm -rf strict &&
444 +test_expect_success 'setup for --strict and --fsck-objects downgrading fsck msgs' '
445 git init strict &&
446 (
447 cd strict &&
@@ -457,12 +456,32 @@ test_expect_success 'index-pack with --strict downgrading fsck msgs' '
456
457 EOF
458 git hash-object --literally -t commit -w --stdin <commit >commit_list &&
460 - PACK=$(git pack-objects test <commit_list) &&
461 - test_must_fail git index-pack --strict "test-$PACK.pack" &&
462 - git index-pack --strict="missingEmail=ignore" "test-$PACK.pack"
459 + git pack-objects test <commit_list >pack-name
460 )
461 '
462
463 +test_with_bad_commit () {
464 + must_fail_arg="$1" &&
465 + must_pass_arg="$2" &&
466 + (
467 + cd strict &&
468 + test_expect_fail git index-pack "$must_fail_arg" "test-$(cat pack-name).pack"
469 + git index-pack "$must_pass_arg" "test-$(cat pack-name).pack"
470 + )
471 +}
472 +
473 +test_expect_success 'index-pack with --strict downgrading fsck msgs' '
474 + test_with_bad_commit --strict --strict="missingEmail=ignore"
475 +'
476 +
477 +test_expect_success 'index-pack with --fsck-objects downgrading fsck msgs' '
478 + test_with_bad_commit --fsck-objects --fsck-objects="missingEmail=ignore"
479 +'
480 +
481 +test_expect_success 'cleanup for --strict and --fsck-objects downgrading fsck msgs' '
482 + rm -rf strict
483 +'
484 +
485 test_expect_success 'honor pack.packSizeLimit' '
486 git config pack.packSizeLimit 3m &&
487 packname_10=$(git pack-objects test-10 <obj-list) &&