From bb3782502e3ac69c42194bd574ac279f72aaf127 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 7 Apr 2013 15:32:34 +0200 Subject: [PATCH] Use libgit2 searchpath for finding config files This also improves the case git.exe isn't on the path and system gitattributes are used (up to now libgit2 did not know where to find the attributes file). This only works for use with git_repository. This isn't used for TGitCache (GitIndex), because we need to know which files to use exactly (for caching purposes). Signed-off-by: Sven Strickroth --- src/Git/Git.cpp | 15 +++++++++ src/TortoiseProc/CommitDlg.cpp | 60 ------------------------------------ src/TortoiseProc/GitProgressList.cpp | 60 ------------------------------------ 3 files changed, 15 insertions(+), 120 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 20c935374..9ef8104c6 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -1640,6 +1640,13 @@ int CGit::GetMapHashToFriendName(MAP_HASH_NAME &map) } } +static void SetLibGit2SearchPath(int level, const CString &value) +{ + CStringA valueA = CUnicodeUtils::GetMulti(value, CP_UTF8); + git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, level, valueA.GetBuffer()); + valueA.ReleaseBuffer(); +} + BOOL CGit::CheckMsysGitDir() { if (m_bInitialized) @@ -1743,6 +1750,14 @@ BOOL CGit::CheckMsysGitDir() if (!FileExists(CGit::ms_LastMsysGitDir + _T("\\git.exe"))) return FALSE; + // Configure libgit2 search paths + CString msysGitDir; + PathCanonicalize(msysGitDir.GetBufferSetLength(MAX_PATH), CGit::ms_LastMsysGitDir + _T("\\..\\etc")); + msysGitDir.ReleaseBuffer(); + SetLibGit2SearchPath(GIT_CONFIG_LEVEL_SYSTEM, msysGitDir); + SetLibGit2SearchPath(GIT_CONFIG_LEVEL_GLOBAL, g_Git.GetHomeDirectory()); + SetLibGit2SearchPath(GIT_CONFIG_LEVEL_XDG, g_Git.GetGitGlobalXDGConfigPath()); + //set path _tdupenv_s(&oldpath,&size,_T("PATH")); diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index 9ab822304..f3a4e8293 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -635,66 +635,6 @@ void CCommitDlg::OnOK() } gitdir.ReleaseBuffer(); - git_config *config; - git_config_new(&config); - - CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8); - if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE)) - { - projectConfigA.ReleaseBuffer(); - git_config_free(config); - git_repository_free(repository); - CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open project config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); - break; - } - projectConfigA.ReleaseBuffer(); - CString globalConfig = g_Git.GetGitGlobalConfig(); - if (PathFileExists(globalConfig)) - { - CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8); - if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE)) - { - globalConfigA.ReleaseBuffer(); - git_config_free(config); - git_repository_free(repository); - CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open global config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); - break; - } - globalConfigA.ReleaseBuffer(); - } - CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig(); - if (PathFileExists(globalXDGConfig)) - { - CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8); - if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE)) - { - globalXDGConfigA.ReleaseBuffer(); - CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open xdg config config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); - git_config_free(config); - git_repository_free(repository); - break; - } - globalXDGConfigA.ReleaseBuffer(); - } - CString systemConfig = g_Git.GetGitSystemConfig(); - if (!systemConfig.IsEmpty()) - { - CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8); - if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE)) - { - systemConfigA.ReleaseBuffer(); - CMessageBox::Show(m_hWnd, CGit::GetLibGit2LastErr(_T("Could not open system config.")), _T("TortoiseGit"), MB_OK | MB_ICONERROR); - git_config_free(config); - git_repository_free(repository); - break; - } - systemConfigA.ReleaseBuffer(); - } - - git_repository_set_config(repository, config); - git_config_free(config); - config = nullptr; - CGitHash revHash; CString revRef = _T("HEAD"); if (m_bCommitAmend && !m_bAmendDiffToLastCommit) diff --git a/src/TortoiseProc/GitProgressList.cpp b/src/TortoiseProc/GitProgressList.cpp index cd8427082..cb2b58af7 100644 --- a/src/TortoiseProc/GitProgressList.cpp +++ b/src/TortoiseProc/GitProgressList.cpp @@ -1678,66 +1678,6 @@ bool CGitProgressList::CmdAdd(CString& sWindowTitle, bool& localoperation) } gitdir.ReleaseBuffer(); - git_config * config; - git_config_new(&config); - - CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8); - if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE)) - { - projectConfigA.ReleaseBuffer(); - ReportGitError(); - git_config_free(config); - git_repository_free(repo); - return false; - } - projectConfigA.ReleaseBuffer(); - CString globalConfig = g_Git.GetGitGlobalConfig(); - if (PathFileExists(globalConfig)) - { - CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8); - if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE)) - { - globalConfigA.ReleaseBuffer(); - ReportGitError(); - git_config_free(config); - git_repository_free(repo); - return false; - } - globalConfigA.ReleaseBuffer(); - } - CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig(); - if (PathFileExists(globalXDGConfig)) - { - CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8); - if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE)) - { - globalXDGConfigA.ReleaseBuffer(); - ReportGitError(); - git_config_free(config); - git_repository_free(repo); - return false; - } - globalXDGConfigA.ReleaseBuffer(); - } - CString systemConfig = g_Git.GetGitSystemConfig(); - if (!systemConfig.IsEmpty()) - { - CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8); - if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE)) - { - systemConfigA.ReleaseBuffer(); - ReportGitError(); - git_config_free(config); - git_repository_free(repo); - return false; - } - systemConfigA.ReleaseBuffer(); - } - - git_repository_set_config(repo, config); - git_config_free(config); - config = nullptr; - if (git_repository_index(&index, repo)) { ReportGitError(); -- 2.11.4.GIT