@matheusbsbs / matheus-bagliano / commits / 21edd3f197
Fork 0

upload-pack: Run rev-list in an asynchronous function.

This gets rid of an explicit fork(). Since upload-pack has to coordinate two processes (rev-list and pack-objects), we cannot use the normal finish_async(), but have to monitor the process explicitly. Hence, there are no changes at this front. 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:48 UTC 21edd3f197df80e9493233a3b9849b61764ebf46
1 file changed +18 -28
upload-pack.c
+18 -28
@@ -97,11 +97,12 @@ static void show_edge(struct commit *commit)
97 fprintf(pack_pipe, "-%s\n", sha1_to_hex(commit->object.sha1));
98 }
99
100 -static void do_rev_list(int create_full_pack)
100 +static int do_rev_list(int fd, void *create_full_pack)
101 {
102 int i;
103 struct rev_info revs;
104
105 + pack_pipe = fdopen(fd, "w");
106 if (create_full_pack)
107 use_thin_pack = 0; /* no point doing it */
108 init_revisions(&revs, NULL);
@@ -131,14 +132,12 @@ static void do_rev_list(int create_full_pack)
132 prepare_revision_walk(&revs);
133 mark_edges_uninteresting(revs.commits, &revs, show_edge);
134 traverse_commit_list(&revs, show_commit, show_object);
135 + return 0;
136 }
137
138 static void create_pack_file(void)
139 {
138 - /* Pipe from rev-list to pack-objects
139 - */
140 - int lp_pipe[2];
141 - pid_t pid_rev_list;
140 + struct async rev_list;
141 struct child_process pack_objects;
142 int create_full_pack = (nr_our_refs == want_obj.nr && !have_obj.nr);
143 char data[8193], progress[128];
@@ -148,22 +147,12 @@ static void create_pack_file(void)
147 const char *argv[10];
148 int arg = 0;
149
151 - if (pipe(lp_pipe) < 0)
152 - die("git-upload-pack: unable to create pipe");
153 - pid_rev_list = fork();
154 - if (pid_rev_list < 0)
150 + rev_list.proc = do_rev_list;
151 + /* .data is just a boolean: any non-NULL value will do */
152 + rev_list.data = create_full_pack ? &rev_list : NULL;
153 + if (start_async(&rev_list))
154 die("git-upload-pack: unable to fork git-rev-list");
155
157 - if (!pid_rev_list) {
158 - close(lp_pipe[0]);
159 - pack_pipe = fdopen(lp_pipe[1], "w");
160 - do_rev_list(create_full_pack);
161 - exit(0);
162 - }
163 -
164 - /* writable pipe end must not be inherited by pack_objects */
165 - close(lp_pipe[1]);
166 -
156 argv[arg++] = "pack-objects";
157 argv[arg++] = "--stdout";
158 if (!no_progress)
@@ -173,14 +162,15 @@ static void create_pack_file(void)
162 argv[arg++] = NULL;
163
164 memset(&pack_objects, 0, sizeof(pack_objects));
176 - pack_objects.in = lp_pipe[0]; /* start_command closes it */
165 + pack_objects.in = rev_list.out; /* start_command closes it */
166 pack_objects.out = -1;
167 pack_objects.err = -1;
168 pack_objects.git_cmd = 1;
169 pack_objects.argv = argv;
170 +
171 if (start_command(&pack_objects)) {
172 /* daemon sets things up to ignore TERM */
183 - kill(pid_rev_list, SIGKILL);
173 + kill(rev_list.pid, SIGKILL);
174 die("git-upload-pack: unable to fork git-pack-objects");
175 }
176
@@ -280,11 +270,11 @@ static void create_pack_file(void)
270 }
271
272 /* See if the children are still there */
283 - if (pid_rev_list || pack_objects.pid) {
273 + if (rev_list.pid || pack_objects.pid) {
274 pid = waitpid(-1, &status, WNOHANG);
275 if (!pid)
276 continue;
287 - who = ((pid == pid_rev_list) ? "git-rev-list" :
277 + who = ((pid == rev_list.pid) ? "git-rev-list" :
278 (pid == pack_objects.pid) ? "git-pack-objects" :
279 NULL);
280 if (!who) {
@@ -302,11 +292,11 @@ static void create_pack_file(void)
292 who);
293 goto fail;
294 }
305 - if (pid == pid_rev_list)
306 - pid_rev_list = 0;
295 + if (pid == rev_list.pid)
296 + rev_list.pid = 0;
297 if (pid == pack_objects.pid)
298 pack_objects.pid = 0;
309 - if (pid_rev_list || pack_objects.pid)
299 + if (rev_list.pid || pack_objects.pid)
300 continue;
301 }
302
@@ -329,8 +319,8 @@ static void create_pack_file(void)
319 fail:
320 if (pack_objects.pid)
321 kill(pack_objects.pid, SIGKILL);
332 - if (pid_rev_list)
333 - kill(pid_rev_list, SIGKILL);
322 + if (rev_list.pid)
323 + kill(rev_list.pid, SIGKILL);
324 send_client_data(3, abort_msg, sizeof(abort_msg));
325 die("git-upload-pack: %s", abort_msg);
326 }