OSDN Git Service

Handle Rename case at commit dialog
authorFrank Li <lznuaa@gmail.com>
Tue, 20 Jan 2009 06:56:36 +0000 (14:56 +0800)
committerFrank Li <lznuaa@gmail.com>
Tue, 20 Jan 2009 06:56:36 +0000 (14:56 +0800)
src/Git/GitStatusListCtrl.cpp
src/Git/GitStatusListCtrl.h
src/TortoiseProc/Commands/DiffCommand.cpp
src/TortoiseProc/Commands/PrevDiffCommand.cpp
src/TortoiseProc/FileDiffDlg.cpp
src/TortoiseProc/GitDiff.cpp
src/TortoiseProc/GitDiff.h

index 494f74c..1055bb3 100644 (file)
@@ -4053,10 +4053,21 @@ void CGitStatusListCtrl::StartDiff(int fileindex)
 {\r
        if(fileindex<0)\r
                return;\r
+\r
+       CTGitPath file1=*(CTGitPath*)GetItemData(fileindex);\r
+       CTGitPath file2;\r
+       if(file1.m_Action & CTGitPath::LOGACTIONS_REPLACED)\r
+       {\r
+               file2.SetFromGit(file1.GetGitOldPathString());\r
+       }else\r
+       {\r
+               file2=file1;\r
+       }\r
+\r
        if(this->m_CurrentVersion.IsEmpty() || m_CurrentVersion== GIT_REV_ZERO)\r
        {\r
                if(!g_Git.IsInitRepos())\r
-                       CGitDiff::Diff((CTGitPath*)GetItemData(fileindex),\r
+                       CGitDiff::Diff(&file1,&file2,\r
                                CString(GIT_REV_ZERO),\r
                                        GitRev::GetHead());\r
                else\r
@@ -4064,7 +4075,7 @@ void CGitStatusListCtrl::StartDiff(int fileindex)
                                CString(GIT_REV_ZERO));\r
        }else\r
        {\r
-               CGitDiff::Diff((CTGitPath*)GetItemData(fileindex),\r
+               CGitDiff::Diff(&file1,&file2,\r
                                m_CurrentVersion,\r
                                        m_CurrentVersion+_T("~1"));\r
        }\r
@@ -4150,20 +4161,25 @@ CString CGitStatusListCtrl::GetStatisticsString()
 \r
 }\r
 \r
-CTGitPath CGitStatusListCtrl::GetCommonDirectory(bool bStrict)\r
+CString CGitStatusListCtrl::GetCommonDirectory(bool bStrict)\r
 {\r
        if (!bStrict)\r
        {\r
                // not strict means that the selected folder has priority\r
                if (!m_StatusFileList.GetCommonDirectory().IsEmpty())\r
-                       return m_StatusFileList.GetCommonDirectory();\r
+                       return m_StatusFileList.GetCommonDirectory().GetWinPath();\r
        }\r
 \r
        CTGitPath commonBaseDirectory;\r
        int nListItems = GetItemCount();\r
        for (int i=0; i<nListItems; ++i)\r
        {\r
-               CTGitPath& baseDirectory = *(CTGitPath*)this->GetItemData(i);\r
+               CTGitPath baseDirectory,*p= (CTGitPath*)this->GetItemData(i);\r
+               ASSERT(p);\r
+               if(p==NULL)\r
+                       continue;\r
+               baseDirectory = p->GetDirectory();\r
+\r
                if(commonBaseDirectory.IsEmpty())\r
                {\r
                        commonBaseDirectory = baseDirectory;\r
@@ -4177,7 +4193,7 @@ CTGitPath CGitStatusListCtrl::GetCommonDirectory(bool bStrict)
                        }\r
                }\r
        }\r
-       return commonBaseDirectory;\r
+       return g_Git.m_CurrentDir+CString(_T("\\"))+commonBaseDirectory.GetWinPath();\r
 }\r
 \r
 CTGitPath CGitStatusListCtrl::GetCommonURL(bool bStrict)\r
index 06dbad5..6226cb3 100644 (file)
@@ -638,7 +638,7 @@ public:
         * if \a bStrict is set to false, then the paths passed to the control\r
         * to fetch the status (in GetStatus()) are used if possible.\r
         */\r
