aboutsummaryrefslogtreecommitdiff
path: root/builtin-checkout-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-09-27 00:52:47 -0700
committerJunio C Hamano <gitster@pobox.com>2007-09-27 00:52:47 -0700
commita17ba31b0b75365e1245e494d46abae4afc57480 (patch)
tree41c1d800c92e60d97a8b984dce086bcb3473dcc2 /builtin-checkout-index.c
parent0f729f21348c43a1c80f48faed2e753b1c923e85 (diff)
parent6d69b6f6ac27ab6f71a10da34b813ca25fd2a358 (diff)
downloadgit-a17ba31b0b75365e1245e494d46abae4afc57480.tar.gz
git-a17ba31b0b75365e1245e494d46abae4afc57480.tar.xz
Merge branch 'ph/strbuf' into kh/commit
* ph/strbuf: Clean up stripspace a bit, use strbuf even more. Add strbuf_read_file(). rerere: Fix use of an empty strbuf.buf Small cache_tree_write refactor. Make builtin-rerere use of strbuf nicer and more efficient. Add strbuf_cmp. strbuf_setlen(): do not barf on setting length of an empty buffer to 0 sq_quote_argv and add_to_string rework with strbuf's. Full rework of quote_c_style and write_name_quoted. Rework unquote_c_style to work on a strbuf. strbuf API additions and enhancements. nfv?asprintf are broken without va_copy, workaround them. Fix the expansion pattern of the pseudo-static path buffer.
Diffstat (limited to 'builtin-checkout-index.c')
-rw-r--r--builtin-checkout-index.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c
index a18ecc4ba..70d619da8 100644
--- a/builtin-checkout-index.c
+++ b/builtin-checkout-index.c
@@ -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;
@@ -270,26 +268,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);
}