From 789b5736e33ecc5e60d0c4ca794fbcf8ac1c35af Mon Sep 17 00:00:00 2001 From: Frank Li Date: Tue, 20 Jan 2009 14:56:36 +0800 Subject: [PATCH] Handle Rename case at commit dialog --- src/Git/GitStatusListCtrl.cpp | 28 +++++++++++++++++++++------ src/Git/GitStatusListCtrl.h | 2 +- src/TortoiseProc/Commands/DiffCommand.cpp | 2 +- src/TortoiseProc/Commands/PrevDiffCommand.cpp | 2 +- src/TortoiseProc/FileDiffDlg.cpp | 2 +- src/TortoiseProc/GitDiff.cpp | 12 ++++++------ src/TortoiseProc/GitDiff.h | 3 ++- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/Git/GitStatusListCtrl.cpp b/src/Git/GitStatusListCtrl.cpp index 494f74c..1055bb3 100644 --- a/src/Git/GitStatusListCtrl.cpp +++ b/src/Git/GitStatusListCtrl.cpp @@ -4053,10 +4053,21 @@ void CGitStatusListCtrl::StartDiff(int fileindex) { if(fileindex<0) return; + + CTGitPath file1=*(CTGitPath*)GetItemData(fileindex); + CTGitPath file2; + if(file1.m_Action & CTGitPath::LOGACTIONS_REPLACED) + { + file2.SetFromGit(file1.GetGitOldPathString()); + }else + { + file2=file1; + } + if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO) { if(!g_Git.IsInitRepos()) - CGitDiff::Diff((CTGitPath*)GetItemData(fileindex), + CGitDiff::Diff(&file1,&file2, CString(GIT_REV_ZERO), GitRev::GetHead()); else @@ -4064,7 +4075,7 @@ void CGitStatusListCtrl::StartDiff(int fileindex) CString(GIT_REV_ZERO)); }else { - CGitDiff::Diff((CTGitPath*)GetItemData(fileindex), + CGitDiff::Diff(&file1,&file2, m_CurrentVersion, m_CurrentVersion+_T("~1")); } @@ -4150,20 +4161,25 @@ CString CGitStatusListCtrl::GetStatisticsString() } -CTGitPath CGitStatusListCtrl::GetCommonDirectory(bool bStrict) +CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict) { if (!bStrict) { // not strict means that the selected folder has priority if (!m_StatusFileList.GetCommonDirectory().IsEmpty()) - return m_StatusFileList.GetCommonDirectory(); + return m_StatusFileList.GetCommonDirectory().GetWinPath(); } CTGitPath commonBaseDirectory; int nListItems = GetItemCount(); for (int i=0; iGetItemData(i); + CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i); + ASSERT(p); + if(p==NULL) + continue; + baseDirectory = p->GetDirectory(); + if(commonBaseDirectory.IsEmpty()) { commonBaseDirectory = baseDirectory; @@ -4177,7 +4193,7 @@ CTGitPath CGitStatusListCtrl::GetCommonDirectory(bool bStrict) } } } - return commonBaseDirectory; + return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath(); } CTGitPath CGitStatusListCtrl::GetCommonURL(bool bStrict) diff --git a/src/Git/GitStatusListCtrl.h b/src/Git/GitStatusListCtrl.h index 06dbad5..6226cb3 100644 --- a/src/Git/GitStatusListCtrl.h +++ b/src/Git/GitStatusListCtrl.h @@ -638,7 +638,7 @@ public: * if \a bStrict is set to false, then the paths passed to the control * to fetch the status (in GetStatus()) are used if possible. */ - CTGitPath GetCommonDirectory(bool bStrict); + CString GetCommonDirectory(bool bStrict); /** * Returns the parent url of all entries in the control. diff --git a/src/TortoiseProc/Commands/DiffCommand.cpp b/src/TortoiseProc/Commands/DiffCommand.cpp index 1ac7b52..090615a 100644 --- a/src/TortoiseProc/Commands/DiffCommand.cpp +++ b/src/TortoiseProc/Commands/DiffCommand.cpp @@ -54,7 +54,7 @@ bool DiffCommand::Execute() #endif { //git_revnum_t baseRev = 0; - bRet = diff.Diff(&cmdLinePath,git_revnum_t(_T("HEAD")),git_revnum_t(GIT_REV_ZERO)); + bRet = diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(_T("HEAD")),git_revnum_t(GIT_REV_ZERO)); } } } diff --git a/src/TortoiseProc/Commands/PrevDiffCommand.cpp b/src/TortoiseProc/Commands/PrevDiffCommand.cpp index 096f494..b8fa037 100644 --- a/src/TortoiseProc/Commands/PrevDiffCommand.cpp +++ b/src/TortoiseProc/Commands/PrevDiffCommand.cpp @@ -65,7 +65,7 @@ bool PrevDiffCommand::Execute() if( revs.size() == 2 ) { CGitDiff diff; - bRet = diff.Diff(&cmdLinePath, revs[0].m_CommitHash, revs[1].m_CommitHash, false); + bRet = diff.Diff(&cmdLinePath,&cmdLinePath, revs[0].m_CommitHash, revs[1].m_CommitHash, false); } } else diff --git a/src/TortoiseProc/FileDiffDlg.cpp b/src/TortoiseProc/FileDiffDlg.cpp index d987e40..9796df9 100644 --- a/src/TortoiseProc/FileDiffDlg.cpp +++ b/src/TortoiseProc/FileDiffDlg.cpp @@ -318,7 +318,7 @@ void CFileDiffDlg::DoDiff(int selIndex, bool blame) CGitDiff diff; CTGitPath* fd = m_arFilteredList[selIndex]; - diff.Diff(fd, this->m_rev1.m_CommitHash, this->m_rev2.m_CommitHash, blame, FALSE); + diff.Diff(fd, fd,this->m_rev1.m_CommitHash, this->m_rev2.m_CommitHash, blame, FALSE); #if 0 CFileDiffDlg::CTGitPath* fd = m_arFilteredList[selIndex]; diff --git a/src/TortoiseProc/GitDiff.cpp b/src/TortoiseProc/GitDiff.cpp index fdb9f2a..cfed705 100644 --- a/src/TortoiseProc/GitDiff.cpp +++ b/src/TortoiseProc/GitDiff.cpp @@ -62,7 +62,7 @@ int CGitDiff::DiffNull(CTGitPath *pPath, git_revnum_t &rev1) return 0; } -int CGitDiff::Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2, bool blame, bool unified) +int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool blame, bool unified) { CString temppath; GetTempPath(temppath); @@ -90,19 +90,19 @@ int CGitDiff::Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2, file2.Format(_T("%s\\%s_%s%s"), temppath, - pPath->GetBaseFilename(), + pPath2->GetBaseFilename(), rev2.Left(6), - pPath->GetFileExtension()); - cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2,pPath->GetGitPathString()); + pPath2->GetFileExtension()); + cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2,pPath2->GetGitPathString()); g_Git.RunLogFile(cmd,file2); }else { - file2=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString(); + file2=g_Git.m_CurrentDir+_T("\\")+pPath2->GetWinPathString(); } CAppUtils::DiffFlags flags; CAppUtils::StartExtDiff(file2,file1, - pPath->GetGitPathString()+_T(":")+rev2.Left(6), + pPath2->GetGitPathString()+_T(":")+rev2.Left(6), pPath->GetGitPathString()+_T(":")+rev1.Left(6) ,flags); diff --git a/src/TortoiseProc/GitDiff.h b/src/TortoiseProc/GitDiff.h index b6162c0..a2e5385 100644 --- a/src/TortoiseProc/GitDiff.h +++ b/src/TortoiseProc/GitDiff.h @@ -10,6 +10,7 @@ public: ~CGitDiff(void); static int Parser(git_revnum_t &rev); - static int Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2, bool blame=false, bool unified=false); + // 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 DiffNull(CTGitPath *pPath, git_revnum_t &rev1); }; -- 2.11.0