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>

Junio C Hamano committed Jan 13, 2016 at 16:14 UTC a392f57daf7dc5e72ab3ada7802eddc000fa3081
1 file changed +8 -8
builtin/checkout-index.c
+8 -8
@@ -11,7 +11,7 @@
11 #include "parse-options.h"
12
13 #define CHECKOUT_ALL 4
14 -static int line_termination = '\n';
14 +static int nul_term_line;
15 static int checkout_stage; /* default to checkout stage0 */
16 static int to_tempfile;
17 static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
@@ -35,7 +35,8 @@ static void write_tempfile_record(const char *name, const char *prefix)
35 fputs(topath[checkout_stage], stdout);
36
37 putchar('\t');
38 - write_name_quoted_relative(name, prefix, stdout, line_termination);
38 + write_name_quoted_relative(name, prefix, stdout,
39 + nul_term_line ? '\0' : '\n');
40
41 for (i = 0; i < 4; i++) {
42 topath[i][0] = 0;
@@ -144,10 +145,7 @@ static int option_parse_u(const struct option *opt,
145 static int option_parse_z(const struct option *opt,
146 const char *arg, int unset)
147 {
147 - if (unset)
148 - line_termination = '\n';
149 - else
150 - line_termination = 0;
148 + nul_term_line = !unset;
149 return 0;
150 }
151
@@ -254,13 +252,15 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
252
253 if (read_from_stdin) {
254 struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
255 + strbuf_getline_fn getline_fn;
256
257 if (all)
258 die("git checkout-index: don't mix '--all' and '--stdin'");
259
261 - while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
260 + getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
261 + while (getline_fn(&buf, stdin) != EOF) {
262 char *p;
263 - if (line_termination && buf.buf[0] == '"') {
263 + if (!nul_term_line && buf.buf[0] == '"') {
264 strbuf_reset(&nbuf);
265 if (unquote_c_style(&nbuf, buf.buf, NULL))
266 die("line is badly quoted");