Skip to content

Commit fb1c85d

Browse files
committed
Merge branch 'jc/remote-http-argv-array'
* jc/remote-http-argv-array: remote-http: use argv-array
2 parents d5a3897 + 222b121 commit fb1c85d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

remote-curl.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "run-command.h"
88
#include "pkt-line.h"
99
#include "sideband.h"
10+
#include "argv-array.h"
1011

1112
static struct remote *remote;
1213
static const char *url; /* always ends with a trailing slash */
@@ -787,36 +788,35 @@ static int push_dav(int nr_spec, char **specs)
787788
static int push_git(struct discovery *heads, int nr_spec, char **specs)
788789
{
789790
struct rpc_state rpc;
790-
const char **argv;
791-
int argc = 0, i, err;
791+
int i, err;
792+
struct argv_array args;
793+
794+
argv_array_init(&args);
795+
argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
796+
NULL);
792797

793-
argv = xmalloc((10 + nr_spec) * sizeof(char*));
794-
argv[argc++] = "send-pack";
795-
argv[argc++] = "--stateless-rpc";
796-
argv[argc++] = "--helper-status";
797798
if (options.thin)
798-
argv[argc++] = "--thin";
799+
argv_array_push(&args, "--thin");
799800
if (options.dry_run)
800-
argv[argc++] = "--dry-run";
801+
argv_array_push(&args, "--dry-run");
801802
if (options.verbosity == 0)
802-
argv[argc++] = "--quiet";
803+
argv_array_push(&args, "--quiet");
803804
else if (options.verbosity > 1)
804-
argv[argc++] = "--verbose";
805-
argv[argc++] = options.progress ? "--progress" : "--no-progress";
806-
argv[argc++] = url;
805+
argv_array_push(&args, "--verbose");
806+
argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
807+
argv_array_push(&args, url);
807808
for (i = 0; i < nr_spec; i++)
808-
argv[argc++] = specs[i];
809-
argv[argc++] = NULL;
809+
argv_array_push(&args, specs[i]);
810810

811811
memset(&rpc, 0, sizeof(rpc));
812812
rpc.service_name = "git-receive-pack",
813-
rpc.argv = argv;
813+
rpc.argv = args.argv;
814814

815815
err = rpc_service(&rpc, heads);
816816
if (rpc.result.len)
817817
write_or_die(1, rpc.result.buf, rpc.result.len);
818818
strbuf_release(&rpc.result);
819-
free(argv);
819+
argv_array_clear(&args);
820820
return err;
821821
}
822822

0 commit comments

Comments
 (0)