diff options
author | Shawn Pearce <spearce@spearce.org> | 2006-02-28 21:43:33 -0500 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-03-01 01:15:31 -0800 |
commit | 9debe63d10e476b96ff550d550df344a68b240e8 (patch) | |
tree | 2a4366f0983c0df1436def2bb7ab530b39df1aa0 /checkout-index.c | |
parent | 858cbfbabe4ede5f5eba32041eb7448319e53e2a (diff) | |
download | git-9debe63d10e476b96ff550d550df344a68b240e8.tar.gz |
Teach git-checkout-index to read filenames from stdin.
Since git-checkout-index is often used from scripts which
may have a stream of filenames they wish to checkout it is
more convenient to use --stdin than xargs. On platforms
where fork performance is currently sub-optimal and
the length of a command line is limited (*cough* Cygwin
*cough*) running a single git-checkout-index process for
a large number of files beats spawning it multiple times
from xargs.
File names are still accepted on the command line if
--stdin is not supplied. Nothing is performed if no files
are supplied on the command line or by stdin.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'checkout-index.c')
-rw-r--r-- | checkout-index.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/checkout-index.c b/checkout-index.c index 957b4a86b0..f54c606414 100644 --- a/checkout-index.c +++ b/checkout-index.c @@ -22,6 +22,10 @@ * * find . -name '*.h' -print0 | xargs -0 git-checkout-index -f -- * + * or: + * + * find . -name '*.h' -print0 | git-checkout-index -f -z --stdin + * * which will force all existing *.h files to be replaced with * their cached copies. If an empty command line implied "all", * then this would force-refresh everything in the cache, which @@ -33,6 +37,8 @@ * but get used to it in scripting!). */ #include "cache.h" +#include "strbuf.h" +#include "quote.h" static const char *prefix; static int prefix_length; @@ -114,6 +120,8 @@ int main(int argc, char **argv) int i; int newfd = -1; int all = 0; + int read_from_stdin = 0; + int line_termination = '\n'; prefix = setup_git_directory(); git_config(git_default_config); @@ -156,6 +164,17 @@ int main(int argc, char **argv) die("cannot open index.lock file."); continue; } + if (!strcmp(arg, "-z")) { + line_termination = 0; + continue; + } + if (!strcmp(arg, "--stdin")) { + if (i != argc - 1) + die("--stdin must be at the end"); + read_from_stdin = 1; + i++; /* do not consider arg as a file name */ + break; + } if (!strncmp(arg, "--prefix=", 9)) { state.base_dir = arg+9; state.base_dir_len = strlen(state.base_dir); @@ -191,9 +210,31 @@ int main(int argc, char **argv) if (all) die("git-checkout-index: don't mix '--all' and explicit filenames"); + if (read_from_stdin) + die("git-checkout-index: don't mix '--stdin' and explicit filenames"); checkout_file(prefix_path(prefix, prefix_length, arg)); } + if (read_from_stdin) { + struct strbuf buf; + if (all) + die("git-checkout-index: don't mix '--all' and '--stdin'"); + strbuf_init(&buf); + while (1) { + char *path_name; + 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; + checkout_file(prefix_path(prefix, prefix_length, path_name)); + if (path_name != buf.buf) + free(path_name); + } + } + if (all) checkout_all(); |