Browse Source

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
pull/825/merge
Junio C Hamano 2 years ago
parent
commit
46b225f153
  1. 4
      Documentation/technical/api-parse-options.txt
  2. 2
      Makefile
  3. 28
      add-interactive.c
  4. 48
      add-patch.c
  5. 109
      argv-array.c
  6. 20
      bisect.c
  7. 18
      builtin/add.c
  8. 80
      builtin/am.c
  9. 10
      builtin/annotate.c
  10. 20
      builtin/bisect--helper.c
  11. 14
      builtin/bundle.c
  12. 38
      builtin/clone.c
  13. 8
      builtin/commit.c
  14. 44
      builtin/describe.c
  15. 30
      builtin/difftool.c
  16. 64
      builtin/fetch.c
  17. 78
      builtin/gc.c
  18. 2
      builtin/grep.c
  19. 12
      builtin/log.c
  20. 6
      builtin/ls-remote.c
  21. 26
      builtin/pack-objects.c
  22. 160
      builtin/pull.c
  23. 4
      builtin/range-diff.c
  24. 90
      builtin/rebase.c
  25. 126
      builtin/receive-pack.c
  26. 4
      builtin/remote-ext.c
  27. 26
      builtin/remote.c
  28. 72
      builtin/repack.c
  29. 18
      builtin/replace.c
  30. 16
      builtin/show-branch.c
  31. 162
      builtin/stash.c
  32. 144
      builtin/submodule--helper.c
  33. 2
      builtin/update-ref.c
  34. 12
      builtin/upload-archive.c
  35. 68
      builtin/worktree.c
  36. 24
      bundle.c
  37. 4
      bundle.h
  38. 12
      column.c
  39. 10
      commit.c
  40. 4
      compat/mingw.c
  41. 18
      compat/terminal.c
  42. 69
      connect.c
  43. 24
      connected.c
  44. 60
      daemon.c
  45. 32
      diff.c
  46. 12
      environment.c
  47. 18
      exec-cmd.c
  48. 4
      exec-cmd.h
  49. 4
      fast-import.c
  50. 46
      fetch-pack.c
  51. 6
      fsmonitor.c
  52. 32
      git.c
  53. 22
      gpg-interface.c
  54. 16
      graph.c
  55. 8
      http-backend.c
  56. 18
      http-push.c
  57. 8
      http.c
  58. 2
      imap-send.c
  59. 8
      line-log.c
  60. 2
      list-objects-filter-options.c
  61. 18
      ls-refs.c
  62. 4
      ls-refs.h
  63. 18
      merge.c
  64. 12
      midx.c
  65. 8
      pager.c
  66. 8
      parse-options-cb.c
  67. 10
      pathspec.c
  68. 8
      quote.c
  69. 8
      quote.h
  70. 40
      range-diff.c
  71. 4
      range-diff.h
  72. 12
      ref-filter.c
  73. 8
      refs.c
  74. 4
      refs.h
  75. 10
      refspec.c
  76. 4
      refspec.h
  77. 102
      remote-curl.c
  78. 10
      remote-testsvn.c
  79. 20
      remote.c
  80. 4
      remote.h
  81. 20
      revision.c
  82. 72
      run-command.c
  83. 12
      run-command.h
  84. 18
      send-pack.c
  85. 126
      sequencer.c
  86. 20
      serve.c
  87. 4
      serve.h
  88. 14
      sha1-file.c
  89. 109
      strvec.c
  90. 58
      strvec.h
  91. 2
      sub-process.c
  92. 218
      submodule.c
  93. 6
      submodule.h
  94. 52
      t/helper/test-run-command.c
  95. 2
      t/helper/test-trace2.c
  96. 20
      tmp-objdir.c
  97. 36
      transport-helper.c
  98. 4
      transport-internal.h
  99. 12
      transport.c
  100. 2
      transport.h
  101. 12
      unpack-trees.c
  102. 4
      unpack-trees.h
  103. 53
      upload-pack.c
  104. 4
      upload-pack.h
  105. 19
      wt-status.c

4
Documentation/technical/api-parse-options.txt

@ -232,9 +232,9 @@ There are some macros to easily define options:
will be overwritten, so this should only be used for options where
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
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,
to another command.

