Merge branch 'jk/strvec'

The argv_array API is useful for not just managing argv but any
"vector" (NULL-terminated array) of strings, and has seen adoption
to a certain degree.  It has been renamed to "strvec" to reduce the
barrier to adoption.

* jk/strvec:
  strvec: rename struct fields
  strvec: drop argv_array compatibility layer
  strvec: update documention to avoid argv_array
  strvec: fix indentation in renamed calls
  strvec: convert remaining callers away from argv_array name
  strvec: convert more callers away from argv_array name
  strvec: convert builtin/ callers away from argv_array name
  quote: rename sq_dequote_to_argv_array to mention strvec
  strvec: rename files from argv-array to strvec
  argv-array: rename to strvec
  argv-array: use size_t for count and alloc
This commit is contained in:
Junio C Hamano 2020-08-10 10:23:57 -07:00
commit 46b225f153
105 changed files with 1619 additions and 1620 deletions

View file

@ -232,9 +232,9 @@ There are some macros to easily define options:
will be overwritten, so this should only be used for options where will be overwritten, so this should only be used for options where
the last one specified on the command line wins. the last one specified on the command line wins.
`OPT_PASSTHRU_ARGV(short, long, &argv_array_var, arg_str, description, flags)`:: `OPT_PASSTHRU_ARGV(short, long, &strvec_var, arg_str, description, flags)`::
Introduce an option where all instances of it on the command-line will Introduce an option where all instances of it on the command-line will
be reconstructed into an argv_array. This is useful when you need to be reconstructed into a strvec. This is useful when you need to
pass the command-line option, which can be specified multiple times, pass the command-line option, which can be specified multiple times,
to another command. to another command.

View file

@ -828,7 +828,6 @@ LIB_OBJS += apply.o
LIB_OBJS += archive-tar.o LIB_OBJS += archive-tar.o
LIB_OBJS += archive-zip.o LIB_OBJS += archive-zip.o
LIB_OBJS += archive.o LIB_OBJS += archive.o
LIB_OBJS += argv-array.o
LIB_OBJS += attr.o LIB_OBJS += attr.o
LIB_OBJS += base85.o LIB_OBJS += base85.o
LIB_OBJS += bisect.o LIB_OBJS += bisect.o
@ -986,6 +985,7 @@ LIB_OBJS += sigchain.o
LIB_OBJS += split-index.o LIB_OBJS += split-index.o
LIB_OBJS += stable-qsort.o LIB_OBJS += stable-qsort.o
LIB_OBJS += strbuf.o LIB_OBJS += strbuf.o
LIB_OBJS += strvec.o
LIB_OBJS += streaming.o LIB_OBJS += streaming.o
LIB_OBJS += string-list.o LIB_OBJS += string-list.o
LIB_OBJS += sub-process.o LIB_OBJS += sub-process.o

View file

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

View file

@ -2,7 +2,7 @@
#include "add-interactive.h" #include "add-interactive.h"
#include "strbuf.h" #include "strbuf.h"
#include "run-command.h" #include "run-command.h"
#include "argv-array.h" #include "strvec.h"
#include "pathspec.h" #include "pathspec.h"
#include "color.h" #include "color.h"
#include "diff.h" #include "diff.h"
@ -286,12 +286,12 @@ static void setup_child_process(struct add_p_state *s,
va_start(ap, cp); va_start(ap, cp);
while ((arg = va_arg(ap, const char *))) while ((arg = va_arg(ap, const char *)))
argv_array_push(&cp->args, arg); strvec_push(&cp->args, arg);
va_end(ap); va_end(ap);
cp->git_cmd = 1; cp->git_cmd = 1;
argv_array_pushf(&cp->env_array, strvec_pushf(&cp->env_array,
INDEX_ENVIRONMENT "=%s", s->s.r->index_file); INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
} }
static int parse_range(const char **p, static int parse_range(const char **p,
@ -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) 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; const char *diff_algorithm = s->s.interactive_diff_algorithm;
struct strbuf *plain = &s->plain, *colored = NULL; struct strbuf *plain = &s->plain, *colored = NULL;
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
@ -380,32 +380,32 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
struct hunk *hunk = NULL; struct hunk *hunk = NULL;
int res; int res;
argv_array_pushv(&args, s->mode->diff_cmd); strvec_pushv(&args, s->mode->diff_cmd);
if (diff_algorithm) if (diff_algorithm)
argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm); strvec_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
if (s->revision) { if (s->revision) {
struct object_id oid; struct object_id oid;
argv_array_push(&args, strvec_push(&args,
/* could be on an unborn branch */ /* could be on an unborn branch */
!strcmp("HEAD", s->revision) && !strcmp("HEAD", s->revision) &&
get_oid("HEAD", &oid) ? get_oid("HEAD", &oid) ?
empty_tree_oid_hex() : s->revision); empty_tree_oid_hex() : s->revision);
} }
color_arg_index = args.argc; color_arg_index = args.nr;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */ /* 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++) 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); setup_child_process(s, &cp, NULL);
cp.argv = args.argv; cp.argv = args.v;
res = capture_command(&cp, plain, 0); res = capture_command(&cp, plain, 0);
if (res) { if (res) {
argv_array_clear(&args); strvec_clear(&args);
return error(_("could not parse diff")); return error(_("could not parse diff"));
} }
if (!plain->len) { if (!plain->len) {
argv_array_clear(&args); strvec_clear(&args);
return 0; return 0;
} }
strbuf_complete_line(plain); strbuf_complete_line(plain);
@ -415,11 +415,11 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
const char *diff_filter = s->s.interactive_diff_filter; const char *diff_filter = s->s.interactive_diff_filter;
setup_child_process(s, &colored_cp, NULL); setup_child_process(s, &colored_cp, NULL);
xsnprintf((char *)args.argv[color_arg_index], 8, "--color"); xsnprintf((char *)args.v[color_arg_index], 8, "--color");
colored_cp.argv = args.argv; colored_cp.argv = args.v;
colored = &s->colored; colored = &s->colored;
res = capture_command(&colored_cp, colored, 0); res = capture_command(&colored_cp, colored, 0);
argv_array_clear(&args); strvec_clear(&args);
if (res) if (res)
return error(_("could not parse colored diff")); 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_p = colored->buf;
colored_pend = colored_p + colored->len; colored_pend = colored_p + colored->len;
} }
argv_array_clear(&args); strvec_clear(&args);
/* parse files and hunks */ /* parse files and hunks */
p = plain->buf; p = plain->buf;
@ -1158,7 +1158,7 @@ static int run_apply_check(struct add_p_state *s,
setup_child_process(s, &cp, setup_child_process(s, &cp,
"apply", "--check", NULL); "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)) if (pipe_command(&cp, s->buf.buf, s->buf.len, NULL, 0, NULL, 0))
return error(_("'git apply --cached' failed")); return error(_("'git apply --cached' failed"));
@ -1619,7 +1619,7 @@ static int patch_update_file(struct add_p_state *s,
s->mode->is_reverse); s->mode->is_reverse);
else { else {
setup_child_process(s, &cp, "apply", NULL); 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, if (pipe_command(&cp, s->buf.buf, s->buf.len,
NULL, 0, NULL, 0)) NULL, 0, NULL, 0))
error(_("'git apply' failed")); error(_("'git apply' failed"));

View file

@ -1,109 +0,0 @@
#include "cache.h"
#include "argv-array.h"
#include "strbuf.h"
const char *empty_argv[] = { NULL };
void argv_array_init(struct argv_array *array)
{
array->argv = empty_argv;
array->argc = 0;
array->alloc = 0;
}
static void argv_array_push_nodup(struct argv_array *array, const char *value)
{
if (array->argv == empty_argv)
array->argv = NULL;
ALLOC_GROW(array->argv, array->argc + 2, array->alloc);
array->argv[array->argc++] = value;
array->argv[array->argc] = NULL;
}
const char *argv_array_push(struct argv_array *array, const char *value)
{
argv_array_push_nodup(array, xstrdup(value));
return array->argv[array->argc - 1];
}
const char *argv_array_pushf(struct argv_array *array, const char *fmt, ...)
{
va_list ap;
struct strbuf v = STRBUF_INIT;
va_start(ap, fmt);
strbuf_vaddf(&v, fmt, ap);
va_end(ap);
argv_array_push_nodup(array, strbuf_detach(&v, NULL));
return array->argv[array->argc - 1];
}
void argv_array_pushl(struct argv_array *array, ...)
{
va_list ap;
const char *arg;
va_start(ap, array);
while ((arg = va_arg(ap, const char *)))
argv_array_push(array, arg);
va_end(ap);
}
void argv_array_pushv(struct argv_array *array, const char **argv)
{
for (; *argv; argv++)
argv_array_push(array, *argv);
}
void argv_array_pop(struct argv_array *array)
{
if (!array->argc)
return;
free((char *)array->argv[array->argc - 1]);
array->argv[array->argc - 1] = NULL;
array->argc--;
}
void argv_array_split(struct argv_array *array, const char *to_split)
{
while (isspace(*to_split))
to_split++;
for (;;) {
const char *p = to_split;
if (!*p)
break;
while (*p && !isspace(*p))
p++;
argv_array_push_nodup(array, xstrndup(to_split, p - to_split));
while (isspace(*p))
p++;
to_split = p;
}
}
void argv_array_clear(struct argv_array *array)
{
if (array->argv != empty_argv) {
int i;
for (i = 0; i < array->argc; i++)
free((char *)array->argv[i]);
free(array->argv);
}
argv_array_init(array);
}
const char **argv_array_detach(struct argv_array *array)
{
if (array->argv == empty_argv)
return xcalloc(1, sizeof(const char *));
else {
const char **ret = array->argv;
argv_array_init(array);
return ret;
}
}

View file

@ -11,7 +11,7 @@
#include "log-tree.h" #include "log-tree.h"
#include "bisect.h" #include "bisect.h"
#include "oid-array.h" #include "oid-array.h"
#include "argv-array.h" #include "strvec.h"
#include "commit-slab.h" #include "commit-slab.h"
#include "commit-reach.h" #include "commit-reach.h"
#include "object-store.h" #include "object-store.h"
@ -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_bisect_terms, "BISECT_TERMS")
static GIT_PATH_FUNC(git_path_head_name, "head-name") 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; struct strbuf str = STRBUF_INIT;
const char *filename = git_path_bisect_names(); const char *filename = git_path_bisect_names();
@ -464,7 +464,7 @@ static void read_bisect_paths(struct argv_array *array)
while (strbuf_getline_lf(&str, fp) != EOF) { while (strbuf_getline_lf(&str, fp) != EOF) {
strbuf_trim(&str); strbuf_trim(&str);
if (sq_dequote_to_argv_array(str.buf, array)) if (sq_dequote_to_strvec(str.buf, array))
die(_("Badly quoted content in file '%s': %s"), die(_("Badly quoted content in file '%s': %s"),
filename, str.buf); filename, str.buf);
} }
@ -632,7 +632,7 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
const char *bad_format, const char *good_format, const char *bad_format, const char *good_format,
int read_paths) int read_paths)
{ {
struct argv_array rev_argv = ARGV_ARRAY_INIT; struct strvec rev_argv = STRVEC_INIT;
int i; int i;
repo_init_revisions(r, revs, prefix); repo_init_revisions(r, revs, prefix);
@ -640,16 +640,16 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
revs->commit_format = CMIT_FMT_UNSPECIFIED; revs->commit_format = CMIT_FMT_UNSPECIFIED;
/* rev_argv.argv[0] will be ignored by setup_revisions */ /* rev_argv.argv[0] will be ignored by setup_revisions */
argv_array_push(&rev_argv, "bisect_rev_setup"); strvec_push(&rev_argv, "bisect_rev_setup");
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid)); strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
for (i = 0; i < good_revs.nr; i++) 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)); oid_to_hex(good_revs.oid + i));
argv_array_push(&rev_argv, "--"); strvec_push(&rev_argv, "--");
if (read_paths) if (read_paths)
read_bisect_paths(&rev_argv); read_bisect_paths(&rev_argv);
setup_revisions(rev_argv.argc, rev_argv.argv, revs, NULL); setup_revisions(rev_argv.nr, rev_argv.v, revs, NULL);
/* XXX leak rev_argv, as "revs" may still be pointing to it */ /* XXX leak rev_argv, as "revs" may still be pointing to it */
} }

View file

@ -18,7 +18,7 @@
#include "diffcore.h" #include "diffcore.h"
#include "revision.h" #include "revision.h"
#include "bulk-checkin.h" #include "bulk-checkin.h"
#include "argv-array.h" #include "strvec.h"
#include "submodule.h" #include "submodule.h"
#include "add-interactive.h" #include "add-interactive.h"
@ -188,7 +188,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
const struct pathspec *pathspec) const struct pathspec *pathspec)
{ {
int status, i; int status, i;
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
int use_builtin_add_i = int use_builtin_add_i =
git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1); git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
@ -218,18 +218,18 @@ int run_add_interactive(const char *revision, const char *patch_mode,
return !!run_add_p(the_repository, mode, revision, pathspec); return !!run_add_p(the_repository, mode, revision, pathspec);
} }
argv_array_push(&argv, "add--interactive"); strvec_push(&argv, "add--interactive");
if (patch_mode) if (patch_mode)
argv_array_push(&argv, patch_mode); strvec_push(&argv, patch_mode);
if (revision) if (revision)
argv_array_push(&argv, revision); strvec_push(&argv, revision);
argv_array_push(&argv, "--"); strvec_push(&argv, "--");
for (i = 0; i < pathspec->nr; i++) for (i = 0; i < pathspec->nr; i++)
/* pass original pathspec, to be re-parsed */ /* pass original pathspec, to be re-parsed */
argv_array_push(&argv, pathspec->items[i].original); strvec_push(&argv, pathspec->items[i].original);
status = run_command_v_opt(argv.argv, RUN_GIT_CMD); status = run_command_v_opt(argv.v, RUN_GIT_CMD);
argv_array_clear(&argv); strvec_clear(&argv);
return status; return status;
} }

View file

@ -116,7 +116,7 @@ struct am_state {
int keep; /* enum keep_type */ int keep; /* enum keep_type */
int message_id; int message_id;
int scissors; /* enum scissors_type */ int scissors; /* enum scissors_type */
struct argv_array git_apply_opts; struct strvec git_apply_opts;
const char *resolvemsg; const char *resolvemsg;
int committer_date_is_author_date; int committer_date_is_author_date;
int ignore_date; int ignore_date;
@ -146,7 +146,7 @@ static void am_state_init(struct am_state *state)
state->scissors = SCISSORS_UNSET; state->scissors = SCISSORS_UNSET;
argv_array_init(&state->git_apply_opts); strvec_init(&state->git_apply_opts);
if (!git_config_get_bool("commit.gpgsign", &gpgsign)) if (!git_config_get_bool("commit.gpgsign", &gpgsign))
state->sign_commit = gpgsign ? "" : NULL; state->sign_commit = gpgsign ? "" : NULL;
@ -162,7 +162,7 @@ static void am_state_release(struct am_state *state)
free(state->author_email); free(state->author_email);
free(state->author_date); free(state->author_date);
free(state->msg); free(state->msg);
argv_array_clear(&state->git_apply_opts); strvec_clear(&state->git_apply_opts);
} }
/** /**
@ -398,8 +398,8 @@ static void am_load(struct am_state *state)
state->scissors = SCISSORS_UNSET; state->scissors = SCISSORS_UNSET;
read_state_file(&sb, state, "apply-opt", 1); read_state_file(&sb, state, "apply-opt", 1);
argv_array_clear(&state->git_apply_opts); strvec_clear(&state->git_apply_opts);
if (sq_dequote_to_argv_array(sb.buf, &state->git_apply_opts) < 0) if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0)
die(_("could not parse %s"), am_path(state, "apply-opt")); die(_("could not parse %s"), am_path(state, "apply-opt"));
state->rebasing = !!file_exists(am_path(state, "rebasing")); state->rebasing = !!file_exists(am_path(state, "rebasing"));
@ -452,8 +452,8 @@ static int run_post_rewrite_hook(const struct am_state *state)
if (!hook) if (!hook)
return 0; return 0;
argv_array_push(&cp.args, hook); strvec_push(&cp.args, hook);
argv_array_push(&cp.args, "rebase"); strvec_push(&cp.args, "rebase");
cp.in = xopen(am_path(state, "rewritten"), O_RDONLY); cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
cp.stdout_to_stderr = 1; cp.stdout_to_stderr = 1;
@ -651,16 +651,16 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
int ret; int ret;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_push(&cp.args, "mailsplit"); strvec_push(&cp.args, "mailsplit");
argv_array_pushf(&cp.args, "-d%d", state->prec); strvec_pushf(&cp.args, "-d%d", state->prec);
argv_array_pushf(&cp.args, "-o%s", state->dir); strvec_pushf(&cp.args, "-o%s", state->dir);
argv_array_push(&cp.args, "-b"); strvec_push(&cp.args, "-b");
if (keep_cr) if (keep_cr)
argv_array_push(&cp.args, "--keep-cr"); strvec_push(&cp.args, "--keep-cr");
if (mboxrd) if (mboxrd)
argv_array_push(&cp.args, "--mboxrd"); strvec_push(&cp.args, "--mboxrd");
argv_array_push(&cp.args, "--"); strvec_push(&cp.args, "--");
argv_array_pushv(&cp.args, paths); strvec_pushv(&cp.args, paths);
ret = capture_command(&cp, &last, 8); ret = capture_command(&cp, &last, 8);
if (ret) if (ret)
@ -787,7 +787,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
const char *series_dir; const char *series_dir;
char *series_dir_buf; char *series_dir_buf;
FILE *fp; FILE *fp;
struct argv_array patches = ARGV_ARRAY_INIT; struct strvec patches = STRVEC_INIT;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
int ret; int ret;
@ -805,16 +805,16 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
if (*sb.buf == '#') if (*sb.buf == '#')
continue; /* skip comment lines */ continue; /* skip comment lines */
argv_array_push(&patches, mkpath("%s/%s", series_dir, sb.buf)); strvec_push(&patches, mkpath("%s/%s", series_dir, sb.buf));
} }
fclose(fp); fclose(fp);
strbuf_release(&sb); strbuf_release(&sb);
free(series_dir_buf); free(series_dir_buf);
ret = split_mail_conv(stgit_patch_to_mail, state, patches.argv, keep_cr); ret = split_mail_conv(stgit_patch_to_mail, state, patches.v, keep_cr);
argv_array_clear(&patches); strvec_clear(&patches);
return ret; return ret;
} }
@ -1002,7 +1002,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
} }
write_state_text(state, "scissors", str); write_state_text(state, "scissors", str);
sq_quote_argv(&sb, state->git_apply_opts.argv); sq_quote_argv(&sb, state->git_apply_opts.v);
write_state_text(state, "apply-opt", sb.buf); write_state_text(state, "apply-opt", sb.buf);
if (state->rebasing) if (state->rebasing)
@ -1390,8 +1390,8 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
*/ */
static int run_apply(const struct am_state *state, const char *index_file) static int run_apply(const struct am_state *state, const char *index_file)
{ {
struct argv_array apply_paths = ARGV_ARRAY_INIT; struct strvec apply_paths = STRVEC_INIT;
struct argv_array apply_opts = ARGV_ARRAY_INIT; struct strvec apply_opts = STRVEC_INIT;
struct apply_state apply_state; struct apply_state apply_state;
int res, opts_left; int res, opts_left;
int force_apply = 0; int force_apply = 0;
@ -1400,10 +1400,10 @@ static int run_apply(const struct am_state *state, const char *index_file)
if (init_apply_state(&apply_state, the_repository, NULL)) if (init_apply_state(&apply_state, the_repository, NULL))
BUG("init_apply_state() failed"); BUG("init_apply_state() failed");
argv_array_push(&apply_opts, "apply"); strvec_push(&apply_opts, "apply");
argv_array_pushv(&apply_opts, state->git_apply_opts.argv); strvec_pushv(&apply_opts, state->git_apply_opts.v);
opts_left = apply_parse_options(apply_opts.argc, apply_opts.argv, opts_left = apply_parse_options(apply_opts.nr, apply_opts.v,
&apply_state, &force_apply, &options, &apply_state, &force_apply, &options,
NULL); NULL);
@ -1426,12 +1426,12 @@ static int run_apply(const struct am_state *state, const char *index_file)
if (check_apply_state(&apply_state, force_apply)) if (check_apply_state(&apply_state, force_apply))
BUG("check_apply_state() failed"); BUG("check_apply_state() failed");
argv_array_push(&apply_paths, am_path(state, "patch")); strvec_push(&apply_paths, am_path(state, "patch"));
res = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options); res = apply_all_patches(&apply_state, apply_paths.nr, apply_paths.v, options);
argv_array_clear(&apply_paths); strvec_clear(&apply_paths);
argv_array_clear(&apply_opts); strvec_clear(&apply_opts);
clear_apply_state(&apply_state); clear_apply_state(&apply_state);
if (res) if (res)
@ -1454,10 +1454,10 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_push(&cp.args, "apply"); strvec_push(&cp.args, "apply");
argv_array_pushv(&cp.args, state->git_apply_opts.argv); strvec_pushv(&cp.args, state->git_apply_opts.v);
argv_array_pushf(&cp.args, "--build-fake-ancestor=%s", index_file); strvec_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
argv_array_push(&cp.args, am_path(state, "patch")); strvec_push(&cp.args, am_path(state, "patch"));
if (run_command(&cp)) if (run_command(&cp))
return -1; return -1;
@ -1676,7 +1676,7 @@ static int do_interactive(struct am_state *state)
if (!pager) if (!pager)
pager = "cat"; pager = "cat";
prepare_pager_args(&cp, pager); prepare_pager_args(&cp, pager);
argv_array_push(&cp.args, am_path(state, "patch")); strvec_push(&cp.args, am_path(state, "patch"));
run_command(&cp); run_command(&cp);
} }
} }
@ -2346,7 +2346,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
if (state.signoff == SIGNOFF_EXPLICIT) if (state.signoff == SIGNOFF_EXPLICIT)
am_append_signoff(&state); am_append_signoff(&state);
} else { } else {
struct argv_array paths = ARGV_ARRAY_INIT; struct strvec paths = STRVEC_INIT;
int i; int i;
/* /*
@ -2371,17 +2371,17 @@ int cmd_am(int argc, const char **argv, const char *prefix)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
if (is_absolute_path(argv[i]) || !prefix) if (is_absolute_path(argv[i]) || !prefix)
argv_array_push(&paths, argv[i]); strvec_push(&paths, argv[i]);
else else
argv_array_push(&paths, mkpath("%s/%s", prefix, argv[i])); strvec_push(&paths, mkpath("%s/%s", prefix, argv[i]));
} }
if (state.interactive && !paths.argc) if (state.interactive && !paths.nr)
die(_("interactive mode requires patches on the command line")); die(_("interactive mode requires patches on the command line"));
am_setup(&state, patch_format, paths.argv, keep_cr); am_setup(&state, patch_format, paths.v, keep_cr);
argv_array_clear(&paths); strvec_clear(&paths);
} }
switch (resume.mode) { switch (resume.mode) {

View file

@ -5,18 +5,18 @@
*/ */
#include "git-compat-util.h" #include "git-compat-util.h"
#include "builtin.h" #include "builtin.h"
#include "argv-array.h" #include "strvec.h"
int cmd_annotate(int argc, const char **argv, const char *prefix) int cmd_annotate(int argc, const char **argv, const char *prefix)
{ {
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
int i; int i;
argv_array_pushl(&args, "annotate", "-c", NULL); strvec_pushl(&args, "annotate", "-c", NULL);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
argv_array_push(&args, argv[i]); strvec_push(&args, argv[i]);
} }
return cmd_blame(args.argc, args.argv, prefix); return cmd_blame(args.nr, args.v, prefix);
} }

View file

