]> git.ipfire.org Git - thirdparty/git.git/commit
commit-graph: introduce `commit_graph_generation_from_graph()`
authorTaylor Blau <me@ttaylorr.com>
Mon, 21 Aug 2023 21:34:34 +0000 (17:34 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Aug 2023 23:07:33 +0000 (16:07 -0700)
commit868c991155b3392e0b1a6aab8daab89bb93400f4
treef7dea8e1d87355c4abbe9b9829e283ce0e0bf0d7
parenta82fb66fed250e16d3010c75404503bea3f0ab61
commit-graph: introduce `commit_graph_generation_from_graph()`

In 2ee11f7261 (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 2ee11f7261, 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 2ee11f7261 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 2ee11f7261, 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 <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
t/t5318-commit-graph.sh