Skip to content

Commit

Permalink
Use start_comand() in builtin-fetch-pack.c instead of explicit fork/e…
Browse files Browse the repository at this point in the history
…xec.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Johannes Sixt authored and Shawn O. Pearce committed Oct 21, 2007
1 parent d5535ec commit 477822c
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions builtin-fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pack.h"
#include "sideband.h"
#include "fetch-pack.h"
#include "run-command.h"

static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
Expand Down Expand Up @@ -491,18 +492,19 @@ static pid_t setup_sideband(int fd[2], int xd[2])

static int get_pack(int xd[2], char **pack_lockfile)
{
int status;
pid_t pid, side_pid;
pid_t side_pid;
int fd[2];
const char *argv[20];
char keep_arg[256];
char hdr_arg[256];
const char **av;
int do_keep = args.keep_pack;
int keep_pipe[2];
struct child_process cmd;

side_pid = setup_sideband(fd, xd);

memset(&cmd, 0, sizeof(cmd));
cmd.argv = argv;
av = argv;
*hdr_arg = 0;
if (!args.keep_pack && unpack_limit) {
Expand All @@ -519,8 +521,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
}

if (do_keep) {
if (pack_lockfile && pipe(keep_pipe))
die("fetch-pack: pipe setup failure: %s", strerror(errno));
if (pack_lockfile)
cmd.out = -1;
*av++ = "index-pack";
*av++ = "--stdin";
if (!args.quiet && !args.no_progress)
Expand All @@ -544,43 +546,17 @@ static int get_pack(int xd[2], char **pack_lockfile)
*av++ = hdr_arg;
*av++ = NULL;

pid = fork();
if (pid < 0)
cmd.in = fd[0];
cmd.git_cmd = 1;
if (start_command(&cmd))
die("fetch-pack: unable to fork off %s", argv[0]);
if (!pid) {
dup2(fd[0], 0);
if (do_keep && pack_lockfile) {
dup2(keep_pipe[1], 1);
close(keep_pipe[0]);
close(keep_pipe[1]);
}
close(fd[0]);
close(fd[1]);
execv_git_cmd(argv);
die("%s exec failed", argv[0]);
}
close(fd[0]);
close(fd[1]);
if (do_keep && pack_lockfile) {
close(keep_pipe[1]);
*pack_lockfile = index_pack_lockfile(keep_pipe[0]);
close(keep_pipe[0]);
}
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR)
die("waiting for %s: %s", argv[0], strerror(errno));
}
if (WIFEXITED(status)) {
int code = WEXITSTATUS(status);
if (code)
die("%s died with error code %d", argv[0], code);
return 0;
}
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
die("%s died of signal %d", argv[0], sig);
}
die("%s died of unnatural causes %d", argv[0], status);
if (do_keep && pack_lockfile)
*pack_lockfile = index_pack_lockfile(cmd.out);

if (finish_command(&cmd))
die("%s failed", argv[0]);
return 0;
}

static struct ref *do_fetch_pack(int fd[2],
Expand Down

0 comments on commit 477822c

Please sign in to comment.