use child_process members "args" and "env" directly
Build argument list and environment of child processes by using struct child_process and populating its members "args" and "env" directly instead of maintaining separate strvecs and letting run_command_v_opt() and friends populate these members. This is simpler, shorter and slightly more efficient. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Taylor Blau <me@ttaylorr.com>
René Scharfe committed
Oct 30, 2022 at 12:51 UTC
0e90673957f12adc1a84b13d3dfff02151e4a7a8
13 files changed
+185
-206
add-interactive.c
+4
-5
@@ -997,18 +997,17 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
997
count = list_and_choose(s, files, opts);
998
opts->flags = 0;
999
if (count > 0) {
1000
- struct strvec args = STRVEC_INIT;
1000
+ struct child_process cmd = CHILD_PROCESS_INIT;
1001
1002
- strvec_pushl(&args, "git", "diff", "-p", "--cached",
1002
+ strvec_pushl(&cmd.args, "git", "diff", "-p", "--cached",
1003
oid_to_hex(!is_initial ? &oid :
1004
s->r->hash_algo->empty_tree),
1005
"--", NULL);
1006
for (i = 0; i < files->items.nr; i++)
1007
if (files->selected[i])
1008
- strvec_push(&args,
1008
+ strvec_push(&cmd.args,
1009
files->items.items[i].string);
1010
- res = run_command_v_opt(args.v, 0);
1011
- strvec_clear(&args);
1010
+ res = run_command(&cmd);
1011
}
1012
1013
putchar('\n');
builtin/add.c
+9
-10
@@ -240,8 +240,8 @@ static int refresh(int verbose, const struct pathspec *pathspec)
240
int run_add_interactive(const char *revision, const char *patch_mode,
241
const struct pathspec *pathspec)
242
{
243
- int status, i;
244
- struct strvec argv = STRVEC_INIT;
243
+ int i;
244
+ struct child_process cmd = CHILD_PROCESS_INIT;
245
int use_builtin_add_i =
246
git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
247
@@ -272,19 +272,18 @@ int run_add_interactive(const char *revision, const char *patch_mode,
272
return !!run_add_p(the_repository, mode, revision, pathspec);
273
}
274
275
- strvec_push(&argv, "add--interactive");
275
+ strvec_push(&cmd.args, "add--interactive");
276
if (patch_mode)
277
- strvec_push(&argv, patch_mode);
277
+ strvec_push(&cmd.args, patch_mode);
278
if (revision)
279
- strvec_push(&argv, revision);
280
- strvec_push(&argv, "--");
279
+ strvec_push(&cmd.args, revision);
280
+ strvec_push(&cmd.args, "--");
281
for (i = 0; i < pathspec->nr; i++)
282
/* pass original pathspec, to be re-parsed */
283
- strvec_push(&argv, pathspec->items[i].original);
283
+ strvec_push(&cmd.args, pathspec->items[i].original);
284
285
- status = run_command_v_opt(argv.v, RUN_GIT_CMD);
286
- strvec_clear(&argv);
287
- return status;
285
+ cmd.git_cmd = 1;
286
+ return run_command(&cmd);
287
}
288
289
int interactive_add(const char **argv, const char *prefix, int patch)
builtin/bisect--helper.c
+16
-19
@@ -220,18 +220,17 @@ static int bisect_reset(const char *commit)
220
}
221
222
if (!ref_exists("BISECT_HEAD")) {
223
- struct strvec argv = STRVEC_INIT;
223
+ struct child_process cmd = CHILD_PROCESS_INIT;
224
225
- strvec_pushl(&argv, "checkout", branch.buf, "--", NULL);
226
- if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
225
+ cmd.git_cmd = 1;
226
+ strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL);
227
+ if (run_command(&cmd)) {
228
error(_("could not check out original"
229
" HEAD '%s'. Try 'git bisect"
230
" reset <commit>'."), branch.buf);
231
strbuf_release(&branch);
231
- strvec_clear(&argv);
232
return -1;
233
}
234
- strvec_clear(&argv);
234
}
235
236
strbuf_release(&branch);
@@ -1098,40 +1097,38 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar
1097
1098
static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc)
1099
{
1101
- struct strvec args = STRVEC_INIT;
1102
- int flags = RUN_COMMAND_NO_STDIN, res = 0;
1100
+ struct child_process cmd = CHILD_PROCESS_INIT;
1101
struct strbuf sb = STRBUF_INIT;
1102
1103
if (bisect_next_check(terms, NULL) != 0)
1104
return BISECT_FAILED;
1105
1106
+ cmd.no_stdin = 1;
1107
if (!argc) {
1108
if ((getenv("DISPLAY") || getenv("SESSIONNAME") || getenv("MSYSTEM") ||
1109
getenv("SECURITYSESSIONID")) && exists_in_PATH("gitk")) {
1111
- strvec_push(&args, "gitk");
1110
+ strvec_push(&cmd.args, "gitk");
1111
} else {
1113
- strvec_push(&args, "log");
1114
- flags |= RUN_GIT_CMD;
1112
+ strvec_push(&cmd.args, "log");
1113
+ cmd.git_cmd = 1;
1114
}
1115
} else {
1116
if (argv[0][0] == '-') {
1118
- strvec_push(&args, "log");
1119
- flags |= RUN_GIT_CMD;
1117
+ strvec_push(&cmd.args, "log");
1118
+ cmd.git_cmd = 1;
1119
} else if (strcmp(argv[0], "tig") && !starts_with(argv[0], "git"))
1121
- flags |= RUN_GIT_CMD;
1120
+ cmd.git_cmd = 1;
1121
1123
- strvec_pushv(&args, argv);
1122
+ strvec_pushv(&cmd.args, argv);
1123
}
1124
1126
- strvec_pushl(&args, "--bisect", "--", NULL);
1125
+ strvec_pushl(&cmd.args, "--bisect", "--", NULL);
1126
1127
strbuf_read_file(&sb, git_path_bisect_names(), 0);
1129
- sq_dequote_to_strvec(sb.buf, &args);
1128
+ sq_dequote_to_strvec(sb.buf, &cmd.args);
1129
strbuf_release(&sb);
1130
1132
- res = run_command_v_opt(args.v, flags);
1133
- strvec_clear(&args);
1134
- return res;
1131
+ return run_command(&cmd);
1132
}
1133
1134
static int get_first_good(const char *refname UNUSED,
builtin/clone.c
+17
-16
@@ -653,9 +653,9 @@ static void update_head(const struct ref *our, const struct ref *remote,
653
654
static int git_sparse_checkout_init(const char *repo)
655
{
656
- struct strvec argv = STRVEC_INIT;
656
+ struct child_process cmd = CHILD_PROCESS_INIT;
657
int result = 0;
658
- strvec_pushl(&argv, "-C", repo, "sparse-checkout", "set", NULL);
658
+ strvec_pushl(&cmd.args, "-C", repo, "sparse-checkout", "set", NULL);
659
660
/*
661
* We must apply the setting in the current process
@@ -663,12 +663,12 @@ static int git_sparse_checkout_init(const char *repo)
663
*/
664
core_apply_sparse_checkout = 1;
665
666
- if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
666
+ cmd.git_cmd = 1;
667
+ if (run_command(&cmd)) {
668
error(_("failed to initialize sparse-checkout"));
669
result = 1;
670
}
671
671
- strvec_clear(&argv);
672
return result;
673
}
674
@@ -733,37 +733,38 @@ static int checkout(int submodule_progress, int filter_submodules)
733
oid_to_hex(&oid), "1", NULL);
734
735
if (!err && (option_recurse_submodules.nr > 0)) {
736
- struct strvec args = STRVEC_INIT;
737
- strvec_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL);
736
+ struct child_process cmd = CHILD_PROCESS_INIT;
737
+ strvec_pushl(&cmd.args, "submodule", "update", "--require-init",
738
+ "--recursive", NULL);
739
740
if (option_shallow_submodules == 1)
740
- strvec_push(&args, "--depth=1");
741
+ strvec_push(&cmd.args, "--depth=1");
742
743
if (max_jobs != -1)
743
- strvec_pushf(&args, "--jobs=%d", max_jobs);
744
+ strvec_pushf(&cmd.args, "--jobs=%d", max_jobs);
745
746
if (submodule_progress)
746
- strvec_push(&args, "--progress");
747
+ strvec_push(&cmd.args, "--progress");
748
749
if (option_verbosity < 0)
749
- strvec_push(&args, "--quiet");
750
+ strvec_push(&cmd.args, "--quiet");
751
752
if (option_remote_submodules) {
752
- strvec_push(&args, "--remote");
753
- strvec_push(&args, "--no-fetch");
753
+ strvec_push(&cmd.args, "--remote");
754
+ strvec_push(&cmd.args, "--no-fetch");
755
}
756
757
if (filter_submodules && filter_options.choice)
757
- strvec_pushf(&args, "--filter=%s",
758
+ strvec_pushf(&cmd.args, "--filter=%s",
759
expand_list_objects_filter_spec(&filter_options));
760
761
if (option_single_branch >= 0)
761
- strvec_push(&args, option_single_branch ?
762
+ strvec_push(&cmd.args, option_single_branch ?
763
"--single-branch" :
764
"--no-single-branch");
765
765
- err = run_command_v_opt(args.v, RUN_GIT_CMD);
766
- strvec_clear(&args);
766
+ cmd.git_cmd = 1;
767
+ err = run_command(&cmd);
768
}
769
770
return err;
builtin/gc.c
+5
-9
@@ -1910,20 +1910,16 @@ static char *schtasks_task_name(const char *frequency)
1910
static int schtasks_remove_task(enum schedule_priority schedule)
1911
{
1912
const char *cmd = "schtasks";
1913
- int result;
1914
- struct strvec args = STRVEC_INIT;
1913
+ struct child_process child = CHILD_PROCESS_INIT;
1914
const char *frequency = get_frequency(schedule);
1915
char *name = schtasks_task_name(frequency);
1916
1917
get_schedule_cmd(&cmd, NULL);
1919
- strvec_split(&args, cmd);
1920
- strvec_pushl(&args, "/delete", "/tn", name, "/f", NULL);
1921
-
1922
- result = run_command_v_opt(args.v, 0);
1923
-
1924
- strvec_clear(&args);
1918
+ strvec_split(&child.args, cmd);
1919
+ strvec_pushl(&child.args, "/delete", "/tn", name, "/f", NULL);
1920
free(name);
1926
- return result;
1921
+
1922
+ return run_command(&child);
1923
}
1924
1925
static int schtasks_remove_tasks(void)
builtin/merge.c
+5
-5
@@ -372,22 +372,22 @@ static void reset_hard(const struct object_id *oid)
372
static void restore_state(const struct object_id *head,
373
const struct object_id *stash)
374
{
375
- struct strvec args = STRVEC_INIT;
375
+ struct child_process cmd = CHILD_PROCESS_INIT;
376
377
reset_hard(head);
378
379
if (is_null_oid(stash))
380
goto refresh_cache;
381
382
- strvec_pushl(&args, "stash", "apply", "--index", "--quiet", NULL);
383
- strvec_push(&args, oid_to_hex(stash));
382
+ strvec_pushl(&cmd.args, "stash", "apply", "--index", "--quiet", NULL);
383
+ strvec_push(&cmd.args, oid_to_hex(stash));
384
385
/*
386
* It is OK to ignore error here, for example when there was
387
* nothing to restore.
388
*/
389
- run_command_v_opt(args.v, RUN_GIT_CMD);
390
- strvec_clear(&args);
389
+ cmd.git_cmd = 1;
390
+ run_command(&cmd);
391
392
refresh_cache:
393
if (discard_cache() < 0 || read_cache() < 0)
builtin/pull.c
+71
-76
@@ -515,76 +515,75 @@ static void parse_repo_refspecs(int argc, const char **argv, const char **repo,
515
*/
516
static int run_fetch(const char *repo, const char **refspecs)
517
{
518
- struct strvec args = STRVEC_INIT;
519
- int ret;
518
+ struct child_process cmd = CHILD_PROCESS_INIT;
519
521
- strvec_pushl(&args, "fetch", "--update-head-ok", NULL);
520
+ strvec_pushl(&cmd.args, "fetch", "--update-head-ok", NULL);
521
522
/* Shared options */
524
- argv_push_verbosity(&args);
523
+ argv_push_verbosity(&cmd.args);
524
if (opt_progress)
526
- strvec_push(&args, opt_progress);
525
+ strvec_push(&cmd.args, opt_progress);
526
527
/* Options passed to git-fetch */
528
if (opt_all)
530
- strvec_push(&args, opt_all);
529
+ strvec_push(&cmd.args, opt_all);
530
if (opt_append)
532
- strvec_push(&args, opt_append);
531
+ strvec_push(&cmd.args, opt_append);
532
if (opt_upload_pack)
534
- strvec_push(&args, opt_upload_pack);
535
- argv_push_force(&args);
533
+ strvec_push(&cmd.args, opt_upload_pack);
534
+ argv_push_force(&cmd.args);
535
if (opt_tags)
537
- strvec_push(&args, opt_tags);
536
+ strvec_push(&cmd.args, opt_tags);
537
if (opt_prune)
539
- strvec_push(&args, opt_prune);
538
+ strvec_push(&cmd.args, opt_prune);
539
if (recurse_submodules_cli != RECURSE_SUBMODULES_DEFAULT)
540
switch (recurse_submodules_cli) {
541
case RECURSE_SUBMODULES_ON:
543
- strvec_push(&args, "--recurse-submodules=on");
542
+ strvec_push(&cmd.args, "--recurse-submodules=on");
543
break;
544
case RECURSE_SUBMODULES_OFF:
546
- strvec_push(&args, "--recurse-submodules=no");
545
+ strvec_push(&cmd.args, "--recurse-submodules=no");
546
break;
547
case RECURSE_SUBMODULES_ON_DEMAND:
549
- strvec_push(&args, "--recurse-submodules=on-demand");
548
+ strvec_push(&cmd.args, "--recurse-submodules=on-demand");
549
break;
550
default:
551
BUG("submodule recursion option not understood");
552
}
553
if (max_children)
555
- strvec_push(&args, max_children);
554
+ strvec_push(&cmd.args, max_children);
555
if (opt_dry_run)
557
- strvec_push(&args, "--dry-run");
556
+ strvec_push(&cmd.args, "--dry-run");
557
if (opt_keep)
559
- strvec_push(&args, opt_keep);
558
+ strvec_push(&cmd.args, opt_keep);
559
if (opt_depth)
561
- strvec_push(&args, opt_depth);
560
+ strvec_push(&cmd.args, opt_depth);
561
if (opt_unshallow)
563
- strvec_push(&args, opt_unshallow);
562
+ strvec_push(&cmd.args, opt_unshallow);
563
if (opt_update_shallow)
565
- strvec_push(&args, opt_update_shallow);
564
+ strvec_push(&cmd.args, opt_update_shallow);
565
if (opt_refmap)
567
- strvec_push(&args, opt_refmap);
566
+ strvec_push(&cmd.args, opt_refmap);
567
if (opt_ipv4)
569
- strvec_push(&args, opt_ipv4);
568
+ strvec_push(&cmd.args, opt_ipv4);
569
if (opt_ipv6)
571
- strvec_push(&args, opt_ipv6);
570
+ strvec_push(&cmd.args, opt_ipv6);
571
if (opt_show_forced_updates > 0)
573
- strvec_push(&args, "--show-forced-updates");
572
+ strvec_push(&cmd.args, "--show-forced-updates");
573
else if (opt_show_forced_updates == 0)
575
- strvec_push(&args, "--no-show-forced-updates");
574
+ strvec_push(&cmd.args, "--no-show-forced-updates");
575
if (set_upstream)
577
- strvec_push(&args, set_upstream);
578
- strvec_pushv(&args, opt_fetch.v);
576
+ strvec_push(&cmd.args, set_upstream);
577
+ strvec_pushv(&cmd.args, opt_fetch.v);
578
579
if (repo) {
581
- strvec_push(&args, repo);
582
- strvec_pushv(&args, refspecs);
580
+ strvec_push(&cmd.args, repo);
581
+ strvec_pushv(&cmd.args, refspecs);
582
} else if (*refspecs)
583
BUG("refspecs without repo?");
585
- ret = run_command_v_opt(args.v, RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE);
586
- strvec_clear(&args);
587
- return ret;
584
+ cmd.git_cmd = 1;
585
+ cmd.close_object_store = 1;
586
+ return run_command(&cmd);
587
}
588
589
/**
@@ -653,52 +652,50 @@ static int update_submodules(void)
652
*/
653
static int run_merge(void)
654
{
656
- int ret;
657
- struct strvec args = STRVEC_INIT;
655
+ struct child_process cmd = CHILD_PROCESS_INIT;
656
659
- strvec_pushl(&args, "merge", NULL);
657
+ strvec_pushl(&cmd.args, "merge", NULL);
658
659
/* Shared options */
662
- argv_push_verbosity(&args);
660
+ argv_push_verbosity(&cmd.args);
661
if (opt_progress)
664
- strvec_push(&args, opt_progress);
662
+ strvec_push(&cmd.args, opt_progress);
663
664
/* Options passed to git-merge */
665
if (opt_diffstat)
668
- strvec_push(&args, opt_diffstat);
666
+ strvec_push(&cmd.args, opt_diffstat);
667
if (opt_log)
670
- strvec_push(&args, opt_log);
668
+ strvec_push(&cmd.args, opt_log);
669
if (opt_signoff)
672
- strvec_push(&args, opt_signoff);
670
+ strvec_push(&cmd.args, opt_signoff);
671
if (opt_squash)
674
- strvec_push(&args, opt_squash);
672
+ strvec_push(&cmd.args, opt_squash);
673
if (opt_commit)
676
- strvec_push(&args, opt_commit);
674
+ strvec_push(&cmd.args, opt_commit);
675
if (opt_edit)
678
- strvec_push(&args, opt_edit);
676
+ strvec_push(&cmd.args, opt_edit);
677
if (cleanup_arg)
680
- strvec_pushf(&args, "--cleanup=%s", cleanup_arg);
678
+ strvec_pushf(&cmd.args, "--cleanup=%s", cleanup_arg);
679
if (opt_ff)
682
- strvec_push(&args, opt_ff);
680
+ strvec_push(&cmd.args, opt_ff);
681
if (opt_verify)
684
- strvec_push(&args, opt_verify);
682
+ strvec_push(&cmd.args, opt_verify);
683
if (opt_verify_signatures)
686
- strvec_push(&args, opt_verify_signatures);
687
- strvec_pushv(&args, opt_strategies.v);
688
- strvec_pushv(&args, opt_strategy_opts.v);
684
+ strvec_push(&cmd.args, opt_verify_signatures);
685
+ strvec_pushv(&cmd.args, opt_strategies.v);
686
+ strvec_pushv(&cmd.args, opt_strategy_opts.v);
687
if (opt_gpg_sign)
690
- strvec_push(&args, opt_gpg_sign);
688
+ strvec_push(&cmd.args, opt_gpg_sign);
689
if (opt_autostash == 0)
692
- strvec_push(&args, "--no-autostash");
690
+ strvec_push(&cmd.args, "--no-autostash");
691
else if (opt_autostash == 1)
694
- strvec_push(&args, "--autostash");
692
+ strvec_push(&cmd.args, "--autostash");
693
if (opt_allow_unrelated_histories > 0)
696
- strvec_push(&args, "--allow-unrelated-histories");
694
+ strvec_push(&cmd.args, "--allow-unrelated-histories");
695
698
- strvec_push(&args, "FETCH_HEAD");
699
- ret = run_command_v_opt(args.v, RUN_GIT_CMD);
700
- strvec_clear(&args);
701
- return ret;
696
+ strvec_push(&cmd.args, "FETCH_HEAD");
697
+ cmd.git_cmd = 1;
698
+ return run_command(&cmd);
699
}
700
701
/**
@@ -879,43 +876,41 @@ static int get_rebase_newbase_and_upstream(struct object_id *newbase,
876
static int run_rebase(const struct object_id *newbase,
877
const struct object_id *upstream)
878
{
882
- int ret;
883
- struct strvec args = STRVEC_INIT;
879
+ struct child_process cmd = CHILD_PROCESS_INIT;
880
885
- strvec_push(&args, "rebase");
881
+ strvec_push(&cmd.args, "rebase");
882
883
/* Shared options */
888
- argv_push_verbosity(&args);
884
+ argv_push_verbosity(&cmd.args);
885
886
/* Options passed to git-rebase */
887
if (opt_rebase == REBASE_MERGES)
892
- strvec_push(&args, "--rebase-merges");
888
+ strvec_push(&cmd.args, "--rebase-merges");
889
else if (opt_rebase == REBASE_INTERACTIVE)
894
- strvec_push(&args, "--interactive");
890
+ strvec_push(&cmd.args, "--interactive");
891
if (opt_diffstat)
896
- strvec_push(&args, opt_diffstat);
897
- strvec_pushv(&args, opt_strategies.v);
898
- strvec_pushv(&args, opt_strategy_opts.v);
892
+ strvec_push(&cmd.args, opt_diffstat);
893
+ strvec_pushv(&cmd.args, opt_strategies.v);
894
+ strvec_pushv(&cmd.args, opt_strategy_opts.v);
895
if (opt_gpg_sign)
900
- strvec_push(&args, opt_gpg_sign);
896
+ strvec_push(&cmd.args, opt_gpg_sign);
897
if (opt_signoff)
902
- strvec_push(&args, opt_signoff);
898
+ strvec_push(&cmd.args, opt_signoff);
899
if (opt_autostash == 0)
904
- strvec_push(&args, "--no-autostash");
900
+ strvec_push(&cmd.args, "--no-autostash");
901
else if (opt_autostash == 1)
906
- strvec_push(&args, "--autostash");
902
+ strvec_push(&cmd.args, "--autostash");
903
if (opt_verify_signatures &&
904
!strcmp(opt_verify_signatures, "--verify-signatures"))
905
warning(_("ignoring --verify-signatures for rebase"));
906
911
- strvec_push(&args, "--onto");
912
- strvec_push(&args, oid_to_hex(newbase));
907
+ strvec_push(&cmd.args, "--onto");
908
+ strvec_push(&cmd.args, oid_to_hex(newbase));
909
914
- strvec_push(&args, oid_to_hex(upstream));
910
+ strvec_push(&cmd.args, oid_to_hex(upstream));
911
916
- ret = run_command_v_opt(args.v, RUN_GIT_CMD);
917
- strvec_clear(&args);
918
- return ret;
912
+ cmd.git_cmd = 1;
913
+ return run_command(&cmd);
914
}
915
916
static int get_can_ff(struct object_id *orig_head,
builtin/remote.c
+12
-14
@@ -1510,37 +1510,35 @@ static int update(int argc, const char **argv, const char *prefix)
1510
N_("prune remotes after fetching")),
1511
OPT_END()
1512
};
1513
- struct strvec fetch_argv = STRVEC_INIT;
1513
+ struct child_process cmd = CHILD_PROCESS_INIT;
1514
int default_defined = 0;
1515
- int retval;
1515
1516
argc = parse_options(argc, argv, prefix, options,
1517
builtin_remote_update_usage,
1518
PARSE_OPT_KEEP_ARGV0);
1519
1521
- strvec_push(&fetch_argv, "fetch");
1520
+ strvec_push(&cmd.args, "fetch");
1521
1522
if (prune != -1)
1524
- strvec_push(&fetch_argv, prune ? "--prune" : "--no-prune");
1523
+ strvec_push(&cmd.args, prune ? "--prune" : "--no-prune");
1524
if (verbose)
1526
- strvec_push(&fetch_argv, "-v");
1527
- strvec_push(&fetch_argv, "--multiple");
1525
+ strvec_push(&cmd.args, "-v");
1526
+ strvec_push(&cmd.args, "--multiple");
1527
if (argc < 2)
1529
- strvec_push(&fetch_argv, "default");
1528
+ strvec_push(&cmd.args, "default");
1529
for (i = 1; i < argc; i++)
1531
- strvec_push(&fetch_argv, argv[i]);
1530
+ strvec_push(&cmd.args, argv[i]);
1531
1533
- if (strcmp(fetch_argv.v[fetch_argv.nr-1], "default") == 0) {
1532
+ if (strcmp(cmd.args.v[cmd.args.nr-1], "default") == 0) {
1533
git_config(get_remote_default, &default_defined);
1534
if (!default_defined) {
1536
- strvec_pop(&fetch_argv);
1537
- strvec_push(&fetch_argv, "--all");
1535
+ strvec_pop(&cmd.args);
1536
+ strvec_push(&cmd.args, "--all");
1537
}
1538
}
1539
1541
- retval = run_command_v_opt(fetch_argv.v, RUN_GIT_CMD);
1542
- strvec_clear(&fetch_argv);
1543
- return retval;
1540
+ cmd.git_cmd = 1;
1541
+ return run_command(&cmd);
1542
}
1543
1544
static int remove_all_fetch_refspecs(const char *key)
diff.c
+13
-14
@@ -4278,35 +4278,34 @@ static void run_external_diff(const char *pgm,
4278
const char *xfrm_msg,
4279
struct diff_options *o)
4280
{
4281
- struct strvec argv = STRVEC_INIT;
4282
- struct strvec env = STRVEC_INIT;
4281
+ struct child_process cmd = CHILD_PROCESS_INIT;
4282
struct diff_queue_struct *q = &diff_queued_diff;
4283
4285
- strvec_push(&argv, pgm);
4286
- strvec_push(&argv, name);
4284
+ strvec_push(&cmd.args, pgm);
4285
+ strvec_push(&cmd.args, name);
4286
4287
if (one && two) {
4289
- add_external_diff_name(o->repo, &argv, name, one);
4288
+ add_external_diff_name(o->repo, &cmd.args, name, one);
4289
if (!other)
4291
- add_external_diff_name(o->repo, &argv, name, two);
4290
+ add_external_diff_name(o->repo, &cmd.args, name, two);
4291
else {
4293
- add_external_diff_name(o->repo, &argv, other, two);
4294
- strvec_push(&argv, other);
4295
- strvec_push(&argv, xfrm_msg);
4292
+ add_external_diff_name(o->repo, &cmd.args, other, two);
4293
+ strvec_push(&cmd.args, other);
4294
+ strvec_push(&cmd.args, xfrm_msg);
4295
}
4296
}
4297
4299
- strvec_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
4300
- strvec_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
4298
+ strvec_pushf(&cmd.env, "GIT_DIFF_PATH_COUNTER=%d",
4299
+ ++o->diff_path_counter);
4300
+ strvec_pushf(&cmd.env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
4301
4302
diff_free_filespec_data(one);
4303
diff_free_filespec_data(two);
4304
- if (run_command_v_opt_cd_env(argv.v, RUN_USING_SHELL, NULL, env.v))
4304
+ cmd.use_shell = 1;
4305
+ if (run_command(&cmd))
4306
die(_("external diff died, stopping at %s"), name);
4307
4308
remove_tempfile();
4308
- strvec_clear(&argv);
4309
- strvec_clear(&env);
4309
}
4310
4311
static int similarity_index(struct diff_filepair *p)
git.c
+9
-6
@@ -787,7 +787,7 @@ static int run_argv(int *argcp, const char ***argv)
787
if (!done_alias)
788
handle_builtin(*argcp, *argv);
789
else if (get_builtin(**argv)) {
790
- struct strvec args = STRVEC_INIT;
790
+ struct child_process cmd = CHILD_PROCESS_INIT;
791
int i;
792
793
/*
@@ -804,18 +804,21 @@ static int run_argv(int *argcp, const char ***argv)
804
805
commit_pager_choice();
806
807
- strvec_push(&args, "git");
807
+ strvec_push(&cmd.args, "git");
808
for (i = 0; i < *argcp; i++)
809
- strvec_push(&args, (*argv)[i]);
809
+ strvec_push(&cmd.args, (*argv)[i]);
810
811
- trace_argv_printf(args.v, "trace: exec:");
811
+ trace_argv_printf(cmd.args.v, "trace: exec:");
812
813
/*
814
* if we fail because the command is not found, it is
815
* OK to return. Otherwise, we just pass along the status code.
816
*/
817
- i = run_command_v_opt_tr2(args.v, RUN_SILENT_EXEC_FAILURE |
818
- RUN_CLEAN_ON_EXIT | RUN_WAIT_AFTER_CLEAN, "git_alias");
817
+ cmd.silent_exec_failure = 1;
818
+ cmd.clean_on_exit = 1;
819
+ cmd.wait_after_clean = 1;
820
+ cmd.trace2_child_class = "git_alias";
821
+ i = run_command(&cmd);
822
if (i >= 0 || errno != ENOENT)
823
exit(i);
824
die("could not execute builtin %s", **argv);
merge.c
+9
-9
@@ -19,22 +19,22 @@ int try_merge_command(struct repository *r,
19
const char **xopts, struct commit_list *common,
20
const char *head_arg, struct commit_list *remotes)
21
{
22
- struct strvec args = STRVEC_INIT;
22
+ struct child_process cmd = CHILD_PROCESS_INIT;
23
int i, ret;
24
struct commit_list *j;
25
26
- strvec_pushf(&args, "merge-%s", strategy);
26
+ strvec_pushf(&cmd.args, "merge-%s", strategy);
27
for (i = 0; i < xopts_nr; i++)
28
- strvec_pushf(&args, "--%s", xopts[i]);
28
+ strvec_pushf(&cmd.args, "--%s", xopts[i]);
29
for (j = common; j; j = j->next)
30
- strvec_push(&args, merge_argument(j->item));
31
- strvec_push(&args, "--");
32
- strvec_push(&args, head_arg);
30
+ strvec_push(&cmd.args, merge_argument(j->item));
31
+ strvec_push(&cmd.args, "--");
32
+ strvec_push(&cmd.args, head_arg);
33
for (j = remotes; j; j = j->next)
34
- strvec_push(&args, merge_argument(j->item));
34
+ strvec_push(&cmd.args, merge_argument(j->item));
35
36
- ret = run_command_v_opt(args.v, RUN_GIT_CMD);
37
- strvec_clear(&args);
36
+ cmd.git_cmd = 1;
37
+ ret = run_command(&cmd);
38
39
discard_index(r->index);
40
if (repo_read_index(r) < 0)
scalar.c
+5
-8
@@ -69,21 +69,18 @@ static void setup_enlistment_directory(int argc, const char **argv,
69
70
static int run_git(const char *arg, ...)
71
{
72
- struct strvec argv = STRVEC_INIT;
72
+ struct child_process cmd = CHILD_PROCESS_INIT;
73
va_list args;
74
const char *p;
75
- int res;
75
76
va_start(args, arg);
78
- strvec_push(&argv, arg);
77
+ strvec_push(&cmd.args, arg);
78
while ((p = va_arg(args, const char *)))
80
- strvec_push(&argv, p);
79
+ strvec_push(&cmd.args, p);
80
va_end(args);
81
83
- res = run_command_v_opt(argv.v, RUN_GIT_CMD);
84
-
85
- strvec_clear(&argv);
86
- return res;
82
+ cmd.git_cmd = 1;
83
+ return run_command(&cmd);
84
}
85
86
struct scalar_config {
sequencer.c
+10
-15
@@ -3183,18 +3183,15 @@ static int rollback_is_safe(void)
3183
3184
static int reset_merge(const struct object_id *oid)
3185
{
3186
- int ret;
3187
- struct strvec argv = STRVEC_INIT;
3186
+ struct child_process cmd = CHILD_PROCESS_INIT;
3187
3189
- strvec_pushl(&argv, "reset", "--merge", NULL);
3188
+ cmd.git_cmd = 1;
3189
+ strvec_pushl(&cmd.args, "reset", "--merge", NULL);
3190
3191
if (!is_null_oid(oid))
3192
- strvec_push(&argv, oid_to_hex(oid));
3192
+ strvec_push(&cmd.args, oid_to_hex(oid));
3193
3194
- ret = run_command_v_opt(argv.v, RUN_GIT_CMD);
3195
- strvec_clear(&argv);
3196
-
3197
- return ret;
3194
+ return run_command(&cmd);
3195
}
3196
3197
static int rollback_single_pick(struct repository *r)
@@ -4866,14 +4863,14 @@ cleanup_head_ref:
4863
4864
static int continue_single_pick(struct repository *r, struct replay_opts *opts)
4865
{
4869
- struct strvec argv = STRVEC_INIT;
4870
- int ret;
4866
+ struct child_process cmd = CHILD_PROCESS_INIT;
4867
4868
if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
4869
!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
4870
return error(_("no cherry-pick or revert in progress"));
4871
4876
- strvec_push(&argv, "commit");
4872
+ cmd.git_cmd = 1;
4873
+ strvec_push(&cmd.args, "commit");
4874
4875
/*
4876
* continue_single_pick() handles the case of recovering from a
@@ -4886,11 +4883,9 @@ static int continue_single_pick(struct repository *r, struct replay_opts *opts)
4883
* Include --cleanup=strip as well because we don't want the
4884
* "# Conflicts:" messages.
4885
*/
4889
- strvec_pushl(&argv, "--no-edit", "--cleanup=strip", NULL);
4886
+ strvec_pushl(&cmd.args, "--no-edit", "--cleanup=strip", NULL);
4887
4891
- ret = run_command_v_opt(argv.v, RUN_GIT_CMD);
4892
- strvec_clear(&argv);
4893
- return ret;
4888
+ return run_command(&cmd);
4889
}
4890
4891
static int commit_staged_changes(struct repository *r,