]> git.ipfire.org Git - thirdparty/git.git/commit
tree-diff: pass whole path string to path_appendnew()
authorJeff King <peff@peff.net>
Thu, 9 Jan 2025 08:49:07 +0000 (03:49 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Jan 2025 20:24:25 +0000 (12:24 -0800)
commit8c53354658462aa6783022def86750ab0b79eb6f
tree24cbcb9d3cfc34310e8678f7a261a3e764ec665f
parenta8dda1af6ab400d45b7524bc46b64e04d14fc912
tree-diff: pass whole path string to path_appendnew()

When diffing trees, we'll have a strbuf "base" containing the
slash-separted names of our parent trees, and a "path" string
representing an entry name from the current tree. We pass these
separately to path_appendnew(), which combines them to form a single
path string in the combine_diff_path struct.

Instead, let's append the path string to our base strbuf ourselves, pass
in the result, and then roll it back with strbuf_setlen(). This lets us
simplify path_appendnew() a bit, enabling further refactoring.

And while it might seem like this causes extra wasted allocations, it
does not in practice. We reuse the same strbuf for each tree entry, so
we only have to allocate it to match the largest name. Plus, in a
recursive diff we'll end up doing this same operation to extend the base
for the next level of recursion. So we're really just incurring a small
memcpy().

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