strvec: convert more callers away from argv_array name

We eventually want to drop the argv_array name and just use strvec
consistently. There's no particular reason we have to do it all at once,
or care about interactions between converted and unconverted bits.
Because of our preprocessor compat layer, the names are interchangeable
to the compiler (so even a definition and declaration using different
names is OK).

This patch converts remaining files from the first half of the alphabet,
to keep the diff to a manageable size.

The conversion was done purely mechanically with:

  git ls-files '*.c' '*.h' |
  xargs perl -i -pe '
    s/ARGV_ARRAY/STRVEC/g;
    s/argv_array/strvec/g;
  '

and then selectively staging files with "git add '[abcdefghjkl]*'".
We'll deal with any indentation/style fallouts separately.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pull/825/merge
Jeff King 2 years ago committed by Junio C Hamano
parent 22f9b7f3f5
commit ef8d7ac42a
  1. 14
      add-interactive.c
  2. 28
      add-patch.c
  3. 12
      bisect.c
  4. 12
      bundle.c
  5. 2
      bundle.h
  6. 12
      column.c
  7. 8
      commit.c
  8. 4
      compat/mingw.c
  9. 18
      compat/terminal.c
  10. 48
      connect.c
  11. 22
      connected.c
  12. 52
      daemon.c
  13. 28
      diff.c
  14. 8
      environment.c
  15. 10
      exec-cmd.c
  16. 4
      fast-import.c
  17. 34
      fetch-pack.c
  18. 6
      fsmonitor.c
  19. 22
      git.c
  20. 8
      gpg-interface.c
  21. 10
      graph.c
  22. 4
      http-backend.c
  23. 12
      http-push.c
  24. 6
      http.c
  25. 2
      imap-send.c
  26. 6
      line-log.c
  27. 10
      ls-refs.c

