{"thread":{"id":"3499","subject":"[PATCH] Teach git-checkout-index to read filenames from stdin.","startedAt":"2006-03-01T02:43:33Z","lastAt":"2006-03-02T13:14:24Z","messageCount":5,"participants":["Shawn Pearce","Christopher Faylor","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"16929","messageId":"20060301024333.GB21186@spearce.org","threadId":"3499","inReplyTo":null,"subject":"[PATCH] Teach git-checkout-index to read filenames from stdin.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-03-01T02:43:33Z","receivedAt":"2006-03-01T02:43:33Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Since git-checkout-index is often used from scripts which\nmay have a stream of filenames they wish to checkout it is\nmore convenient to use --stdin than xargs.  On platforms\nwhere fork performance is currently sub-optimal and\nthe length of a command line is limited (*cough* Cygwin\n*cough*) running a single git-checkout-index process for\na large number of files beats spawning it multiple times\nfrom xargs.\n\nFile names are still accepted on the command line if\n--stdin is not supplied.  Nothing is performed if no files\nare supplied on the command line or by stdin.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n\n---\n I wonder if Linus will stop using\n\n   find ... -print0 | xargs -0 git-checkout-index --\n\n with this option available.\n\n Eh, probably not as xargs requires less typing than -z --stdin.\n\n Documentation/git-checkout-index.txt |   20 +++++++++++++++--\n checkout-index.c                     |   41 ++++++++++++++++++++++++++++++++++\n 2 files changed, 59 insertions(+), 2 deletions(-)\n\nbase 84434f9549d56e522a2eb4de370100f0a6e5e041\nlast df23c1119d0af1fbac6b8afd296113e155d9a878\ndiff --git a/Documentation/git-checkout-index.txt b/Documentation/git-checkout-index.txt\nindex 2a1e526..b0b6588 100644\n--- a/Documentation/git-checkout-index.txt\n+++ b/Documentation/git-checkout-index.txt\n@@ -10,7 +10,9 @@ SYNOPSIS\n --------\n [verse]\n 'git-checkout-index' [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]\n-\t\t   [--stage=<number>] [--] <file>...\n+\t\t   [--stage=<number>]\n+\t\t   [-z] [--stdin]\n+\t\t   [--] [<file>]\\*\n \n DESCRIPTION\n -----------\n@@ -45,6 +47,15 @@ OPTIONS\n \tInstead of checking out unmerged entries, copy out the\n \tfiles from named stage.  <number> must be between 1 and 3.\n \n+--stdin::\n+\tInstead of taking list of paths from the command line,\n+\tread list of paths from the standard input.  Paths are\n+\tseparated by LF (i.e. one path per line) by default.\n+\n+-z::\n+\tOnly meaningful with `--stdin`; paths are separated with\n+\tNUL character instead of LF.\n+\n --::\n \tDo not interpret any more arguments as options.\n \n@@ -64,7 +75,12 @@ $ find . -name '*.h' -print0 | xargs -0 \n \n which will force all existing `*.h` files to be replaced with their\n cached copies. If an empty command line implied \"all\", then this would\n-force-refresh everything in the index, which was not the point.\n+force-refresh everything in the index, which was not the point.  But\n+since git-checkout-index accepts --stdin it would be faster to use:\n+\n+----------------\n+$ find . -name '*.h' -print0 | git-checkout-index -f -z --stdin\n+----------------\n \n The `--` is just a good idea when you know the rest will be filenames;\n it will prevent problems with a filename of, for example,  `-a`.\ndiff --git a/checkout-index.c b/checkout-index.c\nindex 957b4a8..f54c606 100644\n--- a/checkout-index.c\n+++ b/checkout-index.c\n@@ -22,6 +22,10 @@\n  *\n  *\tfind . -name '*.h' -print0 | xargs -0 git-checkout-index -f --\n  *\n+ * or:\n+ *\n+ *\tfind . -name '*.h' -print0 | git-checkout-index -f -z --stdin\n+ *\n  * which will force all existing *.h files to be replaced with\n  * their cached copies. If an empty command line implied \"all\",\n  * then this would force-refresh everything in the cache, which\n@@ -33,6 +37,8 @@\n  * but get used to it in scripting!).\n  */\n #include \"cache.h\"\n+#include \"strbuf.h\"\n+#include \"quote.h\"\n \n static const char *prefix;\n static int prefix_length;\n@@ -114,6 +120,8 @@ int main(int argc, char **argv)\n \tint i;\n \tint newfd = -1;\n \tint all = 0;\n+\tint read_from_stdin = 0;\n+\tint line_termination = '\\n';\n \n \tprefix = setup_git_directory();\n \tgit_config(git_default_config);\n@@ -156,6 +164,17 @@ int main(int argc, char **argv)\n \t\t\t\tdie(\"cannot open index.lock file.\");\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"-z\")) {\n+\t\t\tline_termination = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"--stdin\")) {\n+\t\t\tif (i != argc - 1)\n+\t\t\t\tdie(\"--stdin must be at the end\");\n+\t\t\tread_from_stdin = 1;\n+\t\t\ti++; /* do not consider arg as a file name */\n+\t\t\tbreak;\n+\t\t}\n \t\tif (!strncmp(arg, \"--prefix=\", 9)) {\n \t\t\tstate.base_dir = arg+9;\n \t\t\tstate.base_dir_len = strlen(state.base_dir);\n@@ -191,9 +210,31 @@ int main(int argc, char **argv)\n \n \t\tif (all)\n \t\t\tdie(\"git-checkout-index: don't mix '--all' and explicit filenames\");\n+\t\tif (read_from_stdin)\n+\t\t\tdie(\"git-checkout-index: don't mix '--stdin' and explicit filenames\");\n \t\tcheckout_file(prefix_path(prefix, prefix_length, arg));\n \t}\n \n+\tif (read_from_stdin) {\n+\t\tstruct strbuf buf;\n+\t\tif (all)\n+\t\t\tdie(\"git-checkout-index: don't mix '--all' and '--stdin'\");\n+\t\tstrbuf_init(&buf);\n+\t\twhile (1) {\n+\t\t\tchar *path_name;\n+\t\t\tread_line(&buf, stdin, line_termination);\n+\t\t\tif (buf.eof)\n+\t\t\t\tbreak;\n+\t\t\tif (line_termination && buf.buf[0] == '\"')\n+\t\t\t\tpath_name = unquote_c_style(buf.buf, NULL);\n+\t\t\telse\n+\t\t\t\tpath_name = buf.buf;\n+\t\t\tcheckout_file(prefix_path(prefix, prefix_length, path_name));\n+\t\t\tif (path_name != buf.buf)\n+\t\t\t\tfree(path_name);\n+\t\t}\n+\t}\n+\n \tif (all)\n \t\tcheckout_all();\n \n-- \n1.2.3.gdf23c\n"},{"id":"16949","messageId":"20060301155053.GC1010@trixie.casa.cgf.cx","threadId":"3499","inReplyTo":"20060301024333.GB21186@spearce.org","subject":"Re: [PATCH] Teach git-checkout-index to read filenames from stdin.","fromName":"Christopher Faylor","fromEmail":"me@cgf.cx","sentAt":"2006-03-01T15:50:53Z","receivedAt":"2006-03-01T15:50:53Z","isPatch":true,"sender":{"key":"me@cgf.cx","avatar":null},"body":"On Tue, Feb 28, 2006 at 09:43:33PM -0500, Shawn Pearce wrote:\n>Since git-checkout-index is often used from scripts which may have a\n>stream of filenames they wish to checkout it is more convenient to use\n>--stdin than xargs.  On platforms where fork performance is currently\n>sub-optimal and the length of a command line is limited (*cough* Cygwin\n>*cough*)\n\nAFAIK, the length of the command line for cygwin apps is very large --\nif you're using recent versions of Cygwin.  I believe that it is longer\nthan the linux default.  We bypass the Windows mechanism for setting the\ncommand line when a cygwin program starts a cygwin program.\n\nFor native Windows programs, the command line length is ~32K but I don't\nthink that git uses any native Windows programs, does it?\n\ncgf\n"},{"id":"16965","messageId":"20060301175606.GA4190@spearce.org","threadId":"3499","inReplyTo":"20060301155053.GC1010@trixie.casa.cgf.cx","subject":"Re: [PATCH] Teach git-checkout-index to read filenames from stdin.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-03-01T17:56:06Z","receivedAt":"2006-03-01T17:56:06Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Christopher Faylor <me@cgf.cx> wrote:\n> AFAIK, the length of the command line for cygwin apps is very large --\n> if you're using recent versions of Cygwin.  I believe that it is longer\n> than the linux default.  We bypass the Windows mechanism for setting the\n> command line when a cygwin program starts a cygwin program.\n> \n> For native Windows programs, the command line length is ~32K but I don't\n> think that git uses any native Windows programs, does it?\n\nNo.  Currently GIT is entirely dependent on Cygwin.  So GIT\nwouldn't bump into the ~32K limit due to the cygwin-cygwin feature\nyou mention.  But thanks for the information.  I had thought I had\nread somewhere in the Cygwin documentation that the command line\nlength was rather limited (even under cygwin-cygwin calls).  Maybe\nI was just seeing things.  :-)\n\nBut even if we can get a long set of args into git-checkout-index its\nprobably still better to stream them as you can get both programs\nworking at the same time (rather than waiting for xargs to build\nthe argument buffer) and you are saving yourself at least one fork\nas you don't need to start xargs just to feed git-checkout-index.\nEven on Linux where fork is cheap, that's still soemething saved.\n\n-- \nShawn.\n"},{"id":"17030","messageId":"81b0412b0603020512i429481f7i4a0dbe4599dbb5a6@mail.gmail.com","threadId":"3499","inReplyTo":"20060301155053.GC1010@trixie.casa.cgf.cx","subject":"Re: [PATCH] Teach git-checkout-index to read filenames from stdin.","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-03-02T13:12:06Z","receivedAt":"2006-03-02T13:12:06Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 3/1/06, Christopher Faylor <me@cgf.cx> wrote:\n>\n> For native Windows programs, the command line length is ~32K but I don't\n> think that git uses any native Windows programs, does it?\n>\n\nYes, ActiveState Perl is as native as it gets.\n"},{"id":"17031","messageId":"81b0412b0603020514i2e4531efxafc38d95656ce9de@mail.gmail.com","threadId":"3499","inReplyTo":"81b0412b0603020512i429481f7i4a0dbe4599dbb5a6@mail.gmail.com","subject":"Re: [PATCH] Teach git-checkout-index to read filenames from stdin.","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-03-02T13:14:24Z","receivedAt":"2006-03-02T13:14:24Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 3/2/06, Alex Riesen <raa.lkml@gmail.com> wrote:\n> On 3/1/06, Christopher Faylor <me@cgf.cx> wrote:\n> >\n> > For native Windows programs, the command line length is ~32K but I don't\n> > think that git uses any native Windows programs, does it?\n> >\n>\n> Yes, ActiveState Perl is as native as it gets.\n>\n\nIt does use native windows programs, I mean.\nAt least for me it does.\n"}]}