Skip to content

Commit

Permalink
run-command API: rename "env_array" to "env"
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
avar authored and gitster committed Jun 2, 2022
1 parent 07330a4 commit 29fda24
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 113 deletions.
2 changes: 1 addition & 1 deletion add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static void setup_child_process(struct add_p_state *s,
va_end(ap);

cp->git_cmd = 1;
strvec_pushf(&cp->env_array,
strvec_pushf(&cp->env,
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
}

Expand Down
2 changes: 1 addition & 1 deletion branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ static int submodule_create_branch(struct repository *r,
child.err = -1;
child.stdout_to_stderr = 1;

prepare_other_repo_env(&child.env_array, r->gitdir);
prepare_other_repo_env(&child.env, r->gitdir);
/*
* submodule_create_branch() is indirectly invoked by "git
* branch", but we cannot invoke "git branch" in the child
Expand Down
6 changes: 3 additions & 3 deletions builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
update_index.use_shell = 0;
update_index.clean_on_exit = 1;
update_index.dir = workdir;
strvec_pushf(&update_index.env_array, "GIT_INDEX_FILE=%s", index_path);
strvec_pushf(&update_index.env, "GIT_INDEX_FILE=%s", index_path);
/* Ignore any errors of update-index */
run_command(&update_index);

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

child->git_cmd = 1;
child->dir = prefix;
strvec_pushv(&child->env_array, env);
strvec_pushv(&child->env, env);

return run_command(child);
}
Expand Down
32 changes: 16 additions & 16 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,23 +764,23 @@ static void prepare_push_cert_sha1(struct child_process *proc)
nonce_status = check_nonce(push_cert.buf, bogs);
}
if (!is_null_oid(&push_cert_oid)) {
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s",
strvec_pushf(&proc->env, "GIT_PUSH_CERT=%s",
oid_to_hex(&push_cert_oid));
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s",
strvec_pushf(&proc->env, "GIT_PUSH_CERT_SIGNER=%s",
sigcheck.signer ? sigcheck.signer : "");
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s",
strvec_pushf(&proc->env, "GIT_PUSH_CERT_KEY=%s",
sigcheck.key ? sigcheck.key : "");
strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c",
strvec_pushf(&proc->env, "GIT_PUSH_CERT_STATUS=%c",
sigcheck.result);
if (push_cert_nonce) {
strvec_pushf(&proc->env_array,
strvec_pushf(&proc->env,
"GIT_PUSH_CERT_NONCE=%s",
push_cert_nonce);
strvec_pushf(&proc->env_array,
strvec_pushf(&proc->env,
"GIT_PUSH_CERT_NONCE_STATUS=%s",
nonce_status);
if (nonce_status == NONCE_SLOP)
strvec_pushf(&proc->env_array,
strvec_pushf(&proc->env,
"GIT_PUSH_CERT_NONCE_SLOP=%ld",
nonce_stamp_slop);
}
Expand Down Expand Up @@ -815,17 +815,17 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,
if (feed_state->push_options) {
size_t i;
for (i = 0; i < feed_state->push_options->nr; i++)
strvec_pushf(&proc.env_array,
strvec_pushf(&proc.env,
"GIT_PUSH_OPTION_%"PRIuMAX"=%s",
(uintmax_t)i,
feed_state->push_options->items[i].string);
strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%"PRIuMAX"",
strvec_pushf(&proc.env, "GIT_PUSH_OPTION_COUNT=%"PRIuMAX"",
(uintmax_t)feed_state->push_options->nr);
} else
strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT");
strvec_pushf(&proc.env, "GIT_PUSH_OPTION_COUNT");

if (tmp_objdir)
strvec_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir));
strvec_pushv(&proc.env, tmp_objdir_env(tmp_objdir));

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

strvec_pushl(&child.args, "update-index", "-q", "--ignore-submodules",
"--refresh", NULL);
strvec_pushv(&child.env_array, env->v);
strvec_pushv(&child.env, env->v);
child.dir = work_tree;
child.no_stdin = 1;
child.stdout_to_stderr = 1;
Expand All @@ -1369,7 +1369,7 @@ static const char *push_to_deploy(unsigned char *sha1,
child_process_init(&child);
strvec_pushl(&child.args, "diff-files", "--quiet",
"--ignore-submodules", "--", NULL);
strvec_pushv(&child.env_array, env->v);
strvec_pushv(&child.env, env->v);
child.dir = work_tree;
child.no_stdin = 1;
child.stdout_to_stderr = 1;
Expand All @@ -1383,7 +1383,7 @@ static const char *push_to_deploy(unsigned char *sha1,
/* diff-index with either HEAD or an empty tree */
head_has_history() ? "HEAD" : empty_tree_oid_hex(),
"--", NULL);
strvec_pushv(&child.env_array, env->v);
strvec_pushv(&child.env, env->v);
child.no_stdin = 1;
child.no_stdout = 1;
child.stdout_to_stderr = 0;
Expand All @@ -1394,7 +1394,7 @@ static const char *push_to_deploy(unsigned char *sha1,
child_process_init(&child);
strvec_pushl(&child.args, "read-tree", "-u", "-m", hash_to_hex(sha1),
NULL);
strvec_pushv(&child.env_array, env->v);
strvec_pushv(&child.env, env->v);
child.dir = work_tree;
child.no_stdin = 1;
child.no_stdout = 1;
Expand Down Expand Up @@ -2215,7 +2215,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
return "unable to create temporary object directory";
}
if (tmp_objdir)
strvec_pushv(&child.env_array, tmp_objdir_env(tmp_objdir));
strvec_pushv(&child.env, tmp_objdir_env(tmp_objdir));

/*
* Normally we just pass the tmp_objdir environment to the child
Expand Down
16 changes: 8 additions & 8 deletions builtin/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static int restore_untracked(struct object_id *u_tree)
cp.git_cmd = 1;
strvec_push(&cp.args, "read-tree");
strvec_push(&cp.args, oid_to_hex(u_tree));
strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
strvec_pushf(&cp.env, "GIT_INDEX_FILE=%s",
stash_index_path.buf);
if (run_command(&cp)) {
remove_path(stash_index_path.buf);
Expand All @@ -366,7 +366,7 @@ static int restore_untracked(struct object_id *u_tree)
child_process_init(&cp);
cp.git_cmd = 1;
strvec_pushl(&cp.args, "checkout-index", "--all", NULL);
strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s",
strvec_pushf(&cp.env, "GIT_INDEX_FILE=%s",
stash_index_path.buf);

res = run_command(&cp);
Expand Down Expand Up @@ -585,9 +585,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
*/
cp.git_cmd = 1;
cp.dir = prefix;
strvec_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s",
strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s",
absolute_path(get_git_work_tree()));
strvec_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s",
strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s",
absolute_path(get_git_dir()));
strvec_push(&cp.args, "status");
run_command(&cp);
Expand Down Expand Up @@ -1088,7 +1088,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
cp_upd_index.git_cmd = 1;
strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
"--remove", "--stdin", NULL);
strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
strvec_pushf(&cp_upd_index.env, "GIT_INDEX_FILE=%s",
stash_index_path.buf);

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

cp_read_tree.git_cmd = 1;
strvec_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL);
strvec_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s",
strvec_pushf(&cp_read_tree.env, "GIT_INDEX_FILE=%s",
stash_index_path.buf);
if (run_command(&cp_read_tree)) {
ret = -1;
Expand Down Expand Up @@ -1249,7 +1249,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
strvec_pushl(&cp_upd_index.args, "update-index",
"--ignore-skip-worktree-entries",
"-z", "--add", "--remove", "--stdin", NULL);
strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
strvec_pushf(&cp_upd_index.env, "GIT_INDEX_FILE=%s",
stash_index_path.buf);

if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len,
Expand Down Expand Up @@ -1525,7 +1525,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
cp.git_cmd = 1;
if (startup_info->original_cwd) {
cp.dir = startup_info->original_cwd;
strvec_pushf(&cp.env_array, "%s=%s",
strvec_pushf(&cp.env, "%s=%s",
GIT_WORK_TREE_ENVIRONMENT,
the_repository->worktree);
}
Expand Down
42 changes: 21 additions & 21 deletions builtin/submodule--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static char *compute_rev_name(const char *sub_path, const char* object_id)

for (d = describe_argv; *d; d++) {
struct child_process cp = CHILD_PROCESS_INIT;
prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);
cp.dir = sub_path;
cp.git_cmd = 1;
cp.no_stderr = 1;
Expand Down Expand Up @@ -479,7 +479,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
if (!is_submodule_populated_gently(path, NULL))
goto cleanup;

prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);

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

strvec_pushf(&cp.env_array, "name=%s", sub->name);
strvec_pushf(&cp.env_array, "sm_path=%s", path);
strvec_pushf(&cp.env_array, "displaypath=%s", displaypath);
strvec_pushf(&cp.env_array, "sha1=%s",
strvec_pushf(&cp.env, "name=%s", sub->name);
strvec_pushf(&cp.env, "sm_path=%s", path);
strvec_pushf(&cp.env, "displaypath=%s", displaypath);
strvec_pushf(&cp.env, "sha1=%s",
oid_to_hex(ce_oid));
strvec_pushf(&cp.env_array, "toplevel=%s", toplevel);
strvec_pushf(&cp.env, "toplevel=%s", toplevel);

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

cpr.git_cmd = 1;
cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array);
prepare_submodule_repo_env(&cpr.env);

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

cpr.git_cmd = 1;
cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array);
prepare_submodule_repo_env(&cpr.env);

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

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

cp_log.git_cmd = 1;
cp_log.dir = p->sm_path;
prepare_submodule_repo_env(&cp_log.env_array);
prepare_submodule_repo_env(&cp_log.env);
strvec_pushl(&cp_log.args, "log", NULL);

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

cp_rev_list.git_cmd = 1;
cp_rev_list.dir = p->sm_path;
prepare_submodule_repo_env(&cp_rev_list.env_array);
prepare_submodule_repo_env(&cp_rev_list.env);

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

cpr.git_cmd = 1;
cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array);
prepare_submodule_repo_env(&cpr.env);

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

