Skip to content

Commit 35866d5

Browse files
shejialuogitster
authored andcommitted
builtin/fsck: add git refs verify child process
At now, we have already implemented the ref consistency checks for both "files-backend" and "packed-backend". Although we would check some redundant things, it won't cause trouble. So, let's integrate it into the "git-fsck(1)" command to get feedback from the users. And also by calling "git refs verify" in "git-fsck(1)", we make sure that the new added checks don't break. Introduce a new function "fsck_refs" that initializes and runs a child process to execute the "git refs verify" command. In order to provide the user interface create a progress which makes the total task be 1. It's hard to know how many loose refs we will check now. We might improve this later. And we run this function in the first execution sequence of "git-fsck(1)" because we don't want the existing code of "git-fsck(1)" which implicitly checks the consistency of refs to die the program. Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Karthik Nayak <[email protected]> Signed-off-by: shejialuo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1cc8811 commit 35866d5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

builtin/fsck.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,32 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
902902
return res;
903903
}
904904

905+
static void fsck_refs(void)
906+
{
907+
struct child_process refs_verify = CHILD_PROCESS_INIT;
908+
struct progress *progress = NULL;
909+
910+
if (show_progress)
911+
progress = start_progress(_("Checking ref database"), 1);
912+
913+
if (verbose)
914+
fprintf_ln(stderr, _("Checking ref database"));
915+
916+
child_process_init(&refs_verify);
917+
refs_verify.git_cmd = 1;
918+
strvec_pushl(&refs_verify.args, "refs", "verify", NULL);
919+
if (verbose)
920+
strvec_push(&refs_verify.args, "--verbose");
921+
if (check_strict)
922+
strvec_push(&refs_verify.args, "--strict");
923+
924+
if (run_command(&refs_verify))
925+
errors_found |= ERROR_REFS;
926+
927+
display_progress(progress, 1);
928+
stop_progress(&progress);
929+
}
930+
905931
static char const * const fsck_usage[] = {
906932
N_("git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n"
907933
" [--[no-]full] [--strict] [--verbose] [--lost-found]\n"
@@ -967,6 +993,8 @@ int cmd_fsck(int argc,
967993
git_config(git_fsck_config, &fsck_obj_options);
968994
prepare_repo_settings(the_repository);
969995

996+
fsck_refs();
997+
970998
if (connectivity_only) {
971999
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
9721000
for_each_packed_object(the_repository,

0 commit comments

Comments
 (0)