Git 2.8-rc3
[gitweb.git] / builtin / mktree.c
index b0aab653539c4000044f88bfeb18e55dc55cbbd1..4282b62c595edd987a87eb23ba679079211e0835 100644 (file)
@@ -66,7 +66,7 @@ static const char *mktree_usage[] = {
        NULL
 };
 
-static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing)
+static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing)
 {
        char *ptr, *ntr;
        unsigned mode;
@@ -98,7 +98,7 @@ static void mktree_line(char *buf, size_t len, int line_termination, int allow_m
        *ntr++ = 0; /* now at the beginning of SHA1 */
 
        path = ntr + 41;  /* at the beginning of name */
-       if (line_termination && path[0] == '"') {
+       if (!nul_term_line && path[0] == '"') {
                struct strbuf p_uq = STRBUF_INIT;
                if (unquote_c_style(&p_uq, path, NULL))
                        die("invalid quoting");
@@ -142,23 +142,25 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
 {
        struct strbuf sb = STRBUF_INIT;
        unsigned char sha1[20];
-       int line_termination = '\n';
+       int nul_term_line = 0;
        int allow_missing = 0;
        int is_batch_mode = 0;
        int got_eof = 0;
+       strbuf_getline_fn getline_fn;
 
        const struct option option[] = {
-               OPT_SET_INT('z', NULL, &line_termination, N_("input is NUL terminated"), '\0'),
+               OPT_BOOL('z', NULL, &nul_term_line, N_("input is NUL terminated")),
                OPT_SET_INT( 0 , "missing", &allow_missing, N_("allow missing objects"), 1),
                OPT_SET_INT( 0 , "batch", &is_batch_mode, N_("allow creation of more than one tree"), 1),
                OPT_END()
        };
 
        ac = parse_options(ac, av, prefix, option, mktree_usage, 0);
+       getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
 
        while (!got_eof) {
                while (1) {
-                       if (strbuf_getline(&sb, stdin, line_termination) == EOF) {
+                       if (getline_fn(&sb, stdin) == EOF) {
                                got_eof = 1;
                                break;
                        }
@@ -168,7 +170,7 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
                                        break;
                                die("input format error: (blank line only valid in batch mode)");
                        }
-                       mktree_line(sb.buf, sb.len, line_termination, allow_missing);
+                       mktree_line(sb.buf, sb.len, nul_term_line, allow_missing);
                }
                if (is_batch_mode && got_eof && used < 1) {
                        /*