send-pack: tell pack-objects to use its internal rev-list.
This means one less process in the pipeline to worry about, and removes about 1/8 of the code. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 31, 2006 at 01:26 UTC
0ae5f98c7ba29fa4c698989cd6b38deba06d5bf3
1 file changed
+42
-97
send-pack.c
+42
-97
@@ -14,100 +14,49 @@ static int send_all;
14
static int force_update;
15
static int use_thin_pack;
16
17
-static void exec_pack_objects(void)
18
-{
19
- static const char *args[] = {
20
- "pack-objects",
21
- "--all-progress",
22
- "--stdout",
23
- NULL
24
- };
25
- execv_git_cmd(args);
26
- die("git-pack-objects exec failed (%s)", strerror(errno));
27
-}
28
-
29
-static void exec_rev_list(struct ref *refs)
30
-{
31
- static const char *args[4];
32
- int i = 0;
33
-
34
- args[i++] = "rev-list"; /* 0 */
35
- if (use_thin_pack) /* 1 */
36
- args[i++] = "--objects-edge";
37
- else
38
- args[i++] = "--objects";
39
-
40
- args[i++] = "--stdin";
41
-
42
- args[i] = NULL;
43
- execv_git_cmd(args);
44
- die("git-rev-list exec failed (%s)", strerror(errno));
45
-}
46
-
17
/*
48
- * Run "rev-list --stdin | pack-objects" pipe.
49
- */
50
-static void rev_list(struct ref *refs)
51
-{
52
- int pipe_fd[2];
53
- pid_t pack_objects_pid;
54
-
55
- if (pipe(pipe_fd) < 0)
56
- die("rev-list setup: pipe failed");
57
- pack_objects_pid = fork();
58
- if (!pack_objects_pid) {
59
- /* The child becomes pack-objects; reads from pipe
60
- * and writes to the original fd
61
- */
62
- dup2(pipe_fd[0], 0);
63
- close(pipe_fd[0]);
64
- close(pipe_fd[1]);
65
- exec_pack_objects();
66
- die("pack-objects setup failed");
67
- }
68
- if (pack_objects_pid < 0)
69
- die("pack-objects fork failed");
70
-
71
- /* We become rev-list --stdin; output goes to pipe. */
72
- dup2(pipe_fd[1], 1);
73
- close(pipe_fd[0]);
74
- close(pipe_fd[1]);
75
- exec_rev_list(refs);
76
-}
77
-
78
-/*
79
- * Create "rev-list --stdin | pack-objects" pipe and feed
80
- * the refs into the pipeline.
18
+ * Make a pack stream and spit it out into file descriptor fd
19
*/
82
-static void rev_list_generate(int fd, struct ref *refs)
20
+static int pack_objects(int fd, struct ref *refs)
21
{
22
int pipe_fd[2];
85
- pid_t rev_list_generate_pid;
23
+ pid_t pid;
24
25
if (pipe(pipe_fd) < 0)
88
- die("rev-list-generate setup: pipe failed");
89
- rev_list_generate_pid = fork();
90
- if (!rev_list_generate_pid) {
91
- /* The child becomes the "rev-list | pack-objects"
92
- * pipeline. It takes input from us, and its output
93
- * goes to fd.
26
+ return error("send-pack: pipe failed");
27
+ pid = fork();
28
+ if (!pid) {
29
+ /*
30
+ * The child becomes pack-objects --revs; we feed
31
+ * the revision parameters to it via its stdin and
32
+ * let its stdout go back to the other end.
33
*/
34
+ static const char *args[] = {
35
+ "pack-objects",
36
+ "--all-progress",
37
+ "--revs",
38
+ "--stdout",
39
+ NULL,
40
+ NULL,
41
+ };
42
+ if (use_thin_pack)
43
+ args[4] = "--thin";
44
dup2(pipe_fd[0], 0);
45
dup2(fd, 1);
46
close(pipe_fd[0]);
47
close(pipe_fd[1]);
48
close(fd);
100
- rev_list(refs);
101
- die("rev-list setup failed");
49
+ execv_git_cmd(args);
50
+ die("git-pack-objects exec failed (%s)", strerror(errno));
51
}
103
- if (rev_list_generate_pid < 0)
104
- die("rev-list-generate fork failed");
52
106
- /* We feed the rev parameters to them. We do not write into
107
- * fd nor read from the pipe.
53
+ /*
54
+ * We feed the pack-objects we just spawned with revision
55
+ * parameters by writing to the pipe.
56
*/
57
close(pipe_fd[0]);
58
close(fd);
59
+
60
while (refs) {
61
char buf[42];
62
@@ -126,28 +75,24 @@ static void rev_list_generate(int fd, struct ref *refs)
75
refs = refs->next;
76
}
77
close(pipe_fd[1]);
129
- // waitpid(rev_list_generate_pid);
130
- exit(0);
131
-}
78
133
-/*
134
- * Make a pack stream and spit it out into file descriptor fd
135
- */
136
-static void pack_objects(int fd, struct ref *refs)
137
-{
138
- pid_t rev_list_pid;
79
+ for (;;) {
80
+ int status, code;
81
+ pid_t waiting = waitpid(pid, &status, 0);
82
140
- rev_list_pid = fork();
141
- if (!rev_list_pid) {
142
- rev_list_generate(fd, refs);
143
- die("rev-list setup failed");
83
+ if (waiting < 0) {
84
+ if (errno == EINTR)
85
+ continue;
86
+ return error("waitpid failed (%s)", strerror(errno));
87
+ }
88
+ if ((waiting != pid) || WIFSIGNALED(status) ||
89
+ !WIFEXITED(status))
90
+ return error("pack-objects died with strange error");
91
+ code = WEXITSTATUS(status);
92
+ if (code)
93
+ return -code;
94
+ return 0;
95
}
145
- if (rev_list_pid < 0)
146
- die("rev-list fork failed");
147
- /*
148
- * We don't wait for the rev-list pipeline in the parent:
149
- * we end up waiting for the other end instead
150
- */
96
}
97
98
static void unmark_and_free(struct commit_list *list, unsigned int mark)
@@ -379,7 +324,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
324
325
packet_flush(out);
326
if (new_refs)
382
- pack_objects(out, remote_refs);
327
+ ret = pack_objects(out, remote_refs);
328
close(out);
329
330
if (expect_status_report) {