Skip to content

Commit a392f57

Browse files
committed
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 <[email protected]>
1 parent 7e07ed8 commit a392f57

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/checkout-index.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "parse-options.h"
1212

1313
#define CHECKOUT_ALL 4
14-
static int line_termination = '\n';
14+
static int nul_term_line;
1515
static int checkout_stage; /* default to checkout stage0 */
1616
static int to_tempfile;
1717
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
@@ -35,7 +35,8 @@ static void write_tempfile_record(const char *name, const char *prefix)
3535
fputs(topath[checkout_stage], stdout);
3636

3737
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');
3940

4041
for (i = 0; i < 4; i++) {
4142
topath[i][0] = 0;
@@ -144,10 +145,7 @@ static int option_parse_u(const struct option *opt,
144145
static int option_parse_z(const struct option *opt,
145146
const char *arg, int unset)
146147
{
147-
if (unset)
148-
line_termination = '\n';
149-
else
150-
line_termination = 0;
148+
nul_term_line = !unset;
151149
return 0;
152150
}
153151

@@ -254,13 +252,15 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
254252

255253
if (read_from_stdin) {
256254
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
255+
strbuf_getline_fn getline_fn;
257256

258257
if (all)
259258
die("git checkout-index: don't mix '--all' and '--stdin'");
260259

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) {
262262
char *p;
263-
if (line_termination && buf.buf[0] == '"') {
263+
if (!nul_term_line && buf.buf[0] == '"') {
264264
strbuf_reset(&nbuf);
265265
if (unquote_c_style(&nbuf, buf.buf, NULL))
266266
die("line is badly quoted");

0 commit comments

Comments
 (0)