mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 17:20:22 +00:00
Refactor git_win32__find_system_dirs() to extract "etc\\" as subpath parameter
This commit is contained in:
parent
92457cad41
commit
f84bc38853
@ -592,7 +592,7 @@ clean_up:
|
|||||||
static int git_futils_guess_system_dirs(git_buf *out)
|
static int git_futils_guess_system_dirs(git_buf *out)
|
||||||
{
|
{
|
||||||
#ifdef GIT_WIN32
|
#ifdef GIT_WIN32
|
||||||
return git_win32__find_system_dirs(out);
|
return git_win32__find_system_dirs(out, L"etc\\");
|
||||||
#else
|
#else
|
||||||
return git_buf_sets(out, "/etc");
|
return git_buf_sets(out, "/etc");
|
||||||
#endif
|
#endif
|
||||||
|
@ -86,7 +86,7 @@ static wchar_t* win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
|
|||||||
return (path != base) ? path : NULL;
|
return (path != base) ? path : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe)
|
static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe, const wchar_t *subdir)
|
||||||
{
|
{
|
||||||
wchar_t *env = _wgetenv(L"PATH"), lastch;
|
wchar_t *env = _wgetenv(L"PATH"), lastch;
|
||||||
struct git_win32__path root;
|
struct git_win32__path root;
|
||||||
@ -110,8 +110,8 @@ static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe)
|
|||||||
wcscpy(&root.path[root.len], gitexe);
|
wcscpy(&root.path[root.len], gitexe);
|
||||||
|
|
||||||
if (_waccess(root.path, F_OK) == 0 && root.len > 5) {
|
if (_waccess(root.path, F_OK) == 0 && root.len > 5) {
|
||||||
/* replace "bin\\" or "cmd\\" with "etc\\" */
|
/* replace "bin\\" or "cmd\\" with subdir */
|
||||||
wcscpy(&root.path[root.len - 4], L"etc\\");
|
wcscpy(&root.path[root.len - 4], subdir);
|
||||||
|
|
||||||
win32_path_to_8(buf, root.path);
|
win32_path_to_8(buf, root.path);
|
||||||
return 0;
|
return 0;
|
||||||
@ -122,7 +122,7 @@ static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int win32_find_git_in_registry(
|
static int win32_find_git_in_registry(
|
||||||
git_buf *buf, const HKEY hieve, const wchar_t *key)
|
git_buf *buf, const HKEY hieve, const wchar_t *key, const wchar_t *subdir)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
DWORD dwType = REG_SZ;
|
DWORD dwType = REG_SZ;
|
||||||
@ -143,7 +143,7 @@ static int win32_find_git_in_registry(
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscat(path16.path, L"etc\\");
|
wcscat(path16.path, subdir);
|
||||||
path16.len += 4;
|
path16.len += 4;
|
||||||
|
|
||||||
win32_path_to_8(buf, path16.path);
|
win32_path_to_8(buf, path16.path);
|
||||||
@ -180,26 +180,26 @@ static int win32_find_existing_dirs(
|
|||||||
return (git_buf_oom(out) ? -1 : 0);
|
return (git_buf_oom(out) ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_win32__find_system_dirs(git_buf *out)
|
int git_win32__find_system_dirs(git_buf *out, const wchar_t *subdir)
|
||||||
{
|
{
|
||||||
git_buf buf = GIT_BUF_INIT;
|
git_buf buf = GIT_BUF_INIT;
|
||||||
|
|
||||||
/* directories where git.exe & git.cmd are found */
|
/* directories where git.exe & git.cmd are found */
|
||||||
if (!win32_find_git_in_path(&buf, L"git.exe") && buf.size)
|
if (!win32_find_git_in_path(&buf, L"git.exe", subdir) && buf.size)
|
||||||
git_buf_set(out, buf.ptr, buf.size);
|
git_buf_set(out, buf.ptr, buf.size);
|
||||||
else
|
else
|
||||||
git_buf_clear(out);
|
git_buf_clear(out);
|
||||||
|
|
||||||
if (!win32_find_git_in_path(&buf, L"git.cmd") && buf.size)
|
if (!win32_find_git_in_path(&buf, L"git.cmd", subdir) && buf.size)
|
||||||
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
||||||
|
|
||||||
/* directories where git is installed according to registry */
|
/* directories where git is installed according to registry */
|
||||||
if (!win32_find_git_in_registry(
|
if (!win32_find_git_in_registry(
|
||||||
&buf, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL) && buf.size)
|
&buf, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL, subdir) && buf.size)
|
||||||
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
||||||
|
|
||||||
if (!win32_find_git_in_registry(
|
if (!win32_find_git_in_registry(
|
||||||
&buf, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL) && buf.size)
|
&buf, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, subdir) && buf.size)
|
||||||
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
||||||
|
|
||||||
git_buf_free(&buf);
|
git_buf_free(&buf);
|
||||||
|
@ -19,7 +19,7 @@ extern int git_win32__expand_path(
|
|||||||
extern int git_win32__find_file(
|
extern int git_win32__find_file(
|
||||||
git_buf *path, const struct git_win32__path *root, const char *filename);
|
git_buf *path, const struct git_win32__path *root, const char *filename);
|
||||||
|
|
||||||
extern int git_win32__find_system_dirs(git_buf *out);
|
extern int git_win32__find_system_dirs(git_buf *out, const wchar_t *subpath);
|
||||||
extern int git_win32__find_global_dirs(git_buf *out);
|
extern int git_win32__find_global_dirs(git_buf *out);
|
||||||
extern int git_win32__find_xdg_dirs(git_buf *out);
|
extern int git_win32__find_xdg_dirs(git_buf *out);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user