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

[PATCH] transport: simplify fetch_objs_via_rsync() using argv_array

From
René Scharfe <l.s.r@web.de>
Date
Jul 18, 2014, 15:12 UTC
Message-ID
<53C93962.6020904@web.de>

Use the existing argv_array member instead of building the arguments list using a string array and a strbuf. This way we don't need magic number constants and allocations are cleaned up for us automatically by run_command().

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 transport.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/transport.c b/transport.c
index 59c9727..3e42570 100644
--- a/transport.c
+++ b/transport.c
@@ -263,32 +263,20 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
 static int fetch_objs_via_rsync(struct transport *transport,
 				int nr_objs, struct ref **to_fetch)
 {
-	struct strbuf buf = STRBUF_INIT;
 	struct child_process rsync;
-	const char *args[8];
-	int result;
-
-	strbuf_addstr(&buf, rsync_url(transport->url));
-	strbuf_addstr(&buf, "/objects/");
 
 	memset(&rsync, 0, sizeof(rsync));
-	rsync.argv = args;
 	rsync.stdout_to_stderr = 1;
-	args[0] = "rsync";
-	args[1] = (transport->verbose > 1) ? "-rv" : "-r";
-	args[2] = "--ignore-existing";
-	args[3] = "--exclude";
-	args[4] = "info";
-	args[5] = buf.buf;
-	args[6] = get_object_directory();
-	args[7] = NULL;
+	argv_array_push(&rsync.args, "rsync");
+	argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r");
+	argv_array_push(&rsync.args, "--ignore-existing");
+	argv_array_push(&rsync.args, "--exclude");
+	argv_array_push(&rsync.args, "info");
+	argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url));
+	argv_array_push(&rsync.args, get_object_directory());
 
 	/* NEEDSWORK: handle one level of alternates */
-	result = run_command(&rsync);
-
-	strbuf_release(&buf);
-
-	return result;
+	return run_command(&rsync);
 }
 
 static int write_one_ref(const char *name, const unsigned char *sha1,
-- 
2.0.0
Message 1 of 1 in “transport: simplify fetch_objs_via_rsync() using argv_array”
  1. transport: simplify fetch_objs_via_rsync() using argv_arrayRené Scharfe, Jul 18, 2014

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.