@ -4,7 +4,7 @@
#include "bisect.h" #include "bisect.h"
#include "refs.h" #include "refs.h"
#include "dir.h" #include "dir.h"
#include "argv-array.h" #include "strvec.h"
#include "run-command.h" #include "run-command.h"
#include "prompt.h" #include "prompt.h"
#include "quote.h" #include "quote.h"
@ -164,18 +164,18 @@ static int bisect_reset(const char *commit)
} }
if (!ref_exists("BISECT_HEAD")) { if (!ref_exists("BISECT_HEAD")) {
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL); strvec_pushl(&argv, "checkout", branch.buf, "--", NULL);
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
error(_("could not check out original" error(_("could not check out original"
" HEAD '%s'. Try 'git bisect" " HEAD '%s'. Try 'git bisect"
" reset <commit>'."), branch.buf); " reset <commit>'."), branch.buf);
strbuf_release(&branch); strbuf_release(&branch);
argv_array_clear(&argv); strvec_clear(&argv);
return -1; return -1;
} }
argv_array_clear(&argv); strvec_clear(&argv);
} }
strbuf_release(&branch); strbuf_release(&branch);
@ -525,11 +525,11 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
strbuf_read_file(&start_head, git_path_bisect_start(), 0); strbuf_read_file(&start_head, git_path_bisect_start(), 0);
strbuf_trim(&start_head); strbuf_trim(&start_head);
if (!no_checkout) { if (!no_checkout) {
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
argv_array_pushl(&argv, "checkout", start_head.buf, strvec_pushl(&argv, "checkout", start_head.buf,
"--", NULL); "--", NULL);
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
res = error(_("checking out '%s' failed." res = error(_("checking out '%s' failed."
" Try 'git bisect start " " Try 'git bisect start "
"<valid-branch>'."), "<valid-branch>'."),

View file

@ -1,5 +1,5 @@
#include "builtin.h" #include "builtin.h"
#include "argv-array.h" #include "strvec.h"
#include "parse-options.h" #include "parse-options.h"
#include "cache.h" #include "cache.h"
#include "bundle.h" #include "bundle.h"
@ -59,7 +59,7 @@ static int parse_options_cmd_bundle(int argc,
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
int all_progress_implied = 0; int all_progress_implied = 0;
int progress = isatty(STDERR_FILENO); int progress = isatty(STDERR_FILENO);
struct argv_array pack_opts; struct strvec pack_opts;
struct option options[] = { struct option options[] = {
OPT_SET_INT('q', "quiet", &progress, OPT_SET_INT('q', "quiet", &progress,
@ -79,15 +79,15 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
builtin_bundle_create_usage, options, &bundle_file); builtin_bundle_create_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */ /* bundle internals use argv[1] as further parameters */
argv_array_init(&pack_opts); strvec_init(&pack_opts);
if (progress == 0) if (progress == 0)
argv_array_push(&pack_opts, "--quiet"); strvec_push(&pack_opts, "--quiet");
else if (progress == 1) else if (progress == 1)
argv_array_push(&pack_opts, "--progress"); strvec_push(&pack_opts, "--progress");
else if (progress == 2) else if (progress == 2)
argv_array_push(&pack_opts, "--all-progress"); strvec_push(&pack_opts, "--all-progress");
if (progress && all_progress_implied) if (progress && all_progress_implied)
argv_array_push(&pack_opts, "--all-progress-implied"); strvec_push(&pack_opts, "--all-progress-implied");
if (!startup_info->have_repository) if (!startup_info->have_repository)
die(_("Need a repository to create a bundle.")); die(_("Need a repository to create a bundle."));

View file

@ -742,9 +742,9 @@ static void update_head(const struct ref *our, const struct ref *remote,
static int git_sparse_checkout_init(const char *repo) static int git_sparse_checkout_init(const char *repo)
{ {
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
int result = 0; int result = 0;
argv_array_pushl(&argv, "-C", repo, "sparse-checkout", "init", NULL); strvec_pushl(&argv, "-C", repo, "sparse-checkout", "init", NULL);
/* /*
* We must apply the setting in the current process * We must apply the setting in the current process
@ -752,12 +752,12 @@ static int git_sparse_checkout_init(const char *repo)
*/ */
core_apply_sparse_checkout = 1; core_apply_sparse_checkout = 1;
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
error(_("failed to initialize sparse-checkout")); error(_("failed to initialize sparse-checkout"));
result = 1; result = 1;
} }
argv_array_clear(&argv); strvec_clear(&argv);
return result; return result;
} }
@ -819,33 +819,33 @@ static int checkout(int submodule_progress)
oid_to_hex(&oid), "1", NULL); oid_to_hex(&oid), "1", NULL);
if (!err && (option_recurse_submodules.nr > 0)) { if (!err && (option_recurse_submodules.nr > 0)) {
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
argv_array_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL); strvec_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL);
if (option_shallow_submodules == 1) if (option_shallow_submodules == 1)
argv_array_push(&args, "--depth=1"); strvec_push(&args, "--depth=1");
if (max_jobs != -1) if (max_jobs != -1)
argv_array_pushf(&args, "--jobs=%d", max_jobs); strvec_pushf(&args, "--jobs=%d", max_jobs);
if (submodule_progress) if (submodule_progress)
argv_array_push(&args, "--progress"); strvec_push(&args, "--progress");
if (option_verbosity < 0) if (option_verbosity < 0)
argv_array_push(&args, "--quiet"); strvec_push(&args, "--quiet");
if (option_remote_submodules) { if (option_remote_submodules) {
argv_array_push(&args, "--remote"); strvec_push(&args, "--remote");
argv_array_push(&args, "--no-fetch"); strvec_push(&args, "--no-fetch");
} }
if (option_single_branch >= 0) if (option_single_branch >= 0)
argv_array_push(&args, option_single_branch ? strvec_push(&args, option_single_branch ?
"--single-branch" : "--single-branch" :
"--no-single-branch"); "--no-single-branch");
err = run_command_v_opt(args.argv, RUN_GIT_CMD); err = run_command_v_opt(args.v, RUN_GIT_CMD);
argv_array_clear(&args); strvec_clear(&args);
} }
return err; return err;
@ -961,7 +961,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
int err = 0, complete_refs_before_fetch = 1; int err = 0, complete_refs_before_fetch = 1;
int submodule_progress; int submodule_progress;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT; struct strvec ref_prefixes = STRVEC_INIT;
packet_trace_identity("clone"); packet_trace_identity("clone");
argc = parse_options(argc, argv, prefix, builtin_clone_options, argc = parse_options(argc, argv, prefix, builtin_clone_options,
@ -1219,12 +1219,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport->smart_options->check_self_contained_and_connected = 1; transport->smart_options->check_self_contained_and_connected = 1;
argv_array_push(&ref_prefixes, "HEAD"); strvec_push(&ref_prefixes, "HEAD");
refspec_ref_prefixes(&remote->fetch, &ref_prefixes); refspec_ref_prefixes(&remote->fetch, &ref_prefixes);
if (option_branch) if (option_branch)
expand_ref_prefix(&ref_prefixes, option_branch); expand_ref_prefix(&ref_prefixes, option_branch);
if (!option_no_tags) if (!option_no_tags)
argv_array_push(&ref_prefixes, "refs/tags/"); strvec_push(&ref_prefixes, "refs/tags/");
refs = transport_get_remote_refs(transport, &ref_prefixes); refs = transport_get_remote_refs(transport, &ref_prefixes);
@ -1335,6 +1335,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
strbuf_release(&default_refspec); strbuf_release(&default_refspec);
junk_mode = JUNK_LEAVE_ALL; junk_mode = JUNK_LEAVE_ALL;
argv_array_clear(&ref_prefixes); strvec_clear(&ref_prefixes);
return err; return err;
} }

View file

@ -1005,15 +1005,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
return 0; return 0;
if (use_editor) { if (use_editor) {
struct argv_array env = ARGV_ARRAY_INIT; struct strvec env = STRVEC_INIT;
argv_array_pushf(&env, "GIT_INDEX_FILE=%s", index_file); strvec_pushf(&env, "GIT_INDEX_FILE=%s", index_file);
if (launch_editor(git_path_commit_editmsg(), NULL, env.argv)) { if (launch_editor(git_path_commit_editmsg(), NULL, env.v)) {
fprintf(stderr, fprintf(stderr,
_("Please supply the message using either -m or -F option.\n")); _("Please supply the message using either -m or -F option.\n"));
exit(1); exit(1);
} }
argv_array_clear(&env); strvec_clear(&env);
} }
if (!no_verify && if (!no_verify &&

View file

@ -12,7 +12,7 @@
#include "revision.h" #include "revision.h"
#include "diff.h" #include "diff.h"
#include "hashmap.h" #include "hashmap.h"
#include "argv-array.h" #include "strvec.h"
#include "run-command.h" #include "run-command.h"
#include "object-store.h" #include "object-store.h"
#include "list-objects.h" #include "list-objects.h"
@ -501,15 +501,15 @@ static void process_object(struct object *obj, const char *path, void *data)
static void describe_blob(struct object_id oid, struct strbuf *dst) static void describe_blob(struct object_id oid, struct strbuf *dst)
{ {
struct rev_info revs; struct rev_info revs;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
struct process_commit_data pcd = { null_oid, oid, dst, &revs}; struct process_commit_data pcd = { null_oid, oid, dst, &revs};
argv_array_pushl(&args, "internal: The first arg is not parsed", strvec_pushl(&args, "internal: The first arg is not parsed",
"--objects", "--in-commit-order", "--reverse", "HEAD", "--objects", "--in-commit-order", "--reverse", "HEAD",
NULL); NULL);
repo_init_revisions(the_repository, &revs, NULL); repo_init_revisions(the_repository, &revs, NULL);
if (setup_revisions(args.argc, args.argv, &revs, NULL) > 1) if (setup_revisions(args.nr, args.v, &revs, NULL) > 1)
BUG("setup_revisions could not handle all args?"); BUG("setup_revisions could not handle all args?");
if (prepare_revision_walk(&revs)) if (prepare_revision_walk(&revs))
@ -594,26 +594,26 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
if (contains) { if (contains) {
struct string_list_item *item; struct string_list_item *item;
struct argv_array args; struct strvec args;
argv_array_init(&args); strvec_init(&args);
argv_array_pushl(&args, "name-rev", strvec_pushl(&args, "name-rev",
"--peel-tag", "--name-only", "--no-undefined", "--peel-tag", "--name-only", "--no-undefined",
NULL); NULL);
if (always) if (always)
argv_array_push(&args, "--always"); strvec_push(&args, "--always");
if (!all) { if (!all) {
argv_array_push(&args, "--tags"); strvec_push(&args, "--tags");
for_each_string_list_item(item, &patterns) for_each_string_list_item(item, &patterns)
argv_array_pushf(&args, "--refs=refs/tags/%s", item->string); strvec_pushf(&args, "--refs=refs/tags/%s", item->string);
for_each_string_list_item(item, &exclude_patterns) for_each_string_list_item(item, &exclude_patterns)
argv_array_pushf(&args, "--exclude=refs/tags/%s", item->string); strvec_pushf(&args, "--exclude=refs/tags/%s", item->string);
} }
if (argc) if (argc)
argv_array_pushv(&args, argv); strvec_pushv(&args, argv);
else else
argv_array_push(&args, "HEAD"); strvec_push(&args, "HEAD");
return cmd_name_rev(args.argc, args.argv, prefix); return cmd_name_rev(args.nr, args.v, prefix);
} }
hashmap_init(&names, commit_name_neq, NULL, 0); hashmap_init(&names, commit_name_neq, NULL, 0);
@ -624,7 +624,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
if (argc == 0) { if (argc == 0) {
if (broken) { if (broken) {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
argv_array_pushv(&cp.args, diff_index_args); strvec_pushv(&cp.args, diff_index_args);
cp.git_cmd = 1; cp.git_cmd = 1;
cp.no_stdin = 1; cp.no_stdin = 1;
cp.no_stdout = 1; cp.no_stdout = 1;
@ -646,7 +646,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
} else if (dirty) { } else if (dirty) {
struct lock_file index_lock = LOCK_INIT; struct lock_file index_lock = LOCK_INIT;
struct rev_info revs; struct rev_info revs;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
int fd, result; int fd, result;
setup_work_tree(); setup_work_tree();
@ -658,8 +658,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
repo_update_index_if_able(the_repository, &index_lock); repo_update_index_if_able(the_repository, &index_lock);
repo_init_revisions(the_repository, &revs, prefix); repo_init_revisions(the_repository, &revs, prefix);
argv_array_pushv(&args, diff_index_args); strvec_pushv(&args, diff_index_args);
if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1) if (setup_revisions(args.nr, args.v, &revs, NULL) != 1)
BUG("malformed internal diff-index command line"); BUG("malformed internal diff-index command line");
result = run_diff_index(&revs, 0); result = run_diff_index(&revs, 0);

View file

@ -18,7 +18,7 @@
#include "run-command.h" #include "run-command.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "parse-options.h" #include "parse-options.h"
#include "argv-array.h" #include "strvec.h"
#include "strbuf.h" #include "strbuf.h"
#include "lockfile.h" #include "lockfile.h"
#include "object-store.h" #include "object-store.h"
@ -210,10 +210,10 @@ static void changed_files(struct hashmap *result, const char *index_path,
strbuf_addf(&index_env, "GIT_INDEX_FILE=%s", index_path); strbuf_addf(&index_env, "GIT_INDEX_FILE=%s", index_path);
env[0] = index_env.buf; env[0] = index_env.buf;
argv_array_pushl(&update_index.args, strvec_pushl(&update_index.args,
"--git-dir", git_dir, "--work-tree", workdir, "--git-dir", git_dir, "--work-tree", workdir,
"update-index", "--really-refresh", "-q", "update-index", "--really-refresh", "-q",
"--unmerged", NULL); "--unmerged", NULL);
update_index.no_stdin = 1; update_index.no_stdin = 1;
update_index.no_stdout = 1; update_index.no_stdout = 1;
update_index.no_stderr = 1; update_index.no_stderr = 1;
@ -225,9 +225,9 @@ static void changed_files(struct hashmap *result, const char *index_path,
/* Ignore any errors of update-index */ /* Ignore any errors of update-index */
run_command(&update_index); run_command(&update_index);
argv_array_pushl(&diff_files.args, strvec_pushl(&diff_files.args,
"--git-dir", git_dir, "--work-tree", workdir, "--git-dir", git_dir, "--work-tree", workdir,
"diff-files", "--name-only", "-z", NULL); "diff-files", "--name-only", "-z", NULL);
diff_files.no_stdin = 1; diff_files.no_stdin = 1;
diff_files.git_cmd = 1; diff_files.git_cmd = 1;
diff_files.use_shell = 0; diff_files.use_shell = 0;
@ -393,10 +393,10 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
child.clean_on_exit = 1; child.clean_on_exit = 1;
child.dir = prefix; child.dir = prefix;
child.out = -1; child.out = -1;
argv_array_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z", strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
NULL); NULL);
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
argv_array_push(&child.args, argv[i]); strvec_push(&child.args, argv[i]);
if (start_command(&child)) if (start_command(&child))
die("could not obtain raw diff"); die("could not obtain raw diff");
fp = xfdopen(child.out, "r"); fp = xfdopen(child.out, "r");
@ -667,7 +667,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
static int run_file_diff(int prompt, const char *prefix, static int run_file_diff(int prompt, const char *prefix,
int argc, const char **argv) int argc, const char **argv)
{ {
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
const char *env[] = { const char *env[] = {
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL, "GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
NULL NULL
@ -680,10 +680,10 @@ static int run_file_diff(int prompt, const char *prefix,
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true"; env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
argv_array_push(&args, "diff"); strvec_push(&args, "diff");
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
argv_array_push(&args, argv[i]); strvec_push(&args, argv[i]);
ret = run_command_v_opt_cd_env(args.argv, RUN_GIT_CMD, prefix, env); ret = run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
exit(ret); exit(ret);
} }

View file

@ -19,7 +19,7 @@
#include "submodule-config.h" #include "submodule-config.h"
#include "submodule.h" #include "submodule.h"
#include "connected.h" #include "connected.h"
#include "argv-array.h" #include "strvec.h"
#include "utf8.h" #include "utf8.h"
#include "packfile.h" #include "packfile.h"
#include "list-objects-filter-options.h" #include "list-objects-filter-options.h"
@ -1316,7 +1316,7 @@ static int do_fetch(struct transport *transport,
int autotags = (transport->remote->fetch_tags == 1); int autotags = (transport->remote->fetch_tags == 1);
int retcode = 0; int retcode = 0;
const struct ref *remote_refs; const struct ref *remote_refs;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT; struct strvec ref_prefixes = STRVEC_INIT;
int must_list_refs = 1; int must_list_refs = 1;
if (tags == TAGS_DEFAULT) { if (tags == TAGS_DEFAULT) {
@ -1354,8 +1354,8 @@ static int do_fetch(struct transport *transport,
if (tags == TAGS_SET || tags == TAGS_DEFAULT) { if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
must_list_refs = 1; must_list_refs = 1;
if (ref_prefixes.argc) if (ref_prefixes.nr)
argv_array_push(&ref_prefixes, "refs/tags/"); strvec_push(&ref_prefixes, "refs/tags/");
} }
if (must_list_refs) { if (must_list_refs) {
@ -1365,7 +1365,7 @@ static int do_fetch(struct transport *transport,
} else } else
remote_refs = NULL; remote_refs = NULL;
argv_array_clear(&ref_prefixes); strvec_clear(&ref_prefixes);
ref_map = get_ref_map(transport->remote, remote_refs, rs, ref_map = get_ref_map(transport->remote, remote_refs, rs,
tags, &autotags); tags, &autotags);
@ -1503,34 +1503,34 @@ static int add_remote_or_group(const char *name, struct string_list *list)
return 1; return 1;
} }
static void add_options_to_argv(struct argv_array *argv) static void add_options_to_argv(struct strvec *argv)
{ {
if (dry_run) if (dry_run)
argv_array_push(argv, "--dry-run"); strvec_push(argv, "--dry-run");
if (prune != -1) if (prune != -1)
argv_array_push(argv, prune ? "--prune" : "--no-prune"); strvec_push(argv, prune ? "--prune" : "--no-prune");
if (prune_tags != -1) if (prune_tags != -1)
argv_array_push(argv, prune_tags ? "--prune-tags" : "--no-prune-tags"); strvec_push(argv, prune_tags ? "--prune-tags" : "--no-prune-tags");
if (update_head_ok) if (update_head_ok)
argv_array_push(argv, "--update-head-ok"); strvec_push(argv, "--update-head-ok");
if (force) if (force)
argv_array_push(argv, "--force"); strvec_push(argv, "--force");
if (keep) if (keep)
argv_array_push(argv, "--keep"); strvec_push(argv, "--keep");
if (recurse_submodules == RECURSE_SUBMODULES_ON) if (recurse_submodules == RECURSE_SUBMODULES_ON)
argv_array_push(argv, "--recurse-submodules"); strvec_push(argv, "--recurse-submodules");
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
argv_array_push(argv, "--recurse-submodules=on-demand"); strvec_push(argv, "--recurse-submodules=on-demand");
if (tags == TAGS_SET) if (tags == TAGS_SET)
argv_array_push(argv, "--tags"); strvec_push(argv, "--tags");
else if (tags == TAGS_UNSET) else if (tags == TAGS_UNSET)
argv_array_push(argv, "--no-tags"); strvec_push(argv, "--no-tags");
if (verbosity >= 2) if (verbosity >= 2)
argv_array_push(argv, "-v"); strvec_push(argv, "-v");
if (verbosity >= 1) if (verbosity >= 1)
argv_array_push(argv, "-v"); strvec_push(argv, "-v");
else if (verbosity < 0) else if (verbosity < 0)
argv_array_push(argv, "-q"); strvec_push(argv, "-q");
} }
@ -1554,8 +1554,8 @@ static int fetch_next_remote(struct child_process *cp, struct strbuf *out,
remote = state->remotes->items[state->next++].string; remote = state->remotes->items[state->next++].string;
*task_cb = remote; *task_cb = remote;
argv_array_pushv(&cp->args, state->argv); strvec_pushv(&cp->args, state->argv);
argv_array_push(&cp->args, remote); strvec_push(&cp->args, remote);
cp->git_cmd = 1; cp->git_cmd = 1;
if (verbosity >= 0) if (verbosity >= 0)
@ -1592,7 +1592,7 @@ static int fetch_finished(int result, struct strbuf *out,
static int fetch_multiple(struct string_list *list, int max_children) static int fetch_multiple(struct string_list *list, int max_children)
{ {
int i, result = 0; int i, result = 0;
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
if (!append && !dry_run) { if (!append && !dry_run) {
int errcode = truncate_fetch_head(); int errcode = truncate_fetch_head();
@ -1600,14 +1600,14 @@ static int fetch_multiple(struct string_list *list, int max_children)
return errcode; return errcode;
} }
argv_array_pushl(&argv, "fetch", "--append", "--no-auto-gc", strvec_pushl(&argv, "fetch", "--append", "--no-auto-gc",
"--no-write-commit-graph", NULL); "--no-write-commit-graph", NULL);
add_options_to_argv(&argv); add_options_to_argv(&argv);
if (max_children != 1 && list->nr != 1) { if (max_children != 1 && list->nr != 1) {
struct parallel_fetch_state state = { argv.argv, list, 0, 0 }; struct parallel_fetch_state state = { argv.v, list, 0, 0 };
argv_array_push(&argv, "--end-of-options"); strvec_push(&argv, "--end-of-options");
result = run_processes_parallel_tr2(max_children, result = run_processes_parallel_tr2(max_children,
&fetch_next_remote, &fetch_next_remote,
&fetch_failed_to_start, &fetch_failed_to_start,
@ -1620,17 +1620,17 @@ static int fetch_multiple(struct string_list *list, int max_children)
} else } else
for (i = 0; i < list->nr; i++) { for (i = 0; i < list->nr; i++) {
const char *name = list->items[i].string; const char *name = list->items[i].string;
argv_array_push(&argv, name); strvec_push(&argv, name);
if (verbosity >= 0) if (verbosity >= 0)
printf(_("Fetching %s\n"), name); printf(_("Fetching %s\n"), name);
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
error(_("Could not fetch %s"), name); error(_("Could not fetch %s"), name);
result = 1; result = 1;
} }
argv_array_pop(&argv); strvec_pop(&argv);
} }
argv_array_clear(&argv); strvec_clear(&argv);
return !!result; return !!result;
} }
@ -1844,7 +1844,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
} }
if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) { if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
struct argv_array options = ARGV_ARRAY_INIT; struct strvec options = STRVEC_INIT;
int max_children = max_jobs; int max_children = max_jobs;
if (max_children < 0) if (max_children < 0)
@ -1860,7 +1860,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
recurse_submodules_default, recurse_submodules_default,
verbosity < 0, verbosity < 0,
max_children); max_children);
argv_array_clear(&options); strvec_clear(&options);
} }
string_list_clear(&list, 0); string_list_clear(&list, 0);

View file

@ -18,7 +18,7 @@
#include "parse-options.h" #include "parse-options.h"
#include "run-command.h" #include "run-command.h"
#include "sigchain.h" #include "sigchain.h"
#include "argv-array.h" #include "strvec.h"
#include "commit.h" #include "commit.h"
#include "commit-graph.h" #include "commit-graph.h"
#include "packfile.h" #include "packfile.h"
@ -50,12 +50,12 @@ static const char *prune_worktrees_expire = "3.months.ago";
static unsigned long big_pack_threshold; static unsigned long big_pack_threshold;
static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE; static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT; static struct strvec pack_refs_cmd = STRVEC_INIT;
static struct argv_array reflog = ARGV_ARRAY_INIT; static struct strvec reflog = STRVEC_INIT;
static struct argv_array repack = ARGV_ARRAY_INIT; static struct strvec repack = STRVEC_INIT;
static struct argv_array prune = ARGV_ARRAY_INIT; static struct strvec prune = STRVEC_INIT;
static struct argv_array prune_worktrees = ARGV_ARRAY_INIT; static struct strvec prune_worktrees = STRVEC_INIT;
static struct argv_array rerere = ARGV_ARRAY_INIT; static struct strvec rerere = STRVEC_INIT;
static struct tempfile *pidfile; static struct tempfile *pidfile;
static struct lock_file log_lock; static struct lock_file log_lock;
@ -311,18 +311,18 @@ static uint64_t estimate_repack_memory(struct packed_git *pack)
static int keep_one_pack(struct string_list_item *item, void *data) static int keep_one_pack(struct string_list_item *item, void *data)
{ {
argv_array_pushf(&repack, "--keep-pack=%s", basename(item->string)); strvec_pushf(&repack, "--keep-pack=%s", basename(item->string));
return 0; return 0;
} }
static void add_repack_all_option(struct string_list *keep_pack) static void add_repack_all_option(struct string_list *keep_pack)
{ {
if (prune_expire && !strcmp(prune_expire, "now")) if (prune_expire && !strcmp(prune_expire, "now"))
argv_array_push(&repack, "-a"); strvec_push(&repack, "-a");
else { else {
argv_array_push(&repack, "-A"); strvec_push(&repack, "-A");
if (prune_expire) if (prune_expire)
argv_array_pushf(&repack, "--unpack-unreachable=%s", prune_expire); strvec_pushf(&repack, "--unpack-unreachable=%s", prune_expire);
} }
if (keep_pack) if (keep_pack)
@ -331,7 +331,7 @@ static void add_repack_all_option(struct string_list *keep_pack)
static void add_repack_incremental_option(void) static void add_repack_incremental_option(void)
{ {
argv_array_push(&repack, "--no-write-bitmap-index"); strvec_push(&repack, "--no-write-bitmap-index");
} }
static int need_to_gc(void) static int need_to_gc(void)
@ -514,11 +514,11 @@ static void gc_before_repack(void)
if (done++) if (done++)
return; return;
if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) if (pack_refs && run_command_v_opt(pack_refs_cmd.v, RUN_GIT_CMD))
die(FAILED_RUN, pack_refs_cmd.argv[0]); die(FAILED_RUN, pack_refs_cmd.v[0]);
if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD)) if (prune_reflogs && run_command_v_opt(reflog.v, RUN_GIT_CMD))
die(FAILED_RUN, reflog.argv[0]); die(FAILED_RUN, reflog.v[0]);
} }
int cmd_gc(int argc, const char **argv, const char *prefix) int cmd_gc(int argc, const char **argv, const char *prefix)
@ -552,12 +552,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h")) if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_gc_usage, builtin_gc_options); usage_with_options(builtin_gc_usage, builtin_gc_options);
argv_array_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL); strvec_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
argv_array_pushl(&reflog, "reflog", "expire", "--all", NULL); strvec_pushl(&reflog, "reflog", "expire", "--all", NULL);
argv_array_pushl(&repack, "repack", "-d", "-l", NULL); strvec_pushl(&repack, "repack", "-d", "-l", NULL);
argv_array_pushl(&prune, "prune", "--expire", NULL); strvec_pushl(&prune, "prune", "--expire", NULL);
argv_array_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL); strvec_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);
argv_array_pushl(&rerere, "rerere", "gc", NULL); strvec_pushl(&rerere, "rerere", "gc", NULL);
/* default expiry time, overwritten in gc_config */ /* default expiry time, overwritten in gc_config */
gc_config(); gc_config();
@ -576,14 +576,14 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
die(_("failed to parse prune expiry value %s"), prune_expire); die(_("failed to parse prune expiry value %s"), prune_expire);
if (aggressive) { if (aggressive) {
argv_array_push(&repack, "-f"); strvec_push(&repack, "-f");
if (aggressive_depth > 0) if (aggressive_depth > 0)
argv_array_pushf(&repack, "--depth=%d", aggressive_depth); strvec_pushf(&repack, "--depth=%d", aggressive_depth);
if (aggressive_window > 0) if (aggressive_window > 0)
argv_array_pushf(&repack, "--window=%d", aggressive_window); strvec_pushf(&repack, "--window=%d", aggressive_window);
} }
if (quiet) if (quiet)
argv_array_push(&repack, "-q"); strvec_push(&repack, "-q");
if (auto_gc) { if (auto_gc) {
/* /*
@ -653,29 +653,29 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
if (!repository_format_precious_objects) { if (!repository_format_precious_objects) {
close_object_store(the_repository->objects); close_object_store(the_repository->objects);
if (run_command_v_opt(repack.argv, RUN_GIT_CMD)) if (run_command_v_opt(repack.v, RUN_GIT_CMD))
die(FAILED_RUN, repack.argv[0]); die(FAILED_RUN, repack.v[0]);
if (prune_expire) { if (prune_expire) {
argv_array_push(&prune, prune_expire); strvec_push(&prune, prune_expire);
if (quiet) if (quiet)
argv_array_push(&prune, "--no-progress"); strvec_push(&prune, "--no-progress");
if (has_promisor_remote()) if (has_promisor_remote())
argv_array_push(&prune, strvec_push(&prune,
"--exclude-promisor-objects"); "--exclude-promisor-objects");
if (run_command_v_opt(prune.argv, RUN_GIT_CMD)) if (run_command_v_opt(prune.v, RUN_GIT_CMD))
die(FAILED_RUN, prune.argv[0]); die(FAILED_RUN, prune.v[0]);
} }
} }
if (prune_worktrees_expire) { if (prune_worktrees_expire) {
argv_array_push(&prune_worktrees, prune_worktrees_expire); strvec_push(&prune_worktrees, prune_worktrees_expire);
if (run_command_v_opt(prune_worktrees.argv, RUN_GIT_CMD)) if (run_command_v_opt(prune_worktrees.v, RUN_GIT_CMD))
die(FAILED_RUN, prune_worktrees.argv[0]); die(FAILED_RUN, prune_worktrees.v[0]);
} }
if (run_command_v_opt(rerere.argv, RUN_GIT_CMD)) if (run_command_v_opt(rerere.v, RUN_GIT_CMD))
die(FAILED_RUN, rerere.argv[0]); die(FAILED_RUN, rerere.v[0]);
report_garbage = report_pack_garbage; report_garbage = report_pack_garbage;
reprepare_packed_git(the_repository); reprepare_packed_git(the_repository);

View file

@ -397,7 +397,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
int i, status; int i, status;
for (i = 0; i < path_list->nr; i++) for (i = 0; i < path_list->nr; i++)
argv_array_push(&child.args, path_list->items[i].string); strvec_push(&child.args, path_list->items[i].string);
child.dir = prefix; child.dir = prefix;
child.use_shell = 1; child.use_shell = 1;

View file

@ -1128,18 +1128,18 @@ static void prepare_cover_text(struct pretty_print_context *pp,
static int get_notes_refs(struct string_list_item *item, void *arg) static int get_notes_refs(struct string_list_item *item, void *arg)
{ {
argv_array_pushf(arg, "--notes=%s", item->string); strvec_pushf(arg, "--notes=%s", item->string);
return 0; return 0;
} }
static void get_notes_args(struct argv_array *arg, struct rev_info *rev) static void get_notes_args(struct strvec *arg, struct rev_info *rev)
{ {
if (!rev->show_notes) { if (!rev->show_notes) {
argv_array_push(arg, "--no-notes"); strvec_push(arg, "--no-notes");
} else if (rev->notes_opt.use_default_notes > 0 || } else if (rev->notes_opt.use_default_notes > 0 ||
(rev->notes_opt.use_default_notes == -1 && (rev->notes_opt.use_default_notes == -1 &&
!rev->notes_opt.extra_notes_refs.nr)) { !rev->notes_opt.extra_notes_refs.nr)) {
argv_array_push(arg, "--notes"); strvec_push(arg, "--notes");
} else { } else {
for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg); for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
} }
@ -1217,7 +1217,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
* can be added later if deemed desirable. * can be added later if deemed desirable.
*/ */
struct diff_options opts; struct diff_options opts;
struct argv_array other_arg = ARGV_ARRAY_INIT; struct strvec other_arg = STRVEC_INIT;
diff_setup(&opts); diff_setup(&opts);
opts.file = rev->diffopt.file; opts.file = rev->diffopt.file;
opts.use_color = rev->diffopt.use_color; opts.use_color = rev->diffopt.use_color;
@ -1226,7 +1226,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
get_notes_args(&other_arg, rev); get_notes_args(&other_arg, rev);
show_range_diff(rev->rdiff1, rev->rdiff2, show_range_diff(rev->rdiff1, rev->rdiff2,
rev->creation_factor, 1, &opts, &other_arg); rev->creation_factor, 1, &opts, &other_arg);
argv_array_clear(&other_arg); strvec_clear(&other_arg);
} }
} }

View file

@ -45,7 +45,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
int show_symref_target = 0; int show_symref_target = 0;
const char *uploadpack = NULL; const char *uploadpack = NULL;
const char **pattern = NULL; const char **pattern = NULL;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT; struct strvec ref_prefixes = STRVEC_INIT;
int i; int i;
struct string_list server_options = STRING_LIST_INIT_DUP; struct string_list server_options = STRING_LIST_INIT_DUP;
@ -92,9 +92,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
} }
if (flags & REF_TAGS) if (flags & REF_TAGS)
argv_array_push(&ref_prefixes, "refs/tags/"); strvec_push(&ref_prefixes, "refs/tags/");
if (flags & REF_HEADS) if (flags & REF_HEADS)
argv_array_push(&ref_prefixes, "refs/heads/"); strvec_push(&ref_prefixes, "refs/heads/");
remote = remote_get(dest); remote = remote_get(dest);
if (!remote) { if (!remote) {

View file

@ -27,7 +27,7 @@
#include "delta-islands.h" #include "delta-islands.h"
#include "reachable.h" #include "reachable.h"
#include "oid-array.h" #include "oid-array.h"
#include "argv-array.h" #include "strvec.h"
#include "list.h" #include "list.h"
#include "packfile.h" #include "packfile.h"
#include "object-store.h" #include "object-store.h"
@ -3471,7 +3471,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
int use_internal_rev_list = 0; int use_internal_rev_list = 0;
int shallow = 0; int shallow = 0;
int all_progress_implied = 0; int all_progress_implied = 0;
struct argv_array rp = ARGV_ARRAY_INIT; struct strvec rp = STRVEC_INIT;
int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0; int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;
int rev_list_index = 0; int rev_list_index = 0;
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP; struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
@ -3607,36 +3607,36 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
cache_max_small_delta_size = (1U << OE_Z_DELTA_BITS) - 1; cache_max_small_delta_size = (1U << OE_Z_DELTA_BITS) - 1;
} }
argv_array_push(&rp, "pack-objects"); strvec_push(&rp, "pack-objects");
if (thin) { if (thin) {
use_internal_rev_list = 1; use_internal_rev_list = 1;
argv_array_push(&rp, shallow strvec_push(&rp, shallow
? "--objects-edge-aggressive" ? "--objects-edge-aggressive"
: "--objects-edge"); : "--objects-edge");
} else } else
argv_array_push(&rp, "--objects"); strvec_push(&rp, "--objects");
if (rev_list_all) { if (rev_list_all) {
use_internal_rev_list = 1; use_internal_rev_list = 1;
argv_array_push(&rp, "--all"); strvec_push(&rp, "--all");
} }
if (rev_list_reflog) { if (rev_list_reflog) {
use_internal_rev_list = 1; use_internal_rev_list = 1;
argv_array_push(&rp, "--reflog"); strvec_push(&rp, "--reflog");
} }
if (rev_list_index) { if (rev_list_index) {
use_internal_rev_list = 1; use_internal_rev_list = 1;
argv_array_push(&rp, "--indexed-objects"); strvec_push(&rp, "--indexed-objects");
} }
if (rev_list_unpacked) { if (rev_list_unpacked) {
use_internal_rev_list = 1; use_internal_rev_list = 1;
argv_array_push(&rp, "--unpacked"); strvec_push(&rp, "--unpacked");
} }
if (exclude_promisor_objects) { if (exclude_promisor_objects) {
use_internal_rev_list = 1; use_internal_rev_list = 1;
fetch_if_missing = 0; fetch_if_missing = 0;
argv_array_push(&rp, "--exclude-promisor-objects"); strvec_push(&rp, "--exclude-promisor-objects");
} }
if (unpack_unreachable || keep_unreachable || pack_loose_unreachable) if (unpack_unreachable || keep_unreachable || pack_loose_unreachable)
use_internal_rev_list = 1; use_internal_rev_list = 1;
@ -3698,7 +3698,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
write_bitmap_index = 0; write_bitmap_index = 0;
if (use_delta_islands) if (use_delta_islands)
argv_array_push(&rp, "--topo-order"); strvec_push(&rp, "--topo-order");
if (progress && all_progress_implied) if (progress && all_progress_implied)
progress = 2; progress = 2;
@ -3736,8 +3736,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (!use_internal_rev_list) if (!use_internal_rev_list)
read_object_list_from_stdin(); read_object_list_from_stdin();
else { else {
get_object_list(rp.argc, rp.argv); get_object_list(rp.nr, rp.v);
argv_array_clear(&rp); strvec_clear(&rp);
} }
cleanup_preferred_base(); cleanup_preferred_base();
if (include_tag && nr_result) if (include_tag && nr_result)

View file

@ -87,8 +87,8 @@ static char *opt_verify_signatures;
static int opt_autostash = -1; static int opt_autostash = -1;
static int config_autostash; static int config_autostash;
static int check_trust_level = 1; static int check_trust_level = 1;
static struct argv_array opt_strategies = ARGV_ARRAY_INIT; static struct strvec opt_strategies = STRVEC_INIT;
static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT; static struct strvec opt_strategy_opts = STRVEC_INIT;
static char *opt_gpg_sign; static char *opt_gpg_sign;
static int opt_allow_unrelated_histories; static int opt_allow_unrelated_histories;
@ -110,7 +110,7 @@ static char *opt_ipv4;
static char *opt_ipv6; static char *opt_ipv6;
static int opt_show_forced_updates = -1; static int opt_show_forced_updates = -1;
static char *set_upstream; static char *set_upstream;
static struct argv_array opt_fetch = ARGV_ARRAY_INIT; static struct strvec opt_fetch = STRVEC_INIT;
static struct option pull_options[] = { static struct option pull_options[] = {
/* Shared options */ /* Shared options */
@ -251,25 +251,25 @@ static struct option pull_options[] = {
/** /**
* Pushes "-q" or "-v" switches into arr to match the opt_verbosity level. * Pushes "-q" or "-v" switches into arr to match the opt_verbosity level.
*/ */
static void argv_push_verbosity(struct argv_array *arr) static void argv_push_verbosity(struct strvec *arr)
{ {
int verbosity; int verbosity;
for (verbosity = opt_verbosity; verbosity > 0; verbosity--) for (verbosity = opt_verbosity; verbosity > 0; verbosity--)
argv_array_push(arr, "-v"); strvec_push(arr, "-v");
for (verbosity = opt_verbosity; verbosity < 0; verbosity++) for (verbosity = opt_verbosity; verbosity < 0; verbosity++)
argv_array_push(arr, "-q"); strvec_push(arr, "-q");
} }
/** /**
* Pushes "-f" switches into arr to match the opt_force level. * Pushes "-f" switches into arr to match the opt_force level.
*/ */
static void argv_push_force(struct argv_array *arr) static void argv_push_force(struct strvec *arr)
{ {
int force = opt_force; int force = opt_force;
while (force-- > 0) while (force-- > 0)
argv_array_push(arr, "-f"); strvec_push(arr, "-f");
} }
/** /**
@ -524,75 +524,75 @@ static void parse_repo_refspecs(int argc, const char **argv, const char **repo,
*/ */
static int run_fetch(const char *repo, const char **refspecs) static int run_fetch(const char *repo, const char **refspecs)
{ {
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
int ret; int ret;
argv_array_pushl(&args, "fetch", "--update-head-ok", NULL); strvec_pushl(&args, "fetch", "--update-head-ok", NULL);
/* Shared options */ /* Shared options */
argv_push_verbosity(&args); argv_push_verbosity(&args);
if (opt_progress) if (opt_progress)
argv_array_push(&args, opt_progress); strvec_push(&args, opt_progress);
/* Options passed to git-fetch */ /* Options passed to git-fetch */
if (opt_all) if (opt_all)
argv_array_push(&args, opt_all); strvec_push(&args, opt_all);
if (opt_append) if (opt_append)
argv_array_push(&args, opt_append); strvec_push(&args, opt_append);
if (opt_upload_pack) if (opt_upload_pack)
argv_array_push(&args, opt_upload_pack); strvec_push(&args, opt_upload_pack);
argv_push_force(&args); argv_push_force(&args);
if (opt_tags) if (opt_tags)
argv_array_push(&args, opt_tags); strvec_push(&args, opt_tags);
if (opt_prune) if (opt_prune)
argv_array_push(&args, opt_prune); strvec_push(&args, opt_prune);
if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT)
switch (recurse_submodules) { switch (recurse_submodules) {
case RECURSE_SUBMODULES_ON: case RECURSE_SUBMODULES_ON:
argv_array_push(&args, "--recurse-submodules=on"); strvec_push(&args, "--recurse-submodules=on");
break; break;
case RECURSE_SUBMODULES_OFF: case RECURSE_SUBMODULES_OFF:
argv_array_push(&args, "--recurse-submodules=no"); strvec_push(&args, "--recurse-submodules=no");
break; break;
case RECURSE_SUBMODULES_ON_DEMAND: case RECURSE_SUBMODULES_ON_DEMAND:
argv_array_push(&args, "--recurse-submodules=on-demand"); strvec_push(&args, "--recurse-submodules=on-demand");
break; break;
default: default:
BUG("submodule recursion option not understood"); BUG("submodule recursion option not understood");
} }
if (max_children) if (max_children)
argv_array_push(&args, max_children); strvec_push(&args, max_children);
if (opt_dry_run) if (opt_dry_run)
argv_array_push(&args, "--dry-run"); strvec_push(&args, "--dry-run");
if (opt_keep) if (opt_keep)
argv_array_push(&args, opt_keep); strvec_push(&args, opt_keep);
if (opt_depth) if (opt_depth)
argv_array_push(&args, opt_depth); strvec_push(&args, opt_depth);
if (opt_unshallow) if (opt_unshallow)
argv_array_push(&args, opt_unshallow); strvec_push(&args, opt_unshallow);
if (opt_update_shallow) if (opt_update_shallow)
argv_array_push(&args, opt_update_shallow); strvec_push(&args, opt_update_shallow);
if (opt_refmap) if (opt_refmap)
argv_array_push(&args, opt_refmap); strvec_push(&args, opt_refmap);
if (opt_ipv4) if (opt_ipv4)
argv_array_push(&args, opt_ipv4); strvec_push(&args, opt_ipv4);
if (opt_ipv6) if (opt_ipv6)
argv_array_push(&args, opt_ipv6); strvec_push(&args, opt_ipv6);
if (opt_show_forced_updates > 0) if (opt_show_forced_updates > 0)
argv_array_push(&args, "--show-forced-updates"); strvec_push(&args, "--show-forced-updates");
else if (opt_show_forced_updates == 0) else if (opt_show_forced_updates == 0)
argv_array_push(&args, "--no-show-forced-updates"); strvec_push(&args, "--no-show-forced-updates");
if (set_upstream) if (set_upstream)
argv_array_push(&args, set_upstream); strvec_push(&args, set_upstream);
argv_array_pushv(&args, opt_fetch.argv); strvec_pushv(&args, opt_fetch.v);
if (repo) { if (repo) {
argv_array_push(&args, repo); strvec_push(&args, repo);
argv_array_pushv(&args, refspecs); strvec_pushv(&args, refspecs);
} else if (*refspecs) } else if (*refspecs)
BUG("refspecs without repo?"); BUG("refspecs without repo?");
ret = run_command_v_opt(args.argv, RUN_GIT_CMD); ret = run_command_v_opt(args.v, RUN_GIT_CMD);
argv_array_clear(&args); strvec_clear(&args);
return ret; return ret;
} }
@ -637,8 +637,8 @@ static int rebase_submodules(void)
cp.git_cmd = 1; cp.git_cmd = 1;
cp.no_stdin = 1; cp.no_stdin = 1;
argv_array_pushl(&cp.args, "submodule", "update", strvec_pushl(&cp.args, "submodule", "update",
"--recursive", "--rebase", NULL); "--recursive", "--rebase", NULL);
argv_push_verbosity(&cp.args); argv_push_verbosity(&cp.args);
return run_command(&cp); return run_command(&cp);
@ -650,8 +650,8 @@ static int update_submodules(void)
cp.git_cmd = 1; cp.git_cmd = 1;
cp.no_stdin = 1; cp.no_stdin = 1;
argv_array_pushl(&cp.args, "submodule", "update", strvec_pushl(&cp.args, "submodule", "update",
"--recursive", "--checkout", NULL); "--recursive", "--checkout", NULL);
argv_push_verbosity(&cp.args); argv_push_verbosity(&cp.args);
return run_command(&cp); return run_command(&cp);
@ -663,48 +663,48 @@ static int update_submodules(void)
static int run_merge(void) static int run_merge(void)
{ {
int ret; int ret;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
argv_array_pushl(&args, "merge", NULL); strvec_pushl(&args, "merge", NULL);
/* Shared options */ /* Shared options */
argv_push_verbosity(&args); argv_push_verbosity(&args);
if (opt_progress) if (opt_progress)
argv_array_push(&args, opt_progress); strvec_push(&args, opt_progress);
/* Options passed to git-merge */ /* Options passed to git-merge */
if (opt_diffstat) if (opt_diffstat)
argv_array_push(&args, opt_diffstat); strvec_push(&args, opt_diffstat);
if (opt_log) if (opt_log)
argv_array_push(&args, opt_log); strvec_push(&args, opt_log);
if (opt_signoff) if (opt_signoff)
argv_array_push(&args, opt_signoff); strvec_push(&args, opt_signoff);
if (opt_squash) if (opt_squash)
argv_array_push(&args, opt_squash); strvec_push(&args, opt_squash);
if (opt_commit) if (opt_commit)
argv_array_push(&args, opt_commit); strvec_push(&args, opt_commit);
if (opt_edit) if (opt_edit)
argv_array_push(&args, opt_edit); strvec_push(&args, opt_edit);
if (cleanup_arg) if (cleanup_arg)
argv_array_pushf(&args, "--cleanup=%s", cleanup_arg); strvec_pushf(&args, "--cleanup=%s", cleanup_arg);
if (opt_ff) if (opt_ff)
argv_array_push(&args, opt_ff); strvec_push(&args, opt_ff);
if (opt_verify_signatures) if (opt_verify_signatures)
argv_array_push(&args, opt_verify_signatures); strvec_push(&args, opt_verify_signatures);
argv_array_pushv(&args, opt_strategies.argv); strvec_pushv(&args, opt_strategies.v);
argv_array_pushv(&args, opt_strategy_opts.argv); strvec_pushv(&args, opt_strategy_opts.v);
if (opt_gpg_sign) if (opt_gpg_sign)
argv_array_push(&args, opt_gpg_sign); strvec_push(&args, opt_gpg_sign);
if (opt_autostash == 0) if (opt_autostash == 0)
argv_array_push(&args, "--no-autostash"); strvec_push(&args, "--no-autostash");
else if (opt_autostash == 1) else if (opt_autostash == 1)
argv_array_push(&args, "--autostash"); strvec_push(&args, "--autostash");
if (opt_allow_unrelated_histories > 0) if (opt_allow_unrelated_histories > 0)
argv_array_push(&args, "--allow-unrelated-histories"); strvec_push(&args, "--allow-unrelated-histories");
argv_array_push(&args, "FETCH_HEAD"); strvec_push(&args, "FETCH_HEAD");
ret = run_command_v_opt(args.argv, RUN_GIT_CMD); ret = run_command_v_opt(args.v, RUN_GIT_CMD);
argv_array_clear(&args); strvec_clear(&args);
return ret; return ret;
} }
@ -801,8 +801,8 @@ static int get_rebase_fork_point(struct object_id *fork_point, const char *repo,
if (!remote_branch) if (!remote_branch)
return -1; return -1;
argv_array_pushl(&cp.args, "merge-base", "--fork-point", strvec_pushl(&cp.args, "merge-base", "--fork-point",
remote_branch, curr_branch->name, NULL); remote_branch, curr_branch->name, NULL);
cp.no_stdin = 1; cp.no_stdin = 1;
cp.no_stderr = 1; cp.no_stderr = 1;
cp.git_cmd = 1; cp.git_cmd = 1;
@ -862,48 +862,48 @@ static int run_rebase(const struct object_id *curr_head,
{ {
int ret; int ret;
struct object_id oct_merge_base; struct object_id oct_merge_base;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point)) if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))
if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point)) if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))
fork_point = NULL; fork_point = NULL;
argv_array_push(&args, "rebase"); strvec_push(&args, "rebase");
/* Shared options */ /* Shared options */
argv_push_verbosity(&args); argv_push_verbosity(&args);
/* Options passed to git-rebase */ /* Options passed to git-rebase */
if (opt_rebase == REBASE_MERGES) if (opt_rebase == REBASE_MERGES)
argv_array_push(&args, "--rebase-merges"); strvec_push(&args, "--rebase-merges");
else if (opt_rebase == REBASE_PRESERVE) else if (opt_rebase == REBASE_PRESERVE)
argv_array_push(&args, "--preserve-merges"); strvec_push(&args, "--preserve-merges");
else if (opt_rebase == REBASE_INTERACTIVE) else if (opt_rebase == REBASE_INTERACTIVE)
argv_array_push(&args, "--interactive"); strvec_push(&args, "--interactive");
if (opt_diffstat) if (opt_diffstat)
argv_array_push(&args, opt_diffstat); strvec_push(&args, opt_diffstat);
argv_array_pushv(&args, opt_strategies.argv); strvec_pushv(&args, opt_strategies.v);
argv_array_pushv(&args, opt_strategy_opts.argv); strvec_pushv(&args, opt_strategy_opts.v);
if (opt_gpg_sign) if (opt_gpg_sign)
argv_array_push(&args, opt_gpg_sign); strvec_push(&args, opt_gpg_sign);
if (opt_autostash == 0) if (opt_autostash == 0)
argv_array_push(&args, "--no-autostash"); strvec_push(&args, "--no-autostash");
else if (opt_autostash == 1) else if (opt_autostash == 1)
argv_array_push(&args, "--autostash"); strvec_push(&args, "--autostash");
if (opt_verify_signatures && if (opt_verify_signatures &&
!strcmp(opt_verify_signatures, "--verify-signatures")) !strcmp(opt_verify_signatures, "--verify-signatures"))
warning(_("ignoring --verify-signatures for rebase")); warning(_("ignoring --verify-signatures for rebase"));
argv_array_push(&args, "--onto"); strvec_push(&args, "--onto");
argv_array_push(&args, oid_to_hex(merge_head)); strvec_push(&args, oid_to_hex(merge_head));
if (fork_point && !is_null_oid(fork_point)) if (fork_point && !is_null_oid(fork_point))
argv_array_push(&args, oid_to_hex(fork_point)); strvec_push(&args, oid_to_hex(fork_point));
else else
argv_array_push(&args, oid_to_hex(merge_head)); strvec_push(&args, oid_to_hex(merge_head));
ret = run_command_v_opt(args.argv, RUN_GIT_CMD); ret = run_command_v_opt(args.v, RUN_GIT_CMD);
argv_array_clear(&args); strvec_clear(&args);
return ret; return ret;
} }