2
Makefile

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

28
add-interactive.c

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

48
add-patch.c

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

109
argv-array.c

@ -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;
}
}

20
bisect.c

@ -11,7 +11,7 @@
#include "log-tree.h"
#include "bisect.h"
#include "oid-array.h"
#include "argv-array.h"
#include "strvec.h"
#include "commit-slab.h"
#include "commit-reach.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_head_name, "head-name")
static void read_bisect_paths(struct argv_array *array)
static void read_bisect_paths(struct strvec *array)
{
struct strbuf str = STRBUF_INIT;
const char *filename = git_path_bisect_names();
@ -464,7 +464,7 @@ static void read_bisect_paths(struct argv_array *array)
while (strbuf_getline_lf(&str, fp) != EOF) {
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"),
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,
int read_paths)
{
struct argv_array rev_argv = ARGV_ARRAY_INIT;
struct strvec rev_argv = STRVEC_INIT;
int i;
repo_init_revisions(r, revs, prefix);
@ -640,16 +640,16 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
revs->commit_format = CMIT_FMT_UNSPECIFIED;
/* rev_argv.argv[0] will be ignored by setup_revisions */
argv_array_push(&rev_argv, "bisect_rev_setup");
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
strvec_push(&rev_argv, "bisect_rev_setup");
strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
for (i = 0; i < good_revs.nr; i++)
argv_array_pushf(&rev_argv, good_format,
oid_to_hex(good_revs.oid + i));
argv_array_push(&rev_argv, "--");
strvec_pushf(&rev_argv, good_format,
oid_to_hex(good_revs.oid + i));
strvec_push(&rev_argv, "--");
if (read_paths)
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 */
}

18
builtin/add.c

@ -18,7 +18,7 @@
#include "diffcore.h"
#include "revision.h"
#include "bulk-checkin.h"
#include "argv-array.h"
#include "strvec.h"
#include "submodule.h"
#include "add-interactive.h"
@ -188,7 +188,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
const struct pathspec *pathspec)
{
int status, i;
struct argv_array argv = ARGV_ARRAY_INIT;
struct strvec argv = STRVEC_INIT;
int use_builtin_add_i =
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);
}
argv_array_push(&argv, "add--interactive");
strvec_push(&argv, "add--interactive");
if (patch_mode)
argv_array_push(&argv, patch_mode);
strvec_push(&argv, patch_mode);
if (revision)
argv_array_push(&argv, revision);
argv_array_push(&argv, "--");
strvec_push(&argv, revision);
strvec_push(&argv, "--");
for (i = 0; i < pathspec->nr; i++)
/* 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);
argv_array_clear(&argv);
status = run_command_v_opt(argv.v, RUN_GIT_CMD);
strvec_clear(&argv);
return status;
}

80
builtin/am.c

@ -116,7 +116,7 @@ struct am_state {
int keep; /* enum keep_type */
int message_id;
int scissors; /* enum scissors_type */
struct argv_array git_apply_opts;
struct strvec git_apply_opts;
const char *resolvemsg;
int committer_date_is_author_date;
int ignore_date;
@ -146,7 +146,7 @@ static void am_state_init(struct am_state *state)
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))
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_date);
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;
read_state_file(&sb, state, "apply-opt", 1);
argv_array_clear(&state->git_apply_opts);
if (sq_dequote_to_argv_array(sb.buf, &state->git_apply_opts) < 0)
strvec_clear(&state->git_apply_opts);
if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0)
die(_("could not parse %s"), am_path(state, "apply-opt"));
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)
return 0;
argv_array_push(&cp.args, hook);
argv_array_push(&cp.args, "rebase");
strvec_push(&cp.args, hook);
strvec_push(&cp.args, "rebase");
cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
cp.stdout_to_stderr = 1;
@ -651,16 +651,16 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
int ret;
cp.git_cmd = 1;
argv_array_push(&cp.args, "mailsplit");
argv_array_pushf(&cp.args, "-d%d", state->prec);
argv_array_pushf(&cp.args, "-o%s", state->dir);
argv_array_push(&cp.args, "-b");
strvec_push(&cp.args, "mailsplit");
strvec_pushf(&cp.args, "-d%d", state->prec);
strvec_pushf(&cp.args, "-o%s", state->dir);
strvec_push(&cp.args, "-b");
if (keep_cr)
argv_array_push(&cp.args, "--keep-cr");
strvec_push(&cp.args, "--keep-cr");
if (mboxrd)
argv_array_push(&cp.args, "--mboxrd");
argv_array_push(&cp.args, "--");
argv_array_pushv(&cp.args, paths);
strvec_push(&cp.args, "--mboxrd");
strvec_push(&cp.args, "--");
strvec_pushv(&cp.args, paths);
ret = capture_command(&cp, &last, 8);
if (ret)
@ -787,7 +787,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
const char *series_dir;
char *series_dir_buf;
FILE *fp;
struct argv_array patches = ARGV_ARRAY_INIT;
struct strvec patches = STRVEC_INIT;
struct strbuf sb = STRBUF_INIT;
int ret;
@ -805,16 +805,16 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
if (*sb.buf == '#')
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);
strbuf_release(&sb);
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;
}
@ -1002,7 +1002,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
}
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);
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)
{
struct argv_array apply_paths = ARGV_ARRAY_INIT;
struct argv_array apply_opts = ARGV_ARRAY_INIT;
struct strvec apply_paths = STRVEC_INIT;
struct strvec apply_opts = STRVEC_INIT;
struct apply_state apply_state;
int res, opts_left;
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))
BUG("init_apply_state() failed");
argv_array_push(&apply_opts, "apply");
argv_array_pushv(&apply_opts, state->git_apply_opts.argv);
strvec_push(&apply_opts, "apply");
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,
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))
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);
argv_array_clear(&apply_opts);
strvec_clear(&apply_paths);
strvec_clear(&apply_opts);
clear_apply_state(&apply_state);
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;
cp.git_cmd = 1;
argv_array_push(&cp.args, "apply");
argv_array_pushv(&cp.args, state->git_apply_opts.argv);
argv_array_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
argv_array_push(&cp.args, am_path(state, "patch"));
strvec_push(&cp.args, "apply");
strvec_pushv(&cp.args, state->git_apply_opts.v);
strvec_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
strvec_push(&cp.args, am_path(state, "patch"));
if (run_command(&cp))
return -1;
@ -1676,7 +1676,7 @@ static int do_interactive(struct am_state *state)
if (!pager)
pager = "cat";
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);
}
}
@ -2346,7 +2346,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
if (state.signoff == SIGNOFF_EXPLICIT)
am_append_signoff(&state);
} else {
struct argv_array paths = ARGV_ARRAY_INIT;
struct strvec paths = STRVEC_INIT;
int i;
/*
@ -2371,17 +2371,17 @@ int cmd_am(int argc, const char **argv, const char *prefix)
for (i = 0; i < argc; i++) {
if (is_absolute_path(argv[i]) || !prefix)
argv_array_push(&paths, argv[i]);
strvec_push(&paths, argv[i]);
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"));
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) {

10
builtin/annotate.c

@ -5,18 +5,18 @@
*/
#include "git-compat-util.h"
#include "builtin.h"
#include "argv-array.h"
#include "strvec.h"
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;
argv_array_pushl(&args, "annotate", "-c", NULL);
strvec_pushl(&args, "annotate", "-c", NULL);
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);
}