-       CTGitPath GetCommonDirectory(bool bStrict);\r
+       CString GetCommonDirectory(bool bStrict);\r
 \r
        /**\r
         * Returns the parent url of all entries in the control.\r
index 1ac7b52..090615a 100644 (file)
@@ -54,7 +54,7 @@ bool DiffCommand::Execute()
 #endif\r
                        {\r
                                //git_revnum_t baseRev = 0;\r
-                               bRet = diff.Diff(&cmdLinePath,git_revnum_t(_T("HEAD")),git_revnum_t(GIT_REV_ZERO));\r
+                               bRet = diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(_T("HEAD")),git_revnum_t(GIT_REV_ZERO));\r
                        }\r
                }\r
        } \r
index 096f494..b8fa037 100644 (file)
@@ -65,7 +65,7 @@ bool PrevDiffCommand::Execute()
                        if( revs.size() == 2 )\r
                        {\r
                                CGitDiff diff;\r
-                               bRet = diff.Diff(&cmdLinePath, revs[0].m_CommitHash, revs[1].m_CommitHash, false);\r
+                               bRet = diff.Diff(&cmdLinePath,&cmdLinePath, revs[0].m_CommitHash, revs[1].m_CommitHash, false);\r
                        }\r
                }\r
                else\r
index d987e40..9796df9 100644 (file)
@@ -318,7 +318,7 @@ void CFileDiffDlg::DoDiff(int selIndex, bool blame)
 \r
        CGitDiff diff;\r
        CTGitPath* fd = m_arFilteredList[selIndex];\r
-       diff.Diff(fd, this->m_rev1.m_CommitHash, this->m_rev2.m_CommitHash, blame, FALSE);\r
+       diff.Diff(fd, fd,this->m_rev1.m_CommitHash, this->m_rev2.m_CommitHash, blame, FALSE);\r
 \r
 #if 0\r
        CFileDiffDlg::CTGitPath* fd = m_arFilteredList[selIndex];\r
index fdb9f2a..cfed705 100644 (file)
@@ -62,7 +62,7 @@ int CGitDiff::DiffNull(CTGitPath *pPath, git_revnum_t &rev1)
        return 0;\r
 }\r
 \r
-int CGitDiff::Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2, bool blame, bool unified)\r
+int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool blame, bool unified)\r
 {\r
        CString temppath;\r
        GetTempPath(temppath);\r
@@ -90,19 +90,19 @@ int CGitDiff::Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2,
                \r
                file2.Format(_T("%s\\%s_%s%s"),\r
                                temppath,                                               \r
-                               pPath->GetBaseFilename(),\r
+                               pPath2->GetBaseFilename(),\r
                                rev2.Left(6),\r
-                               pPath->GetFileExtension());\r
-               cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2,pPath->GetGitPathString());\r
+                               pPath2->GetFileExtension());\r
+               cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2,pPath2->GetGitPathString());\r
                g_Git.RunLogFile(cmd,file2);\r
        }else\r
        {\r
-               file2=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
+               file2=g_Git.m_CurrentDir+_T("\\")+pPath2->GetWinPathString();\r
        }\r
        \r
        CAppUtils::DiffFlags flags;\r
        CAppUtils::StartExtDiff(file2,file1,\r
-                                                       pPath->GetGitPathString()+_T(":")+rev2.Left(6),\r
+                                                       pPath2->GetGitPathString()+_T(":")+rev2.Left(6),\r
                                                        pPath->GetGitPathString()+_T(":")+rev1.Left(6)\r
                                                        ,flags);\r
 \r
index b6162c0..a2e5385 100644 (file)
@@ -10,6 +10,7 @@ public:
        ~CGitDiff(void);\r
        static int Parser(git_revnum_t &rev);\r
 \r
-       static int Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2, bool blame=false, bool unified=false);\r
+       // Use two path to handle rename cases\r
+       static int Diff(CTGitPath * pPath1, CTGitPath *pPath2 ,git_revnum_t & rev1, git_revnum_t & rev2, bool blame=false, bool unified=false);\r
        static int DiffNull(CTGitPath *pPath, git_revnum_t &rev1);\r
 };\r