diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-08-24 23:54:56 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-08-25 22:01:09 +0300 |
commit | 3ea54d054a2af24c9127502a010385777df6afe1 (patch) | |
tree | ee35c9a021f8afd1819199c7065783cc0de25648 /rerere.c | |
parent | ca30ba266c0a8b2cf110de00062847e108718923 (diff) |
rerere: modernize use of empty strbuf
Back when the code in the handle_conflict() helper function that
hashes the contents stored in the strbuf "one" and "two", including
its terminating NUL, was written, a freshly initialized strbuf had
NULL in its .buf member, so it was an error to say
update(one.buf, one.len + 1)
which was corrected by b4833a2c (rerere: Fix use of an empty
strbuf.buf, 2007-09-26).
But soon after that, b315c5c0 (strbuf change: be sure ->buf is never
ever NULL., 2007-09-27) introduced strbuf_slopbuf mechanism that
ensures that .buf member of a strbuf is *never* NULL. A freshly
initialized and empty strbuf uses a static piece of memory that has
NUL in it, with its .len member set to 0, so we can always safely
use from offset 0 of .buf[] array for (one.len + 1) bytes.
Simplify the code by essentially reverting the b4833a2c, whose fix
is no longer necessary in the modern world order.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'rerere.c')
-rw-r--r-- | rerere.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -390,12 +390,8 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, strbuf_addbuf(out, &two); rerere_strbuf_putconflict(out, '>', marker_size); if (ctx) { - the_hash_algo->update_fn(ctx, one.buf ? - one.buf : "", - one.len + 1); - the_hash_algo->update_fn(ctx, two.buf ? - two.buf : "", - two.len + 1); + the_hash_algo->update_fn(ctx, one.buf, one.len + 1); + the_hash_algo->update_fn(ctx, two.buf, two.len + 1); } break; } else if (hunk == RR_SIDE_1) |