Merge branch 'ps/cat-file-null-output' into next

"git cat-file --batch" and friends learned "-Z" that uses NUL
delimiter for both input and output.

* ps/cat-file-null-output:
  cat-file: add option '-Z' that delimits input and output with NUL
  cat-file: simplify reading from standard input
  strbuf: provide CRLF-aware helper to read until a specified delimiter
  t1006: modernize test style to use `test_cmp`
  t1006: don't strip timestamps from expected results
This commit is contained in:
Junio C Hamano
2023-06-15 14:04:55 -07:00
5 changed files with 232 additions and 138 deletions

View File

@ -722,11 +722,11 @@ static int strbuf_getdelim(struct strbuf *sb, FILE *fp, int term)
return 0;
}
int strbuf_getline(struct strbuf *sb, FILE *fp)
int strbuf_getdelim_strip_crlf(struct strbuf *sb, FILE *fp, int term)
{
if (strbuf_getwholeline(sb, fp, '\n'))
if (strbuf_getwholeline(sb, fp, term))
return EOF;
if (sb->buf[sb->len - 1] == '\n') {
if (term == '\n' && sb->buf[sb->len - 1] == '\n') {
strbuf_setlen(sb, sb->len - 1);
if (sb->len && sb->buf[sb->len - 1] == '\r')
strbuf_setlen(sb, sb->len - 1);
@ -734,6 +734,11 @@ int strbuf_getline(struct strbuf *sb, FILE *fp)
return 0;
}
int strbuf_getline(struct strbuf *sb, FILE *fp)
{
return strbuf_getdelim_strip_crlf(sb, fp, '\n');
}
int strbuf_getline_lf(struct strbuf *sb, FILE *fp)
{
return strbuf_getdelim(sb, fp, '\n');