View file

@ -15,7 +15,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
{ {
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
struct diff_options diffopt = { NULL }; struct diff_options diffopt = { NULL };
struct argv_array other_arg = ARGV_ARRAY_INIT; struct strvec other_arg = STRVEC_INIT;
int simple_color = -1; int simple_color = -1;
struct option range_diff_options[] = { struct option range_diff_options[] = {
OPT_INTEGER(0, "creation-factor", &creation_factor, OPT_INTEGER(0, "creation-factor", &creation_factor,
@ -84,7 +84,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
res = show_range_diff(range1.buf, range2.buf, creation_factor, res = show_range_diff(range1.buf, range2.buf, creation_factor,
simple_color < 1, &diffopt, &other_arg); simple_color < 1, &diffopt, &other_arg);
argv_array_clear(&other_arg); strvec_clear(&other_arg);
strbuf_release(&range1); strbuf_release(&range1);
strbuf_release(&range2); strbuf_release(&range2);

View file

@ -8,7 +8,7 @@
#include "builtin.h" #include "builtin.h"
#include "run-command.h" #include "run-command.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "argv-array.h" #include "strvec.h"
#include "dir.h" #include "dir.h"
#include "packfile.h" #include "packfile.h"
#include "refs.h" #include "refs.h"
@ -84,7 +84,7 @@ struct rebase_options {
REBASE_FORCE = 1<<3, REBASE_FORCE = 1<<3,
REBASE_INTERACTIVE_EXPLICIT = 1<<4, REBASE_INTERACTIVE_EXPLICIT = 1<<4,
} flags; } flags;
struct argv_array git_am_opts; struct strvec git_am_opts;
const char *action; const char *action;
int signoff; int signoff;
int allow_rerere_autoupdate; int allow_rerere_autoupdate;
@ -108,7 +108,7 @@ struct rebase_options {
.keep_empty = 1, \ .keep_empty = 1, \
.default_backend = "merge", \ .default_backend = "merge", \
.flags = REBASE_NO_QUIET, \ .flags = REBASE_NO_QUIET, \
.git_am_opts = ARGV_ARRAY_INIT, \ .git_am_opts = STRVEC_INIT, \
.git_format_patch_opt = STRBUF_INIT \ .git_format_patch_opt = STRBUF_INIT \
} }
@ -323,7 +323,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
int ret; int ret;
const char *head_hash = NULL; const char *head_hash = NULL;
char *revisions = NULL, *shortrevisions = NULL; char *revisions = NULL, *shortrevisions = NULL;
struct argv_array make_script_args = ARGV_ARRAY_INIT; struct strvec make_script_args = STRVEC_INIT;
struct todo_list todo_list = TODO_LIST_INIT; struct todo_list todo_list = TODO_LIST_INIT;
struct replay_opts replay = get_replay_opts(opts); struct replay_opts replay = get_replay_opts(opts);
struct string_list commands = STRING_LIST_INIT_DUP; struct string_list commands = STRING_LIST_INIT_DUP;
@ -345,13 +345,13 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
write_file(path_squash_onto(), "%s\n", write_file(path_squash_onto(), "%s\n",
oid_to_hex(opts->squash_onto)); oid_to_hex(opts->squash_onto));
argv_array_pushl(&make_script_args, "", revisions, NULL); strvec_pushl(&make_script_args, "", revisions, NULL);
if (opts->restrict_revision) if (opts->restrict_revision)
argv_array_pushf(&make_script_args, "^%s", strvec_pushf(&make_script_args, "^%s",
oid_to_hex(&opts->restrict_revision->object.oid)); oid_to_hex(&opts->restrict_revision->object.oid));
ret = sequencer_make_script(the_repository, &todo_list.buf, ret = sequencer_make_script(the_repository, &todo_list.buf,
make_script_args.argc, make_script_args.argv, make_script_args.nr, make_script_args.v,
flags); flags);
if (ret) if (ret)
@ -372,7 +372,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
free(revisions); free(revisions);
free(shortrevisions); free(shortrevisions);
todo_list_release(&todo_list); todo_list_release(&todo_list);
argv_array_clear(&make_script_args); strvec_clear(&make_script_args);
return ret; return ret;
} }
@ -420,7 +420,7 @@ static int run_sequencer_rebase(struct rebase_options *opts,
struct child_process cmd = CHILD_PROCESS_INIT; struct child_process cmd = CHILD_PROCESS_INIT;
cmd.git_cmd = 1; cmd.git_cmd = 1;
argv_array_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL); strvec_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL);
ret = run_command(&cmd); ret = run_command(&cmd);
break; break;
@ -811,13 +811,13 @@ static int run_am(struct rebase_options *opts)
char *rebased_patches; char *rebased_patches;
am.git_cmd = 1; am.git_cmd = 1;
argv_array_push(&am.args, "am"); strvec_push(&am.args, "am");
if (opts->action && !strcmp("continue", opts->action)) { if (opts->action && !strcmp("continue", opts->action)) {
argv_array_push(&am.args, "--resolved"); strvec_push(&am.args, "--resolved");
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
if (opts->gpg_sign_opt) if (opts->gpg_sign_opt)
argv_array_push(&am.args, opts->gpg_sign_opt); strvec_push(&am.args, opts->gpg_sign_opt);
status = run_command(&am); status = run_command(&am);
if (status) if (status)
return status; return status;
@ -825,8 +825,8 @@ static int run_am(struct rebase_options *opts)
return move_to_original_branch(opts); return move_to_original_branch(opts);
} }
if (opts->action && !strcmp("skip", opts->action)) { if (opts->action && !strcmp("skip", opts->action)) {
argv_array_push(&am.args, "--skip"); strvec_push(&am.args, "--skip");
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
status = run_command(&am); status = run_command(&am);
if (status) if (status)
return status; return status;
@ -834,7 +834,7 @@ static int run_am(struct rebase_options *opts)
return move_to_original_branch(opts); return move_to_original_branch(opts);
} }
if (opts->action && !strcmp("show-current-patch", opts->action)) { if (opts->action && !strcmp("show-current-patch", opts->action)) {
argv_array_push(&am.args, "--show-current-patch"); strvec_push(&am.args, "--show-current-patch");
return run_command(&am); return run_command(&am);
} }
@ -852,29 +852,29 @@ static int run_am(struct rebase_options *opts)
status = error_errno(_("could not open '%s' for writing"), status = error_errno(_("could not open '%s' for writing"),
rebased_patches); rebased_patches);
free(rebased_patches); free(rebased_patches);
argv_array_clear(&am.args); strvec_clear(&am.args);
return status; return status;
} }
format_patch.git_cmd = 1; format_patch.git_cmd = 1;
argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout", strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
"--full-index", "--cherry-pick", "--right-only", "--full-index", "--cherry-pick", "--right-only",
"--src-prefix=a/", "--dst-prefix=b/", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/", "--no-renames",
"--no-cover-letter", "--pretty=mboxrd", "--topo-order", "--no-cover-letter", "--pretty=mboxrd", "--topo-order",
"--no-base", NULL); "--no-base", NULL);
if (opts->git_format_patch_opt.len) if (opts->git_format_patch_opt.len)
argv_array_split(&format_patch.args, strvec_split(&format_patch.args,
opts->git_format_patch_opt.buf); opts->git_format_patch_opt.buf);
argv_array_push(&format_patch.args, revisions.buf); strvec_push(&format_patch.args, revisions.buf);
if (opts->restrict_revision) if (opts->restrict_revision)
argv_array_pushf(&format_patch.args, "^%s", strvec_pushf(&format_patch.args, "^%s",
oid_to_hex(&opts->restrict_revision->object.oid)); oid_to_hex(&opts->restrict_revision->object.oid));
status = run_command(&format_patch); status = run_command(&format_patch);
if (status) { if (status) {
unlink(rebased_patches); unlink(rebased_patches);
free(rebased_patches); free(rebased_patches);
argv_array_clear(&am.args); strvec_clear(&am.args);
reset_head(the_repository, &opts->orig_head, "checkout", reset_head(the_repository, &opts->orig_head, "checkout",
opts->head_name, 0, opts->head_name, 0,
@ -896,20 +896,20 @@ static int run_am(struct rebase_options *opts)
status = error_errno(_("could not open '%s' for reading"), status = error_errno(_("could not open '%s' for reading"),
rebased_patches); rebased_patches);
free(rebased_patches); free(rebased_patches);
argv_array_clear(&am.args); strvec_clear(&am.args);
return status; return status;
} }
argv_array_pushv(&am.args, opts->git_am_opts.argv); strvec_pushv(&am.args, opts->git_am_opts.v);
argv_array_push(&am.args, "--rebasing"); strvec_push(&am.args, "--rebasing");
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
argv_array_push(&am.args, "--patch-format=mboxrd"); strvec_push(&am.args, "--patch-format=mboxrd");
if (opts->allow_rerere_autoupdate == RERERE_AUTOUPDATE) if (opts->allow_rerere_autoupdate == RERERE_AUTOUPDATE)
argv_array_push(&am.args, "--rerere-autoupdate"); strvec_push(&am.args, "--rerere-autoupdate");
else if (opts->allow_rerere_autoupdate == RERERE_NOAUTOUPDATE) else if (opts->allow_rerere_autoupdate == RERERE_NOAUTOUPDATE)
argv_array_push(&am.args, "--no-rerere-autoupdate"); strvec_push(&am.args, "--no-rerere-autoupdate");
if (opts->gpg_sign_opt) if (opts->gpg_sign_opt)
argv_array_push(&am.args, opts->gpg_sign_opt); strvec_push(&am.args, opts->gpg_sign_opt);
status = run_command(&am); status = run_command(&am);
unlink(rebased_patches); unlink(rebased_patches);
free(rebased_patches); free(rebased_patches);
@ -969,7 +969,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action)
add_var(&script_snippet, "revisions", opts->revisions); add_var(&script_snippet, "revisions", opts->revisions);
add_var(&script_snippet, "restrict_revision", opts->restrict_revision ? add_var(&script_snippet, "restrict_revision", opts->restrict_revision ?
oid_to_hex(&opts->restrict_revision->object.oid) : NULL); oid_to_hex(&opts->restrict_revision->object.oid) : NULL);
sq_quote_argv_pretty(&buf, opts->git_am_opts.argv); sq_quote_argv_pretty(&buf, opts->git_am_opts.v);
add_var(&script_snippet, "git_am_opt", buf.buf); add_var(&script_snippet, "git_am_opt", buf.buf);
strbuf_release(&buf); strbuf_release(&buf);
add_var(&script_snippet, "verbose", add_var(&script_snippet, "verbose",
@ -1625,8 +1625,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
allow_preemptive_ff = 0; allow_preemptive_ff = 0;
} }
for (i = 0; i < options.git_am_opts.argc; i++) { for (i = 0; i < options.git_am_opts.nr; i++) {
const char *option = options.git_am_opts.argv[i], *p; const char *option = options.git_am_opts.v[i], *p;
if (!strcmp(option, "--committer-date-is-author-date") || if (!strcmp(option, "--committer-date-is-author-date") ||
!strcmp(option, "--ignore-date") || !strcmp(option, "--ignore-date") ||
!strcmp(option, "--whitespace=fix") || !strcmp(option, "--whitespace=fix") ||
@ -1649,7 +1649,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
exit(1); exit(1);
if (!(options.flags & REBASE_NO_QUIET)) if (!(options.flags & REBASE_NO_QUIET))
argv_array_push(&options.git_am_opts, "-q"); strvec_push(&options.git_am_opts, "-q");
if (options.empty != EMPTY_UNSPECIFIED) if (options.empty != EMPTY_UNSPECIFIED)
imply_merge(&options, "--empty"); imply_merge(&options, "--empty");
@ -1721,10 +1721,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (isatty(2) && options.flags & REBASE_NO_QUIET) if (isatty(2) && options.flags & REBASE_NO_QUIET)
strbuf_addstr(&options.git_format_patch_opt, " --progress"); strbuf_addstr(&options.git_format_patch_opt, " --progress");
if (options.git_am_opts.argc || options.type == REBASE_APPLY) { if (options.git_am_opts.nr || options.type == REBASE_APPLY) {
/* all am options except -q are compatible only with --apply */ /* all am options except -q are compatible only with --apply */
for (i = options.git_am_opts.argc - 1; i >= 0; i--) for (i = options.git_am_opts.nr - 1; i >= 0; i--)
if (strcmp(options.git_am_opts.argv[i], "-q")) if (strcmp(options.git_am_opts.v[i], "-q"))
break; break;
if (i >= 0) { if (i >= 0) {
@ -1776,7 +1776,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (options.type == REBASE_PRESERVE_MERGES) if (options.type == REBASE_PRESERVE_MERGES)
die("cannot combine '--signoff' with " die("cannot combine '--signoff' with "
"'--preserve-merges'"); "'--preserve-merges'");
argv_array_push(&options.git_am_opts, "--signoff"); strvec_push(&options.git_am_opts, "--signoff");
options.flags |= REBASE_FORCE; options.flags |= REBASE_FORCE;
} }

View file

@ -15,7 +15,7 @@
#include "string-list.h" #include "string-list.h"
#include "oid-array.h" #include "oid-array.h"
#include "connected.h" #include "connected.h"
#include "argv-array.h" #include "strvec.h"
#include "version.h" #include "version.h"
#include "tag.h" #include "tag.h"
#include "gpg-interface.h" #include "gpg-interface.h"
@ -667,25 +667,25 @@ static void prepare_push_cert_sha1(struct child_process *proc)
nonce_status = check_nonce(push_cert.buf, bogs); nonce_status = check_nonce(push_cert.buf, bogs);
} }
if (!is_null_oid(&push_cert_oid)) { if (!is_null_oid(&push_cert_oid)) {
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT=%s", strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s",
oid_to_hex(&push_cert_oid)); oid_to_hex(&push_cert_oid));
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s", strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s",
sigcheck.signer ? sigcheck.signer : ""); sigcheck.signer ? sigcheck.signer : "");
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s", strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s",
sigcheck.key ? sigcheck.key : ""); sigcheck.key ? sigcheck.key : "");
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c", strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c",
sigcheck.result); sigcheck.result);
if (push_cert_nonce) { if (push_cert_nonce) {
argv_array_pushf(&proc->env_array, strvec_pushf(&proc->env_array,
"GIT_PUSH_CERT_NONCE=%s", "GIT_PUSH_CERT_NONCE=%s",
push_cert_nonce); push_cert_nonce);
argv_array_pushf(&proc->env_array, strvec_pushf(&proc->env_array,
"GIT_PUSH_CERT_NONCE_STATUS=%s", "GIT_PUSH_CERT_NONCE_STATUS=%s",
nonce_status); nonce_status);
if (nonce_status == NONCE_SLOP) if (nonce_status == NONCE_SLOP)
argv_array_pushf(&proc->env_array, strvec_pushf(&proc->env_array,
"GIT_PUSH_CERT_NONCE_SLOP=%ld", "GIT_PUSH_CERT_NONCE_SLOP=%ld",
nonce_stamp_slop); nonce_stamp_slop);
} }
} }
} }
@ -720,16 +720,16 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,
if (feed_state->push_options) { if (feed_state->push_options) {
int i; int i;
for (i = 0; i < feed_state->push_options->nr; i++) for (i = 0; i < feed_state->push_options->nr; i++)
argv_array_pushf(&proc.env_array, strvec_pushf(&proc.env_array,
"GIT_PUSH_OPTION_%d=%s", i, "GIT_PUSH_OPTION_%d=%s", i,
feed_state->push_options->items[i].string); feed_state->push_options->items[i].string);
argv_array_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d", strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d",
feed_state->push_options->nr); feed_state->push_options->nr);
} else } else
argv_array_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT"); strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT");
if (tmp_objdir) if (tmp_objdir)
argv_array_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir)); strvec_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir));
if (use_sideband) { if (use_sideband) {
memset(&muxer, 0, sizeof(muxer)); memset(&muxer, 0, sizeof(muxer));
@ -931,7 +931,7 @@ static int head_has_history(void)
} }
static const char *push_to_deploy(unsigned char *sha1, static const char *push_to_deploy(unsigned char *sha1,
struct argv_array *env, struct strvec *env,
const char *work_tree) const char *work_tree)
{ {
const char *update_refresh[] = { const char *update_refresh[] = {
@ -950,7 +950,7 @@ static const char *push_to_deploy(unsigned char *sha1,
struct child_process child = CHILD_PROCESS_INIT; struct child_process child = CHILD_PROCESS_INIT;
child.argv = update_refresh; child.argv = update_refresh;
child.env = env->argv; child.env = env->v;
child.dir = work_tree; child.dir = work_tree;
child.no_stdin = 1; child.no_stdin = 1;
child.stdout_to_stderr = 1; child.stdout_to_stderr = 1;
@ -961,7 +961,7 @@ static const char *push_to_deploy(unsigned char *sha1,
/* run_command() does not clean up completely; reinitialize */ /* run_command() does not clean up completely; reinitialize */
child_process_init(&child); child_process_init(&child);
child.argv = diff_files; child.argv = diff_files;
child.env = env->argv; child.env = env->v;
child.dir = work_tree; child.dir = work_tree;
child.no_stdin = 1; child.no_stdin = 1;
child.stdout_to_stderr = 1; child.stdout_to_stderr = 1;
@ -974,7 +974,7 @@ static const char *push_to_deploy(unsigned char *sha1,
child_process_init(&child); child_process_init(&child);
child.argv = diff_index; child.argv = diff_index;
child.env = env->argv; child.env = env->v;
child.no_stdin = 1; child.no_stdin = 1;
child.no_stdout = 1; child.no_stdout = 1;
child.stdout_to_stderr = 0; child.stdout_to_stderr = 0;
@ -985,7 +985,7 @@ static const char *push_to_deploy(unsigned char *sha1,
read_tree[3] = hash_to_hex(sha1); read_tree[3] = hash_to_hex(sha1);
child_process_init(&child); child_process_init(&child);
child.argv = read_tree; child.argv = read_tree;
child.env = env->argv; child.env = env->v;
child.dir = work_tree; child.dir = work_tree;
child.no_stdin = 1; child.no_stdin = 1;
child.no_stdout = 1; child.no_stdout = 1;
@ -1000,11 +1000,11 @@ static const char *push_to_deploy(unsigned char *sha1,
static const char *push_to_checkout_hook = "push-to-checkout"; static const char *push_to_checkout_hook = "push-to-checkout";
static const char *push_to_checkout(unsigned char *hash, static const char *push_to_checkout(unsigned char *hash,
struct argv_array *env, struct strvec *env,
const char *work_tree) const char *work_tree)
{ {
argv_array_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree));
if (run_hook_le(env->argv, push_to_checkout_hook, if (run_hook_le(env->v, push_to_checkout_hook,
hash_to_hex(hash), NULL)) hash_to_hex(hash), NULL))
return "push-to-checkout hook declined"; return "push-to-checkout hook declined";
else else
@ -1014,7 +1014,7 @@ static const char *push_to_checkout(unsigned char *hash,
static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree) static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree)
{ {
const char *retval, *work_tree, *git_dir = NULL; const char *retval, *work_tree, *git_dir = NULL;
struct argv_array env = ARGV_ARRAY_INIT; struct strvec env = STRVEC_INIT;
if (worktree && worktree->path) if (worktree && worktree->path)
work_tree = worktree->path; work_tree = worktree->path;
@ -1030,14 +1030,14 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w
if (!git_dir) if (!git_dir)
git_dir = get_git_dir(); git_dir = get_git_dir();
argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir));
if (!find_hook(push_to_checkout_hook)) if (!find_hook(push_to_checkout_hook))
retval = push_to_deploy(sha1, &env, work_tree); retval = push_to_deploy(sha1, &env, work_tree);
else else
retval = push_to_checkout(sha1, &env, work_tree); retval = push_to_checkout(sha1, &env, work_tree);
argv_array_clear(&env); strvec_clear(&env);
return retval; return retval;
} }
@ -1205,11 +1205,11 @@ static void run_update_post_hook(struct command *commands)
for (cmd = commands; cmd; cmd = cmd->next) { for (cmd = commands; cmd; cmd = cmd->next) {
if (cmd->error_string || cmd->did_not_exist) if (cmd->error_string || cmd->did_not_exist)
continue; continue;
if (!proc.args.argc) if (!proc.args.nr)
argv_array_push(&proc.args, hook); strvec_push(&proc.args, hook);
argv_array_push(&proc.args, cmd->ref_name); strvec_push(&proc.args, cmd->ref_name);
} }
if (!proc.args.argc) if (!proc.args.nr)
return; return;
proc.no_stdin = 1; proc.no_stdin = 1;
@ -1715,10 +1715,10 @@ static const char *parse_pack_header(struct pack_header *hdr)
static const char *pack_lockfile; static const char *pack_lockfile;
static void push_header_arg(struct argv_array *args, struct pack_header *hdr) static void push_header_arg(struct strvec *args, struct pack_header *hdr)
{ {
argv_array_pushf(args, "--pack_header=%"PRIu32",%"PRIu32, strvec_pushf(args, "--pack_header=%"PRIu32",%"PRIu32,
ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries)); ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries));
} }
static const char *unpack(int err_fd, struct shallow_info *si) static const char *unpack(int err_fd, struct shallow_info *si)
@ -1742,8 +1742,8 @@ static const char *unpack(int err_fd, struct shallow_info *si)
if (si->nr_ours || si->nr_theirs) { if (si->nr_ours || si->nr_theirs) {
alt_shallow_file = setup_temporary_shallow(si->shallow); alt_shallow_file = setup_temporary_shallow(si->shallow);
argv_array_push(&child.args, "--shallow-file"); strvec_push(&child.args, "--shallow-file");
argv_array_push(&child.args, alt_shallow_file); strvec_push(&child.args, alt_shallow_file);
} }
tmp_objdir = tmp_objdir_create(); tmp_objdir = tmp_objdir_create();
@ -1762,16 +1762,16 @@ static const char *unpack(int err_fd, struct shallow_info *si)
tmp_objdir_add_as_alternate(tmp_objdir); tmp_objdir_add_as_alternate(tmp_objdir);
if (ntohl(hdr.hdr_entries) < unpack_limit) { if (ntohl(hdr.hdr_entries) < unpack_limit) {
argv_array_push(&child.args, "unpack-objects"); strvec_push(&child.args, "unpack-objects");
push_header_arg(&child.args, &hdr); push_header_arg(&child.args, &hdr);
if (quiet) if (quiet)
argv_array_push(&child.args, "-q"); strvec_push(&child.args, "-q");
if (fsck_objects) if (fsck_objects)
argv_array_pushf(&child.args, "--strict%s", strvec_pushf(&child.args, "--strict%s",
fsck_msg_types.buf); fsck_msg_types.buf);
if (max_input_size) if (max_input_size)
argv_array_pushf(&child.args, "--max-input-size=%"PRIuMAX, strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX,
(uintmax_t)max_input_size); (uintmax_t)max_input_size);
child.no_stdout = 1; child.no_stdout = 1;
child.err = err_fd; child.err = err_fd;
child.git_cmd = 1; child.git_cmd = 1;
@ -1781,28 +1781,28 @@ static const char *unpack(int err_fd, struct shallow_info *si)
} else { } else {
char hostname[HOST_NAME_MAX + 1]; char hostname[HOST_NAME_MAX + 1];
argv_array_pushl(&child.args, "index-pack", "--stdin", NULL); strvec_pushl(&child.args, "index-pack", "--stdin", NULL);
push_header_arg(&child.args, &hdr); push_header_arg(&child.args, &hdr);
if (xgethostname(hostname, sizeof(hostname))) if (xgethostname(hostname, sizeof(hostname)))
xsnprintf(hostname, sizeof(hostname), "localhost"); xsnprintf(hostname, sizeof(hostname), "localhost");
argv_array_pushf(&child.args, strvec_pushf(&child.args,
"--keep=receive-pack %"PRIuMAX" on %s", "--keep=receive-pack %"PRIuMAX" on %s",
(uintmax_t)getpid(), (uintmax_t)getpid(),
hostname); hostname);
if (!quiet && err_fd) if (!quiet && err_fd)
argv_array_push(&child.args, "--show-resolving-progress"); strvec_push(&child.args, "--show-resolving-progress");
if (use_sideband) if (use_sideband)
argv_array_push(&child.args, "--report-end-of-input"); strvec_push(&child.args, "--report-end-of-input");
if (fsck_objects) if (fsck_objects)
argv_array_pushf(&child.args, "--strict%s", strvec_pushf(&child.args, "--strict%s",
fsck_msg_types.buf); fsck_msg_types.buf);
if (!reject_thin) if (!reject_thin)
argv_array_push(&child.args, "--fix-thin"); strvec_push(&child.args, "--fix-thin");
if (max_input_size) if (max_input_size)
argv_array_pushf(&child.args, "--max-input-size=%"PRIuMAX, strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX,
(uintmax_t)max_input_size); (uintmax_t)max_input_size);
child.out = -1; child.out = -1;
child.err = err_fd; child.err = err_fd;
child.git_cmd = 1; child.git_cmd = 1;

View file

@ -117,12 +117,12 @@ static char *strip_escapes(const char *str, const char *service,
} }
} }
static void parse_argv(struct argv_array *out, const char *arg, const char *service) static void parse_argv(struct strvec *out, const char *arg, const char *service)
{ {
while (*arg) { while (*arg) {
char *expanded = strip_escapes(arg, service, &arg); char *expanded = strip_escapes(arg, service, &arg);
if (expanded) if (expanded)
argv_array_push(out, expanded); strvec_push(out, expanded);
free(expanded); free(expanded);
} }
} }

View file

@ -10,7 +10,7 @@
#include "refs.h" #include "refs.h"
#include "refspec.h" #include "refspec.h"
#include "object-store.h" #include "object-store.h"
#include "argv-array.h" #include "strvec.h"
#include "commit-reach.h" #include "commit-reach.h"
static const char * const builtin_remote_usage[] = { static const char * const builtin_remote_usage[] = {
@ -1451,35 +1451,35 @@ static int update(int argc, const char **argv)
N_("prune remotes after fetching")), N_("prune remotes after fetching")),
OPT_END() OPT_END()
}; };
struct argv_array fetch_argv = ARGV_ARRAY_INIT; struct strvec fetch_argv = STRVEC_INIT;
int default_defined = 0; int default_defined = 0;
int retval; int retval;
argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage, argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
PARSE_OPT_KEEP_ARGV0); PARSE_OPT_KEEP_ARGV0);
argv_array_push(&fetch_argv, "fetch"); strvec_push(&fetch_argv, "fetch");
if (prune != -1) if (prune != -1)
argv_array_push(&fetch_argv, prune ? "--prune" : "--no-prune"); strvec_push(&fetch_argv, prune ? "--prune" : "--no-prune");
if (verbose) if (verbose)
argv_array_push(&fetch_argv, "-v"); strvec_push(&fetch_argv, "-v");
argv_array_push(&fetch_argv, "--multiple"); strvec_push(&fetch_argv, "--multiple");
if (argc < 2) if (argc < 2)
argv_array_push(&fetch_argv, "default"); strvec_push(&fetch_argv, "default");
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
argv_array_push(&fetch_argv, argv[i]); strvec_push(&fetch_argv, argv[i]);
if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) { if (strcmp(fetch_argv.v[fetch_argv.nr-1], "default") == 0) {
git_config(get_remote_default, &default_defined); git_config(get_remote_default, &default_defined);
if (!default_defined) { if (!default_defined) {
argv_array_pop(&fetch_argv); strvec_pop(&fetch_argv);
argv_array_push(&fetch_argv, "--all"); strvec_push(&fetch_argv, "--all");
} }
} }
retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD); retval = run_command_v_opt(fetch_argv.v, RUN_GIT_CMD);
argv_array_clear(&fetch_argv); strvec_clear(&fetch_argv);
return retval; return retval;
} }

View file

@ -7,7 +7,7 @@
#include "sigchain.h" #include "sigchain.h"
#include "strbuf.h" #include "strbuf.h"
#include "string-list.h" #include "string-list.h"
#include "argv-array.h" #include "strvec.h"
#include "midx.h" #include "midx.h"
#include "packfile.h" #include "packfile.h"
#include "prune-packed.h" #include "prune-packed.h"
@ -153,28 +153,28 @@ struct pack_objects_args {
static void prepare_pack_objects(struct child_process *cmd, static void prepare_pack_objects(struct child_process *cmd,
const struct pack_objects_args *args) const struct pack_objects_args *args)
{ {
argv_array_push(&cmd->args, "pack-objects"); strvec_push(&cmd->args, "pack-objects");
if (args->window) if (args->window)
argv_array_pushf(&cmd->args, "--window=%s", args->window); strvec_pushf(&cmd->args, "--window=%s", args->window);
if (args->window_memory) if (args->window_memory)
argv_array_pushf(&cmd->args, "--window-memory=%s", args->window_memory); strvec_pushf(&cmd->args, "--window-memory=%s", args->window_memory);
if (args->depth) if (args->depth)
argv_array_pushf(&cmd->args, "--depth=%s", args->depth); strvec_pushf(&cmd->args, "--depth=%s", args->depth);
if (args->threads) if (args->threads)
argv_array_pushf(&cmd->args, "--threads=%s", args->threads); strvec_pushf(&cmd->args, "--threads=%s", args->threads);
if (args->max_pack_size) if (args->max_pack_size)
argv_array_pushf(&cmd->args, "--max-pack-size=%s", args->max_pack_size); strvec_pushf(&cmd->args, "--max-pack-size=%s", args->max_pack_size);
if (args->no_reuse_delta) if (args->no_reuse_delta)
argv_array_pushf(&cmd->args, "--no-reuse-delta"); strvec_pushf(&cmd->args, "--no-reuse-delta");
if (args->no_reuse_object) if (args->no_reuse_object)
argv_array_pushf(&cmd->args, "--no-reuse-object"); strvec_pushf(&cmd->args, "--no-reuse-object");
if (args->local) if (args->local)
argv_array_push(&cmd->args, "--local"); strvec_push(&cmd->args, "--local");
if (args->quiet) if (args->quiet)
argv_array_push(&cmd->args, "--quiet"); strvec_push(&cmd->args, "--quiet");
if (delta_base_offset) if (delta_base_offset)
argv_array_push(&cmd->args, "--delta-base-offset"); strvec_push(&cmd->args, "--delta-base-offset");
argv_array_push(&cmd->args, packtmp); strvec_push(&cmd->args, packtmp);
cmd->git_cmd = 1; cmd->git_cmd = 1;
cmd->out = -1; cmd->out = -1;
} }
@ -361,24 +361,24 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
prepare_pack_objects(&cmd, &po_args); prepare_pack_objects(&cmd, &po_args);
argv_array_push(&cmd.args, "--keep-true-parents"); strvec_push(&cmd.args, "--keep-true-parents");
if (!pack_kept_objects) if (!pack_kept_objects)
argv_array_push(&cmd.args, "--honor-pack-keep"); strvec_push(&cmd.args, "--honor-pack-keep");
for (i = 0; i < keep_pack_list.nr; i++) for (i = 0; i < keep_pack_list.nr; i++)
argv_array_pushf(&cmd.args, "--keep-pack=%s", strvec_pushf(&cmd.args, "--keep-pack=%s",
keep_pack_list.items[i].string); keep_pack_list.items[i].string);
argv_array_push(&cmd.args, "--non-empty"); strvec_push(&cmd.args, "--non-empty");
argv_array_push(&cmd.args, "--all"); strvec_push(&cmd.args, "--all");
argv_array_push(&cmd.args, "--reflog"); strvec_push(&cmd.args, "--reflog");
argv_array_push(&cmd.args, "--indexed-objects"); strvec_push(&cmd.args, "--indexed-objects");
if (has_promisor_remote()) if (has_promisor_remote())
argv_array_push(&cmd.args, "--exclude-promisor-objects"); strvec_push(&cmd.args, "--exclude-promisor-objects");
if (write_bitmaps > 0) if (write_bitmaps > 0)
argv_array_push(&cmd.args, "--write-bitmap-index"); strvec_push(&cmd.args, "--write-bitmap-index");
else if (write_bitmaps < 0) else if (write_bitmaps < 0)
argv_array_push(&cmd.args, "--write-bitmap-index-quiet"); strvec_push(&cmd.args, "--write-bitmap-index-quiet");
if (use_delta_islands) if (use_delta_islands)
argv_array_push(&cmd.args, "--delta-islands"); strvec_push(&cmd.args, "--delta-islands");
if (pack_everything & ALL_INTO_ONE) { if (pack_everything & ALL_INTO_ONE) {
get_non_kept_pack_filenames(&existing_packs, &keep_pack_list); get_non_kept_pack_filenames(&existing_packs, &keep_pack_list);
@ -387,23 +387,23 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
if (existing_packs.nr && delete_redundant) { if (existing_packs.nr && delete_redundant) {
if (unpack_unreachable) { if (unpack_unreachable) {
argv_array_pushf(&cmd.args, strvec_pushf(&cmd.args,
"--unpack-unreachable=%s", "--unpack-unreachable=%s",
unpack_unreachable); unpack_unreachable);
argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
} else if (pack_everything & LOOSEN_UNREACHABLE) { } else if (pack_everything & LOOSEN_UNREACHABLE) {
argv_array_push(&cmd.args, strvec_push(&cmd.args,
"--unpack-unreachable"); "--unpack-unreachable");
} else if (keep_unreachable) { } else if (keep_unreachable) {
argv_array_push(&cmd.args, "--keep-unreachable"); strvec_push(&cmd.args, "--keep-unreachable");
argv_array_push(&cmd.args, "--pack-loose-unreachable"); strvec_push(&cmd.args, "--pack-loose-unreachable");
} else { } else {
argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
} }
} }
} else { } else {
argv_array_push(&cmd.args, "--unpacked"); strvec_push(&cmd.args, "--unpacked");
argv_array_push(&cmd.args, "--incremental"); strvec_push(&cmd.args, "--incremental");
} }
cmd.no_stdin = 1; cmd.no_stdin = 1;

View file

@ -228,13 +228,13 @@ static int export_object(const struct object_id *oid, enum object_type type,
if (fd < 0) if (fd < 0)
return error_errno(_("unable to open %s for writing"), filename); return error_errno(_("unable to open %s for writing"), filename);
argv_array_push(&cmd.args, "--no-replace-objects"); strvec_push(&cmd.args, "--no-replace-objects");
argv_array_push(&cmd.args, "cat-file"); strvec_push(&cmd.args, "cat-file");
if (raw) if (raw)
argv_array_push(&cmd.args, type_name(type)); strvec_push(&cmd.args, type_name(type));
else else
argv_array_push(&cmd.args, "-p"); strvec_push(&cmd.args, "-p");
argv_array_push(&cmd.args, oid_to_hex(oid)); strvec_push(&cmd.args, oid_to_hex(oid));
cmd.git_cmd = 1; cmd.git_cmd = 1;
cmd.out = fd; cmd.out = fd;
@ -502,7 +502,7 @@ static int convert_graft_file(int force)
const char *graft_file = get_graft_file(the_repository); const char *graft_file = get_graft_file(the_repository);
FILE *fp = fopen_or_warn(graft_file, "r"); FILE *fp = fopen_or_warn(graft_file, "r");
struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
if (!fp) if (!fp)
return -1; return -1;
@ -512,10 +512,10 @@ static int convert_graft_file(int force)
if (*buf.buf == '#') if (*buf.buf == '#')
continue; continue;
argv_array_split(&args, buf.buf); strvec_split(&args, buf.buf);
if (args.argc && create_graft(args.argc, args.argv, force, 1)) if (args.nr && create_graft(args.nr, args.v, force, 1))
strbuf_addf(&err, "\n\t%s", buf.buf); strbuf_addf(&err, "\n\t%s", buf.buf);
argv_array_clear(&args); strvec_clear(&args);
} }
fclose(fp); fclose(fp);

