]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Allow environment variables to be unset in the processes started by run_command
authorAlex Riesen <raa.lkml@gmail.com>
Wed, 23 May 2007 20:21:39 +0000 (22:21 +0200)
committerJunio 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>
run-command.c
run-command.h

index 4ee4bdf16c1c5288d63ed0ba9a4503d04377c19e..7e779d33ee9ea5f7d2e6aedc8c3a0a0476e87135 100644 (file)
@@ -77,8 +77,12 @@ int start_command(struct child_process *cmd)
                        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);
index af1e0bf1789f13cd14e189b1042e8e1cbe2c2dca..7958eb1e0b7a927019460e06d7a01622eddf81df 100644 (file)
@@ -35,6 +35,11 @@ int run_command(struct child_process *);
 #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