From 7208fc87589455f0123353f8b2223af4511b5ac9 Mon Sep 17 00:00:00 2001 From: Evgeny Pashkin Date: Thu, 29 Sep 2011 22:32:37 +0400 Subject: [PATCH 1/3] Fixed wrong path delimiter in exe finding On Windows XP3 in git bash git clone git@github.com:octocat/Spoon-Knife.git cd Spoon-Knife git gui menu Remote\Fetch from\origin error: cannot spawn git: No such file or directory error: could not run rev-list if u run git fetch --all it worked normal in git bash or gitgui tools In second version CreateProcess get 'C:\Git\libexec\git-core/git.exe' in first version - C:/Git/libexec/git-core/git.exe and not executes (unix slashes) after fixing C:\Git\libexec\git-core\git.exe or C:/Git/libexec/git-core\git.exe it works normal Signed-off-by: Johannes Schindelin --- compat/mingw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 3fbfda5978..481e7c6df6 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -998,7 +998,7 @@ static void free_path_split(char **path) static char *lookup_prog(const char *dir, const char *cmd, int isexe, int exe_only) { char path[MAX_PATH]; - snprintf(path, sizeof(path), "%s/%s.exe", dir, cmd); + snprintf(path, sizeof(path), "%s\\%s.exe", dir, cmd); if (!isexe && access(path, F_OK) == 0) return xstrdup(path); From 61b1c1b6d49759b26c8f61fa8460092557c7f008 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 5 Jun 2012 10:24:11 -0400 Subject: [PATCH 2/3] Fix launching of externals from Unicode paths If Git were installed in a path containing non-ASCII characters, commands such as git-am and git-submodule, which are implemented as externals, would fail to launch with the following error: > fatal: 'am' appears to be a git command, but we were not > able to execute it. Maybe git-am is broken? This was due to lookup_prog not being Unicode-aware. It was somehow missed in 2ee5a1a14ad17ff35f0ad52390a27fbbc41258f3. Note that the only problem in this function was calling GetFileAttributes instead of GetFileAttributesW. The calls to access() were fine because access() is a macro which resolves to mingw_access, which already handles Unicode correctly. But I changed lookup_prog to use _waccess directly so that we only convert the path to UTF-16 once. Signed-off-by: Adam Roben --- compat/mingw.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 481e7c6df6..7197e66769 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -998,14 +998,20 @@ static void free_path_split(char **path) static char *lookup_prog(const char *dir, const char *cmd, int isexe, int exe_only) { char path[MAX_PATH]; + wchar_t wpath[MAX_PATH]; snprintf(path, sizeof(path), "%s\\%s.exe", dir, cmd); - if (!isexe && access(path, F_OK) == 0) + if (xutftowcs_path(wpath, path) < 0) + return NULL; + + if (!isexe && _waccess(wpath, F_OK) == 0) return xstrdup(path); path[strlen(path)-4] = '\0'; - if ((!exe_only || isexe) && access(path, F_OK) == 0) - if (!(GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY)) + if ((!exe_only || isexe) && _waccess(wpath, F_OK) == 0) { + + if (!(GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY)) return xstrdup(path); + } return NULL; } From 545bd93f85e5fa3a1e1058ae2c4104627af18f51 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 5 Jun 2012 15:40:33 -0400 Subject: [PATCH 3/3] Make non-.exe externals work again 7ebac8cb94f3a06d3fbdde469414a1443ca45510 made launching of .exe externals work when installed in Unicode paths. But it broke launching of non-.exe externals, no matter where they were installed. We now correctly maintain the UTF-8 and UTF-16 paths in tandem in lookup_prog. This fixes t5526, among others. Signed-off-by: Adam Roben --- compat/mingw.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 7197e66769..b931c07126 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1006,11 +1006,12 @@ static char *lookup_prog(const char *dir, const char *cmd, int isexe, int exe_on if (!isexe && _waccess(wpath, F_OK) == 0) return xstrdup(path); - path[strlen(path)-4] = '\0'; + wpath[wcslen(wpath)-4] = '\0'; if ((!exe_only || isexe) && _waccess(wpath, F_OK) == 0) { - - if (!(GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY)) + if (!(GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY)) { + path[strlen(path)-4] = '\0'; return xstrdup(path); + } } return NULL; }