1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // GitLogList.cpp : implementation file
24 #include "GitLogListBase.h"
26 #include "GitProgressDlg.h"
27 #include "ProgressDlg.h"
28 #include "MessageBox.h"
29 #include "LoglistUtils.h"
30 #include "StringUtils.h"
31 #include "UnicodeUtils.h"
33 #include "..\TortoiseShell\Resource.h"
35 template < typename Cont
, typename Pred
>
36 void for_each(Cont
& c
, Pred p
)
38 std::for_each(cbegin(c
), cend(c
), p
);
42 using const_iterator
= typename
T::const_iterator
;
44 template <typename Cont
, typename Pred
>
45 const_iterator
<Cont
> find_if(Cont
& c
, Pred p
)
47 return std::find_if(cbegin(c
), cend(c
), p
);
50 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
51 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_SCROLLTO");
52 const UINT
CGitLogListBase::m_ScrollToRef
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_SCROLLTOREF");
53 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(L
"TORTOISEGIT_LOG_REBASEACTION");
55 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>)
57 CGitLogListBase::CGitLogListBase() : CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>()
58 ,m_regMaxBugIDColWidth(L
"Software\\TortoiseGit\\MaxBugIDColWidth", 200)
60 ,m_bNoDispUpdates(FALSE
)
61 , m_bThreadRunning(FALSE
)
62 , m_bStrictStopped(false)
63 , m_SelectedFilters(LOGFILTER_ALL
)
64 , m_ShowFilter(FILTERSHOW_ALL
)
66 , m_logEntries(&m_LogCache
)
67 , m_pFindDialog(nullptr)
68 , m_dwDefaultColumns(0)
69 , m_arShownList(&m_critSec
)
71 , m_bNoHightlightHead(FALSE
)
72 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
73 , m_bFullCommitMessageOnLogLine(false)
75 , m_AsyncThreadRunning(FALSE
)
76 , m_AsyncThreadExit(FALSE
)
77 , m_bIsCherryPick(false)
79 , m_bShowBugtraqColumn(false)
80 , m_IsIDReplaceAction(FALSE
)
82 , m_LoadingThread(nullptr)
83 , m_bExitThread(FALSE
)
85 , m_IsRebaseReplaceGraph(FALSE
)
86 , m_ContextMenuMask(0xFFFFFFFFFFFFFFFF)
87 , m_bDragndropEnabled(false)
90 , m_nDropMarkerLast(-1)
91 , m_nDropMarkerLastHot(-1)
93 // use the default GUI font, create a copy of it and
94 // change the copy to BOLD (leave the rest of the font
96 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
98 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
99 lf
.lfWeight
= FW_BOLD
;
100 m_boldFont
.CreateFontIndirect(&lf
);
101 lf
.lfWeight
= FW_DONTCARE
;
103 m_FontItalics
.CreateFontIndirect(&lf
);
104 lf
.lfWeight
= FW_BOLD
;
105 m_boldItalicsFont
.CreateFontIndirect(&lf
);
107 this->m_critSec
.Init();
110 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
111 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
112 m_hConflictedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
113 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
114 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
115 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
117 m_bFilterWithRegex
= !!CRegDWORD(L
"Software\\TortoiseGit\\UseRegexFilter", FALSE
);
118 m_bFilterCaseSensitively
= !!CRegDWORD(L
"Software\\TortoiseGit\\FilterCaseSensitively", FALSE
);
120 m_Filter
.m_NumberOfLogsScale
= (DWORD
)CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale", CFilterData::SHOW_NO_LIMIT
);
121 if (m_Filter
.m_NumberOfLogsScale
== CFilterData::SHOW_LAST_SEL_DATE
)
124 key
.Format(L
"Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate", (LPCTSTR
)g_Git
.m_CurrentDir
);
125 key
.Replace(L
':', L
'_');
126 CString lastSelFromDate
= CRegString(key
);
127 if (lastSelFromDate
.GetLength() == 10)
129 CTime time
= CTime(_wtoi((LPCTSTR
)lastSelFromDate
.Mid(0, 4)), _wtoi((LPCTSTR
)lastSelFromDate
.Mid(5, 2)), _wtoi((LPCTSTR
)lastSelFromDate
.Mid(8, 2)), 0, 0, 0);
130 m_Filter
.m_From
= (DWORD
)time
.GetTime();
133 m_Filter
.m_NumberOfLogs
= (DWORD
)CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\NumberOfLogs", 1);
135 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
137 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
139 // get short/long datetime setting from registry
140 DWORD RegUseShortDateFormat
= CRegDWORD(L
"Software\\TortoiseGit\\LogDateFormat", TRUE
);
141 if ( RegUseShortDateFormat
)
143 m_DateFormat
= DATE_SHORTDATE
;
147 m_DateFormat
= DATE_LONGDATE
;
149 // get relative time display setting from registry
150 DWORD regRelativeTimes
= CRegDWORD(L
"Software\\TortoiseGit\\RelativeTimes", FALSE
);
151 m_bRelativeTimes
= (regRelativeTimes
!= 0);
153 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
154 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
155 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
156 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
157 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
158 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
159 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
161 m_ColumnRegKey
= L
"log";
163 m_bTagsBranchesOnRightSide
= !!CRegDWORD(L
"Software\\TortoiseGit\\DrawTagsBranchesOnRightSide", FALSE
);
164 m_bSymbolizeRefNames
= !!CRegDWORD(L
"Software\\TortoiseGit\\SymbolizeRefNames", FALSE
);
165 m_bIncludeBoundaryCommits
= !!CRegDWORD(L
"Software\\TortoiseGit\\LogIncludeBoundaryCommits", FALSE
);
166 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(L
"Software\\TortoiseGit\\FullCommitMessageOnLogLine", FALSE
);
168 m_LineWidth
= max(1, CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth", 2));
169 m_NodeSize
= max(1, CRegDWORD(L
"Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize", 10));
171 if (CRegDWORD(L
"Software\\TortoiseGit\\LogDialog\\UseMailmap", FALSE
) == TRUE
)
172 git_read_mailmap(&m_pMailmap
);
174 m_AsyncDiffEvent
= ::CreateEvent(nullptr, FALSE
, TRUE
, nullptr);
175 m_AsynDiffListLock
.Init();
176 StartAsyncDiffThread();
179 int CGitLogListBase::AsyncDiffThread()
181 while(!m_AsyncThreadExit
)
183 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
185 GitRevLoglist
* pRev
= nullptr;
186 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
188 m_AsynDiffListLock
.Lock();
189 pRev
= m_AsynDiffList
.back();
190 m_AsynDiffList
.pop_back();
191 m_AsynDiffListLock
.Unlock();
193 if( pRev
->m_CommitHash
.IsEmpty() )
195 if(pRev
->m_IsDiffFiles
)
198 CTGitPathList
& files
= pRev
->GetFiles(this);
200 pRev
->m_ParentHash
.clear();
201 pRev
->m_ParentHash
.push_back(m_HeadHash
);
202 g_Git
.RefreshGitIndex();
203 g_Git
.GetWorkingTreeChanges(files
);
204 int& action
= pRev
->GetAction(this);
206 for (int j
= 0; j
< files
.GetCount(); ++j
)
207 action
|= files
[j
].m_Action
;
210 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
212 MessageBox(L
"Failed to get UnRev file list\n" + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
213 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
217 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
218 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
220 CString body
= L
"\n";
221 body
.AppendFormat(IDS_FILESCHANGES
, files
.GetCount());
222 pRev
->GetBody() = body
;
223 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
224 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
227 if (!pRev
->CheckAndDiff())
228 { // fetch change file list
229 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
231 if (i
< (int)m_arShownList
.size())
233 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(i
);
234 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
236 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
242 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
244 POSITION pos
= GetFirstSelectedItemPosition();
245 int nItem
= GetNextSelectedItem(pos
);
249 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(nItem
);
251 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
252 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
258 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
264 m_ContextMenuMask
&= hideMask
;
266 m_ContextMenuMask
&= ~hideMask
;
269 CGitLogListBase::~CGitLogListBase()
271 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
272 this->m_arShownList
.SafeRemoveAll();
274 DestroyIcon(m_hModifiedIcon
);
275 DestroyIcon(m_hReplacedIcon
);
276 DestroyIcon(m_hConflictedIcon
);
277 DestroyIcon(m_hAddedIcon
);
278 DestroyIcon(m_hDeletedIcon
);
279 m_logEntries
.ClearAll();
281 git_free_mailmap(m_pMailmap
);
283 SafeTerminateThread();
284 SafeTerminateAsyncDiffThread();
287 CloseHandle(m_AsyncDiffEvent
);
291 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintCtrl
<CResizableColumnsListCtrl
<CListCtrl
>>)
292 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
293 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
294 ON_REGISTERED_MESSAGE(m_ScrollToRef
, OnScrollToRef
)
295 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
296 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
298 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
299 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
302 ON_MESSAGE(MSG_LOADED
,OnLoad
)
304 ON_WM_MEASUREITEM_REFLECT()
305 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
306 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
309 ON_NOTIFY_REFLECT(LVN_BEGINDRAG
, OnBeginDrag
)
312 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
314 //if (m_nRowHeight>0)
315 lpMeasureItemStruct
->itemHeight
= 50;
318 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
321 return __super::OnCreate(lpCreateStruct
);
324 void CGitLogListBase::SetStyle()
326 SetExtendedStyle(LVS_EX_INFOTIP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_SUBITEMIMAGES
| LVS_EX_FULLROWSELECT
);
329 void CGitLogListBase::PreSubclassWindow()
332 // load the icons for the action columns
333 // m_Theme.Open(m_hWnd, L"ListView");
334 SetWindowTheme(m_hWnd
, L
"Explorer", nullptr);
335 __super::PreSubclassWindow();
338 CString
CGitLogListBase::GetRebaseActionName(int action
)
340 if (action
& LOGACTIONS_REBASE_EDIT
)
341 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
342 if (action
& LOGACTIONS_REBASE_SQUASH
)
343 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
344 if (action
& LOGACTIONS_REBASE_PICK
)
345 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
346 if (action
& LOGACTIONS_REBASE_SKIP
)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
352 void CGitLogListBase::InsertGitColumn()
358 // only load properties if we have a repository
359 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
360 UpdateProjectProperties();
362 static UINT normal
[] =
374 IDS_LOG_COMMIT_EMAIL
,
386 2*ICONITEMBORDER
+16*5,
397 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
399 DWORD hideColumns
= 0;
400 if(this->m_IsRebaseReplaceGraph
)
402 hideColumns
|= GIT_LOG_GRAPH
;
403 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
406 hideColumns
|= GIT_LOG_REBASE
;
408 if(this->m_IsIDReplaceAction
)
410 hideColumns
|= GIT_LOG_ACTIONS
;
411 m_dwDefaultColumns
|= GIT_LOG_ID
;
412 m_dwDefaultColumns
|= GIT_LOG_HASH
;
415 hideColumns
|= GIT_LOG_ID
;
416 if(this->m_bShowBugtraqColumn
)
417 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
419 hideColumns
|= GIT_LOGLIST_BUG
;
420 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
421 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
423 hideColumns
|= GIT_LOGLIST_SVNREV
;
426 m_ColumnManager
.SetNames(normal
, _countof(normal
));
427 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+ L
"loglist", _countof(normal
), with
);
428 m_ColumnManager
.SetRightAlign(LOGLIST_ID
);
433 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
435 LVITEM rItem
= { 0 };
436 rItem
.mask
= LVIF_STATE
;
437 rItem
.iItem
= (int)Index
;
438 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
441 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(Index
);
442 HBRUSH brush
= nullptr;
444 if (!(rItem
.state
& LVIS_SELECTED
))
446 int action
= pLogEntry
->GetRebaseAction();
447 if (action
& LOGACTIONS_REBASE_SQUASH
)
448 brush
= ::CreateSolidBrush(RGB(156,156,156));
449 else if (action
& LOGACTIONS_REBASE_EDIT
)
450 brush
= ::CreateSolidBrush(RGB(200,200,128));
452 else if (!IsAppThemed())
454 if (rItem
.state
& LVIS_SELECTED
)
456 if (::GetFocus() == m_hWnd
)
457 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
459 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
464 ::FillRect(hdc
, &rect
, brush
);
465 ::DeleteObject(brush
);
469 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
471 POINT point
= { 4, 4 };
473 rt2
.DeflateRect(1, 1);
474 rt2
.OffsetRect(2, 2);
476 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
477 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
478 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
479 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
480 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
482 ::SelectObject(hdc
, brush
);
483 rt2
.OffsetRect(-2, -2);
484 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
485 ::SelectObject(hdc
, oldbrush
);
486 ::SelectObject(hdc
, oldpen
);
487 ::DeleteObject(nullPen
);
488 ::DeleteObject(darkBrush
);
491 void DrawUpstream(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
493 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
494 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
495 ::MoveToEx(hdc
, rect
.left
+ 2 + bold
, rect
.top
+ 2 - bold
, nullptr);
496 ::LineTo(hdc
, rect
.left
+ 2 + bold
, rect
.bottom
+ 1 - bold
);
497 ::MoveToEx(hdc
, rect
.left
+ 3, rect
.top
+ 1, nullptr);
498 ::LineTo(hdc
, rect
.left
, rect
.top
+ 4);
499 ::MoveToEx(hdc
, rect
.left
+ 2 + bold
, rect
.top
+ 1, nullptr);
500 ::LineTo(hdc
, rect
.right
+ 1 + bold
, rect
.top
+ 4);
501 ::MoveToEx(hdc
, rect
.left
+ 1, rect
.top
+ 2 + bold
, nullptr);
502 ::LineTo(hdc
, rect
.right
+ 1 + bold
, rect
.top
+ 2 + bold
);
503 ::SelectObject(hdc
, oldpen
);
507 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
509 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(index
);
511 LVITEM rItem
= { 0 };
512 rItem
.mask
= LVIF_STATE
;
513 rItem
.iItem
= (int)index
;
514 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
520 HTHEME hTheme
= nullptr;
522 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
525 if (m_bTagsBranchesOnRightSide
)
527 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
528 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
529 SelectObject(hdc
, oldFont
);
530 rt
.left
+= oneSpaceSize
.cx
* 2;
534 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
535 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
536 rt
.left
+= oneSpaceSize
.cx
;
539 CString msg
= MessageDisplayStr(data
);
540 int action
= data
->GetRebaseAction();
541 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
544 int txtState
= LISS_NORMAL
;
545 if (rItem
.state
& LVIS_SELECTED
)
546 txtState
= LISS_SELECTED
;
548 DTTOPTS opts
= { 0 };
549 opts
.dwSize
= sizeof(opts
);
550 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
551 opts
.dwFlags
= DTT_TEXTCOLOR
;
552 DrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
556 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
558 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
559 ::DrawText(hdc
,msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
560 ::SetTextColor(hdc
, clrOld
);
564 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
565 ::DrawText(hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
566 ::SetTextColor(hdc
, clrOld
);
570 if (m_bTagsBranchesOnRightSide
)
573 GetTextExtentPoint32(hdc
, msg
, msg
.GetLength(), &size
);
575 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
577 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
581 CloseThemeData(hTheme
);
586 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
)
588 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
590 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
592 COLORREF colRef
= refList
[i
].color
;
593 bool singleRemote
= refList
[i
].singleRemote
;
594 bool hasTracking
= refList
[i
].hasTracking
;
595 CGit::REF_TYPE refType
= refList
[i
].refType
;
597 //When row selected, ajust label color
600 if (rItem
.state
& LVIS_SELECTED
)
601 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
604 brush
= ::CreateSolidBrush(colRef
);
606 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
609 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
611 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
614 int textpos
= DT_CENTER
;
616 if (rt
.right
> rect
.right
)
618 rt
.right
= rect
.right
;
627 textRect
.OffsetRect(5, 0);
631 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
634 //Fill interior of ref label
635 ::FillRect(hdc
, &rt
, brush
);
643 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
644 rectEdge
.DeflateRect(1, 1);
645 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
648 if (refType
== CGit::REF_TYPE::ANNOTATED_TAG
)
651 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
652 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
653 ::FillRgn(hdc
, hrgn
, brush
);
654 ::DeleteObject(hrgn
);
655 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, nullptr);
657 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
658 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
660 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
661 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
663 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
664 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, nullptr);
665 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
667 SelectObject(hdc
, oldpen
);
670 //Draw text inside label
671 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
672 if (!customColor
&& IsAppThemed())
674 int txtState
= LISS_NORMAL
;
675 if (rItem
.state
& LVIS_SELECTED
)
676 txtState
= LISS_SELECTED
;
678 DTTOPTS opts
= { 0 };
679 opts
.dwSize
= sizeof(opts
);
680 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
681 opts
.dwFlags
= DTT_TEXTCOLOR
;
682 DrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
686 W_Dc
.SetBkMode(TRANSPARENT
);
687 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
689 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
690 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
691 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
692 ::SetTextColor(hdc
,clrOld
);
696 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
697 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
698 ::SetTextColor(hdc
, clrOld
);
704 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
705 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
707 newRect
.SetRect(rt
.left
+ 2, rt
.top
+ 4, rt
.left
+ 6, rt
.bottom
- 4);
708 DrawUpstream(hdc
, newRect
, color
, bold
);
711 if (!refList
[i
].fullName
.IsEmpty())
712 m_RefLabelPosMap
[refList
[i
].fullName
] = rt
;
714 rt
.left
= rt
.right
+ 1;
717 ::DeleteObject(brush
);
719 rt
.right
= rect
.right
;
722 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
723 // Returns ((256 - amount)*col1 + amount*col2) / 256;
724 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
725 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
726 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
729 Gdiplus::Color
GetGdiColor(COLORREF col
)
731 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
733 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
734 const COLORREF
& col
,const COLORREF
& activeColor
, int top
737 int h
= laneHeight
/ 2;
738 int m
= (x1
+ x2
) / 2;
739 int r
= (x2
- x1
) * m_NodeSize
/ 30;
742 #define P_CENTER m , h+top
743 #define P_0 x2, h+top
744 #define P_90 m , 0+top-1
745 #define P_180 x1, h+top
746 #define P_270 m , 2 * h+top +1
747 #define R_CENTER m - r, h - r+top, d, d
750 #define DELTA_UR_B 2*(x1 - m), 2*h +top
751 #define DELTA_UR_E 0*16, 90*16 +top // -,
753 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
754 #define DELTA_DR_E 270*16, 90*16 +top // -'
756 #define DELTA_UL_B 2*(x2 - m), 2*h +top
757 #define DELTA_UL_E 90*16, 90*16 +top // ,-
759 #define DELTA_DL_B 2*(x2 - m),2*-h +top
760 #define DELTA_DL_E 180*16, 90*16 // '-
762 #define CENTER_UR x1, 2*h, 225
763 #define CENTER_DR x1, 0 , 135
764 #define CENTER_UL x2, 2*h, 315
765 #define CENTER_DL x2, 0 , 45
768 Gdiplus::Graphics
graphics( hdc
);
770 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
779 Gdiplus::LinearGradientBrush
gradient(
780 Gdiplus::Point(x1
-2, h
+top
-2),
781 Gdiplus::Point(P_270
),
782 GetGdiColor(activeColor
),GetGdiColor(col
));
785 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
786 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
788 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
789 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
790 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
796 Gdiplus::LinearGradientBrush
gradient(
797 Gdiplus::Point(P_270
),
798 Gdiplus::Point(x2
+1, h
+top
-1),
799 GetGdiColor(col
),GetGdiColor(activeColor
));
802 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
803 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
805 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
806 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
807 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
815 Gdiplus::LinearGradientBrush
gradient(
816 Gdiplus::Point(x1
-2, h
+top
-2),
817 Gdiplus::Point(P_90
),
818 GetGdiColor(activeColor
),GetGdiColor(col
));
820 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
822 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
825 QConicalGradient
gradient(CENTER_DR
);
826 gradient
.setColorAt(0.375, activeCol
);
827 gradient
.setColorAt(0.625, col
);
828 myPen
.setBrush(gradient
);
830 p
->drawArc(P_CENTER
, DELTA_DR
);
839 //static QPen myPen(Qt::black, 2); // fast path here
841 pen
.CreatePen(PS_SOLID
,2,col
);
842 //myPen.setColor(col);
843 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
845 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
847 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
854 case Lanes::NOT_ACTIVE
:
855 case Lanes::MERGE_FORK
:
856 case Lanes::MERGE_FORK_R
:
857 case Lanes::MERGE_FORK_L
:
862 //DrawLine(hdc,P_90,P_270);
863 graphics
.DrawLine(&myPen
,P_90
,P_270
);
864 //p->drawLine(P_90, P_270);
868 //DrawLine(hdc,P_CENTER,P_270);
869 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
870 //p->drawLine(P_CENTER, P_270);
874 case Lanes::BOUNDARY
:
875 case Lanes::BOUNDARY_C
:
876 case Lanes::BOUNDARY_R
:
877 case Lanes::BOUNDARY_L
:
878 //DrawLine(hdc,P_90, P_CENTER);
879 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
880 //p->drawLine(P_90, P_CENTER);
886 myPen
.SetColor(GetGdiColor(activeColor
));
890 case Lanes::MERGE_FORK
:
895 case Lanes::CROSS_EMPTY
:
896 case Lanes::BOUNDARY_C
:
897 //DrawLine(hdc,P_180,P_0);
898 graphics
.DrawLine(&myPen
,P_180
,P_0
);
899 //p->drawLine(P_180, P_0);
901 case Lanes::MERGE_FORK_R
:
902 case Lanes::BOUNDARY_R
:
903 //DrawLine(hdc,P_180,P_CENTER);
904 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
905 //p->drawLine(P_180, P_CENTER);
907 case Lanes::MERGE_FORK_L
:
910 case Lanes::BOUNDARY_L
:
911 //DrawLine(hdc,P_CENTER,P_0);
912 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
913 //p->drawLine(P_CENTER, P_0);
919 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
922 brush
.CreateSolidBrush(col
);
923 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
925 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
926 // center symbol, e.g. rect or ellipse
932 //p->setPen(Qt::NoPen);
934 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
935 graphics
.FillEllipse(&myBrush
, R_CENTER
);
936 //p->drawEllipse(R_CENTER);
938 case Lanes::MERGE_FORK
:
939 case Lanes::MERGE_FORK_R
:
940 case Lanes::MERGE_FORK_L
:
941 //p->setPen(Qt::NoPen);
943 //p->drawRect(R_CENTER);
944 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
945 graphics
.FillRectangle(&myBrush
, R_CENTER
);
947 case Lanes::UNAPPLIED
:
949 //p->setPen(Qt::NoPen);
950 //p->setBrush(Qt::red);
951 //p->drawRect(m - r, h - 1, d, 2);
952 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
953 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
957 //p->setPen(Qt::NoPen);
958 //p->setBrush(DARK_GREEN);
959 //p->drawRect(m - r, h - 1, d, 2);
960 //p->drawRect(m - 1, h - r, 2, d);
961 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
962 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
963 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
965 case Lanes::BOUNDARY
:
967 //p->drawEllipse(R_CENTER);
968 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
969 graphics
.DrawEllipse(&myPen
, R_CENTER
);
971 case Lanes::BOUNDARY_C
:
972 case Lanes::BOUNDARY_R
:
973 case Lanes::BOUNDARY_L
:
975 //p->drawRect(R_CENTER);
976 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
977 graphics
.FillRectangle(&myBrush
,R_CENTER
);
983 ::SelectObject(hdc
,oldpen
);
984 ::SelectObject(hdc
,oldbrush
);
993 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
997 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(index
);
998 if(data
->m_CommitHash
.IsEmpty())
1002 LVITEM rItem
= { 0 };
1003 rItem
.mask
= LVIF_STATE
;
1004 rItem
.iItem
= (int)index
;
1005 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1008 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1010 if (data
->m_Lanes
.empty())
1011 m_logEntries
.setLane(data
->m_CommitHash
);
1013 std::vector
<int>& lanes
=data
->m_Lanes
;
1014 size_t laneNum
= lanes
.size();
1015 UINT activeLane
= 0;
1016 for (UINT i
= 0; i
< laneNum
; ++i
)
1017 if (Lanes::isMerge(lanes
[i
])) {
1023 int maxWidth
= rect
.Width();
1024 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1026 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1027 //if (opt.state & QStyle::State_Selected)
1028 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1030 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1036 if (ln
== Lanes::EMPTY
)
1039 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1040 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1044 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1049 if (ln
== Lanes::EMPTY
)
1052 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1053 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1055 if (ln
== Lanes::CROSS
)
1057 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1058 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1061 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1066 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1068 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1069 // Take the default processing unless we set this to something else below.
1070 *pResult
= CDRF_DODEFAULT
;
1072 if (m_bNoDispUpdates
)
1075 switch (pLVCD
->nmcd
.dwDrawStage
)
1079 *pResult
= CDRF_NOTIFYITEMDRAW
;
1083 case CDDS_ITEMPREPAINT
:
1085 // This is the prepaint stage for an item. Here's where we set the
1086 // item's text color.
1088 // Tell Windows to send draw notifications for each subitem.
1089 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1091 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1093 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
)
1095 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1098 HGDIOBJ hGdiObj
= nullptr;
1099 int action
= data
->GetRebaseAction();
1100 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1101 crText
= RGB(128,128,128);
1103 if (action
& LOGACTIONS_REBASE_SQUASH
)
1104 pLVCD
->clrTextBk
= RGB(156,156,156);
1105 else if (action
& LOGACTIONS_REBASE_EDIT
)
1106 pLVCD
->clrTextBk
= RGB(200,200,128);
1108 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1110 if (action
& LOGACTIONS_REBASE_CURRENT
)
1111 hGdiObj
= m_boldFont
.GetSafeHandle();
1113 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1114 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1115 if (isHeadHash
&& isHighlight
)
1116 hGdiObj
= m_boldItalicsFont
.GetSafeHandle();
1117 else if (isHeadHash
)
1118 hGdiObj
= m_boldFont
.GetSafeHandle();
1119 else if (isHighlight
)
1120 hGdiObj
= m_FontItalics
.GetSafeHandle();
1124 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1125 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1128 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1129 // crText = GetSysColor(COLOR_GRAYTEXT);
1131 if (data
->m_CommitHash
.IsEmpty())
1133 //crText = GetSysColor(RGB(200,200,0));
1134 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1135 // We changed the font, so we're returning CDRF_NEWFONT. This
1136 // tells the control to recalculate the extent of the text.
1137 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1141 if (m_arShownList
.size() == pLVCD
->nmcd
.dwItemSpec
)
1143 if (m_bStrictStopped
)
1144 crText
= GetSysColor(COLOR_GRAYTEXT
);
1146 // Store the color back in the NMLVCUSTOMDRAW struct.
1147 pLVCD
->clrText
= crText
;
1151 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1153 if (m_bStrictStopped
&& m_arShownList
.size() == pLVCD
->nmcd
.dwItemSpec
)
1155 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1158 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1160 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
&& !this->m_IsRebaseReplaceGraph
)
1163 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1165 //TRACE(L"A Graphic left %d right %d\r\n", rect.left, rect.right);
1166 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1168 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1169 if( !data
->m_CommitHash
.IsEmpty())
1170 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1172 *pResult
= CDRF_SKIPDEFAULT
;
1177 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1179 // If the top index of list is changed, the position map of reference label is outdated.
1180 if (m_OldTopIndex
!= GetTopIndex())
1182 m_OldTopIndex
= GetTopIndex();
1183 m_RefLabelPosMap
.clear();
1186 if (m_arShownList
.size() > pLVCD
->nmcd
.dwItemSpec
)
1188 GitRevLoglist
* data
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1190 if ((!m_HashMap
[data
->m_CommitHash
].empty() || (!m_superProjectHash
.IsEmpty() && data
->m_CommitHash
== m_superProjectHash
)) && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1193 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1195 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1196 // not in FillBackGround method, because this only affected the message subitem
1197 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1200 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1201 int state
= GetItemState(index
, LVIS_SELECTED
);
1202 int txtState
= LISS_NORMAL
;
1203 if (IsAppThemed() && GetHotItem() == (int)index
)
1205 if (state
& LVIS_SELECTED
)
1206 txtState
= LISS_HOTSELECTED
;
1208 txtState
= LISS_HOT
;
1210 else if (state
& LVIS_SELECTED
)
1212 if (::GetFocus() == m_hWnd
)
1213 txtState
= LISS_SELECTED
;
1215 txtState
= LISS_SELECTEDNOTFOCUS
;
1218 HTHEME hTheme
= nullptr;
1220 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1222 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1223 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1226 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1227 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1228 ::DeleteObject(brush
);
1230 if (hTheme
&& txtState
!= LISS_NORMAL
)
1233 // get rect of whole line
1234 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1237 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1238 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1240 CloseThemeData(hTheme
);
1242 // END: extended redraw
1244 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1246 std::vector
<REFLABEL
> refsToShow
;
1247 STRING_VECTOR remoteTrackingList
;
1248 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1249 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1251 CString str
= refList
[i
];
1254 refLabel
.color
= RGB(255, 255, 255);
1255 refLabel
.singleRemote
= false;
1256 refLabel
.hasTracking
= false;
1257 refLabel
.sameName
= false;
1258 refLabel
.name
= CGit::GetShortName(str
, &refLabel
.refType
);
1259 refLabel
.fullName
= str
;
1261 switch (refLabel
.refType
)
1263 case CGit::REF_TYPE::LOCAL_BRANCH
:
1265 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1267 if (refLabel
.name
== m_CurrentBranch
)
1268 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1270 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1272 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1273 CString pullRemote
= trackingEntry
.first
;
1274 CString pullBranch
= trackingEntry
.second
;
1275 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1277 CString defaultUpstream
;
1278 defaultUpstream
.Format(L
"refs/remotes/%s/%s", (LPCTSTR
)pullRemote
, (LPCTSTR
)pullBranch
);
1279 refLabel
.hasTracking
= true;
1280 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1283 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1285 if (refList
[j
] == defaultUpstream
)
1294 bool sameName
= pullBranch
== refLabel
.name
;
1295 refsToShow
.push_back(refLabel
);
1296 CGit::GetShortName(defaultUpstream
, refLabel
.name
, L
"refs/remotes/");
1297 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1298 if (m_bSymbolizeRefNames
)
1300 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1302 refLabel
.simplifiedName
= L
'/';
1304 refLabel
.simplifiedName
+= L
'≡';
1306 refLabel
.simplifiedName
+= pullBranch
;
1307 refLabel
.singleRemote
= true;
1310 refLabel
.simplifiedName
= pullRemote
+ L
"/≡";
1311 refLabel
.sameName
= sameName
;
1313 refLabel
.fullName
= defaultUpstream
;
1314 refsToShow
.push_back(refLabel
);
1315 remoteTrackingList
.push_back(defaultUpstream
);
1322 case CGit::REF_TYPE::REMOTE_BRANCH
:
1324 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1327 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1329 if (remoteTrackingList
[j
] == str
)
1338 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1339 if (m_bSymbolizeRefNames
)
1341 if (!m_SingleRemote
.IsEmpty() && CStringUtils::StartsWith(refLabel
.name
, m_SingleRemote
+ L
"/"))
1343 refLabel
.simplifiedName
= L
'/' + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1344 refLabel
.singleRemote
= true;
1349 case CGit::REF_TYPE::ANNOTATED_TAG
:
1350 case CGit::REF_TYPE::TAG
:
1351 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1353 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1355 case CGit::REF_TYPE::STASH
:
1356 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1358 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1360 case CGit::REF_TYPE::BISECT_GOOD
:
1361 case CGit::REF_TYPE::BISECT_BAD
:
1362 case CGit::REF_TYPE::BISECT_SKIP
:
1363 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1365 refLabel
.color
= (refLabel
.refType
== CGit::REF_TYPE::BISECT_GOOD
) ? m_Colors
.GetColor(CColors::BisectGood
) : ((refLabel
.refType
== CGit::REF_TYPE::BISECT_SKIP
) ? m_Colors
.GetColor(CColors::BisectSkip
) : m_Colors
.GetColor(CColors::BisectBad
));
1370 refsToShow
.push_back(refLabel
);
1372 if (!m_superProjectHash
.IsEmpty() && data
->m_CommitHash
== m_superProjectHash
)
1375 refLabel
.color
= RGB(246, 153, 253);
1376 refLabel
.singleRemote
= false;
1377 refLabel
.hasTracking
= false;
1378 refLabel
.sameName
= false;
1379 refLabel
.name
= L
"super-project-pointer";
1380 refLabel
.fullName
= "";
1381 refsToShow
.push_back(refLabel
);
1384 if (refsToShow
.empty())
1386 *pResult
= CDRF_DODEFAULT
;
1390 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1392 *pResult
= CDRF_SKIPDEFAULT
;
1400 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1402 if(this->m_IsIDReplaceAction
)
1404 *pResult
= CDRF_DODEFAULT
;
1407 *pResult
= CDRF_DODEFAULT
;
1409 if (m_arShownList
.size() <= pLVCD
->nmcd
.dwItemSpec
)
1413 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1414 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1416 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1418 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1419 //TRACE(L"Action left %d right %d\r\n", rect.left, rect.right);
1420 // Get the selected state of the
1421 // item being drawn.
1423 // Fill the background if necessary
1424 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1426 // Draw the icon(s) into the compatible DC
1427 int action
= pLogEntry
->GetAction(this);
1428 if (!pLogEntry
->m_IsDiffFiles
)
1430 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1431 *pResult
= CDRF_SKIPDEFAULT
;
1435 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1436 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1439 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1440 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
* iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1443 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1444 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
* iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1447 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1448 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
* iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1451 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1452 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
* iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, nullptr, DI_NORMAL
);
1455 *pResult
= CDRF_SKIPDEFAULT
;
1461 *pResult
= CDRF_DODEFAULT
;
1464 CString
FindSVNRev(const CString
& msg
)
1468 const std::tr1::wsregex_iterator end
;
1469 std::wstring s
= msg
;
1470 std::tr1::wregex
regex1(L
"^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$");
1471 for (std::tr1::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex1
); it
!= end
; ++it
)
1473 const std::tr1::wsmatch match
= *it
;
1474 if (match
.size() == 4)
1476 ATLTRACE(L
"matched rev: %s\n", std::wstring(match
[2]).c_str());
1477 return std::wstring(match
[2]).c_str();
1480 std::tr1::wregex
regex2(L
"^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$");
1481 for (std::tr1::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex2
); it
!= end
; ++it
)
1483 const std::tr1::wsmatch match
= *it
;
1484 if (match
.size() == 3)
1486 ATLTRACE(L
"matched rev: %s\n", std::wstring(match
[1]).c_str());
1487 return std::wstring(match
[1]).c_str();
1491 catch (std::exception
&) {}
1496 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1498 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1499 return pLogEntry
->GetSubject();
1501 CString
txt(pLogEntry
->GetSubject());
1503 txt
+= pLogEntry
->GetBody();
1506 txt
.Replace(L
'\n', L
' ');
1507 txt
.Replace(L
'\r', L
' ');
1512 // CGitLogListBase message handlers
1514 static const char* GetMailmapMapping(GIT_MAILMAP mailmap
, const CString
& email
, const CString
& name
, bool returnEmail
)
1516 struct payload_struct
{ const CString
* name
; const char* authorName
; };
1517 payload_struct payload
= { &name
, nullptr };
1518 const char* author1
= nullptr;
1519 const char* email1
= nullptr;
1520 git_lookup_mailmap(mailmap
, &email1
, &author1
, CUnicodeUtils::GetUTF8(email
), &payload
,
1521 [](void* payload
) -> const char* { return reinterpret_cast<payload_struct
*>(payload
)->authorName
= _strdup(CUnicodeUtils::GetUTF8(*reinterpret_cast<payload_struct
*>(payload
)->name
)); });
1522 free((void *)payload
.authorName
);
1528 static void CopyMailmapProcessedData(GIT_MAILMAP mailmap
, LV_ITEM
* pItem
, const CString
& email
, const CString
& name
, bool returnEmail
)
1532 const char* translated
= GetMailmapMapping(mailmap
, email
, name
, returnEmail
);
1535 lstrcpyn(pItem
->pszText
, CUnicodeUtils::GetUnicode(translated
), pItem
->cchTextMax
- 1);
1540 lstrcpyn(pItem
->pszText
, (LPCTSTR
)email
, pItem
->cchTextMax
- 1);
1542 lstrcpyn(pItem
->pszText
, (LPCTSTR
)name
, pItem
->cchTextMax
- 1);
1545 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1547 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1549 // Create a pointer to the item
1550 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1552 // Do the list need text information?
1553 if (!(pItem
->mask
& LVIF_TEXT
))
1556 // By default, clear text buffer.
1557 lstrcpyn(pItem
->pszText
, L
"", pItem
->cchTextMax
- 1);
1559 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1562 if (m_bNoDispUpdates
|| bOutOfRange
)
1565 // Which item number?
1566 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(pItem
->iItem
);
1570 temp
.Format(L
"%d", pItem
->iItem
+ 1);
1572 temp
.Format(L
"%d", m_arShownList
.size() - pItem
->iItem
);
1578 switch (pItem
->iSubItem
)
1580 case LOGLIST_GRAPH
: //Graphic
1582 case LOGLIST_REBASE
:
1583 if (m_IsRebaseReplaceGraph
)
1584 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1586 case LOGLIST_ACTION
: //action -- no text in the column
1589 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1592 if (this->m_IsIDReplaceAction
)
1593 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1595 case LOGLIST_MESSAGE
: //Message
1596 lstrcpyn(pItem
->pszText
, (LPCTSTR
)MessageDisplayStr(pLogEntry
), pItem
->cchTextMax
- 1);
1598 case LOGLIST_AUTHOR
: //Author
1599 CopyMailmapProcessedData(m_pMailmap
, pItem
, pLogEntry
->GetAuthorEmail(), pLogEntry
->GetAuthorName(), false);
1601 case LOGLIST_DATE
: //Date
1602 if (!pLogEntry
->m_CommitHash
.IsEmpty())
1603 lstrcpyn(pItem
->pszText
,
1604 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1605 pItem
->cchTextMax
- 1);
1609 CopyMailmapProcessedData(m_pMailmap
, pItem
, pLogEntry
->GetAuthorEmail(), pLogEntry
->GetAuthorName(), true);
1612 case LOGLIST_COMMIT_NAME
: //Commit
1613 CopyMailmapProcessedData(m_pMailmap
, pItem
, pLogEntry
->GetCommitterEmail(), pLogEntry
->GetCommitterName(), false);
1616 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1617 CopyMailmapProcessedData(m_pMailmap
, pItem
, pLogEntry
->GetCommitterEmail(), pLogEntry
->GetCommitterName(), true);
1620 case LOGLIST_COMMIT_DATE
: //Commit Date
1621 if (!pLogEntry
->m_CommitHash
.IsEmpty())
1622 lstrcpyn(pItem
->pszText
,
1623 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1624 pItem
->cchTextMax
- 1);
1626 case LOGLIST_BUG
: //Bug ID
1627 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubjectBody()), pItem
->cchTextMax
- 1);
1629 case LOGLIST_SVNREV
: //SVN revision
1630 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubjectBody()), pItem
->cchTextMax
- 1);
1638 bool CGitLogListBase::IsOnStash(int index
)
1640 GitRevLoglist
* rev
= m_arShownList
.SafeGetAt(index
);
1645 GitRevLoglist
* preRev
= m_arShownList
.SafeGetAt(index
- 1);
1646 if (IsStash(preRev
))
1647 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1652 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1654 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1656 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == L
"refs/stash")
1662 bool CGitLogListBase::IsBisect(const GitRev
* pSelLogEntry
)
1664 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1666 if (CStringUtils::StartsWith(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
], L
"refs/bisect/"))
1672 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1674 if (pRev
->m_ParentHash
.empty())
1676 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1677 MessageBox(pRev
->GetLastErr(), L
"TortoiseGit", MB_ICONERROR
);
1679 parentHash
= pRev
->m_ParentHash
;
1682 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1684 __super::OnContextMenu(pWnd
, point
);
1689 int selIndex
= GetSelectionMark();
1691 return; // nothing selected, nothing to do with a context menu
1693 // if the user selected the info text telling about not all revisions shown due to
1694 // the "stop on copy/rename" option, we also don't show the context menu
1695 if (m_bStrictStopped
&& selIndex
== (int)m_arShownList
.size())
1698 // if the context menu is invoked through the keyboard, we have to use
1699 // a calculated position on where to anchor the menu on
1700 if ((point
.x
== -1) && (point
.y
== -1))
1703 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1704 ClientToScreen(&rect
);
1705 point
= rect
.CenterPoint();
1707 m_nSearchIndex
= selIndex
;
1708 m_bCancelled
= FALSE
;
1710 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1712 POSITION pos
= GetFirstSelectedItemPosition();
1713 int FirstSelect
= GetNextSelectedItem(pos
);
1714 if (FirstSelect
< 0)
1717 GitRevLoglist
* pSelLogEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
1718 if (pSelLogEntry
== nullptr)
1721 int LastSelect
= -1;
1722 UINT selectedCount
= 1;
1725 LastSelect
= GetNextSelectedItem(pos
);
1729 ASSERT(GetSelectedCount() == selectedCount
);
1732 GitRev revSelected
= pSelLogEntry
->Rev
;
1733 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1734 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1736 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1738 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1739 if (changedpath
->lCopyFromRev
)
1740 revPrevious
= changedpath
->lCopyFromRev
;
1743 GitRev revSelected2
;
1746 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1747 revSelected2
= pLogEntry
->Rev
;
1749 bool bAllFromTheSameAuthor
= true;
1750 CString firstAuthor
;
1751 CLogDataVector selEntries
;
1752 GitRev revLowest
, revHighest
;
1753 GitRevRangeArray revisionRanges
;
1755 POSITION pos
= GetFirstSelectedItemPosition();
1756 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1757 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1758 selEntries
.push_back(pLogEntry
);
1759 firstAuthor
= pLogEntry
->sAuthor
;
1760 revLowest
= pLogEntry
->Rev
;
1761 revHighest
= pLogEntry
->Rev
;
1764 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1765 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1766 selEntries
.push_back(pLogEntry
);
1767 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1768 bAllFromTheSameAuthor
= false;
1769 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1770 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1776 //entry is selected, now show the popup menu
1778 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1780 if (popup
.CreatePopupMenu())
1782 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1783 CString currentBranch
= L
"refs/heads/" + g_Git
.GetCurrentBranch();
1784 CTGitPath
workingTree(g_Git
.m_CurrentDir
);
1785 bool isMergeActive
= workingTree
.IsMergeActive();
1786 bool isBisectActive
= workingTree
.IsBisectActive();
1787 bool isStash
= IsOnStash(FirstSelect
);
1788 GIT_REV_LIST parentHash
;
1789 GetParentHashes(pSelLogEntry
, parentHash
);
1791 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1792 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1794 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1 && (m_bIsCherryPick
|| pSelLogEntry
->ParentsCount() == 1))
1795 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1797 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1798 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1800 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1801 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1803 if (m_ContextMenuMask
& (GetContextMenuBit(ID_REBASE_SKIP
) | GetContextMenuBit(ID_REBASE_EDIT
) | GetContextMenuBit(ID_REBASE_SQUASH
) | GetContextMenuBit(ID_REBASE_PICK
)) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1804 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1806 if (selectedCount
== 1)
1809 bool requiresSeparator
= false;
1810 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1812 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1814 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1815 requiresSeparator
= true;
1820 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1822 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1823 requiresSeparator
= true;
1825 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1827 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1828 requiresSeparator
= true;
1832 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1834 if (parentHash
.size() == 1)
1836 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1837 requiresSeparator
= true;
1839 else if (parentHash
.size() > 1)
1841 blamemenu
.CreatePopupMenu();
1842 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1843 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1846 str
.Format(IDS_PARENT
, i
+ 1);
1847 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1849 requiresSeparator
= true;
1853 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1855 if (parentHash
.size() == 1)
1857 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1858 requiresSeparator
= true;
1860 else if (parentHash
.size() > 1)
1862 gnudiffmenu
.CreatePopupMenu();
1863 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1865 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1866 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1867 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1869 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1872 str
.Format(IDS_PARENT
, i
+ 1);
1873 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1875 requiresSeparator
= true;
1879 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1881 if (parentHash
.size() == 1)
1883 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1884 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
1885 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1886 requiresSeparator
= true;
1888 else if (parentHash
.size() > 1)
1890 diffmenu
.CreatePopupMenu();
1891 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1892 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1895 str
.Format(IDS_PARENT
, i
+ 1);
1896 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1897 if (i
== 0 && CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
1899 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1900 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1903 requiresSeparator
= true;
1907 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1909 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1910 requiresSeparator
= true;
1913 if (requiresSeparator
)
1915 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1916 requiresSeparator
= false;
1919 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1921 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1923 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1924 requiresSeparator
= true;
1928 if ((pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
) && workingTree
.HasStashDir())
1930 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1932 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1933 requiresSeparator
= true;
1936 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1938 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1939 requiresSeparator
= true;
1943 if (requiresSeparator
)
1945 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1946 requiresSeparator
= false;
1951 GitRevLoglist
* pFirstEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
1952 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTGOOD
) && !IsBisect(pFirstEntry
))
1954 popup
.AppendMenuIcon(ID_BISECTGOOD
, IDS_MENUBISECTGOOD
, IDI_THUMB_UP
);
1955 requiresSeparator
= true;
1958 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTBAD
) && !IsBisect(pFirstEntry
))
1960 popup
.AppendMenuIcon(ID_BISECTBAD
, IDS_MENUBISECTBAD
, IDI_THUMB_DOWN
);
1961 requiresSeparator
= true;
1963 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTSKIP
) && !IsBisect(pFirstEntry
))
1965 popup
.AppendMenuIcon(ID_BISECTSKIP
, IDS_MENUBISECTSKIP
, IDI_BISECT
);
1966 requiresSeparator
= true;
1970 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && isBisectActive
)
1972 if (m_ContextMenuMask
&GetContextMenuBit(ID_BISECTRESET
))
1974 popup
.AppendMenuIcon(ID_BISECTRESET
, IDS_MENUBISECTRESET
, IDI_BISECT_RESET
);
1975 requiresSeparator
= true;
1979 if (requiresSeparator
)
1981 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1982 requiresSeparator
= false;
1985 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1987 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1988 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1990 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1991 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1993 if ((m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
)) && workingTree
.HasSubmodules())
1994 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1996 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1998 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1999 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
2001 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2005 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2007 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2009 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2011 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2013 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2014 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2016 // popup.AppendMenu(MF_SEPARATOR, NULL);
2021 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2023 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2025 if ((m_ContextMenuMask
& GetContextMenuBit(ID_LOG
)) && selectedCount
== 1)
2026 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2028 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2029 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2031 str
.Format(IDS_LOG_POPUP_MERGEREV
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2033 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2035 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2037 size_t index
= (size_t)-1;
2038 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2039 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, nullptr, &index
))
2040 popup
.SetMenuItemData(ID_MERGEREV
, (ULONG_PTR
)&m_HashMap
[pSelLogEntry
->m_CommitHash
][index
]);
2043 str
.Format(IDS_RESET_TO_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2045 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2046 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2049 // Add Switch Branch express Menu
2050 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2051 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2054 std::vector
<const CString
*> branchs
;
2055 auto addCheck
= [&](const CString
& ref
)
2057 if (!CStringUtils::StartsWith(ref
, L
"refs/heads/") || ref
== currentBranch
)
2059 branchs
.push_back(&ref
);
2061 size_t index
= (size_t)-1;
2062 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2063 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, nullptr, &index
))
2064 addCheck(m_HashMap
[pSelLogEntry
->m_CommitHash
][index
]);
2066 for_each(m_HashMap
[pSelLogEntry
->m_CommitHash
], addCheck
);
2069 str2
.LoadString(IDS_SWITCH_BRANCH
);
2071 if(branchs
.size() == 1)
2074 str2
+= L
'"' + branchs
[0]->Mid(11) + L
'"'; // 11 = len("refs/heads/")
2075 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2077 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2080 else if(branchs
.size() > 1)
2082 subbranchmenu
.CreatePopupMenu();
2083 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2085 if (*branchs
[i
] != currentBranch
)
2087 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2088 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2092 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2096 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2098 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2099 size_t index
= (size_t)-1;
2100 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2101 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, nullptr, &index
))
2102 popup
.SetMenuItemData(ID_SWITCHTOREV
, (ULONG_PTR
)&m_HashMap
[pSelLogEntry
->m_CommitHash
][index
]);
2105 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2107 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2109 size_t index
= (size_t)-1;
2110 CGit::REF_TYPE type
= CGit::REF_TYPE::REMOTE_BRANCH
;
2111 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, nullptr, &index
))
2112 popup
.SetMenuItemData(ID_CREATE_BRANCH
, (ULONG_PTR
)&m_HashMap
[pSelLogEntry
->m_CommitHash
][index
]);
2115 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2116 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2118 str
.Format(IDS_REBASE_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2120 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2121 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2122 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2124 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2125 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2127 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2129 if (parentHash
.size() == 1)
2130 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2131 else if (parentHash
.size() > 1)
2133 revertmenu
.CreatePopupMenu();
2134 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2136 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2139 str2
.Format(IDS_PARENT
, i
+ 1);
2140 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2145 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2146 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2148 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2152 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2154 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2155 if (selectedCount
== 1 && CStringUtils::StartsWith(pSelLogEntry
->m_Ref
, L
"refs/stash"))
2156 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2157 if (selectedCount
<= 2)
2158 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2161 if (selectedCount
>= 2)
2163 bool bAddSeparator
= false;
2164 if ((selectedCount
== 2) || IsSelectionContinuous())
2166 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2167 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2170 if (selectedCount
== 2)
2172 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2173 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2175 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2177 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2178 GitRevLoglist
* pLastEntry
= m_arShownList
.SafeGetAt(LastSelect
);
2179 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2181 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ L
".." + firstSelHash
));
2182 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2183 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ L
"..." + firstSelHash
));
2184 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2187 bAddSeparator
= true;
2190 if ((m_ContextMenuMask
& GetContextMenuBit(ID_COMPARETWOCOMMITCHANGES
)) && selectedCount
== 2 && !IsSelectionContinuous())
2192 bAddSeparator
= true;
2193 popup
.AppendMenuIcon(ID_COMPARETWOCOMMITCHANGES
, IDS_LOG_POPUP_COMPARECHANGESET
, IDI_DIFF
);
2197 bAddSeparator
= true;
2201 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2202 bAddSeparator
= false;
2205 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2206 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2209 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2212 if (selectedCount
> 1 && isBisectActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSKIP
)) && !IsBisect(pSelLogEntry
))
2214 popup
.AppendMenuIcon(ID_BISECTSKIP
, IDS_MENUBISECTSKIP
, IDI_BISECT
);
2215 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2218 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2220 bool bAddSeparator
= false;
2221 if (selectedCount
>= 2 && IsSelectionContinuous())
2223 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2227 headindex
= this->GetHeadIndex();
2228 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2230 head
.Format(L
"HEAD~%d", FirstSelect
- headindex
);
2232 int ret
= g_Git
.GetHash(hashFirst
, head
);
2233 head
.Format(L
"HEAD~%d",LastSelect
-headindex
);
2235 ret
= ret
|| g_Git
.GetHash(hash
, head
);
2236 GitRevLoglist
* pFirstEntry
= m_arShownList
.SafeGetAt(FirstSelect
);
2237 GitRevLoglist
* pLastEntry
= m_arShownList
.SafeGetAt(LastSelect
);
2238 if (!ret
&& pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
)
2240 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2241 bAddSeparator
= true;
2246 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2247 if (selectedCount
>= 2)
2248 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2250 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2251 bAddSeparator
= true;
2254 if (selectedCount
<= 2 || (IsSelectionContinuous() && !isStash
))
2255 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2256 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2257 bAddSeparator
= true;
2261 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2264 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && selectedCount
== 2 && !m_arShownList
.SafeGetAt(FirstSelect
)->m_CommitHash
.IsEmpty() && !isBisectActive
)
2266 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2267 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2270 if (selectedCount
== 1)
2272 bool bAddSeparator
= false;
2273 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2275 // show the push-option only if the log entry has an associated local branch
2276 bool isLocal
= find_if(m_HashMap
[pSelLogEntry
->m_CommitHash
], [](const CString
& ref
) { return CStringUtils::StartsWith(ref
, L
"refs/heads/"); }) != m_HashMap
[pSelLogEntry
->m_CommitHash
].cend();
2277 if (isLocal
|| showExtendedMenu
)
2280 str
.LoadString(IDS_LOG_PUSH
);
2283 size_t index
= (size_t)-1;
2284 CGit::REF_TYPE type
= CGit::REF_TYPE::LOCAL_BRANCH
;
2285 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, &branch
, &index
))
2286 str
.Insert(str
.Find(L
'.'), L
" \"" + branch
+ L
'"');
2288 popup
.AppendMenuIcon(ID_PUSH
, str
, IDI_PUSH
);
2290 if (index
!= (size_t)-1 && index
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size())
2291 popup
.SetMenuItemData(ID_PUSH
, (ULONG_PTR
)&m_HashMap
[pSelLogEntry
->m_CommitHash
][index
]);
2293 if (m_ContextMenuMask
& GetContextMenuBit(ID_SVNDCOMMIT
) && workingTree
.HasGitSVNDir())
2294 popup
.AppendMenuIcon(ID_SVNDCOMMIT
, IDS_MENUSVNDCOMMIT
, IDI_COMMIT
);
2296 bAddSeparator
= true;
2299 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2301 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2302 bAddSeparator
= true;
2306 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2308 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2310 std::vector
<const CString
*> branchs
;
2311 auto addCheck
= [&](const CString
& ref
)
2313 if (ref
== currentBranch
)
2315 branchs
.push_back(&ref
);
2317 size_t index
= (size_t)-1;
2318 CGit::REF_TYPE type
= CGit::REF_TYPE::UNKNOWN
;
2319 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry
, point
, type
, nullptr, &index
))
2320 addCheck(m_HashMap
[pSelLogEntry
->m_CommitHash
][index
]);
2322 for_each(m_HashMap
[pSelLogEntry
->m_CommitHash
], addCheck
);
2325 if (branchs
.size() == 1)
2327 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2330 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2331 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2332 bAddSeparator
= true;
2334 else if (branchs
.size() > 1)
2336 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2337 submenu
.CreatePopupMenu();
2338 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2340 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2341 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2343 submenu
.AppendMenuIcon(ID_DELETE
+ (branchs
.size() << 16), IDS_ALL
);
2344 submenu
.SetMenuItemData(ID_DELETE
+ (branchs
.size() << 16), (ULONG_PTR
)MAKEINTRESOURCE(IDS_ALL
));
2346 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2347 bAddSeparator
= true;
2350 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2352 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2353 } // selectedCount == 1
2355 if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYHASH
))
2356 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2357 if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYCLIPBOARD
))
2358 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2359 if (m_ContextMenuMask
& GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2360 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2362 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2363 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2365 if (selectedCount
== 1 && (m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
)) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2366 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2368 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this);
2369 // DialogEnableWindow(IDOK, FALSE);
2370 // SetPromptApp(&theApp);
2372 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2374 // EnableOKButton();
2375 } // if (popup.CreatePopupMenu())
2378 bool CGitLogListBase::IsSelectionContinuous()
2380 if ( GetSelectedCount()==1 )
2382 // if only one revision is selected, the selection is of course
2387 POSITION pos
= GetFirstSelectedItemPosition();
2388 bool bContinuous
= (m_arShownList
.size() == m_logEntries
.size());
2391 int itemindex
= GetNextSelectedItem(pos
);
2394 int nextindex
= GetNextSelectedItem(pos
);
2395 if (nextindex
- itemindex
> 1)
2397 bContinuous
= false;
2400 itemindex
= nextindex
;
2406 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2409 POSITION pos
= GetFirstSelectedItemPosition();
2413 sRev
.LoadString(IDS_LOG_REVISION
);
2415 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2417 sDate
.LoadString(IDS_LOG_DATE
);
2419 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2423 CString sLogCopyText
;
2425 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
));
2427 if (toCopy
== ID_COPY_ALL
)
2429 //pLogEntry->GetFiles(this)
2430 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2432 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2433 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2435 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + L
": " + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2436 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2439 sPaths
.AppendFormat(from
, (LPCTSTR
)((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2446 if (!pLogEntry
->m_Notes
.IsEmpty())
2448 sNotesTags
= L
"----\n" + CString(MAKEINTRESOURCE(IDS_NOTES
));
2449 sNotesTags
+= L
":\n";
2450 sNotesTags
+= pLogEntry
->m_Notes
;
2451 sNotesTags
.Replace(L
"\n", L
"\r\n");
2453 CString tagInfo
= GetTagInfo(pLogEntry
);
2454 if (!tagInfo
.IsEmpty())
2456 sNotesTags
+= L
"----\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_LOG_TAGINFO
)) + L
":\r\n";
2457 tagInfo
.Replace(L
"\n", L
"\r\n");
2458 sNotesTags
+= tagInfo
;
2461 sLogCopyText
.Format(L
"%s: %s\r\n%s: %s <%s>\r\n%s: %s\r\n%s:\r\n%s\r\n%s----\r\n%s\r\n\r\n",
2462 (LPCTSTR
)sRev
, (LPCTSTR
)pLogEntry
->m_CommitHash
.ToString(),
2463 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2465 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2466 (LPCTSTR
)sMessage
, (LPCTSTR
)pLogEntry
->GetSubjectBody(true),
2467 (LPCTSTR
)sNotesTags
,
2469 sClipdata
+= sLogCopyText
;
2471 else if (toCopy
== ID_COPY_MESSAGE
)
2474 sClipdata
+= pLogEntry
->GetSubjectBody(true);
2475 sClipdata
+= L
"\r\n\r\n";
2477 else if (toCopy
== ID_COPY_SUBJECT
)
2480 sClipdata
+= pLogEntry
->GetSubject().Trim();
2481 sClipdata
+= L
"\r\n\r\n";
2486 sClipdata
+= L
"\r\n";
2487 sClipdata
+= pLogEntry
->m_CommitHash
;
2492 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2496 void CGitLogListBase::DiffSelectedRevWithPrevious()
2498 if (m_bThreadRunning
)
2501 int FirstSelect
=-1, LastSelect
=-1;
2502 POSITION pos
= GetFirstSelectedItemPosition();
2503 FirstSelect
= GetNextSelectedItem(pos
);
2505 LastSelect
= GetNextSelectedItem(pos
);
2507 ContextMenuAction(ID_COMPAREWITHPREVIOUS
, FirstSelect
, LastSelect
, nullptr);
2510 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2512 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2515 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2517 if (pFindInfo
->iStart
< 0 || pFindInfo
->iStart
>= (int)m_arShownList
.size())
2519 if (!pFindInfo
->lvfi
.psz
)
2522 CString sCmp
= pFindInfo
->lvfi
.psz
;
2524 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2526 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2527 sRev
.Format(L
"%ld", pLogEntry
->Rev
);
2528 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2530 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2538 if (sCmp
.Compare(sRev
)==0)
2545 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2547 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2549 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2550 sRev
.Format(L
"%ld", pLogEntry
->Rev
);
2551 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2553 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2561 if (sCmp
.Compare(sRev
)==0)
2573 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2577 this->m_arShownList
.SafeRemoveAll();
2579 this->m_logEntries
.ClearAll();
2580 if (this->m_logEntries
.ParserFromLog(path
, 0, info
, range
))
2583 SetItemCountEx((int)m_logEntries
.size());
2585 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2589 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2590 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2594 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2595 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2606 int CGitLogListBase::FillGitLog(std::unordered_set
<CGitHash
>& hashes
)
2610 m_arShownList
.SafeRemoveAll();
2612 m_logEntries
.ClearAll();
2613 if (m_logEntries
.Fill(hashes
))
2616 SetItemCountEx((int)m_logEntries
.size());
2618 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2622 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2623 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2627 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2628 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2637 int CGitLogListBase::BeginFetchLog()
2641 this->m_arShownList
.SafeRemoveAll();
2643 this->m_logEntries
.ClearAll();
2645 this->m_LogCache
.ClearAllParent();
2647 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2650 if(this->m_Path
.IsEmpty())
2656 mask
= CGit::LOG_INFO_ONLY_HASH
;
2657 if (m_bIncludeBoundaryCommits
)
2658 mask
|= CGit::LOG_INFO_BOUNDARY
;
2659 // if(this->m_bAllBranch)
2660 mask
|= m_ShowMask
;
2664 this->m_logEntries
.insert(m_logEntries
.cbegin(), m_wcRev
.m_CommitHash
);
2666 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2669 if (m_sRange
.IsEmpty())
2672 #if 0 /* use tortoiegit filter */
2673 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2674 data
.m_Author
= this->m_sFilterText
;
2676 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2677 data
.m_MessageFilter
= this->m_sFilterText
;
2679 data
.m_IsRegex
= m_bFilterWithRegex
;
2682 // follow does not work for directories
2683 if (!path
|| path
->IsDirectory())
2684 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2685 // follow does not work with all branches 8at least in TGit)
2686 if (mask
& CGit::LOG_INFO_FOLLOW
)
2687 mask
&= ~(CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_BASIC_REFS
| CGit::LOG_INFO_LOCAL_BRANCHES
);
2689 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, mask
, &m_Filter
, CRegDWORD(L
"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER
));
2691 //this->m_logEntries.ParserFromLog();
2692 if(IsInWorkingThread())
2694 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2698 SetItemCountEx((int)m_logEntries
.size());
2703 [] { git_init(); } ();
2708 MessageBox(L
"Could not initialize libgit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2712 if (!g_Git
.CanParseRev(m_sRange
))
2714 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_BASIC_REFS
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2717 // if show all branches, pick any ref as dummy entry ref
2719 if (g_Git
.GetRefList(list
))
2720 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
2724 cmd
= g_Git
.GetLogCmd(list
[0], path
, mask
, &m_Filter
, CRegDWORD(L
"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER
));
2727 g_Git
.m_critGitDllSec
.Lock();
2729 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2731 g_Git
.m_critGitDllSec
.Unlock();
2737 g_Git
.m_critGitDllSec
.Unlock();
2739 MessageBox(L
"Could not open log.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2742 g_Git
.m_critGitDllSec
.Unlock();
2747 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2749 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2751 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2753 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
2755 DiffSelectedRevWithPrevious();
2760 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2767 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2769 // select all entries
2770 for (int i
=0; i
<GetItemCount(); ++i
)
2771 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2776 if (m_hAccel
&& !bSkipAccelerator
)
2778 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2784 //m_tooltips.RelayEvent(pMsg);
2785 return __super::PreTranslateMessage(pMsg
);
2788 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2790 // a double click on an entry in the revision list has happened
2793 if (CRegDWORD(L
"Software\\TortoiseGit\\DiffByDoubleClickInLog", FALSE
))
2794 DiffSelectedRevWithPrevious();
2797 void CGitLogListBase::FetchLogAsync(void* data
)
2801 StartLoadingThread();
2804 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2806 return ((CGitLogListBase
*)pVoid
)->LogThread();
2809 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2812 oldest
=CTime::GetCurrentTime();
2813 latest
=CTime(1971,1,2,0,0,0);
2814 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2816 if(m_logEntries
[i
].IsEmpty())
2819 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() < oldest
.GetTime())
2820 oldest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2822 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() > latest
.GetTime())
2823 latest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2831 UINT
CGitLogListBase::LogThread()
2833 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2839 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2840 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2845 std::tr1::wregex pat
;//(L"Remove", tr1::regex_constants::icase);
2846 bool bRegex
= false;
2847 if (m_bFilterWithRegex
)
2848 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2850 TRACE(L
"\n===Begin===\n");
2851 //Update work copy item;
2853 if (!m_logEntries
.empty())
2855 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2857 m_arShownList
.SafeAdd(pRev
);
2861 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2863 // store commit number of the last selected commit/line before the refresh or -1
2864 int lastSelectedHashNItem
= -1;
2865 if (m_lastSelectedHash
.IsEmpty())
2866 lastSelectedHashNItem
= 0;
2870 bool shouldWalk
= true;
2871 if (!g_Git
.CanParseRev(m_sRange
))
2873 // walk revisions if show all branches and there exists any ref
2874 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_BASIC_REFS
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2879 if (g_Git
.GetRefList(list
))
2880 MessageBox(g_Git
.GetGitLastErr(L
"Could not get all refs."), L
"TortoiseGit", MB_ICONERROR
);
2888 g_Git
.m_critGitDllSec
.Lock();
2892 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2893 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2898 MessageBox(L
"Could not get first commit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2901 g_Git
.m_critGitDllSec
.Unlock();
2904 t2
= t1
= GetTickCount64();
2905 int oldprecentage
= 0;
2906 size_t oldsize
= m_logEntries
.size();
2907 std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>> commitChildren
;
2908 while (ret
== 0 && !m_bExitThread
)
2910 g_Git
.m_critGitDllSec
.Lock();
2913 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2917 g_Git
.m_critGitDllSec
.Unlock();
2919 MessageBox(L
"Could not get next commit.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2922 g_Git
.m_critGitDllSec
.Unlock();
2926 if (ret
!= -2) // other than end of revision walking
2927 MessageBox((L
"Could not get next commit.\nlibgit returns:" + std::to_wstring(ret
)).c_str(), L
"TortoiseGit", MB_ICONERROR
);
2931 if (commit
.m_ignore
== 1)
2933 git_free_commit(&commit
);
2937 //printf("%s\r\n",commit.GetSubject());
2941 CGitHash
hash(commit
.m_hash
);
2943 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2944 pRev
->m_GitCommit
= commit
;
2945 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2947 char* note
= nullptr;
2948 g_Git
.m_critGitDllSec
.Lock();
2951 git_get_notes(commit
.m_hash
, ¬e
);
2955 g_Git
.m_critGitDllSec
.Unlock();
2957 MessageBox(L
"Could not get commit notes.\nlibgit reports:\n" + err
, L
"TortoiseGit", MB_ICONERROR
);
2960 g_Git
.m_critGitDllSec
.Unlock();
2964 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2969 if(!pRev
->m_IsDiffFiles
)
2971 pRev
->m_CallDiffAsync
= DiffAsync
;
2974 pRev
->ParserParentFromCommit(&commit
);
2975 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2977 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2979 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2980 auto it
= commitChildren
.find(parentHash
);
2981 if (it
== commitChildren
.end())
2982 it
= commitChildren
.insert(make_pair(parentHash
, std::unordered_set
<CGitHash
>())).first
;
2983 it
->second
.insert(pRev
->m_CommitHash
);
2992 bool visible
= true;
2993 if (HasFilterText())
2995 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2998 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
3000 this->m_critSec
.Lock();
3001 m_logEntries
.append(hash
, visible
);
3003 m_arShownList
.SafeAdd(pRev
);
3004 this->m_critSec
.Unlock();
3009 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3010 lastSelectedHashNItem
= (int)m_arShownList
.size() - 1;
3012 t2
= GetTickCount64();
3014 if (t2
- t1
> 500UL || (m_logEntries
.size() - oldsize
> 100))
3017 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3020 if(percent
< GITLOG_START
)
3021 percent
= GITLOG_START
+1;
3023 oldsize
= m_logEntries
.size();
3024 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3026 //if( percent > oldprecentage )
3028 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3029 oldprecentage
= percent
;
3032 if (lastSelectedHashNItem
>= 0)
3033 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3038 g_Git
.m_critGitDllSec
.Lock();
3039 git_close_log(m_DllGitLog
);
3040 g_Git
.m_critGitDllSec
.Unlock();
3046 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3051 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3053 if (lastSelectedHashNItem
>= 0)
3054 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3057 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3059 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3064 void CGitLogListBase::FetchRemoteList()
3066 STRING_VECTOR remoteList
;
3067 m_SingleRemote
.Empty();
3068 if (!g_Git
.GetRemoteList(remoteList
) && remoteList
.size() == 1)
3069 m_SingleRemote
= remoteList
[0];
3072 void CGitLogListBase::FetchTrackingBranchList()
3074 m_TrackingMap
.clear();
3075 for (auto it
= m_HashMap
.cbegin(); it
!= m_HashMap
.cend(); ++it
)
3077 for (const auto& ref
: it
->second
)
3080 if (CGit::GetShortName(ref
, branchName
, L
"refs/heads/"))
3082 CString pullRemote
, pullBranch
;
3083 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3084 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3085 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3091 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3093 SafeTerminateThread();
3095 this->SetItemCountEx(0);
3100 ShowGraphColumn((m_ShowMask
& CGit::LOG_INFO_FOLLOW
) ? false : true);
3104 git_free_mailmap(m_pMailmap
);
3105 git_read_mailmap(&m_pMailmap
);
3108 //Update branch and Tag info
3111 m_pFindDialog
->RefreshList();
3112 //Assume Thread have exited
3113 //if(!m_bThreadRunning)
3115 m_logEntries
.clear();
3119 m_sFilterText
.Empty();
3122 SafeTerminateAsyncDiffThread();
3123 m_AsynDiffListLock
.Lock();
3124 m_AsynDiffList
.clear();
3125 m_AsynDiffListLock
.Unlock();
3126 StartAsyncDiffThread();
3128 StartLoadingThread();
3132 void CGitLogListBase::StartAsyncDiffThread()
3134 if (m_AsyncThreadExit
)
3136 if (InterlockedExchange(&m_AsyncThreadRunning
, TRUE
) != FALSE
)
3138 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
3139 if (!m_DiffingThread
)
3141 InterlockedExchange(&m_AsyncThreadRunning
, FALSE
);
3142 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3146 void CGitLogListBase::StartLoadingThread()
3148 if (InterlockedExchange(&m_bThreadRunning
, TRUE
) != FALSE
)
3150 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3151 InterlockedExchange(&m_bExitThread
, FALSE
);
3152 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
3153 if (!m_LoadingThread
)
3155 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3156 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3157 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3161 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3165 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3167 type
|= std::tr1::regex_constants::icase
;
3168 pat
= std::tr1::wregex(regexp_str
, type
);
3171 catch (std::exception
&) {}
3174 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3177 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3180 if ((bRegex
)&&(m_bFilterWithRegex
))
3182 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3184 if(this->m_bShowBugtraqColumn
)
3186 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubjectBody());
3188 ATLTRACE(L
"bugID = \"%s\"\n", (LPCTSTR
)sBugIds
);
3189 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3194 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3196 ATLTRACE(L
"messge = \"%s\"\n", (LPCTSTR
)pRev
->GetSubject());
3197 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3201 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3203 ATLTRACE(L
"messge = \"%s\"\n", (LPCTSTR
)pRev
->GetBody());
3204 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3208 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3210 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3213 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3217 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3219 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3222 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3226 if (m_SelectedFilters
& LOGFILTER_REVS
)
3228 sRev
= pRev
->m_CommitHash
.ToString();
3229 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3235 if (m_SelectedFilters
& LOGFILTER_NOTES
)
3237 if (std::regex_search(std::wstring(pRev
->m_Notes
), pat
, flags
))
3241 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3243 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3244 for (const auto& ref
: refs
)
3246 if (std::regex_search(std::wstring(ref
), pat
, flags
))
3251 if (m_SelectedFilters
& LOGFILTER_ANNOTATEDTAG
)
3253 if (std::regex_search(std::wstring(GetTagInfo(pRev
)), pat
, flags
))
3257 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3259 CTGitPathList
* pathList
= nullptr;
3260 if( pRev
->m_IsDiffFiles
)
3261 pathList
= &pRev
->GetFiles(this);
3264 if(!pRev
->m_IsSimpleListReady
)
3265 pRev
->SafeGetSimpleList(&g_Git
);
3269 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3271 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
[cpPathIndex
].GetGitOldPathString()), pat
, flags
))
3273 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
[cpPathIndex
].GetGitPathString()), pat
, flags
))
3277 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3279 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3286 CString find
= m_sFilterText
;
3287 if (!m_bFilterCaseSensitively
)
3289 result
= find
[0] == '!' ? FALSE
: TRUE
;
3293 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3295 if(this->m_bShowBugtraqColumn
)
3297 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubjectBody());
3299 if (!m_bFilterCaseSensitively
)
3300 sBugIds
.MakeLower();
3301 if ((sBugIds
.Find(find
) >= 0))
3306 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3308 CString msg
= pRev
->GetSubject();
3310 if (!m_bFilterCaseSensitively
)
3311 msg
= msg
.MakeLower();
3312 if ((msg
.Find(find
) >= 0))
3316 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3318 CString msg
= pRev
->GetBody();
3320 if (!m_bFilterCaseSensitively
)
3321 msg
= msg
.MakeLower();
3322 if ((msg
.Find(find
) >= 0))
3326 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3328 CString msg
= pRev
->GetAuthorName();
3329 if (!m_bFilterCaseSensitively
)
3330 msg
= msg
.MakeLower();
3331 if ((msg
.Find(find
) >= 0))
3335 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3337 CString msg
= pRev
->GetAuthorEmail();
3338 if (!m_bFilterCaseSensitively
)
3339 msg
= msg
.MakeLower();
3340 if ((msg
.Find(find
) >= 0))
3344 if (m_SelectedFilters
& LOGFILTER_NOTES
)
3346 CString msg
= pRev
->m_Notes
;
3347 if (!m_bFilterCaseSensitively
)
3348 msg
= msg
.MakeLower();
3349 if ((msg
.Find(find
) >= 0))
3353 if (m_SelectedFilters
& LOGFILTER_REVS
)
3355 sRev
= pRev
->m_CommitHash
.ToString();
3356 if ((sRev
.Find(find
) >= 0))
3360 if (m_SelectedFilters
& LOGFILTER_ANNOTATEDTAG
)
3362 CString msg
= GetTagInfo(pRev
);
3363 if (!m_bFilterCaseSensitively
)
3364 msg
= msg
.MakeLower();
3365 if ((msg
.Find(find
) >= 0))
3369 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3371 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3372 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3374 if (it
->Find(find
) >= 0)
3379 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3381 CTGitPathList
* pathList
= nullptr;
3382 if( pRev
->m_IsDiffFiles
)
3383 pathList
= &pRev
->GetFiles(this);
3386 if(!pRev
->m_IsSimpleListReady
)
3387 pRev
->SafeGetSimpleList(&g_Git
);
3390 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3392 CTGitPath
* cpath
= &pathList
->m_paths
[cpPathIndex
];
3393 CString path
= cpath
->GetGitOldPathString();
3394 if (!m_bFilterCaseSensitively
)
3396 if ((path
.Find(find
)>=0))
3398 path
= cpath
->GetGitPathString();
3399 if (!m_bFilterCaseSensitively
)
3401 if ((path
.Find(find
)>=0))
3405 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3407 CString path
= pRev
->m_SimpleFileList
[i
];
3408 if (!m_bFilterCaseSensitively
)
3410 if ((path
.Find(find
)>=0))
3414 } // else (from if (bRegex))
3418 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3420 return str
.Left(prefix
.GetLength()) == prefix
;
3422 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::unordered_map
<CGitHash
, std::unordered_set
<CGitHash
>>& commitChildren
)
3424 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3427 if (m_ShowFilter
& FILTERSHOW_REFS
)
3430 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3431 for (size_t i
= 0; i
< refList
.size(); ++i
)
3433 const CString
&str
= refList
[i
];
3434 if (CStringStartsWith(str
, L
"refs/heads/"))
3436 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3439 else if (CStringStartsWith(str
, L
"refs/remotes/"))
3441 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3444 else if (CStringStartsWith(str
, L
"refs/tags/"))
3446 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3449 else if (CStringStartsWith(str
, L
"refs/stash"))
3451 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3454 else if (CStringStartsWith(str
, L
"refs/bisect/"))
3456 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3460 // Keep the head too.
3461 if (pRev
->m_CommitHash
== m_HeadHash
)
3465 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3467 if (pRev
->ParentsCount() > 1)
3469 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3470 if (childrenIt
!= commitChildren
.end())
3472 const std::unordered_set
<CGitHash
> &children
= childrenIt
->second
;
3473 if (children
.size() > 1)
3480 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3482 // HACK to hide graph column
3484 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3486 SetColumnWidth(0, 0);
3489 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3494 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3496 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3497 for (size_t i
= 0; i
< vector
.size(); ++i
)
3499 if (CStringUtils::StartsWith(vector
[i
], L
"refs/tags/"))
3501 CString tag
= vector
[i
];
3502 int start
= vector
[i
].Find(L
"^{}");
3504 tag
= tag
.Left(start
);
3508 cmd
.Format(L
"git.exe cat-file tag %s", (LPCTSTR
)tag
);
3509 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3510 output
.Trim().AppendChar(L
'\n');
3518 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3520 pShownlist
->SafeRemoveAll();
3522 std::tr1::wregex pat
;//(L"Remove", tr1::regex_constants::icase);
3523 bool bRegex
= false;
3524 if (m_bFilterWithRegex
)
3525 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3527 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3529 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3531 if ((bRegex
)&&(m_bFilterWithRegex
))
3534 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3536 ATLTRACE(L
"bugID = \"%s\"\n", (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3537 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3539 pShownlist
->SafeAdd(m_logEntries
[i
]);
3544 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3546 ATLTRACE(L
"messge = \"%s\"\n", m_logEntries
.GetGitRevAt(i
).GetSubject());
3547 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3549 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3553 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3555 ATLTRACE("messge = \"%s\"\n", m_logEntries
.GetGitRevAt(i
).GetBody());
3556 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3558 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3562 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3564 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3567 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3569 CTGitPath cpath
= pathList
[cpPathIndex
];
3570 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3572 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3576 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3578 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3582 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3584 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3590 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3592 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3594 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3598 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3600 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3602 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3606 if (m_SelectedFilters
& LOGFILTER_REVS
)
3608 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3609 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3611 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3615 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3617 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3618 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3620 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3622 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3630 CString find
= m_sFilterText
;
3631 if (!m_bFilterCaseSensitively
)
3634 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3636 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3638 if (!m_bFilterCaseSensitively
)
3639 sBugIDs
= sBugIDs
.MakeLower();
3640 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3642 pShownlist
->SafeAdd(m_logEntries
[i
]);
3647 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3649 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3651 if (!m_bFilterCaseSensitively
)
3652 msg
= msg
.MakeLower();
3653 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3655 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3659 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3661 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3663 if (!m_bFilterCaseSensitively
)
3664 msg
= msg
.MakeLower();
3665 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3667 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3671 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3673 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3676 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3678 CTGitPath cpath
= pathList
[cpPathIndex
];
3679 CString path
= cpath
.GetGitOldPathString();
3680 if (!m_bFilterCaseSensitively
)
3682 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3684 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3688 path
= cpath
.GetGitPathString();
3689 if (!m_bFilterCaseSensitively
)
3691 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3693 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3697 path
= cpath
.GetActionName();
3698 if (!m_bFilterCaseSensitively
)
3700 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3702 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3708 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3710 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3711 if (!m_bFilterCaseSensitively
)
3712 msg
= msg
.MakeLower();
3713 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3715 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3719 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3721 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3722 if (!m_bFilterCaseSensitively
)
3723 msg
= msg
.MakeLower();
3724 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3726 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3730 if (m_SelectedFilters
& LOGFILTER_REVS
)
3732 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3733 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3735 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3739 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3741 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3742 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3744 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3746 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3751 } // else (from if (bRegex))
3752 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3755 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3758 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3764 return time <= m_To;
3767 return time >= m_From;
3769 return ((time >= m_From)&&(time <= m_To));
3771 return TRUE
; /* git dll will filter time range */
3776 void CGitLogListBase::StartFilter()
3778 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3779 RecalculateShownList(&m_arShownList
);
3780 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3784 SetItemCountEx(ShownCountWithStopped());
3785 RedrawItems(0, ShownCountWithStopped());
3789 void CGitLogListBase::RemoveFilter()
3791 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3793 m_arShownList
.SafeRemoveAll();
3795 // reset the time filter too
3797 m_timFrom
= (__time64_t(m_tFrom
));
3798 m_timTo
= (__time64_t(m_tTo
));
3799 m_DateFrom
.SetTime(&m_timFrom
);
3800 m_DateTo
.SetTime(&m_timTo
);
3801 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3802 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3805 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3807 if(this->m_IsOldFirst
)
3808 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3810 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3812 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3814 SetItemCountEx(ShownCountWithStopped());
3815 RedrawItems(0, ShownCountWithStopped());
3817 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3820 void CGitLogListBase::Clear()
3822 m_arShownList
.SafeRemoveAll();
3825 m_logEntries
.ClearAll();
3828 void CGitLogListBase::OnDestroy()
3830 SafeTerminateThread();
3831 SafeTerminateAsyncDiffThread();
3834 while(m_LogCache
.SaveCache())
3842 //if(CMessageBox::Show(nullptr, L"Cannot Save Log Cache to Disk. To retry click yes. To give up click no.", L"TortoiseGit",
3843 // MB_YESNO) == IDNO)
3847 __super::OnDestroy();
3850 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3854 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3855 this->InvalidateRect(rect
);
3861 * Save column widths to the registry
3863 void CGitLogListBase::SaveColumnWidths()
3865 // HACK that graph column is always shown
3866 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3868 __super::SaveColumnWidths();
3871 int CGitLogListBase::GetHeadIndex()
3873 if(m_HeadHash
.IsEmpty())
3876 for (size_t i
= 0; i
< m_arShownList
.size(); ++i
)
3878 GitRev
* pRev
= m_arShownList
.SafeGetAt(i
);
3881 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3887 void CGitLogListBase::OnFind()
3891 m_pFindDialog
= new CFindDlg(this);
3892 m_pFindDialog
->Create(this);
3896 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3898 if (GetSelectedCount() != 0)
3901 CGitHash theSelectedHash
= m_lastSelectedHash
;
3902 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3903 m_lastSelectedHash
= theSelectedHash
;
3905 int countPerPage
= GetCountPerPage();
3906 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3907 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3908 EnsureVisible((int)itemToSelect
, FALSE
);
3912 LRESULT
CGitLogListBase::OnScrollToRef(WPARAM wParam
, LPARAM
/*lParam*/)
3914 CString
* ref
= reinterpret_cast<CString
*>(wParam
);
3915 if (!ref
|| ref
->IsEmpty())
3918 bool bShift
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
3921 if (g_Git
.GetHash(hash
, *ref
+ L
"^{}")) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3922 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + *ref
+ L
"^{}\"."), L
"TortoiseGit", MB_ICONERROR
);
3927 bool bFound
= false;
3928 int cnt
= (int)m_arShownList
.size();
3930 for (i
= 0; i
< cnt
; ++i
)
3932 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3933 if (pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3942 EnsureVisible(i
, FALSE
);
3945 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3946 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3947 SetSelectionMark(i
);
3951 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3953 m_highlight
= pLogEntry
->m_CommitHash
;
3961 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3963 ASSERT(m_pFindDialog
);
3964 bool bFound
= false;
3967 if (m_pFindDialog
->IsTerminating())
3969 // invalidate the handle identifying the dialog box.
3970 m_pFindDialog
= nullptr;
3974 int cnt
= (int)m_arShownList
.size();
3975 bool bShift
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
3977 if(m_pFindDialog
->IsRef())
3980 str
=m_pFindDialog
->GetFindString();
3986 if (g_Git
.GetHash(hash
, str
+ L
"^{}")) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3987 MessageBox(g_Git
.GetGitLastErr(L
"Could not get hash of ref \"" + str
+ L
"^{}\"."), L
"TortoiseGit", MB_ICONERROR
);
3992 for (i
= 0; i
< cnt
; ++i
)
3994 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
3995 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
4004 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
4009 if (m_pFindDialog
->FindNext() && !bFound
)
4011 //read data from dialog
4012 CString findText
= m_pFindDialog
->GetFindString();
4013 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
4015 std::tr1::wregex pat
;
4016 bool bRegex
= false;
4017 if (m_pFindDialog
->Regex())
4018 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
4020 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
4022 for (i
= m_nSearchIndex
+ 1; ; ++i
)
4027 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
4029 if (m_nSearchIndex
>= 0)
4031 if (i
== m_nSearchIndex
)
4033 ::MessageBeep(0xFFFFFFFF);
4034 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4039 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
4042 str
+=pLogEntry
->m_CommitHash
.ToString();
4045 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4047 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4051 str
+=pLogEntry
->GetAuthorEmail();
4053 str
+=pLogEntry
->GetAuthorName();
4055 str
+=pLogEntry
->GetBody();
4057 str
+=pLogEntry
->GetCommitterEmail();
4059 str
+=pLogEntry
->GetCommitterName();
4061 str
+=pLogEntry
->GetSubject();
4063 str
+=pLogEntry
->m_Notes
;
4065 str
+=GetTagInfo(pLogEntry
);
4069 /*Because changed files list is loaded on demand when gui show,
4070 files will empty when files have not fetched.
4072 we can add it back by using one-way diff(with outnumber changed and rename detect.
4073 here just need changed filename list. one-way is much quicker.
4075 if(pLogEntry
->m_IsFull
)
4077 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4079 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4081 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4087 if(!pLogEntry
->m_IsSimpleListReady
)
4088 pLogEntry
->SafeGetSimpleList(&g_Git
);
4090 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4092 str
+= pLogEntry
->m_SimpleFileList
[j
];
4099 if (std::regex_search(std::wstring(str
), pat
, flags
))
4109 if (str
.Find(findText
) >= 0)
4118 msg
= msg
.MakeLower();
4119 CString find
= findText
.MakeLower();
4120 if (msg
.Find(find
) >= 0)
4127 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4129 } // if(m_pFindDialog->FindNext())
4130 //UpdateLogInfoLabel();
4135 EnsureVisible(i
, FALSE
);
4138 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4139 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4140 SetSelectionMark(i
);
4144 GitRev
* pLogEntry
= m_arShownList
.SafeGetAt(i
);
4146 m_highlight
= pLogEntry
->m_CommitHash
;
4149 //FillLogMessageCtrl();
4156 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4158 LVHITTESTINFO lvhitTestInfo
;
4160 lvhitTestInfo
.pt
= point
;
4162 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4163 int nSubItem
= lvhitTestInfo
.iSubItem
;
4165 UINT nFlags
= lvhitTestInfo
.flags
;
4167 // nFlags is 0 if the SubItemHitTest fails
4168 // Therefore, 0 & <anything> will equal false
4169 if (nFlags
& LVHT_ONITEM
)
4171 // Get the client area occupied by this control
4173 GetClientRect(&rcClient
);
4175 // Fill in the TOOLINFO structure
4177 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4178 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4179 pTI
->rect
= rcClient
;
4181 return pTI
->uId
; // By returning a unique value per listItem,
4182 // we ensure that when the mouse moves over another list item,
4183 // the tooltip will change
4187 // Otherwise, we aren't interested, so let the message propagate
4192 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4194 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4195 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4199 // Ignore messages from the built in tooltip, we are processing them internally
4200 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4201 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4202 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4205 // Get the mouse position
4206 const MSG
* pMessage
= GetCurrentMessage();
4210 ScreenToClient(&pt
);
4212 // Check if the point falls onto a list item
4213 LVHITTESTINFO lvhitTestInfo
;
4214 lvhitTestInfo
.pt
= pt
;
4216 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4218 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4220 // Get branch description first
4222 if (lvhitTestInfo
.iSubItem
== LOGLIST_MESSAGE
)
4225 CGit::REF_TYPE type
= CGit::REF_TYPE::LOCAL_BRANCH
;
4226 if (IsMouseOnRefLabel(m_arShownList
.SafeGetAt(nItem
), lvhitTestInfo
.pt
, type
, &branch
))
4228 MAP_STRING_STRING descriptions
;
4229 g_Git
.GetBranchDescriptions(descriptions
);
4230 if (descriptions
.find(branch
) != descriptions
.cend())
4232 strTipText
.LoadString(IDS_DESCRIPTION
);
4233 strTipText
+= L
":\n";
4234 strTipText
+= descriptions
[branch
];
4239 bool followMousePos
= false;
4240 if (!strTipText
.IsEmpty())
4241 followMousePos
= true;
4243 strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4244 if (strTipText
.IsEmpty())
4247 // we want multiline tooltips
4248 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4250 wcscpy_s(m_wszTip
, strTipText
);
4251 // handle Unicode as well as non-Unicode requests
4252 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4254 pTTTA
->hinst
= nullptr;
4255 pTTTA
->lpszText
= m_szTip
;
4256 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, nullptr, nullptr);
4260 pTTTW
->hinst
= nullptr;
4261 pTTTW
->lpszText
= m_wszTip
;
4265 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4267 rect
.MoveToXY(pt
.x
, pt
.y
+ 18); // 18: to act like a normal tooltip
4268 ClientToScreen(rect
);
4269 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4271 return TRUE
; // We found a tool tip,
4272 // tell the framework this message has been handled
4275 return FALSE
; // We didn't handle the message,
4276 // let the framework continue propagating the message
4279 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4281 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4283 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
4284 if (pLogEntry
== nullptr)
4286 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty() && (m_superProjectHash
.IsEmpty() || pLogEntry
->m_CommitHash
!= m_superProjectHash
))
4288 return pLogEntry
->GetSubject();
4290 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4292 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
4293 if (pLogEntry
== nullptr)
4295 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4297 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4299 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
4300 if (pLogEntry
== nullptr)
4302 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4304 else if (nSubItem
== LOGLIST_ACTION
)
4306 GitRevLoglist
* pLogEntry
= m_arShownList
.SafeGetAt(nItem
);
4307 if (pLogEntry
== nullptr)
4310 if (!pLogEntry
->m_IsDiffFiles
)
4311 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4313 int actions
= pLogEntry
->GetAction(this);
4314 CString sToolTipText
;
4317 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4318 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4320 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4322 if (!actionText
.IsEmpty())
4323 actionText
+= L
"\r\n";
4324 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4327 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4329 if (!actionText
.IsEmpty())
4330 actionText
+= L
"\r\n";
4331 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4334 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4336 if (!actionText
.IsEmpty())
4337 actionText
+= L
"\r\n";
4338 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4341 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4343 if (!actionText
.IsEmpty())
4344 actionText
+= L
"\r\n";
4345 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4348 if (!actionText
.IsEmpty())
4350 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4351 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4353 return sToolTipText
;
4358 bool CGitLogListBase::IsMouseOnRefLabelFromPopupMenu(const GitRevLoglist
* pLogEntry
, const CPoint
& point
, CGit::REF_TYPE
& type
, CString
* pShortname
/*nullptr*/, size_t* pIndex
/*nullptr*/)
4361 ScreenToClient(&pt
);
4362 return IsMouseOnRefLabel(pLogEntry
, pt
, type
, pShortname
, pIndex
);
4365 bool CGitLogListBase::IsMouseOnRefLabel(const GitRevLoglist
* pLogEntry
, const POINT
& pt
, CGit::REF_TYPE
& type
, CString
* pShortname
/*nullptr*/, size_t* pIndex
/*nullptr*/)
4370 for (size_t i
= 0; i
< m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++i
)
4372 const auto labelpos
= m_RefLabelPosMap
.find(m_HashMap
[pLogEntry
->m_CommitHash
][i
]);
4373 if (labelpos
== m_RefLabelPosMap
.cend() || !labelpos
->second
.PtInRect(pt
))
4376 CGit::REF_TYPE foundType
;
4378 *pShortname
= CGit::GetShortName(m_HashMap
[pLogEntry
->m_CommitHash
][i
], &foundType
);
4380 CGit::GetShortName(m_HashMap
[pLogEntry
->m_CommitHash
][i
], &foundType
);
4381 if (foundType
!= type
&& type
!= CGit::REF_TYPE::UNKNOWN
)
4392 void CGitLogListBase::OnBeginDrag(NMHDR
* /*pnmhdr*/, LRESULT
* pResult
)
4396 if (!m_bDragndropEnabled
|| GetSelectedCount() == 0 || !IsSelectionContinuous())
4401 m_nDropMarkerLast
= -1;
4402 m_nDropMarkerLastHot
= GetHotItem();
4406 void CGitLogListBase::OnMouseMove(UINT nFlags
, CPoint point
)
4408 __super::OnMouseMove(nFlags
, point
);
4413 CPoint dropPoint
= point
;
4414 ClientToScreen(&dropPoint
);
4416 if (WindowFromPoint(dropPoint
) != this)
4418 SetCursor(LoadCursor(nullptr, IDC_NO
));
4420 DrawDropInsertMarker(m_nDropIndex
);
4424 SetCursor(LoadCursor(nullptr, IDC_ARROW
));
4425 ScreenToClient(&dropPoint
);
4428 m_nDropIndex
= HitTest(dropPoint
);
4430 if (m_nDropIndex
== -1) // might be last item, allow to move past last item
4433 m_nDropIndex
= HitTest(dropPoint
);
4434 if (m_nDropIndex
!= -1)
4435 m_nDropIndex
= GetItemCount();
4438 POSITION pos
= GetFirstSelectedItemPosition();
4439 int first
= GetNextSelectedItem(pos
);
4442 last
= GetNextSelectedItem(pos
);
4443 if (m_nDropIndex
== -1 || (m_nDropIndex
>= first
&& m_nDropIndex
- 1 <= last
))
4445 SetCursor(LoadCursor(nullptr, IDC_NO
));
4449 // handle auto scrolling
4450 int hotItem
= GetHotItem();
4451 int topindex
= GetTopIndex();
4452 if (hotItem
== topindex
&& hotItem
!= 0)
4453 EnsureVisible(hotItem
- 1, FALSE
);
4454 else if (hotItem
>= topindex
+ GetCountPerPage() - 1 && hotItem
+ 1 < GetItemCount())
4455 EnsureVisible(hotItem
+ 1, FALSE
);
4457 DrawDropInsertMarker(m_nDropIndex
);
4460 void CGitLogListBase::OnLButtonUp(UINT nFlags
, CPoint point
)
4465 SetCursor(LoadCursor(nullptr, IDC_HAND
));
4466 m_bDragging
= FALSE
;
4469 GetItemRect(m_nDropMarkerLast
, &rect
, 0);
4470 rect
.bottom
= rect
.top
+ 2;
4472 InvalidateRect(&rect
, 0);
4475 ClientToScreen(&pt
);
4476 if (WindowFromPoint(pt
) == this && m_nDropIndex
!= -1)
4477 GetParent()->PostMessage(MSG_COMMITS_REORDERED
, m_nDropIndex
, 0);
4480 __super::OnLButtonUp(nFlags
, point
);
4483 void CGitLogListBase::DrawDropInsertMarker(int nIndex
)
4485 if (m_nDropMarkerLast
!= nIndex
)
4488 if (GetItemRect(m_nDropMarkerLast
, &rect
, 0))
4490 rect
.bottom
= rect
.top
+ 2;
4492 InvalidateRect(&rect
, 0);
4494 else if (m_nDropMarkerLast
== GetItemCount())
4495 DrawDropInsertMarkerLine(m_nDropMarkerLast
); // double painting = removal
4496 m_nDropMarkerLast
= nIndex
;
4501 DrawDropInsertMarkerLine(m_nDropMarkerLast
);
4503 else if (m_nDropMarkerLastHot
!= GetHotItem())
4505 m_nDropMarkerLastHot
= GetHotItem();
4506 m_nDropMarkerLast
= -1;
4510 void CGitLogListBase::DrawDropInsertMarkerLine(int nIndex
)
4512 CBrush
* pBrush
= CDC::GetHalftoneBrush();
4516 if (nIndex
< GetItemCount())
4518 GetItemRect(nIndex
, &rect
, 0);
4519 rect
.bottom
= rect
.top
+ 2;
4524 GetItemRect(nIndex
- 1, &rect
, 0);
4525 rect
.top
= rect
.bottom
- 2;
4529 CBrush
* pBrushOld
= pDC
->SelectObject(pBrush
);
4530 pDC
->PatBlt(rect
.left
, rect
.top
, rect
.Width(), rect
.Height(), PATINVERT
);
4531 pDC
->SelectObject(pBrushOld
);