Use run_command within send-pack
Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>maint
parent
e8016abf8d
commit
38b1c6626b
54
send-pack.c
54
send-pack.c
|
@ -3,7 +3,7 @@
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "pkt-line.h"
|
#include "pkt-line.h"
|
||||||
#include "exec_cmd.h"
|
#include "run-command.h"
|
||||||
|
|
||||||
static const char send_pack_usage[] =
|
static const char send_pack_usage[] =
|
||||||
"git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
|
"git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
|
||||||
|
@ -19,21 +19,12 @@ static int use_thin_pack;
|
||||||
*/
|
*/
|
||||||
static int pack_objects(int fd, struct ref *refs)
|
static int pack_objects(int fd, struct ref *refs)
|
||||||
{
|
{
|
||||||
int pipe_fd[2];
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
if (pipe(pipe_fd) < 0)
|
|
||||||
return error("send-pack: pipe failed");
|
|
||||||
pid = fork();
|
|
||||||
if (pid < 0)
|
|
||||||
return error("send-pack: unable to fork git-pack-objects");
|
|
||||||
if (!pid) {
|
|
||||||
/*
|
/*
|
||||||
* The child becomes pack-objects --revs; we feed
|
* The child becomes pack-objects --revs; we feed
|
||||||
* the revision parameters to it via its stdin and
|
* the revision parameters to it via its stdin and
|
||||||
* let its stdout go back to the other end.
|
* let its stdout go back to the other end.
|
||||||
*/
|
*/
|
||||||
static const char *args[] = {
|
const char *args[] = {
|
||||||
"pack-objects",
|
"pack-objects",
|
||||||
"--all-progress",
|
"--all-progress",
|
||||||
"--revs",
|
"--revs",
|
||||||
|
@ -41,24 +32,22 @@ static int pack_objects(int fd, struct ref *refs)
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
struct child_process po;
|
||||||
|
|
||||||
if (use_thin_pack)
|
if (use_thin_pack)
|
||||||
args[4] = "--thin";
|
args[4] = "--thin";
|
||||||
dup2(pipe_fd[0], 0);
|
memset(&po, 0, sizeof(po));
|
||||||
dup2(fd, 1);
|
po.argv = args;
|
||||||
close(pipe_fd[0]);
|
po.in = -1;
|
||||||
close(pipe_fd[1]);
|
po.out = fd;
|
||||||
close(fd);
|
po.git_cmd = 1;
|
||||||
execv_git_cmd(args);
|
if (start_command(&po))
|
||||||
die("git-pack-objects exec failed (%s)", strerror(errno));
|
die("git-pack-objects failed (%s)", strerror(errno));
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We feed the pack-objects we just spawned with revision
|
* We feed the pack-objects we just spawned with revision
|
||||||
* parameters by writing to the pipe.
|
* parameters by writing to the pipe.
|
||||||
*/
|
*/
|
||||||
close(pipe_fd[0]);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
while (refs) {
|
while (refs) {
|
||||||
char buf[42];
|
char buf[42];
|
||||||
|
|
||||||
|
@ -67,39 +56,24 @@ static int pack_objects(int fd, struct ref *refs)
|
||||||
memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
|
memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
|
||||||
buf[0] = '^';
|
buf[0] = '^';
|
||||||
buf[41] = '\n';
|
buf[41] = '\n';
|
||||||
if (!write_or_whine(pipe_fd[1], buf, 42,
|
if (!write_or_whine(po.in, buf, 42,
|
||||||
"send-pack: send refs"))
|
"send-pack: send refs"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!is_null_sha1(refs->new_sha1)) {
|
if (!is_null_sha1(refs->new_sha1)) {
|
||||||
memcpy(buf, sha1_to_hex(refs->new_sha1), 40);
|
memcpy(buf, sha1_to_hex(refs->new_sha1), 40);
|
||||||
buf[40] = '\n';
|
buf[40] = '\n';
|
||||||
if (!write_or_whine(pipe_fd[1], buf, 41,
|
if (!write_or_whine(po.in, buf, 41,
|
||||||
"send-pack: send refs"))
|
"send-pack: send refs"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
refs = refs->next;
|
refs = refs->next;
|
||||||
}
|
}
|
||||||
close(pipe_fd[1]);
|
|
||||||
|
|
||||||
for (;;) {
|
if (finish_command(&po))
|
||||||
int status, code;
|
|
||||||
pid_t waiting = waitpid(pid, &status, 0);
|
|
||||||
|
|
||||||
if (waiting < 0) {
|
|
||||||
if (errno == EINTR)
|
|
||||||
continue;
|
|
||||||
return error("waitpid failed (%s)", strerror(errno));
|
|
||||||
}
|
|
||||||
if ((waiting != pid) || WIFSIGNALED(status) ||
|
|
||||||
!WIFEXITED(status))
|
|
||||||
return error("pack-objects died with strange error");
|
return error("pack-objects died with strange error");
|
||||||
code = WEXITSTATUS(status);
|
|
||||||
if (code)
|
|
||||||
return -code;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void unmark_and_free(struct commit_list *list, unsigned int mark)
|
static void unmark_and_free(struct commit_list *list, unsigned int mark)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue