Skip to content

Commit ef8d7ac

Browse files
peffgitster
authored andcommitted
strvec: convert more callers away from argv_array name
We eventually want to drop the argv_array name and just use strvec consistently. There's no particular reason we have to do it all at once, or care about interactions between converted and unconverted bits. Because of our preprocessor compat layer, the names are interchangeable to the compiler (so even a definition and declaration using different names is OK). This patch converts remaining files from the first half of the alphabet, to keep the diff to a manageable size. The conversion was done purely mechanically with: git ls-files '*.c' '*.h' | xargs perl -i -pe ' s/ARGV_ARRAY/STRVEC/g; s/argv_array/strvec/g; ' and then selectively staging files with "git add '[abcdefghjkl]*'". We'll deal with any indentation/style fallouts separately. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22f9b7f commit ef8d7ac

27 files changed

+201
-201
lines changed

add-interactive.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -935,18 +935,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
935935
opts->prompt = N_("Patch update");
936936
count = list_and_choose(s, files, opts);
937937
if (count > 0) {
938-
struct argv_array args = ARGV_ARRAY_INIT;
938+
struct strvec args = STRVEC_INIT;
939939
struct pathspec ps_selected = { 0 };
940940

941941
for (i = 0; i < files->items.nr; i++)
942942
if (files->selected[i])
943-
argv_array_push(&args,
943+
strvec_push(&args,
944944
files->items.items[i].string);
945945
parse_pathspec(&ps_selected,
946946
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
947947
PATHSPEC_LITERAL_PATH, "", args.argv);
948948
res = run_add_p(s->r, ADD_P_ADD, NULL, &ps_selected);
949-
argv_array_clear(&args);
949+
strvec_clear(&args);
950950
clear_pathspec(&ps_selected);
951951
}
952952

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

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

993993
putchar('\n');

add-patch.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ static void setup_child_process(struct add_p_state *s,
286286

287287
va_start(ap, cp);
288288
while ((arg = va_arg(ap, const char *)))
289-
argv_array_push(&cp->args, arg);
289+
strvec_push(&cp->args, arg);
290290
va_end(ap);
291291

292292
cp->git_cmd = 1;
293-
argv_array_pushf(&cp->env_array,
293+
strvec_pushf(&cp->env_array,
294294
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
295295
}
296296

@@ -370,7 +370,7 @@ static int is_octal(const char *p, size_t len)
370370

371371
static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
372372
{
373-
struct argv_array args = ARGV_ARRAY_INIT;
373+
struct strvec args = STRVEC_INIT;
374374
const char *diff_algorithm = s->s.interactive_diff_algorithm;
375375
struct strbuf *plain = &s->plain, *colored = NULL;
376376
struct child_process cp = CHILD_PROCESS_INIT;
@@ -380,32 +380,32 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
380380
struct hunk *hunk = NULL;
381381
int res;
382382

383-
argv_array_pushv(&args, s->mode->diff_cmd);
383+
strvec_pushv(&args, s->mode->diff_cmd);
384384
if (diff_algorithm)
385-
argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
385+
strvec_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
386386
if (s->revision) {
387387
struct object_id oid;
388-
argv_array_push(&args,
388+
strvec_push(&args,
389389
/* could be on an unborn branch */
390390
!strcmp("HEAD", s->revision) &&
391391
get_oid("HEAD", &oid) ?
392392
empty_tree_oid_hex() : s->revision);
393393
}
394394
color_arg_index = args.argc;
395395
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
396-
argv_array_pushl(&args, "--no-color", "-p", "--", NULL);
396+
strvec_pushl(&args, "--no-color", "-p", "--", NULL);
397397
for (i = 0; i < ps->nr; i++)
398-
argv_array_push(&args, ps->items[i].original);
398+
strvec_push(&args, ps->items[i].original);
399399

400400
setup_child_process(s, &cp, NULL);
401401
cp.argv = args.argv;
402402
res = capture_command(&cp, plain, 0);
403403
if (res) {
404-
argv_array_clear(&args);
404+
strvec_clear(&args);
405405
return error(_("could not parse diff"));
406406
}
407407
if (!plain->len) {
408-
argv_array_clear(&args);
408+
strvec_clear(&args);
409409
return 0;
410410
}
411411
strbuf_complete_line(plain);
@@ -419,7 +419,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
419419
colored_cp.argv = args.argv;
420420
colored = &s->colored;
421421
res = capture_command(&colored_cp, colored, 0);
422-
argv_array_clear(&args);
422+
strvec_clear(&args);
423423
if (res)
424424
return error(_("could not parse colored diff"));
425425

@@ -444,7 +444,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
444444
colored_p = colored->buf;
445445
colored_pend = colored_p + colored->len;
446446
}
447-
argv_array_clear(&args);
447+
strvec_clear(&args);
448448

449449
/* parse files and hunks */
450450
p = plain->buf;
@@ -1158,7 +1158,7 @@ static int run_apply_check(struct add_p_state *s,
11581158

11591159
setup_child_process(s, &cp,
11601160
"apply", "--check", NULL);
1161-
argv_array_pushv(&cp.args, s->mode->apply_check_args);
1161+
strvec_pushv(&cp.args, s->mode->apply_check_args);
11621162
if (pipe_command(&cp, s->buf.buf, s->buf.len, NULL, 0, NULL, 0))
11631163
return error(_("'git apply --cached' failed"));
11641164

@@ -1619,7 +1619,7 @@ static int patch_update_file(struct add_p_state *s,
16191619
s->mode->is_reverse);
16201620
else {
16211621
setup_child_process(s, &cp, "apply", NULL);
1622-
argv_array_pushv(&cp.args, s->mode->apply_args);
1622+
strvec_pushv(&cp.args, s->mode->apply_args);
16231623
if (pipe_command(&cp, s->buf.buf, s->buf.len,
16241624
NULL, 0, NULL, 0))
16251625
error(_("'git apply' failed"));

bisect.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
456456
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
457457
static GIT_PATH_FUNC(git_path_head_name, "head-name")
458458

459-
static void read_bisect_paths(struct argv_array *array)
459+
static void read_bisect_paths(struct strvec *array)
460460
{
461461
struct strbuf str = STRBUF_INIT;
462462
const char *filename = git_path_bisect_names();
@@ -632,20 +632,20 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
632632
const char *bad_format, const char *good_format,
633633
int read_paths)
634634
{
635-
struct argv_array rev_argv = ARGV_ARRAY_INIT;
635+
struct strvec rev_argv = STRVEC_INIT;
636636
int i;
637637

638638
repo_init_revisions(r, revs, prefix);
639639
revs->abbrev = 0;
640640
revs->commit_format = CMIT_FMT_UNSPECIFIED;
641641

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

bundle.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,16 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
269269

270270

271271
/* Write the pack data to bundle_fd */
272-
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct argv_array *pack_options)
272+
static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options)
273273
{
274274
struct child_process pack_objects = CHILD_PROCESS_INIT;
275275
int i;
276276

277-
argv_array_pushl(&pack_objects.args,
277+
strvec_pushl(&pack_objects.args,
278278
"pack-objects",
279279
"--stdout", "--thin", "--delta-base-offset",
280280
NULL);
281-
argv_array_pushv(&pack_objects.args, pack_options->argv);
281+
strvec_pushv(&pack_objects.args, pack_options->argv);
282282
pack_objects.in = -1;
283283
pack_objects.out = bundle_fd;
284284
pack_objects.git_cmd = 1;
@@ -321,11 +321,11 @@ static int compute_and_write_prerequisites(int bundle_fd,
321321
FILE *rls_fout;
322322
int i;
323323

324-
argv_array_pushl(&rls.args,
324+
strvec_pushl(&rls.args,
325325
"rev-list", "--boundary", "--pretty=oneline",
326326
NULL);
327327
for (i = 1; i < argc; i++)
328-
argv_array_push(&rls.args, argv[i]);
328+
strvec_push(&rls.args, argv[i]);
329329
rls.out = -1;
330330
rls.git_cmd = 1;
331331
if (start_command(&rls))
@@ -449,7 +449,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
449449
}
450450

451451
int create_bundle(struct repository *r, const char *path,
452-
int argc, const char **argv, struct argv_array *pack_options)
452+
int argc, const char **argv, struct strvec *pack_options)
453453
{
454454
struct lock_file lock = LOCK_INIT;
455455
int bundle_fd = -1;

bundle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct bundle_header {
2121
int is_bundle(const char *path, int quiet);
2222
int read_bundle_header(const char *path, struct bundle_header *header);
2323
int create_bundle(struct repository *r, const char *path,
24-
int argc, const char **argv, struct argv_array *pack_options);
24+
int argc, const char **argv, struct strvec *pack_options);
2525
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
2626
#define BUNDLE_VERBOSE 1
2727
int unbundle(struct repository *r, struct bundle_header *header,

column.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,22 @@ static struct child_process column_process = CHILD_PROCESS_INIT;
358358

359359
int run_column_filter(int colopts, const struct column_options *opts)
360360
{
361-
struct argv_array *argv;
361+
struct strvec *argv;
362362

363363
if (fd_out != -1)
364364
return -1;
365365

366366
child_process_init(&column_process);
367367
argv = &column_process.args;
368368

369-
argv_array_push(argv, "column");
370-
argv_array_pushf(argv, "--raw-mode=%d", colopts);
369+
strvec_push(argv, "column");
370+
strvec_pushf(argv, "--raw-mode=%d", colopts);
371371
if (opts && opts->width)
372-
argv_array_pushf(argv, "--width=%d", opts->width);
372+
strvec_pushf(argv, "--width=%d", opts->width);
373373
if (opts && opts->indent)
374-
argv_array_pushf(argv, "--indent=%s", opts->indent);
374+
strvec_pushf(argv, "--indent=%s", opts->indent);
375375
if (opts && opts->padding)
376-
argv_array_pushf(argv, "--padding=%d", opts->padding);
376+
strvec_pushf(argv, "--padding=%d", opts->padding);
377377

378378
fflush(stdout);
379379
column_process.in = -1;

commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,22 +1630,22 @@ size_t ignore_non_trailer(const char *buf, size_t len)
16301630
int run_commit_hook(int editor_is_used, const char *index_file,
16311631
const char *name, ...)
16321632
{
1633-
struct argv_array hook_env = ARGV_ARRAY_INIT;
1633+
struct strvec hook_env = STRVEC_INIT;
16341634
va_list args;
16351635
int ret;
16361636

1637-
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
1637+
strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
16381638

16391639
/*
16401640
* Let the hook know that no editor will be launched.
16411641
*/
16421642
if (!editor_is_used)
1643-
argv_array_push(&hook_env, "GIT_EDITOR=:");
1643+
strvec_push(&hook_env, "GIT_EDITOR=:");
16441644

16451645
va_start(args, name);
16461646
ret = run_hook_ve(hook_env.argv,name, args);
16471647
va_end(args);
1648-
argv_array_clear(&hook_env);
1648+
strvec_clear(&hook_env);
16491649

16501650
return ret;
16511651
}

compat/mingw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ void open_in_gdb(void)
1818
static struct child_process cp = CHILD_PROCESS_INIT;
1919
extern char *_pgmptr;
2020

21-
argv_array_pushl(&cp.args, "mintty", "gdb", NULL);
22-
argv_array_pushf(&cp.args, "--pid=%d", getpid());
21+
strvec_pushl(&cp.args, "mintty", "gdb", NULL);
22+
strvec_pushf(&cp.args, "--pid=%d", getpid());
2323
cp.clean_on_exit = 1;
2424
if (start_command(&cp) < 0)
2525
die_errno("Could not start gdb");

compat/terminal.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ static void restore_term(void)
8686
if (stty_restore.nr == 0)
8787
return;
8888

89-
argv_array_push(&cp.args, "stty");
89+
strvec_push(&cp.args, "stty");
9090
for (i = 0; i < stty_restore.nr; i++)
91-
argv_array_push(&cp.args, stty_restore.items[i].string);
91+
strvec_push(&cp.args, stty_restore.items[i].string);
9292
run_command(&cp);
9393
string_list_clear(&stty_restore, 0);
9494
return;
@@ -107,25 +107,25 @@ static int disable_bits(DWORD bits)
107107
if (use_stty) {
108108
struct child_process cp = CHILD_PROCESS_INIT;
109109

110-
argv_array_push(&cp.args, "stty");
110+
strvec_push(&cp.args, "stty");
111111

112112
if (bits & ENABLE_LINE_INPUT) {
113113
string_list_append(&stty_restore, "icanon");
114-
argv_array_push(&cp.args, "-icanon");
114+
strvec_push(&cp.args, "-icanon");
115115
}
116116

117117
if (bits & ENABLE_ECHO_INPUT) {
118118
string_list_append(&stty_restore, "echo");
119-
argv_array_push(&cp.args, "-echo");
119+
strvec_push(&cp.args, "-echo");
120120
}
121121

122122
if (bits & ENABLE_PROCESSED_INPUT) {
123123
string_list_append(&stty_restore, "-ignbrk");
124124
string_list_append(&stty_restore, "intr");
125125
string_list_append(&stty_restore, "^c");
126-
argv_array_push(&cp.args, "ignbrk");
127-
argv_array_push(&cp.args, "intr");
128-
argv_array_push(&cp.args, "");
126+
strvec_push(&cp.args, "ignbrk");
127+
strvec_push(&cp.args, "intr");
128+
strvec_push(&cp.args, "");
129129
}
130130

131131
if (run_command(&cp) == 0)
@@ -273,7 +273,7 @@ static int is_known_escape_sequence(const char *sequence)
273273
hashmap_init(&sequences, (hashmap_cmp_fn)sequence_entry_cmp,
274274
NULL, 0);
275275

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

0 commit comments

Comments
 (0)