X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-checkout-index.c;h=eb1fc9aa6f7f61a817a198feaf94ca9d983eb14b;hb=328a4750b155df9de29cac007c74e2412d244620;hp=8460f97b6637127d78b58caf2e29d25f3ad0b5a0;hpb=8299886619b8dab99773b5810f50c63a50b2d611;p=git.git diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c index 8460f97b6..eb1fc9aa6 100644 --- a/builtin-checkout-index.c +++ b/builtin-checkout-index.c @@ -36,8 +36,8 @@ * of "-a" causing problems (not possible in the above example, * but get used to it in scripting!). */ +#include "builtin.h" #include "cache.h" -#include "strbuf.h" #include "quote.h" #include "cache-tree.h" @@ -66,9 +66,7 @@ static void write_tempfile_record(const char *name, int prefix_length) fputs(topath[checkout_stage], stdout); putchar('\t'); - write_name_quoted("", 0, name + prefix_length, - line_termination, stdout); - putchar(line_termination); + write_name_quoted(name + prefix_length, stdout, line_termination); for (i = 0; i < 4; i++) { topath[i][0] = 0; @@ -168,7 +166,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) int read_from_stdin = 0; int prefix_length; - git_config(git_default_config); + git_config(git_default_config, NULL); state.base_dir = ""; prefix_length = prefix ? strlen(prefix) : 0; @@ -248,8 +246,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) * want to update cache. */ if (state.refresh_cache) { - close(newfd); newfd = -1; rollback_lock_file(&lock_file); + newfd = -1; } state.refresh_cache = 0; } @@ -270,28 +268,28 @@ 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); - while (1) { - char *path_name; - const char *p; - read_line(&buf, stdin, line_termination); - if (buf.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); + strbuf_init(&buf, 0); + strbuf_init(&nbuf, 0); + while (strbuf_getline(&buf, stdin, line_termination) != EOF) { + const char *p; + 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); } if (all) @@ -299,7 +297,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) if (0 <= newfd && (write_cache(newfd, active_cache, active_nr) || - close(newfd) || commit_locked_index(&lock_file))) + commit_locked_index(&lock_file))) die("Unable to write new index file"); return 0; }