Skip to content

Commit 22f9b7f

Browse files
peffgitster
authored andcommitted
strvec: convert builtin/ 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 all of the files in builtin/ 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 builtin/". 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 2745b6b commit 22f9b7f

28 files changed

+503
-503
lines changed

builtin/add.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
188188
const struct pathspec *pathspec)
189189
{
190190
int status, i;
191-
struct argv_array argv = ARGV_ARRAY_INIT;
191+
struct strvec argv = STRVEC_INIT;
192192
int use_builtin_add_i =
193193
git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
194194

@@ -218,18 +218,18 @@ int run_add_interactive(const char *revision, const char *patch_mode,
218218
return !!run_add_p(the_repository, mode, revision, pathspec);
219219
}
220220

221-
argv_array_push(&argv, "add--interactive");
221+
strvec_push(&argv, "add--interactive");
222222
if (patch_mode)
223-
argv_array_push(&argv, patch_mode);
223+
strvec_push(&argv, patch_mode);
224224
if (revision)
225-
argv_array_push(&argv, revision);
226-
argv_array_push(&argv, "--");
225+
strvec_push(&argv, revision);
226+
strvec_push(&argv, "--");
227227
for (i = 0; i < pathspec->nr; i++)
228228
/* pass original pathspec, to be re-parsed */
229-
argv_array_push(&argv, pathspec->items[i].original);
229+
strvec_push(&argv, pathspec->items[i].original);
230230

231231
status = run_command_v_opt(argv.argv, RUN_GIT_CMD);
232-
argv_array_clear(&argv);
232+
strvec_clear(&argv);
233233
return status;
234234
}
235235

builtin/am.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct am_state {
116116
int keep; /* enum keep_type */
117117
int message_id;
118118
int scissors; /* enum scissors_type */
119-
struct argv_array git_apply_opts;
119+
struct strvec git_apply_opts;
120120
const char *resolvemsg;
121121
int committer_date_is_author_date;
122122
int ignore_date;
@@ -146,7 +146,7 @@ static void am_state_init(struct am_state *state)
146146

147147
state->scissors = SCISSORS_UNSET;
148148

149-
argv_array_init(&state->git_apply_opts);
149+
strvec_init(&state->git_apply_opts);
150150

151151
if (!git_config_get_bool("commit.gpgsign", &gpgsign))
152152
state->sign_commit = gpgsign ? "" : NULL;
@@ -162,7 +162,7 @@ static void am_state_release(struct am_state *state)
162162
free(state->author_email);
163163
free(state->author_date);
164164
free(state->msg);
165-
argv_array_clear(&state->git_apply_opts);
165+
strvec_clear(&state->git_apply_opts);
166166
}
167167

168168
/**
@@ -398,7 +398,7 @@ static void am_load(struct am_state *state)
398398
state->scissors = SCISSORS_UNSET;
399399

400400
read_state_file(&sb, state, "apply-opt", 1);
401-
argv_array_clear(&state->git_apply_opts);
401+
strvec_clear(&state->git_apply_opts);
402402
if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0)
403403
die(_("could not parse %s"), am_path(state, "apply-opt"));
404404

@@ -452,8 +452,8 @@ static int run_post_rewrite_hook(const struct am_state *state)
452452
if (!hook)
453453
return 0;
454454

455-
argv_array_push(&cp.args, hook);
456-
argv_array_push(&cp.args, "rebase");
455+
strvec_push(&cp.args, hook);
456+
strvec_push(&cp.args, "rebase");
457457

458458
cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
459459
cp.stdout_to_stderr = 1;
@@ -651,16 +651,16 @@ static int split_mail_mbox(struct am_state *state, const char **paths,
651651
int ret;
652652

653653
cp.git_cmd = 1;
654-
argv_array_push(&cp.args, "mailsplit");
655-
argv_array_pushf(&cp.args, "-d%d", state->prec);
656-
argv_array_pushf(&cp.args, "-o%s", state->dir);
657-
argv_array_push(&cp.args, "-b");
654+
strvec_push(&cp.args, "mailsplit");
655+
strvec_pushf(&cp.args, "-d%d", state->prec);
656+
strvec_pushf(&cp.args, "-o%s", state->dir);
657+
strvec_push(&cp.args, "-b");
658658
if (keep_cr)
659-
argv_array_push(&cp.args, "--keep-cr");
659+
strvec_push(&cp.args, "--keep-cr");
660660
if (mboxrd)
661-
argv_array_push(&cp.args, "--mboxrd");
662-
argv_array_push(&cp.args, "--");
663-
argv_array_pushv(&cp.args, paths);
661+
strvec_push(&cp.args, "--mboxrd");
662+
strvec_push(&cp.args, "--");
663+
strvec_pushv(&cp.args, paths);
664664

665665
ret = capture_command(&cp, &last, 8);
666666
if (ret)
@@ -787,7 +787,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
787787
const char *series_dir;
788788
char *series_dir_buf;
789789
FILE *fp;
790-
struct argv_array patches = ARGV_ARRAY_INIT;
790+
struct strvec patches = STRVEC_INIT;
791791
struct strbuf sb = STRBUF_INIT;
792792
int ret;
793793

@@ -805,7 +805,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
805805
if (*sb.buf == '#')
806806
continue; /* skip comment lines */
807807

