Now that we're using `commit_graph_generation_from_graph()` (which can return a zero value) and we have a pure if/else instead of an else-if, let's swap the arms of the if-statement. This avoids an "if (!x) { foo(); } else { bar(); }" and replaces it with the more readable "if (x) { bar(); } else { foo(); }". Let's also move this code to verify mixed zero/non-zero generation numbers out to its own function, and have it modify the `generation_zero` variable through a pointer. There is no functionality change in this patch, but note that there are a couple of textual differences. First, the wrapping is adjusted on both `graph_report()` calls to avoid overly-long lines. Second, we use the OID from `graph_commit` instead of passing in `cur_oid`, since these are verified to be the same by `verify_one_commit_graph()`. Signed-off-by: Taylor Blau <me@xxxxxxxxxxxx> --- commit-graph.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index acca753ce8..f7d9b31546 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2568,6 +2568,27 @@ static int commit_graph_checksum_valid(struct commit_graph *g) return hashfile_checksum_valid(g->data, g->data_len); } +static void verify_mixed_generation_numbers(struct commit_graph *g, + struct commit *graph_commit, + int *generation_zero) +{ + if (commit_graph_generation_from_graph(graph_commit)) { + if (*generation_zero == GENERATION_ZERO_EXISTS) + graph_report(_("commit-graph has non-zero generation " + "number for commit %s, but zero " + "elsewhere"), + oid_to_hex(&graph_commit->object.oid)); + *generation_zero = GENERATION_NUMBER_EXISTS; + } else { + if (*generation_zero == GENERATION_NUMBER_EXISTS) + graph_report(_("commit-graph has generation number " + "zero for commit %s, but non-zero " + "elsewhere"), + oid_to_hex(&graph_commit->object.oid)); + *generation_zero = GENERATION_ZERO_EXISTS; + } +} + static int verify_one_commit_graph(struct repository *r, struct commit_graph *g, struct progress *progress, @@ -2681,17 +2702,8 @@ static int verify_one_commit_graph(struct repository *r, graph_report(_("commit-graph parent list for commit %s terminates early"), oid_to_hex(&cur_oid)); - if (!commit_graph_generation_from_graph(graph_commit)) { - if (generation_zero == GENERATION_NUMBER_EXISTS) - graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"), - oid_to_hex(&cur_oid)); - generation_zero = GENERATION_ZERO_EXISTS; - } else { - if (generation_zero == GENERATION_ZERO_EXISTS) - graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"), - oid_to_hex(&cur_oid)); - generation_zero = GENERATION_NUMBER_EXISTS; - } + verify_mixed_generation_numbers(g, graph_commit, + &generation_zero); if (generation_zero == GENERATION_ZERO_EXISTS) continue; -- 2.42.0.rc0.30.gb82b15ebc8