{"thread":{"id":"37162","subject":"[PATCH] transport: simplify fetch_objs_via_rsync() using argv_array","startedAt":"2014-07-18T15:12:34Z","lastAt":"2014-07-18T15:12:34Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"246313","messageId":"53C93962.6020904@web.de","threadId":"37162","inReplyTo":null,"subject":"[PATCH] transport: simplify fetch_objs_via_rsync() using argv_array","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-07-18T15:12:34Z","receivedAt":"2014-07-18T15:12:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use the existing argv_array member instead of building the arguments\nlist using a string array and a strbuf.  This way we don't need magic\nnumber constants and allocations are cleaned up for us automatically\nby run_command().\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n transport.c | 28 ++++++++--------------------\n 1 file changed, 8 insertions(+), 20 deletions(-)\n\ndiff --git a/transport.c b/transport.c\nindex 59c9727..3e42570 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -263,32 +263,20 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)\n static int fetch_objs_via_rsync(struct transport *transport,\n \t\t\t\tint nr_objs, struct ref **to_fetch)\n {\n-\tstruct strbuf buf = STRBUF_INIT;\n \tstruct child_process rsync;\n-\tconst char *args[8];\n-\tint result;\n-\n-\tstrbuf_addstr(&buf, rsync_url(transport->url));\n-\tstrbuf_addstr(&buf, \"/objects/\");\n \n \tmemset(&rsync, 0, sizeof(rsync));\n-\trsync.argv = args;\n \trsync.stdout_to_stderr = 1;\n-\targs[0] = \"rsync\";\n-\targs[1] = (transport->verbose > 1) ? \"-rv\" : \"-r\";\n-\targs[2] = \"--ignore-existing\";\n-\targs[3] = \"--exclude\";\n-\targs[4] = \"info\";\n-\targs[5] = buf.buf;\n-\targs[6] = get_object_directory();\n-\targs[7] = NULL;\n+\targv_array_push(&rsync.args, \"rsync\");\n+\targv_array_push(&rsync.args, (transport->verbose > 1) ? \"-rv\" : \"-r\");\n+\targv_array_push(&rsync.args, \"--ignore-existing\");\n+\targv_array_push(&rsync.args, \"--exclude\");\n+\targv_array_push(&rsync.args, \"info\");\n+\targv_array_pushf(&rsync.args, \"%s/objects/\", rsync_url(transport->url));\n+\targv_array_push(&rsync.args, get_object_directory());\n \n \t/* NEEDSWORK: handle one level of alternates */\n-\tresult = run_command(&rsync);\n-\n-\tstrbuf_release(&buf);\n-\n-\treturn result;\n+\treturn run_command(&rsync);\n }\n \n static int write_one_ref(const char *name, const unsigned char *sha1,\n-- \n2.0.0\n"}]}