@matheusbsbs / matheus-bagliano / commits / ee4931486b
Fork 0

Add ability to specify environment extension to run_command

There is no way to specify and override for the environment: there'd be no user for it yet. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Alex Riesen committed May 22, 2007 at 23:48 UTC ee4931486b752b0a3ee04be31f25aed13913cb31
2 files changed +17 -1
run-command.c
+15 -1
@@ -76,6 +76,10 @@ int start_command(struct child_process *cmd)
76 if (cmd->dir && chdir(cmd->dir))
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);
82 + }
83 if (cmd->git_cmd) {
84 execv_git_cmd(cmd->argv);
85 } else {
@@ -137,7 +141,8 @@ int run_command(struct child_process *cmd)
141 }
142
143 static void prepare_run_command_v_opt(struct child_process *cmd,
140 - const char **argv, int opt)
144 + const char **argv,
145 + int opt)
146 {
147 memset(cmd, 0, sizeof(*cmd));
148 cmd->argv = argv;
@@ -160,3 +165,12 @@ int run_command_v_opt_cd(const char **argv, int opt, const char *dir)
165 cmd.dir = dir;
166 return run_command(&cmd);
167 }
168 +
169 +int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env)
170 +{
171 + struct child_process cmd;
172 + prepare_run_command_v_opt(&cmd, argv, opt);
173 + cmd.dir = dir;
174 + cmd.env = env;
175 + return run_command(&cmd);
176 +}
run-command.h
+2
@@ -17,6 +17,7 @@ struct child_process {
17 int in;
18 int out;
19 const char *dir;
20 + const char *const *env;
21 unsigned close_in:1;
22 unsigned close_out:1;
23 unsigned no_stdin:1;
@@ -34,5 +35,6 @@ 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 +int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env);
39
40 #endif