]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-checkout-index.c
Rework unquote_c_style to work on a strbuf.
[thirdparty/git.git] / builtin-checkout-index.c
index a18ecc4bab7541477144402d4d680277d95c4e9a..e6264c4bf0ef537ea7ea2127133d1fad5a33b7d6 100644 (file)
@@ -270,26 +270,27 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
        }
 
        if (read_from_stdin) {
-               struct strbuf buf;
+               struct strbuf buf, nbuf;
+
                if (all)
                        die("git-checkout-index: don't mix '--all' and '--stdin'");
+
                strbuf_init(&buf, 0);
-               while (1) {
-                       char *path_name;
+               strbuf_init(&nbuf, 0);
+               while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
                        const char *p;
-                       if (strbuf_getline(&buf, stdin, line_termination) == EOF)
-                               break;
-                       if (line_termination && buf.buf[0] == '"')
-                               path_name = unquote_c_style(buf.buf, NULL);
-                       else
-                               path_name = buf.buf;
-                       p = prefix_path(prefix, prefix_length, path_name);
+                       if (line_termination && buf.buf[0] == '"') {
+                               strbuf_reset(&nbuf);
+                               if (unquote_c_style(&nbuf, buf.buf, NULL))
+                                       die("line is badly quoted");
+                               strbuf_swap(&buf, &nbuf);
+                       }
+                       p = prefix_path(prefix, prefix_length, buf.buf);
                        checkout_file(p, prefix_length);
-                       if (p < path_name || p > path_name + strlen(path_name))
+                       if (p < buf.buf || p > buf.buf + buf.len)
                                free((char *)p);
-                       if (path_name != buf.buf)
-                               free(path_name);
                }
+               strbuf_release(&nbuf);
                strbuf_release(&buf);
        }