summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2015-07-17 23:00:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-07-20 18:29:51 (GMT)
commitae2a38271f778522ceb9182b94e0024a816e3338 (patch)
tree778019ace5095c32e751af820b830b0720ac1ceb /builtin/worktree.c
parentc2842439a3ab9bcab122105f3f457afb37fbc7c1 (diff)
downloadgit-ae2a38271f778522ceb9182b94e0024a816e3338.zip
git-ae2a38271f778522ceb9182b94e0024a816e3338.tar.gz
git-ae2a38271f778522ceb9182b94e0024a816e3338.tar.bz2
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>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 8225468..7bd6f17 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -186,6 +186,7 @@ static int add_worktree(const char *path, const char **child_argv,
const char *name;
struct stat st;
struct child_process cp;
+ struct argv_array child_env = ARGV_ARRAY_INIT;
int counter = 0, len, ret;
unsigned char rev[20];
@@ -256,11 +257,12 @@ static int add_worktree(const char *path, const char **child_argv,
fprintf_ln(stderr, _("Preparing %s (identifier %s)"), path, name);
setenv("GIT_CHECKOUT_NEW_WORKTREE", "1", 1);
- setenv(GIT_DIR_ENVIRONMENT, sb_git.buf, 1);
- setenv(GIT_WORK_TREE_ENVIRONMENT, path, 1);
+ argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
+ argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
memset(&cp, 0, sizeof(cp));
cp.git_cmd = 1;
cp.argv = child_argv;
+ cp.env = child_env.argv;
ret = run_command(&cp);
if (!ret) {
is_junk = 0;
@@ -272,6 +274,7 @@ static int add_worktree(const char *path, const char **child_argv,
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/locked", sb_repo.buf);
unlink_or_warn(sb.buf);
+ argv_array_clear(&child_env);
strbuf_release(&sb);
strbuf_release(&sb_repo);
strbuf_release(&sb_git);