Drop REFLABEL annotatedTag member and add a new member for reference type
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobfe34ae4c89d7840f73f108429454f8b72edc3a84
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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"
38 #include "SysInfo.h"
40 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
41 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
42 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
44 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
46 CGitLogListBase::CGitLogListBase():CHintListCtrl()
47 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
48 ,m_nSearchIndex(0)
49 ,m_bNoDispUpdates(FALSE)
50 , m_bThreadRunning(FALSE)
51 , m_bStrictStopped(false)
52 , m_SelectedFilters(LOGFILTER_ALL)
53 , m_ShowFilter(FILTERSHOW_ALL)
54 , m_bShowWC(false)
55 , m_logEntries(&m_LogCache)
56 , m_pFindDialog(NULL)
57 , m_ColumnManager(this)
58 , m_dwDefaultColumns(0)
59 , m_arShownList(&m_critSec)
60 , m_hasWC(true)
61 , m_bNoHightlightHead(FALSE)
62 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
63 , m_bFullCommitMessageOnLogLine(false)
65 // use the default GUI font, create a copy of it and
66 // change the copy to BOLD (leave the rest of the font
67 // the same)
68 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
69 LOGFONT lf = {0};
70 GetObject(hFont, sizeof(LOGFONT), &lf);
71 lf.lfWeight = FW_BOLD;
72 m_boldFont = CreateFontIndirect(&lf);
73 lf.lfWeight = FW_DONTCARE;
74 lf.lfItalic = TRUE;
75 m_FontItalics = CreateFontIndirect(&lf);
76 lf.lfWeight = FW_BOLD;
77 m_boldItalicsFont = CreateFontIndirect(&lf);
79 m_bShowBugtraqColumn=false;
81 m_IsIDReplaceAction=FALSE;
83 this->m_critSec.Init();
84 ResetWcRev(false);
86 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
87 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
88 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
89 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
90 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
91 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
93 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
94 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
96 m_Filter.m_NumberOfLogsScale = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT);
97 if (m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE)
99 CString key;
100 key.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR)g_Git.m_CurrentDir);
101 key.Replace(_T(':'), _T('_'));
102 CString lastSelFromDate = CRegString(key);
103 if (lastSelFromDate.GetLength() == 10)
105 CTime time = CTime(_wtoi((LPCTSTR)lastSelFromDate.Mid(0, 4)), _wtoi((LPCTSTR)lastSelFromDate.Mid(5, 2)), _wtoi((LPCTSTR)lastSelFromDate.Mid(8, 2)), 0, 0, 0);
106 m_Filter.m_From = (DWORD)time.GetTime();
109 m_Filter.m_NumberOfLogs = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
111 m_ShowMask = 0;
112 m_LoadingThread = NULL;
114 InterlockedExchange(&m_bExitThread,FALSE);
115 m_IsOldFirst = FALSE;
116 m_IsRebaseReplaceGraph = FALSE;
118 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
120 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
122 // get short/long datetime setting from registry
123 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
124 if ( RegUseShortDateFormat )
126 m_DateFormat = DATE_SHORTDATE;
128 else
130 m_DateFormat = DATE_LONGDATE;
132 // get relative time display setting from registry
133 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
134 m_bRelativeTimes = (regRelativeTimes != 0);
135 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
137 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
141 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
142 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
143 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
145 m_ColumnRegKey=_T("log");
147 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
148 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
149 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
150 m_bFullCommitMessageOnLogLine = !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE);
152 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
153 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
155 m_AsyncThreadExit = FALSE;
156 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
157 m_AsynDiffListLock.Init();
159 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
160 if (hUxTheme)
161 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
163 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL, 0, CREATE_SUSPENDED);
164 if (m_DiffingThread ==NULL)
166 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
167 return;
169 m_DiffingThread->m_bAutoDelete = FALSE;
170 m_DiffingThread->ResumeThread();
173 int CGitLogListBase::AsyncDiffThread()
175 m_AsyncThreadExited = false;
176 while(!m_AsyncThreadExit)
178 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
180 GitRevLoglist* pRev = nullptr;
181 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
183 m_AsynDiffListLock.Lock();
184 pRev = m_AsynDiffList.back();
185 m_AsynDiffList.pop_back();
186 m_AsynDiffListLock.Unlock();
188 if( pRev->m_CommitHash.IsEmpty() )
190 if(pRev->m_IsDiffFiles)
191 continue;
193 CTGitPathList& files = pRev->GetFiles(this);
194 files.Clear();
195 pRev->m_ParentHash.clear();
196 pRev->m_ParentHash.push_back(m_HeadHash);
197 g_Git.GetWorkingTreeChanges(files);
198 int& action = pRev->GetAction(this);
199 action = 0;
200 for (int j = 0; j < files.GetCount(); ++j)
201 action |= files[j].m_Action;
203 CString err;
204 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
206 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
207 return -1;
210 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
211 InterlockedExchange(&pRev->m_IsFull, TRUE);
213 pRev->GetBody().Format(IDS_FILESCHANGES, files.GetCount());
214 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
215 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
218 if (!pRev->CheckAndDiff())
219 { // fetch change file list
220 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
222 if(i < m_arShownList.GetCount())
224 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
225 if(data->m_CommitHash == pRev->m_CommitHash)
227 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
228 break;
233 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
235 POSITION pos = GetFirstSelectedItemPosition();
236 int nItem = GetNextSelectedItem(pos);
238 if(nItem>=0)
240 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
241 if(data)
242 if(data->m_CommitHash == pRev->m_CommitHash)
244 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
251 m_AsyncThreadExited = true;
252 return 0;
254 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
256 if (exclusivelyShow)
258 m_ContextMenuMask &= hideMask;
260 else
262 m_ContextMenuMask &= ~hideMask;
266 CGitLogListBase::~CGitLogListBase()
268 InterlockedExchange(&m_bNoDispUpdates, TRUE);
269 this->m_arShownList.SafeRemoveAll();
271 DestroyIcon(m_hModifiedIcon);
272 DestroyIcon(m_hReplacedIcon);
273 DestroyIcon(m_hConflictedIcon);
274 DestroyIcon(m_hAddedIcon);
275 DestroyIcon(m_hDeletedIcon);
276 m_logEntries.ClearAll();
278 if (m_boldFont)
279 DeleteObject(m_boldFont);
281 if (m_FontItalics)
282 DeleteObject(m_FontItalics);
284 if (m_boldItalicsFont)
285 DeleteObject(m_boldItalicsFont);
287 SafeTerminateThread();
288 SafeTerminateAsyncDiffThread();
290 if(m_AsyncDiffEvent)
291 CloseHandle(m_AsyncDiffEvent);
293 if (hUxTheme)
294 FreeLibrary(hUxTheme);
298 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
299 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
300 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
301 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
302 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
303 ON_WM_CONTEXTMENU()
304 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
305 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
306 ON_WM_CREATE()
307 ON_WM_DESTROY()
308 ON_MESSAGE(MSG_LOADED,OnLoad)
309 ON_WM_MEASUREITEM()
310 ON_WM_MEASUREITEM_REFLECT()
311 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
312 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
313 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
314 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
315 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
316 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
317 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
318 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
319 END_MESSAGE_MAP()
321 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
323 //if (m_nRowHeight>0)
325 lpMeasureItemStruct->itemHeight = 50;
329 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
331 PreSubclassWindow();
332 return CHintListCtrl::OnCreate(lpCreateStruct);
335 void CGitLogListBase::PreSubclassWindow()
337 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
338 // load the icons for the action columns
339 // m_Theme.Open(m_hWnd, L"ListView");
340 SetWindowTheme(m_hWnd, L"Explorer", NULL);
341 CHintListCtrl::PreSubclassWindow();
344 CString CGitLogListBase::GetRebaseActionName(int action)
346 if (action & LOGACTIONS_REBASE_EDIT)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
348 if (action & LOGACTIONS_REBASE_SQUASH)
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
350 if (action & LOGACTIONS_REBASE_PICK)
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
352 if (action & LOGACTIONS_REBASE_SKIP)
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
355 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
358 void CGitLogListBase::InsertGitColumn()
360 CString temp;
362 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
363 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
364 if (DWORD(regFullRowSelect))
365 exStyle |= LVS_EX_FULLROWSELECT;
366 SetExtendedStyle(exStyle);
368 // only load properties if we have a repository
369 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
370 UpdateProjectProperties();
372 static UINT normal[] =
374 IDS_LOG_GRAPH,
375 IDS_LOG_REBASE,
376 IDS_LOG_ID,
377 IDS_LOG_HASH,
378 IDS_LOG_ACTIONS,
379 IDS_LOG_MESSAGE,
380 IDS_LOG_AUTHOR,
381 IDS_LOG_DATE,
382 IDS_LOG_EMAIL,
383 IDS_LOG_COMMIT_NAME,
384 IDS_LOG_COMMIT_EMAIL,
385 IDS_LOG_COMMIT_DATE,
386 IDS_LOG_BUGIDS,
387 IDS_LOG_SVNREV,
390 static int with[] =
392 ICONITEMBORDER+16*4,
393 ICONITEMBORDER+16*4,
394 ICONITEMBORDER+16*4,
395 ICONITEMBORDER+16*4,
396 ICONITEMBORDER+16*4,
397 LOGLIST_MESSAGE_MIN,
398 ICONITEMBORDER+16*4,
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 ICONITEMBORDER+16*4,
402 ICONITEMBORDER+16*4,
403 ICONITEMBORDER+16*4,
404 ICONITEMBORDER+16*4,
405 ICONITEMBORDER+16*4,
407 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
409 DWORD hideColumns = 0;
410 if(this->m_IsRebaseReplaceGraph)
412 hideColumns |= GIT_LOG_GRAPH;
413 m_dwDefaultColumns |= GIT_LOG_REBASE;
415 else
417 hideColumns |= GIT_LOG_REBASE;
420 if(this->m_IsIDReplaceAction)
422 hideColumns |= GIT_LOG_ACTIONS;
423 m_dwDefaultColumns |= GIT_LOG_ID;
424 m_dwDefaultColumns |= GIT_LOG_HASH;
426 else
428 hideColumns |= GIT_LOG_ID;
430 if(this->m_bShowBugtraqColumn)
432 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
434 else
436 hideColumns |= GIT_LOGLIST_BUG;
438 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
439 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
440 else
441 hideColumns |= GIT_LOGLIST_SVNREV;
442 SetRedraw(false);
444 m_ColumnManager.SetNames(normal, _countof(normal));
445 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
447 SetRedraw(true);
451 * Resizes all columns in a list control to values in registry.
453 void CGitLogListBase::ResizeAllListCtrlCols()
455 // column max and min widths to allow
456 static const int nMinimumWidth = 10;
457 static const int nMaximumWidth = 1000;
458 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
459 if (pHdrCtrl)
461 int numcols = pHdrCtrl->GetItemCount();
462 for (int col = 0; col < numcols; ++col)
464 // get width for this col last time from registry
465 CString regentry;
466 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR)m_ColumnRegKey, col);
467 CRegDWORD regwidth(regentry, 0);
468 int cx = regwidth;
469 if ( cx == 0 )
471 // no saved value, setup sensible defaults
472 if (col == this->LOGLIST_MESSAGE)
474 cx = LOGLIST_MESSAGE_MIN;
476 else
478 cx = ICONITEMBORDER+16*4;
481 if (cx < nMinimumWidth)
483 cx = nMinimumWidth;
485 else if (cx > nMaximumWidth)
487 cx = nMaximumWidth;
490 SetColumnWidth(col, cx);
497 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
499 LVITEM rItem = { 0 };
500 rItem.mask = LVIF_STATE;
501 rItem.iItem = (int)Index;
502 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
503 GetItem(&rItem);
505 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index);
506 HBRUSH brush = NULL;
508 if (!(rItem.state & LVIS_SELECTED))
510 int action = pLogEntry->GetRebaseAction();
511 if (action & LOGACTIONS_REBASE_SQUASH)
512 brush = ::CreateSolidBrush(RGB(156,156,156));
513 else if (action & LOGACTIONS_REBASE_EDIT)
514 brush = ::CreateSolidBrush(RGB(200,200,128));
516 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
518 if (rItem.state & LVIS_SELECTED)
520 if (::GetFocus() == m_hWnd)
521 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
522 else
523 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
526 if (brush != NULL)
528 ::FillRect(hdc, &rect, brush);
529 ::DeleteObject(brush);
533 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
535 POINT point = { 4, 4 };
536 CRect rt2 = rect;
537 rt2.DeflateRect(1, 1);
538 rt2.OffsetRect(2, 2);
540 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
541 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
542 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
543 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
544 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
546 ::SelectObject(hdc, brush);
547 rt2.OffsetRect(-2, -2);
548 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
549 ::SelectObject(hdc, oldbrush);
550 ::SelectObject(hdc, oldpen);
551 ::DeleteObject(nullPen);
552 ::DeleteObject(darkBrush);
555 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
557 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
558 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
559 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
560 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
561 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
562 ::LineTo(hdc, rect.left, rect.bottom);
563 ::SelectObject(hdc, oldpen);
564 ::DeleteObject(pen);
567 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
569 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
570 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
571 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
572 ::LineTo(hdc, rect.left, rect.bottom);
573 ::LineTo(hdc, rect.right, rect.bottom);
574 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
575 ::SelectObject(hdc, oldpen);
576 ::DeleteObject(pen);
579 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
581 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
582 CRect rt=rect;
583 LVITEM rItem = { 0 };
584 rItem.mask = LVIF_STATE;
585 rItem.iItem = (int)index;
586 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
587 GetItem(&rItem);
589 CDC W_Dc;
590 W_Dc.Attach(hdc);
592 HTHEME hTheme = NULL;
593 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
594 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
596 SIZE oneSpaceSize;
597 if (m_bTagsBranchesOnRightSide)
599 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
600 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
601 SelectObject(hdc, oldFont);
602 rt.left += oneSpaceSize.cx * 2;
604 else
606 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
607 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
608 rt.left += oneSpaceSize.cx;
611 CString msg = MessageDisplayStr(data);
612 int action = data->GetRebaseAction();
613 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
614 if (IsAppThemed() && pfnDrawThemeTextEx)
616 int txtState = LISS_NORMAL;
617 if (rItem.state & LVIS_SELECTED)
618 txtState = LISS_SELECTED;
620 DTTOPTS opts = { 0 };
621 opts.dwSize = sizeof(opts);
622 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
623 opts.dwFlags = DTT_TEXTCOLOR;
624 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, msg, -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
626 else
628 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
630 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
631 ::DrawText(hdc,msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
632 ::SetTextColor(hdc, clrOld);
634 else
636 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
637 ::DrawText(hdc, msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
638 ::SetTextColor(hdc, clrOld);
642 if (m_bTagsBranchesOnRightSide)
644 SIZE size;
645 GetTextExtentPoint32(hdc, msg, msg.GetLength(), &size);
647 rt.left += oneSpaceSize.cx + size.cx;
649 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
652 if (hTheme)
653 CloseThemeData(hTheme);
655 W_Dc.Detach();
658 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
660 for (unsigned int i = 0; i < refList.size(); ++i)
662 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
663 HBRUSH brush = 0;
664 COLORREF colRef = refList[i].color;
665 bool singleRemote = refList[i].singleRemote;
666 bool hasTracking = refList[i].hasTracking;
667 bool sameName = refList[i].sameName;
668 CGit::REF_TYPE refType = refList[i].refType;
670 //When row selected, ajust label color
671 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
673 if (rItem.state & LVIS_SELECTED)
674 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
677 brush = ::CreateSolidBrush(colRef);
679 if (!shortname.IsEmpty() && (rt.left < rect.right))
681 SIZE size;
682 memset(&size,0,sizeof(SIZE));
683 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
685 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
686 rt.right += 8;
688 int textpos = DT_CENTER;
690 if (rt.right > rect.right)
692 rt.right = rect.right;
693 textpos = 0;
696 CRect textRect = rt;
698 if (singleRemote)
700 rt.right += 8;
701 textRect.OffsetRect(8, 0);
704 if (sameName)
705 rt.right += 8;
707 if (hasTracking)
709 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
711 else
713 //Fill interior of ref label
714 ::FillRect(hdc, &rt, brush);
717 //Draw edge of label
718 CRect rectEdge = rt;
720 if (!hasTracking)
722 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
723 rectEdge.DeflateRect(1, 1);
724 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
727 if (refType == CGit::REF_TYPE::ANNOTATED_TAG)
729 rt.right += 8;
730 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
731 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
732 ::FillRgn(hdc, hrgn, brush);
733 ::DeleteObject(hrgn);
734 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
735 HPEN pen;
736 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
737 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
738 ::DeleteObject(pen);
739 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
740 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
741 ::DeleteObject(pen);
742 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
743 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
744 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
745 ::DeleteObject(pen);
746 SelectObject(hdc, oldpen);
749 //Draw text inside label
750 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
751 if (!customColor && IsAppThemed() && pfnDrawThemeTextEx)
753 int txtState = LISS_NORMAL;
754 if (rItem.state & LVIS_SELECTED)
755 txtState = LISS_SELECTED;
757 DTTOPTS opts = { 0 };
758 opts.dwSize = sizeof(opts);
759 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
760 opts.dwFlags = DTT_TEXTCOLOR;
761 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
763 else
765 W_Dc.SetBkMode(TRANSPARENT);
766 if (customColor || (rItem.state & LVIS_SELECTED))
768 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
769 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
770 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
771 ::SetTextColor(hdc,clrOld);
773 else
775 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
776 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
777 ::SetTextColor(hdc, clrOld);
781 if (singleRemote)
783 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
784 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
785 CRect newRect;
786 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
787 DrawLightning(hdc, newRect, color, bold);
790 if (sameName)
792 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
793 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
794 CRect newRect;
795 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
796 DrawUpTriangle(hdc, newRect, color, bold);
799 rt.left = rt.right + 1;
801 if (brush)
802 ::DeleteObject(brush);
804 rt.right = rect.right;
807 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
809 // Returns ((256 - amount)*col1 + amount*col2) / 256;
810 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
811 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
812 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
815 Gdiplus::Color GetGdiColor(COLORREF col)
817 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
819 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
820 const COLORREF& col,const COLORREF& activeColor, int top
823 int h = laneHeight / 2;
824 int m = (x1 + x2) / 2;
825 int r = (x2 - x1) * m_NodeSize / 30;
826 int d = 2 * r;
828 #define P_CENTER m , h+top
829 #define P_0 x2, h+top
830 #define P_90 m , 0+top-1
831 #define P_180 x1, h+top
832 #define P_270 m , 2 * h+top +1
833 #define R_CENTER m - r, h - r+top, d, d
836 #define DELTA_UR_B 2*(x1 - m), 2*h +top
837 #define DELTA_UR_E 0*16, 90*16 +top // -,
839 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
840 #define DELTA_DR_E 270*16, 90*16 +top // -'
842 #define DELTA_UL_B 2*(x2 - m), 2*h +top
843 #define DELTA_UL_E 90*16, 90*16 +top // ,-
845 #define DELTA_DL_B 2*(x2 - m),2*-h +top
846 #define DELTA_DL_E 180*16, 90*16 // '-
848 #define CENTER_UR x1, 2*h, 225
849 #define CENTER_DR x1, 0 , 135
850 #define CENTER_UL x2, 2*h, 315
851 #define CENTER_DL x2, 0 , 45
854 Gdiplus::Graphics graphics( hdc );
856 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
858 // arc
859 switch (type) {
860 case Lanes::JOIN:
861 case Lanes::JOIN_R:
862 case Lanes::HEAD:
863 case Lanes::HEAD_R:
865 Gdiplus::LinearGradientBrush gradient(
866 Gdiplus::Point(x1-2, h+top-2),
867 Gdiplus::Point(P_270),
868 GetGdiColor(activeColor),GetGdiColor(col));
871 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
872 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
874 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
875 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
876 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
878 break;
880 case Lanes::JOIN_L:
883 Gdiplus::LinearGradientBrush gradient(
884 Gdiplus::Point(P_270),
885 Gdiplus::Point(x2+1, h+top-1),
886 GetGdiColor(col),GetGdiColor(activeColor));
889 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
890 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
892 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
893 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
894 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
897 break;
899 case Lanes::TAIL:
900 case Lanes::TAIL_R:
903 Gdiplus::LinearGradientBrush gradient(
904 Gdiplus::Point(x1-2, h+top-2),
905 Gdiplus::Point(P_90),
906 GetGdiColor(activeColor),GetGdiColor(col));
908 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
910 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
912 #if 0
913 QConicalGradient gradient(CENTER_DR);
914 gradient.setColorAt(0.375, activeCol);
915 gradient.setColorAt(0.625, col);
916 myPen.setBrush(gradient);
917 p->setPen(myPen);
918 p->drawArc(P_CENTER, DELTA_DR);
919 #endif
920 break;
922 default:
923 break;
927 //static QPen myPen(Qt::black, 2); // fast path here
928 CPen pen;
929 pen.CreatePen(PS_SOLID,2,col);
930 //myPen.setColor(col);
931 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
933 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
935 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
937 //p->setPen(myPen);
939 // vertical line
940 switch (type) {
941 case Lanes::ACTIVE:
942 case Lanes::NOT_ACTIVE:
943 case Lanes::MERGE_FORK:
944 case Lanes::MERGE_FORK_R:
945 case Lanes::MERGE_FORK_L:
946 case Lanes::JOIN:
947 case Lanes::JOIN_R:
948 case Lanes::JOIN_L:
949 case Lanes::CROSS:
950 //DrawLine(hdc,P_90,P_270);
951 graphics.DrawLine(&myPen,P_90,P_270);
952 //p->drawLine(P_90, P_270);
953 break;
954 case Lanes::HEAD_L:
955 case Lanes::BRANCH:
956 //DrawLine(hdc,P_CENTER,P_270);
957 graphics.DrawLine(&myPen,P_CENTER,P_270);
958 //p->drawLine(P_CENTER, P_270);
959 break;
960 case Lanes::TAIL_L:
961 case Lanes::INITIAL:
962 case Lanes::BOUNDARY:
963 case Lanes::BOUNDARY_C:
964 case Lanes::BOUNDARY_R:
965 case Lanes::BOUNDARY_L:
966 //DrawLine(hdc,P_90, P_CENTER);
967 graphics.DrawLine(&myPen,P_90,P_CENTER);
968 //p->drawLine(P_90, P_CENTER);
969 break;
970 default:
971 break;
974 myPen.SetColor(GetGdiColor(activeColor));
976 // horizontal line
977 switch (type) {
978 case Lanes::MERGE_FORK:
979 case Lanes::JOIN:
980 case Lanes::HEAD:
981 case Lanes::TAIL:
982 case Lanes::CROSS:
983 case Lanes::CROSS_EMPTY:
984 case Lanes::BOUNDARY_C:
985 //DrawLine(hdc,P_180,P_0);
986 graphics.DrawLine(&myPen,P_180,P_0);
987 //p->drawLine(P_180, P_0);
988 break;
989 case Lanes::MERGE_FORK_R:
990 case Lanes::BOUNDARY_R:
991 //DrawLine(hdc,P_180,P_CENTER);
992 graphics.DrawLine(&myPen,P_180,P_CENTER);
993 //p->drawLine(P_180, P_CENTER);
994 break;
995 case Lanes::MERGE_FORK_L:
996 case Lanes::HEAD_L:
997 case Lanes::TAIL_L:
998 case Lanes::BOUNDARY_L:
999 //DrawLine(hdc,P_CENTER,P_0);
1000 graphics.DrawLine(&myPen,P_CENTER,P_0);
1001 //p->drawLine(P_CENTER, P_0);
1002 break;
1003 default:
1004 break;
1007 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1009 CBrush brush;
1010 brush.CreateSolidBrush(col);
1011 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1013 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1014 // center symbol, e.g. rect or ellipse
1015 switch (type) {
1016 case Lanes::ACTIVE:
1017 case Lanes::INITIAL:
1018 case Lanes::BRANCH:
1020 //p->setPen(Qt::NoPen);
1021 //p->setBrush(col);
1022 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1023 graphics.FillEllipse(&myBrush, R_CENTER);
1024 //p->drawEllipse(R_CENTER);
1025 break;
1026 case Lanes::MERGE_FORK:
1027 case Lanes::MERGE_FORK_R:
1028 case Lanes::MERGE_FORK_L:
1029 //p->setPen(Qt::NoPen);
1030 //p->setBrush(col);
1031 //p->drawRect(R_CENTER);
1032 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1033 graphics.FillRectangle(&myBrush, R_CENTER);
1034 break;
1035 case Lanes::UNAPPLIED:
1036 // Red minus sign
1037 //p->setPen(Qt::NoPen);
1038 //p->setBrush(Qt::red);
1039 //p->drawRect(m - r, h - 1, d, 2);
1040 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1041 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1042 break;
1043 case Lanes::APPLIED:
1044 // Green plus sign
1045 //p->setPen(Qt::NoPen);
1046 //p->setBrush(DARK_GREEN);
1047 //p->drawRect(m - r, h - 1, d, 2);
1048 //p->drawRect(m - 1, h - r, 2, d);
1049 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1050 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1051 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1052 break;
1053 case Lanes::BOUNDARY:
1054 //p->setBrush(back);
1055 //p->drawEllipse(R_CENTER);
1056 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1057 graphics.DrawEllipse(&myPen, R_CENTER);
1058 break;
1059 case Lanes::BOUNDARY_C:
1060 case Lanes::BOUNDARY_R:
1061 case Lanes::BOUNDARY_L:
1062 //p->setBrush(back);
1063 //p->drawRect(R_CENTER);
1064 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1065 graphics.FillRectangle(&myBrush,R_CENTER);
1066 break;
1067 default:
1068 break;
1071 ::SelectObject(hdc,oldpen);
1072 ::SelectObject(hdc,oldbrush);
1073 #undef P_CENTER
1074 #undef P_0
1075 #undef P_90
1076 #undef P_180
1077 #undef P_270
1078 #undef R_CENTER
1081 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1083 // TODO: unfinished
1084 // return;
1085 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
1086 if(data->m_CommitHash.IsEmpty())
1087 return;
1089 CRect rt=rect;
1090 LVITEM rItem = { 0 };
1091 rItem.mask = LVIF_STATE;
1092 rItem.iItem = (int)index;
1093 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1094 GetItem(&rItem);
1096 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1098 if (data->m_Lanes.empty())
1099 m_logEntries.setLane(data->m_CommitHash);
1101 std::vector<int>& lanes=data->m_Lanes;
1102 size_t laneNum = lanes.size();
1103 UINT activeLane = 0;
1104 for (UINT i = 0; i < laneNum; ++i)
1105 if (Lanes::isMerge(lanes[i])) {
1106 activeLane = i;
1107 break;
1110 int x2 = 0;
1111 int maxWidth = rect.Width();
1112 int lw = 3 * rect.Height() / 4; //laneWidth()
1114 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1115 //if (opt.state & QStyle::State_Selected)
1116 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1118 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1121 int x1 = x2;
1122 x2 += lw;
1124 int ln = lanes[i];
1125 if (ln == Lanes::EMPTY)
1126 continue;
1128 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1129 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1132 #if 0
1133 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1135 int x1 = x2;
1136 x2 += lw;
1138 int ln = lanes[i];
1139 if (ln == Lanes::EMPTY)
1140 continue;
1142 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1143 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1145 if (ln == Lanes::CROSS)
1147 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1148 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1150 else
1151 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1153 #endif
1157 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1160 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1161 // Take the default processing unless we set this to something else below.
1162 *pResult = CDRF_DODEFAULT;
1164 if (m_bNoDispUpdates)
1165 return;
1167 switch (pLVCD->nmcd.dwDrawStage)
1169 case CDDS_PREPAINT:
1171 *pResult = CDRF_NOTIFYITEMDRAW;
1172 return;
1174 break;
1175 case CDDS_ITEMPREPAINT:
1177 // This is the prepaint stage for an item. Here's where we set the
1178 // item's text color.
1180 // Tell Windows to send draw notifications for each subitem.
1181 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1183 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1185 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1187 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1188 if (data)
1190 HGDIOBJ hGdiObj = nullptr;
1191 int action = data->GetRebaseAction();
1192 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1193 crText = RGB(128,128,128);
1195 if (action & LOGACTIONS_REBASE_SQUASH)
1196 pLVCD->clrTextBk = RGB(156,156,156);
1197 else if (action & LOGACTIONS_REBASE_EDIT)
1198 pLVCD->clrTextBk = RGB(200,200,128);
1199 else
1200 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1202 if (action & LOGACTIONS_REBASE_CURRENT)
1203 hGdiObj = m_boldFont;
1205 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1206 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1207 if (isHeadHash && isHighlight)
1208 hGdiObj = m_boldItalicsFont;
1209 else if (isHeadHash)
1210 hGdiObj = m_boldFont;
1211 else if (isHighlight)
1212 hGdiObj = m_FontItalics;
1214 if (hGdiObj)
1216 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1217 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1220 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1221 // crText = GetSysColor(COLOR_GRAYTEXT);
1223 if (data->m_CommitHash.IsEmpty())
1225 //crText = GetSysColor(RGB(200,200,0));
1226 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1227 // We changed the font, so we're returning CDRF_NEWFONT. This
1228 // tells the control to recalculate the extent of the text.
1229 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1233 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1235 if (m_bStrictStopped)
1236 crText = GetSysColor(COLOR_GRAYTEXT);
1238 // Store the color back in the NMLVCUSTOMDRAW struct.
1239 pLVCD->clrText = crText;
1240 return;
1242 break;
1243 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1245 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1247 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1250 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1252 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1254 CRect rect;
1255 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1257 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1258 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1260 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1261 if( !data ->m_CommitHash.IsEmpty())
1262 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1264 *pResult = CDRF_SKIPDEFAULT;
1265 return;
1269 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1271 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1273 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1275 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1277 CRect rect;
1278 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1280 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1281 // not in FillBackGround method, because this only affected the message subitem
1282 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1283 return;
1285 int index = (int)pLVCD->nmcd.dwItemSpec;
1286 int state = GetItemState(index, LVIS_SELECTED);
1287 int txtState = LISS_NORMAL;
1288 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1290 if (state & LVIS_SELECTED)
1291 txtState = LISS_HOTSELECTED;
1292 else
1293 txtState = LISS_HOT;
1295 else if (state & LVIS_SELECTED)
1297 if (::GetFocus() == m_hWnd)
1298 txtState = LISS_SELECTED;
1299 else
1300 txtState = LISS_SELECTEDNOTFOCUS;
1303 HTHEME hTheme = nullptr;
1304 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1305 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1307 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1308 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1309 else
1311 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1312 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1313 ::DeleteObject(brush);
1315 if (hTheme)
1317 CRect rt;
1318 // get rect of whole line
1319 GetItemRect(index, rt, LVIR_BOUNDS);
1320 CRect rect2 = rect;
1321 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1322 rect2.DeflateRect(1, 1, 1, 1);
1324 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1325 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1327 CloseThemeData(hTheme);
1329 // END: extended redraw
1331 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1333 std::vector<REFLABEL> refsToShow;
1334 STRING_VECTOR remoteTrackingList;
1335 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1336 for (unsigned int i = 0; i < refList.size(); ++i)
1338 CString str = refList[i];
1340 REFLABEL refLabel;
1341 refLabel.color = RGB(255, 255, 255);
1342 refLabel.singleRemote = false;
1343 refLabel.hasTracking = false;
1344 refLabel.sameName = false;
1345 refLabel.name = CGit::GetShortName(str, &refLabel.refType);
1347 switch (refLabel.refType)
1349 case CGit::REF_TYPE::LOCAL_BRANCH:
1351 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1352 continue;
1353 if (refLabel.name == m_CurrentBranch)
1354 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1355 else
1356 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1358 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1359 CString pullRemote = trackingEntry.first;
1360 CString pullBranch = trackingEntry.second;
1361 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1363 CString defaultUpstream;
1364 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1365 refLabel.hasTracking = true;
1366 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1368 bool found = false;
1369 for (size_t j = i + 1; j < refList.size(); ++j)
1371 if (refList[j] == defaultUpstream)
1373 found = true;
1374 break;
1378 if (found)
1380 bool sameName = pullBranch == refLabel.name;
1381 refsToShow.push_back(refLabel);
1382 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1383 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1384 if (m_bSymbolizeRefNames)
1386 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1388 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1389 refLabel.singleRemote = true;
1391 else if (sameName)
1392 refLabel.simplifiedName = pullRemote + _T("/");
1393 refLabel.sameName = sameName;
1395 refsToShow.push_back(refLabel);
1396 remoteTrackingList.push_back(defaultUpstream);
1397 continue;
1401 break;
1403 case CGit::REF_TYPE::REMOTE_BRANCH:
1405 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1406 continue;
1407 bool found = false;
1408 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1410 if (remoteTrackingList[j] == str)
1412 found = true;
1413 break;
1416 if (found)
1417 continue;
1419 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1420 if (m_bSymbolizeRefNames)
1422 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1424 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1425 refLabel.singleRemote = true;
1428 break;
1430 case CGit::REF_TYPE::ANNOTATED_TAG:
1431 case CGit::REF_TYPE::TAG:
1432 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1433 continue;
1434 refLabel.color = m_Colors.GetColor(CColors::Tag);
1435 break;
1436 case CGit::REF_TYPE::STASH:
1437 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1438 continue;
1439 refLabel.color = m_Colors.GetColor(CColors::Stash);
1440 break;
1441 case CGit::REF_TYPE::BISECT_GOOD:
1442 case CGit::REF_TYPE::BISECT_BAD:
1443 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1444 continue;
1445 refLabel.color = (refLabel.refType == CGit::REF_TYPE::BISECT_GOOD) ? m_Colors.GetColor(CColors::BisectGood): m_Colors.GetColor(CColors::BisectBad);
1446 break;
1447 default:
1448 continue;
1450 refsToShow.push_back(refLabel);
1453 if (refsToShow.empty())
1455 *pResult = CDRF_DODEFAULT;
1456 return;
1459 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1461 *pResult = CDRF_SKIPDEFAULT;
1462 return;
1469 if (pLVCD->iSubItem == LOGLIST_ACTION)
1471 if(this->m_IsIDReplaceAction)
1473 *pResult = CDRF_DODEFAULT;
1474 return;
1476 *pResult = CDRF_DODEFAULT;
1478 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1479 return;
1481 int nIcons = 0;
1482 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1483 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1485 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1486 CRect rect;
1487 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1488 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1489 // Get the selected state of the
1490 // item being drawn.
1492 // Fill the background if necessary
1493 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1495 // Draw the icon(s) into the compatible DC
1496 int action = pLogEntry->GetAction(this);
1497 if (!pLogEntry->m_IsDiffFiles)
1499 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1500 *pResult = CDRF_SKIPDEFAULT;
1501 return;
1504 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1505 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1506 ++nIcons;
1508 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1509 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1510 ++nIcons;
1512 if (action & CTGitPath::LOGACTIONS_DELETED)
1513 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1514 ++nIcons;
1516 if (action & CTGitPath::LOGACTIONS_REPLACED)
1517 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1518 ++nIcons;
1520 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1521 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1522 ++nIcons;
1524 *pResult = CDRF_SKIPDEFAULT;
1525 return;
1528 break;
1530 *pResult = CDRF_DODEFAULT;
1533 CString FindSVNRev(const CString& msg)
1537 const std::tr1::wsregex_iterator end;
1538 std::wstring s = msg;
1539 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1540 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex1); it != end; ++it)
1542 const std::tr1::wsmatch match = *it;
1543 if (match.size() == 4)
1545 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1546 return std::wstring(match[2]).c_str();
1549 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1550 for (std::tr1::wsregex_iterator it(s.cbegin(), s.cend(), regex2); it != end; ++it)
1552 const std::tr1::wsmatch match = *it;
1553 if (match.size() == 3)
1555 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1556 return std::wstring(match[1]).c_str();
1560 catch (std::exception) {}
1562 return _T("");
1565 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1567 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1568 return pLogEntry->GetSubject();
1570 CString txt(pLogEntry->GetSubject());
1571 txt += _T(' ');
1572 txt += pLogEntry->GetBody();
1574 // Deal with CRLF
1575 txt.Replace(_T('\n'), _T(' '));
1576 txt.Replace(_T('\r'), _T(' '));
1578 return txt;
1581 // CGitLogListBase message handlers
1583 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1585 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1587 // Create a pointer to the item
1588 LV_ITEM* pItem = &(pDispInfo)->item;
1590 // Do the list need text information?
1591 if (!(pItem->mask & LVIF_TEXT))
1592 return;
1594 // By default, clear text buffer.
1595 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1597 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1599 *pResult = 0;
1600 if (m_bNoDispUpdates || bOutOfRange)
1601 return;
1603 // Which item number?
1604 int itemid = pItem->iItem;
1605 GitRevLoglist* pLogEntry = nullptr;
1606 if (itemid < m_arShownList.GetCount())
1607 pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(pItem->iItem));
1609 CString temp;
1610 if(m_IsOldFirst)
1612 temp.Format(_T("%d"),pItem->iItem+1);
1615 else
1617 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1620 // Which column?
1621 switch (pItem->iSubItem)
1623 case LOGLIST_GRAPH: //Graphic
1624 break;
1625 case LOGLIST_REBASE:
1627 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1628 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1630 break;
1631 case LOGLIST_ACTION: //action -- no text in the column
1632 break;
1633 case LOGLIST_HASH:
1634 if(pLogEntry)
1635 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1636 break;
1637 case LOGLIST_ID:
1638 if(this->m_IsIDReplaceAction)
1639 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1640 break;
1641 case LOGLIST_MESSAGE: //Message
1642 if (pLogEntry)
1643 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1644 break;
1645 case LOGLIST_AUTHOR: //Author
1646 if (pLogEntry)
1647 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1648 break;
1649 case LOGLIST_DATE: //Date
1650 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1651 lstrcpyn(pItem->pszText,
1652 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1653 pItem->cchTextMax - 1);
1654 break;
1656 case LOGLIST_EMAIL:
1657 if (pLogEntry)
1658 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1659 break;
1661 case LOGLIST_COMMIT_NAME: //Commit
1662 if (pLogEntry)
1663 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1664 break;
1666 case LOGLIST_COMMIT_EMAIL: //Commit Email
1667 if (pLogEntry)
1668 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1669 break;
1671 case LOGLIST_COMMIT_DATE: //Commit Date
1672 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1673 lstrcpyn(pItem->pszText,
1674 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1675 pItem->cchTextMax - 1);
1676 break;
1677 case LOGLIST_BUG: //Bug ID
1678 if(pLogEntry)
1679 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1680 break;
1681 case LOGLIST_SVNREV: //SVN revision
1682 if (pLogEntry)
1683 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1684 break;
1686 default:
1687 ASSERT(false);
1691 bool CGitLogListBase::IsOnStash(int index)
1693 GitRevLoglist* rev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index));
1694 if (IsStash(rev))
1695 return true;
1696 if (index > 0)
1698 GitRevLoglist* preRev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index - 1));
1699 if (IsStash(preRev))
1700 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1702 return false;
1705 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1707 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1709 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1710 return true;
1712 return false;
1715 bool CGitLogListBase::IsBisect(const GitRev * pSelLogEntry)
1717 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1719 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Left(12) == _T("refs/bisect/"))
1720 return true;
1722 return false;
1725 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1727 if (pRev->m_ParentHash.empty())
1729 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1730 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1732 parentHash = pRev->m_ParentHash;
1735 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1738 if (pWnd == GetHeaderCtrl())
1740 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1743 int selIndex = GetSelectionMark();
1744 if (selIndex < 0)
1745 return; // nothing selected, nothing to do with a context menu
1747 // if the user selected the info text telling about not all revisions shown due to
1748 // the "stop on copy/rename" option, we also don't show the context menu
1749 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1750 return;
1752 // if the context menu is invoked through the keyboard, we have to use
1753 // a calculated position on where to anchor the menu on
1754 if ((point.x == -1) && (point.y == -1))
1756 CRect rect;
1757 GetItemRect(selIndex, &rect, LVIR_LABEL);
1758 ClientToScreen(&rect);
1759 point = rect.CenterPoint();
1761 m_nSearchIndex = selIndex;
1762 m_bCancelled = FALSE;
1764 // calculate some information the context menu commands can use
1765 // CString pathURL = GetURLFromPath(m_path);
1767 POSITION pos = GetFirstSelectedItemPosition();
1768 int indexNext = GetNextSelectedItem(pos);
1769 if (indexNext < 0)
1770 return;
1772 GitRevLoglist* pSelLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(indexNext));
1773 if (pSelLogEntry == nullptr)
1774 return;
1775 #if 0
1776 GitRev revSelected = pSelLogEntry->Rev;
1777 GitRev revPrevious = git_revnum_t(revSelected)-1;
1778 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1780 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1782 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1783 if (changedpath->lCopyFromRev)
1784 revPrevious = changedpath->lCopyFromRev;
1787 GitRev revSelected2;
1788 if (pos)
1790 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1791 revSelected2 = pLogEntry->Rev;
1793 bool bAllFromTheSameAuthor = true;
1794 CString firstAuthor;
1795 CLogDataVector selEntries;
1796 GitRev revLowest, revHighest;
1797 GitRevRangeArray revisionRanges;
1799 POSITION pos = GetFirstSelectedItemPosition();
1800 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1801 revisionRanges.AddRevision(pLogEntry->Rev);
1802 selEntries.push_back(pLogEntry);
1803 firstAuthor = pLogEntry->sAuthor;
1804 revLowest = pLogEntry->Rev;
1805 revHighest = pLogEntry->Rev;
1806 while (pos)
1808 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1809 revisionRanges.AddRevision(pLogEntry->Rev);
1810 selEntries.push_back(pLogEntry);
1811 if (firstAuthor.Compare(pLogEntry->sAuthor))
1812 bAllFromTheSameAuthor = false;
1813 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1814 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1818 #endif
1820 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1822 int FirstSelect=-1, LastSelect=-1;
1823 pos = GetFirstSelectedItemPosition();
1824 FirstSelect = GetNextSelectedItem(pos);
1825 while(pos)
1827 LastSelect = GetNextSelectedItem(pos);
1829 //entry is selected, now show the popup menu
1830 CIconMenu popup;
1831 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1833 if (popup.CreatePopupMenu())
1835 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1836 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1837 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1838 bool isStash = IsOnStash(indexNext);
1839 GIT_REV_LIST parentHash;
1840 GetParentHashes(pSelLogEntry, parentHash);
1842 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1843 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1845 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)) && FirstSelect != GetItemCount() - 1 && LastSelect != GetItemCount() - 1)
1846 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1848 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1849 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1851 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1852 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1854 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)))
1855 popup.AppendMenu(MF_SEPARATOR, NULL);
1857 if (GetSelectedCount() == 1)
1860 bool requiresSeparator = false;
1861 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1863 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1865 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1866 requiresSeparator = true;
1869 else
1871 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1873 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1874 requiresSeparator = true;
1876 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1878 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1879 requiresSeparator = true;
1883 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1885 if (parentHash.size() == 1)
1887 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1888 requiresSeparator = true;
1890 else if (parentHash.size() > 1)
1892 blamemenu.CreatePopupMenu();
1893 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1894 for (size_t i = 0; i < parentHash.size(); ++i)
1896 CString str;
1897 str.Format(IDS_PARENT, i + 1);
1898 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1900 requiresSeparator = true;
1904 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1906 if (parentHash.size() == 1)
1908 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1909 requiresSeparator = true;
1911 else if (parentHash.size() > 1)
1913 gnudiffmenu.CreatePopupMenu();
1914 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1916 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1917 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1918 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1920 for (size_t i = 0; i < parentHash.size(); ++i)
1922 CString str;
1923 str.Format(IDS_PARENT, i + 1);
1924 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1926 requiresSeparator = true;
1930 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1932 if (parentHash.size() == 1)
1934 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1935 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1936 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1937 requiresSeparator = true;
1939 else if (parentHash.size() > 1)
1941 diffmenu.CreatePopupMenu();
1942 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1943 for (size_t i = 0; i < parentHash.size(); ++i)
1945 CString str;
1946 str.Format(IDS_PARENT, i + 1);
1947 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1948 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1950 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1951 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1954 requiresSeparator = true;
1958 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1960 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1961 requiresSeparator = true;
1964 if (requiresSeparator)
1966 popup.AppendMenu(MF_SEPARATOR, NULL);
1967 requiresSeparator = false;
1970 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1972 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1974 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1975 requiresSeparator = true;
1979 if ((pSelLogEntry->m_CommitHash.IsEmpty() || isStash) && CTGitPath(g_Git.m_CurrentDir).HasStashDir())
1981 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1983 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1984 requiresSeparator = true;
1987 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1989 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1990 requiresSeparator = true;
1994 if (requiresSeparator)
1996 popup.AppendMenu(MF_SEPARATOR, NULL);
1997 requiresSeparator = false;
2000 if (CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2002 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2003 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTGOOD) && !IsBisect(pFirstEntry))
2005 popup.AppendMenuIcon(ID_BISECTGOOD, IDS_MENUBISECTGOOD, IDI_THUMB_UP);
2006 requiresSeparator = true;
2009 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTBAD) && !IsBisect(pFirstEntry))
2011 popup.AppendMenuIcon(ID_BISECTBAD, IDS_MENUBISECTBAD, IDI_THUMB_DOWN);
2012 requiresSeparator = true;
2016 if (pSelLogEntry->m_CommitHash.IsEmpty() && CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2018 if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTRESET))
2020 popup.AppendMenuIcon(ID_BISECTRESET, IDS_MENUBISECTRESET, IDI_BISECT_RESET);
2021 requiresSeparator = true;
2025 if (requiresSeparator)
2027 popup.AppendMenu(MF_SEPARATOR, NULL);
2028 requiresSeparator = false;
2031 if (pSelLogEntry->m_CommitHash.IsEmpty())
2033 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
2034 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2036 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
2037 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
2039 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
2040 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
2042 popup.AppendMenu(MF_SEPARATOR, NULL);
2044 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
2045 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
2047 popup.AppendMenu(MF_SEPARATOR, NULL);
2051 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2052 // {
2053 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2054 // }
2055 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2056 // {
2057 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2058 // }
2059 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2060 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2061 // {
2062 // popup.AppendMenu(MF_SEPARATOR, NULL);
2063 // }
2065 CString str;
2066 //if (m_hasWC)
2067 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2069 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2071 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2072 GetSelectedCount() == 1)
2073 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2075 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2076 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2078 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
2080 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2081 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2083 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2085 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2086 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2089 // Add Switch Branch express Menu
2090 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2091 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2094 std::vector<CString *> branchs;
2095 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2097 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2098 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2100 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2104 CString str2;
2105 str2.LoadString(IDS_SWITCH_BRANCH);
2107 if(branchs.size() == 1)
2109 str2 += _T(' ');
2110 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2111 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2113 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2116 else if(branchs.size() > 1)
2118 subbranchmenu.CreatePopupMenu();
2119 for (size_t i = 0 ; i < branchs.size(); ++i)
2121 if (*branchs[i] != currentBranch)
2123 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2124 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2128 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2132 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2133 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2135 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2136 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2138 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2139 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2141 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2143 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2144 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2145 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2147 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2148 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2150 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2152 if (parentHash.size() == 1)
2154 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2156 else if (parentHash.size() > 1)
2158 revertmenu.CreatePopupMenu();
2159 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2161 for (size_t i = 0; i < parentHash.size(); ++i)
2163 CString str2;
2164 str2.Format(IDS_PARENT, i + 1);
2165 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2170 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2171 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2173 popup.AppendMenu(MF_SEPARATOR, NULL);
2178 if(!pSelLogEntry->m_Ref.IsEmpty())
2180 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2181 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2182 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2183 popup.AppendMenu(MF_SEPARATOR, NULL);
2186 if (GetSelectedCount() >= 2)
2188 bool bAddSeparator = false;
2189 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2191 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2192 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2195 if (GetSelectedCount() == 2)
2197 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2198 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2200 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2202 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2203 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2204 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2205 CString menu;
2206 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2207 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2208 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2209 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2212 bAddSeparator = true;
2215 if (m_hasWC)
2217 bAddSeparator = true;
2220 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2221 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2223 if (bAddSeparator)
2224 popup.AppendMenu(MF_SEPARATOR, NULL);
2227 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2229 bool bAddSeparator = false;
2230 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2232 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2234 CString head;
2235 int headindex;
2236 headindex = this->GetHeadIndex();
2237 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2239 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2240 CGitHash hashFirst;
2241 if (g_Git.GetHash(hashFirst, head))
2242 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2243 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2244 CGitHash hash;
2245 if (g_Git.GetHash(hash, head))
2246 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2247 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2248 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2249 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2250 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2251 bAddSeparator = true;
2256 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2257 if (GetSelectedCount() >= 2)
2258 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2259 else
2260 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2261 bAddSeparator = true;
2264 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2265 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2266 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2267 bAddSeparator = true;
2270 if (bAddSeparator)
2271 popup.AppendMenu(MF_SEPARATOR, NULL);
2274 if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2276 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2277 popup.AppendMenu(MF_SEPARATOR, NULL);
2280 if (GetSelectedCount() == 1)
2282 bool bAddSeparator = false;
2283 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2285 // show the push-option only if the log entry has an associated local branch
2286 bool isLocal = false;
2287 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2289 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2290 isLocal = true;
2292 if (isLocal || showExtendedMenu)
2294 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2295 bAddSeparator = true;
2298 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2300 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2301 bAddSeparator = true;
2305 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2307 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2309 std::vector<CString *> branchs;
2310 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2312 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2313 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2315 CString str;
2316 if (branchs.size() == 1)
2318 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2319 str+=_T(' ');
2320 str += *branchs[0];
2321 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2322 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2323 bAddSeparator = true;
2325 else if (branchs.size() > 1)
2327 str.LoadString(IDS_DELETE_BRANCHTAG);
2328 submenu.CreatePopupMenu();
2329 for (size_t i = 0; i < branchs.size(); ++i)
2331 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2332 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2335 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2336 bAddSeparator = true;
2339 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2340 if (bAddSeparator)
2341 popup.AppendMenu(MF_SEPARATOR, NULL);
2342 } // GetSelectedCount() == 1
2344 if (GetSelectedCount() != 0)
2346 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2347 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2348 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2349 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2350 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2351 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2354 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2355 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2357 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2358 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2360 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2361 // DialogEnableWindow(IDOK, FALSE);
2362 // SetPromptApp(&theApp);
2364 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2366 // EnableOKButton();
2367 } // if (popup.CreatePopupMenu())
2371 bool CGitLogListBase::IsSelectionContinuous()
2373 if ( GetSelectedCount()==1 )
2375 // if only one revision is selected, the selection is of course
2376 // continuous
2377 return true;
2380 POSITION pos = GetFirstSelectedItemPosition();
2381 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2382 if (bContinuous)
2384 int itemindex = GetNextSelectedItem(pos);
2385 while (pos)
2387 int nextindex = GetNextSelectedItem(pos);
2388 if (nextindex - itemindex > 1)
2390 bContinuous = false;
2391 break;
2393 itemindex = nextindex;
2396 return bContinuous;
2399 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2402 CString sClipdata;
2403 POSITION pos = GetFirstSelectedItemPosition();
2404 if (pos != NULL)
2406 CString sRev;
2407 sRev.LoadString(IDS_LOG_REVISION);
2408 CString sAuthor;
2409 sAuthor.LoadString(IDS_LOG_AUTHOR);
2410 CString sDate;
2411 sDate.LoadString(IDS_LOG_DATE);
2412 CString sMessage;
2413 sMessage.LoadString(IDS_LOG_MESSAGE);
2414 bool first = true;
2415 while (pos)
2417 CString sLogCopyText;
2418 CString sPaths;
2419 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2421 if (toCopy == ID_COPY_ALL)
2423 //pLogEntry->GetFiles(this)
2424 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2426 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2427 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2429 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2430 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2432 CString rename;
2433 rename.Format(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2434 sPaths += _T(' ');
2435 sPaths += rename;
2437 sPaths += _T("\r\n");
2439 sPaths.Trim();
2440 CString body = pLogEntry->GetBody();
2441 body.Replace(_T("\n"), _T("\r\n"));
2442 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"),
2443 (LPCTSTR)sRev, (LPCTSTR)pLogEntry->m_CommitHash.ToString(),
2444 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2445 (LPCTSTR)sDate,
2446 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2447 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->GetSubjectBody(true),
2448 (LPCTSTR)sPaths);
2449 sClipdata += sLogCopyText;
2451 else if (toCopy == ID_COPY_MESSAGE)
2453 sClipdata += _T("* ");
2454 sClipdata += pLogEntry->GetSubjectBody(true);
2455 sClipdata += _T("\r\n\r\n");
2457 else if (toCopy == ID_COPY_SUBJECT)
2459 sClipdata += _T("* ");
2460 sClipdata += pLogEntry->GetSubject().Trim();
2461 sClipdata += _T("\r\n\r\n");
2463 else
2465 if (!first)
2466 sClipdata += _T("\r\n");
2467 sClipdata += pLogEntry->m_CommitHash;
2470 first = false;
2472 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2477 void CGitLogListBase::DiffSelectedRevWithPrevious()
2479 if (m_bThreadRunning)
2480 return;
2482 int FirstSelect=-1, LastSelect=-1;
2483 POSITION pos = GetFirstSelectedItemPosition();
2484 FirstSelect = GetNextSelectedItem(pos);
2485 while(pos)
2487 LastSelect = GetNextSelectedItem(pos);
2490 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2493 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2495 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2496 *pResult = -1;
2498 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2499 return;
2500 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2501 return;
2502 if (pFindInfo->lvfi.psz == 0)
2503 return;
2504 #if 0
2505 CString sCmp = pFindInfo->lvfi.psz;
2506 CString sRev;
2507 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2509 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2510 sRev.Format(_T("%ld"), pLogEntry->Rev);
2511 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2513 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2515 *pResult = i;
2516 return;
2519 else
2521 if (sCmp.Compare(sRev)==0)
2523 *pResult = i;
2524 return;
2528 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2530 for (int i=0; i<pFindInfo->iStart; ++i)
2532 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2533 sRev.Format(_T("%ld"), pLogEntry->Rev);
2534 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2536 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2538 *pResult = i;
2539 return;
2542 else
2544 if (sCmp.Compare(sRev)==0)
2546 *pResult = i;
2547 return;
2552 #endif
2553 *pResult = -1;
2556 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2558 ClearText();
2560 this->m_arShownList.SafeRemoveAll();
2562 this->m_logEntries.ClearAll();
2563 if (this->m_logEntries.ParserFromLog(path, 0, info, range))
2564 return -1;
2566 SetItemCountEx((int)m_logEntries.size());
2568 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2570 if(m_IsOldFirst)
2572 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2573 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2576 else
2578 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2579 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2583 ReloadHashMap();
2585 if(path)
2586 m_Path=*path;
2587 return 0;
2591 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2593 ClearText();
2595 m_arShownList.SafeRemoveAll();
2597 m_logEntries.ClearAll();
2598 if (m_logEntries.Fill(hashes))
2599 return -1;
2601 SetItemCountEx((int)m_logEntries.size());
2603 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2605 if (m_IsOldFirst)
2607 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2608 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2610 else
2612 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2613 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2617 ReloadHashMap();
2619 return 0;
2622 int CGitLogListBase::BeginFetchLog()
2624 ClearText();
2626 this->m_arShownList.SafeRemoveAll();
2628 this->m_logEntries.ClearAll();
2630 this->m_LogCache.ClearAllParent();
2632 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2634 CTGitPath *path;
2635 if(this->m_Path.IsEmpty())
2636 path=NULL;
2637 else
2638 path=&this->m_Path;
2640 int mask;
2641 mask = CGit::LOG_INFO_ONLY_HASH;
2642 if (m_bIncludeBoundaryCommits)
2643 mask |= CGit::LOG_INFO_BOUNDARY;
2644 // if(this->m_bAllBranch)
2645 mask |= m_ShowMask ;
2647 if(m_bShowWC)
2649 this->m_logEntries.insert(m_logEntries.cbegin(), m_wcRev.m_CommitHash);
2650 ResetWcRev();
2651 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2654 if (m_sRange.IsEmpty())
2655 m_sRange = _T("HEAD");
2657 #if 0 /* use tortoiegit filter */
2658 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2659 data.m_Author = this->m_sFilterText;
2661 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2662 data.m_MessageFilter = this->m_sFilterText;
2664 data.m_IsRegex = m_bFilterWithRegex;
2665 #endif
2667 // follow does not work for directories
2668 if (!path || path->IsDirectory())
2669 mask &= ~CGit::LOG_INFO_FOLLOW;
2670 // follow does not work with all branches 8at least in TGit)
2671 if (mask & CGit::LOG_INFO_FOLLOW)
2672 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2674 CString cmd = g_Git.GetLogCmd(m_sRange, path, mask, &m_Filter);
2676 //this->m_logEntries.ParserFromLog();
2677 if(IsInWorkingThread())
2679 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2681 else
2683 SetItemCountEx((int)m_logEntries.size());
2688 [] { git_init(); } ();
2690 catch (char* msg)
2692 CString err(msg);
2693 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2694 return -1;
2697 if (!g_Git.CanParseRev(m_sRange))
2699 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2700 return 0;
2702 // if show all branches, pick any ref as dummy entry ref
2703 STRING_VECTOR list;
2704 if (g_Git.GetRefList(list))
2705 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2706 if (list.size() == 0)
2707 return 0;
2709 cmd = g_Git.GetLogCmd(list[0], path, mask, &m_Filter);
2712 g_Git.m_critGitDllSec.Lock();
2713 try {
2714 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2716 g_Git.m_critGitDllSec.Unlock();
2717 return -1;
2720 catch (char* msg)
2722 g_Git.m_critGitDllSec.Unlock();
2723 CString err(msg);
2724 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2725 return -1;
2727 g_Git.m_critGitDllSec.Unlock();
2729 return 0;
2732 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2734 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2736 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2738 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2740 DiffSelectedRevWithPrevious();
2741 return TRUE;
2744 #if 0
2745 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2747 DiffSelectedFile();
2748 return TRUE;
2750 #endif
2752 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2754 // select all entries
2755 for (int i=0; i<GetItemCount(); ++i)
2757 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2759 return TRUE;
2762 #if 0
2763 if (m_hAccel && !bSkipAccelerator)
2765 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2766 if (ret)
2767 return TRUE;
2770 #endif
2771 //m_tooltips.RelayEvent(pMsg);
2772 return __super::PreTranslateMessage(pMsg);
2775 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2777 // a double click on an entry in the revision list has happened
2778 *pResult = 0;
2780 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2781 DiffSelectedRevWithPrevious();
2784 int CGitLogListBase::FetchLogAsync(void * data)
2786 ReloadHashMap();
2787 m_ProcData=data;
2788 m_bExitThread=FALSE;
2789 InterlockedExchange(&m_bThreadRunning, TRUE);
2790 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2791 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2792 if (m_LoadingThread ==NULL)
2794 InterlockedExchange(&m_bThreadRunning, FALSE);
2795 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2796 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2797 return -1;
2799 return 0;
2802 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2804 return ((CGitLogListBase*)pVoid)->LogThread();
2807 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2809 //CTime time;
2810 oldest=CTime::GetCurrentTime();
2811 latest=CTime(1971,1,2,0,0,0);
2812 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2814 if(m_logEntries[i].IsEmpty())
2815 continue;
2817 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() < oldest.GetTime())
2818 oldest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2820 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() > latest.GetTime())
2821 latest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2825 if(latest<oldest)
2826 latest=oldest;
2829 UINT CGitLogListBase::LogThread()
2831 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2833 InterlockedExchange(&m_bThreadRunning, TRUE);
2834 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2836 ULONGLONG t1,t2;
2838 if(BeginFetchLog())
2840 InterlockedExchange(&m_bThreadRunning, FALSE);
2841 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2843 return 1;
2846 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2847 bool bRegex = false;
2848 if (m_bFilterWithRegex)
2849 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2851 TRACE(_T("\n===Begin===\n"));
2852 //Update work copy item;
2854 if (!m_logEntries.empty())
2856 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2858 m_arShownList.SafeAdd(pRev);
2862 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2864 // store commit number of the last selected commit/line before the refresh or -1
2865 int lastSelectedHashNItem = -1;
2866 if (m_lastSelectedHash.IsEmpty())
2867 lastSelectedHashNItem = 0;
2869 int ret = 0;
2871 bool shouldWalk = true;
2872 if (!g_Git.CanParseRev(m_sRange))
2874 // walk revisions if show all branches and there exists any ref
2875 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2876 shouldWalk = false;
2877 else
2879 STRING_VECTOR list;
2880 if (g_Git.GetRefList(list))
2881 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2882 if (list.size() == 0)
2883 shouldWalk = false;
2887 if (shouldWalk)
2889 g_Git.m_critGitDllSec.Lock();
2890 int total = 0;
2893 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2894 total = git_get_log_estimate_commit_count(m_DllGitLog);
2896 catch (char* msg)
2898 CString err(msg);
2899 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2900 ret = -1;
2902 g_Git.m_critGitDllSec.Unlock();
2904 GIT_COMMIT commit;
2905 t2=t1=GetTickCount();
2906 int oldprecentage = 0;
2907 size_t oldsize = m_logEntries.size();
2908 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2909 while (ret== 0 && !m_bExitThread)
2911 g_Git.m_critGitDllSec.Lock();
2914 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2916 catch (char* msg)
2918 g_Git.m_critGitDllSec.Unlock();
2919 CString err(msg);
2920 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2921 break;
2923 g_Git.m_critGitDllSec.Unlock();
2925 if(ret)
2927 if (ret != -2) // other than end of revision walking
2928 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2929 break;
2932 if (commit.m_ignore == 1)
2934 git_free_commit(&commit);
2935 continue;
2938 //printf("%s\r\n",commit.GetSubject());
2939 if(m_bExitThread)
2940 break;
2942 CGitHash hash = (char*)commit.m_hash ;
2944 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2945 pRev->m_GitCommit = commit;
2946 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2948 char *note=NULL;
2949 g_Git.m_critGitDllSec.Lock();
2952 git_get_notes(commit.m_hash, &note);
2954 catch (char* msg)
2956 g_Git.m_critGitDllSec.Unlock();
2957 CString err(msg);
2958 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2959 break;
2961 g_Git.m_critGitDllSec.Unlock();
2963 if(note)
2965 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2966 free(note);
2967 note = nullptr;
2970 if(!pRev->m_IsDiffFiles)
2972 pRev->m_CallDiffAsync = DiffAsync;
2975 pRev->ParserParentFromCommit(&commit);
2976 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2978 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2980 const CGitHash &parentHash = pRev->m_ParentHash[i];
2981 auto it = commitChildren.find(parentHash);
2982 if (it == commitChildren.end())
2984 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2986 it->second.insert(pRev->m_CommitHash);
2990 #ifdef DEBUG
2991 pRev->DbgPrint();
2992 TRACE(_T("\n"));
2993 #endif
2995 bool visible = true;
2996 if (HasFilterText())
2998 if(!IsMatchFilter(bRegex,pRev,pat))
2999 visible = false;
3001 if (visible && !ShouldShowFilter(pRev, commitChildren))
3002 visible = false;
3003 this->m_critSec.Lock();
3004 m_logEntries.append(hash, visible);
3005 if (visible)
3006 m_arShownList.SafeAdd(pRev);
3007 this->m_critSec.Unlock();
3009 if (!visible)
3010 continue;
3012 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3013 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3015 t2=GetTickCount();
3017 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3019 //update UI
3020 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3021 if(percent > 99)
3022 percent =99;
3023 if(percent < GITLOG_START)
3024 percent = GITLOG_START +1;
3026 oldsize = m_logEntries.size();
3027 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3029 //if( percent > oldprecentage )
3031 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3032 oldprecentage = percent;
3035 if (lastSelectedHashNItem >= 0)
3036 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3038 t1 = t2;
3041 g_Git.m_critGitDllSec.Lock();
3042 git_close_log(m_DllGitLog);
3043 g_Git.m_critGitDllSec.Unlock();
3047 if (m_bExitThread)
3049 InterlockedExchange(&m_bThreadRunning, FALSE);
3050 return 0;
3053 //Update UI;
3054 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3056 if (lastSelectedHashNItem >= 0)
3057 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3059 if (this->m_hWnd)
3060 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3062 InterlockedExchange(&m_bThreadRunning, FALSE);
3064 return 0;
3067 void CGitLogListBase::FetchRemoteList()
3069 STRING_VECTOR remoteList;
3070 m_SingleRemote.Empty();
3071 if (!g_Git.GetRemoteList(remoteList) && remoteList.size() == 1)
3072 m_SingleRemote = remoteList[0];
3075 void CGitLogListBase::FetchTrackingBranchList()
3077 m_TrackingMap.clear();
3078 for (auto it = m_HashMap.cbegin(); it != m_HashMap.cend(); ++it)
3080 for (const auto& ref : it->second)
3082 CString branchName;
3083 if (CGit::GetShortName(ref, branchName, _T("refs/heads/")))
3085 CString pullRemote, pullBranch;
3086 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3087 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3089 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3096 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3098 SafeTerminateThread();
3100 this->SetItemCountEx(0);
3101 this->Clear();
3103 ResetWcRev();
3105 ShowGraphColumn((m_ShowMask & CGit::LOG_INFO_FOLLOW) ? false : true);
3107 //Update branch and Tag info
3108 ReloadHashMap();
3109 if (m_pFindDialog)
3110 m_pFindDialog->RefreshList();
3111 //Assume Thread have exited
3112 //if(!m_bThreadRunning)
3114 m_logEntries.clear();
3116 if(IsCleanFilter)
3118 m_sFilterText.Empty();
3121 InterlockedExchange(&m_bExitThread,FALSE);
3123 InterlockedExchange(&m_bThreadRunning, TRUE);
3124 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3126 SafeTerminateAsyncDiffThread();
3127 m_AsynDiffListLock.Lock();
3128 m_AsynDiffList.clear();
3129 m_AsynDiffListLock.Unlock();
3130 InterlockedExchange(&m_AsyncThreadExit, FALSE);
3131 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL, 0, CREATE_SUSPENDED);
3132 if (!m_DiffingThread)
3133 CMessageBox::Show(nullptr, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3134 else
3136 m_DiffingThread->m_bAutoDelete = FALSE;
3137 m_DiffingThread->ResumeThread();
3139 if ((m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST)) == nullptr)
3141 InterlockedExchange(&m_bThreadRunning, FALSE);
3142 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3143 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3147 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3151 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3152 if (!bMatchCase)
3153 type |= std::tr1::regex_constants::icase;
3154 pat = std::tr1::wregex(regexp_str, type);
3155 return true;
3157 catch (std::exception) {}
3158 return false;
3160 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3162 BOOL result = TRUE;
3163 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3164 CString sRev;
3166 if ((bRegex)&&(m_bFilterWithRegex))
3168 if (m_SelectedFilters & LOGFILTER_BUGID)
3170 if(this->m_bShowBugtraqColumn)
3172 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3174 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3175 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3177 return TRUE;
3182 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3184 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3185 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3187 return TRUE;
3191 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3193 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3194 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3196 return TRUE;
3200 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3202 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3204 return TRUE;
3207 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3209 return TRUE;
3213 if (m_SelectedFilters & LOGFILTER_EMAILS)
3215 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3217 return TRUE;
3220 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3222 return TRUE;
3226 if (m_SelectedFilters & LOGFILTER_REVS)
3228 sRev = pRev->m_CommitHash.ToString();
3229 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3231 return TRUE;
3235 if (m_SelectedFilters & LOGFILTER_NOTES)
3237 if (std::regex_search(std::wstring(pRev->m_Notes), pat, flags))
3239 return TRUE;
3243 if (m_SelectedFilters & LOGFILTER_REFNAME)
3245 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3246 for (const auto& ref : refs)
3248 if (std::regex_search(std::wstring(ref), pat, flags))
3250 return TRUE;
3255 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3257 if (std::regex_search(std::wstring(GetTagInfo(pRev)), pat, flags))
3259 return TRUE;
3263 if (m_SelectedFilters & LOGFILTER_PATHS)
3265 CTGitPathList *pathList=NULL;
3266 if( pRev->m_IsDiffFiles)
3267 pathList = &pRev->GetFiles(this);
3268 else
3270 if(!pRev->m_IsSimpleListReady)
3271 pRev->SafeGetSimpleList(&g_Git);
3274 if(pathList)
3275 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3277 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3279 return true;
3281 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3283 return true;
3287 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3289 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3291 return true;
3296 else
3298 CString find = m_sFilterText;
3299 if (!m_bFilterCaseSensitively)
3300 find.MakeLower();
3301 result = find[0] == '!' ? FALSE : TRUE;
3302 if (!result)
3303 find = find.Mid(1);
3305 if (m_SelectedFilters & LOGFILTER_BUGID)
3307 if(this->m_bShowBugtraqColumn)
3309 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3311 if (!m_bFilterCaseSensitively)
3312 sBugIds.MakeLower();
3313 if ((sBugIds.Find(find) >= 0))
3315 return result;
3320 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3322 CString msg = pRev->GetSubject();
3324 if (!m_bFilterCaseSensitively)
3325 msg = msg.MakeLower();
3326 if ((msg.Find(find) >= 0))
3328 return result;
3332 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3334 CString msg = pRev->GetBody();
3336 if (!m_bFilterCaseSensitively)
3337 msg = msg.MakeLower();
3338 if ((msg.Find(find) >= 0))
3340 return result;
3344 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3346 CString msg = pRev->GetAuthorName();
3347 if (!m_bFilterCaseSensitively)
3348 msg = msg.MakeLower();
3349 if ((msg.Find(find) >= 0))
3351 return result;
3355 if (m_SelectedFilters & LOGFILTER_EMAILS)
3357 CString msg = pRev->GetAuthorEmail();
3358 if (!m_bFilterCaseSensitively)
3359 msg = msg.MakeLower();
3360 if ((msg.Find(find) >= 0))
3362 return result;
3366 if (m_SelectedFilters & LOGFILTER_NOTES)
3368 CString msg = pRev->m_Notes;
3369 if (!m_bFilterCaseSensitively)
3370 msg = msg.MakeLower();
3371 if ((msg.Find(find) >= 0))
3373 return result;
3377 if (m_SelectedFilters & LOGFILTER_REVS)
3379 sRev = pRev->m_CommitHash.ToString();
3380 if ((sRev.Find(find) >= 0))
3382 return result;
3386 if (m_SelectedFilters & LOGFILTER_ANNOTATEDTAG)
3388 CString msg = GetTagInfo(pRev);
3389 if (!m_bFilterCaseSensitively)
3390 msg = msg.MakeLower();
3391 if ((msg.Find(find) >= 0))
3393 return result;
3397 if (m_SelectedFilters & LOGFILTER_REFNAME)
3399 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3400 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3402 if (it->Find(find) >= 0)
3404 return result;
3409 if (m_SelectedFilters & LOGFILTER_PATHS)
3411 CTGitPathList *pathList=NULL;
3412 if( pRev->m_IsDiffFiles)
3413 pathList = &pRev->GetFiles(this);
3414 else
3416 if(!pRev->m_IsSimpleListReady)
3417 pRev->SafeGetSimpleList(&g_Git);
3419 if(pathList)
3420 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3422 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3423 CString path = cpath->GetGitOldPathString();
3424 if (!m_bFilterCaseSensitively)
3425 path.MakeLower();
3426 if ((path.Find(find)>=0))
3428 return result;
3430 path = cpath->GetGitPathString();
3431 if (!m_bFilterCaseSensitively)
3432 path.MakeLower();
3433 if ((path.Find(find)>=0))
3435 return result;
3439 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3441 CString path = pRev->m_SimpleFileList[i];
3442 if (!m_bFilterCaseSensitively)
3443 path.MakeLower();
3444 if ((path.Find(find)>=0))
3446 return result;
3450 } // else (from if (bRegex))
3451 return !result;
3454 static bool CStringStartsWith(const CString &str, const CString &prefix)
3456 return str.Left(prefix.GetLength()) == prefix;
3458 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3460 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3461 return true;
3463 if (m_ShowFilter & FILTERSHOW_REFS)
3465 // Keep all refs.
3466 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3467 for (size_t i = 0; i < refList.size(); ++i)
3469 const CString &str = refList[i];
3470 if (CStringStartsWith(str, _T("refs/heads/")))
3472 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3473 return true;
3475 else if (CStringStartsWith(str, _T("refs/remotes/")))
3477 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3478 return true;
3480 else if (CStringStartsWith(str, _T("refs/tags/")))
3482 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3483 return true;
3485 else if (CStringStartsWith(str, _T("refs/stash")))
3487 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3488 return true;
3490 else if (CStringStartsWith(str, _T("refs/bisect/")))
3492 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3493 return true;
3496 // Keep the head too.
3497 if (pRev->m_CommitHash == m_HeadHash)
3498 return true;
3501 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3503 if (pRev->ParentsCount() > 1)
3504 return true;
3505 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3506 if (childrenIt != commitChildren.end())
3508 const std::set<CGitHash> &children = childrenIt->second;
3509 if (children.size() > 1)
3510 return true;
3513 return false;
3516 void CGitLogListBase::ShowGraphColumn(bool bShow)
3518 // HACK to hide graph column
3519 if (bShow)
3520 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3521 else
3522 SetColumnWidth(0, 0);
3525 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3527 CString cmd;
3528 CString output;
3530 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3532 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3533 for (size_t i = 0; i < vector.size(); ++i)
3535 if (vector[i].Find(_T("refs/tags/")) == 0)
3537 CString tag = vector[i];
3538 int start = vector[i].Find(_T("^{}"));
3539 if (start > 0)
3540 tag = tag.Left(start);
3541 else
3542 continue;
3544 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3545 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3546 output.AppendChar(_T('\n'));
3551 return output;
3554 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3557 pShownlist->SafeRemoveAll();
3559 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3560 bool bRegex = false;
3561 if (m_bFilterWithRegex)
3562 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3564 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3565 CString sRev;
3566 for (DWORD i=0; i<m_logEntries.size(); ++i)
3568 if ((bRegex)&&(m_bFilterWithRegex))
3570 #if 0
3571 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3573 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3574 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3576 pShownlist->SafeAdd(m_logEntries[i]);
3577 continue;
3580 #endif
3581 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3583 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3584 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3586 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3587 continue;
3590 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3592 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3593 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3595 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3596 continue;
3599 if (m_SelectedFilters & LOGFILTER_PATHS)
3601 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3603 bool bGoing = true;
3604 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3606 CTGitPath cpath = pathList[cpPathIndex];
3607 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3609 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3610 bGoing = false;
3611 continue;
3613 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3615 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3616 bGoing = false;
3617 continue;
3619 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3621 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3622 bGoing = false;
3623 continue;
3627 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3629 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3631 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3632 continue;
3635 if (m_SelectedFilters & LOGFILTER_EMAILS)
3637 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3639 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3640 continue;
3643 if (m_SelectedFilters & LOGFILTER_REVS)
3645 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3646 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3648 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3649 continue;
3652 if (m_SelectedFilters & LOGFILTER_REFNAME)
3654 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3655 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3657 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3659 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3660 continue;
3664 } // if (bRegex)
3665 else
3667 CString find = m_sFilterText;
3668 if (!m_bFilterCaseSensitively)
3669 find.MakeLower();
3670 #if 0
3671 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3673 CString sBugIDs = m_logEntries[i]->sBugIDs;
3675 if (!m_bFilterCaseSensitively)
3676 sBugIDs = sBugIDs.MakeLower();
3677 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3679 pShownlist->SafeAdd(m_logEntries[i]);
3680 continue;
3683 #endif
3684 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3686 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3688 if (!m_bFilterCaseSensitively)
3689 msg = msg.MakeLower();
3690 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3692 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3693 continue;
3696 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3698 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3700 if (!m_bFilterCaseSensitively)
3701 msg = msg.MakeLower();
3702 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3704 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3705 continue;
3708 if (m_SelectedFilters & LOGFILTER_PATHS)
3710 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3712 bool bGoing = true;
3713 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3715 CTGitPath cpath = pathList[cpPathIndex];
3716 CString path = cpath.GetGitOldPathString();
3717 if (!m_bFilterCaseSensitively)
3718 path.MakeLower();
3719 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3721 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3722 bGoing = false;
3723 continue;
3725 path = cpath.GetGitPathString();
3726 if (!m_bFilterCaseSensitively)
3727 path.MakeLower();
3728 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3730 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3731 bGoing = false;
3732 continue;
3734 path = cpath.GetActionName();
3735 if (!m_bFilterCaseSensitively)
3736 path.MakeLower();
3737 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3739 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3740 bGoing = false;
3741 continue;
3745 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3747 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3748 if (!m_bFilterCaseSensitively)
3749 msg = msg.MakeLower();
3750 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3752 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3753 continue;
3756 if (m_SelectedFilters & LOGFILTER_EMAILS)
3758 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3759 if (!m_bFilterCaseSensitively)
3760 msg = msg.MakeLower();
3761 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3763 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3764 continue;
3767 if (m_SelectedFilters & LOGFILTER_REVS)
3769 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3770 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3772 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3773 continue;
3776 if (m_SelectedFilters & LOGFILTER_REFNAME)
3778 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3779 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3781 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3783 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3784 continue;
3788 } // else (from if (bRegex))
3789 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3793 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3796 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3798 if(m_From == -1)
3799 if(m_To == -1)
3800 return true;
3801 else
3802 return time <= m_To;
3803 else
3804 if(m_To == -1)
3805 return time >= m_From;
3806 else
3807 return ((time >= m_From)&&(time <= m_To));
3809 return TRUE; /* git dll will filter time range */
3811 // return TRUE;
3813 void CGitLogListBase::StartFilter()
3815 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3816 RecalculateShownList(&m_arShownList);
3817 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3820 DeleteAllItems();
3821 SetItemCountEx(ShownCountWithStopped());
3822 RedrawItems(0, ShownCountWithStopped());
3823 Invalidate();
3826 void CGitLogListBase::RemoveFilter()
3829 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3831 m_arShownList.SafeRemoveAll();
3833 // reset the time filter too
3834 #if 0
3835 m_timFrom = (__time64_t(m_tFrom));
3836 m_timTo = (__time64_t(m_tTo));
3837 m_DateFrom.SetTime(&m_timFrom);
3838 m_DateTo.SetTime(&m_timTo);
3839 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3840 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3841 #endif
3843 for (DWORD i=0; i<m_logEntries.size(); ++i)
3845 if(this->m_IsOldFirst)
3847 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3849 else
3851 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3854 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3855 DeleteAllItems();
3856 SetItemCountEx(ShownCountWithStopped());
3857 RedrawItems(0, ShownCountWithStopped());
3859 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3862 void CGitLogListBase::Clear()
3864 m_arShownList.SafeRemoveAll();
3865 DeleteAllItems();
3867 m_logEntries.ClearAll();
3871 void CGitLogListBase::OnDestroy()
3873 // save the column widths to the registry
3874 SaveColumnWidths();
3876 SafeTerminateThread();
3877 SafeTerminateAsyncDiffThread();
3879 int retry = 0;
3880 while(m_LogCache.SaveCache())
3882 if(retry > 5)
3883 break;
3884 Sleep(1000);
3886 ++retry;
3888 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3889 // MB_YESNO) == IDNO)
3890 // break;
3893 CHintListCtrl::OnDestroy();
3896 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3898 CRect rect;
3899 int i=(int)wParam;
3900 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3901 this->InvalidateRect(rect);
3903 return 0;
3907 * Save column widths to the registry
3909 void CGitLogListBase::SaveColumnWidths()
3911 int maxcol = m_ColumnManager.GetColumnCount();
3913 // HACK that graph column is always shown
3914 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3916 for (int col = 0; col < maxcol; ++col)
3917 if (m_ColumnManager.IsVisible (col))
3918 m_ColumnManager.ColumnResized (col);
3920 m_ColumnManager.WriteSettings();
3923 int CGitLogListBase::GetHeadIndex()
3925 if(m_HeadHash.IsEmpty())
3926 return -1;
3928 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3930 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3931 if(pRev)
3933 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3934 return i;
3937 return -1;
3939 void CGitLogListBase::OnFind()
3941 if (!m_pFindDialog)
3943 m_pFindDialog = new CFindDlg(this);
3944 m_pFindDialog->Create(this);
3947 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3949 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3951 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3953 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3954 Default();
3956 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3958 if (GetSelectedCount() != 0)
3959 return 0;
3961 CGitHash theSelectedHash = m_lastSelectedHash;
3962 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3963 m_lastSelectedHash = theSelectedHash;
3965 int countPerPage = GetCountPerPage();
3966 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3967 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3968 EnsureVisible((int)itemToSelect, FALSE);
3969 return 0;
3971 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3974 ASSERT(m_pFindDialog != NULL);
3975 bool bFound = false;
3976 int i=0;
3978 if (m_pFindDialog->IsTerminating())
3980 // invalidate the handle identifying the dialog box.
3981 m_pFindDialog = NULL;
3982 return 0;
3985 INT_PTR cnt = m_arShownList.GetCount();
3987 if(m_pFindDialog->IsRef())
3989 CString str;
3990 str=m_pFindDialog->GetFindString();
3992 CGitHash hash;
3994 if(!str.IsEmpty())
3996 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3997 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
4000 if(!hash.IsEmpty())
4002 for (i = 0; i < cnt; ++i)
4004 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4005 if(pLogEntry && pLogEntry->m_CommitHash == hash)
4007 bFound = true;
4008 break;
4012 if (!bFound)
4014 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
4015 return 0;
4019 if (m_pFindDialog->FindNext() && !bFound)
4021 //read data from dialog
4022 CString findText = m_pFindDialog->GetFindString();
4023 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
4025 std::tr1::wregex pat;
4026 bool bRegex = false;
4027 if (m_pFindDialog->Regex())
4028 bRegex = ValidateRegexp(findText, pat, bMatchCase);
4030 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
4032 for (i = m_nSearchIndex + 1; ; ++i)
4034 if (i >= cnt)
4036 i = 0;
4037 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
4039 if (m_nSearchIndex >= 0)
4041 if (i == m_nSearchIndex)
4043 ::MessageBeep(0xFFFFFFFF);
4044 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
4045 break;
4049 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
4051 CString str;
4052 str+=pLogEntry->m_CommitHash.ToString();
4053 str += _T('\n');
4055 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4057 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4058 str += _T('\n');
4061 str+=pLogEntry->GetAuthorEmail();
4062 str += _T('\n');
4063 str+=pLogEntry->GetAuthorName();
4064 str += _T('\n');
4065 str+=pLogEntry->GetBody();
4066 str += _T('\n');
4067 str+=pLogEntry->GetCommitterEmail();
4068 str += _T('\n');
4069 str+=pLogEntry->GetCommitterName();
4070 str += _T('\n');
4071 str+=pLogEntry->GetSubject();
4072 str += _T('\n');
4073 str+=pLogEntry->m_Notes;
4074 str += _T('\n');
4075 str+=GetTagInfo(pLogEntry);
4076 str += _T('\n');
4079 /*Because changed files list is loaded on demand when gui show,
4080 files will empty when files have not fetched.
4082 we can add it back by using one-way diff(with outnumber changed and rename detect.
4083 here just need changed filename list. one-way is much quicker.
4085 if(pLogEntry->m_IsFull)
4087 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4089 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4090 str += _T('\n');
4091 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4092 str += _T('\n');
4095 else
4097 if(!pLogEntry->m_IsSimpleListReady)
4098 pLogEntry->SafeGetSimpleList(&g_Git);
4100 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4102 str += pLogEntry->m_SimpleFileList[j];
4103 str += _T('\n');
4109 if (bRegex)
4111 if (std::regex_search(std::wstring(str), pat, flags))
4113 bFound = true;
4114 break;
4117 else
4119 if (bMatchCase)
4121 if (str.Find(findText) >= 0)
4123 bFound = true;
4124 break;
4128 else
4130 CString msg = str;
4131 msg = msg.MakeLower();
4132 CString find = findText.MakeLower();
4133 if (msg.Find(find) >= 0)
4135 bFound = TRUE;
4136 break;
4140 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4142 } // if(m_pFindDialog->FindNext())
4143 //UpdateLogInfoLabel();
4145 if (bFound)
4147 m_nSearchIndex = i;
4148 EnsureVisible(i, FALSE);
4149 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4151 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4152 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4153 SetSelectionMark(i);
4155 else
4157 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4158 if (pLogEntry)
4159 m_highlight = pLogEntry->m_CommitHash;
4161 Invalidate();
4162 //FillLogMessageCtrl();
4163 UpdateData(FALSE);
4166 return 0;
4169 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4171 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4173 *pResult = FALSE;
4176 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4178 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4180 Invalidate(FALSE);
4183 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4185 LVHITTESTINFO lvhitTestInfo;
4187 lvhitTestInfo.pt = point;
4189 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4190 int nSubItem = lvhitTestInfo.iSubItem;
4192 UINT nFlags = lvhitTestInfo.flags;
4194 // nFlags is 0 if the SubItemHitTest fails
4195 // Therefore, 0 & <anything> will equal false
4196 if (nFlags & LVHT_ONITEM)
4198 // Get the client area occupied by this control
4199 RECT rcClient;
4200 GetClientRect(&rcClient);
4202 // Fill in the TOOLINFO structure
4203 pTI->hwnd = m_hWnd;
4204 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4205 pTI->lpszText = LPSTR_TEXTCALLBACK;
4206 pTI->rect = rcClient;
4208 return pTI->uId; // By returning a unique value per listItem,
4209 // we ensure that when the mouse moves over another list item,
4210 // the tooltip will change
4212 else
4214 // Otherwise, we aren't interested, so let the message propagate
4215 return -1;
4219 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4221 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4222 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4224 *pResult = 0;
4226 // Ignore messages from the built in tooltip, we are processing them internally
4227 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4228 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4229 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4230 return FALSE;
4232 // Get the mouse position
4233 const MSG* pMessage = GetCurrentMessage();
4235 CPoint pt;
4236 pt = pMessage->pt;
4237 ScreenToClient(&pt);
4239 // Check if the point falls onto a list item
4240 LVHITTESTINFO lvhitTestInfo;
4241 lvhitTestInfo.pt = pt;
4243 int nItem = SubItemHitTest(&lvhitTestInfo);
4245 if (lvhitTestInfo.flags & LVHT_ONITEM)
4247 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4248 if (strTipText.IsEmpty())
4249 return FALSE;
4251 // we want multiline tooltips
4252 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4254 wcscpy_s(m_wszTip, strTipText);
4255 // handle Unicode as well as non-Unicode requests
4256 if (pNMHDR->code == TTN_NEEDTEXTA)
4258 pTTTA->hinst = nullptr;
4259 pTTTA->lpszText = m_szTip;
4260 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4262 else
4264 pTTTW->hinst = nullptr;
4265 pTTTW->lpszText = m_wszTip;
4268 CRect rect;
4269 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4270 ClientToScreen(rect);
4271 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4273 return TRUE; // We found a tool tip,
4274 // tell the framework this message has been handled
4277 return FALSE; // We didn't handle the message,
4278 // let the framework continue propagating the message
4281 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4283 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4285 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4286 if (pLogEntry == nullptr)
4287 return CString();
4288 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4289 return CString();
4290 return pLogEntry->GetSubject();
4292 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4294 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4295 if (pLogEntry == nullptr)
4296 return CString();
4297 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4299 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4301 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4302 if (pLogEntry == nullptr)
4303 return CString();
4304 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4306 else if (nSubItem == LOGLIST_ACTION)
4308 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4309 if (pLogEntry == nullptr)
4310 return CString();
4312 if (!pLogEntry->m_IsDiffFiles)
4313 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4315 int actions = pLogEntry->GetAction(this);
4316 CString sToolTipText;
4318 CString actionText;
4319 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4320 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4322 if (actions & CTGitPath::LOGACTIONS_ADDED)
4324 if (!actionText.IsEmpty())
4325 actionText += L"\r\n";
4326 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4329 if (actions & CTGitPath::LOGACTIONS_DELETED)
4331 if (!actionText.IsEmpty())
4332 actionText += L"\r\n";
4333 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4336 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4338 if (!actionText.IsEmpty())
4339 actionText += L"\r\n";
4340 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4343 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4345 if (!actionText.IsEmpty())
4346 actionText += L"\r\n";
4347 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4350 if (!actionText.IsEmpty())
4352 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4353 sToolTipText = sTitle + L":\r\n" + actionText;
4355 return sToolTipText;
4357 return CString();