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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>

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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux