Git Property Page: get latest change in new thread
[TortoiseGit.git] / src / TortoiseProc / RebaseDlg.cpp
blobce5eed45169a852637f2d5357b710d4b06cdab87
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // RebaseDlg.cpp : implementation file
24 #include "stdafx.h"
25 #include "TortoiseProc.h"
26 #include "RebaseDlg.h"
27 #include "AppUtils.h"
28 #include "LoglistUtils.h"
29 #include "MessageBox.h"
30 #include "UnicodeUtils.h"
31 #include "BrowseRefsDlg.h"
32 #include "ProgressDlg.h"
33 #include "SmartHandle.h"
34 #include "../TGitCache/CacheInterface.h"
35 #include "Settings\Settings.h"
37 // CRebaseDlg dialog
39 IMPLEMENT_DYNAMIC(CRebaseDlg, CResizableStandAloneDialog)
41 CRebaseDlg::CRebaseDlg(CWnd* pParent /*=NULL*/)
42 : CResizableStandAloneDialog(CRebaseDlg::IDD, pParent)
43 , m_bPickAll(FALSE)
44 , m_bSquashAll(FALSE)
45 , m_bEditAll(FALSE)
46 , m_bAddCherryPickedFrom(FALSE)
48 m_RebaseStage=CHOOSE_BRANCH;
49 m_CurrentRebaseIndex=-1;
50 m_bThreadRunning =FALSE;
51 this->m_IsCherryPick = FALSE;
52 m_bForce=FALSE;
53 m_IsFastForward=FALSE;
56 CRebaseDlg::~CRebaseDlg()
60 void CRebaseDlg::DoDataExchange(CDataExchange* pDX)
62 CDialog::DoDataExchange(pDX);
63 DDX_Control(pDX, IDC_REBASE_PROGRESS, m_ProgressBar);
64 DDX_Control(pDX, IDC_STATUS_STATIC, m_CtrlStatusText);
65 DDX_Check(pDX, IDC_PICK_ALL, m_bPickAll);
66 DDX_Check(pDX, IDC_SQUASH_ALL, m_bSquashAll);
67 DDX_Check(pDX, IDC_EDIT_ALL, m_bEditAll);
68 DDX_Control(pDX, IDC_REBASE_SPLIT, m_wndSplitter);
69 DDX_Control(pDX,IDC_COMMIT_LIST,m_CommitList);
70 DDX_Control(pDX,IDC_REBASE_COMBOXEX_BRANCH, this->m_BranchCtrl);
71 DDX_Control(pDX,IDC_REBASE_COMBOXEX_UPSTREAM, this->m_UpstreamCtrl);
72 DDX_Check(pDX, IDC_REBASE_CHECK_FORCE,m_bForce);
73 DDX_Check(pDX, IDC_CHECK_CHERRYPICKED_FROM, m_bAddCherryPickedFrom);
74 DDX_Control(pDX,IDC_REBASE_POST_BUTTON,m_PostButton);
78 BEGIN_MESSAGE_MAP(CRebaseDlg, CResizableStandAloneDialog)
79 ON_BN_CLICKED(IDC_PICK_ALL, &CRebaseDlg::OnBnClickedPickAll)
80 ON_BN_CLICKED(IDC_SQUASH_ALL, &CRebaseDlg::OnBnClickedSquashAll)
81 ON_BN_CLICKED(IDC_EDIT_ALL, &CRebaseDlg::OnBnClickedEditAll)
82 ON_BN_CLICKED(IDC_REBASE_SPLIT, &CRebaseDlg::OnBnClickedRebaseSplit)
83 ON_BN_CLICKED(IDC_REBASE_CONTINUE,OnBnClickedContinue)
84 ON_BN_CLICKED(IDC_REBASE_ABORT, OnBnClickedAbort)
85 ON_WM_SIZE()
86 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_BRANCH, &CRebaseDlg::OnCbnSelchangeBranch)
87 ON_CBN_SELCHANGE(IDC_REBASE_COMBOXEX_UPSTREAM, &CRebaseDlg::OnCbnSelchangeUpstream)
88 ON_MESSAGE(MSG_REBASE_UPDATE_UI, OnRebaseUpdateUI)
89 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
90 ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CRebaseDlg::OnBnClickedButtonBrowse)
91 ON_BN_CLICKED(IDC_REBASE_CHECK_FORCE, &CRebaseDlg::OnBnClickedRebaseCheckForce)
92 ON_BN_CLICKED(IDC_CHECK_CHERRYPICKED_FROM, &CRebaseDlg::OnBnClickedCheckCherryPickedFrom)
93 ON_BN_CLICKED(IDC_REBASE_POST_BUTTON, &CRebaseDlg::OnBnClickedRebasePostButton)
94 ON_BN_CLICKED(IDC_BUTTON_UP2, &CRebaseDlg::OnBnClickedButtonUp2)
95 ON_BN_CLICKED(IDC_BUTTON_DOWN2, &CRebaseDlg::OnBnClickedButtonDown2)
96 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
97 ON_NOTIFY(LVN_ITEMCHANGED, IDC_COMMIT_LIST, OnLvnItemchangedLoglist)
98 END_MESSAGE_MAP()
100 void CRebaseDlg::AddRebaseAnchor()
102 AddAnchor(IDC_REBASE_TAB,TOP_LEFT,BOTTOM_RIGHT);
103 AddAnchor(IDC_COMMIT_LIST,TOP_LEFT, TOP_RIGHT);
104 AddAnchor(IDC_REBASE_SPLIT,TOP_LEFT, TOP_RIGHT);
105 AddAnchor(IDC_STATUS_STATIC, BOTTOM_LEFT,BOTTOM_RIGHT);
106 AddAnchor(IDC_REBASE_CONTINUE,BOTTOM_RIGHT);
107 AddAnchor(IDC_REBASE_ABORT, BOTTOM_RIGHT);
108 AddAnchor(IDC_REBASE_PROGRESS,BOTTOM_LEFT, BOTTOM_RIGHT);
109 AddAnchor(IDC_PICK_ALL,TOP_LEFT);
110 AddAnchor(IDC_SQUASH_ALL,TOP_LEFT);
111 AddAnchor(IDC_EDIT_ALL,TOP_LEFT);
112 AddAnchor(IDC_BUTTON_UP2,TOP_LEFT);
113 AddAnchor(IDC_BUTTON_DOWN2,TOP_LEFT);
114 AddAnchor(IDC_REBASE_COMBOXEX_UPSTREAM,TOP_LEFT);
115 AddAnchor(IDC_REBASE_COMBOXEX_BRANCH,TOP_LEFT);
116 AddAnchor(IDC_REBASE_STATIC_UPSTREAM,TOP_LEFT);
117 AddAnchor(IDC_REBASE_STATIC_BRANCH,TOP_LEFT);
118 AddAnchor(IDHELP, BOTTOM_RIGHT);
119 AddAnchor(IDC_REBASE_CHECK_FORCE,TOP_RIGHT);
120 AddAnchor(IDC_CHECK_CHERRYPICKED_FROM, TOP_RIGHT);
121 AddAnchor(IDC_REBASE_POST_BUTTON,BOTTOM_LEFT);
123 this->AddOthersToAnchor();
126 BOOL CRebaseDlg::OnInitDialog()
128 CResizableStandAloneDialog::OnInitDialog();
129 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
131 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
132 // do this, Explorer would be unable to send that message to our window if we
133 // were running elevated. It's OK to make the call all the time, since if we're
134 // not elevated, this is a no-op.
135 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
136 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
137 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
138 if (hUser)
140 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
141 if (pfnChangeWindowMessageFilterEx)
143 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
146 m_pTaskbarList.Release();
147 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
149 CRect rectDummy;
150 //IDC_REBASE_DUMY_TAB
152 GetClientRect(m_DlgOrigRect);
153 m_CommitList.GetClientRect(m_CommitListOrigRect);
155 CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB);
156 pwnd->GetWindowRect(&rectDummy);
157 this->ScreenToClient(rectDummy);
159 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB))
161 TRACE0("Failed to create output tab window\n");
162 return FALSE; // fail to create
164 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
165 // Create output panes:
166 //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
167 DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
169 if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) )
171 TRACE0("Failed to create output windows\n");
172 return FALSE; // fail to create
174 m_FileListCtrl.m_hwndLogicalParent = this;
176 if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) )
178 TRACE0("Failed to create log message control");
179 return FALSE;
181 m_LogMessageCtrl.Init(0);
182 m_LogMessageCtrl.Call(SCI_SETREADONLY, TRUE);
184 dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
186 if (!m_wndOutputRebase.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) )
188 TRACE0("Failed to create output windows\n");
189 return -1; // fail to create
191 m_wndOutputRebase.Init(0);
192 m_wndOutputRebase.Call(SCI_SETREADONLY, TRUE);
194 m_tooltips.Create(this);
196 m_tooltips.AddTool(IDC_REBASE_CHECK_FORCE,IDS_REBASE_FORCE_TT);
197 m_tooltips.AddTool(IDC_REBASE_ABORT,IDS_REBASE_ABORT_TT);
201 m_FileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("RebaseDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT|GITSLC_POPRESTORE)), false, true, GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD| GITSLC_COLDEL);
203 m_ctrlTabCtrl.AddTab(&m_FileListCtrl, CString(MAKEINTRESOURCE(IDS_PROC_REVISIONFILES)));
204 m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl, CString(MAKEINTRESOURCE(IDS_PROC_COMMITMESSAGE)), 1);
205 AddRebaseAnchor();
207 AdjustControlSize(IDC_PICK_ALL);
208 AdjustControlSize(IDC_SQUASH_ALL);
209 AdjustControlSize(IDC_EDIT_ALL);
210 AdjustControlSize(IDC_CHECK_CHERRYPICKED_FROM);
212 CString sWindowTitle;
213 GetWindowText(sWindowTitle);
214 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
216 EnableSaveRestore(_T("RebaseDlg"));
218 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
219 RECT rcDlg, rcLogMsg, rcFileList;
220 GetClientRect(&rcDlg);
221 m_CommitList.GetWindowRect(&rcLogMsg);
222 ScreenToClient(&rcLogMsg);
223 this->m_ctrlTabCtrl.GetWindowRect(&rcFileList);
224 ScreenToClient(&rcFileList);
225 if (yPos)
227 RECT rectSplitter;
228 m_wndSplitter.GetWindowRect(&rectSplitter);
229 ScreenToClient(&rectSplitter);
230 int delta = yPos - rectSplitter.top;
231 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
233 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
234 DoSize(delta);
238 if( this->m_RebaseStage == CHOOSE_BRANCH)
240 this->LoadBranchInfo();
243 else
245 this->m_BranchCtrl.EnableWindow(FALSE);
246 this->m_UpstreamCtrl.EnableWindow(FALSE);
249 m_CommitList.m_ColumnRegKey = _T("Rebase");
250 m_CommitList.m_IsIDReplaceAction = TRUE;
251 // m_CommitList.m_IsOldFirst = TRUE;
252 m_CommitList.m_IsRebaseReplaceGraph = TRUE;
253 m_CommitList.m_bNoHightlightHead = TRUE;
255 m_CommitList.InsertGitColumn();
257 this->SetControlEnable();
259 if(!this->m_PreCmd.IsEmpty())
261 CProgressDlg progress;
262 progress.m_GitCmd=m_PreCmd;
263 progress.m_bAutoCloseOnSuccess=true;
264 progress.DoModal();
267 if(m_IsCherryPick)
269 this->m_BranchCtrl.SetCurSel(-1);
270 this->m_BranchCtrl.EnableWindow(FALSE);
271 GetDlgItem(IDC_REBASE_CHECK_FORCE)->ShowWindow(SW_HIDE);
272 GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
273 this->m_UpstreamCtrl.AddString(_T("HEAD"));
274 this->m_UpstreamCtrl.EnableWindow(FALSE);
275 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CHERRYPICK)));
276 this->m_CommitList.StartFilter();
278 else
280 GetDlgItem(IDC_CHECK_CHERRYPICKED_FROM)->ShowWindow(SW_HIDE);
281 SetContinueButtonText();
282 m_CommitList.DeleteAllItems();
283 FetchLogList();
286 m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK)|
287 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV)|
288 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_RESET)|
289 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTREV)|
290 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION)|
291 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV)|
292 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT));
294 if(m_CommitList.m_IsOldFirst)
295 this->m_CurrentRebaseIndex = -1;
296 else
297 this->m_CurrentRebaseIndex = (int)m_CommitList.m_logEntries.size();
300 if(this->CheckRebaseCondition())
302 /* Disable Start Rebase */
303 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);
306 return TRUE;
308 // CRebaseDlg message handlers
310 void CRebaseDlg::OnBnClickedPickAll()
312 this->UpdateData();
313 if(this->m_bPickAll)
314 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_PICK);
316 this->m_bEditAll=FALSE;
317 this->m_bSquashAll=FALSE;
318 this->UpdateData(FALSE);
321 void CRebaseDlg::OnBnClickedSquashAll()
323 this->UpdateData();
324 if(this->m_bSquashAll)
325 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
327 this->m_bEditAll=FALSE;
328 this->m_bPickAll=FALSE;
329 this->UpdateData(FALSE);
332 void CRebaseDlg::OnBnClickedEditAll()
334 this->UpdateData();
335 if( this->m_bEditAll )
336 this->SetAllRebaseAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
338 this->m_bPickAll=FALSE;
339 this->m_bSquashAll=FALSE;
340 this->UpdateData(FALSE);
343 void CRebaseDlg::SetAllRebaseAction(int action)
345 for(int i=0;i<this->m_CommitList.m_logEntries.size();i++)
347 m_CommitList.m_logEntries.GetGitRevAt(i).GetAction(&m_CommitList)=action;
349 m_CommitList.Invalidate();
352 void CRebaseDlg::OnBnClickedRebaseSplit()
354 this->UpdateData();
357 LRESULT CRebaseDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
359 switch (message) {
360 case WM_NOTIFY:
361 if (wParam == IDC_REBASE_SPLIT)
363 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
364 DoSize(pHdr->delta);
366 break;
369 return __super::DefWindowProc(message, wParam, lParam);
372 void CRebaseDlg::DoSize(int delta)
374 this->RemoveAllAnchors();
376 CSplitterControl::ChangeHeight(GetDlgItem(IDC_COMMIT_LIST), delta, CW_TOPALIGN);
377 //CSplitterControl::ChangeHeight(GetDlgItem(), delta, CW_TOPALIGN);
378 CSplitterControl::ChangeHeight(GetDlgItem(IDC_REBASE_TAB), -delta, CW_BOTTOMALIGN);
379 //CSplitterControl::ChangeHeight(GetDlgItem(), -delta, CW_BOTTOMALIGN);
380 CSplitterControl::ChangePos(GetDlgItem(IDC_SQUASH_ALL),0,delta);
381 CSplitterControl::ChangePos(GetDlgItem(IDC_PICK_ALL),0,delta);
382 CSplitterControl::ChangePos(GetDlgItem(IDC_EDIT_ALL),0,delta);
383 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_UP2),0,delta);
384 CSplitterControl::ChangePos(GetDlgItem(IDC_BUTTON_DOWN2),0,delta);
385 CSplitterControl::ChangePos(GetDlgItem(IDC_REBASE_CHECK_FORCE),0,delta);
387 this->AddRebaseAnchor();
388 // adjust the minimum size of the dialog to prevent the resizing from
389 // moving the list control too far down.
390 CRect rcLogMsg;
391 m_CommitList.GetClientRect(rcLogMsg);
392 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_CommitListOrigRect.Height()+rcLogMsg.Height()));
394 SetSplitterRange();
395 // m_CommitList.Invalidate();
397 // GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
399 this->m_ctrlTabCtrl.Invalidate();
400 this->m_CommitList.Invalidate();
401 this->m_FileListCtrl.Invalidate();
402 this->m_LogMessageCtrl.Invalidate();
406 void CRebaseDlg::SetSplitterRange()
408 if ((m_CommitList)&&(m_ctrlTabCtrl))
410 CRect rcTop;
411 m_CommitList.GetWindowRect(rcTop);
412 ScreenToClient(rcTop);
413 CRect rcMiddle;
414 m_ctrlTabCtrl.GetWindowRect(rcMiddle);
415 ScreenToClient(rcMiddle);
416 if (rcMiddle.Height() && rcMiddle.Width())
417 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
421 void CRebaseDlg::OnSize(UINT nType,int cx, int cy)
423 // first, let the resizing take place
424 __super::OnSize(nType, cx, cy);
426 //set range
427 SetSplitterRange();
430 void CRebaseDlg::SaveSplitterPos()
432 if (!IsIconic())
434 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer"));
435 RECT rectSplitter;
436 m_wndSplitter.GetWindowRect(&rectSplitter);
437 ScreenToClient(&rectSplitter);
438 regPos = rectSplitter.top;
442 void CRebaseDlg::LoadBranchInfo()
444 m_BranchCtrl.SetMaxHistoryItems(0x7FFFFFFF);
445 m_UpstreamCtrl.SetMaxHistoryItems(0x7FFFFFFF);
447 STRING_VECTOR list;
448 list.clear();
449 int current;
450 g_Git.GetBranchList(list,&current,CGit::BRANCH_ALL);
451 m_BranchCtrl.AddString(list);
452 m_BranchCtrl.SetCurSel(current);
453 list.clear();
454 g_Git.GetBranchList(list, NULL, CGit::BRANCH_ALL_F);
455 m_UpstreamCtrl.AddString(list);
457 AddBranchToolTips(&m_BranchCtrl);
458 AddBranchToolTips(&m_UpstreamCtrl);
460 if(!m_Upstream.IsEmpty())
462 m_UpstreamCtrl.AddString(m_Upstream);
463 m_UpstreamCtrl.SetCurSel(m_UpstreamCtrl.GetCount()-1);
465 else
467 //Select pull-remote from current branch
468 CString currentBranch = g_Git.GetSymbolicRef();
469 CString configName;
470 configName.Format(L"branch.%s.remote", currentBranch);
471 CString pullRemote = g_Git.GetConfigValue(configName);
473 //Select pull-branch from current branch
474 configName.Format(L"branch.%s.merge", currentBranch);
475 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
477 CString defaultUpstream;
478 defaultUpstream.Format(L"remotes/%s/%s", pullRemote, pullBranch);
479 int found = m_UpstreamCtrl.FindStringExact(0, defaultUpstream);
480 if(found >= 0)
481 m_UpstreamCtrl.SetCurSel(found);
482 else
483 m_UpstreamCtrl.SetCurSel(-1);
487 void CRebaseDlg::OnCbnSelchangeBranch()
489 FetchLogList();
492 void CRebaseDlg::OnCbnSelchangeUpstream()
494 FetchLogList();
497 void CRebaseDlg::FetchLogList()
499 CGitHash base,hash,upstream;
500 m_IsFastForward=FALSE;
502 if (g_Git.GetHash(hash, m_BranchCtrl.GetString()))
504 m_CommitList.ShowText(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl.GetString() + _T("\".")));
505 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(false);
506 return;
508 if (g_Git.GetHash(upstream, m_UpstreamCtrl.GetString()))
510 m_CommitList.ShowText(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl.GetString() + _T("\".")));
511 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(false);
512 return;
515 if (hash == upstream)
517 m_CommitList.Clear();
518 CString text,fmt;
519 fmt.LoadString(IDS_REBASE_EQUAL_FMT);
520 text.Format(fmt,m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString());
522 m_CommitList.ShowText(text);
523 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(false);
524 return;
527 if (g_Git.IsFastForward(m_BranchCtrl.GetString(), m_UpstreamCtrl.GetString(), &base))
529 //fast forword
530 this->m_IsFastForward=TRUE;
532 m_CommitList.Clear();
533 CString text,fmt;
534 fmt.LoadString(IDS_REBASE_FASTFORWARD_FMT);
535 text.Format(fmt,m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString(),
536 m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString());
538 m_CommitList.ShowText(text);
539 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(true);
540 SetContinueButtonText();
542 return ;
545 if(!this->m_bForce)
547 if (base == upstream)
549 m_CommitList.Clear();
550 CString text,fmt;
551 fmt.LoadString(IDS_REBASE_UPTODATE_FMT);
552 text.Format(fmt,m_BranchCtrl.GetString());
553 m_CommitList.ShowText(text);
554 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(m_CommitList.GetItemCount());
555 SetContinueButtonText();
556 return;
560 m_CommitList.Clear();
561 CString from,to;
562 from = m_UpstreamCtrl.GetString();
563 to = m_BranchCtrl.GetString();
564 this->m_CommitList.FillGitLog(NULL,0,&from,&to);
566 if( m_CommitList.GetItemCount() == 0 )
567 m_CommitList.ShowText(CString(MAKEINTRESOURCE(IDS_PROC_NOTHINGTOREBASE)));
569 #if 0
570 if(m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash.size() >=0 )
572 if(upstream == m_CommitList.m_logEntries[m_CommitList.m_logEntries.size()-1].m_ParentHash[0])
574 m_CommitList.Clear();
575 m_CommitList.ShowText(_T("Nothing Rebase"));
578 #endif
580 m_tooltips.Pop();
581 AddBranchToolTips(&this->m_BranchCtrl);
582 AddBranchToolTips(&this->m_UpstreamCtrl);
584 for(int i=0;i<m_CommitList.m_logEntries.size();i++)
586 m_CommitList.m_logEntries.GetGitRevAt(i).GetAction(&m_CommitList) = CTGitPath::LOGACTIONS_REBASE_PICK;
589 m_CommitList.Invalidate();
591 if(m_CommitList.m_IsOldFirst)
592 this->m_CurrentRebaseIndex = -1;
593 else
594 this->m_CurrentRebaseIndex = (int)m_CommitList.m_logEntries.size();
596 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(m_CommitList.GetItemCount());
597 SetContinueButtonText();
600 void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch)
602 if(pBranch)
604 CString text=pBranch->GetString();
605 CString tooltip;
607 GitRev rev;
608 rev.GetCommit(text);
610 tooltip.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"),
611 CString(MAKEINTRESOURCE(IDS_LOG_REVISION)),
612 rev.m_CommitHash.ToString(),
613 CString(MAKEINTRESOURCE(IDS_LOG_AUTHOR)),
614 rev.GetAuthorName(),
615 rev.GetAuthorEmail(),
616 CString(MAKEINTRESOURCE(IDS_LOG_DATE)),
617 CLoglistUtils::FormatDateAndTime(rev.GetAuthorDate(), DATE_LONGDATE),
618 CString(MAKEINTRESOURCE(IDS_LOG_MESSAGE)),
619 rev.GetSubject(),
620 rev.GetBody());
622 pBranch->DisableTooltip();
623 this->m_tooltips.AddTool(pBranch->GetComboBoxCtrl(),tooltip);
627 BOOL CRebaseDlg::PreTranslateMessage(MSG*pMsg)
629 if (pMsg->message == WM_KEYDOWN)
631 switch (pMsg->wParam)
633 case ' ':
634 if(LogListHasFocus(pMsg->hwnd))
636 m_CommitList.ShiftSelectedAction();
637 return TRUE;
639 break;
640 case 'P':
641 if(LogListHasFocus(pMsg->hwnd))
643 m_CommitList.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
644 return TRUE;
646 break;
647 case 'S':
648 if(LogListHasFocus(pMsg->hwnd))
650 m_CommitList.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
651 return TRUE;
653 break;
654 case 'Q':
655 if(LogListHasFocus(pMsg->hwnd))
657 m_CommitList.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
658 return TRUE;
660 break;
661 case 'E':
662 if(LogListHasFocus(pMsg->hwnd))
664 m_CommitList.SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
665 return TRUE;
667 break;
668 case 'A':
669 if(LogListHasFocus(pMsg->hwnd) && GetAsyncKeyState(VK_CONTROL) & 0x8000)
671 // select all entries
672 for (int i = 0; i < m_CommitList.GetItemCount(); ++i)
674 m_CommitList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
676 return TRUE;
678 break;
679 case VK_F5:
681 Refresh();
682 return TRUE;
684 break;
685 case VK_RETURN:
687 if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
689 if (GetDlgItem(IDC_REBASE_CONTINUE)->IsWindowEnabled())
690 GetDlgItem(IDC_REBASE_CONTINUE)->SetFocus();
691 else if (GetDlgItem(IDC_REBASE_ABORT)->IsWindowEnabled())
692 GetDlgItem(IDC_REBASE_ABORT)->SetFocus();
693 else
694 GetDlgItem(IDHELP)->SetFocus();
695 return TRUE;
698 break;
699 /* Avoid TAB control destroy but dialog exist*/
700 case VK_ESCAPE:
701 case VK_CANCEL:
703 TCHAR buff[128];
704 ::GetClassName(pMsg->hwnd,buff,128);
707 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0 ||
708 _tcsnicmp(buff,_T("Scintilla"),128)==0 ||
709 _tcsnicmp(buff,_T("SysListView32"),128)==0||
710 ::GetParent(pMsg->hwnd) == this->m_ctrlTabCtrl.m_hWnd)
712 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
713 return TRUE;
718 else if (pMsg->message == WM_NEXTDLGCTL)
720 if (GetFocus()->GetSafeHwnd() == m_LogMessageCtrl.GetSafeHwnd())
722 if (GetDlgItem(IDC_REBASE_CONTINUE)->IsWindowEnabled())
723 GetDlgItem(IDC_REBASE_CONTINUE)->SetFocus();
724 else if (GetDlgItem(IDC_REBASE_ABORT)->IsWindowEnabled())
725 GetDlgItem(IDC_REBASE_ABORT)->SetFocus();
726 else
727 GetDlgItem(IDHELP)->SetFocus();
728 return TRUE;
731 m_tooltips.RelayEvent(pMsg);
732 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
735 bool CRebaseDlg::LogListHasFocus(HWND hwnd)
737 TCHAR buff[128];
738 ::GetClassName(hwnd, buff, 128);
740 if(_tcsnicmp(buff, _T("SysListView32"), 128) == 0)
741 return true;
742 return false;
745 int CRebaseDlg::CheckRebaseCondition()
747 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
749 if( !g_Git.CheckCleanWorkTree() )
751 if (CMessageBox::Show(NULL, IDS_ERROR_NOCLEAN_STASH, IDS_APPNAME, 1, IDI_QUESTION, IDS_STASHBUTTON, IDS_ABORTBUTTON) == 1)
753 CString cmd,out;
754 cmd=_T("git.exe stash");
755 this->AddLogString(cmd);
756 if (g_Git.Run(cmd, &out, CP_UTF8))
758 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
759 return -1;
763 else
764 return -1;
766 //Todo Check $REBASE_ROOT
767 //Todo Check $DOTEST
769 if (!CAppUtils::CheckUserData())
770 return -1;
772 //Todo call pre_rebase_hook
773 return 0;
775 int CRebaseDlg::StartRebase()
777 CString cmd,out;
778 m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick;
779 if(!this->m_IsCherryPick)
781 //Todo call comment_for_reflog
782 cmd.Format(_T("git.exe checkout %s"),this->m_BranchCtrl.GetString());
783 this->AddLogString(cmd);
784 while (true)
786 out.Empty();
787 if (g_Git.Run(cmd, &out, CP_UTF8))
789 this->AddLogString(out);
790 if (CMessageBox::Show(m_hWnd, out + _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
791 return -1;
793 else
794 break;
797 this->AddLogString(out);
800 cmd=_T("git.exe rev-parse --verify HEAD");
801 if(g_Git.Run(cmd,&out,CP_UTF8))
803 AddLogString(CString(MAKEINTRESOURCE(IDS_PROC_NOHEAD)));
804 return -1;
806 //Todo
807 //git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
808 // echo "detached HEAD" > "$DOTEST"/head-name
810 cmd.Format(_T("git.exe update-ref ORIG_HEAD HEAD"));
811 if(g_Git.Run(cmd,&out,CP_UTF8))
813 AddLogString(_T("update ORIG_HEAD Fail"));
814 return -1;
817 m_OrigUpstreamHash.Empty();
818 if (g_Git.GetHash(m_OrigUpstreamHash, m_UpstreamCtrl.GetString()))
820 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
821 return -1;
824 if( !this->m_IsCherryPick )
826 cmd.Format(_T("git.exe checkout -f %s"), m_OrigUpstreamHash.ToString());
827 this->AddLogString(cmd);
828 while (true)
830 out.Empty();
831 if (g_Git.Run(cmd, &out, CP_UTF8))
833 this->AddLogString(out);
834 if (CMessageBox::Show(m_hWnd, out + _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
835 return -1;
837 else
838 break;
842 CString log;
843 if( !this->m_IsCherryPick )
845 if (g_Git.GetHash(m_OrigBranchHash, m_BranchCtrl.GetString()))
847 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
848 return -1;
850 log.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTREBASE)));
852 else
853 log.Format(_T("%s\r\n"), CString(MAKEINTRESOURCE(IDS_PROC_REBASE_STARTCHERRYPICK)));
855 this->AddLogString(log);
856 return 0;
858 int CRebaseDlg::VerifyNoConflict()
860 CTGitPathList list;
861 if(g_Git.ListConflictFile(list))
863 AddLogString(_T("Get conflict files fail"));
864 return -1;
866 if( list.GetCount() != 0 )
868 CMessageBox::Show(NULL, IDS_PROGRS_CONFLICTSOCCURED, IDS_APPNAME, MB_OK);
869 return -1;
871 return 0;
874 int CRebaseDlg::FinishRebase()
876 if(this->m_IsCherryPick) //cherry pick mode no "branch", working at upstream branch
877 return 0;
879 CGitHash head;
880 if (g_Git.GetHash(head, _T("HEAD")))
882 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR);
883 return -1;
885 CString out,cmd;
887 cmd.Format(_T("git.exe checkout -f %s"),this->m_BranchCtrl.GetString());
888 AddLogString(cmd);
889 while (true)
891 out.Empty();
892 if (g_Git.Run(cmd, &out, CP_UTF8))
894 AddLogString(out);
895 if (CMessageBox::Show(m_hWnd, out + _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
896 return -1;
898 else
899 break;
901 AddLogString(out);
903 cmd.Format(_T("git.exe reset --hard %s"), head.ToString());
904 AddLogString(cmd);
905 while (true)
907 out.Empty();
908 if (g_Git.Run(cmd, &out, CP_UTF8))
910 AddLogString(out);
911 if (CMessageBox::Show(m_hWnd, out + _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
912 return -1;
914 else
915 break;
917 AddLogString(out);
919 m_ctrlTabCtrl.RemoveTab(0);
920 m_ctrlTabCtrl.RemoveTab(0);
921 m_LogMessageCtrl.ShowWindow(SW_HIDE);
922 m_CtrlStatusText.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_REBASEFINISHED)));
924 return 0;
926 void CRebaseDlg::OnBnClickedContinue()
928 if( m_RebaseStage == REBASE_DONE)
930 OnOK();
931 return;
934 if( this->m_IsFastForward )
936 CString cmd,out;
937 CString oldbranch = g_Git.GetCurrentBranch();
938 if( oldbranch != m_BranchCtrl.GetString() )
940 cmd.Format(_T("git.exe checkout %s"),m_BranchCtrl.GetString());
941 AddLogString(cmd);
942 while (true)
944 out.Empty();
945 if (g_Git.Run(cmd, &out, CP_UTF8))
947 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
948 AddLogString(out);
949 if (CMessageBox::Show(m_hWnd, out + _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
950 return;
952 else
953 break;
956 AddLogString(out);
957 out.Empty();
958 if (g_Git.GetHash(m_OrigBranchHash, m_BranchCtrl.GetString()))
960 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_BranchCtrl.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
961 return;
963 if (g_Git.GetHash(m_OrigUpstreamHash, m_UpstreamCtrl.GetString()))
965 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of \"") + m_UpstreamCtrl.GetString() + _T("\".")), _T("TortoiseGit"), MB_ICONERROR);
966 return;
969 if(!g_Git.IsFastForward(this->m_BranchCtrl.GetString(),this->m_UpstreamCtrl.GetString()))
971 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
972 AddLogString(_T("No fast forward possible.\r\nMaybe repository changed"));
973 return;
976 cmd.Format(_T("git.exe reset --hard %s"),g_Git.FixBranchName(this->m_UpstreamCtrl.GetString()));
977 CString log;
978 log.Format(IDS_PROC_REBASE_FFTO, m_UpstreamCtrl.GetString());
979 this->AddLogString(log);
981 AddLogString(cmd);
982 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
983 while (true)
985 out.Empty();
986 if (g_Git.Run(cmd, &out, CP_UTF8))
988 AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL)));
989 AddLogString(out);
990 if (CMessageBox::Show(m_hWnd, out + _T("\nRetry?"), _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
991 return;
993 else
994 break;
996 AddLogString(out);
997 AddLogString(CString(MAKEINTRESOURCE(IDS_DONE)));
998 m_RebaseStage = REBASE_DONE;
999 UpdateCurrentStatus();
1000 return;
1003 if( m_RebaseStage == CHOOSE_BRANCH|| m_RebaseStage == CHOOSE_COMMIT_PICK_MODE )
1005 if(CheckRebaseCondition())
1006 return ;
1007 m_RebaseStage = REBASE_START;
1008 m_FileListCtrl.Clear();
1009 m_FileListCtrl.m_CurrentVersion = L"";
1010 m_ctrlTabCtrl.SetTabLabel(REBASE_TAB_CONFLICT, CString(MAKEINTRESOURCE(IDS_PROC_CONFLICTFILES)));
1011 m_ctrlTabCtrl.AddTab(&m_wndOutputRebase, CString(MAKEINTRESOURCE(IDS_LOG)), 2);
1014 if( m_RebaseStage == REBASE_FINISH )
1016 if(FinishRebase())
1017 return ;
1019 OnOK();
1022 if( m_RebaseStage == REBASE_SQUASH_CONFLICT)
1024 if(VerifyNoConflict())
1025 return;
1026 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];
1027 if(this->CheckNextCommitIsSquash())
1028 {//next commit is not squash;
1029 m_RebaseStage = REBASE_SQUASH_EDIT;
1030 this->OnRebaseUpdateUI(0,0);
1031 this->UpdateCurrentStatus();
1032 return ;
1035 m_RebaseStage=REBASE_CONTINUE;
1036 curRev->GetAction(&m_CommitList)|=CTGitPath::LOGACTIONS_REBASE_DONE;
1037 this->UpdateCurrentStatus();
1041 if( m_RebaseStage == REBASE_CONFLICT )
1043 if(VerifyNoConflict())
1044 return;
1046 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];
1048 CString out =_T("");
1049 CString cmd;
1050 cmd.Format(_T("git.exe commit -a -C %s"), curRev->m_CommitHash.ToString());
1052 AddLogString(cmd);
1054 if(g_Git.Run(cmd,&out,CP_UTF8))
1056 AddLogString(out);
1057 if(!g_Git.CheckCleanWorkTree())
1059 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1060 return;
1064 AddLogString(out);
1065 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
1066 if( curRev->GetAction(&m_CommitList) & CTGitPath::LOGACTIONS_REBASE_EDIT)
1068 m_RebaseStage=REBASE_EDIT;
1069 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);
1070 this->UpdateCurrentStatus();
1071 return;
1073 else
1075 m_RebaseStage=REBASE_CONTINUE;
1076 curRev->GetAction(&m_CommitList)|=CTGitPath::LOGACTIONS_REBASE_DONE;
1077 this->UpdateCurrentStatus();
1081 if( m_RebaseStage == REBASE_EDIT || m_RebaseStage == REBASE_SQUASH_EDIT )
1083 CString str;
1084 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];
1086 str=this->m_LogMessageCtrl.GetText();
1087 if(str.Trim().IsEmpty())
1089 CMessageBox::Show(NULL, IDS_PROC_COMMITMESSAGE_EMPTY,IDS_APPNAME, MB_OK | MB_ICONERROR);
1090 return;
1093 CString tempfile=::GetTempFile();
1094 CAppUtils::SaveCommitUnicodeFile(tempfile, str);
1096 CString out,cmd;
1098 if( m_RebaseStage == REBASE_SQUASH_EDIT )
1099 cmd.Format(_T("git.exe commit -F \"%s\""), tempfile);
1100 else
1101 cmd.Format(_T("git.exe commit --amend -F \"%s\""), tempfile);
1103 if(g_Git.Run(cmd,&out,CP_UTF8))
1105 if(!g_Git.CheckCleanWorkTree())
1107 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1108 return;
1112 CFile::Remove(tempfile);
1113 AddLogString(out);
1114 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
1115 m_RebaseStage=REBASE_CONTINUE;
1116 curRev->GetAction(&m_CommitList)|=CTGitPath::LOGACTIONS_REBASE_DONE;
1117 this->UpdateCurrentStatus();
1121 InterlockedExchange(&m_bThreadRunning, TRUE);
1122 SetControlEnable();
1124 if (AfxBeginThread(RebaseThreadEntry, this)==NULL)
1126 InterlockedExchange(&m_bThreadRunning, FALSE);
1127 CMessageBox::Show(NULL, _T("Create Rebase Thread Fail"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
1128 SetControlEnable();
1131 int CRebaseDlg::CheckNextCommitIsSquash()
1133 int index;
1134 if(m_CommitList.m_IsOldFirst)
1135 index=m_CurrentRebaseIndex+1;
1136 else
1137 index=m_CurrentRebaseIndex-1;
1139 GitRev *curRev;
1142 if(index<0)
1143 return -1;
1144 if(index>= m_CommitList.GetItemCount())
1145 return -1;
1147 curRev=(GitRev*)m_CommitList.m_arShownList[index];
1149 if( curRev->GetAction(&m_CommitList)&CTGitPath::LOGACTIONS_REBASE_SQUASH )
1150 return 0;
1151 if( curRev->GetAction(&m_CommitList)&CTGitPath::LOGACTIONS_REBASE_SKIP)
1153 if(m_CommitList.m_IsOldFirst)
1154 index++;
1155 else
1156 index--;
1158 else
1159 return -1;
1161 }while(curRev->GetAction(&m_CommitList)&CTGitPath::LOGACTIONS_REBASE_SKIP);
1163 return -1;
1166 int CRebaseDlg::GoNext()
1168 if(m_CommitList.m_IsOldFirst)
1169 m_CurrentRebaseIndex++;
1170 else
1171 m_CurrentRebaseIndex--;
1172 return 0;
1175 int CRebaseDlg::StateAction()
1177 switch(this->m_RebaseStage)
1179 case CHOOSE_BRANCH:
1180 case CHOOSE_COMMIT_PICK_MODE:
1181 if(StartRebase())
1182 return -1;
1183 m_RebaseStage = REBASE_START;
1184 GoNext();
1185 break;
1188 return 0;
1190 void CRebaseDlg::SetContinueButtonText()
1192 CString Text;
1193 switch(this->m_RebaseStage)
1195 case CHOOSE_BRANCH:
1196 case CHOOSE_COMMIT_PICK_MODE:
1197 if(this->m_IsFastForward)
1198 Text.LoadString(IDS_PROC_STARTREBASEFFBUTTON);
1199 else
1200 Text.LoadString(IDS_PROC_STARTREBASEBUTTON);
1201 break;
1203 case REBASE_START:
1204 case REBASE_CONTINUE:
1205 case REBASE_SQUASH_CONFLICT:
1206 Text.LoadString(IDS_CONTINUEBUTTON);
1207 break;
1209 case REBASE_CONFLICT:
1210 Text.LoadString(IDS_COMMITBUTTON);
1211 break;
1212 case REBASE_EDIT:
1213 Text.LoadString(IDS_AMENDBUTTON);
1214 break;
1216 case REBASE_SQUASH_EDIT:
1217 Text.LoadString(IDS_COMMITBUTTON);
1218 break;
1220 case REBASE_ABORT:
1221 case REBASE_FINISH:
1222 Text.LoadString(IDS_FINISHBUTTON);
1223 break;
1225 case REBASE_DONE:
1226 Text.LoadString(IDS_DONE);
1227 break;
1229 this->GetDlgItem(IDC_REBASE_CONTINUE)->SetWindowText(Text);
1232 void CRebaseDlg::SetControlEnable()
1234 switch(this->m_RebaseStage)
1236 case CHOOSE_BRANCH:
1237 case CHOOSE_COMMIT_PICK_MODE:
1239 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(TRUE);
1240 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(TRUE);
1241 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(TRUE);
1242 this->GetDlgItem(IDC_BUTTON_UP2)->EnableWindow(TRUE);
1243 this->GetDlgItem(IDC_BUTTON_DOWN2)->EnableWindow(TRUE);
1245 if(!m_IsCherryPick)
1247 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(TRUE);
1248 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(TRUE);
1249 this->GetDlgItem(IDC_REBASE_CHECK_FORCE)->EnableWindow(TRUE);
1251 //this->m_CommitList.m_IsEnableRebaseMenu=TRUE;
1252 this->m_CommitList.m_ContextMenuMask |= m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|
1253 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|
1254 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|
1255 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP);
1256 break;
1258 case REBASE_START:
1259 case REBASE_CONTINUE:
1260 case REBASE_ABORT:
1261 case REBASE_FINISH:
1262 case REBASE_CONFLICT:
1263 case REBASE_EDIT:
1264 case REBASE_SQUASH_CONFLICT:
1265 case REBASE_DONE:
1266 this->GetDlgItem(IDC_PICK_ALL)->EnableWindow(FALSE);
1267 this->GetDlgItem(IDC_EDIT_ALL)->EnableWindow(FALSE);
1268 this->GetDlgItem(IDC_SQUASH_ALL)->EnableWindow(FALSE);
1269 this->GetDlgItem(IDC_REBASE_COMBOXEX_BRANCH)->EnableWindow(FALSE);
1270 this->GetDlgItem(IDC_REBASE_COMBOXEX_UPSTREAM)->EnableWindow(FALSE);
1271 this->GetDlgItem(IDC_REBASE_CHECK_FORCE)->EnableWindow(FALSE);
1272 this->GetDlgItem(IDC_BUTTON_UP2)->EnableWindow(FALSE);
1273 this->GetDlgItem(IDC_BUTTON_DOWN2)->EnableWindow(FALSE);
1274 //this->m_CommitList.m_IsEnableRebaseMenu=FALSE;
1275 this->m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_PICK)|
1276 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SQUASH)|
1277 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_EDIT)|
1278 m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_SKIP));
1280 if( m_RebaseStage == REBASE_DONE && (this->m_PostButtonTexts.GetCount() != 0) )
1282 this->GetDlgItem(IDC_STATUS_STATIC)->ShowWindow(SW_HIDE);
1283 this->GetDlgItem(IDC_REBASE_POST_BUTTON)->ShowWindow(SW_SHOWNORMAL);
1284 this->m_PostButton.RemoveAll();
1285 this->m_PostButton.AddEntries(m_PostButtonTexts);
1286 //this->GetDlgItem(IDC_REBASE_POST_BUTTON)->SetWindowText(this->m_PostButtonText);
1288 break;
1291 if(m_bThreadRunning)
1293 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);
1296 else
1298 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(TRUE);
1302 void CRebaseDlg::UpdateProgress()
1304 int index;
1305 CRect rect;
1307 if(m_CommitList.m_IsOldFirst)
1308 index = m_CurrentRebaseIndex+1;
1309 else
1310 index = m_CommitList.GetItemCount()-m_CurrentRebaseIndex;
1312 m_ProgressBar.SetRange32(1, m_CommitList.GetItemCount());
1313 m_ProgressBar.SetPos(index);
1314 if (m_pTaskbarList)
1316 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1317 m_pTaskbarList->SetProgressValue(m_hWnd, index, m_CommitList.GetItemCount());
1320 if(m_CurrentRebaseIndex>=0 && m_CurrentRebaseIndex< m_CommitList.GetItemCount())
1322 CString text;
1323 text.Format(IDS_PROC_REBASING_PROGRESS, index, m_CommitList.GetItemCount());
1324 m_CtrlStatusText.SetWindowText(text);
1328 GitRev *prevRev=NULL, *curRev=NULL;
1330 if( m_CurrentRebaseIndex >= 0 && m_CurrentRebaseIndex< m_CommitList.m_arShownList.GetSize())
1332 curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];
1335 for(int i=0;i<m_CommitList.m_arShownList.GetSize();i++)
1337 prevRev=(GitRev*)m_CommitList.m_arShownList[i];
1338 if(prevRev->GetAction(&m_CommitList) & CTGitPath::LOGACTIONS_REBASE_CURRENT)
1340 prevRev->GetAction(&m_CommitList) &= ~ CTGitPath::LOGACTIONS_REBASE_CURRENT;
1341 m_CommitList.GetItemRect(i,&rect,LVIR_BOUNDS);
1342 m_CommitList.InvalidateRect(rect);
1346 if(curRev)
1348 curRev->GetAction(&m_CommitList) |= CTGitPath::LOGACTIONS_REBASE_CURRENT;
1349 m_CommitList.GetItemRect(m_CurrentRebaseIndex,&rect,LVIR_BOUNDS);
1350 m_CommitList.InvalidateRect(rect);
1352 m_CommitList.EnsureVisible(m_CurrentRebaseIndex,FALSE);
1355 void CRebaseDlg::UpdateCurrentStatus()
1357 SetContinueButtonText();
1358 SetControlEnable();
1359 UpdateProgress();
1362 void CRebaseDlg::AddLogString(CString str)
1364 this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, FALSE);
1365 CStringA sTextA = m_wndOutputRebase.StringForControl(str);//CUnicodeUtils::GetUTF8(str);
1366 this->m_wndOutputRebase.SendMessage(SCI_DOCUMENTEND);
1367 this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)sTextA);
1368 this->m_wndOutputRebase.SendMessage(SCI_REPLACESEL, 0, (LPARAM)(LPCSTR)"\n");
1369 this->m_wndOutputRebase.SendMessage(SCI_SETREADONLY, TRUE);
1372 int CRebaseDlg::GetCurrentCommitID()
1374 if(m_CommitList.m_IsOldFirst)
1376 return this->m_CurrentRebaseIndex+1;
1379 else
1381 return m_CommitList.GetItemCount()-m_CurrentRebaseIndex;
1385 int CRebaseDlg::DoRebase()
1387 CString cmd,out;
1388 if(m_CurrentRebaseIndex <0)
1389 return 0;
1390 if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )
1391 return 0;
1393 GitRev *pRev = (GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];
1394 int mode=pRev->GetAction(&m_CommitList) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1395 CString nocommit;
1397 if( mode== CTGitPath::LOGACTIONS_REBASE_SKIP)
1399 pRev->GetAction(&m_CommitList)|= CTGitPath::LOGACTIONS_REBASE_DONE;
1400 return 0;
1403 if (!CheckNextCommitIsSquash() || mode != CTGitPath::LOGACTIONS_REBASE_PICK)
1404 { // next commit is squash or not pick
1405 if (!this->m_SquashMessage.IsEmpty())
1406 this->m_SquashMessage += _T("\n\n");
1407 this->m_SquashMessage += pRev->GetSubject();
1408 this->m_SquashMessage += _T("\n");
1409 this->m_SquashMessage += pRev->GetBody().TrimRight();
1411 else
1412 this->m_SquashMessage.Empty();
1414 if (!CheckNextCommitIsSquash() || mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)
1415 { // next or this commit is squash
1416 nocommit=_T(" --no-commit ");
1419 CString log;
1420 log.Format(_T("%s %d: %s"),CTGitPath::GetActionName(mode),this->GetCurrentCommitID(),pRev->m_CommitHash.ToString());
1421 AddLogString(log);
1422 AddLogString(pRev->GetSubject());
1423 if (pRev->GetSubject().IsEmpty())
1425 CMessageBox::Show(m_hWnd, IDS_PROC_REBASE_EMPTYCOMMITMSG, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
1426 mode = CTGitPath::LOGACTIONS_REBASE_EDIT;
1429 CString cherryPickedFrom;
1430 if (m_bAddCherryPickedFrom)
1431 cherryPickedFrom = _T("-x ");
1433 cmd.Format(_T("git.exe cherry-pick %s%s %s"), cherryPickedFrom, nocommit, pRev->m_CommitHash.ToString());
1435 if(g_Git.Run(cmd,&out,CP_UTF8))
1437 AddLogString(out);
1438 CTGitPathList list;
1439 if(g_Git.ListConflictFile(list))
1441 AddLogString(_T("Get conflict files fail"));
1442 return -1;
1444 if(list.GetCount() == 0 )
1446 if(mode == CTGitPath::LOGACTIONS_REBASE_PICK)
1448 pRev->GetAction(&m_CommitList)|= CTGitPath::LOGACTIONS_REBASE_DONE;
1449 return 0;
1451 if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)
1453 this->m_RebaseStage = REBASE_EDIT ;
1454 return -1; // Edit return -1 to stop rebase.
1456 // Squash Case
1457 if(CheckNextCommitIsSquash())
1458 { // no squash
1459 // let user edit last commmit message
1460 this->m_RebaseStage = REBASE_SQUASH_EDIT;
1461 return -1;
1464 if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)
1465 m_RebaseStage = REBASE_SQUASH_CONFLICT;
1466 else
1467 m_RebaseStage = REBASE_CONFLICT;
1468 return -1;
1471 else
1473 AddLogString(out);
1474 if(mode == CTGitPath::LOGACTIONS_REBASE_PICK)
1476 pRev->GetAction(&m_CommitList)|= CTGitPath::LOGACTIONS_REBASE_DONE;
1477 return 0;
1479 if(mode == CTGitPath::LOGACTIONS_REBASE_EDIT)
1481 this->m_RebaseStage = REBASE_EDIT ;
1482 return -1; // Edit return -1 to stop rebase.
1485 // Squash Case
1486 if(CheckNextCommitIsSquash())
1487 { // no squash
1488 // let user edit last commmit message
1489 this->m_RebaseStage = REBASE_SQUASH_EDIT;
1490 return -1;
1492 else if(mode == CTGitPath::LOGACTIONS_REBASE_SQUASH)
1493 pRev->GetAction(&m_CommitList)|= CTGitPath::LOGACTIONS_REBASE_DONE;
1496 return 0;
1499 BOOL CRebaseDlg::IsEnd()
1501 if(m_CommitList.m_IsOldFirst)
1502 return m_CurrentRebaseIndex>= this->m_CommitList.GetItemCount();
1503 else
1504 return m_CurrentRebaseIndex<0;
1507 int CRebaseDlg::RebaseThread()
1509 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
1511 int ret=0;
1512 while(1)
1514 if( m_RebaseStage == REBASE_START )
1516 if( this->StartRebase() )
1518 InterlockedExchange(&m_bThreadRunning, FALSE);
1519 ret = -1;
1520 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
1521 break;
1523 m_RebaseStage = REBASE_CONTINUE;
1526 else if( m_RebaseStage == REBASE_CONTINUE )
1528 this->GoNext();
1529 UpdateCurrentStatus();
1530 if(IsEnd())
1532 ret = 0;
1533 m_RebaseStage = REBASE_FINISH;
1536 else
1538 ret = DoRebase();
1540 if( ret )
1542 break;
1547 else if( m_RebaseStage == REBASE_FINISH )
1549 FinishRebase();
1550 m_RebaseStage = REBASE_DONE;
1551 if (m_pTaskbarList)
1552 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
1553 break;
1556 else
1558 break;
1560 this->PostMessage(MSG_REBASE_UPDATE_UI);
1561 //this->UpdateCurrentStatus();
1564 InterlockedExchange(&m_bThreadRunning, FALSE);
1565 this->PostMessage(MSG_REBASE_UPDATE_UI);
1566 return ret;
1569 void CRebaseDlg::ListConflictFile()
1571 this->m_FileListCtrl.Clear();
1572 CTGitPathList list;
1573 CTGitPath path;
1574 list.AddPath(path);
1576 m_FileListCtrl.m_bIsRevertTheirMy = !m_IsCherryPick;
1578 this->m_FileListCtrl.GetStatus(&list,true);
1579 this->m_FileListCtrl.Show(CTGitPath::LOGACTIONS_UNMERGED|CTGitPath::LOGACTIONS_MODIFIED|CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_DELETED,
1580 CTGitPath::LOGACTIONS_UNMERGED);
1583 LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM)
1585 UpdateCurrentStatus();
1586 if(m_CurrentRebaseIndex <0)
1587 return 0;
1588 if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() )
1589 return 0;
1590 GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex];
1592 switch(m_RebaseStage)
1594 case REBASE_CONFLICT:
1595 case REBASE_SQUASH_CONFLICT:
1596 ListConflictFile();
1597 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_CONFLICT);
1598 if (m_pTaskbarList)
1599 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
1600 this->m_LogMessageCtrl.Call(SCI_SETREADONLY, FALSE);
1601 this->m_LogMessageCtrl.SetText(curRev->GetSubject()+_T("\n")+curRev->GetBody());
1602 break;
1603 case REBASE_EDIT:
1604 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);
1605 if (m_pTaskbarList)
1606 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
1607 this->m_LogMessageCtrl.Call(SCI_SETREADONLY, FALSE);
1608 this->m_LogMessageCtrl.SetText(curRev->GetSubject()+_T("\n")+curRev->GetBody());
1609 break;
1610 case REBASE_SQUASH_EDIT:
1611 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_MESSAGE);
1612 this->m_LogMessageCtrl.Call(SCI_SETREADONLY, FALSE);
1613 this->m_LogMessageCtrl.SetText(this->m_SquashMessage);
1614 if (m_pTaskbarList)
1615 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
1616 break;
1617 default:
1618 this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG);
1620 return 0;
1622 void CRebaseDlg::OnCancel()
1624 OnBnClickedAbort();
1626 void CRebaseDlg::OnBnClickedAbort()
1628 if (m_pTaskbarList)
1629 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
1631 CString cmd,out;
1632 CString pron = m_OrigUpstreamHash.ToString();
1633 if(m_OrigUpstreamHash.IsEmpty())
1635 __super::OnCancel();
1638 if(m_RebaseStage == CHOOSE_BRANCH || m_RebaseStage== CHOOSE_COMMIT_PICK_MODE)
1640 return;
1643 if(CMessageBox::Show(NULL, IDS_PROC_REBASE_ABORT, IDS_APPNAME, MB_YESNO) != IDYES)
1644 return;
1646 if(this->m_IsFastForward)
1648 cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.ToString());
1649 while (true)
1651 out.Empty();
1652 if (g_Git.Run(cmd, &out, CP_UTF8))
1654 AddLogString(out);
1655 if (CMessageBox::Show(m_hWnd, _T("Retry?\nUnrecoverable error on cleanup:\n") + out, _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
1656 break;
1658 else
1659 break;
1661 __super::OnCancel();
1662 return;
1664 cmd.Format(_T("git.exe checkout -f %s"),g_Git.FixBranchName(this->m_UpstreamCtrl.GetString()));
1665 while (true)
1667 out.Empty();
1668 if (g_Git.Run(cmd, &out, CP_UTF8))
1670 AddLogString(out);
1671 if (CMessageBox::Show(this->m_hWnd, _T("Retry?\nUnrecoverable error on cleanup:\n") + out, _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
1673 __super::OnCancel();
1674 return;
1677 else
1678 break;
1681 cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigUpstreamHash.ToString());
1682 while (true)
1684 out.Empty();
1685 if (g_Git.Run(cmd, &out, CP_UTF8))
1687 AddLogString(out);
1688 if (CMessageBox::Show(m_hWnd, _T("Retry?\nUnrecoverable error on cleanup:\n") + out, _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
1690 __super::OnCancel();
1691 return;
1694 else
1695 break;
1698 if(this->m_IsCherryPick) //there are not "branch" at cherry pick mode
1700 __super::OnCancel();
1701 return;
1704 cmd.Format(_T("git checkout -f %s"),this->m_BranchCtrl.GetString());
1705 if(g_Git.Run(cmd,&out,CP_UTF8))
1707 AddLogString(out);
1708 ::MessageBox(this->m_hWnd, _T("Unrecoverable error on cleanup:\n") + out, _T("TortoiseGit"), MB_ICONERROR);
1709 __super::OnCancel();
1710 return;
1713 cmd.Format(_T("git.exe reset --hard %s"),this->m_OrigBranchHash.ToString());
1714 while (true)
1716 out.Empty();
1717 if (g_Git.Run(cmd, &out, CP_UTF8))
1719 AddLogString(out);
1720 if (CMessageBox::Show(m_hWnd, _T("Retry?\nUnrecoverable error on cleanup:\n") + out, _T("TortoiseGit"), MB_YESNO | MB_ICONERROR) != IDYES)
1721 break;
1723 else
1724 break;
1726 __super::OnCancel();
1729 void CRebaseDlg::OnBnClickedButtonBrowse()
1731 if(CBrowseRefsDlg::PickRefForCombo(&m_UpstreamCtrl, gPickRef_NoTag))
1732 OnCbnSelchangeUpstream();
1735 void CRebaseDlg::OnBnClickedRebaseCheckForce()
1737 this->UpdateData();
1738 this->FetchLogList();
1739 if(this->CheckRebaseCondition())
1741 /* Disable Start Rebase */
1742 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);
1746 void CRebaseDlg::OnBnClickedRebasePostButton()
1748 this->m_Upstream=this->m_UpstreamCtrl.GetString();
1749 this->m_Branch=this->m_BranchCtrl.GetString();
1751 this->EndDialog((int)(IDC_REBASE_POST_BUTTON+this->m_PostButton.GetCurrentEntry()));
1754 LRESULT CRebaseDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1756 Refresh();
1757 return 0;
1760 void CRebaseDlg::Refresh()
1762 if (m_RebaseStage == REBASE_CONFLICT || m_RebaseStage == REBASE_SQUASH_CONFLICT)
1764 ListConflictFile();
1765 return;
1768 if(this->m_IsCherryPick)
1769 return ;
1771 if(this->m_RebaseStage == CHOOSE_BRANCH )
1773 this->UpdateData();
1774 this->FetchLogList();
1775 if(this->CheckRebaseCondition())
1777 /* Disable Start Rebase */
1778 this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE);
1783 void CRebaseDlg::OnBnClickedButtonUp2()
1785 POSITION pos;
1786 pos = m_CommitList.GetFirstSelectedItemPosition();
1788 // do nothing if the first selected item is the first item in the list
1789 if (m_CommitList.GetNextSelectedItem(pos) == 0)
1790 return;
1792 pos = m_CommitList.GetFirstSelectedItemPosition();
1794 bool changed = false;
1795 while(pos)
1797 int index=m_CommitList.GetNextSelectedItem(pos);
1798 if(index>=1)
1800 CGitHash old = m_CommitList.m_logEntries[index-1];
1801 m_CommitList.m_logEntries[index-1] = m_CommitList.m_logEntries[index];
1802 m_CommitList.m_logEntries[index] = old;
1803 m_CommitList.SetItemState(index-1, LVIS_SELECTED, LVIS_SELECTED);
1804 m_CommitList.SetItemState(index, 0, LVIS_SELECTED);
1805 changed = true;
1808 if (changed)
1810 m_CommitList.RecalculateShownList(&m_CommitList.m_arShownList);
1811 m_CommitList.Invalidate();
1812 m_CommitList.SetFocus();
1816 void CRebaseDlg::OnBnClickedButtonDown2()
1818 if (m_CommitList.GetSelectedCount() == 0)
1819 return;
1821 POSITION pos;
1822 pos = m_CommitList.GetFirstSelectedItemPosition();
1823 bool changed = false;
1824 // use an array to store all selected item indexes; the user won't select too much items
1825 int* indexes = NULL;
1826 indexes = new int[m_CommitList.GetSelectedCount()];
1827 int i = 0;
1828 while(pos)
1830 indexes[i++] = m_CommitList.GetNextSelectedItem(pos);
1832 // don't move any item if the last selected item is the last item in the m_CommitList
1833 // (that would change the order of the selected items)
1834 if(indexes[m_CommitList.GetSelectedCount() - 1] < m_CommitList.GetItemCount() - 1)
1836 // iterate over the indexes backwards in order to correctly move multiselected items
1837 for (i = m_CommitList.GetSelectedCount() - 1; i >= 0; i--)
1839 int index = indexes[i];
1840 CGitHash old = m_CommitList.m_logEntries[index+1];
1841 m_CommitList.m_logEntries[index+1] = m_CommitList.m_logEntries[index];
1842 m_CommitList.m_logEntries[index] = old;
1843 m_CommitList.SetItemState(index, 0, LVIS_SELECTED);
1844 m_CommitList.SetItemState(index+1, LVIS_SELECTED, LVIS_SELECTED);
1845 changed = true;
1848 delete [] indexes;
1849 indexes = NULL;
1850 if (changed)
1852 m_CommitList.RecalculateShownList(&m_CommitList.m_arShownList);
1853 m_CommitList.Invalidate();
1854 m_CommitList.SetFocus();
1858 LRESULT CRebaseDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
1860 m_pTaskbarList.Release();
1861 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
1862 return 0;
1865 void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1867 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1868 *pResult = 0;
1869 if(m_CommitList.m_bNoDispUpdates)
1870 return;
1871 if (pNMLV->iItem >= 0)
1873 this->m_CommitList.m_nSearchIndex = pNMLV->iItem;
1874 if (pNMLV->iSubItem != 0)
1875 return;
1876 if ((pNMLV->iItem == m_CommitList.m_arShownList.GetCount()))
1878 // remove the selected state
1879 if (pNMLV->uChanged & LVIF_STATE)
1881 m_CommitList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1882 FillLogMessageCtrl();
1884 return;
1886 if (pNMLV->uChanged & LVIF_STATE)
1888 FillLogMessageCtrl();
1891 else
1893 FillLogMessageCtrl();
1897 void CRebaseDlg::FillLogMessageCtrl()
1899 int selCount = m_CommitList.GetSelectedCount();
1900 if (selCount == 1 && (m_RebaseStage == CHOOSE_BRANCH || m_RebaseStage == CHOOSE_COMMIT_PICK_MODE))
1902 POSITION pos = m_CommitList.GetFirstSelectedItemPosition();
1903 int selIndex = m_CommitList.GetNextSelectedItem(pos);
1904 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_CommitList.m_arShownList.SafeGetAt(selIndex));
1905 m_FileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_CommitList));
1906 m_FileListCtrl.m_CurrentVersion = pLogEntry->m_CommitHash;
1907 m_FileListCtrl.Show(GITSLC_SHOWVERSIONED);
1908 m_LogMessageCtrl.Call(SCI_SETREADONLY, FALSE);
1909 m_LogMessageCtrl.SetText(pLogEntry->GetSubject() + _T("\n") + pLogEntry->GetBody());
1910 m_LogMessageCtrl.Call(SCI_SETREADONLY, TRUE);
1913 void CRebaseDlg::OnBnClickedCheckCherryPickedFrom()
1915 UpdateData();