]> git.ipfire.org Git - thirdparty/git.git/commit
combine-diff: use pointer for parent paths
authorJeff King <peff@peff.net>
Thu, 9 Jan 2025 08:42:29 +0000 (03:42 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Jan 2025 18:31:23 +0000 (10:31 -0800)
commit3a0599788fd38822dcd2f32de538afdd36a478aa
treeed04117d7fd2b2520480d4e70fc57cf00af90db4
parent5173099aae25bedf7a87225891d124569cba7076
combine-diff: use pointer for parent paths

Commit d76ce4f734 (log,diff-tree: add --combined-all-paths option,
2019-02-07) added a "path" field to each combine_diff_parent struct.
It's defined as a strbuf, but this is overkill. We never manipulate the
buffer beyond inserting a single string into it.

And in fact there's a small bug: we zero the parent structs, including
the path strbufs. For the 0th parent, we strbuf_init() the strbuf before
adding to it. But for subsequent parents, we never do the init. This is
technically violating the strbuf API, though the code there is resilient
enough to handle this zero'd state.

This patch switches us to just store an allocated string pointer.
Zeroing it is enough to properly initialize it there (modulo the usual
assumption we make that a NULL pointer is all-zeroes).

And as a bonus, we can just check for a non-NULL value to see if it is
present, rather than repeating the combined_all_paths logic at each
site.

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