OSDN Git Service

Fixed issue #104: Doubleclicking changed submodule dir in Check For Modifications...
authorFrank Li <lznuaa@gmail.com>
Sun, 5 Jul 2009 15:41:25 +0000 (23:41 +0800)
committerFrank Li <lznuaa@gmail.com>
Sun, 5 Jul 2009 15:41:25 +0000 (23:41 +0800)
Fix check modify case.

Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/GitDiff.cpp
src/TortoiseProc/GitDiff.h

index 059920c..e4b1055 100644 (file)
@@ -72,20 +72,55 @@ int CGitDiff::DiffNull(CTGitPath *pPath, git_revnum_t &rev1,bool bIsAdd)
        return 0;\r
 }\r
 \r
-int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/)\r
+int CGitDiff::SubmoduleDiff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, git_revnum_t & rev2, bool /*blame*/, bool /*unified*/)\r
 {\r
-       CString temppath;\r
-       GetTempPath(temppath);\r
-       Parser(rev1);\r
-       Parser(rev2);\r
-       CString file1;\r
-       CString title1;\r
-       CString cmd;\r
+       CString oldhash;\r
+       CString newhash;\r
+       oldhash = GIT_REV_ZERO;\r
+       newhash = GIT_REV_ZERO;\r
+       CString cmd,err;\r
+       CString workingcopy;\r
+\r
+       if( rev2 == GIT_REV_ZERO || rev1 == GIT_REV_ZERO )\r
+       {\r
+               CString rev;\r
+               if( rev2 != GIT_REV_ZERO )\r
+                       rev = rev2;\r
+               if( rev1 != GIT_REV_ZERO )\r
+                       rev = rev1;\r
+               \r
+               workingcopy = _T("(Work Copy)");\r
 \r
-       if(pPath->IsDirectory() || pPath2->IsDirectory())\r
+               cmd.Format(_T("git.exe diff %s -- \"%s\""),\r
+               rev,pPath->GetGitPathString());\r
+\r
+               CString output;\r
+               if(g_Git.Run(cmd,&output,CP_ACP))\r
+               {\r
+                       CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                       return -1;\r
+               }\r
+               int start =0;\r
+               int oldstart = output.Find(_T("-Subproject commit"),start);\r
+               if(oldstart<0)\r
+               {\r
+                       CMessageBox::Show(NULL,_T("Subproject Diff Format error") ,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                       return -1;\r
+               }\r
+               oldhash = output.Mid(oldstart+ CString(_T("-Subproject commit")).GetLength()+1,40);\r
+               start = 0;\r
+               int newstart = output.Find(_T("+Subproject commit"),start);\r
+               if(oldstart<0)\r
+               {\r
+                       CMessageBox::Show(NULL,_T("Subproject Diff Format error") ,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                       return -1;\r
+               }\r
+               newhash = output.Mid(newstart+ CString(_T("+Subproject commit")).GetLength()+1,40);\r
+               \r
+       }else\r
        {\r
                cmd.Format(_T("git.exe diff-tree -r -z %s %s -- \"%s\""),\r
-                       rev2,rev1,pPath->GetGitPathString());\r
+               rev2,rev1,pPath->GetGitPathString());\r
                \r
                BYTE_VECTOR bytes;\r
                if(g_Git.Run(cmd,&bytes))\r
@@ -93,46 +128,61 @@ int CGitDiff::Diff(CTGitPath * pPath,CTGitPath * pPath2, git_revnum_t & rev1, gi
                        CString err;\r
                        g_Git.StringAppend(&err,&bytes[0],CP_ACP);\r
                        CMessageBox::Show(NULL,err,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                       return -1;\r
                }\r
-               \r
-               CString oldhash;\r
+\r
                g_Git.StringAppend(&oldhash,&bytes[15],CP_ACP,40);\r
-               CString newhash;\r
                g_Git.StringAppend(&newhash,&bytes[15+41],CP_ACP,40);\r
+               \r
+       }\r
+               \r
+       CString oldsub;\r
+       CString newsub;\r
 \r
-               CString oldsub;\r
-               CString newsub;\r
+       CGit subgit; \r
+       subgit.m_CurrentDir=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
 \r
-               CGit subgit; \r
-               subgit.m_CurrentDir=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
+       if(pPath->HasAdminDir())\r
+       {\r
+               int encode=CAppUtils::GetLogOutputEncode(&subgit);\r
 \r
-               CString cmd;\r
-               if(pPath->HasAdminDir())\r
+               if(oldhash != GIT_REV_ZERO)\r
+               {\r
+                       cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),oldhash);\r
+                       subgit.Run(cmd,&oldsub,encode);\r
+               }\r
+               if(newsub != GIT_REV_ZERO)\r
                {\r
-                       int encode=CAppUtils::GetLogOutputEncode(&subgit);\r
-\r
-                       if(oldhash != GIT_REV_ZERO)\r
-                       {\r
-                               cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),oldhash);\r
-                               subgit.Run(cmd,&oldsub,encode);\r
-                       }\r
-\r
-                       if(newsub != GIT_REV_ZERO)\r
-                       {\r
-                               cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),newhash);\r
-                               subgit.Run(cmd,&newsub,encode);\r
-                       }\r
+                       cmd.Format(_T("git log -n1 HEAD --pretty=format:\"%%s\" %s"),newhash);\r
+                       subgit.Run(cmd,&newsub,encode);\r
                }\r
-               CString msg;\r
-               msg.Format(_T("Submodule <b>%s</b> Change\r\n\r\n<b>From:</b> %s\r\n\t%s\r\n\r\n<b>To:</b>     %s\r\n\t\t%s"),\r
-                                  pPath->GetWinPath(),\r
-                                  oldhash,\r
-                                  oldsub ,\r
-                                  newhash,\r
-                                  newsub);\r
-               CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);\r
+       }\r
+       CString msg;\r
+       msg.Format(_T("Submodule <b>%s</b> Change\r\n\r\n<b>From:</b> %s\r\n\t%s\r\n\r\n<b>To%s:</b>     %s\r\n\t\t%s"),\r
+                          pPath->GetWinPath(),\r
+                          oldhash,\r
+                          oldsub ,\r
+                          workingcopy,\r
+                          newhash,\r
+                          newsub);\r
+       CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);\r
 \r
-               return 0;\r
+       return 0;\r
+}\r
+\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
+       Parser(rev1);\r
+       Parser(rev2);\r
+       CString file1;\r
+       CString title1;\r
+       CString cmd;\r
+\r
+       if(pPath->IsDirectory() || pPath2->IsDirectory())\r
+       {\r
+               return SubmoduleDiff(pPath,pPath2,rev1,rev2);\r
        }\r
 \r
        if(rev1 != GIT_REV_ZERO )\r
index 4a7c048..7826573 100644 (file)
@@ -12,5 +12,6 @@ public:
 \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 SubmoduleDiff(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,bool bIsAdd=true);\r
 };\r