added new log filter (for subject)
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.h
blob1990033c1e9f527995106d180a8782cb30f41fd0
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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.
19 // GitLogList.cpp : implementation file
21 #pragma once
23 #include "HintListCtrl.h"
24 #include "CommonResource.h"
25 #include "Git.h"
26 #include "ProjectProperties.h"
27 #include "TGitPath.h"
28 #include "registry.h"
29 #include "SplitterControl.h"
30 #include "Colors.h"
31 #include "MenuButton.h"
32 #include "LogDlgHelper.h"
33 #include "FilterEdit.h"
34 #include "GitRev.h"
35 #include "Tooltip.h"
36 //#include "GitLogList.h"
37 #include "lanes.h"
38 #include "GitLogCache.h"
39 #include <regex>
40 #include <GitStatusListCtrl.h>
41 #include "FindDlg.h"
43 // CGitLogList
44 #if (NTDDI_VERSION < NTDDI_LONGHORN)
46 enum LISTITEMSTATES_MINE {
47 LISS_NORMAL = 1,
48 LISS_HOT = 2,
49 LISS_SELECTED = 3,
50 LISS_DISABLED = 4,
51 LISS_SELECTEDNOTFOCUS = 5,
52 LISS_HOTSELECTED = 6,
55 // these defines must be in the order the columns are inserted!
58 #define MCS_NOTRAILINGDATES 0x0040
59 #define MCS_SHORTDAYSOFWEEK 0x0080
60 #define MCS_NOSELCHANGEONNAV 0x0100
62 #define DTM_SETMCSTYLE (DTM_FIRST + 11)
64 #endif
66 #define ICONITEMBORDER 5
68 #define GITLOG_START 0
69 #define GITLOG_START_ALL 1
70 #define GITLOG_END 100
72 #define LOGFILTER_ALL 1
73 #define LOGFILTER_MESSAGES 2
74 #define LOGFILTER_PATHS 3
75 #define LOGFILTER_AUTHORS 4
76 #define LOGFILTER_REVS 5
77 #define LOGFILTER_REGEX 6
78 #define LOGFILTER_BUGID 7
79 #define LOGFILTER_SUBJECT 8
81 //typedef void CALLBACK_PROCESS(void * data, int progress);
82 #define MSG_LOADED (WM_USER+110)
83 #define MSG_LOAD_PERCENTAGE (WM_USER+111)
84 #define MSG_REFLOG_CHANGED (WM_USER+112)
85 #define MSG_FETCHED_DIFF (WM_USER+113)
87 class CThreadSafePtrArray: public CPtrArray
89 CComCriticalSection *m_critSec;
90 public:
91 CThreadSafePtrArray(CComCriticalSection *section){ m_critSec = section ;}
92 void * SafeGetAt(INT_PTR i)
94 if(m_critSec)
95 m_critSec->Lock();
97 if( i<0 || i>=GetCount())
99 if(m_critSec)
100 m_critSec->Unlock();
102 return NULL;
105 if(m_critSec)
106 m_critSec->Unlock();
108 return GetAt(i);
110 INT_PTR SafeAdd(void *newElement)
112 INT_PTR ret;
113 if(m_critSec)
114 m_critSec->Lock();
115 ret = Add(newElement);
116 if(m_critSec)
117 m_critSec->Unlock();
118 return ret;
121 void SafeRemoveAll()
123 if(m_critSec)
124 m_critSec->Lock();
125 RemoveAll();
126 if(m_critSec)
127 m_critSec->Unlock();
132 class CGitLogListBase : public CHintListCtrl
134 DECLARE_DYNAMIC(CGitLogListBase)
136 public:
137 CGitLogListBase();
138 virtual ~CGitLogListBase();
139 ProjectProperties m_ProjectProperties;
141 CFilterData m_Filter;
143 void UpdateProjectProperties()
145 m_ProjectProperties.ReadProps(this->m_Path);
147 if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))
148 m_bShowBugtraqColumn = true;
149 else
150 m_bShowBugtraqColumn = false;
153 void ResetWcRev()
155 m_wcRev.GetBody()=_T("Fetching Status...");
156 m_wcRev.m_CallDiffAsync = DiffAsync;
157 InterlockedExchange(&m_wcRev.m_IsDiffFiles, FALSE);
159 void SetProjectPropertiesPath(const CTGitPath& path) {m_ProjectProperties.ReadProps(path);}
161 volatile LONG m_bNoDispUpdates;
162 BOOL m_IsIDReplaceAction;
163 BOOL m_IsOldFirst;
164 void hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow);
165 BOOL m_IsRebaseReplaceGraph;
167 void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
169 BOOL m_bStrictStopped;
170 BOOL m_bShowBugtraqColumn;
171 BOOL m_bSearchIndex;
172 BOOL m_bCancelled;
173 unsigned __int64 m_ContextMenuMask;
175 bool m_hasWC;
176 bool m_bShowWC;
177 GitRev m_wcRev;
178 volatile LONG m_bThreadRunning;
179 CLogCache m_LogCache;
181 CString m_startrev;
182 CString m_endrev;
184 // don't forget to bump BLAME_COLUMN_VERSION in GitStatusListCtrlHelpers.cpp if you change columns
185 enum
187 LOGLIST_GRAPH,
188 LOGLIST_REBASE,
189 LOGLIST_ID,
190 LOGLIST_HASH,
191 LOGLIST_ACTION,
192 LOGLIST_MESSAGE,
193 LOGLIST_AUTHOR,
194 LOGLIST_DATE,
195 LOGLIST_EMAIL,
196 LOGLIST_COMMIT_NAME,
197 LOGLIST_COMMIT_EMAIL,
198 LOGLIST_COMMIT_DATE,
199 LOGLIST_BUG,
200 LOGLIST_MESSAGE_MAX=300,
201 LOGLIST_MESSAGE_MIN=200,
203 GIT_LOG_GRAPH = 1<< LOGLIST_GRAPH,
204 GIT_LOG_REBASE = 1<< LOGLIST_REBASE,
205 GIT_LOG_ID = 1<< LOGLIST_ID,
206 GIT_LOG_HASH = 1<< LOGLIST_HASH,
207 GIT_LOG_ACTIONS = 1<< LOGLIST_ACTION,
208 GIT_LOG_MESSAGE = 1<< LOGLIST_MESSAGE,
209 GIT_LOG_AUTHOR = 1<< LOGLIST_AUTHOR,
210 GIT_LOG_DATE = 1<< LOGLIST_DATE,
211 GIT_LOG_EMAIL = 1<< LOGLIST_EMAIL,
212 GIT_LOG_COMMIT_NAME = 1<< LOGLIST_COMMIT_NAME,
213 GIT_LOG_COMMIT_EMAIL= 1<< LOGLIST_COMMIT_EMAIL,
214 GIT_LOG_COMMIT_DATE = 1<< LOGLIST_COMMIT_DATE,
215 GIT_LOGLIST_BUG = 1<< LOGLIST_BUG,
218 enum
220 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
221 ID_COMPARE = 1,
222 ID_SAVEAS,
223 ID_COMPARETWO,
224 ID_UPDATE,
225 ID_COPY,
226 ID_REVERTREV,
227 ID_MERGEREV,
228 ID_GNUDIFF1,
229 ID_GNUDIFF2,
230 ID_FINDENTRY,
231 ID_OPEN,
232 ID_BLAME,
233 ID_REPOBROWSE,
234 ID_LOG,
235 ID_POPPROPS,
236 ID_EDITNOTE,
237 ID_EDITLOG,
238 ID_DIFF,
239 ID_OPENWITH,
240 ID_COPYCLIPBOARD,
241 ID_COPYHASH,
242 ID_REVERTTOREV,
243 ID_BLAMECOMPARE,
244 ID_BLAMETWO,
245 ID_BLAMEDIFF,
246 ID_VIEWREV,
247 ID_VIEWPATHREV,
248 ID_EXPORT,
249 ID_COMPAREWITHPREVIOUS,
250 ID_BLAMEWITHPREVIOUS,
251 ID_GETMERGELOGS,
252 ID_REVPROPS,
253 ID_CHERRY_PICK,
254 ID_CREATE_BRANCH,
255 ID_CREATE_TAG,
256 ID_SWITCHTOREV,
257 ID_SWITCHBRANCH,
258 ID_RESET,
259 ID_REBASE_PICK,
260 ID_REBASE_EDIT,
261 ID_REBASE_SQUASH,
262 ID_REBASE_SKIP,
263 ID_COMBINE_COMMIT,
264 ID_STASH_APPLY,
265 ID_REFLOG_DEL,
266 ID_REBASE_TO_VERSION,
267 ID_CREATE_PATCH,
268 ID_DELETE,
269 ID_COMMIT,
270 ID_PUSH,
272 inline unsigned __int64 GetContextMenuBit(int i){ return ((unsigned __int64 )0x1)<<i ;}
273 void InsertGitColumn();
274 void ResizeAllListCtrlCols();
275 void CopySelectionToClipBoard(bool hashonly=FALSE);
276 void DiffSelectedRevWithPrevious();
277 bool IsSelectionContinuous();
278 int BeginFetchLog();
279 int FillGitLog(CTGitPath *path,int infomask=CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,CString *from=NULL,CString *to=NULL);
280 BOOL IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat);
282 CFindDlg *m_pFindDialog;
283 static const UINT m_FindDialogMessage;
284 void OnFind();
286 inline int ShownCountWithStopped() const { return (int)m_arShownList.GetCount() + (m_bStrictStopped ? 1 : 0); }
287 int FetchLogAsync(void * data=NULL);
288 CThreadSafePtrArray m_arShownList;
289 void Refresh(BOOL IsCleanFilter=TRUE);
290 void RecalculateShownList(CThreadSafePtrArray * pShownlist);
291 void Clear();
293 int m_nSelectedFilter;
294 bool m_bFilterWithRegex;
295 CLogDataVector m_logEntries;
296 void RemoveFilter();
297 void StartFilter();
298 bool ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase = false );
299 CString m_sFilterText;
301 __time64_t m_From;
302 __time64_t m_To;
304 CTGitPath m_Path;
305 int m_ShowMask;
306 CGitHash m_lastSelectedHash;
308 void GetTimeRange(CTime &oldest,CTime &latest);
309 virtual void ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMenu * menu)=0;
310 void ReloadHashMap()
312 m_HashMap.clear();
313 g_Git.GetMapHashToFriendName(m_HashMap);
314 m_CurrentBranch=g_Git.GetCurrentBranch();
315 this->m_HeadHash=g_Git.GetHash(_T("HEAD"));
316 m_wcRev.m_ParentHash.clear();
317 m_wcRev.m_ParentHash.push_back(m_HeadHash);
319 void SafeTerminateThread()
321 if(m_LoadingThread!=NULL)
323 InterlockedExchange(&m_bExitThread,TRUE);
324 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
325 if(ret == WAIT_TIMEOUT)
326 ::TerminateThread(m_LoadingThread,0);
327 m_LoadingThread = NULL;
331 bool IsInWorkingThread()
333 return (AfxGetThread() == m_LoadingThread);
336 void SetStartRef(const CString& StartRef)
338 m_StartRef=StartRef;
341 CString GetStartRef() const {return m_StartRef;}
343 int m_nSearchIndex;
345 volatile LONG m_bExitThread;
346 CWinThread* m_LoadingThread;
347 MAP_HASH_NAME m_HashMap;
349 public:
350 CString m_ColumnRegKey;
352 protected:
353 DECLARE_MESSAGE_MAP()
354 afx_msg void OnDestroy();
355 virtual afx_msg void OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult);
356 virtual afx_msg void OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult);
357 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
358 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
359 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
360 afx_msg LRESULT OnLoad(WPARAM wParam, LPARAM lParam);
361 afx_msg void OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult);
362 afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);
363 afx_msg void OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult);
364 afx_msg void OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult);
365 void OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult);
366 afx_msg void OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult);
367 void PreSubclassWindow();
368 virtual BOOL PreTranslateMessage(MSG* pMsg);
369 static UINT LogThreadEntry(LPVOID pVoid);
370 UINT LogThread();
371 void FetchLastLogInfo();
372 void FetchFullLogInfo(CString &from, CString &to);
373 void FillBackGround(HDC hdc, int Index,CRect &rect);
374 void DrawTagBranch(HDC,CRect &rect,INT_PTR index);
375 void DrawGraph(HDC,CRect &rect,INT_PTR index);
377 BOOL GetShortName(CString ref, CString &shortname,CString prefix);
378 void paintGraphLane(HDC hdc,int laneHeight, int type, int x1, int x2,
379 const COLORREF& col,const COLORREF& activeColor, int top) ;
380 void DrawLine(HDC hdc, int x1, int y1, int x2, int y2){::MoveToEx(hdc,x1,y1,NULL);::LineTo(hdc,x2,y2);}
382 * Save column widths to the registry
384 void SaveColumnWidths(); // save col widths to the registry
386 BOOL IsEntryInDateRange(int i);
388 int GetHeadIndex();
390 std::vector<GitRev*> m_AsynDiffList;
391 CComCriticalSection m_AsynDiffListLock;
392 HANDLE m_AsyncDiffEvent;
393 volatile LONG m_AsyncThreadExit;
394 CWinThread* m_DiffingThread;
396 static int DiffAsync(GitRev *rev, void *data)
398 ULONGLONG offset=((CGitLogListBase*)data)->m_LogCache.GetOffset(rev->m_CommitHash);
399 if(!offset)
401 ((CGitLogListBase*)data)->m_AsynDiffListLock.Lock();
402 ((CGitLogListBase*)data)->m_AsynDiffList.push_back(rev);
403 ((CGitLogListBase*)data)->m_AsynDiffListLock.Unlock();
404 ::SetEvent(((CGitLogListBase*)data)->m_AsyncDiffEvent);
406 else
408 if(((CGitLogListBase*)data)->m_LogCache.LoadOneItem(*rev,offset))
410 ((CGitLogListBase*)data)->m_AsynDiffListLock.Lock();
411 ((CGitLogListBase*)data)->m_AsynDiffList.push_back(rev);
412 ((CGitLogListBase*)data)->m_AsynDiffListLock.Unlock();
413 ::SetEvent(((CGitLogListBase*)data)->m_AsyncDiffEvent);
415 InterlockedExchange(&rev->m_IsDiffFiles, TRUE);
416 if(rev->m_IsDiffFiles && rev->m_IsCommitParsed)
417 InterlockedExchange(&rev->m_IsFull, TRUE);
419 return 0;
422 static UINT AsyncThread(LPVOID data)
424 return ((CGitLogListBase*)data)->AsyncDiffThread();
427 int AsyncDiffThread();
428 bool m_AsyncThreadExited;
430 public:
431 void SafeTerminateAsyncDiffThread()
433 if(m_DiffingThread!=NULL && m_AsyncThreadExit != TRUE)
435 m_AsyncThreadExit = TRUE;
436 ::SetEvent(m_AsyncDiffEvent);
437 DWORD ret = WAIT_TIMEOUT;
438 // do not block here, but process messages and ask until the thread ends
439 while (ret == WAIT_TIMEOUT && !m_AsyncThreadExited)
441 AfxGetThread()->PumpMessage(); // process messages, so that GetTopIndex and so on in the thread work
442 ret = ::WaitForSingleObject(m_DiffingThread->m_hThread, 100);
444 m_DiffingThread = NULL;
448 protected:
449 CComCriticalSection m_critSec;
451 HICON m_hModifiedIcon;
452 HICON m_hReplacedIcon;
453 HICON m_hAddedIcon;
454 HICON m_hDeletedIcon;
455 HICON m_hFetchIcon;
457 HFONT m_boldFont;
459 CRegDWORD m_regMaxBugIDColWidth;
461 void *m_ProcData;
462 CStoreSelection* m_pStoreSelection;
464 CColors m_Colors;
466 CString m_CurrentBranch;
467 CGitHash m_HeadHash;
469 CString m_StartRef; //Ref of the top-commit
471 COLORREF m_LineColors[Lanes::COLORS_NUM];
472 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
473 bool m_bRelativeTimes; // Show relative times
474 GIT_LOG m_DllGitLog;
476 ColumnManager m_ColumnManager;
477 DWORD m_dwDefaultColumns;