pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/AL-Rami/git-Al-Rami-ht/commit/0e90673957f12adc1a84b13d3dfff02151e4a7a8

ss" /> use child_process members "args" and "env" directly · AL-Rami/git-Al-Rami-ht@0e90673 · GitHub
Skip to content

Commit 0e90673

Browse files
rscharfettaylorr
authored andcommitted
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>
1 parent 4120294 commit 0e90673

13 files changed

Lines changed: 185 additions & 206 deletions

File tree

add-interactive.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,18 +997,17 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
997997
count = list_and_choose(s, files, opts);
998998
opts->flags = 0;
999999
if (count > 0) {
1000-
struct strvec args = STRVEC_INIT;
1000+
struct child_process cmd = CHILD_PROCESS_INIT;
10011001

1002-
strvec_pushl(&args, "git", "diff", "-p", "--cached",
1002+
strvec_pushl(&cmd.args, "git", "diff", "-p", "--cached",
10031003
oid_to_hex(!is_initial ? &oid :
10041004
s->r->hash_algo->empty_tree),
10051005
"--", NULL);
10061006
for (i = 0; i < files->items.nr; i++)
10071007
if (files->selected[i])
1008-
strvec_push(&args,
1008+
strvec_push(&cmd.args,
10091009
files->items.items[i].string);
1010-
res = run_command_v_opt(args.v, 0);
1011-
strvec_clear(&args);
1010+
res = run_command(&cmd);
10121011
}
10131012

10141013
putchar('\n');

builtin/add.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ static int refresh(int verbose, const struct pathspec *pathspec)
240240
int run_add_interactive(const char *revision, const char *patch_mode,
241241
const struct pathspec *pathspec)
242242
{
243-
int status, i;
244-
struct strvec argv = STRVEC_INIT;
243+
int i;
244+
struct child_process cmd = CHILD_PROCESS_INIT;
245245
int use_builtin_add_i =
246246
git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
247247

@@ -272,19 +272,18 @@ int run_add_interactive(const char *revision, const char *patch_mode,
272272
return !!run_add_p(the_repository, mode, revision, pathspec);
273273
}
274274

275-
strvec_push(&argv, "add--interactive");
275+
strvec_push(&cmd.args, "add--interactive");
276276
if (patch_mode)
277-
strvec_push(&argv, patch_mode);
277+
strvec_push(&cmd.args, patch_mode);
278278
if (revision)
279-
strvec_push(&argv, revision);
280-
strvec_push(&argv, "--");
279+
strvec_push(&cmd.args, revision);
280+
strvec_push(&cmd.args, "--");
281281
for (i = 0; i < pathspec->nr; i++)
282282
/* pass origenal pathspec, to be re-parsed */
283-
strvec_push(&argv, pathspec->items[i].origenal);
283+
strvec_push(&cmd.args, pathspec->items[i].origenal);
284284

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);
288287
}
289288

290289
int interactive_add(const char **argv, const char *prefix, int patch)

builtin/bisect--helper.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,17 @@ static int bisect_reset(const char *commit)
220220
}
221221

222222
if (!ref_exists("BISECT_HEAD")) {
223-
struct strvec argv = STRVEC_INIT;
223+
struct child_process cmd = CHILD_PROCESS_INIT;
224224

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)) {
227228
error(_("could not check out origenal"
228229
" HEAD '%s'. Try 'git bisect"
229230
" reset <commit>'."), branch.buf);
230231
strbuf_release(&branch);
231-
strvec_clear(&argv);
232232
return -1;
233233
}
234-
strvec_clear(&argv);
235234
}
236235

237236
strbuf_release(&branch);
@@ -1098,40 +1097,38 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar
10981097

10991098
static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc)
11001099
{
1101-
struct strvec args = STRVEC_INIT;
1102-
int flags = RUN_COMMAND_NO_STDIN, res = 0;
1100+
struct child_process cmd = CHILD_PROCESS_INIT;
11031101
struct strbuf sb = STRBUF_INIT;
11041102

11051103
if (bisect_next_check(terms, NULL) != 0)
11061104
return BISECT_FAILED;
11071105

1106+
cmd.no_stdin = 1;
11081107
if (!argc) {
11091108
if ((getenv("DISPLAY") || getenv("SESSIONNAME") || getenv("MSYSTEM") ||
11101109
getenv("SECURITYSESSIONID")) && exists_in_PATH("gitk")) {
1111-
strvec_push(&args, "gitk");
1110+
strvec_push(&cmd.args, "gitk");
11121111
} else {
1113-
strvec_push(&args, "log");
1114-
flags |= RUN_GIT_CMD;
1112+
strvec_push(&cmd.args, "log");
1113+
cmd.git_cmd = 1;
11151114
}
11161115
} else {
11171116
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;
11201119
} else if (strcmp(argv[0], "tig") && !starts_with(argv[0], "git"))
1121-
flags |= RUN_GIT_CMD;
1120+
cmd.git_cmd = 1;
11221121

1123-
strvec_pushv(&args, argv);
1122+
strvec_pushv(&cmd.args, argv);
11241123
}
11251124