cp.git_cmd = 1;
prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);
cp.no_stdin = 1;

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

prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);

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

prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);
cp.git_cmd = 1;
cp.dir = xstrdup(module_path);

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

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

cp.dir = update_data->sm_path;
cp.git_cmd = 1;
prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);
update_data_to_args(&next, &cp.args);

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

cp_remote.git_cmd = 1;
strvec_pushf(&cp_remote.env_array,
strvec_pushf(&cp_remote.env,
"GIT_DIR=%s", git_dir_path);
strvec_push(&cp_remote.env_array, "GIT_WORK_TREE=.");
strvec_push(&cp_remote.env, "GIT_WORK_TREE=.");
strvec_pushl(&cp_remote.args, "remote", "-v", NULL);
if (!capture_command(&cp_remote, &sb_remote_out, 0)) {
char *next_line;
Expand Down Expand Up @@ -3209,7 +3209,7 @@ static int add_submodule(const struct add_data *add_data)
if (clone_submodule(&clone_data))
return -1;

prepare_submodule_repo_env(&cp.env_array);
prepare_submodule_repo_env(&cp.env);
cp.git_cmd = 1;
cp.dir = add_data->sm_path;
/*
Expand Down
8 changes: 4 additions & 4 deletions builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int checkout_worktree(const struct add_opts *opts,
strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
if (opts->quiet)
strvec_push(&cp.args, "--quiet");
strvec_pushv(&cp.env_array, child_env->v);
strvec_pushv(&cp.env, child_env->v);
return run_command(&cp);
}

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

strvec_pushv(&cp.env_array, child_env.v);
strvec_pushv(&cp.env, child_env.v);
ret = run_command(&cp);
if (ret)
goto done;
Expand Down Expand Up @@ -989,9 +989,9 @@ static void check_clean_worktree(struct worktree *wt,
validate_no_submodules(wt);

child_process_init(&cp);
strvec_pushf(&cp.env_array, "%s=%s/.git",
strvec_pushf(&cp.env, "%s=%s/.git",
GIT_DIR_ENVIRONMENT, wt->path);
strvec_pushf(&cp.env_array, "%s=%s",
strvec_pushf(&cp.env, "%s=%s",
GIT_WORK_TREE_ENVIRONMENT, wt->path);
strvec_pushl(&cp.args, "status",
"--porcelain", "--ignore-submodules=none",
Expand Down
Loading

0 comments on commit 29fda24

Please sign in to comment.