1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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
23 #include "HintListCtrl.h"
25 #include "ProjectProperties.h"
28 #include "SplitterControl.h"
30 #include "MenuButton.h"
31 #include "LogDlgHelper.h"
32 #include "FilterEdit.h"
36 #include "GitLogCache.h"
38 #include "GitStatusListCtrl.h"
42 #define ICONITEMBORDER 5
44 #define GITLOG_START 0
45 #define GITLOG_START_ALL 1
46 #define GITLOG_END 100
48 #define LOGFILTER_ALL 0xFFFF
49 #define LOGFILTER_TOGGLE 0x8000
50 #define LOGFILTER_MESSAGES 0x0001
51 #define LOGFILTER_PATHS 0x0002
52 #define LOGFILTER_AUTHORS 0x0004
53 #define LOGFILTER_REVS 0x0008
54 #define LOGFILTER_REGEX 0x0010
55 #define LOGFILTER_BUGID 0x0020
56 #define LOGFILTER_SUBJECT 0x0040
57 #define LOGFILTER_REFNAME 0x0080
58 #define LOGFILTER_EMAILS 0x0100
60 #define LOGLIST_SHOWNOTHING 0x0000
61 #define LOGLIST_SHOWLOCALBRANCHES 0x0001
62 #define LOGLIST_SHOWREMOTEBRANCHES 0x0002
63 #define LOGLIST_SHOWTAGS 0x0004
64 #define LOGLIST_SHOWSTASH 0x0008
65 #define LOGLIST_SHOWBISECT 0x0010
66 #define LOGLIST_SHOWALLREFS 0xFFFF
68 //typedef void CALLBACK_PROCESS(void * data, int progress);
69 #define MSG_LOADED (WM_USER+110)
70 #define MSG_LOAD_PERCENTAGE (WM_USER+111)
71 #define MSG_REFLOG_CHANGED (WM_USER+112)
72 #define MSG_FETCHED_DIFF (WM_USER+113)
74 class SelectionHistory
76 #define HISTORYLENGTH 50
78 SelectionHistory(void)
81 lastselected
.reserve(HISTORYLENGTH
);
83 void Add(CGitHash
&hash
)
88 size_t size
= lastselected
.size();
90 // re-select last selected commit
91 if (size
> 0 && hash
== lastselected
[size
- 1])
94 if (location
!= size
- 1)
99 // go back and some commit was highlight
100 if (size
> 0 && location
!= size
- 1)
102 // Re-select current one, it may be a forked point.
103 if (hash
== lastselected
[location
])
105 // That is that discarding forward history when a forked entry is really coming.
106 // And user has the chance to Go Forward again in this situation.
107 // IOW, (hash != lastselected[location]) means user wants a forked history,
108 // and this change saves one step from old behavior.
111 // Discard forward history if any
112 while (lastselected
.size() - 1 > location
)
113 lastselected
.pop_back();
116 if (lastselected
.size() >= HISTORYLENGTH
)
117 lastselected
.erase(lastselected
.cbegin());
119 lastselected
.push_back(hash
);
120 location
= lastselected
.size() - 1;
122 BOOL
GoBack(CGitHash
& historyEntry
)
127 historyEntry
= lastselected
[--location
];
131 BOOL
GoForward(CGitHash
& historyEntry
)
133 if (location
>= lastselected
.size() - 1)
136 historyEntry
= lastselected
[++location
];
141 std::vector
<CGitHash
> lastselected
;
145 class CThreadSafePtrArray
: public CPtrArray
147 CComCriticalSection
*m_critSec
;
149 CThreadSafePtrArray(CComCriticalSection
*section
){ m_critSec
= section
;}
150 void * SafeGetAt(INT_PTR i
)
155 if( i
<0 || i
>=GetCount())
168 INT_PTR
SafeAdd(void *newElement
)
173 ret
= Add(newElement
);
190 class CGitLogListBase
: public CHintListCtrl
192 DECLARE_DYNAMIC(CGitLogListBase
)
196 virtual ~CGitLogListBase();
197 ProjectProperties m_ProjectProperties
;
199 CFilterData m_Filter
;
201 void UpdateProjectProperties()
203 m_ProjectProperties
.ReadProps();
205 if ((!m_ProjectProperties
.sUrl
.IsEmpty())||(!m_ProjectProperties
.sCheckRe
.IsEmpty()))
206 m_bShowBugtraqColumn
= true;
208 m_bShowBugtraqColumn
= false;
211 void ResetWcRev(bool refresh
= false)
214 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
215 m_wcRev
.m_Mark
= _T('-');
216 m_wcRev
.GetBody() = CString(MAKEINTRESOURCE(IDS_LOG_FETCHINGSTATUS
));
217 m_wcRev
.m_CallDiffAsync
= DiffAsync
;
218 InterlockedExchange(&m_wcRev
.m_IsDiffFiles
, FALSE
);
219 if (refresh
&& m_bShowWC
)
220 m_arShownList
[0] = &m_wcRev
;
223 volatile LONG m_bNoDispUpdates
;
224 BOOL m_IsIDReplaceAction
;
226 void hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
);
227 BOOL m_IsRebaseReplaceGraph
;
228 BOOL m_bNoHightlightHead
;
230 void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
);
232 BOOL m_bStrictStopped
;
233 BOOL m_bShowBugtraqColumn
;
236 unsigned __int64 m_ContextMenuMask
;
241 volatile LONG m_bThreadRunning
;
242 CLogCache m_LogCache
;
245 // don't forget to bump BLAME_COLUMN_VERSION in GitStatusListCtrlHelpers.cpp if you change columns
258 LOGLIST_COMMIT_EMAIL
,
262 LOGLIST_MESSAGE_MAX
=300,
263 LOGLIST_MESSAGE_MIN
=200,
265 GIT_LOG_GRAPH
= 1<< LOGLIST_GRAPH
,
266 GIT_LOG_REBASE
= 1<< LOGLIST_REBASE
,
267 GIT_LOG_ID
= 1<< LOGLIST_ID
,
268 GIT_LOG_HASH
= 1<< LOGLIST_HASH
,
269 GIT_LOG_ACTIONS
= 1<< LOGLIST_ACTION
,
270 GIT_LOG_MESSAGE
= 1<< LOGLIST_MESSAGE
,
271 GIT_LOG_AUTHOR
= 1<< LOGLIST_AUTHOR
,
272 GIT_LOG_DATE
= 1<< LOGLIST_DATE
,
273 GIT_LOG_EMAIL
= 1<< LOGLIST_EMAIL
,
274 GIT_LOG_COMMIT_NAME
= 1<< LOGLIST_COMMIT_NAME
,
275 GIT_LOG_COMMIT_EMAIL
= 1<< LOGLIST_COMMIT_EMAIL
,
276 GIT_LOG_COMMIT_DATE
= 1<< LOGLIST_COMMIT_DATE
,
277 GIT_LOGLIST_BUG
= 1<< LOGLIST_BUG
,
278 GIT_LOGLIST_SVNREV
= 1<< LOGLIST_SVNREV
,
283 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
284 ID_COMPARE
= 1, // compare revision with WC
286 ID_COMPARETWO
, // compare two revisions
290 ID_GNUDIFF1
, // compare with WC, unified
291 ID_GNUDIFF2
, // compare two revisions, unified
308 ID_COMPAREWITHPREVIOUS
,
324 ID_REFLOG_STASH_APPLY
,
326 ID_REBASE_TO_VERSION
,
334 ID_COPYCLIPBOARDMESSAGES
,
337 ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
,
352 FILTERSHOW_MERGEPOINTS
= 2,
353 FILTERSHOW_ANYCOMMIT
= 4,
354 FILTERSHOW_ALL
= FILTERSHOW_ANYCOMMIT
| FILTERSHOW_REFS
| FILTERSHOW_MERGEPOINTS
359 LOGACTIONS_REBASE_CURRENT
= 0x08000000,
360 LOGACTIONS_REBASE_PICK
= 0x04000000,
361 LOGACTIONS_REBASE_SQUASH
= 0x02000000,
362 LOGACTIONS_REBASE_EDIT
= 0x01000000,
363 LOGACTIONS_REBASE_DONE
= 0x00800000,
364 LOGACTIONS_REBASE_SKIP
= 0x00400000,
365 LOGACTIONS_REBASE_MASK
= 0x0FC00000,
366 LOGACTIONS_REBASE_MODE_MASK
= 0x07C00000,
368 inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
369 static CString
GetRebaseActionName(int action
);
370 void InsertGitColumn();
371 void ResizeAllListCtrlCols();
372 void CopySelectionToClipBoard(int toCopy
= ID_COPY_ALL
);
373 void DiffSelectedRevWithPrevious();
374 bool IsSelectionContinuous();
376 int FillGitLog(CTGitPath
*path
, CString
*range
= NULL
, int infomask
= CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
377 int FillGitLog(std::set
<CGitHash
>& hashes
);
378 BOOL
IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
);
379 bool ShouldShowFilter(GitRev
*pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>> &commitChildren
);
380 void ShowGraphColumn(bool bShow
);
381 CString
GetTagInfo(GitRev
* pLogEntry
);
383 CFindDlg
*m_pFindDialog
;
384 static const UINT m_FindDialogMessage
;
387 static const UINT m_ScrollToMessage
;
388 static const UINT m_RebaseActionMessage
;
390 inline int ShownCountWithStopped() const { return (int)m_arShownList
.GetCount() + (m_bStrictStopped
? 1 : 0); }
391 int FetchLogAsync(void * data
=NULL
);
392 CThreadSafePtrArray m_arShownList
;
393 void Refresh(BOOL IsCleanFilter
=TRUE
);
394 void RecalculateShownList(CThreadSafePtrArray
* pShownlist
);
397 DWORD m_SelectedFilters
;
398 FilterShow m_ShowFilter
;
399 bool m_bFilterWithRegex
;
400 CLogDataVector m_logEntries
;
403 bool ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
= false );
404 CString m_sFilterText
;
411 CGitHash m_lastSelectedHash
;
412 SelectionHistory m_selectionHistory
;
413 CGitHash m_highlight
;
416 void GetTimeRange(CTime
&oldest
,CTime
&latest
);
417 virtual void GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
);
418 virtual void ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
* menu
)=0;
423 if (g_Git
.GetMapHashToFriendName(m_HashMap
))
424 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
426 m_CurrentBranch
=g_Git
.GetCurrentBranch();
428 if (g_Git
.GetHash(m_HeadHash
, _T("HEAD")))
430 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash. Quitting...")), _T("TortoiseGit"), MB_ICONERROR
);
434 m_wcRev
.m_ParentHash
.clear();
435 m_wcRev
.m_ParentHash
.push_back(m_HeadHash
);
438 FetchTrackingBranchList();
440 void SafeTerminateThread()
442 if (m_LoadingThread
!=NULL
&& InterlockedExchange(&m_bExitThread
, TRUE
) == FALSE
)
444 DWORD ret
= WAIT_TIMEOUT
;
445 for (int i
= 0; i
< 200 && m_bThreadRunning
; ++i
)
446 ret
=::WaitForSingleObject(m_LoadingThread
->m_hThread
, 100);
447 if (ret
== WAIT_TIMEOUT
&& m_bThreadRunning
)
448 ::TerminateThread(m_LoadingThread
, 0);
449 m_LoadingThread
= NULL
;
453 bool IsInWorkingThread()
455 return (AfxGetThread() == m_LoadingThread
);
458 void SetRange(const CString
& range
)
463 CString
GetRange() const { return m_sRange
; }
465 bool HasFilterText() const { return !m_sFilterText
.IsEmpty() && m_sFilterText
!= _T("!"); }
469 volatile LONG m_bExitThread
;
470 CWinThread
* m_LoadingThread
;
471 MAP_HASH_NAME m_HashMap
;
472 std::map
<CString
, std::pair
<CString
, CString
>> m_TrackingMap
;
475 CString m_ColumnRegKey
;
476 CComCriticalSection m_critSec_AsyncDiff
;
482 CString simplifiedName
;
489 DECLARE_MESSAGE_MAP()
490 afx_msg
void OnDestroy();
491 virtual afx_msg
void OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
492 virtual afx_msg
void OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
493 afx_msg LRESULT
OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
);
494 afx_msg LRESULT
OnScrollToMessage(WPARAM wParam
, LPARAM lParam
);
495 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
496 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
497 afx_msg LRESULT
OnLoad(WPARAM wParam
, LPARAM lParam
);
498 afx_msg
void OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
);
499 afx_msg
void OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
);
500 afx_msg
void OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
);
501 afx_msg
void OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
);
502 void OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
);
503 afx_msg
void OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
504 void PreSubclassWindow();
505 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
506 static UINT
LogThreadEntry(LPVOID pVoid
);
508 bool IsOnStash(int index
);
509 bool IsStash(const GitRev
* pSelLogEntry
);
510 void FetchRemoteList();
511 void FetchTrackingBranchList();
512 void FetchLastLogInfo();
513 void FetchFullLogInfo(CString
&from
, CString
&to
);
514 void FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
);
515 void DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
);
516 void DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
);
517 void DrawGraph(HDC
,CRect
&rect
,INT_PTR index
);
519 void paintGraphLane(HDC hdc
,int laneHeight
, int type
, int x1
, int x2
,
520 const COLORREF
& col
,const COLORREF
& activeColor
, int top
) ;
521 void DrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
){::MoveToEx(hdc
,x1
,y1
,NULL
);::LineTo(hdc
,x2
,y2
);}
523 * Save column widths to the registry
525 void SaveColumnWidths(); // save col widths to the registry
527 BOOL
IsEntryInDateRange(int i
);
531 std::vector
<GitRev
*> m_AsynDiffList
;
532 CComCriticalSection m_AsynDiffListLock
;
533 HANDLE m_AsyncDiffEvent
;
534 volatile LONG m_AsyncThreadExit
;
535 CWinThread
* m_DiffingThread
;
537 static int DiffAsync(GitRev
*rev
, void *data
)
539 ULONGLONG offset
=((CGitLogListBase
*)data
)->m_LogCache
.GetOffset(rev
->m_CommitHash
);
542 ((CGitLogListBase
*)data
)->m_AsynDiffListLock
.Lock();
543 ((CGitLogListBase
*)data
)->m_AsynDiffList
.push_back(rev
);
544 ((CGitLogListBase
*)data
)->m_AsynDiffListLock
.Unlock();
545 ::SetEvent(((CGitLogListBase
*)data
)->m_AsyncDiffEvent
);
549 if(((CGitLogListBase
*)data
)->m_LogCache
.LoadOneItem(*rev
,offset
))
551 ((CGitLogListBase
*)data
)->m_AsynDiffListLock
.Lock();
552 ((CGitLogListBase
*)data
)->m_AsynDiffList
.push_back(rev
);
553 ((CGitLogListBase
*)data
)->m_AsynDiffListLock
.Unlock();
554 ::SetEvent(((CGitLogListBase
*)data
)->m_AsyncDiffEvent
);
556 InterlockedExchange(&rev
->m_IsDiffFiles
, TRUE
);
557 if(rev
->m_IsDiffFiles
&& rev
->m_IsCommitParsed
)
558 InterlockedExchange(&rev
->m_IsFull
, TRUE
);
563 static UINT
AsyncThread(LPVOID data
)
565 return ((CGitLogListBase
*)data
)->AsyncDiffThread();
568 int AsyncDiffThread();
569 bool m_AsyncThreadExited
;
571 int SafeGetAction(GitRev
*rev
, int **ptr
= nullptr)
575 int *p
= &rev
->GetAction(this);
580 catch (const char* msg
)
582 MessageBox(_T("Could not get action of commit ") + rev
->m_CommitHash
.ToString() + _T(".\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
588 void SafeTerminateAsyncDiffThread()
590 if(m_DiffingThread
!=NULL
&& m_AsyncThreadExit
!= TRUE
)
592 m_AsyncThreadExit
= TRUE
;
593 ::SetEvent(m_AsyncDiffEvent
);
594 DWORD ret
= WAIT_TIMEOUT
;
595 // do not block here, but process messages and ask until the thread ends
596 while (ret
== WAIT_TIMEOUT
&& !m_AsyncThreadExited
)
599 if (::PeekMessage(&msg
, NULL
, 0,0, PM_NOREMOVE
))
600 AfxGetThread()->PumpMessage(); // process messages, so that GetTopIndex and so on in the thread work
601 ret
= ::WaitForSingleObject(m_DiffingThread
->m_hThread
, 100);
603 m_DiffingThread
= NULL
;
608 CComCriticalSection m_critSec
;
610 HICON m_hModifiedIcon
;
611 HICON m_hReplacedIcon
;
613 HICON m_hDeletedIcon
;
618 HFONT m_boldItalicsFont
;
620 CRegDWORD m_regMaxBugIDColWidth
;
623 CStoreSelection
* m_pStoreSelection
;
627 CString m_CurrentBranch
;
630 COLORREF m_LineColors
[Lanes::COLORS_NUM
];
633 DWORD m_DateFormat
; // DATE_SHORTDATE or DATE_LONGDATE
634 bool m_bRelativeTimes
; // Show relative times
636 CString m_SingleRemote
;
637 bool m_bTagsBranchesOnRightSide
;
638 bool m_bSymbolizeRefNames
;
639 bool m_bIncludeBoundaryCommits
;
641 ColumnManager m_ColumnManager
;
642 DWORD m_dwDefaultColumns
;