Use the asyncronous function infrastructure in builtin-fetch-pack.c.
We run the sideband demultiplexer in an asynchronous function. Note that earlier there was a check in the child process that closed xd[1] only if it was different from xd[0]; this test is no longer needed because git_connect() always returns two different file descriptors (see ec587fde0a76780931c7ac32474c8c000aa45134). 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
088fab5fc48ebb8b476c3b32dd25df3aa4236f94
1 file changed
+18
-21
builtin-fetch-pack.c
+18
-21
@@ -457,42 +457,37 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
457
return retval;
458
}
459
460
-static pid_t setup_sideband(int fd[2], int xd[2])
460
+static int sideband_demux(int fd, void *data)
461
{
462
- pid_t side_pid;
462
+ int *xd = data;
463
464
+ close(xd[1]);
465
+ return recv_sideband("fetch-pack", xd[0], fd, 2);
466
+}
467
+
468
+static void setup_sideband(int fd[2], int xd[2], struct async *demux)
469
+{
470
if (!use_sideband) {
471
fd[0] = xd[0];
472
fd[1] = xd[1];
467
- return 0;
473
+ return;
474
}
475
/* xd[] is talking with upload-pack; subprocess reads from
476
* xd[0], spits out band#2 to stderr, and feeds us band#1
471
- * through our fd[0].
477
+ * through demux->out.
478
*/
473
- if (pipe(fd) < 0)
474
- die("fetch-pack: unable to set up pipe");
475
- side_pid = fork();
476
- if (side_pid < 0)
479
+ demux->proc = sideband_demux;
480
+ demux->data = xd;
481
+ if (start_async(demux))
482
die("fetch-pack: unable to fork off sideband demultiplexer");
478
- if (!side_pid) {
479
- /* subprocess */
480
- close(fd[0]);
481
- if (xd[0] != xd[1])
482
- close(xd[1]);
483
- if (recv_sideband("fetch-pack", xd[0], fd[1], 2))
484
- exit(1);
485
- exit(0);
486
- }
483
close(xd[0]);
488
- close(fd[1]);
484
+ fd[0] = demux->out;
485
fd[1] = xd[1];
490
- return side_pid;
486
}
487
488
static int get_pack(int xd[2], char **pack_lockfile)
489
{
495
- pid_t side_pid;
490
+ struct async demux;
491
int fd[2];
492
const char *argv[20];
493
char keep_arg[256];
@@ -501,7 +496,7 @@ static int get_pack(int xd[2], char **pack_lockfile)
496
int do_keep = args.keep_pack;
497
struct child_process cmd;
498
504
- side_pid = setup_sideband(fd, xd);
499
+ setup_sideband(fd, xd, &demux);
500
501
memset(&cmd, 0, sizeof(cmd));
502
cmd.argv = argv;
@@ -556,6 +551,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
551
552
if (finish_command(&cmd))
553
die("%s failed", argv[0]);
554
+ if (use_sideband && finish_async(&demux))
555
+ die("error in sideband demultiplexer");
556
return 0;
557
}
558