20
builtin/bisect--helper.c

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

14
builtin/bundle.c

@ -1,5 +1,5 @@
#include "builtin.h"
#include "argv-array.h"
#include "strvec.h"
#include "parse-options.h"
#include "cache.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) {
int all_progress_implied = 0;
int progress = isatty(STDERR_FILENO);
struct argv_array pack_opts;
struct strvec pack_opts;
struct option options[] = {
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);
/* bundle internals use argv[1] as further parameters */
argv_array_init(&pack_opts);
strvec_init(&pack_opts);
if (progress == 0)
argv_array_push(&pack_opts, "--quiet");
strvec_push(&pack_opts, "--quiet");
else if (progress == 1)
argv_array_push(&pack_opts, "--progress");
strvec_push(&pack_opts, "--progress");
else if (progress == 2)
argv_array_push(&pack_opts, "--all-progress");
strvec_push(&pack_opts, "--all-progress");
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)
die(_("Need a repository to create a bundle."));

38
builtin/clone.c

@ -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)
{
struct argv_array argv = ARGV_ARRAY_INIT;
struct strvec argv = STRVEC_INIT;
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
@ -752,12 +752,12 @@ static int git_sparse_checkout_init(const char *repo)
*/
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"));
result = 1;
}
argv_array_clear(&argv);
strvec_clear(&argv);
return result;
}
@ -819,33 +819,33 @@ static int checkout(int submodule_progress)
oid_to_hex(&oid), "1", NULL);
if (!err && (option_recurse_submodules.nr > 0)) {
struct argv_array args = ARGV_ARRAY_INIT;
argv_array_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL);
struct strvec args = STRVEC_INIT;
strvec_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL);
if (option_shallow_submodules == 1)
argv_array_push(&args, "--depth=1");
strvec_push(&args, "--depth=1");
if (max_jobs != -1)
argv_array_pushf(&args, "--jobs=%d", max_jobs);
strvec_pushf(&args, "--jobs=%d", max_jobs);
if (submodule_progress)
argv_array_push(&args, "--progress");
strvec_push(&args, "--progress");
if (option_verbosity < 0)
argv_array_push(&args, "--quiet");
strvec_push(&args, "--quiet");
if (option_remote_submodules) {
argv_array_push(&args, "--remote");
argv_array_push(&args, "--no-fetch");
strvec_push(&args, "--remote");
strvec_push(&args, "--no-fetch");
}
if (option_single_branch >= 0)
argv_array_push(&args, option_single_branch ?
strvec_push(&args, option_single_branch ?
"--single-branch" :
"--no-single-branch");
err = run_command_v_opt(args.argv, RUN_GIT_CMD);
argv_array_clear(&args);
err = run_command_v_opt(args.v, RUN_GIT_CMD);
strvec_clear(&args);
}
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 submodule_progress;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
struct strvec ref_prefixes = STRVEC_INIT;
packet_trace_identity("clone");
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;
argv_array_push(&ref_prefixes, "HEAD");
strvec_push(&ref_prefixes, "HEAD");
refspec_ref_prefixes(&remote->fetch, &ref_prefixes);
if (option_branch)
expand_ref_prefix(&ref_prefixes, option_branch);
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);
@ -1335,6 +1335,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
strbuf_release(&default_refspec);
junk_mode = JUNK_LEAVE_ALL;
argv_array_clear(&ref_prefixes);
strvec_clear(&ref_prefixes);
return err;
}

