commit-graph: add trace2 instrumentation for generation DFS

Count the number of steps taken in compute_reachable_generation_numbers() and expose it via trace2 to make it easier to detect performance regressions. Add a failing test for such a regression, introduced in 199d452758 (commit-graph: return the prepared commit graph from `prepare_commit_graph()`, 2025-09-04), where incremental commit-graph writes do not see existing generation numbers from lower graph layers and fall back to walking the full ancestry. Signed-off-by: Kristofer Karlsson <krka@spotify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kristofer Karlsson committed Jul 9, 2026 at 15:03 UTC 02d62c33be04260445fb201fc65769f421324ed0
2 files changed +29
commit-graph.c
+5
@@ -1653,6 +1653,7 @@ static void compute_reachable_generation_numbers(
1653 {
1654 int i;
1655 struct commit_list *list = NULL;
1656 + intmax_t steps = 0;
1657
1658 for (i = 0; i < info->commits->nr; i++) {
1659 struct commit *c = info->commits->items[i];
@@ -1671,6 +1672,7 @@ static void compute_reachable_generation_numbers(
1672 int all_parents_computed = 1;
1673 timestamp_t max_gen = 0;
1674
1675 + steps++;
1676 for (parent = current->parents; parent; parent = parent->next) {
1677 repo_parse_commit(info->r, parent->item);
1678 gen = info->get_generation(parent->item, info->data);
@@ -1694,6 +1696,9 @@ static void compute_reachable_generation_numbers(
1696 }
1697 }
1698 }
1699 +
1700 + trace2_data_intmax("commit-graph", info->r,
1701 + "generation-dfs-steps", steps);
1702 }
1703
1704 static timestamp_t get_topo_level(struct commit *c, void *data)
t/t5324-split-commit-graph.sh
+24
@@ -718,6 +718,30 @@ test_expect_success 'write generation data chunk when commit-graph chain is repl
718 )
719 '
720
721 +test_expect_failure 'incremental write reads topo levels from all layers' '
722 + git init topo-from-lower &&
723 + (
724 + cd topo-from-lower &&
725 +
726 + for i in $(test_seq 5)
727 + do
728 + test_commit base-$i || return 1
729 + done &&
730 + git commit-graph write --reachable &&
731 +
732 + test_commit extra &&
733 + git commit-graph write --reachable --split=no-merge &&
734 +
735 + git checkout base-3 &&
736 + test_commit new-branch &&
737 +
738 + GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
739 + git commit-graph write --reachable --split=no-merge &&
740 +
741 + test_trace2_data commit-graph generation-dfs-steps 1 <trace.txt
742 + )
743 +'
744 +
745 test_expect_success 'temporary graph layer is discarded upon failure' '
746 git init layer-discard &&
747 (