transport: simplify fetch_objs_via_rsync() using argv_array

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 18, 2014 at 17:12 UTC e929f515faaa44deed9057cdbaf8e44b3d855333
1 file changed +8 -20
transport.c
+8 -20
@@ -263,32 +263,20 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
263 static int fetch_objs_via_rsync(struct transport *transport,
264 int nr_objs, struct ref **to_fetch)
265 {
266 - struct strbuf buf = STRBUF_INIT;
266 struct child_process rsync;
268 - const char *args[8];
269 - int result;
270 -
271 - strbuf_addstr(&buf, rsync_url(transport->url));
272 - strbuf_addstr(&buf, "/objects/");
267
268 memset(&rsync, 0, sizeof(rsync));
275 - rsync.argv = args;
269 rsync.stdout_to_stderr = 1;
277 - args[0] = "rsync";
278 - args[1] = (transport->verbose > 1) ? "-rv" : "-r";
279 - args[2] = "--ignore-existing";
280 - args[3] = "--exclude";
281 - args[4] = "info";
282 - args[5] = buf.buf;
283 - args[6] = get_object_directory();
284 - args[7] = NULL;
270 + argv_array_push(&rsync.args, "rsync");
271 + argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r");
272 + argv_array_push(&rsync.args, "--ignore-existing");
273 + argv_array_push(&rsync.args, "--exclude");
274 + argv_array_push(&rsync.args, "info");
275 + argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url));
276 + argv_array_push(&rsync.args, get_object_directory());
277
278 /* NEEDSWORK: handle one level of alternates */
287 - result = run_command(&rsync);
288 -
289 - strbuf_release(&buf);
290 -
291 - return result;
279 + return run_command(&rsync);
280 }
281
282 static int write_one_ref(const char *name, const unsigned char *sha1,