Skip to content

Commit 29fda24

Browse files
avargitster
authored andcommitted
run-command API: rename "env_array" to "env"
Start following-up on the rename mentioned in c7c4bde (run-command API: remove "env" member, always use "env_array", 2021-11-25) of "env_array" to "env". The "env_array" name was picked in 19a583d (run-command: add env_array, an optional argv_array for env, 2014-10-19) because "env" was taken. Let's not forever keep the oddity of "*_array" for this "struct strvec", but not for its "args" sibling. This commit is almost entirely made with a coccinelle rule[1]. The only manual change here is in run-command.h to rename the struct member itself and to change "env_array" to "env" in the CHILD_PROCESS_INIT initializer. The rest of this is all a result of applying [1]: * make contrib/coccinelle/run_command.cocci.patch * patch -p1 <contrib/coccinelle/run_command.cocci.patch * git add -u 1. cat contrib/coccinelle/run_command.pending.cocci @@ struct child_process E; @@ - E.env_array + E.env @@ struct child_process *E; @@ - E->env_array + E->env I've avoided changing any comments and derived variable names here, that will all be done in the next commit. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 07330a4 commit 29fda24

24 files changed

+115
-113
lines changed

add-patch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void setup_child_process(struct add_p_state *s,
305305
va_end(ap);
306306

307307
cp->git_cmd = 1;
308-
strvec_pushf(&cp->env_array,
308+
strvec_pushf(&cp->env,
309309
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
310310
}
311311

branch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ static int submodule_create_branch(struct repository *r,
564564
child.err = -1;
565565
child.stdout_to_stderr = 1;
566566

567-
prepare_other_repo_env(&child.env_array, r->gitdir);
567+
prepare_other_repo_env(&child.env, r->gitdir);
568568
/*
569569
* submodule_create_branch() is indirectly invoked by "git
570570
* branch", but we cannot invoke "git branch" in the child

builtin/difftool.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
217217
update_index.use_shell = 0;
218218
update_index.clean_on_exit = 1;
219219
update_index.dir = workdir;
220-
strvec_pushf(&update_index.env_array, "GIT_INDEX_FILE=%s", index_path);
220+
strvec_pushf(&update_index.env, "GIT_INDEX_FILE=%s", index_path);
221221
/* Ignore any errors of update-index */
222222
run_command(&update_index);
223223

@@ -230,7 +230,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
230230
diff_files.clean_on_exit = 1;
231231
diff_files.out = -1;
232232
diff_files.dir = workdir;
233-
strvec_pushf(&diff_files.env_array, "GIT_INDEX_FILE=%s", index_path);
233+
strvec_pushf(&diff_files.env, "GIT_INDEX_FILE=%s", index_path);
234234
if (start_command(&diff_files))
235235
die("could not obtain raw diff");
236236
fp = xfdopen(diff_files.out, "r");
@@ -675,7 +675,7 @@ static int run_file_diff(int prompt, const char *prefix,
675675

676676
child->git_cmd = 1;
677677
child->dir = prefix;
678-
strvec_pushv(&child->env_array, env);
678+
strvec_pushv(&child->env, env);
679679

680680
return run_command(child);
681681
}

builtin/receive-pack.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -764,23 +764,23 @@ static void prepare_push_cert_sha1(struct child_process *proc)
764764
nonce_status = check_nonce(push_cert.buf, bogs);
765765
}
766766
if (!is_null_oid(&push_cert_oid)) {
767-
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s",
767+
strvec_pushf(&proc->env, "GIT_PUSH_CERT=%s",
768768
oid_to_hex(&push_cert_oid));
769-
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s",
769+
strvec_pushf(&proc->env, "GIT_PUSH_CERT_SIGNER=%s",
770770
sigcheck.signer ? sigcheck.signer : "");
771-
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s",
771+
strvec_pushf(&proc->env, "GIT_PUSH_CERT_KEY=%s",
772772
sigcheck.key ? sigcheck.key : "");
773-
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c",
773+
strvec_pushf(&proc->env, "GIT_PUSH_CERT_STATUS=%c",
774774
sigcheck.result);
775775
if (push_cert_nonce) {
776-
strvec_pushf(&proc->env_array,
776+
strvec_pushf(&proc->env,
777777
"GIT_PUSH_CERT_NONCE=%s",
778778
push_cert_nonce);
779-
strvec_pushf(&proc->env_array,
779+
strvec_pushf(&proc->env,
780780
"GIT_PUSH_CERT_NONCE_STATUS=%s",
781781
nonce_status);
782782
if (nonce_status == NONCE_SLOP)
783-
strvec_pushf(&proc->env_array,
783+
strvec_pushf(&proc->env,
784784
"GIT_PUSH_CERT_NONCE_SLOP=%ld",
785785
nonce_stamp_slop);
786786
}
@@ -815,17 +815,17 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,
815815
if (feed_state->push_options) {
816816
size_t i;
817817
for (i = 0; i < feed_state->push_options->nr; i++)
818-
strvec_pushf(&proc.env_array,
818+
strvec_pushf(&proc.env,
819819
"GIT_PUSH_OPTION_%"PRIuMAX"=%s",
820820
(uintmax_t)i,
821821
feed_state->push_options->items[i].string);
822-
strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%"PRIuMAX"",
822+
strvec_pushf(&proc.env, "GIT_PUSH_OPTION_COUNT=%"PRIuMAX"",
823823
(uintmax_t)feed_state->push_options->nr);
824824
} else
825-
strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT");
825+
strvec_pushf(&proc.env, "GIT_PUSH_OPTION_COUNT");
826826

827827
if (tmp_objdir)
828-
strvec_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir));
828+
strvec_pushv(&proc.env, tmp_objdir_env(tmp_objdir));
829829

830830
if (use_sideband) {
831831
memset(&muxer, 0, sizeof(muxer));
@@ -1357,7 +1357,7 @@ static const char *push_to_deploy(unsigned char *sha1,
13571357

13581358
strvec_pushl(&child.args, "update-index", "-q", "--ignore-submodules",
13591359
"--refresh", NULL);
1360-
strvec_pushv(&child.env_array, env->v);
1360+
strvec_pushv(&child.env, env->v);
13611361
child.dir = work_tree;
13621362
child.no_stdin = 1;
13631363
child.stdout_to_stderr = 1;
@@ -1369,7 +1369,7 @@ static const char *push_to_deploy(unsigned char *sha1,
13691369
child_process_init(&child);
13701370
strvec_pushl(&child.args, "diff-files", "--quiet",
13711371
"--ignore-submodules", "--", NULL);
1372-
strvec_pushv(&child.env_array, env->v);
1372+
strvec_pushv(&child.env, env->v);
13731373
child.dir = work_tree;
13741374
child.no_stdin = 1;
13751375
child.stdout_to_stderr = 1;
@@ -1383,7 +1383,7 @@ static const char *push_to_deploy(unsigned char *sha1,
13831383
/* diff-index with either HEAD or an empty tree */
13841384
head_has_history() ? "HEAD" : empty_tree_oid_hex(),
13851385
"--", NULL);
1386-
strvec_pushv(&child.env_array, env->v);
1386+
strvec_pushv(&child.env, env->v);
13871387
child.no_stdin = 1;
13881388
child.no_stdout = 1;
13891389
child.stdout_to_stderr = 0;
@@ -1394,7 +1394,7 @@ static const char *push_to_deploy(unsigned char *sha1,
13941394
child_process_init(&child);
13951395
strvec_pushl(&child.args, "read-tree", "-u", "-m", hash_to_hex(sha1),
13961396
NULL);
1397-
strvec_pushv(&child.env_array, env->v);
1397+
strvec_pushv(&child.env, env->v);
13981398
child.dir = work_tree;
13991399
child.no_stdin = 1;
14001400
child.no_stdout = 1;
@@ -2215,7 +2215,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
22152215
return "unable to create temporary object directory";
22162216
}
22172217
if (tmp_objdir)
2218-
strvec_pushv(&child.env_array, tmp_objdir_env(tmp_objdir));
2218+
strvec_pushv(&child.env, tmp_objdir_env(tmp_objdir));
22192219

22202220
/*
22212221
* Normally we just pass the tmp_objdir environment to the child

builtin/stash.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static int restore_untracked(struct object_id *u_tree)
356356
cp.git_cmd = 1;
357357
strvec_push(&cp.args, "read-tree");
358358
strvec_push(&cp.args, oid_to_hex(u_tree));
359-
strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
359+
strvec_pushf(&cp.env, "GIT_INDEX_FILE=%s",
360360
stash_index_path.buf);
361361
if (run_command(&cp)) {
362362
remove_path(stash_index_path.buf);
@@ -366,7 +366,7 @@ static int restore_untracked(struct object_id *u_tree)
366366
child_process_init(&cp);
367367
cp.git_cmd = 1;
368368
strvec_pushl(&cp.args, "checkout-index", "--all", NULL);
369-
strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
369+
strvec_pushf(&cp.env, "GIT_INDEX_FILE=%s",
370370
stash_index_path.buf);
371371

372372
res = run_command(&cp);
@@ -585,9 +585,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
585585
*/
586586
cp.git_cmd = 1;
587587
cp.dir = prefix;
588-
strvec_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s",
588+
strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s",
589589
absolute_path(get_git_work_tree()));
590-
strvec_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s",
590+
strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s",
591591
absolute_path(get_git_dir()));
592592
strvec_push(&cp.args, "status");
593593
run_command(&cp);
@@ -1088,7 +1088,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
10881088
cp_upd_index.git_cmd = 1;
10891089
strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
10901090
"--remove", "--stdin", NULL);
1091-
strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
1091+
strvec_pushf(&cp_upd_index.env, "GIT_INDEX_FILE=%s",
10921092
stash_index_path.buf);
10931093

10941094
strbuf_addf(&untracked_msg, "untracked files on %s\n", msg->buf);
@@ -1162,7 +1162,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
11621162

11631163
cp_read_tree.git_cmd = 1;
11641164
strvec_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL);
1165-
strvec_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s",
1165+
strvec_pushf(&cp_read_tree.env, "GIT_INDEX_FILE=%s",
11661166
stash_index_path.buf);
11671167
if (run_command(&cp_read_tree)) {
11681168
ret = -1;
@@ -1249,7 +1249,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
12491249
strvec_pushl(&cp_upd_index.args, "update-index",
12501250
"--ignore-skip-worktree-entries",
12511251
"-z", "--add", "--remove", "--stdin", NULL);
1252-
strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
1252+
strvec_pushf(&cp_upd_index.env, "GIT_INDEX_FILE=%s",
12531253
stash_index_path.buf);
12541254

12551255
if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len,
@@ -1525,7 +1525,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
15251525
cp.git_cmd = 1;
15261526
if (startup_info->original_cwd) {
15271527
cp.dir = startup_info->original_cwd;
1528-
strvec_pushf(&cp.env_array, "%s=%s",
1528+
strvec_pushf(&cp.env, "%s=%s",
15291529
GIT_WORK_TREE_ENVIRONMENT,
15301530
the_repository->worktree);
15311531
}

builtin/submodule--helper.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static char *compute_rev_name(const char *sub_path, const char* object_id)
292292

293293
for (d = describe_argv; *d; d++) {
294294
struct child_process cp = CHILD_PROCESS_INIT;
295-
prepare_submodule_repo_env(&cp.env_array);
295+
prepare_submodule_repo_env(&cp.env);
296296
cp.dir = sub_path;
297297
cp.git_cmd = 1;
298298
cp.no_stderr = 1;
@@ -479,7 +479,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
479479
if (!is_submodule_populated_gently(path, NULL))
480480
goto cleanup;
481481

482-
prepare_submodule_repo_env(&cp.env_array);
482+
prepare_submodule_repo_env(&cp.env);
483483

484484
/*
485485
* For the purpose of executing <command> in the submodule,
@@ -499,12 +499,12 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
499499
char *toplevel = xgetcwd();
500500
struct strbuf sb = STRBUF_INIT;
501501

502-
strvec_pushf(&cp.env_array, "name=%s", sub->name);
503-
strvec_pushf(&cp.env_array, "sm_path=%s", path);
504-
strvec_pushf(&cp.env_array, "displaypath=%s", displaypath);
505-
strvec_pushf(&cp.env_array, "sha1=%s",
502+
strvec_pushf(&cp.env, "name=%s", sub->name);
503+
strvec_pushf(&cp.env, "sm_path=%s", path);
504+
strvec_pushf(&cp.env, "displaypath=%s", displaypath);
505+
strvec_pushf(&cp.env, "sha1=%s",
506506
oid_to_hex(ce_oid));
507-
strvec_pushf(&cp.env_array, "toplevel=%s", toplevel);
507+
strvec_pushf(&cp.env, "toplevel=%s", toplevel);
508508

509509
/*
510510
* Since the path variable was accessible from the script
@@ -536,7 +536,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
536536

537537
cpr.git_cmd = 1;
538538
cpr.dir = path;
539-
prepare_submodule_repo_env(&cpr.env_array);
539+
prepare_submodule_repo_env(&cpr.env);
540540

541541
strvec_pushl(&cpr.args, "--super-prefix", NULL);
542542
strvec_pushf(&cpr.args, "%s/", displaypath);
@@ -833,7 +833,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
833833

834834
cpr.git_cmd = 1;
835835
cpr.dir = path;
836-
prepare_submodule_repo_env(&cpr.env_array);
836+
prepare_submodule_repo_env(&cpr.env);
837837

838838
strvec_push(&cpr.args, "--super-prefix");
839839
strvec_pushf(&cpr.args, "%s/", displaypath);
@@ -955,7 +955,7 @@ static char *verify_submodule_committish(const char *sm_path,
955955

956956
cp_rev_parse.git_cmd = 1;
957957
cp_rev_parse.dir = sm_path;
958-
prepare_submodule_repo_env(&cp_rev_parse.env_array);
958+
prepare_submodule_repo_env(&cp_rev_parse.env);
959959
strvec_pushl(&cp_rev_parse.args, "rev-parse", "-q", "--short", NULL);
960960
strvec_pushf(&cp_rev_parse.args, "%s^0", committish);
961961
strvec_push(&cp_rev_parse.args, "--");
@@ -996,7 +996,7 @@ static void print_submodule_summary(struct summary_cb *info, char *errmsg,
996996

997997
cp_log.git_cmd = 1;
998998
cp_log.dir = p->sm_path;
999-
prepare_submodule_repo_env(&cp_log.env_array);
999+
prepare_submodule_repo_env(&cp_log.env);
10001000
strvec_pushl(&cp_log.args, "log", NULL);
10011001

10021002
if (S_ISGITLINK(p->mod_src) && S_ISGITLINK(p->mod_dst)) {
@@ -1113,7 +1113,7 @@ static void generate_submodule_summary(struct summary_cb *info,
11131113

11141114
cp_rev_list.git_cmd = 1;
11151115
cp_rev_list.dir = p->sm_path;
1116-
prepare_submodule_repo_env(&cp_rev_list.env_array);
1116+
prepare_submodule_repo_env(&cp_rev_list.env);
11171117

11181118
if (!capture_command(&cp_rev_list, &sb_rev_list, 0))
11191119
total_commits = atoi(sb_rev_list.buf);
@@ -1414,7 +1414,7 @@ static void sync_submodule(const char *path, const char *prefix,
14141414

14151415
cpr.git_cmd = 1;
14161416
cpr.dir = path;
1417-
prepare_submodule_repo_env(&cpr.env_array);
1417+
prepare_submodule_repo_env(&cpr.env);
14181418

14191419
strvec_push(&cpr.args, "--super-prefix");
14201420
strvec_pushf(&cpr.args, "%s/", displaypath);
@@ -1819,7 +1819,7 @@ static int clone_submodule(struct module_clone_data *clone_data)
18191819
strvec_push(&cp.args, clone_data->path);
18201820

18211821
cp.git_cmd = 1;
1822-
prepare_submodule_repo_env(&cp.env_array);
1822+
prepare_submodule_repo_env(&cp.env);
18231823
cp.no_stdin = 1;
18241824

18251825
if(run_command(&cp))
@@ -2295,7 +2295,7 @@ static int is_tip_reachable(const char *path, struct object_id *oid)
22952295
cp.no_stderr = 1;
22962296
strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL);
22972297

2298-
prepare_submodule_repo_env(&cp.env_array);
2298+
prepare_submodule_repo_env(&cp.env);
22992299

23002300
if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len)
23012301
return 0;
@@ -2307,7 +2307,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str
23072307
{
23082308
struct child_process cp = CHILD_PROCESS_INIT;
23092309

2310-
prepare_submodule_repo_env(&cp.env_array);
2310+
prepare_submodule_repo_env(&cp.env);
23112311
cp.git_cmd = 1;
23122312
cp.dir = xstrdup(module_path);
23132313

@@ -2364,7 +2364,7 @@ static int run_update_command(struct update_data *ud, int subforce)
23642364
strvec_push(&cp.args, oid);
23652365

23662366
cp.dir = xstrdup(ud->sm_path);
2367-
prepare_submodule_repo_env(&cp.env_array);
2367+
prepare_submodule_repo_env(&cp.env);
23682368
if (run_command(&cp)) {
23692369
switch (ud->update_strategy.type) {
23702370
case SM_UPDATE_CHECKOUT:
@@ -2630,7 +2630,7 @@ static int update_submodule(struct update_data *update_data)
26302630

26312631
cp.dir = update_data->sm_path;
26322632
cp.git_cmd = 1;
2633-
prepare_submodule_repo_env(&cp.env_array);
2633+
prepare_submodule_repo_env(&cp.env);
26342634
update_data_to_args(&next, &cp.args);
26352635

26362636
/* die() if child process die()'d */
@@ -3123,9 +3123,9 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
31233123
struct strbuf sb_remote_out = STRBUF_INIT;
31243124

31253125
cp_remote.git_cmd = 1;
3126-
strvec_pushf(&cp_remote.env_array,
3126+
strvec_pushf(&cp_remote.env,
31273127
"GIT_DIR=%s", git_dir_path);
3128-
strvec_push(&cp_remote.env_array, "GIT_WORK_TREE=.");
3128+
strvec_push(&cp_remote.env, "GIT_WORK_TREE=.");
31293129
strvec_pushl(&cp_remote.args, "remote", "-v", NULL);
31303130
if (!capture_command(&cp_remote, &sb_remote_out, 0)) {
31313131
char *next_line;
@@ -3209,7 +3209,7 @@ static int add_submodule(const struct add_data *add_data)
32093209
if (clone_submodule(&clone_data))
32103210
return -1;
32113211

3212-
prepare_submodule_repo_env(&cp.env_array);
3212+
prepare_submodule_repo_env(&cp.env);
32133213
cp.git_cmd = 1;
32143214
cp.dir = add_data->sm_path;
32153215
/*

builtin/worktree.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int checkout_worktree(const struct add_opts *opts,
301301
strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
302302
if (opts->quiet)
303303
strvec_push(&cp.args, "--quiet");
304-
strvec_pushv(&cp.env_array, child_env->v);
304+
strvec_pushv(&cp.env, child_env->v);
305305
return run_command(&cp);
306306
}
307307

@@ -433,7 +433,7 @@ static int add_worktree(const char *path, const char *refname,
433433
strvec_push(&cp.args, "--quiet");
434434
}
435435

436-
strvec_pushv(&cp.env_array, child_env.v);
436+
strvec_pushv(&cp.env, child_env.v);
437437
ret = run_command(&cp);
438438
if (ret)
439439
goto done;
@@ -989,9 +989,9 @@ static void check_clean_worktree(struct worktree *wt,
989989
validate_no_submodules(wt);
990990

991991
child_process_init(&cp);
992-
strvec_pushf(&cp.env_array, "%s=%s/.git",
992+
strvec_pushf(&cp.env, "%s=%s/.git",
993993
GIT_DIR_ENVIRONMENT, wt->path);
994-
strvec_pushf(&cp.env_array, "%s=%s",
994+
strvec_pushf(&cp.env, "%s=%s",
995995
GIT_WORK_TREE_ENVIRONMENT, wt->path);
996996
strvec_pushl(&cp.args, "status",
997997
"--porcelain", "--ignore-submodules=none",

0 commit comments

Comments
 (0)