diff options
| author | Patrick Steinhardt <ps@pks.im> | 2023-06-06 07:19:37 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-06-12 13:23:24 -0700 |
| commit | af35e56b0f83f872a8d82d8293fae87c80b491ef (patch) | |
| tree | 504a29c18dde8f8c85332d7f7b7c3820d4d0cb57 /commit.c | |
| parent | t1006: modernize test style to use `test_cmp` (diff) | |
| download | git-af35e56b0f83f872a8d82d8293fae87c80b491ef.tar.gz git-af35e56b0f83f872a8d82d8293fae87c80b491ef.zip | |
strbuf: provide CRLF-aware helper to read until a specified delimiter
Many of our commands support reading input that is separated either via
newlines or via NUL characters. Furthermore, in order to be a better
cross platform citizen, these commands typically know to strip the CRLF
sequence so that we also support reading newline-separated inputs on
e.g. the Windows platform. This results in the following kind of awkward
pattern:
```
struct strbuf input = STRBUF_INIT;
while (1) {
int ret;
if (nul_terminated)
ret = strbuf_getline_nul(&input, stdin);
else
ret = strbuf_getline(&input, stdin);
if (ret)
break;
...
}
```
Introduce a new CRLF-aware helper function that can read up to a user
specified delimiter. If the delimiter is `\n` the function knows to also
strip CRLF, otherwise it will only strip the specified delimiter. This
results in the following, much more readable code pattern:
```
struct strbuf input = STRBUF_INIT;
while (strbuf_getdelim_strip_crlf(&input, stdin, delim) != EOF) {
...
}
```
The new function will be used in a subsequent commit.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
0 files changed, 0 insertions, 0 deletions