View file

@ -4,7 +4,7 @@
#include "refs.h" #include "refs.h"
#include "builtin.h" #include "builtin.h"
#include "color.h" #include "color.h"
#include "argv-array.h" #include "strvec.h"
#include "parse-options.h" #include "parse-options.h"
#include "dir.h" #include "dir.h"
#include "commit-slab.h" #include "commit-slab.h"
@ -20,7 +20,7 @@ static const char* show_branch_usage[] = {
static int showbranch_use_color = -1; static int showbranch_use_color = -1;
static struct argv_array default_args = ARGV_ARRAY_INIT; static struct strvec default_args = STRVEC_INIT;
/* /*
* TODO: convert this use of commit->object.flags to commit-slab * TODO: convert this use of commit->object.flags to commit-slab
@ -561,9 +561,9 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
* default_arg is now passed to parse_options(), so we need to * default_arg is now passed to parse_options(), so we need to
* mimic the real argv a bit better. * mimic the real argv a bit better.
*/ */
if (!default_args.argc) if (!default_args.nr)
argv_array_push(&default_args, "show-branch"); strvec_push(&default_args, "show-branch");
argv_array_push(&default_args, value); strvec_push(&default_args, value);
return 0; return 0;
} }
@ -684,9 +684,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
git_config(git_show_branch_config, NULL); git_config(git_show_branch_config, NULL);
/* If nothing is specified, try the default first */ /* If nothing is specified, try the default first */
if (ac == 1 && default_args.argc) { if (ac == 1 && default_args.nr) {
ac = default_args.argc; ac = default_args.nr;
av = default_args.argv; av = default_args.v;
} }
ac = parse_options(ac, av, prefix, builtin_show_branch_options, ac = parse_options(ac, av, prefix, builtin_show_branch_options,

View file

@ -7,7 +7,7 @@
#include "cache-tree.h" #include "cache-tree.h"
#include "unpack-trees.h" #include "unpack-trees.h"
#include "merge-recursive.h" #include "merge-recursive.h"
#include "argv-array.h" #include "strvec.h"
#include "run-command.h" #include "run-command.h"
#include "dir.h" #include "dir.h"
#include "rerere.h" #include "rerere.h"
@ -277,8 +277,8 @@ static int diff_tree_binary(struct strbuf *out, struct object_id *w_commit)
* however it should be done together with apply_cached. * however it should be done together with apply_cached.
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "diff-tree", "--binary", NULL); strvec_pushl(&cp.args, "diff-tree", "--binary", NULL);
argv_array_pushf(&cp.args, "%s^2^..%s^2", w_commit_hex, w_commit_hex); strvec_pushf(&cp.args, "%s^2^..%s^2", w_commit_hex, w_commit_hex);
return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); return pipe_command(&cp, NULL, 0, out, 0, NULL, 0);
} }
@ -293,7 +293,7 @@ static int apply_cached(struct strbuf *out)
* buffer. * buffer.
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "apply", "--cached", NULL); strvec_pushl(&cp.args, "apply", "--cached", NULL);
return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0); return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0);
} }
@ -306,7 +306,7 @@ static int reset_head(void)
* API for resetting. * API for resetting.
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_push(&cp.args, "reset"); strvec_push(&cp.args, "reset");
return run_command(&cp); return run_command(&cp);
} }
@ -335,9 +335,9 @@ static int get_newly_staged(struct strbuf *out, struct object_id *c_tree)
* converted together with update_index. * converted together with update_index.
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "diff-index", "--cached", "--name-only", strvec_pushl(&cp.args, "diff-index", "--cached", "--name-only",
"--diff-filter=A", NULL); "--diff-filter=A", NULL);
argv_array_push(&cp.args, c_tree_hex); strvec_push(&cp.args, c_tree_hex);
return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); return pipe_command(&cp, NULL, 0, out, 0, NULL, 0);
} }
@ -350,7 +350,7 @@ static int update_index(struct strbuf *out)
* function exposed in order to remove this forking. * function exposed in order to remove this forking.
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "update-index", "--add", "--stdin", NULL); strvec_pushl(&cp.args, "update-index", "--add", "--stdin", NULL);
return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0); return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0);
} }
@ -365,10 +365,10 @@ static int restore_untracked(struct object_id *u_tree)
* run_command to fork processes that will not interfere. * run_command to fork processes that will not interfere.
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_push(&cp.args, "read-tree"); strvec_push(&cp.args, "read-tree");
argv_array_push(&cp.args, oid_to_hex(u_tree)); strvec_push(&cp.args, oid_to_hex(u_tree));
argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf); stash_index_path.buf);
if (run_command(&cp)) { if (run_command(&cp)) {
remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);
return -1; return -1;
@ -376,9 +376,9 @@ static int restore_untracked(struct object_id *u_tree)
child_process_init(&cp); child_process_init(&cp);
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "checkout-index", "--all", NULL); strvec_pushl(&cp.args, "checkout-index", "--all", NULL);
argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf); stash_index_path.buf);
res = run_command(&cp); res = run_command(&cp);
remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);
@ -499,11 +499,11 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
*/ */
cp.git_cmd = 1; cp.git_cmd = 1;
cp.dir = prefix; cp.dir = prefix;
argv_array_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s", strvec_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s",
absolute_path(get_git_work_tree())); absolute_path(get_git_work_tree()));
argv_array_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s", strvec_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s",
absolute_path(get_git_dir())); absolute_path(get_git_dir()));
argv_array_push(&cp.args, "status"); strvec_push(&cp.args, "status");
run_command(&cp); run_command(&cp);
} }
@ -546,9 +546,9 @@ static int do_drop_stash(struct stash_info *info, int quiet)
*/ */
cp_reflog.git_cmd = 1; cp_reflog.git_cmd = 1;
argv_array_pushl(&cp_reflog.args, "reflog", "delete", "--updateref", strvec_pushl(&cp_reflog.args, "reflog", "delete", "--updateref",
"--rewrite", NULL); "--rewrite", NULL);
argv_array_push(&cp_reflog.args, info->revision.buf); strvec_push(&cp_reflog.args, info->revision.buf);
ret = run_command(&cp_reflog); ret = run_command(&cp_reflog);
if (!ret) { if (!ret) {
if (!quiet) if (!quiet)
@ -566,8 +566,8 @@ static int do_drop_stash(struct stash_info *info, int quiet)
cp.git_cmd = 1; cp.git_cmd = 1;
/* Even though --quiet is specified, rev-parse still outputs the hash */ /* Even though --quiet is specified, rev-parse still outputs the hash */
cp.no_stdout = 1; cp.no_stdout = 1;
argv_array_pushl(&cp.args, "rev-parse", "--verify", "--quiet", NULL); strvec_pushl(&cp.args, "rev-parse", "--verify", "--quiet", NULL);
argv_array_pushf(&cp.args, "%s@{0}", ref_stash); strvec_pushf(&cp.args, "%s@{0}", ref_stash);
ret = run_command(&cp); ret = run_command(&cp);
/* do_clear_stash if we just dropped the last stash entry */ /* do_clear_stash if we just dropped the last stash entry */
@ -663,9 +663,9 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
return -1; return -1;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "checkout", "-b", NULL); strvec_pushl(&cp.args, "checkout", "-b", NULL);
argv_array_push(&cp.args, branch); strvec_push(&cp.args, branch);
argv_array_push(&cp.args, oid_to_hex(&info.b_commit)); strvec_push(&cp.args, oid_to_hex(&info.b_commit));
ret = run_command(&cp); ret = run_command(&cp);
if (!ret) if (!ret)
ret = do_apply_stash(prefix, &info, 1, 0); ret = do_apply_stash(prefix, &info, 1, 0);
@ -692,11 +692,11 @@ static int list_stash(int argc, const char **argv, const char *prefix)
return 0; return 0;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "log", "--format=%gd: %gs", "-g", strvec_pushl(&cp.args, "log", "--format=%gd: %gs", "-g",
"--first-parent", "-m", NULL); "--first-parent", "-m", NULL);
argv_array_pushv(&cp.args, argv); strvec_pushv(&cp.args, argv);
argv_array_push(&cp.args, ref_stash); strvec_push(&cp.args, ref_stash);
argv_array_push(&cp.args, "--"); strvec_push(&cp.args, "--");
return run_command(&cp); return run_command(&cp);
} }
@ -727,8 +727,8 @@ static int show_stash(int argc, const char **argv, const char *prefix)
int ret = 0; int ret = 0;
struct stash_info info; struct stash_info info;
struct rev_info rev; struct rev_info rev;
struct argv_array stash_args = ARGV_ARRAY_INIT; struct strvec stash_args = STRVEC_INIT;
struct argv_array revision_args = ARGV_ARRAY_INIT; struct strvec revision_args = STRVEC_INIT;
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
}; };
@ -737,16 +737,16 @@ static int show_stash(int argc, const char **argv, const char *prefix)
git_config(git_diff_ui_config, NULL); git_config(git_diff_ui_config, NULL);
init_revisions(&rev, prefix); init_revisions(&rev, prefix);
argv_array_push(&revision_args, argv[0]); strvec_push(&revision_args, argv[0]);
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (argv[i][0] != '-') if (argv[i][0] != '-')
argv_array_push(&stash_args, argv[i]); strvec_push(&stash_args, argv[i]);
else else
argv_array_push(&revision_args, argv[i]); strvec_push(&revision_args, argv[i]);
} }
ret = get_stash_info(&info, stash_args.argc, stash_args.argv); ret = get_stash_info(&info, stash_args.nr, stash_args.v);
argv_array_clear(&stash_args); strvec_clear(&stash_args);
if (ret) if (ret)
return -1; return -1;
@ -754,7 +754,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
* The config settings are applied only if there are not passed * The config settings are applied only if there are not passed
* any options. * any options.
*/ */
if (revision_args.argc == 1) { if (revision_args.nr == 1) {
if (show_stat) if (show_stat)
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT; rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT;
@ -767,7 +767,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
} }
} }
argc = setup_revisions(revision_args.argc, revision_args.argv, &rev, NULL); argc = setup_revisions(revision_args.nr, revision_args.v, &rev, NULL);
if (argc > 1) { if (argc > 1) {
free_stash_info(&info); free_stash_info(&info);
usage_with_options(git_stash_show_usage, options); usage_with_options(git_stash_show_usage, options);
@ -842,12 +842,12 @@ static int store_stash(int argc, const char **argv, const char *prefix)
return do_store_stash(&obj, stash_msg, quiet); return do_store_stash(&obj, stash_msg, quiet);
} }
static void add_pathspecs(struct argv_array *args, static void add_pathspecs(struct strvec *args,
const struct pathspec *ps) { const struct pathspec *ps) {
int i; int i;
for (i = 0; i < ps->nr; i++) for (i = 0; i < ps->nr; i++)
argv_array_push(args, ps->items[i].original); strvec_push(args, ps->items[i].original);
} }
/* /*
@ -960,9 +960,9 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
struct index_state istate = { NULL }; struct index_state istate = { NULL };
cp_upd_index.git_cmd = 1; cp_upd_index.git_cmd = 1;
argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
"--remove", "--stdin", NULL); "--remove", "--stdin", NULL);
argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf); stash_index_path.buf);
strbuf_addf(&untracked_msg, "untracked files on %s\n", msg->buf); strbuf_addf(&untracked_msg, "untracked files on %s\n", msg->buf);
@ -1003,9 +1003,9 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);
cp_read_tree.git_cmd = 1; cp_read_tree.git_cmd = 1;
argv_array_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL); strvec_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL);
argv_array_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s", strvec_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf); stash_index_path.buf);
if (run_command(&cp_read_tree)) { if (run_command(&cp_read_tree)) {
ret = -1; ret = -1;
goto done; goto done;
@ -1034,8 +1034,8 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
} }
cp_diff_tree.git_cmd = 1; cp_diff_tree.git_cmd = 1;
argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD", strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD",
oid_to_hex(&info->w_tree), "--", NULL); oid_to_hex(&info->w_tree), "--", NULL);
if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) { if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) {
ret = -1; ret = -1;
goto done; goto done;
@ -1088,11 +1088,11 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
} }
cp_upd_index.git_cmd = 1; cp_upd_index.git_cmd = 1;
argv_array_pushl(&cp_upd_index.args, "update-index", strvec_pushl(&cp_upd_index.args, "update-index",
"--ignore-skip-worktree-entries", "--ignore-skip-worktree-entries",
"-z", "--add", "--remove", "--stdin", NULL); "-z", "--add", "--remove", "--stdin", NULL);
argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf); stash_index_path.buf);
if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len, if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len,
NULL, 0, NULL, 0)) { NULL, 0, NULL, 0)) {
@ -1342,10 +1342,10 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "clean", "--force", strvec_pushl(&cp.args, "clean", "--force",
"--quiet", "-d", NULL); "--quiet", "-d", NULL);
if (include_untracked == INCLUDE_ALL_FILES) if (include_untracked == INCLUDE_ALL_FILES)
argv_array_push(&cp.args, "-x"); strvec_push(&cp.args, "-x");
if (run_command(&cp)) { if (run_command(&cp)) {
ret = -1; ret = -1;
goto done; goto done;
@ -1359,12 +1359,12 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
struct strbuf out = STRBUF_INIT; struct strbuf out = STRBUF_INIT;
cp_add.git_cmd = 1; cp_add.git_cmd = 1;
argv_array_push(&cp_add.args, "add"); strvec_push(&cp_add.args, "add");
if (!include_untracked) if (!include_untracked)
argv_array_push(&cp_add.args, "-u"); strvec_push(&cp_add.args, "-u");
if (include_untracked == INCLUDE_ALL_FILES) if (include_untracked == INCLUDE_ALL_FILES)
argv_array_push(&cp_add.args, "--force"); strvec_push(&cp_add.args, "--force");
argv_array_push(&cp_add.args, "--"); strvec_push(&cp_add.args, "--");
add_pathspecs(&cp_add.args, ps); add_pathspecs(&cp_add.args, ps);
if (run_command(&cp_add)) { if (run_command(&cp_add)) {
ret = -1; ret = -1;
@ -1372,9 +1372,9 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
} }
cp_diff.git_cmd = 1; cp_diff.git_cmd = 1;
argv_array_pushl(&cp_diff.args, "diff-index", "-p", strvec_pushl(&cp_diff.args, "diff-index", "-p",
"--cached", "--binary", "HEAD", "--", "--cached", "--binary", "HEAD", "--",
NULL); NULL);
add_pathspecs(&cp_diff.args, ps); add_pathspecs(&cp_diff.args, ps);
if (pipe_command(&cp_diff, NULL, 0, &out, 0, NULL, 0)) { if (pipe_command(&cp_diff, NULL, 0, &out, 0, NULL, 0)) {
ret = -1; ret = -1;
@ -1382,8 +1382,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
} }
cp_apply.git_cmd = 1; cp_apply.git_cmd = 1;
argv_array_pushl(&cp_apply.args, "apply", "--index", strvec_pushl(&cp_apply.args, "apply", "--index",
"-R", NULL); "-R", NULL);
if (pipe_command(&cp_apply, out.buf, out.len, NULL, 0, if (pipe_command(&cp_apply, out.buf, out.len, NULL, 0,
NULL, 0)) { NULL, 0)) {
ret = -1; ret = -1;
@ -1392,8 +1392,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
} else { } else {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "reset", "--hard", "-q", strvec_pushl(&cp.args, "reset", "--hard", "-q",
"--no-recurse-submodules", NULL); "--no-recurse-submodules", NULL);
if (run_command(&cp)) { if (run_command(&cp)) {
ret = -1; ret = -1;
goto done; goto done;
@ -1404,10 +1404,10 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "checkout", "--no-overlay", strvec_pushl(&cp.args, "checkout", "--no-overlay",
oid_to_hex(&info.i_tree), "--", NULL); oid_to_hex(&info.i_tree), "--", NULL);
if (!ps->nr) if (!ps->nr)
argv_array_push(&cp.args, ":/"); strvec_push(&cp.args, ":/");
else else
add_pathspecs(&cp.args, ps); add_pathspecs(&cp.args, ps);
if (run_command(&cp)) { if (run_command(&cp)) {
@ -1420,7 +1420,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "apply", "-R", NULL); strvec_pushl(&cp.args, "apply", "-R", NULL);
if (pipe_command(&cp, patch.buf, patch.len, NULL, 0, NULL, 0)) { if (pipe_command(&cp, patch.buf, patch.len, NULL, 0, NULL, 0)) {
if (!quiet) if (!quiet)
@ -1434,7 +1434,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "reset", "-q", "--", NULL); strvec_pushl(&cp.args, "reset", "-q", "--", NULL);
add_pathspecs(&cp.args, ps); add_pathspecs(&cp.args, ps);
if (run_command(&cp)) { if (run_command(&cp)) {
ret = -1; ret = -1;
@ -1560,7 +1560,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
{ {
pid_t pid = getpid(); pid_t pid = getpid();
const char *index_file; const char *index_file;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
struct option options[] = { struct option options[] = {
OPT_END() OPT_END()
@ -1609,7 +1609,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
git_stash_usage, options); git_stash_usage, options);
/* Assume 'stash push' */ /* Assume 'stash push' */
argv_array_push(&args, "push"); strvec_push(&args, "push");
argv_array_pushv(&args, argv); strvec_pushv(&args, argv);
return !!push_stash(args.argc, args.argv, prefix, 1); return !!push_stash(args.nr, args.v, prefix, 1);
} }

View file

