From 59859ba884bbf26473b807ab7c6a0439965968f4 Mon Sep 17 00:00:00 2001 From: Colin Law Date: Sun, 25 Jan 2009 16:15:24 +0000 Subject: [PATCH] Stop CGit::CheckMsysGitDir() from adding to the path every time through. 1. Make it check whether the msysgitpath is already in the environment path. 2. When it adds a new one take out the last one it added, if any. --- src/Git/Git.cpp | 29 ++++++++++++++++++++++++----- src/Git/Git.h | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index bd9724f..387b491 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -6,6 +6,7 @@ #include "GitConfig.h" #define MAX_DIRBUFFER 1000 +CString CGit::ms_LastMsysGitDir; CGit g_Git; CGit::CGit(void) { @@ -22,7 +23,7 @@ int CGit::RunAsync(CString cmd,PROCESS_INFORMATION *piOut,HANDLE *hReadOut,CStri { SECURITY_ATTRIBUTES sa; HANDLE hRead, hWrite; - HANDLE hStdioFile; + HANDLE hStdioFile = NULL; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor=NULL; @@ -530,11 +531,29 @@ BOOL CGit::CheckMsysGitDir() _tdupenv_s(&oldpath,&size,_T("PATH")); CString path; + CString unterminated_path = str; // path to msysgit without semicolon + CString oldpath_s = oldpath; path.Format(_T("%s;"),str); - path+=oldpath; - - _tputenv_s(_T("PATH"),path); - + // check msysgit not already in path + if ( oldpath_s.Find( path ) < 0 && oldpath_s.Right( unterminated_path.GetLength() ) != unterminated_path ) + { + // not already there, see if we have to take out one we added last time + if ( ms_LastMsysGitDir != "" ) + { + // we have added one so take it out + int index = oldpath_s.Find( ms_LastMsysGitDir ); + if ( index >= 0 ) + { + oldpath_s = oldpath_s.Left( index ) + + oldpath_s.Right( oldpath_s.GetLength() - (index+ms_LastMsysGitDir.GetLength()) ); + } + } + // save the new msysdir path that we are about to add + ms_LastMsysGitDir = path; + // add the new one on the front of the existing path + path+=oldpath_s; + _tputenv_s(_T("PATH"),path); + } free(oldpath); CString cmd,out; diff --git a/src/Git/Git.h b/src/Git/Git.h index b7bde0c..6871838 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -11,6 +11,7 @@ private: GitAdminDir m_GitDir; public: static BOOL CheckMsysGitDir(); + static CString ms_LastMsysGitDir; // the last msysgitdir added to the path, blank if none // static CString m_MsysGitPath; CGit(void); -- 2.11.0