Skip to content

Commit b2c32bf

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 ef7dbd7 commit b2c32bf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

builtin/fsck.c

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

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

998+
fsck_refs(the_repository);
999+
9701000
if (connectivity_only) {
9711001
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
9721002
for_each_packed_object(the_repository,

0 commit comments

Comments
 (0)