Teach git-checkout-index to read filenames from stdin.
PATCH 1/1 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.
---
I wonder if Linus will stop using
find ... -print0 | xargs -0 git-checkout-index --
with this option available.
Eh, probably not as xargs requires less typing than -z --stdin.
Documentation/git-checkout-index.txt | 20 +++++++++++++++-- checkout-index.c | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-)
base 84434f9549d56e522a2eb4de370100f0a6e5e041
last df23c1119d0af1fbac6b8afd296113e155d9a878
Documentation/git-checkout-index.txt +18 -2
@@ -10,7 +10,9 @@ SYNOPSIS -------- [verse] 'git-checkout-index' [-u] [-q] [-a] [-f] [-n] [--prefix=<string>] - [--stage=<number>] [--] <file>... + [--stage=<number>] + [-z] [--stdin] + [--] [<file>]\* DESCRIPTION -----------
@@ -45,6 +47,15 @@ OPTIONS Instead of checking out unmerged entries, copy out the files from named stage. <number> must be between 1 and 3. +--stdin:: + Instead of taking list of paths from the command line, + read list of paths from the standard input. Paths are + separated by LF (i.e. one path per line) by default. + +-z:: + Only meaningful with `--stdin`; paths are separated with + NUL character instead of LF. + --:: Do not interpret any more arguments as options.
@@ -64,7 +75,12 @@ $ find . -name '*.h' -print0 | xargs -0 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 index, which was not the point. +force-refresh everything in the index, which was not the point. But +since git-checkout-index accepts --stdin it would be faster to use: + +---------------- +$ find . -name '*.h' -print0 | git-checkout-index -f -z --stdin +---------------- The `--` is just a good idea when you know the rest will be filenames; it will prevent problems with a filename of, for example, `-a`.
checkout-index.c +41 -0
74 lines not on this page · raw message
Signature · 1 line
1.2.3.gdf23c
Quoted 5 lines · Shawn Pearce
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*)
AFAIK, the length of the command line for cygwin apps is very large -- if you're using recent versions of Cygwin. I believe that it is longer than the linux default. We bypass the Windows mechanism for setting the command line when a cygwin program starts a cygwin program.
For native Windows programs, the command line length is ~32K but I don't think that git uses any native Windows programs, does it?
cgf
Quoted 7 lines · Christopher Faylor
AFAIK, the length of the command line for cygwin apps is very large -- if you're using recent versions of Cygwin. I believe that it is longer than the linux default. We bypass the Windows mechanism for setting the command line when a cygwin program starts a cygwin program.
For native Windows programs, the command line length is ~32K but I don't think that git uses any native Windows programs, does it?
No. Currently GIT is entirely dependent on Cygwin. So GIT wouldn't bump into the ~32K limit due to the cygwin-cygwin feature you mention. But thanks for the information. I had thought I had read somewhere in the Cygwin documentation that the command line length was rather limited (even under cygwin-cygwin calls). Maybe I was just seeing things. :-)
But even if we can get a long set of args into git-checkout-index its probably still better to stream them as you can get both programs working at the same time (rather than waiting for xargs to build the argument buffer) and you are saving yourself at least one fork as you don't need to start xargs just to feed git-checkout-index. Even on Linux where fork is cheap, that's still soemething saved.
Signature · 1 line
Shawn.
Quoted 4 lines · Christopher Faylor
For native Windows programs, the command line length is ~32K but I don't think that git uses any native Windows programs, does it?
Yes, ActiveState Perl is as native as it gets.
Quoted 8 lines · Alex Riesen
Quoted 4 lines · Christopher Faylor
For native Windows programs, the command line length is ~32K but I don't think that git uses any native Windows programs, does it?
Yes, ActiveState Perl is as native as it gets.
It does use native windows programs, I mean.
At least for me it does.