From d76d1b3532dfdc1a1ab1b06f031cf29aaa75e2be Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Fri, 1 Aug 2014 04:44:40 +0200 Subject: [PATCH] Start new processes with our prepared environment variables Signed-off-by: Sven Strickroth --- src/Git/Git.cpp | 2 +- src/libgit2/filter-filter.c | 8 +++++--- src/libgit2/filter-filter.h | 2 +- src/libgit2/system-call.c | 4 ++-- src/libgit2/system-call.h | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 49cc8caf9..2968ba8d8 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -1931,7 +1931,7 @@ BOOL CGit::CheckMsysGitDir(BOOL bFallback) // register filter only once if (!git_filter_lookup("filter")) { - if (git_filter_register("filter", git_filter_filter_new(), GIT_FILTER_DRIVER_PRIORITY)) + if (git_filter_register("filter", git_filter_filter_new(&m_Environment[0]), GIT_FILTER_DRIVER_PRIORITY)) return FALSE; } #endif diff --git a/src/libgit2/filter-filter.c b/src/libgit2/filter-filter.c index 0007e4b0a..7044ce600 100644 --- a/src/libgit2/filter-filter.c +++ b/src/libgit2/filter-filter.c @@ -34,6 +34,7 @@ struct filter_filter { git_filter f; + LPWSTR pEnv; }; static int filter_check( @@ -107,7 +108,7 @@ static int filter_apply( const git_buf *from, const git_filter_source *src) { - GIT_UNUSED(self); + struct filter_filter *ffs = (struct filter_filter *)self; if (!*payload) return GIT_PASSTHROUGH; @@ -165,7 +166,7 @@ static int filter_apply( git_buf_free(&cmdBuf); COMMAND_HANDLE commandHandle = { 0 }; - if (command_start(wide_cmd, &commandHandle)) { + if (command_start(wide_cmd, &commandHandle, ffs->pEnv)) { git__free(wide_cmd); if (isRequired) return -1; @@ -208,7 +209,7 @@ static void filter_cleanup( git__free(payload); } -git_filter *git_filter_filter_new(void) +git_filter *git_filter_filter_new(LPWSTR pEnv) { struct filter_filter *f = git__calloc(1, sizeof(struct filter_filter)); @@ -219,6 +220,7 @@ git_filter *git_filter_filter_new(void) f->f.check = filter_check; f->f.apply = filter_apply; f->f.cleanup = filter_cleanup; + f->pEnv = pEnv; return (git_filter *)f; } diff --git a/src/libgit2/filter-filter.h b/src/libgit2/filter-filter.h index 1226442d4..9211c2cba 100644 --- a/src/libgit2/filter-filter.h +++ b/src/libgit2/filter-filter.h @@ -21,6 +21,6 @@ GIT_BEGIN_DECL -GIT_EXTERN(git_filter *) git_filter_filter_new(void); +GIT_EXTERN(git_filter *) git_filter_filter_new(LPWSTR pEnv); GIT_END_DECL diff --git a/src/libgit2/system-call.c b/src/libgit2/system-call.c index bcd8e2657..1a63e2ba3 100644 --- a/src/libgit2/system-call.c +++ b/src/libgit2/system-call.c @@ -21,7 +21,7 @@ #include "netops.h" #include "system-call.h" -int command_start(wchar_t *cmd, COMMAND_HANDLE *commandHandle) +int command_start(wchar_t *cmd, COMMAND_HANDLE *commandHandle, LPWSTR pEnv) { SECURITY_ATTRIBUTES sa; HANDLE hReadOut = INVALID_HANDLE_VALUE, hWriteOut = INVALID_HANDLE_VALUE, hReadIn = INVALID_HANDLE_VALUE, hWriteIn = INVALID_HANDLE_VALUE; @@ -60,7 +60,7 @@ int command_start(wchar_t *cmd, COMMAND_HANDLE *commandHandle) si.wShowWindow = SW_HIDE; si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; - if (!CreateProcessW(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { + if (!CreateProcessW(NULL, cmd, NULL, NULL, TRUE, pEnv ? CREATE_UNICODE_ENVIRONMENT : 0, pEnv, NULL, &si, &pi)) { giterr_set(GITERR_OS, "Could not start external tool"); CloseHandle(hReadOut); CloseHandle(hWriteOut); diff --git a/src/libgit2/system-call.h b/src/libgit2/system-call.h index 79f1aa0a3..a2b69d218 100644 --- a/src/libgit2/system-call.h +++ b/src/libgit2/system-call.h @@ -26,7 +26,7 @@ typedef struct { bool running; } COMMAND_HANDLE; -int command_start(wchar_t *cmd, COMMAND_HANDLE *commandHandle); +int command_start(wchar_t *cmd, COMMAND_HANDLE *commandHandle, LPWSTR pEnv); void command_close_stdout(COMMAND_HANDLE *commandHandle); void command_close_stdin(COMMAND_HANDLE *commandHandle); DWORD command_close(COMMAND_HANDLE *commandHandle); -- 2.11.4.GIT