summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-01-14 13:26:20 -0800
committerJunio C Hamano <gitster@pobox.com>2016-01-15 10:12:58 -0800
commitf418afa98afb15afb8f93fe1ab11d5b83266d17d (patch)
tree62ac08b21b5b6f9134d1ca84d9c0eb290d060bca
parentb4df87b8ca3b9cf8e648058af4870cfc7305b082 (diff)
downloadgit-f418afa98afb15afb8f93fe1ab11d5b83266d17d.tar.gz
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 <gitster@pobox.com>
-rw-r--r--builtin/check-attr.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 265c9ba022..087325ef69 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -73,12 +73,13 @@ static void check_attr_stdin_paths(const char *prefix, int cnt,
struct git_attr_check *check)
{
struct strbuf buf, nbuf;
- int line_termination = nul_term_line ? 0 : '\n';
+ strbuf_getline_fn getline_fn;
+ getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
strbuf_init(&buf, 0);
strbuf_init(&nbuf, 0);
- while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
- if (line_termination && buf.buf[0] == '"') {
+ while (getline_fn(&buf, stdin) != EOF) {
+ if (!nul_term_line && buf.buf[0] == '"') {
strbuf_reset(&nbuf);
if (unquote_c_style(&nbuf, buf.buf, NULL))
die("line is badly quoted");