Skip to content

Commit dca9003

Browse files
committed
check-ignore: 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 f418afa commit dca9003

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/check-ignore.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
117117
{
118118
struct strbuf buf, nbuf;
119119
char *pathspec[2] = { NULL, NULL };
120-
int line_termination = nul_term_line ? 0 : '\n';
120+
strbuf_getline_fn getline_fn;
121121
int num_ignored = 0;
122122

123+
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
123124
strbuf_init(&buf, 0);
124125
strbuf_init(&nbuf, 0);
125-
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
126-
if (line_termination && buf.buf[0] == '"') {
126+
while (getline_fn(&buf, stdin) != EOF) {
127+
if (!nul_term_line && buf.buf[0] == '"') {
127128
strbuf_reset(&nbuf);
128129
if (unquote_c_style(&nbuf, buf.buf, NULL))
129130
die("line is badly quoted");

0 commit comments

Comments
 (0)