From 13a01bc603e7b911570e789bcf538c63f76796b6 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Sun, 5 Jul 2009 23:41:25 +0800 Subject: [PATCH] Fixed issue #104: Doubleclicking changed submodule dir in Check For Modifications dlg, crashes TGit Fix check modify case. Signed-off-by: Frank Li --- src/TortoiseProc/GitDiff.cpp | 132 +++++++++++++++++++++++++++++-------------- src/TortoiseProc/GitDiff.h | 1 + 2 files changed, 92 insertions(+), 41 deletions(-) diff --git a/src/TortoiseProc/GitDiff.cpp b/src/TortoiseProc/GitDiff.cpp index 059920c..e4b1055 100644 --- a/src/TortoiseProc/GitDiff.cpp +++ b/src/TortoiseProc/GitDiff.cpp @@ -72,20 +72,55 @@ int CGitDiff::DiffNull(CTGitPath *pPath, git_revnum_t &rev1,bool bIsAdd) return 0; } -int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/) +int CGitDiff::SubmoduleDiff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/) { - CString temppath; - GetTempPath(temppath); - Parser(rev1); - Parser(rev2); - CString file1; - CString title1; - CString cmd; + CString oldhash; + CString newhash; + oldhash = GIT_REV_ZERO; + newhash = GIT_REV_ZERO; + CString cmd,err; + CString workingcopy; + + if( rev2 == GIT_REV_ZERO || rev1 == GIT_REV_ZERO ) + { + CString rev; + if( rev2 != GIT_REV_ZERO ) + rev = rev2; + if( rev1 != GIT_REV_ZERO ) + rev = rev1; + + workingcopy = _T("(Work Copy)"); - if(pPath->IsDirectory() || pPath2->IsDirectory()) + cmd.Format(_T("git.exe diff %s -- \"%s\""), + rev,pPath->GetGitPathString()); + + CString output; + if(g_Git.Run(cmd,&output,CP_ACP)) + { + CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return -1; + } + int start =0; + int oldstart = output.Find(_T("-Subproject commit"),start); + if(oldstart<0) + { + CMessageBox::Show(NULL,_T("Subproject Diff Format error") ,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return -1; + } + oldhash = output.Mid(oldstart+ CString(_T("-Subproject commit")).GetLength()+1,40); + start = 0; + int newstart = output.Find(_T("+Subproject commit"),start); + if(oldstart<0) + { + CMessageBox::Show(NULL,_T("Subproject Diff Format error") ,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return -1; + } + newhash = output.Mid(newstart+ CString(_T("+Subproject commit")).GetLength()+1,40); + + }else { cmd.Format(_T("git.exe diff-tree -r -z %s %s -- \"%s\""), - rev2,rev1,pPath->GetGitPathString()); + rev2,rev1,pPath->GetGitPathString()); BYTE_VECTOR bytes; if(g_Git.Run(cmd,&bytes)) @@ -93,46 +128,61 @@ int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, gi CString err; g_Git.StringAppend(&err,&bytes[0],CP_ACP); CMessageBox::Show(NULL,err,_T("TortoiseGit"),MB_OK|MB_ICONERROR); + return -1; } - - CString oldhash; + g_Git.StringAppend(&oldhash,&bytes[15],CP_ACP,40); - CString newhash; g_Git.StringAppend(&newhash,&bytes[15+41],CP_ACP,40); + + } + + CString oldsub; + CString newsub; - CString oldsub; - CString newsub; + CGit subgit; + subgit.m_CurrentDir=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString(); - CGit subgit; - subgit.m_CurrentDir=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString(); + if(pPath->HasAdminDir()) + { + int encode=CAppUtils::GetLogOutputEncode(&subgit); - CString cmd; - if(pPath->HasAdminDir()) + if(oldhash != GIT_REV_ZERO) + { + cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),oldhash); + subgit.Run(cmd,&oldsub,encode); + } + if(newsub != GIT_REV_ZERO) { - int encode=CAppUtils::GetLogOutputEncode(&subgit); - - if(oldhash != GIT_REV_ZERO) - { - cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),oldhash); - subgit.Run(cmd,&oldsub,encode); - } - - if(newsub != GIT_REV_ZERO) - { - cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),newhash); - subgit.Run(cmd,&newsub,encode); - } + cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),newhash); + subgit.Run(cmd,&newsub,encode); } - CString msg; - msg.Format(_T("Submodule %s Change\r\n\r\nFrom: %s\r\n\t%s\r\n\r\nTo: %s\r\n\t\t%s"), - pPath->GetWinPath(), - oldhash, - oldsub , - newhash, - newsub); - CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK); + } + CString msg; + msg.Format(_T("Submodule %s Change\r\n\r\nFrom: %s\r\n\t%s\r\n\r\nTo%s: %s\r\n\t\t%s"), + pPath->GetWinPath(), + oldhash, + oldsub , + workingcopy, + newhash, + newsub); + CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK); - return 0; + return 0; +} + +int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/) +{ + CString temppath; + GetTempPath(temppath); + Parser(rev1); + Parser(rev2); + CString file1; + CString title1; + CString cmd; + + if(pPath->IsDirectory() || pPath2->IsDirectory()) + { + return SubmoduleDiff(pPath,pPath2,rev1,rev2); } if(rev1 != GIT_REV_ZERO ) diff --git a/src/TortoiseProc/GitDiff.h b/src/TortoiseProc/GitDiff.h index 4a7c048..7826573 100644 --- a/src/TortoiseProc/GitDiff.h +++ b/src/TortoiseProc/GitDiff.h @@ -12,5 +12,6 @@ public: // Use two path to handle rename cases static int Diff(CTGitPath * pPath1, CTGitPath *pPath2 ,git_revnum_t & rev1, git_revnum_t & rev2, bool blame=false, bool unified=false); + static int SubmoduleDiff(CTGitPath * pPath1, CTGitPath *pPath2 ,git_revnum_t & rev1, git_revnum_t & rev2, bool blame=false, bool unified=false); static int DiffNull(CTGitPath *pPath, git_revnum_t &rev1,bool bIsAdd=true); }; -- 2.11.0