Re: [PATCH v3 1/2] repo: factor out field printing to dedicated function
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Oct 27, 2025, 16:09 UTC
- Message-ID
- <CAPig+cThZd3urbiPJ6WiToLcdmaj6AqRpj-edEjiD54Lt_r-1Q@mail.gmail.com>
- In-Reply-To
- <xmqqwm4gl7fg.fsf@gitster.g>
On Mon, Oct 27, 2025 at 10:56 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 17 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > 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;
> > }
>
> 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);Thanks, that's even better. Nice and clean and easy to read.
(I didn't have the Git source code at hand, so didn't know that `quote_c_style` could take `FILE *`.)