git/builtin
Patrick Steinhardt f79e18849b cat-file: add option '-Z' that delimits input and output with NUL
In db9d67f2e9 (builtin/cat-file.c: support NUL-delimited input with
`-z`, 2022-07-22), we have introduced a new mode to read the input via
NUL-delimited records instead of newline-delimited records. This allows
the user to query for revisions that have newlines in their path
component. While unusual, such queries are perfectly valid and thus it
is clear that we should be able to support them properly.

Unfortunately, the commit only changed the input to be NUL-delimited,
but didn't change the output at the same time. While this is fine for
queries that are processed successfully, it is less so for queries that
aren't. In the case of missing commits for example the result can become
entirely unparsable:

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

commit missing
```

This is of course a crafted query that is intentionally gaming the
deficiency, but more benign queries that contain newlines would have
similar problems.

Ideally, we should have also changed the output to be NUL-delimited when
`-z` is specified to avoid this problem. As the input is NUL-delimited,
it is clear that the output in this case cannot ever contain NUL
characters by itself. Furthermore, Git does not allow NUL characters in
revisions anyway, further stressing the point that using NUL-delimited
output is safe. The only exception is of course the object data itself,
but as git-cat-file(1) prints the size of the object data clients should
read until that specified size has been consumed.

But even though `-z` has only been introduced a few releases ago in Git
v2.38.0, changing the output format retroactively to also NUL-delimit
output would be a backwards incompatible change. And while one could
make the argument that the output is inherently broken already, we need
to assume that there are existing users out there that use it just fine
given that revisions containing newlines are quite exotic.

Instead, introduce a new option `-Z` that switches to NUL-delimited
input and output. While this new option could arguably only switch the
output format to be NUL-delimited, the consequence would be that users
have to always specify both `-z` and `-Z` when the input may contain
newlines. On the other hand, if the user knows that there never will be
newlines in the input, they don't have to use either of those options.
There is thus no usecase that would warrant treating input and output
format separately, which is why we instead opt to "do the right thing"
and have `-Z` mean to NUL-terminate both formats.

The old `-z` option is marked as deprecated with a hint that its output
may become unparsable. It is thus hidden both from the synopsis as well
as the command's help output.

Co-authored-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-06-12 13:23:46 -07:00
..
add.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
am.c pager.h: move declarations for pager.c functions from cache.h 2023-04-11 08:52:10 -07:00
annotate.c strvec: rename struct fields 2020-07-30 19:18:06 -07:00
apply.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
archive.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
bisect.c copy.h: move declarations for copy.c functions from cache.h 2023-04-24 12:47:31 -07:00
blame.c pager.h: move declarations for pager.c functions from cache.h 2023-04-11 08:52:10 -07:00
branch.c Merge branch 'rj/branch-unborn-in-other-worktrees' 2023-05-15 13:59:03 -07:00
bugreport.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
bundle.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
cat-file.c cat-file: add option '-Z' that delimits input and output with NUL 2023-06-12 13:23:46 -07:00
check-attr.c Merge branch 'jc/attr-source-tree' 2023-05-17 10:11:41 -07:00
check-ignore.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
check-mailmap.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
check-ref-format.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
checkout--worker.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
checkout-index.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
checkout.c symlinks.h: move declarations for symlinks.c functions from cache.h 2023-04-24 12:47:31 -07:00
clean.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
clone.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
column.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
commit-graph.c treewide: be explicit about dependence on trace.h & trace2.h 2023-04-11 08:52:08 -07:00
commit-tree.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
commit.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
config.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
count-objects.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
credential-cache--daemon.c Merge branch 'mh/credential-oauth-refresh-token' 2023-05-10 10:23:29 -07:00
credential-cache.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
credential-store.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
credential.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
describe.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
diagnose.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
diff-files.c diff-files: integrate with sparse index 2023-05-09 14:26:36 -07:00
diff-index.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
diff-tree.c commit.h: reduce unnecessary includes 2023-04-24 12:47:33 -07:00
diff.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
difftool.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
fast-export.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
fast-import.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
fetch-pack.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
fetch.c Merge branch 'ps/fetch-output-format' 2023-05-15 13:59:07 -07:00
fmt-merge-msg.c wrapper.h: move declarations for wrapper.c functions from cache.h 2023-03-21 10:56:53 -07:00
for-each-ref.c Merge branch 'ow/ref-filter-omit-empty' 2023-04-21 15:35:05 -07:00
for-each-repo.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
fsck.c fsck: use local repository 2023-05-02 08:48:23 -07:00
fsmonitor--daemon.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
gc.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
get-tar-commit-id.c Merge branch 'rs/get-tar-commit-id-use-defined-const' 2023-04-20 14:33:36 -07:00
grep.c pager.h: move declarations for pager.c functions from cache.h 2023-04-11 08:52:10 -07:00
hash-object.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
help.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
hook.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
index-pack.c Merge branch 'tb/pack-revindex-on-disk' 2023-04-27 16:00:59 -07:00
init-db.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
interpret-trailers.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
log.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
ls-files.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
ls-remote.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
ls-tree.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
mailinfo.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
mailsplit.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
merge-base.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
merge-file.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
merge-index.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
merge-ours.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
merge-recursive.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
merge-tree.c Merge branch 'ds/merge-tree-use-config' 2023-05-15 13:59:06 -07:00
merge.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
mktag.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
mktree.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
multi-pack-index.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
mv.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
name-rev.c name-rev: make --stdin hidden 2023-05-06 14:32:20 -07:00
notes.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
pack-objects.c attr: teach "--attr-source=<tree>" global option to "git" 2023-05-06 14:34:09 -07:00
pack-redundant.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
pack-refs.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
patch-id.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
prune-packed.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
prune.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
pull.c Merge branch 'ob/messages-capitalize-exception' 2023-05-09 16:45:46 -07:00
push.c Merge branch 'tl/push-branches-is-an-alias-for-all' 2023-05-15 13:59:05 -07:00
range-diff.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
read-tree.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
rebase.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
receive-pack.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
reflog.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
remote-ext.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
remote-fd.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
remote.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
repack.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
replace.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
rerere.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
reset.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
rev-list.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
rev-parse.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
revert.c Merge branch 'pw/rebase-cleanup-merge-strategy-option-handling' 2023-04-17 18:05:13 -07:00
rm.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
send-pack.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
shortlog.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
show-branch.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
show-index.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
show-ref.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
sparse-checkout.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
stash.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
stripspace.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
submodule--helper.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
symbolic-ref.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
tag.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
unpack-file.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
unpack-objects.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
update-index.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
update-ref.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
update-server-info.c server-info.h: move declarations for server-info.c functions from cache.h 2023-04-24 12:47:31 -07:00
upload-archive.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
upload-pack.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
var.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
verify-commit.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
verify-pack.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
verify-tag.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
worktree.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
write-tree.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00