]> git.ipfire.org Git - thirdparty/git.git/commit
wt-status: avoid strbuf_split*()
authorJunio C Hamano <gitster@pobox.com>
Thu, 31 Jul 2025 22:54:23 +0000 (15:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Aug 2025 05:37:06 +0000 (22:37 -0700)
commit2efe707054d184565f081f9d882940381b2645ca
tree91f666fe33c6467f64b524658968b9ac3904716e
parent5e901d16904b354a0de399484db09b7b67132151
wt-status: avoid strbuf_split*()

strbuf is a very good data structure to work with string data
without having to worry about running past the end of the string,
but strbuf_split() is a wrong API and an array of strbuf that the
function produces is a wrong thing to use in general.  You do not
edit these N strings split out of a single strbuf simultaneously.
Often it is much better off to split a string into string_list and
work with the resulting strings.

wt-status.c:abbrev_oid_in_line() takes one line of rebase todo list
(like "pick e813a0200a7121b97fec535f0d0b460b0a33356c title"), and
for instructions that has an object name as the second token on the
line, replace the object name with its unique abbreviation.  After
splitting these tokens out of a single line, no simultaneous edit on
any of these pieces of string that takes advantage of strbuf API
takes place.  The final string is composed with strbuf API, but
these split pieces are merely used as pieces of strings and there is
no need for them to be stored in individual strbuf.

Instead, split the line into a string_list, and compose the final
string using these pieces.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
wt-status.c