Merge pull request #1299 from csware/support_local_msysgit_install Support local msysgit installations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
diff --git a/AUTHORS b/AUTHORS
index 3803e7b..587da24 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -64,6 +64,7 @@ Sergey Nikishin
Shawn O. Pearce
Shuhei Tanuma
Steve Frécinaux
+Sven Strickroth
Tim Branyen
Tim Clem
Tim Harder
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index 8c4fc7a..6fc7c75 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -9,8 +9,9 @@
#include "path.h"
#include "findfile.h"
+#define REG_MSYSGIT_INSTALL_LOCAL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
#ifndef _WIN64
-#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
+#define REG_MSYSGIT_INSTALL REG_MSYSGIT_INSTALL_LOCAL
#else
#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
#endif
@@ -113,37 +114,43 @@ int win32_find_system_file_using_registry(git_buf *path, const char *filename)
{
struct win32_path root;
+ if (win32_find_msysgit_in_registry(&root, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL)) {
+ if (win32_find_msysgit_in_registry(&root, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL)) {
+ giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
+ return -1;
+ }
+ }
+
+ if (win32_find_file(path, &root, filename) < 0) {
+ giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename);
+ git_buf_clear(path);
+ return GIT_ENOTFOUND;
+ }
+
+ return 0;
+}
+
+int win32_find_msysgit_in_registry(struct win32_path *root, const HKEY hieve, const wchar_t *key)
+{
HKEY hKey;
DWORD dwType = REG_SZ;
DWORD dwSize = MAX_PATH;
- root.len = 0;
- if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
- {
- if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,(LPBYTE)&root.path, &dwSize) == ERROR_SUCCESS)
- {
+ assert(root);
+
+ root->len = 0;
+ if (RegOpenKeyExW(hieve, key, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
+ if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType, (LPBYTE)&root->path, &dwSize) == ERROR_SUCCESS) {
// InstallLocation points to the root of the msysgit directory
- if (dwSize + 4 > MAX_PATH) // 4 = wcslen(L"etc\\")
- {
+ if (dwSize + 4 > MAX_PATH) {// 4 = wcslen(L"etc\\")
giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long");
return -1;
}
- wcscat(root.path, L"etc\\");
- root.len = (DWORD)wcslen(root.path) + 1;
+ wcscat(root->path, L"etc\\");
+ root->len = (DWORD)wcslen(root->path) + 1;
}
}
RegCloseKey(hKey);
- if (!root.len) {
- giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
- return -1;
- }
-
- if (win32_find_file(path, &root, filename) < 0) {
- giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename);
- git_buf_clear(path);
- return GIT_ENOTFOUND;
- }
-
- return 0;
+ return root->len ? 0 : GIT_ENOTFOUND;
}
diff --git a/src/win32/findfile.h b/src/win32/findfile.h
index 918991c..47fe715 100644
--- a/src/win32/findfile.h
+++ b/src/win32/findfile.h
@@ -18,6 +18,7 @@ int win32_expand_path(struct win32_path *s_root, const wchar_t *templ);
int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename);
int win32_find_system_file_using_path(git_buf *path, const char *filename);
int win32_find_system_file_using_registry(git_buf *path, const char *filename);
+int win32_find_msysgit_in_registry(struct win32_path *root, const HKEY hieve, const wchar_t *key);
#endif