OSDN Git Service

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