OSDN Git Service

TGitPath Add Rename handle
authorFrank Li <lznuaa@gmail.com>
Mon, 19 Jan 2009 15:32:53 +0000 (23:32 +0800)
committerFrank Li <lznuaa@gmail.com>
Mon, 19 Jan 2009 15:32:53 +0000 (23:32 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Git/GitStatusListCtrl.cpp
src/Git/TGitPath.cpp
src/Git/TGitPath.h
src/TortoiseProc/CommitDlg.cpp
src/TortoiseProc/TortoiseProc.vcproj
src/TortoiseProc/TortoiseProc.vcproj.FSL.B20596.user

index 46aebff..a2c7e45 100644 (file)
@@ -1442,6 +1442,11 @@ void CGitStatusListCtrl::AddEntry(CTGitPath * GitPath, WORD langID, int listInde
                icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);\r
        }\r
        // relative path\r
                icon_idx = SYS_IMAGE_LIST().GetPathIconIndex(*GitPath);\r
        }\r
        // relative path\r
+       CString rename;\r
+       rename.Format(_T("(from %s)"),GitPath->GetGitOldPathString());\r
+       if(GitPath->m_Action & CTGitPath::LOGACTIONS_REPLACED)\r
+               entryname+=rename;\r
+       \r
        InsertItem(index, entryname, icon_idx);\r
 \r
        this->SetItemData(index, (DWORD_PTR)GitPath);\r
        InsertItem(index, entryname, icon_idx);\r
 \r
        this->SetItemData(index, (DWORD_PTR)GitPath);\r
index b0aec5c..018f272 100644 (file)
@@ -116,11 +116,13 @@ void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
        m_bIsDirectory = bIsDirectory;\r
 }\r
 \r
        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
 {\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
 }\r
 \r
 void CTGitPath::SetFromWin(LPCTSTR pPath)\r
@@ -188,6 +190,10 @@ const CString& CTGitPath::GetGitPathString() const
        return m_sFwdslashPath;\r
 }\r
 \r
        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
 #if 0\r
 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const\r
 {\r
@@ -876,6 +882,7 @@ int CTGitPathList::ParserFromLog(CString &log)
        while( pos>=0 )\r
        {\r
                one=log.Tokenize(_T("\n"),pos);\r
        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
                if(one[0]==_T(':'))\r
                {\r
                        int tabstart=0;\r
@@ -901,15 +908,30 @@ int CTGitPathList::ParserFromLog(CString &log)
                                                        \r
                                }else\r
                                {       \r
                                                        \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
                                        //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
                                        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
                        int tabstart=0;\r
                        path.Reset();\r
                        CString StatAdd=(one.Tokenize(_T("\t"),tabstart));\r
@@ -917,7 +939,13 @@ int CTGitPathList::ParserFromLog(CString &log)
                                break;\r
                        CString StatDel=(one.Tokenize(_T("\t"),tabstart));\r
                        //SetFromGit will reset all context of GitRev\r
                                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
+                               path.SetFromGit(one.Right(one.GetLength()-rename-4),&one.Left(rename));\r
+                       }else\r
+                               path.SetFromGit(one.Right(one.GetLength()-tabstart));\r
                                \r
                        CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());\r
                        if(GitPath)\r
                                \r
                        CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());\r
                        if(GitPath)\r
@@ -932,6 +960,7 @@ int CTGitPathList::ParserFromLog(CString &log)
                                AddPath(path);\r
                        }\r
                }\r
                                AddPath(path);\r
                        }\r
                }\r
+\r
        }\r
        return pos;\r
 }\r
        }\r
        return pos;\r
 }\r
index 130e5ee..5b99a67 100644 (file)
@@ -29,7 +29,8 @@ public:
         */\r
        void SetFromGit(const char* pPath);\r
        void SetFromGit(const char* pPath, bool bIsDirectory);\r
         */\r
        void SetFromGit(const char* pPath);\r
        void SetFromGit(const char* pPath, bool bIsDirectory);\r
-       void SetFromGit(const CString& sPath);\r
+       void SetFromGit(const CString& sPath,CString *OldPath=NULL);\r
+       \r
        /**\r
         * Set the path as UNICODE with backslashes\r
         */\r
        /**\r
         * Set the path as UNICODE with backslashes\r
         */\r
