git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/14] Use the asyncronous function infrastructure in builtin-fetch-pack.c.

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Oct 19, 2007, 19:48 UTC
Message-ID
<1192823286-9654-10-git-send-email-johannes.sixt@telecom.at>
In-Reply-To
<1192823286-9654-9-git-send-email-johannes.sixt@telecom.at>
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>
---
 builtin-fetch-pack.c |   39 ++++++++++++++++++---------------------
 1 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 871b704..51d8a32 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -457,42 +457,37 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
 	return retval;
 }
 
-static pid_t setup_sideband(int fd[2], int xd[2])
+static int sideband_demux(int fd, void *data)
 {
-	pid_t side_pid;
+	int *xd = data;
 
+	close(xd[1]);
+	return recv_sideband("fetch-pack", xd[0], fd, 2);
+}
+
+static void setup_sideband(int fd[2], int xd[2], struct async *demux)
+{
 	if (!use_sideband) {
 		fd[0] = xd[0];
 		fd[1] = xd[1];
-		return 0;
+		return;
 	}
 	/* xd[] is talking with upload-pack; subprocess reads from
 	 * xd[0], spits out band#2 to stderr, and feeds us band#1
-	 * through our fd[0].
+	 * through demux->out.
 	 */
-	if (pipe(fd) < 0)
-		die("fetch-pack: unable to set up pipe");
-	side_pid = fork();
-	if (side_pid < 0)
+	demux->proc = sideband_demux;
+	demux->data = xd;
+	if (start_async(demux))
 		die("fetch-pack: unable to fork off sideband demultiplexer");
-	if (!side_pid) {
-		/* subprocess */
-		close(fd[0]);
-		if (xd[0] != xd[1])
-			close(xd[1]);
-		if (recv_sideband("fetch-pack", xd[0], fd[1], 2))
-			exit(1);
-		exit(0);
-	}
 	close(xd[0]);
-	close(fd[1]);
+	fd[0] = demux->out;
 	fd[1] = xd[1];
-	return side_pid;
 }
 
 static int get_pack(int xd[2], char **pack_lockfile)
 {
-	pid_t side_pid;
+	struct async demux;
 	int fd[2];
 	const char *argv[20];
 	char keep_arg[256];
@@ -501,7 +496,7 @@ static int get_pack(int xd[2], char **pack_lockfile)
 	int do_keep = args.keep_pack;
 	struct child_process cmd;
 
-	side_pid = setup_sideband(fd, xd);
+	setup_sideband(fd, xd, &demux);
 
 	memset(&cmd, 0, sizeof(cmd));
 	cmd.argv = argv;
@@ -556,6 +551,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
 
 	if (finish_command(&cmd))
 		die("%s failed", argv[0]);
+	if (use_sideband && finish_async(&demux))
+		die("error in sideband demultiplexer");
 	return 0;
 }
 
-- 
1.5.3.4.315.g2ce38
Previous: Johannes SixtNext: Johannes Sixt
Message 10 of 18 in “fork/exec removal series”
  1. 0/14 fork/exec removal seriesJohannes Sixt, Oct 19, 2007
  2. 01/14 Change git_connect() to return a struct child_process instead of a pid_t.Johannes Sixt, Oct 19, 2007
  3. 02/14 Use start_command() in git_connect() instead of explicit fork/exec.Johannes Sixt, Oct 19, 2007
  4. 03/14 Use start_command() to run content filters instead of explicit fork/exec.Johannes Sixt, Oct 19, 2007
  5. 04/14 Use run_command() to spawn external diff programs instead of fork/exec.Johannes Sixt, Oct 19, 2007
  6. 05/14 Use start_comand() in builtin-fetch-pack.c instead of explicit fork/exec.Johannes Sixt, Oct 19, 2007
  7. 06/14 Have start_command() create a pipe to read the stderr of the child.Johannes Sixt, Oct 19, 2007
  8. 07/14 upload-pack: Use start_command() to run pack-objects in create_pack_file().Johannes Sixt, Oct 19, 2007
  9. 08/14 Add infrastructure to run a function asynchronously.Johannes Sixt, Oct 19, 2007
  10. 09/14 Use the asyncronous function infrastructure in builtin-fetch-pack.c.Johannes Sixt, Oct 19, 2007
  11. 10/14 upload-pack: Move the revision walker into a separate function.Johannes Sixt, Oct 19, 2007
  12. 11/14 upload-pack: Run rev-list in an asynchronous function.Johannes Sixt, Oct 19, 2007
  13. 12/14 t0021-conversion.sh: Test that the clean filter really cleans content.Johannes Sixt, Oct 19, 2007
  14. 13/14 Avoid a dup2(2) in apply_filter() - start_command() can do it for us.Johannes Sixt, Oct 19, 2007
  15. 14/14 Use the asyncronous function infrastructure to run the content filter.Johannes Sixt, Oct 19, 2007
  16. Shawn O. PearceOct 20, 2007
  17. Johannes SixtOct 20, 2007
  18. Shawn O. PearceOct 21, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.