Update PuTTY to 0.81
[TortoiseGit.git] / src / TortoiseProc / RebaseDlg.h
blob32ce65b752c1409d0be8113bc8d0d8dc767bfcf7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2023 - 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.
20 #pragma once
21 #include "StandAloneDlg.h"
22 #include "GitStatusListCtrl.h"
23 #include "SciEdit.h"
24 #include "SplitterControl.h"
25 #include "HistoryCombo.h"
26 #include "GitLogList.h"
27 #include "MenuButton.h"
28 #include "ProjectProperties.h"
29 #include "AppUtils.h"
31 // CRebaseDlg dialog
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)
44 public:
45 CRebaseDlg(CWnd* pParent = nullptr); // standard constructor
46 virtual ~CRebaseDlg();
48 // Dialog Data
49 enum { IDD = IDD_REBASE };
51 enum class RebaseStage
53 Choose_Branch,
54 Choose_Commit_Pick_Mode,
55 Start,
56 Continue,
57 Abort,
58 Finish,
59 Conclict,
60 Edit,
61 Squash_Edit,
62 Squash_Conclict,
63 Done,
64 Error,
67 protected:
68 void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
69 BOOL OnInitDialog() override;
70 DECLARE_MESSAGE_MAP()
71 LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) override;
72 afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
73 afx_msg LRESULT OnRebaseUpdateUI(WPARAM wParam, LPARAM lParam);
74 void SetTheme(bool bDark) override;
75 void DoSize(int delta);
76 void AddRebaseAnchor();
78 void SetSplitterRange();
79 void SaveSplitterPos();
81 void LoadBranchInfo();
82 void FetchLogList();
83 void SetAllRebaseAction(int action);
84 void OnCancel() override;
86 CRect m_DlgOrigRect;
87 CRect m_CommitListOrigRect;
88 CString m_sStatusText;
89 bool m_bStatusWarning = false;
90 BOOL PreTranslateMessage(MSG* pMsg) override;
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);
101 int DoRebase();
102 afx_msg LRESULT OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM);
103 void Refresh();
104 volatile LONG m_bThreadRunning = FALSE;
105 volatile LONG m_bAbort = FALSE;
106 int RebaseThread();
107 static UINT RebaseThreadEntry(LPVOID pVoid) { return static_cast<CRebaseDlg*>(pVoid)->RebaseThread(); };
108 BOOL IsEnd();
110 int IsCommitEmpty(const CGitHash& hash);
112 bool m_IsFastForward = false;
114 CGitHash m_OrigBranchHash;
115 CGitHash m_OrigUpstreamHash;
116 CString m_OrigHEADBranch;
117 CGitHash m_OrigHEADHash;
119 ProjectProperties m_ProjectProperties;
121 int VerifyNoConflict();
123 CString m_SquashMessage;
124 bool m_CurrentCommitEmpty = false;
125 struct SquashFirstMetaData
127 CString name;
128 CString email;
129 CTime time;
130 bool set = false;
132 SquashFirstMetaData() = default;
134 SquashFirstMetaData(GitRev* rev)
135 : set(true)
136 , name(rev->GetAuthorName())
137 , email(rev->GetAuthorEmail())
138 , time(rev->GetAuthorDate())
142 void UpdateDate(GitRev* rev)
144 ATLASSERT(set);
145 time = rev->GetAuthorDate();
148 void Empty()
150 set = false;
151 name.Empty();
152 email.Empty();
153 time = 0;
156 CString GetAuthor() const
158 if (!set)
159 return CString();
160 CString temp;
161 temp.Format(L"%s <%s>", static_cast<LPCWSTR>(name), static_cast<LPCWSTR>(email));
162 return temp;
165 CString GetAsParam(bool now) const
167 if (!set)
168 return CString();
170 CString date = time.Format(L"%Y-%m-%dT%H:%M:%S");
171 if (now)
172 date = L"\"now\"";
174 CString temp;
175 temp.Format(L"--date=%s --author=\"%s\" ", static_cast<LPCWSTR>(date), static_cast<LPCWSTR>(GetAuthor()));
176 return temp;
178 } m_SquashFirstMetaData;
179 int m_iSquashdate = 0;
181 int CheckNextCommitIsSquash();
182 int GetCurrentCommitID();
183 int FinishRebase();
184 void RewriteNotes();
186 CMenuButton m_PostButton;
188 afx_msg void OnBnClickedRebaseSplit();
189 afx_msg void OnSize(UINT nType, int cx, int cy);
190 afx_msg void OnCbnSelchangeBranch();
191 afx_msg void OnCbnSelchangeUpstream();
192 afx_msg void OnBnClickedContinue();
193 afx_msg void OnBnClickedAbort();
194 afx_msg void OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult);
195 void FillLogMessageCtrl();
197 CProgressCtrl m_ProgressBar;
198 CStatic m_CtrlStatusText;
200 BOOL m_bAddCherryPickedFrom;
201 BOOL m_bAutoSkipFailedCommit = FALSE;
202 bool m_bRebaseAutoEnd = false;
204 public:
205 CStringArray m_PostButtonTexts;
206 CGitLogList m_CommitList;
208 CString m_Upstream;
209 CString m_Branch;
210 CString m_Onto;
212 bool m_IsCherryPick = false;
213 bool m_bRebaseAutoStart = false;
214 BOOL m_bPreserveMerges;
215 BOOL m_bForce;
216 protected:
217 CSplitterControl m_wndSplitter;
218 CMFCTabCtrl m_ctrlTabCtrl;
219 CGitStatusListCtrl m_FileListCtrl;
220 CSciEdit m_LogMessageCtrl;
222 CHistoryCombo m_BranchCtrl;
223 CHistoryCombo m_UpstreamCtrl;
225 CMenuButton m_SplitAllOptions;
227 BOOL m_bSplitCommit;
229 RebaseStage m_RebaseStage = RebaseStage::Choose_Branch;
230 bool m_bFinishedRebase = false;
231 bool m_bStashed = false;
233 std::unordered_map<CGitHash, CGitHash> m_rewrittenCommitsMap;
234 std::vector<CGitHash> m_forRewrite;
235 std::unordered_map<CGitHash, GIT_REV_LIST> m_droppedCommitsMap;
236 std::vector<CGitHash> m_currentCommits;
238 void AddBranchToolTips(CHistoryCombo& pBranch);
239 void AddLogString(const CString& str);
240 int WriteReflog(CGitHash hash, const char* message);
241 int StartRebase();
242 int CheckRebaseCondition();
243 void CheckRestoreStash();
244 int m_CurrentRebaseIndex = -1;
245 int GoNext();
246 void ResetParentForSquash(const CString& commitMessage);
247 void CleanUpRebaseActiveFolder();
248 afx_msg void OnBnClickedButtonReverse();
249 afx_msg void OnBnClickedButtonBrowse();
250 afx_msg void OnBnClickedRebaseCheckForce();
251 afx_msg void OnBnClickedCheckCherryPickedFrom();
252 afx_msg void OnBnClickedRebasePostButton();
253 afx_msg void OnBnClickedSplitAllOptions();
254 afx_msg void OnBnClickedButtonUp();
255 afx_msg void OnBnClickedButtonDown();
256 afx_msg void OnHelp();
258 afx_msg LRESULT OnTaskbarBtnCreated(WPARAM wParam, LPARAM lParam);
259 CComPtr<ITaskbarList3> m_pTaskbarList;
261 afx_msg LRESULT OnRebaseActionMessage(WPARAM wParam, LPARAM lParam);
262 afx_msg LRESULT OnCommitsReordered(WPARAM wParam, LPARAM lParam);
263 afx_msg void OnRefreshFilelist();
264 afx_msg void OnBnClickedRebaseSplitCommit();
265 afx_msg void OnBnClickedButtonOnto();
266 afx_msg void OnBnClickedButtonAdd();