git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Previous: Chris TorekNext: Junio C Hamano
Message 5 of 15 in “cat-file: support NUL-delimited input with `-z`”
  1. 0/2 cat-file: support NUL-delimited input with `-z`Taylor Blau, Jul 22, 2022
  2. 1/2 t1006: extract --batch-command inputs to variablesTaylor Blau, Jul 22, 2022
  3. 2/2 builtin/cat-file.c: support NUL-delimited input with `-z`Taylor Blau, Jul 22, 2022
  4. Chris TorekJul 22, 2022
  5. Taylor BlauJul 25, 2022
  6. Junio C HamanoJul 23, 2022
  7. Taylor BlauJul 25, 2022
  8. Junio C HamanoJul 27, 2022
  9. Ævar Arnfjörð BjarmasonJul 23, 2022
  10. Junio C HamanoJul 23, 2022
  11. Taylor BlauJul 25, 2022
  12. Junio C HamanoJul 27, 2022
  13. Phillip WoodJul 31, 2022
  14. Ævar Arnfjörð BjarmasonAug 11, 2022
  15. Junio C HamanoJul 23, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.