diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-01-13 16:14:48 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-01-15 10:12:58 -0800 |
commit | a392f57daf7dc5e72ab3ada7802eddc000fa3081 (patch) | |
tree | 9b58948885bd756563aef6e615d8020252b2c1d8 /builtin | |
parent | update-index: there are only two possible line terminations (diff) | |
download | tgif-a392f57daf7dc5e72ab3ada7802eddc000fa3081.tar.xz |
checkout-index: 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>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/checkout-index.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 8028c3768f..ed888a5b9e 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -11,7 +11,7 @@ #include "parse-options.h" #define CHECKOUT_ALL 4 -static int line_termination = '\n'; +static int nul_term_line; static int checkout_stage; /* default to checkout stage0 */ static int to_tempfile; static char topath[4][TEMPORARY_FILENAME_LENGTH + 1]; @@ -35,7 +35,8 @@ static void write_tempfile_record(const char *name, const char *prefix) fputs(topath[checkout_stage], stdout); putchar('\t'); - write_name_quoted_relative(name, prefix, stdout, line_termination); + write_name_quoted_relative(name, prefix, stdout, + nul_term_line ? '\0' : '\n'); for (i = 0; i < 4; i++) { topath[i][0] = 0; @@ -144,10 +145,7 @@ static int option_parse_u(const struct option *opt, static int option_parse_z(const struct option *opt, const char *arg, int unset) { - if (unset) - line_termination = '\n'; - else - line_termination = 0; + nul_term_line = !unset; return 0; } @@ -254,13 +252,15 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) if (read_from_stdin) { struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; + strbuf_getline_fn getline_fn; if (all) die("git checkout-index: don't mix '--all' and '--stdin'"); - while (strbuf_getline(&buf, stdin, line_termination) != EOF) { + getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; + while (getline_fn(&buf, stdin) != EOF) { char *p; - if (line_termination && buf.buf[0] == '"') { + if (!nul_term_line && buf.buf[0] == '"') { strbuf_reset(&nbuf); if (unquote_c_style(&nbuf, buf.buf, NULL)) die("line is badly quoted"); |