{"thread":{"id":"7225","subject":"[PATCH 7/7] Use run_command within send-pack","startedAt":"2007-03-12T23:00:29Z","lastAt":"2007-03-12T23:00:29Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"36971","messageId":"20070312230029.GG16840@spearce.org","threadId":"7225","inReplyTo":null,"subject":"[PATCH 7/7] Use run_command within send-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-12T23:00:29Z","receivedAt":"2007-03-12T23:00:29Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n send-pack.c |   86 ++++++++++++++++++++--------------------------------------\n 1 files changed, 30 insertions(+), 56 deletions(-)\n\ndiff --git a/send-pack.c b/send-pack.c\nindex 512b660..d5b5162 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -3,7 +3,7 @@\n #include \"tag.h\"\n #include \"refs.h\"\n #include \"pkt-line.h\"\n-#include \"exec_cmd.h\"\n+#include \"run-command.h\"\n \n static const char send_pack_usage[] =\n \"git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\\n\"\n@@ -19,46 +19,35 @@ static int use_thin_pack;\n  */\n static int pack_objects(int fd, struct ref *refs)\n {\n-\tint pipe_fd[2];\n-\tpid_t pid;\n-\n-\tif (pipe(pipe_fd) < 0)\n-\t\treturn error(\"send-pack: pipe failed\");\n-\tpid = fork();\n-\tif (pid < 0)\n-\t\treturn error(\"send-pack: unable to fork git-pack-objects\");\n-\tif (!pid) {\n-\t\t/*\n-\t\t * The child becomes pack-objects --revs; we feed\n-\t\t * the revision parameters to it via its stdin and\n-\t\t * let its stdout go back to the other end.\n-\t\t */\n-\t\tstatic const char *args[] = {\n-\t\t\t\"pack-objects\",\n-\t\t\t\"--all-progress\",\n-\t\t\t\"--revs\",\n-\t\t\t\"--stdout\",\n-\t\t\tNULL,\n-\t\t\tNULL,\n-\t\t};\n-\t\tif (use_thin_pack)\n-\t\t\targs[4] = \"--thin\";\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\texecv_git_cmd(args);\n-\t\tdie(\"git-pack-objects exec failed (%s)\", strerror(errno));\n-\t}\n+\t/*\n+\t * The child becomes pack-objects --revs; we feed\n+\t * the revision parameters to it via its stdin and\n+\t * let its stdout go back to the other end.\n+\t */\n+\tconst char *args[] = {\n+\t\t\"pack-objects\",\n+\t\t\"--all-progress\",\n+\t\t\"--revs\",\n+\t\t\"--stdout\",\n+\t\tNULL,\n+\t\tNULL,\n+\t};\n+\tstruct child_process po;\n+\n+\tif (use_thin_pack)\n+\t\targs[4] = \"--thin\";\n+\tmemset(&po, 0, sizeof(po));\n+\tpo.argv = args;\n+\tpo.in = -1;\n+\tpo.out = fd;\n+\tpo.git_cmd = 1;\n+\tif (start_command(&po))\n+\t\tdie(\"git-pack-objects failed (%s)\", strerror(errno));\n \n \t/*\n \t * We feed the pack-objects we just spawned with revision\n \t * parameters by writing to the pipe.\n \t */\n-\tclose(pipe_fd[0]);\n-\tclose(fd);\n-\n \twhile (refs) {\n \t\tchar buf[42];\n \n@@ -67,38 +56,23 @@ static int pack_objects(int fd, struct ref *refs)\n \t\t\tmemcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);\n \t\t\tbuf[0] = '^';\n \t\t\tbuf[41] = '\\n';\n-\t\t\tif (!write_or_whine(pipe_fd[1], buf, 42,\n+\t\t\tif (!write_or_whine(po.in, buf, 42,\n \t\t\t\t\t\t\"send-pack: send refs\"))\n \t\t\t\tbreak;\n \t\t}\n \t\tif (!is_null_sha1(refs->new_sha1)) {\n \t\t\tmemcpy(buf, sha1_to_hex(refs->new_sha1), 40);\n \t\t\tbuf[40] = '\\n';\n-\t\t\tif (!write_or_whine(pipe_fd[1], buf, 41,\n+\t\t\tif (!write_or_whine(po.in, buf, 41,\n \t\t\t\t\t\t\"send-pack: send refs\"))\n \t\t\t\tbreak;\n \t\t}\n \t\trefs = refs->next;\n \t}\n-\tclose(pipe_fd[1]);\n-\n-\tfor (;;) {\n-\t\tint status, code;\n-\t\tpid_t waiting = waitpid(pid, &status, 0);\n \n-\t\tif (waiting < 0) {\n-\t\t\tif (errno == EINTR)\n-\t\t\t\tcontinue;\n-\t\t\treturn error(\"waitpid failed (%s)\", strerror(errno));\n-\t\t}\n-\t\tif ((waiting != pid) || WIFSIGNALED(status) ||\n-\t\t    !WIFEXITED(status))\n-\t\t\treturn error(\"pack-objects died with strange error\");\n-\t\tcode = WEXITSTATUS(status);\n-\t\tif (code)\n-\t\t\treturn -code;\n-\t\treturn 0;\n-\t}\n+\tif (finish_command(&po))\n+\t\treturn error(\"pack-objects died with strange error\");\n+\treturn 0;\n }\n \n static void unmark_and_free(struct commit_list *list, unsigned int mark)\n-- \n1.5.0.3.985.gcf0b4\n"}]}