Right align column contents
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobf5b5530d485c820f345b17c76d50ac660e32abe2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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
22 #include "stdafx.h"
23 #include "resource.h"
24 #include "GitLogListBase.h"
25 #include "IconMenu.h"
26 #include "cursor.h"
27 #include "GitProgressDlg.h"
28 #include "ProgressDlg.h"
29 #include "MessageBox.h"
30 #include "registry.h"
31 #include "LoglistUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
34 #include "IconMenu.h"
35 #include "GitStatus.h"
36 #include "..\TortoiseShell\Resource.h"
37 #include "FindDlg.h"
39 template < typename Cont, typename Pred>
40 void for_each(Cont& c, Pred p)
42 std::for_each(cbegin(c), cend(c), p);
45 template<typename T>
46 using const_iterator = typename T::const_iterator;
48 template <typename Cont, typename Pred>
49 const_iterator<Cont> find_if(Cont& c, Pred p)
51 return std::find_if(cbegin(c), cend(c), p);
54 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
55 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
56 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
58 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
60 CGitLogListBase::CGitLogListBase():CHintListCtrl()
61 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
62 ,m_nSearchIndex(0)
63 ,m_bNoDispUpdates(FALSE)
64 , m_bThreadRunning(FALSE)
65 , m_bStrictStopped(false)
66 , m_SelectedFilters(LOGFILTER_ALL)
67 , m_ShowFilter(FILTERSHOW_ALL)
68 , m_bShowWC(false)
69 , m_logEntries(&m_LogCache)
70 , m_pFindDialog(nullptr)
71 , m_ColumnManager(this)
72 , m_dwDefaultColumns(0)
73 , m_arShownList(&m_critSec)
74 , m_hasWC(true)
75 , m_bNoHightlightHead(FALSE)
76 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
77 , m_bFullCommitMessageOnLogLine(false)
78 , m_OldTopIndex(-1)
79 , m_AsyncThreadRunning(FALSE)
80 , m_AsyncThreadExit(FALSE)
81 , m_bIsCherryPick(false)
83 // use the default GUI font, create a copy of it and
84 // change the copy to BOLD (leave the rest of the font
85 // the same)
86 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
87 LOGFONT lf = {0};
88 GetObject(hFont, sizeof(LOGFONT), &lf);
89 lf.lfWeight = FW_BOLD;
90 m_boldFont.CreateFontIndirect(&lf);
91 lf.lfWeight = FW_DONTCARE;
92 lf.lfItalic = TRUE;
93 m_FontItalics.CreateFontIndirect(&lf);
94 lf.lfWeight = FW_BOLD;
95 m_boldItalicsFont.CreateFontIndirect(&lf);
97 m_bShowBugtraqColumn=false;
99 m_IsIDReplaceAction=FALSE;
101 this->m_critSec.Init();
102 ResetWcRev(false);
104 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
105 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
106 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
111 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
112 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
114 m_Filter.m_NumberOfLogsScale = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT);
115 if (m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE)
117 CString key;
118 key.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR)g_Git.m_CurrentDir);
119 key.Replace(_T(':'), _T('_'));
120 CString lastSelFromDate = CRegString(key);
121 if (lastSelFromDate.GetLength() == 10)
123 CTime time = CTime(_wtoi((LPCTSTR)lastSelFromDate.Mid(0, 4)), _wtoi((LPCTSTR)lastSelFromDate.Mid(5, 2)), _wtoi((LPCTSTR)lastSelFromDate.Mid(8, 2)), 0, 0, 0);
124 m_Filter.m_From = (DWORD)time.GetTime();
127 m_Filter.m_NumberOfLogs = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
129 m_ShowMask = 0;
130 m_LoadingThread = nullptr;
132 InterlockedExchange(&m_bExitThread,FALSE);
133 m_IsOldFirst = FALSE;
134 m_IsRebaseReplaceGraph = FALSE;
136 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
138 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
140 // get short/long datetime setting from registry
141 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
142 if ( RegUseShortDateFormat )
144 m_DateFormat = DATE_SHORTDATE;
146 else
148 m_DateFormat = DATE_LONGDATE;
150 // get relative time display setting from registry
151 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
152 m_bRelativeTimes = (regRelativeTimes != 0);
153 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
155 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
156 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
157 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
158 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
159 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
160 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
161 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
163 m_ColumnRegKey=_T("log");
165 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
166 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
167 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
168 m_bFullCommitMessageOnLogLine = !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE);
170 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
171 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
173 m_AsyncDiffEvent = ::CreateEvent(nullptr, FALSE, TRUE, nullptr);
174 m_AsynDiffListLock.Init();
175 StartAsyncDiffThread();
178 int CGitLogListBase::AsyncDiffThread()
180 while(!m_AsyncThreadExit)
182 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
184 GitRevLoglist* pRev = nullptr;
185 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
187 m_AsynDiffListLock.Lock();
188 pRev = m_AsynDiffList.back();
189 m_AsynDiffList.pop_back();
190 m_AsynDiffListLock.Unlock();
192 if( pRev->m_CommitHash.IsEmpty() )
194 if(pRev->m_IsDiffFiles)
195 continue;
197 CTGitPathList& files = pRev->GetFiles(this);
198 files.Clear();
199 pRev->m_ParentHash.clear();
200 pRev->m_ParentHash.push_back(m_HeadHash);
201 g_Git.GetWorkingTreeChanges(files);
202 int& action = pRev->GetAction(this);
203 action = 0;
204 for (int j = 0; j < files.GetCount(); ++j)
205 action |= files[j].m_Action;
207 CString err;
208 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
210 MessageBox(_T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
211 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
212 return -1;
215 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
216 InterlockedExchange(&pRev->m_IsFull, TRUE);
218 pRev->GetBody().Format(IDS_FILESCHANGES, files.GetCount());
219 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
220 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
223 if (!pRev->CheckAndDiff())
224 { // fetch change file list
225 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
227 if (i < (int)m_arShownList.size())
229 GitRevLoglist* data = m_arShownList.SafeGetAt(i);
230 if(data->m_CommitHash == pRev->m_CommitHash)
232 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
233 break;
238 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
240 POSITION pos = GetFirstSelectedItemPosition();
241 int nItem = GetNextSelectedItem(pos);
243 if(nItem>=0)
245 GitRevLoglist* data = m_arShownList.SafeGetAt(nItem);
246 if(data)
247 if(data->m_CommitHash == pRev->m_CommitHash)
248 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
254 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
255 return 0;
257 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
259 if (exclusivelyShow)
260 m_ContextMenuMask &= hideMask;
261 else
262 m_ContextMenuMask &= ~hideMask;
265 CGitLogListBase::~CGitLogListBase()
267 InterlockedExchange(&m_bNoDispUpdates, TRUE);
268 this->m_arShownList.SafeRemoveAll();
270 DestroyIcon(m_hModifiedIcon);
271 DestroyIcon(m_hReplacedIcon);
272 DestroyIcon(m_hConflictedIcon);
273 DestroyIcon(m_hAddedIcon);
274 DestroyIcon(m_hDeletedIcon);
275 m_logEntries.ClearAll();
277 SafeTerminateThread();
278 SafeTerminateAsyncDiffThread();
280 if(m_AsyncDiffEvent)
281 CloseHandle(m_AsyncDiffEvent);
285 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
286 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
287 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
288 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
289 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
290 ON_WM_CONTEXTMENU()
291 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
292 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
293 ON_WM_CREATE()
294 ON_WM_DESTROY()
295 ON_MESSAGE(MSG_LOADED,OnLoad)
296 ON_WM_MEASUREITEM()
297 ON_WM_MEASUREITEM_REFLECT()
298 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
299 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
300 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
301 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
302 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
303 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
304 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
305 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
306 END_MESSAGE_MAP()
308 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
310 //if (m_nRowHeight>0)
311 lpMeasureItemStruct->itemHeight = 50;
314 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
316 PreSubclassWindow();
317 return CHintListCtrl::OnCreate(lpCreateStruct);
320 void CGitLogListBase::PreSubclassWindow()
322 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
323 // load the icons for the action columns
324 // m_Theme.Open(m_hWnd, L"ListView");
325 SetWindowTheme(m_hWnd, L"Explorer", nullptr);
326 CHintListCtrl::PreSubclassWindow();
329 CString CGitLogListBase::GetRebaseActionName(int action)
331 if (action & LOGACTIONS_REBASE_EDIT)
332 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
333 if (action & LOGACTIONS_REBASE_SQUASH)
334 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
335 if (action & LOGACTIONS_REBASE_PICK)
336 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
337 if (action & LOGACTIONS_REBASE_SKIP)
338 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
340 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
343 void CGitLogListBase::InsertGitColumn()
345 CString temp;
347 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
348 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
349 if (DWORD(regFullRowSelect))
350 exStyle |= LVS_EX_FULLROWSELECT;
351 SetExtendedStyle(exStyle);
353 // only load properties if we have a repository
354 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
355 UpdateProjectProperties();
357 static UINT normal[] =
359 IDS_LOG_GRAPH,
360 IDS_LOG_REBASE,
361 IDS_LOG_ID,
362 IDS_LOG_HASH,
363 IDS_LOG_ACTIONS,
364 IDS_LOG_MESSAGE,
365 IDS_LOG_AUTHOR,
366 IDS_LOG_DATE,
367 IDS_LOG_EMAIL,
368 IDS_LOG_COMMIT_NAME,
369 IDS_LOG_COMMIT_EMAIL,
370 IDS_LOG_COMMIT_DATE,
371 IDS_LOG_BUGIDS,
372 IDS_LOG_SVNREV,
375 static int with[] =
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
381 ICONITEMBORDER+16*4,
382 LOGLIST_MESSAGE_MIN,
383 ICONITEMBORDER+16*4,
384 ICONITEMBORDER+16*4,
385 ICONITEMBORDER+16*4,
386 ICONITEMBORDER+16*4,
387 ICONITEMBORDER+16*4,
388 ICONITEMBORDER+16*4,
389 ICONITEMBORDER+16*4,
390 ICONITEMBORDER+16*4,
392 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
394 DWORD hideColumns = 0;
395 if(this->m_IsRebaseReplaceGraph)
397 hideColumns |= GIT_LOG_GRAPH;
398 m_dwDefaultColumns |= GIT_LOG_REBASE;
400 else
401 hideColumns |= GIT_LOG_REBASE;
403 if(this->m_IsIDReplaceAction)
405 hideColumns |= GIT_LOG_ACTIONS;
406 m_dwDefaultColumns |= GIT_LOG_ID;
407 m_dwDefaultColumns |= GIT_LOG_HASH;
409 else
410 hideColumns |= GIT_LOG_ID;
411 if(this->m_bShowBugtraqColumn)
412 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
413 else
414 hideColumns |= GIT_LOGLIST_BUG;
415 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
416 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
417 else
418 hideColumns |= GIT_LOGLIST_SVNREV;
419 SetRedraw(false);
421 m_ColumnManager.SetNames(normal, _countof(normal));
422 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
423 m_ColumnManager.SetRightAlign(2);
425 SetRedraw(true);
429 * Resizes all columns in a list control to values in registry.
431 void CGitLogListBase::ResizeAllListCtrlCols()
433 // column max and min widths to allow
434 static const int nMinimumWidth = 10;
435 static const int nMaximumWidth = 1000;
436 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
437 if (pHdrCtrl)
439 int numcols = pHdrCtrl->GetItemCount();
440 for (int col = 0; col < numcols; ++col)
442 // get width for this col last time from registry
443 CString regentry;
444 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR)m_ColumnRegKey, col);
445 CRegDWORD regwidth(regentry, 0);
446 int cx = regwidth;
447 if ( cx == 0 )
449 // no saved value, setup sensible defaults
450 if (col == this->LOGLIST_MESSAGE)
451 cx = LOGLIST_MESSAGE_MIN;
452 else
453 cx = ICONITEMBORDER+16*4;
455 if (cx < nMinimumWidth)
456 cx = nMinimumWidth;
457 else if (cx > nMaximumWidth)
458 cx = nMaximumWidth;
460 SetColumnWidth(col, cx);
465 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
467 LVITEM rItem = { 0 };
468 rItem.mask = LVIF_STATE;
469 rItem.iItem = (int)Index;
470 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
471 GetItem(&rItem);
473 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(Index);
474 HBRUSH brush = nullptr;
476 if (!(rItem.state & LVIS_SELECTED))
478 int action = pLogEntry->GetRebaseAction();
479 if (action & LOGACTIONS_REBASE_SQUASH)
480 brush = ::CreateSolidBrush(RGB(156,156,156));
481 else if (action & LOGACTIONS_REBASE_EDIT)
482 brush = ::CreateSolidBrush(RGB(200,200,128));
484 else if (!IsAppThemed())
486 if (rItem.state & LVIS_SELECTED)
488 if (::GetFocus() == m_hWnd)
489 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
490 else
491 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
494 if (brush)
496 ::FillRect(hdc, &rect, brush);
497 ::DeleteObject(brush);
501 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
503 POINT point = { 4, 4 };
504 CRect rt2 = rect;
505 rt2.DeflateRect(1, 1);
506 rt2.OffsetRect(2, 2);
508 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
509 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
510 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
511 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
512 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
514 ::SelectObject(hdc, brush);
515 rt2.OffsetRect(-2, -2);
516 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
517 ::SelectObject(hdc, oldbrush);
518 ::SelectObject(hdc, oldpen);
519 ::DeleteObject(nullPen);
520 ::DeleteObject(darkBrush);
523 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
525 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
526 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
527 ::MoveToEx(hdc, rect.left + 7, rect.top, nullptr);
528 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
529 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
530 ::LineTo(hdc, rect.left, rect.bottom);
531 ::SelectObject(hdc, oldpen);
532 ::DeleteObject(pen);
535 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
537 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
538 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
539 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, nullptr);
540 ::LineTo(hdc, rect.left, rect.bottom);
541 ::LineTo(hdc, rect.right, rect.bottom);
542 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
543 ::SelectObject(hdc, oldpen);
544 ::DeleteObject(pen);
547 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
549 GitRevLoglist* data = m_arShownList.SafeGetAt(index);
550 CRect rt=rect;
551 LVITEM rItem = { 0 };
552 rItem.mask = LVIF_STATE;
553 rItem.iItem = (int)index;
554 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
555 GetItem(&rItem);
557 CDC W_Dc;
558 W_Dc.Attach(hdc);
560 HTHEME hTheme = nullptr;
561 if (IsAppThemed())
562 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
564 SIZE oneSpaceSize;
565 if (m_bTagsBranchesOnRightSide)
567 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
568 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
569 SelectObject(hdc, oldFont);
570 rt.left += oneSpaceSize.cx * 2;
572 else
574 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
575 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
576 rt.left += oneSpaceSize.cx;
579 CString msg = MessageDisplayStr(data);
580 int action = data->GetRebaseAction();
581 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
582 if (IsAppThemed())
584 int txtState = LISS_NORMAL;
585 if (rItem.state & LVIS_SELECTED)
586 txtState = LISS_SELECTED;
588 DTTOPTS opts = { 0 };
589 opts.dwSize = sizeof(opts);
590 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
591 opts.dwFlags = DTT_TEXTCOLOR;
592 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, msg, -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
594 else
596 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
598 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
599 ::DrawText(hdc,msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
600 ::SetTextColor(hdc, clrOld);
602 else
604 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
605 ::DrawText(hdc, msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
606 ::SetTextColor(hdc, clrOld);
610 if (m_bTagsBranchesOnRightSide)
612 SIZE size;
613 GetTextExtentPoint32(hdc, msg, msg.GetLength(), &size);
615 rt.left += oneSpaceSize.cx + size.cx;
617 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
620 if (hTheme)
621 CloseThemeData(hTheme);
623 W_Dc.Detach();
626 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
628 for (unsigned int i = 0; i < refList.size(); ++i)
630 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
631 HBRUSH brush = 0;
632 COLORREF colRef = refList[i].color;
633 bool singleRemote = refList[i].singleRemote;
634 bool hasTracking = refList[i].hasTracking;
635 bool sameName = refList[i].sameName;
636 CGit::REF_TYPE refType = refList[i].refType;
638 //When row selected, ajust label color
639 if (!IsAppThemed())
641 if (rItem.state & LVIS_SELECTED)
642 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
645 brush = ::CreateSolidBrush(colRef);
647 if (!shortname.IsEmpty() && (rt.left < rect.right))
649 SIZE size = { 0 };
650 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
652 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
653 rt.right += 8;
655 int textpos = DT_CENTER;
657 if (rt.right > rect.right)
659 rt.right = rect.right;
660 textpos = 0;
663 CRect textRect = rt;
665 if (singleRemote)
667 rt.right += 8;
668 textRect.OffsetRect(8, 0);
671 if (sameName)
672 rt.right += 8;
674 if (hasTracking)
675 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
676 else
678 //Fill interior of ref label
679 ::FillRect(hdc, &rt, brush);
682 //Draw edge of label
683 CRect rectEdge = rt;
685 if (!hasTracking)
687 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
688 rectEdge.DeflateRect(1, 1);
689 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
692 if (refType == CGit::REF_TYPE::ANNOTATED_TAG)
694 rt.right += 8;
695 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
696 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
697 ::FillRgn(hdc, hrgn, brush);
698 ::DeleteObject(hrgn);
699 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, nullptr);
700 HPEN pen;
701 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
702 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
703 ::DeleteObject(pen);
704 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
705 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
706 ::DeleteObject(pen);
707 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
708 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, nullptr);
709 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
710 ::DeleteObject(pen);
711 SelectObject(hdc, oldpen);
714 //Draw text inside label
715 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
716 if (!customColor && IsAppThemed())
718 int txtState = LISS_NORMAL;
719 if (rItem.state & LVIS_SELECTED)
720 txtState = LISS_SELECTED;
722 DTTOPTS opts = { 0 };
723 opts.dwSize = sizeof(opts);
724 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
725 opts.dwFlags = DTT_TEXTCOLOR;
726 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
728 else
730 W_Dc.SetBkMode(TRANSPARENT);
731 if (customColor || (rItem.state & LVIS_SELECTED))
733 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
734 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
735 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
736 ::SetTextColor(hdc,clrOld);
738 else
740 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
741 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
742 ::SetTextColor(hdc, clrOld);
746 if (singleRemote)
748 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
749 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
750 CRect newRect;
751 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
752 DrawLightning(hdc, newRect, color, bold);
755 if (sameName)
757 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
758 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
759 CRect newRect;
760 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
761 DrawUpTriangle(hdc, newRect, color, bold);
764 m_RefLabelPosMap[refList[i].fullName] = rt;
766 rt.left = rt.right + 1;
768 if (brush)
769 ::DeleteObject(brush);
771 rt.right = rect.right;
774 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
775 // Returns ((256 - amount)*col1 + amount*col2) / 256;
776 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
777 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
778 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
781 Gdiplus::Color GetGdiColor(COLORREF col)
783 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
785 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
786 const COLORREF& col,const COLORREF& activeColor, int top
789 int h = laneHeight / 2;
790 int m = (x1 + x2) / 2;
791 int r = (x2 - x1) * m_NodeSize / 30;
792 int d = 2 * r;
794 #define P_CENTER m , h+top
795 #define P_0 x2, h+top
796 #define P_90 m , 0+top-1
797 #define P_180 x1, h+top
798 #define P_270 m , 2 * h+top +1
799 #define R_CENTER m - r, h - r+top, d, d
802 #define DELTA_UR_B 2*(x1 - m), 2*h +top
803 #define DELTA_UR_E 0*16, 90*16 +top // -,
805 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
806 #define DELTA_DR_E 270*16, 90*16 +top // -'
808 #define DELTA_UL_B 2*(x2 - m), 2*h +top
809 #define DELTA_UL_E 90*16, 90*16 +top // ,-
811 #define DELTA_DL_B 2*(x2 - m),2*-h +top
812 #define DELTA_DL_E 180*16, 90*16 // '-
814 #define CENTER_UR x1, 2*h, 225
815 #define CENTER_DR x1, 0 , 135
816 #define CENTER_UL x2, 2*h, 315
817 #define CENTER_DL x2, 0 , 45
820 Gdiplus::Graphics graphics( hdc );
822 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
824 // arc
825 switch (type) {
826 case Lanes::JOIN:
827 case Lanes::JOIN_R:
828 case Lanes::HEAD:
829 case Lanes::HEAD_R:
831 Gdiplus::LinearGradientBrush gradient(
832 Gdiplus::Point(x1-2, h+top-2),
833 Gdiplus::Point(P_270),
834 GetGdiColor(activeColor),GetGdiColor(col));
837 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
838 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
840 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
841 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
842 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
844 break;
846 case Lanes::JOIN_L:
848 Gdiplus::LinearGradientBrush gradient(
849 Gdiplus::Point(P_270),
850 Gdiplus::Point(x2+1, h+top-1),
851 GetGdiColor(col),GetGdiColor(activeColor));
854 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
855 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
857 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
858 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
859 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
862 break;
864 case Lanes::TAIL:
865 case Lanes::TAIL_R:
867 Gdiplus::LinearGradientBrush gradient(
868 Gdiplus::Point(x1-2, h+top-2),
869 Gdiplus::Point(P_90),
870 GetGdiColor(activeColor),GetGdiColor(col));
872 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
874 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
876 #if 0
877 QConicalGradient gradient(CENTER_DR);
878 gradient.setColorAt(0.375, activeCol);
879 gradient.setColorAt(0.625, col);
880 myPen.setBrush(gradient);
881 p->setPen(myPen);
882 p->drawArc(P_CENTER, DELTA_DR);
883 #endif
884 break;
886 default:
887 break;
891 //static QPen myPen(Qt::black, 2); // fast path here
892 CPen pen;
893 pen.CreatePen(PS_SOLID,2,col);
894 //myPen.setColor(col);
895 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
897 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
899 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
901 //p->setPen(myPen);
903 // vertical line
904 switch (type) {
905 case Lanes::ACTIVE:
906 case Lanes::NOT_ACTIVE:
907 case Lanes::MERGE_FORK:
908 case Lanes::MERGE_FORK_R:
909 case Lanes::MERGE_FORK_L:
910 case Lanes::JOIN:
911 case Lanes::JOIN_R:
912 case Lanes::JOIN_L:
913 case Lanes::CROSS:
914 //DrawLine(hdc,P_90,P_270);
915 graphics.DrawLine(&myPen,P_90,P_270);
916 //p->drawLine(P_90, P_270);
917 break;
918 case Lanes::HEAD_L:
919 case Lanes::BRANCH:
920 //DrawLine(hdc,P_CENTER,P_270);
921 graphics.DrawLine(&myPen,P_CENTER,P_270);
922 //p->drawLine(P_CENTER, P_270);
923 break;
924 case Lanes::TAIL_L:
925 case Lanes::INITIAL:
926 case Lanes::BOUNDARY:
927 case Lanes::BOUNDARY_C:
928 case Lanes::BOUNDARY_R:
929 case Lanes::BOUNDARY_L:
930 //DrawLine(hdc,P_90, P_CENTER);
931 graphics.DrawLine(&myPen,P_90,P_CENTER);
932 //p->drawLine(P_90, P_CENTER);
933 break;
934 default:
935 break;
938 myPen.SetColor(GetGdiColor(activeColor));
940 // horizontal line
941 switch (type) {
942 case Lanes::MERGE_FORK:
943 case Lanes::JOIN:
944 case Lanes::HEAD:
945 case Lanes::TAIL:
946 case Lanes::CROSS:
947 case Lanes::CROSS_EMPTY:
948 case Lanes::BOUNDARY_C:
949 //DrawLine(hdc,P_180,P_0);
950 graphics.DrawLine(&myPen,P_180,P_0);
951 //p->drawLine(P_180, P_0);
952 break;
953 case Lanes::MERGE_FORK_R:
954 case Lanes::BOUNDARY_R:
955 //DrawLine(hdc,P_180,P_CENTER);
956 graphics.DrawLine(&myPen,P_180,P_CENTER);
957 //p->drawLine(P_180, P_CENTER);
958 break;
959 case Lanes::MERGE_FORK_L:
960 case Lanes::HEAD_L:
961 case Lanes::TAIL_L:
962 case Lanes::BOUNDARY_L:
963 //DrawLine(hdc,P_CENTER,P_0);
964 graphics.DrawLine(&myPen,P_CENTER,P_0);
965 //p->drawLine(P_CENTER, P_0);
966 break;
967 default:
968 break;
971 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
973 CBrush brush;
974 brush.CreateSolidBrush(col);
975 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
977 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
978 // center symbol, e.g. rect or ellipse
979 switch (type) {
980 case Lanes::ACTIVE:
981 case Lanes::INITIAL:
982 case Lanes::BRANCH:
984 //p->setPen(Qt::NoPen);
985 //p->setBrush(col);
986 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
987 graphics.FillEllipse(&myBrush, R_CENTER);
988 //p->drawEllipse(R_CENTER);
989 break;
990 case Lanes::MERGE_FORK:
991 case Lanes::MERGE_FORK_R:
992 case Lanes::MERGE_FORK_L:
993 //p->setPen(Qt::NoPen);
994 //p->setBrush(col);
995 //p->drawRect(R_CENTER);
996 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
997 graphics.FillRectangle(&myBrush, R_CENTER);
998 break;
999 case Lanes::UNAPPLIED:
1000 // Red minus sign
1001 //p->setPen(Qt::NoPen);
1002 //p->setBrush(Qt::red);
1003 //p->drawRect(m - r, h - 1, d, 2);
1004 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1005 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1006 break;
1007 case Lanes::APPLIED:
1008 // Green plus sign
1009 //p->setPen(Qt::NoPen);
1010 //p->setBrush(DARK_GREEN);
1011 //p->drawRect(m - r, h - 1, d, 2);
1012 //p->drawRect(m - 1, h - r, 2, d);
1013 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1014 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1015 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1016 break;
1017 case Lanes::BOUNDARY:
1018 //p->setBrush(back);
1019 //p->drawEllipse(R_CENTER);
1020 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1021 graphics.DrawEllipse(&myPen, R_CENTER);
1022 break;
1023 case Lanes::BOUNDARY_C:
1024 case Lanes::BOUNDARY_R:
1025 case Lanes::BOUNDARY_L:
1026 //p->setBrush(back);
1027 //p->drawRect(R_CENTER);
1028 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1029 graphics.FillRectangle(&myBrush,R_CENTER);
1030 break;
1031 default:
1032 break;
1035 ::SelectObject(hdc,oldpen);
1036 ::SelectObject(hdc,oldbrush);
1037 #undef P_CENTER
1038 #undef P_0
1039 #undef P_90
1040 #undef P_180
1041 #undef P_270
1042 #undef R_CENTER
1045 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1047 // TODO: unfinished
1048 // return;
1049 GitRevLoglist* data = m_arShownList.SafeGetAt(index);
1050 if(data->m_CommitHash.IsEmpty())
1051 return;
1053 CRect rt=rect;
1054 LVITEM rItem = { 0 };
1055 rItem.mask = LVIF_STATE;
1056 rItem.iItem = (int)index;
1057 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1058 GetItem(&rItem);
1060 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1062 if (data->m_Lanes.empty())
1063 m_logEntries.setLane(data->m_CommitHash);
1065 std::vector<int>& lanes=data->m_Lanes;
1066 size_t laneNum = lanes.size();
1067 UINT activeLane = 0;
1068 for (UINT i = 0; i < laneNum; ++i)
1069 if (Lanes::isMerge(lanes[i])) {
1070 activeLane = i;
1071 break;
1074 int x2 = 0;
1075 int maxWidth = rect.Width();
1076 int lw = 3 * rect.Height() / 4; //laneWidth()
1078 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1079 //if (opt.state & QStyle::State_Selected)
1080 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1082 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1084 int x1 = x2;
1085 x2 += lw;
1087 int ln = lanes[i];
1088 if (ln == Lanes::EMPTY)
1089 continue;
1091 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1092 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1095 #if 0
1096 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1097 int x1 = x2;
1098 x2 += lw;
1100 int ln = lanes[i];
1101 if (ln == Lanes::EMPTY)
1102 continue;
1104 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1105 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1107 if (ln == Lanes::CROSS)
1109 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1110 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1112 else
1113 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1115 #endif
1118 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1120 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1121 // Take the default processing unless we set this to something else below.
1122 *pResult = CDRF_DODEFAULT;
1124 if (m_bNoDispUpdates)
1125 return;
1127 switch (pLVCD->nmcd.dwDrawStage)
1129 case CDDS_PREPAINT:
1131 *pResult = CDRF_NOTIFYITEMDRAW;
1132 return;
1134 break;
1135 case CDDS_ITEMPREPAINT:
1137 // This is the prepaint stage for an item. Here's where we set the
1138 // item's text color.
1140 // Tell Windows to send draw notifications for each subitem.
1141 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1143 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1145 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec)
1147 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1148 if (data)
1150 HGDIOBJ hGdiObj = nullptr;
1151 int action = data->GetRebaseAction();
1152 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1153 crText = RGB(128,128,128);
1155 if (action & LOGACTIONS_REBASE_SQUASH)
1156 pLVCD->clrTextBk = RGB(156,156,156);
1157 else if (action & LOGACTIONS_REBASE_EDIT)
1158 pLVCD->clrTextBk = RGB(200,200,128);
1159 else
1160 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1162 if (action & LOGACTIONS_REBASE_CURRENT)
1163 hGdiObj = m_boldFont.GetSafeHandle();
1165 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1166 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1167 if (isHeadHash && isHighlight)
1168 hGdiObj = m_boldItalicsFont.GetSafeHandle();
1169 else if (isHeadHash)
1170 hGdiObj = m_boldFont.GetSafeHandle();
1171 else if (isHighlight)
1172 hGdiObj = m_FontItalics.GetSafeHandle();
1174 if (hGdiObj)
1176 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1177 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1180 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1181 // crText = GetSysColor(COLOR_GRAYTEXT);
1183 if (data->m_CommitHash.IsEmpty())
1185 //crText = GetSysColor(RGB(200,200,0));
1186 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1187 // We changed the font, so we're returning CDRF_NEWFONT. This
1188 // tells the control to recalculate the extent of the text.
1189 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1193 if (m_arShownList.size() == pLVCD->nmcd.dwItemSpec)
1195 if (m_bStrictStopped)
1196 crText = GetSysColor(COLOR_GRAYTEXT);
1198 // Store the color back in the NMLVCUSTOMDRAW struct.
1199 pLVCD->clrText = crText;
1200 return;
1202 break;
1203 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1205 if (m_bStrictStopped && m_arShownList.size() == pLVCD->nmcd.dwItemSpec)
1207 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1210 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1212 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec && !this->m_IsRebaseReplaceGraph)
1214 CRect rect;
1215 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1217 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1218 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1220 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1221 if( !data ->m_CommitHash.IsEmpty())
1222 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1224 *pResult = CDRF_SKIPDEFAULT;
1225 return;
1229 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1231 // If the top index of list is changed, the position map of reference label is outdated.
1232 if (m_OldTopIndex != GetTopIndex())
1234 m_OldTopIndex = GetTopIndex();
1235 m_RefLabelPosMap.clear();
1238 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec)
1240 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1242 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1244 CRect rect;
1245 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1247 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1248 // not in FillBackGround method, because this only affected the message subitem
1249 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1250 return;
1252 int index = (int)pLVCD->nmcd.dwItemSpec;
1253 int state = GetItemState(index, LVIS_SELECTED);
1254 int txtState = LISS_NORMAL;
1255 if (IsAppThemed() && GetHotItem() == (int)index)
1257 if (state & LVIS_SELECTED)
1258 txtState = LISS_HOTSELECTED;
1259 else
1260 txtState = LISS_HOT;
1262 else if (state & LVIS_SELECTED)
1264 if (::GetFocus() == m_hWnd)
1265 txtState = LISS_SELECTED;
1266 else
1267 txtState = LISS_SELECTEDNOTFOCUS;
1270 HTHEME hTheme = nullptr;
1271 if (IsAppThemed())
1272 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1274 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1275 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1276 else
1278 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1279 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1280 ::DeleteObject(brush);
1282 if (hTheme)
1284 CRect rt;
1285 // get rect of whole line
1286 GetItemRect(index, rt, LVIR_BOUNDS);
1287 CRect rect2 = rect;
1288 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1289 rect2.DeflateRect(1, 1, 1, 1);
1291 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1292 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1294 CloseThemeData(hTheme);
1296 // END: extended redraw
1298 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1300 std::vector<REFLABEL> refsToShow;
1301 STRING_VECTOR remoteTrackingList;
1302 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1303 for (unsigned int i = 0; i < refList.size(); ++i)
1305 CString str = refList[i];
1307 REFLABEL refLabel;
1308 refLabel.color = RGB(255, 255, 255);
1309 refLabel.singleRemote = false;
1310 refLabel.hasTracking = false;
1311 refLabel.sameName = false;
1312 refLabel.name = CGit::GetShortName(str, &refLabel.refType);
1313 refLabel.fullName = str;
1315 switch (refLabel.refType)
1317 case CGit::REF_TYPE::LOCAL_BRANCH:
1319 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1320 continue;
1321 if (refLabel.name == m_CurrentBranch)
1322 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1323 else
1324 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1326 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1327 CString pullRemote = trackingEntry.first;
1328 CString pullBranch = trackingEntry.second;
1329 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1331 CString defaultUpstream;
1332 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1333 refLabel.hasTracking = true;
1334 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1336 bool found = false;
1337 for (size_t j = i + 1; j < refList.size(); ++j)
1339 if (refList[j] == defaultUpstream)
1341 found = true;
1342 break;
1346 if (found)
1348 bool sameName = pullBranch == refLabel.name;
1349 refsToShow.push_back(refLabel);
1350 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1351 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1352 if (m_bSymbolizeRefNames)
1354 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1356 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1357 refLabel.singleRemote = true;
1359 else if (sameName)
1360 refLabel.simplifiedName = pullRemote + _T("/");
1361 refLabel.sameName = sameName;
1363 refLabel.fullName = defaultUpstream;
1364 refsToShow.push_back(refLabel);
1365 remoteTrackingList.push_back(defaultUpstream);
1366 continue;
1370 break;
1372 case CGit::REF_TYPE::REMOTE_BRANCH:
1374 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1375 continue;
1376 bool found = false;
1377 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1379 if (remoteTrackingList[j] == str)
1381 found = true;
1382 break;
1385 if (found)
1386 continue;
1388 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1389 if (m_bSymbolizeRefNames)
1391 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1393 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1394 refLabel.singleRemote = true;
1397 break;
1399 case CGit::REF_TYPE::ANNOTATED_TAG:
1400 case CGit::REF_TYPE::TAG:
1401 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1402 continue;
1403 refLabel.color = m_Colors.GetColor(CColors::Tag);
1404 break;
1405 case CGit::REF_TYPE::STASH:
1406 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1407 continue;
1408 refLabel.color = m_Colors.GetColor(CColors::Stash);
1409 break;
1410 case CGit::REF_TYPE::BISECT_GOOD:
1411 case CGit::REF_TYPE::BISECT_BAD:
1412 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1413 continue;
1414 refLabel.color = (refLabel.refType == CGit::REF_TYPE::BISECT_GOOD) ? m_Colors.GetColor(CColors::BisectGood): m_Colors.GetColor(CColors::BisectBad);
1415 break;
1416 default:
1417 continue;
1419 refsToShow.push_back(refLabel);
1422 if (refsToShow.empty())
1424 *pResult = CDRF_DODEFAULT;
1425 return;
1428 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1430 *pResult = CDRF_SKIPDEFAULT;
1431 return;
1438 if (pLVCD->iSubItem == LOGLIST_ACTION)
1440 if(this->m_IsIDReplaceAction)
1442 *pResult = CDRF_DODEFAULT;
1443 return;
1445 *pResult = CDRF_DODEFAULT;
1447 if (m_arShownList.size() <= pLVCD->nmcd.dwItemSpec)
1448 return;
1450 int nIcons = 0;
1451 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1452 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1454 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1455 CRect rect;
1456 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1457 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1458 // Get the selected state of the
1459 // item being drawn.
1461 // Fill the background if necessary
1462 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1464 // Draw the icon(s) into the compatible DC
1465 int action = pLogEntry->GetAction(this);
1466 if (!pLogEntry->m_IsDiffFiles)
1468 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1469 *pResult = CDRF_SKIPDEFAULT;
1470 return;
1473 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1474 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1475 ++nIcons;
1477 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1478 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1479 ++nIcons;
1481 if (action & CTGitPath::LOGACTIONS_DELETED)
1482 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1483 ++nIcons;
1485 if (action & CTGitPath::LOGACTIONS_REPLACED)
1486 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1487 ++nIcons;
1489 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1490 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1491 ++nIcons;
1493 *pResult = CDRF_SKIPDEFAULT;
1494 return;
1497 break;
1499 *pResult = CDRF_DODEFAULT;
1502 CString FindSVNRev(const CString& msg)
1506 const std::tr1::wsregex_iterator end;
1507 std::wstring s = msg;
1508 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1509 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex1); it != end; ++it)
1511 const std::tr1::wsmatch match = *it;
1512 if (match.size() == 4)
1514 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1515 return std::wstring(match[2]).c_str();
1518 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1519 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex2); it != end; ++it)
1521 const std::tr1::wsmatch match = *it;
1522 if (match.size() == 3)
1524 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1525 return std::wstring(match[1]).c_str();
1529 catch (std::exception) {}
1531 return _T("");
1534 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1536 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1537 return pLogEntry->GetSubject();
1539 CString txt(pLogEntry->GetSubject());
1540 txt += _T(' ');
1541 txt += pLogEntry->GetBody();
1543 // Deal with CRLF
1544 txt.Replace(_T('\n'), _T(' '));
1545 txt.Replace(_T('\r'), _T(' '));
1547 return txt;
1550 // CGitLogListBase message handlers
1552 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1554 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1556 // Create a pointer to the item
1557 LV_ITEM* pItem = &(pDispInfo)->item;
1559 // Do the list need text information?
1560 if (!(pItem->mask & LVIF_TEXT))
1561 return;
1563 // By default, clear text buffer.
1564 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1566 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1568 *pResult = 0;
1569 if (m_bNoDispUpdates || bOutOfRange)
1570 return;
1572 // Which item number?
1573 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem);
1575 CString temp;
1576 if(m_IsOldFirst)
1577 temp.Format(_T("%d"),pItem->iItem+1);
1578 else
1579 temp.Format(_T("%d"), m_arShownList.size() - pItem->iItem);
1581 // Which column?
1582 switch (pItem->iSubItem)
1584 case LOGLIST_GRAPH: //Graphic
1585 break;
1586 case LOGLIST_REBASE:
1588 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1589 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1591 break;
1592 case LOGLIST_ACTION: //action -- no text in the column
1593 break;
1594 case LOGLIST_HASH:
1595 if(pLogEntry)
1596 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1597 break;
1598 case LOGLIST_ID:
1599 if(this->m_IsIDReplaceAction)
1600 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1601 break;
1602 case LOGLIST_MESSAGE: //Message
1603 if (pLogEntry)
1604 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1605 break;
1606 case LOGLIST_AUTHOR: //Author
1607 if (pLogEntry)
1608 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1609 break;
1610 case LOGLIST_DATE: //Date
1611 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1612 lstrcpyn(pItem->pszText,
1613 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1614 pItem->cchTextMax - 1);
1615 break;
1617 case LOGLIST_EMAIL:
1618 if (pLogEntry)
1619 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1620 break;
1622 case LOGLIST_COMMIT_NAME: //Commit
1623 if (pLogEntry)
1624 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1625 break;
1627 case LOGLIST_COMMIT_EMAIL: //Commit Email
1628 if (pLogEntry)
1629 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1630 break;
1632 case LOGLIST_COMMIT_DATE: //Commit Date
1633 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1634 lstrcpyn(pItem->pszText,
1635 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1636 pItem->cchTextMax - 1);
1637 break;
1638 case LOGLIST_BUG: //Bug ID
1639 if(pLogEntry)
1640 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1641 break;
1642 case LOGLIST_SVNREV: //SVN revision
1643 if (pLogEntry)
1644 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1645 break;
1647 default:
1648 ASSERT(false);
1652 bool CGitLogListBase::IsOnStash(int index)
1654 GitRevLoglist* rev = m_arShownList.SafeGetAt(index);
1655 if (IsStash(rev))
1656 return true;
1657 if (index > 0)
1659 GitRevLoglist* preRev = m_arShownList.SafeGetAt(index - 1);
1660 if (IsStash(preRev))
1661 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1663 return false;
1666 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1668 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1670 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1671 return true;
1673 return false;
1676 bool CGitLogListBase::IsBisect(const GitRev * pSelLogEntry)
1678 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1680 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Left(12) == _T("refs/bisect/"))
1681 return true;
1683 return false;
1686 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1688 if (pRev->m_ParentHash.empty())
1690 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1691 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1693 parentHash = pRev->m_ParentHash;
1696 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1698 if (pWnd == GetHeaderCtrl())
1699 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1701 int selIndex = GetSelectionMark();
1702 if (selIndex < 0)
1703 return; // nothing selected, nothing to do with a context menu
1705 // if the user selected the info text telling about not all revisions shown due to
1706 // the "stop on copy/rename" option, we also don't show the context menu
1707 if (m_bStrictStopped && selIndex == (int)m_arShownList.size())
1708 return;
1710 // if the context menu is invoked through the keyboard, we have to use
1711 // a calculated position on where to anchor the menu on
1712 if ((point.x == -1) && (point.y == -1))
1714 CRect rect;
1715 GetItemRect(selIndex, &rect, LVIR_LABEL);
1716 ClientToScreen(&rect);
1717 point = rect.CenterPoint();
1719 m_nSearchIndex = selIndex;
1720 m_bCancelled = FALSE;
1722 // calculate some information the context menu commands can use
1723 // CString pathURL = GetURLFromPath(m_path);
1725 POSITION pos = GetFirstSelectedItemPosition();
1726 int indexNext = GetNextSelectedItem(pos);
1727 if (indexNext < 0)
1728 return;
1730 GitRevLoglist* pSelLogEntry = m_arShownList.SafeGetAt(indexNext);
1731 if (pSelLogEntry == nullptr)
1732 return;
1733 #if 0
1734 GitRev revSelected = pSelLogEntry->Rev;
1735 GitRev revPrevious = git_revnum_t(revSelected)-1;
1736 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1738 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1740 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1741 if (changedpath->lCopyFromRev)
1742 revPrevious = changedpath->lCopyFromRev;
1745 GitRev revSelected2;
1746 if (pos)
1748 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1749 revSelected2 = pLogEntry->Rev;
1751 bool bAllFromTheSameAuthor = true;
1752 CString firstAuthor;
1753 CLogDataVector selEntries;
1754 GitRev revLowest, revHighest;
1755 GitRevRangeArray revisionRanges;
1757 POSITION pos = GetFirstSelectedItemPosition();
1758 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1759 revisionRanges.AddRevision(pLogEntry->Rev);
1760 selEntries.push_back(pLogEntry);
1761 firstAuthor = pLogEntry->sAuthor;
1762 revLowest = pLogEntry->Rev;
1763 revHighest = pLogEntry->Rev;
1764 while (pos)
1766 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1767 revisionRanges.AddRevision(pLogEntry->Rev);
1768 selEntries.push_back(pLogEntry);
1769 if (firstAuthor.Compare(pLogEntry->sAuthor))
1770 bAllFromTheSameAuthor = false;
1771 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1772 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1776 #endif
1778 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1780 int FirstSelect=-1, LastSelect=-1;
1781 pos = GetFirstSelectedItemPosition();
1782 FirstSelect = GetNextSelectedItem(pos);
1783 while(pos)
1785 LastSelect = GetNextSelectedItem(pos);
1787 //entry is selected, now show the popup menu
1788 CIconMenu popup;
1789 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1791 if (popup.CreatePopupMenu())
1793 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1794 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1795 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1796 bool isStash = IsOnStash(indexNext);
1797 GIT_REV_LIST parentHash;
1798 GetParentHashes(pSelLogEntry, parentHash);
1800 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1801 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1803 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))
1804 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1806 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1807 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1809 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1810 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1812 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)))
1813 popup.AppendMenu(MF_SEPARATOR, NULL);
1815 if (GetSelectedCount() == 1)
1818 bool requiresSeparator = false;
1819 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1821 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1823 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1824 requiresSeparator = true;
1827 else
1829 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1831 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1832 requiresSeparator = true;
1834 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1836 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1837 requiresSeparator = true;
1841 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1843 if (parentHash.size() == 1)
1845 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1846 requiresSeparator = true;
1848 else if (parentHash.size() > 1)
1850 blamemenu.CreatePopupMenu();
1851 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1852 for (size_t i = 0; i < parentHash.size(); ++i)
1854 CString str;
1855 str.Format(IDS_PARENT, i + 1);
1856 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1858 requiresSeparator = true;
1862 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1864 if (parentHash.size() == 1)
1866 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1867 requiresSeparator = true;
1869 else if (parentHash.size() > 1)
1871 gnudiffmenu.CreatePopupMenu();
1872 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1874 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1875 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1876 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1878 for (size_t i = 0; i < parentHash.size(); ++i)
1880 CString str;
1881 str.Format(IDS_PARENT, i + 1);
1882 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1884 requiresSeparator = true;
1888 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1890 if (parentHash.size() == 1)
1892 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1893 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1894 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1895 requiresSeparator = true;
1897 else if (parentHash.size() > 1)
1899 diffmenu.CreatePopupMenu();
1900 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1901 for (size_t i = 0; i < parentHash.size(); ++i)
1903 CString str;
1904 str.Format(IDS_PARENT, i + 1);
1905 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1906 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1908 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1909 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1912 requiresSeparator = true;
1916 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1918 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1919 requiresSeparator = true;
1922 if (requiresSeparator)
1924 popup.AppendMenu(MF_SEPARATOR, NULL);
1925 requiresSeparator = false;
1928 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1930 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1932 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1933 requiresSeparator = true;
1937 if ((pSelLogEntry->m_CommitHash.IsEmpty() || isStash) && CTGitPath(g_Git.m_CurrentDir).HasStashDir())
1939 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1941 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1942 requiresSeparator = true;
1945 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1947 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1948 requiresSeparator = true;
1952 if (requiresSeparator)
1954 popup.AppendMenu(MF_SEPARATOR, NULL);
1955 requiresSeparator = false;
1958 if (CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1960 GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect);
1961 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTGOOD) && !IsBisect(pFirstEntry))
1963 popup.AppendMenuIcon(ID_BISECTGOOD, IDS_MENUBISECTGOOD, IDI_THUMB_UP);
1964 requiresSeparator = true;
1967 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTBAD) && !IsBisect(pFirstEntry))
1969 popup.AppendMenuIcon(ID_BISECTBAD, IDS_MENUBISECTBAD, IDI_THUMB_DOWN);
1970 requiresSeparator = true;
1974 if (pSelLogEntry->m_CommitHash.IsEmpty() && CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1976 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTRESET))
1978 popup.AppendMenuIcon(ID_BISECTRESET, IDS_MENUBISECTRESET, IDI_BISECT_RESET);
1979 requiresSeparator = true;
1983 if (requiresSeparator)
1985 popup.AppendMenu(MF_SEPARATOR, NULL);
1986 requiresSeparator = false;
1989 if (pSelLogEntry->m_CommitHash.IsEmpty())
1991 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1992 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1994 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1995 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1997 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1998 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
2000 popup.AppendMenu(MF_SEPARATOR, NULL);
2002 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
2003 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
2005 popup.AppendMenu(MF_SEPARATOR, NULL);
2009 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2010 // {
2011 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2012 // }
2013 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2014 // {
2015 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2016 // }
2017 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2018 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2019 // {
2020 // popup.AppendMenu(MF_SEPARATOR, NULL);
2021 // }
2023 CString str;
2024 //if (m_hasWC)
2025 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2027 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2029 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2030 GetSelectedCount() == 1)
2031 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2033 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2034 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2036 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
2038 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2040 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2042 size_t index = (size_t)-1;
2043 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2044 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2045 popup.SetMenuItemData(ID_MERGEREV, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2048 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2050 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2051 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2054 // Add Switch Branch express Menu
2055 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2056 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2059 std::vector<const CString*> branchs;
2060 auto addCheck = [&](const CString& ref)
2062 if (ref.Find(_T("refs/heads/")) != 0 || ref == currentBranch)
2063 return;
2064 branchs.push_back(&ref);
2066 size_t index = (size_t)-1;
2067 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2068 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2069 addCheck(m_HashMap[pSelLogEntry->m_CommitHash][index]);
2070 else
2071 for_each(m_HashMap[pSelLogEntry->m_CommitHash], addCheck);
2073 CString str2;
2074 str2.LoadString(IDS_SWITCH_BRANCH);
2076 if(branchs.size() == 1)
2078 str2 += _T(' ');
2079 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2080 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2082 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2085 else if(branchs.size() > 1)
2087 subbranchmenu.CreatePopupMenu();
2088 for (size_t i = 0 ; i < branchs.size(); ++i)
2090 if (*branchs[i] != currentBranch)
2092 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2093 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2097 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2101 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2103 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS, IDI_SWITCH);
2104 size_t index = (size_t)-1;
2105 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2106 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2107 popup.SetMenuItemData(ID_SWITCHTOREV, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2110 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2112 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS, IDI_COPY);
2114 size_t index = (size_t)-1;
2115 CGit::REF_TYPE type = CGit::REF_TYPE::REMOTE_BRANCH;
2116 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2117 popup.SetMenuItemData(ID_CREATE_BRANCH, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2120 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2121 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2123 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2125 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2126 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2127 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2129 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2130 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2132 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2134 if (parentHash.size() == 1)
2135 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2136 else if (parentHash.size() > 1)
2138 revertmenu.CreatePopupMenu();
2139 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2141 for (size_t i = 0; i < parentHash.size(); ++i)
2143 CString str2;
2144 str2.Format(IDS_PARENT, i + 1);
2145 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2150 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2151 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2153 popup.AppendMenu(MF_SEPARATOR, NULL);
2157 if(!pSelLogEntry->m_Ref.IsEmpty())
2159 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2160 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2161 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2162 popup.AppendMenu(MF_SEPARATOR, NULL);
2165 if (GetSelectedCount() >= 2)
2167 bool bAddSeparator = false;
2168 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2170 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2171 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2174 if (GetSelectedCount() == 2)
2176 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2177 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2179 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2181 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2182 GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect);
2183 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2184 CString menu;
2185 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2186 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2187 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2188 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2191 bAddSeparator = true;
2194 if (m_hasWC)
2195 bAddSeparator = true;
2197 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2198 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2200 if (bAddSeparator)
2201 popup.AppendMenu(MF_SEPARATOR, NULL);
2204 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2206 bool bAddSeparator = false;
2207 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2209 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2211 CString head;
2212 int headindex;
2213 headindex = this->GetHeadIndex();
2214 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2216 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2217 CGitHash hashFirst;
2218 if (g_Git.GetHash(hashFirst, head))
2219 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2220 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2221 CGitHash hash;
2222 if (g_Git.GetHash(hash, head))
2223 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2224 GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect);
2225 GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect);
2226 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2227 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2228 bAddSeparator = true;
2233 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2234 if (GetSelectedCount() >= 2)
2235 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2236 else
2237 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2238 bAddSeparator = true;
2241 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2242 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2243 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2244 bAddSeparator = true;
2247 if (bAddSeparator)
2248 popup.AppendMenu(MF_SEPARATOR, NULL);
2251 if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !m_arShownList.SafeGetAt(FirstSelect)->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2253 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2254 popup.AppendMenu(MF_SEPARATOR, NULL);
2257 if (GetSelectedCount() == 1)
2259 bool bAddSeparator = false;
2260 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2262 // show the push-option only if the log entry has an associated local branch
2263 bool isLocal = find_if(m_HashMap[pSelLogEntry->m_CommitHash], [](const CString& ref) { return ref.Find(_T("refs/heads/")) == 0; }) != m_HashMap[pSelLogEntry->m_CommitHash].cend();
2264 if (isLocal || showExtendedMenu)
2266 CString str;
2267 str.LoadString(IDS_LOG_PUSH);
2269 CString branch;
2270 size_t index = (size_t)-1;
2271 CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH;
2272 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, &branch, &index))
2273 str.Insert(str.Find(L'.'), L" \"" + branch + L'"');
2275 popup.AppendMenuIcon(ID_PUSH, str, IDI_PUSH);
2277 if (index != (size_t)-1 && index < m_HashMap[pSelLogEntry->m_CommitHash].size())
2278 popup.SetMenuItemData(ID_PUSH, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2280 bAddSeparator = true;
2283 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2285 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2286 bAddSeparator = true;
2290 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2292 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2294 std::vector<const CString*> branchs;
2295 auto addCheck = [&](const CString& ref)
2297 if (ref == currentBranch)
2298 return;
2299 branchs.push_back(&ref);
2301 size_t index = (size_t)-1;
2302 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2303 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2304 addCheck(m_HashMap[pSelLogEntry->m_CommitHash][index]);
2305 else
2306 for_each(m_HashMap[pSelLogEntry->m_CommitHash], addCheck);
2308 CString str;
2309 if (branchs.size() == 1)
2311 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2312 str+=_T(' ');
2313 str += *branchs[0];
2314 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2315 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2316 bAddSeparator = true;
2318 else if (branchs.size() > 1)
2320 str.LoadString(IDS_DELETE_BRANCHTAG);
2321 submenu.CreatePopupMenu();
2322 for (size_t i = 0; i < branchs.size(); ++i)
2324 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2325 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2327 submenu.AppendMenuIcon(ID_DELETE + (branchs.size() << 16), IDS_ALL);
2328 submenu.SetMenuItemData(ID_DELETE + (branchs.size() << 16), (ULONG_PTR)MAKEINTRESOURCE(IDS_ALL));
2330 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2331 bAddSeparator = true;
2334 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2335 if (bAddSeparator)
2336 popup.AppendMenu(MF_SEPARATOR, NULL);
2337 } // GetSelectedCount() == 1
2339 if (GetSelectedCount() != 0)
2341 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2342 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2343 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2344 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2345 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2346 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2349 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2350 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2352 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2353 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2355 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2356 // DialogEnableWindow(IDOK, FALSE);
2357 // SetPromptApp(&theApp);
2359 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2361 // EnableOKButton();
2362 } // if (popup.CreatePopupMenu())
2365 bool CGitLogListBase::IsSelectionContinuous()
2367 if ( GetSelectedCount()==1 )
2369 // if only one revision is selected, the selection is of course
2370 // continuous
2371 return true;
2374 POSITION pos = GetFirstSelectedItemPosition();
2375 bool bContinuous = (m_arShownList.size() == m_logEntries.size());
2376 if (bContinuous)
2378 int itemindex = GetNextSelectedItem(pos);
2379 while (pos)
2381 int nextindex = GetNextSelectedItem(pos);
2382 if (nextindex - itemindex > 1)
2384 bContinuous = false;
2385 break;
2387 itemindex = nextindex;
2390 return bContinuous;
2393 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2395 CString sClipdata;
2396 POSITION pos = GetFirstSelectedItemPosition();
2397 if (pos)
2399 CString sRev;
2400 sRev.LoadString(IDS_LOG_REVISION);
2401 CString sAuthor;
2402 sAuthor.LoadString(IDS_LOG_AUTHOR);
2403 CString sDate;
2404 sDate.LoadString(IDS_LOG_DATE);
2405 CString sMessage;
2406 sMessage.LoadString(IDS_LOG_MESSAGE);
2407 bool first = true;
2408 while (pos)
2410 CString sLogCopyText;
2411 CString sPaths;
2412 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(GetNextSelectedItem(pos));
2414 if (toCopy == ID_COPY_ALL)
2416 //pLogEntry->GetFiles(this)
2417 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2419 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2420 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2422 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2423 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2425 sPaths += L' ';
2426 sPaths.AppendFormat(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2428 sPaths += _T("\r\n");
2430 sPaths.Trim();
2431 CString body = pLogEntry->GetBody();
2432 body.Replace(_T("\n"), _T("\r\n"));
2433 sLogCopyText.Format(_T("%s: %s\r\n%s: %s <%s>\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
2434 (LPCTSTR)sRev, (LPCTSTR)pLogEntry->m_CommitHash.ToString(),
2435 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2436 (LPCTSTR)sDate,
2437 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2438 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->GetSubjectBody(true),
2439 (LPCTSTR)sPaths);
2440 sClipdata += sLogCopyText;
2442 else if (toCopy == ID_COPY_MESSAGE)
2444 sClipdata += _T("* ");
2445 sClipdata += pLogEntry->GetSubjectBody(true);
2446 sClipdata += _T("\r\n\r\n");
2448 else if (toCopy == ID_COPY_SUBJECT)
2450 sClipdata += _T("* ");
2451 sClipdata += pLogEntry->GetSubject().Trim();
2452 sClipdata += _T("\r\n\r\n");
2454 else
2456 if (!first)
2457 sClipdata += _T("\r\n");
2458 sClipdata += pLogEntry->m_CommitHash;
2461 first = false;
2463 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2467 void CGitLogListBase::DiffSelectedRevWithPrevious()
2469 if (m_bThreadRunning)
2470 return;
2472 int FirstSelect=-1, LastSelect=-1;
2473 POSITION pos = GetFirstSelectedItemPosition();
2474 FirstSelect = GetNextSelectedItem(pos);
2475 while(pos)
2476 LastSelect = GetNextSelectedItem(pos);
2478 ContextMenuAction(ID_COMPAREWITHPREVIOUS, FirstSelect, LastSelect, nullptr);
2481 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2483 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2484 *pResult = -1;
2486 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2487 return;
2488 if (pFindInfo->iStart < 0 || pFindInfo->iStart >= (int)m_arShownList.size())
2489 return;
2490 if (!pFindInfo->lvfi.psz)
2491 return;
2492 #if 0
2493 CString sCmp = pFindInfo->lvfi.psz;
2494 CString sRev;
2495 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2497 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2498 sRev.Format(_T("%ld"), pLogEntry->Rev);
2499 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2501 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2503 *pResult = i;
2504 return;
2507 else
2509 if (sCmp.Compare(sRev)==0)
2511 *pResult = i;
2512 return;
2516 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2518 for (int i=0; i<pFindInfo->iStart; ++i)
2520 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2521 sRev.Format(_T("%ld"), pLogEntry->Rev);
2522 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2524 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2526 *pResult = i;
2527 return;
2530 else
2532 if (sCmp.Compare(sRev)==0)
2534 *pResult = i;
2535 return;
2540 #endif
2541 *pResult = -1;
2544 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2546 ClearText();
2548 this->m_arShownList.SafeRemoveAll();
2550 this->m_logEntries.ClearAll();
2551 if (this->m_logEntries.ParserFromLog(path, 0, info, range))
2552 return -1;
2554 SetItemCountEx((int)m_logEntries.size());
2556 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2558 if(m_IsOldFirst)
2560 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2561 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2563 else
2565 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2566 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2570 ReloadHashMap();
2572 if(path)
2573 m_Path=*path;
2574 return 0;
2577 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2579 ClearText();
2581 m_arShownList.SafeRemoveAll();
2583 m_logEntries.ClearAll();
2584 if (m_logEntries.Fill(hashes))
2585 return -1;
2587 SetItemCountEx((int)m_logEntries.size());
2589 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2591 if (m_IsOldFirst)
2593 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2594 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2596 else
2598 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2599 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2603 ReloadHashMap();
2605 return 0;
2608 int CGitLogListBase::BeginFetchLog()
2610 ClearText();
2612 this->m_arShownList.SafeRemoveAll();
2614 this->m_logEntries.ClearAll();
2616 this->m_LogCache.ClearAllParent();
2618 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2620 CTGitPath *path;
2621 if(this->m_Path.IsEmpty())
2622 path = nullptr;
2623 else
2624 path=&this->m_Path;
2626 int mask;
2627 mask = CGit::LOG_INFO_ONLY_HASH;
2628 if (m_bIncludeBoundaryCommits)
2629 mask |= CGit::LOG_INFO_BOUNDARY;
2630 // if(this->m_bAllBranch)
2631 mask |= m_ShowMask ;
2633 if(m_bShowWC)
2635 this->m_logEntries.insert(m_logEntries.cbegin(), m_wcRev.m_CommitHash);
2636 ResetWcRev();
2637 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2640 if (m_sRange.IsEmpty())
2641 m_sRange = _T("HEAD");
2643 #if 0 /* use tortoiegit filter */
2644 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2645 data.m_Author = this->m_sFilterText;
2647 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2648 data.m_MessageFilter = this->m_sFilterText;
2650 data.m_IsRegex = m_bFilterWithRegex;
2651 #endif
2653 // follow does not work for directories
2654 if (!path || path->IsDirectory())
2655 mask &= ~CGit::LOG_INFO_FOLLOW;
2656 // follow does not work with all branches 8at least in TGit)
2657 if (mask & CGit::LOG_INFO_FOLLOW)
2658 mask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES);
2660 CString cmd = g_Git.GetLogCmd(m_sRange, path, mask, &m_Filter, CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER));
2662 //this->m_logEntries.ParserFromLog();
2663 if(IsInWorkingThread())
2665 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2667 else
2669 SetItemCountEx((int)m_logEntries.size());
2674 [] { git_init(); } ();
2676 catch (char* msg)
2678 CString err(msg);
2679 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2680 return -1;
2683 if (!g_Git.CanParseRev(m_sRange))
2685 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_BASIC_REFS) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2686 return 0;
2688 // if show all branches, pick any ref as dummy entry ref
2689 STRING_VECTOR list;
2690 if (g_Git.GetRefList(list))
2691 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2692 if (list.empty())
2693 return 0;
2695 cmd = g_Git.GetLogCmd(list[0], path, mask, &m_Filter, CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER));
2698 g_Git.m_critGitDllSec.Lock();
2699 try {
2700 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2702 g_Git.m_critGitDllSec.Unlock();
2703 return -1;
2706 catch (char* msg)
2708 g_Git.m_critGitDllSec.Unlock();
2709 CString err(msg);
2710 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2711 return -1;
2713 g_Git.m_critGitDllSec.Unlock();
2715 return 0;
2718 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2720 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2722 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2724 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2726 DiffSelectedRevWithPrevious();
2727 return TRUE;
2730 #if 0
2731 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2733 DiffSelectedFile();
2734 return TRUE;
2736 #endif
2738 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2740 // select all entries
2741 for (int i=0; i<GetItemCount(); ++i)
2742 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2743 return TRUE;
2746 #if 0
2747 if (m_hAccel && !bSkipAccelerator)
2749 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2750 if (ret)
2751 return TRUE;
2754 #endif
2755 //m_tooltips.RelayEvent(pMsg);
2756 return __super::PreTranslateMessage(pMsg);
2759 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2761 // a double click on an entry in the revision list has happened
2762 *pResult = 0;
2764 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2765 DiffSelectedRevWithPrevious();
2768 void CGitLogListBase::FetchLogAsync(void* data)
2770 ReloadHashMap();
2771 m_ProcData=data;
2772 StartLoadingThread();
2775 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2777 return ((CGitLogListBase*)pVoid)->LogThread();
2780 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2782 //CTime time;
2783 oldest=CTime::GetCurrentTime();
2784 latest=CTime(1971,1,2,0,0,0);
2785 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2787 if(m_logEntries[i].IsEmpty())
2788 continue;
2790 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() < oldest.GetTime())
2791 oldest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2793 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() > latest.GetTime())
2794 latest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2798 if(latest<oldest)
2799 latest=oldest;
2802 UINT CGitLogListBase::LogThread()
2804 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2806 ULONGLONG t1,t2;
2808 if(BeginFetchLog())
2810 InterlockedExchange(&m_bThreadRunning, FALSE);
2811 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2813 return 1;
2816 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2817 bool bRegex = false;
2818 if (m_bFilterWithRegex)
2819 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2821 TRACE(_T("\n===Begin===\n"));
2822 //Update work copy item;
2824 if (!m_logEntries.empty())
2826 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2828 m_arShownList.SafeAdd(pRev);
2832 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2834 // store commit number of the last selected commit/line before the refresh or -1
2835 int lastSelectedHashNItem = -1;
2836 if (m_lastSelectedHash.IsEmpty())
2837 lastSelectedHashNItem = 0;
2839 int ret = 0;
2841 bool shouldWalk = true;
2842 if (!g_Git.CanParseRev(m_sRange))
2844 // walk revisions if show all branches and there exists any ref
2845 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_BASIC_REFS) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2846 shouldWalk = false;
2847 else
2849 STRING_VECTOR list;
2850 if (g_Git.GetRefList(list))
2851 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2852 if (list.empty())
2853 shouldWalk = false;
2857 if (shouldWalk)
2859 g_Git.m_critGitDllSec.Lock();
2860 int total = 0;
2863 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2864 total = git_get_log_estimate_commit_count(m_DllGitLog);
2866 catch (char* msg)
2868 CString err(msg);
2869 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2870 ret = -1;
2872 g_Git.m_critGitDllSec.Unlock();
2874 GIT_COMMIT commit;
2875 t2 = t1 = GetTickCount64();
2876 int oldprecentage = 0;
2877 size_t oldsize = m_logEntries.size();
2878 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2879 while (ret== 0 && !m_bExitThread)
2881 g_Git.m_critGitDllSec.Lock();
2884 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2886 catch (char* msg)
2888 g_Git.m_critGitDllSec.Unlock();
2889 CString err(msg);
2890 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2891 break;
2893 g_Git.m_critGitDllSec.Unlock();
2895 if(ret)
2897 if (ret != -2) // other than end of revision walking
2898 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2899 break;
2902 if (commit.m_ignore == 1)
2904 git_free_commit(&commit);
2905 continue;
2908 //printf("%s\r\n",commit.GetSubject());
2909 if(m_bExitThread)
2910 break;
2912 CGitHash hash = (char*)commit.m_hash ;
2914 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2915 pRev->m_GitCommit = commit;
2916 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2918 char* note = nullptr;
2919 g_Git.m_critGitDllSec.Lock();
2922 git_get_notes(commit.m_hash, &note);
2924 catch (char* msg)
2926 g_Git.m_critGitDllSec.Unlock();
2927 CString err(msg);
2928 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2929 break;
2931 g_Git.m_critGitDllSec.Unlock();
2933 if(note)
2935 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2936 free(note);
2937 note = nullptr;
2940 if(!pRev->m_IsDiffFiles)
2942 pRev->m_CallDiffAsync = DiffAsync;
2945 pRev->ParserParentFromCommit(&commit);
2946 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2948 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2950 const CGitHash &parentHash = pRev->m_ParentHash[i];
2951 auto it = commitChildren.find(parentHash);
2952 if (it == commitChildren.end())
2953 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2954 it->second.insert(pRev->m_CommitHash);
2958 #ifdef DEBUG
2959 pRev->DbgPrint();
2960 TRACE(_T("\n"));
2961 #endif
2963 bool visible = true;
2964 if (HasFilterText())
2966 if(!IsMatchFilter(bRegex,pRev,pat))
2967 visible = false;
2969 if (visible && !ShouldShowFilter(pRev, commitChildren))
2970 visible = false;
2971 this->m_critSec.Lock();
2972 m_logEntries.append(hash, visible);
2973 if (visible)
2974 m_arShownList.SafeAdd(pRev);
2975 this->m_critSec.Unlock();
2977 if (!visible)
2978 continue;
2980 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2981 lastSelectedHashNItem = (int)m_arShownList.size() - 1;
2983 t2 = GetTickCount64();
2985 if (t2 - t1 > 500UL || (m_logEntries.size() - oldsize > 100))
2987 //update UI
2988 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2989 if(percent > 99)
2990 percent =99;
2991 if(percent < GITLOG_START)
2992 percent = GITLOG_START +1;
2994 oldsize = m_logEntries.size();
2995 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2997 //if( percent > oldprecentage )
2999 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3000 oldprecentage = percent;
3003 if (lastSelectedHashNItem >= 0)
3004 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3006 t1 = t2;
3009 g_Git.m_critGitDllSec.Lock();
3010 git_close_log(m_DllGitLog);
3011 g_Git.m_critGitDllSec.Unlock();
3015 if (m_bExitThread)
3017 InterlockedExchange(&m_bThreadRunning, FALSE);
3018 return 0;
3021 //Update UI;
3022 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3024 if (lastSelectedHashNItem >= 0)
3025 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3027 if (this->m_hWnd)
3028 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3030 InterlockedExchange(&m_bThreadRunning, FALSE);
3032 return 0;
3035 void CGitLogListBase::FetchRemoteList()
3037 STRING_VECTOR remoteList;
3038 m_SingleRemote.Empty();
3039 if (!g_Git.GetRemoteList(remoteList) && remoteList.size() == 1)
3040 m_SingleRemote = remoteList[0];
3043 void CGitLogListBase::FetchTrackingBranchList()
3045 m_TrackingMap.clear();
3046 for (auto it = m_HashMap.cbegin(); it != m_HashMap.cend(); ++it)
3048 for (const auto& ref : it->second)
3050 CString branchName;
3051 if (CGit::GetShortName(ref, branchName, _T("refs/heads/")))
3053 CString pullRemote, pullBranch;
3054 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3055 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3056 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3062 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3064 SafeTerminateThread();
3066 this->SetItemCountEx(0);
3067 this->Clear();
3069 ResetWcRev();
3071 ShowGraphColumn((m_ShowMask & CGit::LOG_INFO_FOLLOW) ? false : true);
3073 //Update branch and Tag info
3074 ReloadHashMap();
3075 if (m_pFindDialog)
3076 m_pFindDialog->RefreshList();
3077 //Assume Thread have exited
3078 //if(!m_bThreadRunning)
3080 m_logEntries.clear();
3082 if(IsCleanFilter)
3084 m_sFilterText.Empty();
3087 SafeTerminateAsyncDiffThread();
3088 m_AsynDiffListLock.Lock();
3089 m_AsynDiffList.clear();
3090 m_AsynDiffListLock.Unlock();
3091 StartAsyncDiffThread();
3093 StartLoadingThread();
3097 void CGitLogListBase::StartAsyncDiffThread()
3099 if (m_AsyncThreadExit)
3100 return;
3101 if (InterlockedExchange(&m_AsyncThreadRunning, TRUE) != FALSE)
3102 return;
3103 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
3104 if (!m_DiffingThread)
3106 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
3107 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3111 void CGitLogListBase::StartLoadingThread()
3113 if (InterlockedExchange(&m_bThreadRunning, TRUE) != FALSE)
3114 return;
3115 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3116 InterlockedExchange(&m_bExitThread, FALSE);
3117 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
3118 if (!m_LoadingThread)
3120 InterlockedExchange(&m_bThreadRunning, FALSE);
3121 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3122 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3126 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3130 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3131 if (!bMatchCase)
3132 type |= std::tr1::regex_constants::icase;
3133 pat = std::tr1::wregex(regexp_str, type);
3134 return true;
3136 catch (std::exception) {}
3137 return false;
3139 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3141 BOOL result = TRUE;
3142 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3143 CString sRev;
3145 if ((bRegex)&&(m_bFilterWithRegex))
3147 if (m_SelectedFilters & LOGFILTER_BUGID)
3149 if(this->m_bShowBugtraqColumn)
3151 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3153 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3154 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3155 return TRUE;
3159 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3161 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3162 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3163 return TRUE;
3166 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3168 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3169 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3170 return TRUE;
3173 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3175 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3176 return TRUE;
3178 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3179 return TRUE;
3182 if (m_SelectedFilters & LOGFILTER_EMAILS)
3184 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3185 return TRUE;
3187 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3188 return TRUE;
3191 if (m_SelectedFilters & LOGFILTER_REVS)
3193 sRev = pRev->m_CommitHash.ToString();
3194 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3196 return TRUE;
3200 if (m_SelectedFilters & LOGFILTER_NOTES)
3202 if (std::regex_search(std::wstring(pRev->m_Notes), pat, flags))
3203 return TRUE;
3206 if (m_SelectedFilters & LOGFILTER_REFNAME)
3208 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3209 for (const auto& ref : refs)
3211 if (std::regex_search(std::wstring(ref), pat, flags))
3212 return TRUE;
3216 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3218 if (std::regex_search(std::wstring(GetTagInfo(pRev)), pat, flags))
3219 return TRUE;
3222 if (m_SelectedFilters & LOGFILTER_PATHS)
3224 CTGitPathList* pathList = nullptr;
3225 if( pRev->m_IsDiffFiles)
3226 pathList = &pRev->GetFiles(this);
3227 else
3229 if(!pRev->m_IsSimpleListReady)
3230 pRev->SafeGetSimpleList(&g_Git);
3233 if(pathList)
3234 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3236 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3237 return true;
3238 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3239 return true;
3242 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3244 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3245 return true;
3249 else
3251 CString find = m_sFilterText;
3252 if (!m_bFilterCaseSensitively)
3253 find.MakeLower();
3254 result = find[0] == '!' ? FALSE : TRUE;
3255 if (!result)
3256 find = find.Mid(1);
3258 if (m_SelectedFilters & LOGFILTER_BUGID)
3260 if(this->m_bShowBugtraqColumn)
3262 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3264 if (!m_bFilterCaseSensitively)
3265 sBugIds.MakeLower();
3266 if ((sBugIds.Find(find) >= 0))
3267 return result;
3271 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3273 CString msg = pRev->GetSubject();
3275 if (!m_bFilterCaseSensitively)
3276 msg = msg.MakeLower();
3277 if ((msg.Find(find) >= 0))
3278 return result;
3281 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3283 CString msg = pRev->GetBody();
3285 if (!m_bFilterCaseSensitively)
3286 msg = msg.MakeLower();
3287 if ((msg.Find(find) >= 0))
3288 return result;
3291 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3293 CString msg = pRev->GetAuthorName();
3294 if (!m_bFilterCaseSensitively)
3295 msg = msg.MakeLower();
3296 if ((msg.Find(find) >= 0))
3297 return result;
3300 if (m_SelectedFilters & LOGFILTER_EMAILS)
3302 CString msg = pRev->GetAuthorEmail();
3303 if (!m_bFilterCaseSensitively)
3304 msg = msg.MakeLower();
3305 if ((msg.Find(find) >= 0))
3306 return result;
3309 if (m_SelectedFilters & LOGFILTER_NOTES)
3311 CString msg = pRev->m_Notes;
3312 if (!m_bFilterCaseSensitively)
3313 msg = msg.MakeLower();
3314 if ((msg.Find(find) >= 0))
3315 return result;
3318 if (m_SelectedFilters & LOGFILTER_REVS)
3320 sRev = pRev->m_CommitHash.ToString();
3321 if ((sRev.Find(find) >= 0))
3322 return result;
3325 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3327 CString msg = GetTagInfo(pRev);
3328 if (!m_bFilterCaseSensitively)
3329 msg = msg.MakeLower();
3330 if ((msg.Find(find) >= 0))
3331 return result;
3334 if (m_SelectedFilters & LOGFILTER_REFNAME)
3336 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3337 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3339 if (it->Find(find) >= 0)
3340 return result;
3344 if (m_SelectedFilters & LOGFILTER_PATHS)
3346 CTGitPathList* pathList = nullptr;
3347 if( pRev->m_IsDiffFiles)
3348 pathList = &pRev->GetFiles(this);
3349 else
3351 if(!pRev->m_IsSimpleListReady)
3352 pRev->SafeGetSimpleList(&g_Git);
3354 if(pathList)
3355 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3357 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3358 CString path = cpath->GetGitOldPathString();
3359 if (!m_bFilterCaseSensitively)
3360 path.MakeLower();
3361 if ((path.Find(find)>=0))
3362 return result;
3363 path = cpath->GetGitPathString();
3364 if (!m_bFilterCaseSensitively)
3365 path.MakeLower();
3366 if ((path.Find(find)>=0))
3367 return result;
3370 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3372 CString path = pRev->m_SimpleFileList[i];
3373 if (!m_bFilterCaseSensitively)
3374 path.MakeLower();
3375 if ((path.Find(find)>=0))
3376 return result;
3379 } // else (from if (bRegex))
3380 return !result;
3383 static bool CStringStartsWith(const CString &str, const CString &prefix)
3385 return str.Left(prefix.GetLength()) == prefix;
3387 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3389 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3390 return true;
3392 if (m_ShowFilter & FILTERSHOW_REFS)
3394 // Keep all refs.
3395 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3396 for (size_t i = 0; i < refList.size(); ++i)
3398 const CString &str = refList[i];
3399 if (CStringStartsWith(str, _T("refs/heads/")))
3401 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3402 return true;
3404 else if (CStringStartsWith(str, _T("refs/remotes/")))
3406 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3407 return true;
3409 else if (CStringStartsWith(str, _T("refs/tags/")))
3411 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3412 return true;
3414 else if (CStringStartsWith(str, _T("refs/stash")))
3416 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3417 return true;
3419 else if (CStringStartsWith(str, _T("refs/bisect/")))
3421 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3422 return true;
3425 // Keep the head too.
3426 if (pRev->m_CommitHash == m_HeadHash)
3427 return true;
3430 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3432 if (pRev->ParentsCount() > 1)
3433 return true;
3434 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3435 if (childrenIt != commitChildren.end())
3437 const std::set<CGitHash> &children = childrenIt->second;
3438 if (children.size() > 1)
3439 return true;
3442 return false;
3445 void CGitLogListBase::ShowGraphColumn(bool bShow)
3447 // HACK to hide graph column
3448 if (bShow)
3449 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3450 else
3451 SetColumnWidth(0, 0);
3454 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3456 CString cmd;
3457 CString output;
3459 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3461 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3462 for (size_t i = 0; i < vector.size(); ++i)
3464 if (vector[i].Find(_T("refs/tags/")) == 0)
3466 CString tag = vector[i];
3467 int start = vector[i].Find(_T("^{}"));
3468 if (start > 0)
3469 tag = tag.Left(start);
3470 else
3471 continue;
3473 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3474 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3475 output.AppendChar(_T('\n'));
3480 return output;
3483 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3485 pShownlist->SafeRemoveAll();
3487 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3488 bool bRegex = false;
3489 if (m_bFilterWithRegex)
3490 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3492 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3493 CString sRev;
3494 for (DWORD i=0; i<m_logEntries.size(); ++i)
3496 if ((bRegex)&&(m_bFilterWithRegex))
3498 #if 0
3499 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3501 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3502 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3504 pShownlist->SafeAdd(m_logEntries[i]);
3505 continue;
3508 #endif
3509 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3511 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3512 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3514 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3515 continue;
3518 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3520 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3521 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3523 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3524 continue;
3527 if (m_SelectedFilters & LOGFILTER_PATHS)
3529 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3531 bool bGoing = true;
3532 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3534 CTGitPath cpath = pathList[cpPathIndex];
3535 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3537 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3538 bGoing = false;
3539 continue;
3541 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3543 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3544 bGoing = false;
3545 continue;
3547 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3549 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3550 bGoing = false;
3551 continue;
3555 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3557 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3559 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3560 continue;
3563 if (m_SelectedFilters & LOGFILTER_EMAILS)
3565 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3567 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3568 continue;
3571 if (m_SelectedFilters & LOGFILTER_REVS)
3573 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3574 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3576 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3577 continue;
3580 if (m_SelectedFilters & LOGFILTER_REFNAME)
3582 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3583 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3585 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3587 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3588 continue;
3592 } // if (bRegex)
3593 else
3595 CString find = m_sFilterText;
3596 if (!m_bFilterCaseSensitively)
3597 find.MakeLower();
3598 #if 0
3599 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3601 CString sBugIDs = m_logEntries[i]->sBugIDs;
3603 if (!m_bFilterCaseSensitively)
3604 sBugIDs = sBugIDs.MakeLower();
3605 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3607 pShownlist->SafeAdd(m_logEntries[i]);
3608 continue;
3611 #endif
3612 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3614 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3616 if (!m_bFilterCaseSensitively)
3617 msg = msg.MakeLower();
3618 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3620 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3621 continue;
3624 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3626 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3628 if (!m_bFilterCaseSensitively)
3629 msg = msg.MakeLower();
3630 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3632 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3633 continue;
3636 if (m_SelectedFilters & LOGFILTER_PATHS)
3638 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3640 bool bGoing = true;
3641 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3643 CTGitPath cpath = pathList[cpPathIndex];
3644 CString path = cpath.GetGitOldPathString();
3645 if (!m_bFilterCaseSensitively)
3646 path.MakeLower();
3647 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3649 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3650 bGoing = false;
3651 continue;
3653 path = cpath.GetGitPathString();
3654 if (!m_bFilterCaseSensitively)
3655 path.MakeLower();
3656 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3658 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3659 bGoing = false;
3660 continue;
3662 path = cpath.GetActionName();
3663 if (!m_bFilterCaseSensitively)
3664 path.MakeLower();
3665 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3667 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3668 bGoing = false;
3669 continue;
3673 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3675 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3676 if (!m_bFilterCaseSensitively)
3677 msg = msg.MakeLower();
3678 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3680 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3681 continue;
3684 if (m_SelectedFilters & LOGFILTER_EMAILS)
3686 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3687 if (!m_bFilterCaseSensitively)
3688 msg = msg.MakeLower();
3689 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3691 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3692 continue;
3695 if (m_SelectedFilters & LOGFILTER_REVS)
3697 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3698 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3700 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3701 continue;
3704 if (m_SelectedFilters & LOGFILTER_REFNAME)
3706 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3707 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3709 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3711 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3712 continue;
3716 } // else (from if (bRegex))
3717 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3720 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3723 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3725 if(m_From == -1)
3726 if(m_To == -1)
3727 return true;
3728 else
3729 return time <= m_To;
3730 else
3731 if(m_To == -1)
3732 return time >= m_From;
3733 else
3734 return ((time >= m_From)&&(time <= m_To));
3736 return TRUE; /* git dll will filter time range */
3738 // return TRUE;
3741 void CGitLogListBase::StartFilter()
3743 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3744 RecalculateShownList(&m_arShownList);
3745 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3748 DeleteAllItems();
3749 SetItemCountEx(ShownCountWithStopped());
3750 RedrawItems(0, ShownCountWithStopped());
3751 Invalidate();
3754 void CGitLogListBase::RemoveFilter()
3756 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3758 m_arShownList.SafeRemoveAll();
3760 // reset the time filter too
3761 #if 0
3762 m_timFrom = (__time64_t(m_tFrom));
3763 m_timTo = (__time64_t(m_tTo));
3764 m_DateFrom.SetTime(&m_timFrom);
3765 m_DateTo.SetTime(&m_timTo);
3766 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3767 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3768 #endif
3770 for (DWORD i=0; i<m_logEntries.size(); ++i)
3772 if(this->m_IsOldFirst)
3773 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3774 else
3775 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3777 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3778 DeleteAllItems();
3779 SetItemCountEx(ShownCountWithStopped());
3780 RedrawItems(0, ShownCountWithStopped());
3782 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3785 void CGitLogListBase::Clear()
3787 m_arShownList.SafeRemoveAll();
3788 DeleteAllItems();
3790 m_logEntries.ClearAll();
3793 void CGitLogListBase::OnDestroy()
3795 // save the column widths to the registry
3796 SaveColumnWidths();
3798 SafeTerminateThread();
3799 SafeTerminateAsyncDiffThread();
3801 int retry = 0;
3802 while(m_LogCache.SaveCache())
3804 if(retry > 5)
3805 break;
3806 Sleep(1000);
3808 ++retry;
3810 //if(CMessageBox::Show(nullptr, _T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."), _T("TortoiseGit"),
3811 // MB_YESNO) == IDNO)
3812 // break;
3815 CHintListCtrl::OnDestroy();
3818 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3820 CRect rect;
3821 int i=(int)wParam;
3822 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3823 this->InvalidateRect(rect);
3825 return 0;
3829 * Save column widths to the registry
3831 void CGitLogListBase::SaveColumnWidths()
3833 int maxcol = m_ColumnManager.GetColumnCount();
3835 // HACK that graph column is always shown
3836 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3838 for (int col = 0; col < maxcol; ++col)
3839 if (m_ColumnManager.IsVisible (col))
3840 m_ColumnManager.ColumnResized (col);
3842 m_ColumnManager.WriteSettings();
3845 int CGitLogListBase::GetHeadIndex()
3847 if(m_HeadHash.IsEmpty())
3848 return -1;
3850 for (size_t i = 0; i < m_arShownList.size(); ++i)
3852 GitRev* pRev = m_arShownList.SafeGetAt(i);
3853 if(pRev)
3855 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3856 return (int)i;
3859 return -1;
3861 void CGitLogListBase::OnFind()
3863 if (!m_pFindDialog)
3865 m_pFindDialog = new CFindDlg(this);
3866 m_pFindDialog->Create(this);
3869 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3871 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3873 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3875 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3876 Default();
3878 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3880 if (GetSelectedCount() != 0)
3881 return 0;
3883 CGitHash theSelectedHash = m_lastSelectedHash;
3884 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3885 m_lastSelectedHash = theSelectedHash;
3887 int countPerPage = GetCountPerPage();
3888 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3889 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3890 EnsureVisible((int)itemToSelect, FALSE);
3891 return 0;
3893 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3895 ASSERT(m_pFindDialog);
3896 bool bFound = false;
3897 int i=0;
3899 if (m_pFindDialog->IsTerminating())
3901 // invalidate the handle identifying the dialog box.
3902 m_pFindDialog = nullptr;
3903 return 0;
3906 int cnt = (int)m_arShownList.size();
3908 if(m_pFindDialog->IsRef())
3910 CString str;
3911 str=m_pFindDialog->GetFindString();
3913 CGitHash hash;
3915 if(!str.IsEmpty())
3917 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3918 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3921 if(!hash.IsEmpty())
3923 for (i = 0; i < cnt; ++i)
3925 GitRev* pLogEntry = m_arShownList.SafeGetAt(i);
3926 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3928 bFound = true;
3929 break;
3933 if (!bFound)
3935 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3936 return 0;
3940 if (m_pFindDialog->FindNext() && !bFound)
3942 //read data from dialog
3943 CString findText = m_pFindDialog->GetFindString();
3944 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3946 std::tr1::wregex pat;
3947 bool bRegex = false;
3948 if (m_pFindDialog->Regex())
3949 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3951 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3953 for (i = m_nSearchIndex + 1; ; ++i)
3955 if (i >= cnt)
3957 i = 0;
3958 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3960 if (m_nSearchIndex >= 0)
3962 if (i == m_nSearchIndex)
3964 ::MessageBeep(0xFFFFFFFF);
3965 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3966 break;
3970 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(i);
3972 CString str;
3973 str+=pLogEntry->m_CommitHash.ToString();
3974 str += _T('\n');
3976 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3978 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3979 str += _T('\n');
3982 str+=pLogEntry->GetAuthorEmail();
3983 str += _T('\n');
3984 str+=pLogEntry->GetAuthorName();
3985 str += _T('\n');
3986 str+=pLogEntry->GetBody();
3987 str += _T('\n');
3988 str+=pLogEntry->GetCommitterEmail();
3989 str += _T('\n');
3990 str+=pLogEntry->GetCommitterName();
3991 str += _T('\n');
3992 str+=pLogEntry->GetSubject();
3993 str += _T('\n');
3994 str+=pLogEntry->m_Notes;
3995 str += _T('\n');
3996 str+=GetTagInfo(pLogEntry);
3997 str += _T('\n');
4000 /*Because changed files list is loaded on demand when gui show,
4001 files will empty when files have not fetched.
4003 we can add it back by using one-way diff(with outnumber changed and rename detect.
4004 here just need changed filename list. one-way is much quicker.
4006 if(pLogEntry->m_IsFull)
4008 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4010 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4011 str += _T('\n');
4012 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4013 str += _T('\n');
4016 else
4018 if(!pLogEntry->m_IsSimpleListReady)
4019 pLogEntry->SafeGetSimpleList(&g_Git);
4021 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4023 str += pLogEntry->m_SimpleFileList[j];
4024 str += _T('\n');
4028 if (bRegex)
4030 if (std::regex_search(std::wstring(str), pat, flags))
4032 bFound = true;
4033 break;
4036 else
4038 if (bMatchCase)
4040 if (str.Find(findText) >= 0)
4042 bFound = true;
4043 break;
4046 else
4048 CString msg = str;
4049 msg = msg.MakeLower();
4050 CString find = findText.MakeLower();
4051 if (msg.Find(find) >= 0)
4053 bFound = TRUE;
4054 break;
4058 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4060 } // if(m_pFindDialog->FindNext())
4061 //UpdateLogInfoLabel();
4063 if (bFound)
4065 m_nSearchIndex = i;
4066 EnsureVisible(i, FALSE);
4067 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4069 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4070 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4071 SetSelectionMark(i);
4073 else
4075 GitRev* pLogEntry = m_arShownList.SafeGetAt(i);
4076 if (pLogEntry)
4077 m_highlight = pLogEntry->m_CommitHash;
4079 Invalidate();
4080 //FillLogMessageCtrl();
4081 UpdateData(FALSE);
4084 return 0;
4087 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4089 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4091 *pResult = FALSE;
4094 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4096 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4098 Invalidate(FALSE);
4101 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4103 LVHITTESTINFO lvhitTestInfo;
4105 lvhitTestInfo.pt = point;
4107 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4108 int nSubItem = lvhitTestInfo.iSubItem;
4110 UINT nFlags = lvhitTestInfo.flags;
4112 // nFlags is 0 if the SubItemHitTest fails
4113 // Therefore, 0 & <anything> will equal false
4114 if (nFlags & LVHT_ONITEM)
4116 // Get the client area occupied by this control
4117 RECT rcClient;
4118 GetClientRect(&rcClient);
4120 // Fill in the TOOLINFO structure
4121 pTI->hwnd = m_hWnd;
4122 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4123 pTI->lpszText = LPSTR_TEXTCALLBACK;
4124 pTI->rect = rcClient;
4126 return pTI->uId; // By returning a unique value per listItem,
4127 // we ensure that when the mouse moves over another list item,
4128 // the tooltip will change
4130 else
4132 // Otherwise, we aren't interested, so let the message propagate
4133 return -1;
4137 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4139 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4140 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4142 *pResult = 0;
4144 // Ignore messages from the built in tooltip, we are processing them internally
4145 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4146 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4147 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4148 return FALSE;
4150 // Get the mouse position
4151 const MSG* pMessage = GetCurrentMessage();
4153 CPoint pt;
4154 pt = pMessage->pt;
4155 ScreenToClient(&pt);
4157 // Check if the point falls onto a list item
4158 LVHITTESTINFO lvhitTestInfo;
4159 lvhitTestInfo.pt = pt;
4161 int nItem = SubItemHitTest(&lvhitTestInfo);
4163 if (lvhitTestInfo.flags & LVHT_ONITEM)
4165 // Get branch description first
4166 CString strTipText;
4167 if (lvhitTestInfo.iSubItem == LOGLIST_MESSAGE)
4169 CString branch;
4170 CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH;
4171 if (IsMouseOnRefLabel(m_arShownList.SafeGetAt(nItem), lvhitTestInfo.pt, type, &branch))
4173 MAP_STRING_STRING descriptions;
4174 g_Git.GetBranchDescriptions(descriptions);
4175 if (descriptions.find(branch) != descriptions.cend())
4177 strTipText.LoadString(IDS_DESCRIPTION);
4178 strTipText += L":\n";
4179 strTipText += descriptions[branch];
4184 bool followMousePos = false;
4185 if (!strTipText.IsEmpty())
4186 followMousePos = true;
4187 else
4188 strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4189 if (strTipText.IsEmpty())
4190 return FALSE;
4192 // we want multiline tooltips
4193 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4195 wcscpy_s(m_wszTip, strTipText);
4196 // handle Unicode as well as non-Unicode requests
4197 if (pNMHDR->code == TTN_NEEDTEXTA)
4199 pTTTA->hinst = nullptr;
4200 pTTTA->lpszText = m_szTip;
4201 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, nullptr, nullptr);
4203 else
4205 pTTTW->hinst = nullptr;
4206 pTTTW->lpszText = m_wszTip;
4209 CRect rect;
4210 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4211 if (followMousePos)
4212 rect.MoveToXY(pt.x, pt.y + 18); // 18: to act like a normal tooltip
4213 ClientToScreen(rect);
4214 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4216 return TRUE; // We found a tool tip,
4217 // tell the framework this message has been handled
4220 return FALSE; // We didn't handle the message,
4221 // let the framework continue propagating the message
4224 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4226 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4228 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4229 if (pLogEntry == nullptr)
4230 return CString();
4231 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4232 return CString();
4233 return pLogEntry->GetSubject();
4235 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4237 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4238 if (pLogEntry == nullptr)
4239 return CString();
4240 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4242 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4244 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4245 if (pLogEntry == nullptr)
4246 return CString();
4247 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4249 else if (nSubItem == LOGLIST_ACTION)
4251 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4252 if (pLogEntry == nullptr)
4253 return CString();
4255 if (!pLogEntry->m_IsDiffFiles)
4256 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4258 int actions = pLogEntry->GetAction(this);
4259 CString sToolTipText;
4261 CString actionText;
4262 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4263 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4265 if (actions & CTGitPath::LOGACTIONS_ADDED)
4267 if (!actionText.IsEmpty())
4268 actionText += L"\r\n";
4269 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4272 if (actions & CTGitPath::LOGACTIONS_DELETED)
4274 if (!actionText.IsEmpty())
4275 actionText += L"\r\n";
4276 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4279 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4281 if (!actionText.IsEmpty())
4282 actionText += L"\r\n";
4283 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4286 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4288 if (!actionText.IsEmpty())
4289 actionText += L"\r\n";
4290 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4293 if (!actionText.IsEmpty())
4295 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4296 sToolTipText = sTitle + L":\r\n" + actionText;
4298 return sToolTipText;
4300 return CString();
4303 bool CGitLogListBase::IsMouseOnRefLabelFromPopupMenu(const GitRevLoglist* pLogEntry, const CPoint& point, CGit::REF_TYPE& type, CString* pShortname /*nullptr*/, size_t* pIndex /*nullptr*/)
4305 POINT pt = point;
4306 ScreenToClient(&pt);
4307 return IsMouseOnRefLabel(pLogEntry, pt, type, pShortname, pIndex);
4310 bool CGitLogListBase::IsMouseOnRefLabel(const GitRevLoglist* pLogEntry, const POINT& pt, CGit::REF_TYPE& type, CString* pShortname /*nullptr*/, size_t* pIndex /*nullptr*/)
4312 if (!pLogEntry)
4313 return false;
4315 for (size_t i = 0; i < m_HashMap[pLogEntry->m_CommitHash].size(); ++i)
4317 const auto labelpos = m_RefLabelPosMap.find(m_HashMap[pLogEntry->m_CommitHash][i]);
4318 if (labelpos == m_RefLabelPosMap.cend() || !labelpos->second.PtInRect(pt))
4319 continue;
4321 CGit::REF_TYPE foundType;
4322 if (pShortname)
4323 *pShortname = CGit::GetShortName(m_HashMap[pLogEntry->m_CommitHash][i], &foundType);
4324 else
4325 CGit::GetShortName(m_HashMap[pLogEntry->m_CommitHash][i], &foundType);
4326 if (foundType != type && type != CGit::REF_TYPE::UNKNOWN)
4327 return false;
4329 type = foundType;
4330 if (pIndex)
4331 *pIndex = i;
4332 return true;
4334 return false;