8
builtin/commit.c

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

44
builtin/describe.c

@ -12,7 +12,7 @@
#include "revision.h"
#include "diff.h"
#include "hashmap.h"
#include "argv-array.h"
#include "strvec.h"
#include "run-command.h"
#include "object-store.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)
{
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};
argv_array_pushl(&args, "internal: The first arg is not parsed",
"--objects", "--in-commit-order", "--reverse", "HEAD",
NULL);
strvec_pushl(&args, "internal: The first arg is not parsed",
"--objects", "--in-commit-order", "--reverse", "HEAD",
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?");
if (prepare_revision_walk(&revs))
@ -594,26 +594,26 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
if (contains) {
struct string_list_item *item;
struct argv_array args;
struct strvec args;
argv_array_init(&args);
argv_array_pushl(&args, "name-rev",
"--peel-tag", "--name-only", "--no-undefined",
NULL);
strvec_init(&args);
strvec_pushl(&args, "name-rev",
"--peel-tag", "--name-only", "--no-undefined",
NULL);
if (always)
argv_array_push(&args, "--always");
strvec_push(&args, "--always");
if (!all) {
argv_array_push(&args, "--tags");
strvec_push(&args, "--tags");
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)
argv_array_pushf(&args, "--exclude=refs/tags/%s", item->string);
strvec_pushf(&args, "--exclude=refs/tags/%s", item->string);
}
if (argc)
argv_array_pushv(&args, argv);
strvec_pushv(&args, argv);
else
argv_array_push(&args, "HEAD");
return cmd_name_rev(args.argc, args.argv, prefix);
strvec_push(&args, "HEAD");
return cmd_name_rev(args.nr, args.v, prefix);
}
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 (broken) {
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.no_stdin = 1;
cp.no_stdout = 1;
@ -646,7 +646,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
} else if (dirty) {
struct lock_file index_lock = LOCK_INIT;
struct rev_info revs;
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
int fd, result;
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_init_revisions(the_repository, &revs, prefix);
argv_array_pushv(&args, diff_index_args);
if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1)
strvec_pushv(&args, diff_index_args);
if (setup_revisions(args.nr, args.v, &revs, NULL) != 1)
BUG("malformed internal diff-index command line");
result = run_diff_index(&revs, 0);

