Skip to content

Commit 868c991

Browse files
ttaylorrgitster
authored andcommitted
commit-graph: introduce commit_graph_generation_from_graph()
In 2ee11f7 (commit-graph: return generation from memory, 2023-03-20), the `commit_graph_generation()` function stopped returning zeros when asked to locate the generation number of a given commit. This was done at the time to prepare for a later change which set generation values in memory, meaning that we could no longer rely on `graph_pos` alone to tell us whether or not to trust the generation number returned by this function. In 2ee11f7, it was noted that this change only impacted very old commit-graphs, which were written with all commits having generation number 0. Indeed, zero is not a valid generation number, so we should never expect to see that value outside of the aforementioned case. The test fallout in 2ee11f7 indicated that we were no longer able to fsck a specific old case of commit-graph corruption, where we see a non-zero generation number after having seen a generation number of 0 earlier. Introduce a variant of `commit_graph_generation()` which behaves like that function did prior to 2ee11f7, known as `commit_graph_generation_from_graph()`. Then use this function in the context of `verify_one_commit_graph()`, where we only want to trust the values from the graph. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a82fb66 commit 868c991

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

commit-graph.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ timestamp_t commit_graph_generation(const struct commit *c)
128128
return GENERATION_NUMBER_INFINITY;
129129
}
130130

131+
static timestamp_t commit_graph_generation_from_graph(const struct commit *c)
132+
{
133+
struct commit_graph_data *data =
134+
commit_graph_data_slab_peek(&commit_graph_data_slab, c);
135+
136+
if (!data || data->graph_pos == COMMIT_NOT_FROM_GRAPH)
137+
return GENERATION_NUMBER_INFINITY;
138+
return data->generation;
139+
}
140+
131141
static struct commit_graph_data *commit_graph_data_at(const struct commit *c)
132142
{
133143
unsigned int i, nth_slab;
@@ -2659,7 +2669,7 @@ static int verify_one_commit_graph(struct repository *r,
26592669
oid_to_hex(&graph_parents->item->object.oid),
26602670
oid_to_hex(&odb_parents->item->object.oid));
26612671

2662-
generation = commit_graph_generation(graph_parents->item);
2672+
generation = commit_graph_generation_from_graph(graph_parents->item);
26632673
if (generation > max_generation)
26642674
max_generation = generation;
26652675

@@ -2671,7 +2681,7 @@ static int verify_one_commit_graph(struct repository *r,
26712681
graph_report(_("commit-graph parent list for commit %s terminates early"),
26722682
oid_to_hex(&cur_oid));
26732683

2674-
if (!commit_graph_generation(graph_commit)) {
2684+
if (!commit_graph_generation_from_graph(graph_commit)) {
26752685
if (generation_zero == GENERATION_NUMBER_EXISTS)
26762686
graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
26772687
oid_to_hex(&cur_oid));

t/t5318-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ test_expect_success 'detect incorrect generation number' '
598598

599599
test_expect_success 'detect incorrect generation number' '
600600
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
601-
"commit-graph generation for commit"
601+
"but zero elsewhere"
602602
'
603603

604604
test_expect_success 'detect incorrect commit date' '

0 commit comments

Comments
 (0)