worktree: elucidate environment variables intended for child processes

Take advantage of 'struct child_process.env' to make it obvious that environment variables set by add_worktree() are intended specifically for sub-commands it invokes to operate in the new worktree. We assign a local 'struct argv_array' to child_process.env, rather than utilizing the child_process.env_array 'struct argv_array', because future patches will make add_worktree() invoke additional sub-commands, and it's simpler to populate the environment array just once, whereas child_process.env_array gets cleared after each invocation, thus would require re-population for each sub-command. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 17, 2015 at 19:00 UTC ae2a38271f778522ceb9182b94e0024a816e3338
1 file changed +5 -2
builtin/worktree.c
+5 -2
@@ -186,6 +186,7 @@ static int add_worktree(const char *path, const char **child_argv,
186 const char *name;
187 struct stat st;
188 struct child_process cp;
189 + struct argv_array child_env = ARGV_ARRAY_INIT;
190 int counter = 0, len, ret;
191 unsigned char rev[20];
192
@@ -256,11 +257,12 @@ static int add_worktree(const char *path, const char **child_argv,
257 fprintf_ln(stderr, _("Preparing %s (identifier %s)"), path, name);
258
259 setenv("GIT_CHECKOUT_NEW_WORKTREE", "1", 1);
259 - setenv(GIT_DIR_ENVIRONMENT, sb_git.buf, 1);
260 - setenv(GIT_WORK_TREE_ENVIRONMENT, path, 1);
260 + argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
261 + argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
262 memset(&cp, 0, sizeof(cp));
263 cp.git_cmd = 1;
264 cp.argv = child_argv;
265 + cp.env = child_env.argv;
266 ret = run_command(&cp);
267 if (!ret) {
268 is_junk = 0;
@@ -272,6 +274,7 @@ static int add_worktree(const char *path, const char **child_argv,
274 strbuf_reset(&sb);
275 strbuf_addf(&sb, "%s/locked", sb_repo.buf);
276 unlink_or_warn(sb.buf);
277 + argv_array_clear(&child_env);
278 strbuf_release(&sb);
279 strbuf_release(&sb_repo);
280 strbuf_release(&sb_git);