OSDN Git Service

Remove combine option from Rebase context menu Fix crash in CGitLogListBase::Refresh()
[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 }\r
457 int CRebaseDlg::StartRebase()\r
458 {\r
459         CString cmd,out;\r
460         //Todo call comment_for_reflog\r
461         cmd.Format(_T("git.exe checkout %s"),this->m_BranchCtrl.GetString());\r
462         this->AddLogString(cmd);\r
463 \r
464         if(g_Git.Run(cmd,&out,CP_UTF8))\r
465                 return -1;\r
466 \r
467         this->AddLogString(out);\r
468 \r
469         cmd=_T("git.exe rev-parse --verify HEAD");\r
470         if(g_Git.Run(cmd,&out,CP_UTF8))\r
471         {\r
472                 AddLogString(_T("No Head"));\r
473                 return -1;\r
474         }\r
475         //Todo \r
476         //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||\r
477         //              echo "detached HEAD" > "$DOTEST"/head-name\r
478 \r
479         cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
480         if(g_Git.Run(cmd,&out,CP_UTF8))\r
481         {\r
482                 AddLogString(_T("update ORIG_HEAD Fail"));\r
483                 return -1;\r
484         }\r
485         \r
486         cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));\r
487 \r
488         cmd.Format(_T("git.exe checkout %s"),this->m_UpstreamCtrl.GetString());\r
489         this->AddLogString(cmd);\r
490 \r
491         out.Empty();\r
492         if(g_Git.Run(cmd,&out,CP_UTF8))\r
493         {\r
494                 return -1;\r
495         }\r
496         \r
497         cmd.Format(_T("git.exe rev-parse %s"),this->m_UpstreamCtrl.GetString());\r
498         if(g_Git.Run(cmd,&this->m_OrigUpstreamHash,CP_UTF8))\r
499         {\r
500                 this->AddLogString(m_OrigUpstreamHash);\r
501                 return -1;\r
502         }\r
503 \r
504         cmd.Format(_T("git.exe rev-parse %s"),this->m_BranchCtrl.GetString());\r
505         if(g_Git.Run(cmd,&this->m_OrigBranchHash,CP_UTF8))\r
506         {\r
507                 this->AddLogString(m_OrigBranchHash);\r
508                 return -1;\r
509         }\r
510 \r
511         this->AddLogString(_T("Start Rebase\r\n"));\r
512         return 0;\r
513 }\r
514 int  CRebaseDlg::VerifyNoConflict()\r
515 {\r
516         CTGitPathList list;\r
517         if(g_Git.ListConflictFile(list))\r
518         {\r
519                 AddLogString(_T("Get conflict files fail"));\r
520                 return -1;\r
521         }\r
522         if( list.GetCount() != 0 )\r
523         {\r
524                 CMessageBox::Show(NULL,_T("There are conflict file, you should mark it resolve"),_T("TortoiseGit"),MB_OK);\r
525                 return -1;\r
526         }\r
527         return 0;\r
528 \r
529 }\r
530 void CRebaseDlg::OnBnClickedContinue()\r
531 {\r
532         if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE )\r
533         {\r
534                 if(CheckRebaseCondition())\r
535                         return ;\r
536                 m_RebaseStage = REBASE_START;\r
537         }\r
538 \r
539         if( m_RebaseStage == REBASE_FINISH )\r
540         {\r
541                 CString cmd,out;\r
542                 cmd.Format(_T("git branch -f %s"),this->m_BranchCtrl.GetString());\r
543                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
544                 {\r
545                         AddLogString(out);\r
546                         return ;\r
547                 }\r
548                 cmd.Format(_T("git reset --hard %s"),this->m_OrigUpstreamHash);\r
549                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
550                 {\r
551                         AddLogString(out);\r
552                         return ;\r
553                 }\r
554                 OnOK();\r
555         }\r
556 \r
557         if( m_RebaseStage == REBASE_SQUASH_CONFLICT)\r
558         {\r
559                 if(VerifyNoConflict())\r
560                         return;\r
561                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
562                 if(this->CheckNextCommitIsSquash())\r
563                 {//next commit is not squash;\r
564                         m_RebaseStage = REBASE_SQUASH_EDIT;\r
565                         this->OnRebaseUpdateUI(0,0);\r
566                         this->UpdateCurrentStatus();\r
567                         return ;\r
568 \r
569                 }\r
570                 m_RebaseStage=REBASE_CONTINUE;\r
571                 curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
572                 this->UpdateCurrentStatus();\r
573 \r
574         }\r
575 \r
576         if( m_RebaseStage == REBASE_CONFLICT )\r
577         {\r
578                 if(VerifyNoConflict())\r
579                         return;\r
580 \r
581                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
582                 \r
583                 CString out =_T("");\r
584                 CString cmd;\r
585                 cmd.Format(_T("git.exe commit -C %s"), curRev->m_CommitHash);\r
586 \r
587                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
588                 {\r
589                         if(!g_Git.CheckCleanWorkTree())\r
590                         {\r
591                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
592                                 return;\r
593                         }\r
594                 }\r
595 \r
596                 AddLogString(out);\r
597                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
598                 if( curRev->m_Action & CTGitPath::LOGACTIONS_REBASE_EDIT)\r
599                 {\r
600                         m_RebaseStage=REBASE_EDIT;\r
601                         this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
602                         this->UpdateCurrentStatus();\r
603                         return;\r
604                 }\r
605                 else\r
606                 {\r
607                         m_RebaseStage=REBASE_CONTINUE;\r
608                         curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
609                         this->UpdateCurrentStatus();\r
610                 }\r
611                 \r
612         }\r
613 \r
614         if( m_RebaseStage == REBASE_EDIT ||  m_RebaseStage == REBASE_SQUASH_EDIT )\r
615         {\r
616                 CString str;\r
617                 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
618         \r
619                 str=this->m_LogMessageCtrl.GetText();\r
620                 if(str.Trim().IsEmpty())\r
621                 {\r
622                         CMessageBox::Show(NULL,_T("Commit Message Is Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
623                                 return;\r
624                 }\r
625 \r
626                 CString tempfile=::GetTempFile();\r
627                 CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
628                 CStringA log=CUnicodeUtils::GetUTF8( str);\r
629                 file.Write(log,log.GetLength());\r
630                 //file.WriteString(m_sLogMessage);\r
631                 file.Close();\r
632         \r
633                 CString out,cmd;\r
634                 \r
635                 if(  m_RebaseStage == REBASE_SQUASH_EDIT )\r
636                         cmd.Format(_T("git.exe commit -F \"%s\""), tempfile);\r
637                 else\r
638                         cmd.Format(_T("git.exe commit --amend -F \"%s\""), tempfile);\r
639 \r
640                 if(g_Git.Run(cmd,&out,CP_UTF8))\r
641                 {\r
642                         if(!g_Git.CheckCleanWorkTree())\r
643                         {\r
644                                 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
645                                 return;\r
646                         }\r
647                 }\r
648 \r
649                 CFile::Remove(tempfile);\r
650                 AddLogString(out);\r
651                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
652                 m_RebaseStage=REBASE_CONTINUE;\r
653                 curRev->m_Action|=CTGitPath::LOGACTIONS_REBASE_DONE;\r
654                 this->UpdateCurrentStatus();\r
655         }\r
656 \r
657 \r
658         InterlockedExchange(&m_bThreadRunning, TRUE);\r
659         SetControlEnable();\r
660         \r
661         if (AfxBeginThread(RebaseThreadEntry, this)==NULL)\r
662         {\r
663                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
664                 CMessageBox::Show(NULL, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);\r
665                 SetControlEnable();\r
666         }\r
667 }\r
668 int CRebaseDlg::CheckNextCommitIsSquash()\r
669 {\r
670         int index;\r
671         if(m_CommitList.m_IsOldFirst)\r
672                 index=m_CurrentRebaseIndex+1;\r
673         else\r
674                 index=m_CurrentRebaseIndex-1;\r
675 \r
676         GitRev *curRev;\r
677         do\r
678         {\r
679                 curRev=(GitRev*)m_CommitList.m_arShownList[index];\r
680                 \r
681                 if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH )\r
682                         return 0;\r
683                 if( curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP)\r
684                 {\r
685                         if(m_CommitList.m_IsOldFirst)\r
686                                 index++;\r
687                         else\r
688                                 index--;\r
689                 }else\r
690                         return -1;\r
691 \r
692                 if(index<0)\r
693                         return -1;\r
694                 if(index>= m_CommitList.GetItemCount())\r
695                         return -1;\r
696 \r
697         }while(curRev->m_Action&CTGitPath::LOGACTIONS_REBASE_SKIP);\r
698         \r
699         return -1;\r
700 \r
701 }\r
702 int CRebaseDlg::GoNext()\r
703 {\r
704         if(m_CommitList.m_IsOldFirst)\r
705                 m_CurrentRebaseIndex++;\r
706         else\r
707                 m_CurrentRebaseIndex--; \r
708         return 0;\r
709 \r
710 }\r
711 int CRebaseDlg::StateAction()\r
712 {\r
713         switch(this->m_RebaseStage)\r
714         {\r
715         case CHOOSE_BRANCH:\r
716         case CHOOSE_COMMIT_PICK_MODE:\r
717                 if(StartRebase())\r
718                         return -1;\r
719                 m_RebaseStage = REBASE_START;\r
720                 GoNext();\r
721                 break;\r
722         }\r
723 \r
724         return 0;       \r
725 }\r
726 void CRebaseDlg::SetContinueButtonText()\r
727 {\r
728         CString Text;\r
729         switch(this->m_RebaseStage)\r
730         {\r
731         case CHOOSE_BRANCH:\r
732         case CHOOSE_COMMIT_PICK_MODE:\r
733                 Text = _T("Start");\r
734                 break;\r
735 \r
736         case REBASE_START:\r
737         case REBASE_CONTINUE:\r
738         case REBASE_SQUASH_CONFLICT:\r
739                 Text = _T("Continue");\r
740                 break;\r
741 \r
742         case REBASE_CONFLICT:\r
743                 Text = _T("Commit");\r
744                 break;\r
745         case REBASE_EDIT:\r
746                 Text = _T("Amend");\r
747                 break;\r
748 \r
749         case REBASE_SQUASH_EDIT:\r
750                 Text = _T("Commit");\r
751                 break;\r
752 \r
753         case REBASE_ABORT:\r
754         case REBASE_FINISH:\r
755                 Text = _T("Finish");\r
756                 break;\r
757         }\r
758         this->GetDlgItem(IDC_REBASE_CONTINUE)->SetWindowText(Text);\r
759 }\r
760 \r
761 void CRebaseDlg::SetControlEnable()\r
762 {\r
763         switch(this->m_RebaseStage)\r
764         {\r
765         case CHOOSE_BRANCH:\r
766         case CHOOSE_COMMIT_PICK_MODE:\r
767                 \r
768                 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(TRUE);\r
769                 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(TRUE);\r
770                 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(TRUE);\r
771                 if(!m_IsCherryPick)\r
772                 {\r
773                         this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(TRUE);\r
774                         this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(TRUE);\r
775                 }\r
776                 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;\r
777                 this->m_CommitList.m_ContextMenuMask |= m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|\r
778                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|\r
779                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|\r
780                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP);\r
781                 break;\r
782 \r
783         case REBASE_START:\r
784         case REBASE_CONTINUE:\r
785         case REBASE_ABORT:\r
786         case REBASE_FINISH:\r
787         case REBASE_CONFLICT:\r
788         case REBASE_EDIT:\r
789         case REBASE_SQUASH_CONFLICT:\r
790                 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(FALSE);\r
791                 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(FALSE);\r
792                 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(FALSE);\r
793                 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(FALSE);\r
794                 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(FALSE);\r
795                 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;\r
796                 this->m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|\r
797                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|\r
798                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|\r
799                                                                                                 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP));\r
800                 break;\r
801         }\r
802 \r
803         if(m_bThreadRunning)\r
804         {\r
805                 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);\r
806                 this->GetDlgItem(IDC_REBASE_ABORT)->EnableWindow(FALSE);\r
807 \r
808         }else\r
809         {\r
810                 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(TRUE);\r
811                 this->GetDlgItem(IDC_REBASE_ABORT)->EnableWindow(TRUE);\r
812         }\r
813 }\r
814 \r
815 void CRebaseDlg::UpdateProgress()\r
816 {\r
817         int index;\r
818         CRect rect;\r
819 \r
820         if(m_CommitList.m_IsOldFirst)\r
821                 index = m_CurrentRebaseIndex+1;\r
822         else\r
823                 index = m_CommitList.GetItemCount()-m_CurrentRebaseIndex;\r
824 \r
825         m_ProgressBar.SetRange(1,m_CommitList.GetItemCount());\r
826         m_ProgressBar.SetPos(index);\r
827 \r
828         if(m_CurrentRebaseIndex>0 && m_CurrentRebaseIndex< m_CommitList.GetItemCount())\r
829         {\r
830                 CString text;\r
831                 text.Format(_T("Rebasing...(%d/%d)"),index,m_CommitList.GetItemCount());\r
832                 m_CtrlStatusText.SetWindowText(text);\r
833 \r
834         }\r
835 \r
836         GitRev *prevRev=NULL, *curRev=NULL;\r
837 \r
838         if( m_CurrentRebaseIndex >= 0 && m_CurrentRebaseIndex< m_CommitList.m_arShownList.GetSize())\r
839         {\r
840                 curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
841         }\r
842         \r
843         for(int i=0;i<m_CommitList.m_arShownList.GetSize();i++)\r
844         {\r
845                 prevRev=(GitRev*)m_CommitList.m_arShownList[i];\r
846                 if(prevRev->m_Action & CTGitPath::LOGACTIONS_REBASE_CURRENT)\r
847                 {       \r
848                         prevRev->m_Action &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
849                         m_CommitList.GetItemRect(i,&rect,LVIR_BOUNDS);\r
850                         m_CommitList.InvalidateRect(rect);\r
851                 }\r
852         }\r
853 \r
854         if(curRev)\r
855         {\r
856                 curRev->m_Action |= CTGitPath::LOGACTIONS_REBASE_CURRENT;\r
857                 m_CommitList.GetItemRect(m_CurrentRebaseIndex,&rect,LVIR_BOUNDS);\r
858                 m_CommitList.InvalidateRect(rect);\r
859         }\r
860         m_CommitList.EnsureVisible(m_CurrentRebaseIndex,FALSE);\r
861 \r
862 }\r
863 \r
864 void CRebaseDlg::UpdateCurrentStatus()\r
865 {\r
866         if( m_CurrentRebaseIndex < 0)\r
867         {\r
868                 if(m_CommitList.m_IsOldFirst)\r
869                         m_RebaseStage = CRebaseDlg::REBASE_START;\r
870                 else\r
871                         m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
872         }\r
873 \r
874         if( m_CurrentRebaseIndex == m_CommitList.m_arShownList.GetSize())\r
875         {\r
876                 if(m_CommitList.m_IsOldFirst)\r
877                         m_RebaseStage = CRebaseDlg::REBASE_FINISH;\r
878                 else\r
879                         m_RebaseStage = CRebaseDlg::REBASE_START;\r
880         }\r
881 \r
882         SetContinueButtonText();\r
883         SetControlEnable();\r
884         UpdateProgress();\r
885 }\r
886 \r
887 void CRebaseDlg::AddLogString(CString str)\r
888 {\r
889         this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, FALSE);\r
890         CStringA sTextA = m_wndOutputRebase.StringForControl(str);//CUnicodeUtils::GetUTF8(str);\r
891         this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);\r
892         this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");\r
893         this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, TRUE);\r
894 }\r
895 \r
896 int CRebaseDlg::GetCurrentCommitID()\r
897 {\r
898         if(m_CommitList.m_IsOldFirst)\r
899         {\r
900                 return this->m_CurrentRebaseIndex+1;\r
901 \r
902         }else\r
903         {\r
904                 return m_CommitList.GetItemCount()-m_CurrentRebaseIndex;\r
905         }\r
906 }\r
907 \r
908 int CRebaseDlg::DoRebase()\r
909 {       \r
910         CString cmd,out;\r
911         if(m_CurrentRebaseIndex <0)\r
912                 return 0;\r
913         if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )\r
914                 return 0;\r
915 \r
916         GitRev *pRev = (GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
917         int mode=pRev->m_Action & CTGitPath::LOGACTIONS_REBASE_MODE_MASK;\r
918         CString nocommit;\r
919 \r
920         if( mode== CTGitPath::LOGACTIONS_REBASE_SKIP)\r
921         {\r
922                 pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
923                 return 0;\r
924         }\r
925         \r
926         if( mode != CTGitPath::LOGACTIONS_REBASE_PICK )\r
927         {\r
928                 this->m_SquashMessage+= pRev->m_Subject;\r
929                 this->m_SquashMessage+= _T("\n");\r
930                 this->m_SquashMessage+= pRev->m_Body;\r
931         }\r
932         else\r
933                 this->m_SquashMessage.Empty();\r
934 \r
935         if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
936                 nocommit=_T(" --no-commit ");\r
937 \r
938         CString log;\r
939         log.Format(_T("%s %d:%s"),CTGitPath::GetActionName(mode),this->GetCurrentCommitID(),pRev->m_CommitHash);\r
940         AddLogString(log);\r
941         AddLogString(pRev->m_Subject);\r
942         cmd.Format(_T("git.exe cherry-pick %s %s"),nocommit,pRev->m_CommitHash);\r
943 \r
944         if(g_Git.Run(cmd,&out,CP_UTF8))\r
945         {\r
946                 AddLogString(out);\r
947                 CTGitPathList list;\r
948                 if(g_Git.ListConflictFile(list))\r
949                 {\r
950                         AddLogString(_T("Get conflict files fail"));\r
951                         return -1;\r
952                 }\r
953                 if(list.GetCount() == 0 )\r
954                 {\r
955                         if(mode ==  CTGitPath::LOGACTIONS_REBASE_PICK)\r
956                         {\r
957                                 pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
958                                 return 0;\r
959                         }\r
960                         if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
961                                 return -1; // Edit return -1 to stop rebase. \r
962                         \r
963                         // Squash Case\r
964                         if(CheckNextCommitIsSquash())\r
965                         {   // no squash\r
966                                 // let user edit last commmit message\r
967                                 this->m_RebaseStage = REBASE_SQUASH_EDIT;\r
968                                 return -1;\r
969                         }\r
970                 }\r
971                 if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
972                         m_RebaseStage = REBASE_SQUASH_CONFLICT;\r
973                 else\r
974                         m_RebaseStage = REBASE_CONFLICT;\r
975                 return -1;      \r
976 \r
977         }else\r
978         {\r
979                 AddLogString(out);\r
980                 if(mode ==  CTGitPath::LOGACTIONS_REBASE_PICK)\r
981                 {\r
982                         pRev->m_Action|= CTGitPath::LOGACTIONS_REBASE_DONE;\r
983                         return 0;\r
984                 }\r
985                 if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)\r
986                         return -1; // Edit return -1 to stop rebase. \r
987 \r
988                 // Squash Case\r
989                 if(CheckNextCommitIsSquash())\r
990                 {   // no squash\r
991                         // let user edit last commmit message\r
992                         this->m_RebaseStage = REBASE_SQUASH_EDIT;\r
993                         return -1;\r
994                 }\r
995         }\r
996         \r
997         return 0;\r
998 }\r
999 \r
1000 BOOL CRebaseDlg::IsEnd()\r
1001 {\r
1002         if(m_CommitList.m_IsOldFirst)\r
1003                 return m_CurrentRebaseIndex>= this->m_CommitList.GetItemCount();\r
1004         else\r
1005                 return m_CurrentRebaseIndex<0;\r
1006 }\r
1007 \r
1008 int CRebaseDlg::RebaseThread()\r
1009 {\r
1010         int ret=0;\r
1011         while(1)\r
1012         {\r
1013                 if( m_RebaseStage == REBASE_START )\r
1014                 {\r
1015                         if( this->StartRebase() )\r
1016                         {\r
1017                                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1018                                 ret = -1;\r
1019                                 break;\r
1020                         }\r
1021                         m_RebaseStage = REBASE_CONTINUE;\r
1022 \r
1023                 }else if( m_RebaseStage == REBASE_CONTINUE )\r
1024                 {\r
1025                         this->GoNext(); \r
1026                         if(IsEnd())\r
1027                         {\r
1028                                 ret = 0;\r
1029                                 m_RebaseStage = REBASE_FINISH;\r
1030                                 break;\r
1031                         }\r
1032 \r
1033                         ret = DoRebase();\r
1034 \r
1035                         if( ret )\r
1036                         {       \r
1037                                 break;\r
1038                         }\r
1039 \r
1040                 }else\r
1041                         break;\r
1042                 this->PostMessage(MSG_REBASE_UPDATE_UI);\r
1043                 //this->UpdateCurrentStatus();\r
1044         }\r
1045 \r
1046         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1047         this->PostMessage(MSG_REBASE_UPDATE_UI);\r
1048         return ret;\r
1049 }\r
1050 \r
1051 void CRebaseDlg::ListConflictFile()\r
1052 {\r
1053         this->m_FileListCtrl.Clear();   \r
1054         CTGitPathList list;\r
1055         CTGitPath path;\r
1056         list.AddPath(path);\r
1057 \r
1058         this->m_FileListCtrl.GetStatus(&list,true);\r
1059         this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED,CTGitPath::LOGACTIONS_UNMERGED);\r
1060         if( this->m_FileListCtrl.GetItemCount() == 0 )\r
1061         {\r
1062                 \r
1063         }\r
1064 }\r
1065 \r
1066 LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM)\r
1067 {\r
1068         UpdateCurrentStatus();\r
1069         if(m_CurrentRebaseIndex <0)\r
1070                 return 0;\r
1071         if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )\r
1072                 return 0;\r
1073         GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];\r
1074         \r
1075         switch(m_RebaseStage)\r
1076         {\r
1077         case REBASE_CONFLICT:\r
1078         case REBASE_SQUASH_CONFLICT:\r
1079                 ListConflictFile();                     \r
1080                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_CONFLICT);\r
1081                 this->m_LogMessageCtrl.SetText(curRev->m_Subject+_T("\n")+curRev->m_Body);\r
1082                 break;\r
1083         case REBASE_EDIT:\r
1084                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
1085                 this->m_LogMessageCtrl.SetText(curRev->m_Subject+_T("\n")+curRev->m_Body);\r
1086                 break;\r
1087         case REBASE_SQUASH_EDIT:\r
1088                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);\r
1089                 this->m_LogMessageCtrl.SetText(this->m_SquashMessage);\r
1090                 break;\r
1091         default:\r
1092                 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);\r
1093         }       \r
1094         return 0;\r
1095 }\r
1096 void CRebaseDlg::OnCancel()\r
1097 {\r
1098         OnBnClickedAbort();\r
1099 }\r
1100 void CRebaseDlg::OnBnClickedAbort()\r
1101 {\r
1102         CString cmd,out;\r
1103         if(m_OrigUpstreamHash.IsEmpty())\r
1104         {\r
1105                 __super::OnCancel();\r
1106         }\r
1107         \r
1108         if(m_RebaseStage == CHOOSE_BRANCH || m_RebaseStage== CHOOSE_COMMIT_PICK_MODE)\r
1109         {\r
1110                 return;\r
1111         }\r
1112 \r
1113         if(CMessageBox::Show(NULL,_T("Are you sure abort rebase"),_T("TortoiseGit"),MB_YESNO) != IDYES)\r
1114                 return;\r
1115 \r
1116         cmd.Format(_T("git.exe reset --hard  %s"),this->m_OrigUpstreamHash.Left(40));\r
1117         if(g_Git.Run(cmd,&out,CP_UTF8))\r
1118         {\r
1119                 AddLogString(out);\r
1120                 return ;\r
1121         }\r
1122         \r
1123         cmd.Format(_T("git checkout -f %s"),this->m_BranchCtrl.GetString());\r
1124         if(g_Git.Run(cmd,&out,CP_UTF8))\r
1125         {\r
1126                 AddLogString(out);\r
1127                 return ;\r
1128         }\r
1129         \r
1130         __super::OnCancel();\r
1131 }\r