summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ee49314)
raw | patch | inline | side by side (parent: ee49314)
author | Alex Riesen <raa.lkml@gmail.com> | |
Wed, 23 May 2007 20:21:39 +0000 (22:21 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Thu, 24 May 2007 05:38:44 +0000 (22:38 -0700) |
To unset a variable, just specify its name, without "=". For example:
const char *env[] = {"GIT_DIR=.git", "PWD", NULL};
const char *argv[] = {"git-ls-files", "-s", NULL};
int err = run_command_v_opt_cd_env(argv, RUN_GIT_CMD, ".", env);
The PWD will be unset before executing git-ls-files.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
const char *env[] = {"GIT_DIR=.git", "PWD", NULL};
const char *argv[] = {"git-ls-files", "-s", NULL};
int err = run_command_v_opt_cd_env(argv, RUN_GIT_CMD, ".", env);
The PWD will be unset before executing git-ls-files.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
run-command.c | patch | blob | history | |
run-command.h | patch | blob | history |
diff --git a/run-command.c b/run-command.c
index 4ee4bdf16c1c5288d63ed0ba9a4503d04377c19e..7e779d33ee9ea5f7d2e6aedc8c3a0a0476e87135 100644 (file)
--- a/run-command.c
+++ b/run-command.c
die("exec %s: cd to %s failed (%s)", cmd->argv[0],
cmd->dir, strerror(errno));
if (cmd->env) {
- for (; *cmd->env; cmd->env++)
- putenv((char*)*cmd->env);
+ for (; *cmd->env; cmd->env++) {
+ if (strchr(*cmd->env, '='))
+ putenv((char*)*cmd->env);
+ else
+ unsetenv(*cmd->env);
+ }
}
if (cmd->git_cmd) {
execv_git_cmd(cmd->argv);
diff --git a/run-command.h b/run-command.h
index af1e0bf1789f13cd14e189b1042e8e1cbe2c2dca..7958eb1e0b7a927019460e06d7a01622eddf81df 100644 (file)
--- a/run-command.h
+++ b/run-command.h
#define RUN_COMMAND_STDOUT_TO_STDERR 4
int run_command_v_opt(const char **argv, int opt);
int run_command_v_opt_cd(const char **argv, int opt, const char *dir);
+
+/*
+ * env (the environment) is to be formatted like environ: "VAR=VALUE".
+ * To unset an environment variable use just "VAR".
+ */
int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env);
#endif