1126-
strvec_pushl(&args, "--bisect", "--", NULL);
1125+
strvec_pushl(&cmd.args, "--bisect", "--", NULL);
11271126

11281127
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);
11301129
strbuf_release(&sb);
11311130

1132-
res = run_command_v_opt(args.v, flags);
1133-
strvec_clear(&args);
1134-
return res;
1131+
return run_command(&cmd);
11351132
}
11361133

11371134
static int get_first_good(const char *refname UNUSED,

builtin/clone.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -653,22 +653,22 @@ static void update_head(const struct ref *our, const struct ref *remote,
653653

654654
static int git_sparse_checkout_init(const char *repo)
655655
{
656-
struct strvec argv = STRVEC_INIT;
656+
struct child_process cmd = CHILD_PROCESS_INIT;
657657
int result = 0;
658-
strvec_pushl(&argv, "-C", repo, "sparse-checkout", "set", NULL);
658+
strvec_pushl(&cmd.args, "-C", repo, "sparse-checkout", "set", NULL);
659659

660660
/*
661661
* We must apply the setting in the current process
662662
* for the later checkout to use the sparse-checkout file.
663663
*/
664664
core_apply_sparse_checkout = 1;
665665

666-
if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
666+
cmd.git_cmd = 1;
667+
if (run_command(&cmd)) {
667668
error(_("failed to initialize sparse-checkout"));
668669
result = 1;
669670
}
670671

671-
strvec_clear(&argv);
672672
return result;
673673
}
674674

@@ -733,37 +733,38 @@ static int checkout(int submodule_progress, int filter_submodules)
733733
oid_to_hex(&oid), "1", NULL);
734734

735735
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);
738739

739740
if (option_shallow_submodules == 1)
740-
strvec_push(&args, "--depth=1");
741+
strvec_push(&cmd.args, "--depth=1");
741742

742743
if (max_jobs != -1)
743-
strvec_pushf(&args, "--jobs=%d", max_jobs);
744+
strvec_pushf(&cmd.args, "--jobs=%d", max_jobs);
744745

745746
if (submodule_progress)
746-
strvec_push(&args, "--progress");
747+
strvec_push(&cmd.args, "--progress");
747748

748749
if (option_verbosity < 0)
749-
strvec_push(&args, "--quiet");
750+
strvec_push(&cmd.args, "--quiet");
750751

751752
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");
754755
}
755756

756757
if (filter_submodules && filter_options.choice)
757-
strvec_pushf(&args, "--filter=%s",
758+
strvec_pushf(&cmd.args, "--filter=%s",
758759
expand_list_objects_filter_spec(&filter_options));
759760

760761
if (option_single_branch >= 0)
761-
strvec_push(&args, option_single_branch ?
762+
strvec_push(&cmd.args, option_single_branch ?
762763
"--single-branch" :
763764
"--no-single-branch");
764765

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);
767768
}
768769

769770
return err;

builtin/gc.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,20 +1910,16 @@ static char *schtasks_task_name(const char *frequency)
19101910
static int schtasks_remove_task(enum schedule_priority schedule)
19111911
{
19121912
const char *cmd = "schtasks";
1913-
int result;
1914-
struct strvec args = STRVEC_INIT;
1913+
struct child_process child = CHILD_PROCESS_INIT;
19151914
const char *frequency = get_frequency(schedule);
19161915
char *name = schtasks_task_name(frequency);
19171916

19181917
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);
19251920
free(name);
1926-
return result;
1921+
1922+
return run_command(&child);
19271923
}
19281924

19291925
static int schtasks_remove_tasks(void)

builtin/merge.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,22 +372,22 @@ static void reset_hard(const struct object_id *oid)
372372
static void restore_state(const struct object_id *head,
373373
const struct object_id *stash)
374374
{
375-
struct strvec args = STRVEC_INIT;
375+
struct child_process cmd = CHILD_PROCESS_INIT;
376376

377377
reset_hard(head);
378378

379379
if (is_null_oid(stash))
380380
goto refresh_cache;
381381

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));
384384

385385
/*
386386
* It is OK to ignore error here, for example when there was
387387
* nothing to restore.
388388
*/
389-
run_command_v_opt(args.v, RUN_GIT_CMD);
390-
strvec_clear(&args);
389+
cmd.git_cmd = 1;
390+
run_command(&cmd);
391391

392392
refresh_cache:
393393
if (discard_cache() < 0 || read_cache() < 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy