{"thread":{"id":"10873","subject":"[PATCH] Extend cat-file to take multiple arguments or read input from stdin.","startedAt":"2007-11-15T04:22:25Z","lastAt":"2007-11-15T13:33:38Z","messageCount":5,"participants":["Han-Wen Nienhuys","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"59916","messageId":"fhghqv$98a$1@ger.gmane.org","threadId":"10873","inReplyTo":null,"subject":"[PATCH] Extend cat-file to take multiple arguments or read input from stdin.","fromName":"Han-Wen Nienhuys","fromEmail":"hanwen@xs4all.nl","sentAt":"2007-11-15T04:22:25Z","receivedAt":"2007-11-15T04:22:25Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"\nWith this patch, cat-file can be invoked either on an arbitrary number\nof objects, eg.\n\n  git cat-file commit HEAD HEAD^^^\n\nthe object names can also be supplied on stdin, like so\n\n  echo  -e 'HEAD\\nHEAD^^^' | git cat-file commit -\n\nWith this functionality, the entire object database can be dumped with\na limited number of processes: two cat-file processes for discovering size and\ntype, and one cat-file process per type.\n\nSigned-off-by: Han-Wen Nienhuys <hanwen@xs4all.nl>\n---\n builtin-cat-file.c |   63 ++++++++++++++++++++++++++++++++++++++--------------\n 1 files changed, 46 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin-cat-file.c b/builtin-cat-file.c\nindex f132d58..57e2111 100644\n--- a/builtin-cat-file.c\n+++ b/builtin-cat-file.c\n@@ -76,31 +76,17 @@ static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long\n \t\twrite_or_die(1, cp, endp - cp);\n }\n \n-int cmd_cat_file(int argc, const char **argv, const char *prefix)\n+\n+int cat_one_file (const char *obj_name, int opt, const char *exp_type)\n {\n \tunsigned char sha1[20];\n-\tenum object_type type;\n \tvoid *buf;\n \tunsigned long size;\n-\tint opt;\n-\tconst char *exp_type, *obj_name;\n-\n-\tgit_config(git_default_config);\n-\tif (argc != 3)\n-\t\tusage(\"git-cat-file [-t|-s|-e|-p|<type>] <sha1>\");\n-\texp_type = argv[1];\n-\tobj_name = argv[2];\n+\tenum object_type type;\n \n \tif (get_sha1(obj_name, sha1))\n \t\tdie(\"Not a valid object name %s\", obj_name);\n \n-\topt = 0;\n-\tif ( exp_type[0] == '-' ) {\n-\t\topt = exp_type[1];\n-\t\tif ( !opt || exp_type[2] )\n-\t\t\topt = -1; /* Not a single character option */\n-\t}\n-\n \tbuf = NULL;\n \tswitch (opt) {\n \tcase 't':\n@@ -157,3 +143,46 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)\n \twrite_or_die(1, buf, size);\n \treturn 0;\n }\n+\n+int cmd_cat_file(int argc, const char **argv, const char *prefix)\n+{\n+\tint opt = 0;\n+\tconst char *exp_type;\n+\tint all_exists = 1;\n+\tstruct strbuf buf;\n+\n+\tgit_config(git_default_config);\n+\tif (argc < 3)\n+\t\tusage(\"git-cat-file [-t|-s|-e|-p|<type>] <sha1> ... \");\n+\texp_type = argv[1];\n+\n+\tif ( exp_type[0] == '-' ) {\n+\t\topt = exp_type[1];\n+\t\tif ( !opt || exp_type[2] )\n+\t\t\topt = -1; /* Not a single character option */\n+\t}\n+\n+\targv += 2;\n+\tstrbuf_init(&buf, 0);\n+\tdo {\n+\t\tconst char *arg = NULL;\n+\t\tif (argv[0] == NULL)\n+\t\t\tbreak;\n+\t\tif (strcmp(argv[0], \"-\")) {\n+\t\t\targ = *argv;\n+\t\t\targv++;\n+\t\t} else {\n+\t\t\tif (strbuf_getline(&buf, stdin, '\\n') == EOF)\n+\t\t\t\tbreak;\n+\t\t\targ = buf.buf;\n+\t\t}\n+\t\tint not_exists_one = cat_one_file(arg, opt, exp_type);\n+\t\tif (opt == 'e')\n+\t\t\tall_exists = all_exists && !not_exists_one;\n+\t\tif (not_exists_one)\n+\t\t\tbreak;\n+\t} while (1);\n+\tstrbuf_release(&buf);\n+\treturn !all_exists;\n+}\n+\n-- \n1.5.3.4\n\n\n-- \n Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"},{"id":"59917","messageId":"Pine.LNX.4.64.0711150432420.4362@racer.site","threadId":"10873","inReplyTo":"fhghqv$98a$1@ger.gmane.org","subject":"Re: [PATCH] Extend cat-file to take multiple arguments or read input from stdin.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-15T04:34:02Z","receivedAt":"2007-11-15T04:34:02Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 15 Nov 2007, Han-Wen Nienhuys wrote:\n\n> With this functionality, the entire object database can be dumped with a \n> limited number of processes: two cat-file processes for discovering size \n> and type, and one cat-file process per type.\n\nIMHO a better idea would be a counterpart to fast-import, probably called \n\"fast-export\".  You'd need only one process then, and it would not only be \nfaster, but would be usable by even more people, I guess.\n\nCiao,\nDscho\n"},{"id":"59920","messageId":"fhgitt$b8d$1@ger.gmane.org","threadId":"10873","inReplyTo":"Pine.LNX.4.64.0711150432420.4362@racer.site","subject":"Re: [PATCH] Extend cat-file to take multiple arguments or read input from stdin.","fromName":"Han-Wen Nienhuys","fromEmail":"hanwen@xs4all.nl","sentAt":"2007-11-15T04:41:02Z","receivedAt":"2007-11-15T04:41:02Z","isPatch":true,"sender":{"key":"hanwen@google.com","avatar":"https://avatars.githubusercontent.com/u/31547?v=4"},"body":"Johannes Schindelin escreveu:\n> Hi,\n> \n> On Thu, 15 Nov 2007, Han-Wen Nienhuys wrote:\n> \n>> With this functionality, the entire object database can be dumped with a \n>> limited number of processes: two cat-file processes for discovering size \n>> and type, and one cat-file process per type.\n> \n> IMHO a better idea would be a counterpart to fast-import, probably called \n> \"fast-export\".  You'd need only one process then, and it would not only be \n> faster, but would be usable by even more people, I guess.\n\nI know, and that's what I was thinking. However, I was hoping someone else \nwould pick up the hint :-)\n\nI suppose fast-export would just be cat-file with a different name and  \nslightly saner interface.  How about\n\n  type <sha1> <newline>\n  size <sha1> <newline>\n  dump <type> <sha1> <newline>\n\n?\n\n-- \n Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"},{"id":"59926","messageId":"7vd4uc82g2.fsf@gitster.siamese.dyndns.org","threadId":"10873","inReplyTo":"fhgitt$b8d$1@ger.gmane.org","subject":"Re: [PATCH] Extend cat-file to take multiple arguments or read input from stdin.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-15T06:09:33Z","receivedAt":"2007-11-15T06:09:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Han-Wen Nienhuys <hanwen@xs4all.nl> writes:\n\n> I know, and that's what I was thinking. However, I was hoping someone else \n> would pick up the hint :-)\n>\n> I suppose fast-export would just be cat-file with a different name and  \n> slightly saner interface.  How about\n>\n>   type <sha1> <newline>\n>   size <sha1> <newline>\n>   dump <type> <sha1> <newline>\n\nI wondered why that looked so familiar ;-)\n\n\thttp://thread.gmane.org/gmane.comp.version-control.git/62295/focus=62441\n\nAdam Roben CC'ed.\n"},{"id":"59981","messageId":"f329bf540711150533n5aeb454ay1a27e6a8a313b248@mail.gmail.com","threadId":"10873","inReplyTo":"7vd4uc82g2.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Extend cat-file to take multiple arguments or read input from stdin.","fromName":"Han-Wen Nienhuys","fromEmail":"hanwenn@gmail.com","sentAt":"2007-11-15T13:33:38Z","receivedAt":"2007-11-15T13:33:38Z","isPatch":true,"sender":{"key":"hanwenn@gmail.com","avatar":"https://gravatar.com/avatar/058832acb8d613baeb6ce9d21b009d9772424a309b9a521330423daef909a27a?d=mp&s=160"},"body":"2007/11/15, Junio C Hamano <gitster@pobox.com>:\n> > I suppose fast-export would just be cat-file with a different name and\n> > slightly saner interface.  How about\n> >\n> >   type <sha1> <newline>\n> >   size <sha1> <newline>\n> >   dump <type> <sha1> <newline>\n>\n> I wondered why that looked so familiar ;-)\n>\n>         http://thread.gmane.org/gmane.comp.version-control.git/62295/focus=62441\n\nSo,  where has that patch gone?\n\n-- \nHan-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen\n"}]}