30
builtin/difftool.c

@ -18,7 +18,7 @@
#include "run-command.h"
#include "exec-cmd.h"
#include "parse-options.h"
#include "argv-array.h"
#include "strvec.h"
#include "strbuf.h"
#include "lockfile.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);
env[0] = index_env.buf;
argv_array_pushl(&update_index.args,
"--git-dir", git_dir, "--work-tree", workdir,
"update-index", "--really-refresh", "-q",
"--unmerged", NULL);
strvec_pushl(&update_index.args,
"--git-dir", git_dir, "--work-tree", workdir,
"update-index", "--really-refresh", "-q",
"--unmerged", NULL);
update_index.no_stdin = 1;
update_index.no_stdout = 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 */
run_command(&update_index);
argv_array_pushl(&diff_files.args,
"--git-dir", git_dir, "--work-tree", workdir,
"diff-files", "--name-only", "-z", NULL);
strvec_pushl(&diff_files.args,
"--git-dir", git_dir, "--work-tree", workdir,
"diff-files", "--name-only", "-z", NULL);
diff_files.no_stdin = 1;
diff_files.git_cmd = 1;
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.dir = prefix;
child.out = -1;
argv_array_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
NULL);
strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
NULL);
for (i = 0; i < argc; i++)
argv_array_push(&child.args, argv[i]);
strvec_push(&child.args, argv[i]);
if (start_command(&child))
die("could not obtain raw diff");
fp = xfdopen(child.out, "r");
@ -667,7 +667,7 @@ finish:
static int run_file_diff(int prompt, const char *prefix,
int argc, const char **argv)
{
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
const char *env[] = {
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
NULL
@ -680,10 +680,10 @@ static int run_file_diff(int prompt, const char *prefix,
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
argv_array_push(&args, "diff");
strvec_push(&args, "diff");
for (i = 0; i < argc; i++)
argv_array_push(&args, argv[i]);
ret = run_command_v_opt_cd_env(args.argv, RUN_GIT_CMD, prefix, env);
strvec_push(&args, argv[i]);
ret = run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
exit(ret);
}

64
builtin/fetch.c

@ -19,7 +19,7 @@
#include "submodule-config.h"
#include "submodule.h"
#include "connected.h"
#include "argv-array.h"
#include "strvec.h"
#include "utf8.h"
#include "packfile.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 retcode = 0;
const struct ref *remote_refs;
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
struct strvec ref_prefixes = STRVEC_INIT;
int must_list_refs = 1;
if (tags == TAGS_DEFAULT) {
@ -1354,8 +1354,8 @@ static int do_fetch(struct transport *transport,
if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
must_list_refs = 1;
if (ref_prefixes.argc)
argv_array_push(&ref_prefixes, "refs/tags/");
if (ref_prefixes.nr)
strvec_push(&ref_prefixes, "refs/tags/");
}
if (must_list_refs) {
@ -1365,7 +1365,7 @@ static int do_fetch(struct transport *transport,
} else
remote_refs = NULL;
argv_array_clear(&ref_prefixes);
strvec_clear(&ref_prefixes);
ref_map = get_ref_map(transport->remote, remote_refs, rs,
tags, &autotags);
@ -1503,34 +1503,34 @@ static int add_remote_or_group(const char *name, struct string_list *list)
return 1;
}
static void add_options_to_argv(struct argv_array *argv)
static void add_options_to_argv(struct strvec *argv)
{
if (dry_run)
argv_array_push(argv, "--dry-run");
strvec_push(argv, "--dry-run");