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>

Nguyễn Thái Ngọc Duy committed Jun 12, 2016 at 17:53 UTC b5f62ebea55a07dbd9f68f33f5efbd0437946220
1 file changed +18 -28
remote-curl.c
+18 -28
@@ -725,38 +725,28 @@ static int fetch_git(struct discovery *heads,
725 {
726 struct rpc_state rpc;
727 struct strbuf preamble = STRBUF_INIT;
728 - char *depth_arg = NULL;
729 - int argc = 0, i, err;
730 - const char *argv[17];
731 -
732 - argv[argc++] = "fetch-pack";
733 - argv[argc++] = "--stateless-rpc";
734 - argv[argc++] = "--stdin";
735 - argv[argc++] = "--lock-pack";
728 + int i, err;
729 + struct argv_array args = ARGV_ARRAY_INIT;
730 +
731 + argv_array_pushl(&args, "fetch-pack", "--stateless-rpc",
732 + "--stdin", "--lock-pack", NULL);
733 if (options.followtags)
737 - argv[argc++] = "--include-tag";
734 + argv_array_push(&args, "--include-tag");
735 if (options.thin)
739 - argv[argc++] = "--thin";
740 - if (options.verbosity >= 3) {
741 - argv[argc++] = "-v";
742 - argv[argc++] = "-v";
743 - }
736 + argv_array_push(&args, "--thin");
737 + if (options.verbosity >= 3)
738 + argv_array_pushl(&args, "-v", "-v", NULL);
739 if (options.check_self_contained_and_connected)
745 - argv[argc++] = "--check-self-contained-and-connected";
740 + argv_array_push(&args, "--check-self-contained-and-connected");
741 if (options.cloning)
747 - argv[argc++] = "--cloning";
742 + argv_array_push(&args, "--cloning");
743 if (options.update_shallow)
749 - argv[argc++] = "--update-shallow";
744 + argv_array_push(&args, "--update-shallow");
745 if (!options.progress)
751 - argv[argc++] = "--no-progress";
752 - if (options.depth) {
753 - struct strbuf buf = STRBUF_INIT;
754 - strbuf_addf(&buf, "--depth=%lu", options.depth);
755 - depth_arg = strbuf_detach(&buf, NULL);
756 - argv[argc++] = depth_arg;
757 - }
758 - argv[argc++] = url.buf;
759 - argv[argc++] = NULL;
746 + argv_array_push(&args, "--no-progress");
747 + if (options.depth)
748 + argv_array_pushf(&args, "--depth=%lu", options.depth);
749 + argv_array_push(&args, url.buf);
750
751 for (i = 0; i < nr_heads; i++) {
752 struct ref *ref = to_fetch[i];
@@ -769,7 +759,7 @@ static int fetch_git(struct discovery *heads,
759
760 memset(&rpc, 0, sizeof(rpc));
761 rpc.service_name = "git-upload-pack",
772 - rpc.argv = argv;
762 + rpc.argv = args.argv;
763 rpc.stdin_preamble = &preamble;
764 rpc.gzip_request = 1;
765
@@ -778,7 +768,7 @@ static int fetch_git(struct discovery *heads,
768 write_or_die(1, rpc.result.buf, rpc.result.len);
769 strbuf_release(&rpc.result);
770 strbuf_release(&preamble);
781 - free(depth_arg);
771 + argv_array_clear(&args);
772 return err;
773 }
774