{"thread":{"id":"7223","subject":"[PATCH 6/7] Use run_command within receive-pack to invoke index-pack","startedAt":"2007-03-12T23:00:26Z","lastAt":"2007-03-12T23:00:26Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"36969","messageId":"20070312230026.GF16840@spearce.org","threadId":"7223","inReplyTo":null,"subject":"[PATCH 6/7] Use run_command within receive-pack to invoke index-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-12T23:00:26Z","receivedAt":"2007-03-12T23:00:26Z","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 receive-pack.c |   35 ++++++++++-------------------------\n 1 files changed, 10 insertions(+), 25 deletions(-)\n\ndiff --git a/receive-pack.c b/receive-pack.c\nindex 7cf5878..26aa26b 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -382,10 +382,10 @@ static const char *unpack(void)\n \t\t}\n \t} else {\n \t\tconst char *keeper[6];\n-\t\tint fd[2], s, len, status;\n-\t\tpid_t pid;\n+\t\tint s, len, status;\n \t\tchar keep_arg[256];\n \t\tchar packname[46];\n+\t\tstruct child_process ip;\n \n \t\ts = sprintf(keep_arg, \"--keep=receive-pack %i on \", getpid());\n \t\tif (gethostname(keep_arg + s, sizeof(keep_arg) - s))\n@@ -397,20 +397,12 @@ static const char *unpack(void)\n \t\tkeeper[3] = hdr_arg;\n \t\tkeeper[4] = keep_arg;\n \t\tkeeper[5] = NULL;\n-\n-\t\tif (pipe(fd) < 0)\n-\t\t\treturn \"index-pack pipe failed\";\n-\t\tpid = fork();\n-\t\tif (pid < 0)\n+\t\tmemset(&ip, 0, sizeof(ip));\n+\t\tip.argv = keeper;\n+\t\tip.out = -1;\n+\t\tip.git_cmd = 1;\n+\t\tif (start_command(&ip))\n \t\t\treturn \"index-pack fork failed\";\n-\t\tif (!pid) {\n-\t\t\tdup2(fd[1], 1);\n-\t\t\tclose(fd[1]);\n-\t\t\tclose(fd[0]);\n-\t\t\texecv_git_cmd(keeper);\n-\t\t\tdie(\"execv of index-pack failed\");\n-\t\t}\n-\t\tclose(fd[1]);\n \n \t\t/*\n \t\t * The first thing we expects from index-pack's output\n@@ -420,9 +412,8 @@ static const char *unpack(void)\n \t\t * later on.  If we don't get that then tough luck with it.\n \t\t */\n \t\tfor (len = 0;\n-\t\t     len < 46 && (s = xread(fd[0], packname+len, 46-len)) > 0;\n+\t\t     len < 46 && (s = xread(ip.out, packname+len, 46-len)) > 0;\n \t\t     len += s);\n-\t\tclose(fd[0]);\n \t\tif (len == 46 && packname[45] == '\\n' &&\n \t\t    memcmp(packname, \"keep\\t\", 5) == 0) {\n \t\t\tchar path[PATH_MAX];\n@@ -432,14 +423,8 @@ static const char *unpack(void)\n \t\t\tpack_lockfile = xstrdup(path);\n \t\t}\n \n-\t\t/* Then wrap our index-pack process. */\n-\t\twhile (waitpid(pid, &status, 0) < 0)\n-\t\t\tif (errno != EINTR)\n-\t\t\t\treturn \"waitpid failed\";\n-\t\tif (WIFEXITED(status)) {\n-\t\t\tint code = WEXITSTATUS(status);\n-\t\t\tif (code)\n-\t\t\t\treturn \"index-pack exited with error code\";\n+\t\tstatus = finish_command(&ip);\n+\t\tif (!status) {\n \t\t\treprepare_packed_git();\n \t\t\treturn NULL;\n \t\t}\n-- \n1.5.0.3.985.gcf0b4\n"}]}