@matheusbsbs / matheus-bagliano / commits / e8016abf8d
Fork 0

Use run_command within receive-pack to invoke index-pack

Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Mar 12, 2007 at 19:00 UTC e8016abf8d6716296829d12324ea02e34c757256
1 file changed +10 -25
receive-pack.c
+10 -25
@@ -382,10 +382,10 @@ static const char *unpack(void)
382 }
383 } else {
384 const char *keeper[6];
385 - int fd[2], s, len, status;
386 - pid_t pid;
385 + int s, len, status;
386 char keep_arg[256];
387 char packname[46];
388 + struct child_process ip;
389
390 s = sprintf(keep_arg, "--keep=receive-pack %i on ", getpid());
391 if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
@@ -397,20 +397,12 @@ static const char *unpack(void)
397 keeper[3] = hdr_arg;
398 keeper[4] = keep_arg;
399 keeper[5] = NULL;
400 -
401 - if (pipe(fd) < 0)
402 - return "index-pack pipe failed";
403 - pid = fork();
404 - if (pid < 0)
400 + memset(&ip, 0, sizeof(ip));
401 + ip.argv = keeper;
402 + ip.out = -1;
403 + ip.git_cmd = 1;
404 + if (start_command(&ip))
405 return "index-pack fork failed";
406 - if (!pid) {
407 - dup2(fd[1], 1);
408 - close(fd[1]);
409 - close(fd[0]);
410 - execv_git_cmd(keeper);
411 - die("execv of index-pack failed");
412 - }
413 - close(fd[1]);
406
407 /*
408 * The first thing we expects from index-pack's output
@@ -420,9 +412,8 @@ static const char *unpack(void)
412 * later on. If we don't get that then tough luck with it.
413 */
414 for (len = 0;
423 - len < 46 && (s = xread(fd[0], packname+len, 46-len)) > 0;
415 + len < 46 && (s = xread(ip.out, packname+len, 46-len)) > 0;
416 len += s);
425 - close(fd[0]);
417 if (len == 46 && packname[45] == '\n' &&
418 memcmp(packname, "keep\t", 5) == 0) {
419 char path[PATH_MAX];
@@ -432,14 +423,8 @@ static const char *unpack(void)
423 pack_lockfile = xstrdup(path);
424 }
425
435 - /* Then wrap our index-pack process. */
436 - while (waitpid(pid, &status, 0) < 0)
437 - if (errno != EINTR)
438 - return "waitpid failed";
439 - if (WIFEXITED(status)) {
440 - int code = WEXITSTATUS(status);
441 - if (code)
442 - return "index-pack exited with error code";
426 + status = finish_command(&ip);
427 + if (!status) {
428 reprepare_packed_git();
429 return NULL;
430 }