@matheusbsbs / matheus-bagliano / commits / 38b1c6626b
Fork 0

Use run_command within send-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 38b1c6626b4690a745e23be9aa9ada98c1a55f41
1 file changed +30 -56
send-pack.c
+30 -56
@@ -3,7 +3,7 @@
3 #include "tag.h"
4 #include "refs.h"
5 #include "pkt-line.h"
6 -#include "exec_cmd.h"
6 +#include "run-command.h"
7
8 static const char send_pack_usage[] =
9 "git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
@@ -19,46 +19,35 @@ static int use_thin_pack;
19 */
20 static int pack_objects(int fd, struct ref *refs)
21 {
22 - int pipe_fd[2];
23 - pid_t pid;
24 -
25 - if (pipe(pipe_fd) < 0)
26 - return error("send-pack: pipe failed");
27 - pid = fork();
28 - if (pid < 0)
29 - return error("send-pack: unable to fork git-pack-objects");
30 - if (!pid) {
31 - /*
32 - * The child becomes pack-objects --revs; we feed
33 - * the revision parameters to it via its stdin and
34 - * let its stdout go back to the other end.
35 - */
36 - static const char *args[] = {
37 - "pack-objects",
38 - "--all-progress",
39 - "--revs",
40 - "--stdout",
41 - NULL,
42 - NULL,
43 - };
44 - if (use_thin_pack)
45 - args[4] = "--thin";
46 - dup2(pipe_fd[0], 0);
47 - dup2(fd, 1);
48 - close(pipe_fd[0]);
49 - close(pipe_fd[1]);
50 - close(fd);
51 - execv_git_cmd(args);
52 - die("git-pack-objects exec failed (%s)", strerror(errno));
53 - }
22 + /*
23 + * The child becomes pack-objects --revs; we feed
24 + * the revision parameters to it via its stdin and
25 + * let its stdout go back to the other end.
26 + */
27 + const char *args[] = {
28 + "pack-objects",
29 + "--all-progress",
30 + "--revs",
31 + "--stdout",
32 + NULL,
33 + NULL,
34 + };
35 + struct child_process po;
36 +
37 + if (use_thin_pack)
38 + args[4] = "--thin";
39 + memset(&po, 0, sizeof(po));
40 + po.argv = args;
41 + po.in = -1;
42 + po.out = fd;
43 + po.git_cmd = 1;
44 + if (start_command(&po))
45 + die("git-pack-objects failed (%s)", strerror(errno));
46
47 /*
48 * We feed the pack-objects we just spawned with revision
49 * parameters by writing to the pipe.
50 */
59 - close(pipe_fd[0]);
60 - close(fd);
61 -
51 while (refs) {
52 char buf[42];
53
@@ -67,38 +56,23 @@ static int pack_objects(int fd, struct ref *refs)
56 memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
57 buf[0] = '^';
58 buf[41] = '\n';
70 - if (!write_or_whine(pipe_fd[1], buf, 42,
59 + if (!write_or_whine(po.in, buf, 42,
60 "send-pack: send refs"))
61 break;
62 }
63 if (!is_null_sha1(refs->new_sha1)) {
64 memcpy(buf, sha1_to_hex(refs->new_sha1), 40);
65 buf[40] = '\n';
77 - if (!write_or_whine(pipe_fd[1], buf, 41,
66 + if (!write_or_whine(po.in, buf, 41,
67 "send-pack: send refs"))
68 break;
69 }
70 refs = refs->next;
71 }
83 - close(pipe_fd[1]);
84 -
85 - for (;;) {
86 - int status, code;
87 - pid_t waiting = waitpid(pid, &status, 0);
72
89 - if (waiting < 0) {
90 - if (errno == EINTR)
91 - continue;
92 - return error("waitpid failed (%s)", strerror(errno));
93 - }
94 - if ((waiting != pid) || WIFSIGNALED(status) ||
95 - !WIFEXITED(status))
96 - return error("pack-objects died with strange error");
97 - code = WEXITSTATUS(status);
98 - if (code)
99 - return -code;
100 - return 0;
101 - }
73 + if (finish_command(&po))
74 + return error("pack-objects died with strange error");
75 + return 0;
76 }
77
78 static void unmark_and_free(struct commit_list *list, unsigned int mark)