@matheusbsbs / matheus-bagliano / commits / 477822c35d
Fork 0

Use start_comand() in builtin-fetch-pack.c instead of explicit fork/exec.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Johannes Sixt committed Oct 19, 2007 at 21:47 UTC 477822c35dbf3d5f16fce1425638e761e60ede3d
1 file changed +16 -40
builtin-fetch-pack.c
+16 -40
@@ -7,6 +7,7 @@
7 #include "pack.h"
8 #include "sideband.h"
9 #include "fetch-pack.h"
10 +#include "run-command.h"
11
12 static int transfer_unpack_limit = -1;
13 static int fetch_unpack_limit = -1;
@@ -491,18 +492,19 @@ static pid_t setup_sideband(int fd[2], int xd[2])
492
493 static int get_pack(int xd[2], char **pack_lockfile)
494 {
494 - int status;
495 - pid_t pid, side_pid;
495 + pid_t side_pid;
496 int fd[2];
497 const char *argv[20];
498 char keep_arg[256];
499 char hdr_arg[256];
500 const char **av;
501 int do_keep = args.keep_pack;
502 - int keep_pipe[2];
502 + struct child_process cmd;
503
504 side_pid = setup_sideband(fd, xd);
505
506 + memset(&cmd, 0, sizeof(cmd));
507 + cmd.argv = argv;
508 av = argv;
509 *hdr_arg = 0;
510 if (!args.keep_pack && unpack_limit) {
@@ -519,8 +521,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
521 }
522
523 if (do_keep) {
522 - if (pack_lockfile && pipe(keep_pipe))
523 - die("fetch-pack: pipe setup failure: %s", strerror(errno));
524 + if (pack_lockfile)
525 + cmd.out = -1;
526 *av++ = "index-pack";
527 *av++ = "--stdin";
528 if (!args.quiet && !args.no_progress)
@@ -544,43 +546,17 @@ static int get_pack(int xd[2], char **pack_lockfile)
546 *av++ = hdr_arg;
547 *av++ = NULL;
548
547 - pid = fork();
548 - if (pid < 0)
549 + cmd.in = fd[0];
550 + cmd.git_cmd = 1;
551 + if (start_command(&cmd))
552 die("fetch-pack: unable to fork off %s", argv[0]);
550 - if (!pid) {
551 - dup2(fd[0], 0);
552 - if (do_keep && pack_lockfile) {
553 - dup2(keep_pipe[1], 1);
554 - close(keep_pipe[0]);
555 - close(keep_pipe[1]);
556 - }
557 - close(fd[0]);
558 - close(fd[1]);
559 - execv_git_cmd(argv);
560 - die("%s exec failed", argv[0]);
561 - }
562 - close(fd[0]);
553 close(fd[1]);
564 - if (do_keep && pack_lockfile) {
565 - close(keep_pipe[1]);
566 - *pack_lockfile = index_pack_lockfile(keep_pipe[0]);
567 - close(keep_pipe[0]);
568 - }
569 - while (waitpid(pid, &status, 0) < 0) {
570 - if (errno != EINTR)
571 - die("waiting for %s: %s", argv[0], strerror(errno));
572 - }
573 - if (WIFEXITED(status)) {
574 - int code = WEXITSTATUS(status);
575 - if (code)
576 - die("%s died with error code %d", argv[0], code);
577 - return 0;
578 - }
579 - if (WIFSIGNALED(status)) {
580 - int sig = WTERMSIG(status);
581 - die("%s died of signal %d", argv[0], sig);
582 - }
583 - die("%s died of unnatural causes %d", argv[0], status);
554 + if (do_keep && pack_lockfile)
555 + *pack_lockfile = index_pack_lockfile(cmd.out);
556 +
557 + if (finish_command(&cmd))
558 + die("%s failed", argv[0]);
559 + return 0;
560 }
561
562 static struct ref *do_fetch_pack(int fd[2],