Skip to content

Commit

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

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

The conversion was done purely mechanically with:

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

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

Signed-off-by: Jeff King <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Jul 28, 2020
1 parent 22f9b7f commit ef8d7ac
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 201 deletions.
14 changes: 7 additions & 7 deletions add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,18 +935,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
opts->prompt = N_("Patch update");
count = list_and_choose(s, files, opts);
if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
struct pathspec ps_selected = { 0 };

for (i = 0; i < files->items.nr; i++)
if (files->selected[i])
argv_array_push(&args,
strvec_push(&args,
files->items.items[i].string);
parse_pathspec(&ps_selected,
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_LITERAL_PATH, "", args.argv);
res = run_add_p(s->r, ADD_P_ADD, NULL, &ps_selected);
argv_array_clear(&args);
strvec_clear(&args);
clear_pathspec(&ps_selected);
}

Expand Down Expand Up @@ -976,18 +976,18 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
count = list_and_choose(s, files, opts);
opts->flags = 0;
if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;

argv_array_pushl(&args, "git", "diff", "-p", "--cached",
strvec_pushl(&args, "git", "diff", "-p", "--cached",
oid_to_hex(!is_initial ? &oid :
s->r->hash_algo->empty_tree),
"--", NULL);
for (i = 0; i < files->items.nr; i++)
if (files->selected[i])
argv_array_push(&args,
strvec_push(&args,
files->items.items[i].string);
res = run_command_v_opt(args.argv, 0);
argv_array_clear(&args);
strvec_clear(&args);
}

putchar('\n');
Expand Down
28 changes: 14 additions & 14 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ static void setup_child_process(struct add_p_state *s,

va_start(ap, cp);
while ((arg = va_arg(ap, const char *)))
argv_array_push(&cp->args, arg);
strvec_push(&cp->args, arg);
va_end(ap);

cp->git_cmd = 1;
argv_array_pushf(&cp->env_array,
strvec_pushf(&cp->env_array,
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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,
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;
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
argv_array_pushl(&args, "--no-color", "-p", "--", NULL);
strvec_pushl(&args, "--no-color", "-p", "--", NULL);
for (i = 0; i < ps->nr; i++)
argv_array_push(&args, ps->items[i].original);
strvec_push(&args, ps->items[i].original);

setup_child_process(s, &cp, NULL);
cp.argv = args.argv;
res = capture_command(&cp, plain, 0);
if (res) {
argv_array_clear(&args);
strvec_clear(&args);
return error(_("could not parse diff"));
}
if (!plain->len) {
argv_array_clear(&args);
strvec_clear(&args);
return 0;
}
strbuf_complete_line(plain);
Expand All @@ -419,7 +419,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
colored_cp.argv = args.argv;
colored = &s->colored;
res = capture_command(&colored_cp, colored, 0);
argv_array_clear(&args);
strvec_clear(&args);
if (res)
return error(_("could not parse colored diff"));

Expand All @@ -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;
Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -1619,7 +1619,7 @@ static int patch_update_file(struct add_p_state *s,
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"));
Expand Down
12 changes: 6 additions & 6 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -632,20 +632,20 @@ 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);
revs->abbrev = 0;
revs->commit_format = CMIT_FMT_UNSPECIFIED;

/* rev_argv.argv[0] will be ignored by setup_revisions */
argv_array_push(&rev_argv, "bisect_rev_setup");
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
strvec_push(&rev_argv, "bisect_rev_setup");
strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
for (i = 0; i < good_revs.nr; i++)
argv_array_pushf(&rev_argv, good_format,
strvec_pushf(&rev_argv, good_format,
oid_to_hex(good_revs.oid + i));
argv_array_push(&rev_argv, "--");
strvec_push(&rev_argv, "--");
if (read_paths)
read_bisect_paths(&rev_argv);

Expand Down
12 changes: 6 additions & 6 deletions bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct argv_array *pack_options)
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options)
{
struct child_process pack_objects = CHILD_PROCESS_INIT;
int i;

argv_array_pushl(&pack_objects.args,
strvec_pushl(&pack_objects.args,
"pack-objects",
"--stdout", "--thin", "--delta-base-offset",
NULL);
argv_array_pushv(&pack_objects.args, pack_options->argv);
strvec_pushv(&pack_objects.args, pack_options->argv);
pack_objects.in = -1;
pack_objects.out = bundle_fd;
pack_objects.git_cmd = 1;
Expand Down Expand Up @@ -321,11 +321,11 @@ static int compute_and_write_prerequisites(int bundle_fd,
FILE *rls_fout;
int i;

argv_array_pushl(&rls.args,
strvec_pushl(&rls.args,
"rev-list", "--boundary", "--pretty=oneline",
NULL);
for (i = 1; i < argc; i++)
argv_array_push(&rls.args, argv[i]);
strvec_push(&rls.args, argv[i]);
rls.out = -1;
rls.git_cmd = 1;
if (start_command(&rls))
Expand Down Expand Up @@ -449,7 +449,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
}

int create_bundle(struct repository *r, const char *path,
int argc, const char **argv, struct argv_array *pack_options)
int argc, const char **argv, struct strvec *pack_options)
{
struct lock_file lock = LOCK_INIT;
int bundle_fd = -1;
Expand Down
2 changes: 1 addition & 1 deletion bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct bundle_header {
int is_bundle(const char *path, int quiet);
int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct repository *r, const char *path,
int argc, const char **argv, struct argv_array *pack_options);
int argc, const char **argv, struct strvec *pack_options);
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
#define BUNDLE_VERBOSE 1
int unbundle(struct repository *r, struct bundle_header *header,
Expand Down
12 changes: 6 additions & 6 deletions column.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,22 @@ static struct child_process column_process = CHILD_PROCESS_INIT;

int run_column_filter(int colopts, const struct column_options *opts)
{
struct argv_array *argv;
struct strvec *argv;

if (fd_out != -1)
return -1;

child_process_init(&column_process);
argv = &column_process.args;

argv_array_push(argv, "column");
argv_array_pushf(argv, "--raw-mode=%d", colopts);
strvec_push(argv, "column");
strvec_pushf(argv, "--raw-mode=%d", colopts);
if (opts && opts->width)
argv_array_pushf(argv, "--width=%d", opts->width);
strvec_pushf(argv, "--width=%d", opts->width);
if (opts && opts->indent)
argv_array_pushf(argv, "--indent=%s", opts->indent);
strvec_pushf(argv, "--indent=%s", opts->indent);
if (opts && opts->padding)
argv_array_pushf(argv, "--padding=%d", opts->padding);
strvec_pushf(argv, "--padding=%d", opts->padding);

fflush(stdout);
column_process.in = -1;
Expand Down
8 changes: 4 additions & 4 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,22 +1630,22 @@ size_t ignore_non_trailer(const char *buf, size_t len)
int run_commit_hook(int editor_is_used, const char *index_file,
const char *name, ...)
{
struct argv_array hook_env = ARGV_ARRAY_INIT;
struct strvec hook_env = STRVEC_INIT;
va_list args;
int ret;

argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);

/*
* Let the hook know that no editor will be launched.
*/
if (!editor_is_used)
argv_array_push(&hook_env, "GIT_EDITOR=:");
strvec_push(&hook_env, "GIT_EDITOR=:");

va_start(args, name);
ret = run_hook_ve(hook_env.argv,name, args);
va_end(args);
argv_array_clear(&hook_env);
strvec_clear(&hook_env);

return ret;
}
4 changes: 2 additions & 2 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void open_in_gdb(void)
static struct child_process cp = CHILD_PROCESS_INIT;
extern char *_pgmptr;

argv_array_pushl(&cp.args, "mintty", "gdb", NULL);
argv_array_pushf(&cp.args, "--pid=%d", getpid());
strvec_pushl(&cp.args, "mintty", "gdb", NULL);
strvec_pushf(&cp.args, "--pid=%d", getpid());
cp.clean_on_exit = 1;
if (start_command(&cp) < 0)
die_errno("Could not start gdb");
Expand Down
18 changes: 9 additions & 9 deletions compat/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ static void restore_term(void)
if (stty_restore.nr == 0)
return;

argv_array_push(&cp.args, "stty");
strvec_push(&cp.args, "stty");
for (i = 0; i < stty_restore.nr; i++)
argv_array_push(&cp.args, stty_restore.items[i].string);
strvec_push(&cp.args, stty_restore.items[i].string);
run_command(&cp);
string_list_clear(&stty_restore, 0);
return;
Expand All @@ -107,25 +107,25 @@ static int disable_bits(DWORD bits)
if (use_stty) {
struct child_process cp = CHILD_PROCESS_INIT;

argv_array_push(&cp.args, "stty");
strvec_push(&cp.args, "stty");

if (bits & ENABLE_LINE_INPUT) {
string_list_append(&stty_restore, "icanon");
argv_array_push(&cp.args, "-icanon");
strvec_push(&cp.args, "-icanon");
}

if (bits & ENABLE_ECHO_INPUT) {
string_list_append(&stty_restore, "echo");
argv_array_push(&cp.args, "-echo");
strvec_push(&cp.args, "-echo");
}

if (bits & ENABLE_PROCESSED_INPUT) {
string_list_append(&stty_restore, "-ignbrk");
string_list_append(&stty_restore, "intr");
string_list_append(&stty_restore, "^c");
argv_array_push(&cp.args, "ignbrk");
argv_array_push(&cp.args, "intr");
argv_array_push(&cp.args, "");
strvec_push(&cp.args, "ignbrk");
strvec_push(&cp.args, "intr");
strvec_push(&cp.args, "");
}

if (run_command(&cp) == 0)
Expand Down Expand Up @@ -273,7 +273,7 @@ static int is_known_escape_sequence(const char *sequence)
hashmap_init(&sequences, (hashmap_cmp_fn)sequence_entry_cmp,
NULL, 0);

argv_array_pushl(&cp.args, "infocmp", "-L", "-1", NULL);
strvec_pushl(&cp.args, "infocmp", "-L", "-1", NULL);
if (pipe_command(&cp, NULL, 0, &buf, 0, NULL, 0))
strbuf_setlen(&buf, 0);

Expand Down
Loading

0 comments on commit ef8d7ac

Please sign in to comment.