Skip to content

Commit e929f51

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1d0945 commit e929f51

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

transport.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -263,32 +263,20 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
263263
static int fetch_objs_via_rsync(struct transport *transport,
264264
int nr_objs, struct ref **to_fetch)
265265
{
266-
struct strbuf buf = STRBUF_INIT;
267266
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/");
273267

274268
memset(&rsync, 0, sizeof(rsync));
275-
rsync.argv = args;
276269
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());
285277

286278
/* 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);
292280
}
293281

294282
static int write_one_ref(const char *name, const unsigned char *sha1,

0 commit comments

Comments
 (0)