1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "StandAloneDlg.h"
22 #include "GitStatusListCtrl.h"
24 #include "SplitterControl.h"
25 #include "HistoryCombo.h"
26 #include "GitLogList.h"
27 #include "MenuButton.h"
28 #include "ProjectProperties.h"
32 #define IDC_REBASE_TAB 0x1000000
34 #define REBASE_TAB_CONFLICT 0
35 #define REBASE_TAB_MESSAGE 1
36 #define REBASE_TAB_LOG 2
38 #define MSG_REBASE_UPDATE_UI (WM_USER+151)
40 class CRebaseDlg
: public CResizableStandAloneDialog
42 DECLARE_DYNAMIC(CRebaseDlg
)
45 CRebaseDlg(CWnd
* pParent
= nullptr); // standard constructor
46 virtual ~CRebaseDlg();
49 enum { IDD
= IDD_REBASE
};
54 CHOOSE_COMMIT_PICK_MODE
,
62 REBASE_SQUASH_CONFLICT
,
68 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
69 virtual BOOL
OnInitDialog();
71 virtual LRESULT
DefWindowProc(UINT message
, WPARAM wParam
, LPARAM lParam
);
72 virtual HBRUSH
OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
);
73 LRESULT
OnRebaseUpdateUI(WPARAM wParam
, LPARAM lParam
);
74 void DoSize(int delta
);
75 void AddRebaseAnchor();
78 void SetSplitterRange();
79 void SaveSplitterPos();
81 void LoadBranchInfo();
83 void SetAllRebaseAction(int action
);
87 CRect m_CommitListOrigRect
;
88 CString m_sStatusText
;
89 bool m_bStatusWarning
;
90 BOOL
PreTranslateMessage(MSG
* pMsg
);
91 bool LogListHasFocus(HWND hwnd
);
92 bool LogListHasMenuItem(int i
);
94 CSciEdit m_wndOutputRebase
;
95 void SetContinueButtonText();
96 void SetControlEnable();
97 void UpdateProgress();
98 void UpdateCurrentStatus();
99 void ListConflictFile(bool noStoreScrollPosition
);
100 int RunGitCmdRetryOrAbort(const CString
& cmd
);
102 afx_msg LRESULT
OnGitStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
);
104 volatile LONG m_bThreadRunning
;
106 static UINT
RebaseThreadEntry(LPVOID pVoid
) { return reinterpret_cast<CRebaseDlg
*>(pVoid
)->RebaseThread(); };
109 int IsCommitEmpty(const CGitHash
& hash
);
111 BOOL m_IsFastForward
;
113 CGitHash m_OrigBranchHash
;
114 CGitHash m_OrigUpstreamHash
;
115 CString m_OrigHEADBranch
;
116 CGitHash m_OrigHEADHash
;
118 ProjectProperties m_ProjectProperties
;
120 int VerifyNoConflict();
121 CString
GetRebaseModeName(int rebasemode
);
123 CString m_SquashMessage
;
124 struct SquashFirstMetaData
131 SquashFirstMetaData()
136 SquashFirstMetaData(GitRev
* rev
)
139 name
= rev
->GetAuthorName();
140 email
= rev
->GetAuthorEmail();
141 time
= rev
->GetAuthorDate();
144 void UpdateDate(GitRev
* rev
)
147 time
= rev
->GetAuthorDate();
158 CString
GetAuthor() const
163 temp
.Format(L
"%s <%s>", (LPCTSTR
)name
, (LPCTSTR
)email
);
167 CString
GetAsParam(bool now
) const
172 CString date
= time
.Format(L
"%Y-%m-%dT%H:%M:%S");
174 date
= CAppUtils::GetMsysgitVersion() > 0x02010000 ? L
"\"now\"" : L
"\"\"";
177 temp
.Format(L
"--date=%s --author=\"%s\" ", (LPCTSTR
)date
, (LPCTSTR
)GetAuthor());
180 } m_SquashFirstMetaData
;
183 int CheckNextCommitIsSquash();
184 int GetCurrentCommitID();
188 CMenuButton m_PostButton
;
190 afx_msg
void OnBnClickedPickAll();
191 afx_msg
void OnBnClickedSquashAll();
192 afx_msg
void OnBnClickedEditAll();
193 afx_msg
void OnBnClickedRebaseSplit();
194 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
195 afx_msg
void OnCbnSelchangeBranch();
196 afx_msg
void OnCbnSelchangeUpstream();
197 afx_msg
void OnBnClickedContinue();
198 afx_msg
void OnBnClickedAbort();
199 afx_msg
void OnLvnItemchangedLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
200 afx_msg
void OnSysColorChange();
201 afx_msg LRESULT
OnThemeChanged();
202 void FillLogMessageCtrl();
204 CProgressCtrl m_ProgressBar
;
205 CStatic m_CtrlStatusText
;
208 BOOL m_bAddCherryPickedFrom
;
209 BOOL m_bAutoSkipFailedCommit
;
210 bool m_bRebaseAutoEnd
;
213 CStringArray m_PostButtonTexts
;
214 CGitLogList m_CommitList
;
221 bool m_bRebaseAutoStart
;
222 BOOL m_bPreserveMerges
;
224 CSplitterControl m_wndSplitter
;
225 CMFCTabCtrl m_ctrlTabCtrl
;
226 CGitStatusListCtrl m_FileListCtrl
;
227 CSciEdit m_LogMessageCtrl
;
229 CHistoryCombo m_BranchCtrl
;
230 CHistoryCombo m_UpstreamCtrl
;
232 CMenuButton m_SplitAllOptions
;
236 REBASE_STAGE m_RebaseStage
;
237 bool m_bFinishedRebase
;
240 std::unordered_map
<CGitHash
, CGitHash
> m_rewrittenCommitsMap
;
241 std::vector
<CGitHash
> m_forRewrite
;
242 std::unordered_map
<CGitHash
, GIT_REV_LIST
> m_droppedCommitsMap
;
243 std::vector
<CGitHash
> m_currentCommits
;
245 void AddBranchToolTips(CHistoryCombo
*pBranch
);
246 void AddLogString(CString str
);
248 int CheckRebaseCondition();
249 void CheckRestoreStash();
250 int m_CurrentRebaseIndex
;
252 void ResetParentForSquash(const CString
& commitMessage
);
253 void CleanUpRebaseActiveFolder();
254 afx_msg
void OnBnClickedButtonReverse();
255 afx_msg
void OnBnClickedButtonBrowse();
256 afx_msg
void OnBnClickedRebaseCheckForce();
257 afx_msg
void OnBnClickedCheckCherryPickedFrom();
258 afx_msg
void OnBnClickedRebasePostButton();
259 afx_msg
void OnBnClickedSplitAllOptions();
260 afx_msg
void OnBnClickedButtonUp();
261 afx_msg
void OnBnClickedButtonDown();
262 afx_msg
void OnHelp();
264 afx_msg LRESULT
OnTaskbarBtnCreated(WPARAM wParam
, LPARAM lParam
);
265 CComPtr
<ITaskbarList3
> m_pTaskbarList
;
267 afx_msg LRESULT
OnRebaseActionMessage(WPARAM wParam
, LPARAM lParam
);
268 afx_msg LRESULT
OnCommitsReordered(WPARAM wParam
, LPARAM lParam
);
269 afx_msg
void OnBnClickedRebaseSplitCommit();
270 afx_msg
void OnBnClickedButtonOnto();
271 afx_msg
void OnBnClickedButtonAdd();