OSDN Git Service

Add Combine Commit to one commit at log list dialog
authorFrank Li <lznuaa@gmail.com>
Fri, 20 Feb 2009 16:10:02 +0000 (00:10 +0800)
committerFrank Li <lznuaa@gmail.com>
Fri, 20 Feb 2009 16:10:02 +0000 (00:10 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/CommitDlg.cpp
src/TortoiseProc/GitLogListAction.cpp
src/TortoiseProc/GitLogListBase.cpp
src/TortoiseProc/GitLogListBase.h

index b2e0879..84220a7 100644 (file)
@@ -57,6 +57,7 @@ CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
        , m_itemsCount(0)\r
        , m_bSelectFilesForCommit(TRUE)\r
 {\r
        , m_itemsCount(0)\r
        , m_bSelectFilesForCommit(TRUE)\r
 {\r
+       this->m_bCommitAmend=FALSE;\r
 }\r
 \r
 CCommitDlg::~CCommitDlg()\r
 }\r
 \r
 CCommitDlg::~CCommitDlg()\r
@@ -284,9 +285,9 @@ BOOL CCommitDlg::OnInitDialog()
        }\r
        err = FALSE;\r
 \r
        }\r
        err = FALSE;\r
 \r
-       this->UpdateData(TRUE);\r
-       this->m_bCommitAmend=FALSE;\r
-       this->UpdateData(FALSE);\r
+       //this->UpdateData(TRUE);\r
+       //this->m_bCommitAmend=FALSE;\r
+       //this->UpdateData(FALSE);\r
 \r
        return FALSE;  // return TRUE unless you set the focus to a control\r
        // EXCEPTION: OCX Property Pages should return FALSE\r
 \r
        return FALSE;  // return TRUE unless you set the focus to a control\r
        // EXCEPTION: OCX Property Pages should return FALSE\r
index 0b3d003..86bd2cc 100644 (file)
@@ -45,6 +45,7 @@
 //#include "RepositoryInfo.h"\r
 //#include "EditPropertiesDlg.h"\r
 #include "FileDiffDlg.h"\r
 //#include "RepositoryInfo.h"\r
 //#include "EditPropertiesDlg.h"\r
 #include "FileDiffDlg.h"\r
+#include "CommitDlg.h"\r
 \r
 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)\r
 \r
 \r
 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)\r
 \r
@@ -188,6 +189,62 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)
                case ID_REBASE_SKIP:\r
                        SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);\r
                        break;\r
                case ID_REBASE_SKIP:\r
                        SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);\r
                        break;\r
+               case ID_COMBINE_COMMIT:\r
+               {\r
+                       CString head;\r
+                       CString headhash;\r
+                       \r
+                       head.Format(_T("HEAD~%d"),LastSelect);\r
+                       CString hash=g_Git.GetHash(head);\r
+                       hash=hash.Left(40);\r
+                       \r
+                       headhash=g_Git.GetHash(CString(_T("HEAD")));\r
+                       headhash=headhash.Left(40);                     \r
+                       \r
+                       GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));\r
+                       if(pLastEntry->m_CommitHash != hash)\r
+                       {\r
+                               CMessageBox::Show(NULL,_T("Only combine top continuous commit"),_T("TortoiseGit"),MB_OK);\r
+                       }\r
+                       if(!g_Git.CheckCleanWorkTree())\r
+                       {\r
+                               CMessageBox::Show(NULL,_T("Combine need clean work tree"),_T("TortoiseGit"),MB_OK);\r
+                               break;\r
+                       }\r
+                       CString cmd,out;\r
+\r
+                       cmd.Format(_T("git.exe reset --mixed  %s"),hash);\r
+                       if(g_Git.Run(cmd,&out,CP_UTF8))\r
+                       {\r
+                               CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);\r
+                       }\r
+                       CCommitDlg dlg;\r
+                       for(int i=FirstSelect;i<=LastSelect;i++)\r
+                       {\r
+                               GitRev* pRev = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));\r
+                               dlg.m_sLogMessage+=pRev->m_Subject+_T("\n")+pRev->m_Body;\r
+                               dlg.m_sLogMessage+=_T("\n");\r
+                       }\r
+                       dlg.m_bWholeProject=true;\r
+                       dlg.m_bSelectFilesForCommit = true;\r
+                       dlg.m_bCommitAmend=true;\r
+                       dlg.m_AmendStr=dlg.m_sLogMessage;\r
+\r
+                       if (dlg.DoModal() == IDOK)\r
+                       {\r
+                                                                       \r
+                       }else\r
+                       {\r
+                               cmd.Format(_T("git.exe reset --hard  %s"),headhash);\r
+                               out.Empty();\r
+                               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+                               {\r
+                                       CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);\r
+                               }\r
+                       }\r
+                       Refresh();\r
+               }\r
+                       break;\r
                default:\r
                        //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);\r
                        break;\r
                default:\r
                        //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);\r
                        break;\r
index 3bc63a3..da2078b 100644 (file)
@@ -1133,6 +1133,7 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
                                if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))\r
                                        popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);\r
                        }\r
                                if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))\r
                                        popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);\r
                        }\r
+\r
                        if (GetSelectedCount() == 2)\r
                        {\r
                                //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);\r
                        if (GetSelectedCount() == 2)\r
                        {\r
                                //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);\r
@@ -1140,6 +1141,20 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
                                        popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);\r
                                bAddSeparator = true;\r
                        }\r
                                        popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);\r
                                bAddSeparator = true;\r
                        }\r
+\r
+                       if ( IsSelectionContinuous() )\r
+                       {\r
+                               if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))\r
+                               {\r
+                                       CString head;\r
+                                       head.Format(_T("HEAD~%d"),LastSelect);\r
+                                       CString hash=g_Git.GetHash(head);\r
+                                       hash=hash.Left(40);\r
+                                       GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));\r
+                                       if(pLastEntry->m_CommitHash == hash)\r
+                                               popup.AppendMenuIcon(ID_COMBINE_COMMIT,_T("Combine to one commit"),IDI_MERGE);\r
+                               }\r
+                       }\r
                        if (m_hasWC)\r
                        {\r
                                //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);\r
                        if (m_hasWC)\r
                        {\r
                                //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);\r
index 659c881..6ed2495 100644 (file)
@@ -138,6 +138,7 @@ public:
        ID_REBASE_EDIT,\r
        ID_REBASE_SQUASH,\r
        ID_REBASE_SKIP,\r
        ID_REBASE_EDIT,\r
        ID_REBASE_SQUASH,\r
        ID_REBASE_SKIP,\r
+       ID_COMBINE_COMMIT,\r
        };\r
        inline unsigned __int64 GetContextMenuBit(int i){ return ((unsigned __int64 )0x1)<<i ;}\r
        void InsertGitColumn();\r
        };\r
        inline unsigned __int64 GetContextMenuBit(int i){ return ((unsigned __int64 )0x1)<<i ;}\r
        void InsertGitColumn();\r