808-
argv_array_push(&patches, mkpath("%s/%s", series_dir, sb.buf));
808+
strvec_push(&patches, mkpath("%s/%s", series_dir, sb.buf));
809809
}
810810

811811
fclose(fp);
@@ -814,7 +814,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
814814

815815
ret = split_mail_conv(stgit_patch_to_mail, state, patches.argv, keep_cr);
816816

817-
argv_array_clear(&patches);
817+
strvec_clear(&patches);
818818
return ret;
819819
}
820820

@@ -1390,8 +1390,8 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
13901390
*/
13911391
static int run_apply(const struct am_state *state, const char *index_file)
13921392
{
1393-
struct argv_array apply_paths = ARGV_ARRAY_INIT;
1394-
struct argv_array apply_opts = ARGV_ARRAY_INIT;
1393+
struct strvec apply_paths = STRVEC_INIT;
1394+
struct strvec apply_opts = STRVEC_INIT;
13951395
struct apply_state apply_state;
13961396
int res, opts_left;
13971397
int force_apply = 0;
@@ -1400,8 +1400,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
14001400
if (init_apply_state(&apply_state, the_repository, NULL))
14011401
BUG("init_apply_state() failed");
14021402

1403-
argv_array_push(&apply_opts, "apply");
1404-
argv_array_pushv(&apply_opts, state->git_apply_opts.argv);
1403+
strvec_push(&apply_opts, "apply");
1404+
strvec_pushv(&apply_opts, state->git_apply_opts.argv);
14051405

14061406
opts_left = apply_parse_options(apply_opts.argc, apply_opts.argv,
14071407
&apply_state, &force_apply, &options,
@@ -1426,12 +1426,12 @@ static int run_apply(const struct am_state *state, const char *index_file)
14261426
if (check_apply_state(&apply_state, force_apply))
14271427
BUG("check_apply_state() failed");
14281428

1429-
argv_array_push(&apply_paths, am_path(state, "patch"));
1429+
strvec_push(&apply_paths, am_path(state, "patch"));
14301430

14311431
res = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options);
14321432

1433-
argv_array_clear(&apply_paths);
1434-
argv_array_clear(&apply_opts);
1433+
strvec_clear(&apply_paths);
1434+
strvec_clear(&apply_opts);
14351435
clear_apply_state(&apply_state);
14361436

14371437
if (res)
@@ -1454,10 +1454,10 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f
14541454
struct child_process cp = CHILD_PROCESS_INIT;
14551455

14561456
cp.git_cmd = 1;
1457-
argv_array_push(&cp.args, "apply");
1458-
argv_array_pushv(&cp.args, state->git_apply_opts.argv);
1459-
argv_array_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
1460-
argv_array_push(&cp.args, am_path(state, "patch"));
1457+
strvec_push(&cp.args, "apply");
1458+
strvec_pushv(&cp.args, state->git_apply_opts.argv);
1459+
strvec_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
1460+
strvec_push(&cp.args, am_path(state, "patch"));
14611461

14621462
if (run_command(&cp))
14631463
return -1;
@@ -1676,7 +1676,7 @@ static int do_interactive(struct am_state *state)
16761676
if (!pager)
16771677
pager = "cat";
16781678
prepare_pager_args(&cp, pager);
1679-
argv_array_push(&cp.args, am_path(state, "patch"));
1679+
strvec_push(&cp.args, am_path(state, "patch"));
16801680
run_command(&cp);
16811681
}
16821682
}
@@ -2346,7 +2346,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23462346
if (state.signoff == SIGNOFF_EXPLICIT)
23472347
am_append_signoff(&state);
23482348
} else {
2349-
struct argv_array paths = ARGV_ARRAY_INIT;
2349+
struct strvec paths = STRVEC_INIT;
23502350
int i;
23512351

23522352
/*
@@ -2371,17 +2371,17 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23712371

23722372
for (i = 0; i < argc; i++) {
23732373
if (is_absolute_path(argv[i]) || !prefix)
2374-
argv_array_push(&paths, argv[i]);
2374+
strvec_push(&paths, argv[i]);
23752375
else
2376-
argv_array_push(&paths, mkpath("%s/%s", prefix, argv[i]));
2376+
strvec_push(&paths, mkpath("%s/%s", prefix, argv[i]));
23772377
}
23782378

23792379
if (state.interactive && !paths.argc)
23802380
die(_("interactive mode requires patches on the command line"));
23812381

23822382
am_setup(&state, patch_format, paths.argv, keep_cr);
23832383

2384-
argv_array_clear(&paths);
2384+
strvec_clear(&paths);
23852385
}
23862386

23872387
switch (resume.mode) {

builtin/annotate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
int cmd_annotate(int argc, const char **argv, const char *prefix)
1111
{
12-
struct argv_array args = ARGV_ARRAY_INIT;
12+
struct strvec args = STRVEC_INIT;
1313
int i;
1414

15-
argv_array_pushl(&args, "annotate", "-c", NULL);
15+
strvec_pushl(&args, "annotate", "-c", NULL);
1616

1717
for (i = 1; i < argc; i++) {
18-
argv_array_push(&args, argv[i]);
18+
strvec_push(&args, argv[i]);
1919
}
2020

2121
return cmd_blame(args.argc, args.argv, prefix);

builtin/bisect--helper.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,18 @@ static int bisect_reset(const char *commit)
165165
}
166166

167167
if (!file_exists(git_path_bisect_head())) {
168-
struct argv_array argv = ARGV_ARRAY_INIT;
168+
struct strvec argv = STRVEC_INIT;
169169

170-
argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
170+
strvec_pushl(&argv, "checkout", branch.buf, "--", NULL);
171171
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
172172
error(_("could not check out original"
173173
" HEAD '%s'. Try 'git bisect"
174174
" reset <commit>'."), branch.buf);
175175
strbuf_release(&branch);
176-
argv_array_clear(&argv);
176+
strvec_clear(&argv);
177177
return -1;
178178
}
179-
argv_array_clear(&argv);
179+
strvec_clear(&argv);
180180
}
181181

182182
strbuf_release(&branch);
@@ -526,9 +526,9 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
526526
strbuf_read_file(&start_head, git_path_bisect_start(), 0);
527527
strbuf_trim(&start_head);
528528
if (!no_checkout) {
529-
struct argv_array argv = ARGV_ARRAY_INIT;
529+
struct strvec argv = STRVEC_INIT;
530530

531-
argv_array_pushl(&argv, "checkout", start_head.buf,
531+
strvec_pushl(&argv, "checkout", start_head.buf,
532532
"--", NULL);
533533
if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
534534
res = error(_("checking out '%s' failed."

builtin/bundle.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int parse_options_cmd_bundle(int argc,
5959
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
6060
int all_progress_implied = 0;
6161
int progress = isatty(STDERR_FILENO);
62-
struct argv_array pack_opts;
62+
struct strvec pack_opts;
6363

6464
struct option options[] = {
6565
OPT_SET_INT('q', "quiet", &progress,
@@ -79,15 +79,15 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
7979
builtin_bundle_create_usage, options, &bundle_file);
8080
/* bundle internals use argv[1] as further parameters */
8181

82-
argv_array_init(&pack_opts);
82+
strvec_init(&pack_opts);
8383
if (progress == 0)
84-
argv_array_push(&pack_opts, "--quiet");
84+
strvec_push(&pack_opts, "--quiet");
8585
else if (progress == 1)
86-
argv_array_push(&pack_opts, "--progress");
86+
strvec_push(&pack_opts, "--progress");
8787
else if (progress == 2)
88-
argv_array_push(&pack_opts, "--all-progress");
88+
strvec_push(&pack_opts, "--all-progress");
8989
if (progress && all_progress_implied)
90-
argv_array_push(&pack_opts, "--all-progress-implied");
90+
strvec_push(&pack_opts, "--all-progress-implied");
9191

9292
if (!startup_info->have_repository)
9393
die(_("Need a repository to create a bundle."));

0 commit comments

Comments
 (0)