1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-24 16:36:21 +02:00

Merge branch 'tb/fsck-no-progress'

"git fsck --no-progress" still spewed noise from the commit-graph
subsystem, which has been corrected.

* tb/fsck-no-progress:
  commit-graph.c: avoid duplicated progress output during `verify`
  commit-graph.c: pass progress to `verify_one_commit_graph()`
  commit-graph.c: iteratively verify commit-graph chains
  commit-graph.c: extract `verify_one_commit_graph()`
  fsck: suppress MIDX output with `--no-progress`
  fsck: suppress commit-graph output with `--no-progress`
This commit is contained in:
Junio C Hamano 2023-07-18 07:28:52 -07:00
commit 6016ee0a71
5 changed files with 67 additions and 19 deletions

View File

@ -1074,6 +1074,10 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
"verify", "--object-dir", odb->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
strvec_push(&commit_graph_verify.args, "--no-progress");
if (run_command(&commit_graph_verify))
errors_found |= ERROR_COMMIT_GRAPH;
}
@ -1088,6 +1092,10 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
"verify", "--object-dir", odb->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
strvec_push(&midx_verify.args, "--no-progress");
if (run_command(&midx_verify))
errors_found |= ERROR_MULTI_PACK_INDEX;
}

View File

@ -2541,18 +2541,14 @@ static int commit_graph_checksum_valid(struct commit_graph *g)
return hashfile_checksum_valid(g->data, g->data_len);
}
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
static int verify_one_commit_graph(struct repository *r,
struct commit_graph *g,
struct progress *progress,
uint64_t *seen)
{
uint32_t i, cur_fanout_pos = 0;
struct object_id prev_oid, cur_oid;
int generation_zero = 0;
struct progress *progress = NULL;
int local_error = 0;
if (!g) {
graph_report("no commit-graph file loaded");
return 1;
}
verify_commit_graph_error = verify_commit_graph_lite(g);
if (verify_commit_graph_error)
@ -2603,17 +2599,13 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
return verify_commit_graph_error;
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
progress = start_progress(_("Verifying commits in commit graph"),
g->num_commits);
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit, *odb_commit;
struct commit_list *graph_parents, *odb_parents;
timestamp_t max_generation = 0;
timestamp_t generation;
display_progress(progress, i + 1);
display_progress(progress, ++(*seen));
oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
graph_commit = lookup_commit(r, &cur_oid);
@ -2696,13 +2688,38 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
graph_commit->date,
odb_commit->date);
}
return verify_commit_graph_error;
}
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
{
struct progress *progress = NULL;
int local_error = 0;
uint64_t seen = 0;
if (!g) {
graph_report("no commit-graph file loaded");
return 1;
}
if (flags & COMMIT_GRAPH_WRITE_PROGRESS) {
uint64_t total = g->num_commits;
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
total += g->num_commits_in_base;
progress = start_progress(_("Verifying commits in commit graph"),
total);
}
for (; g; g = g->base_graph) {
local_error |= verify_one_commit_graph(r, g, progress, &seen);
if (flags & COMMIT_GRAPH_VERIFY_SHALLOW)
break;
}
stop_progress(&progress);
local_error = verify_commit_graph_error;
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW) && g->base_graph)
local_error |= verify_commit_graph(r, g->base_graph, flags);
return local_error;
}

View File

@ -684,6 +684,16 @@ test_expect_success 'git fsck (checks commit-graph when config unset)' '
test_must_fail git fsck
'
test_expect_success 'git fsck shows commit-graph output with --progress' '
git -C "$TRASH_DIRECTORY/full" fsck --progress 2>err &&
grep "Verifying commits in commit graph" err
'
test_expect_success 'git fsck suppresses commit-graph output with --no-progress' '
git -C "$TRASH_DIRECTORY/full" fsck --no-progress 2>err &&
! grep "Verifying commits in commit graph" err
'
test_expect_success 'setup non-the_repository tests' '
rm -rf repo &&
git init repo &&

View File

@ -485,6 +485,18 @@ test_expect_success 'git-fsck incorrect offset' '
git -c core.multiPackIndex=false fsck
'
test_expect_success 'git fsck shows MIDX output with --progress' '
git fsck --progress 2>err &&
grep "Verifying OID order in multi-pack-index" err &&
grep "Verifying object offsets" err
'
test_expect_success 'git fsck suppresses MIDX output with --no-progress' '
git fsck --no-progress 2>err &&
! grep "Verifying OID order in multi-pack-index" err &&
! grep "Verifying object offsets" err
'
test_expect_success 'corrupt MIDX is not reused' '
corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
"incorrect object offset" &&

View File

@ -351,7 +351,8 @@ test_expect_success 'add octopus merge' '
git branch merge/octopus &&
git commit-graph write --reachable --split &&
git commit-graph verify --progress 2>err &&
test_line_count = 3 err &&
test_line_count = 1 err &&
grep "Verifying commits in commit graph: 100% (18/18)" err &&
test_i18ngrep ! warning err &&
test_line_count = 3 $graphdir/commit-graph-chain
'