{"thread":{"id":"65992","subject":"[PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()","startedAt":"2026-07-14T08:46:05Z","lastAt":"2026-07-14T21:49:43Z","messageCount":3,"participants":["René Scharfe","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"548093","messageId":"d4ffe7fb-f782-4f06-9e3b-f72729d1e225@web.de","threadId":"65992","inReplyTo":null,"subject":"[PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2026-07-14T08:45:59Z","receivedAt":"2026-07-14T08:46:05Z","isPatch":true,"body":"The HAVE_GETDELIM variant of strbuf_getwholeline() calls strbuf_reset()\non the strbuf before handing it over to getdelim(3).  This is\nunnecessary:\n\n  - getdelim(3) doesn't care whether the old buffer contents is\n    NUL-terminated and has no access to ->len,\n  - on success getdelim(3) NUL-terminates the buffer and we set ->len,\n  - on error we either call strbuf_init() or strbuf_reset().\n\nRemove the superfluous preparatory call.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n strbuf.c | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/strbuf.c b/strbuf.c\nindex 764b629927..44955669e8 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -646,8 +646,6 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)\n \tif (feof(fp))\n \t\treturn EOF;\n \n-\tstrbuf_reset(sb);\n-\n \t/* Translate slopbuf to NULL, as we cannot call realloc on it */\n \tif (!sb->alloc)\n \t\tsb->buf = NULL;\n-- \n2.55.0\n"},{"id":"548134","messageId":"xmqq8q7dv82b.fsf@gitster.g","threadId":"65992","inReplyTo":"d4ffe7fb-f782-4f06-9e3b-f72729d1e225@web.de","subject":"Re: [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-14T16:40:12Z","receivedAt":"2026-07-14T16:40:14Z","isPatch":true,"body":"René Scharfe <l.s.r@web.de> writes:\n\n> The HAVE_GETDELIM variant of strbuf_getwholeline() calls strbuf_reset()\n> on the strbuf before handing it over to getdelim(3).  This is\n> unnecessary:\n>\n>   - getdelim(3) doesn't care whether the old buffer contents is\n>     NUL-terminated and has no access to ->len,\n>   - on success getdelim(3) NUL-terminates the buffer and we set ->len,\n>   - on error we either call strbuf_init() or strbuf_reset().\n>\n> Remove the superfluous preparatory call.\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  strbuf.c | 2 --\n>  1 file changed, 2 deletions(-)\n>\n> diff --git a/strbuf.c b/strbuf.c\n> index 764b629927..44955669e8 100644\n> --- a/strbuf.c\n> +++ b/strbuf.c\n> @@ -646,8 +646,6 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)\n>  \tif (feof(fp))\n>  \t\treturn EOF;\n>  \n> -\tstrbuf_reset(sb);\n> -\n\nThis is well explained and makes perfect sense.\n\nThanks.  Will apply and mark for 'next'.\n\n>  \t/* Translate slopbuf to NULL, as we cannot call realloc on it */\n>  \tif (!sb->alloc)\n>  \t\tsb->buf = NULL;\n"},{"id":"548167","messageId":"20260714214941.GB4095533@coredump.intra.peff.net","threadId":"65992","inReplyTo":"d4ffe7fb-f782-4f06-9e3b-f72729d1e225@web.de","subject":"Re: [PATCH] strbuf: avoid redundant reset in strbuf_getwholeline()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2026-07-14T21:49:41Z","receivedAt":"2026-07-14T21:49:43Z","isPatch":true,"body":"On Tue, Jul 14, 2026 at 10:45:59AM +0200, René Scharfe wrote:\n\n> The HAVE_GETDELIM variant of strbuf_getwholeline() calls strbuf_reset()\n> on the strbuf before handing it over to getdelim(3).  This is\n> unnecessary:\n> \n>   - getdelim(3) doesn't care whether the old buffer contents is\n>     NUL-terminated and has no access to ->len,\n>   - on success getdelim(3) NUL-terminates the buffer and we set ->len,\n>   - on error we either call strbuf_init() or strbuf_reset().\n> \n> Remove the superfluous preparatory call.\n\nGood catch. In the original version of strbuf_getwholeline() we were\nmissing that reset on error, which is why this was included. I think\nit became redundant in b70904306f (strbuf_getwholeline: NUL-terminate\ngetdelim buffer on error, 2016-03-05).\n\n-Peff\n"}]}