OSDN Git Service

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