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

[PATCH 0/5] cat-file: introduce NUL-terminated output format

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 2, 2023, 13:02 UTC
Message-ID
<cover.1685710884.git.ps@pks.im>
Hi,

with Git v2.38.0, we have introduced the `-z` option to git-cat-file(1) that causes it to read NUL-terminated queries from standard input instead of the newline-terminated queries. This fixes issues when the query themselves contains a newline, like it can happen if e.g. we need to pass a path-scoped revision with embedded newlines.

Unfortunately, this change is causing a new problem. When the object cannot be looked up, then we print an error message that echoes the input:

``` $ echo does-not-exist | git cat-file --batch does-not-exist missing ```

Now if the input itself contains newlines then the output can become inherently unparsable:

```
$ printf "7ce4f05bae8120d9fa258e854a8669f6ea9cb7b1 blob 10\n1234567890\n\n\commit000" |
    git cat-file --batch -z
7ce4f05bae8120d9fa258e854a8669f6ea9cb7b1 blob 10
1234567890

commit missing ```

Ideally, `-z` should have also switched the output to be NUL-terminated. But it didn't, and we cannot change this issue now without doing a backwards incompatible change. Instead, this series introduces a new `-Z` mode that switches both input and output to be NUL-terminated to fix the issue.

Note that Toon has sent a patch series for this issue to address the same issue, see the thread starting at [1]. I've collaborated with him internally at GitLab to arrive at this new patch series which thus effectively supersedes the patches he has sent. The approach is also different: while his patches start quoting the output, the approach chosen by my series only changes the lines to be NUL terminated. This should make it easier to use for scripted purposes compared to having to de-quote the input.

I've put all folks that participated in the original thread into Cc.
Patrick
[1]: <20221209150048.2400648-1-toon@iotcl.com>
Patrick Steinhardt (5):
  t1006: don't strip timestamps from expected results
  t1006: modernize test style to use `test_cmp`
  strbuf: provide CRLF-aware helper to read until a specified delimiter
  cat-file: simplify reading from standard input
  cat-file: Introduce new option to delimit output with NUL characters
 Documentation/git-cat-file.txt |  13 +-
 builtin/cat-file.c             |  85 +++++------
 strbuf.c                       |  11 +-
 strbuf.h                       |  12 ++
 t/t1006-cat-file.sh            | 249 +++++++++++++++++++++------------
 5 files changed, 232 insertions(+), 138 deletions(-)
-- 
2.40.1
Next: Patrick Steinhardt
Message 1 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.