OSDN Git Service

updated wingit and fixed bug in new PATH init code (used wrong function for tchar...
[tortoisegit/TortoiseGitJp.git] / src / Git / Git.cpp
index f9b5278..6d84e6f 100644 (file)
@@ -73,27 +73,24 @@ static BOOL FindGitPath()
                return FALSE;\r
        }\r
 \r
-       TCHAR *env = (TCHAR*)alloca(size);\r
+       TCHAR *env = (TCHAR*)alloca(size * sizeof(TCHAR));\r
        _tgetenv_s(&size, env, size, _T("PATH"));\r
 \r
        TCHAR buf[_MAX_PATH];\r
 \r
-       const LPCTSTR filename = _T("git.exe");\r
-       const int filelen = _tcslen(filename);\r
-\r
        // search in all paths defined in PATH\r
        while ((env = nextpath(env, buf, _MAX_PATH-1)) && *buf)\r
        {\r
                TCHAR *pfin = buf + _tcslen(buf)-1;\r
 \r
                // ensure trailing slash\r
-               if (*pfin != '/' && *pfin != '\\')\r
-                       _tccpy(pfin+1, _T("\\"));\r
+               if (*pfin != _T('/') && *pfin != _T('\\'))\r
+                       _tcscpy(++pfin, _T("\\"));\r
 \r
                const int len = _tcslen(buf);\r
 \r
-               if ((len + filelen) < _MAX_PATH)\r
-                       _tccpy(buf+len, filename);\r
+               if ((len + 7) < _MAX_PATH)\r
+                       _tcscpy(pfin+1, _T("git.exe"));\r
                else\r
                        break;\r
 \r
@@ -652,15 +649,16 @@ BOOL CGit::CheckMsysGitDir()
        {\r
                CRegString msysinstalldir=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);\r
                str=msysinstalldir;\r
-        // check it has a trailing blank\r
-        if (str.Right(1) != _T("\\"))\r
-        {\r
-            str += _T("\\");\r
-        }\r
-               str+=_T("bin");\r
-               msysdir=str;\r
-               msysdir.write();\r
-\r
+               if ( !str.IsEmpty() )\r
+               {\r
+                       str += (str[str.GetLength()-1] != '\\') ? "\\bin" : "bin";\r
+                       msysdir=str;\r
+                       msysdir.write();\r
+               }\r
+               else\r
+               {\r
+                       return false;\r
+               }\r
        }\r
        //CGit::m_MsysGitPath=str;\r
 \r
@@ -669,29 +667,10 @@ BOOL CGit::CheckMsysGitDir()
        _tdupenv_s(&oldpath,&size,_T("PATH")); \r
 \r
        CString path;\r
-       CString unterminated_path = str;        // path to msysgit without semicolon\r
-       CString oldpath_s = oldpath;\r
-       path.Format(_T("%s;"),str);\r
-       // check msysgit not already in path\r
-       if ( oldpath_s.Find( path ) < 0  &&  oldpath_s.Right( unterminated_path.GetLength() ) != unterminated_path )\r
-       {\r
-               // not already there, see if we have to take out one we added last time\r
-               if ( ms_LastMsysGitDir != _T("") )\r
-               {\r
-                       // we have added one so take it out\r
-                       int index = oldpath_s.Find( ms_LastMsysGitDir );\r
-                       if ( index >= 0 )\r
-                       {\r
-                               oldpath_s = oldpath_s.Left( index ) + \r
-                                       oldpath_s.Right( oldpath_s.GetLength() - (index+ms_LastMsysGitDir.GetLength()) );\r
-                       }\r
-               }\r
-               // save the new msysdir path that we are about to add\r
-               ms_LastMsysGitDir = path;\r
-               // add the new one on the front of the existing path\r
-               path+=oldpath_s;\r
-               _tputenv_s(_T("PATH"),path);\r
-       }\r
+       path.Format(_T("%s;%s"),oldpath,str);\r
+\r
+       _tputenv_s(_T("PATH"),path);\r
+\r
        free(oldpath);\r
 \r
        if( !FindGitPath() )\r