]> Kevux Git Server - rit/commit
commit-graph.c: remove temporary graph layers on exit
authorTaylor Blau <me@ttaylorr.com>
Thu, 6 Jun 2024 22:19:25 +0000 (18:19 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 15:40:48 +0000 (08:40 -0700)
commitc195ecda7703098f28c160cc63306ca0e1488236
tree13d3cff3475e65231bc11d886f378fc8ef978a05
parent7b0defb3915eaa0bd118f0996e8c00b4eb2dc1ca
commit-graph.c: remove temporary graph layers on exit

Since the introduction of split commit graph layers in 92b1ea66b9a
(Merge branch 'ds/commit-graph-incremental', 2019-07-19), the function
write_commit_graph_file() has done the following when writing an
incremental commit-graph layer:

  - used a lock_file to control access to the commit-graph-chain file

  - used an auxiliary file (whose descriptor was stored in 'fd') to
    write the new commit-graph layer itself

Using a lock_file to control access to the commit-graph-chain is
sensible, since only one writer may modify it at a time. Likewise, when
the commit-graph machinery is writing out a single layer, the lock_file
structure is used to modify the commit-graph itself. This is also
sensible, since the non-incremental commit-graph may also have at most
one writer.

However, using an auxiliary temporary file without using the tempfile.h
API means that writes that fail after the temporary graph layer has been
created will leave around a file in

    $GIT_DIR/objects/info/commit-graphs/tmp_graph_XXXXXX

The commit-graph-chain file and non-incremental commit-graph do not
suffer from this problem as the lockfile.h API uses the tempfile.h API
transparently, so processes that died before moving those finals into
their final location cleaned up after themselves.

Ensure that the temporary file used to write incremental commit-graphs
is also managed with the tempfile.h API, to ensure that we do not ever
leave tmp_graph_XXXXXX files laying around.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
t/t5324-split-commit-graph.sh