Skip to content

Commit 0f8edf7

Browse files
john-caigitster
authored andcommitted
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 <[email protected]> Signed-off-by: John Cai <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2811019 commit 0f8edf7

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

Documentation/git-index-pack.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ default and "Indexing objects" when `--stdin` is specified.
9696
--check-self-contained-and-connected::
9797
Die if the pack contains broken links. For internal use only.
9898

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").
101105
+
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>`.
106111

107112
--threads=<n>::
108113
Specifies the number of threads to spawn when resolving

builtin/index-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "setup.h"
2727

2828
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>])";
3030

3131
struct object_entry {
3232
struct pack_idx_entry idx;
@@ -1785,8 +1785,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17851785
} else if (!strcmp(arg, "--check-self-contained-and-connected")) {
17861786
strict = 1;
17871787
check_self_contained_and_connected = 1;
1788-
} else if (!strcmp(arg, "--fsck-objects")) {
1788+
} else if (skip_to_optional_arg(arg, "--fsck-objects", &arg)) {
17891789
do_fsck_object = 1;
1790+
fsck_set_msg_types(&fsck_options, arg);
17901791
} else if (!strcmp(arg, "--verify")) {
17911792
verify = 1;
17921793
} else if (!strcmp(arg, "--verify-stat")) {

t/t5300-pack-object.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ test_expect_success 'index-pack with --strict' '
441441
)
442442
'
443443

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' '
446445
git init strict &&
447446
(
448447
cd strict &&
@@ -457,12 +456,32 @@ test_expect_success 'index-pack with --strict downgrading fsck msgs' '
457456
458457
EOF
459458
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
463460
)
464461
'
465462

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+
466485
test_expect_success 'honor pack.packSizeLimit' '
467486
git config pack.packSizeLimit 3m &&
468487
packname_10=$(git pack-objects test-10 <obj-list) &&

0 commit comments

Comments
 (0)