@matheusbsbs / matheus-bagliano / commits / 3427b375b5
Fork 0

Allow environment variables to be unset in the processes started by run_command

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>

Alex Riesen committed May 23, 2007 at 22:21 UTC 3427b375b594b93ed47ae80ca1d6bb361d7d8f5e
2 files changed +11 -2
run-command.c
+6 -2
@@ -77,8 +77,12 @@ int start_command(struct child_process *cmd)
77 die("exec %s: cd to %s failed (%s)", cmd->argv[0],
78 cmd->dir, strerror(errno));
79 if (cmd->env) {
80 - for (; *cmd->env; cmd->env++)
81 - putenv((char*)*cmd->env);
80 + for (; *cmd->env; cmd->env++) {
81 + if (strchr(*cmd->env, '='))
82 + putenv((char*)*cmd->env);
83 + else
84 + unsetenv(*cmd->env);
85 + }
86 }
87 if (cmd->git_cmd) {
88 execv_git_cmd(cmd->argv);
run-command.h
+5
@@ -35,6 +35,11 @@ int run_command(struct child_process *);
35 #define RUN_COMMAND_STDOUT_TO_STDERR 4
36 int run_command_v_opt(const char **argv, int opt);
37 int run_command_v_opt_cd(const char **argv, int opt, const char *dir);
38 +
39 +/*
40 + * env (the environment) is to be formatted like environ: "VAR=VALUE".
41 + * To unset an environment variable use just "VAR".
42 + */
43 int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env);
44
45 #endif