{"thread":{"id":"5493","subject":"[PATCH 2/2] Teach rev-list an option to read revs from the standard input.","startedAt":"2006-09-06T04:47:08Z","lastAt":"2006-09-07T09:07:17Z","messageCount":7,"participants":["Junio C Hamano","Jakub Narebski","Andy Whitcroft"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"26385","messageId":"7v64g1a9f7.fsf@assigned-by-dhcp.cox.net","threadId":"5493","inReplyTo":null,"subject":"[PATCH 2/2] Teach rev-list an option to read revs from the standard input.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-06T04:47:08Z","receivedAt":"2006-09-06T04:47:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When --stdin option is given, in addition to the <rev>s listed\non the command line, the command can read one rev parameter per\nline from the standard input.  The list of revs ends at the\nfirst empty line or EOF.\n\nNote that you still have to give all the flags from the command\nline; only rev arguments (including A..B, A...B, and A^@ notations)\ncan be give from the standard input.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n Documentation/git-rev-list.txt |    6 ++++++\n builtin-rev-list.c             |   25 +++++++++++++++++++++++++\n 2 files changed, 31 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt\nindex 3c4c2fb..28966ad 100644\n--- a/Documentation/git-rev-list.txt\n+++ b/Documentation/git-rev-list.txt\n@@ -17,6 +17,7 @@ SYNOPSIS\n \t     [ \\--remove-empty ]\n \t     [ \\--not ]\n \t     [ \\--all ]\n+\t     [ \\--stdin ]\n \t     [ \\--topo-order ]\n \t     [ \\--parents ]\n \t     [ [\\--objects | \\--objects-edge] [ \\--unpacked ] ]\n@@ -171,6 +172,11 @@ limiting may be applied.\n \tPretend as if all the refs in `$GIT_DIR/refs/` are listed on the\n \tcommand line as '<commit>'.\n \n+--stdin::\n+\n+\tIn addition to the '<commit>' listed on the command\n+\tline, read them from the standard input.\n+\n --merge::\n \n \tAfter a failed merge, show refs that touch files having a\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 8437454..8fe8afb 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -23,6 +23,7 @@ static const char rev_list_usage[] =\n \"    --no-merges\\n\"\n \"    --remove-empty\\n\"\n \"    --all\\n\"\n+\"    --stdin\\n\"\n \"  ordering output:\\n\"\n \"    --topo-order\\n\"\n \"    --date-order\\n\"\n@@ -304,10 +305,28 @@ static void mark_edges_uninteresting(str\n \t}\n }\n \n+static void read_revisions_from_stdin(struct rev_info *revs)\n+{\n+\tchar line[1000];\n+\n+\twhile (fgets(line, sizeof(line), stdin) != NULL) {\n+\t\tint len = strlen(line);\n+\t\tif (line[len - 1] == '\\n')\n+\t\t\tline[--len] = 0;\n+\t\tif (!len)\n+\t\t\tbreak;\n+\t\tif (line[0] == '-')\n+\t\t\tdie(\"options not supported in --stdin mode\");\n+\t\tif (handle_revision_arg(line, revs, 0, 1))\n+\t\t\tdie(\"bad revision '%s'\", line);\n+\t}\n+}\n+\n int cmd_rev_list(int argc, const char **argv, const char *prefix)\n {\n \tstruct commit_list *list;\n \tint i;\n+\tint read_from_stdin = 0;\n \n \tinit_revisions(&revs, prefix);\n \trevs.abbrev = 0;\n@@ -329,6 +348,12 @@ int cmd_rev_list(int argc, const char **\n \t\t\tbisect_list = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--stdin\")) {\n+\t\t\tif (read_from_stdin++)\n+\t\t\t\tdie(\"--stdin given twice?\");\n+\t\t\tread_revisions_from_stdin(&revs);\n+\t\t\tcontinue;\n+\t\t}\n \t\tusage(rev_list_usage);\n \n \t}\n-- \n1.4.2.g980c3\n"},{"id":"26394","messageId":"edm3ce$c4e$1@sea.gmane.org","threadId":"5493","inReplyTo":"7v64g1a9f7.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Teach rev-list an option to read revs from the standard input.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-09-06T09:12:02Z","receivedAt":"2006-09-06T09:12:02Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n\n> Note that you still have to give all the flags from the command\n> line; only rev arguments (including A..B, A...B, and A^@ notations)\n> can be give from the standard input.\n\nDoes this include ^A notation?\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"26401","messageId":"44FEBFD6.10709@shadowen.org","threadId":"5493","inReplyTo":"7v64g1a9f7.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Teach rev-list an option to read revs from the standard input.","fromName":"Andy Whitcroft","fromEmail":"apw@shadowen.org","sentAt":"2006-09-06T12:32:22Z","receivedAt":"2006-09-06T12:32:22Z","isPatch":true,"sender":{"key":"apw@shadowen.org","avatar":"https://gravatar.com/avatar/d3088262854661a913ef35cc40fedcc270142d4461791142bc1ea0b2a4e2e147?d=mp&s=160"},"body":"Ok, I've tested this with an updated version of my patch to make\nsend-pack use this (which I'll send out following this message) and it\nseems to work pretty well.\n\n-apw\n"},{"id":"26402","messageId":"20060906124022.GA30861@shadowen.org","threadId":"5493","inReplyTo":"44FEBFD6.10709@shadowen.org","subject":"[PATCH] send pack switch to using git rev list stdin v2","fromName":"Andy Whitcroft","fromEmail":"apw@shadowen.org","sentAt":"2006-09-06T12:40:22Z","receivedAt":"2006-09-06T12:40:22Z","isPatch":true,"sender":{"key":"apw@shadowen.org","avatar":"https://gravatar.com/avatar/d3088262854661a913ef35cc40fedcc270142d4461791142bc1ea0b2a4e2e147?d=mp&s=160"},"body":"send-pack: switch to using git-rev-list --stdin v2\n\nWhen we are generating packs to update remote repositories we\nwant to supply as much information as possible about the revisions\nthat already exist to rev-list in order optimise the pack as much\nas possible.  We need to pass two revisions for each branch we are\nupdating in the remote repository and one for each additional branch.\nWhere the remote repository has numerous branches we can run out\nof command line space to pass them.\n\nUtilise the git-rev-list --stdin mode to allow unlimited numbers\nof revision constraints.  This allows us to move back to the much\nsimpler unordered revision selection code.\n\nSigned-off-by: Andy Whitcroft <apw@shadowen.org>\n---\ndiff --git a/send-pack.c b/send-pack.c\nindex ac4501d..b403ee9 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -38,9 +38,8 @@ static void exec_pack_objects(void)\n \n static void exec_rev_list(struct ref *refs)\n {\n-\tstruct ref *ref;\n-\tstatic const char *args[1000];\n-\tint i = 0, j;\n+\tstatic const char *args[4];\n+\tint i = 0;\n \n \targs[i++] = \"rev-list\";\t/* 0 */\n \tif (use_thin_pack)\t/* 1 */\n@@ -48,43 +47,29 @@ static void exec_rev_list(struct ref *re\n \telse\n \t\targs[i++] = \"--objects\";\n \n-\t/* First send the ones we care about most */\n-\tfor (ref = refs; ref; ref = ref->next) {\n-\t\tif (900 < i)\n-\t\t\tdie(\"git-rev-list environment overflow\");\n-\t\tif (!is_zero_sha1(ref->new_sha1)) {\n-\t\t\tchar *buf = xmalloc(100);\n-\t\t\targs[i++] = buf;\n-\t\t\tsnprintf(buf, 50, \"%s\", sha1_to_hex(ref->new_sha1));\n-\t\t\tbuf += 50;\n-\t\t\tif (!is_zero_sha1(ref->old_sha1) &&\n-\t\t\t    has_sha1_file(ref->old_sha1)) {\n-\t\t\t\targs[i++] = buf;\n-\t\t\t\tsnprintf(buf, 50, \"^%s\",\n-\t\t\t\t\t sha1_to_hex(ref->old_sha1));\n-\t\t\t}\n-\t\t}\n-\t}\n+\targs[i++] = \"--stdin\";\n \n-\t/* Then a handful of the remainder\n-\t * NEEDSWORK: we would be better off if used the newer ones first.\n-\t */\n-\tfor (ref = refs, j = i + 16;\n-\t     i < 900 && i < j && ref;\n-\t     ref = ref->next) {\n-\t\tif (is_zero_sha1(ref->new_sha1) &&\n-\t\t    !is_zero_sha1(ref->old_sha1) &&\n-\t\t    has_sha1_file(ref->old_sha1)) {\n-\t\t\tchar *buf = xmalloc(42);\n-\t\t\targs[i++] = buf;\n-\t\t\tsnprintf(buf, 42, \"^%s\", sha1_to_hex(ref->old_sha1));\n-\t\t}\n-\t}\n \targs[i] = NULL;\n \texecv_git_cmd(args);\n \tdie(\"git-rev-list exec failed (%s)\", strerror(errno));\n }\n \n+static void builtin_rev_list_generate(struct ref *refs)\n+{\n+\twhile (refs) {\n+\t\tif (!is_zero_sha1(refs->old_sha1) &&\n+\t\t    has_sha1_file(refs->old_sha1)) {\n+\t\t\tprintf(\"^%s\\n\", sha1_to_hex(refs->old_sha1));\n+\t\t}\n+\t\tif (!is_zero_sha1(refs->new_sha1)) {\n+\t\t\tprintf(\"%s\\n\", sha1_to_hex(refs->new_sha1));\n+\t\t}\n+\t\trefs = refs->next;\n+\t}\n+\n+\texit(0);\n+}\n+\n static void rev_list(int fd, struct ref *refs)\n {\n \tint pipe_fd[2];\n@@ -111,13 +96,38 @@ static void rev_list(int fd, struct ref \n \texec_rev_list(refs);\n }\n \n+static void rev_list_generate(int fd, struct ref *refs)\n+{\n+\tint pipe_fd[2];\n+\tpid_t rev_list_generate_pid;\n+\n+\tif (pipe(pipe_fd) < 0)\n+\t\tdie(\"rev-list-generate setup: pipe failed\");\n+\trev_list_generate_pid = fork();\n+\tif (!rev_list_generate_pid) {\n+\t\tdup2(pipe_fd[0], 0);\n+\t\tdup2(fd, 1);\n+\t\tclose(pipe_fd[0]);\n+\t\tclose(pipe_fd[1]);\n+\t\tclose(fd);\n+\t\trev_list(fd, refs);\n+\t\tdie(\"rev-list setup failed\");\n+\t}\n+\tif (rev_list_generate_pid < 0)\n+\t\tdie(\"rev-list-generate fork failed\");\n+\tdup2(pipe_fd[1], 1);\n+\tclose(pipe_fd[0]);\n+\tclose(pipe_fd[1]);\n+\tclose(fd);\n+\tbuiltin_rev_list_generate(refs);\n+}\n static void pack_objects(int fd, struct ref *refs)\n {\n \tpid_t rev_list_pid;\n \n \trev_list_pid = fork();\n \tif (!rev_list_pid) {\n-\t\trev_list(fd, refs);\n+\t\trev_list_generate(fd, refs);\n \t\tdie(\"rev-list setup failed\");\n \t}\n \tif (rev_list_pid < 0)\n"},{"id":"26464","messageId":"7vhczk5wup.fsf@assigned-by-dhcp.cox.net","threadId":"5493","inReplyTo":"44FEBFD6.10709@shadowen.org","subject":"Re: [PATCH 2/2] Teach rev-list an option to read revs from the standard input.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-07T00:44:30Z","receivedAt":"2006-09-07T00:44:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Whitcroft <apw@shadowen.org> writes:\n\n> Ok, I've tested this with an updated version of my patch to make\n> send-pack use this (which I'll send out following this message) and it\n> seems to work pretty well.\n\nEh, I have your earlier one placed on \"pu\" already.  I do not\nmind replacing it with the new one but (1) have you checked what\nis in \"pu\"?  (2) how different is this new one compared to it?\n"},{"id":"26497","messageId":"44FFD436.4020407@shadowen.org","threadId":"5493","inReplyTo":"7vhczk5wup.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Teach rev-list an option to read revs from the standard input.","fromName":"Andy Whitcroft","fromEmail":"apw@shadowen.org","sentAt":"2006-09-07T08:11:34Z","receivedAt":"2006-09-07T08:11:34Z","isPatch":true,"sender":{"key":"apw@shadowen.org","avatar":"https://gravatar.com/avatar/d3088262854661a913ef35cc40fedcc270142d4461791142bc1ea0b2a4e2e147?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Andy Whitcroft <apw@shadowen.org> writes:\n> \n>> Ok, I've tested this with an updated version of my patch to make\n>> send-pack use this (which I'll send out following this message) and it\n>> seems to work pretty well.\n> \n> Eh, I have your earlier one placed on \"pu\" already.  I do not\n> mind replacing it with the new one but (1) have you checked what\n> is in \"pu\"?  (2) how different is this new one compared to it?\n\nThere was white space breakage in the patch which I noticed late in the\ngame, and a problem with the printing lacking newlines.  Your conversion\nto direct writes on the fd fixes the bug part.\n\nWhat you have on 'pu' looks good to me.\n\n/me wasn't aware of the meaning of the pu branch :)\n\n-apw\n"},{"id":"26504","messageId":"7virk02gfu.fsf@assigned-by-dhcp.cox.net","threadId":"5493","inReplyTo":"44FFD436.4020407@shadowen.org","subject":"Re: [PATCH 2/2] Teach rev-list an option to read revs from the standard input.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-07T09:07:17Z","receivedAt":"2006-09-07T09:07:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Whitcroft <apw@shadowen.org> writes:\n\n> There was white space breakage in the patch which I noticed late in the\n> game, and a problem with the printing lacking newlines.  Your conversion\n> to direct writes on the fd fixes the bug part.\n>\n> What you have on 'pu' looks good to me.\n>\n> /me wasn't aware of the meaning of the pu branch :)\n\nThanks.  Will merge into \"next\" with a plan to have it graduate\nto master by next week.\n"}]}