@ -935,18 +935,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
opts->prompt = N_("Patch update");
count = list_and_choose(s, files, opts);
if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
struct pathspec ps_selected = { 0 };
for (i = 0; i < files->items.nr; i++)
if (files->selected[i])
argv_array_push(&args,
strvec_push(&args,
files->items.items[i].string);
parse_pathspec(&ps_selected,
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_LITERAL_PATH, "", args.argv);
res = run_add_p(s->r, ADD_P_ADD, NULL, &ps_selected);
argv_array_clear(&args);
strvec_clear(&args);
clear_pathspec(&ps_selected);
}
@ -976,18 +976,18 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
count = list_and_choose(s, files, opts);
opts->flags = 0;
if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
argv_array_pushl(&args, "git", "diff", "-p", "--cached",
strvec_pushl(&args, "git", "diff", "-p", "--cached",
oid_to_hex(!is_initial ? &oid :
s->r->hash_algo->empty_tree),
"--", NULL);
for (i = 0; i < files->items.nr; i++)
if (files->selected[i])
argv_array_push(&args,
strvec_push(&args,
files->items.items[i].string);
res = run_command_v_opt(args.argv, 0);
argv_array_clear(&args);
strvec_clear(&args);
}
putchar('\n');

@ -286,11 +286,11 @@ static void setup_child_process(struct add_p_state *s,
va_start(ap, cp);
while ((arg = va_arg(ap, const char *)))
argv_array_push(&cp->args, arg);
strvec_push(&cp->args, arg);
va_end(ap);
cp->git_cmd = 1;
argv_array_pushf(&cp->env_array,
strvec_pushf(&cp->env_array,
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
}
@ -370,7 +370,7 @@ static int is_octal(const char *p, size_t len)
static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
{
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
const char *diff_algorithm = s->s.interactive_diff_algorithm;
struct strbuf *plain = &s->plain, *colored = NULL;
struct child_process cp = CHILD_PROCESS_INIT;
@ -380,12 +380,12 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
struct hunk *hunk = NULL;
int res;
argv_array_pushv(&args, s->mode->diff_cmd);
strvec_pushv(&args, s->mode->diff_cmd);
if (diff_algorithm)
argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
strvec_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
if (s->revision) {
struct object_id oid;
argv_array_push(&args,
strvec_push(&args,
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
get_oid("HEAD", &oid) ?
@ -393,19 +393,19 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
}
color_arg_index = args.argc;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
argv_array_pushl(&args, "--no-color", "-p", "--", NULL);
strvec_pushl(&args, "--no-color", "-p", "--", NULL);
for (i = 0; i < ps->nr; i++)
argv_array_push(&args, ps->items[i].original);
strvec_push(&args, ps->items[i].original);
setup_child_process(s, &cp, NULL);
cp.argv = args.argv;
res = capture_command(&cp, plain, 0);
if (res) {
argv_array_clear(&args);
strvec_clear(&args);
return error(_("could not parse diff"));
}
if (!plain->len) {
argv_array_clear(&args);
strvec_clear(&args);
return 0;
}
strbuf_complete_line(plain);
@ -419,7 +419,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
colored_cp.argv = args.argv;
colored = &s->colored;
res = capture_command(&colored_cp, colored, 0);
argv_array_clear(&args);
strvec_clear(&args);
if (res)
return error(_("could not parse colored diff"));
@ -444,7 +444,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
colored_p = colored->buf;
colored_pend = colored_p + colored->len;
}
argv_array_clear(&args);
strvec_clear(&args);
/* parse files and hunks */
p = plain->buf;
@ -1158,7 +1158,7 @@ static int run_apply_check(struct add_p_state *s,
setup_child_process(s, &cp,
"apply", "--check", NULL);
argv_array_pushv(&cp.args, s->mode->apply_check_args);
strvec_pushv(&cp.args, s->mode->apply_check_args);
if (pipe_command(&cp, s->buf.buf, s->buf.len, NULL, 0, NULL, 0))
return error(_("'git apply --cached' failed"));
@ -1619,7 +1619,7 @@ soft_increment:
s->mode->is_reverse);
else {
setup_child_process(s, &cp, "apply", NULL);
argv_array_pushv(&cp.args, s->mode->apply_args);
strvec_pushv(&cp.args, s->mode->apply_args);
if (pipe_command(&cp, s->buf.buf, s->buf.len,
NULL, 0, NULL, 0))
error(_("'git apply' failed"));

@ -456,7 +456,7 @@ static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
static GIT_PATH_FUNC(git_path_head_name, "head-name")
static void read_bisect_paths(struct argv_array *array)
static void read_bisect_paths(struct strvec *array)
{
struct strbuf str = STRBUF_INIT;
const char *filename = git_path_bisect_names();
@ -632,7 +632,7 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
const char *bad_format, const char *good_format,
int read_paths)
{
struct argv_array rev_argv = ARGV_ARRAY_INIT;
struct strvec rev_argv = STRVEC_INIT;
int i;
repo_init_revisions(r, revs, prefix);
@ -640,12 +640,12 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
revs->commit_format = CMIT_FMT_UNSPECIFIED;
/* rev_argv.argv[0] will be ignored by setup_revisions */
argv_array_push(&rev_argv, "bisect_rev_setup");
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
strvec_push(&rev_argv, "bisect_rev_setup");
strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
for (i = 0; i < good_revs.nr; i++)
argv_array_pushf(&rev_argv, good_format,
strvec_pushf(&rev_argv, good_format,
oid_to_hex(good_revs.oid + i));
argv_array_push(&rev_argv, "--");
strvec_push(&rev_argv, "--");
if (read_paths)
read_bisect_paths(&rev_argv);

@ -269,16 +269,16 @@ out:
/* Write the pack data to bundle_fd */
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct argv_array *pack_options)
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options)
{
struct child_process pack_objects = CHILD_PROCESS_INIT;
int i;
argv_array_pushl(&pack_objects.args,
strvec_pushl(&pack_objects.args,
"pack-objects",
"--stdout", "--thin", "--delta-base-offset",
NULL);
argv_array_pushv(&pack_objects.args, pack_options->argv);
strvec_pushv(&pack_objects.args, pack_options->argv);
pack_objects.in = -1;
pack_objects.out = bundle_fd;
pack_objects.git_cmd = 1;
@ -321,11 +321,11 @@ static int compute_and_write_prerequisites(int bundle_fd,
FILE *rls_fout;
int i;
argv_array_pushl(&rls.args,
strvec_pushl(&rls.args,
"rev-list", "--boundary", "--pretty=oneline",
NULL);
for (i = 1; i < argc; i++)
argv_array_push(&rls.args, argv[i]);
strvec_push(&rls.args, argv[i]);
rls.out = -1;
rls.git_cmd = 1;
if (start_command(&rls))
@ -449,7 +449,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
}
int create_bundle(struct repository *r, const char *path,
int argc, const char **argv, struct argv_array *pack_options)
int argc, const char **argv, struct strvec *pack_options)
{
struct lock_file lock = LOCK_INIT;
int bundle_fd = -1;

@ -21,7 +21,7 @@ struct bundle_header {
int is_bundle(const char *path, int quiet);
int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct repository *r, const char *path,
int argc, const char **argv, struct argv_array *pack_options);
int argc, const char **argv, struct strvec *pack_options);
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
#define BUNDLE_VERBOSE 1
int unbundle(struct repository *r, struct bundle_header *header,

@ -358,7 +358,7 @@ static struct child_process column_process = CHILD_PROCESS_INIT;
int run_column_filter(int colopts, const struct column_options *opts)
{
struct argv_array *argv;
struct strvec *argv;
if (fd_out != -1)
return -1;
@ -366,14 +366,14 @@ int run_column_filter(int colopts, const struct column_options *opts)
child_process_init(&column_process);
argv = &column_process.args;
argv_array_push(argv, "column");
argv_array_pushf(argv, "--raw-mode=%d", colopts);
strvec_push(argv, "column");
strvec_pushf(argv, "--raw-mode=%d", colopts);
if (opts && opts->width)
argv_array_pushf(argv, "--width=%d", opts->width);
strvec_pushf(argv, "--width=%d", opts->width);
if (opts && opts->indent)
argv_array_pushf(argv, "--indent=%s", opts->indent);
strvec_pushf(argv, "--indent=%s", opts->indent);
if (opts && opts->padding)
argv_array_pushf(argv, "--padding=%d", opts->padding);
strvec_pushf(argv, "--padding=%d", opts->padding);
fflush(stdout);
column_process.in = -1;

@ -1630,22 +1630,22 @@ size_t ignore_non_trailer(const char *buf, size_t len)
int run_commit_hook(int editor_is_used, const char *index_file,
const char *name, ...)
{
struct argv_array hook_env = ARGV_ARRAY_INIT;
struct strvec hook_env = STRVEC_INIT;
va_list args;
int ret;
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
/*
* Let the hook know that no editor will be launched.
*/
if (!editor_is_used)
argv_array_push(&hook_env, "GIT_EDITOR=:");
strvec_push(&hook_env, "GIT_EDITOR=:");
va_start(args, name);
ret = run_hook_ve(hook_env.argv,name, args);
va_end(args);
argv_array_clear(&hook_env);
strvec_clear(&hook_env);
return ret;
}

@ -18,8 +18,8 @@ void open_in_gdb(void)
static struct child_process cp = CHILD_PROCESS_INIT;
extern char *_pgmptr;
argv_array_pushl(&cp.args, "mintty", "gdb", NULL);
argv_array_pushf(&cp.args, "--pid=%d", getpid());
strvec_pushl(&cp.args, "mintty", "gdb", NULL);
strvec_pushf(&cp.args, "--pid=%d", getpid());
cp.clean_on_exit = 1;
if (start_command(&cp) < 0)
die_errno("Could not start gdb");

@ -86,9 +86,9 @@ static void restore_term(void)
if (stty_restore.nr == 0)
return;
argv_array_push(&cp.args, "stty");
strvec_push(&cp.args, "stty");
for (i = 0; i < stty_restore.nr; i++)
argv_array_push(&cp.args, stty_restore.items[i].string);
strvec_push(&cp.args, stty_restore.items[i].string);
run_command(&cp);
string_list_clear(&stty_restore, 0);
return;
@ -107,25 +107,25 @@ static int disable_bits(DWORD bits)
if (use_stty) {
struct child_process cp = CHILD_PROCESS_INIT;
argv_array_push(&cp.args, "stty");
strvec_push(&cp.args, "stty");
if (bits & ENABLE_LINE_INPUT) {
string_list_append(&stty_restore, "icanon");
argv_array_push(&cp.args, "-icanon");
strvec_push(&cp.args, "-icanon");
}
if (bits & ENABLE_ECHO_INPUT) {
string_list_append(&stty_restore, "echo");
argv_array_push(&cp.args, "-echo");
strvec_push(&cp.args, "-echo");
}
if (bits & ENABLE_PROCESSED_INPUT) {
string_list_append(&stty_restore, "-ignbrk");
string_list_append(&stty_restore, "intr");
string_list_append(&stty_restore, "^c");
argv_array_push(&cp.args, "ignbrk");
argv_array_push(&cp.args, "intr");
argv_array_push(&cp.args, "");
strvec_push(&cp.args, "ignbrk");
strvec_push(&cp.args, "intr");
strvec_push(&cp.args, "");
}
if (run_command(&cp) == 0)
@ -273,7 +273,7 @@ static int is_known_escape_sequence(const char *sequence)
hashmap_init(&sequences, (hashmap_cmp_fn)sequence_entry_cmp,
NULL, 0);
argv_array_pushl(&cp.args, "infocmp", "-L", "-1", NULL);
strvec_pushl(&cp.args, "infocmp", "-L", "-1", NULL);
if (pipe_command(&cp, NULL, 0, &buf, 0, NULL, 0))
strbuf_setlen(&buf, 0);

@ -17,7 +17,7 @@
#include "alias.h"
static char *server_capabilities_v1;
static struct argv_array server_capabilities_v2 = ARGV_ARRAY_INIT;
static struct strvec server_capabilities_v2 = STRVEC_INIT;
static const char *next_server_feature_value(const char *feature, int *len, int *offset);
static int check_ref(const char *name, unsigned int flags)
@ -123,7 +123,7 @@ int server_supports_feature(const char *c, const char *feature,
static void process_capabilities_v2(struct packet_reader *reader)
{
while (packet_reader_read(reader) == PACKET_READ_NORMAL)
argv_array_push(&server_capabilities_v2, reader->line);
strvec_push(&server_capabilities_v2, reader->line);
if (reader->status != PACKET_READ_FLUSH)
die(_("expected flush after capabilities"));
@ -453,7 +453,7 @@ void check_stateless_delimiter(int stateless_rpc,
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
struct ref **list, int for_push,
const struct argv_array *ref_prefixes,
const struct strvec *ref_prefixes,
const struct string_list *server_options,
int stateless_rpc)
{
@ -944,9 +944,9 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
proxy = xmalloc(sizeof(*proxy));
child_process_init(proxy);
argv_array_push(&proxy->args, git_proxy_command);
argv_array_push(&proxy->args, host);
argv_array_push(&proxy->args, port);
strvec_push(&proxy->args, git_proxy_command);
strvec_push(&proxy->args, host);
strvec_push(&proxy->args, port);
proxy->in = -1;
proxy->out = -1;
if (start_command(proxy))
@ -1199,15 +1199,15 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
* Append the appropriate environment variables to `env` and options to
* `args` for running ssh in Git's SSH-tunneled transport.
*/
static void push_ssh_options(struct argv_array *args, struct argv_array *env,
static void push_ssh_options(struct strvec *args, struct strvec *env,
enum ssh_variant variant, const char *port,
enum protocol_version version, int flags)
{
if (variant == VARIANT_SSH &&
version > 0) {
argv_array_push(args, "-o");
argv_array_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
strvec_push(args, "-o");
strvec_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT);
strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
version);
}
@ -1221,7 +1221,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
case VARIANT_PLINK:
case VARIANT_PUTTY:
case VARIANT_TORTOISEPLINK:
argv_array_push(args, "-4");
strvec_push(args, "-4");
}
} else if (flags & CONNECT_IPV6) {
switch (variant) {
@ -1233,12 +1233,12 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
case VARIANT_PLINK:
case VARIANT_PUTTY:
case VARIANT_TORTOISEPLINK:
argv_array_push(args, "-6");
strvec_push(args, "-6");
}
}
if (variant == VARIANT_TORTOISEPLINK)
argv_array_push(args, "-batch");
strvec_push(args, "-batch");
if (port) {
switch (variant) {
@ -1247,15 +1247,15 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env,
case VARIANT_SIMPLE:
die(_("ssh variant 'simple' does not support setting port"));
case VARIANT_SSH:
argv_array_push(args, "-p");
strvec_push(args, "-p");
break;
case VARIANT_PLINK:
case VARIANT_PUTTY:
case VARIANT_TORTOISEPLINK:
argv_array_push(args, "-P");
strvec_push(args, "-P");
}
argv_array_push(args, port);
strvec_push(args, port);
}
}
@ -1293,18 +1293,18 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host,
detect.use_shell = conn->use_shell;
detect.no_stdin = detect.no_stdout = detect.no_stderr = 1;
argv_array_push(&detect.args, ssh);
argv_array_push(&detect.args, "-G");
strvec_push(&detect.args, ssh);
strvec_push(&detect.args, "-G");
push_ssh_options(&detect.args, &detect.env_array,
VARIANT_SSH, port, version, flags);
argv_array_push(&detect.args, ssh_host);
strvec_push(&detect.args, ssh_host);
variant = run_command(&detect) ? VARIANT_SIMPLE : VARIANT_SSH;
}
argv_array_push(&conn->args, ssh);
strvec_push(&conn->args, ssh);
push_ssh_options(&conn->args, &conn->env_array, variant, port, version, flags);
argv_array_push(&conn->args, ssh_host);
strvec_push(&conn->args, ssh_host);
}
/*
@ -1365,7 +1365,7 @@ struct child_process *git_connect(int fd[2], const char *url,
/* remove repo-local variables from the environment */
for (var = local_repo_env; *var; var++)
argv_array_push(&conn->env_array, *var);
strvec_push(&conn->env_array, *var);
conn->use_shell = 1;
conn->in = conn->out = -1;
@ -1397,11 +1397,11 @@ struct child_process *git_connect(int fd[2], const char *url,
transport_check_allowed("file");
conn->trace2_child_class = "transport/file";
if (version > 0) {
argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
strvec_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d",
version);
}
}
argv_array_push(&conn->args, cmd.buf);
strvec_push(&conn->args, cmd.buf);
if (start_command(conn))
die(_("unable to fork"));

@ -90,22 +90,22 @@ promisor_pack_found:
no_promisor_pack_found:
if (opt->shallow_file) {
argv_array_push(&rev_list.args, "--shallow-file");
argv_array_push(&rev_list.args, opt->shallow_file);
strvec_push(&rev_list.args, "--shallow-file");
strvec_push(&rev_list.args, opt->shallow_file);
}
argv_array_push(&rev_list.args,"rev-list");
argv_array_push(&rev_list.args, "--objects");
argv_array_push(&rev_list.args, "--stdin");
strvec_push(&rev_list.args,"rev-list");
strvec_push(&rev_list.args, "--objects");
strvec_push(&rev_list.args, "--stdin");
if (has_promisor_remote())
argv_array_push(&rev_list.args, "--exclude-promisor-objects");
strvec_push(&rev_list.args, "--exclude-promisor-objects");
if (!opt->is_deepening_fetch) {
argv_array_push(&rev_list.args, "--not");
argv_array_push(&rev_list.args, "--all");
strvec_push(&rev_list.args, "--not");
strvec_push(&rev_list.args, "--all");
}
argv_array_push(&rev_list.args, "--quiet");
argv_array_push(&rev_list.args, "--alternate-refs");
strvec_push(&rev_list.args, "--quiet");
strvec_push(&rev_list.args, "--alternate-refs");
if (opt->progress)
argv_array_pushf(&rev_list.args, "--progress=%s",
strvec_pushf(&rev_list.args, "--progress=%s",
_("Checking connectivity"));
rev_list.git_cmd = 1;

@ -296,7 +296,7 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
return NULL; /* Fallthrough. Deny by default */
}
typedef int (*daemon_service_fn)(const struct argv_array *env);
typedef int (*daemon_service_fn)(const struct strvec *env);
struct daemon_service {
const char *name;
const char *config_name;
@ -377,7 +377,7 @@ error_return:
}
static int run_service(const char *dir, struct daemon_service *service,
struct hostinfo *hi, const struct argv_array *env)
struct hostinfo *hi, const struct strvec *env)
{
const char *path;
int enabled = service->enabled;
@ -462,7 +462,7 @@ static void copy_to_log(int fd)
static int run_service_command(struct child_process *cld)
{
argv_array_push(&cld->args, ".");
strvec_push(&cld->args, ".");
cld->git_cmd = 1;
cld->err = -1;
if (start_command(cld))
@ -476,33 +476,33 @@ static int run_service_command(struct child_process *cld)
return finish_command(cld);
}
static int upload_pack(const struct argv_array *env)
static int upload_pack(const struct strvec *env)
{
struct child_process cld = CHILD_PROCESS_INIT;
argv_array_pushl(&cld.args, "upload-pack", "--strict", NULL);
argv_array_pushf(&cld.args, "--timeout=%u", timeout);
strvec_pushl(&cld.args, "upload-pack", "--strict", NULL);
strvec_pushf(&cld.args, "--timeout=%u", timeout);
argv_array_pushv(&cld.env_array, env->argv);
strvec_pushv(&cld.env_array, env->argv);
return run_service_command(&cld);
}
static int upload_archive(const struct argv_array *env)
static int upload_archive(const struct strvec *env)
{
struct child_process cld = CHILD_PROCESS_INIT;
argv_array_push(&cld.args, "upload-archive");
strvec_push(&cld.args, "upload-archive");
argv_array_pushv(&cld.env_array, env->argv);
strvec_pushv(&cld.env_array, env->argv);
return run_service_command(&cld);
}
static int receive_pack(const struct argv_array *env)
static int receive_pack(const struct strvec *env)
{
struct child_process cld = CHILD_PROCESS_INIT;
argv_array_push(&cld.args, "receive-pack");
strvec_push(&cld.args, "receive-pack");
argv_array_pushv(&cld.env_array, env->argv);
strvec_pushv(&cld.env_array, env->argv);
return run_service_command(&cld);
}
@ -633,7 +633,7 @@ static char *parse_host_arg(struct hostinfo *hi, char *extra_args, int buflen)
return extra_args;
}
static void parse_extra_args(struct hostinfo *hi, struct argv_array *env,
static void parse_extra_args(struct hostinfo *hi, struct strvec *env,
char *extra_args, int buflen)
{
const char *end = extra_args + buflen;
@ -664,7 +664,7 @@ static void parse_extra_args(struct hostinfo *hi, struct argv_array *env,
if (git_protocol.len > 0) {
loginfo("Extended attribute \"protocol\": %s", git_protocol.buf);
argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s",
strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s",
git_protocol.buf);
}
strbuf_release(&git_protocol);
@ -761,7 +761,7 @@ static int execute(void)
int pktlen, len, i;
char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT");
struct hostinfo hi;
struct argv_array env = ARGV_ARRAY_INIT;
struct strvec env = STRVEC_INIT;
hostinfo_init(&hi);
@ -794,13 +794,13 @@ static int execute(void)
*/
int rc = run_service(arg, s, &hi, &env);
hostinfo_clear(&hi);
argv_array_clear(&env);
strvec_clear(&env);
return rc;
}
}
hostinfo_clear(&hi);
argv_array_clear(&env);
strvec_clear(&env);
logerror("Protocol error: '%s'", line);
return -1;
}
@ -893,7 +893,7 @@ static void check_dead_children(void)
cradle = &blanket->next;
}
static struct argv_array cld_argv = ARGV_ARRAY_INIT;
static struct strvec cld_argv = STRVEC_INIT;
static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
{
struct child_process cld = CHILD_PROCESS_INIT;
@ -913,16 +913,16 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
char buf[128] = "";
struct sockaddr_in *sin_addr = (void *) addr;
inet_ntop(addr->sa_family, &sin_addr->sin_addr, buf, sizeof(buf));
argv_array_pushf(&cld.env_array, "REMOTE_ADDR=%s", buf);
argv_array_pushf(&cld.env_array, "REMOTE_PORT=%d",
strvec_pushf(&cld.env_array, "REMOTE_ADDR=%s", buf);
strvec_pushf(&cld.env_array, "REMOTE_PORT=%d",
ntohs(sin_addr->sin_port));
#ifndef NO_IPV6
} else if (addr->sa_family == AF_INET6) {
char buf[128] = "";
struct sockaddr_in6 *sin6_addr = (void *) addr;
inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(buf));
argv_array_pushf(&cld.env_array, "REMOTE_ADDR=[%s]", buf);
argv_array_pushf(&cld.env_array, "REMOTE_PORT=%d",
strvec_pushf(&cld.env_array, "REMOTE_ADDR=[%s]", buf);
strvec_pushf(&cld.env_array, "REMOTE_PORT=%d",
ntohs(sin6_addr->sin6_port));
#endif
}
@ -1476,10 +1476,10 @@ int cmd_main(int argc, const char **argv)
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
/* prepare argv for serving-processes */
argv_array_push(&cld_argv, argv[0]); /* git-daemon */
argv_array_push(&cld_argv, "--serve");
strvec_push(&cld_argv, argv[0]); /* git-daemon */
strvec_push(&cld_argv, "--serve");
for (i = 1; i < argc; ++i)
argv_array_push(&cld_argv, argv[i]);
strvec_push(&cld_argv, argv[i]);
return serve(&listen_addr, listen_port, cred);
}

@ -4192,14 +4192,14 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
}
static void add_external_diff_name(struct repository *r,
struct argv_array *argv,
struct strvec *argv,
const char *name,
struct diff_filespec *df)
{
struct diff_tempfile *temp = prepare_temp_file(r, name, df);
argv_array_push(argv, temp->name);
argv_array_push(argv, temp->hex);
argv_array_push(argv, temp->mode);
strvec_push(argv, temp->name);
strvec_push(argv, temp->hex);
strvec_push(argv, temp->mode);
}
/* An external diff command takes:
@ -4216,12 +4216,12 @@ static void run_external_diff(const char *pgm,
const char *xfrm_msg,
struct diff_options *o)
{
struct argv_array argv = ARGV_ARRAY_INIT;
struct argv_array env = ARGV_ARRAY_INIT;
struct strvec argv = STRVEC_INIT;
struct strvec env = STRVEC_INIT;
struct diff_queue_struct *q = &diff_queued_diff;
argv_array_push(&argv, pgm);
argv_array_push(&argv, name);
strvec_push(&argv, pgm);
strvec_push(&argv, name);
if (one && two) {
add_external_diff_name(o->repo, &argv, name, one);
@ -4229,13 +4229,13 @@ static void run_external_diff(const char *pgm,
add_external_diff_name(o->repo, &argv, name, two);
else {
add_external_diff_name(o->repo, &argv, other, two);
argv_array_push(&argv, other);
argv_array_push(&argv, xfrm_msg);
strvec_push(&argv, other);
strvec_push(&argv, xfrm_msg);
}
}
argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
strvec_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
strvec_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
diff_free_filespec_data(one);
diff_free_filespec_data(two);
@ -4243,8 +4243,8 @@ static void run_external_diff(const char *pgm,
die(_("external diff died, stopping at %s"), name);
remove_tempfile();
argv_array_clear(&argv);
argv_array_clear(&env);
strvec_clear(&argv);
strvec_clear(&env);
}
static int similarity_index(struct diff_filepair *p)

@ -156,14 +156,14 @@ static char *expand_namespace(const char *raw_namespace)
* Wrapper of getenv() that returns a strdup value. This value is kept
* in argv to be freed later.
*/
static const char *getenv_safe(struct argv_array *argv, const char *name)
static const char *getenv_safe(struct strvec *argv, const char *name)
{
const char *value = getenv(name);
if (!value)
return NULL;
argv_array_push(argv, value);
strvec_push(argv, value);
return argv->argv[argv->argc - 1];
}
@ -172,7 +172,7 @@ void setup_git_env(const char *git_dir)
const char *shallow_file;
const char *replace_ref_base;
struct set_gitdir_args args = { NULL };
struct argv_array to_free = ARGV_ARRAY_INIT;
struct strvec to_free = STRVEC_INIT;
args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT);
args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT);
@ -180,7 +180,7 @@ void setup_git_env(const char *git_dir)
args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
repo_set_gitdir(the_repository, git_dir, &args);
argv_array_clear(&to_free);
strvec_clear(&to_free);
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0;

@ -320,16 +320,16 @@ void setup_path(void)
strbuf_release(&new_path);
}
const char **prepare_git_cmd(struct argv_array *out, const char **argv)
const char **prepare_git_cmd(struct strvec *out, const char **argv)
{
argv_array_push(out, "git");
argv_array_pushv(out, argv);
strvec_push(out, "git");
strvec_pushv(out, argv);
return out->argv;
}
int execv_git_cmd(const char **argv)
{
struct argv_array nargv = ARGV_ARRAY_INIT;
struct strvec nargv = STRVEC_INIT;
prepare_git_cmd(&nargv, argv);
trace_argv_printf(nargv.argv, "trace: exec:");
@ -339,7 +339,7 @@ int execv_git_cmd(const char **argv)
trace_printf("trace: exec failed: %s\n", strerror(errno));
argv_array_clear(&nargv);
strvec_clear(&nargv);
return -1;
}

@ -843,9 +843,9 @@ static int loosen_small_pack(const struct packed_git *p)
unpack.in = p->pack_fd;
unpack.git_cmd = 1;
unpack.stdout_to_stderr = 1;
argv_array_push(&unpack.args, "unpack-objects");
strvec_push(&unpack.args, "unpack-objects");
if (!show_stats)
argv_array_push(&unpack.args, "-q");
strvec_push(&unpack.args, "-q");
return run_command(&unpack);
}

