diff options
author | Pierre Habouzit <madcoder@debian.org> | 2007-09-20 00:42:14 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-20 23:32:18 -0700 |
commit | 7fb1011e610a28518959b1d2d48cea17ecc32048 (patch) | |
tree | 2f07cfdbd6e14dd3e98e1325c7f30c325ea4c785 /builtin-checkout-index.c | |
parent | c76689df6c64a1e987bd779bd71a2042b5131fb9 (diff) | |
download | git-7fb1011e610a28518959b1d2d48cea17ecc32048.tar.gz |
Rework unquote_c_style to work on a strbuf.
If the gain is not obvious in the diffstat, the resulting code is more
readable, _and_ in checkout-index/update-index we now reuse the same buffer
to unquote strings instead of always freeing/mallocing.
This also is more coherent with the next patch that reworks quoting
functions.
The quoting function is also made more efficient scanning for backslashes
and treating portions of strings without a backslash at once.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Diffstat (limited to 'builtin-checkout-index.c')
-rw-r--r-- | builtin-checkout-index.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c index a18ecc4bab..e6264c4bf0 100644 --- a/builtin-checkout-index.c +++ b/builtin-checkout-index.c @@ -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); } |