Re: [PATCH v3 1/2] repo: factor out field printing to dedicated function
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 27, 2025, 14:56 UTC
- Message-ID
- <xmqqwm4gl7fg.fsf@gitster.g>
- In-Reply-To
- <CAPig+cRHKySZ+JPs3G0HowdCEJmE9fP=tCFB=DV-KMPknKTZkQ@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 9 quoted lines
> Or, even better, scope the strbuf just to the `case` branch which needs it:
>
> case FORMAT_KEYVALUE: {
> struct strbuf buf = STRBUF_INIT;
> quote_c_style(value, buf, NULL, 0);
> printf("%s=%s\n", key, buf->buf);
> strbuf_release(&buf);
> break;
> }Yuck.
For something simple like this, quote_c_style() can take "FILE *" instead of struct "strbuf *" so that you do not have to allocate; especially without any need for i18n, perhaps
printf("%s=", key);
quote_c_style(value, NULL, stdout, 0);is sufficient?