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

Re: [PATCH 5/5] cat-file: Introduce new option to delimit output with NUL characters

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 6, 2023, 04:52 UTC
Message-ID
<ZH67eBAtFxo95aBL@ncase>
In-Reply-To
<xmqq35355utz.fsf@gitster.g>
On Tue, Jun 06, 2023 at 08:54:16AM +0900, Junio C Hamano wrote:
Show 35 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
> >> Instead, introduce a new option `-Z` that switches to NUL-delimited
> >> input and output. The old `-z` option is marked as deprecated with a
> >> hint that its output may become unparsable.
> >
> > The commit message explains the problem well, I agree adding a new
> > option is the cleanest solution.
> >
> >...
> >>   @@ -246,6 +246,12 @@ respectively print:
> >>   -z::
> >>   	Only meaningful with `--batch`, `--batch-check`, or
> >>   	`--batch-command`; input is NUL-delimited instead of
> >> +	newline-delimited. This option is deprecated in favor of
> >> +	`-Z` as the output can otherwise be ambiguous.
> >> +
> >> +-Z::
> >> +	Only meaningful with `--batch`, `--batch-check`, or
> >> +	`--batch-command`; input and output is NUL-delimited instead of
> >>   	newline-delimited.
> >
> > The documentation changes look good. I wonder if we should put the
> > documentation for "-Z" above "-z" so users see the preferred option
> > first.
> 
> Hmph, I expected "-z" and "-Z" to be orthogonal, the former
> controlling how input records are delimited, the latter controlling
> how output records are delimited, as it usually is a good idea to
> keep things that could be orthogonal to be orthogonal to avoid
> unnecessarily robbing users flexibility.  "-Z is a new way that is
> preferred over -z" was something I did not expect, actually.
> 
> I am not outright rejecting such a deliberately limiting design, but
> I'll have to think about it a bit.

Well, the way I see it we shouldn't have ever decoupled the input and output format, and I consider it a bug that `-z` did as it makes it unusable with arbitrary input. So I'd rather be helping the user of these modes to do the right thing and NUL-delimit both input and output than running into these edge cases later down the road.

That being said I'd be fine to change this series to mean "-Z changes stdout" if you insist. In that case we should be pointing out in our documentation that "You should never use `-z` without `-Z` when you process arbitrary input".

Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 22 in “cat-file: introduce NUL-terminated output format”
  1. 0/5 cat-file: introduce NUL-terminated output formatPatrick Steinhardt, Jun 2, 2023
  2. 1/5 t1006: don't strip timestamps from expected resultsPatrick Steinhardt, Jun 2, 2023
  3. 2/5 t1006: modernize test style to use `test_cmp`Patrick Steinhardt, Jun 2, 2023
  4. 3/5 strbuf: provide CRLF-aware helper to read until a specified delimiterPatrick Steinhardt, Jun 2, 2023
  5. 4/5 cat-file: simplify reading from standard inputPatrick Steinhardt, Jun 2, 2023
  6. 5/5 cat-file: Introduce new option to delimit output with NUL charactersPatrick Steinhardt, Jun 2, 2023
  7. Phillip WoodJun 5, 2023
  8. Junio C HamanoJun 5, 2023
  9. Patrick SteinhardtJun 6, 2023
  10. Junio C HamanoJun 6, 2023
  11. Patrick SteinhardtJun 6, 2023
  12. Junio C HamanoJun 12, 2023
  13. Patrick SteinhardtJun 6, 2023
  14. Junio C HamanoJun 6, 2023
  15. Junio C HamanoJun 3, 2023
  16. 0/5 catfile: introduce NUL-terminated output formatPatrick Steinhardt, Jun 6, 2023
  17. 1/5 t1006: don't strip timestamps from expected resultsPatrick Steinhardt, Jun 6, 2023
  18. 2/5 t1006: modernize test style to use `test_cmp`Patrick Steinhardt, Jun 6, 2023
  19. 3/5 strbuf: provide CRLF-aware helper to read until a specified delimiterPatrick Steinhardt, Jun 6, 2023
  20. 4/5 cat-file: simplify reading from standard inputPatrick Steinhardt, Jun 6, 2023
  21. 5/5 cat-file: introduce option to delimit input and output with NULPatrick Steinhardt, Jun 6, 2023
  22. Junio C HamanoJun 12, 2023

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.