Skip to content

Commit 753c810

Browse files
committed
rerere: update to modern representation of empty strbufs
Back when b4833a2c (rerere: Fix use of an empty strbuf.buf, 2007-09-26) was written, a freshly initialized empty strbuf had NULL in its .buf member, with .len set to 0. The code this patch touches in rerere.c was written to _fix_ the original code that assumed that the .buf member is always pointing at a NUL-terminated string, even for an empty string, which did not hold back then. That changed in b315c5c (strbuf change: be sure ->buf is never ever NULL., 2007-09-27), and it has again become safe to assume that .buf is never NULL, and .buf[0] has '\0' for an empty string (i.e., a strbuf with its .len member set to 0). A funny thing is, this piece of code has been moved around from builtin-rerere.c to rerere.c and also adjusted for updates to the hash function API over the years, but nobody bothered to question if this special casing for an empty strbuf was still necessary: b4833a2 (rerere: Fix use of an empty strbuf.buf, 2007-09-26) 5b2fd95 (rerere: Separate libgit and builtin functions, 2008-07-09) 9126f00 (fix openssl headers conflicting with custom SHA1 implementations, 2008-10-01) c0f16f8 (rerere: factor out handle_conflict function, 2018-08-05) 0d7c419 (rerere: convert to use the_hash_algo, 2018-10-15) 0578f1e (global: adapt callers to use generic hash context helpers, 2025-01-31) Finally get rid of the special casing that was unnecessary for the last 19 years. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f368df4 commit 753c810

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

rerere.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,8 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,
402402
strbuf_addbuf(out, &two);
403403
rerere_strbuf_putconflict(out, '>', marker_size);
404404
if (ctx) {
405-
git_hash_update(ctx, one.buf ?
406-
one.buf : "",
407-
one.len + 1);
408-
git_hash_update(ctx, two.buf ?
409-
two.buf : "",
410-
two.len + 1);
405+
git_hash_update(ctx, one.buf, one.len + 1);
406+
git_hash_update(ctx, two.buf, two.len + 1);
411407
}
412408
break;
413409
} else if (hunk == RR_SIDE_1)

0 commit comments

Comments
 (0)