housekeeping: Fix rewriting of commit-graphs without generation data
With eab4c475 (housekeeping: Replace commit-graph chain when missing
generation data, 2022-12-13) we have introduced logic to rewrite the
commit-graph in case it is missing generation data. One thing we missed
though is that we essentially have the same logic in two different
places: once via WriteCommitGraphConfigForRepository()
, which is used
for the legacy fine-grained repository housekeeping RPCs. And once via
new the optimization strategy in ShouldWriteCommitGraph()
. And while
we have adjusted the former, we didn't adjust the latter, and as a
result we don't properly rewrite in OptimizeRepository()
.
Deduplicate the logic by introducing a new commitGraphNeedsRewrite()
function that is shared between both implementations so that we now also
correctly rewrite the commit-graphs in OptimizeRepository()
.
Fixes !5211 (merged).
Part of #4704 (closed).