@ -294,9 +294,9 @@ static char *compute_rev_name(const char *sub_path, const char* object_id)
cp.git_cmd = 1; cp.git_cmd = 1;
cp.no_stderr = 1; cp.no_stderr = 1;
argv_array_push(&cp.args, "describe"); strvec_push(&cp.args, "describe");
argv_array_pushv(&cp.args, *d); strvec_pushv(&cp.args, *d);
argv_array_push(&cp.args, object_id); strvec_push(&cp.args, object_id);
if (!capture_command(&cp, &sb, 0)) { if (!capture_command(&cp, &sb, 0)) {
strbuf_strip_suffix(&sb, "\n"); strbuf_strip_suffix(&sb, "\n");
@ -495,12 +495,12 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
char *toplevel = xgetcwd(); char *toplevel = xgetcwd();
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
argv_array_pushf(&cp.env_array, "name=%s", sub->name); strvec_pushf(&cp.env_array, "name=%s", sub->name);
argv_array_pushf(&cp.env_array, "sm_path=%s", path); strvec_pushf(&cp.env_array, "sm_path=%s", path);
argv_array_pushf(&cp.env_array, "displaypath=%s", displaypath); strvec_pushf(&cp.env_array, "displaypath=%s", displaypath);
argv_array_pushf(&cp.env_array, "sha1=%s", strvec_pushf(&cp.env_array, "sha1=%s",
oid_to_hex(ce_oid)); oid_to_hex(ce_oid));
argv_array_pushf(&cp.env_array, "toplevel=%s", toplevel); strvec_pushf(&cp.env_array, "toplevel=%s", toplevel);
/* /*
* Since the path variable was accessible from the script * Since the path variable was accessible from the script
@ -509,15 +509,15 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
* on windows. And since environment variables are * on windows. And since environment variables are
* case-insensitive in windows, it interferes with the * case-insensitive in windows, it interferes with the
* existing PATH variable. Hence, to avoid that, we expose * existing PATH variable. Hence, to avoid that, we expose
* path via the args argv_array and not via env_array. * path via the args strvec and not via env_array.
*/ */
sq_quote_buf(&sb, path); sq_quote_buf(&sb, path);
argv_array_pushf(&cp.args, "path=%s; %s", strvec_pushf(&cp.args, "path=%s; %s",
sb.buf, info->argv[0]); sb.buf, info->argv[0]);
strbuf_release(&sb); strbuf_release(&sb);
free(toplevel); free(toplevel);
} else { } else {
argv_array_pushv(&cp.args, info->argv); strvec_pushv(&cp.args, info->argv);
} }
if (!info->quiet) if (!info->quiet)
@ -534,16 +534,16 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
cpr.dir = path; cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array); prepare_submodule_repo_env(&cpr.env_array);
argv_array_pushl(&cpr.args, "--super-prefix", NULL); strvec_pushl(&cpr.args, "--super-prefix", NULL);
argv_array_pushf(&cpr.args, "%s/", displaypath); strvec_pushf(&cpr.args, "%s/", displaypath);
argv_array_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive", strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive",
NULL); NULL);
if (info->quiet) if (info->quiet)
argv_array_push(&cpr.args, "--quiet"); strvec_push(&cpr.args, "--quiet");
argv_array_push(&cpr.args, "--"); strvec_push(&cpr.args, "--");
argv_array_pushv(&cpr.args, info->argv); strvec_pushv(&cpr.args, info->argv);
if (run_command(&cpr)) if (run_command(&cpr))
die(_("run_command returned non-zero status while " die(_("run_command returned non-zero status while "
@ -779,7 +779,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
unsigned int flags) unsigned int flags)
{ {
char *displaypath; char *displaypath;
struct argv_array diff_files_args = ARGV_ARRAY_INIT; struct strvec diff_files_args = STRVEC_INIT;
struct rev_info rev; struct rev_info rev;
int diff_files_result; int diff_files_result;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
@ -809,17 +809,17 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
} }
strbuf_release(&buf); strbuf_release(&buf);
argv_array_pushl(&diff_files_args, "diff-files", strvec_pushl(&diff_files_args, "diff-files",
"--ignore-submodules=dirty", "--quiet", "--", "--ignore-submodules=dirty", "--quiet", "--",
path, NULL); path, NULL);
git_config(git_diff_basic_config, NULL); git_config(git_diff_basic_config, NULL);
repo_init_revisions(the_repository, &rev, NULL); repo_init_revisions(the_repository, &rev, NULL);
rev.abbrev = 0; rev.abbrev = 0;
diff_files_args.argc = setup_revisions(diff_files_args.argc, diff_files_args.nr = setup_revisions(diff_files_args.nr,
diff_files_args.argv, diff_files_args.v,
&rev, NULL); &rev, NULL);
diff_files_result = run_diff_files(&rev, 0); diff_files_result = run_diff_files(&rev, 0);
if (!diff_result_code(&rev.diffopt, diff_files_result)) { if (!diff_result_code(&rev.diffopt, diff_files_result)) {
@ -849,23 +849,23 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
cpr.dir = path; cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array); prepare_submodule_repo_env(&cpr.env_array);
argv_array_push(&cpr.args, "--super-prefix"); strvec_push(&cpr.args, "--super-prefix");
argv_array_pushf(&cpr.args, "%s/", displaypath); strvec_pushf(&cpr.args, "%s/", displaypath);
argv_array_pushl(&cpr.args, "submodule--helper", "status", strvec_pushl(&cpr.args, "submodule--helper", "status",
"--recursive", NULL); "--recursive", NULL);
if (flags & OPT_CACHED) if (flags & OPT_CACHED)
argv_array_push(&cpr.args, "--cached"); strvec_push(&cpr.args, "--cached");
if (flags & OPT_QUIET) if (flags & OPT_QUIET)
argv_array_push(&cpr.args, "--quiet"); strvec_push(&cpr.args, "--quiet");
if (run_command(&cpr)) if (run_command(&cpr))
die(_("failed to recurse into submodule '%s'"), path); die(_("failed to recurse into submodule '%s'"), path);
} }
cleanup: cleanup:
argv_array_clear(&diff_files_args); strvec_clear(&diff_files_args);
free(displaypath); free(displaypath);
} }
@ -995,8 +995,8 @@ static void sync_submodule(const char *path, const char *prefix,
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
cp.dir = path; cp.dir = path;
argv_array_pushl(&cp.args, "submodule--helper", strvec_pushl(&cp.args, "submodule--helper",
"print-default-remote", NULL); "print-default-remote", NULL);
strbuf_reset(&sb); strbuf_reset(&sb);
if (capture_command(&cp, &sb, 0)) if (capture_command(&cp, &sb, 0))
@ -1021,13 +1021,13 @@ static void sync_submodule(const char *path, const char *prefix,
cpr.dir = path; cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array); prepare_submodule_repo_env(&cpr.env_array);
argv_array_push(&cpr.args, "--super-prefix"); strvec_push(&cpr.args, "--super-prefix");
argv_array_pushf(&cpr.args, "%s/", displaypath); strvec_pushf(&cpr.args, "%s/", displaypath);
argv_array_pushl(&cpr.args, "submodule--helper", "sync", strvec_pushl(&cpr.args, "submodule--helper", "sync",
"--recursive", NULL); "--recursive", NULL);
if (flags & OPT_QUIET) if (flags & OPT_QUIET)
argv_array_push(&cpr.args, "--quiet"); strvec_push(&cpr.args, "--quiet");
if (run_command(&cpr)) if (run_command(&cpr))
die(_("failed to recurse into submodule '%s'"), die(_("failed to recurse into submodule '%s'"),
@ -1127,8 +1127,8 @@ static void deinit_submodule(const char *path, const char *prefix,
if (!(flags & OPT_FORCE)) { if (!(flags & OPT_FORCE)) {
struct child_process cp_rm = CHILD_PROCESS_INIT; struct child_process cp_rm = CHILD_PROCESS_INIT;
cp_rm.git_cmd = 1; cp_rm.git_cmd = 1;
argv_array_pushl(&cp_rm.args, "rm", "-qn", strvec_pushl(&cp_rm.args, "rm", "-qn",
path, NULL); path, NULL);
if (run_command(&cp_rm)) if (run_command(&cp_rm))
die(_("Submodule work tree '%s' contains local " die(_("Submodule work tree '%s' contains local "
@ -1156,8 +1156,8 @@ static void deinit_submodule(const char *path, const char *prefix,
displaypath); displaypath);
cp_config.git_cmd = 1; cp_config.git_cmd = 1;
argv_array_pushl(&cp_config.args, "config", "--get-regexp", NULL); strvec_pushl(&cp_config.args, "config", "--get-regexp", NULL);
argv_array_pushf(&cp_config.args, "submodule.%s\\.", sub->name); strvec_pushf(&cp_config.args, "submodule.%s\\.", sub->name);
/* remove the .git/config entries (unless the user already did it) */ /* remove the .git/config entries (unless the user already did it) */
if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) { if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) {
@ -1239,32 +1239,32 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
{ {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
argv_array_push(&cp.args, "clone"); strvec_push(&cp.args, "clone");
argv_array_push(&cp.args, "--no-checkout"); strvec_push(&cp.args, "--no-checkout");
if (quiet) if (quiet)
argv_array_push(&cp.args, "--quiet"); strvec_push(&cp.args, "--quiet");
if (progress) if (progress)
argv_array_push(&cp.args, "--progress"); strvec_push(&cp.args, "--progress");
if (depth && *depth) if (depth && *depth)
argv_array_pushl(&cp.args, "--depth", depth, NULL); strvec_pushl(&cp.args, "--depth", depth, NULL);
if (reference->nr) { if (reference->nr) {
struct string_list_item *item; struct string_list_item *item;
for_each_string_list_item(item, reference) for_each_string_list_item(item, reference)
argv_array_pushl(&cp.args, "--reference", strvec_pushl(&cp.args, "--reference",
item->string, NULL); item->string, NULL);
} }
if (dissociate) if (dissociate)
argv_array_push(&cp.args, "--dissociate"); strvec_push(&cp.args, "--dissociate");
if (gitdir && *gitdir) if (gitdir && *gitdir)
argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL); strvec_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
if (single_branch >= 0) if (single_branch >= 0)
argv_array_push(&cp.args, single_branch ? strvec_push(&cp.args, single_branch ?
"--single-branch" : "--single-branch" :
"--no-single-branch"); "--no-single-branch");
argv_array_push(&cp.args, "--"); strvec_push(&cp.args, "--");
argv_array_push(&cp.args, url); strvec_push(&cp.args, url);
argv_array_push(&cp.args, path); strvec_push(&cp.args, path);
cp.git_cmd = 1; cp.git_cmd = 1;
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
@ -1717,32 +1717,32 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
child->no_stdin = 1; child->no_stdin = 1;
child->stdout_to_stderr = 1; child->stdout_to_stderr = 1;
child->err = -1; child->err = -1;
argv_array_push(&child->args, "submodule--helper"); strvec_push(&child->args, "submodule--helper");
argv_array_push(&child->args, "clone"); strvec_push(&child->args, "clone");
if (suc->progress) if (suc->progress)
argv_array_push(&child->args, "--progress"); strvec_push(&child->args, "--progress");
if (suc->quiet) if (suc->quiet)
argv_array_push(&child->args, "--quiet"); strvec_push(&child->args, "--quiet");
if (suc->prefix) if (suc->prefix)
argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL); strvec_pushl(&child->args, "--prefix", suc->prefix, NULL);
if (suc->recommend_shallow && sub->recommend_shallow == 1) if (suc->recommend_shallow && sub->recommend_shallow == 1)
argv_array_push(&child->args, "--depth=1"); strvec_push(&child->args, "--depth=1");
if (suc->require_init) if (suc->require_init)
argv_array_push(&child->args, "--require-init"); strvec_push(&child->args, "--require-init");
argv_array_pushl(&child->args, "--path", sub->path, NULL); strvec_pushl(&child->args, "--path", sub->path, NULL);
argv_array_pushl(&child->args, "--name", sub->name, NULL); strvec_pushl(&child->args, "--name", sub->name, NULL);
argv_array_pushl(&child->args, "--url", url, NULL); strvec_pushl(&child->args, "--url", url, NULL);
if (suc->references.nr) { if (suc->references.nr) {
struct string_list_item *item; struct string_list_item *item;
for_each_string_list_item(item, &suc->references) for_each_string_list_item(item, &suc->references)
argv_array_pushl(&child->args, "--reference", item->string, NULL); strvec_pushl(&child->args, "--reference", item->string, NULL);
} }
if (suc->dissociate) if (suc->dissociate)
argv_array_push(&child->args, "--dissociate"); strvec_push(&child->args, "--dissociate");
if (suc->depth) if (suc->depth)
argv_array_push(&child->args, suc->depth); strvec_push(&child->args, suc->depth);
if (suc->single_branch >= 0) if (suc->single_branch >= 0)
argv_array_push(&child->args, suc->single_branch ? strvec_push(&child->args, suc->single_branch ?
"--single-branch" : "--single-branch" :
"--no-single-branch"); "--no-single-branch");

View file

@ -4,7 +4,7 @@
#include "builtin.h" #include "builtin.h"
#include "parse-options.h" #include "parse-options.h"
#include "quote.h" #include "quote.h"
#include "argv-array.h" #include "strvec.h"
static const char * const git_update_ref_usage[] = { static const char * const git_update_ref_usage[] = {
N_("git update-ref [<options>] -d <refname> [<old-val>]"), N_("git update-ref [<options>] -d <refname> [<old-val>]"),

View file

@ -7,7 +7,7 @@
#include "pkt-line.h" #include "pkt-line.h"
#include "sideband.h" #include "sideband.h"
#include "run-command.h" #include "run-command.h"
#include "argv-array.h" #include "strvec.h"
static const char upload_archive_usage[] = static const char upload_archive_usage[] =
"git upload-archive <repo>"; "git upload-archive <repo>";
@ -19,7 +19,7 @@ static const char deadchild[] =
int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
{ {
struct argv_array sent_argv = ARGV_ARRAY_INIT; struct strvec sent_argv = STRVEC_INIT;
const char *arg_cmd = "argument "; const char *arg_cmd = "argument ";
if (argc != 2 || !strcmp(argv[1], "-h")) if (argc != 2 || !strcmp(argv[1], "-h"))
@ -31,21 +31,21 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
init_archivers(); init_archivers();
/* put received options in sent_argv[] */ /* put received options in sent_argv[] */
argv_array_push(&sent_argv, "git-upload-archive"); strvec_push(&sent_argv, "git-upload-archive");
for (;;) { for (;;) {
char *buf = packet_read_line(0, NULL); char *buf = packet_read_line(0, NULL);
if (!buf) if (!buf)
break; /* got a flush */ break; /* got a flush */
if (sent_argv.argc > MAX_ARGS) if (sent_argv.nr > MAX_ARGS)
die("Too many options (>%d)", MAX_ARGS - 1); die("Too many options (>%d)", MAX_ARGS - 1);
if (!starts_with(buf, arg_cmd)) if (!starts_with(buf, arg_cmd))
die("'argument' token or flush expected"); die("'argument' token or flush expected");
argv_array_push(&sent_argv, buf + strlen(arg_cmd)); strvec_push(&sent_argv, buf + strlen(arg_cmd));
} }
/* parse all options sent by the client */ /* parse all options sent by the client */
return write_archive(sent_argv.argc, sent_argv.argv, prefix, return write_archive(sent_argv.nr, sent_argv.v, prefix,
the_repository, NULL, 1); the_repository, NULL, 1);
} }

View file

@ -4,7 +4,7 @@
#include "builtin.h" #include "builtin.h"
#include "dir.h" #include "dir.h"
#include "parse-options.h" #include "parse-options.h"
#include "argv-array.h" #include "strvec.h"
#include "branch.h" #include "branch.h"
#include "refs.h" #include "refs.h"
#include "run-command.h" #include "run-command.h"
@ -316,7 +316,7 @@ static int add_worktree(const char *path, const char *refname,
struct strbuf sb = STRBUF_INIT, realpath = STRBUF_INIT; struct strbuf sb = STRBUF_INIT, realpath = STRBUF_INIT;
const char *name; const char *name;
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
struct argv_array child_env = ARGV_ARRAY_INIT; struct strvec child_env = STRVEC_INIT;
unsigned int counter = 0; unsigned int counter = 0;
int len, ret; int len, ret;
struct strbuf symref = STRBUF_INIT; struct strbuf symref = STRBUF_INIT;
@ -408,32 +408,32 @@ static int add_worktree(const char *path, const char *refname,
strbuf_addf(&sb, "%s/commondir", sb_repo.buf); strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
write_file(sb.buf, "../.."); write_file(sb.buf, "../..");
argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf); strvec_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path); strvec_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
cp.git_cmd = 1; cp.git_cmd = 1;
if (!is_branch) if (!is_branch)
argv_array_pushl(&cp.args, "update-ref", "HEAD", strvec_pushl(&cp.args, "update-ref", "HEAD",
oid_to_hex(&commit->object.oid), NULL); oid_to_hex(&commit->object.oid), NULL);
else { else {
argv_array_pushl(&cp.args, "symbolic-ref", "HEAD", strvec_pushl(&cp.args, "symbolic-ref", "HEAD",
symref.buf, NULL); symref.buf, NULL);
if (opts->quiet) if (opts->quiet)
argv_array_push(&cp.args, "--quiet"); strvec_push(&cp.args, "--quiet");
} }
cp.env = child_env.argv; cp.env = child_env.v;
ret = run_command(&cp); ret = run_command(&cp);
if (ret) if (ret)
goto done; goto done;
if (opts->checkout) { if (opts->checkout) {
cp.argv = NULL; cp.argv = NULL;
argv_array_clear(&cp.args); strvec_clear(&cp.args);
argv_array_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
if (opts->quiet) if (opts->quiet)
argv_array_push(&cp.args, "--quiet"); strvec_push(&cp.args, "--quiet");
cp.env = child_env.argv; cp.env = child_env.v;
ret = run_command(&cp); ret = run_command(&cp);
if (ret) if (ret)
goto done; goto done;
@ -465,15 +465,15 @@ static int add_worktree(const char *path, const char *refname,
cp.env = env; cp.env = env;
cp.argv = NULL; cp.argv = NULL;
cp.trace2_hook_name = "post-checkout"; cp.trace2_hook_name = "post-checkout";
argv_array_pushl(&cp.args, absolute_path(hook), strvec_pushl(&cp.args, absolute_path(hook),
oid_to_hex(&null_oid), oid_to_hex(&null_oid),
oid_to_hex(&commit->object.oid), oid_to_hex(&commit->object.oid),
"1", NULL); "1", NULL);
ret = run_command(&cp); ret = run_command(&cp);
} }
} }
argv_array_clear(&child_env); strvec_clear(&child_env);
strbuf_release(&sb); strbuf_release(&sb);
strbuf_release(&symref); strbuf_release(&symref);
strbuf_release(&sb_repo); strbuf_release(&sb_repo);
@ -619,15 +619,15 @@ static int add(int ac, const char **av, const char *prefix)
if (new_branch) { if (new_branch) {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_push(&cp.args, "branch"); strvec_push(&cp.args, "branch");
if (new_branch_force) if (new_branch_force)
argv_array_push(&cp.args, "--force"); strvec_push(&cp.args, "--force");
if (opts.quiet) if (opts.quiet)
argv_array_push(&cp.args, "--quiet"); strvec_push(&cp.args, "--quiet");
argv_array_push(&cp.args, new_branch); strvec_push(&cp.args, new_branch);
argv_array_push(&cp.args, branch); strvec_push(&cp.args, branch);
if (opt_track) if (opt_track)
argv_array_push(&cp.args, opt_track); strvec_push(&cp.args, opt_track);
if (run_command(&cp)) if (run_command(&cp))
return -1; return -1;
branch = new_branch; branch = new_branch;
@ -924,7 +924,7 @@ static int move_worktree(int ac, const char **av, const char *prefix)
static void check_clean_worktree(struct worktree *wt, static void check_clean_worktree(struct worktree *wt,
const char *original_path) const char *original_path)
{ {
struct argv_array child_env = ARGV_ARRAY_INIT; struct strvec child_env = STRVEC_INIT;
struct child_process cp; struct child_process cp;
char buf[1]; char buf[1];
int ret; int ret;
@ -935,15 +935,15 @@ static void check_clean_worktree(struct worktree *wt,
*/ */
validate_no_submodules(wt); validate_no_submodules(wt);
argv_array_pushf(&child_env, "%s=%s/.git", strvec_pushf(&child_env, "%s=%s/.git",
GIT_DIR_ENVIRONMENT, wt->path); GIT_DIR_ENVIRONMENT, wt->path);
argv_array_pushf(&child_env, "%s=%s", strvec_pushf(&child_env, "%s=%s",
GIT_WORK_TREE_ENVIRONMENT, wt->path); GIT_WORK_TREE_ENVIRONMENT, wt->path);
memset(&cp, 0, sizeof(cp)); memset(&cp, 0, sizeof(cp));
argv_array_pushl(&cp.args, "status", strvec_pushl(&cp.args, "status",
"--porcelain", "--ignore-submodules=none", "--porcelain", "--ignore-submodules=none",
NULL); NULL);
cp.env = child_env.argv; cp.env = child_env.v;
cp.git_cmd = 1; cp.git_cmd = 1;
cp.dir = wt->path; cp.dir = wt->path;
cp.out = -1; cp.out = -1;

View file

@ -10,7 +10,7 @@
#include "list-objects.h" #include "list-objects.h"
#include "run-command.h" #include "run-command.h"
#include "refs.h" #include "refs.h"
#include "argv-array.h" #include "strvec.h"
static const char bundle_signature[] = "# v2 git bundle\n"; static const char bundle_signature[] = "# v2 git bundle\n";
@ -269,16 +269,16 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
/* Write the pack data to bundle_fd */ /* 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; struct child_process pack_objects = CHILD_PROCESS_INIT;
int i; int i;
argv_array_pushl(&pack_objects.args, strvec_pushl(&pack_objects.args,
"pack-objects", "pack-objects",
"--stdout", "--thin", "--delta-base-offset", "--stdout", "--thin", "--delta-base-offset",
NULL); NULL);
argv_array_pushv(&pack_objects.args, pack_options->argv); strvec_pushv(&pack_objects.args, pack_options->v);
pack_objects.in = -1; pack_objects.in = -1;
pack_objects.out = bundle_fd; pack_objects.out = bundle_fd;
pack_objects.git_cmd = 1; pack_objects.git_cmd = 1;
@ -321,11 +321,11 @@ static int compute_and_write_prerequisites(int bundle_fd,
FILE *rls_fout; FILE *rls_fout;
int i; int i;
argv_array_pushl(&rls.args, strvec_pushl(&rls.args,
"rev-list", "--boundary", "--pretty=oneline", "rev-list", "--boundary", "--pretty=oneline",
NULL); NULL);
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
argv_array_push(&rls.args, argv[i]); strvec_push(&rls.args, argv[i]);
rls.out = -1; rls.out = -1;
rls.git_cmd = 1; rls.git_cmd = 1;
if (start_command(&rls)) 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 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; struct lock_file lock = LOCK_INIT;
int bundle_fd = -1; int bundle_fd = -1;

View file

@ -1,7 +1,7 @@
#ifndef BUNDLE_H #ifndef BUNDLE_H
#define BUNDLE_H #define BUNDLE_H
#include "argv-array.h" #include "strvec.h"
#include "cache.h" #include "cache.h"
struct ref_list { struct ref_list {
@ -21,7 +21,7 @@ struct bundle_header {
int is_bundle(const char *path, int quiet); int is_bundle(const char *path, int quiet);
int read_bundle_header(const char *path, struct bundle_header *header); int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct repository *r, const char *path, 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); int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
#define BUNDLE_VERBOSE 1 #define BUNDLE_VERBOSE 1
int unbundle(struct repository *r, struct bundle_header *header, int unbundle(struct repository *r, struct bundle_header *header,

View file

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

View file

@ -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, int run_commit_hook(int editor_is_used, const char *index_file,
const char *name, ...) const char *name, ...)
{ {
struct argv_array hook_env = ARGV_ARRAY_INIT; struct strvec hook_env = STRVEC_INIT;
va_list args; va_list args;
int ret; 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. * Let the hook know that no editor will be launched.
*/ */
if (!editor_is_used) if (!editor_is_used)
argv_array_push(&hook_env, "GIT_EDITOR=:"); strvec_push(&hook_env, "GIT_EDITOR=:");
va_start(args, name); va_start(args, name);
ret = run_hook_ve(hook_env.argv,name, args); ret = run_hook_ve(hook_env.v, name, args);
va_end(args); va_end(args);
argv_array_clear(&hook_env); strvec_clear(&hook_env);
return ret; return ret;
} }

View file

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

View file

@ -86,9 +86,9 @@ static void restore_term(void)
if (stty_restore.nr == 0) if (stty_restore.nr == 0)
return; return;
argv_array_push(&cp.args, "stty"); strvec_push(&cp.args, "stty");
for (i = 0; i < stty_restore.nr; i++) 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); run_command(&cp);
string_list_clear(&stty_restore, 0); string_list_clear(&stty_restore, 0);
return; return;
@ -107,25 +107,25 @@ static int disable_bits(DWORD bits)
if (use_stty) { if (use_stty) {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
argv_array_push(&cp.args, "stty"); strvec_push(&cp.args, "stty");
if (bits & ENABLE_LINE_INPUT) { if (bits & ENABLE_LINE_INPUT) {
string_list_append(&stty_restore, "icanon"); string_list_append(&stty_restore, "icanon");
argv_array_push(&cp.args, "-icanon"); strvec_push(&cp.args, "-icanon");
} }
if (bits & ENABLE_ECHO_INPUT) { if (bits & ENABLE_ECHO_INPUT) {
string_list_append(&stty_restore, "echo"); string_list_append(&stty_restore, "echo");
argv_array_push(&cp.args, "-echo"); strvec_push(&cp.args, "-echo");
} }
if (bits & ENABLE_PROCESSED_INPUT) { if (bits & ENABLE_PROCESSED_INPUT) {
string_list_append(&stty_restore, "-ignbrk"); string_list_append(&stty_restore, "-ignbrk");
string_list_append(&stty_restore, "intr"); string_list_append(&stty_restore, "intr");
string_list_append(&stty_restore, "^c"); string_list_append(&stty_restore, "^c");
argv_array_push(&cp.args, "ignbrk"); strvec_push(&cp.args, "ignbrk");
argv_array_push(&cp.args, "intr"); strvec_push(&cp.args, "intr");
argv_array_push(&cp.args, ""); strvec_push(&cp.args, "");
} }
if (run_command(&cp) == 0) 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, hashmap_init(&sequences, (hashmap_cmp_fn)sequence_entry_cmp,
NULL, 0); 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)) if (pipe_command(&cp, NULL, 0, &buf, 0, NULL, 0))
strbuf_setlen(&buf, 0); strbuf_setlen(&buf, 0);

View file

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

View file

@ -90,23 +90,23 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
no_promisor_pack_found: no_promisor_pack_found:
if (opt->shallow_file) { if (opt->shallow_file) {
argv_array_push(&rev_list.args, "--shallow-file"); strvec_push(&rev_list.args, "--shallow-file");
argv_array_push(&rev_list.args, opt->shallow_file); strvec_push(&rev_list.args, opt->shallow_file);
} }
argv_array_push(&rev_list.args,"rev-list"); strvec_push(&rev_list.args,"rev-list");
argv_array_push(&rev_list.args, "--objects"); strvec_push(&rev_list.args, "--objects");
argv_array_push(&rev_list.args, "--stdin"); strvec_push(&rev_list.args, "--stdin");
if (has_promisor_remote()) 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) { if (!opt->is_deepening_fetch) {
argv_array_push(&rev_list.args, "--not"); strvec_push(&rev_list.args, "--not");
argv_array_push(&rev_list.args, "--all"); strvec_push(&rev_list.args, "--all");
} }
argv_array_push(&rev_list.args, "--quiet"); strvec_push(&rev_list.args, "--quiet");
argv_array_push(&rev_list.args, "--alternate-refs"); strvec_push(&rev_list.args, "--alternate-refs");
if (opt->progress) if (opt->progress)
argv_array_pushf(&rev_list.args, "--progress=%s", strvec_pushf(&rev_list.args, "--progress=%s",
_("Checking connectivity")); _("Checking connectivity"));
rev_list.git_cmd = 1; rev_list.git_cmd = 1;
rev_list.env = opt->env; rev_list.env = opt->env;

View file

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

32
diff.c
View file

@ -20,7 +20,7 @@
#include "hashmap.h" #include "hashmap.h"
#include "ll-merge.h" #include "ll-merge.h"
#include "string-list.h" #include "string-list.h"
#include "argv-array.h" #include "strvec.h"
#include "graph.h" #include "graph.h"
#include "packfile.h" #include "packfile.h"
#include "parse-options.h" #include "parse-options.h"
@ -4192,14 +4192,14 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
} }
static void add_external_diff_name(struct repository *r, static void add_external_diff_name(struct repository *r,
struct argv_array *argv, struct strvec *argv,
const char *name, const char *name,
struct diff_filespec *df) struct diff_filespec *df)
{ {
struct diff_tempfile *temp = prepare_temp_file(r, name, df); struct diff_tempfile *temp = prepare_temp_file(r, name, df);
argv_array_push(argv, temp->name); strvec_push(argv, temp->name);
argv_array_push(argv, temp->hex); strvec_push(argv, temp->hex);
argv_array_push(argv, temp->mode); strvec_push(argv, temp->mode);
} }
/* An external diff command takes: /* An external diff command takes:
@ -4216,12 +4216,12 @@ static void run_external_diff(const char *pgm,
const char *xfrm_msg, const char *xfrm_msg,
struct diff_options *o) struct diff_options *o)
{ {
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
struct argv_array env = ARGV_ARRAY_INIT; struct strvec env = STRVEC_INIT;
struct diff_queue_struct *q = &diff_queued_diff; struct diff_queue_struct *q = &diff_queued_diff;
argv_array_push(&argv, pgm); strvec_push(&argv, pgm);
argv_array_push(&argv, name); strvec_push(&argv, name);
if (one && two) { if (one && two) {
add_external_diff_name(o->repo, &argv, name, one); add_external_diff_name(o->repo, &argv, name, one);
@ -4229,22 +4229,22 @@ static void run_external_diff(const char *pgm,
add_external_diff_name(o->repo, &argv, name, two); add_external_diff_name(o->repo, &argv, name, two);
else { else {
add_external_diff_name(o->repo, &argv, other, two); add_external_diff_name(o->repo, &argv, other, two);
argv_array_push(&argv, other); strvec_push(&argv, other);
argv_array_push(&argv, xfrm_msg); strvec_push(&argv, xfrm_msg);
} }
} }
argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); strvec_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_TOTAL=%d", q->nr);
diff_free_filespec_data(one); diff_free_filespec_data(one);
diff_free_filespec_data(two); diff_free_filespec_data(two);
if (run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv)) if (run_command_v_opt_cd_env(argv.v, RUN_USING_SHELL, NULL, env.v))
die(_("external diff died, stopping at %s"), name); die(_("external diff died, stopping at %s"), name);
remove_tempfile(); remove_tempfile();
argv_array_clear(&argv); strvec_clear(&argv);
argv_array_clear(&env); strvec_clear(&env);
} }
static int similarity_index(struct diff_filepair *p) static int similarity_index(struct diff_filepair *p)

View file

@ -14,7 +14,7 @@
#include "refs.h" #include "refs.h"
#include "fmt-merge-msg.h" #include "fmt-merge-msg.h"
#include "commit.h" #include "commit.h"
#include "argv-array.h" #include "strvec.h"
#include "object-store.h" #include "object-store.h"
#include "chdir-notify.h" #include "chdir-notify.h"
#include "shallow.h" #include "shallow.h"
@ -156,15 +156,15 @@ static char *expand_namespace(const char *raw_namespace)
* Wrapper of getenv() that returns a strdup value. This value is kept * Wrapper of getenv() that returns a strdup value. This value is kept
* in argv to be freed later. * 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); const char *value = getenv(name);
if (!value) if (!value)
return NULL; return NULL;
argv_array_push(argv, value); strvec_push(argv, value);
return argv->argv[argv->argc - 1]; return argv->v[argv->nr - 1];
} }
void setup_git_env(const char *git_dir) void setup_git_env(const char *git_dir)
@ -172,7 +172,7 @@ void setup_git_env(const char *git_dir)
const char *shallow_file; const char *shallow_file;
const char *replace_ref_base; const char *replace_ref_base;
struct set_gitdir_args args = { NULL }; 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.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT);
args.object_dir = getenv_safe(&to_free, DB_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.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
repo_set_gitdir(the_repository, git_dir, &args); repo_set_gitdir(the_repository, git_dir, &args);
argv_array_clear(&to_free); strvec_clear(&to_free);
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0; read_replace_refs = 0;

View file

@ -1,7 +1,7 @@
#include "cache.h" #include "cache.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "quote.h" #include "quote.h"
#include "argv-array.h" #include "strvec.h"
#if defined(RUNTIME_PREFIX) #if defined(RUNTIME_PREFIX)
@ -320,26 +320,26 @@ void setup_path(void)
strbuf_release(&new_path); 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"); strvec_push(out, "git");
argv_array_pushv(out, argv); strvec_pushv(out, argv);
return out->argv; return out->v;
} }
int execv_git_cmd(const char **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); prepare_git_cmd(&nargv, argv);
trace_argv_printf(nargv.argv, "trace: exec:"); trace_argv_printf(nargv.v, "trace: exec:");
/* execvp() can only ever return if it fails */ /* execvp() can only ever return if it fails */
sane_execvp("git", (char **)nargv.argv); sane_execvp("git", (char **)nargv.v);
trace_printf("trace: exec failed: %s\n", strerror(errno)); trace_printf("trace: exec failed: %s\n", strerror(errno));
argv_array_clear(&nargv); strvec_clear(&nargv);
return -1; return -1;
} }

View file

@ -1,13 +1,13 @@
#ifndef GIT_EXEC_CMD_H #ifndef GIT_EXEC_CMD_H
#define GIT_EXEC_CMD_H #define GIT_EXEC_CMD_H
struct argv_array; struct strvec;
void git_set_exec_path(const char *exec_path); void git_set_exec_path(const char *exec_path);
void git_resolve_executable_dir(const char *path); void git_resolve_executable_dir(const char *path);
const char *git_exec_path(void); const char *git_exec_path(void);
void setup_path(void); void setup_path(void);
const char **prepare_git_cmd(struct argv_array *out, const char **argv); const char **prepare_git_cmd(struct strvec *out, const char **argv);
int execv_git_cmd(const char **argv); /* NULL terminated */ int execv_git_cmd(const char **argv); /* NULL terminated */
LAST_ARG_MUST_BE_NULL LAST_ARG_MUST_BE_NULL
int execl_git_cmd(const char *cmd, ...); int execl_git_cmd(const char *cmd, ...);

View file

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

View file

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

View file

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

32
git.c
View file

@ -349,10 +349,10 @@ static int handle_alias(int *argcp, const char ***argv)
child.clean_on_exit = 1; child.clean_on_exit = 1;
child.wait_after_clean = 1; child.wait_after_clean = 1;
child.trace2_child_class = "shell_alias"; child.trace2_child_class = "shell_alias";
argv_array_push(&child.args, alias_string + 1); strvec_push(&child.args, alias_string + 1);
argv_array_pushv(&child.args, (*argv) + 1); strvec_pushv(&child.args, (*argv) + 1);
trace2_cmd_alias(alias_command, child.args.argv); trace2_cmd_alias(alias_command, child.args.v);
trace2_cmd_list_config(); trace2_cmd_list_config();
trace2_cmd_list_env_vars(); trace2_cmd_list_env_vars();
trace2_cmd_name("_run_shell_alias_"); trace2_cmd_name("_run_shell_alias_");
@ -646,7 +646,7 @@ static void strip_extension(const char **argv)
static void handle_builtin(int argc, 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; const char *cmd;
struct cmd_struct *builtin; struct cmd_struct *builtin;
@ -661,19 +661,19 @@ static void handle_builtin(int argc, const char **argv)
argv[0] = cmd = "help"; argv[0] = cmd = "help";
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
argv_array_push(&args, argv[i]); strvec_push(&args, argv[i]);
if (!i) if (!i)
argv_array_push(&args, "--exclude-guides"); strvec_push(&args, "--exclude-guides");
} }
argc++; argc++;
argv = args.argv; argv = args.v;
} }
builtin = get_builtin(cmd); builtin = get_builtin(cmd);
if (builtin) if (builtin)
exit(run_builtin(builtin, argc, argv)); exit(run_builtin(builtin, argc, argv));
argv_array_clear(&args); strvec_clear(&args);
} }
static void execv_dashed_external(const char **argv) 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]); use_pager = check_pager_config(argv[0]);
commit_pager_choice(); commit_pager_choice();
argv_array_pushf(&cmd.args, "git-%s", argv[0]); strvec_pushf(&cmd.args, "git-%s", argv[0]);
argv_array_pushv(&cmd.args, argv + 1); strvec_pushv(&cmd.args, argv + 1);
cmd.clean_on_exit = 1; cmd.clean_on_exit = 1;
cmd.wait_after_clean = 1; cmd.wait_after_clean = 1;
cmd.silent_exec_failure = 1; cmd.silent_exec_failure = 1;
@ -701,7 +701,7 @@ static void execv_dashed_external(const char **argv)
* The code in run_command() logs trace2 child_start/child_exit * The code in run_command() logs trace2 child_start/child_exit
* events, so we do not need to report exec/exec_result events here. * events, so we do not need to report exec/exec_result events here.
*/ */
trace_argv_printf(cmd.args.argv, "trace: exec:"); trace_argv_printf(cmd.args.v, "trace: exec:");
/* /*
* If we fail because the command is not found, it is * If we fail because the command is not found, it is
@ -741,7 +741,7 @@ static int run_argv(int *argcp, const char ***argv)
if (!done_alias) if (!done_alias)
handle_builtin(*argcp, *argv); handle_builtin(*argcp, *argv);
else if (get_builtin(**argv)) { else if (get_builtin(**argv)) {
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
int i; int i;
/* /*
@ -758,17 +758,17 @@ static int run_argv(int *argcp, const char ***argv)
commit_pager_choice(); commit_pager_choice();
argv_array_push(&args, "git"); strvec_push(&args, "git");
for (i = 0; i < *argcp; i++) for (i = 0; i < *argcp; i++)
argv_array_push(&args, (*argv)[i]); strvec_push(&args, (*argv)[i]);
trace_argv_printf(args.argv, "trace: exec:"); trace_argv_printf(args.v, "trace: exec:");
/* /*
* if we fail because the command is not found, it is * if we fail because the command is not found, it is
* OK to return. Otherwise, we just pass along the status code. * OK to return. Otherwise, we just pass along the status code.
*/ */
i = run_command_v_opt_tr2(args.argv, RUN_SILENT_EXEC_FAILURE | i = run_command_v_opt_tr2(args.v, RUN_SILENT_EXEC_FAILURE |
RUN_CLEAN_ON_EXIT | RUN_WAIT_AFTER_CLEAN, "git_alias"); RUN_CLEAN_ON_EXIT | RUN_WAIT_AFTER_CLEAN, "git_alias");
if (i >= 0 || errno != ENOENT) if (i >= 0 || errno != ENOENT)
exit(i); exit(i);

View file

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

16
graph.c
View file

@ -4,7 +4,7 @@
#include "color.h" #include "color.h"
#include "graph.h" #include "graph.h"
#include "revision.h" #include "revision.h"
#include "argv-array.h" #include "strvec.h"
/* Internal API */ /* Internal API */
@ -82,7 +82,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
static const char **column_colors; static const char **column_colors;
static unsigned short column_colors_max; 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; 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]; char color[COLOR_MAXLEN];
if (!color_parse_mem(start, comma - start, color)) if (!color_parse_mem(start, comma - start, color))
argv_array_push(colors, color); strvec_push(colors, color);
else else
warning(_("ignore invalid color '%.*s' in log.graphColors"), warning(_("ignore invalid color '%.*s' in log.graphColors"),
(int)(comma - start), start); (int)(comma - start), start);
start = comma + 1; 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) void graph_set_column_colors(const char **colors, unsigned short colors_max)
@ -350,13 +350,13 @@ struct git_graph *graph_init(struct rev_info *opt)
graph_set_column_colors(column_colors_ansi, graph_set_column_colors(column_colors_ansi,
column_colors_ansi_max); column_colors_ansi_max);
} else { } else {
static struct argv_array custom_colors = ARGV_ARRAY_INIT; static struct strvec custom_colors = STRVEC_INIT;
argv_array_clear(&custom_colors); strvec_clear(&custom_colors);
parse_graph_colors_config(&custom_colors, string); parse_graph_colors_config(&custom_colors, string);
free(string); free(string);
/* graph_set_column_colors takes a max-index, not a count */ /* graph_set_column_colors takes a max-index, not a count */
graph_set_column_colors(custom_colors.argv, graph_set_column_colors(custom_colors.v,
custom_colors.argc - 1); custom_colors.nr - 1);
} }
} }

View file

@ -9,7 +9,7 @@
#include "run-command.h" #include "run-command.h"
#include "string-list.h" #include "string-list.h"
#include "url.h" #include "url.h"
#include "argv-array.h" #include "strvec.h"
#include "packfile.h" #include "packfile.h"
#include "object-store.h" #include "object-store.h"
#include "protocol.h" #include "protocol.h"
@ -477,10 +477,10 @@ static void run_service(const char **argv, int buffer_input)
host = "(none)"; host = "(none)";
if (!getenv("GIT_COMMITTER_NAME")) if (!getenv("GIT_COMMITTER_NAME"))
argv_array_pushf(&cld.env_array, "GIT_COMMITTER_NAME=%s", user); strvec_pushf(&cld.env_array, "GIT_COMMITTER_NAME=%s", user);
if (!getenv("GIT_COMMITTER_EMAIL")) if (!getenv("GIT_COMMITTER_EMAIL"))
argv_array_pushf(&cld.env_array, strvec_pushf(&cld.env_array,
"GIT_COMMITTER_EMAIL=%s@http.%s", user, host); "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
cld.argv = argv; cld.argv = argv;
if (buffer_input || gzipped_request || req_len >= 0) if (buffer_input || gzipped_request || req_len >= 0)

View file

@ -11,7 +11,7 @@
#include "remote.h" #include "remote.h"
#include "list-objects.h" #include "list-objects.h"
#include "sigchain.h" #include "sigchain.h"
#include "argv-array.h" #include "strvec.h"
#include "packfile.h" #include "packfile.h"
#include "object-store.h" #include "object-store.h"
#include "commit-reach.h" #include "commit-reach.h"
@ -1846,7 +1846,7 @@ int cmd_main(int argc, const char **argv)
new_refs = 0; new_refs = 0;
for (ref = remote_refs; ref; ref = ref->next) { for (ref = remote_refs; ref; ref = ref->next) {
struct argv_array commit_argv = ARGV_ARRAY_INIT; struct strvec commit_argv = STRVEC_INIT;
if (!ref->peer_ref) if (!ref->peer_ref)
continue; continue;
@ -1924,14 +1924,14 @@ int cmd_main(int argc, const char **argv)
} }
/* Set up revision info for this refspec */ /* Set up revision info for this refspec */
argv_array_push(&commit_argv, ""); /* ignored */ strvec_push(&commit_argv, ""); /* ignored */
argv_array_push(&commit_argv, "--objects"); strvec_push(&commit_argv, "--objects");
argv_array_push(&commit_argv, oid_to_hex(&ref->new_oid)); strvec_push(&commit_argv, oid_to_hex(&ref->new_oid));
if (!push_all && !is_null_oid(&ref->old_oid)) if (!push_all && !is_null_oid(&ref->old_oid))
argv_array_pushf(&commit_argv, "^%s", strvec_pushf(&commit_argv, "^%s",
oid_to_hex(&ref->old_oid)); oid_to_hex(&ref->old_oid));
repo_init_revisions(the_repository, &revs, setup_git_directory()); repo_init_revisions(the_repository, &revs, setup_git_directory());
setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL); setup_revisions(commit_argv.nr, commit_argv.v, &revs, NULL);
revs.edge_hint = 0; /* just in case */ revs.edge_hint = 0; /* just in case */
/* Generate a list of objects that need to be pushed */ /* Generate a list of objects that need to be pushed */
@ -1961,7 +1961,7 @@ int cmd_main(int argc, const char **argv)
printf("%s %s\n", !rc ? "ok" : "error", ref->name); printf("%s %s\n", !rc ? "ok" : "error", ref->name);
unlock_remote(ref_lock); unlock_remote(ref_lock);
check_locks(); check_locks();
argv_array_clear(&commit_argv); strvec_clear(&commit_argv);
} }
/* Update remote server info if appropriate */ /* Update remote server info if appropriate */

8
http.c
View file

