OSDN Git Service

Using cherry Pick implement combine commits to avoid the rebase start by command...
authorFrank Li <lznuaa@gmail.com>
Wed, 25 Feb 2009 15:24:50 +0000 (23:24 +0800)
committerFrank Li <lznuaa@gmail.com>
Wed, 25 Feb 2009 15:24:50 +0000 (23:24 +0800)
Show progress bar when pick up top commits.

Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/GitLogList.h
src/TortoiseProc/GitLogListAction.cpp
src/Utils/MiscUI/ProgressDlg.cpp
src/Utils/MiscUI/SysProgressDlg.h

index 213363f..bd3c59a 100644 (file)
@@ -9,6 +9,7 @@ class CGitLogList : public CGitLogListBase
 protected:\r
        \r
        void SetSelectedAction(int action);\r
+       int      CherryPickFrom(CString from, CString to);\r
 \r
 public:\r
        void ContextMenuAction(int cmd,int FirstSelect, int LastSelect);\r
index 03c349e..06cadb3 100644 (file)
@@ -20,6 +20,7 @@
 #include "PropDlg.h"\r
 #include "SVNProgressDlg.h"\r
 #include "ProgressDlg.h"\r
+#include "SysProgressDlg.h"\r
 //#include "RepositoryBrowser.h"\r
 //#include "CopyDlg.h"\r
 //#include "StatGraphDlg.h"\r
 \r
 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)\r
 \r
+int CGitLogList::CherryPickFrom(CString from, CString to)\r
+{\r
+       CLogDataVector logs;\r
+       if(logs.ParserFromLog(NULL,-1,0,&from,&to))\r
+               return -1;\r
+\r
+       if(logs.size() == 0)\r
+               return 0;\r
+\r
+       CSysProgressDlg progress;\r
+       if (progress.IsValid())\r
+       {\r
+               progress.SetTitle(_T("Cherry Pick"));\r
+               progress.SetAnimation(IDR_MOVEANI);\r
+               progress.SetTime(true);\r
+               progress.ShowModeless(this);\r
+       }\r
+\r
+       for(int i=logs.size()-1;i>=0;i--)\r
+       {\r
+               if (progress.IsValid())\r
+               {\r
+                       progress.FormatPathLine(1, _T("Pick up %s"), logs[i].m_CommitHash);\r
+                       progress.FormatPathLine(2, _T("%s"), logs[i].m_Subject);\r
+                       progress.SetProgress(logs.size()-i, logs.size());\r
+               }\r
+               if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
+               {\r
+                       //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);\r
+                       throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));\r
+                       return -1;\r
+               }\r
+               CString cmd,out;\r
+               cmd.Format(_T("git.exe cherry-pick %s"),logs[i].m_CommitHash);\r
+               out.Empty();\r
+               if(g_Git.Run(cmd,&out,CP_UTF8))\r
+               {\r
+                       throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out));\r
+                       return -1;\r
+               }\r
+       }\r
+       \r
+       return 0;\r
+}\r
+\r
 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)\r
 {      \r
        POSITION pos = GetFirstSelectedItemPosition();\r
@@ -270,6 +316,13 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)
                                                //\r
                                                //Later the progress dialog could be used to execute these steps.\r
 \r
+                                               if(CherryPickFrom(pFirstEntry->m_CommitHash,headhash))\r
+                                               {\r
+                                                       CString msg;\r
+                                                       msg.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));\r
+                                                       throw std::exception(CUnicodeUtils::GetUTF8(msg));\r
+                                               }\r
+#if 0\r
                                                CString currentBranch=g_Git.GetCurrentBranch();\r
                                                cmd.Format(_T("git.exe rebase --onto \"%s\" %s %s"),\r
                                                        currentBranch,\r
@@ -302,6 +355,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)
                                                cmd.Format(_T("git.exe reset --hard  %s"),newHead);\r
                                                if(g_Git.Run(cmd,&out,CP_UTF8))\r
                                                        throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out));\r
+#endif\r
                                        }\r
                                }\r
                                else\r
index 05024a2..efb261d 100644 (file)
@@ -149,6 +149,18 @@ void CSysProgressDlg::FormatPathLine ( DWORD dwLine, UINT idFormatText, ...)
        va_end(args);\r
 }\r
 \r
+void CSysProgressDlg::FormatPathLine ( DWORD dwLine, CString FormatText, ...)\r
+{\r
+       va_list args;\r
+       va_start(args, FormatText);\r
+\r
+       CString sText;\r
+       sText.FormatV(CString(FormatText), args);\r
+       SetLine(dwLine, sText, true);\r
+\r
+       va_end(args);\r
+}\r
+\r
 void CSysProgressDlg::FormatNonPathLine(DWORD dwLine, UINT idFormatText, ...)\r
 {\r
        va_list args;\r
index 95aa626..05d8911 100644 (file)
@@ -63,6 +63,7 @@ public:
        * the system to measure the space available for the text, and do path compaction properly\r
        */\r
        void FormatPathLine ( DWORD dwLine, UINT idFormatText, ...);\r
+       void FormatPathLine ( DWORD dwLine, CString FormatText, ...);\r
        void FormatNonPathLine ( DWORD dwLine, UINT idFormatText, ...);\r
 #endif\r
     /**\r