]> git.ipfire.org Git - thirdparty/git.git/commit
diff: store graph prefix buf in git_graph struct
authorJeff King <peff@peff.net>
Thu, 3 Oct 2024 21:13:17 +0000 (17:13 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Oct 2024 21:22:22 +0000 (14:22 -0700)
commit1164e270b5af80516625b628945ec7365d992055
tree0cf60a382cc20f6bcb1c01416d68ff1f8e9e75ab
parent19752d9c912478b9eef0bd83c2cf6da98974f536
diff: store graph prefix buf in git_graph struct

The diffopt output_prefix interface makes it the callback's job to
handle ownership of the memory it returns, keeping it valid while
callers are using it and then eventually freeing it when we are done
diffing.

In diff_output_prefix_callback() we handle this with a static strbuf,
effectively "leaking" it when the diff is done (but not triggering any
leak detectors because it's technically still reachable). This has not
been a big problem in practice, but it is a problem for libification:
two diffs running in the same process could stomp on each other's prefix
buffers.

Since we only need the strbuf when we are formatting graph padding, we
can give ownership of the strbuf to the git_graph struct, letting us
free it when that struct is no longer in use.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
graph.c