Skip to content

Commit f418afa

Browse files
committed
check-attr: there are only two possible line terminations
The program by default reads LF terminated lines, with an option to use NUL terminated records. Instead of pretending that there can be other useful values for line_termination, use a boolean variable, nul_term_line, to tell if NUL terminated records are used, and switch between strbuf_getline_{lf,nul} based on it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4df87b commit f418afa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/check-attr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ static void check_attr_stdin_paths(const char *prefix, int cnt,
7373
struct git_attr_check *check)
7474
{
7575
struct strbuf buf, nbuf;
76-
int line_termination = nul_term_line ? 0 : '\n';
76+
strbuf_getline_fn getline_fn;
7777

78+
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
7879
strbuf_init(&buf, 0);
7980
strbuf_init(&nbuf, 0);
80-
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
81-
if (line_termination && buf.buf[0] == '"') {
81+
while (getline_fn(&buf, stdin) != EOF) {
82+
if (!nul_term_line && buf.buf[0] == '"') {
8283
strbuf_reset(&nbuf);
8384
if (unquote_c_style(&nbuf, buf.buf, NULL))
8485
die("line is badly quoted");

0 commit comments

Comments
 (0)