Skip to content

Commit ee5d2be

Browse files
committed
Merge branch 'sj/ref-consistency-checks-more' into seen
"git fsck" becomes more careful when checking the refs. * sj/ref-consistency-checks-more: builtin/fsck: add `git refs verify` child process packed-backend: check whether the "packed-refs" is sorted packed-backend: add "packed-refs" entry consistency check packed-backend: check whether the refname contains NUL characters packed-backend: add "packed-refs" header consistency check packed-backend: check whether the "packed-refs" is regular builtin/refs: get worktrees without reading head info t0602: use subshell to ensure working directory unchanged
2 parents 9096168 + b2c32bf commit ee5d2be

File tree

8 files changed

+1040
-481
lines changed

8 files changed

+1040
-481
lines changed

Documentation/fsck-msgids.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
`badObjectSha1`::
1717
(ERROR) An object has a bad sha1.
1818

19+
`badPackedRefEntry`::
20+
(ERROR) The "packed-refs" file contains an invalid entry.
21+
22+
`badPackedRefHeader`::
23+
(ERROR) The "packed-refs" file contains an invalid
24+
header.
25+
1926
`badParentSha1`::
2027
(ERROR) A commit object has a bad parent sha1.
2128

@@ -176,6 +183,16 @@
176183
`nullSha1`::
177184
(WARN) Tree contains entries pointing to a null sha1.
178185

186+
`packedRefEntryNotTerminated`::
187+
(ERROR) The "packed-refs" file contains an entry that is
188+
not terminated by a newline.
189+
190+
`packedRefMissingHeader`::
191+
(INFO) The "packed-refs" file does not contain the header.
192+
193+
`packedRefUnsorted`::
194+
(ERROR) The "packed-refs" file is not sorted.
195+
179196
`refMissingNewline`::
180197
(INFO) A loose ref that does not end with newline(LF). As
181198
valid implementations of Git never created such a loose ref
@@ -208,6 +225,11 @@
208225
`treeNotSorted`::
209226
(ERROR) A tree is not properly sorted.
210227

228+
`unknownPackedRefHeader`::
229+
(INFO) The "packed-refs" header starts with "# pack-refs with:"
230+
but the remaining content is not the same as what `git pack-refs`
231+
would write.
232+
211233
`unknownType`::
212234
(ERROR) Found an unknown object type.
213235

builtin/fsck.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,34 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
905905
return res;
906906
}
907907

908+
static void fsck_refs(struct repository *r)
909+
{
910+
struct child_process refs_verify = CHILD_PROCESS_INIT;
911+
struct progress *progress = NULL;
912+
uint64_t progress_num = 1;
913+
914+
if (show_progress)
915+
progress = start_progress(r, _("Checking ref database"),
916+
progress_num);
917+
918+
if (verbose)
919+
fprintf_ln(stderr, _("Checking ref database"));
920+
921+
child_process_init(&refs_verify);
922+
refs_verify.git_cmd = 1;
923+
strvec_pushl(&refs_verify.args, "refs", "verify", NULL);
924+
if (verbose)
925+
strvec_push(&refs_verify.args, "--verbose");
926+
if (check_strict)
927+
strvec_push(&refs_verify.args, "--strict");
928+
929+
if (run_command(&refs_verify))
930+
errors_found |= ERROR_REFS;
931+
932+
display_progress(progress, 1);
933+
stop_progress(&progress);
934+
}
935+
908936
static char const * const fsck_usage[] = {
909937
N_("git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n"
910938
" [--[no-]full] [--strict] [--verbose] [--lost-found]\n"
@@ -970,6 +998,8 @@ int cmd_fsck(int argc,
970998
git_config(git_fsck_config, &fsck_obj_options);
971999
prepare_repo_settings(the_repository);
9721000

1001+
fsck_refs(the_repository);
1002+
9731003
if (connectivity_only) {
9741004
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
9751005
for_each_packed_object(the_repository,

builtin/refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
8888
git_config(git_fsck_config, &fsck_refs_options);
8989
prepare_repo_settings(the_repository);
9090

91-
worktrees = get_worktrees();
91+
worktrees = get_worktrees_without_reading_head();
9292
for (size_t i = 0; worktrees[i]; i++)
9393
ret |= refs_fsck(get_worktree_ref_store(worktrees[i]),
9494
&fsck_refs_options, worktrees[i]);

fsck.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ enum fsck_msg_type {
3030
FUNC(BAD_EMAIL, ERROR) \
3131
FUNC(BAD_NAME, ERROR) \
3232
FUNC(BAD_OBJECT_SHA1, ERROR) \
33+
FUNC(BAD_PACKED_REF_ENTRY, ERROR) \
34+
FUNC(BAD_PACKED_REF_HEADER, ERROR) \
3335
FUNC(BAD_PARENT_SHA1, ERROR) \
3436
FUNC(BAD_REF_CONTENT, ERROR) \
3537
FUNC(BAD_REF_FILETYPE, ERROR) \
@@ -53,6 +55,8 @@ enum fsck_msg_type {
5355
FUNC(MISSING_TYPE, ERROR) \
5456
FUNC(MISSING_TYPE_ENTRY, ERROR) \
5557
FUNC(MULTIPLE_AUTHORS, ERROR) \
58+
FUNC(PACKED_REF_ENTRY_NOT_TERMINATED, ERROR) \
59+
FUNC(PACKED_REF_UNSORTED, ERROR) \
5660
FUNC(TREE_NOT_SORTED, ERROR) \
5761
FUNC(UNKNOWN_TYPE, ERROR) \
5862
FUNC(ZERO_PADDED_DATE, ERROR) \
@@ -90,6 +94,8 @@ enum fsck_msg_type {
9094
FUNC(REF_MISSING_NEWLINE, INFO) \
9195
FUNC(SYMREF_TARGET_IS_NOT_A_REF, INFO) \
9296
FUNC(TRAILING_REF_CONTENT, INFO) \
97+
FUNC(UNKNOWN_PACKED_REF_HEADER, INFO) \
98+
FUNC(PACKED_REF_MISSING_HEADER, INFO) \
9399
/* ignored (elevated when requested) */ \
94100
FUNC(EXTRA_HEADER_ENTRY, IGNORE)
95101

0 commit comments

Comments
 (0)