5 #include "systeminfo.h"
8 #define MAX_PROCESSING_TIME (60 * 1000)
12 static char *environment
;
15 * if we can't find path to msys in the registry, return NULL and
16 * the CreateProcess will copy the environment for us
18 if (!environment
&& msys_path()) {
19 char *old
= GetEnvironmentStrings();
20 size_t space
= 0, path_index
= -1, name_len
= 0, len2
;
23 /* if it's PATH variable (could be Path= too!) */
24 if (!strnicmp(old
+ space
, "PATH=", 5)) {
31 space
++; /* skip var-terminating NULL */
37 environment
= malloc(space
+
38 2 * strlen(msys_path()) + 32);
40 /* copy the block up to the equal sign of PATH var */
41 memcpy(environment
, old
, path_index
);
42 /* insert new segments of the PATH */
43 len2
= sprintf(environment
+ path_index
,
44 "PATH=%s\\bin;%s\\mingw\\bin%s",
45 msys_path(), msys_path(), name_len
? ";" : "");
46 /* append original value of PATH and variables after it */
47 memcpy(environment
+ path_index
+ len2
,
48 old
+ path_index
+ name_len
,
49 space
+ 1 - path_index
- name_len
);
51 FreeEnvironmentStrings(old
);
57 int exec_git(char *command
, const char *wd
, int mode
)
59 STARTUPINFO si
= { sizeof(si
) };
60 PROCESS_INFORMATION pi
;
65 debug_git("[ERROR] Could not find msysPath");
69 sprintf(cmd
, "\"%s\\bin\\git.exe\" %s", msys_path(), command
);
71 si
.dwFlags
= STARTF_USESHOWWINDOW
;
72 si
.wShowWindow
= SW_HIDE
;
74 debug_git("Trying to spawn 'git %s' in working directory '%s'\n",
76 if (!CreateProcess(NULL
, cmd
, NULL
, NULL
, FALSE
, 0,
77 env_for_git(), wd
, &si
, &pi
)) {
78 debug_git("[ERROR] Could not create process (%d); "
80 GetLastError(), wd
, command
);
86 if (WAIT_OBJECT_0
== WaitForSingleObject(pi
.hProcess
,
87 MAX_PROCESSING_TIME
)) {
89 if (!GetExitCodeProcess(pi
.hProcess
, &status
))
90 debug_git("[ERROR] GetExitCode failed (%d); "
92 GetLastError(), wd
, command
);
95 debug_git("[ERROR] process timed out; "
100 CloseHandle(pi
.hProcess
);
101 CloseHandle(pi
.hThread
);