@matheusbsbs / matheus-bagliano / commits / 1f759eeede
Fork 0

fetch-pack: Prepare for a side-band demultiplexer in a thread.

get_pack() receives a pair of file descriptors that communicate with upload-pack at the remote end. In order to support the case where the side-band demultiplexer runs in a thread, and, hence, in the same process as the main routine, we must not close the readable file descriptor early. The handling of the readable fd is changed in the case where upload-pack supports side-band communication: The old code closed the fd after it was inherited to the side-band demultiplexer process. Now we do not close it. The caller (do_fetch_pack) will close it later anyway. The demultiplexer is the only reader, it does not matter that the fd remains open in the main process as well as in unpack-objects/index-pack, which inherits it. The writable fd is not needed in get_pack(), hence, the old code closed the fd. For symmetry with the readable fd, we now do not close it; the caller (do_fetch_pack) will close it later anyway. Therefore, the new behavior is that the channel now remains open during the entire conversation, but this has no ill effects because upload-pack does not read from it once it has begun to send the pack data. For the same reason it does not matter that the writable fd is now inherited to the demultiplexer and unpack-objects/index-pack processes. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Nov 17, 2007 at 23:09 UTC 1f759eeede0597580be8ce26305550350e3c017a
1 file changed +16 -26
builtin-fetch-pack.c
+16 -26
@@ -462,34 +462,12 @@ static int sideband_demux(int fd, void *data)
462 {
463 int *xd = data;
464
465 - close(xd[1]);
465 return recv_sideband("fetch-pack", xd[0], fd, 2);
466 }
467
469 -static void setup_sideband(int fd[2], int xd[2], struct async *demux)
470 -{
471 - if (!use_sideband) {
472 - fd[0] = xd[0];
473 - fd[1] = xd[1];
474 - return;
475 - }
476 - /* xd[] is talking with upload-pack; subprocess reads from
477 - * xd[0], spits out band#2 to stderr, and feeds us band#1
478 - * through demux->out.
479 - */
480 - demux->proc = sideband_demux;
481 - demux->data = xd;
482 - if (start_async(demux))
483 - die("fetch-pack: unable to fork off sideband demultiplexer");
484 - close(xd[0]);
485 - fd[0] = demux->out;
486 - fd[1] = xd[1];
487 -}
488 -
468 static int get_pack(int xd[2], char **pack_lockfile)
469 {
470 struct async demux;
492 - int fd[2];
471 const char *argv[20];
472 char keep_arg[256];
473 char hdr_arg[256];
@@ -497,7 +475,20 @@ static int get_pack(int xd[2], char **pack_lockfile)
475 int do_keep = args.keep_pack;
476 struct child_process cmd;
477
500 - setup_sideband(fd, xd, &demux);
478 + memset(&demux, 0, sizeof(demux));
479 + if (use_sideband) {
480 + /* xd[] is talking with upload-pack; subprocess reads from
481 + * xd[0], spits out band#2 to stderr, and feeds us band#1
482 + * through demux->out.
483 + */
484 + demux.proc = sideband_demux;
485 + demux.data = xd;
486 + if (start_async(&demux))
487 + die("fetch-pack: unable to fork off sideband"
488 + " demultiplexer");
489 + }
490 + else
491 + demux.out = xd[0];
492
493 memset(&cmd, 0, sizeof(cmd));
494 cmd.argv = argv;
@@ -506,7 +497,7 @@ static int get_pack(int xd[2], char **pack_lockfile)
497 if (!args.keep_pack && unpack_limit) {
498 struct pack_header header;
499
509 - if (read_pack_header(fd[0], &header))
500 + if (read_pack_header(demux.out, &header))
501 die("protocol error: bad pack header");
502 snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
503 ntohl(header.hdr_version), ntohl(header.hdr_entries));
@@ -542,11 +533,10 @@ static int get_pack(int xd[2], char **pack_lockfile)
533 *av++ = hdr_arg;
534 *av++ = NULL;
535
545 - cmd.in = fd[0];
536 + cmd.in = demux.out;
537 cmd.git_cmd = 1;
538 if (start_command(&cmd))
539 die("fetch-pack: unable to fork off %s", argv[0]);
549 - close(fd[1]);
540 if (do_keep && pack_lockfile)
541 *pack_lockfile = index_pack_lockfile(cmd.out);
542