@ -2270,13 +2270,13 @@ int finish_http_pack_request(struct http_pack_request *preq)
tmpfile_fd = xopen(preq->tmpfile.buf, O_RDONLY); tmpfile_fd = xopen(preq->tmpfile.buf, O_RDONLY);
argv_array_push(&ip.args, "index-pack"); strvec_push(&ip.args, "index-pack");
argv_array_push(&ip.args, "--stdin"); strvec_push(&ip.args, "--stdin");
ip.git_cmd = 1; ip.git_cmd = 1;
ip.in = tmpfile_fd; ip.in = tmpfile_fd;
if (preq->generate_keep) { if (preq->generate_keep) {
argv_array_pushf(&ip.args, "--keep=git %"PRIuMAX, strvec_pushf(&ip.args, "--keep=git %"PRIuMAX,
(uintmax_t)getpid()); (uintmax_t)getpid());
ip.out = 0; ip.out = 0;
} else { } else {
ip.no_stdout = 1; ip.no_stdout = 1;

View file

@ -976,7 +976,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f
imap_info("Starting tunnel '%s'... ", srvc->tunnel); imap_info("Starting tunnel '%s'... ", srvc->tunnel);
argv_array_push(&tunnel.args, srvc->tunnel); strvec_push(&tunnel.args, srvc->tunnel);
tunnel.use_shell = 1; tunnel.use_shell = 1;
tunnel.in = -1; tunnel.in = -1;
tunnel.out = -1; tunnel.out = -1;

View file

@ -14,7 +14,7 @@
#include "graph.h" #include "graph.h"
#include "userdiff.h" #include "userdiff.h"
#include "line-log.h" #include "line-log.h"
#include "argv-array.h" #include "strvec.h"
#include "bloom.h" #include "bloom.h"
static void range_set_grow(struct range_set *rs, size_t extra) static void range_set_grow(struct range_set *rs, size_t extra)
@ -758,12 +758,12 @@ static void parse_pathspec_from_ranges(struct pathspec *pathspec,
struct line_log_data *range) struct line_log_data *range)
{ {
struct line_log_data *r; struct line_log_data *r;
struct argv_array array = ARGV_ARRAY_INIT; struct strvec array = STRVEC_INIT;
const char **paths; const char **paths;
for (r = range; r; r = r->next) for (r = range; r; r = r->next)
argv_array_push(&array, r->path); strvec_push(&array, r->path);
paths = argv_array_detach(&array); paths = strvec_detach(&array);
parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", paths); parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", paths);
/* strings are now owned by pathspec */ /* strings are now owned by pathspec */

View file

@ -2,7 +2,7 @@
#include "commit.h" #include "commit.h"
#include "config.h" #include "config.h"
#include "revision.h" #include "revision.h"
#include "argv-array.h" #include "strvec.h"
#include "list-objects.h" #include "list-objects.h"
#include "list-objects-filter.h" #include "list-objects-filter.h"
#include "list-objects-filter-options.h" #include "list-objects-filter-options.h"

View file

@ -2,7 +2,7 @@
#include "repository.h" #include "repository.h"
#include "refs.h" #include "refs.h"
#include "remote.h" #include "remote.h"
#include "argv-array.h" #include "strvec.h"
#include "ls-refs.h" #include "ls-refs.h"
#include "pkt-line.h" #include "pkt-line.h"
#include "config.h" #include "config.h"
@ -11,15 +11,15 @@
* Check if one of the prefixes is a prefix of the ref. * Check if one of the prefixes is a prefix of the ref.
* If no prefixes were provided, all refs match. * If no prefixes were provided, all refs match.
*/ */
static int ref_match(const struct argv_array *prefixes, const char *refname) static int ref_match(const struct strvec *prefixes, const char *refname)
{ {
int i; int i;
if (!prefixes->argc) if (!prefixes->nr)
return 1; /* no restriction */ return 1; /* no restriction */
for (i = 0; i < prefixes->argc; i++) { for (i = 0; i < prefixes->nr; i++) {
const char *prefix = prefixes->argv[i]; const char *prefix = prefixes->v[i];
if (starts_with(refname, prefix)) if (starts_with(refname, prefix))
return 1; return 1;
@ -31,7 +31,7 @@ static int ref_match(const struct argv_array *prefixes, const char *refname)
struct ls_refs_data { struct ls_refs_data {
unsigned peel; unsigned peel;
unsigned symrefs; unsigned symrefs;
struct argv_array prefixes; struct strvec prefixes;
}; };
static int send_ref(const char *refname, const struct object_id *oid, static int send_ref(const char *refname, const struct object_id *oid,
@ -84,7 +84,7 @@ static int ls_refs_config(const char *var, const char *value, void *data)
return parse_hide_refs_config(var, value, "uploadpack"); return parse_hide_refs_config(var, value, "uploadpack");
} }
int ls_refs(struct repository *r, struct argv_array *keys, int ls_refs(struct repository *r, struct strvec *keys,
struct packet_reader *request) struct packet_reader *request)
{ {
struct ls_refs_data data; struct ls_refs_data data;
@ -102,7 +102,7 @@ int ls_refs(struct repository *r, struct argv_array *keys,
else if (!strcmp("symrefs", arg)) else if (!strcmp("symrefs", arg))
data.symrefs = 1; data.symrefs = 1;
else if (skip_prefix(arg, "ref-prefix ", &out)) else if (skip_prefix(arg, "ref-prefix ", &out))
argv_array_push(&data.prefixes, out); strvec_push(&data.prefixes, out);
} }
if (request->status != PACKET_READ_FLUSH) if (request->status != PACKET_READ_FLUSH)
@ -111,6 +111,6 @@ int ls_refs(struct repository *r, struct argv_array *keys,
head_ref_namespaced(send_ref, &data); head_ref_namespaced(send_ref, &data);
for_each_namespaced_ref(send_ref, &data); for_each_namespaced_ref(send_ref, &data);
packet_flush(1); packet_flush(1);
argv_array_clear(&data.prefixes); strvec_clear(&data.prefixes);
return 0; return 0;
} }

View file

@ -2,9 +2,9 @@
#define LS_REFS_H #define LS_REFS_H
struct repository; struct repository;
struct argv_array; struct strvec;
struct packet_reader; struct packet_reader;
int ls_refs(struct repository *r, struct argv_array *keys, int ls_refs(struct repository *r, struct strvec *keys,
struct packet_reader *request); struct packet_reader *request);
#endif /* LS_REFS_H */ #endif /* LS_REFS_H */

18
merge.c
View file

@ -19,22 +19,22 @@ int try_merge_command(struct repository *r,
const char **xopts, struct commit_list *common, const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes) const char *head_arg, struct commit_list *remotes)
{ {
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
int i, ret; int i, ret;
struct commit_list *j; struct commit_list *j;
argv_array_pushf(&args, "merge-%s", strategy); strvec_pushf(&args, "merge-%s", strategy);
for (i = 0; i < xopts_nr; i++) for (i = 0; i < xopts_nr; i++)
argv_array_pushf(&args, "--%s", xopts[i]); strvec_pushf(&args, "--%s", xopts[i]);
for (j = common; j; j = j->next) for (j = common; j; j = j->next)
argv_array_push(&args, merge_argument(j->item)); strvec_push(&args, merge_argument(j->item));
argv_array_push(&args, "--"); strvec_push(&args, "--");
argv_array_push(&args, head_arg); strvec_push(&args, head_arg);
for (j = remotes; j; j = j->next) for (j = remotes; j; j = j->next)
argv_array_push(&args, merge_argument(j->item)); strvec_push(&args, merge_argument(j->item));
ret = run_command_v_opt(args.argv, RUN_GIT_CMD); ret = run_command_v_opt(args.v, RUN_GIT_CMD);
argv_array_clear(&args); strvec_clear(&args);
discard_index(r->index); discard_index(r->index);
if (repo_read_index(r) < 0) if (repo_read_index(r) < 0)

12
midx.c
View file

@ -1408,21 +1408,21 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset); repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset);
repo_config_get_bool(r, "repack.usedeltaislands", &use_delta_islands); repo_config_get_bool(r, "repack.usedeltaislands", &use_delta_islands);
argv_array_push(&cmd.args, "pack-objects"); strvec_push(&cmd.args, "pack-objects");
strbuf_addstr(&base_name, object_dir); strbuf_addstr(&base_name, object_dir);
strbuf_addstr(&base_name, "/pack/pack"); strbuf_addstr(&base_name, "/pack/pack");
argv_array_push(&cmd.args, base_name.buf); strvec_push(&cmd.args, base_name.buf);
if (delta_base_offset) if (delta_base_offset)
argv_array_push(&cmd.args, "--delta-base-offset"); strvec_push(&cmd.args, "--delta-base-offset");
if (use_delta_islands) if (use_delta_islands)
argv_array_push(&cmd.args, "--delta-islands"); strvec_push(&cmd.args, "--delta-islands");
if (flags & MIDX_PROGRESS) if (flags & MIDX_PROGRESS)
argv_array_push(&cmd.args, "--progress"); strvec_push(&cmd.args, "--progress");
else else
argv_array_push(&cmd.args, "-q"); strvec_push(&cmd.args, "-q");
strbuf_release(&base_name); strbuf_release(&base_name);

View file

@ -68,7 +68,7 @@ const char *git_pager(int stdout_is_tty)
return pager; return pager;
} }
static void setup_pager_env(struct argv_array *env) static void setup_pager_env(struct strvec *env)
{ {
const char **argv; const char **argv;
int i; int i;
@ -88,7 +88,7 @@ static void setup_pager_env(struct argv_array *env)
*cp = '\0'; *cp = '\0';
if (!getenv(argv[i])) { if (!getenv(argv[i])) {
*cp = '='; *cp = '=';
argv_array_push(env, argv[i]); strvec_push(env, argv[i]);
} }
} }
free(pager_env); free(pager_env);
@ -97,7 +97,7 @@ static void setup_pager_env(struct argv_array *env)
void prepare_pager_args(struct child_process *pager_process, const char *pager) void prepare_pager_args(struct child_process *pager_process, const char *pager)
{ {
argv_array_push(&pager_process->args, pager); strvec_push(&pager_process->args, pager);
pager_process->use_shell = 1; pager_process->use_shell = 1;
setup_pager_env(&pager_process->env_array); setup_pager_env(&pager_process->env_array);
pager_process->trace2_child_class = "pager"; pager_process->trace2_child_class = "pager";
@ -126,7 +126,7 @@ void setup_pager(void)
/* spawn the pager */ /* spawn the pager */
prepare_pager_args(&pager_process, pager); prepare_pager_args(&pager_process, pager);
pager_process.in = -1; pager_process.in = -1;
argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE"); strvec_push(&pager_process.env_array, "GIT_PAGER_IN_USE");
if (start_command(&pager_process)) if (start_command(&pager_process))
return; return;

View file

@ -4,7 +4,7 @@
#include "commit.h" #include "commit.h"
#include "color.h" #include "color.h"
#include "string-list.h" #include "string-list.h"
#include "argv-array.h" #include "strvec.h"
#include "oid-array.h" #include "oid-array.h"
/*----- some often used options -----*/ /*----- some often used options -----*/
@ -275,19 +275,19 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
/** /**
* For an option opt, recreate the command-line option, appending it to * For an option opt, recreate the command-line option, appending it to
* opt->value which must be a argv_array. This is useful when we need to pass * opt->value which must be a strvec. This is useful when we need to pass
* the command-line option, which can be specified multiple times, to another * the command-line option, which can be specified multiple times, to another
* command. * command.
*/ */
int parse_opt_passthru_argv(const struct option *opt, const char *arg, int unset) int parse_opt_passthru_argv(const struct option *opt, const char *arg, int unset)
{ {
static struct strbuf sb = STRBUF_INIT; static struct strbuf sb = STRBUF_INIT;
struct argv_array *opt_value = opt->value; struct strvec *opt_value = opt->value;
if (recreate_opt(&sb, opt, arg, unset) < 0) if (recreate_opt(&sb, opt, arg, unset) < 0)
return -1; return -1;
argv_array_push(opt_value, sb.buf); strvec_push(opt_value, sb.buf);
return 0; return 0;
} }

View file

@ -3,7 +3,7 @@
#include "dir.h" #include "dir.h"
#include "pathspec.h" #include "pathspec.h"
#include "attr.h" #include "attr.h"
#include "argv-array.h" #include "strvec.h"
#include "quote.h" #include "quote.h"
/* /*
@ -624,7 +624,7 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask,
unsigned flags, const char *prefix, unsigned flags, const char *prefix,
const char *file, int nul_term_line) const char *file, int nul_term_line)
{ {
struct argv_array parsed_file = ARGV_ARRAY_INIT; struct strvec parsed_file = STRVEC_INIT;
strbuf_getline_fn getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_fn getline_fn = nul_term_line ? strbuf_getline_nul :
strbuf_getline; strbuf_getline;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
@ -643,7 +643,7 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask,
die(_("line is badly quoted: %s"), buf.buf); die(_("line is badly quoted: %s"), buf.buf);
strbuf_swap(&buf, &unquoted); strbuf_swap(&buf, &unquoted);
} }
argv_array_push(&parsed_file, buf.buf); strvec_push(&parsed_file, buf.buf);
strbuf_reset(&buf); strbuf_reset(&buf);
} }
@ -652,8 +652,8 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask,
if (in != stdin) if (in != stdin)
fclose(in); fclose(in);
parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.argv); parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.v);
argv_array_clear(&parsed_file); strvec_clear(&parsed_file);
} }
void copy_pathspec(struct pathspec *dst, const struct pathspec *src) void copy_pathspec(struct pathspec *dst, const struct pathspec *src)

View file

@ -1,6 +1,6 @@
#include "cache.h" #include "cache.h"
#include "quote.h" #include "quote.h"
#include "argv-array.h" #include "strvec.h"
int quote_path_fully = 1; int quote_path_fully = 1;
@ -172,7 +172,7 @@ char *sq_dequote(char *arg)
static int sq_dequote_to_argv_internal(char *arg, static int sq_dequote_to_argv_internal(char *arg,
const char ***argv, int *nr, int *alloc, const char ***argv, int *nr, int *alloc,
struct argv_array *array) struct strvec *array)
{ {
char *next = arg; char *next = arg;
@ -187,7 +187,7 @@ static int sq_dequote_to_argv_internal(char *arg,
(*argv)[(*nr)++] = dequoted; (*argv)[(*nr)++] = dequoted;
} }
if (array) if (array)
argv_array_push(array, dequoted); strvec_push(array, dequoted);
} while (next); } while (next);
return 0; return 0;
@ -198,7 +198,7 @@ int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
return sq_dequote_to_argv_internal(arg, argv, nr, alloc, NULL); return sq_dequote_to_argv_internal(arg, argv, nr, alloc, NULL);
} }
int sq_dequote_to_argv_array(char *arg, struct argv_array *array) int sq_dequote_to_strvec(char *arg, struct strvec *array)
{ {
return sq_dequote_to_argv_internal(arg, NULL, NULL, NULL, array); return sq_dequote_to_argv_internal(arg, NULL, NULL, NULL, array);
} }

View file

@ -56,12 +56,12 @@ char *sq_dequote(char *);
int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc); int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc);
/* /*
* Same as above, but store the unquoted strings in an argv_array. We will * Same as above, but store the unquoted strings in a strvec. We will
* still modify arg in place, but unlike sq_dequote_to_argv, the argv_array * still modify arg in place, but unlike sq_dequote_to_argv, the strvec
* will duplicate and take ownership of the strings. * will duplicate and take ownership of the strings.
*/ */
struct argv_array; struct strvec;
int sq_dequote_to_argv_array(char *arg, struct argv_array *); int sq_dequote_to_strvec(char *arg, struct strvec *);
int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);

View file

@ -2,7 +2,7 @@
#include "range-diff.h" #include "range-diff.h"
#include "string-list.h" #include "string-list.h"
#include "run-command.h" #include "run-command.h"
#include "argv-array.h" #include "strvec.h"
#include "hashmap.h" #include "hashmap.h"
#include "xdiff-interface.h" #include "xdiff-interface.h"
#include "linear-assignment.h" #include "linear-assignment.h"
@ -41,7 +41,7 @@ static size_t find_end_of_line(char *buffer, unsigned long size)
* as struct object_id (will need to be free()d). * as struct object_id (will need to be free()d).
*/ */
static int read_patches(const char *range, struct string_list *list, static int read_patches(const char *range, struct string_list *list,
const struct argv_array *other_arg) const struct strvec *other_arg)
{ {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT;
@ -51,24 +51,24 @@ static int read_patches(const char *range, struct string_list *list,
int offset, len; int offset, len;
size_t size; size_t size;
argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
"--reverse", "--date-order", "--decorate=no", "--reverse", "--date-order", "--decorate=no",
"--no-prefix", "--no-prefix",
/* /*
* Choose indicators that are not used anywhere * Choose indicators that are not used anywhere
* else in diffs, but still look reasonable * else in diffs, but still look reasonable
* (e.g. will not be confusing when debugging) * (e.g. will not be confusing when debugging)
*/ */
"--output-indicator-new=>", "--output-indicator-new=>",
"--output-indicator-old=<", "--output-indicator-old=<",
"--output-indicator-context=#", "--output-indicator-context=#",
"--no-abbrev-commit", "--no-abbrev-commit",
"--pretty=medium", "--pretty=medium",
"--notes", "--notes",
NULL); NULL);
if (other_arg) if (other_arg)
argv_array_pushv(&cp.args, other_arg->argv); strvec_pushv(&cp.args, other_arg->v);
argv_array_push(&cp.args, range); strvec_push(&cp.args, range);
cp.out = -1; cp.out = -1;
cp.no_stdin = 1; cp.no_stdin = 1;
cp.git_cmd = 1; cp.git_cmd = 1;
@ -523,7 +523,7 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
int show_range_diff(const char *range1, const char *range2, int show_range_diff(const char *range1, const char *range2,
int creation_factor, int dual_color, int creation_factor, int dual_color,
const struct diff_options *diffopt, const struct diff_options *diffopt,
const struct argv_array *other_arg) const struct strvec *other_arg)
{ {
int res = 0; int res = 0;

View file

@ -2,7 +2,7 @@
#define RANGE_DIFF_H #define RANGE_DIFF_H
#include "diff.h" #include "diff.h"
#include "argv-array.h" #include "strvec.h"
#define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60 #define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60
@ -14,6 +14,6 @@
int show_range_diff(const char *range1, const char *range2, int show_range_diff(const char *range1, const char *range2,
int creation_factor, int dual_color, int creation_factor, int dual_color,
const struct diff_options *diffopt, const struct diff_options *diffopt,
const struct argv_array *other_arg); const struct strvec *other_arg);
#endif #endif

View file

@ -22,7 +22,7 @@
#include "commit-reach.h" #include "commit-reach.h"
#include "worktree.h" #include "worktree.h"
#include "hashmap.h" #include "hashmap.h"
#include "argv-array.h" #include "strvec.h"
static struct ref_msg { static struct ref_msg {
const char *gone; const char *gone;
@ -1919,15 +1919,15 @@ static void find_longest_prefixes_1(struct string_list *out,
static void find_longest_prefixes(struct string_list *out, static void find_longest_prefixes(struct string_list *out,
const char **patterns) const char **patterns)
{ {
struct argv_array sorted = ARGV_ARRAY_INIT; struct strvec sorted = STRVEC_INIT;
struct strbuf prefix = STRBUF_INIT; struct strbuf prefix = STRBUF_INIT;
argv_array_pushv(&sorted, patterns); strvec_pushv(&sorted, patterns);
QSORT(sorted.argv, sorted.argc, qsort_strcmp); QSORT(sorted.v, sorted.nr, qsort_strcmp);
find_longest_prefixes_1(out, &prefix, sorted.argv, sorted.argc); find_longest_prefixes_1(out, &prefix, sorted.v, sorted.nr);
argv_array_clear(&sorted); strvec_clear(&sorted);
strbuf_release(&prefix); strbuf_release(&prefix);
} }

8
refs.c
View file

@ -15,7 +15,7 @@
#include "tag.h" #include "tag.h"
#include "submodule.h" #include "submodule.h"
#include "worktree.h" #include "worktree.h"
#include "argv-array.h" #include "strvec.h"
#include "repository.h" #include "repository.h"
#include "sigchain.h" #include "sigchain.h"
@ -553,13 +553,13 @@ int refname_match(const char *abbrev_name, const char *full_name)
* Given a 'prefix' expand it by the rules in 'ref_rev_parse_rules' and add * Given a 'prefix' expand it by the rules in 'ref_rev_parse_rules' and add
* the results to 'prefixes' * the results to 'prefixes'
*/ */
void expand_ref_prefix(struct argv_array *prefixes, const char *prefix) void expand_ref_prefix(struct strvec *prefixes, const char *prefix)
{ {
const char **p; const char **p;
int len = strlen(prefix); int len = strlen(prefix);
for (p = ref_rev_parse_rules; *p; p++) for (p = ref_rev_parse_rules; *p; p++)
argv_array_pushf(prefixes, *p, len, prefix); strvec_pushf(prefixes, *p, len, prefix);
} }
char *repo_default_branch_name(struct repository *r) char *repo_default_branch_name(struct repository *r)
@ -2050,7 +2050,7 @@ static int run_transaction_hook(struct ref_transaction *transaction,
return ret; return ret;
} }
argv_array_pushl(&proc.args, hook, state, NULL); strvec_pushl(&proc.args, hook, state, NULL);
proc.in = -1; proc.in = -1;
proc.stdout_to_stderr = 1; proc.stdout_to_stderr = 1;
proc.trace2_hook_name = "reference-transaction"; proc.trace2_hook_name = "reference-transaction";

4
refs.h
View file

@ -145,8 +145,8 @@ int refname_match(const char *abbrev_name, const char *full_name);
* Given a 'prefix' expand it by the rules in 'ref_rev_parse_rules' and add * Given a 'prefix' expand it by the rules in 'ref_rev_parse_rules' and add
* the results to 'prefixes' * the results to 'prefixes'
*/ */
struct argv_array; struct strvec;
void expand_ref_prefix(struct argv_array *prefixes, const char *prefix); void expand_ref_prefix(struct strvec *prefixes, const char *prefix);
int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);

View file

@ -1,5 +1,5 @@
#include "cache.h" #include "cache.h"
#include "argv-array.h" #include "strvec.h"
#include "refs.h" #include "refs.h"
#include "refspec.h" #include "refspec.h"
@ -202,7 +202,7 @@ int valid_fetch_refspec(const char *fetch_refspec_str)
} }
void refspec_ref_prefixes(const struct refspec *rs, void refspec_ref_prefixes(const struct refspec *rs,
struct argv_array *ref_prefixes) struct strvec *ref_prefixes)
{ {
int i; int i;
for (i = 0; i < rs->nr; i++) { for (i = 0; i < rs->nr; i++) {
@ -221,9 +221,9 @@ void refspec_ref_prefixes(const struct refspec *rs,
if (prefix) { if (prefix) {
if (item->pattern) { if (item->pattern) {
const char *glob = strchr(prefix, '*'); const char *glob = strchr(prefix, '*');
argv_array_pushf(ref_prefixes, "%.*s", strvec_pushf(ref_prefixes, "%.*s",
(int)(glob - prefix), (int)(glob - prefix),
prefix); prefix);
} else { } else {
expand_ref_prefix(ref_prefixes, prefix); expand_ref_prefix(ref_prefixes, prefix);
} }

View file

@ -60,12 +60,12 @@ void refspec_clear(struct refspec *rs);
int valid_fetch_refspec(const char *refspec); int valid_fetch_refspec(const char *refspec);
struct argv_array; struct strvec;
/* /*
* Determine what <prefix> values to pass to the peer in ref-prefix lines * Determine what <prefix> values to pass to the peer in ref-prefix lines
* (see Documentation/technical/protocol-v2.txt). * (see Documentation/technical/protocol-v2.txt).
*/ */
void refspec_ref_prefixes(const struct refspec *rs, void refspec_ref_prefixes(const struct refspec *rs,
struct argv_array *ref_prefixes); struct strvec *ref_prefixes);
#endif /* REFSPEC_H */ #endif /* REFSPEC_H */

View file

@ -10,7 +10,7 @@
#include "pkt-line.h" #include "pkt-line.h"
#include "string-list.h" #include "string-list.h"
#include "sideband.h" #include "sideband.h"
#include "argv-array.h" #include "strvec.h"
#include "credential.h" #include "credential.h"
#include "oid-array.h" #include "oid-array.h"
#include "send-pack.h" #include "send-pack.h"
@ -1145,41 +1145,41 @@ 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;
int i, err; int i, err;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
struct strbuf rpc_result = STRBUF_INIT; struct strbuf rpc_result = STRBUF_INIT;
argv_array_pushl(&args, "fetch-pack", "--stateless-rpc", strvec_pushl(&args, "fetch-pack", "--stateless-rpc",
"--stdin", "--lock-pack", NULL); "--stdin", "--lock-pack", NULL);
if (options.followtags) if (options.followtags)
argv_array_push(&args, "--include-tag"); strvec_push(&args, "--include-tag");
if (options.thin) if (options.thin)
argv_array_push(&args, "--thin"); strvec_push(&args, "--thin");
if (options.verbosity >= 3) if (options.verbosity >= 3)
argv_array_pushl(&args, "-v", "-v", NULL); strvec_pushl(&args, "-v", "-v", NULL);
if (options.check_self_contained_and_connected) if (options.check_self_contained_and_connected)
argv_array_push(&args, "--check-self-contained-and-connected"); strvec_push(&args, "--check-self-contained-and-connected");
if (options.cloning) if (options.cloning)
argv_array_push(&args, "--cloning"); strvec_push(&args, "--cloning");
if (options.update_shallow) if (options.update_shallow)
argv_array_push(&args, "--update-shallow"); strvec_push(&args, "--update-shallow");
if (!options.progress) if (!options.progress)
argv_array_push(&args, "--no-progress"); strvec_push(&args, "--no-progress");
if (options.depth) if (options.depth)
argv_array_pushf(&args, "--depth=%lu", options.depth); strvec_pushf(&args, "--depth=%lu", options.depth);
if (options.deepen_since) if (options.deepen_since)
argv_array_pushf(&args, "--shallow-since=%s", options.deepen_since); strvec_pushf(&args, "--shallow-since=%s", options.deepen_since);
for (i = 0; i < options.deepen_not.nr; i++) for (i = 0; i < options.deepen_not.nr; i++)
argv_array_pushf(&args, "--shallow-exclude=%s", strvec_pushf(&args, "--shallow-exclude=%s",
options.deepen_not.items[i].string); options.deepen_not.items[i].string);
if (options.deepen_relative && options.depth) if (options.deepen_relative && options.depth)
argv_array_push(&args, "--deepen-relative"); strvec_push(&args, "--deepen-relative");
if (options.from_promisor) if (options.from_promisor)
argv_array_push(&args, "--from-promisor"); strvec_push(&args, "--from-promisor");
if (options.no_dependents) if (options.no_dependents)
argv_array_push(&args, "--no-dependents"); strvec_push(&args, "--no-dependents");
if (options.filter) if (options.filter)
argv_array_pushf(&args, "--filter=%s", options.filter); strvec_pushf(&args, "--filter=%s", options.filter);
argv_array_push(&args, url.buf); strvec_push(&args, url.buf);
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];
@ -1194,12 +1194,12 @@ static int fetch_git(struct discovery *heads,
rpc.service_name = "git-upload-pack", rpc.service_name = "git-upload-pack",
rpc.gzip_request = 1; rpc.gzip_request = 1;
err = rpc_service(&rpc, heads, args.argv, &preamble, &rpc_result); err = rpc_service(&rpc, heads, args.v, &preamble, &rpc_result);
if (rpc_result.len) if (rpc_result.len)
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);
argv_array_clear(&args); strvec_clear(&args);
return err; return err;
} }
@ -1271,15 +1271,15 @@ static int push_dav(int nr_spec, const char **specs)
size_t i; size_t i;
child.git_cmd = 1; child.git_cmd = 1;
argv_array_push(&child.args, "http-push"); strvec_push(&child.args, "http-push");
argv_array_push(&child.args, "--helper-status"); strvec_push(&child.args, "--helper-status");
if (options.dry_run) if (options.dry_run)
argv_array_push(&child.args, "--dry-run"); strvec_push(&child.args, "--dry-run");
if (options.verbosity > 1) if (options.verbosity > 1)
argv_array_push(&child.args, "--verbose"); strvec_push(&child.args, "--verbose");
argv_array_push(&child.args, url.buf); strvec_push(&child.args, url.buf);
for (i = 0; i < nr_spec; i++) for (i = 0; i < nr_spec; i++)
argv_array_push(&child.args, specs[i]); strvec_push(&child.args, specs[i]);
if (run_command(&child)) if (run_command(&child))
die(_("git-http-push failed")); die(_("git-http-push failed"));
@ -1290,38 +1290,38 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
{ {
struct rpc_state rpc; struct rpc_state rpc;
int i, err; int i, err;
struct argv_array args; struct strvec args;
struct string_list_item *cas_option; struct string_list_item *cas_option;
struct strbuf preamble = STRBUF_INIT; struct strbuf preamble = STRBUF_INIT;
struct strbuf rpc_result = STRBUF_INIT; struct strbuf rpc_result = STRBUF_INIT;
argv_array_init(&args); strvec_init(&args);
argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", strvec_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
NULL); NULL);
if (options.thin) if (options.thin)
argv_array_push(&args, "--thin"); strvec_push(&args, "--thin");
if (options.dry_run) if (options.dry_run)
argv_array_push(&args, "--dry-run"); strvec_push(&args, "--dry-run");
if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS) if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS)
argv_array_push(&args, "--signed=yes"); strvec_push(&args, "--signed=yes");
else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED)
argv_array_push(&args, "--signed=if-asked"); strvec_push(&args, "--signed=if-asked");
if (options.atomic) if (options.atomic)
argv_array_push(&args, "--atomic"); strvec_push(&args, "--atomic");
if (options.verbosity == 0) if (options.verbosity == 0)
argv_array_push(&args, "--quiet"); strvec_push(&args, "--quiet");
else if (options.verbosity > 1) else if (options.verbosity > 1)
argv_array_push(&args, "--verbose"); strvec_push(&args, "--verbose");
for (i = 0; i < options.push_options.nr; i++) for (i = 0; i < options.push_options.nr; i++)
argv_array_pushf(&args, "--push-option=%s", strvec_pushf(&args, "--push-option=%s",
options.push_options.items[i].string); options.push_options.items[i].string);
argv_array_push(&args, options.progress ? "--progress" : "--no-progress"); strvec_push(&args, options.progress ? "--progress" : "--no-progress");
for_each_string_list_item(cas_option, &cas_options) for_each_string_list_item(cas_option, &cas_options)
argv_array_push(&args, cas_option->string); strvec_push(&args, cas_option->string);
argv_array_push(&args, url.buf); strvec_push(&args, url.buf);
argv_array_push(&args, "--stdin"); strvec_push(&args, "--stdin");
for (i = 0; i < nr_spec; i++) for (i = 0; i < nr_spec; i++)
packet_buf_write(&preamble, "%s\n", specs[i]); packet_buf_write(&preamble, "%s\n", specs[i]);
packet_buf_flush(&preamble); packet_buf_flush(&preamble);
@ -1329,12 +1329,12 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
memset(&rpc, 0, sizeof(rpc)); memset(&rpc, 0, sizeof(rpc));
rpc.service_name = "git-receive-pack", rpc.service_name = "git-receive-pack",
err = rpc_service(&rpc, heads, args.argv, &preamble, &rpc_result); err = rpc_service(&rpc, heads, args.v, &preamble, &rpc_result);
if (rpc_result.len) if (rpc_result.len)
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);
argv_array_clear(&args); strvec_clear(&args);
return err; return err;
} }
@ -1353,13 +1353,13 @@ static int push(int nr_spec, const char **specs)
static void parse_push(struct strbuf *buf) static void parse_push(struct strbuf *buf)
{ {
struct argv_array specs = ARGV_ARRAY_INIT; struct strvec specs = STRVEC_INIT;
int ret; int ret;
do { do {
const char *arg; const char *arg;
if (skip_prefix(buf->buf, "push ", &arg)) if (skip_prefix(buf->buf, "push ", &arg))
argv_array_push(&specs, arg); strvec_push(&specs, arg);
else else
die(_("http transport does not support %s"), buf->buf); die(_("http transport does not support %s"), buf->buf);
@ -1370,7 +1370,7 @@ static void parse_push(struct strbuf *buf)
break; break;
} while (1); } while (1);
ret = push(specs.argc, specs.argv); ret = push(specs.nr, specs.v);
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);
@ -1378,7 +1378,7 @@ static void parse_push(struct strbuf *buf)
exit(128); /* error already reported */ exit(128); /* error already reported */
free_specs: free_specs:
argv_array_clear(&specs); strvec_clear(&specs);
} }
static int stateless_connect(const char *service_name) static int stateless_connect(const char *service_name)

View file

@ -8,7 +8,7 @@
#include "run-command.h" #include "run-command.h"
#include "vcs-svn/svndump.h" #include "vcs-svn/svndump.h"
#include "notes.h" #include "notes.h"
#include "argv-array.h" #include "strvec.h"
static const char *url; static const char *url;
static int dump_from_file; static int dump_from_file;
@ -198,10 +198,10 @@ static int cmd_import(const char *line)
die_errno("Couldn't open svn dump file %s.", url); die_errno("Couldn't open svn dump file %s.", url);
} else { } else {
svndump_proc.out = -1; svndump_proc.out = -1;
argv_array_push(&svndump_proc.args, command); strvec_push(&svndump_proc.args, command);
argv_array_push(&svndump_proc.args, "dump"); strvec_push(&svndump_proc.args, "dump");
argv_array_push(&svndump_proc.args, url); strvec_push(&svndump_proc.args, url);
argv_array_pushf(&svndump_proc.args, "-r%u:HEAD", startrev); strvec_pushf(&svndump_proc.args, "-r%u:HEAD", startrev);
code = start_command(&svndump_proc); code = start_command(&svndump_proc);
if (code) if (code)

View file

@ -11,7 +11,7 @@
#include "tag.h" #include "tag.h"
#include "string-list.h" #include "string-list.h"
#include "mergesort.h" #include "mergesort.h"
#include "argv-array.h" #include "strvec.h"
#include "commit-reach.h" #include "commit-reach.h"
#include "advice.h" #include "advice.h"
@ -1885,7 +1885,7 @@ static int stat_branch_pair(const char *branch_name, const char *base,
struct object_id oid; struct object_id oid;
struct commit *ours, *theirs; struct commit *ours, *theirs;
struct rev_info revs; struct rev_info revs;
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
/* Cannot stat if what we used to build on no longer exists */ /* Cannot stat if what we used to build on no longer exists */
if (read_ref(base, &oid)) if (read_ref(base, &oid))
@ -1911,15 +1911,15 @@ static int stat_branch_pair(const char *branch_name, const char *base,
BUG("stat_branch_pair: invalid abf '%d'", abf); BUG("stat_branch_pair: invalid abf '%d'", abf);
/* Run "rev-list --left-right ours...theirs" internally... */ /* Run "rev-list --left-right ours...theirs" internally... */
argv_array_push(&argv, ""); /* ignored */ strvec_push(&argv, ""); /* ignored */
argv_array_push(&argv, "--left-right"); strvec_push(&argv, "--left-right");
argv_array_pushf(&argv, "%s...%s", strvec_pushf(&argv, "%s...%s",
oid_to_hex(&ours->object.oid), oid_to_hex(&ours->object.oid),
oid_to_hex(&theirs->object.oid)); oid_to_hex(&theirs->object.oid));
argv_array_push(&argv, "--"); strvec_push(&argv, "--");
repo_init_revisions(the_repository, &revs, NULL); repo_init_revisions(the_repository, &revs, NULL);
setup_revisions(argv.argc, argv.argv, &revs, NULL); setup_revisions(argv.nr, argv.v, &revs, NULL);
if (prepare_revision_walk(&revs)) if (prepare_revision_walk(&revs))
die(_("revision walk setup failed")); die(_("revision walk setup failed"));
@ -1938,7 +1938,7 @@ static int stat_branch_pair(const char *branch_name, const char *base,
clear_commit_marks(ours, ALL_REV_FLAGS); clear_commit_marks(ours, ALL_REV_FLAGS);
clear_commit_marks(theirs, ALL_REV_FLAGS); clear_commit_marks(theirs, ALL_REV_FLAGS);
argv_array_clear(&argv); strvec_clear(&argv);
return 1; return 1;
} }

View file

@ -168,7 +168,7 @@ void free_refs(struct ref *ref);
struct oid_array; struct oid_array;
struct packet_reader; struct packet_reader;
struct argv_array; struct strvec;
struct string_list; struct string_list;
struct ref **get_remote_heads(struct packet_reader *reader, struct ref **get_remote_heads(struct packet_reader *reader,
struct ref **list, unsigned int flags, struct ref **list, unsigned int flags,
@ -178,7 +178,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
/* Used for protocol v2 in order to retrieve refs from a remote */ /* Used for protocol v2 in order to retrieve refs from a remote */
struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
struct ref **list, int for_push, struct ref **list, int for_push,
const struct argv_array *ref_prefixes, const struct strvec *ref_prefixes,
const struct string_list *server_options, const struct string_list *server_options,
int stateless_rpc); int stateless_rpc);

View file

@ -23,7 +23,7 @@
#include "bisect.h" #include "bisect.h"
#include "packfile.h" #include "packfile.h"
#include "worktree.h" #include "worktree.h"
#include "argv-array.h" #include "strvec.h"
#include "commit-reach.h" #include "commit-reach.h"
#include "commit-graph.h" #include "commit-graph.h"
#include "prio-queue.h" #include "prio-queue.h"
@ -2095,14 +2095,14 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
} }
static void read_pathspec_from_stdin(struct strbuf *sb, static void read_pathspec_from_stdin(struct strbuf *sb,
struct argv_array *prune) struct strvec *prune)
{ {
while (strbuf_getline(sb, stdin) != EOF) while (strbuf_getline(sb, stdin) != EOF)
argv_array_push(prune, sb->buf); strvec_push(prune, sb->buf);
} }
static void read_revisions_from_stdin(struct rev_info *revs, static void read_revisions_from_stdin(struct rev_info *revs,
struct argv_array *prune) struct strvec *prune)
{ {
struct strbuf sb; struct strbuf sb;
int seen_dashdash = 0; int seen_dashdash = 0;
@ -2697,7 +2697,7 @@ static void NORETURN diagnose_missing_default(const char *def)
int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt) int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
{ {
int i, flags, left, seen_dashdash, got_rev_arg = 0, revarg_opt; int i, flags, left, seen_dashdash, got_rev_arg = 0, revarg_opt;
struct argv_array prune_data = ARGV_ARRAY_INIT; struct strvec prune_data = STRVEC_INIT;
const char *submodule = NULL; const char *submodule = NULL;
int seen_end_of_options = 0; int seen_end_of_options = 0;
@ -2716,7 +2716,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
argv[i] = NULL; argv[i] = NULL;
argc = i; argc = i;
if (argv[i + 1]) if (argv[i + 1])
argv_array_pushv(&prune_data, argv + i + 1); strvec_pushv(&prune_data, argv + i + 1);
seen_dashdash = 1; seen_dashdash = 1;
break; break;
} }
@ -2782,14 +2782,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
for (j = i; j < argc; j++) for (j = i; j < argc; j++)
verify_filename(revs->prefix, argv[j], j == i); verify_filename(revs->prefix, argv[j], j == i);
argv_array_pushv(&prune_data, argv + i); strvec_pushv(&prune_data, argv + i);
break; break;
} }
else else
got_rev_arg = 1; got_rev_arg = 1;
} }
if (prune_data.argc) { if (prune_data.nr) {
/* /*
* If we need to introduce the magic "a lone ':' means no * If we need to introduce the magic "a lone ':' means no
* pathspec whatsoever", here is the place to do so. * pathspec whatsoever", here is the place to do so.
@ -2805,9 +2805,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
* } * }
*/ */
parse_pathspec(&revs->prune_data, 0, 0, parse_pathspec(&revs->prune_data, 0, 0,
revs->prefix, prune_data.argv); revs->prefix, prune_data.v);
} }
argv_array_clear(&prune_data); strvec_clear(&prune_data);
if (revs->def == NULL) if (revs->def == NULL)
revs->def = opt ? opt->def : NULL; revs->def = opt ? opt->def : NULL;

View file

