OSDN Git Service

Handle Rename case when rename files is in difference dir
[tortoisegit/TortoiseGitJp.git] / src / Git / TGitPath.cpp
index 7417a4f..418f236 100644 (file)
@@ -28,6 +28,9 @@
 //#include "AppUtils.h"\r
 #endif\r
 \r
+#ifndef ASSERT\r
+#define ASSERT()\r
+#endif\r
 using namespace std;\r
 extern CGit g_Git;\r
 \r
@@ -116,11 +119,13 @@ void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
        m_bIsDirectory = bIsDirectory;\r
 }\r
 \r
-void CTGitPath::SetFromGit(const CString& sPath)\r
+void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)\r
 {\r
        Reset();\r
        m_sFwdslashPath = sPath;\r
        SanitizeRootPath(m_sFwdslashPath, true);\r
+       if(oldpath)\r
+               m_sOldFwdslashPath = *oldpath;\r
 }\r
 \r
 void CTGitPath::SetFromWin(LPCTSTR pPath)\r
@@ -188,6 +193,10 @@ const CString& CTGitPath::GetGitPathString() const
        return m_sFwdslashPath;\r
 }\r
 \r
+const CString &CTGitPath::GetGitOldPathString() const\r
+{\r
+       return m_sOldFwdslashPath;\r
+}\r
 #if 0\r
 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const\r
 {\r
@@ -816,27 +825,53 @@ CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
 {\r
        AddPath(firstEntry);\r
 }\r
-int CTGitPathList::FillUnRev(int action)\r
+int CTGitPathList::FillUnRev(int action,CTGitPathList *list)\r
 {\r
        int pos=0;\r
        this->Clear();\r
        CTGitPath path;\r
-       \r
-       CString cmd(_T("git.cmd ls-files --exclude-standard --full-name --others"));\r
-       if(action & CTGitPath::LOGACTIONS_IGNORE)\r
-               cmd += _T(" --ignored");\r
-       CString out;\r
-       g_Git.Run(cmd,&out);\r
 \r
-       CString one;\r
-       while( pos>=0 )\r
-       {\r
-               one=out.Tokenize(_T("\n"),pos);\r
+       int count;\r
+       if(list==NULL)\r
+               count=1;\r
+       else\r
+               count=list->GetCount();\r
+       for(int i=0;i<count;i++)\r
+       {       \r
+               CString cmd;\r
+               pos=0;\r
+               \r
+               CString ignored;\r
+               if(action & CTGitPath::LOGACTIONS_IGNORE)\r
+                       ignored= _T(" --ignored");\r
+               \r
+               if(list==NULL)\r
+               {\r
+                       cmd=_T("git.exe ls-files --exclude-standard --full-name --others");\r
+                       cmd+=ignored;\r
+                       \r
+               }\r
+               else\r
+               {       cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others %s-- \"%s\""),\r
+                                       ignored,\r
+                                       (*list)[i].GetWinPathString());\r
+               }\r
+               \r
+               CString out;\r
+               g_Git.Run(cmd,&out);\r
 \r
-               //SetFromGit will clear all status\r
-               path.SetFromGit(one);\r
-               path.m_Action=action;\r
-               AddPath(path);\r
+               CString one;\r
+               while( pos>=0 )\r
+               {\r
+                       one=out.Tokenize(_T("\n"),pos);\r
+                       if(!one.IsEmpty())\r
+                       {\r
+                               //SetFromGit will clear all status\r
+                               path.SetFromGit(one);\r
+                               path.m_Action=action;\r
+                               AddPath(path);\r
+                       }\r
+               }\r
        }\r
        return 0;\r
 }\r
@@ -850,6 +885,7 @@ int CTGitPathList::ParserFromLog(CString &log)
        while( pos>=0 )\r
        {\r
                one=log.Tokenize(_T("\n"),pos);\r
+               path.Reset();\r
                if(one[0]==_T(':'))\r
                {\r
                        int tabstart=0;\r
@@ -875,15 +911,30 @@ int CTGitPathList::ParserFromLog(CString &log)
                                                        \r
                                }else\r
                                {       \r
-                                       path.SetFromGit(pathname);\r
+                                       int ac=path.ParserAction(action);\r
+                                       if(ac & CTGitPath::LOGACTIONS_REPLACED)\r
+                                       {\r
+                                               CString oldname;\r
+                                               int oldnametab=pathname.Find(_T("\t"));\r
+                                               if(oldnametab>0)\r
+                                                       path.SetFromGit(pathname.Right(pathname.GetLength()-oldnametab-1),&pathname.Left(oldnametab));\r
+                                               else\r
+                                               {\r
+                                                       ASSERT(FALSE);\r
+                                                       path.SetFromGit(pathname);\r
+                                               }\r
+                                       }else\r
+                                               path.SetFromGit(pathname);\r
+                                       path.m_Action=ac;\r
                                        //action must be set after setfromgit. SetFromGit will clear all status. \r
-                                       this->m_Action|=path.ParserAction(action);\r
+                                       this->m_Action|=ac;\r
                                        AddPath(path);\r
                                }\r
                        }\r
                                        \r
                }else\r
                {\r
+\r
                        int tabstart=0;\r
                        path.Reset();\r
                        CString StatAdd=(one.Tokenize(_T("\t"),tabstart));\r
@@ -891,7 +942,22 @@ int CTGitPathList::ParserFromLog(CString &log)
                                break;\r
                        CString StatDel=(one.Tokenize(_T("\t"),tabstart));\r
                        //SetFromGit will reset all context of GitRev\r
-                       path.SetFromGit(one.Right(one.GetLength()-tabstart));\r
+                       one=one.Right(one.GetLength()-tabstart);\r
+                       int rename=one.Find(_T(" => "));\r
+                       if(rename>0)\r
+                       {\r
+                               CString basepath;\r
+                               int include_left=one.Find(_T("/{"));\r
+                               if(include_left>0)\r
+                               {\r
+                                       basepath=one.Left(include_left+1);\r
+                                       CString newname=basepath+one.Mid(rename+4,one.GetLength()-rename-5);\r
+                                       CString oldname=basepath+one.Mid(include_left+2,rename-include_left-2);\r
+                                       path.SetFromGit(newname,&oldname        );\r
+                               }else\r
+                                       path.SetFromGit(one.Right(one.GetLength()-rename-4),&one.Left(rename));\r
+                       }else\r
+                               path.SetFromGit(one);\r
                                \r
                        CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());\r
                        if(GitPath)\r
@@ -906,6 +972,7 @@ int CTGitPathList::ParserFromLog(CString &log)
                                AddPath(path);\r
                        }\r
                }\r
+\r
        }\r
        return pos;\r
 }\r