1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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
24 #include "ResizableColumnsListCtrl.h"
26 #include "ProjectProperties.h"
30 #include "LogDlgHelper.h"
31 #include "GitRevLoglist.h"
33 #include "GitLogCache.h"
35 #include "GitStatusListCtrl.h"
39 #define ICONITEMBORDER 5
41 #define GITLOG_START 0
42 #define GITLOG_START_ALL 1
43 #define GITLOG_END 100
45 #define LOGFILTER_ALL 0xFFFF
46 #define LOGFILTER_TOGGLE 0x8000
47 #define LOGFILTER_MESSAGES 0x0001
48 #define LOGFILTER_PATHS 0x0002
49 #define LOGFILTER_AUTHORS 0x0004
50 #define LOGFILTER_REVS 0x0008
51 #define LOGFILTER_REGEX 0x0010
52 #define LOGFILTER_BUGID 0x0020
53 #define LOGFILTER_SUBJECT 0x0040
54 #define LOGFILTER_REFNAME 0x0080
55 #define LOGFILTER_EMAILS 0x0100
56 #define LOGFILTER_NOTES 0x0200
57 #define LOGFILTER_ANNOTATEDTAG 0x0400
58 #define LOGFILTER_CASE 0x0800
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 std::vector
<GitRevLoglist
*>
147 CComCriticalSection
*m_critSec
;
149 CThreadSafePtrArray(CComCriticalSection
*section
){ m_critSec
= section
;}
150 GitRevLoglist
* SafeGetAt(size_t i
)
167 void SafeAdd(GitRevLoglist
* newElement
)
171 push_back(newElement
);
176 void SafeRemoveAt(size_t i
)
203 class CGitLogListBase
: public CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>
205 DECLARE_DYNAMIC(CGitLogListBase
)
209 virtual ~CGitLogListBase();
210 ProjectProperties m_ProjectProperties
;
212 void UpdateProjectProperties()
214 m_ProjectProperties
.ReadProps();
216 if ((!m_ProjectProperties
.sUrl
.IsEmpty())||(!m_ProjectProperties
.sCheckRe
.IsEmpty()))
217 m_bShowBugtraqColumn
= true;
219 m_bShowBugtraqColumn
= false;
222 void ResetWcRev(bool refresh
= false)
225 m_wcRev
.GetSubject().LoadString(IDS_LOG_WORKINGDIRCHANGES
);
226 m_wcRev
.m_Mark
= _T('-');
227 m_wcRev
.GetBody().LoadString(IDS_LOG_FETCHINGSTATUS
);
228 m_wcRev
.m_CallDiffAsync
= DiffAsync
;
229 InterlockedExchange(&m_wcRev
.m_IsDiffFiles
, FALSE
);
230 if (refresh
&& m_bShowWC
)
231 m_arShownList
[0] = &m_wcRev
;
234 volatile LONG m_bNoDispUpdates
;
235 BOOL m_IsIDReplaceAction
;
237 void hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
);
238 BOOL m_IsRebaseReplaceGraph
;
239 BOOL m_bNoHightlightHead
;
241 void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
);
243 BOOL m_bStrictStopped
;
244 BOOL m_bShowBugtraqColumn
;
247 bool m_bIsCherryPick
;
248 unsigned __int64 m_ContextMenuMask
;
252 GitRevLoglist m_wcRev
;
253 volatile LONG m_bThreadRunning
;
254 CLogCache m_LogCache
;
257 // don't forget to bump BLAME_COLUMN_VERSION in GitStatusListCtrlHelpers.cpp if you change columns
270 LOGLIST_COMMIT_EMAIL
,
274 LOGLIST_MESSAGE_MAX
=300,
275 LOGLIST_MESSAGE_MIN
=200,
277 GIT_LOG_GRAPH
= 1<< LOGLIST_GRAPH
,
278 GIT_LOG_REBASE
= 1<< LOGLIST_REBASE
,
279 GIT_LOG_ID
= 1<< LOGLIST_ID
,
280 GIT_LOG_HASH
= 1<< LOGLIST_HASH
,
281 GIT_LOG_ACTIONS
= 1<< LOGLIST_ACTION
,
282 GIT_LOG_MESSAGE
= 1<< LOGLIST_MESSAGE
,
283 GIT_LOG_AUTHOR
= 1<< LOGLIST_AUTHOR
,
284 GIT_LOG_DATE
= 1<< LOGLIST_DATE
,
285 GIT_LOG_EMAIL
= 1<< LOGLIST_EMAIL
,
286 GIT_LOG_COMMIT_NAME
= 1<< LOGLIST_COMMIT_NAME
,
287 GIT_LOG_COMMIT_EMAIL
= 1<< LOGLIST_COMMIT_EMAIL
,
288 GIT_LOG_COMMIT_DATE
= 1<< LOGLIST_COMMIT_DATE
,
289 GIT_LOGLIST_BUG
= 1<< LOGLIST_BUG
,
290 GIT_LOGLIST_SVNREV
= 1<< LOGLIST_SVNREV
,
295 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
296 ID_COMPARE
= 1, // compare revision with WC
298 ID_COMPARETWO
, // compare two revisions
302 ID_GNUDIFF1
, // compare with WC, unified
303 ID_GNUDIFF2
, // compare two revisions, unified
320 ID_COMPAREWITHPREVIOUS
,
336 ID_REFLOG_STASH_APPLY
,
338 ID_REBASE_TO_VERSION
,
346 ID_COPYCLIPBOARDMESSAGES
,
349 ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
,
367 FILTERSHOW_MERGEPOINTS
= 2,
368 FILTERSHOW_ANYCOMMIT
= 4,
369 FILTERSHOW_ALL
= FILTERSHOW_ANYCOMMIT
| FILTERSHOW_REFS
| FILTERSHOW_MERGEPOINTS
374 LOGACTIONS_REBASE_CURRENT
= 0x08000000,
375 LOGACTIONS_REBASE_PICK
= 0x04000000,
376 LOGACTIONS_REBASE_SQUASH
= 0x02000000,
377 LOGACTIONS_REBASE_EDIT
= 0x01000000,
378 LOGACTIONS_REBASE_DONE
= 0x00800000,
379 LOGACTIONS_REBASE_SKIP
= 0x00400000,
380 LOGACTIONS_REBASE_MASK
= 0x0FC00000,
381 LOGACTIONS_REBASE_MODE_MASK
= 0x07C00000,
383 inline unsigned __int64
GetContextMenuBit(int i
){ return ((unsigned __int64
)0x1)<<i
;}
384 static CString
GetRebaseActionName(int action
);
385 void InsertGitColumn();
386 void CopySelectionToClipBoard(int toCopy
= ID_COPY_ALL
);
387 void DiffSelectedRevWithPrevious();
388 bool IsSelectionContinuous();
390 int FillGitLog(CTGitPath
* path
, CString
* range
= nullptr, int infomask
= CGit::LOG_INFO_STAT
| CGit::LOG_INFO_FILESTATE
| CGit::LOG_INFO_SHOW_MERGEDFILE
);
391 int FillGitLog(std::set
<CGitHash
>& hashes
);
392 CString
MessageDisplayStr(GitRev
* pLogEntry
);
393 BOOL
IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
);
394 bool ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
);
395 void ShowGraphColumn(bool bShow
);
396 CString
GetTagInfo(GitRev
* pLogEntry
);
398 CFindDlg
*m_pFindDialog
;
399 static const UINT m_FindDialogMessage
;
402 static const UINT m_ScrollToMessage
;
403 static const UINT m_RebaseActionMessage
;
405 inline int ShownCountWithStopped() const { return (int)m_arShownList
.size() + (m_bStrictStopped
? 1 : 0); }
406 void FetchLogAsync(void* data
= nullptr);
407 CThreadSafePtrArray m_arShownList
;
408 void Refresh(BOOL IsCleanFilter
=TRUE
);
409 void RecalculateShownList(CThreadSafePtrArray
* pShownlist
);
412 DWORD m_SelectedFilters
;
413 FilterShow m_ShowFilter
;
414 bool m_bFilterWithRegex
;
415 bool m_bFilterCaseSensitively
;
416 CLogDataVector m_logEntries
;
419 bool ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
= false );
420 CString m_sFilterText
;
422 CFilterData m_Filter
;
426 CGitHash m_lastSelectedHash
;
427 SelectionHistory m_selectionHistory
;
428 CGitHash m_highlight
;
431 void GetTimeRange(CTime
&oldest
,CTime
&latest
);
432 virtual void GetParentHashes(GitRev
* pRev
, GIT_REV_LIST
& parentHash
);
433 virtual void ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
* menu
)=0;
436 m_RefLabelPosMap
.clear();
439 if (g_Git
.GetMapHashToFriendName(m_HashMap
))
440 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
442 m_CurrentBranch
=g_Git
.GetCurrentBranch();
444 if (g_Git
.GetHash(m_HeadHash
, _T("HEAD")))
446 MessageBox(g_Git
.GetGitLastErr(_T("Could not get HEAD hash. Quitting...")), _T("TortoiseGit"), MB_ICONERROR
);
450 m_wcRev
.m_ParentHash
.clear();
451 m_wcRev
.m_ParentHash
.push_back(m_HeadHash
);
454 FetchTrackingBranchList();
456 void StartAsyncDiffThread();
457 void StartLoadingThread();
458 void SafeTerminateThread()
460 if (m_LoadingThread
&& InterlockedExchange(&m_bExitThread
, TRUE
) == FALSE
)
462 DWORD ret
= WAIT_TIMEOUT
;
463 for (int i
= 0; i
< 200 && m_bThreadRunning
; ++i
)
464 ret
=::WaitForSingleObject(m_LoadingThread
->m_hThread
, 100);
465 if (ret
== WAIT_TIMEOUT
&& m_bThreadRunning
)
466 ::TerminateThread(m_LoadingThread
, 0);
467 m_LoadingThread
= nullptr;
471 bool IsInWorkingThread()
473 return (AfxGetThread() == m_LoadingThread
);
476 void SetRange(const CString
& range
)
481 CString
GetRange() const { return m_sRange
; }
483 bool HasFilterText() const { return !m_sFilterText
.IsEmpty() && m_sFilterText
!= _T("!"); }
487 volatile LONG m_bExitThread
;
488 CWinThread
* m_LoadingThread
;
489 MAP_HASH_NAME m_HashMap
;
490 std::map
<CString
, std::pair
<CString
, CString
>> m_TrackingMap
;
493 CString m_ColumnRegKey
;
499 CString simplifiedName
;
504 CGit::REF_TYPE refType
;
507 DECLARE_MESSAGE_MAP()
508 afx_msg
void OnDestroy();
509 virtual afx_msg
void OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
510 virtual afx_msg
void OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
511 afx_msg LRESULT
OnFindDialogMessage(WPARAM wParam
, LPARAM lParam
);
512 afx_msg LRESULT
OnScrollToMessage(WPARAM wParam
, LPARAM lParam
);
513 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
514 afx_msg
void OnContextMenu(CWnd
* pWnd
, CPoint point
);
515 afx_msg LRESULT
OnLoad(WPARAM wParam
, LPARAM lParam
);
516 void OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
);
517 afx_msg
void OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
);
518 void PreSubclassWindow();
519 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
520 static UINT
LogThreadEntry(LPVOID pVoid
);
522 bool IsOnStash(int index
);
523 bool IsStash(const GitRev
* pSelLogEntry
);
524 bool IsBisect(const GitRev
* pSelLogEntry
);
525 void FetchRemoteList();
526 void FetchTrackingBranchList();
527 void FetchLastLogInfo();
528 void FetchFullLogInfo(CString
&from
, CString
&to
);
530 virtual afx_msg BOOL
OnToolTipText(UINT id
, NMHDR
* pNMHDR
, LRESULT
* pResult
);
531 virtual INT_PTR
OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const;
532 CString
GetToolTipText(int nItem
, int nSubItem
);
534 /** Checks whether a referenfe label is under pt and returns the index/type
535 * pLogEntry IN: the entry of commit
536 * pt IN: the mouse position in client coordinate
537 * type IN: give the specific reference type, then check if it is the same reference type.
538 * OUT: give CGit::REF_TYPE::UNKNOWN for getting the real type it is.
539 * pShortname OUT: the short name of that reference label
540 * pIndex OUT: the index value of label of that entry
542 bool IsMouseOnRefLabel(const GitRevLoglist
* pLogEntry
, const POINT
& pt
, CGit::REF_TYPE
& type
, CString
* pShortname
= nullptr, size_t* pIndex
= nullptr);
543 bool IsMouseOnRefLabelFromPopupMenu(const GitRevLoglist
* pLogEntry
, const CPoint
& pt
, CGit::REF_TYPE
& type
, CString
* pShortname
= nullptr, size_t* pIndex
= nullptr);
545 void FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
);
546 void DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
);
547 void DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
);
548 void DrawGraph(HDC
,CRect
&rect
,INT_PTR index
);
550 void paintGraphLane(HDC hdc
,int laneHeight
, int type
, int x1
, int x2
,
551 const COLORREF
& col
,const COLORREF
& activeColor
, int top
) ;
552 void DrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
){ ::MoveToEx(hdc
, x1
, y1
, nullptr); ::LineTo(hdc
, x2
, y2
); }
554 * Save column widths to the registry
556 void SaveColumnWidths(); // save col widths to the registry
558 BOOL
IsEntryInDateRange(int i
);
562 std::vector
<GitRevLoglist
*> m_AsynDiffList
;
563 CComCriticalSection m_AsynDiffListLock
;
564 HANDLE m_AsyncDiffEvent
;
565 volatile LONG m_AsyncThreadExit
;
566 CWinThread
* m_DiffingThread
;
567 volatile LONG m_AsyncThreadRunning
;
569 static int DiffAsync(GitRevLoglist
* rev
, void* data
)
571 ULONGLONG offset
=((CGitLogListBase
*)data
)->m_LogCache
.GetOffset(rev
->m_CommitHash
);
572 if (!offset
|| ((CGitLogListBase
*)data
)->m_LogCache
.LoadOneItem(*rev
, offset
))
574 ((CGitLogListBase
*)data
)->m_AsynDiffListLock
.Lock();
575 ((CGitLogListBase
*)data
)->m_AsynDiffList
.push_back(rev
);
576 ((CGitLogListBase
*)data
)->m_AsynDiffListLock
.Unlock();
577 ::SetEvent(((CGitLogListBase
*)data
)->m_AsyncDiffEvent
);
581 InterlockedExchange(&rev
->m_IsDiffFiles
, TRUE
);
582 if (!rev
->m_IsCommitParsed
)
584 InterlockedExchange(&rev
->m_IsFull
, TRUE
);
585 // we might need to signal that the changed files are now available
586 if (((CGitLogListBase
*)data
)->GetSelectedCount() == 1)
588 POSITION pos
= ((CGitLogListBase
*)data
)->GetFirstSelectedItemPosition();
589 int nItem
= ((CGitLogListBase
*)data
)->GetNextSelectedItem(pos
);
592 GitRevLoglist
* data2
= (GitRevLoglist
*)((CGitLogListBase
*)data
)->m_arShownList
.SafeGetAt(nItem
);
593 if (data2
&& data2
->m_CommitHash
== rev
->m_CommitHash
)
594 ((CGitLogListBase
*)data
)->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
600 static UINT
AsyncThread(LPVOID data
)
602 return ((CGitLogListBase
*)data
)->AsyncDiffThread();
605 int AsyncDiffThread();
608 void SafeTerminateAsyncDiffThread()
610 if (m_DiffingThread
&& InterlockedExchange(&m_AsyncThreadExit
, TRUE
) == FALSE
)
612 ::SetEvent(m_AsyncDiffEvent
);
613 DWORD ret
= WAIT_TIMEOUT
;
614 // do not block here, but process messages and ask until the thread ends
615 while (ret
== WAIT_TIMEOUT
&& m_AsyncThreadRunning
)
618 if (::PeekMessage(&msg
, nullptr, 0,0, PM_NOREMOVE
))
619 AfxGetThread()->PumpMessage(); // process messages, so that GetTopIndex and so on in the thread work
620 ret
= ::WaitForSingleObject(m_DiffingThread
->m_hThread
, 100);
622 m_DiffingThread
= nullptr;
623 InterlockedExchange(&m_AsyncThreadExit
, FALSE
);
628 CComCriticalSection m_critSec
;
630 HICON m_hModifiedIcon
;
631 HICON m_hReplacedIcon
;
632 HICON m_hConflictedIcon
;
634 HICON m_hDeletedIcon
;
639 CFont m_boldItalicsFont
;
641 CRegDWORD m_regMaxBugIDColWidth
;
647 CString m_CurrentBranch
;
650 COLORREF m_LineColors
[Lanes::COLORS_NUM
];
653 DWORD m_DateFormat
; // DATE_SHORTDATE or DATE_LONGDATE
654 bool m_bRelativeTimes
; // Show relative times
656 CString m_SingleRemote
;
657 bool m_bTagsBranchesOnRightSide
;
658 bool m_bFullCommitMessageOnLogLine
;
659 bool m_bSymbolizeRefNames
;
660 bool m_bIncludeBoundaryCommits
;
662 DWORD m_dwDefaultColumns
;
663 TCHAR m_wszTip
[8192];
665 std::map
<CString
, CRect
> m_RefLabelPosMap
; // ref name vs. label position