Drop some magic numbers
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob9ef8c4a2db6cd50e0d9351a28be4844329ea2617
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, CHintCtrl<CResizableColumnsListCtrl<CListCtrl>>)
60 CGitLogListBase::CGitLogListBase() : CHintCtrl<CResizableColumnsListCtrl<CListCtrl>>()
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_dwDefaultColumns(0)
72 , m_arShownList(&m_critSec)
73 , m_hasWC(true)
74 , m_bNoHightlightHead(FALSE)
75 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
76 , m_bFullCommitMessageOnLogLine(false)
77 , m_OldTopIndex(-1)
78 , m_AsyncThreadRunning(FALSE)
79 , m_AsyncThreadExit(FALSE)
80 , m_bIsCherryPick(false)
82 // use the default GUI font, create a copy of it and
83 // change the copy to BOLD (leave the rest of the font
84 // the same)
85 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
86 LOGFONT lf = {0};
87 GetObject(hFont, sizeof(LOGFONT), &lf);
88 lf.lfWeight = FW_BOLD;
89 m_boldFont.CreateFontIndirect(&lf);
90 lf.lfWeight = FW_DONTCARE;
91 lf.lfItalic = TRUE;
92 m_FontItalics.CreateFontIndirect(&lf);
93 lf.lfWeight = FW_BOLD;
94 m_boldItalicsFont.CreateFontIndirect(&lf);
96 m_bShowBugtraqColumn=false;
98 m_IsIDReplaceAction=FALSE;
100 this->m_critSec.Init();
101 ResetWcRev(false);
103 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
104 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
105 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
106 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
111 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
113 m_Filter.m_NumberOfLogsScale = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT);
114 if (m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE)
116 CString key;
117 key.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR)g_Git.m_CurrentDir);
118 key.Replace(_T(':'), _T('_'));
119 CString lastSelFromDate = CRegString(key);
120 if (lastSelFromDate.GetLength() == 10)
122 CTime time = CTime(_wtoi((LPCTSTR)lastSelFromDate.Mid(0, 4)), _wtoi((LPCTSTR)lastSelFromDate.Mid(5, 2)), _wtoi((LPCTSTR)lastSelFromDate.Mid(8, 2)), 0, 0, 0);
123 m_Filter.m_From = (DWORD)time.GetTime();
126 m_Filter.m_NumberOfLogs = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
128 m_ShowMask = 0;
129 m_LoadingThread = nullptr;
131 InterlockedExchange(&m_bExitThread,FALSE);
132 m_IsOldFirst = FALSE;
133 m_IsRebaseReplaceGraph = FALSE;
135 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
137 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
139 // get short/long datetime setting from registry
140 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
141 if ( RegUseShortDateFormat )
143 m_DateFormat = DATE_SHORTDATE;
145 else
147 m_DateFormat = DATE_LONGDATE;
149 // get relative time display setting from registry
150 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
151 m_bRelativeTimes = (regRelativeTimes != 0);
152 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
154 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
155 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
156 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
157 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
158 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
159 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
160 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
162 m_ColumnRegKey=_T("log");
164 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
165 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
166 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
167 m_bFullCommitMessageOnLogLine = !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE);
169 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
170 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
172 m_AsyncDiffEvent = ::CreateEvent(nullptr, FALSE, TRUE, nullptr);
173 m_AsynDiffListLock.Init();
174 StartAsyncDiffThread();
177 int CGitLogListBase::AsyncDiffThread()
179 while(!m_AsyncThreadExit)
181 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
183 GitRevLoglist* pRev = nullptr;
184 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
186 m_AsynDiffListLock.Lock();
187 pRev = m_AsynDiffList.back();
188 m_AsynDiffList.pop_back();
189 m_AsynDiffListLock.Unlock();
191 if( pRev->m_CommitHash.IsEmpty() )
193 if(pRev->m_IsDiffFiles)
194 continue;
196 CTGitPathList& files = pRev->GetFiles(this);
197 files.Clear();
198 pRev->m_ParentHash.clear();
199 pRev->m_ParentHash.push_back(m_HeadHash);
200 g_Git.RefreshGitIndex();
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, CHintCtrl<CResizableColumnsListCtrl<CListCtrl>>)
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_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
299 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
300 END_MESSAGE_MAP()
302 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
304 //if (m_nRowHeight>0)
305 lpMeasureItemStruct->itemHeight = 50;
308 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
310 PreSubclassWindow();
311 return __super::OnCreate(lpCreateStruct);
314 void CGitLogListBase::PreSubclassWindow()
316 SetExtendedStyle(LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
317 // load the icons for the action columns
318 // m_Theme.Open(m_hWnd, L"ListView");
319 SetWindowTheme(m_hWnd, L"Explorer", nullptr);
320 __super::PreSubclassWindow();
323 CString CGitLogListBase::GetRebaseActionName(int action)
325 if (action & LOGACTIONS_REBASE_EDIT)
326 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
327 if (action & LOGACTIONS_REBASE_SQUASH)
328 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
329 if (action & LOGACTIONS_REBASE_PICK)
330 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
331 if (action & LOGACTIONS_REBASE_SKIP)
332 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
334 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
337 void CGitLogListBase::InsertGitColumn()
339 CString temp;
341 Init();
343 // only load properties if we have a repository
344 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
345 UpdateProjectProperties();
347 static UINT normal[] =
349 IDS_LOG_GRAPH,
350 IDS_LOG_REBASE,
351 IDS_LOG_ID,
352 IDS_LOG_HASH,
353 IDS_LOG_ACTIONS,
354 IDS_LOG_MESSAGE,
355 IDS_LOG_AUTHOR,
356 IDS_LOG_DATE,
357 IDS_LOG_EMAIL,
358 IDS_LOG_COMMIT_NAME,
359 IDS_LOG_COMMIT_EMAIL,
360 IDS_LOG_COMMIT_DATE,
361 IDS_LOG_BUGIDS,
362 IDS_LOG_SVNREV,
365 static int with[] =
367 ICONITEMBORDER+16*4,
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 2*ICONITEMBORDER+16*5,
372 LOGLIST_MESSAGE_MIN,
373 ICONITEMBORDER+16*4,
374 ICONITEMBORDER+16*4,
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
382 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
384 DWORD hideColumns = 0;
385 if(this->m_IsRebaseReplaceGraph)
387 hideColumns |= GIT_LOG_GRAPH;
388 m_dwDefaultColumns |= GIT_LOG_REBASE;
390 else
391 hideColumns |= GIT_LOG_REBASE;
393 if(this->m_IsIDReplaceAction)
395 hideColumns |= GIT_LOG_ACTIONS;
396 m_dwDefaultColumns |= GIT_LOG_ID;
397 m_dwDefaultColumns |= GIT_LOG_HASH;
399 else
400 hideColumns |= GIT_LOG_ID;
401 if(this->m_bShowBugtraqColumn)
402 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
403 else
404 hideColumns |= GIT_LOGLIST_BUG;
405 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
406 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
407 else
408 hideColumns |= GIT_LOGLIST_SVNREV;
409 SetRedraw(false);
411 m_ColumnManager.SetNames(normal, _countof(normal));
412 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
413 m_ColumnManager.SetRightAlign(LOGLIST_ID);
415 SetRedraw(true);
418 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
420 LVITEM rItem = { 0 };
421 rItem.mask = LVIF_STATE;
422 rItem.iItem = (int)Index;
423 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
424 GetItem(&rItem);
426 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(Index);
427 HBRUSH brush = nullptr;
429 if (!(rItem.state & LVIS_SELECTED))
431 int action = pLogEntry->GetRebaseAction();
432 if (action & LOGACTIONS_REBASE_SQUASH)
433 brush = ::CreateSolidBrush(RGB(156,156,156));
434 else if (action & LOGACTIONS_REBASE_EDIT)
435 brush = ::CreateSolidBrush(RGB(200,200,128));
437 else if (!IsAppThemed())
439 if (rItem.state & LVIS_SELECTED)
441 if (::GetFocus() == m_hWnd)
442 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
443 else
444 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
447 if (brush)
449 ::FillRect(hdc, &rect, brush);
450 ::DeleteObject(brush);
454 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
456 POINT point = { 4, 4 };
457 CRect rt2 = rect;
458 rt2.DeflateRect(1, 1);
459 rt2.OffsetRect(2, 2);
461 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
462 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
463 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
464 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
465 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
467 ::SelectObject(hdc, brush);
468 rt2.OffsetRect(-2, -2);
469 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
470 ::SelectObject(hdc, oldbrush);
471 ::SelectObject(hdc, oldpen);
472 ::DeleteObject(nullPen);
473 ::DeleteObject(darkBrush);
476 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
478 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
479 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
480 ::MoveToEx(hdc, rect.left + 7, rect.top, nullptr);
481 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
482 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
483 ::LineTo(hdc, rect.left, rect.bottom);
484 ::SelectObject(hdc, oldpen);
485 ::DeleteObject(pen);
488 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
490 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
491 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
492 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, nullptr);
493 ::LineTo(hdc, rect.left, rect.bottom);
494 ::LineTo(hdc, rect.right, rect.bottom);
495 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
496 ::SelectObject(hdc, oldpen);
497 ::DeleteObject(pen);
500 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
502 GitRevLoglist* data = m_arShownList.SafeGetAt(index);
503 CRect rt=rect;
504 LVITEM rItem = { 0 };
505 rItem.mask = LVIF_STATE;
506 rItem.iItem = (int)index;
507 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
508 GetItem(&rItem);
510 CDC W_Dc;
511 W_Dc.Attach(hdc);
513 HTHEME hTheme = nullptr;
514 if (IsAppThemed())
515 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
517 SIZE oneSpaceSize;
518 if (m_bTagsBranchesOnRightSide)
520 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
521 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
522 SelectObject(hdc, oldFont);
523 rt.left += oneSpaceSize.cx * 2;
525 else
527 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
528 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
529 rt.left += oneSpaceSize.cx;
532 CString msg = MessageDisplayStr(data);
533 int action = data->GetRebaseAction();
534 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
535 if (IsAppThemed())
537 int txtState = LISS_NORMAL;
538 if (rItem.state & LVIS_SELECTED)
539 txtState = LISS_SELECTED;
541 DTTOPTS opts = { 0 };
542 opts.dwSize = sizeof(opts);
543 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
544 opts.dwFlags = DTT_TEXTCOLOR;
545 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, msg, -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
547 else
549 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
551 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
552 ::DrawText(hdc,msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
553 ::SetTextColor(hdc, clrOld);
555 else
557 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
558 ::DrawText(hdc, msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
559 ::SetTextColor(hdc, clrOld);
563 if (m_bTagsBranchesOnRightSide)
565 SIZE size;
566 GetTextExtentPoint32(hdc, msg, msg.GetLength(), &size);
568 rt.left += oneSpaceSize.cx + size.cx;
570 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
573 if (hTheme)
574 CloseThemeData(hTheme);
576 W_Dc.Detach();
579 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
581 for (unsigned int i = 0; i < refList.size(); ++i)
583 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
584 HBRUSH brush = 0;
585 COLORREF colRef = refList[i].color;
586 bool singleRemote = refList[i].singleRemote;
587 bool hasTracking = refList[i].hasTracking;
588 bool sameName = refList[i].sameName;
589 CGit::REF_TYPE refType = refList[i].refType;
591 //When row selected, ajust label color
592 if (!IsAppThemed())
594 if (rItem.state & LVIS_SELECTED)
595 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
598 brush = ::CreateSolidBrush(colRef);
600 if (!shortname.IsEmpty() && (rt.left < rect.right))
602 SIZE size = { 0 };
603 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
605 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
606 rt.right += 8;
608 int textpos = DT_CENTER;
610 if (rt.right > rect.right)
612 rt.right = rect.right;
613 textpos = 0;
616 CRect textRect = rt;
618 if (singleRemote)
620 rt.right += 8;
621 textRect.OffsetRect(8, 0);
624 if (sameName)
625 rt.right += 8;
627 if (hasTracking)
628 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
629 else
631 //Fill interior of ref label
632 ::FillRect(hdc, &rt, brush);
635 //Draw edge of label
636 CRect rectEdge = rt;
638 if (!hasTracking)
640 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
641 rectEdge.DeflateRect(1, 1);
642 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
645 if (refType == CGit::REF_TYPE::ANNOTATED_TAG)
647 rt.right += 8;
648 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
649 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
650 ::FillRgn(hdc, hrgn, brush);
651 ::DeleteObject(hrgn);
652 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, nullptr);
653 HPEN pen;
654 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
655 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
656 ::DeleteObject(pen);
657 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
658 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
659 ::DeleteObject(pen);
660 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
661 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, nullptr);
662 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
663 ::DeleteObject(pen);
664 SelectObject(hdc, oldpen);
667 //Draw text inside label
668 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
669 if (!customColor && IsAppThemed())
671 int txtState = LISS_NORMAL;
672 if (rItem.state & LVIS_SELECTED)
673 txtState = LISS_SELECTED;
675 DTTOPTS opts = { 0 };
676 opts.dwSize = sizeof(opts);
677 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
678 opts.dwFlags = DTT_TEXTCOLOR;
679 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
681 else
683 W_Dc.SetBkMode(TRANSPARENT);
684 if (customColor || (rItem.state & LVIS_SELECTED))
686 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
687 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
688 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
689 ::SetTextColor(hdc,clrOld);
691 else
693 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
694 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
695 ::SetTextColor(hdc, clrOld);
699 if (singleRemote)
701 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
702 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
703 CRect newRect;
704 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
705 DrawLightning(hdc, newRect, color, bold);
708 if (sameName)
710 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
711 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
712 CRect newRect;
713 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
714 DrawUpTriangle(hdc, newRect, color, bold);
717 m_RefLabelPosMap[refList[i].fullName] = rt;
719 rt.left = rt.right + 1;
721 if (brush)
722 ::DeleteObject(brush);
724 rt.right = rect.right;
727 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
728 // Returns ((256 - amount)*col1 + amount*col2) / 256;
729 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
730 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
731 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
734 Gdiplus::Color GetGdiColor(COLORREF col)
736 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
738 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
739 const COLORREF& col,const COLORREF& activeColor, int top
742 int h = laneHeight / 2;
743 int m = (x1 + x2) / 2;
744 int r = (x2 - x1) * m_NodeSize / 30;
745 int d = 2 * r;
747 #define P_CENTER m , h+top
748 #define P_0 x2, h+top
749 #define P_90 m , 0+top-1
750 #define P_180 x1, h+top
751 #define P_270 m , 2 * h+top +1
752 #define R_CENTER m - r, h - r+top, d, d
755 #define DELTA_UR_B 2*(x1 - m), 2*h +top
756 #define DELTA_UR_E 0*16, 90*16 +top // -,
758 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
759 #define DELTA_DR_E 270*16, 90*16 +top // -'
761 #define DELTA_UL_B 2*(x2 - m), 2*h +top
762 #define DELTA_UL_E 90*16, 90*16 +top // ,-
764 #define DELTA_DL_B 2*(x2 - m),2*-h +top
765 #define DELTA_DL_E 180*16, 90*16 // '-
767 #define CENTER_UR x1, 2*h, 225
768 #define CENTER_DR x1, 0 , 135
769 #define CENTER_UL x2, 2*h, 315
770 #define CENTER_DL x2, 0 , 45
773 Gdiplus::Graphics graphics( hdc );
775 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
777 // arc
778 switch (type) {
779 case Lanes::JOIN:
780 case Lanes::JOIN_R:
781 case Lanes::HEAD:
782 case Lanes::HEAD_R:
784 Gdiplus::LinearGradientBrush gradient(
785 Gdiplus::Point(x1-2, h+top-2),
786 Gdiplus::Point(P_270),
787 GetGdiColor(activeColor),GetGdiColor(col));
790 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
791 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
793 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
794 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
795 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
797 break;
799 case Lanes::JOIN_L:
801 Gdiplus::LinearGradientBrush gradient(
802 Gdiplus::Point(P_270),
803 Gdiplus::Point(x2+1, h+top-1),
804 GetGdiColor(col),GetGdiColor(activeColor));
807 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
808 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
810 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
811 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
812 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
815 break;
817 case Lanes::TAIL:
818 case Lanes::TAIL_R:
820 Gdiplus::LinearGradientBrush gradient(
821 Gdiplus::Point(x1-2, h+top-2),
822 Gdiplus::Point(P_90),
823 GetGdiColor(activeColor),GetGdiColor(col));
825 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
827 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
829 #if 0
830 QConicalGradient gradient(CENTER_DR);
831 gradient.setColorAt(0.375, activeCol);
832 gradient.setColorAt(0.625, col);
833 myPen.setBrush(gradient);
834 p->setPen(myPen);
835 p->drawArc(P_CENTER, DELTA_DR);
836 #endif
837 break;
839 default:
840 break;
844 //static QPen myPen(Qt::black, 2); // fast path here
845 CPen pen;
846 pen.CreatePen(PS_SOLID,2,col);
847 //myPen.setColor(col);
848 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
850 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
852 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
854 //p->setPen(myPen);
856 // vertical line
857 switch (type) {
858 case Lanes::ACTIVE:
859 case Lanes::NOT_ACTIVE:
860 case Lanes::MERGE_FORK:
861 case Lanes::MERGE_FORK_R:
862 case Lanes::MERGE_FORK_L:
863 case Lanes::JOIN:
864 case Lanes::JOIN_R:
865 case Lanes::JOIN_L:
866 case Lanes::CROSS:
867 //DrawLine(hdc,P_90,P_270);
868 graphics.DrawLine(&myPen,P_90,P_270);
869 //p->drawLine(P_90, P_270);
870 break;
871 case Lanes::HEAD_L:
872 case Lanes::BRANCH:
873 //DrawLine(hdc,P_CENTER,P_270);
874 graphics.DrawLine(&myPen,P_CENTER,P_270);
875 //p->drawLine(P_CENTER, P_270);
876 break;
877 case Lanes::TAIL_L:
878 case Lanes::INITIAL:
879 case Lanes::BOUNDARY:
880 case Lanes::BOUNDARY_C:
881 case Lanes::BOUNDARY_R:
882 case Lanes::BOUNDARY_L:
883 //DrawLine(hdc,P_90, P_CENTER);
884 graphics.DrawLine(&myPen,P_90,P_CENTER);
885 //p->drawLine(P_90, P_CENTER);
886 break;
887 default:
888 break;
891 myPen.SetColor(GetGdiColor(activeColor));
893 // horizontal line
894 switch (type) {
895 case Lanes::MERGE_FORK:
896 case Lanes::JOIN:
897 case Lanes::HEAD:
898 case Lanes::TAIL:
899 case Lanes::CROSS:
900 case Lanes::CROSS_EMPTY:
901 case Lanes::BOUNDARY_C:
902 //DrawLine(hdc,P_180,P_0);
903 graphics.DrawLine(&myPen,P_180,P_0);
904 //p->drawLine(P_180, P_0);
905 break;
906 case Lanes::MERGE_FORK_R:
907 case Lanes::BOUNDARY_R:
908 //DrawLine(hdc,P_180,P_CENTER);
909 graphics.DrawLine(&myPen,P_180,P_CENTER);
910 //p->drawLine(P_180, P_CENTER);
911 break;
912 case Lanes::MERGE_FORK_L:
913 case Lanes::HEAD_L:
914 case Lanes::TAIL_L:
915 case Lanes::BOUNDARY_L:
916 //DrawLine(hdc,P_CENTER,P_0);
917 graphics.DrawLine(&myPen,P_CENTER,P_0);
918 //p->drawLine(P_CENTER, P_0);
919 break;
920 default:
921 break;
924 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
926 CBrush brush;
927 brush.CreateSolidBrush(col);
928 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
930 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
931 // center symbol, e.g. rect or ellipse
932 switch (type) {
933 case Lanes::ACTIVE:
934 case Lanes::INITIAL:
935 case Lanes::BRANCH:
937 //p->setPen(Qt::NoPen);
938 //p->setBrush(col);
939 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
940 graphics.FillEllipse(&myBrush, R_CENTER);
941 //p->drawEllipse(R_CENTER);
942 break;
943 case Lanes::MERGE_FORK:
944 case Lanes::MERGE_FORK_R:
945 case Lanes::MERGE_FORK_L:
946 //p->setPen(Qt::NoPen);
947 //p->setBrush(col);
948 //p->drawRect(R_CENTER);
949 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
950 graphics.FillRectangle(&myBrush, R_CENTER);
951 break;
952 case Lanes::UNAPPLIED:
953 // Red minus sign
954 //p->setPen(Qt::NoPen);
955 //p->setBrush(Qt::red);
956 //p->drawRect(m - r, h - 1, d, 2);
957 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
958 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
959 break;
960 case Lanes::APPLIED:
961 // Green plus sign
962 //p->setPen(Qt::NoPen);
963 //p->setBrush(DARK_GREEN);
964 //p->drawRect(m - r, h - 1, d, 2);
965 //p->drawRect(m - 1, h - r, 2, d);
966 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
967 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
968 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
969 break;
970 case Lanes::BOUNDARY:
971 //p->setBrush(back);
972 //p->drawEllipse(R_CENTER);
973 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
974 graphics.DrawEllipse(&myPen, R_CENTER);
975 break;
976 case Lanes::BOUNDARY_C:
977 case Lanes::BOUNDARY_R:
978 case Lanes::BOUNDARY_L:
979 //p->setBrush(back);
980 //p->drawRect(R_CENTER);
981 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
982 graphics.FillRectangle(&myBrush,R_CENTER);
983 break;
984 default:
985 break;
988 ::SelectObject(hdc,oldpen);
989 ::SelectObject(hdc,oldbrush);
990 #undef P_CENTER
991 #undef P_0
992 #undef P_90
993 #undef P_180
994 #undef P_270
995 #undef R_CENTER
998 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1000 // TODO: unfinished
1001 // return;
1002 GitRevLoglist* data = m_arShownList.SafeGetAt(index);
1003 if(data->m_CommitHash.IsEmpty())
1004 return;
1006 CRect rt=rect;
1007 LVITEM rItem = { 0 };
1008 rItem.mask = LVIF_STATE;
1009 rItem.iItem = (int)index;
1010 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1011 GetItem(&rItem);
1013 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1015 if (data->m_Lanes.empty())
1016 m_logEntries.setLane(data->m_CommitHash);
1018 std::vector<int>& lanes=data->m_Lanes;
1019 size_t laneNum = lanes.size();
1020 UINT activeLane = 0;
1021 for (UINT i = 0; i < laneNum; ++i)
1022 if (Lanes::isMerge(lanes[i])) {
1023 activeLane = i;
1024 break;
1027 int x2 = 0;
1028 int maxWidth = rect.Width();
1029 int lw = 3 * rect.Height() / 4; //laneWidth()
1031 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1032 //if (opt.state & QStyle::State_Selected)
1033 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1035 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1037 int x1 = x2;
1038 x2 += lw;
1040 int ln = lanes[i];
1041 if (ln == Lanes::EMPTY)
1042 continue;
1044 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1045 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1048 #if 0
1049 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1050 int x1 = x2;
1051 x2 += lw;
1053 int ln = lanes[i];
1054 if (ln == Lanes::EMPTY)
1055 continue;
1057 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1058 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1060 if (ln == Lanes::CROSS)
1062 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1063 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1065 else
1066 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1068 #endif
1071 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1073 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1074 // Take the default processing unless we set this to something else below.
1075 *pResult = CDRF_DODEFAULT;
1077 if (m_bNoDispUpdates)
1078 return;
1080 switch (pLVCD->nmcd.dwDrawStage)
1082 case CDDS_PREPAINT:
1084 *pResult = CDRF_NOTIFYITEMDRAW;
1085 return;
1087 break;
1088 case CDDS_ITEMPREPAINT:
1090 // This is the prepaint stage for an item. Here's where we set the
1091 // item's text color.
1093 // Tell Windows to send draw notifications for each subitem.
1094 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1096 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1098 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec)
1100 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1101 if (data)
1103 HGDIOBJ hGdiObj = nullptr;
1104 int action = data->GetRebaseAction();
1105 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1106 crText = RGB(128,128,128);
1108 if (action & LOGACTIONS_REBASE_SQUASH)
1109 pLVCD->clrTextBk = RGB(156,156,156);
1110 else if (action & LOGACTIONS_REBASE_EDIT)
1111 pLVCD->clrTextBk = RGB(200,200,128);
1112 else
1113 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1115 if (action & LOGACTIONS_REBASE_CURRENT)
1116 hGdiObj = m_boldFont.GetSafeHandle();
1118 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1119 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1120 if (isHeadHash && isHighlight)
1121 hGdiObj = m_boldItalicsFont.GetSafeHandle();
1122 else if (isHeadHash)
1123 hGdiObj = m_boldFont.GetSafeHandle();
1124 else if (isHighlight)
1125 hGdiObj = m_FontItalics.GetSafeHandle();
1127 if (hGdiObj)
1129 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1130 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1133 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1134 // crText = GetSysColor(COLOR_GRAYTEXT);
1136 if (data->m_CommitHash.IsEmpty())
1138 //crText = GetSysColor(RGB(200,200,0));
1139 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1140 // We changed the font, so we're returning CDRF_NEWFONT. This
1141 // tells the control to recalculate the extent of the text.
1142 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1146 if (m_arShownList.size() == pLVCD->nmcd.dwItemSpec)
1148 if (m_bStrictStopped)
1149 crText = GetSysColor(COLOR_GRAYTEXT);
1151 // Store the color back in the NMLVCUSTOMDRAW struct.
1152 pLVCD->clrText = crText;
1153 return;
1155 break;
1156 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1158 if (m_bStrictStopped && m_arShownList.size() == pLVCD->nmcd.dwItemSpec)
1160 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1163 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1165 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec && !this->m_IsRebaseReplaceGraph)
1167 CRect rect;
1168 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1170 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1171 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1173 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1174 if( !data ->m_CommitHash.IsEmpty())
1175 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1177 *pResult = CDRF_SKIPDEFAULT;
1178 return;
1182 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1184 // If the top index of list is changed, the position map of reference label is outdated.
1185 if (m_OldTopIndex != GetTopIndex())
1187 m_OldTopIndex = GetTopIndex();
1188 m_RefLabelPosMap.clear();
1191 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec)
1193 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1195 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1197 CRect rect;
1198 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1200 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1201 // not in FillBackGround method, because this only affected the message subitem
1202 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1203 return;
1205 int index = (int)pLVCD->nmcd.dwItemSpec;
1206 int state = GetItemState(index, LVIS_SELECTED);
1207 int txtState = LISS_NORMAL;
1208 if (IsAppThemed() && GetHotItem() == (int)index)
1210 if (state & LVIS_SELECTED)
1211 txtState = LISS_HOTSELECTED;
1212 else
1213 txtState = LISS_HOT;
1215 else if (state & LVIS_SELECTED)
1217 if (::GetFocus() == m_hWnd)
1218 txtState = LISS_SELECTED;
1219 else
1220 txtState = LISS_SELECTEDNOTFOCUS;
1223 HTHEME hTheme = nullptr;
1224 if (IsAppThemed())
1225 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1227 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1228 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1229 else
1231 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1232 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1233 ::DeleteObject(brush);
1235 if (hTheme && txtState != LISS_NORMAL)
1237 CRect rt;
1238 // get rect of whole line
1239 GetItemRect(index, rt, LVIR_BOUNDS);
1240 CRect rect2 = rect;
1242 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1243 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1245 CloseThemeData(hTheme);
1247 // END: extended redraw
1249 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1251 std::vector<REFLABEL> refsToShow;
1252 STRING_VECTOR remoteTrackingList;
1253 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1254 for (unsigned int i = 0; i < refList.size(); ++i)
1256 CString str = refList[i];
1258 REFLABEL refLabel;
1259 refLabel.color = RGB(255, 255, 255);
1260 refLabel.singleRemote = false;
1261 refLabel.hasTracking = false;
1262 refLabel.sameName = false;
1263 refLabel.name = CGit::GetShortName(str, &refLabel.refType);
1264 refLabel.fullName = str;
1266 switch (refLabel.refType)
1268 case CGit::REF_TYPE::LOCAL_BRANCH:
1270 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1271 continue;
1272 if (refLabel.name == m_CurrentBranch)
1273 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1274 else
1275 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1277 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1278 CString pullRemote = trackingEntry.first;
1279 CString pullBranch = trackingEntry.second;
1280 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1282 CString defaultUpstream;
1283 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1284 refLabel.hasTracking = true;
1285 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1287 bool found = false;
1288 for (size_t j = i + 1; j < refList.size(); ++j)
1290 if (refList[j] == defaultUpstream)
1292 found = true;
1293 break;
1297 if (found)
1299 bool sameName = pullBranch == refLabel.name;
1300 refsToShow.push_back(refLabel);
1301 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1302 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1303 if (m_bSymbolizeRefNames)
1305 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1307 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1308 refLabel.singleRemote = true;
1310 else if (sameName)
1311 refLabel.simplifiedName = pullRemote + _T("/");
1312 refLabel.sameName = sameName;
1314 refLabel.fullName = defaultUpstream;
1315 refsToShow.push_back(refLabel);
1316 remoteTrackingList.push_back(defaultUpstream);
1317 continue;
1321 break;
1323 case CGit::REF_TYPE::REMOTE_BRANCH:
1325 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1326 continue;
1327 bool found = false;
1328 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1330 if (remoteTrackingList[j] == str)
1332 found = true;
1333 break;
1336 if (found)
1337 continue;
1339 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1340 if (m_bSymbolizeRefNames)
1342 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1344 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1345 refLabel.singleRemote = true;
1348 break;
1350 case CGit::REF_TYPE::ANNOTATED_TAG:
1351 case CGit::REF_TYPE::TAG:
1352 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1353 continue;
1354 refLabel.color = m_Colors.GetColor(CColors::Tag);
1355 break;
1356 case CGit::REF_TYPE::STASH:
1357 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1358 continue;
1359 refLabel.color = m_Colors.GetColor(CColors::Stash);
1360 break;
1361 case CGit::REF_TYPE::BISECT_GOOD:
1362 case CGit::REF_TYPE::BISECT_BAD:
1363 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1364 continue;
1365 refLabel.color = (refLabel.refType == CGit::REF_TYPE::BISECT_GOOD) ? m_Colors.GetColor(CColors::BisectGood): m_Colors.GetColor(CColors::BisectBad);
1366 break;
1367 default:
1368 continue;
1370 refsToShow.push_back(refLabel);
1373 if (refsToShow.empty())
1375 *pResult = CDRF_DODEFAULT;
1376 return;
1379 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1381 *pResult = CDRF_SKIPDEFAULT;
1382 return;
1389 if (pLVCD->iSubItem == LOGLIST_ACTION)
1391 if(this->m_IsIDReplaceAction)
1393 *pResult = CDRF_DODEFAULT;
1394 return;
1396 *pResult = CDRF_DODEFAULT;
1398 if (m_arShownList.size() <= pLVCD->nmcd.dwItemSpec)
1399 return;
1401 int nIcons = 0;
1402 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1403 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1405 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1406 CRect rect;
1407 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1408 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1409 // Get the selected state of the
1410 // item being drawn.
1412 // Fill the background if necessary
1413 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1415 // Draw the icon(s) into the compatible DC
1416 int action = pLogEntry->GetAction(this);
1417 if (!pLogEntry->m_IsDiffFiles)
1419 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1420 *pResult = CDRF_SKIPDEFAULT;
1421 return;
1424 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1425 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1426 ++nIcons;
1428 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1429 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1430 ++nIcons;
1432 if (action & CTGitPath::LOGACTIONS_DELETED)
1433 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1434 ++nIcons;
1436 if (action & CTGitPath::LOGACTIONS_REPLACED)
1437 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1438 ++nIcons;
1440 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1441 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1442 ++nIcons;
1444 *pResult = CDRF_SKIPDEFAULT;
1445 return;
1448 break;
1450 *pResult = CDRF_DODEFAULT;
1453 CString FindSVNRev(const CString& msg)
1457 const std::tr1::wsregex_iterator end;
1458 std::wstring s = msg;
1459 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1460 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex1); it != end; ++it)
1462 const std::tr1::wsmatch match = *it;
1463 if (match.size() == 4)
1465 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1466 return std::wstring(match[2]).c_str();
1469 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1470 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex2); it != end; ++it)
1472 const std::tr1::wsmatch match = *it;
1473 if (match.size() == 3)
1475 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1476 return std::wstring(match[1]).c_str();
1480 catch (std::exception) {}
1482 return _T("");
1485 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1487 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1488 return pLogEntry->GetSubject();
1490 CString txt(pLogEntry->GetSubject());
1491 txt += _T(' ');
1492 txt += pLogEntry->GetBody();
1494 // Deal with CRLF
1495 txt.Replace(_T('\n'), _T(' '));
1496 txt.Replace(_T('\r'), _T(' '));
1498 return txt;
1501 // CGitLogListBase message handlers
1503 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1505 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1507 // Create a pointer to the item
1508 LV_ITEM* pItem = &(pDispInfo)->item;
1510 // Do the list need text information?
1511 if (!(pItem->mask & LVIF_TEXT))
1512 return;
1514 // By default, clear text buffer.
1515 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1517 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1519 *pResult = 0;
1520 if (m_bNoDispUpdates || bOutOfRange)
1521 return;
1523 // Which item number?
1524 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem);
1526 CString temp;
1527 if(m_IsOldFirst)
1528 temp.Format(_T("%d"),pItem->iItem+1);
1529 else
1530 temp.Format(_T("%d"), m_arShownList.size() - pItem->iItem);
1532 // Which column?
1533 switch (pItem->iSubItem)
1535 case LOGLIST_GRAPH: //Graphic
1536 break;
1537 case LOGLIST_REBASE:
1539 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1540 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1542 break;
1543 case LOGLIST_ACTION: //action -- no text in the column
1544 break;
1545 case LOGLIST_HASH:
1546 if(pLogEntry)
1547 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1548 break;
1549 case LOGLIST_ID:
1550 if(this->m_IsIDReplaceAction)
1551 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1552 break;
1553 case LOGLIST_MESSAGE: //Message
1554 if (pLogEntry)
1555 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1556 break;
1557 case LOGLIST_AUTHOR: //Author
1558 if (pLogEntry)
1559 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1560 break;
1561 case LOGLIST_DATE: //Date
1562 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1563 lstrcpyn(pItem->pszText,
1564 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1565 pItem->cchTextMax - 1);
1566 break;
1568 case LOGLIST_EMAIL:
1569 if (pLogEntry)
1570 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1571 break;
1573 case LOGLIST_COMMIT_NAME: //Commit
1574 if (pLogEntry)
1575 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1576 break;
1578 case LOGLIST_COMMIT_EMAIL: //Commit Email
1579 if (pLogEntry)
1580 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1581 break;
1583 case LOGLIST_COMMIT_DATE: //Commit Date
1584 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1585 lstrcpyn(pItem->pszText,
1586 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1587 pItem->cchTextMax - 1);
1588 break;
1589 case LOGLIST_BUG: //Bug ID
1590 if(pLogEntry)
1591 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1592 break;
1593 case LOGLIST_SVNREV: //SVN revision
1594 if (pLogEntry)
1595 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1596 break;
1598 default:
1599 ASSERT(false);
1603 bool CGitLogListBase::IsOnStash(int index)
1605 GitRevLoglist* rev = m_arShownList.SafeGetAt(index);
1606 if (IsStash(rev))
1607 return true;
1608 if (index > 0)
1610 GitRevLoglist* preRev = m_arShownList.SafeGetAt(index - 1);
1611 if (IsStash(preRev))
1612 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1614 return false;
1617 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1619 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1621 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1622 return true;
1624 return false;
1627 bool CGitLogListBase::IsBisect(const GitRev * pSelLogEntry)
1629 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1631 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Left(12) == _T("refs/bisect/"))
1632 return true;
1634 return false;
1637 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1639 if (pRev->m_ParentHash.empty())
1641 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1642 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1644 parentHash = pRev->m_ParentHash;
1647 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1649 __super::OnContextMenu(pWnd, point);
1651 if (pWnd != this)
1652 return;
1654 int selIndex = GetSelectionMark();
1655 if (selIndex < 0)
1656 return; // nothing selected, nothing to do with a context menu
1658 // if the user selected the info text telling about not all revisions shown due to
1659 // the "stop on copy/rename" option, we also don't show the context menu
1660 if (m_bStrictStopped && selIndex == (int)m_arShownList.size())
1661 return;
1663 // if the context menu is invoked through the keyboard, we have to use
1664 // a calculated position on where to anchor the menu on
1665 if ((point.x == -1) && (point.y == -1))
1667 CRect rect;
1668 GetItemRect(selIndex, &rect, LVIR_LABEL);
1669 ClientToScreen(&rect);
1670 point = rect.CenterPoint();
1672 m_nSearchIndex = selIndex;
1673 m_bCancelled = FALSE;
1675 // calculate some information the context menu commands can use
1676 // CString pathURL = GetURLFromPath(m_path);
1678 POSITION pos = GetFirstSelectedItemPosition();
1679 int indexNext = GetNextSelectedItem(pos);
1680 if (indexNext < 0)
1681 return;
1683 GitRevLoglist* pSelLogEntry = m_arShownList.SafeGetAt(indexNext);
1684 if (pSelLogEntry == nullptr)
1685 return;
1686 #if 0
1687 GitRev revSelected = pSelLogEntry->Rev;
1688 GitRev revPrevious = git_revnum_t(revSelected)-1;
1689 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1691 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1693 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1694 if (changedpath->lCopyFromRev)
1695 revPrevious = changedpath->lCopyFromRev;
1698 GitRev revSelected2;
1699 if (pos)
1701 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1702 revSelected2 = pLogEntry->Rev;
1704 bool bAllFromTheSameAuthor = true;
1705 CString firstAuthor;
1706 CLogDataVector selEntries;
1707 GitRev revLowest, revHighest;
1708 GitRevRangeArray revisionRanges;
1710 POSITION pos = GetFirstSelectedItemPosition();
1711 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1712 revisionRanges.AddRevision(pLogEntry->Rev);
1713 selEntries.push_back(pLogEntry);
1714 firstAuthor = pLogEntry->sAuthor;
1715 revLowest = pLogEntry->Rev;
1716 revHighest = pLogEntry->Rev;
1717 while (pos)
1719 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1720 revisionRanges.AddRevision(pLogEntry->Rev);
1721 selEntries.push_back(pLogEntry);
1722 if (firstAuthor.Compare(pLogEntry->sAuthor))
1723 bAllFromTheSameAuthor = false;
1724 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1725 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1729 #endif
1731 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1733 int FirstSelect=-1, LastSelect=-1;
1734 pos = GetFirstSelectedItemPosition();
1735 FirstSelect = GetNextSelectedItem(pos);
1736 while(pos)
1738 LastSelect = GetNextSelectedItem(pos);
1740 //entry is selected, now show the popup menu
1741 CIconMenu popup;
1742 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1744 if (popup.CreatePopupMenu())
1746 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1747 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1748 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1749 bool isStash = IsOnStash(indexNext);
1750 GIT_REV_LIST parentHash;
1751 GetParentHashes(pSelLogEntry, parentHash);
1753 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1754 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1756 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))
1757 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1759 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1760 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1762 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1763 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1765 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)))
1766 popup.AppendMenu(MF_SEPARATOR, NULL);
1768 if (GetSelectedCount() == 1)
1771 bool requiresSeparator = false;
1772 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1774 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1776 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1777 requiresSeparator = true;
1780 else
1782 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1784 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1785 requiresSeparator = true;
1787 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1789 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1790 requiresSeparator = true;
1794 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1796 if (parentHash.size() == 1)
1798 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1799 requiresSeparator = true;
1801 else if (parentHash.size() > 1)
1803 blamemenu.CreatePopupMenu();
1804 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1805 for (size_t i = 0; i < parentHash.size(); ++i)
1807 CString str;
1808 str.Format(IDS_PARENT, i + 1);
1809 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1811 requiresSeparator = true;
1815 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1817 if (parentHash.size() == 1)
1819 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1820 requiresSeparator = true;
1822 else if (parentHash.size() > 1)
1824 gnudiffmenu.CreatePopupMenu();
1825 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1827 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1828 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1829 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1831 for (size_t i = 0; i < parentHash.size(); ++i)
1833 CString str;
1834 str.Format(IDS_PARENT, i + 1);
1835 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1837 requiresSeparator = true;
1841 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1843 if (parentHash.size() == 1)
1845 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1846 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1847 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1848 requiresSeparator = true;
1850 else if (parentHash.size() > 1)
1852 diffmenu.CreatePopupMenu();
1853 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1854 for (size_t i = 0; i < parentHash.size(); ++i)
1856 CString str;
1857 str.Format(IDS_PARENT, i + 1);
1858 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1859 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1861 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1862 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1865 requiresSeparator = true;
1869 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1871 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1872 requiresSeparator = true;
1875 if (requiresSeparator)
1877 popup.AppendMenu(MF_SEPARATOR, NULL);
1878 requiresSeparator = false;
1881 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1883 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1885 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1886 requiresSeparator = true;
1890 if ((pSelLogEntry->m_CommitHash.IsEmpty() || isStash) && CTGitPath(g_Git.m_CurrentDir).HasStashDir())
1892 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1894 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1895 requiresSeparator = true;
1898 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1900 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1901 requiresSeparator = true;
1905 if (requiresSeparator)
1907 popup.AppendMenu(MF_SEPARATOR, NULL);
1908 requiresSeparator = false;
1911 if (CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1913 GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect);
1914 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTGOOD) && !IsBisect(pFirstEntry))
1916 popup.AppendMenuIcon(ID_BISECTGOOD, IDS_MENUBISECTGOOD, IDI_THUMB_UP);
1917 requiresSeparator = true;
1920 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTBAD) && !IsBisect(pFirstEntry))
1922 popup.AppendMenuIcon(ID_BISECTBAD, IDS_MENUBISECTBAD, IDI_THUMB_DOWN);
1923 requiresSeparator = true;
1927 if (pSelLogEntry->m_CommitHash.IsEmpty() && CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1929 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTRESET))
1931 popup.AppendMenuIcon(ID_BISECTRESET, IDS_MENUBISECTRESET, IDI_BISECT_RESET);
1932 requiresSeparator = true;
1936 if (requiresSeparator)
1938 popup.AppendMenu(MF_SEPARATOR, NULL);
1939 requiresSeparator = false;
1942 if (pSelLogEntry->m_CommitHash.IsEmpty())
1944 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1945 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1947 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1948 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1950 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1951 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1953 popup.AppendMenu(MF_SEPARATOR, NULL);
1955 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1956 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1958 popup.AppendMenu(MF_SEPARATOR, NULL);
1962 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1963 // {
1964 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1965 // }
1966 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1967 // {
1968 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1969 // }
1970 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1971 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1972 // {
1973 // popup.AppendMenu(MF_SEPARATOR, NULL);
1974 // }
1976 CString str;
1977 //if (m_hasWC)
1978 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1980 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1982 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1983 GetSelectedCount() == 1)
1984 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1986 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1987 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1989 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
1991 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
1993 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1995 size_t index = (size_t)-1;
1996 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
1997 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
1998 popup.SetMenuItemData(ID_MERGEREV, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2001 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2003 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2004 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2007 // Add Switch Branch express Menu
2008 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2009 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2012 std::vector<const CString*> branchs;
2013 auto addCheck = [&](const CString& ref)
2015 if (ref.Find(_T("refs/heads/")) != 0 || ref == currentBranch)
2016 return;
2017 branchs.push_back(&ref);
2019 size_t index = (size_t)-1;
2020 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2021 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2022 addCheck(m_HashMap[pSelLogEntry->m_CommitHash][index]);
2023 else
2024 for_each(m_HashMap[pSelLogEntry->m_CommitHash], addCheck);
2026 CString str2;
2027 str2.LoadString(IDS_SWITCH_BRANCH);
2029 if(branchs.size() == 1)
2031 str2 += _T(' ');
2032 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2033 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2035 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2038 else if(branchs.size() > 1)
2040 subbranchmenu.CreatePopupMenu();
2041 for (size_t i = 0 ; i < branchs.size(); ++i)
2043 if (*branchs[i] != currentBranch)
2045 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2046 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2050 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2054 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2056 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS, IDI_SWITCH);
2057 size_t index = (size_t)-1;
2058 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2059 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2060 popup.SetMenuItemData(ID_SWITCHTOREV, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2063 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2065 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS, IDI_COPY);
2067 size_t index = (size_t)-1;
2068 CGit::REF_TYPE type = CGit::REF_TYPE::REMOTE_BRANCH;
2069 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2070 popup.SetMenuItemData(ID_CREATE_BRANCH, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2073 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2074 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2076 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2078 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2079 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2080 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2082 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2083 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2085 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2087 if (parentHash.size() == 1)
2088 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2089 else if (parentHash.size() > 1)
2091 revertmenu.CreatePopupMenu();
2092 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2094 for (size_t i = 0; i < parentHash.size(); ++i)
2096 CString str2;
2097 str2.Format(IDS_PARENT, i + 1);
2098 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2103 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2104 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2106 popup.AppendMenu(MF_SEPARATOR, NULL);
2110 if(!pSelLogEntry->m_Ref.IsEmpty())
2112 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2113 if (GetSelectedCount() == 1 && CStringUtils::StartsWith(pSelLogEntry->m_Ref, L"refs/stash"))
2114 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2115 popup.AppendMenu(MF_SEPARATOR, NULL);
2118 if (GetSelectedCount() >= 2)
2120 bool bAddSeparator = false;
2121 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2123 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2124 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2127 if (GetSelectedCount() == 2)
2129 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2130 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2132 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2134 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2135 GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect);
2136 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2137 CString menu;
2138 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2139 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2140 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2141 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2144 bAddSeparator = true;
2147 if (m_hasWC)
2148 bAddSeparator = true;
2150 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2151 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2153 if (bAddSeparator)
2154 popup.AppendMenu(MF_SEPARATOR, NULL);
2157 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2159 bool bAddSeparator = false;
2160 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2162 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2164 CString head;
2165 int headindex;
2166 headindex = this->GetHeadIndex();
2167 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2169 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2170 CGitHash hashFirst;
2171 if (g_Git.GetHash(hashFirst, head))
2172 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2173 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2174 CGitHash hash;
2175 if (g_Git.GetHash(hash, head))
2176 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2177 GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect);
2178 GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect);
2179 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2180 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2181 bAddSeparator = true;
2186 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2187 if (GetSelectedCount() >= 2)
2188 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2189 else
2190 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2191 bAddSeparator = true;
2194 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2195 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2196 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2197 bAddSeparator = true;
2200 if (bAddSeparator)
2201 popup.AppendMenu(MF_SEPARATOR, NULL);
2204 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())
2206 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2207 popup.AppendMenu(MF_SEPARATOR, NULL);
2210 if (GetSelectedCount() == 1)
2212 bool bAddSeparator = false;
2213 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2215 // show the push-option only if the log entry has an associated local branch
2216 bool isLocal = find_if(m_HashMap[pSelLogEntry->m_CommitHash], [](const CString& ref) { return CStringUtils::StartsWith(ref, L"refs/heads/"); }) != m_HashMap[pSelLogEntry->m_CommitHash].cend();
2217 if (isLocal || showExtendedMenu)
2219 CString str;
2220 str.LoadString(IDS_LOG_PUSH);
2222 CString branch;
2223 size_t index = (size_t)-1;
2224 CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH;
2225 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, &branch, &index))
2226 str.Insert(str.Find(L'.'), L" \"" + branch + L'"');
2228 popup.AppendMenuIcon(ID_PUSH, str, IDI_PUSH);
2230 if (index != (size_t)-1 && index < m_HashMap[pSelLogEntry->m_CommitHash].size())
2231 popup.SetMenuItemData(ID_PUSH, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2233 bAddSeparator = true;
2236 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2238 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2239 bAddSeparator = true;
2243 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2245 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2247 std::vector<const CString*> branchs;
2248 auto addCheck = [&](const CString& ref)
2250 if (ref == currentBranch)
2251 return;
2252 branchs.push_back(&ref);
2254 size_t index = (size_t)-1;
2255 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2256 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2257 addCheck(m_HashMap[pSelLogEntry->m_CommitHash][index]);
2258 else
2259 for_each(m_HashMap[pSelLogEntry->m_CommitHash], addCheck);
2261 CString str;
2262 if (branchs.size() == 1)
2264 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2265 str+=_T(' ');
2266 str += *branchs[0];
2267 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2268 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2269 bAddSeparator = true;
2271 else if (branchs.size() > 1)
2273 str.LoadString(IDS_DELETE_BRANCHTAG);
2274 submenu.CreatePopupMenu();
2275 for (size_t i = 0; i < branchs.size(); ++i)
2277 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2278 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2280 submenu.AppendMenuIcon(ID_DELETE + (branchs.size() << 16), IDS_ALL);
2281 submenu.SetMenuItemData(ID_DELETE + (branchs.size() << 16), (ULONG_PTR)MAKEINTRESOURCE(IDS_ALL));
2283 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2284 bAddSeparator = true;
2287 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2288 if (bAddSeparator)
2289 popup.AppendMenu(MF_SEPARATOR, NULL);
2290 } // GetSelectedCount() == 1
2292 if (GetSelectedCount() != 0)
2294 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2295 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2296 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2297 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2298 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2299 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2302 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2303 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2305 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2306 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2308 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2309 // DialogEnableWindow(IDOK, FALSE);
2310 // SetPromptApp(&theApp);
2312 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2314 // EnableOKButton();
2315 } // if (popup.CreatePopupMenu())
2318 bool CGitLogListBase::IsSelectionContinuous()
2320 if ( GetSelectedCount()==1 )
2322 // if only one revision is selected, the selection is of course
2323 // continuous
2324 return true;
2327 POSITION pos = GetFirstSelectedItemPosition();
2328 bool bContinuous = (m_arShownList.size() == m_logEntries.size());
2329 if (bContinuous)
2331 int itemindex = GetNextSelectedItem(pos);
2332 while (pos)
2334 int nextindex = GetNextSelectedItem(pos);
2335 if (nextindex - itemindex > 1)
2337 bContinuous = false;
2338 break;
2340 itemindex = nextindex;
2343 return bContinuous;
2346 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2348 CString sClipdata;
2349 POSITION pos = GetFirstSelectedItemPosition();
2350 if (pos)
2352 CString sRev;
2353 sRev.LoadString(IDS_LOG_REVISION);
2354 CString sAuthor;
2355 sAuthor.LoadString(IDS_LOG_AUTHOR);
2356 CString sDate;
2357 sDate.LoadString(IDS_LOG_DATE);
2358 CString sMessage;
2359 sMessage.LoadString(IDS_LOG_MESSAGE);
2360 bool first = true;
2361 while (pos)
2363 CString sLogCopyText;
2364 CString sPaths;
2365 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(GetNextSelectedItem(pos));
2367 if (toCopy == ID_COPY_ALL)
2369 //pLogEntry->GetFiles(this)
2370 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2372 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2373 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2375 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2376 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2378 sPaths += L' ';
2379 sPaths.AppendFormat(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2381 sPaths += _T("\r\n");
2383 sPaths.Trim();
2384 CString body = pLogEntry->GetBody();
2385 body.Replace(_T("\n"), _T("\r\n"));
2386 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"),
2387 (LPCTSTR)sRev, (LPCTSTR)pLogEntry->m_CommitHash.ToString(),
2388 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2389 (LPCTSTR)sDate,
2390 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2391 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->GetSubjectBody(true),
2392 (LPCTSTR)sPaths);
2393 sClipdata += sLogCopyText;
2395 else if (toCopy == ID_COPY_MESSAGE)
2397 sClipdata += _T("* ");
2398 sClipdata += pLogEntry->GetSubjectBody(true);
2399 sClipdata += _T("\r\n\r\n");
2401 else if (toCopy == ID_COPY_SUBJECT)
2403 sClipdata += _T("* ");
2404 sClipdata += pLogEntry->GetSubject().Trim();
2405 sClipdata += _T("\r\n\r\n");
2407 else
2409 if (!first)
2410 sClipdata += _T("\r\n");
2411 sClipdata += pLogEntry->m_CommitHash;
2414 first = false;
2416 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2420 void CGitLogListBase::DiffSelectedRevWithPrevious()
2422 if (m_bThreadRunning)
2423 return;
2425 int FirstSelect=-1, LastSelect=-1;
2426 POSITION pos = GetFirstSelectedItemPosition();
2427 FirstSelect = GetNextSelectedItem(pos);
2428 while(pos)
2429 LastSelect = GetNextSelectedItem(pos);
2431 ContextMenuAction(ID_COMPAREWITHPREVIOUS, FirstSelect, LastSelect, nullptr);
2434 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2436 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2437 *pResult = -1;
2439 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2440 return;
2441 if (pFindInfo->iStart < 0 || pFindInfo->iStart >= (int)m_arShownList.size())
2442 return;
2443 if (!pFindInfo->lvfi.psz)
2444 return;
2445 #if 0
2446 CString sCmp = pFindInfo->lvfi.psz;
2447 CString sRev;
2448 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2450 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2451 sRev.Format(_T("%ld"), pLogEntry->Rev);
2452 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2454 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2456 *pResult = i;
2457 return;
2460 else
2462 if (sCmp.Compare(sRev)==0)
2464 *pResult = i;
2465 return;
2469 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2471 for (int i=0; i<pFindInfo->iStart; ++i)
2473 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2474 sRev.Format(_T("%ld"), pLogEntry->Rev);
2475 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2477 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2479 *pResult = i;
2480 return;
2483 else
2485 if (sCmp.Compare(sRev)==0)
2487 *pResult = i;
2488 return;
2493 #endif
2494 *pResult = -1;
2497 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2499 ClearText();
2501 this->m_arShownList.SafeRemoveAll();
2503 this->m_logEntries.ClearAll();
2504 if (this->m_logEntries.ParserFromLog(path, 0, info, range))
2505 return -1;
2507 SetItemCountEx((int)m_logEntries.size());
2509 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2511 if(m_IsOldFirst)
2513 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2514 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2516 else
2518 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2519 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2523 ReloadHashMap();
2525 if(path)
2526 m_Path=*path;
2527 return 0;
2530 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2532 ClearText();
2534 m_arShownList.SafeRemoveAll();
2536 m_logEntries.ClearAll();
2537 if (m_logEntries.Fill(hashes))
2538 return -1;
2540 SetItemCountEx((int)m_logEntries.size());
2542 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2544 if (m_IsOldFirst)
2546 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2547 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2549 else
2551 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2552 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2556 ReloadHashMap();
2558 return 0;
2561 int CGitLogListBase::BeginFetchLog()
2563 ClearText();
2565 this->m_arShownList.SafeRemoveAll();
2567 this->m_logEntries.ClearAll();
2569 this->m_LogCache.ClearAllParent();
2571 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2573 CTGitPath *path;
2574 if(this->m_Path.IsEmpty())
2575 path = nullptr;
2576 else
2577 path=&this->m_Path;
2579 int mask;
2580 mask = CGit::LOG_INFO_ONLY_HASH;
2581 if (m_bIncludeBoundaryCommits)
2582 mask |= CGit::LOG_INFO_BOUNDARY;
2583 // if(this->m_bAllBranch)
2584 mask |= m_ShowMask ;
2586 if(m_bShowWC)
2588 this->m_logEntries.insert(m_logEntries.cbegin(), m_wcRev.m_CommitHash);
2589 ResetWcRev();
2590 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2593 if (m_sRange.IsEmpty())
2594 m_sRange = _T("HEAD");
2596 #if 0 /* use tortoiegit filter */
2597 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2598 data.m_Author = this->m_sFilterText;
2600 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2601 data.m_MessageFilter = this->m_sFilterText;
2603 data.m_IsRegex = m_bFilterWithRegex;
2604 #endif
2606 // follow does not work for directories
2607 if (!path || path->IsDirectory())
2608 mask &= ~CGit::LOG_INFO_FOLLOW;
2609 // follow does not work with all branches 8at least in TGit)
2610 if (mask & CGit::LOG_INFO_FOLLOW)
2611 mask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES);
2613 CString cmd = g_Git.GetLogCmd(m_sRange, path, mask, &m_Filter, CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER));
2615 //this->m_logEntries.ParserFromLog();
2616 if(IsInWorkingThread())
2618 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2620 else
2622 SetItemCountEx((int)m_logEntries.size());
2627 [] { git_init(); } ();
2629 catch (char* msg)
2631 CString err(msg);
2632 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2633 return -1;
2636 if (!g_Git.CanParseRev(m_sRange))
2638 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_BASIC_REFS) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2639 return 0;
2641 // if show all branches, pick any ref as dummy entry ref
2642 STRING_VECTOR list;
2643 if (g_Git.GetRefList(list))
2644 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2645 if (list.empty())
2646 return 0;
2648 cmd = g_Git.GetLogCmd(list[0], path, mask, &m_Filter, CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER));
2651 g_Git.m_critGitDllSec.Lock();
2652 try {
2653 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2655 g_Git.m_critGitDllSec.Unlock();
2656 return -1;
2659 catch (char* msg)
2661 g_Git.m_critGitDllSec.Unlock();
2662 CString err(msg);
2663 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2664 return -1;
2666 g_Git.m_critGitDllSec.Unlock();
2668 return 0;
2671 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2673 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2675 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2677 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2679 DiffSelectedRevWithPrevious();
2680 return TRUE;
2683 #if 0
2684 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2686 DiffSelectedFile();
2687 return TRUE;
2689 #endif
2691 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2693 // select all entries
2694 for (int i=0; i<GetItemCount(); ++i)
2695 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2696 return TRUE;
2699 #if 0
2700 if (m_hAccel && !bSkipAccelerator)
2702 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2703 if (ret)
2704 return TRUE;
2707 #endif
2708 //m_tooltips.RelayEvent(pMsg);
2709 return __super::PreTranslateMessage(pMsg);
2712 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2714 // a double click on an entry in the revision list has happened
2715 *pResult = 0;
2717 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2718 DiffSelectedRevWithPrevious();
2721 void CGitLogListBase::FetchLogAsync(void* data)
2723 ReloadHashMap();
2724 m_ProcData=data;
2725 StartLoadingThread();
2728 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2730 return ((CGitLogListBase*)pVoid)->LogThread();
2733 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2735 //CTime time;
2736 oldest=CTime::GetCurrentTime();
2737 latest=CTime(1971,1,2,0,0,0);
2738 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2740 if(m_logEntries[i].IsEmpty())
2741 continue;
2743 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() < oldest.GetTime())
2744 oldest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2746 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() > latest.GetTime())
2747 latest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2751 if(latest<oldest)
2752 latest=oldest;
2755 UINT CGitLogListBase::LogThread()
2757 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2759 ULONGLONG t1,t2;
2761 if(BeginFetchLog())
2763 InterlockedExchange(&m_bThreadRunning, FALSE);
2764 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2766 return 1;
2769 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2770 bool bRegex = false;
2771 if (m_bFilterWithRegex)
2772 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2774 TRACE(_T("\n===Begin===\n"));
2775 //Update work copy item;
2777 if (!m_logEntries.empty())
2779 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2781 m_arShownList.SafeAdd(pRev);
2785 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2787 // store commit number of the last selected commit/line before the refresh or -1
2788 int lastSelectedHashNItem = -1;
2789 if (m_lastSelectedHash.IsEmpty())
2790 lastSelectedHashNItem = 0;
2792 int ret = 0;
2794 bool shouldWalk = true;
2795 if (!g_Git.CanParseRev(m_sRange))
2797 // walk revisions if show all branches and there exists any ref
2798 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_BASIC_REFS) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2799 shouldWalk = false;
2800 else
2802 STRING_VECTOR list;
2803 if (g_Git.GetRefList(list))
2804 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2805 if (list.empty())
2806 shouldWalk = false;
2810 if (shouldWalk)
2812 g_Git.m_critGitDllSec.Lock();
2813 int total = 0;
2816 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2817 total = git_get_log_estimate_commit_count(m_DllGitLog);
2819 catch (char* msg)
2821 CString err(msg);
2822 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2823 ret = -1;
2825 g_Git.m_critGitDllSec.Unlock();
2827 GIT_COMMIT commit;
2828 t2 = t1 = GetTickCount64();
2829 int oldprecentage = 0;
2830 size_t oldsize = m_logEntries.size();
2831 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2832 while (ret== 0 && !m_bExitThread)
2834 g_Git.m_critGitDllSec.Lock();
2837 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2839 catch (char* msg)
2841 g_Git.m_critGitDllSec.Unlock();
2842 CString err(msg);
2843 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2844 break;
2846 g_Git.m_critGitDllSec.Unlock();
2848 if(ret)
2850 if (ret != -2) // other than end of revision walking
2851 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2852 break;
2855 if (commit.m_ignore == 1)
2857 git_free_commit(&commit);
2858 continue;
2861 //printf("%s\r\n",commit.GetSubject());
2862 if(m_bExitThread)
2863 break;
2865 CGitHash hash = (char*)commit.m_hash ;
2867 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2868 pRev->m_GitCommit = commit;
2869 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2871 char* note = nullptr;
2872 g_Git.m_critGitDllSec.Lock();
2875 git_get_notes(commit.m_hash, &note);
2877 catch (char* msg)
2879 g_Git.m_critGitDllSec.Unlock();
2880 CString err(msg);
2881 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2882 break;
2884 g_Git.m_critGitDllSec.Unlock();
2886 if(note)
2888 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2889 free(note);
2890 note = nullptr;
2893 if(!pRev->m_IsDiffFiles)
2895 pRev->m_CallDiffAsync = DiffAsync;
2898 pRev->ParserParentFromCommit(&commit);
2899 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2901 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2903 const CGitHash &parentHash = pRev->m_ParentHash[i];
2904 auto it = commitChildren.find(parentHash);
2905 if (it == commitChildren.end())
2906 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2907 it->second.insert(pRev->m_CommitHash);
2911 #ifdef DEBUG
2912 pRev->DbgPrint();
2913 TRACE(_T("\n"));
2914 #endif
2916 bool visible = true;
2917 if (HasFilterText())
2919 if(!IsMatchFilter(bRegex,pRev,pat))
2920 visible = false;
2922 if (visible && !ShouldShowFilter(pRev, commitChildren))
2923 visible = false;
2924 this->m_critSec.Lock();
2925 m_logEntries.append(hash, visible);
2926 if (visible)
2927 m_arShownList.SafeAdd(pRev);
2928 this->m_critSec.Unlock();
2930 if (!visible)
2931 continue;
2933 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2934 lastSelectedHashNItem = (int)m_arShownList.size() - 1;
2936 t2 = GetTickCount64();
2938 if (t2 - t1 > 500UL || (m_logEntries.size() - oldsize > 100))
2940 //update UI
2941 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2942 if(percent > 99)
2943 percent =99;
2944 if(percent < GITLOG_START)
2945 percent = GITLOG_START +1;
2947 oldsize = m_logEntries.size();
2948 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2950 //if( percent > oldprecentage )
2952 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2953 oldprecentage = percent;
2956 if (lastSelectedHashNItem >= 0)
2957 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2959 t1 = t2;
2962 g_Git.m_critGitDllSec.Lock();
2963 git_close_log(m_DllGitLog);
2964 g_Git.m_critGitDllSec.Unlock();
2968 if (m_bExitThread)
2970 InterlockedExchange(&m_bThreadRunning, FALSE);
2971 return 0;
2974 //Update UI;
2975 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2977 if (lastSelectedHashNItem >= 0)
2978 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2980 if (this->m_hWnd)
2981 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2983 InterlockedExchange(&m_bThreadRunning, FALSE);
2985 return 0;
2988 void CGitLogListBase::FetchRemoteList()
2990 STRING_VECTOR remoteList;
2991 m_SingleRemote.Empty();
2992 if (!g_Git.GetRemoteList(remoteList) && remoteList.size() == 1)
2993 m_SingleRemote = remoteList[0];
2996 void CGitLogListBase::FetchTrackingBranchList()
2998 m_TrackingMap.clear();
2999 for (auto it = m_HashMap.cbegin(); it != m_HashMap.cend(); ++it)
3001 for (const auto& ref : it->second)
3003 CString branchName;
3004 if (CGit::GetShortName(ref, branchName, _T("refs/heads/")))
3006 CString pullRemote, pullBranch;
3007 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3008 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3009 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3015 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3017 SafeTerminateThread();
3019 this->SetItemCountEx(0);
3020 this->Clear();
3022 ResetWcRev();
3024 ShowGraphColumn((m_ShowMask & CGit::LOG_INFO_FOLLOW) ? false : true);
3026 //Update branch and Tag info
3027 ReloadHashMap();
3028 if (m_pFindDialog)
3029 m_pFindDialog->RefreshList();
3030 //Assume Thread have exited
3031 //if(!m_bThreadRunning)
3033 m_logEntries.clear();
3035 if(IsCleanFilter)
3037 m_sFilterText.Empty();
3040 SafeTerminateAsyncDiffThread();
3041 m_AsynDiffListLock.Lock();
3042 m_AsynDiffList.clear();
3043 m_AsynDiffListLock.Unlock();
3044 StartAsyncDiffThread();
3046 StartLoadingThread();
3050 void CGitLogListBase::StartAsyncDiffThread()
3052 if (m_AsyncThreadExit)
3053 return;
3054 if (InterlockedExchange(&m_AsyncThreadRunning, TRUE) != FALSE)
3055 return;
3056 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
3057 if (!m_DiffingThread)
3059 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
3060 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3064 void CGitLogListBase::StartLoadingThread()
3066 if (InterlockedExchange(&m_bThreadRunning, TRUE) != FALSE)
3067 return;
3068 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3069 InterlockedExchange(&m_bExitThread, FALSE);
3070 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
3071 if (!m_LoadingThread)
3073 InterlockedExchange(&m_bThreadRunning, FALSE);
3074 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3075 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3079 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3083 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3084 if (!bMatchCase)
3085 type |= std::tr1::regex_constants::icase;
3086 pat = std::tr1::wregex(regexp_str, type);
3087 return true;
3089 catch (std::exception) {}
3090 return false;
3092 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3094 BOOL result = TRUE;
3095 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3096 CString sRev;
3098 if ((bRegex)&&(m_bFilterWithRegex))
3100 if (m_SelectedFilters & LOGFILTER_BUGID)
3102 if(this->m_bShowBugtraqColumn)
3104 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3106 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3107 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3108 return TRUE;
3112 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3114 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3115 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3116 return TRUE;
3119 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3121 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3122 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3123 return TRUE;
3126 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3128 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3129 return TRUE;
3131 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3132 return TRUE;
3135 if (m_SelectedFilters & LOGFILTER_EMAILS)
3137 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3138 return TRUE;
3140 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3141 return TRUE;
3144 if (m_SelectedFilters & LOGFILTER_REVS)
3146 sRev = pRev->m_CommitHash.ToString();
3147 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3149 return TRUE;
3153 if (m_SelectedFilters & LOGFILTER_NOTES)
3155 if (std::regex_search(std::wstring(pRev->m_Notes), pat, flags))
3156 return TRUE;
3159 if (m_SelectedFilters & LOGFILTER_REFNAME)
3161 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3162 for (const auto& ref : refs)
3164 if (std::regex_search(std::wstring(ref), pat, flags))
3165 return TRUE;
3169 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3171 if (std::regex_search(std::wstring(GetTagInfo(pRev)), pat, flags))
3172 return TRUE;
3175 if (m_SelectedFilters & LOGFILTER_PATHS)
3177 CTGitPathList* pathList = nullptr;
3178 if( pRev->m_IsDiffFiles)
3179 pathList = &pRev->GetFiles(this);
3180 else
3182 if(!pRev->m_IsSimpleListReady)
3183 pRev->SafeGetSimpleList(&g_Git);
3186 if(pathList)
3187 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3189 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3190 return true;
3191 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3192 return true;
3195 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3197 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3198 return true;
3202 else
3204 CString find = m_sFilterText;
3205 if (!m_bFilterCaseSensitively)
3206 find.MakeLower();
3207 result = find[0] == '!' ? FALSE : TRUE;
3208 if (!result)
3209 find = find.Mid(1);
3211 if (m_SelectedFilters & LOGFILTER_BUGID)
3213 if(this->m_bShowBugtraqColumn)
3215 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3217 if (!m_bFilterCaseSensitively)
3218 sBugIds.MakeLower();
3219 if ((sBugIds.Find(find) >= 0))
3220 return result;
3224 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3226 CString msg = pRev->GetSubject();
3228 if (!m_bFilterCaseSensitively)
3229 msg = msg.MakeLower();
3230 if ((msg.Find(find) >= 0))
3231 return result;
3234 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3236 CString msg = pRev->GetBody();
3238 if (!m_bFilterCaseSensitively)
3239 msg = msg.MakeLower();
3240 if ((msg.Find(find) >= 0))
3241 return result;
3244 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3246 CString msg = pRev->GetAuthorName();
3247 if (!m_bFilterCaseSensitively)
3248 msg = msg.MakeLower();
3249 if ((msg.Find(find) >= 0))
3250 return result;
3253 if (m_SelectedFilters & LOGFILTER_EMAILS)
3255 CString msg = pRev->GetAuthorEmail();
3256 if (!m_bFilterCaseSensitively)
3257 msg = msg.MakeLower();
3258 if ((msg.Find(find) >= 0))
3259 return result;
3262 if (m_SelectedFilters & LOGFILTER_NOTES)
3264 CString msg = pRev->m_Notes;
3265 if (!m_bFilterCaseSensitively)
3266 msg = msg.MakeLower();
3267 if ((msg.Find(find) >= 0))
3268 return result;
3271 if (m_SelectedFilters & LOGFILTER_REVS)
3273 sRev = pRev->m_CommitHash.ToString();
3274 if ((sRev.Find(find) >= 0))
3275 return result;
3278 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3280 CString msg = GetTagInfo(pRev);
3281 if (!m_bFilterCaseSensitively)
3282 msg = msg.MakeLower();
3283 if ((msg.Find(find) >= 0))
3284 return result;
3287 if (m_SelectedFilters & LOGFILTER_REFNAME)
3289 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3290 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3292 if (it->Find(find) >= 0)
3293 return result;
3297 if (m_SelectedFilters & LOGFILTER_PATHS)
3299 CTGitPathList* pathList = nullptr;
3300 if( pRev->m_IsDiffFiles)
3301 pathList = &pRev->GetFiles(this);
3302 else
3304 if(!pRev->m_IsSimpleListReady)
3305 pRev->SafeGetSimpleList(&g_Git);
3307 if(pathList)
3308 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3310 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3311 CString path = cpath->GetGitOldPathString();
3312 if (!m_bFilterCaseSensitively)
3313 path.MakeLower();
3314 if ((path.Find(find)>=0))
3315 return result;
3316 path = cpath->GetGitPathString();
3317 if (!m_bFilterCaseSensitively)
3318 path.MakeLower();
3319 if ((path.Find(find)>=0))
3320 return result;
3323 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3325 CString path = pRev->m_SimpleFileList[i];
3326 if (!m_bFilterCaseSensitively)
3327 path.MakeLower();
3328 if ((path.Find(find)>=0))
3329 return result;
3332 } // else (from if (bRegex))
3333 return !result;
3336 static bool CStringStartsWith(const CString &str, const CString &prefix)
3338 return str.Left(prefix.GetLength()) == prefix;
3340 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3342 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3343 return true;
3345 if (m_ShowFilter & FILTERSHOW_REFS)
3347 // Keep all refs.
3348 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3349 for (size_t i = 0; i < refList.size(); ++i)
3351 const CString &str = refList[i];
3352 if (CStringStartsWith(str, _T("refs/heads/")))
3354 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3355 return true;
3357 else if (CStringStartsWith(str, _T("refs/remotes/")))
3359 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3360 return true;
3362 else if (CStringStartsWith(str, _T("refs/tags/")))
3364 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3365 return true;
3367 else if (CStringStartsWith(str, _T("refs/stash")))
3369 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3370 return true;
3372 else if (CStringStartsWith(str, _T("refs/bisect/")))
3374 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3375 return true;
3378 // Keep the head too.
3379 if (pRev->m_CommitHash == m_HeadHash)
3380 return true;
3383 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3385 if (pRev->ParentsCount() > 1)
3386 return true;
3387 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3388 if (childrenIt != commitChildren.end())
3390 const std::set<CGitHash> &children = childrenIt->second;
3391 if (children.size() > 1)
3392 return true;
3395 return false;
3398 void CGitLogListBase::ShowGraphColumn(bool bShow)
3400 // HACK to hide graph column
3401 if (bShow)
3402 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3403 else
3404 SetColumnWidth(0, 0);
3407 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3409 CString cmd;
3410 CString output;
3412 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3414 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3415 for (size_t i = 0; i < vector.size(); ++i)
3417 if (CStringUtils::StartsWith(vector[i], L"refs/tags/"))
3419 CString tag = vector[i];
3420 int start = vector[i].Find(_T("^{}"));
3421 if (start > 0)
3422 tag = tag.Left(start);
3423 else
3424 continue;
3426 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3427 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3428 output.AppendChar(_T('\n'));
3433 return output;
3436 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3438 pShownlist->SafeRemoveAll();
3440 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3441 bool bRegex = false;
3442 if (m_bFilterWithRegex)
3443 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3445 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3446 CString sRev;
3447 for (DWORD i=0; i<m_logEntries.size(); ++i)
3449 if ((bRegex)&&(m_bFilterWithRegex))
3451 #if 0
3452 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3454 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3455 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3457 pShownlist->SafeAdd(m_logEntries[i]);
3458 continue;
3461 #endif
3462 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3464 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3465 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3467 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3468 continue;
3471 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3473 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3474 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3476 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3477 continue;
3480 if (m_SelectedFilters & LOGFILTER_PATHS)
3482 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3484 bool bGoing = true;
3485 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3487 CTGitPath cpath = pathList[cpPathIndex];
3488 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3490 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3491 bGoing = false;
3492 continue;
3494 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3496 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3497 bGoing = false;
3498 continue;
3500 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3502 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3503 bGoing = false;
3504 continue;
3508 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3510 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3512 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3513 continue;
3516 if (m_SelectedFilters & LOGFILTER_EMAILS)
3518 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3520 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3521 continue;
3524 if (m_SelectedFilters & LOGFILTER_REVS)
3526 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3527 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3529 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3530 continue;
3533 if (m_SelectedFilters & LOGFILTER_REFNAME)
3535 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3536 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3538 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3540 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3541 continue;
3545 } // if (bRegex)
3546 else
3548 CString find = m_sFilterText;
3549 if (!m_bFilterCaseSensitively)
3550 find.MakeLower();
3551 #if 0
3552 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3554 CString sBugIDs = m_logEntries[i]->sBugIDs;
3556 if (!m_bFilterCaseSensitively)
3557 sBugIDs = sBugIDs.MakeLower();
3558 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3560 pShownlist->SafeAdd(m_logEntries[i]);
3561 continue;
3564 #endif
3565 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3567 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3569 if (!m_bFilterCaseSensitively)
3570 msg = msg.MakeLower();
3571 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3573 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3574 continue;
3577 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3579 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3581 if (!m_bFilterCaseSensitively)
3582 msg = msg.MakeLower();
3583 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3585 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3586 continue;
3589 if (m_SelectedFilters & LOGFILTER_PATHS)
3591 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3593 bool bGoing = true;
3594 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3596 CTGitPath cpath = pathList[cpPathIndex];
3597 CString path = cpath.GetGitOldPathString();
3598 if (!m_bFilterCaseSensitively)
3599 path.MakeLower();
3600 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3602 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3603 bGoing = false;
3604 continue;
3606 path = cpath.GetGitPathString();
3607 if (!m_bFilterCaseSensitively)
3608 path.MakeLower();
3609 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3611 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3612 bGoing = false;
3613 continue;
3615 path = cpath.GetActionName();
3616 if (!m_bFilterCaseSensitively)
3617 path.MakeLower();
3618 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3620 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3621 bGoing = false;
3622 continue;
3626 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3628 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3629 if (!m_bFilterCaseSensitively)
3630 msg = msg.MakeLower();
3631 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3633 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3634 continue;
3637 if (m_SelectedFilters & LOGFILTER_EMAILS)
3639 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3640 if (!m_bFilterCaseSensitively)
3641 msg = msg.MakeLower();
3642 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3644 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3645 continue;
3648 if (m_SelectedFilters & LOGFILTER_REVS)
3650 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3651 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3653 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3654 continue;
3657 if (m_SelectedFilters & LOGFILTER_REFNAME)
3659 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3660 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3662 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3664 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3665 continue;
3669 } // else (from if (bRegex))
3670 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3673 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3676 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3678 if(m_From == -1)
3679 if(m_To == -1)
3680 return true;
3681 else
3682 return time <= m_To;
3683 else
3684 if(m_To == -1)
3685 return time >= m_From;
3686 else
3687 return ((time >= m_From)&&(time <= m_To));
3689 return TRUE; /* git dll will filter time range */
3691 // return TRUE;
3694 void CGitLogListBase::StartFilter()
3696 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3697 RecalculateShownList(&m_arShownList);
3698 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3701 DeleteAllItems();
3702 SetItemCountEx(ShownCountWithStopped());
3703 RedrawItems(0, ShownCountWithStopped());
3704 Invalidate();
3707 void CGitLogListBase::RemoveFilter()
3709 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3711 m_arShownList.SafeRemoveAll();
3713 // reset the time filter too
3714 #if 0
3715 m_timFrom = (__time64_t(m_tFrom));
3716 m_timTo = (__time64_t(m_tTo));
3717 m_DateFrom.SetTime(&m_timFrom);
3718 m_DateTo.SetTime(&m_timTo);
3719 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3720 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3721 #endif
3723 for (DWORD i=0; i<m_logEntries.size(); ++i)
3725 if(this->m_IsOldFirst)
3726 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3727 else
3728 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3730 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3731 DeleteAllItems();
3732 SetItemCountEx(ShownCountWithStopped());
3733 RedrawItems(0, ShownCountWithStopped());
3735 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3738 void CGitLogListBase::Clear()
3740 m_arShownList.SafeRemoveAll();
3741 DeleteAllItems();
3743 m_logEntries.ClearAll();
3746 void CGitLogListBase::OnDestroy()
3748 SafeTerminateThread();
3749 SafeTerminateAsyncDiffThread();
3751 int retry = 0;
3752 while(m_LogCache.SaveCache())
3754 if(retry > 5)
3755 break;
3756 Sleep(1000);
3758 ++retry;
3760 //if(CMessageBox::Show(nullptr, _T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."), _T("TortoiseGit"),
3761 // MB_YESNO) == IDNO)
3762 // break;
3765 __super::OnDestroy();
3768 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3770 CRect rect;
3771 int i=(int)wParam;
3772 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3773 this->InvalidateRect(rect);
3775 return 0;
3779 * Save column widths to the registry
3781 void CGitLogListBase::SaveColumnWidths()
3783 // HACK that graph column is always shown
3784 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3786 __super::SaveColumnWidths();
3789 int CGitLogListBase::GetHeadIndex()
3791 if(m_HeadHash.IsEmpty())
3792 return -1;
3794 for (size_t i = 0; i < m_arShownList.size(); ++i)
3796 GitRev* pRev = m_arShownList.SafeGetAt(i);
3797 if(pRev)
3799 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3800 return (int)i;
3803 return -1;
3805 void CGitLogListBase::OnFind()
3807 if (!m_pFindDialog)
3809 m_pFindDialog = new CFindDlg(this);
3810 m_pFindDialog->Create(this);
3814 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3816 if (GetSelectedCount() != 0)
3817 return 0;
3819 CGitHash theSelectedHash = m_lastSelectedHash;
3820 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3821 m_lastSelectedHash = theSelectedHash;
3823 int countPerPage = GetCountPerPage();
3824 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3825 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3826 EnsureVisible((int)itemToSelect, FALSE);
3827 return 0;
3829 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3831 ASSERT(m_pFindDialog);
3832 bool bFound = false;
3833 int i=0;
3835 if (m_pFindDialog->IsTerminating())
3837 // invalidate the handle identifying the dialog box.
3838 m_pFindDialog = nullptr;
3839 return 0;
3842 int cnt = (int)m_arShownList.size();
3844 if(m_pFindDialog->IsRef())
3846 CString str;
3847 str=m_pFindDialog->GetFindString();
3849 CGitHash hash;
3851 if(!str.IsEmpty())
3853 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3854 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3857 if(!hash.IsEmpty())
3859 for (i = 0; i < cnt; ++i)
3861 GitRev* pLogEntry = m_arShownList.SafeGetAt(i);
3862 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3864 bFound = true;
3865 break;
3869 if (!bFound)
3871 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3872 return 0;
3876 if (m_pFindDialog->FindNext() && !bFound)
3878 //read data from dialog
3879 CString findText = m_pFindDialog->GetFindString();
3880 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3882 std::tr1::wregex pat;
3883 bool bRegex = false;
3884 if (m_pFindDialog->Regex())
3885 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3887 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3889 for (i = m_nSearchIndex + 1; ; ++i)
3891 if (i >= cnt)
3893 i = 0;
3894 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3896 if (m_nSearchIndex >= 0)
3898 if (i == m_nSearchIndex)
3900 ::MessageBeep(0xFFFFFFFF);
3901 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3902 break;
3906 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(i);
3908 CString str;
3909 str+=pLogEntry->m_CommitHash.ToString();
3910 str += _T('\n');
3912 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3914 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3915 str += _T('\n');
3918 str+=pLogEntry->GetAuthorEmail();
3919 str += _T('\n');
3920 str+=pLogEntry->GetAuthorName();
3921 str += _T('\n');
3922 str+=pLogEntry->GetBody();
3923 str += _T('\n');
3924 str+=pLogEntry->GetCommitterEmail();
3925 str += _T('\n');
3926 str+=pLogEntry->GetCommitterName();
3927 str += _T('\n');
3928 str+=pLogEntry->GetSubject();
3929 str += _T('\n');
3930 str+=pLogEntry->m_Notes;
3931 str += _T('\n');
3932 str+=GetTagInfo(pLogEntry);
3933 str += _T('\n');
3936 /*Because changed files list is loaded on demand when gui show,
3937 files will empty when files have not fetched.
3939 we can add it back by using one-way diff(with outnumber changed and rename detect.
3940 here just need changed filename list. one-way is much quicker.
3942 if(pLogEntry->m_IsFull)
3944 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
3946 str += pLogEntry->GetFiles(this)[j].GetWinPath();
3947 str += _T('\n');
3948 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
3949 str += _T('\n');
3952 else
3954 if(!pLogEntry->m_IsSimpleListReady)
3955 pLogEntry->SafeGetSimpleList(&g_Git);
3957 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
3959 str += pLogEntry->m_SimpleFileList[j];
3960 str += _T('\n');
3964 if (bRegex)
3966 if (std::regex_search(std::wstring(str), pat, flags))
3968 bFound = true;
3969 break;
3972 else
3974 if (bMatchCase)
3976 if (str.Find(findText) >= 0)
3978 bFound = true;
3979 break;
3982 else
3984 CString msg = str;
3985 msg = msg.MakeLower();
3986 CString find = findText.MakeLower();
3987 if (msg.Find(find) >= 0)
3989 bFound = TRUE;
3990 break;
3994 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3996 } // if(m_pFindDialog->FindNext())
3997 //UpdateLogInfoLabel();
3999 if (bFound)
4001 m_nSearchIndex = i;
4002 EnsureVisible(i, FALSE);
4003 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4005 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4006 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4007 SetSelectionMark(i);
4009 else
4011 GitRev* pLogEntry = m_arShownList.SafeGetAt(i);
4012 if (pLogEntry)
4013 m_highlight = pLogEntry->m_CommitHash;
4015 Invalidate();
4016 //FillLogMessageCtrl();
4017 UpdateData(FALSE);
4020 return 0;
4023 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4025 LVHITTESTINFO lvhitTestInfo;
4027 lvhitTestInfo.pt = point;
4029 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4030 int nSubItem = lvhitTestInfo.iSubItem;
4032 UINT nFlags = lvhitTestInfo.flags;
4034 // nFlags is 0 if the SubItemHitTest fails
4035 // Therefore, 0 & <anything> will equal false
4036 if (nFlags & LVHT_ONITEM)
4038 // Get the client area occupied by this control
4039 RECT rcClient;
4040 GetClientRect(&rcClient);
4042 // Fill in the TOOLINFO structure
4043 pTI->hwnd = m_hWnd;
4044 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4045 pTI->lpszText = LPSTR_TEXTCALLBACK;
4046 pTI->rect = rcClient;
4048 return pTI->uId; // By returning a unique value per listItem,
4049 // we ensure that when the mouse moves over another list item,
4050 // the tooltip will change
4052 else
4054 // Otherwise, we aren't interested, so let the message propagate
4055 return -1;
4059 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4061 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4062 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4064 *pResult = 0;
4066 // Ignore messages from the built in tooltip, we are processing them internally
4067 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4068 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4069 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4070 return FALSE;
4072 // Get the mouse position
4073 const MSG* pMessage = GetCurrentMessage();
4075 CPoint pt;
4076 pt = pMessage->pt;
4077 ScreenToClient(&pt);
4079 // Check if the point falls onto a list item
4080 LVHITTESTINFO lvhitTestInfo;
4081 lvhitTestInfo.pt = pt;
4083 int nItem = SubItemHitTest(&lvhitTestInfo);
4085 if (lvhitTestInfo.flags & LVHT_ONITEM)
4087 // Get branch description first
4088 CString strTipText;
4089 if (lvhitTestInfo.iSubItem == LOGLIST_MESSAGE)
4091 CString branch;
4092 CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH;
4093 if (IsMouseOnRefLabel(m_arShownList.SafeGetAt(nItem), lvhitTestInfo.pt, type, &branch))
4095 MAP_STRING_STRING descriptions;
4096 g_Git.GetBranchDescriptions(descriptions);
4097 if (descriptions.find(branch) != descriptions.cend())
4099 strTipText.LoadString(IDS_DESCRIPTION);
4100 strTipText += L":\n";
4101 strTipText += descriptions[branch];
4106 bool followMousePos = false;
4107 if (!strTipText.IsEmpty())
4108 followMousePos = true;
4109 else
4110 strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4111 if (strTipText.IsEmpty())
4112 return FALSE;
4114 // we want multiline tooltips
4115 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4117 wcscpy_s(m_wszTip, strTipText);
4118 // handle Unicode as well as non-Unicode requests
4119 if (pNMHDR->code == TTN_NEEDTEXTA)
4121 pTTTA->hinst = nullptr;
4122 pTTTA->lpszText = m_szTip;
4123 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, nullptr, nullptr);
4125 else
4127 pTTTW->hinst = nullptr;
4128 pTTTW->lpszText = m_wszTip;
4131 CRect rect;
4132 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4133 if (followMousePos)
4134 rect.MoveToXY(pt.x, pt.y + 18); // 18: to act like a normal tooltip
4135 ClientToScreen(rect);
4136 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4138 return TRUE; // We found a tool tip,
4139 // tell the framework this message has been handled
4142 return FALSE; // We didn't handle the message,
4143 // let the framework continue propagating the message
4146 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4148 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4150 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4151 if (pLogEntry == nullptr)
4152 return CString();
4153 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4154 return CString();
4155 return pLogEntry->GetSubject();
4157 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4159 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4160 if (pLogEntry == nullptr)
4161 return CString();
4162 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4164 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4166 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4167 if (pLogEntry == nullptr)
4168 return CString();
4169 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4171 else if (nSubItem == LOGLIST_ACTION)
4173 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4174 if (pLogEntry == nullptr)
4175 return CString();
4177 if (!pLogEntry->m_IsDiffFiles)
4178 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4180 int actions = pLogEntry->GetAction(this);
4181 CString sToolTipText;
4183 CString actionText;
4184 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4185 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4187 if (actions & CTGitPath::LOGACTIONS_ADDED)
4189 if (!actionText.IsEmpty())
4190 actionText += L"\r\n";
4191 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4194 if (actions & CTGitPath::LOGACTIONS_DELETED)
4196 if (!actionText.IsEmpty())
4197 actionText += L"\r\n";
4198 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4201 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4203 if (!actionText.IsEmpty())
4204 actionText += L"\r\n";
4205 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4208 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4210 if (!actionText.IsEmpty())
4211 actionText += L"\r\n";
4212 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4215 if (!actionText.IsEmpty())
4217 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4218 sToolTipText = sTitle + L":\r\n" + actionText;
4220 return sToolTipText;
4222 return CString();
4225 bool CGitLogListBase::IsMouseOnRefLabelFromPopupMenu(const GitRevLoglist* pLogEntry, const CPoint& point, CGit::REF_TYPE& type, CString* pShortname /*nullptr*/, size_t* pIndex /*nullptr*/)
4227 POINT pt = point;
4228 ScreenToClient(&pt);
4229 return IsMouseOnRefLabel(pLogEntry, pt, type, pShortname, pIndex);
4232 bool CGitLogListBase::IsMouseOnRefLabel(const GitRevLoglist* pLogEntry, const POINT& pt, CGit::REF_TYPE& type, CString* pShortname /*nullptr*/, size_t* pIndex /*nullptr*/)
4234 if (!pLogEntry)
4235 return false;
4237 for (size_t i = 0; i < m_HashMap[pLogEntry->m_CommitHash].size(); ++i)
4239 const auto labelpos = m_RefLabelPosMap.find(m_HashMap[pLogEntry->m_CommitHash][i]);
4240 if (labelpos == m_RefLabelPosMap.cend() || !labelpos->second.PtInRect(pt))
4241 continue;
4243 CGit::REF_TYPE foundType;
4244 if (pShortname)
4245 *pShortname = CGit::GetShortName(m_HashMap[pLogEntry->m_CommitHash][i], &foundType);
4246 else
4247 CGit::GetShortName(m_HashMap[pLogEntry->m_CommitHash][i], &foundType);
4248 if (foundType != type && type != CGit::REF_TYPE::UNKNOWN)
4249 return false;
4251 type = foundType;
4252 if (pIndex)
4253 *pIndex = i;
4254 return true;
4256 return false;