http-push: avoid fork() by calling merge_bases() directly
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Aug 4, 2006 at 17:50 UTC
61ffbcb988046dfaf8266569f78a31483be026f6
1 file changed
+7
-42
http-push.c
+7
-42
@@ -2182,49 +2182,14 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
2182
2183
static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha1)
2184
{
2185
- int pipe_fd[2];
2186
- pid_t merge_base_pid;
2187
- char line[PATH_MAX + 20];
2188
- unsigned char merge_sha1[20];
2189
- int verified = 0;
2190
-
2191
- if (pipe(pipe_fd) < 0)
2192
- die("Verify merge base: pipe failed");
2193
-
2194
- merge_base_pid = fork();
2195
- if (!merge_base_pid) {
2196
- static const char *args[] = {
2197
- "merge-base",
2198
- "-a",
2199
- NULL,
2200
- NULL,
2201
- NULL
2202
- };
2203
- args[2] = strdup(sha1_to_hex(head_sha1));
2204
- args[3] = sha1_to_hex(branch_sha1);
2205
-
2206
- dup2(pipe_fd[1], 1);
2207
- close(pipe_fd[0]);
2208
- close(pipe_fd[1]);
2209
- execv_git_cmd(args);
2210
- die("merge-base setup failed");
2211
- }
2212
- if (merge_base_pid < 0)
2213
- die("merge-base fork failed");
2214
-
2215
- dup2(pipe_fd[0], 0);
2216
- close(pipe_fd[0]);
2217
- close(pipe_fd[1]);
2218
- while (fgets(line, sizeof(line), stdin) != NULL) {
2219
- if (get_sha1_hex(line, merge_sha1))
2220
- die("expected sha1, got garbage:\n %s", line);
2221
- if (!memcmp(branch_sha1, merge_sha1, 20)) {
2222
- verified = 1;
2223
- break;
2224
- }
2225
- }
2185
+ struct commit *head = lookup_commit(head_sha1);
2186
+ struct commit *branch = lookup_commit(branch_sha1);
2187
+ struct commit_list *merge_bases = get_merge_bases(head, branch, 1);
2188
2227
- return verified;
2189
+ if (merge_bases && !merge_bases->next && merge_bases->item == branch)
2190
+ return 1;
2191
+
2192
+ return 0;
2193
}
2194
2195
static int delete_remote_branch(char *pattern, int force)