Re: [PATCH 2/2] builtin/cat-file.c: support NUL-delimited input with `-z`
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Jul 25, 2022, 23:39 UTC
- Message-ID
- <Yt8pohJWhhnDrG1c@nand.local>
- In-Reply-To
- <CAPx1GvecmCD1bJDuEks0edu_dwcH92MN4A2Lyj_Tb5W=WtzKig@mail.gmail.com>
On Fri, Jul 22, 2022 at 04:41:54PM -0700, Chris Torek wrote:
Show 10 quoted lines
> > It's tempting to think that we could use `strbuf_getwholeline()` and > > specify either `\n` or `\0` as the terminating character. ... > > How about: > > int (*get)(struct strbuf *, FILE *); > get = opt->nul_terminated ? strbuf_getline_nul : strbuf_getline; > while (get(&buf, stdin) != EOF) > > or similar?
I thought about it, but it seemed cleaner to lift the ternary out to capture the result, too, leading to the if/else-statement I sent in the patch above.
If we wanted to change it, I'd probably suggest a more general-purpose strbuf function that implemented this behavior through a single call. But it sounds like supporting the carriage return character was a mistake from the beginning, which simplifies this direction quite a bit, anyways.
Thanks, Taylor