@ -2,7 +2,7 @@
#include "run-command.h" #include "run-command.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "sigchain.h" #include "sigchain.h"
#include "argv-array.h" #include "strvec.h"
#include "thread-utils.h" #include "thread-utils.h"
#include "strbuf.h" #include "strbuf.h"
#include "string-list.h" #include "string-list.h"
@ -11,14 +11,14 @@
void child_process_init(struct child_process *child) void child_process_init(struct child_process *child)
{ {
memset(child, 0, sizeof(*child)); memset(child, 0, sizeof(*child));
argv_array_init(&child->args); strvec_init(&child->args);
argv_array_init(&child->env_array); strvec_init(&child->env_array);
} }
void child_process_clear(struct child_process *child) void child_process_clear(struct child_process *child)
{ {
argv_array_clear(&child->args); strvec_clear(&child->args);
argv_array_clear(&child->env_array); strvec_clear(&child->env_array);
} }
struct child_to_clean { struct child_to_clean {
@ -263,31 +263,31 @@ int sane_execvp(const char *file, char * const argv[])
return -1; return -1;
} }
static const char **prepare_shell_cmd(struct argv_array *out, const char **argv) static const char **prepare_shell_cmd(struct strvec *out, const char **argv)
{ {
if (!argv[0]) if (!argv[0])
BUG("shell command is empty"); BUG("shell command is empty");
if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
#ifndef GIT_WINDOWS_NATIVE #ifndef GIT_WINDOWS_NATIVE
argv_array_push(out, SHELL_PATH); strvec_push(out, SHELL_PATH);
#else #else
argv_array_push(out, "sh"); strvec_push(out, "sh");
#endif #endif
argv_array_push(out, "-c"); strvec_push(out, "-c");
/* /*
* If we have no extra arguments, we do not even need to * If we have no extra arguments, we do not even need to
* bother with the "$@" magic. * bother with the "$@" magic.
*/ */
if (!argv[1]) if (!argv[1])
argv_array_push(out, argv[0]); strvec_push(out, argv[0]);
else else
argv_array_pushf(out, "%s \"$@\"", argv[0]); strvec_pushf(out, "%s \"$@\"", argv[0]);
} }
argv_array_pushv(out, argv); strvec_pushv(out, argv);
return out->argv; return out->v;
} }
#ifndef GIT_WINDOWS_NATIVE #ifndef GIT_WINDOWS_NATIVE
@ -401,7 +401,7 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
set_error_routine(old_errfn); set_error_routine(old_errfn);
} }
static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) static int prepare_cmd(struct strvec *out, const struct child_process *cmd)
{ {
if (!cmd->argv[0]) if (!cmd->argv[0])
BUG("command is empty"); BUG("command is empty");
@ -410,14 +410,14 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd)
* Add SHELL_PATH so in the event exec fails with ENOEXEC we can * Add SHELL_PATH so in the event exec fails with ENOEXEC we can
* attempt to interpret the command with 'sh'. * attempt to interpret the command with 'sh'.
*/ */
argv_array_push(out, SHELL_PATH); strvec_push(out, SHELL_PATH);
if (cmd->git_cmd) { if (cmd->git_cmd) {
prepare_git_cmd(out, cmd->argv); prepare_git_cmd(out, cmd->argv);
} else if (cmd->use_shell) { } else if (cmd->use_shell) {
prepare_shell_cmd(out, cmd->argv); prepare_shell_cmd(out, cmd->argv);
} else { } else {
argv_array_pushv(out, cmd->argv); strvec_pushv(out, cmd->argv);
} }
/* /*
@ -426,13 +426,13 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd)
* there are dir separator characters, we have exec attempt to invoke * there are dir separator characters, we have exec attempt to invoke
* the command directly. * the command directly.
*/ */
if (!has_dir_sep(out->argv[1])) { if (!has_dir_sep(out->v[1])) {
char *program = locate_in_PATH(out->argv[1]); char *program = locate_in_PATH(out->v[1]);
if (program) { if (program) {
free((char *)out->argv[1]); free((char *)out->v[1]);
out->argv[1] = program; out->v[1] = program;
} else { } else {
argv_array_clear(out); strvec_clear(out);
errno = ENOENT; errno = ENOENT;
return -1; return -1;
} }
@ -672,9 +672,9 @@ int start_command(struct child_process *cmd)
char *str; char *str;
if (!cmd->argv) if (!cmd->argv)
cmd->argv = cmd->args.argv; cmd->argv = cmd->args.v;
if (!cmd->env) if (!cmd->env)
cmd->env = cmd->env_array.argv; cmd->env = cmd->env_array.v;
/* /*
* In case of errors we must keep the promise to close FDs * In case of errors we must keep the promise to close FDs
@ -742,7 +742,7 @@ int start_command(struct child_process *cmd)
int notify_pipe[2]; int notify_pipe[2];
int null_fd = -1; int null_fd = -1;
char **childenv; char **childenv;
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
struct child_err cerr; struct child_err cerr;
struct atfork_state as; struct atfork_state as;
@ -846,10 +846,10 @@ int start_command(struct child_process *cmd)
* be used in the event exec failed with ENOEXEC at which point * be used in the event exec failed with ENOEXEC at which point
* we will try to interpret the command using 'sh'. * we will try to interpret the command using 'sh'.
*/ */
execve(argv.argv[1], (char *const *) argv.argv + 1, execve(argv.v[1], (char *const *) argv.v + 1,
(char *const *) childenv); (char *const *) childenv);
if (errno == ENOEXEC) if (errno == ENOEXEC)
execve(argv.argv[0], (char *const *) argv.argv, execve(argv.v[0], (char *const *) argv.v,
(char *const *) childenv); (char *const *) childenv);
if (errno == ENOENT) { if (errno == ENOENT) {
@ -888,7 +888,7 @@ int start_command(struct child_process *cmd)
if (null_fd >= 0) if (null_fd >= 0)
close(null_fd); close(null_fd);
argv_array_clear(&argv); strvec_clear(&argv);
free(childenv); free(childenv);
} }
end_of_spawn: end_of_spawn:
@ -897,7 +897,7 @@ int start_command(struct child_process *cmd)
{ {
int fhin = 0, fhout = 1, fherr = 2; int fhin = 0, fhout = 1, fherr = 2;
const char **sargv = cmd->argv; const char **sargv = cmd->argv;
struct argv_array nargv = ARGV_ARRAY_INIT; struct strvec nargv = STRVEC_INIT;
if (cmd->no_stdin) if (cmd->no_stdin)
fhin = open("/dev/null", O_RDWR); fhin = open("/dev/null", O_RDWR);
@ -935,7 +935,7 @@ int start_command(struct child_process *cmd)
if (cmd->clean_on_exit && cmd->pid >= 0) if (cmd->clean_on_exit && cmd->pid >= 0)
mark_child_for_cleanup(cmd->pid, cmd); mark_child_for_cleanup(cmd->pid, cmd);
argv_array_clear(&nargv); strvec_clear(&nargv);
cmd->argv = sargv; cmd->argv = sargv;
if (fhin != 0) if (fhin != 0)
close(fhin); close(fhin);
@ -1352,9 +1352,9 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
if (!p) if (!p)
return 0; return 0;
argv_array_push(&hook.args, p); strvec_push(&hook.args, p);
while ((p = va_arg(args, const char *))) while ((p = va_arg(args, const char *)))
argv_array_push(&hook.args, p); strvec_push(&hook.args, p);
hook.env = env; hook.env = env;
hook.no_stdin = 1; hook.no_stdin = 1;
hook.stdout_to_stderr = 1; hook.stdout_to_stderr = 1;
@ -1868,13 +1868,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
int run_auto_gc(int quiet) int run_auto_gc(int quiet)
{ {
struct argv_array argv_gc_auto = ARGV_ARRAY_INIT; struct strvec argv_gc_auto = STRVEC_INIT;
int status; int status;
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL); strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL);
if (quiet) if (quiet)
argv_array_push(&argv_gc_auto, "--quiet"); strvec_push(&argv_gc_auto, "--quiet");
status = run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD); status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD);
argv_array_clear(&argv_gc_auto); strvec_clear(&argv_gc_auto);
return status; return status;
} }

View file

@ -3,7 +3,7 @@
#include "thread-utils.h" #include "thread-utils.h"
#include "argv-array.h" #include "strvec.h"
/** /**
* The run-command API offers a versatile tool to run sub-processes with * The run-command API offers a versatile tool to run sub-processes with
@ -52,15 +52,15 @@ struct child_process {
* Note that the ownership of the memory pointed to by .argv stays with the * Note that the ownership of the memory pointed to by .argv stays with the
* caller, but it should survive until `finish_command` completes. If the * caller, but it should survive until `finish_command` completes. If the
* .argv member is NULL, `start_command` will point it at the .args * .argv member is NULL, `start_command` will point it at the .args
* `argv_array` (so you may use one or the other, but you must use exactly * `strvec` (so you may use one or the other, but you must use exactly
* one). The memory in .args will be cleaned up automatically during * one). The memory in .args will be cleaned up automatically during
* `finish_command` (or during `start_command` when it is unsuccessful). * `finish_command` (or during `start_command` when it is unsuccessful).
* *
*/ */
const char **argv; const char **argv;
struct argv_array args; struct strvec args;
struct argv_array env_array; struct strvec env_array;
pid_t pid; pid_t pid;
int trace2_child_id; int trace2_child_id;
@ -107,7 +107,7 @@ struct child_process {
* variable that will be removed from the child process's environment. * variable that will be removed from the child process's environment.
* *
* If the .env member is NULL, `start_command` will point it at the * If the .env member is NULL, `start_command` will point it at the
* .env_array `argv_array` (so you may use one or the other, but not both). * .env_array `strvec` (so you may use one or the other, but not both).
* The memory in .env_array will be cleaned up automatically during * The memory in .env_array will be cleaned up automatically during
* `finish_command` (or during `start_command` when it is unsuccessful). * `finish_command` (or during `start_command` when it is unsuccessful).
*/ */
@ -134,7 +134,7 @@ struct child_process {
void *clean_on_exit_handler_cbdata; void *clean_on_exit_handler_cbdata;
}; };
#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT, ARGV_ARRAY_INIT } #define CHILD_PROCESS_INIT { NULL, STRVEC_INIT, STRVEC_INIT }
/** /**
* The functions: child_process_init, start_command, finish_command, * The functions: child_process_init, start_command, finish_command,

View file

@ -68,20 +68,20 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
int i; int i;
int rc; int rc;
argv_array_push(&po.args, "pack-objects"); strvec_push(&po.args, "pack-objects");
argv_array_push(&po.args, "--all-progress-implied"); strvec_push(&po.args, "--all-progress-implied");
argv_array_push(&po.args, "--revs"); strvec_push(&po.args, "--revs");
argv_array_push(&po.args, "--stdout"); strvec_push(&po.args, "--stdout");
if (args->use_thin_pack) if (args->use_thin_pack)
argv_array_push(&po.args, "--thin"); strvec_push(&po.args, "--thin");
if (args->use_ofs_delta) if (args->use_ofs_delta)
argv_array_push(&po.args, "--delta-base-offset"); strvec_push(&po.args, "--delta-base-offset");
if (args->quiet || !args->progress) if (args->quiet || !args->progress)
argv_array_push(&po.args, "-q"); strvec_push(&po.args, "-q");
if (args->progress) if (args->progress)
argv_array_push(&po.args, "--progress"); strvec_push(&po.args, "--progress");
if (is_repository_shallow(the_repository)) if (is_repository_shallow(the_repository))
argv_array_push(&po.args, "--shallow"); strvec_push(&po.args, "--shallow");
po.in = -1; po.in = -1;
po.out = args->stateless_rpc ? -1 : fd; po.out = args->stateless_rpc ? -1 : fd;
po.git_cmd = 1; po.git_cmd = 1;

View file

@ -16,7 +16,7 @@
#include "rerere.h" #include "rerere.h"
#include "merge-recursive.h" #include "merge-recursive.h"
#include "refs.h" #include "refs.h"
#include "argv-array.h" #include "strvec.h"
#include "quote.h" #include "quote.h"
#include "trailer.h" #include "trailer.h"
#include "log-tree.h" #include "log-tree.h"
@ -830,10 +830,10 @@ int read_author_script(const char *path, char **name, char **email, char **date,
/* /*
* Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL AND GIT_AUTHOR_DATE from a * Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL AND GIT_AUTHOR_DATE from a
* file with shell quoting into struct argv_array. Returns -1 on * file with shell quoting into struct strvec. Returns -1 on
* error, 0 otherwise. * error, 0 otherwise.
*/ */
static int read_env_script(struct argv_array *env) static int read_env_script(struct strvec *env)
{ {
char *name, *email, *date; char *name, *email, *date;
@ -841,9 +841,9 @@ static int read_env_script(struct argv_array *env)
&name, &email, &date, 0)) &name, &email, &date, 0))
return -1; return -1;
argv_array_pushf(env, "GIT_AUTHOR_NAME=%s", name); strvec_pushf(env, "GIT_AUTHOR_NAME=%s", name);
argv_array_pushf(env, "GIT_AUTHOR_EMAIL=%s", email); strvec_pushf(env, "GIT_AUTHOR_EMAIL=%s", email);
argv_array_pushf(env, "GIT_AUTHOR_DATE=%s", date); strvec_pushf(env, "GIT_AUTHOR_DATE=%s", date);
free(name); free(name);
free(email); free(email);
free(date); free(date);
@ -929,34 +929,34 @@ static int run_git_commit(struct repository *r,
gpg_opt, gpg_opt); gpg_opt, gpg_opt);
} }
argv_array_push(&cmd.args, "commit"); strvec_push(&cmd.args, "commit");
if (!(flags & VERIFY_MSG)) if (!(flags & VERIFY_MSG))
argv_array_push(&cmd.args, "-n"); strvec_push(&cmd.args, "-n");
if ((flags & AMEND_MSG)) if ((flags & AMEND_MSG))
argv_array_push(&cmd.args, "--amend"); strvec_push(&cmd.args, "--amend");
if (opts->gpg_sign) if (opts->gpg_sign)
argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign); strvec_pushf(&cmd.args, "-S%s", opts->gpg_sign);
else else
argv_array_push(&cmd.args, "--no-gpg-sign"); strvec_push(&cmd.args, "--no-gpg-sign");
if (defmsg) if (defmsg)
argv_array_pushl(&cmd.args, "-F", defmsg, NULL); strvec_pushl(&cmd.args, "-F", defmsg, NULL);
else if (!(flags & EDIT_MSG)) else if (!(flags & EDIT_MSG))
argv_array_pushl(&cmd.args, "-C", "HEAD", NULL); strvec_pushl(&cmd.args, "-C", "HEAD", NULL);
if ((flags & CLEANUP_MSG)) if ((flags & CLEANUP_MSG))
argv_array_push(&cmd.args, "--cleanup=strip"); strvec_push(&cmd.args, "--cleanup=strip");
if ((flags & EDIT_MSG)) if ((flags & EDIT_MSG))
argv_array_push(&cmd.args, "-e"); strvec_push(&cmd.args, "-e");
else if (!(flags & CLEANUP_MSG) && else if (!(flags & CLEANUP_MSG) &&
!opts->signoff && !opts->record_origin && !opts->signoff && !opts->record_origin &&
!opts->explicit_cleanup) !opts->explicit_cleanup)
argv_array_push(&cmd.args, "--cleanup=verbatim"); strvec_push(&cmd.args, "--cleanup=verbatim");
if ((flags & ALLOW_EMPTY)) if ((flags & ALLOW_EMPTY))
argv_array_push(&cmd.args, "--allow-empty"); strvec_push(&cmd.args, "--allow-empty");
if (!(flags & EDIT_MSG)) if (!(flags & EDIT_MSG))
argv_array_push(&cmd.args, "--allow-empty-message"); strvec_push(&cmd.args, "--allow-empty-message");
if (is_rebase_i(opts) && !(flags & EDIT_MSG)) if (is_rebase_i(opts) && !(flags & EDIT_MSG))
return run_command_silent_on_success(&cmd); return run_command_silent_on_success(&cmd);
@ -2754,15 +2754,15 @@ static int rollback_is_safe(void)
static int reset_merge(const struct object_id *oid) static int reset_merge(const struct object_id *oid)
{ {
int ret; int ret;
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
argv_array_pushl(&argv, "reset", "--merge", NULL); strvec_pushl(&argv, "reset", "--merge", NULL);
if (!is_null_oid(oid)) if (!is_null_oid(oid))
argv_array_push(&argv, oid_to_hex(oid)); strvec_push(&argv, oid_to_hex(oid));
ret = run_command_v_opt(argv.argv, RUN_GIT_CMD); ret = run_command_v_opt(argv.v, RUN_GIT_CMD);
argv_array_clear(&argv); strvec_clear(&argv);
return ret; return ret;
} }
@ -3125,17 +3125,17 @@ static int error_failed_squash(struct repository *r,
static int do_exec(struct repository *r, const char *command_line) static int do_exec(struct repository *r, const char *command_line)
{ {
struct argv_array child_env = ARGV_ARRAY_INIT; struct strvec child_env = STRVEC_INIT;
const char *child_argv[] = { NULL, NULL }; const char *child_argv[] = { NULL, NULL };
int dirty, status; int dirty, status;
fprintf(stderr, _("Executing: %s\n"), command_line); fprintf(stderr, _("Executing: %s\n"), command_line);
child_argv[0] = command_line; child_argv[0] = command_line;
argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir())); strvec_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
argv_array_pushf(&child_env, "GIT_WORK_TREE=%s", strvec_pushf(&child_env, "GIT_WORK_TREE=%s",
absolute_path(get_git_work_tree())); absolute_path(get_git_work_tree()));
status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL, status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
child_env.argv); child_env.v);
/* force re-reading of the cache */ /* force re-reading of the cache */
if (discard_index(r->index) < 0 || repo_read_index(r) < 0) if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
@ -3165,7 +3165,7 @@ static int do_exec(struct repository *r, const char *command_line)
status = 1; status = 1;
} }
argv_array_clear(&child_env); strvec_clear(&child_env);
return status; return status;
} }
@ -3544,29 +3544,29 @@ static int do_merge(struct repository *r,
} }
cmd.git_cmd = 1; cmd.git_cmd = 1;
argv_array_push(&cmd.args, "merge"); strvec_push(&cmd.args, "merge");
argv_array_push(&cmd.args, "-s"); strvec_push(&cmd.args, "-s");
if (!strategy) if (!strategy)
argv_array_push(&cmd.args, "octopus"); strvec_push(&cmd.args, "octopus");
else { else {
argv_array_push(&cmd.args, strategy); strvec_push(&cmd.args, strategy);
for (k = 0; k < opts->xopts_nr; k++) for (k = 0; k < opts->xopts_nr; k++)
argv_array_pushf(&cmd.args, strvec_pushf(&cmd.args,
"-X%s", opts->xopts[k]); "-X%s", opts->xopts[k]);
} }
argv_array_push(&cmd.args, "--no-edit"); strvec_push(&cmd.args, "--no-edit");
argv_array_push(&cmd.args, "--no-ff"); strvec_push(&cmd.args, "--no-ff");
argv_array_push(&cmd.args, "--no-log"); strvec_push(&cmd.args, "--no-log");
argv_array_push(&cmd.args, "--no-stat"); strvec_push(&cmd.args, "--no-stat");
argv_array_push(&cmd.args, "-F"); strvec_push(&cmd.args, "-F");
argv_array_push(&cmd.args, git_path_merge_msg(r)); strvec_push(&cmd.args, git_path_merge_msg(r));
if (opts->gpg_sign) if (opts->gpg_sign)
argv_array_push(&cmd.args, opts->gpg_sign); strvec_push(&cmd.args, opts->gpg_sign);
/* Add the tips to be merged */ /* Add the tips to be merged */
for (j = to_merge; j; j = j->next) for (j = to_merge; j; j = j->next)
argv_array_push(&cmd.args, strvec_push(&cmd.args,
oid_to_hex(&j->item->object.oid)); oid_to_hex(&j->item->object.oid));
strbuf_release(&ref_name); strbuf_release(&ref_name);
unlink(git_path_cherry_pick_head(r)); unlink(git_path_cherry_pick_head(r));
@ -3694,8 +3694,8 @@ void create_autostash(struct repository *r, const char *path,
struct child_process stash = CHILD_PROCESS_INIT; struct child_process stash = CHILD_PROCESS_INIT;
struct object_id oid; struct object_id oid;
argv_array_pushl(&stash.args, strvec_pushl(&stash.args,
"stash", "create", "autostash", NULL); "stash", "create", "autostash", NULL);
stash.git_cmd = 1; stash.git_cmd = 1;
stash.no_stdin = 1; stash.no_stdin = 1;
strbuf_reset(&buf); strbuf_reset(&buf);
@ -3734,9 +3734,9 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
child.git_cmd = 1; child.git_cmd = 1;
child.no_stdout = 1; child.no_stdout = 1;
child.no_stderr = 1; child.no_stderr = 1;
argv_array_push(&child.args, "stash"); strvec_push(&child.args, "stash");
argv_array_push(&child.args, "apply"); strvec_push(&child.args, "apply");
argv_array_push(&child.args, stash_oid); strvec_push(&child.args, stash_oid);
ret = run_command(&child); ret = run_command(&child);
} }
@ -3746,12 +3746,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
struct child_process store = CHILD_PROCESS_INIT; struct child_process store = CHILD_PROCESS_INIT;
store.git_cmd = 1; store.git_cmd = 1;
argv_array_push(&store.args, "stash"); strvec_push(&store.args, "stash");
argv_array_push(&store.args, "store"); strvec_push(&store.args, "store");
argv_array_push(&store.args, "-m"); strvec_push(&store.args, "-m");
argv_array_push(&store.args, "autostash"); strvec_push(&store.args, "autostash");
argv_array_push(&store.args, "-q"); strvec_push(&store.args, "-q");
argv_array_push(&store.args, stash_oid); strvec_push(&store.args, stash_oid);
if (run_command(&store)) if (run_command(&store))
ret = error(_("cannot store %s"), stash_oid); ret = error(_("cannot store %s"), stash_oid);
else else
@ -3831,9 +3831,9 @@ static int run_git_checkout(struct repository *r, struct replay_opts *opts,
cmd.git_cmd = 1; cmd.git_cmd = 1;
argv_array_push(&cmd.args, "checkout"); strvec_push(&cmd.args, "checkout");
argv_array_push(&cmd.args, commit); strvec_push(&cmd.args, commit);
argv_array_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action); strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
if (opts->verbose) if (opts->verbose)
ret = run_command(&cmd); ret = run_command(&cmd);
@ -4157,9 +4157,9 @@ static int pick_commits(struct repository *r,
child.in = open(rebase_path_rewritten_list(), O_RDONLY); child.in = open(rebase_path_rewritten_list(), O_RDONLY);
child.git_cmd = 1; child.git_cmd = 1;
argv_array_push(&child.args, "notes"); strvec_push(&child.args, "notes");
argv_array_push(&child.args, "copy"); strvec_push(&child.args, "copy");
argv_array_push(&child.args, "--for-rewrite=rebase"); strvec_push(&child.args, "--for-rewrite=rebase");
/* we don't care if this copying failed */ /* we don't care if this copying failed */
run_command(&child); run_command(&child);
@ -4170,8 +4170,8 @@ static int pick_commits(struct repository *r,
O_RDONLY); O_RDONLY);
hook.stdout_to_stderr = 1; hook.stdout_to_stderr = 1;
hook.trace2_hook_name = "post-rewrite"; hook.trace2_hook_name = "post-rewrite";
argv_array_push(&hook.args, post_rewrite_hook); strvec_push(&hook.args, post_rewrite_hook);
argv_array_push(&hook.args, "rebase"); strvec_push(&hook.args, "rebase");
/* we don't care if this hook failed */ /* we don't care if this hook failed */
run_command(&hook); run_command(&hook);
} }

20
serve.c
View file

