libgit2: Enable fetch function
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.h
blob4650ffe01441120d35465edc62d32e1b7929293d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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 "Git.h"
25 #include "ProjectProperties.h"
26 #include "TGitPath.h"
27 #include "registry.h"
28 #include "SplitterControl.h"
29 #include "Colors.h"
30 #include "MenuButton.h"
31 #include "LogDlgHelper.h"
32 #include "FilterEdit.h"
33 #include "GitRev.h"
34 #include "Tooltip.h"
35 //#include "GitLogList.h"
36 #include "lanes.h"
37 #include "GitLogCache.h"
38 #include <regex>
39 #include <GitStatusListCtrl.h>
40 #include "FindDlg.h"
42 // CGitLogList
43 #if (NTDDI_VERSION < NTDDI_LONGHORN)
45 enum LISTITEMSTATES_MINE {
46 LISS_NORMAL = 1,
47 LISS_HOT = 2,
48 LISS_SELECTED = 3,
49 LISS_DISABLED = 4,
50 LISS_SELECTEDNOTFOCUS = 5,
51 LISS_HOTSELECTED = 6,
54 // these defines must be in the order the columns are inserted!
57 #define MCS_NOTRAILINGDATES 0x0040
58 #define MCS_SHORTDAYSOFWEEK 0x0080
59 #define MCS_NOSELCHANGEONNAV 0x0100
61 #define DTM_SETMCSTYLE (DTM_FIRST + 11)
63 #endif
65 #define ICONITEMBORDER 5
67 #define GITLOG_START 0
68 #define GITLOG_START_ALL 1
69 #define GITLOG_END 100
71 #define LOGFILTER_ALL 0xFFFF
72 #define LOGFILTER_MESSAGES 0x0001
73 #define LOGFILTER_PATHS 0x0002
74 #define LOGFILTER_AUTHORS 0x0004
75 #define LOGFILTER_REVS 0x0008
76 #define LOGFILTER_REGEX 0x0010
77 #define LOGFILTER_BUGID 0x0020
78 #define LOGFILTER_SUBJECT 0x0040
79 #define LOGFILTER_REFNAME 0x0080
80 #define LOGFILTER_EMAILS 0x0100
82 #define LOGLIST_SHOWNOREFS 0x0000
83 #define LOGLIST_SHOWLOCALBRANCHES 0x0001
84 #define LOGLIST_SHOWREMOTEBRANCHES 0x0002
85 #define LOGLIST_SHOWTAGS 0x0004
86 #define LOGLIST_SHOWSTASH 0x0008
87 #define LOGLIST_SHOWBISECT 0x0010
88 #define LOGLIST_SHOWALLREFS 0xFFFF
90 //typedef void CALLBACK_PROCESS(void * data, int progress);
91 #define MSG_LOADED (WM_USER+110)
92 #define MSG_LOAD_PERCENTAGE (WM_USER+111)
93 #define MSG_REFLOG_CHANGED (WM_USER+112)
94 #define MSG_FETCHED_DIFF (WM_USER+113)
96 class CThreadSafePtrArray: public CPtrArray
98 CComCriticalSection *m_critSec;
99 public:
100 CThreadSafePtrArray(CComCriticalSection *section){ m_critSec = section ;}
101 void * SafeGetAt(INT_PTR i)
103 if(m_critSec)
104 m_critSec->Lock();
106 if( i<0 || i>=GetCount())
108 if(m_critSec)
109 m_critSec->Unlock();
111 return NULL;
114 if(m_critSec)
115 m_critSec->Unlock();
117 return GetAt(i);
119 INT_PTR SafeAdd(void *newElement)
121 INT_PTR ret;
122 if(m_critSec)
123 m_critSec->Lock();
124 ret = Add(newElement);
125 if(m_critSec)
126 m_critSec->Unlock();
127 return ret;
130 void SafeRemoveAll()
132 if(m_critSec)
133 m_critSec->Lock();
134 RemoveAll();
135 if(m_critSec)
136 m_critSec->Unlock();
141 class CGitLogListBase : public CHintListCtrl
143 DECLARE_DYNAMIC(CGitLogListBase)
145 public:
146 CGitLogListBase();
147 virtual ~CGitLogListBase();
148 ProjectProperties m_ProjectProperties;
150 CFilterData m_Filter;
152 void UpdateProjectProperties()
154 // do not crash if config file is broken; needed for TortoiseGitBlame
157 m_ProjectProperties.ReadProps(this->m_Path);
159 catch (char *)
163 if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))
164 m_bShowBugtraqColumn = true;
165 else
166 m_bShowBugtraqColumn = false;
169 void ResetWcRev(bool refresh = false)
171 m_wcRev.Clear();
172 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
173 m_wcRev.m_Mark = _T('-');
174 m_wcRev.GetBody() = CString(MAKEINTRESOURCE(IDS_LOG_FETCHINGSTATUS));
175 m_wcRev.m_CallDiffAsync = DiffAsync;
176 InterlockedExchange(&m_wcRev.m_IsDiffFiles, FALSE);
177 if (refresh && m_bShowWC)
178 m_arShownList[0] = &m_wcRev;
180 void SetProjectPropertiesPath(const CTGitPath& path) {m_ProjectProperties.ReadProps(path);}
182 volatile LONG m_bNoDispUpdates;
183 BOOL m_IsIDReplaceAction;
184 BOOL m_IsOldFirst;
185 void hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow);
186 BOOL m_IsRebaseReplaceGraph;
187 BOOL m_bNoHightlightHead;
189 void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
191 BOOL m_bStrictStopped;
192 BOOL m_bShowBugtraqColumn;
193 BOOL m_bSearchIndex;
194 BOOL m_bCancelled;
195 unsigned __int64 m_ContextMenuMask;
197 bool m_hasWC;
198 bool m_bShowWC;
199 GitRev m_wcRev;
200 volatile LONG m_bThreadRunning;
201 CLogCache m_LogCache;
203 CString m_startrev;
204 CString m_endrev;
206 // don't forget to bump BLAME_COLUMN_VERSION in GitStatusListCtrlHelpers.cpp if you change columns
207 enum
209 LOGLIST_GRAPH,
210 LOGLIST_REBASE,
211 LOGLIST_ID,
212 LOGLIST_HASH,
213 LOGLIST_ACTION,
214 LOGLIST_MESSAGE,
215 LOGLIST_AUTHOR,
216 LOGLIST_DATE,
217 LOGLIST_EMAIL,
218 LOGLIST_COMMIT_NAME,
219 LOGLIST_COMMIT_EMAIL,
220 LOGLIST_COMMIT_DATE,
221 LOGLIST_BUG,
222 LOGLIST_MESSAGE_MAX=300,
223 LOGLIST_MESSAGE_MIN=200,
225 GIT_LOG_GRAPH = 1<< LOGLIST_GRAPH,
226 GIT_LOG_REBASE = 1<< LOGLIST_REBASE,
227 GIT_LOG_ID = 1<< LOGLIST_ID,
228 GIT_LOG_HASH = 1<< LOGLIST_HASH,
229 GIT_LOG_ACTIONS = 1<< LOGLIST_ACTION,
230 GIT_LOG_MESSAGE = 1<< LOGLIST_MESSAGE,
231 GIT_LOG_AUTHOR = 1<< LOGLIST_AUTHOR,
232 GIT_LOG_DATE = 1<< LOGLIST_DATE,
233 GIT_LOG_EMAIL = 1<< LOGLIST_EMAIL,
234 GIT_LOG_COMMIT_NAME = 1<< LOGLIST_COMMIT_NAME,
235 GIT_LOG_COMMIT_EMAIL= 1<< LOGLIST_COMMIT_EMAIL,
236 GIT_LOG_COMMIT_DATE = 1<< LOGLIST_COMMIT_DATE,
237 GIT_LOGLIST_BUG = 1<< LOGLIST_BUG,
240 enum
242 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
243 ID_COMPARE = 1, // compare revision with WC
244 ID_SAVEAS,
245 ID_COMPARETWO, // compare two revisions
246 ID_COPY,
247 ID_REVERTREV,
248 ID_MERGEREV,
249 ID_GNUDIFF1, // compare with WC, unified
250 ID_GNUDIFF2, // compare two revisions, unified
251 ID_FINDENTRY,
252 ID_OPEN,
253 ID_BLAME,
254 ID_REPOBROWSE,
255 ID_LOG,
256 ID_EDITNOTE,
257 ID_DIFF,
258 ID_OPENWITH,
259 ID_COPYCLIPBOARD,
260 ID_COPYHASH,
261 ID_REVERTTOREV,
262 ID_BLAMECOMPARE,
263 ID_BLAMEDIFF,
264 ID_VIEWREV,
265 ID_VIEWPATHREV,
266 ID_EXPORT,
267 ID_COMPAREWITHPREVIOUS,
268 ID_BLAMEWITHPREVIOUS,
269 ID_CHERRY_PICK,
270 ID_CREATE_BRANCH,
271 ID_CREATE_TAG,
272 ID_SWITCHTOREV,
273 ID_SWITCHBRANCH,
274 ID_RESET,
275 ID_REBASE_PICK,
276 ID_REBASE_EDIT,
277 ID_REBASE_SQUASH,
278 ID_REBASE_SKIP,
279 ID_COMBINE_COMMIT,
280 ID_STASH_SAVE,
281 ID_STASH_LIST,
282 ID_STASH_POP,
283 ID_REFLOG_STASH_APPLY,
284 ID_REFLOG_DEL,
285 ID_REBASE_TO_VERSION,
286 ID_CREATE_PATCH,
287 ID_DELETE,
288 ID_COMMIT,
289 ID_PUSH,
290 ID_FETCH,
291 ID_SHOWBRANCHES,
292 ID_COPYCLIPBOARDMESSAGES,
293 ID_BISECTSTART,
295 enum
297 ID_COPY_ALL,
298 ID_COPY_MESSAGE,
299 ID_COPY_SUBJECT,
300 ID_COPY_HASH,
302 inline unsigned __int64 GetContextMenuBit(int i){ return ((unsigned __int64 )0x1)<<i ;}
303 void InsertGitColumn();
304 void ResizeAllListCtrlCols();
305 void CopySelectionToClipBoard(int toCopy = ID_COPY_ALL);
306 void DiffSelectedRevWithPrevious();
307 bool IsSelectionContinuous();
308 int BeginFetchLog();
309 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);
310 BOOL IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat);
312 CFindDlg *m_pFindDialog;
313 static const UINT m_FindDialogMessage;
314 void OnFind();
316 static const UINT m_ScrollToMessage;
318 inline int ShownCountWithStopped() const { return (int)m_arShownList.GetCount() + (m_bStrictStopped ? 1 : 0); }
319 int FetchLogAsync(void * data=NULL);
320 CThreadSafePtrArray m_arShownList;
321 void Refresh(BOOL IsCleanFilter=TRUE);
322 void RecalculateShownList(CThreadSafePtrArray * pShownlist);
323 void Clear();
325 DWORD m_SelectedFilters;
326 bool m_bFilterWithRegex;
327 CLogDataVector m_logEntries;
328 void RemoveFilter();
329 void StartFilter();
330 bool ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase = false );
331 CString m_sFilterText;
333 __time64_t m_From;
334 __time64_t m_To;
336 CTGitPath m_Path;
337 int m_ShowMask;
338 CGitHash m_lastSelectedHash;
339 int m_ShowRefMask;
341 void GetTimeRange(CTime &oldest,CTime &latest);
342 virtual void ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMenu * menu)=0;
343 void ReloadHashMap()
345 m_HashMap.clear();
347 if (g_Git.GetMapHashToFriendName(m_HashMap))
348 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
350 m_CurrentBranch=g_Git.GetCurrentBranch();
352 if (g_Git.GetHash(m_HeadHash, _T("HEAD")))
354 MessageBox(g_Git.GetGitLastErr(_T("Could not get HEAD hash. Quitting...")), _T("TortoiseGit"), MB_ICONERROR);
355 ExitProcess(1);
358 m_wcRev.m_ParentHash.clear();
359 m_wcRev.m_ParentHash.push_back(m_HeadHash);
361 FetchRemoteList();
362 FetchTrackingBranchList();
364 void SafeTerminateThread()
366 if (m_LoadingThread!=NULL && InterlockedExchange(&m_bExitThread, TRUE) == FALSE)
368 DWORD ret = WAIT_TIMEOUT;
369 for (int i = 0; i < 200 && m_bThreadRunning; ++i)
370 ret =::WaitForSingleObject(m_LoadingThread->m_hThread, 100);
371 if (ret == WAIT_TIMEOUT && m_bThreadRunning)
372 ::TerminateThread(m_LoadingThread, 0);
373 m_LoadingThread = NULL;
377 bool IsInWorkingThread()
379 return (AfxGetThread() == m_LoadingThread);
382 void SetStartRef(const CString& StartRef)
384 m_StartRef=StartRef;
387 CString GetStartRef() const {return m_StartRef;}
389 int m_nSearchIndex;
391 volatile LONG m_bExitThread;
392 CWinThread* m_LoadingThread;
393 MAP_HASH_NAME m_HashMap;
394 std::map<CString, std::pair<CString, CString>> m_TrackingMap;
396 public:
397 CString m_ColumnRegKey;
399 protected:
400 typedef struct {
401 CString name;
402 COLORREF color;
403 CString simplifiedName;
404 bool singleRemote;
405 bool hasTracking;
406 bool sameName;
407 } REFLABEL;
409 DECLARE_MESSAGE_MAP()
410 afx_msg void OnDestroy();
411 virtual afx_msg void OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult);
412 virtual afx_msg void OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult);
413 afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam);
414 afx_msg LRESULT OnScrollToMessage(WPARAM wParam, LPARAM lParam);
415 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
416 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
417 afx_msg LRESULT OnLoad(WPARAM wParam, LPARAM lParam);
418 afx_msg void OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult);
419 afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);
420 afx_msg void OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult);
421 afx_msg void OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult);
422 void OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult);
423 afx_msg void OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult);
424 void PreSubclassWindow();
425 virtual BOOL PreTranslateMessage(MSG* pMsg);
426 static UINT LogThreadEntry(LPVOID pVoid);
427 UINT LogThread();
428 void FetchRemoteList();
429 void FetchTrackingBranchList();
430 void FetchLastLogInfo();
431 void FetchFullLogInfo(CString &from, CString &to);
432 void FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect);
433 void DrawTagBranch(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> refList);
434 void DrawGraph(HDC,CRect &rect,INT_PTR index);
436 void paintGraphLane(HDC hdc,int laneHeight, int type, int x1, int x2,
437 const COLORREF& col,const COLORREF& activeColor, int top) ;
438 void DrawLine(HDC hdc, int x1, int y1, int x2, int y2){::MoveToEx(hdc,x1,y1,NULL);::LineTo(hdc,x2,y2);}
440 * Save column widths to the registry
442 void SaveColumnWidths(); // save col widths to the registry
444 BOOL IsEntryInDateRange(int i);
446 int GetHeadIndex();
448 std::vector<GitRev*> m_AsynDiffList;
449 CComCriticalSection m_AsynDiffListLock;
450 HANDLE m_AsyncDiffEvent;
451 volatile LONG m_AsyncThreadExit;
452 CWinThread* m_DiffingThread;
454 static int DiffAsync(GitRev *rev, void *data)
456 ULONGLONG offset=((CGitLogListBase*)data)->m_LogCache.GetOffset(rev->m_CommitHash);
457 if(!offset)
459 ((CGitLogListBase*)data)->m_AsynDiffListLock.Lock();
460 ((CGitLogListBase*)data)->m_AsynDiffList.push_back(rev);
461 ((CGitLogListBase*)data)->m_AsynDiffListLock.Unlock();
462 ::SetEvent(((CGitLogListBase*)data)->m_AsyncDiffEvent);
464 else
466 if(((CGitLogListBase*)data)->m_LogCache.LoadOneItem(*rev,offset))
468 ((CGitLogListBase*)data)->m_AsynDiffListLock.Lock();
469 ((CGitLogListBase*)data)->m_AsynDiffList.push_back(rev);
470 ((CGitLogListBase*)data)->m_AsynDiffListLock.Unlock();
471 ::SetEvent(((CGitLogListBase*)data)->m_AsyncDiffEvent);
473 InterlockedExchange(&rev->m_IsDiffFiles, TRUE);
474 if(rev->m_IsDiffFiles && rev->m_IsCommitParsed)
475 InterlockedExchange(&rev->m_IsFull, TRUE);
477 return 0;
480 static UINT AsyncThread(LPVOID data)
482 return ((CGitLogListBase*)data)->AsyncDiffThread();
485 int AsyncDiffThread();
486 bool m_AsyncThreadExited;
488 public:
489 void SafeTerminateAsyncDiffThread()
491 if(m_DiffingThread!=NULL && m_AsyncThreadExit != TRUE)
493 m_AsyncThreadExit = TRUE;
494 ::SetEvent(m_AsyncDiffEvent);
495 DWORD ret = WAIT_TIMEOUT;
496 // do not block here, but process messages and ask until the thread ends
497 while (ret == WAIT_TIMEOUT && !m_AsyncThreadExited)
499 AfxGetThread()->PumpMessage(); // process messages, so that GetTopIndex and so on in the thread work
500 ret = ::WaitForSingleObject(m_DiffingThread->m_hThread, 100);
502 m_DiffingThread = NULL;
506 protected:
507 CComCriticalSection m_critSec;
509 HICON m_hModifiedIcon;
510 HICON m_hReplacedIcon;
511 HICON m_hAddedIcon;
512 HICON m_hDeletedIcon;
513 HICON m_hFetchIcon;
515 HFONT m_boldFont;
517 CRegDWORD m_regMaxBugIDColWidth;
519 void *m_ProcData;
520 CStoreSelection* m_pStoreSelection;
522 CColors m_Colors;
524 CString m_CurrentBranch;
525 CGitHash m_HeadHash;
527 CString m_StartRef; //Ref of the top-commit
529 COLORREF m_LineColors[Lanes::COLORS_NUM];
530 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
531 bool m_bRelativeTimes; // Show relative times
532 GIT_LOG m_DllGitLog;
533 CString m_SingleRemote;
534 bool m_bSymbolizeRefNames;
536 ColumnManager m_ColumnManager;
537 DWORD m_dwDefaultColumns;