@@ -52,6 +53,8 @@ public:
         * Returns the path with forward slashes.\r
         */\r
        const CString& GetGitPathString() const;\r
         * Returns the path with forward slashes.\r
         */\r
        const CString& GetGitPathString() const;\r
+\r
+       const CString& GetGitOldPathString() const;\r
        /**\r
         * Returns the path completely prepared to be fed the the Git APIs\r
         * It will be in UTF8, with URLs escaped, if necessary\r
        /**\r
         * Returns the path completely prepared to be fed the the Git APIs\r
         * It will be in UTF8, with URLs escaped, if necessary\r
@@ -245,6 +248,11 @@ private:
        mutable CString m_sUIPath;\r
        mutable CStringA m_sUTF8FwdslashPath;\r
        mutable CStringA m_sUTF8FwdslashPathEscaped;\r
        mutable CString m_sUIPath;\r
        mutable CStringA m_sUTF8FwdslashPath;\r
        mutable CStringA m_sUTF8FwdslashPathEscaped;\r
+\r
+       //used for rename case\r
+       mutable CString m_sOldBackslashPath;\r
+       mutable CString m_sOldFwdslashPath;\r
+       \r
        // Have we yet determined if this is a directory or not?\r
        mutable bool m_bDirectoryKnown;\r
        mutable bool m_bIsDirectory;\r
        // Have we yet determined if this is a directory or not?\r
        mutable bool m_bDirectoryKnown;\r
        mutable bool m_bIsDirectory;\r
index 56ef4a8..7b23d16 100644 (file)
@@ -337,6 +337,7 @@ void CCommitDlg::OnOK()
        //first add all the unversioned files the user selected\r
        //and check if all versioned files are selected\r
        int nUnchecked = 0;\r
        //first add all the unversioned files the user selected\r
        //and check if all versioned files are selected\r
        int nUnchecked = 0;\r
+       int nchecked = 0;\r
        m_bRecursive = true;\r
        int nListItems = m_ListCtrl.GetItemCount();\r
 \r
        m_bRecursive = true;\r
        int nListItems = m_ListCtrl.GetItemCount();\r
 \r
@@ -347,8 +348,11 @@ void CCommitDlg::OnOK()
        //std::set<CString> checkedLists;\r
        //std::set<CString> uncheckedLists;\r
 \r
        //std::set<CString> checkedLists;\r
        //std::set<CString> uncheckedLists;\r
 \r
-       CString checkedfiles;\r
-       CString uncheckedfiles;\r
+       //CString checkedfiles;\r
+       //CString uncheckedfiles;\r
+\r
+       CString cmd;\r
+       CString out;\r
 \r
        for (int j=0; j<nListItems; j++)\r
        {\r
 \r
        for (int j=0; j<nListItems; j++)\r
        {\r
@@ -378,13 +382,27 @@ void CCommitDlg::OnOK()
                                bCheckedInExternal = true;\r
                        }\r
 #endif\r
                                bCheckedInExternal = true;\r
                        }\r
 #endif\r
+                       cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());\r
+                       g_Git.Run(cmd,&out);\r
+                       nchecked++;\r
                        //checkedLists.insert(entry->GetGitPathString());\r
                        //checkedLists.insert(entry->GetGitPathString());\r
-                       checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
+//                     checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
                }\r
                else\r
                {\r
                        //uncheckedLists.insert(entry->GetGitPathString());\r
                }\r
                else\r
                {\r
                        //uncheckedLists.insert(entry->GetGitPathString());\r
-                       uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
+                       if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)\r
+                       {       //To init git repository, there are not HEAD, so we can use git reset command\r
+                               cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());\r
+                               g_Git.Run(cmd,&out);    \r
+                       }\r
+                       else\r
+                       {\r
+                               cmd.Format(_T("git.exe reset -- %s"),entry->GetGitPathString());\r
+                               g_Git.Run(cmd,&out);\r
+                       }\r
+\r
+               //      uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
 #if 0\r
                        if ((entry->status != Git_wc_status_unversioned)        &&\r
                                (entry->status != Git_wc_status_ignored))\r
 #if 0\r
                        if ((entry->status != Git_wc_status_unversioned)        &&\r
                                (entry->status != Git_wc_status_ignored))\r
@@ -412,18 +430,17 @@ void CCommitDlg::OnOK()
                }\r
        }\r
 \r
                }\r
        }\r
 \r
-       CString cmd;\r
-       CString out;\r
-       if(uncheckedfiles.GetLength()>0)\r
-       {\r
-               cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);\r
-               g_Git.Run(cmd,&out);\r
-       }\r
+       //if(uncheckedfiles.GetLength()>0)\r
+       //{\r
+       //      cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);\r
+       //      g_Git.Run(cmd,&out);\r
+       //}\r
 \r
 \r
-       if(checkedfiles.GetLength()>0)\r
+       //if(checkedfiles.GetLength()>0)\r
+       if(nchecked)\r
        {\r
        {\r
-               cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);\r
-               g_Git.Run(cmd,&out);\r
+       //      cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);\r
+       //      g_Git.Run(cmd,&out);\r
 \r
                CString tempfile=::GetTempFile();\r
                CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
 \r
                CString tempfile=::GetTempFile();\r
                CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
@@ -1034,6 +1051,9 @@ void CCommitDlg::GetAutocompletionList()
 \r
                CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);\r
 \r
 \r
                CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);\r
 \r
+               if(path == NULL)\r
+                       continue;\r
+\r
                CString sPartPath =path->GetGitPathString();\r
                m_autolist.insert(sPartPath);\r
 \r
                CString sPartPath =path->GetGitPathString();\r
                m_autolist.insert(sPartPath);\r
 \r
index 3d68115..aa7f0de 100644 (file)
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\explorer.ico"\r
+                               RelativePath="..\Resources\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\explorer.ico"\r
+                               RelativePath=".\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\newfolder.ico"\r
+                               RelativePath="..\Resources\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\newfolder.ico"\r
+                               RelativePath=".\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\open.ico"\r
+                               RelativePath="..\Resources\open.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\open.ico"\r
+                               RelativePath=".\open.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\save.ico"\r
+                               RelativePath="..\Resources\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\save.ico"\r
+                               RelativePath=".\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\saveas.ico"\r
+                               RelativePath="..\Resources\saveas.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\saveas.ico"\r
+                               RelativePath=".\saveas.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\up.ico"\r
+                               RelativePath="..\Resources\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\up.ico"\r
+                               RelativePath=".\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
                                        >\r
                                </File>\r
                        </Filter>\r
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="Compare"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\Commands\ShowCompareCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\ShowCompareCommand.h"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Utility Dialogs"\r
                </Filter>\r
                <Filter\r
                        Name="Utility Dialogs"\r
                                RelativePath=".\SwitchDlg.h"\r
                                >\r
                        </File>\r
                                RelativePath=".\SwitchDlg.h"\r
                                >\r
                        </File>\r
-                       <Filter\r
-                               Name="Compare"\r
-                               >\r
-                               <File\r
-                                       RelativePath=".\Commands\ShowCompareCommand.cpp"\r
-                                       >\r
-                               </File>\r
-                               <File\r
-                                       RelativePath=".\Commands\ShowCompareCommand.h"\r
-                                       >\r
-                               </File>\r
-                       </Filter>\r
                </Filter>\r
                <File\r
                        RelativePath="Resource.h"\r
                </Filter>\r
                <File\r
                        RelativePath="Resource.h"\r
index d63f029..271096d 100644 (file)
@@ -11,7 +11,7 @@
                        <DebugSettings\r
                                Command="$(TargetPath)"\r
                                WorkingDirectory="D:\Profiles\b20596\tortoisegit"\r
                        <DebugSettings\r
                                Command="$(TargetPath)"\r
                                WorkingDirectory="D:\Profiles\b20596\tortoisegit"\r
-                               CommandArguments="/command:log /path:&quot;D:\\test4\\tt&quot;"\r
+                               CommandArguments="/command:commit /path:&quot;D:\\test4\\tt&quot;"\r
                                Attach="false"\r
                                DebuggerType="3"\r
                                Remote="1"\r
                                Attach="false"\r
                                DebuggerType="3"\r
                                Remote="1"\r