]> git.ipfire.org Git - thirdparty/git.git/commit
cat-file: simplify reading from standard input
authorPatrick Steinhardt <ps@pks.im>
Tue, 6 Jun 2023 05:19:41 +0000 (07:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jun 2023 20:23:24 +0000 (13:23 -0700)
commit3217f52a499d5264d98065374a62deb15717b727
treeaa8bef5e96dde90e7b48ab244a7fde9d2ee34080
parentaf35e56b0f83f872a8d82d8293fae87c80b491ef
cat-file: simplify reading from standard input

The batch modes of git-cat-file(1) read queries from stantard input that
are either newline- or NUL-delimited. This code was introduced via
db9d67f2e9 (builtin/cat-file.c: support NUL-delimited input with `-z`,
2022-07-22), which notes that:

"""
The refactoring here is slightly unfortunate, since we turn loops like:

     while (strbuf_getline(&buf, stdin) != EOF)

 into:

     while (1) {
         int ret;
         if (opt->nul_terminated)
             ret = strbuf_getline_nul(&input, stdin);
         else
             ret = strbuf_getline(&input, stdin);

         if (ret == EOF)
             break;
     }
"""

The commit proposed introducing a helper function that is easier to use,
which is just what we have done in the preceding commit. Refactor the
code to use this new helper to simplify the loop.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/cat-file.c