OSDN Git Service

Fix TortoiseGitBlame commit is not in log list problem.
[tortoisegit/TortoiseGitJp.git] / src / Git / Git.cpp
index 7fafa44..58433c2 100644 (file)
@@ -6,6 +6,7 @@
 #include "GitConfig.h"\r
 \r
 #define MAX_DIRBUFFER 1000\r
+CString CGit::ms_LastMsysGitDir;\r
 CGit g_Git;\r
 CGit::CGit(void)\r
 {\r
@@ -22,7 +23,7 @@ int CGit::RunAsync(CString cmd,PROCESS_INFORMATION *piOut,HANDLE *hReadOut,CStri
 {\r
        SECURITY_ATTRIBUTES sa;\r
        HANDLE hRead, hWrite;\r
-       HANDLE hStdioFile;\r
+       HANDLE hStdioFile = NULL;\r
 \r
        sa.nLength = sizeof(SECURITY_ATTRIBUTES);\r
        sa.lpSecurityDescriptor=NULL;\r
@@ -89,7 +90,7 @@ void CGit::StringAppend(CString *str,BYTE *p,int code,int length)
        //buf = new WCHAR[len*4 + 1];\r
        buf = str->GetBuffer(len*4+1+str->GetLength())+str->GetLength();\r
        SecureZeroMemory(buf, (len*4 + 1)*sizeof(WCHAR));\r
-       MultiByteToWideChar(code, 0, (LPCSTR)p, -1, buf, len*4);\r
+       MultiByteToWideChar(code, 0, (LPCSTR)p, len, buf, len*4);\r
        str->ReleaseBuffer();\r
        //str->Append(buf);\r
        //delete buf;\r
@@ -266,9 +267,18 @@ int CGit::GetLog(BYTE_VECTOR& logOut, CString &hash,  CTGitPath *path ,int count
        if(mask& CGit::LOG_INFO_DETECT_RENAME )\r
                param += _T(" -M ");\r
 \r
+       if(mask& CGit::LOG_INFO_FIRST_PARENT )\r
+               param += _T(" --first-parent ");\r
+       \r
+       if(mask& CGit::LOG_INFO_NO_MERGE )\r
+               param += _T(" --no-merges ");\r
+\r
+       if(mask& CGit::LOG_INFO_FOLLOW)\r
+               param += _T(" --follow ");\r
+\r
        param+=hash;\r
 \r
-       cmd.Format(_T("git.exe log %s -z --topo-order --parents %s --pretty=format:\""),\r
+       cmd.Format(_T("git.exe log %s -z --topo-order %s --parents --pretty=format:\""),\r
                                num,param);\r
 \r
        BuildOutputFormat(log,!(mask&CGit::LOG_INFO_ONLY_HASH));\r
@@ -507,7 +517,12 @@ BOOL CGit::CheckMsysGitDir()
        {\r
                CRegString msysinstalldir=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);\r
                str=msysinstalldir;\r
-               str+="\\bin";\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
@@ -523,17 +538,36 @@ BOOL CGit::CheckMsysGitDir()
        {               \r
                _tdupenv_s(&home,&size,_T("USERPROFILE")); \r
                _tputenv_s(_T("HOME"),home);\r
-               free(home);\r
        }\r
+       free(home);\r
+       \r
        //set path\r
        _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
-       path+=oldpath;\r
-\r
-       _tputenv_s(_T("PATH"),path);\r
-\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
        free(oldpath);\r
 \r
        CString cmd,out;\r