remote-curl.c: convert fetch_git() to use argv_array

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Nguyễn Thái Ngọc Duy 2016-06-12 17:53:43 +07:00 committed by Junio C Hamano
parent 7c0da37d7b
commit b5f62ebea5
1 changed files with 17 additions and 27 deletions

View File

@ -725,38 +725,28 @@ static int fetch_git(struct discovery *heads,
{ {
struct rpc_state rpc; struct rpc_state rpc;
struct strbuf preamble = STRBUF_INIT; struct strbuf preamble = STRBUF_INIT;
char *depth_arg = NULL; int i, err;
int argc = 0, i, err; struct argv_array args = ARGV_ARRAY_INIT;
const char *argv[17];


argv[argc++] = "fetch-pack"; argv_array_pushl(&args, "fetch-pack", "--stateless-rpc",
argv[argc++] = "--stateless-rpc"; "--stdin", "--lock-pack", NULL);
argv[argc++] = "--stdin";
argv[argc++] = "--lock-pack";
if (options.followtags) if (options.followtags)
argv[argc++] = "--include-tag"; argv_array_push(&args, "--include-tag");
if (options.thin) if (options.thin)
argv[argc++] = "--thin"; argv_array_push(&args, "--thin");
if (options.verbosity >= 3) { if (options.verbosity >= 3)
argv[argc++] = "-v"; argv_array_pushl(&args, "-v", "-v", NULL);
argv[argc++] = "-v";
}
if (options.check_self_contained_and_connected) if (options.check_self_contained_and_connected)
argv[argc++] = "--check-self-contained-and-connected"; argv_array_push(&args, "--check-self-contained-and-connected");
if (options.cloning) if (options.cloning)
argv[argc++] = "--cloning"; argv_array_push(&args, "--cloning");
if (options.update_shallow) if (options.update_shallow)
argv[argc++] = "--update-shallow"; argv_array_push(&args, "--update-shallow");
if (!options.progress) if (!options.progress)
argv[argc++] = "--no-progress"; argv_array_push(&args, "--no-progress");
if (options.depth) { if (options.depth)
struct strbuf buf = STRBUF_INIT; argv_array_pushf(&args, "--depth=%lu", options.depth);
strbuf_addf(&buf, "--depth=%lu", options.depth); argv_array_push(&args, url.buf);
depth_arg = strbuf_detach(&buf, NULL);
argv[argc++] = depth_arg;
}
argv[argc++] = url.buf;
argv[argc++] = NULL;


for (i = 0; i < nr_heads; i++) { for (i = 0; i < nr_heads; i++) {
struct ref *ref = to_fetch[i]; struct ref *ref = to_fetch[i];
@ -769,7 +759,7 @@ static int fetch_git(struct discovery *heads,


memset(&rpc, 0, sizeof(rpc)); memset(&rpc, 0, sizeof(rpc));
rpc.service_name = "git-upload-pack", rpc.service_name = "git-upload-pack",
rpc.argv = argv; rpc.argv = args.argv;
rpc.stdin_preamble = &preamble; rpc.stdin_preamble = &preamble;
rpc.gzip_request = 1; rpc.gzip_request = 1;


@ -778,7 +768,7 @@ static int fetch_git(struct discovery *heads,
write_or_die(1, rpc.result.buf, rpc.result.len); write_or_die(1, rpc.result.buf, rpc.result.len);
strbuf_release(&rpc.result); strbuf_release(&rpc.result);
strbuf_release(&preamble); strbuf_release(&preamble);
free(depth_arg); argv_array_clear(&args);
return err; return err;
} }