]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/gc.c
maintenance: test commit-graph auto condition
authorDerrick Stolee <dstolee@microsoft.com>
Thu, 8 Oct 2020 00:50:39 +0000 (00:50 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Oct 2020 17:24:40 +0000 (10:24 -0700)
commit8f801804befa12a9c4ddff91275cf03612f1895d
tree4db4768d650ac8d0a86f1a3244ed4ccfd99575a4
parent25914c4fdeefd99b06e134496dfb9bbb58a5c417
maintenance: test commit-graph auto condition

The auto condition for the commit-graph maintenance task walks refs
looking for commits that are not in the commit-graph file. This was
added in 4ddc79b2 (maintenance: add auto condition for commit-graph
task, 2020-09-17) but was left untested.

The initial goal of this change was to demonstrate the feature works
properly by adding tests. However, there was an off-by-one error that
caused the basic tests around maintenance.commit-graph.auto=1 to fail
when it should work.

The subtlety is that if a ref tip is not in the commit-graph, then we
were not adding that to the total count. In the test, we see that we
have only added one commit since our last commit-graph write, so the
auto condition would say there is nothing to do.

The fix is simple: add the check for the commit-graph position to see
that the tip is not in the commit-graph file before starting our walk.
Since this happens before adding to the DFS stack, we do not need to
clear our (currently empty) commit list.

This does add some extra complexity for the test, because we also want
to verify that the walk along the parents actually does some work. This
means we need to add at least two commits in a row without writing the
commit-graph. However, we also need to make sure no additional refs are
pointing to the middle of this list or else the for_each_ref() in
should_write_commit_graph() might visit these commits as tips instead of
doing a DFS walk. Hence, the last two commits are added with "git
commit" instead of "test_commit".

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
t/t7900-maintenance.sh