summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 434a6db)
raw | patch | inline | side by side (parent: 434a6db)
author | Johannes Sixt <j6t@kdbg.org> | |
Fri, 11 Sep 2009 17:40:08 +0000 (19:40 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 11 Sep 2009 23:33:54 +0000 (16:33 -0700) |
Previously, it would not be possible to call start_command twice for the
same struct child_process that has env set.
The fix is achieved by moving the loop that modifies the environment block
into a helper function. This also allows us to make two other helper
functions static.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
same struct child_process that has env set.
The fix is achieved by moving the loop that modifies the environment block
into a helper function. This also allows us to make two other helper
functions static.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c | patch | blob | history | |
compat/mingw.h | patch | blob | history | |
run-command.c | patch | blob | history |
diff --git a/compat/mingw.c b/compat/mingw.c
index bed417875e1344690977fd6aa41b955f127b74b4..36ef8d32147f003fb3912e6e08f8ad13cb370868 100644 (file)
--- a/compat/mingw.c
+++ b/compat/mingw.c
free_path_split(path);
}
-char **copy_environ()
+static char **copy_environ(void)
{
char **env;
int i = 0;
/*
* If name contains '=', then sets the variable, otherwise it unsets it
*/
-char **env_setenv(char **env, const char *name)
+static char **env_setenv(char **env, const char *name)
{
char *eq = strchrnul(name, '=');
int i = lookup_env(env, name, eq-name);
return env;
}
+/*
+ * Copies global environ and adjusts variables as specified by vars.
+ */
+char **make_augmented_environ(const char *const *vars)
+{
+ char **env = copy_environ();
+
+ while (*vars)
+ env = env_setenv(env, *vars++);
+ return env;
+}
+
/* this is the first function to call into WS_32; initialize it */
#undef gethostbyname
struct hostent *mingw_gethostbyname(const char *host)
diff --git a/compat/mingw.h b/compat/mingw.h
index 948de66eb5fb2c1e52e774e86f593e42c26bcd05..c43917cd6eb266f9455c088baea35e514aa07110 100644 (file)
--- a/compat/mingw.h
+++ b/compat/mingw.h
* helpers
*/
-char **copy_environ(void);
+char **make_augmented_environ(const char *const *vars);
void free_environ(char **env);
-char **env_setenv(char **env, const char *name);
/*
* A replacement of main() that ensures that argv[0] has a path
diff --git a/run-command.c b/run-command.c
index f3e7abb7de799a14a8f792195992c4d9d1495c6f..ac314a5a8d96d74a36dd2f274707204142e84b7b 100644 (file)
--- a/run-command.c
+++ b/run-command.c
if (cmd->dir)
die("chdir in start_command() not implemented");
- if (cmd->env) {
- env = copy_environ();
- for (; *cmd->env; cmd->env++)
- env = env_setenv(env, *cmd->env);
- }
+ if (cmd->env)
+ env = make_augmented_environ(cmd->env);
if (cmd->git_cmd) {
cmd->argv = prepare_git_cmd(cmd->argv);