@ -3,7 +3,7 @@
#include "config.h" #include "config.h"
#include "pkt-line.h" #include "pkt-line.h"
#include "version.h" #include "version.h"
#include "argv-array.h" #include "strvec.h"
#include "ls-refs.h" #include "ls-refs.h"
#include "serve.h" #include "serve.h"
#include "upload-pack.h" #include "upload-pack.h"
@ -56,7 +56,7 @@ struct protocol_capability {
* This field should be NULL for capabilities which are not commands. * This field should be NULL for capabilities which are not commands.
*/ */
int (*command)(struct repository *r, int (*command)(struct repository *r,
struct argv_array *keys, struct strvec *keys,
struct packet_reader *request); struct packet_reader *request);
}; };
@ -142,13 +142,13 @@ static int is_command(const char *key, struct protocol_capability **command)
return 0; return 0;
} }
int has_capability(const struct argv_array *keys, const char *capability, int has_capability(const struct strvec *keys, const char *capability,
const char **value) const char **value)
{ {
int i; int i;
for (i = 0; i < keys->argc; i++) { for (i = 0; i < keys->nr; i++) {
const char *out; const char *out;
if (skip_prefix(keys->argv[i], capability, &out) && if (skip_prefix(keys->v[i], capability, &out) &&
(!*out || *out == '=')) { (!*out || *out == '=')) {
if (value) { if (value) {
if (*out == '=') if (*out == '=')
@ -162,7 +162,7 @@ int has_capability(const struct argv_array *keys, const char *capability,
return 0; return 0;
} }
static void check_algorithm(struct repository *r, struct argv_array *keys) static void check_algorithm(struct repository *r, struct strvec *keys)
{ {
int client = GIT_HASH_SHA1, server = hash_algo_by_ptr(r->hash_algo); int client = GIT_HASH_SHA1, server = hash_algo_by_ptr(r->hash_algo);
const char *algo_name; const char *algo_name;
@ -187,7 +187,7 @@ static int process_request(void)
{ {
enum request_state state = PROCESS_REQUEST_KEYS; enum request_state state = PROCESS_REQUEST_KEYS;
struct packet_reader reader; struct packet_reader reader;
struct argv_array keys = ARGV_ARRAY_INIT; struct strvec keys = STRVEC_INIT;
struct protocol_capability *command = NULL; struct protocol_capability *command = NULL;
packet_reader_init(&reader, 0, NULL, 0, packet_reader_init(&reader, 0, NULL, 0,
@ -211,7 +211,7 @@ static int process_request(void)
/* collect request; a sequence of keys and values */ /* collect request; a sequence of keys and values */
if (is_command(reader.line, &command) || if (is_command(reader.line, &command) ||
is_valid_capability(reader.line)) is_valid_capability(reader.line))
argv_array_push(&keys, reader.line); strvec_push(&keys, reader.line);
else else
die("unknown capability '%s'", reader.line); die("unknown capability '%s'", reader.line);
@ -223,7 +223,7 @@ static int process_request(void)
* If no command and no keys were given then the client * If no command and no keys were given then the client
* wanted to terminate the connection. * wanted to terminate the connection.
*/ */
if (!keys.argc) if (!keys.nr)
return 1; return 1;
/* /*
@ -254,7 +254,7 @@ static int process_request(void)
command->command(the_repository, &keys, &reader); command->command(the_repository, &keys, &reader);
argv_array_clear(&keys); strvec_clear(&keys);
return 0; return 0;
} }

View file

@ -1,8 +1,8 @@
#ifndef SERVE_H #ifndef SERVE_H
#define SERVE_H #define SERVE_H
struct argv_array; struct strvec;
int has_capability(const struct argv_array *keys, const char *capability, int has_capability(const struct strvec *keys, const char *capability,
const char **value); const char **value);
struct serve_options { struct serve_options {

View file

@ -763,18 +763,18 @@ static void fill_alternate_refs_command(struct child_process *cmd,
if (!git_config_get_value("core.alternateRefsCommand", &value)) { if (!git_config_get_value("core.alternateRefsCommand", &value)) {
cmd->use_shell = 1; cmd->use_shell = 1;
argv_array_push(&cmd->args, value); strvec_push(&cmd->args, value);
argv_array_push(&cmd->args, repo_path); strvec_push(&cmd->args, repo_path);
} else { } else {
cmd->git_cmd = 1; cmd->git_cmd = 1;
argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path); strvec_pushf(&cmd->args, "--git-dir=%s", repo_path);
argv_array_push(&cmd->args, "for-each-ref"); strvec_push(&cmd->args, "for-each-ref");
argv_array_push(&cmd->args, "--format=%(objectname)"); strvec_push(&cmd->args, "--format=%(objectname)");
if (!git_config_get_value("core.alternateRefsPrefixes", &value)) { if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
argv_array_push(&cmd->args, "--"); strvec_push(&cmd->args, "--");
argv_array_split(&cmd->args, value); strvec_split(&cmd->args, value);
} }
} }

109
strvec.c Normal file
View file

@ -0,0 +1,109 @@
#include "cache.h"
#include "strvec.h"
#include "strbuf.h"
const char *empty_strvec[] = { NULL };
void strvec_init(struct strvec *array)
{
array->v = empty_strvec;
array->nr = 0;
array->alloc = 0;
}
static void strvec_push_nodup(struct strvec *array, const char *value)
{
if (array->v == empty_strvec)
array->v = NULL;
ALLOC_GROW(array->v, array->nr + 2, array->alloc);
array->v[array->nr++] = value;
array->v[array->nr] = NULL;
}
const char *strvec_push(struct strvec *array, const char *value)
{
strvec_push_nodup(array, xstrdup(value));
return array->v[array->nr - 1];
}
const char *strvec_pushf(struct strvec *array, const char *fmt, ...)
{
va_list ap;
struct strbuf v = STRBUF_INIT;
va_start(ap, fmt);
strbuf_vaddf(&v, fmt, ap);
va_end(ap);
strvec_push_nodup(array, strbuf_detach(&v, NULL));
return array->v[array->nr - 1];
}
void strvec_pushl(struct strvec *array, ...)
{
va_list ap;
const char *arg;
va_start(ap, array);
while ((arg = va_arg(ap, const char *)))
strvec_push(array, arg);
va_end(ap);
}
void strvec_pushv(struct strvec *array, const char **items)
{
for (; *items; items++)
strvec_push(array, *items);
}
void strvec_pop(struct strvec *array)
{
if (!array->nr)
return;
free((char *)array->v[array->nr - 1]);
array->v[array->nr - 1] = NULL;
array->nr--;
}
void strvec_split(struct strvec *array, const char *to_split)
{
while (isspace(*to_split))
to_split++;
for (;;) {
const char *p = to_split;
if (!*p)
break;
while (*p && !isspace(*p))
p++;
strvec_push_nodup(array, xstrndup(to_split, p - to_split));
while (isspace(*p))
p++;
to_split = p;
}
}
void strvec_clear(struct strvec *array)
{
if (array->v != empty_strvec) {
int i;
for (i = 0; i < array->nr; i++)
free((char *)array->v[i]);
free(array->v);
}
strvec_init(array);
}
const char **strvec_detach(struct strvec *array)
{
if (array->v == empty_strvec)
return xcalloc(1, sizeof(const char *));
else {
const char **ret = array->v;
strvec_init(array);
return ret;
}
}

View file

@ -1,11 +1,11 @@
#ifndef ARGV_ARRAY_H #ifndef STRVEC_H
#define ARGV_ARRAY_H #define STRVEC_H
/** /**
* The argv-array API allows one to dynamically build and store * The strvec API allows one to dynamically build and store
* NULL-terminated lists. An argv-array maintains the invariant that the * NULL-terminated arrays of strings. A strvec maintains the invariant that the
* `argv` member always points to a non-NULL array, and that the array is * `items` member always points to a non-NULL array, and that the array is
* always NULL-terminated at the element pointed to by `argv[argc]`. This * always NULL-terminated at the element pointed to by `items[nr]`. This
* makes the result suitable for passing to functions expecting to receive * makes the result suitable for passing to functions expecting to receive
* argv from main(). * argv from main().
* *
@ -14,42 +14,42 @@
* it contains an item structure with a `util` field that is not compatible * it contains an item structure with a `util` field that is not compatible
* with the traditional argv interface. * with the traditional argv interface.
* *
* Each `argv_array` manages its own memory. Any strings pushed into the * Each `strvec` manages its own memory. Any strings pushed into the
* array are duplicated, and all memory is freed by argv_array_clear(). * array are duplicated, and all memory is freed by strvec_clear().
*/ */
extern const char *empty_argv[]; extern const char *empty_strvec[];
/** /**
* A single array. This should be initialized by assignment from * A single array. This should be initialized by assignment from
* `ARGV_ARRAY_INIT`, or by calling `argv_array_init`. The `argv` * `STRVEC_INIT`, or by calling `strvec_init`. The `items`
* member contains the actual array; the `argc` member contains the * member contains the actual array; the `nr` member contains the
* number of elements in the array, not including the terminating * number of elements in the array, not including the terminating
* NULL. * NULL.
*/ */
struct argv_array { struct strvec {
const char **argv; const char **v;
int argc; int nr;
int alloc; int alloc;
}; };
#define ARGV_ARRAY_INIT { empty_argv, 0, 0 } #define STRVEC_INIT { empty_strvec, 0, 0 }
/** /**
* Initialize an array. This is no different than assigning from * Initialize an array. This is no different than assigning from
* `ARGV_ARRAY_INIT`. * `STRVEC_INIT`.
*/ */
void argv_array_init(struct argv_array *); void strvec_init(struct strvec *);
/* Push a copy of a string onto the end of the array. */ /* Push a copy of a string onto the end of the array. */
const char *argv_array_push(struct argv_array *, const char *); const char *strvec_push(struct strvec *, const char *);
/** /**
* Format a string and push it onto the end of the array. This is a * Format a string and push it onto the end of the array. This is a
* convenience wrapper combining `strbuf_addf` and `argv_array_push`. * convenience wrapper combining `strbuf_addf` and `strvec_push`.
*/ */
__attribute__((format (printf,2,3))) __attribute__((format (printf,2,3)))
const char *argv_array_pushf(struct argv_array *, const char *fmt, ...); const char *strvec_pushf(struct strvec *, const char *fmt, ...);
/** /**
* Push a list of strings onto the end of the array. The arguments * Push a list of strings onto the end of the array. The arguments
@ -57,33 +57,33 @@ const char *argv_array_pushf(struct argv_array *, const char *fmt, ...);
* argument. * argument.
*/ */
LAST_ARG_MUST_BE_NULL LAST_ARG_MUST_BE_NULL
void argv_array_pushl(struct argv_array *, ...); void strvec_pushl(struct strvec *, ...);
/* Push a null-terminated array of strings onto the end of the array. */ /* Push a null-terminated array of strings onto the end of the array. */
void argv_array_pushv(struct argv_array *, const char **); void strvec_pushv(struct strvec *, const char **);
/** /**
* Remove the final element from the array. If there are no * Remove the final element from the array. If there are no
* elements in the array, do nothing. * elements in the array, do nothing.
*/ */
void argv_array_pop(struct argv_array *); void strvec_pop(struct strvec *);
/* Splits by whitespace; does not handle quoted arguments! */ /* Splits by whitespace; does not handle quoted arguments! */
void argv_array_split(struct argv_array *, const char *); void strvec_split(struct strvec *, const char *);
/** /**
* Free all memory associated with the array and return it to the * Free all memory associated with the array and return it to the
* initial, empty state. * initial, empty state.
*/ */
void argv_array_clear(struct argv_array *); void strvec_clear(struct strvec *);
/** /**
* Disconnect the `argv` member from the `argv_array` struct and * Disconnect the `items` member from the `strvec` struct and
* return it. The caller is responsible for freeing the memory used * return it. The caller is responsible for freeing the memory used
* by the array, and by the strings it references. After detaching, * by the array, and by the strings it references. After detaching,
* the `argv_array` is in a reinitialized state and can be pushed * the `strvec` is in a reinitialized state and can be pushed
* into again. * into again.
*/ */
const char **argv_array_detach(struct argv_array *); const char **strvec_detach(struct strvec *);
#endif /* ARGV_ARRAY_H */ #endif /* STRVEC_H */

View file

@ -84,7 +84,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
process = &entry->process; process = &entry->process;
child_process_init(process); child_process_init(process);
argv_array_push(&process->args, cmd); strvec_push(&process->args, cmd);
process->use_shell = 1; process->use_shell = 1;
process->in = -1; process->in = -1;
process->out = -1; process->out = -1;

View file

@ -13,7 +13,7 @@
#include "refs.h" #include "refs.h"
#include "string-list.h" #include "string-list.h"
#include "oid-array.h" #include "oid-array.h"
#include "argv-array.h" #include "strvec.h"
#include "blob.h" #include "blob.h"
#include "thread-utils.h" #include "thread-utils.h"
#include "quote.h" #include "quote.h"
@ -262,17 +262,17 @@ int is_submodule_active(struct repository *repo, const char *path)
sl = repo_config_get_value_multi(repo, "submodule.active"); sl = repo_config_get_value_multi(repo, "submodule.active");
if (sl) { if (sl) {
struct pathspec ps; struct pathspec ps;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
const struct string_list_item *item; const struct string_list_item *item;
for_each_string_list_item(item, sl) { for_each_string_list_item(item, sl) {
argv_array_push(&args, item->string); strvec_push(&args, item->string);
} }
parse_pathspec(&ps, 0, 0, NULL, args.argv); parse_pathspec(&ps, 0, 0, NULL, args.v);
ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1); ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1);
argv_array_clear(&args); strvec_clear(&args);
clear_pathspec(&ps); clear_pathspec(&ps);
return ret; return ret;
} }
@ -481,27 +481,27 @@ static void print_submodule_summary(struct repository *r, struct rev_info *rev,
strbuf_release(&sb); strbuf_release(&sb);
} }
static void prepare_submodule_repo_env_no_git_dir(struct argv_array *out) static void prepare_submodule_repo_env_no_git_dir(struct strvec *out)
{ {
const char * const *var; const char * const *var;
for (var = local_repo_env; *var; var++) { for (var = local_repo_env; *var; var++) {
if (strcmp(*var, CONFIG_DATA_ENVIRONMENT)) if (strcmp(*var, CONFIG_DATA_ENVIRONMENT))
argv_array_push(out, *var); strvec_push(out, *var);
} }
} }
void prepare_submodule_repo_env(struct argv_array *out) void prepare_submodule_repo_env(struct strvec *out)
{ {
prepare_submodule_repo_env_no_git_dir(out); prepare_submodule_repo_env_no_git_dir(out);
argv_array_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT, strvec_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT,
DEFAULT_GIT_DIR_ENVIRONMENT); DEFAULT_GIT_DIR_ENVIRONMENT);
} }
static void prepare_submodule_repo_env_in_gitdir(struct argv_array *out) static void prepare_submodule_repo_env_in_gitdir(struct strvec *out)
{ {
prepare_submodule_repo_env_no_git_dir(out); prepare_submodule_repo_env_no_git_dir(out);
argv_array_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT); strvec_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT);
} }
/* /*
@ -681,22 +681,22 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
cp.no_stdin = 1; cp.no_stdin = 1;
/* TODO: other options may need to be passed here. */ /* TODO: other options may need to be passed here. */
argv_array_pushl(&cp.args, "diff", "--submodule=diff", NULL); strvec_pushl(&cp.args, "diff", "--submodule=diff", NULL);
argv_array_pushf(&cp.args, "--color=%s", want_color(o->use_color) ? strvec_pushf(&cp.args, "--color=%s", want_color(o->use_color) ?
"always" : "never"); "always" : "never");
if (o->flags.reverse_diff) { if (o->flags.reverse_diff) {
argv_array_pushf(&cp.args, "--src-prefix=%s%s/", strvec_pushf(&cp.args, "--src-prefix=%s%s/",
o->b_prefix, path); o->b_prefix, path);
argv_array_pushf(&cp.args, "--dst-prefix=%s%s/", strvec_pushf(&cp.args, "--dst-prefix=%s%s/",
o->a_prefix, path); o->a_prefix, path);
} else { } else {
argv_array_pushf(&cp.args, "--src-prefix=%s%s/", strvec_pushf(&cp.args, "--src-prefix=%s%s/",
o->a_prefix, path); o->a_prefix, path);
argv_array_pushf(&cp.args, "--dst-prefix=%s%s/", strvec_pushf(&cp.args, "--dst-prefix=%s%s/",
o->b_prefix, path); o->b_prefix, path);
} }
argv_array_push(&cp.args, oid_to_hex(old_oid)); strvec_push(&cp.args, oid_to_hex(old_oid));
/* /*
* If the submodule has modified content, we will diff against the * If the submodule has modified content, we will diff against the
* work tree, under the assumption that the user has asked for the * work tree, under the assumption that the user has asked for the
@ -704,7 +704,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
* haven't yet been committed to the submodule yet. * haven't yet been committed to the submodule yet.
*/ */
if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED)) if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED))
argv_array_push(&cp.args, oid_to_hex(new_oid)); strvec_push(&cp.args, oid_to_hex(new_oid));
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
if (start_command(&cp)) if (start_command(&cp))
@ -836,13 +836,13 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
*/ */
static void collect_changed_submodules(struct repository *r, static void collect_changed_submodules(struct repository *r,
struct string_list *changed, struct string_list *changed,
struct argv_array *argv) struct strvec *argv)
{ {
struct rev_info rev; struct rev_info rev;
const struct commit *commit; const struct commit *commit;
repo_init_revisions(r, &rev, NULL); repo_init_revisions(r, &rev, NULL);
setup_revisions(argv->argc, argv->argv, &rev, NULL); setup_revisions(argv->nr, argv->v, &rev, NULL);
if (prepare_revision_walk(&rev)) if (prepare_revision_walk(&rev))
die(_("revision walk setup failed")); die(_("revision walk setup failed"));
@ -879,8 +879,8 @@ static int has_remote(const char *refname, const struct object_id *oid,
static int append_oid_to_argv(const struct object_id *oid, void *data) static int append_oid_to_argv(const struct object_id *oid, void *data)
{ {
struct argv_array *argv = data; struct strvec *argv = data;
argv_array_push(argv, oid_to_hex(oid)); strvec_push(argv, oid_to_hex(oid));
return 0; return 0;
} }
@ -941,9 +941,9 @@ static int submodule_has_commits(struct repository *r,
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf out = STRBUF_INIT; struct strbuf out = STRBUF_INIT;
argv_array_pushl(&cp.args, "rev-list", "-n", "1", NULL); strvec_pushl(&cp.args, "rev-list", "-n", "1", NULL);
oid_array_for_each_unique(commits, append_oid_to_argv, &cp.args); oid_array_for_each_unique(commits, append_oid_to_argv, &cp.args);
argv_array_pushl(&cp.args, "--not", "--all", NULL); strvec_pushl(&cp.args, "--not", "--all", NULL);
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
@ -982,9 +982,9 @@ static int submodule_needs_pushing(struct repository *r,
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
int needs_pushing = 0; int needs_pushing = 0;
argv_array_push(&cp.args, "rev-list"); strvec_push(&cp.args, "rev-list");
oid_array_for_each_unique(commits, append_oid_to_argv, &cp.args); oid_array_for_each_unique(commits, append_oid_to_argv, &cp.args);
argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL); strvec_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL);
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
@ -1012,13 +1012,13 @@ int find_unpushed_submodules(struct repository *r,
{ {
struct string_list submodules = STRING_LIST_INIT_DUP; struct string_list submodules = STRING_LIST_INIT_DUP;
struct string_list_item *name; struct string_list_item *name;
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
/* argv.argv[0] will be ignored by setup_revisions */ /* argv.v[0] will be ignored by setup_revisions */
argv_array_push(&argv, "find_unpushed_submodules"); strvec_push(&argv, "find_unpushed_submodules");
oid_array_for_each_unique(commits, append_oid_to_argv, &argv); oid_array_for_each_unique(commits, append_oid_to_argv, &argv);
argv_array_push(&argv, "--not"); strvec_push(&argv, "--not");
argv_array_pushf(&argv, "--remotes=%s", remotes_name); strvec_pushf(&argv, "--remotes=%s", remotes_name);
collect_changed_submodules(r, &submodules, &argv); collect_changed_submodules(r, &submodules, &argv);
@ -1041,7 +1041,7 @@ int find_unpushed_submodules(struct repository *r,
} }
free_submodules_oids(&submodules); free_submodules_oids(&submodules);
argv_array_clear(&argv); strvec_clear(&argv);
return needs_pushing->nr; return needs_pushing->nr;
} }
@ -1054,22 +1054,22 @@ static int push_submodule(const char *path,
{ {
if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
argv_array_push(&cp.args, "push"); strvec_push(&cp.args, "push");
if (dry_run) if (dry_run)
argv_array_push(&cp.args, "--dry-run"); strvec_push(&cp.args, "--dry-run");
if (push_options && push_options->nr) { if (push_options && push_options->nr) {
const struct string_list_item *item; const struct string_list_item *item;
for_each_string_list_item(item, push_options) for_each_string_list_item(item, push_options)
argv_array_pushf(&cp.args, "--push-option=%s", strvec_pushf(&cp.args, "--push-option=%s",
item->string); item->string);
} }
if (remote->origin != REMOTE_UNCONFIGURED) { if (remote->origin != REMOTE_UNCONFIGURED) {
int i; int i;
argv_array_push(&cp.args, remote->name); strvec_push(&cp.args, remote->name);
for (i = 0; i < rs->raw_nr; i++) for (i = 0; i < rs->raw_nr; i++)
argv_array_push(&cp.args, rs->raw[i]); strvec_push(&cp.args, rs->raw[i]);
} }
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
@ -1095,13 +1095,13 @@ static void submodule_push_check(const char *path, const char *head,
struct child_process cp = CHILD_PROCESS_INIT; struct child_process cp = CHILD_PROCESS_INIT;
int i; int i;
argv_array_push(&cp.args, "submodule--helper"); strvec_push(&cp.args, "submodule--helper");
argv_array_push(&cp.args, "push-check"); strvec_push(&cp.args, "push-check");
argv_array_push(&cp.args, head); strvec_push(&cp.args, head);
argv_array_push(&cp.args, remote->name); strvec_push(&cp.args, remote->name);
for (i = 0; i < rs->raw_nr; i++) for (i = 0; i < rs->raw_nr; i++)
argv_array_push(&cp.args, rs->raw[i]); strvec_push(&cp.args, rs->raw[i]);
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
@ -1189,17 +1189,17 @@ void check_for_new_submodule_commits(struct object_id *oid)
static void calculate_changed_submodule_paths(struct repository *r, static void calculate_changed_submodule_paths(struct repository *r,
struct string_list *changed_submodule_names) struct string_list *changed_submodule_names)
{ {
struct argv_array argv = ARGV_ARRAY_INIT; struct strvec argv = STRVEC_INIT;
struct string_list_item *name; struct string_list_item *name;
/* No need to check if there are no submodules configured */ /* No need to check if there are no submodules configured */
if (!submodule_from_path(r, NULL, NULL)) if (!submodule_from_path(r, NULL, NULL))
return; return;
argv_array_push(&argv, "--"); /* argv[0] program name */ strvec_push(&argv, "--"); /* argv[0] program name */
oid_array_for_each_unique(&ref_tips_after_fetch, oid_array_for_each_unique(&ref_tips_after_fetch,
append_oid_to_argv, &argv); append_oid_to_argv, &argv);
argv_array_push(&argv, "--not"); strvec_push(&argv, "--not");
oid_array_for_each_unique(&ref_tips_before_fetch, oid_array_for_each_unique(&ref_tips_before_fetch,
append_oid_to_argv, &argv); append_oid_to_argv, &argv);
@ -1231,7 +1231,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
string_list_remove_empty_items(changed_submodule_names, 1); string_list_remove_empty_items(changed_submodule_names, 1);
argv_array_clear(&argv); strvec_clear(&argv);
oid_array_clear(&ref_tips_before_fetch); oid_array_clear(&ref_tips_before_fetch);
oid_array_clear(&ref_tips_after_fetch); oid_array_clear(&ref_tips_after_fetch);
initialized_fetch_ref_tips = 0; initialized_fetch_ref_tips = 0;
@ -1242,24 +1242,24 @@ int submodule_touches_in_range(struct repository *r,
struct object_id *incl_oid) struct object_id *incl_oid)
{ {
struct string_list subs = STRING_LIST_INIT_DUP; struct string_list subs = STRING_LIST_INIT_DUP;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
int ret; int ret;
/* No need to check if there are no submodules configured */ /* No need to check if there are no submodules configured */
if (!submodule_from_path(r, NULL, NULL)) if (!submodule_from_path(r, NULL, NULL))
return 0; return 0;
argv_array_push(&args, "--"); /* args[0] program name */ strvec_push(&args, "--"); /* args[0] program name */
argv_array_push(&args, oid_to_hex(incl_oid)); strvec_push(&args, oid_to_hex(incl_oid));
if (!is_null_oid(excl_oid)) { if (!is_null_oid(excl_oid)) {
argv_array_push(&args, "--not"); strvec_push(&args, "--not");
argv_array_push(&args, oid_to_hex(excl_oid)); strvec_push(&args, oid_to_hex(excl_oid));
} }
collect_changed_submodules(r, &subs, &args); collect_changed_submodules(r, &subs, &args);
ret = subs.nr; ret = subs.nr;
argv_array_clear(&args); strvec_clear(&args);
free_submodules_oids(&subs); free_submodules_oids(&subs);
return ret; return ret;
@ -1267,7 +1267,7 @@ int submodule_touches_in_range(struct repository *r,
struct submodule_parallel_fetch { struct submodule_parallel_fetch {
int count; int count;
struct argv_array args; struct strvec args;
struct repository *r; struct repository *r;
const char *prefix; const char *prefix;
int command_line_option; int command_line_option;
@ -1283,7 +1283,7 @@ struct submodule_parallel_fetch {
struct strbuf submodules_with_errors; struct strbuf submodules_with_errors;
}; };
#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0, \ #define SPF_INIT {0, STRVEC_INIT, NULL, NULL, 0, 0, 0, 0, \
STRING_LIST_INIT_DUP, \ STRING_LIST_INIT_DUP, \
NULL, 0, 0, STRBUF_INIT} NULL, 0, 0, STRBUF_INIT}
@ -1452,15 +1452,15 @@ static int get_next_submodule(struct child_process *cp,
if (!spf->quiet) if (!spf->quiet)
strbuf_addf(err, _("Fetching submodule %s%s\n"), strbuf_addf(err, _("Fetching submodule %s%s\n"),
spf->prefix, ce->name); spf->prefix, ce->name);
argv_array_init(&cp->args); strvec_init(&cp->args);
argv_array_pushv(&cp->args, spf->args.argv); strvec_pushv(&cp->args, spf->args.v);
argv_array_push(&cp->args, default_argv); strvec_push(&cp->args, default_argv);
argv_array_push(&cp->args, "--submodule-prefix"); strvec_push(&cp->args, "--submodule-prefix");
strbuf_addf(&submodule_prefix, "%s%s/", strbuf_addf(&submodule_prefix, "%s%s/",
spf->prefix, spf->prefix,
task->sub->path); task->sub->path);
argv_array_push(&cp->args, submodule_prefix.buf); strvec_push(&cp->args, submodule_prefix.buf);
spf->count++; spf->count++;
*task_cb = task; *task_cb = task;
@ -1500,14 +1500,14 @@ static int get_next_submodule(struct child_process *cp,
cp->git_cmd = 1; cp->git_cmd = 1;
cp->dir = task->repo->gitdir; cp->dir = task->repo->gitdir;
argv_array_init(&cp->args); strvec_init(&cp->args);
argv_array_pushv(&cp->args, spf->args.argv); strvec_pushv(&cp->args, spf->args.v);
argv_array_push(&cp->args, "on-demand"); strvec_push(&cp->args, "on-demand");
argv_array_push(&cp->args, "--submodule-prefix"); strvec_push(&cp->args, "--submodule-prefix");
argv_array_push(&cp->args, submodule_prefix.buf); strvec_push(&cp->args, submodule_prefix.buf);
/* NEEDSWORK: have get_default_remote from submodule--helper */ /* NEEDSWORK: have get_default_remote from submodule--helper */
argv_array_push(&cp->args, "origin"); strvec_push(&cp->args, "origin");
oid_array_for_each_unique(task->commits, oid_array_for_each_unique(task->commits,
append_oid_to_argv, &cp->args); append_oid_to_argv, &cp->args);
@ -1598,7 +1598,7 @@ static int fetch_finish(int retvalue, struct strbuf *err,
} }
int fetch_populated_submodules(struct repository *r, int fetch_populated_submodules(struct repository *r,
const struct argv_array *options, const struct strvec *options,
const char *prefix, int command_line_option, const char *prefix, int command_line_option,
int default_option, int default_option,
int quiet, int max_parallel_jobs) int quiet, int max_parallel_jobs)
@ -1618,10 +1618,10 @@ int fetch_populated_submodules(struct repository *r,
if (repo_read_index(r) < 0) if (repo_read_index(r) < 0)
die(_("index file corrupt")); die(_("index file corrupt"));
argv_array_push(&spf.args, "fetch"); strvec_push(&spf.args, "fetch");
for (i = 0; i < options->argc; i++) for (i = 0; i < options->nr; i++)
argv_array_push(&spf.args, options->argv[i]); strvec_push(&spf.args, options->v[i]);
argv_array_push(&spf.args, "--recurse-submodules-default"); strvec_push(&spf.args, "--recurse-submodules-default");
/* default value, "--submodule-prefix" and its value are added later */ /* default value, "--submodule-prefix" and its value are added later */
calculate_changed_submodule_paths(r, &spf.changed_submodule_names); calculate_changed_submodule_paths(r, &spf.changed_submodule_names);
@ -1638,7 +1638,7 @@ int fetch_populated_submodules(struct repository *r,
spf.submodules_with_errors.buf); spf.submodules_with_errors.buf);
argv_array_clear(&spf.args); strvec_clear(&spf.args);
out: out:
free_submodules_oids(&spf.changed_submodule_names); free_submodules_oids(&spf.changed_submodule_names);
return spf.result; return spf.result;
@ -1666,9 +1666,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
} }
strbuf_reset(&buf); strbuf_reset(&buf);
argv_array_pushl(&cp.args, "status", "--porcelain=2", NULL); strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
if (ignore_untracked) if (ignore_untracked)
argv_array_push(&cp.args, "-uno"); strvec_push(&cp.args, "-uno");
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
@ -1779,16 +1779,16 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
if (!submodule_uses_gitfile(path)) if (!submodule_uses_gitfile(path))
return 1; return 1;
argv_array_pushl(&cp.args, "status", "--porcelain", strvec_pushl(&cp.args, "status", "--porcelain",
"--ignore-submodules=none", NULL); "--ignore-submodules=none", NULL);
if (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) if (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED)
argv_array_push(&cp.args, "-uno"); strvec_push(&cp.args, "-uno");
else else
argv_array_push(&cp.args, "-uall"); strvec_push(&cp.args, "-uall");
if (!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)) if (!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED))
argv_array_push(&cp.args, "--ignored"); strvec_push(&cp.args, "--ignored");
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
@ -1846,8 +1846,8 @@ static int submodule_has_dirty_index(const struct submodule *sub)
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1; cp.git_cmd = 1;
argv_array_pushl(&cp.args, "diff-index", "--quiet", strvec_pushl(&cp.args, "diff-index", "--quiet",
"--cached", "HEAD", NULL); "--cached", "HEAD", NULL);
cp.no_stdin = 1; cp.no_stdin = 1;
cp.no_stdout = 1; cp.no_stdout = 1;
cp.dir = sub->path; cp.dir = sub->path;
@ -1866,11 +1866,11 @@ static void submodule_reset_index(const char *path)
cp.no_stdin = 1; cp.no_stdin = 1;
cp.dir = path; cp.dir = path;
argv_array_pushf(&cp.args, "--super-prefix=%s%s/", strvec_pushf(&cp.args, "--super-prefix=%s%s/",
get_super_prefix_or_empty(), path); get_super_prefix_or_empty(), path);
argv_array_pushl(&cp.args, "read-tree", "-u", "--reset", NULL); strvec_pushl(&cp.args, "read-tree", "-u", "--reset", NULL);
argv_array_push(&cp.args, empty_tree_oid_hex()); strvec_push(&cp.args, empty_tree_oid_hex());
if (run_command(&cp)) if (run_command(&cp))
die(_("could not reset submodule index")); die(_("could not reset submodule index"));
@ -1947,24 +1947,24 @@ int submodule_move_head(const char *path,
cp.no_stdin = 1; cp.no_stdin = 1;
cp.dir = path; cp.dir = path;
argv_array_pushf(&cp.args, "--super-prefix=%s%s/", strvec_pushf(&cp.args, "--super-prefix=%s%s/",
get_super_prefix_or_empty(), path); get_super_prefix_or_empty(), path);
argv_array_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL); strvec_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL);
if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN) if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN)
argv_array_push(&cp.args, "-n"); strvec_push(&cp.args, "-n");
else else
argv_array_push(&cp.args, "-u"); strvec_push(&cp.args, "-u");
if (flags & SUBMODULE_MOVE_HEAD_FORCE) if (flags & SUBMODULE_MOVE_HEAD_FORCE)
argv_array_push(&cp.args, "--reset"); strvec_push(&cp.args, "--reset");
else else
argv_array_push(&cp.args, "-m"); strvec_push(&cp.args, "-m");
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE)) if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
argv_array_push(&cp.args, old_head ? old_head : empty_tree_oid_hex()); strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
argv_array_push(&cp.args, new_head ? new_head : empty_tree_oid_hex()); strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
if (run_command(&cp)) { if (run_command(&cp)) {
ret = error(_("Submodule '%s' could not be updated."), path); ret = error(_("Submodule '%s' could not be updated."), path);
@ -1980,8 +1980,8 @@ int submodule_move_head(const char *path,
cp.dir = path; cp.dir = path;
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
argv_array_pushl(&cp.args, "update-ref", "HEAD", strvec_pushl(&cp.args, "update-ref", "HEAD",
"--no-deref", new_head, NULL); "--no-deref", new_head, NULL);
if (run_command(&cp)) { if (run_command(&cp)) {
ret = -1; ret = -1;
@ -2157,9 +2157,9 @@ void absorb_git_dir_into_superproject(const char *path,
cp.dir = path; cp.dir = path;
cp.git_cmd = 1; cp.git_cmd = 1;
cp.no_stdin = 1; cp.no_stdin = 1;
argv_array_pushl(&cp.args, "--super-prefix", sb.buf, strvec_pushl(&cp.args, "--super-prefix", sb.buf,
"submodule--helper", "submodule--helper",
"absorb-git-dirs", NULL); "absorb-git-dirs", NULL);
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
if (run_command(&cp)) if (run_command(&cp))
die(_("could not recurse into submodule '%s'"), path); die(_("could not recurse into submodule '%s'"), path);
@ -2194,11 +2194,11 @@ int get_superproject_working_tree(struct strbuf *buf)
strbuf_release(&one_up); strbuf_release(&one_up);
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
argv_array_pop(&cp.env_array); strvec_pop(&cp.env_array);
argv_array_pushl(&cp.args, "--literal-pathspecs", "-C", "..", strvec_pushl(&cp.args, "--literal-pathspecs", "-C", "..",
"ls-files", "-z", "--stage", "--full-name", "--", "ls-files", "-z", "--stage", "--full-name", "--",
subpath, NULL); subpath, NULL);
strbuf_reset(&sb); strbuf_reset(&sb);
cp.no_stdin = 1; cp.no_stdin = 1;

View file

@ -1,7 +1,7 @@
#ifndef SUBMODULE_H #ifndef SUBMODULE_H
#define SUBMODULE_H #define SUBMODULE_H
struct argv_array; struct strvec;
struct cache_entry; struct cache_entry;
struct diff_options; struct diff_options;
struct index_state; struct index_state;
@ -84,7 +84,7 @@ int should_update_submodules(void);
const struct submodule *submodule_from_ce(const struct cache_entry *ce); const struct submodule *submodule_from_ce(const struct cache_entry *ce);
void check_for_new_submodule_commits(struct object_id *oid); void check_for_new_submodule_commits(struct object_id *oid);
int fetch_populated_submodules(struct repository *r, int fetch_populated_submodules(struct repository *r,
const struct argv_array *options, const struct strvec *options,
const char *prefix, const char *prefix,
int command_line_option, int command_line_option,
int default_option, int default_option,
@ -143,7 +143,7 @@ void submodule_unset_core_worktree(const struct submodule *sub);
* a submodule by clearing any repo-specific environment variables, but * a submodule by clearing any repo-specific environment variables, but
* retaining any config in the environment. * retaining any config in the environment.
*/ */
void prepare_submodule_repo_env(struct argv_array *out); void prepare_submodule_repo_env(struct strvec *out);
#define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0) #define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0)
void absorb_git_dir_into_superproject(const char *path, void absorb_git_dir_into_superproject(const char *path,

View file

@ -12,7 +12,7 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "cache.h" #include "cache.h"
#include "run-command.h" #include "run-command.h"
#include "argv-array.h" #include "strvec.h"
#include "strbuf.h" #include "strbuf.h"
#include "parse-options.h" #include "parse-options.h"
#include "string-list.h" #include "string-list.h"
@ -31,7 +31,7 @@ static int parallel_next(struct child_process *cp,
if (number_callbacks >= 4) if (number_callbacks >= 4)
return 0; return 0;
argv_array_pushv(&cp->args, d->argv); strvec_pushv(&cp->args, d->argv);
strbuf_addstr(err, "preloaded output of a child\n"); strbuf_addstr(err, "preloaded output of a child\n");
number_callbacks++; number_callbacks++;
return 1; return 1;
@ -72,19 +72,19 @@ static int next_test(struct child_process *cp, struct strbuf *err, void *cb,
return 0; return 0;
test = suite->tests.items[suite->next++].string; test = suite->tests.items[suite->next++].string;
argv_array_pushl(&cp->args, "sh", test, NULL); strvec_pushl(&cp->args, "sh", test, NULL);
if (suite->quiet) if (suite->quiet)
argv_array_push(&cp->args, "--quiet"); strvec_push(&cp->args, "--quiet");
if (suite->immediate) if (suite->immediate)
argv_array_push(&cp->args, "-i"); strvec_push(&cp->args, "-i");
if (suite->verbose) if (suite->verbose)
argv_array_push(&cp->args, "-v"); strvec_push(&cp->args, "-v");
if (suite->verbose_log) if (suite->verbose_log)
argv_array_push(&cp->args, "-V"); strvec_push(&cp->args, "-V");
if (suite->trace) if (suite->trace)
argv_array_push(&cp->args, "-x"); strvec_push(&cp->args, "-x");
if (suite->write_junit_xml) if (suite->write_junit_xml)
argv_array_push(&cp->args, "--write-junit-xml"); strvec_push(&cp->args, "--write-junit-xml");
strbuf_addf(err, "Output of '%s':\n", test); strbuf_addf(err, "Output of '%s':\n", test);
*task_cb = (void *)test; *task_cb = (void *)test;
@ -220,7 +220,7 @@ static int quote_stress_test(int argc, const char **argv)
char special[] = ".?*\\^_\"'`{}()[]<>@~&+:;$%"; // \t\r\n\a"; char special[] = ".?*\\^_\"'`{}()[]<>@~&+:;$%"; // \t\r\n\a";
int i, j, k, trials = 100, skip = 0, msys2 = 0; int i, j, k, trials = 100, skip = 0, msys2 = 0;
struct strbuf out = STRBUF_INIT; struct strbuf out = STRBUF_INIT;
struct argv_array args = ARGV_ARRAY_INIT; struct strvec args = STRVEC_INIT;
struct option options[] = { struct option options[] = {
OPT_INTEGER('n', "trials", &trials, "Number of trials"), OPT_INTEGER('n', "trials", &trials, "Number of trials"),
OPT_INTEGER('s', "skip", &skip, "Skip <n> trials"), OPT_INTEGER('s', "skip", &skip, "Skip <n> trials"),
@ -241,20 +241,20 @@ static int quote_stress_test(int argc, const char **argv)
size_t arg_count, arg_offset; size_t arg_count, arg_offset;
int ret = 0; int ret = 0;
argv_array_clear(&args); strvec_clear(&args);
if (msys2) if (msys2)
argv_array_pushl(&args, "sh", "-c", strvec_pushl(&args, "sh", "-c",
"printf %s\\\\0 \"$@\"", "skip", NULL); "printf %s\\\\0 \"$@\"", "skip", NULL);
else else
argv_array_pushl(&args, "test-tool", "run-command", strvec_pushl(&args, "test-tool", "run-command",
"quote-echo", NULL); "quote-echo", NULL);
arg_offset = args.argc; arg_offset = args.nr;
if (argc > 0) { if (argc > 0) {
trials = 1; trials = 1;
arg_count = argc; arg_count = argc;
for (j = 0; j < arg_count; j++) for (j = 0; j < arg_count; j++)
argv_array_push(&args, argv[j]); strvec_push(&args, argv[j]);
} else { } else {
arg_count = 1 + (my_random() % 5); arg_count = 1 + (my_random() % 5);
for (j = 0; j < arg_count; j++) { for (j = 0; j < arg_count; j++) {
@ -268,20 +268,20 @@ static int quote_stress_test(int argc, const char **argv)
ARRAY_SIZE(special)]; ARRAY_SIZE(special)];
buf[arg_len] = '\0'; buf[arg_len] = '\0';
argv_array_push(&args, buf); strvec_push(&args, buf);
} }
} }
if (i < skip) if (i < skip)
continue; continue;
cp.argv = args.argv; cp.argv = args.v;
strbuf_reset(&out); strbuf_reset(&out);
if (pipe_command(&cp, NULL, 0, &out, 0, NULL, 0) < 0) if (pipe_command(&cp, NULL, 0, &out, 0, NULL, 0) < 0)
return error("Failed to spawn child process"); return error("Failed to spawn child process");
for (j = 0, k = 0; j < arg_count; j++) { for (j = 0, k = 0; j < arg_count; j++) {
const char *arg = args.argv[j + arg_offset]; const char *arg = args.v[j + arg_offset];
if (strcmp(arg, out.buf + k)) if (strcmp(arg, out.buf + k))
ret = error("incorrectly quoted arg: '%s', " ret = error("incorrectly quoted arg: '%s', "
@ -298,10 +298,10 @@ static int quote_stress_test(int argc, const char **argv)
fprintf(stderr, "Trial #%d failed. Arguments:\n", i); fprintf(stderr, "Trial #%d failed. Arguments:\n", i);
for (j = 0; j < arg_count; j++) for (j = 0; j < arg_count; j++)
fprintf(stderr, "arg #%d: '%s'\n", fprintf(stderr, "arg #%d: '%s'\n",
(int)j, args.argv[j + arg_offset]); (int)j, args.v[j + arg_offset]);
strbuf_release(&out); strbuf_release(&out);
argv_array_clear(&args); strvec_clear(&args);
return ret; return ret;
} }
@ -311,7 +311,7 @@ static int quote_stress_test(int argc, const char **argv)
} }
strbuf_release(&out); strbuf_release(&out);
argv_array_clear(&args); strvec_clear(&args);
return 0; return 0;
} }
@ -338,8 +338,8 @@ static int inherit_handle(const char *argv0)
xsnprintf(path, sizeof(path), "out-XXXXXX"); xsnprintf(path, sizeof(path), "out-XXXXXX");
tmp = xmkstemp(path); tmp = xmkstemp(path);
argv_array_pushl(&cp.args, strvec_pushl(&cp.args,
"test-tool", argv0, "inherited-handle-child", NULL); "test-tool", argv0, "inherited-handle-child", NULL);
cp.in = -1; cp.in = -1;
cp.no_stdout = cp.no_stderr = 1; cp.no_stdout = cp.no_stderr = 1;
if (start_command(&cp) < 0) if (start_command(&cp) < 0)
@ -391,7 +391,7 @@ int cmd__run_command(int argc, const char **argv)
while (!strcmp(argv[1], "env")) { while (!strcmp(argv[1], "env")) {
if (!argv[2]) if (!argv[2])
die("env specifier without a value"); die("env specifier without a value");
argv_array_push(&proc.env_array, argv[2]); strvec_push(&proc.env_array, argv[2]);
argv += 2; argv += 2;
argc -= 2; argc -= 2;
} }

View file

@ -1,6 +1,6 @@
#include "test-tool.h" #include "test-tool.h"
#include "cache.h" #include "cache.h"
#include "argv-array.h" #include "strvec.h"
#include "run-command.h" #include "run-command.h"
#include "exec-cmd.h" #include "exec-cmd.h"
#include "config.h" #include "config.h"

View file

@ -4,13 +4,13 @@
#include "sigchain.h" #include "sigchain.h"
#include "string-list.h" #include "string-list.h"
#include "strbuf.h" #include "strbuf.h"
#include "argv-array.h" #include "strvec.h"
#include "quote.h" #include "quote.h"
#include "object-store.h" #include "object-store.h"
struct tmp_objdir { struct tmp_objdir {
struct strbuf path; struct strbuf path;
struct argv_array env; struct strvec env;
}; };
/* /*
@ -24,7 +24,7 @@ static struct tmp_objdir *the_tmp_objdir;
static void tmp_objdir_free(struct tmp_objdir *t) static void tmp_objdir_free(struct tmp_objdir *t)
{ {
strbuf_release(&t->path); strbuf_release(&t->path);
argv_array_clear(&t->env); strvec_clear(&t->env);
free(t); free(t);
} }
@ -79,7 +79,7 @@ static void remove_tmp_objdir_on_signal(int signo)
* separated by PATH_SEP (which is what separate values in * separated by PATH_SEP (which is what separate values in
* GIT_ALTERNATE_OBJECT_DIRECTORIES). * GIT_ALTERNATE_OBJECT_DIRECTORIES).
*/ */
static void env_append(struct argv_array *env, const char *key, const char *val) static void env_append(struct strvec *env, const char *key, const char *val)
{ {
struct strbuf quoted = STRBUF_INIT; struct strbuf quoted = STRBUF_INIT;
const char *old; const char *old;
@ -97,16 +97,16 @@ static void env_append(struct argv_array *env, const char *key, const char *val)
old = getenv(key); old = getenv(key);
if (!old) if (!old)
argv_array_pushf(env, "%s=%s", key, val); strvec_pushf(env, "%s=%s", key, val);
else else
argv_array_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val); strvec_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val);
strbuf_release(&quoted); strbuf_release(&quoted);
} }
static void env_replace(struct argv_array *env, const char *key, const char *val) static void env_replace(struct strvec *env, const char *key, const char *val)
{ {
argv_array_pushf(env, "%s=%s", key, val); strvec_pushf(env, "%s=%s", key, val);
} }
static int setup_tmp_objdir(const char *root) static int setup_tmp_objdir(const char *root)
@ -131,7 +131,7 @@ struct tmp_objdir *tmp_objdir_create(void)
t = xmalloc(sizeof(*t)); t = xmalloc(sizeof(*t));
strbuf_init(&t->path, 0); strbuf_init(&t->path, 0);
argv_array_init(&t->env); strvec_init(&t->env);
strbuf_addf(&t->path, "%s/incoming-XXXXXX", get_object_directory()); strbuf_addf(&t->path, "%s/incoming-XXXXXX", get_object_directory());
@ -283,7 +283,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
{ {
if (!t) if (!t)
return NULL; return NULL;
return t->env.argv; return t->env.v;
} }
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t) void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)

View file

@ -9,7 +9,7 @@
#include "string-list.h" #include "string-list.h"
#include "thread-utils.h" #include "thread-utils.h"
#include "sigchain.h" #include "sigchain.h"
#include "argv-array.h" #include "strvec.h"
#include "refs.h" #include "refs.h"
#include "refspec.h" #include "refspec.h"
#include "transport-internal.h" #include "transport-internal.h"
@ -128,17 +128,17 @@ static struct child_process *get_helper(struct transport *transport)
helper->in = -1; helper->in = -1;
helper->out = -1; helper->out = -1;
helper->err = 0; helper->err = 0;
argv_array_pushf(&helper->args, "git-remote-%s", data->name); strvec_pushf(&helper->args, "git-remote-%s", data->name);
argv_array_push(&helper->args, transport->remote->name); strvec_push(&helper->args, transport->remote->name);
argv_array_push(&helper->args, remove_ext_force(transport->url)); strvec_push(&helper->args, remove_ext_force(transport->url));
helper->git_cmd = 0; helper->git_cmd = 0;
helper->silent_exec_failure = 1; helper->silent_exec_failure = 1;
if (have_git_dir()) if (have_git_dir())
argv_array_pushf(&helper->env_array, "%s=%s", strvec_pushf(&helper->env_array, "%s=%s",
GIT_DIR_ENVIRONMENT, get_git_dir()); GIT_DIR_ENVIRONMENT, get_git_dir());
helper->trace2_child_class = helper->args.argv[0]; /* "remote-<name>" */ helper->trace2_child_class = helper->args.v[0]; /* "remote-<name>" */
code = start_command(helper); code = start_command(helper);
if (code < 0 && errno == ENOENT) if (code < 0 && errno == ENOENT)
@ -439,13 +439,13 @@ static int get_importer(struct transport *transport, struct child_process *fasti
int cat_blob_fd, code; int cat_blob_fd, code;
child_process_init(fastimport); child_process_init(fastimport);
fastimport->in = xdup(helper->out); fastimport->in = xdup(helper->out);
argv_array_push(&fastimport->args, "fast-import"); strvec_push(&fastimport->args, "fast-import");
argv_array_push(&fastimport->args, "--allow-unsafe-features"); strvec_push(&fastimport->args, "--allow-unsafe-features");
argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet"); strvec_push(&fastimport->args, debug ? "--stats" : "--quiet");
if (data->bidi_import) { if (data->bidi_import) {
cat_blob_fd = xdup(helper->in); cat_blob_fd = xdup(helper->in);
argv_array_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd); strvec_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd);
} }
fastimport->git_cmd = 1; fastimport->git_cmd = 1;
@ -466,17 +466,17 @@ static int get_exporter(struct transport *transport,
/* we need to duplicate helper->in because we want to use it after /* we need to duplicate helper->in because we want to use it after
* fastexport is done with it. */ * fastexport is done with it. */
fastexport->out = dup(helper->in); fastexport->out = dup(helper->in);
argv_array_push(&fastexport->args, "fast-export"); strvec_push(&fastexport->args, "fast-export");
argv_array_push(&fastexport->args, "--use-done-feature"); strvec_push(&fastexport->args, "--use-done-feature");
argv_array_push(&fastexport->args, data->signed_tags ? strvec_push(&fastexport->args, data->signed_tags ?
"--signed-tags=verbatim" : "--signed-tags=warn-strip"); "--signed-tags=verbatim" : "--signed-tags=warn-strip");
if (data->export_marks) if (data->export_marks)
argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks); strvec_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks);
if (data->import_marks) if (data->import_marks)
argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks); strvec_pushf(&fastexport->args, "--import-marks=%s", data->import_marks);
for (i = 0; i < revlist_args->nr; i++) for (i = 0; i < revlist_args->nr; i++)
argv_array_push(&fastexport->args, revlist_args->items[i].string); strvec_push(&fastexport->args, revlist_args->items[i].string);
fastexport->git_cmd = 1; fastexport->git_cmd = 1;
return start_command(fastexport); return start_command(fastexport);
@ -1082,7 +1082,7 @@ static int has_attribute(const char *attrs, const char *attr)
} }
static struct ref *get_refs_list(struct transport *transport, int for_push, static struct ref *get_refs_list(struct transport *transport, int for_push,
const struct argv_array *ref_prefixes) const struct strvec *ref_prefixes)
{ {
get_helper(transport); get_helper(transport);

View file

@ -3,7 +3,7 @@
struct ref; struct ref;
struct transport; struct transport;
struct argv_array; struct strvec;
struct transport_vtable { struct transport_vtable {
/** /**
@ -30,7 +30,7 @@ struct transport_vtable {
* in the ref's old_sha1 field; otherwise it should be all 0. * in the ref's old_sha1 field; otherwise it should be all 0.
**/ **/
struct ref *(*get_refs_list)(struct transport *transport, int for_push, struct ref *(*get_refs_list)(struct transport *transport, int for_push,
const struct argv_array *ref_prefixes); const struct strvec *ref_prefixes);
/** /**
* Fetch the objects for the given refs. Note that this gets * Fetch the objects for the given refs. Note that this gets

View file

@ -127,7 +127,7 @@ struct bundle_transport_data {
static struct ref *get_refs_from_bundle(struct transport *transport, static struct ref *get_refs_from_bundle(struct transport *transport,
int for_push, int for_push,
const struct argv_array *ref_prefixes) const struct strvec *ref_prefixes)
{ {
struct bundle_transport_data *data = transport->data; struct bundle_transport_data *data = transport->data;
struct ref *result = NULL; struct ref *result = NULL;
@ -283,7 +283,7 @@ static void die_if_server_options(struct transport *transport)
* remote refs. * remote refs.
*/ */
static struct ref *handshake(struct transport *transport, int for_push, static struct ref *handshake(struct transport *transport, int for_push,
const struct argv_array *ref_prefixes, const struct strvec *ref_prefixes,
int must_list_refs) int must_list_refs)
{ {
struct git_transport_data *data = transport->data; struct git_transport_data *data = transport->data;
@ -327,7 +327,7 @@ static struct ref *handshake(struct transport *transport, int for_push,
} }
static struct ref *get_refs_via_connect(struct transport *transport, int for_push, static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
const struct argv_array *ref_prefixes) const struct strvec *ref_prefixes)
{ {
return handshake(transport, for_push, ref_prefixes, 1); return handshake(transport, for_push, ref_prefixes, 1);
} }
@ -1153,7 +1153,7 @@ int transport_push(struct repository *r,
int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
int pretend = flags & TRANSPORT_PUSH_DRY_RUN; int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
int push_ret, ret, err; int push_ret, ret, err;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT; struct strvec ref_prefixes = STRVEC_INIT;
if (check_push_refs(local_refs, rs) < 0) if (check_push_refs(local_refs, rs) < 0)
return -1; return -1;
@ -1165,7 +1165,7 @@ int transport_push(struct repository *r,
&ref_prefixes); &ref_prefixes);
trace2_region_leave("transport_push", "get_refs_list", r); trace2_region_leave("transport_push", "get_refs_list", r);
argv_array_clear(&ref_prefixes); strvec_clear(&ref_prefixes);
if (flags & TRANSPORT_PUSH_ALL) if (flags & TRANSPORT_PUSH_ALL)
match_flags |= MATCH_REFS_ALL; match_flags |= MATCH_REFS_ALL;
@ -1281,7 +1281,7 @@ int transport_push(struct repository *r,
} }
const struct ref *transport_get_remote_refs(struct transport *transport, const struct ref *transport_get_remote_refs(struct transport *transport,
const struct argv_array *ref_prefixes) const struct strvec *ref_prefixes)
{ {
if (!transport->got_remote_refs) { if (!transport->got_remote_refs) {
transport->remote_refs = transport->remote_refs =

View file

@ -243,7 +243,7 @@ int transport_push(struct repository *repo,
* ref_prefixes. * ref_prefixes.
*/ */
const struct ref *transport_get_remote_refs(struct transport *transport, const struct ref *transport_get_remote_refs(struct transport *transport,
const struct argv_array *ref_prefixes); const struct strvec *ref_prefixes);
/* /*
* Fetch the hash algorithm used by a remote. * Fetch the hash algorithm used by a remote.

Some files were not shown because too many files have changed in this diff Show more