Refactor out CResizableColumnsListCtrl
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobb500405a2f275c72157f7ee9dd3110a8a8c13bfa
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.GetWorkingTreeChanges(files);
201 int& action = pRev->GetAction(this);
202 action = 0;
203 for (int j = 0; j < files.GetCount(); ++j)
204 action |= files[j].m_Action;
206 CString err;
207 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
209 MessageBox(_T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
210 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
211 return -1;
214 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
215 InterlockedExchange(&pRev->m_IsFull, TRUE);
217 pRev->GetBody().Format(IDS_FILESCHANGES, files.GetCount());
218 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
219 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
222 if (!pRev->CheckAndDiff())
223 { // fetch change file list
224 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
226 if (i < (int)m_arShownList.size())
228 GitRevLoglist* data = m_arShownList.SafeGetAt(i);
229 if(data->m_CommitHash == pRev->m_CommitHash)
231 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
232 break;
237 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
239 POSITION pos = GetFirstSelectedItemPosition();
240 int nItem = GetNextSelectedItem(pos);
242 if(nItem>=0)
244 GitRevLoglist* data = m_arShownList.SafeGetAt(nItem);
245 if(data)
246 if(data->m_CommitHash == pRev->m_CommitHash)
247 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
253 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
254 return 0;
256 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
258 if (exclusivelyShow)
259 m_ContextMenuMask &= hideMask;
260 else
261 m_ContextMenuMask &= ~hideMask;
264 CGitLogListBase::~CGitLogListBase()
266 InterlockedExchange(&m_bNoDispUpdates, TRUE);
267 this->m_arShownList.SafeRemoveAll();
269 DestroyIcon(m_hModifiedIcon);
270 DestroyIcon(m_hReplacedIcon);
271 DestroyIcon(m_hConflictedIcon);
272 DestroyIcon(m_hAddedIcon);
273 DestroyIcon(m_hDeletedIcon);
274 m_logEntries.ClearAll();
276 SafeTerminateThread();
277 SafeTerminateAsyncDiffThread();
279 if(m_AsyncDiffEvent)
280 CloseHandle(m_AsyncDiffEvent);
284 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintCtrl<CResizableColumnsListCtrl<CListCtrl>>)
285 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
286 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
287 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
288 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
289 ON_WM_CONTEXTMENU()
290 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
291 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
292 ON_WM_CREATE()
293 ON_WM_DESTROY()
294 ON_MESSAGE(MSG_LOADED,OnLoad)
295 ON_WM_MEASUREITEM()
296 ON_WM_MEASUREITEM_REFLECT()
297 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
298 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
299 END_MESSAGE_MAP()
301 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
303 //if (m_nRowHeight>0)
304 lpMeasureItemStruct->itemHeight = 50;
307 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
309 PreSubclassWindow();
310 return __super::OnCreate(lpCreateStruct);
313 void CGitLogListBase::PreSubclassWindow()
315 SetExtendedStyle(LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
316 // load the icons for the action columns
317 // m_Theme.Open(m_hWnd, L"ListView");
318 SetWindowTheme(m_hWnd, L"Explorer", nullptr);
319 __super::PreSubclassWindow();
322 CString CGitLogListBase::GetRebaseActionName(int action)
324 if (action & LOGACTIONS_REBASE_EDIT)
325 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
326 if (action & LOGACTIONS_REBASE_SQUASH)
327 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
328 if (action & LOGACTIONS_REBASE_PICK)
329 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
330 if (action & LOGACTIONS_REBASE_SKIP)
331 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
333 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
336 void CGitLogListBase::InsertGitColumn()
338 CString temp;
340 Init();
342 // only load properties if we have a repository
343 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
344 UpdateProjectProperties();
346 static UINT normal[] =
348 IDS_LOG_GRAPH,
349 IDS_LOG_REBASE,
350 IDS_LOG_ID,
351 IDS_LOG_HASH,
352 IDS_LOG_ACTIONS,
353 IDS_LOG_MESSAGE,
354 IDS_LOG_AUTHOR,
355 IDS_LOG_DATE,
356 IDS_LOG_EMAIL,
357 IDS_LOG_COMMIT_NAME,
358 IDS_LOG_COMMIT_EMAIL,
359 IDS_LOG_COMMIT_DATE,
360 IDS_LOG_BUGIDS,
361 IDS_LOG_SVNREV,
364 static int with[] =
366 ICONITEMBORDER+16*4,
367 ICONITEMBORDER+16*4,
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 2*ICONITEMBORDER+16*4,
371 LOGLIST_MESSAGE_MIN,
372 ICONITEMBORDER+16*4,
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,
381 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
383 DWORD hideColumns = 0;
384 if(this->m_IsRebaseReplaceGraph)
386 hideColumns |= GIT_LOG_GRAPH;
387 m_dwDefaultColumns |= GIT_LOG_REBASE;
389 else
390 hideColumns |= GIT_LOG_REBASE;
392 if(this->m_IsIDReplaceAction)
394 hideColumns |= GIT_LOG_ACTIONS;
395 m_dwDefaultColumns |= GIT_LOG_ID;
396 m_dwDefaultColumns |= GIT_LOG_HASH;
398 else
399 hideColumns |= GIT_LOG_ID;
400 if(this->m_bShowBugtraqColumn)
401 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
402 else
403 hideColumns |= GIT_LOGLIST_BUG;
404 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
405 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
406 else
407 hideColumns |= GIT_LOGLIST_SVNREV;
408 SetRedraw(false);
410 m_ColumnManager.SetNames(normal, _countof(normal));
411 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
412 m_ColumnManager.SetRightAlign(LOGLIST_ID);
414 SetRedraw(true);
417 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
419 LVITEM rItem = { 0 };
420 rItem.mask = LVIF_STATE;
421 rItem.iItem = (int)Index;
422 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
423 GetItem(&rItem);
425 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(Index);
426 HBRUSH brush = nullptr;
428 if (!(rItem.state & LVIS_SELECTED))
430 int action = pLogEntry->GetRebaseAction();
431 if (action & LOGACTIONS_REBASE_SQUASH)
432 brush = ::CreateSolidBrush(RGB(156,156,156));
433 else if (action & LOGACTIONS_REBASE_EDIT)
434 brush = ::CreateSolidBrush(RGB(200,200,128));
436 else if (!IsAppThemed())
438 if (rItem.state & LVIS_SELECTED)
440 if (::GetFocus() == m_hWnd)
441 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
442 else
443 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
446 if (brush)
448 ::FillRect(hdc, &rect, brush);
449 ::DeleteObject(brush);
453 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
455 POINT point = { 4, 4 };
456 CRect rt2 = rect;
457 rt2.DeflateRect(1, 1);
458 rt2.OffsetRect(2, 2);
460 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
461 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
462 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
463 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
464 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
466 ::SelectObject(hdc, brush);
467 rt2.OffsetRect(-2, -2);
468 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
469 ::SelectObject(hdc, oldbrush);
470 ::SelectObject(hdc, oldpen);
471 ::DeleteObject(nullPen);
472 ::DeleteObject(darkBrush);
475 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
477 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
478 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
479 ::MoveToEx(hdc, rect.left + 7, rect.top, nullptr);
480 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
481 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
482 ::LineTo(hdc, rect.left, rect.bottom);
483 ::SelectObject(hdc, oldpen);
484 ::DeleteObject(pen);
487 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
489 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
490 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
491 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, nullptr);
492 ::LineTo(hdc, rect.left, rect.bottom);
493 ::LineTo(hdc, rect.right, rect.bottom);
494 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
495 ::SelectObject(hdc, oldpen);
496 ::DeleteObject(pen);
499 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
501 GitRevLoglist* data = m_arShownList.SafeGetAt(index);
502 CRect rt=rect;
503 LVITEM rItem = { 0 };
504 rItem.mask = LVIF_STATE;
505 rItem.iItem = (int)index;
506 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
507 GetItem(&rItem);
509 CDC W_Dc;
510 W_Dc.Attach(hdc);
512 HTHEME hTheme = nullptr;
513 if (IsAppThemed())
514 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
516 SIZE oneSpaceSize;
517 if (m_bTagsBranchesOnRightSide)
519 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
520 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
521 SelectObject(hdc, oldFont);
522 rt.left += oneSpaceSize.cx * 2;
524 else
526 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
527 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
528 rt.left += oneSpaceSize.cx;
531 CString msg = MessageDisplayStr(data);
532 int action = data->GetRebaseAction();
533 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
534 if (IsAppThemed())
536 int txtState = LISS_NORMAL;
537 if (rItem.state & LVIS_SELECTED)
538 txtState = LISS_SELECTED;
540 DTTOPTS opts = { 0 };
541 opts.dwSize = sizeof(opts);
542 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
543 opts.dwFlags = DTT_TEXTCOLOR;
544 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, msg, -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
546 else
548 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
550 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
551 ::DrawText(hdc,msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
552 ::SetTextColor(hdc, clrOld);
554 else
556 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
557 ::DrawText(hdc, msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
558 ::SetTextColor(hdc, clrOld);
562 if (m_bTagsBranchesOnRightSide)
564 SIZE size;
565 GetTextExtentPoint32(hdc, msg, msg.GetLength(), &size);
567 rt.left += oneSpaceSize.cx + size.cx;
569 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
572 if (hTheme)
573 CloseThemeData(hTheme);
575 W_Dc.Detach();
578 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
580 for (unsigned int i = 0; i < refList.size(); ++i)
582 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
583 HBRUSH brush = 0;
584 COLORREF colRef = refList[i].color;
585 bool singleRemote = refList[i].singleRemote;
586 bool hasTracking = refList[i].hasTracking;
587 bool sameName = refList[i].sameName;
588 CGit::REF_TYPE refType = refList[i].refType;
590 //When row selected, ajust label color
591 if (!IsAppThemed())
593 if (rItem.state & LVIS_SELECTED)
594 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
597 brush = ::CreateSolidBrush(colRef);
599 if (!shortname.IsEmpty() && (rt.left < rect.right))
601 SIZE size = { 0 };
602 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
604 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
605 rt.right += 8;
607 int textpos = DT_CENTER;
609 if (rt.right > rect.right)
611 rt.right = rect.right;
612 textpos = 0;
615 CRect textRect = rt;
617 if (singleRemote)
619 rt.right += 8;
620 textRect.OffsetRect(8, 0);
623 if (sameName)
624 rt.right += 8;
626 if (hasTracking)
627 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
628 else
630 //Fill interior of ref label
631 ::FillRect(hdc, &rt, brush);
634 //Draw edge of label
635 CRect rectEdge = rt;
637 if (!hasTracking)
639 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
640 rectEdge.DeflateRect(1, 1);
641 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
644 if (refType == CGit::REF_TYPE::ANNOTATED_TAG)
646 rt.right += 8;
647 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
648 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
649 ::FillRgn(hdc, hrgn, brush);
650 ::DeleteObject(hrgn);
651 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, nullptr);
652 HPEN pen;
653 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
654 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
655 ::DeleteObject(pen);
656 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
657 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
658 ::DeleteObject(pen);
659 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
660 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, nullptr);
661 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
662 ::DeleteObject(pen);
663 SelectObject(hdc, oldpen);
666 //Draw text inside label
667 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
668 if (!customColor && IsAppThemed())
670 int txtState = LISS_NORMAL;
671 if (rItem.state & LVIS_SELECTED)
672 txtState = LISS_SELECTED;
674 DTTOPTS opts = { 0 };
675 opts.dwSize = sizeof(opts);
676 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
677 opts.dwFlags = DTT_TEXTCOLOR;
678 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
680 else
682 W_Dc.SetBkMode(TRANSPARENT);
683 if (customColor || (rItem.state & LVIS_SELECTED))
685 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
686 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
687 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
688 ::SetTextColor(hdc,clrOld);
690 else
692 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
693 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
694 ::SetTextColor(hdc, clrOld);
698 if (singleRemote)
700 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
701 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
702 CRect newRect;
703 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
704 DrawLightning(hdc, newRect, color, bold);
707 if (sameName)
709 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
710 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
711 CRect newRect;
712 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
713 DrawUpTriangle(hdc, newRect, color, bold);
716 m_RefLabelPosMap[refList[i].fullName] = rt;
718 rt.left = rt.right + 1;
720 if (brush)
721 ::DeleteObject(brush);
723 rt.right = rect.right;
726 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
727 // Returns ((256 - amount)*col1 + amount*col2) / 256;
728 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
729 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
730 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
733 Gdiplus::Color GetGdiColor(COLORREF col)
735 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
737 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
738 const COLORREF& col,const COLORREF& activeColor, int top
741 int h = laneHeight / 2;
742 int m = (x1 + x2) / 2;
743 int r = (x2 - x1) * m_NodeSize / 30;
744 int d = 2 * r;
746 #define P_CENTER m , h+top
747 #define P_0 x2, h+top
748 #define P_90 m , 0+top-1
749 #define P_180 x1, h+top
750 #define P_270 m , 2 * h+top +1
751 #define R_CENTER m - r, h - r+top, d, d
754 #define DELTA_UR_B 2*(x1 - m), 2*h +top
755 #define DELTA_UR_E 0*16, 90*16 +top // -,
757 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
758 #define DELTA_DR_E 270*16, 90*16 +top // -'
760 #define DELTA_UL_B 2*(x2 - m), 2*h +top
761 #define DELTA_UL_E 90*16, 90*16 +top // ,-
763 #define DELTA_DL_B 2*(x2 - m),2*-h +top
764 #define DELTA_DL_E 180*16, 90*16 // '-
766 #define CENTER_UR x1, 2*h, 225
767 #define CENTER_DR x1, 0 , 135
768 #define CENTER_UL x2, 2*h, 315
769 #define CENTER_DL x2, 0 , 45
772 Gdiplus::Graphics graphics( hdc );
774 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
776 // arc
777 switch (type) {
778 case Lanes::JOIN:
779 case Lanes::JOIN_R:
780 case Lanes::HEAD:
781 case Lanes::HEAD_R:
783 Gdiplus::LinearGradientBrush gradient(
784 Gdiplus::Point(x1-2, h+top-2),
785 Gdiplus::Point(P_270),
786 GetGdiColor(activeColor),GetGdiColor(col));
789 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
790 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
792 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
793 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
794 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
796 break;
798 case Lanes::JOIN_L:
800 Gdiplus::LinearGradientBrush gradient(
801 Gdiplus::Point(P_270),
802 Gdiplus::Point(x2+1, h+top-1),
803 GetGdiColor(col),GetGdiColor(activeColor));
806 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
807 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
809 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
810 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
811 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
814 break;
816 case Lanes::TAIL:
817 case Lanes::TAIL_R:
819 Gdiplus::LinearGradientBrush gradient(
820 Gdiplus::Point(x1-2, h+top-2),
821 Gdiplus::Point(P_90),
822 GetGdiColor(activeColor),GetGdiColor(col));
824 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
826 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
828 #if 0
829 QConicalGradient gradient(CENTER_DR);
830 gradient.setColorAt(0.375, activeCol);
831 gradient.setColorAt(0.625, col);
832 myPen.setBrush(gradient);
833 p->setPen(myPen);
834 p->drawArc(P_CENTER, DELTA_DR);
835 #endif
836 break;
838 default:
839 break;
843 //static QPen myPen(Qt::black, 2); // fast path here
844 CPen pen;
845 pen.CreatePen(PS_SOLID,2,col);
846 //myPen.setColor(col);
847 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
849 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
851 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
853 //p->setPen(myPen);
855 // vertical line
856 switch (type) {
857 case Lanes::ACTIVE:
858 case Lanes::NOT_ACTIVE:
859 case Lanes::MERGE_FORK:
860 case Lanes::MERGE_FORK_R:
861 case Lanes::MERGE_FORK_L:
862 case Lanes::JOIN:
863 case Lanes::JOIN_R:
864 case Lanes::JOIN_L:
865 case Lanes::CROSS:
866 //DrawLine(hdc,P_90,P_270);
867 graphics.DrawLine(&myPen,P_90,P_270);
868 //p->drawLine(P_90, P_270);
869 break;
870 case Lanes::HEAD_L:
871 case Lanes::BRANCH:
872 //DrawLine(hdc,P_CENTER,P_270);
873 graphics.DrawLine(&myPen,P_CENTER,P_270);
874 //p->drawLine(P_CENTER, P_270);
875 break;
876 case Lanes::TAIL_L:
877 case Lanes::INITIAL:
878 case Lanes::BOUNDARY:
879 case Lanes::BOUNDARY_C:
880 case Lanes::BOUNDARY_R:
881 case Lanes::BOUNDARY_L:
882 //DrawLine(hdc,P_90, P_CENTER);
883 graphics.DrawLine(&myPen,P_90,P_CENTER);
884 //p->drawLine(P_90, P_CENTER);
885 break;
886 default:
887 break;
890 myPen.SetColor(GetGdiColor(activeColor));
892 // horizontal line
893 switch (type) {
894 case Lanes::MERGE_FORK:
895 case Lanes::JOIN:
896 case Lanes::HEAD:
897 case Lanes::TAIL:
898 case Lanes::CROSS:
899 case Lanes::CROSS_EMPTY:
900 case Lanes::BOUNDARY_C:
901 //DrawLine(hdc,P_180,P_0);
902 graphics.DrawLine(&myPen,P_180,P_0);
903 //p->drawLine(P_180, P_0);
904 break;
905 case Lanes::MERGE_FORK_R:
906 case Lanes::BOUNDARY_R:
907 //DrawLine(hdc,P_180,P_CENTER);
908 graphics.DrawLine(&myPen,P_180,P_CENTER);
909 //p->drawLine(P_180, P_CENTER);
910 break;
911 case Lanes::MERGE_FORK_L:
912 case Lanes::HEAD_L:
913 case Lanes::TAIL_L:
914 case Lanes::BOUNDARY_L:
915 //DrawLine(hdc,P_CENTER,P_0);
916 graphics.DrawLine(&myPen,P_CENTER,P_0);
917 //p->drawLine(P_CENTER, P_0);
918 break;
919 default:
920 break;
923 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
925 CBrush brush;
926 brush.CreateSolidBrush(col);
927 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
929 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
930 // center symbol, e.g. rect or ellipse
931 switch (type) {
932 case Lanes::ACTIVE:
933 case Lanes::INITIAL:
934 case Lanes::BRANCH:
936 //p->setPen(Qt::NoPen);
937 //p->setBrush(col);
938 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
939 graphics.FillEllipse(&myBrush, R_CENTER);
940 //p->drawEllipse(R_CENTER);
941 break;
942 case Lanes::MERGE_FORK:
943 case Lanes::MERGE_FORK_R:
944 case Lanes::MERGE_FORK_L:
945 //p->setPen(Qt::NoPen);
946 //p->setBrush(col);
947 //p->drawRect(R_CENTER);
948 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
949 graphics.FillRectangle(&myBrush, R_CENTER);
950 break;
951 case Lanes::UNAPPLIED:
952 // Red minus sign
953 //p->setPen(Qt::NoPen);
954 //p->setBrush(Qt::red);
955 //p->drawRect(m - r, h - 1, d, 2);
956 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
957 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
958 break;
959 case Lanes::APPLIED:
960 // Green plus sign
961 //p->setPen(Qt::NoPen);
962 //p->setBrush(DARK_GREEN);
963 //p->drawRect(m - r, h - 1, d, 2);
964 //p->drawRect(m - 1, h - r, 2, d);
965 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
966 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
967 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
968 break;
969 case Lanes::BOUNDARY:
970 //p->setBrush(back);
971 //p->drawEllipse(R_CENTER);
972 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
973 graphics.DrawEllipse(&myPen, R_CENTER);
974 break;
975 case Lanes::BOUNDARY_C:
976 case Lanes::BOUNDARY_R:
977 case Lanes::BOUNDARY_L:
978 //p->setBrush(back);
979 //p->drawRect(R_CENTER);
980 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
981 graphics.FillRectangle(&myBrush,R_CENTER);
982 break;
983 default:
984 break;
987 ::SelectObject(hdc,oldpen);
988 ::SelectObject(hdc,oldbrush);
989 #undef P_CENTER
990 #undef P_0
991 #undef P_90
992 #undef P_180
993 #undef P_270
994 #undef R_CENTER
997 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
999 // TODO: unfinished
1000 // return;
1001 GitRevLoglist* data = m_arShownList.SafeGetAt(index);
1002 if(data->m_CommitHash.IsEmpty())
1003 return;
1005 CRect rt=rect;
1006 LVITEM rItem = { 0 };
1007 rItem.mask = LVIF_STATE;
1008 rItem.iItem = (int)index;
1009 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1010 GetItem(&rItem);
1012 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1014 if (data->m_Lanes.empty())
1015 m_logEntries.setLane(data->m_CommitHash);
1017 std::vector<int>& lanes=data->m_Lanes;
1018 size_t laneNum = lanes.size();
1019 UINT activeLane = 0;
1020 for (UINT i = 0; i < laneNum; ++i)
1021 if (Lanes::isMerge(lanes[i])) {
1022 activeLane = i;
1023 break;
1026 int x2 = 0;
1027 int maxWidth = rect.Width();
1028 int lw = 3 * rect.Height() / 4; //laneWidth()
1030 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1031 //if (opt.state & QStyle::State_Selected)
1032 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1034 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1036 int x1 = x2;
1037 x2 += lw;
1039 int ln = lanes[i];
1040 if (ln == Lanes::EMPTY)
1041 continue;
1043 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1044 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1047 #if 0
1048 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1049 int x1 = x2;
1050 x2 += lw;
1052 int ln = lanes[i];
1053 if (ln == Lanes::EMPTY)
1054 continue;
1056 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1057 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1059 if (ln == Lanes::CROSS)
1061 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1062 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1064 else
1065 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1067 #endif
1070 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1072 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1073 // Take the default processing unless we set this to something else below.
1074 *pResult = CDRF_DODEFAULT;
1076 if (m_bNoDispUpdates)
1077 return;
1079 switch (pLVCD->nmcd.dwDrawStage)
1081 case CDDS_PREPAINT:
1083 *pResult = CDRF_NOTIFYITEMDRAW;
1084 return;
1086 break;
1087 case CDDS_ITEMPREPAINT:
1089 // This is the prepaint stage for an item. Here's where we set the
1090 // item's text color.
1092 // Tell Windows to send draw notifications for each subitem.
1093 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1095 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1097 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec)
1099 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1100 if (data)
1102 HGDIOBJ hGdiObj = nullptr;
1103 int action = data->GetRebaseAction();
1104 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1105 crText = RGB(128,128,128);
1107 if (action & LOGACTIONS_REBASE_SQUASH)
1108 pLVCD->clrTextBk = RGB(156,156,156);
1109 else if (action & LOGACTIONS_REBASE_EDIT)
1110 pLVCD->clrTextBk = RGB(200,200,128);
1111 else
1112 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1114 if (action & LOGACTIONS_REBASE_CURRENT)
1115 hGdiObj = m_boldFont.GetSafeHandle();
1117 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1118 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1119 if (isHeadHash && isHighlight)
1120 hGdiObj = m_boldItalicsFont.GetSafeHandle();
1121 else if (isHeadHash)
1122 hGdiObj = m_boldFont.GetSafeHandle();
1123 else if (isHighlight)
1124 hGdiObj = m_FontItalics.GetSafeHandle();
1126 if (hGdiObj)
1128 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1129 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1132 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1133 // crText = GetSysColor(COLOR_GRAYTEXT);
1135 if (data->m_CommitHash.IsEmpty())
1137 //crText = GetSysColor(RGB(200,200,0));
1138 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1139 // We changed the font, so we're returning CDRF_NEWFONT. This
1140 // tells the control to recalculate the extent of the text.
1141 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1145 if (m_arShownList.size() == pLVCD->nmcd.dwItemSpec)
1147 if (m_bStrictStopped)
1148 crText = GetSysColor(COLOR_GRAYTEXT);
1150 // Store the color back in the NMLVCUSTOMDRAW struct.
1151 pLVCD->clrText = crText;
1152 return;
1154 break;
1155 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1157 if (m_bStrictStopped && m_arShownList.size() == pLVCD->nmcd.dwItemSpec)
1159 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1162 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1164 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec && !this->m_IsRebaseReplaceGraph)
1166 CRect rect;
1167 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1169 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1170 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1172 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1173 if( !data ->m_CommitHash.IsEmpty())
1174 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1176 *pResult = CDRF_SKIPDEFAULT;
1177 return;
1181 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1183 // If the top index of list is changed, the position map of reference label is outdated.
1184 if (m_OldTopIndex != GetTopIndex())
1186 m_OldTopIndex = GetTopIndex();
1187 m_RefLabelPosMap.clear();
1190 if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec)
1192 GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1194 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1196 CRect rect;
1197 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1199 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1200 // not in FillBackGround method, because this only affected the message subitem
1201 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1202 return;
1204 int index = (int)pLVCD->nmcd.dwItemSpec;
1205 int state = GetItemState(index, LVIS_SELECTED);
1206 int txtState = LISS_NORMAL;
1207 if (IsAppThemed() && GetHotItem() == (int)index)
1209 if (state & LVIS_SELECTED)
1210 txtState = LISS_HOTSELECTED;
1211 else
1212 txtState = LISS_HOT;
1214 else if (state & LVIS_SELECTED)
1216 if (::GetFocus() == m_hWnd)
1217 txtState = LISS_SELECTED;
1218 else
1219 txtState = LISS_SELECTEDNOTFOCUS;
1222 HTHEME hTheme = nullptr;
1223 if (IsAppThemed())
1224 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1226 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1227 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1228 else
1230 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1231 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1232 ::DeleteObject(brush);
1234 if (hTheme)
1236 CRect rt;
1237 // get rect of whole line
1238 GetItemRect(index, rt, LVIR_BOUNDS);
1239 CRect rect2 = rect;
1240 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1241 rect2.DeflateRect(1, 1, 1, 1);
1243 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1244 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1246 CloseThemeData(hTheme);
1248 // END: extended redraw
1250 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1252 std::vector<REFLABEL> refsToShow;
1253 STRING_VECTOR remoteTrackingList;
1254 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1255 for (unsigned int i = 0; i < refList.size(); ++i)
1257 CString str = refList[i];
1259 REFLABEL refLabel;
1260 refLabel.color = RGB(255, 255, 255);
1261 refLabel.singleRemote = false;
1262 refLabel.hasTracking = false;
1263 refLabel.sameName = false;
1264 refLabel.name = CGit::GetShortName(str, &refLabel.refType);
1265 refLabel.fullName = str;
1267 switch (refLabel.refType)
1269 case CGit::REF_TYPE::LOCAL_BRANCH:
1271 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1272 continue;
1273 if (refLabel.name == m_CurrentBranch)
1274 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1275 else
1276 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1278 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1279 CString pullRemote = trackingEntry.first;
1280 CString pullBranch = trackingEntry.second;
1281 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1283 CString defaultUpstream;
1284 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1285 refLabel.hasTracking = true;
1286 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1288 bool found = false;
1289 for (size_t j = i + 1; j < refList.size(); ++j)
1291 if (refList[j] == defaultUpstream)
1293 found = true;
1294 break;
1298 if (found)
1300 bool sameName = pullBranch == refLabel.name;
1301 refsToShow.push_back(refLabel);
1302 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1303 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1304 if (m_bSymbolizeRefNames)
1306 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1308 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1309 refLabel.singleRemote = true;
1311 else if (sameName)
1312 refLabel.simplifiedName = pullRemote + _T("/");
1313 refLabel.sameName = sameName;
1315 refLabel.fullName = defaultUpstream;
1316 refsToShow.push_back(refLabel);
1317 remoteTrackingList.push_back(defaultUpstream);
1318 continue;
1322 break;
1324 case CGit::REF_TYPE::REMOTE_BRANCH:
1326 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1327 continue;
1328 bool found = false;
1329 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1331 if (remoteTrackingList[j] == str)
1333 found = true;
1334 break;
1337 if (found)
1338 continue;
1340 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1341 if (m_bSymbolizeRefNames)
1343 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1345 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1346 refLabel.singleRemote = true;
1349 break;
1351 case CGit::REF_TYPE::ANNOTATED_TAG:
1352 case CGit::REF_TYPE::TAG:
1353 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1354 continue;
1355 refLabel.color = m_Colors.GetColor(CColors::Tag);
1356 break;
1357 case CGit::REF_TYPE::STASH:
1358 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1359 continue;
1360 refLabel.color = m_Colors.GetColor(CColors::Stash);
1361 break;
1362 case CGit::REF_TYPE::BISECT_GOOD:
1363 case CGit::REF_TYPE::BISECT_BAD:
1364 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1365 continue;
1366 refLabel.color = (refLabel.refType == CGit::REF_TYPE::BISECT_GOOD) ? m_Colors.GetColor(CColors::BisectGood): m_Colors.GetColor(CColors::BisectBad);
1367 break;
1368 default:
1369 continue;
1371 refsToShow.push_back(refLabel);
1374 if (refsToShow.empty())
1376 *pResult = CDRF_DODEFAULT;
1377 return;
1380 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1382 *pResult = CDRF_SKIPDEFAULT;
1383 return;
1390 if (pLVCD->iSubItem == LOGLIST_ACTION)
1392 if(this->m_IsIDReplaceAction)
1394 *pResult = CDRF_DODEFAULT;
1395 return;
1397 *pResult = CDRF_DODEFAULT;
1399 if (m_arShownList.size() <= pLVCD->nmcd.dwItemSpec)
1400 return;
1402 int nIcons = 0;
1403 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1404 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1406 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1407 CRect rect;
1408 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1409 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1410 // Get the selected state of the
1411 // item being drawn.
1413 // Fill the background if necessary
1414 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1416 // Draw the icon(s) into the compatible DC
1417 int action = pLogEntry->GetAction(this);
1418 if (!pLogEntry->m_IsDiffFiles)
1420 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1421 *pResult = CDRF_SKIPDEFAULT;
1422 return;
1425 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1426 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1427 ++nIcons;
1429 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1430 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1431 ++nIcons;
1433 if (action & CTGitPath::LOGACTIONS_DELETED)
1434 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1435 ++nIcons;
1437 if (action & CTGitPath::LOGACTIONS_REPLACED)
1438 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1439 ++nIcons;
1441 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1442 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons * iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, nullptr, DI_NORMAL);
1443 ++nIcons;
1445 *pResult = CDRF_SKIPDEFAULT;
1446 return;
1449 break;
1451 *pResult = CDRF_DODEFAULT;
1454 CString FindSVNRev(const CString& msg)
1458 const std::tr1::wsregex_iterator end;
1459 std::wstring s = msg;
1460 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1461 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex1); it != end; ++it)
1463 const std::tr1::wsmatch match = *it;
1464 if (match.size() == 4)
1466 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1467 return std::wstring(match[2]).c_str();
1470 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1471 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex2); it != end; ++it)
1473 const std::tr1::wsmatch match = *it;
1474 if (match.size() == 3)
1476 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1477 return std::wstring(match[1]).c_str();
1481 catch (std::exception) {}
1483 return _T("");
1486 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1488 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1489 return pLogEntry->GetSubject();
1491 CString txt(pLogEntry->GetSubject());
1492 txt += _T(' ');
1493 txt += pLogEntry->GetBody();
1495 // Deal with CRLF
1496 txt.Replace(_T('\n'), _T(' '));
1497 txt.Replace(_T('\r'), _T(' '));
1499 return txt;
1502 // CGitLogListBase message handlers
1504 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1506 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1508 // Create a pointer to the item
1509 LV_ITEM* pItem = &(pDispInfo)->item;
1511 // Do the list need text information?
1512 if (!(pItem->mask & LVIF_TEXT))
1513 return;
1515 // By default, clear text buffer.
1516 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1518 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1520 *pResult = 0;
1521 if (m_bNoDispUpdates || bOutOfRange)
1522 return;
1524 // Which item number?
1525 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem);
1527 CString temp;
1528 if(m_IsOldFirst)
1529 temp.Format(_T("%d"),pItem->iItem+1);
1530 else
1531 temp.Format(_T("%d"), m_arShownList.size() - pItem->iItem);
1533 // Which column?
1534 switch (pItem->iSubItem)
1536 case LOGLIST_GRAPH: //Graphic
1537 break;
1538 case LOGLIST_REBASE:
1540 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1541 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1543 break;
1544 case LOGLIST_ACTION: //action -- no text in the column
1545 break;
1546 case LOGLIST_HASH:
1547 if(pLogEntry)
1548 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1549 break;
1550 case LOGLIST_ID:
1551 if(this->m_IsIDReplaceAction)
1552 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1553 break;
1554 case LOGLIST_MESSAGE: //Message
1555 if (pLogEntry)
1556 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1557 break;
1558 case LOGLIST_AUTHOR: //Author
1559 if (pLogEntry)
1560 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1561 break;
1562 case LOGLIST_DATE: //Date
1563 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1564 lstrcpyn(pItem->pszText,
1565 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1566 pItem->cchTextMax - 1);
1567 break;
1569 case LOGLIST_EMAIL:
1570 if (pLogEntry)
1571 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1572 break;
1574 case LOGLIST_COMMIT_NAME: //Commit
1575 if (pLogEntry)
1576 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1577 break;
1579 case LOGLIST_COMMIT_EMAIL: //Commit Email
1580 if (pLogEntry)
1581 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1582 break;
1584 case LOGLIST_COMMIT_DATE: //Commit Date
1585 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1586 lstrcpyn(pItem->pszText,
1587 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1588 pItem->cchTextMax - 1);
1589 break;
1590 case LOGLIST_BUG: //Bug ID
1591 if(pLogEntry)
1592 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1593 break;
1594 case LOGLIST_SVNREV: //SVN revision
1595 if (pLogEntry)
1596 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1597 break;
1599 default:
1600 ASSERT(false);
1604 bool CGitLogListBase::IsOnStash(int index)
1606 GitRevLoglist* rev = m_arShownList.SafeGetAt(index);
1607 if (IsStash(rev))
1608 return true;
1609 if (index > 0)
1611 GitRevLoglist* preRev = m_arShownList.SafeGetAt(index - 1);
1612 if (IsStash(preRev))
1613 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1615 return false;
1618 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1620 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1622 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1623 return true;
1625 return false;
1628 bool CGitLogListBase::IsBisect(const GitRev * pSelLogEntry)
1630 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1632 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Left(12) == _T("refs/bisect/"))
1633 return true;
1635 return false;
1638 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1640 if (pRev->m_ParentHash.empty())
1642 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1643 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1645 parentHash = pRev->m_ParentHash;
1648 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1650 __super::OnContextMenu(pWnd, point);
1652 if (pWnd != this)
1653 return;
1655 int selIndex = GetSelectionMark();
1656 if (selIndex < 0)
1657 return; // nothing selected, nothing to do with a context menu
1659 // if the user selected the info text telling about not all revisions shown due to
1660 // the "stop on copy/rename" option, we also don't show the context menu
1661 if (m_bStrictStopped && selIndex == (int)m_arShownList.size())
1662 return;
1664 // if the context menu is invoked through the keyboard, we have to use
1665 // a calculated position on where to anchor the menu on
1666 if ((point.x == -1) && (point.y == -1))
1668 CRect rect;
1669 GetItemRect(selIndex, &rect, LVIR_LABEL);
1670 ClientToScreen(&rect);
1671 point = rect.CenterPoint();
1673 m_nSearchIndex = selIndex;
1674 m_bCancelled = FALSE;
1676 // calculate some information the context menu commands can use
1677 // CString pathURL = GetURLFromPath(m_path);
1679 POSITION pos = GetFirstSelectedItemPosition();
1680 int indexNext = GetNextSelectedItem(pos);
1681 if (indexNext < 0)
1682 return;
1684 GitRevLoglist* pSelLogEntry = m_arShownList.SafeGetAt(indexNext);
1685 if (pSelLogEntry == nullptr)
1686 return;
1687 #if 0
1688 GitRev revSelected = pSelLogEntry->Rev;
1689 GitRev revPrevious = git_revnum_t(revSelected)-1;
1690 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1692 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1694 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1695 if (changedpath->lCopyFromRev)
1696 revPrevious = changedpath->lCopyFromRev;
1699 GitRev revSelected2;
1700 if (pos)
1702 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1703 revSelected2 = pLogEntry->Rev;
1705 bool bAllFromTheSameAuthor = true;
1706 CString firstAuthor;
1707 CLogDataVector selEntries;
1708 GitRev revLowest, revHighest;
1709 GitRevRangeArray revisionRanges;
1711 POSITION pos = GetFirstSelectedItemPosition();
1712 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1713 revisionRanges.AddRevision(pLogEntry->Rev);
1714 selEntries.push_back(pLogEntry);
1715 firstAuthor = pLogEntry->sAuthor;
1716 revLowest = pLogEntry->Rev;
1717 revHighest = pLogEntry->Rev;
1718 while (pos)
1720 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1721 revisionRanges.AddRevision(pLogEntry->Rev);
1722 selEntries.push_back(pLogEntry);
1723 if (firstAuthor.Compare(pLogEntry->sAuthor))
1724 bAllFromTheSameAuthor = false;
1725 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1726 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1730 #endif
1732 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1734 int FirstSelect=-1, LastSelect=-1;
1735 pos = GetFirstSelectedItemPosition();
1736 FirstSelect = GetNextSelectedItem(pos);
1737 while(pos)
1739 LastSelect = GetNextSelectedItem(pos);
1741 //entry is selected, now show the popup menu
1742 CIconMenu popup;
1743 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1745 if (popup.CreatePopupMenu())
1747 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1748 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1749 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1750 bool isStash = IsOnStash(indexNext);
1751 GIT_REV_LIST parentHash;
1752 GetParentHashes(pSelLogEntry, parentHash);
1754 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1755 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1757 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))
1758 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1760 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1761 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1763 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1764 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1766 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)))
1767 popup.AppendMenu(MF_SEPARATOR, NULL);
1769 if (GetSelectedCount() == 1)
1772 bool requiresSeparator = false;
1773 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1775 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1777 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1778 requiresSeparator = true;
1781 else
1783 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1785 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1786 requiresSeparator = true;
1788 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1790 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1791 requiresSeparator = true;
1795 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1797 if (parentHash.size() == 1)
1799 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1800 requiresSeparator = true;
1802 else if (parentHash.size() > 1)
1804 blamemenu.CreatePopupMenu();
1805 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1806 for (size_t i = 0; i < parentHash.size(); ++i)
1808 CString str;
1809 str.Format(IDS_PARENT, i + 1);
1810 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1812 requiresSeparator = true;
1816 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1818 if (parentHash.size() == 1)
1820 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1821 requiresSeparator = true;
1823 else if (parentHash.size() > 1)
1825 gnudiffmenu.CreatePopupMenu();
1826 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1828 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1829 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1830 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1832 for (size_t i = 0; i < parentHash.size(); ++i)
1834 CString str;
1835 str.Format(IDS_PARENT, i + 1);
1836 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1838 requiresSeparator = true;
1842 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1844 if (parentHash.size() == 1)
1846 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1847 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1848 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1849 requiresSeparator = true;
1851 else if (parentHash.size() > 1)
1853 diffmenu.CreatePopupMenu();
1854 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1855 for (size_t i = 0; i < parentHash.size(); ++i)
1857 CString str;
1858 str.Format(IDS_PARENT, i + 1);
1859 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1860 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1862 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1863 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1866 requiresSeparator = true;
1870 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1872 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1873 requiresSeparator = true;
1876 if (requiresSeparator)
1878 popup.AppendMenu(MF_SEPARATOR, NULL);
1879 requiresSeparator = false;
1882 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1884 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1886 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1887 requiresSeparator = true;
1891 if ((pSelLogEntry->m_CommitHash.IsEmpty() || isStash) && CTGitPath(g_Git.m_CurrentDir).HasStashDir())
1893 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1895 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1896 requiresSeparator = true;
1899 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1901 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1902 requiresSeparator = true;
1906 if (requiresSeparator)
1908 popup.AppendMenu(MF_SEPARATOR, NULL);
1909 requiresSeparator = false;
1912 if (CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1914 GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect);
1915 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTGOOD) && !IsBisect(pFirstEntry))
1917 popup.AppendMenuIcon(ID_BISECTGOOD, IDS_MENUBISECTGOOD, IDI_THUMB_UP);
1918 requiresSeparator = true;
1921 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTBAD) && !IsBisect(pFirstEntry))
1923 popup.AppendMenuIcon(ID_BISECTBAD, IDS_MENUBISECTBAD, IDI_THUMB_DOWN);
1924 requiresSeparator = true;
1928 if (pSelLogEntry->m_CommitHash.IsEmpty() && CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1930 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTRESET))
1932 popup.AppendMenuIcon(ID_BISECTRESET, IDS_MENUBISECTRESET, IDI_BISECT_RESET);
1933 requiresSeparator = true;
1937 if (requiresSeparator)
1939 popup.AppendMenu(MF_SEPARATOR, NULL);
1940 requiresSeparator = false;
1943 if (pSelLogEntry->m_CommitHash.IsEmpty())
1945 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1946 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1948 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1949 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1951 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1952 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1954 popup.AppendMenu(MF_SEPARATOR, NULL);
1956 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1957 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1959 popup.AppendMenu(MF_SEPARATOR, NULL);
1963 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1964 // {
1965 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1966 // }
1967 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1968 // {
1969 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1970 // }
1971 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1972 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1973 // {
1974 // popup.AppendMenu(MF_SEPARATOR, NULL);
1975 // }
1977 CString str;
1978 //if (m_hasWC)
1979 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1981 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1983 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1984 GetSelectedCount() == 1)
1985 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1987 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1988 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1990 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
1992 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
1994 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1996 size_t index = (size_t)-1;
1997 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
1998 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
1999 popup.SetMenuItemData(ID_MERGEREV, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2002 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2004 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2005 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2008 // Add Switch Branch express Menu
2009 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2010 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2013 std::vector<const CString*> branchs;
2014 auto addCheck = [&](const CString& ref)
2016 if (ref.Find(_T("refs/heads/")) != 0 || ref == currentBranch)
2017 return;
2018 branchs.push_back(&ref);
2020 size_t index = (size_t)-1;
2021 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2022 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2023 addCheck(m_HashMap[pSelLogEntry->m_CommitHash][index]);
2024 else
2025 for_each(m_HashMap[pSelLogEntry->m_CommitHash], addCheck);
2027 CString str2;
2028 str2.LoadString(IDS_SWITCH_BRANCH);
2030 if(branchs.size() == 1)
2032 str2 += _T(' ');
2033 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2034 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2036 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2039 else if(branchs.size() > 1)
2041 subbranchmenu.CreatePopupMenu();
2042 for (size_t i = 0 ; i < branchs.size(); ++i)
2044 if (*branchs[i] != currentBranch)
2046 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2047 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2051 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2055 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2057 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS, IDI_SWITCH);
2058 size_t index = (size_t)-1;
2059 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2060 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2061 popup.SetMenuItemData(ID_SWITCHTOREV, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2064 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2066 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS, IDI_COPY);
2068 size_t index = (size_t)-1;
2069 CGit::REF_TYPE type = CGit::REF_TYPE::REMOTE_BRANCH;
2070 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2071 popup.SetMenuItemData(ID_CREATE_BRANCH, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2074 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2075 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2077 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2079 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2080 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2081 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2083 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2084 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2086 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2088 if (parentHash.size() == 1)
2089 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2090 else if (parentHash.size() > 1)
2092 revertmenu.CreatePopupMenu();
2093 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2095 for (size_t i = 0; i < parentHash.size(); ++i)
2097 CString str2;
2098 str2.Format(IDS_PARENT, i + 1);
2099 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2104 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2105 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2107 popup.AppendMenu(MF_SEPARATOR, NULL);
2111 if(!pSelLogEntry->m_Ref.IsEmpty())
2113 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2114 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2115 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2116 popup.AppendMenu(MF_SEPARATOR, NULL);
2119 if (GetSelectedCount() >= 2)
2121 bool bAddSeparator = false;
2122 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2124 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2125 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2128 if (GetSelectedCount() == 2)
2130 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2131 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2133 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2135 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2136 GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect);
2137 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2138 CString menu;
2139 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2140 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2141 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2142 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2145 bAddSeparator = true;
2148 if (m_hasWC)
2149 bAddSeparator = true;
2151 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2152 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2154 if (bAddSeparator)
2155 popup.AppendMenu(MF_SEPARATOR, NULL);
2158 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2160 bool bAddSeparator = false;
2161 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2163 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2165 CString head;
2166 int headindex;
2167 headindex = this->GetHeadIndex();
2168 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2170 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2171 CGitHash hashFirst;
2172 if (g_Git.GetHash(hashFirst, head))
2173 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2174 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2175 CGitHash hash;
2176 if (g_Git.GetHash(hash, head))
2177 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2178 GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect);
2179 GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect);
2180 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2181 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2182 bAddSeparator = true;
2187 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2188 if (GetSelectedCount() >= 2)
2189 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2190 else
2191 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2192 bAddSeparator = true;
2195 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2196 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2197 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2198 bAddSeparator = true;
2201 if (bAddSeparator)
2202 popup.AppendMenu(MF_SEPARATOR, NULL);
2205 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())
2207 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2208 popup.AppendMenu(MF_SEPARATOR, NULL);
2211 if (GetSelectedCount() == 1)
2213 bool bAddSeparator = false;
2214 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2216 // show the push-option only if the log entry has an associated local branch
2217 bool isLocal = find_if(m_HashMap[pSelLogEntry->m_CommitHash], [](const CString& ref) { return ref.Find(_T("refs/heads/")) == 0; }) != m_HashMap[pSelLogEntry->m_CommitHash].cend();
2218 if (isLocal || showExtendedMenu)
2220 CString str;
2221 str.LoadString(IDS_LOG_PUSH);
2223 CString branch;
2224 size_t index = (size_t)-1;
2225 CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH;
2226 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, &branch, &index))
2227 str.Insert(str.Find(L'.'), L" \"" + branch + L'"');
2229 popup.AppendMenuIcon(ID_PUSH, str, IDI_PUSH);
2231 if (index != (size_t)-1 && index < m_HashMap[pSelLogEntry->m_CommitHash].size())
2232 popup.SetMenuItemData(ID_PUSH, (ULONG_PTR)&m_HashMap[pSelLogEntry->m_CommitHash][index]);
2234 bAddSeparator = true;
2237 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2239 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2240 bAddSeparator = true;
2244 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2246 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2248 std::vector<const CString*> branchs;
2249 auto addCheck = [&](const CString& ref)
2251 if (ref == currentBranch)
2252 return;
2253 branchs.push_back(&ref);
2255 size_t index = (size_t)-1;
2256 CGit::REF_TYPE type = CGit::REF_TYPE::UNKNOWN;
2257 if (IsMouseOnRefLabelFromPopupMenu(pSelLogEntry, point, type, nullptr, &index))
2258 addCheck(m_HashMap[pSelLogEntry->m_CommitHash][index]);
2259 else
2260 for_each(m_HashMap[pSelLogEntry->m_CommitHash], addCheck);
2262 CString str;
2263 if (branchs.size() == 1)
2265 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2266 str+=_T(' ');
2267 str += *branchs[0];
2268 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2269 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2270 bAddSeparator = true;
2272 else if (branchs.size() > 1)
2274 str.LoadString(IDS_DELETE_BRANCHTAG);
2275 submenu.CreatePopupMenu();
2276 for (size_t i = 0; i < branchs.size(); ++i)
2278 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2279 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2281 submenu.AppendMenuIcon(ID_DELETE + (branchs.size() << 16), IDS_ALL);
2282 submenu.SetMenuItemData(ID_DELETE + (branchs.size() << 16), (ULONG_PTR)MAKEINTRESOURCE(IDS_ALL));
2284 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2285 bAddSeparator = true;
2288 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2289 if (bAddSeparator)
2290 popup.AppendMenu(MF_SEPARATOR, NULL);
2291 } // GetSelectedCount() == 1
2293 if (GetSelectedCount() != 0)
2295 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2296 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2297 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2298 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2299 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2300 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2303 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2304 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2306 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2307 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2309 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2310 // DialogEnableWindow(IDOK, FALSE);
2311 // SetPromptApp(&theApp);
2313 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2315 // EnableOKButton();
2316 } // if (popup.CreatePopupMenu())
2319 bool CGitLogListBase::IsSelectionContinuous()
2321 if ( GetSelectedCount()==1 )
2323 // if only one revision is selected, the selection is of course
2324 // continuous
2325 return true;
2328 POSITION pos = GetFirstSelectedItemPosition();
2329 bool bContinuous = (m_arShownList.size() == m_logEntries.size());
2330 if (bContinuous)
2332 int itemindex = GetNextSelectedItem(pos);
2333 while (pos)
2335 int nextindex = GetNextSelectedItem(pos);
2336 if (nextindex - itemindex > 1)
2338 bContinuous = false;
2339 break;
2341 itemindex = nextindex;
2344 return bContinuous;
2347 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2349 CString sClipdata;
2350 POSITION pos = GetFirstSelectedItemPosition();
2351 if (pos)
2353 CString sRev;
2354 sRev.LoadString(IDS_LOG_REVISION);
2355 CString sAuthor;
2356 sAuthor.LoadString(IDS_LOG_AUTHOR);
2357 CString sDate;
2358 sDate.LoadString(IDS_LOG_DATE);
2359 CString sMessage;
2360 sMessage.LoadString(IDS_LOG_MESSAGE);
2361 bool first = true;
2362 while (pos)
2364 CString sLogCopyText;
2365 CString sPaths;
2366 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(GetNextSelectedItem(pos));
2368 if (toCopy == ID_COPY_ALL)
2370 //pLogEntry->GetFiles(this)
2371 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2373 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2374 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2376 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2377 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2379 sPaths += L' ';
2380 sPaths.AppendFormat(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2382 sPaths += _T("\r\n");
2384 sPaths.Trim();
2385 CString body = pLogEntry->GetBody();
2386 body.Replace(_T("\n"), _T("\r\n"));
2387 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"),
2388 (LPCTSTR)sRev, (LPCTSTR)pLogEntry->m_CommitHash.ToString(),
2389 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2390 (LPCTSTR)sDate,
2391 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2392 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->GetSubjectBody(true),
2393 (LPCTSTR)sPaths);
2394 sClipdata += sLogCopyText;
2396 else if (toCopy == ID_COPY_MESSAGE)
2398 sClipdata += _T("* ");
2399 sClipdata += pLogEntry->GetSubjectBody(true);
2400 sClipdata += _T("\r\n\r\n");
2402 else if (toCopy == ID_COPY_SUBJECT)
2404 sClipdata += _T("* ");
2405 sClipdata += pLogEntry->GetSubject().Trim();
2406 sClipdata += _T("\r\n\r\n");
2408 else
2410 if (!first)
2411 sClipdata += _T("\r\n");
2412 sClipdata += pLogEntry->m_CommitHash;
2415 first = false;
2417 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2421 void CGitLogListBase::DiffSelectedRevWithPrevious()
2423 if (m_bThreadRunning)
2424 return;
2426 int FirstSelect=-1, LastSelect=-1;
2427 POSITION pos = GetFirstSelectedItemPosition();
2428 FirstSelect = GetNextSelectedItem(pos);
2429 while(pos)
2430 LastSelect = GetNextSelectedItem(pos);
2432 ContextMenuAction(ID_COMPAREWITHPREVIOUS, FirstSelect, LastSelect, nullptr);
2435 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2437 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2438 *pResult = -1;
2440 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2441 return;
2442 if (pFindInfo->iStart < 0 || pFindInfo->iStart >= (int)m_arShownList.size())
2443 return;
2444 if (!pFindInfo->lvfi.psz)
2445 return;
2446 #if 0
2447 CString sCmp = pFindInfo->lvfi.psz;
2448 CString sRev;
2449 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2451 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2452 sRev.Format(_T("%ld"), pLogEntry->Rev);
2453 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2455 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2457 *pResult = i;
2458 return;
2461 else
2463 if (sCmp.Compare(sRev)==0)
2465 *pResult = i;
2466 return;
2470 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2472 for (int i=0; i<pFindInfo->iStart; ++i)
2474 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2475 sRev.Format(_T("%ld"), pLogEntry->Rev);
2476 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2478 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2480 *pResult = i;
2481 return;
2484 else
2486 if (sCmp.Compare(sRev)==0)
2488 *pResult = i;
2489 return;
2494 #endif
2495 *pResult = -1;
2498 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2500 ClearText();
2502 this->m_arShownList.SafeRemoveAll();
2504 this->m_logEntries.ClearAll();
2505 if (this->m_logEntries.ParserFromLog(path, 0, info, range))
2506 return -1;
2508 SetItemCountEx((int)m_logEntries.size());
2510 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2512 if(m_IsOldFirst)
2514 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2515 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2517 else
2519 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2520 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2524 ReloadHashMap();
2526 if(path)
2527 m_Path=*path;
2528 return 0;
2531 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2533 ClearText();
2535 m_arShownList.SafeRemoveAll();
2537 m_logEntries.ClearAll();
2538 if (m_logEntries.Fill(hashes))
2539 return -1;
2541 SetItemCountEx((int)m_logEntries.size());
2543 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2545 if (m_IsOldFirst)
2547 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2548 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2550 else
2552 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2553 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2557 ReloadHashMap();
2559 return 0;
2562 int CGitLogListBase::BeginFetchLog()
2564 ClearText();
2566 this->m_arShownList.SafeRemoveAll();
2568 this->m_logEntries.ClearAll();
2570 this->m_LogCache.ClearAllParent();
2572 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2574 CTGitPath *path;
2575 if(this->m_Path.IsEmpty())
2576 path = nullptr;
2577 else
2578 path=&this->m_Path;
2580 int mask;
2581 mask = CGit::LOG_INFO_ONLY_HASH;
2582 if (m_bIncludeBoundaryCommits)
2583 mask |= CGit::LOG_INFO_BOUNDARY;
2584 // if(this->m_bAllBranch)
2585 mask |= m_ShowMask ;
2587 if(m_bShowWC)
2589 this->m_logEntries.insert(m_logEntries.cbegin(), m_wcRev.m_CommitHash);
2590 ResetWcRev();
2591 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2594 if (m_sRange.IsEmpty())
2595 m_sRange = _T("HEAD");
2597 #if 0 /* use tortoiegit filter */
2598 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2599 data.m_Author = this->m_sFilterText;
2601 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2602 data.m_MessageFilter = this->m_sFilterText;
2604 data.m_IsRegex = m_bFilterWithRegex;
2605 #endif
2607 // follow does not work for directories
2608 if (!path || path->IsDirectory())
2609 mask &= ~CGit::LOG_INFO_FOLLOW;
2610 // follow does not work with all branches 8at least in TGit)
2611 if (mask & CGit::LOG_INFO_FOLLOW)
2612 mask &= ~(CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_BASIC_REFS | CGit::LOG_INFO_LOCAL_BRANCHES);
2614 CString cmd = g_Git.GetLogCmd(m_sRange, path, mask, &m_Filter, CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER));
2616 //this->m_logEntries.ParserFromLog();
2617 if(IsInWorkingThread())
2619 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2621 else
2623 SetItemCountEx((int)m_logEntries.size());
2628 [] { git_init(); } ();
2630 catch (char* msg)
2632 CString err(msg);
2633 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2634 return -1;
2637 if (!g_Git.CanParseRev(m_sRange))
2639 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_BASIC_REFS) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2640 return 0;
2642 // if show all branches, pick any ref as dummy entry ref
2643 STRING_VECTOR list;
2644 if (g_Git.GetRefList(list))
2645 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2646 if (list.empty())
2647 return 0;
2649 cmd = g_Git.GetLogCmd(list[0], path, mask, &m_Filter, CRegDWORD(L"Software\\TortoiseGit\\LogOrderBy", CGit::LOG_ORDER_TOPOORDER));
2652 g_Git.m_critGitDllSec.Lock();
2653 try {
2654 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2656 g_Git.m_critGitDllSec.Unlock();
2657 return -1;
2660 catch (char* msg)
2662 g_Git.m_critGitDllSec.Unlock();
2663 CString err(msg);
2664 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2665 return -1;
2667 g_Git.m_critGitDllSec.Unlock();
2669 return 0;
2672 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2674 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2676 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2678 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2680 DiffSelectedRevWithPrevious();
2681 return TRUE;
2684 #if 0
2685 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2687 DiffSelectedFile();
2688 return TRUE;
2690 #endif
2692 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2694 // select all entries
2695 for (int i=0; i<GetItemCount(); ++i)
2696 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2697 return TRUE;
2700 #if 0
2701 if (m_hAccel && !bSkipAccelerator)
2703 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2704 if (ret)
2705 return TRUE;
2708 #endif
2709 //m_tooltips.RelayEvent(pMsg);
2710 return __super::PreTranslateMessage(pMsg);
2713 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2715 // a double click on an entry in the revision list has happened
2716 *pResult = 0;
2718 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2719 DiffSelectedRevWithPrevious();
2722 void CGitLogListBase::FetchLogAsync(void* data)
2724 ReloadHashMap();
2725 m_ProcData=data;
2726 StartLoadingThread();
2729 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2731 return ((CGitLogListBase*)pVoid)->LogThread();
2734 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2736 //CTime time;
2737 oldest=CTime::GetCurrentTime();
2738 latest=CTime(1971,1,2,0,0,0);
2739 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2741 if(m_logEntries[i].IsEmpty())
2742 continue;
2744 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() < oldest.GetTime())
2745 oldest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2747 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() > latest.GetTime())
2748 latest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2752 if(latest<oldest)
2753 latest=oldest;
2756 UINT CGitLogListBase::LogThread()
2758 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2760 ULONGLONG t1,t2;
2762 if(BeginFetchLog())
2764 InterlockedExchange(&m_bThreadRunning, FALSE);
2765 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2767 return 1;
2770 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2771 bool bRegex = false;
2772 if (m_bFilterWithRegex)
2773 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2775 TRACE(_T("\n===Begin===\n"));
2776 //Update work copy item;
2778 if (!m_logEntries.empty())
2780 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2782 m_arShownList.SafeAdd(pRev);
2786 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2788 // store commit number of the last selected commit/line before the refresh or -1
2789 int lastSelectedHashNItem = -1;
2790 if (m_lastSelectedHash.IsEmpty())
2791 lastSelectedHashNItem = 0;
2793 int ret = 0;
2795 bool shouldWalk = true;
2796 if (!g_Git.CanParseRev(m_sRange))
2798 // walk revisions if show all branches and there exists any ref
2799 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_BASIC_REFS) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2800 shouldWalk = false;
2801 else
2803 STRING_VECTOR list;
2804 if (g_Git.GetRefList(list))
2805 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2806 if (list.empty())
2807 shouldWalk = false;
2811 if (shouldWalk)
2813 g_Git.m_critGitDllSec.Lock();
2814 int total = 0;
2817 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2818 total = git_get_log_estimate_commit_count(m_DllGitLog);
2820 catch (char* msg)
2822 CString err(msg);
2823 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2824 ret = -1;
2826 g_Git.m_critGitDllSec.Unlock();
2828 GIT_COMMIT commit;
2829 t2 = t1 = GetTickCount64();
2830 int oldprecentage = 0;
2831 size_t oldsize = m_logEntries.size();
2832 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2833 while (ret== 0 && !m_bExitThread)
2835 g_Git.m_critGitDllSec.Lock();
2838 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2840 catch (char* msg)
2842 g_Git.m_critGitDllSec.Unlock();
2843 CString err(msg);
2844 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2845 break;
2847 g_Git.m_critGitDllSec.Unlock();
2849 if(ret)
2851 if (ret != -2) // other than end of revision walking
2852 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2853 break;
2856 if (commit.m_ignore == 1)
2858 git_free_commit(&commit);
2859 continue;
2862 //printf("%s\r\n",commit.GetSubject());
2863 if(m_bExitThread)
2864 break;
2866 CGitHash hash = (char*)commit.m_hash ;
2868 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2869 pRev->m_GitCommit = commit;
2870 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2872 char* note = nullptr;
2873 g_Git.m_critGitDllSec.Lock();
2876 git_get_notes(commit.m_hash, &note);
2878 catch (char* msg)
2880 g_Git.m_critGitDllSec.Unlock();
2881 CString err(msg);
2882 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2883 break;
2885 g_Git.m_critGitDllSec.Unlock();
2887 if(note)
2889 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2890 free(note);
2891 note = nullptr;
2894 if(!pRev->m_IsDiffFiles)
2896 pRev->m_CallDiffAsync = DiffAsync;
2899 pRev->ParserParentFromCommit(&commit);
2900 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2902 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2904 const CGitHash &parentHash = pRev->m_ParentHash[i];
2905 auto it = commitChildren.find(parentHash);
2906 if (it == commitChildren.end())
2907 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2908 it->second.insert(pRev->m_CommitHash);
2912 #ifdef DEBUG
2913 pRev->DbgPrint();
2914 TRACE(_T("\n"));
2915 #endif
2917 bool visible = true;
2918 if (HasFilterText())
2920 if(!IsMatchFilter(bRegex,pRev,pat))
2921 visible = false;
2923 if (visible && !ShouldShowFilter(pRev, commitChildren))
2924 visible = false;
2925 this->m_critSec.Lock();
2926 m_logEntries.append(hash, visible);
2927 if (visible)
2928 m_arShownList.SafeAdd(pRev);
2929 this->m_critSec.Unlock();
2931 if (!visible)
2932 continue;
2934 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2935 lastSelectedHashNItem = (int)m_arShownList.size() - 1;
2937 t2 = GetTickCount64();
2939 if (t2 - t1 > 500UL || (m_logEntries.size() - oldsize > 100))
2941 //update UI
2942 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2943 if(percent > 99)
2944 percent =99;
2945 if(percent < GITLOG_START)
2946 percent = GITLOG_START +1;
2948 oldsize = m_logEntries.size();
2949 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2951 //if( percent > oldprecentage )
2953 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2954 oldprecentage = percent;
2957 if (lastSelectedHashNItem >= 0)
2958 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2960 t1 = t2;
2963 g_Git.m_critGitDllSec.Lock();
2964 git_close_log(m_DllGitLog);
2965 g_Git.m_critGitDllSec.Unlock();
2969 if (m_bExitThread)
2971 InterlockedExchange(&m_bThreadRunning, FALSE);
2972 return 0;
2975 //Update UI;
2976 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2978 if (lastSelectedHashNItem >= 0)
2979 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2981 if (this->m_hWnd)
2982 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2984 InterlockedExchange(&m_bThreadRunning, FALSE);
2986 return 0;
2989 void CGitLogListBase::FetchRemoteList()
2991 STRING_VECTOR remoteList;
2992 m_SingleRemote.Empty();
2993 if (!g_Git.GetRemoteList(remoteList) && remoteList.size() == 1)
2994 m_SingleRemote = remoteList[0];
2997 void CGitLogListBase::FetchTrackingBranchList()
2999 m_TrackingMap.clear();
3000 for (auto it = m_HashMap.cbegin(); it != m_HashMap.cend(); ++it)
3002 for (const auto& ref : it->second)
3004 CString branchName;
3005 if (CGit::GetShortName(ref, branchName, _T("refs/heads/")))
3007 CString pullRemote, pullBranch;
3008 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3009 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3010 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3016 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3018 SafeTerminateThread();
3020 this->SetItemCountEx(0);
3021 this->Clear();
3023 ResetWcRev();
3025 ShowGraphColumn((m_ShowMask & CGit::LOG_INFO_FOLLOW) ? false : true);
3027 //Update branch and Tag info
3028 ReloadHashMap();
3029 if (m_pFindDialog)
3030 m_pFindDialog->RefreshList();
3031 //Assume Thread have exited
3032 //if(!m_bThreadRunning)
3034 m_logEntries.clear();
3036 if(IsCleanFilter)
3038 m_sFilterText.Empty();
3041 SafeTerminateAsyncDiffThread();
3042 m_AsynDiffListLock.Lock();
3043 m_AsynDiffList.clear();
3044 m_AsynDiffListLock.Unlock();
3045 StartAsyncDiffThread();
3047 StartLoadingThread();
3051 void CGitLogListBase::StartAsyncDiffThread()
3053 if (m_AsyncThreadExit)
3054 return;
3055 if (InterlockedExchange(&m_AsyncThreadRunning, TRUE) != FALSE)
3056 return;
3057 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
3058 if (!m_DiffingThread)
3060 InterlockedExchange(&m_AsyncThreadRunning, FALSE);
3061 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3065 void CGitLogListBase::StartLoadingThread()
3067 if (InterlockedExchange(&m_bThreadRunning, TRUE) != FALSE)
3068 return;
3069 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3070 InterlockedExchange(&m_bExitThread, FALSE);
3071 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
3072 if (!m_LoadingThread)
3074 InterlockedExchange(&m_bThreadRunning, FALSE);
3075 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3076 CMessageBox::Show(GetSafeHwnd(), IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3080 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3084 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3085 if (!bMatchCase)
3086 type |= std::tr1::regex_constants::icase;
3087 pat = std::tr1::wregex(regexp_str, type);
3088 return true;
3090 catch (std::exception) {}
3091 return false;
3093 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3095 BOOL result = TRUE;
3096 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3097 CString sRev;
3099 if ((bRegex)&&(m_bFilterWithRegex))
3101 if (m_SelectedFilters & LOGFILTER_BUGID)
3103 if(this->m_bShowBugtraqColumn)
3105 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3107 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3108 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3109 return TRUE;
3113 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3115 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3116 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3117 return TRUE;
3120 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3122 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3123 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3124 return TRUE;
3127 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3129 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3130 return TRUE;
3132 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3133 return TRUE;
3136 if (m_SelectedFilters & LOGFILTER_EMAILS)
3138 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3139 return TRUE;
3141 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3142 return TRUE;
3145 if (m_SelectedFilters & LOGFILTER_REVS)
3147 sRev = pRev->m_CommitHash.ToString();
3148 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3150 return TRUE;
3154 if (m_SelectedFilters & LOGFILTER_NOTES)
3156 if (std::regex_search(std::wstring(pRev->m_Notes), pat, flags))
3157 return TRUE;
3160 if (m_SelectedFilters & LOGFILTER_REFNAME)
3162 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3163 for (const auto& ref : refs)
3165 if (std::regex_search(std::wstring(ref), pat, flags))
3166 return TRUE;
3170 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3172 if (std::regex_search(std::wstring(GetTagInfo(pRev)), pat, flags))
3173 return TRUE;
3176 if (m_SelectedFilters & LOGFILTER_PATHS)
3178 CTGitPathList* pathList = nullptr;
3179 if( pRev->m_IsDiffFiles)
3180 pathList = &pRev->GetFiles(this);
3181 else
3183 if(!pRev->m_IsSimpleListReady)
3184 pRev->SafeGetSimpleList(&g_Git);
3187 if(pathList)
3188 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3190 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3191 return true;
3192 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3193 return true;
3196 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3198 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3199 return true;
3203 else
3205 CString find = m_sFilterText;
3206 if (!m_bFilterCaseSensitively)
3207 find.MakeLower();
3208 result = find[0] == '!' ? FALSE : TRUE;
3209 if (!result)
3210 find = find.Mid(1);
3212 if (m_SelectedFilters & LOGFILTER_BUGID)
3214 if(this->m_bShowBugtraqColumn)
3216 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3218 if (!m_bFilterCaseSensitively)
3219 sBugIds.MakeLower();
3220 if ((sBugIds.Find(find) >= 0))
3221 return result;
3225 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3227 CString msg = pRev->GetSubject();
3229 if (!m_bFilterCaseSensitively)
3230 msg = msg.MakeLower();
3231 if ((msg.Find(find) >= 0))
3232 return result;
3235 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3237 CString msg = pRev->GetBody();
3239 if (!m_bFilterCaseSensitively)
3240 msg = msg.MakeLower();
3241 if ((msg.Find(find) >= 0))
3242 return result;
3245 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3247 CString msg = pRev->GetAuthorName();
3248 if (!m_bFilterCaseSensitively)
3249 msg = msg.MakeLower();
3250 if ((msg.Find(find) >= 0))
3251 return result;
3254 if (m_SelectedFilters & LOGFILTER_EMAILS)
3256 CString msg = pRev->GetAuthorEmail();
3257 if (!m_bFilterCaseSensitively)
3258 msg = msg.MakeLower();
3259 if ((msg.Find(find) >= 0))
3260 return result;
3263 if (m_SelectedFilters & LOGFILTER_NOTES)
3265 CString msg = pRev->m_Notes;
3266 if (!m_bFilterCaseSensitively)
3267 msg = msg.MakeLower();
3268 if ((msg.Find(find) >= 0))
3269 return result;
3272 if (m_SelectedFilters & LOGFILTER_REVS)
3274 sRev = pRev->m_CommitHash.ToString();
3275 if ((sRev.Find(find) >= 0))
3276 return result;
3279 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3281 CString msg = GetTagInfo(pRev);
3282 if (!m_bFilterCaseSensitively)
3283 msg = msg.MakeLower();
3284 if ((msg.Find(find) >= 0))
3285 return result;
3288 if (m_SelectedFilters & LOGFILTER_REFNAME)
3290 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3291 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3293 if (it->Find(find) >= 0)
3294 return result;
3298 if (m_SelectedFilters & LOGFILTER_PATHS)
3300 CTGitPathList* pathList = nullptr;
3301 if( pRev->m_IsDiffFiles)
3302 pathList = &pRev->GetFiles(this);
3303 else
3305 if(!pRev->m_IsSimpleListReady)
3306 pRev->SafeGetSimpleList(&g_Git);
3308 if(pathList)
3309 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3311 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3312 CString path = cpath->GetGitOldPathString();
3313 if (!m_bFilterCaseSensitively)
3314 path.MakeLower();
3315 if ((path.Find(find)>=0))
3316 return result;
3317 path = cpath->GetGitPathString();
3318 if (!m_bFilterCaseSensitively)
3319 path.MakeLower();
3320 if ((path.Find(find)>=0))
3321 return result;
3324 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3326 CString path = pRev->m_SimpleFileList[i];
3327 if (!m_bFilterCaseSensitively)
3328 path.MakeLower();
3329 if ((path.Find(find)>=0))
3330 return result;
3333 } // else (from if (bRegex))
3334 return !result;
3337 static bool CStringStartsWith(const CString &str, const CString &prefix)
3339 return str.Left(prefix.GetLength()) == prefix;
3341 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3343 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3344 return true;
3346 if (m_ShowFilter & FILTERSHOW_REFS)
3348 // Keep all refs.
3349 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3350 for (size_t i = 0; i < refList.size(); ++i)
3352 const CString &str = refList[i];
3353 if (CStringStartsWith(str, _T("refs/heads/")))
3355 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3356 return true;
3358 else if (CStringStartsWith(str, _T("refs/remotes/")))
3360 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3361 return true;
3363 else if (CStringStartsWith(str, _T("refs/tags/")))
3365 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3366 return true;
3368 else if (CStringStartsWith(str, _T("refs/stash")))
3370 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3371 return true;
3373 else if (CStringStartsWith(str, _T("refs/bisect/")))
3375 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3376 return true;
3379 // Keep the head too.
3380 if (pRev->m_CommitHash == m_HeadHash)
3381 return true;
3384 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3386 if (pRev->ParentsCount() > 1)
3387 return true;
3388 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3389 if (childrenIt != commitChildren.end())
3391 const std::set<CGitHash> &children = childrenIt->second;
3392 if (children.size() > 1)
3393 return true;
3396 return false;
3399 void CGitLogListBase::ShowGraphColumn(bool bShow)
3401 // HACK to hide graph column
3402 if (bShow)
3403 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3404 else
3405 SetColumnWidth(0, 0);
3408 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3410 CString cmd;
3411 CString output;
3413 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3415 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3416 for (size_t i = 0; i < vector.size(); ++i)
3418 if (vector[i].Find(_T("refs/tags/")) == 0)
3420 CString tag = vector[i];
3421 int start = vector[i].Find(_T("^{}"));
3422 if (start > 0)
3423 tag = tag.Left(start);
3424 else
3425 continue;
3427 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3428 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3429 output.AppendChar(_T('\n'));
3434 return output;
3437 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3439 pShownlist->SafeRemoveAll();
3441 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3442 bool bRegex = false;
3443 if (m_bFilterWithRegex)
3444 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3446 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3447 CString sRev;
3448 for (DWORD i=0; i<m_logEntries.size(); ++i)
3450 if ((bRegex)&&(m_bFilterWithRegex))
3452 #if 0
3453 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3455 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3456 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3458 pShownlist->SafeAdd(m_logEntries[i]);
3459 continue;
3462 #endif
3463 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3465 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3466 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3468 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3469 continue;
3472 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3474 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3475 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3477 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3478 continue;
3481 if (m_SelectedFilters & LOGFILTER_PATHS)
3483 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3485 bool bGoing = true;
3486 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3488 CTGitPath cpath = pathList[cpPathIndex];
3489 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3491 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3492 bGoing = false;
3493 continue;
3495 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3497 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3498 bGoing = false;
3499 continue;
3501 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3503 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3504 bGoing = false;
3505 continue;
3509 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3511 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3513 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3514 continue;
3517 if (m_SelectedFilters & LOGFILTER_EMAILS)
3519 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3521 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3522 continue;
3525 if (m_SelectedFilters & LOGFILTER_REVS)
3527 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3528 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3530 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3531 continue;
3534 if (m_SelectedFilters & LOGFILTER_REFNAME)
3536 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3537 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3539 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3541 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3542 continue;
3546 } // if (bRegex)
3547 else
3549 CString find = m_sFilterText;
3550 if (!m_bFilterCaseSensitively)
3551 find.MakeLower();
3552 #if 0
3553 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3555 CString sBugIDs = m_logEntries[i]->sBugIDs;
3557 if (!m_bFilterCaseSensitively)
3558 sBugIDs = sBugIDs.MakeLower();
3559 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3561 pShownlist->SafeAdd(m_logEntries[i]);
3562 continue;
3565 #endif
3566 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3568 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3570 if (!m_bFilterCaseSensitively)
3571 msg = msg.MakeLower();
3572 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3574 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3575 continue;
3578 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3580 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3582 if (!m_bFilterCaseSensitively)
3583 msg = msg.MakeLower();
3584 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3586 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3587 continue;
3590 if (m_SelectedFilters & LOGFILTER_PATHS)
3592 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3594 bool bGoing = true;
3595 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3597 CTGitPath cpath = pathList[cpPathIndex];
3598 CString path = cpath.GetGitOldPathString();
3599 if (!m_bFilterCaseSensitively)
3600 path.MakeLower();
3601 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3603 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3604 bGoing = false;
3605 continue;
3607 path = cpath.GetGitPathString();
3608 if (!m_bFilterCaseSensitively)
3609 path.MakeLower();
3610 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3612 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3613 bGoing = false;
3614 continue;
3616 path = cpath.GetActionName();
3617 if (!m_bFilterCaseSensitively)
3618 path.MakeLower();
3619 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3621 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3622 bGoing = false;
3623 continue;
3627 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3629 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3630 if (!m_bFilterCaseSensitively)
3631 msg = msg.MakeLower();
3632 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3634 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3635 continue;
3638 if (m_SelectedFilters & LOGFILTER_EMAILS)
3640 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3641 if (!m_bFilterCaseSensitively)
3642 msg = msg.MakeLower();
3643 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3645 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3646 continue;
3649 if (m_SelectedFilters & LOGFILTER_REVS)
3651 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3652 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3654 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3655 continue;
3658 if (m_SelectedFilters & LOGFILTER_REFNAME)
3660 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3661 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3663 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3665 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3666 continue;
3670 } // else (from if (bRegex))
3671 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3674 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3677 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3679 if(m_From == -1)
3680 if(m_To == -1)
3681 return true;
3682 else
3683 return time <= m_To;
3684 else
3685 if(m_To == -1)
3686 return time >= m_From;
3687 else
3688 return ((time >= m_From)&&(time <= m_To));
3690 return TRUE; /* git dll will filter time range */
3692 // return TRUE;
3695 void CGitLogListBase::StartFilter()
3697 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3698 RecalculateShownList(&m_arShownList);
3699 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3702 DeleteAllItems();
3703 SetItemCountEx(ShownCountWithStopped());
3704 RedrawItems(0, ShownCountWithStopped());
3705 Invalidate();
3708 void CGitLogListBase::RemoveFilter()
3710 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3712 m_arShownList.SafeRemoveAll();
3714 // reset the time filter too
3715 #if 0
3716 m_timFrom = (__time64_t(m_tFrom));
3717 m_timTo = (__time64_t(m_tTo));
3718 m_DateFrom.SetTime(&m_timFrom);
3719 m_DateTo.SetTime(&m_timTo);
3720 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3721 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3722 #endif
3724 for (DWORD i=0; i<m_logEntries.size(); ++i)
3726 if(this->m_IsOldFirst)
3727 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3728 else
3729 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3731 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3732 DeleteAllItems();
3733 SetItemCountEx(ShownCountWithStopped());
3734 RedrawItems(0, ShownCountWithStopped());
3736 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3739 void CGitLogListBase::Clear()
3741 m_arShownList.SafeRemoveAll();
3742 DeleteAllItems();
3744 m_logEntries.ClearAll();
3747 void CGitLogListBase::OnDestroy()
3749 SafeTerminateThread();
3750 SafeTerminateAsyncDiffThread();
3752 int retry = 0;
3753 while(m_LogCache.SaveCache())
3755 if(retry > 5)
3756 break;
3757 Sleep(1000);
3759 ++retry;
3761 //if(CMessageBox::Show(nullptr, _T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."), _T("TortoiseGit"),
3762 // MB_YESNO) == IDNO)
3763 // break;
3766 __super::OnDestroy();
3769 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3771 CRect rect;
3772 int i=(int)wParam;
3773 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3774 this->InvalidateRect(rect);
3776 return 0;
3780 * Save column widths to the registry
3782 void CGitLogListBase::SaveColumnWidths()
3784 // HACK that graph column is always shown
3785 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3787 __super::SaveColumnWidths();
3790 int CGitLogListBase::GetHeadIndex()
3792 if(m_HeadHash.IsEmpty())
3793 return -1;
3795 for (size_t i = 0; i < m_arShownList.size(); ++i)
3797 GitRev* pRev = m_arShownList.SafeGetAt(i);
3798 if(pRev)
3800 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3801 return (int)i;
3804 return -1;
3806 void CGitLogListBase::OnFind()
3808 if (!m_pFindDialog)
3810 m_pFindDialog = new CFindDlg(this);
3811 m_pFindDialog->Create(this);
3815 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3817 if (GetSelectedCount() != 0)
3818 return 0;
3820 CGitHash theSelectedHash = m_lastSelectedHash;
3821 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3822 m_lastSelectedHash = theSelectedHash;
3824 int countPerPage = GetCountPerPage();
3825 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3826 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3827 EnsureVisible((int)itemToSelect, FALSE);
3828 return 0;
3830 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3832 ASSERT(m_pFindDialog);
3833 bool bFound = false;
3834 int i=0;
3836 if (m_pFindDialog->IsTerminating())
3838 // invalidate the handle identifying the dialog box.
3839 m_pFindDialog = nullptr;
3840 return 0;
3843 int cnt = (int)m_arShownList.size();
3845 if(m_pFindDialog->IsRef())
3847 CString str;
3848 str=m_pFindDialog->GetFindString();
3850 CGitHash hash;
3852 if(!str.IsEmpty())
3854 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3855 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3858 if(!hash.IsEmpty())
3860 for (i = 0; i < cnt; ++i)
3862 GitRev* pLogEntry = m_arShownList.SafeGetAt(i);
3863 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3865 bFound = true;
3866 break;
3870 if (!bFound)
3872 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3873 return 0;
3877 if (m_pFindDialog->FindNext() && !bFound)
3879 //read data from dialog
3880 CString findText = m_pFindDialog->GetFindString();
3881 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3883 std::tr1::wregex pat;
3884 bool bRegex = false;
3885 if (m_pFindDialog->Regex())
3886 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3888 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3890 for (i = m_nSearchIndex + 1; ; ++i)
3892 if (i >= cnt)
3894 i = 0;
3895 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3897 if (m_nSearchIndex >= 0)
3899 if (i == m_nSearchIndex)
3901 ::MessageBeep(0xFFFFFFFF);
3902 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3903 break;
3907 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(i);
3909 CString str;
3910 str+=pLogEntry->m_CommitHash.ToString();
3911 str += _T('\n');
3913 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3915 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3916 str += _T('\n');
3919 str+=pLogEntry->GetAuthorEmail();
3920 str += _T('\n');
3921 str+=pLogEntry->GetAuthorName();
3922 str += _T('\n');
3923 str+=pLogEntry->GetBody();
3924 str += _T('\n');
3925 str+=pLogEntry->GetCommitterEmail();
3926 str += _T('\n');
3927 str+=pLogEntry->GetCommitterName();
3928 str += _T('\n');
3929 str+=pLogEntry->GetSubject();
3930 str += _T('\n');
3931 str+=pLogEntry->m_Notes;
3932 str += _T('\n');
3933 str+=GetTagInfo(pLogEntry);
3934 str += _T('\n');
3937 /*Because changed files list is loaded on demand when gui show,
3938 files will empty when files have not fetched.
3940 we can add it back by using one-way diff(with outnumber changed and rename detect.
3941 here just need changed filename list. one-way is much quicker.
3943 if(pLogEntry->m_IsFull)
3945 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
3947 str += pLogEntry->GetFiles(this)[j].GetWinPath();
3948 str += _T('\n');
3949 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
3950 str += _T('\n');
3953 else
3955 if(!pLogEntry->m_IsSimpleListReady)
3956 pLogEntry->SafeGetSimpleList(&g_Git);
3958 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
3960 str += pLogEntry->m_SimpleFileList[j];
3961 str += _T('\n');
3965 if (bRegex)
3967 if (std::regex_search(std::wstring(str), pat, flags))
3969 bFound = true;
3970 break;
3973 else
3975 if (bMatchCase)
3977 if (str.Find(findText) >= 0)
3979 bFound = true;
3980 break;
3983 else
3985 CString msg = str;
3986 msg = msg.MakeLower();
3987 CString find = findText.MakeLower();
3988 if (msg.Find(find) >= 0)
3990 bFound = TRUE;
3991 break;
3995 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3997 } // if(m_pFindDialog->FindNext())
3998 //UpdateLogInfoLabel();
4000 if (bFound)
4002 m_nSearchIndex = i;
4003 EnsureVisible(i, FALSE);
4004 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4006 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4007 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4008 SetSelectionMark(i);
4010 else
4012 GitRev* pLogEntry = m_arShownList.SafeGetAt(i);
4013 if (pLogEntry)
4014 m_highlight = pLogEntry->m_CommitHash;
4016 Invalidate();
4017 //FillLogMessageCtrl();
4018 UpdateData(FALSE);
4021 return 0;
4024 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4026 LVHITTESTINFO lvhitTestInfo;
4028 lvhitTestInfo.pt = point;
4030 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4031 int nSubItem = lvhitTestInfo.iSubItem;
4033 UINT nFlags = lvhitTestInfo.flags;
4035 // nFlags is 0 if the SubItemHitTest fails
4036 // Therefore, 0 & <anything> will equal false
4037 if (nFlags & LVHT_ONITEM)
4039 // Get the client area occupied by this control
4040 RECT rcClient;
4041 GetClientRect(&rcClient);
4043 // Fill in the TOOLINFO structure
4044 pTI->hwnd = m_hWnd;
4045 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4046 pTI->lpszText = LPSTR_TEXTCALLBACK;
4047 pTI->rect = rcClient;
4049 return pTI->uId; // By returning a unique value per listItem,
4050 // we ensure that when the mouse moves over another list item,
4051 // the tooltip will change
4053 else
4055 // Otherwise, we aren't interested, so let the message propagate
4056 return -1;
4060 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4062 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4063 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4065 *pResult = 0;
4067 // Ignore messages from the built in tooltip, we are processing them internally
4068 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4069 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4070 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4071 return FALSE;
4073 // Get the mouse position
4074 const MSG* pMessage = GetCurrentMessage();
4076 CPoint pt;
4077 pt = pMessage->pt;
4078 ScreenToClient(&pt);
4080 // Check if the point falls onto a list item
4081 LVHITTESTINFO lvhitTestInfo;
4082 lvhitTestInfo.pt = pt;
4084 int nItem = SubItemHitTest(&lvhitTestInfo);
4086 if (lvhitTestInfo.flags & LVHT_ONITEM)
4088 // Get branch description first
4089 CString strTipText;
4090 if (lvhitTestInfo.iSubItem == LOGLIST_MESSAGE)
4092 CString branch;
4093 CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH;
4094 if (IsMouseOnRefLabel(m_arShownList.SafeGetAt(nItem), lvhitTestInfo.pt, type, &branch))
4096 MAP_STRING_STRING descriptions;
4097 g_Git.GetBranchDescriptions(descriptions);
4098 if (descriptions.find(branch) != descriptions.cend())
4100 strTipText.LoadString(IDS_DESCRIPTION);
4101 strTipText += L":\n";
4102 strTipText += descriptions[branch];
4107 bool followMousePos = false;
4108 if (!strTipText.IsEmpty())
4109 followMousePos = true;
4110 else
4111 strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4112 if (strTipText.IsEmpty())
4113 return FALSE;
4115 // we want multiline tooltips
4116 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4118 wcscpy_s(m_wszTip, strTipText);
4119 // handle Unicode as well as non-Unicode requests
4120 if (pNMHDR->code == TTN_NEEDTEXTA)
4122 pTTTA->hinst = nullptr;
4123 pTTTA->lpszText = m_szTip;
4124 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, nullptr, nullptr);
4126 else
4128 pTTTW->hinst = nullptr;
4129 pTTTW->lpszText = m_wszTip;
4132 CRect rect;
4133 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4134 if (followMousePos)
4135 rect.MoveToXY(pt.x, pt.y + 18); // 18: to act like a normal tooltip
4136 ClientToScreen(rect);
4137 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4139 return TRUE; // We found a tool tip,
4140 // tell the framework this message has been handled
4143 return FALSE; // We didn't handle the message,
4144 // let the framework continue propagating the message
4147 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4149 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4151 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4152 if (pLogEntry == nullptr)
4153 return CString();
4154 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4155 return CString();
4156 return pLogEntry->GetSubject();
4158 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4160 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4161 if (pLogEntry == nullptr)
4162 return CString();
4163 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4165 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4167 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4168 if (pLogEntry == nullptr)
4169 return CString();
4170 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4172 else if (nSubItem == LOGLIST_ACTION)
4174 GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem);
4175 if (pLogEntry == nullptr)
4176 return CString();
4178 if (!pLogEntry->m_IsDiffFiles)
4179 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4181 int actions = pLogEntry->GetAction(this);
4182 CString sToolTipText;
4184 CString actionText;
4185 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4186 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4188 if (actions & CTGitPath::LOGACTIONS_ADDED)
4190 if (!actionText.IsEmpty())
4191 actionText += L"\r\n";
4192 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4195 if (actions & CTGitPath::LOGACTIONS_DELETED)
4197 if (!actionText.IsEmpty())
4198 actionText += L"\r\n";
4199 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4202 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4204 if (!actionText.IsEmpty())
4205 actionText += L"\r\n";
4206 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4209 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4211 if (!actionText.IsEmpty())
4212 actionText += L"\r\n";
4213 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4216 if (!actionText.IsEmpty())
4218 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4219 sToolTipText = sTitle + L":\r\n" + actionText;
4221 return sToolTipText;
4223 return CString();
4226 bool CGitLogListBase::IsMouseOnRefLabelFromPopupMenu(const GitRevLoglist* pLogEntry, const CPoint& point, CGit::REF_TYPE& type, CString* pShortname /*nullptr*/, size_t* pIndex /*nullptr*/)
4228 POINT pt = point;
4229 ScreenToClient(&pt);
4230 return IsMouseOnRefLabel(pLogEntry, pt, type, pShortname, pIndex);
4233 bool CGitLogListBase::IsMouseOnRefLabel(const GitRevLoglist* pLogEntry, const POINT& pt, CGit::REF_TYPE& type, CString* pShortname /*nullptr*/, size_t* pIndex /*nullptr*/)
4235 if (!pLogEntry)
4236 return false;
4238 for (size_t i = 0; i < m_HashMap[pLogEntry->m_CommitHash].size(); ++i)
4240 const auto labelpos = m_RefLabelPosMap.find(m_HashMap[pLogEntry->m_CommitHash][i]);
4241 if (labelpos == m_RefLabelPosMap.cend() || !labelpos->second.PtInRect(pt))
4242 continue;
4244 CGit::REF_TYPE foundType;
4245 if (pShortname)
4246 *pShortname = CGit::GetShortName(m_HashMap[pLogEntry->m_CommitHash][i], &foundType);
4247 else
4248 CGit::GetShortName(m_HashMap[pLogEntry->m_CommitHash][i], &foundType);
4249 if (foundType != type && type != CGit::REF_TYPE::UNKNOWN)
4250 return false;
4252 type = foundType;
4253 if (pIndex)
4254 *pIndex = i;
4255 return true;
4257 return false;