OSDN Git Service

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