OSDN Git Service

Merge remove x86 build
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RebaseDlg.cpp
1 // RebaseDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "RebaseDlg.h"\r
7 #include "AppUtils.h"\r
8 #include "MessageBox.h"\r
9 #include "UnicodeUtils.h"\r
10 // CRebaseDlg dialog\r
11 \r
12 IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog)\r
13 \r
14 CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)\r
15         : CResizableStandAloneDialog(CRebaseDlg::IDD, pParent)\r
16     , m_bPickAll(FALSE)\r
17     , m_bSquashAll(FALSE)\r
18     , m_bEditAll(FALSE)\r
19 {\r
20         m_RebaseStage=CHOOSE_BRANCH;\r
21         m_CurrentRebaseIndex=-1;\r
22         m_bThreadRunning =FALSE;\r
23 }\r
24 \r
25 CRebaseDlg::~CRebaseDlg()\r
26 {\r
27 }\r
28 \r
29 void CRebaseDlg::DoDataExchange(CDataExchange* pDX)\r
30 {\r
31     CDialog::DoDataExchange(pDX);\r
32     DDX_Control(pDX, IDC_REBASE_PROGRESS, m_ProgressBar);\r
33     DDX_Control(pDX, IDC_STATUS_STATIC, m_CtrlStatusText);\r
34     DDX_Check(pDX, IDC_PICK_ALL, m_bPickAll);\r
35     DDX_Check(pDX, IDC_SQUASH_ALL, m_bSquashAll);\r
36     DDX_Check(pDX, IDC_EDIT_ALL, m_bEditAll);\r
37         DDX_Control(pDX, IDC_REBASE_SPLIT, m_wndSplitter);\r
38         DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);\r
39         DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);\r
40         DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM,   this->m_UpstreamCtrl);\r
41 \r
42 }\r
43 \r
44 \r
45 BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)\r
46     ON_BN_CLICKED(IDC_PICK_ALL, &CRebaseDlg::OnBnClickedPickAll)\r
47     ON_BN_CLICKED(IDC_SQUASH_ALL, &CRebaseDlg::OnBnClickedSquashAll)\r
48     ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)\r
49     ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)\r
50         ON_BN_CLICKED(IDC_REBASE_CONTINUE,OnBnClickedContinue)\r
51         ON_BN_CLICKED(IDC_REBASE_ABORT,  OnBnClickedAbort)\r
52         ON_WM_SIZE()\r
53         ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH,   &CRebaseDlg::OnCbnSelchangeBranch)\r
54         ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream)\r
55         ON_MESSAGE(MSG_REBASE_UPDATE_UI, OnRebaseUpdateUI)\r
56 END_MESSAGE_MAP()\r
57 \r
58 void CRebaseDlg::AddRebaseAnchor()\r
59 {\r
60         AddAnchor(IDC_REBASE_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
61         AddAnchor(IDC_COMMIT_LIST,TOP_LEFT, TOP_RIGHT);\r
62         AddAnchor(IDC_REBASE_SPLIT,TOP_LEFT, TOP_RIGHT);\r
63         AddAnchor(IDC_STATUS_STATIC, BOTTOM_LEFT,BOTTOM_RIGHT);\r
64         AddAnchor(IDC_REBASE_CONTINUE,BOTTOM_RIGHT);\r
65         AddAnchor(IDC_REBASE_ABORT, BOTTOM_RIGHT);\r
66         AddAnchor(IDC_REBASE_PROGRESS,BOTTOM_LEFT, BOTTOM_RIGHT);\r
67         AddAnchor(IDC_PICK_ALL,TOP_LEFT);\r
68         AddAnchor(IDC_SQUASH_ALL,TOP_LEFT);\r
69         AddAnchor(IDC_EDIT_ALL,TOP_LEFT);       \r
70         AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM,TOP_LEFT);\r
71         AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT);\r
72         AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT);\r
73         AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT);\r
74         \r
75 }\r
76 \r
77 BOOL CRebaseDlg::OnInitDialog()\r
78 {\r
79         CResizableStandAloneDialog::OnInitDialog();\r
80 \r
81         CRect rectDummy;\r
82         //IDC_REBASE_DUMY_TAB\r
83         \r
84         GetClientRect(m_DlgOrigRect);\r
85         m_CommitList.GetClientRect(m_CommitListOrigRect);\r
86 \r
87         CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);\r
88         pwnd->GetWindowRect(&rectDummy);\r
89 \r
90         rectDummy.top-=20;\r
91         rectDummy.bottom-=20;\r
92 \r
93         rectDummy.left-=5;\r
94         rectDummy.right-=5;\r
95         \r
96         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))\r
97         {\r
98                 TRACE0("Failed to create output tab window\n");\r
99                 return FALSE;      // fail to create\r
100         }\r
101         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
102         // Create output panes:\r
103         //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
104         DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
105 \r
106         if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) )\r
107         {\r
108                 TRACE0("Failed to create output windows\n");\r
109                 return FALSE;      // fail to create\r
110         }\r
111 \r
112         if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )\r
113         {\r
114                 TRACE0("Failed to create log message control");\r
115                 return FALSE;\r
116         }\r
117         m_LogMessageCtrl.Init(0);\r
118 \r
119         dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;\r
120 \r
121         if (!m_wndOutputRebase.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )\r
122         {\r
123                 TRACE0("Failed to create output windows\n");\r
124                 return -1;      // fail to create\r
125         }\r
126         m_wndOutputRebase.Init(0);\r
127         m_wndOutputRebase.Call(SCI_SETREADONLY, TRUE);\r
128         \r
129         m_tooltips.Create(this);\r
130 \r
131         m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |IDS_STATUSLIST_COLADD|IDS_STATUSLIST_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false);\r
132 \r
133         m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Conflict File"));\r
134         m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Commit Message"),1);\r
135         m_ctrlTabCtrl.AddTab(&m_wndOutputRebase,_T("Log"),2);\r
136         AddRebaseAnchor();\r
137 \r
138 \r
139         EnableSaveRestore(_T("RebaseDlg"));\r
140 \r
141         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
142         RECT rcDlg, rcLogMsg, rcFileList;\r
143         GetClientRect(&rcDlg);\r
144         m_CommitList.GetWindowRect(&rcLogMsg);\r
145         ScreenToClient(&rcLogMsg);\r
146         this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);\r
147         ScreenToClient(&rcFileList);\r
148         if (yPos)\r
149         {\r
150                 RECT rectSplitter;\r
151                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
152                 ScreenToClient(&rectSplitter);\r
153                 int delta = yPos - rectSplitter.top;\r
154                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
155                 {\r
156                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
157                         DoSize(delta);\r
158                 }\r
159         }\r
160 \r
161         if( this->m_RebaseStage == CHOOSE_BRANCH)\r
162         {\r
163                 this->LoadBranchInfo();\r
164 \r
165         }else\r
166         {\r
167                 this->m_BranchCtrl.EnableWindow(FALSE);\r
168                 this->m_UpstreamCtrl.EnableWindow(FALSE);\r
169         }\r
170 \r
171         m_CommitList.m_IsIDReplaceAction = TRUE;\r
172 //      m_CommitList.m_IsOldFirst = TRUE;\r
173         m_CommitList.m_IsRebaseReplaceGraph = TRUE;\r
174 \r
175         m_CommitList.DeleteAllItems();\r
176         m_CommitList.InsertGitColumn();\r
177 \r
178         FetchLogList();\r
179         SetContinueButtonText();\r
180         this->SetControlEnable();\r
181 \r
182         m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK)|\r
183                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV)|\r
184                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_RESET)|\r
185                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTREV)|\r
186                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV));\r
187 \r
188         return TRUE;\r
189 }\r
190 // CRebaseDlg message handlers\r
191 \r
192 void CRebaseDlg::OnBnClickedPickAll()\r
193 {\r
194     // TODO: Add your control notification handler code here\r
195         this->UpdateData();\r
196         if(this->m_bPickAll)\r
197                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK);\r
198 \r
199         this->m_bEditAll=FALSE;\r
200         this->m_bSquashAll=FALSE;\r
201         this->UpdateData(FALSE);\r
202         \r
203 }\r
204 \r
205 void CRebaseDlg::OnBnClickedSquashAll()\r
206 {\r
207     // TODO: Add your control notification handler code here\r
208         this->UpdateData();\r
209         if(this->m_bSquashAll)\r
210                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);\r
211 \r
212         this->m_bEditAll=FALSE;\r
213         this->m_bPickAll=FALSE;\r
214         this->UpdateData(FALSE);\r
215 \r
216 }\r
217 \r
218 void CRebaseDlg::OnBnClickedEditAll()\r
219 {\r
220     // TODO: Add your control notification handler code here\r
221         this->UpdateData();\r
222         if( this->m_bEditAll )\r
223                 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT);\r
224 \r
225         this->m_bPickAll=FALSE;\r
226         this->m_bSquashAll=FALSE;\r
227         this->UpdateData(FALSE);\r
228 \r
229 }\r
230 \r
231 void CRebaseDlg::SetAllRebaseAction(int action)\r
232 {\r
233         for(int i=0;i<this->m_CommitList.m_logEntries.size();i++)\r
234         {\r
235                 m_CommitList.m_logEntries[i].m_Action=action;\r
236         }\r
237         m_CommitList.Invalidate();\r
238 }\r
239 \r
240 void CRebaseDlg::OnBnClickedRebaseSplit()\r
241 {\r
242         this->UpdateData();\r
243     // TODO: Add your control notification handler code here\r
244 }\r
245 \r
246 LRESULT CRebaseDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
247 {\r
248         switch (message) {\r
249         case WM_NOTIFY:\r
250                 if (wParam == IDC_REBASE_SPLIT)\r
251                 { \r
252                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
253                         DoSize(pHdr->delta);\r
254                 }\r
255                 break;\r
256         }\r
257 \r
258         return __super::DefWindowProc(message, wParam, lParam);\r
259 }\r
260 \r
261 void CRebaseDlg::DoSize(int delta)\r
262 {\r
263         \r
264         this->RemoveAllAnchors();\r
265 \r
266         CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST), delta, CW_TOPALIGN);\r
267         //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);\r
268         CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB), -delta, CW_BOTTOMALIGN);\r
269         //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);\r
270         CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);\r
271         CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);\r
272         CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);\r
273         \r
274         this->AddRebaseAnchor();\r
275         // adjust the minimum size of the dialog to prevent the resizing from\r
276         // moving the list control too far down.\r
277         CRect rcLogMsg;\r
278         m_CommitList.GetClientRect(rcLogMsg);\r
279         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_CommitListOrigRect.Height()+rcLogMsg.Height()));\r
280 \r
281         SetSplitterRange();\r
282 //      m_CommitList.Invalidate();\r
283 \r
284 //      GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
285 \r
286         this->m_ctrlTabCtrl.Invalidate();\r
287         this->m_CommitList.Invalidate();\r
288         this->m_FileListCtrl.Invalidate();\r
289         this->m_LogMessageCtrl.Invalidate();\r
290 \r
291 }\r
292 \r
293 void CRebaseDlg::SetSplitterRange()\r
294 {\r
295         if ((m_CommitList)&&(m_ctrlTabCtrl))\r
296         {\r
297                 CRect rcTop;\r
298                 m_CommitList.GetWindowRect(rcTop);\r
299                 ScreenToClient(rcTop);\r
300                 CRect rcMiddle;\r
301                 m_ctrlTabCtrl.GetWindowRect(rcMiddle);\r
302                 ScreenToClient(rcMiddle);\r
303                 if (rcMiddle.Height() && rcMiddle.Width())\r
304                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
305         }\r
306 }\r
307 \r
308 void CRebaseDlg::OnSize(UINT nType,int cx, int cy)\r
309 {\r
310          // first, let the resizing take place\r
311     __super::OnSize(nType, cx, cy);\r
312 \r
313     //set range\r
314     SetSplitterRange();\r
315 }\r
316 \r
317 void CRebaseDlg::SaveSplitterPos()\r
318 {\r
319         if (!IsIconic())\r
320         {\r
321                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));\r
322                 RECT rectSplitter;\r
323                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
324                 ScreenToClient(&rectSplitter);\r
325                 regPos = rectSplitter.top;\r
326         }\r
327 }\r
328 \r
329 void CRebaseDlg::LoadBranchInfo()\r
330 {\r
331         m_BranchCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
332         m_UpstreamCtrl.SetMaxHistoryItems(0x7FFFFFFF);\r
333 \r
334         STRING_VECTOR list;\r
335         list.clear();\r
336         int current;\r
337         g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL);\r
338         m_BranchCtrl.AddString(list);\r
339         m_UpstreamCtrl.AddString(list);\r
340 \r
341         m_BranchCtrl.SetCurSel(current);\r
342 \r
343         AddBranchToolTips(&m_BranchCtrl);\r
344         AddBranchToolTips(&m_UpstreamCtrl);\r
345 \r
346 }\r
347 \r
348 void CRebaseDlg::OnCbnSelchangeBranch()\r
349 {\r
350         FetchLogList();\r
351 }\r
352 \r
353 void CRebaseDlg::OnCbnSelchangeUpstream()\r
354 {\r
355         FetchLogList();\r
356 }\r
357 \r
358 void CRebaseDlg::FetchLogList()\r
359 {\r
360         m_CommitList.Clear();\r
361         this->m_CommitList.FillGitLog(NULL,0,&m_UpstreamCtrl.GetString(),&m_BranchCtrl.GetString());\r
362         if( m_CommitList.GetItemCount() == 0 )\r
363                 m_CommitList.ShowText(_T("Nothing Rebase"));\r
364 \r
365         CString hash=g_Git.GetHash(m_UpstreamCtrl.GetString());\r
366         \r
367 #if 0\r
368         if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 )\r
369         {\r
370                 if(hash ==  m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash[0])\r
371                 {\r
372                         m_CommitList.Clear();\r
373                         m_CommitList.ShowText(_T("Nothing Rebase"));\r
374                 }\r
375         }\r
376 #endif\r
377 \r
378         m_tooltips.Pop();\r
379         AddBranchToolTips(&this->m_BranchCtrl);\r
380         AddBranchToolTips(&this->m_UpstreamCtrl);\r
381         \r
382         for(int i=0;i<m_CommitList.m_logEntries.size();i++)\r
383         {\r
384                 m_CommitList.m_logEntries[i].m_Action = CTGitPath::LOGACTIONS_REBASE_PICK;\r
385         }\r
386         \r
387         m_CommitList.Invalidate();\r
388 \r
389         if(m_CommitList.m_IsOldFirst)\r
390                 this->m_CurrentRebaseIndex = -1;\r
391         else\r
392                 this->m_CurrentRebaseIndex = m_CommitList.m_logEntries.size();\r
393         \r
394 }\r
395 \r
396 void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch)\r
397 {\r
398         if(pBranch)\r
399         {\r
400                 CString text=pBranch->GetString();\r
401                 CString tooltip;\r
402                 BYTE_VECTOR data;\r
403                 g_Git.GetLog(data,text,NULL,1,0);\r
404                 GitRev rev;\r
405                 rev.ParserFromLog(data);\r
406                 tooltip.Format(_T("CommitHash:%s\nCommit by: %s  %s\n <b>%s</b> \n %s"),\r
407                         rev.m_CommitHash,\r
408                         rev.m_AuthorName,\r
409                         CAppUtils::FormatDateAndTime(rev.m_AuthorDate,DATE_LONGDATE),\r
410                         rev.m_Subject,\r
411                         rev.m_Body);\r
412 \r
413                 pBranch->DisableTooltip();\r
414                 this->m_tooltips.AddTool(pBranch->GetComboBoxCtrl(),tooltip);\r
415         }\r
416 }\r
417 \r
418 BOOL CRebaseDlg::PreTranslateMessage(MSG*pMsg)\r
419 {\r
420         m_tooltips.RelayEvent(pMsg);\r
421         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
422 }\r
423 int CRebaseDlg::CheckRebaseCondition()\r
424 {\r
425         this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
426 \r
427         if( !g_Git.CheckCleanWorkTree()  )\r
428         {\r
429                 CMessageBox::Show(NULL,_T("Rebase Need Clean Working Tree"),_T("TortoiseGit"),MB_OK);\r
430                 return -1;\r
431         }\r
432         //Todo Check $REBASE_ROOT\r
433         //Todo Check $DOTEST\r
434 \r
435         CString cmd;\r
436         cmd=_T("git.exe var GIT_COMMITTER_IDENT");\r
437         if(g_Git.Run(cmd,NULL,CP_UTF8))\r
438                 return -1;\r
439 \r
440         //Todo call pre_rebase_hook\r
441 }\r
442 int CRebaseDlg::StartRebase()\r
443 {\r
444         CString cmd,out;\r
445         //Todo call comment_for_reflog\r
446         cmd.Format(_T("git.exe checkout %s"),this->m_BranchCtrl.GetString());\r
447         this->AddLogString(cmd);\r
448 \r
449         if(g_Git.Run(cmd,&out,CP_UTF8))\r
450                 return -1;\r
451 \r
452         this->AddLogString(out);\r
453 \r
454         cmd=_T("git.exe rev-parse --verify HEAD");\r
455         if(g_Git.Run(cmd,&out,CP_UTF8))\r
456         {\r
457                 AddLogString(_T("No Head"));\r
458                 return -1;\r
459         }\r
460         //Todo \r
461         //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||\r
462         //              echo "detached HEAD" > "$DOTEST"/head-name\r
463 \r
464         cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
465         if(g_Git.Run(cmd,&out,CP_UTF8))\r
466         {\r
467                 AddLogString(_T("update ORIG_HEAD Fail"));\r
468                 return -1;\r
469         }\r
470         \r
471         cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
472 \r
473         cmd.Format(_T("git.exe checkout %s"),this->m_UpstreamCtrl.GetString());\r
474         this->AddLogString(cmd);\r
475 \r
476         out.Empty();\r
477         if(g_Git.Run(cmd,&out,CP_UTF8))\r
478         {\r
479                 return -1;\r
480         }\r
481         \r
482         cmd.Format(_T("git.exe rev-parse %s"),this->m_UpstreamCtrl.GetString());\r
483         if(g_Git.Run(cmd,&this->m_OrigUpstreamHash,CP_UTF8))\r
484         {\r
485                 this->AddLogString(m_OrigUpstreamHash);\r
486                 return -1;\r
487         }\r
488 \r
489         cmd.Format(_T("git.exe rev-parse %s"),this->m_BranchCtrl.GetString());\r
490         if(g_Git.Run(cmd,&this->m_OrigBranchHash,CP_UTF8))\r
491         {\r
492                 this->AddLogString(m_OrigBranchHash);\r
493                 return -1;\r
494         }\r
495 \r
496         this->AddLogString(_T("Start Rebase\r\n"));\r
497         return 0;\r
498 }\r
499 int  CRebaseDlg::VerifyNoConflict()\r
500 {\r
501         CTGitPathList list;\r
502         if(g_Git.ListConflictFile(list))\r
503         {\r
504                 AddLogString(_T("Get conflict files fail"));\r
505                 return -1;\r
506         }\r
507         if( list.GetCount() != 0 )\r
508         {\r
509                 CMessageBox::Show(NULL,_T("There are conflict file, you should mark it resolve"),_T("TortoiseGit"),MB_OK);\r
510                 return -1;\r
511         }\r
512         return 0;\r
513 \r
514 }\r
515 void CRebaseDlg::OnBnClickedContinue()\r
516 {\r
517         if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE )\r
518         {\r
519                 if(CheckRebaseCondition())\r
520                         return ;\r
521                 m_RebaseStage = REBASE_START;\r
522         }\r
523 \r
524         if( m_RebaseStage == REBASE_FINISH )\r
525         {\r
526                 CString cmd,out;\r
527                 cmd.Format(_T("git branch -f %s"),this->m_BranchCtrl.GetString());\r
528                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
529                 {\r
530                         AddLogString(out);\r
531                         return ;\r
532                 }\r
533                 cmd.Format(_T("git reset --hard %s"),this->m_OrigUpstreamHash);\r
534                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
535                 {\r
536                         AddLogString(out);\r
537                         return ;\r
538                 }\r
539                 OnOK();\r
540         }\r
541 \r
542         if( m_RebaseStage == REBASE_SQUASH_CONFLICT)\r
543         {\r
544                 if(VerifyNoConflict())\r
545                         return;\r
546                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
547                 if(this->CheckNextCommitIsSquash())\r
548                 {//next commit is not squash;\r
549                         m_RebaseStage = REBASE_SQUASH_EDIT;\r
550                         this->OnRebaseUpdateUI(0,0);\r
551                         this->UpdateCurrentStatus();\r
552                         return ;\r
553 \r
554                 }\r
555                 m_RebaseStage=REBASE_CONTINUE;\r
556                 curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
557                 this->UpdateCurrentStatus();\r
558 \r
559         }\r
560 \r
561         if( m_RebaseStage == REBASE_CONFLICT )\r
562         {\r
563                 if(VerifyNoConflict())\r
564                         return;\r
565 \r
566                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
567                 \r
568                 CString out =_T("");\r
569                 CString cmd;\r
570                 cmd.Format(_T("git.exe commit -C %s"), curRev->m_CommitHash);\r
571 \r
572                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
573                 {\r
574                         if(!g_Git.CheckCleanWorkTree())\r
575                         {\r
576                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
577                                 return;\r
578                         }\r
579                 }\r
580 \r
581                 AddLogString(out);\r
582                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
583                 if( curRev->m_Action & CTGitPath::LOGACTIONS_REBASE_EDIT)\r
584                 {\r
585                         m_RebaseStage=REBASE_EDIT;\r
586                         this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
587                         this->UpdateCurrentStatus();\r
588                         return;\r
589                 }\r
590                 else\r
591                 {\r
592                         m_RebaseStage=REBASE_CONTINUE;\r
593                         curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
594                         this->UpdateCurrentStatus();\r
595                 }\r
596                 \r
597         }\r
598 \r
599         if( m_RebaseStage == REBASE_EDIT ||  m_RebaseStage == REBASE_SQUASH_EDIT )\r
600         {\r
601                 CString str;\r
602                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
603         \r
604                 str=this->m_LogMessageCtrl.GetText();\r
605                 if(str.Trim().IsEmpty())\r
606                 {\r
607                         CMessageBox::Show(NULL,_T("Commit Message Is Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
608                                 return;\r
609                 }\r
610 \r
611                 CString tempfile=::GetTempFile();\r
612                 CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
613                 CStringA log=CUnicodeUtils::GetUTF8( str);\r
614                 file.Write(log,log.GetLength());\r
615                 //file.WriteString(m_sLogMessage);\r
616                 file.Close();\r
617         \r
618                 CString out,cmd;\r
619                 \r
620                 if(  m_RebaseStage == REBASE_SQUASH_EDIT )\r
621                         cmd.Format(_T("git.exe commit -F \"%s\""), tempfile);\r
622                 else\r
623                         cmd.Format(_T("git.exe commit --amend -F \"%s\""), tempfile);\r
624 \r
625                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
626                 {\r
627                         if(!g_Git.CheckCleanWorkTree())\r
628                         {\r
629                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
630                                 return;\r
631                         }\r
632                 }\r
633 \r
634                 CFile::Remove(tempfile);\r
635                 AddLogString(out);\r
636                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
637                 m_RebaseStage=REBASE_CONTINUE;\r
638                 curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
639                 this->UpdateCurrentStatus();\r
640         }\r
641 \r
642 \r
643         InterlockedExchange(&m_bThreadRunning, TRUE);\r
644         SetControlEnable();\r
645         \r
646         if (AfxBeginThread(RebaseThreadEntry, this)==NULL)\r
647         {\r
648                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
649                 CMessageBox::Show(NULL, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);\r
650                 SetControlEnable();\r
651         }\r
652 }\r
653 int CRebaseDlg::CheckNextCommitIsSquash()\r
654 {\r
655         int index;\r
656         if(m_CommitList.m_IsOldFirst)\r
657                 index=m_CurrentRebaseIndex+1;\r
658         else\r
659                 index=m_CurrentRebaseIndex-1;\r
660 \r
661         GitRev *curRev;\r
662         do\r
663         {\r
664                 curRev=(GitRev*)m_CommitList.m_arShownList[index];\r
665                 \r
666                 if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH )\r
667                         return 0;\r
668                 if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP)\r
669                 {\r
670                         if(m_CommitList.m_IsOldFirst)\r
671                                 index++;\r
672                         else\r
673                                 index--;\r
674                 }else\r
675                         return -1;\r
676 \r
677                 if(index<0)\r
678                         return -1;\r
679                 if(index>= m_CommitList.GetItemCount())\r
680                         return -1;\r
681 \r
682         }while(curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP);\r
683         \r
684         return -1;\r
685 \r
686 }\r
687 int CRebaseDlg::GoNext()\r
688 {\r
689         if(m_CommitList.m_IsOldFirst)\r
690                 m_CurrentRebaseIndex++;\r
691         else\r
692                 m_CurrentRebaseIndex--; \r
693         return 0;\r
694 \r
695 }\r
696 int CRebaseDlg::StateAction()\r
697 {\r
698         switch(this->m_RebaseStage)\r
699         {\r
700         case CHOOSE_BRANCH:\r
701         case CHOOSE_COMMIT_PICK_MODE:\r
702                 if(StartRebase())\r
703                         return -1;\r
704                 m_RebaseStage = REBASE_START;\r
705                 GoNext();\r
706                 break;\r
707         }\r
708 \r
709         return 0;       \r
710 }\r
711 void CRebaseDlg::SetContinueButtonText()\r
712 {\r
713         CString Text;\r
714         switch(this->m_RebaseStage)\r
715         {\r
716         case CHOOSE_BRANCH:\r
717         case CHOOSE_COMMIT_PICK_MODE:\r
718                 Text = _T("Start");\r
719                 break;\r
720 \r
721         case REBASE_START:\r
722         case REBASE_CONTINUE:\r
723         case REBASE_SQUASH_CONFLICT:\r
724                 Text = _T("Continue");\r
725                 break;\r
726 \r
727         case REBASE_CONFLICT:\r
728                 Text = _T("Commit");\r
729                 break;\r
730         case REBASE_EDIT:\r
731                 Text = _T("Amend");\r
732                 break;\r
733 \r
734         case REBASE_SQUASH_EDIT:\r
735                 Text = _T("Commit");\r
736                 break;\r
737 \r
738         case REBASE_ABORT:\r
739         case REBASE_FINISH:\r
740                 Text = _T("Finish");\r
741                 break;\r
742         }\r
743         this->GetDlgItem(IDC_REBASE_CONTINUE)->SetWindowText(Text);\r
744 }\r
745 \r
746 void CRebaseDlg::SetControlEnable()\r
747 {\r
748         switch(this->m_RebaseStage)\r
749         {\r
750         case CHOOSE_BRANCH:\r
751         case CHOOSE_COMMIT_PICK_MODE:\r
752                 \r
753                 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(TRUE);\r
754                 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(TRUE);\r
755                 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(TRUE);\r
756                 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(TRUE);\r
757                 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(TRUE);\r
758                 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;\r
759                 this->m_CommitList.m_ContextMenuMask |= m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|\r
760                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|\r
761                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|\r
762                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP);\r
763                 break;\r
764 \r
765         case REBASE_START:\r
766         case REBASE_CONTINUE:\r
767         case REBASE_ABORT:\r
768         case REBASE_FINISH:\r
769         case REBASE_CONFLICT:\r
770         case REBASE_EDIT:\r
771         case REBASE_SQUASH_CONFLICT:\r
772                 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(FALSE);\r
773                 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(FALSE);\r
774                 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(FALSE);\r
775                 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(FALSE);\r
776                 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(FALSE);\r
777                 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;\r
778                 this->m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|\r
779                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|\r
780                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|\r
781                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP));\r
782                 break;\r
783         }\r
784 \r
785         if(m_bThreadRunning)\r
786         {\r
787                 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);\r
788                 this->GetDlgItem(IDC_REBASE_ABORT)->EnableWindow(FALSE);\r
789 \r
790         }else\r
791         {\r
792                 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(TRUE);\r
793                 this->GetDlgItem(IDC_REBASE_ABORT)->EnableWindow(TRUE);\r
794         }\r
795 }\r
796 \r
797 void CRebaseDlg::UpdateProgress()\r
798 {\r
799         int index;\r
800         CRect rect;\r
801 \r
802         if(m_CommitList.m_IsOldFirst)\r
803                 index = m_CurrentRebaseIndex+1;\r
804         else\r
805                 index = m_CommitList.GetItemCount()-m_CurrentRebaseIndex;\r
806 \r
807         m_ProgressBar.SetRange(1,m_CommitList.GetItemCount());\r
808         m_ProgressBar.SetPos(index);\r
809 \r
810         if(m_CurrentRebaseIndex>0 && m_CurrentRebaseIndex< m_CommitList.GetItemCount())\r
811         {\r
812                 CString text;\r
813                 text.Format(_T("Rebasing...(%d/%d)"),index,m_CommitList.GetItemCount());\r
814                 m_CtrlStatusText.SetWindowText(text);\r
815 \r
816         }\r
817 \r
818         GitRev *prevRev=NULL, *curRev=NULL;\r
819 \r
820         if( m_CurrentRebaseIndex >= 0 && m_CurrentRebaseIndex< m_CommitList.m_arShownList.GetSize())\r
821         {\r
822                 curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
823         }\r
824         \r
825         for(int i=0;i<m_CommitList.m_arShownList.GetSize();i++)\r
826         {\r
827                 prevRev=(GitRev*)m_CommitList.m_arShownList[i];\r
828                 if(prevRev->m_Action & CTGitPath::LOGACTIONS_REBASE_CURRENT)\r
829                 {       \r
830                         prevRev->m_Action &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
831                         m_CommitList.GetItemRect(i,&rect,LVIR_BOUNDS);\r
832                         m_CommitList.InvalidateRect(rect);\r
833                 }\r
834         }\r
835 \r
836         if(curRev)\r
837         {\r
838                 curRev->m_Action |= CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
839                 m_CommitList.GetItemRect(m_CurrentRebaseIndex,&rect,LVIR_BOUNDS);\r
840                 m_CommitList.InvalidateRect(rect);\r
841         }\r
842         m_CommitList.EnsureVisible(m_CurrentRebaseIndex,FALSE);\r
843 \r
844 }\r
845 \r
846 void CRebaseDlg::UpdateCurrentStatus()\r
847 {\r
848         if( m_CurrentRebaseIndex < 0)\r
849         {\r
850                 if(m_CommitList.m_IsOldFirst)\r
851                         m_RebaseStage = CRebaseDlg::REBASE_START;\r
852                 else\r
853                         m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
854         }\r
855 \r
856         if( m_CurrentRebaseIndex == m_CommitList.m_arShownList.GetSize())\r
857         {\r
858                 if(m_CommitList.m_IsOldFirst)\r
859                         m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
860                 else\r
861                         m_RebaseStage = CRebaseDlg::REBASE_START;\r
862         }\r
863 \r
864         SetContinueButtonText();\r
865         SetControlEnable();\r
866         UpdateProgress();\r
867 }\r
868 \r
869 void CRebaseDlg::AddLogString(CString str)\r
870 {\r
871         this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, FALSE);\r
872         CStringA sTextA = m_wndOutputRebase.StringForControl(str);//CUnicodeUtils::GetUTF8(str);\r
873         this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);\r
874         this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");\r
875         this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, TRUE);\r
876 }\r
877 \r
878 int CRebaseDlg::GetCurrentCommitID()\r
879 {\r
880         if(m_CommitList.m_IsOldFirst)\r
881         {\r
882                 return this->m_CurrentRebaseIndex+1;\r
883 \r
884         }else\r
885         {\r
886                 return m_CommitList.GetItemCount()-m_CurrentRebaseIndex;\r
887         }\r
888 }\r
889 \r
890 int CRebaseDlg::DoRebase()\r
891 {       \r
892         CString cmd,out;\r
893         if(m_CurrentRebaseIndex <0)\r
894                 return 0;\r
895         if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )\r
896                 return 0;\r
897 \r
898         GitRev *pRev = (GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
899         int mode=pRev->m_Action & CTGitPath::LOGACTIONS_REBASE_MODE_MASK;\r
900         CString nocommit;\r
901 \r
902         if( mode== CTGitPath::LOGACTIONS_REBASE_SKIP)\r
903         {\r
904                 pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
905                 return 0;\r
906         }\r
907         \r
908         if( mode != CTGitPath::LOGACTIONS_REBASE_PICK )\r
909         {\r
910                 this->m_SquashMessage+= pRev->m_Subject;\r
911                 this->m_SquashMessage+= _T("\n");\r
912                 this->m_SquashMessage+= pRev->m_Body;\r
913         }\r
914         else\r
915                 this->m_SquashMessage.Empty();\r
916 \r
917         if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
918                 nocommit=_T(" --no-commit ");\r
919 \r
920         CString log;\r
921         log.Format(_T("%s %d:%s"),CTGitPath::GetActionName(mode),this->GetCurrentCommitID(),pRev->m_CommitHash);\r
922         AddLogString(log);\r
923         AddLogString(pRev->m_Subject);\r
924         cmd.Format(_T("git.exe cherry-pick %s %s"),nocommit,pRev->m_CommitHash);\r
925 \r
926         if(g_Git.Run(cmd,&out,CP_UTF8))\r
927         {\r
928                 AddLogString(out);\r
929                 CTGitPathList list;\r
930                 if(g_Git.ListConflictFile(list))\r
931                 {\r
932                         AddLogString(_T("Get conflict files fail"));\r
933                         return -1;\r
934                 }\r
935                 if(list.GetCount() == 0 )\r
936                 {\r
937                         if(mode ==  CTGitPath::LOGACTIONS_REBASE_PICK)\r
938                         {\r
939                                 pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
940                                 return 0;\r
941                         }\r
942                         if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
943                                 return -1; // Edit return -1 to stop rebase. \r
944                         \r
945                         // Squash Case\r
946                         if(CheckNextCommitIsSquash())\r
947                         {   // no squash\r
948                                 // let user edit last commmit message\r
949                                 this->m_RebaseStage = REBASE_SQUASH_EDIT;\r
950                                 return -1;\r
951                         }\r
952                 }\r
953                 if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
954                         m_RebaseStage = REBASE_SQUASH_CONFLICT;\r
955                 else\r
956                         m_RebaseStage = REBASE_CONFLICT;\r
957                 return -1;      \r
958 \r
959         }else\r
960         {\r
961                 AddLogString(out);\r
962                 if(mode ==  CTGitPath::LOGACTIONS_REBASE_PICK)\r
963                 {\r
964                         pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
965                         return 0;\r
966                 }\r
967                 if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
968                         return -1; // Edit return -1 to stop rebase. \r
969 \r
970                 // Squash Case\r
971                 if(CheckNextCommitIsSquash())\r
972                 {   // no squash\r
973                         // let user edit last commmit message\r
974                         this->m_RebaseStage = REBASE_SQUASH_EDIT;\r
975                         return -1;\r
976                 }\r
977         }\r
978         \r
979         return 0;\r
980 }\r
981 \r
982 BOOL CRebaseDlg::IsEnd()\r
983 {\r
984         if(m_CommitList.m_IsOldFirst)\r
985                 return m_CurrentRebaseIndex>= this->m_CommitList.GetItemCount();\r
986         else\r
987                 return m_CurrentRebaseIndex<0;\r
988 }\r
989 \r
990 int CRebaseDlg::RebaseThread()\r
991 {\r
992         int ret=0;\r
993         while(1)\r
994         {\r
995                 if( m_RebaseStage == REBASE_START )\r
996                 {\r
997                         if( this->StartRebase() )\r
998                         {\r
999                                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1000                                 ret = -1;\r
1001                                 break;\r
1002                         }\r
1003                         m_RebaseStage = REBASE_CONTINUE;\r
1004 \r
1005                 }else if( m_RebaseStage == REBASE_CONTINUE )\r
1006                 {\r
1007                         this->GoNext(); \r
1008                         if(IsEnd())\r
1009                         {\r
1010                                 ret = 0;\r
1011                                 m_RebaseStage = REBASE_FINISH;\r
1012                                 break;\r
1013                         }\r
1014 \r
1015                         ret = DoRebase();\r
1016 \r
1017                         if( ret )\r
1018                         {       \r
1019                                 break;\r
1020                         }\r
1021 \r
1022                 }else\r
1023                         break;\r
1024                 this->PostMessage(MSG_REBASE_UPDATE_UI);\r
1025                 //this->UpdateCurrentStatus();\r
1026         }\r
1027 \r
1028         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1029         this->PostMessage(MSG_REBASE_UPDATE_UI);\r
1030         return ret;\r
1031 }\r
1032 \r
1033 void CRebaseDlg::ListConflictFile()\r
1034 {\r
1035         this->m_FileListCtrl.Clear();   \r
1036         CTGitPathList list;\r
1037         CTGitPath path;\r
1038         list.AddPath(path);\r
1039 \r
1040         this->m_FileListCtrl.GetStatus(list,true);\r
1041         this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED,CTGitPath::LOGACTIONS_UNMERGED);\r
1042         if( this->m_FileListCtrl.GetItemCount() == 0 )\r
1043         {\r
1044                 \r
1045         }\r
1046 }\r
1047 \r
1048 LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM)\r
1049 {\r
1050         UpdateCurrentStatus();\r
1051         if(m_CurrentRebaseIndex <0)\r
1052                 return 0;\r
1053         if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )\r
1054                 return 0;\r
1055         GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
1056         \r
1057         switch(m_RebaseStage)\r
1058         {\r
1059         case REBASE_CONFLICT:\r
1060         case REBASE_SQUASH_CONFLICT:\r
1061                 ListConflictFile();                     \r
1062                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_CONFLICT);\r
1063                 this->m_LogMessageCtrl.SetText(curRev->m_Subject+_T("\n")+curRev->m_Body);\r
1064                 break;\r
1065         case REBASE_EDIT:\r
1066                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
1067                 this->m_LogMessageCtrl.SetText(curRev->m_Subject+_T("\n")+curRev->m_Body);\r
1068                 break;\r
1069         case REBASE_SQUASH_EDIT:\r
1070                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
1071                 this->m_LogMessageCtrl.SetText(this->m_SquashMessage);\r
1072                 break;\r
1073         default:\r
1074                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
1075         }       \r
1076         return 0;\r
1077 }\r
1078 void CRebaseDlg::OnCancel()\r
1079 {\r
1080         OnBnClickedAbort();\r
1081 }\r
1082 void CRebaseDlg::OnBnClickedAbort()\r
1083 {\r
1084         CString cmd,out;\r
1085         if(m_OrigUpstreamHash.IsEmpty())\r
1086         {\r
1087                 this->OnCancel();\r
1088         }\r
1089         if(CMessageBox::Show(NULL,_T("Are you sure abort rebase"),_T("TortoiseGit"),MB_YESNO) != IDYES)\r
1090                 return;\r
1091 \r
1092         cmd.Format(_T("git.exe reset --hard  %s"),this->m_OrigUpstreamHash.Left(40));\r
1093         if(g_Git.Run(cmd,&out,CP_UTF8))\r
1094         {\r
1095                 AddLogString(out);\r
1096                 return ;\r
1097         }\r
1098         \r
1099         cmd.Format(_T("git checkout -f %s"),this->m_BranchCtrl.GetString());\r
1100         if(g_Git.Run(cmd,&out,CP_UTF8))\r
1101         {\r
1102                 AddLogString(out);\r
1103                 return ;\r
1104         }\r
1105         \r
1106         __super::OnCancel();\r
1107 }\r