{"thread":{"id":"5122","subject":"[PATCH] http-push: avoid fork() by calling merge_bases() directly","startedAt":"2006-08-04T15:50:41Z","lastAt":"2006-08-04T15:50:41Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"24709","messageId":"Pine.LNX.4.63.0608041750150.1800@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5122","inReplyTo":null,"subject":"[PATCH] http-push: avoid fork() by calling merge_bases() directly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-08-04T15:50:41Z","receivedAt":"2006-08-04T15:50:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n http-push.c |   49 +++++++------------------------------------------\n 1 files changed, 7 insertions(+), 42 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 4021e7d..dc82657 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -2182,49 +2182,14 @@ static void fetch_symref(const char *pat\n \n static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha1)\n {\n-\tint pipe_fd[2];\n-\tpid_t merge_base_pid;\n-\tchar line[PATH_MAX + 20];\n-\tunsigned char merge_sha1[20];\n-\tint verified = 0;\n-\n-\tif (pipe(pipe_fd) < 0)\n-\t\tdie(\"Verify merge base: pipe failed\");\n-\n-\tmerge_base_pid = fork();\n-\tif (!merge_base_pid) {\n-\t\tstatic const char *args[] = {\n-\t\t\t\"merge-base\",\n-\t\t\t\"-a\",\n-\t\t\tNULL,\n-\t\t\tNULL,\n-\t\t\tNULL\n-\t\t};\n-\t\targs[2] = strdup(sha1_to_hex(head_sha1));\n-\t\targs[3] = sha1_to_hex(branch_sha1);\n-\n-\t\tdup2(pipe_fd[1], 1);\n-\t\tclose(pipe_fd[0]);\n-\t\tclose(pipe_fd[1]);\n-\t\texecv_git_cmd(args);\n-\t\tdie(\"merge-base setup failed\");\n-\t}\n-\tif (merge_base_pid < 0)\n-\t\tdie(\"merge-base fork failed\");\n-\n-\tdup2(pipe_fd[0], 0);\n-\tclose(pipe_fd[0]);\n-\tclose(pipe_fd[1]);\n-\twhile (fgets(line, sizeof(line), stdin) != NULL) {\n-\t\tif (get_sha1_hex(line, merge_sha1))\n-\t\t\tdie(\"expected sha1, got garbage:\\n %s\", line);\n-\t\tif (!memcmp(branch_sha1, merge_sha1, 20)) {\n-\t\t\tverified = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t}\n+\tstruct commit *head = lookup_commit(head_sha1);\n+\tstruct commit *branch = lookup_commit(branch_sha1);\n+\tstruct commit_list *merge_bases = get_merge_bases(head, branch, 1);\n \n-\treturn verified;\n+\tif (merge_bases && !merge_bases->next && merge_bases->item == branch)\n+\t\treturn 1;\n+\n+\treturn 0;\n }\n \n static int delete_remote_branch(char *pattern, int force)\n-- \n1.4.2.rc2.g0bca-dirty\n"}]}