Skip to content

Commit db6044d

Browse files
ttaylorrpeff
authored andcommitted
commit-graph: avoid repeated mixed generation number warnings
When validating that a commit-graph has either all zero, or all non-zero generation numbers, we emit a warning on both the rising and falling edge of transitioning between the two. So if we are unfortunate enough to see a commit-graph which has a repeating sequence of zero, then non-zero generation numbers, we'll generate many warnings that contain more or less the same information. Avoid this by keeping track of a single example for a commit with zero- and non-zero generation, and emit a single warning at the end of verification if both are non-NULL. Co-authored-by: Jeff King <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce7629a commit db6044d

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

commit-graph.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,9 +2560,6 @@ static void graph_report(const char *fmt, ...)
25602560
va_end(ap);
25612561
}
25622562

2563-
#define GENERATION_ZERO_EXISTS 1
2564-
#define GENERATION_NUMBER_EXISTS 2
2565-
25662563
static int commit_graph_checksum_valid(struct commit_graph *g)
25672564
{
25682565
return hashfile_checksum_valid(g->data, g->data_len);
@@ -2575,7 +2572,8 @@ static int verify_one_commit_graph(struct repository *r,
25752572
{
25762573
uint32_t i, cur_fanout_pos = 0;
25772574
struct object_id prev_oid, cur_oid;
2578-
int generation_zero = 0;
2575+
struct commit *seen_gen_zero = NULL;
2576+
struct commit *seen_gen_non_zero = NULL;
25792577

25802578
verify_commit_graph_error = verify_commit_graph_lite(g);
25812579
if (verify_commit_graph_error)
@@ -2681,19 +2679,12 @@ static int verify_one_commit_graph(struct repository *r,
26812679
graph_report(_("commit-graph parent list for commit %s terminates early"),
26822680
oid_to_hex(&cur_oid));
26832681

2684-
if (!commit_graph_generation_from_graph(graph_commit)) {
2685-
if (generation_zero == GENERATION_NUMBER_EXISTS)
2686-
graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
2687-
oid_to_hex(&cur_oid));
2688-
generation_zero = GENERATION_ZERO_EXISTS;
2689-
} else {
2690-
if (generation_zero == GENERATION_ZERO_EXISTS)
2691-
graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"),
2692-
oid_to_hex(&cur_oid));
2693-
generation_zero = GENERATION_NUMBER_EXISTS;
2694-
}
2682+
if (commit_graph_generation_from_graph(graph_commit))
2683+
seen_gen_non_zero = graph_commit;
2684+
else
2685+
seen_gen_zero = graph_commit;
26952686

2696-
if (generation_zero == GENERATION_ZERO_EXISTS)
2687+
if (seen_gen_zero)
26972688
continue;
26982689

26992690
/*
@@ -2719,6 +2710,12 @@ static int verify_one_commit_graph(struct repository *r,
27192710
odb_commit->date);
27202711
}
27212712

2713+
if (seen_gen_zero && seen_gen_non_zero)
2714+
graph_report(_("commit-graph has both zero and non-zero "
2715+
"generations (e.g., commits '%s' and '%s')"),
2716+
oid_to_hex(&seen_gen_zero->object.oid),
2717+
oid_to_hex(&seen_gen_non_zero->object.oid));
2718+
27222719
return verify_commit_graph_error;
27232720
}
27242721

t/t5318-commit-graph.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,12 @@ test_expect_success 'detect incorrect chunk count' '
620620

621621
test_expect_success 'detect mixed generation numbers (non-zero to zero)' '
622622
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION_LAST "\0\0\0\0" \
623-
"but non-zero elsewhere"
623+
"both zero and non-zero generations"
624624
'
625625

626626
test_expect_success 'detect mixed generation numbers (zero to non-zero)' '
627627
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\0\0\0\0" \
628-
"but zero elsewhere"
628+
"both zero and non-zero generations"
629629
'
630630

631631
test_expect_success 'git fsck (checks commit-graph when config set to true)' '

0 commit comments

Comments
 (0)