@ -835,30 +835,30 @@ static int get_pack(struct fetch_pack_args *args,
}
if (alternate_shallow_file) {
argv_array_push(&cmd.args, "--shallow-file");
argv_array_push(&cmd.args, alternate_shallow_file);
strvec_push(&cmd.args, "--shallow-file");
strvec_push(&cmd.args, alternate_shallow_file);
}
if (do_keep || args->from_promisor) {
if (pack_lockfiles)
cmd.out = -1;
cmd_name = "index-pack";
argv_array_push(&cmd.args, cmd_name);
argv_array_push(&cmd.args, "--stdin");
strvec_push(&cmd.args, cmd_name);
strvec_push(&cmd.args, "--stdin");
if (!args->quiet && !args->no_progress)
argv_array_push(&cmd.args, "-v");
strvec_push(&cmd.args, "-v");
if (args->use_thin_pack)
argv_array_push(&cmd.args, "--fix-thin");
strvec_push(&cmd.args, "--fix-thin");
if (do_keep && (args->lock_pack || unpack_limit)) {
char hostname[HOST_NAME_MAX + 1];
if (xgethostname(hostname, sizeof(hostname)))
xsnprintf(hostname, sizeof(hostname), "localhost");
argv_array_pushf(&cmd.args,
strvec_pushf(&cmd.args,
"--keep=fetch-pack %"PRIuMAX " on %s",
(uintmax_t)getpid(), hostname);
}
if (only_packfile && args->check_self_contained_and_connected)
argv_array_push(&cmd.args, "--check-self-contained-and-connected");
strvec_push(&cmd.args, "--check-self-contained-and-connected");
else
/*
* We cannot perform any connectivity checks because
@ -873,18 +873,18 @@ static int get_pack(struct fetch_pack_args *args,
* us.
*/
if (!(do_keep && pack_lockfiles) && args->from_promisor)
argv_array_push(&cmd.args, "--promisor");
strvec_push(&cmd.args, "--promisor");
}
else {
cmd_name = "unpack-objects";
argv_array_push(&cmd.args, cmd_name);
strvec_push(&cmd.args, cmd_name);
if (args->quiet || args->no_progress)
argv_array_push(&cmd.args, "-q");
strvec_push(&cmd.args, "-q");
args->check_self_contained_and_connected = 0;
}
if (pass_header)
argv_array_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32,
strvec_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32,
ntohl(header.hdr_version),
ntohl(header.hdr_entries));
if (fetch_fsck_objects >= 0
@ -898,9 +898,9 @@ static int get_pack(struct fetch_pack_args *args,
* checks both broken objects and links, but we only
* want to check for broken objects.
*/
argv_array_push(&cmd.args, "--fsck-objects");
strvec_push(&cmd.args, "--fsck-objects");
else
argv_array_pushf(&cmd.args, "--strict%s",
strvec_pushf(&cmd.args, "--strict%s",
fsck_msg_types.buf);
}
@ -1652,11 +1652,11 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
const char *uri = packfile_uris.items[i].string +
the_hash_algo->hexsz + 1;
argv_array_push(&cmd.args, "http-fetch");
argv_array_pushf(&cmd.args, "--packfile=%.*s",
strvec_push(&cmd.args, "http-fetch");
strvec_pushf(&cmd.args, "--packfile=%.*s",
(int) the_hash_algo->hexsz,
packfile_uris.items[i].string);
argv_array_push(&cmd.args, uri);
strvec_push(&cmd.args, uri);
cmd.git_cmd = 1;
cmd.no_stdin = 1;
cmd.out = -1;

@ -146,9 +146,9 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
if (!core_fsmonitor)
return -1;
argv_array_push(&cp.args, core_fsmonitor);
argv_array_pushf(&cp.args, "%d", version);
argv_array_pushf(&cp.args, "%s", last_update);
strvec_push(&cp.args, core_fsmonitor);
strvec_pushf(&cp.args, "%d", version);
strvec_pushf(&cp.args, "%s", last_update);
cp.use_shell = 1;
cp.dir = get_git_work_tree();

22
git.c

@ -349,8 +349,8 @@ static int handle_alias(int *argcp, const char ***argv)
child.clean_on_exit = 1;
child.wait_after_clean = 1;
child.trace2_child_class = "shell_alias";
argv_array_push(&child.args, alias_string + 1);
argv_array_pushv(&child.args, (*argv) + 1);
strvec_push(&child.args, alias_string + 1);
strvec_pushv(&child.args, (*argv) + 1);
trace2_cmd_alias(alias_command, child.args.argv);
trace2_cmd_list_config();
@ -646,7 +646,7 @@ static void strip_extension(const char **argv)
static void handle_builtin(int argc, const char **argv)
{
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
const char *cmd;
struct cmd_struct *builtin;
@ -661,9 +661,9 @@ static void handle_builtin(int argc, const char **argv)
argv[0] = cmd = "help";
for (i = 0; i < argc; i++) {
argv_array_push(&args, argv[i]);
strvec_push(&args, argv[i]);
if (!i)
argv_array_push(&args, "--exclude-guides");
strvec_push(&args, "--exclude-guides");
}
argc++;
@ -673,7 +673,7 @@ static void handle_builtin(int argc, const char **argv)
builtin = get_builtin(cmd);
if (builtin)
exit(run_builtin(builtin, argc, argv));
argv_array_clear(&args);
strvec_clear(&args);
}
static void execv_dashed_external(const char **argv)
@ -688,8 +688,8 @@ static void execv_dashed_external(const char **argv)
use_pager = check_pager_config(argv[0]);
commit_pager_choice();
argv_array_pushf(&cmd.args, "git-%s", argv[0]);
argv_array_pushv(&cmd.args, argv + 1);
strvec_pushf(&cmd.args, "git-%s", argv[0]);
strvec_pushv(&cmd.args, argv + 1);
cmd.clean_on_exit = 1;
cmd.wait_after_clean = 1;
cmd.silent_exec_failure = 1;
@ -741,7 +741,7 @@ static int run_argv(int *argcp, const char ***argv)
if (!done_alias)
handle_builtin(*argcp, *argv);
else if (get_builtin(**argv)) {
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
int i;
/*
@ -758,9 +758,9 @@ static int run_argv(int *argcp, const char ***argv)
commit_pager_choice();
argv_array_push(&args, "git");
strvec_push(&args, "git");
for (i = 0; i < *argcp; i++)
argv_array_push(&args, (*argv)[i]);
strvec_push(&args, (*argv)[i]);
trace_argv_printf(args.argv, "trace: exec:");

@ -282,9 +282,9 @@ static int verify_signed_buffer(const char *payload, size_t payload_size,
if (!fmt)
BUG("bad signature '%s'", signature);
argv_array_push(&gpg.args, fmt->program);
argv_array_pushv(&gpg.args, fmt->verify_args);
argv_array_pushl(&gpg.args,
strvec_push(&gpg.args, fmt->program);
strvec_pushv(&gpg.args, fmt->verify_args);
strvec_pushl(&gpg.args,
"--status-fd=1",
"--verify", temp->filename.buf, "-",
NULL);
@ -434,7 +434,7 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
size_t i, j, bottom;
struct strbuf gpg_status = STRBUF_INIT;
argv_array_pushl(&gpg.args,
strvec_pushl(&gpg.args,
use_format->program,
"--status-fd=2",
"-bsau", signing_key,

@ -82,7 +82,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
static const char **column_colors;
static unsigned short column_colors_max;
static void parse_graph_colors_config(struct argv_array *colors, const char *string)
static void parse_graph_colors_config(struct strvec *colors, const char *string)
{
const char *end, *start;
@ -93,13 +93,13 @@ static void parse_graph_colors_config(struct argv_array *colors, const char *str
char color[COLOR_MAXLEN];
if (!color_parse_mem(start, comma - start, color))
argv_array_push(colors, color);
strvec_push(colors, color);
else
warning(_("ignore invalid color '%.*s' in log.graphColors"),
(int)(comma - start), start);
start = comma + 1;
}
argv_array_push(colors, GIT_COLOR_RESET);
strvec_push(colors, GIT_COLOR_RESET);
}
void graph_set_column_colors(const char **colors, unsigned short colors_max)
@ -350,8 +350,8 @@ struct git_graph *graph_init(struct rev_info *opt)
graph_set_column_colors(column_colors_ansi,
column_colors_ansi_max);
} else {
static struct argv_array custom_colors = ARGV_ARRAY_INIT;
argv_array_clear(&custom_colors);
static struct strvec custom_colors = STRVEC_INIT;
strvec_clear(&custom_colors);
parse_graph_colors_config(&custom_colors, string);
free(string);
/* graph_set_column_colors takes a max-index, not a count */