CommitDlg: Update empty file list message
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob3a1212c0a627b3e24ea2af67aaf9b7065c4d9e94
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_pStoreSelection(NULL)
53 , m_SelectedFilters(LOGFILTER_ALL)
54 , m_ShowFilter(FILTERSHOW_ALL)
55 , m_bShowWC(false)
56 , m_logEntries(&m_LogCache)
57 , m_pFindDialog(NULL)
58 , m_ColumnManager(this)
59 , m_dwDefaultColumns(0)
60 , m_arShownList(&m_critSec)
61 , m_hasWC(true)
62 , m_bNoHightlightHead(FALSE)
63 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
64 , m_bFullCommitMessageOnLogLine(false)
66 // use the default GUI font, create a copy of it and
67 // change the copy to BOLD (leave the rest of the font
68 // the same)
69 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
70 LOGFONT lf = {0};
71 GetObject(hFont, sizeof(LOGFONT), &lf);
72 lf.lfWeight = FW_BOLD;
73 m_boldFont = CreateFontIndirect(&lf);
74 lf.lfWeight = FW_DONTCARE;
75 lf.lfItalic = TRUE;
76 m_FontItalics = CreateFontIndirect(&lf);
77 lf.lfWeight = FW_BOLD;
78 m_boldItalicsFont = CreateFontIndirect(&lf);
80 m_bShowBugtraqColumn=false;
82 m_IsIDReplaceAction=FALSE;
84 this->m_critSec.Init();
85 m_critSec_AsyncDiff.Init();
86 ResetWcRev(false);
88 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
89 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
90 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
91 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
92 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
93 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
95 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
96 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
98 m_From = -1;
99 m_To = -1;
101 m_ShowMask = 0;
102 m_LoadingThread = NULL;
104 InterlockedExchange(&m_bExitThread,FALSE);
105 m_IsOldFirst = FALSE;
106 m_IsRebaseReplaceGraph = FALSE;
108 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
110 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
112 // get short/long datetime setting from registry
113 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
114 if ( RegUseShortDateFormat )
116 m_DateFormat = DATE_SHORTDATE;
118 else
120 m_DateFormat = DATE_LONGDATE;
122 // get relative time display setting from registry
123 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
124 m_bRelativeTimes = (regRelativeTimes != 0);
125 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
127 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
128 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
129 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
130 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
131 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
132 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
133 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
135 m_ColumnRegKey=_T("log");
137 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
138 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
139 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
140 m_bFullCommitMessageOnLogLine = !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE);
142 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
143 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
145 m_AsyncThreadExit = FALSE;
146 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
147 m_AsynDiffListLock.Init();
149 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
150 if (hUxTheme)
151 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
153 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
154 if (m_DiffingThread ==NULL)
156 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
157 return;
162 int CGitLogListBase::AsyncDiffThread()
164 m_AsyncThreadExited = false;
165 while(!m_AsyncThreadExit)
167 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
169 GitRevLoglist* pRev = nullptr;
170 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
172 m_AsynDiffListLock.Lock();
173 pRev = m_AsynDiffList.back();
174 m_AsynDiffList.pop_back();
175 m_AsynDiffListLock.Unlock();
177 if( pRev->m_CommitHash.IsEmpty() )
179 if(pRev->m_IsDiffFiles)
180 continue;
182 CTGitPathList& files = pRev->GetFiles(this);
183 files.Clear();
184 pRev->m_ParentHash.clear();
185 pRev->m_ParentHash.push_back(m_HeadHash);
186 g_Git.GetWorkingTreeChanges(files);
187 int& action = pRev->GetAction(this);
188 action = 0;
189 for (int j = 0; j < files.GetCount(); ++j)
190 action |= files[j].m_Action;
192 CString err;
193 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
195 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
196 return -1;
199 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
200 InterlockedExchange(&pRev->m_IsFull, TRUE);
202 pRev->GetBody().Format(IDS_FILESCHANGES, files.GetCount());
203 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
204 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
207 m_critSec_AsyncDiff.Lock();
208 int ret = pRev->CheckAndDiff();
209 m_critSec_AsyncDiff.Unlock();
210 if (!ret)
211 { // fetch change file list
212 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
214 if(i < m_arShownList.GetCount())
216 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
217 if(data->m_CommitHash == pRev->m_CommitHash)
219 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
220 break;
225 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
227 POSITION pos = GetFirstSelectedItemPosition();
228 int nItem = GetNextSelectedItem(pos);
230 if(nItem>=0)
232 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
233 if(data)
234 if(data->m_CommitHash == pRev->m_CommitHash)
236 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
243 m_AsyncThreadExited = true;
244 return 0;
246 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
248 if (exclusivelyShow)
250 m_ContextMenuMask &= hideMask;
252 else
254 m_ContextMenuMask &= ~hideMask;
258 CGitLogListBase::~CGitLogListBase()
260 InterlockedExchange(&m_bNoDispUpdates, TRUE);
261 this->m_arShownList.SafeRemoveAll();
263 DestroyIcon(m_hModifiedIcon);
264 DestroyIcon(m_hReplacedIcon);
265 DestroyIcon(m_hConflictedIcon);
266 DestroyIcon(m_hAddedIcon);
267 DestroyIcon(m_hDeletedIcon);
268 m_logEntries.ClearAll();
270 if (m_boldFont)
271 DeleteObject(m_boldFont);
273 if (m_FontItalics)
274 DeleteObject(m_FontItalics);
276 if (m_boldItalicsFont)
277 DeleteObject(m_boldItalicsFont);
279 if ( m_pStoreSelection )
281 delete m_pStoreSelection;
282 m_pStoreSelection = NULL;
285 SafeTerminateThread();
286 SafeTerminateAsyncDiffThread();
288 if(m_AsyncDiffEvent)
289 CloseHandle(m_AsyncDiffEvent);
291 if (hUxTheme)
292 FreeLibrary(hUxTheme);
296 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
297 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
298 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
299 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
300 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
301 ON_WM_CONTEXTMENU()
302 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
303 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
304 ON_WM_CREATE()
305 ON_WM_DESTROY()
306 ON_MESSAGE(MSG_LOADED,OnLoad)
307 ON_WM_MEASUREITEM()
308 ON_WM_MEASUREITEM_REFLECT()
309 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
310 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
311 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
312 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
313 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
314 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
315 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
316 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
317 END_MESSAGE_MAP()
319 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
321 //if (m_nRowHeight>0)
323 lpMeasureItemStruct->itemHeight = 50;
327 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
329 PreSubclassWindow();
330 return CHintListCtrl::OnCreate(lpCreateStruct);
333 void CGitLogListBase::PreSubclassWindow()
335 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
336 // load the icons for the action columns
337 // m_Theme.Open(m_hWnd, L"ListView");
338 SetWindowTheme(m_hWnd, L"Explorer", NULL);
339 CHintListCtrl::PreSubclassWindow();
342 CString CGitLogListBase::GetRebaseActionName(int action)
344 if (action & LOGACTIONS_REBASE_EDIT)
345 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
346 if (action & LOGACTIONS_REBASE_SQUASH)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
348 if (action & LOGACTIONS_REBASE_PICK)
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
350 if (action & LOGACTIONS_REBASE_SKIP)
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
356 void CGitLogListBase::InsertGitColumn()
358 CString temp;
360 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
361 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
362 if (DWORD(regFullRowSelect))
363 exStyle |= LVS_EX_FULLROWSELECT;
364 SetExtendedStyle(exStyle);
366 // only load properties if we have a repository
367 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
368 UpdateProjectProperties();
370 static UINT normal[] =
372 IDS_LOG_GRAPH,
373 IDS_LOG_REBASE,
374 IDS_LOG_ID,
375 IDS_LOG_HASH,
376 IDS_LOG_ACTIONS,
377 IDS_LOG_MESSAGE,
378 IDS_LOG_AUTHOR,
379 IDS_LOG_DATE,
380 IDS_LOG_EMAIL,
381 IDS_LOG_COMMIT_NAME,
382 IDS_LOG_COMMIT_EMAIL,
383 IDS_LOG_COMMIT_DATE,
384 IDS_LOG_BUGIDS,
385 IDS_LOG_SVNREV,
388 static int with[] =
390 ICONITEMBORDER+16*4,
391 ICONITEMBORDER+16*4,
392 ICONITEMBORDER+16*4,
393 ICONITEMBORDER+16*4,
394 ICONITEMBORDER+16*4,
395 LOGLIST_MESSAGE_MIN,
396 ICONITEMBORDER+16*4,
397 ICONITEMBORDER+16*4,
398 ICONITEMBORDER+16*4,
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 ICONITEMBORDER+16*4,
402 ICONITEMBORDER+16*4,
403 ICONITEMBORDER+16*4,
405 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
407 DWORD hideColumns = 0;
408 if(this->m_IsRebaseReplaceGraph)
410 hideColumns |= GIT_LOG_GRAPH;
411 m_dwDefaultColumns |= GIT_LOG_REBASE;
413 else
415 hideColumns |= GIT_LOG_REBASE;
418 if(this->m_IsIDReplaceAction)
420 hideColumns |= GIT_LOG_ACTIONS;
421 m_dwDefaultColumns |= GIT_LOG_ID;
422 m_dwDefaultColumns |= GIT_LOG_HASH;
424 else
426 hideColumns |= GIT_LOG_ID;
428 if(this->m_bShowBugtraqColumn)
430 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
432 else
434 hideColumns |= GIT_LOGLIST_BUG;
436 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
437 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
438 else
439 hideColumns |= GIT_LOGLIST_SVNREV;
440 SetRedraw(false);
442 m_ColumnManager.SetNames(normal, _countof(normal));
443 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
445 SetRedraw(true);
449 * Resizes all columns in a list control to values in registry.
451 void CGitLogListBase::ResizeAllListCtrlCols()
453 // column max and min widths to allow
454 static const int nMinimumWidth = 10;
455 static const int nMaximumWidth = 1000;
456 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
457 if (pHdrCtrl)
459 int numcols = pHdrCtrl->GetItemCount();
460 for (int col = 0; col < numcols; ++col)
462 // get width for this col last time from registry
463 CString regentry;
464 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR)m_ColumnRegKey, col);
465 CRegDWORD regwidth(regentry, 0);
466 int cx = regwidth;
467 if ( cx == 0 )
469 // no saved value, setup sensible defaults
470 if (col == this->LOGLIST_MESSAGE)
472 cx = LOGLIST_MESSAGE_MIN;
474 else
476 cx = ICONITEMBORDER+16*4;
479 if (cx < nMinimumWidth)
481 cx = nMinimumWidth;
483 else if (cx > nMaximumWidth)
485 cx = nMaximumWidth;
488 SetColumnWidth(col, cx);
495 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
497 LVITEM rItem;
498 SecureZeroMemory(&rItem, sizeof(LVITEM));
499 rItem.mask = LVIF_STATE;
500 rItem.iItem = (int)Index;
501 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
502 GetItem(&rItem);
504 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index);
505 HBRUSH brush = NULL;
507 if (!(rItem.state & LVIS_SELECTED))
509 int action = pLogEntry->GetRebaseAction();
510 if (action & LOGACTIONS_REBASE_SQUASH)
511 brush = ::CreateSolidBrush(RGB(156,156,156));
512 else if (action & LOGACTIONS_REBASE_EDIT)
513 brush = ::CreateSolidBrush(RGB(200,200,128));
515 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
517 if (rItem.state & LVIS_SELECTED)
519 if (::GetFocus() == m_hWnd)
520 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
521 else
522 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
525 if (brush != NULL)
527 ::FillRect(hdc, &rect, brush);
528 ::DeleteObject(brush);
532 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
534 POINT point = { 4, 4 };
535 CRect rt2 = rect;
536 rt2.DeflateRect(1, 1);
537 rt2.OffsetRect(2, 2);
539 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
540 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
541 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
542 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
543 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
545 ::SelectObject(hdc, brush);
546 rt2.OffsetRect(-2, -2);
547 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
548 ::SelectObject(hdc, oldbrush);
549 ::SelectObject(hdc, oldpen);
550 ::DeleteObject(nullPen);
551 ::DeleteObject(darkBrush);
554 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
556 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
557 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
558 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
559 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
560 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
561 ::LineTo(hdc, rect.left, rect.bottom);
562 ::SelectObject(hdc, oldpen);
563 ::DeleteObject(pen);
566 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
568 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
569 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
570 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
571 ::LineTo(hdc, rect.left, rect.bottom);
572 ::LineTo(hdc, rect.right, rect.bottom);
573 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
574 ::SelectObject(hdc, oldpen);
575 ::DeleteObject(pen);
578 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
580 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
581 CRect rt=rect;
582 LVITEM rItem;
583 SecureZeroMemory(&rItem, sizeof(LVITEM));
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 bool annotatedTag = refList[i].annotatedTag;
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 (annotatedTag)
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;
1091 SecureZeroMemory(&rItem, sizeof(LVITEM));
1092 rItem.mask = LVIF_STATE;
1093 rItem.iItem = (int)index;
1094 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1095 GetItem(&rItem);
1097 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1099 if (data->m_Lanes.empty())
1100 m_logEntries.setLane(data->m_CommitHash);
1102 std::vector<int>& lanes=data->m_Lanes;
1103 size_t laneNum = lanes.size();
1104 UINT activeLane = 0;
1105 for (UINT i = 0; i < laneNum; ++i)
1106 if (Lanes::isMerge(lanes[i])) {
1107 activeLane = i;
1108 break;
1111 int x2 = 0;
1112 int maxWidth = rect.Width();
1113 int lw = 3 * rect.Height() / 4; //laneWidth()
1115 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1116 //if (opt.state & QStyle::State_Selected)
1117 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1119 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1122 int x1 = x2;
1123 x2 += lw;
1125 int ln = lanes[i];
1126 if (ln == Lanes::EMPTY)
1127 continue;
1129 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1130 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1133 #if 0
1134 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1136 int x1 = x2;
1137 x2 += lw;
1139 int ln = lanes[i];
1140 if (ln == Lanes::EMPTY)
1141 continue;
1143 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1144 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1146 if (ln == Lanes::CROSS)
1148 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1149 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1151 else
1152 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1154 #endif
1158 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1161 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1162 // Take the default processing unless we set this to something else below.
1163 *pResult = CDRF_DODEFAULT;
1165 if (m_bNoDispUpdates)
1166 return;
1168 switch (pLVCD->nmcd.dwDrawStage)
1170 case CDDS_PREPAINT:
1172 *pResult = CDRF_NOTIFYITEMDRAW;
1173 return;
1175 break;
1176 case CDDS_ITEMPREPAINT:
1178 // This is the prepaint stage for an item. Here's where we set the
1179 // item's text color.
1181 // Tell Windows to send draw notifications for each subitem.
1182 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1184 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1186 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1188 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1189 if (data)
1191 HGDIOBJ hGdiObj = nullptr;
1192 int action = data->GetRebaseAction();
1193 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1194 crText = RGB(128,128,128);
1196 if (action & LOGACTIONS_REBASE_SQUASH)
1197 pLVCD->clrTextBk = RGB(156,156,156);
1198 else if (action & LOGACTIONS_REBASE_EDIT)
1199 pLVCD->clrTextBk = RGB(200,200,128);
1200 else
1201 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1203 if (action & LOGACTIONS_REBASE_CURRENT)
1204 hGdiObj = m_boldFont;
1206 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1207 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1208 if (isHeadHash && isHighlight)
1209 hGdiObj = m_boldItalicsFont;
1210 else if (isHeadHash)
1211 hGdiObj = m_boldFont;
1212 else if (isHighlight)
1213 hGdiObj = m_FontItalics;
1215 if (hGdiObj)
1217 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1218 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1221 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1222 // crText = GetSysColor(COLOR_GRAYTEXT);
1224 if (data->m_CommitHash.IsEmpty())
1226 //crText = GetSysColor(RGB(200,200,0));
1227 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1228 // We changed the font, so we're returning CDRF_NEWFONT. This
1229 // tells the control to recalculate the extent of the text.
1230 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1234 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1236 if (m_bStrictStopped)
1237 crText = GetSysColor(COLOR_GRAYTEXT);
1239 // Store the color back in the NMLVCUSTOMDRAW struct.
1240 pLVCD->clrText = crText;
1241 return;
1243 break;
1244 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1246 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1248 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1251 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1253 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1255 CRect rect;
1256 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1258 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1259 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1261 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1262 if( !data ->m_CommitHash.IsEmpty())
1263 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1265 *pResult = CDRF_SKIPDEFAULT;
1266 return;
1270 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1272 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1274 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1276 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1278 CRect rect;
1279 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1281 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1282 // not in FillBackGround method, because this only affected the message subitem
1283 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1284 return;
1286 int index = (int)pLVCD->nmcd.dwItemSpec;
1287 int state = GetItemState(index, LVIS_SELECTED);
1288 int txtState = LISS_NORMAL;
1289 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1291 if (state & LVIS_SELECTED)
1292 txtState = LISS_HOTSELECTED;
1293 else
1294 txtState = LISS_HOT;
1296 else if (state & LVIS_SELECTED)
1298 if (::GetFocus() == m_hWnd)
1299 txtState = LISS_SELECTED;
1300 else
1301 txtState = LISS_SELECTEDNOTFOCUS;
1304 HTHEME hTheme = nullptr;
1305 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1306 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1308 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1309 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1310 else
1312 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1313 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1314 ::DeleteObject(brush);
1316 if (hTheme)
1318 CRect rt;
1319 // get rect of whole line
1320 GetItemRect(index, rt, LVIR_BOUNDS);
1321 CRect rect2 = rect;
1322 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1323 rect2.DeflateRect(1, 1, 1, 1);
1325 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1326 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1328 CloseThemeData(hTheme);
1330 // END: extended redraw
1332 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1334 std::vector<REFLABEL> refsToShow;
1335 STRING_VECTOR remoteTrackingList;
1336 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1337 for (unsigned int i = 0; i < refList.size(); ++i)
1339 CString str = refList[i];
1341 REFLABEL refLabel;
1342 refLabel.color = RGB(255, 255, 255);
1343 refLabel.singleRemote = false;
1344 refLabel.hasTracking = false;
1345 refLabel.sameName = false;
1346 refLabel.annotatedTag = false;
1347 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1349 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1350 continue;
1351 if (refLabel.name == m_CurrentBranch )
1352 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1353 else
1354 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1356 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1357 CString pullRemote = trackingEntry.first;
1358 CString pullBranch = trackingEntry.second;
1359 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1361 CString defaultUpstream;
1362 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1363 refLabel.hasTracking = true;
1364 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1366 bool found = false;
1367 for (size_t j = i + 1; j < refList.size(); ++j)
1369 if (refList[j] == defaultUpstream)
1371 found = true;
1372 break;
1376 if (found)
1378 bool sameName = pullBranch == refLabel.name;
1379 refsToShow.push_back(refLabel);
1380 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1381 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1382 if (m_bSymbolizeRefNames)
1384 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1386 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1387 refLabel.singleRemote = true;
1389 else if (sameName)
1390 refLabel.simplifiedName = pullRemote + _T("/");
1391 refLabel.sameName = sameName;
1393 refsToShow.push_back(refLabel);
1394 remoteTrackingList.push_back(defaultUpstream);
1395 continue;
1400 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1402 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1403 continue;
1405 bool found = false;
1406 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1408 if (remoteTrackingList[j] == str)
1410 found = true;
1411 break;
1414 if (found)
1415 continue;
1417 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1418 if (m_bSymbolizeRefNames)
1420 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1422 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1423 refLabel.singleRemote = true;
1427 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1429 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1430 continue;
1431 refLabel.color = m_Colors.GetColor(CColors::Tag);
1432 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1434 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1436 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1437 continue;
1438 refLabel.color = m_Colors.GetColor(CColors::Stash);
1439 refLabel.name = _T("stash");
1441 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1443 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1444 continue;
1445 if (refLabel.name.Find(_T("good")) == 0)
1447 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1448 refLabel.name = _T("good");
1450 if (refLabel.name.Find(_T("bad")) == 0)
1452 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1453 refLabel.name = _T("bad");
1456 else
1457 continue;
1459 refsToShow.push_back(refLabel);
1462 if (refsToShow.empty())
1464 *pResult = CDRF_DODEFAULT;
1465 return;
1468 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1470 *pResult = CDRF_SKIPDEFAULT;
1471 return;
1478 if (pLVCD->iSubItem == LOGLIST_ACTION)
1480 if(this->m_IsIDReplaceAction)
1482 *pResult = CDRF_DODEFAULT;
1483 return;
1485 *pResult = CDRF_DODEFAULT;
1487 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1488 return;
1490 int nIcons = 0;
1491 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1492 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1494 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1495 CRect rect;
1496 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1497 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1498 // Get the selected state of the
1499 // item being drawn.
1501 // Fill the background if necessary
1502 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1504 // Draw the icon(s) into the compatible DC
1505 int action = pLogEntry->GetAction(this);
1506 if (!pLogEntry->m_IsDiffFiles)
1508 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1509 *pResult = CDRF_SKIPDEFAULT;
1510 return;
1513 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1514 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1515 ++nIcons;
1517 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1518 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1519 ++nIcons;
1521 if (action & CTGitPath::LOGACTIONS_DELETED)
1522 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1523 ++nIcons;
1525 if (action & CTGitPath::LOGACTIONS_REPLACED)
1526 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1527 ++nIcons;
1529 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1530 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1531 ++nIcons;
1533 *pResult = CDRF_SKIPDEFAULT;
1534 return;
1537 break;
1539 *pResult = CDRF_DODEFAULT;
1542 CString FindSVNRev(const CString& msg)
1546 const std::tr1::wsregex_iterator end;
1547 std::wstring s = msg;
1548 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1549 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex1); it != end; ++it)
1551 const std::tr1::wsmatch match = *it;
1552 if (match.size() == 4)
1554 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1555 return std::wstring(match[2]).c_str();
1558 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1559 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex2); it != end; ++it)
1561 const std::tr1::wsmatch match = *it;
1562 if (match.size() == 3)
1564 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1565 return std::wstring(match[1]).c_str();
1569 catch (std::exception) {}
1571 return _T("");
1574 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1576 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1577 return pLogEntry->GetSubject();
1579 CString txt;
1580 txt.Format(L"%s %s", (LPCTSTR)pLogEntry->GetSubject(), (LPCTSTR)pLogEntry->GetBody());
1582 // Deal with CRLF
1583 txt.Replace(_T("\n"), _T(" "));
1584 txt.Replace(_T("\r"), _T(" "));
1586 return txt;
1589 // CGitLogListBase message handlers
1591 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1593 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1595 // Create a pointer to the item
1596 LV_ITEM* pItem = &(pDispInfo)->item;
1598 // Do the list need text information?
1599 if (!(pItem->mask & LVIF_TEXT))
1600 return;
1602 // By default, clear text buffer.
1603 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1605 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1607 *pResult = 0;
1608 if (m_bNoDispUpdates || bOutOfRange)
1609 return;
1611 // Which item number?
1612 int itemid = pItem->iItem;
1613 GitRevLoglist* pLogEntry = nullptr;
1614 if (itemid < m_arShownList.GetCount())
1615 pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(pItem->iItem));
1617 CString temp;
1618 if(m_IsOldFirst)
1620 temp.Format(_T("%d"),pItem->iItem+1);
1623 else
1625 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1628 // Which column?
1629 switch (pItem->iSubItem)
1631 case LOGLIST_GRAPH: //Graphic
1632 break;
1633 case LOGLIST_REBASE:
1635 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1636 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1638 break;
1639 case LOGLIST_ACTION: //action -- no text in the column
1640 break;
1641 case LOGLIST_HASH:
1642 if(pLogEntry)
1643 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1644 break;
1645 case LOGLIST_ID:
1646 if(this->m_IsIDReplaceAction)
1647 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1648 break;
1649 case LOGLIST_MESSAGE: //Message
1650 if (pLogEntry)
1651 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1652 break;
1653 case LOGLIST_AUTHOR: //Author
1654 if (pLogEntry)
1655 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1656 break;
1657 case LOGLIST_DATE: //Date
1658 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1659 lstrcpyn(pItem->pszText,
1660 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1661 pItem->cchTextMax - 1);
1662 break;
1664 case LOGLIST_EMAIL:
1665 if (pLogEntry)
1666 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1667 break;
1669 case LOGLIST_COMMIT_NAME: //Commit
1670 if (pLogEntry)
1671 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1672 break;
1674 case LOGLIST_COMMIT_EMAIL: //Commit Email
1675 if (pLogEntry)
1676 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1677 break;
1679 case LOGLIST_COMMIT_DATE: //Commit Date
1680 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1681 lstrcpyn(pItem->pszText,
1682 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1683 pItem->cchTextMax - 1);
1684 break;
1685 case LOGLIST_BUG: //Bug ID
1686 if(pLogEntry)
1687 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax - 1);
1688 break;
1689 case LOGLIST_SVNREV: //SVN revision
1690 if (pLogEntry)
1691 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax - 1);
1692 break;
1694 default:
1695 ASSERT(false);
1699 bool CGitLogListBase::IsOnStash(int index)
1701 GitRevLoglist* rev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index));
1702 if (IsStash(rev))
1703 return true;
1704 if (index > 0)
1706 GitRevLoglist* preRev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index - 1));
1707 if (IsStash(preRev))
1708 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1710 return false;
1713 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1715 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1717 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1718 return true;
1720 return false;
1723 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1725 if (pRev->m_ParentHash.empty())
1727 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1728 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1730 parentHash = pRev->m_ParentHash;
1733 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1736 if (pWnd == GetHeaderCtrl())
1738 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1741 int selIndex = GetSelectionMark();
1742 if (selIndex < 0)
1743 return; // nothing selected, nothing to do with a context menu
1745 // if the user selected the info text telling about not all revisions shown due to
1746 // the "stop on copy/rename" option, we also don't show the context menu
1747 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1748 return;
1750 // if the context menu is invoked through the keyboard, we have to use
1751 // a calculated position on where to anchor the menu on
1752 if ((point.x == -1) && (point.y == -1))
1754 CRect rect;
1755 GetItemRect(selIndex, &rect, LVIR_LABEL);
1756 ClientToScreen(&rect);
1757 point = rect.CenterPoint();
1759 m_nSearchIndex = selIndex;
1760 m_bCancelled = FALSE;
1762 // calculate some information the context menu commands can use
1763 // CString pathURL = GetURLFromPath(m_path);
1765 POSITION pos = GetFirstSelectedItemPosition();
1766 int indexNext = GetNextSelectedItem(pos);
1767 if (indexNext < 0)
1768 return;
1770 GitRevLoglist* pSelLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(indexNext));
1771 if (pSelLogEntry == nullptr)
1772 return;
1773 #if 0
1774 GitRev revSelected = pSelLogEntry->Rev;
1775 GitRev revPrevious = git_revnum_t(revSelected)-1;
1776 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1778 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1780 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1781 if (changedpath->lCopyFromRev)
1782 revPrevious = changedpath->lCopyFromRev;
1785 GitRev revSelected2;
1786 if (pos)
1788 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1789 revSelected2 = pLogEntry->Rev;
1791 bool bAllFromTheSameAuthor = true;
1792 CString firstAuthor;
1793 CLogDataVector selEntries;
1794 GitRev revLowest, revHighest;
1795 GitRevRangeArray revisionRanges;
1797 POSITION pos = GetFirstSelectedItemPosition();
1798 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1799 revisionRanges.AddRevision(pLogEntry->Rev);
1800 selEntries.push_back(pLogEntry);
1801 firstAuthor = pLogEntry->sAuthor;
1802 revLowest = pLogEntry->Rev;
1803 revHighest = pLogEntry->Rev;
1804 while (pos)
1806 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1807 revisionRanges.AddRevision(pLogEntry->Rev);
1808 selEntries.push_back(pLogEntry);
1809 if (firstAuthor.Compare(pLogEntry->sAuthor))
1810 bAllFromTheSameAuthor = false;
1811 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1812 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1816 #endif
1818 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1820 int FirstSelect=-1, LastSelect=-1;
1821 pos = GetFirstSelectedItemPosition();
1822 FirstSelect = GetNextSelectedItem(pos);
1823 while(pos)
1825 LastSelect = GetNextSelectedItem(pos);
1827 //entry is selected, now show the popup menu
1828 CIconMenu popup;
1829 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1831 if (popup.CreatePopupMenu())
1833 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1834 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1835 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1836 bool isStash = IsOnStash(indexNext);
1837 GIT_REV_LIST parentHash;
1838 GetParentHashes(pSelLogEntry, parentHash);
1840 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1841 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1843 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)) && FirstSelect != GetItemCount() - 1 && LastSelect != GetItemCount() - 1)
1844 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1846 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1847 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1849 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1850 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1852 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)))
1853 popup.AppendMenu(MF_SEPARATOR, NULL);
1855 if (GetSelectedCount() == 1)
1858 bool requiresSeparator = false;
1859 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1861 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1863 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1864 requiresSeparator = true;
1867 else
1869 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1871 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1872 requiresSeparator = true;
1874 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1876 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1877 requiresSeparator = true;
1881 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1883 if (parentHash.size() == 1)
1885 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1886 requiresSeparator = true;
1888 else if (parentHash.size() > 1)
1890 blamemenu.CreatePopupMenu();
1891 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1892 for (size_t i = 0; i < parentHash.size(); ++i)
1894 CString str;
1895 str.Format(IDS_PARENT, i + 1);
1896 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1898 requiresSeparator = true;
1902 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1904 if (parentHash.size() == 1)
1906 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1907 requiresSeparator = true;
1909 else if (parentHash.size() > 1)
1911 gnudiffmenu.CreatePopupMenu();
1912 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1914 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1915 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1916 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1918 for (size_t i = 0; i < parentHash.size(); ++i)
1920 CString str;
1921 str.Format(IDS_PARENT, i + 1);
1922 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1924 requiresSeparator = true;
1928 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1930 if (parentHash.size() == 1)
1932 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1933 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1934 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1935 requiresSeparator = true;
1937 else if (parentHash.size() > 1)
1939 diffmenu.CreatePopupMenu();
1940 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1941 for (size_t i = 0; i < parentHash.size(); ++i)
1943 CString str;
1944 str.Format(IDS_PARENT, i + 1);
1945 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1946 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1948 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1949 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1952 requiresSeparator = true;
1956 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1958 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1959 requiresSeparator = true;
1962 if (requiresSeparator)
1963 popup.AppendMenu(MF_SEPARATOR, NULL);
1965 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1967 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1968 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1971 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1973 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1974 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1976 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1977 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1979 popup.AppendMenu(MF_SEPARATOR, NULL);
1982 if (pSelLogEntry->m_CommitHash.IsEmpty())
1984 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1985 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1987 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1988 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1990 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1991 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1993 popup.AppendMenu(MF_SEPARATOR, NULL);
1995 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1996 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1998 popup.AppendMenu(MF_SEPARATOR, NULL);
2002 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2003 // {
2004 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2005 // }
2006 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2007 // {
2008 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2009 // }
2010 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2011 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2012 // {
2013 // popup.AppendMenu(MF_SEPARATOR, NULL);
2014 // }
2016 CString str;
2017 //if (m_hasWC)
2018 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2020 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2022 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2023 GetSelectedCount() == 1)
2024 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2026 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2027 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2029 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
2031 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2032 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2034 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2036 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2037 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2040 // Add Switch Branch express Menu
2041 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2042 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2045 std::vector<CString *> branchs;
2046 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2048 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2049 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2051 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2055 CString str2;
2056 str2.LoadString(IDS_SWITCH_BRANCH);
2058 if(branchs.size() == 1)
2060 str2 += _T(" ");
2061 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2062 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2064 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2067 else if(branchs.size() > 1)
2069 subbranchmenu.CreatePopupMenu();
2070 for (size_t i = 0 ; i < branchs.size(); ++i)
2072 if (*branchs[i] != currentBranch)
2074 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2075 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2079 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2083 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2084 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2086 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2087 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2089 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2090 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2092 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2094 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2095 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2096 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2098 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2099 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2101 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2103 if (parentHash.size() == 1)
2105 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2107 else if (parentHash.size() > 1)
2109 revertmenu.CreatePopupMenu();
2110 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2112 for (size_t i = 0; i < parentHash.size(); ++i)
2114 CString str2;
2115 str2.Format(IDS_PARENT, i + 1);
2116 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2121 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2122 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2124 popup.AppendMenu(MF_SEPARATOR, NULL);
2129 if(!pSelLogEntry->m_Ref.IsEmpty())
2131 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2132 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2133 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2134 popup.AppendMenu(MF_SEPARATOR, NULL);
2137 if (GetSelectedCount() >= 2)
2139 bool bAddSeparator = false;
2140 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2142 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2143 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2146 if (GetSelectedCount() == 2)
2148 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2149 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2151 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2153 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2154 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2155 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2156 CString menu;
2157 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2158 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2159 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2160 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2163 bAddSeparator = true;
2166 if (m_hasWC)
2168 bAddSeparator = true;
2171 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2172 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2174 if (bAddSeparator)
2175 popup.AppendMenu(MF_SEPARATOR, NULL);
2178 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2180 bool bAddSeparator = false;
2181 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2183 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2185 CString head;
2186 int headindex;
2187 headindex = this->GetHeadIndex();
2188 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2190 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2191 CGitHash hashFirst;
2192 if (g_Git.GetHash(hashFirst, head))
2193 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2194 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2195 CGitHash hash;
2196 if (g_Git.GetHash(hash, head))
2197 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2198 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2199 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2200 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2201 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2202 bAddSeparator = true;
2207 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2208 if (GetSelectedCount() >= 2)
2209 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2210 else
2211 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2212 bAddSeparator = true;
2215 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2216 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2217 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2218 bAddSeparator = true;
2221 if (bAddSeparator)
2222 popup.AppendMenu(MF_SEPARATOR, NULL);
2225 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())
2227 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2228 popup.AppendMenu(MF_SEPARATOR, NULL);
2231 if (GetSelectedCount() == 1)
2233 bool bAddSeparator = false;
2234 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2236 // show the push-option only if the log entry has an associated local branch
2237 bool isLocal = false;
2238 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2240 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2241 isLocal = true;
2243 if (isLocal || showExtendedMenu)
2245 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2246 bAddSeparator = true;
2249 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2251 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2252 bAddSeparator = true;
2256 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2258 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2260 std::vector<CString *> branchs;
2261 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2263 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2264 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2266 CString str;
2267 if (branchs.size() == 1)
2269 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2270 str+=_T(" ");
2271 str += *branchs[0];
2272 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2273 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2274 bAddSeparator = true;
2276 else if (branchs.size() > 1)
2278 str.LoadString(IDS_DELETE_BRANCHTAG);
2279 submenu.CreatePopupMenu();
2280 for (size_t i = 0; i < branchs.size(); ++i)
2282 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2283 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2286 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2287 bAddSeparator = true;
2290 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2291 if (bAddSeparator)
2292 popup.AppendMenu(MF_SEPARATOR, NULL);
2293 } // GetSelectedCount() == 1
2295 if (GetSelectedCount() != 0)
2297 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2298 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2299 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2300 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2301 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2302 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2305 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2306 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2308 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2309 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2311 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2312 // DialogEnableWindow(IDOK, FALSE);
2313 // SetPromptApp(&theApp);
2315 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2317 // EnableOKButton();
2318 } // if (popup.CreatePopupMenu())
2322 bool CGitLogListBase::IsSelectionContinuous()
2324 if ( GetSelectedCount()==1 )
2326 // if only one revision is selected, the selection is of course
2327 // continuous
2328 return true;
2331 POSITION pos = GetFirstSelectedItemPosition();
2332 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2333 if (bContinuous)
2335 int itemindex = GetNextSelectedItem(pos);
2336 while (pos)
2338 int nextindex = GetNextSelectedItem(pos);
2339 if (nextindex - itemindex > 1)
2341 bContinuous = false;
2342 break;
2344 itemindex = nextindex;
2347 return bContinuous;
2350 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2353 CString sClipdata;
2354 POSITION pos = GetFirstSelectedItemPosition();
2355 if (pos != NULL)
2357 CString sRev;
2358 sRev.LoadString(IDS_LOG_REVISION);
2359 CString sAuthor;
2360 sAuthor.LoadString(IDS_LOG_AUTHOR);
2361 CString sDate;
2362 sDate.LoadString(IDS_LOG_DATE);
2363 CString sMessage;
2364 sMessage.LoadString(IDS_LOG_MESSAGE);
2365 bool first = true;
2366 while (pos)
2368 CString sLogCopyText;
2369 CString sPaths;
2370 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2372 if (toCopy == ID_COPY_ALL)
2374 //pLogEntry->GetFiles(this)
2375 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2377 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2378 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2380 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2381 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2383 CString rename;
2384 rename.Format(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2385 sPaths += _T(" ") + rename;
2387 sPaths += _T("\r\n");
2389 sPaths.Trim();
2390 CString body = pLogEntry->GetBody();
2391 body.Replace(_T("\n"), _T("\r\n"));
2392 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"),
2393 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2394 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2395 (LPCTSTR)sDate,
2396 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2397 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2398 (LPCTSTR)sPaths);
2399 sClipdata += sLogCopyText;
2401 else if (toCopy == ID_COPY_MESSAGE)
2403 CString body = pLogEntry->GetBody();
2404 body.Replace(_T("\n"), _T("\r\n"));
2405 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2407 else if (toCopy == ID_COPY_SUBJECT)
2409 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2411 else
2413 if (!first)
2414 sClipdata += _T("\r\n");
2415 sClipdata += pLogEntry->m_CommitHash;
2418 first = false;
2420 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2425 void CGitLogListBase::DiffSelectedRevWithPrevious()
2427 if (m_bThreadRunning)
2428 return;
2430 int FirstSelect=-1, LastSelect=-1;
2431 POSITION pos = GetFirstSelectedItemPosition();
2432 FirstSelect = GetNextSelectedItem(pos);
2433 while(pos)
2435 LastSelect = GetNextSelectedItem(pos);
2438 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2440 #if 0
2441 UpdateLogInfoLabel();
2442 int selIndex = m_LogList.GetSelectionMark();
2443 if (selIndex < 0)
2444 return;
2445 int selCount = m_LogList.GetSelectedCount();
2446 if (selCount != 1)
2447 return;
2449 // Find selected entry in the log list
2450 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2451 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2452 long rev1 = pLogEntry->Rev;
2453 long rev2 = rev1-1;
2454 CTGitPath path = m_path;
2456 // See how many files under the relative root were changed in selected revision
2457 int nChanged = 0;
2458 LogChangedPath * changed = NULL;
2459 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2461 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2462 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2464 ++nChanged;
2465 changed = cpath;
2469 if (m_path.IsDirectory() && nChanged == 1)
2471 // We're looking at the log for a directory and only one file under dir was changed in the revision
2472 // Do diff on that file instead of whole directory
2473 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2476 m_bCancelled = FALSE;
2477 DialogEnableWindow(IDOK, FALSE);
2478 SetPromptApp(&theApp);
2479 theApp.DoWaitCursor(1);
2481 if (PromptShown())
2483 GitDiff diff(this, m_hWnd, true);
2484 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2485 diff.SetHEADPeg(m_LogRevision);
2486 diff.ShowCompare(path, rev2, path, rev1);
2488 else
2490 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2493 theApp.DoWaitCursor(-1);
2494 EnableOKButton();
2495 #endif
2498 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2500 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2501 *pResult = -1;
2503 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2504 return;
2505 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2506 return;
2507 if (pFindInfo->lvfi.psz == 0)
2508 return;
2509 #if 0
2510 CString sCmp = pFindInfo->lvfi.psz;
2511 CString sRev;
2512 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2514 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2515 sRev.Format(_T("%ld"), pLogEntry->Rev);
2516 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2518 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2520 *pResult = i;
2521 return;
2524 else
2526 if (sCmp.Compare(sRev)==0)
2528 *pResult = i;
2529 return;
2533 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2535 for (int i=0; i<pFindInfo->iStart; ++i)
2537 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2538 sRev.Format(_T("%ld"), pLogEntry->Rev);
2539 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2541 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2543 *pResult = i;
2544 return;
2547 else
2549 if (sCmp.Compare(sRev)==0)
2551 *pResult = i;
2552 return;
2557 #endif
2558 *pResult = -1;
2561 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2563 ClearText();
2565 this->m_arShownList.SafeRemoveAll();
2567 this->m_logEntries.ClearAll();
2568 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2569 return -1;
2571 SetItemCountEx((int)m_logEntries.size());
2573 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2575 if(m_IsOldFirst)
2577 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2578 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2581 else
2583 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2584 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2588 ReloadHashMap();
2590 if(path)
2591 m_Path=*path;
2592 return 0;
2596 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2598 ClearText();
2600 m_arShownList.SafeRemoveAll();
2602 m_logEntries.ClearAll();
2603 if (m_logEntries.Fill(hashes))
2604 return -1;
2606 SetItemCountEx((int)m_logEntries.size());
2608 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2610 if (m_IsOldFirst)
2612 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2613 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2615 else
2617 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2618 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2622 ReloadHashMap();
2624 return 0;
2627 int CGitLogListBase::BeginFetchLog()
2629 ClearText();
2631 this->m_arShownList.SafeRemoveAll();
2633 this->m_logEntries.ClearAll();
2635 this->m_LogCache.ClearAllParent();
2637 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2639 CTGitPath *path;
2640 if(this->m_Path.IsEmpty())
2641 path=NULL;
2642 else
2643 path=&this->m_Path;
2645 int mask;
2646 mask = CGit::LOG_INFO_ONLY_HASH;
2647 if (m_bIncludeBoundaryCommits)
2648 mask |= CGit::LOG_INFO_BOUNDARY;
2649 // if(this->m_bAllBranch)
2650 mask |= m_ShowMask ;
2652 if(m_bShowWC)
2654 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2655 ResetWcRev();
2656 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2659 if (m_sRange.IsEmpty())
2660 m_sRange = _T("HEAD");
2662 CFilterData data;
2663 data.m_From = m_From;
2664 data.m_To =m_To;
2666 #if 0 /* use tortoiegit filter */
2667 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2668 data.m_Author = this->m_sFilterText;
2670 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2671 data.m_MessageFilter = this->m_sFilterText;
2673 data.m_IsRegex = m_bFilterWithRegex;
2674 #endif
2676 // follow does not work for directories
2677 if (!path || path->IsDirectory())
2678 mask &= ~CGit::LOG_INFO_FOLLOW;
2679 // follow does not work with all branches 8at least in TGit)
2680 if (mask & CGit::LOG_INFO_FOLLOW)
2681 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2683 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2685 //this->m_logEntries.ParserFromLog();
2686 if(IsInWorkingThread())
2688 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2690 else
2692 SetItemCountEx((int)m_logEntries.size());
2697 [] { git_init(); } ();
2699 catch (char* msg)
2701 CString err(msg);
2702 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2703 return -1;
2706 if (!g_Git.CanParseRev(m_sRange))
2708 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2709 return 0;
2711 // if show all branches, pick any ref as dummy entry ref
2712 STRING_VECTOR list;
2713 if (g_Git.GetRefList(list))
2714 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2715 if (list.size() == 0)
2716 return 0;
2718 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2721 g_Git.m_critGitDllSec.Lock();
2722 try {
2723 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2725 g_Git.m_critGitDllSec.Unlock();
2726 return -1;
2729 catch (char* msg)
2731 g_Git.m_critGitDllSec.Unlock();
2732 CString err(msg);
2733 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2734 return -1;
2736 g_Git.m_critGitDllSec.Unlock();
2738 return 0;
2741 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2743 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2745 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2747 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2749 DiffSelectedRevWithPrevious();
2750 return TRUE;
2753 #if 0
2754 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2756 DiffSelectedFile();
2757 return TRUE;
2759 #endif
2761 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2763 // select all entries
2764 for (int i=0; i<GetItemCount(); ++i)
2766 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2768 return TRUE;
2771 #if 0
2772 if (m_hAccel && !bSkipAccelerator)
2774 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2775 if (ret)
2776 return TRUE;
2779 #endif
2780 //m_tooltips.RelayEvent(pMsg);
2781 return __super::PreTranslateMessage(pMsg);
2784 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2786 // a double click on an entry in the revision list has happened
2787 *pResult = 0;
2789 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2790 DiffSelectedRevWithPrevious();
2793 int CGitLogListBase::FetchLogAsync(void * data)
2795 ReloadHashMap();
2796 m_ProcData=data;
2797 m_bExitThread=FALSE;
2798 InterlockedExchange(&m_bThreadRunning, TRUE);
2799 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2800 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2801 if (m_LoadingThread ==NULL)
2803 InterlockedExchange(&m_bThreadRunning, FALSE);
2804 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2805 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2806 return -1;
2808 return 0;
2811 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2813 return ((CGitLogListBase*)pVoid)->LogThread();
2816 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2818 //CTime time;
2819 oldest=CTime::GetCurrentTime();
2820 latest=CTime(1971,1,2,0,0,0);
2821 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2823 if(m_logEntries[i].IsEmpty())
2824 continue;
2826 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2827 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2829 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2830 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2834 if(latest<oldest)
2835 latest=oldest;
2838 UINT CGitLogListBase::LogThread()
2840 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2842 InterlockedExchange(&m_bThreadRunning, TRUE);
2843 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2845 ULONGLONG t1,t2;
2847 if(BeginFetchLog())
2849 InterlockedExchange(&m_bThreadRunning, FALSE);
2850 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2852 return 1;
2855 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2856 bool bRegex = false;
2857 if (m_bFilterWithRegex)
2858 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2860 TRACE(_T("\n===Begin===\n"));
2861 //Update work copy item;
2863 if (!m_logEntries.empty())
2865 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2867 m_arShownList.SafeAdd(pRev);
2871 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2873 // store commit number of the last selected commit/line before the refresh or -1
2874 int lastSelectedHashNItem = -1;
2875 if (m_lastSelectedHash.IsEmpty())
2876 lastSelectedHashNItem = 0;
2878 int ret = 0;
2880 bool shouldWalk = true;
2881 if (!g_Git.CanParseRev(m_sRange))
2883 // walk revisions if show all branches and there exists any ref
2884 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2885 shouldWalk = false;
2886 else
2888 STRING_VECTOR list;
2889 if (g_Git.GetRefList(list))
2890 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2891 if (list.size() == 0)
2892 shouldWalk = false;
2896 if (shouldWalk)
2898 g_Git.m_critGitDllSec.Lock();
2899 int total = 0;
2902 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2903 total = git_get_log_estimate_commit_count(m_DllGitLog);
2905 catch (char* msg)
2907 CString err(msg);
2908 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2909 ret = -1;
2911 g_Git.m_critGitDllSec.Unlock();
2913 GIT_COMMIT commit;
2914 t2=t1=GetTickCount();
2915 int oldprecentage = 0;
2916 size_t oldsize = m_logEntries.size();
2917 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2918 while (ret== 0 && !m_bExitThread)
2920 g_Git.m_critGitDllSec.Lock();
2923 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2925 catch (char* msg)
2927 g_Git.m_critGitDllSec.Unlock();
2928 CString err(msg);
2929 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2930 break;
2932 g_Git.m_critGitDllSec.Unlock();
2934 if(ret)
2936 if (ret != -2) // other than end of revision walking
2937 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2938 break;
2941 if (commit.m_ignore == 1)
2943 git_free_commit(&commit);
2944 continue;
2947 //printf("%s\r\n",commit.GetSubject());
2948 if(m_bExitThread)
2949 break;
2951 CGitHash hash = (char*)commit.m_hash ;
2953 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2954 pRev->m_GitCommit = commit;
2955 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2957 char *note=NULL;
2958 g_Git.m_critGitDllSec.Lock();
2961 git_get_notes(commit.m_hash, &note);
2963 catch (char* msg)
2965 g_Git.m_critGitDllSec.Unlock();
2966 CString err(msg);
2967 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2968 break;
2970 g_Git.m_critGitDllSec.Unlock();
2972 if(note)
2974 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2975 free(note);
2976 note = nullptr;
2979 if(!pRev->m_IsDiffFiles)
2981 pRev->m_CallDiffAsync = DiffAsync;
2984 pRev->ParserParentFromCommit(&commit);
2985 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2987 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2989 const CGitHash &parentHash = pRev->m_ParentHash[i];
2990 auto it = commitChildren.find(parentHash);
2991 if (it == commitChildren.end())
2993 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2995 it->second.insert(pRev->m_CommitHash);
2999 #ifdef DEBUG
3000 pRev->DbgPrint();
3001 TRACE(_T("\n"));
3002 #endif
3004 bool visible = true;
3005 if (HasFilterText())
3007 if(!IsMatchFilter(bRegex,pRev,pat))
3008 visible = false;
3010 if (visible && !ShouldShowFilter(pRev, commitChildren))
3011 visible = false;
3012 this->m_critSec.Lock();
3013 m_logEntries.append(hash, visible);
3014 if (visible)
3015 m_arShownList.SafeAdd(pRev);
3016 this->m_critSec.Unlock();
3018 if (!visible)
3019 continue;
3021 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3022 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3024 t2=GetTickCount();
3026 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3028 //update UI
3029 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3030 if(percent > 99)
3031 percent =99;
3032 if(percent < GITLOG_START)
3033 percent = GITLOG_START +1;
3035 oldsize = m_logEntries.size();
3036 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3038 //if( percent > oldprecentage )
3040 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3041 oldprecentage = percent;
3044 if (lastSelectedHashNItem >= 0)
3045 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3047 t1 = t2;
3050 g_Git.m_critGitDllSec.Lock();
3051 git_close_log(m_DllGitLog);
3052 g_Git.m_critGitDllSec.Unlock();
3056 if (m_bExitThread)
3058 InterlockedExchange(&m_bThreadRunning, FALSE);
3059 return 0;
3062 //Update UI;
3063 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3065 if (lastSelectedHashNItem >= 0)
3066 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3068 if (this->m_hWnd)
3069 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3071 InterlockedExchange(&m_bThreadRunning, FALSE);
3073 return 0;
3076 void CGitLogListBase::FetchRemoteList()
3078 STRING_VECTOR remoteList;
3079 if (!g_Git.GetRemoteList(remoteList))
3080 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3081 else
3082 m_SingleRemote = _T("");
3085 void CGitLogListBase::FetchTrackingBranchList()
3087 m_TrackingMap.clear();
3088 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3090 for (size_t j = 0; j < it->second.size(); ++j)
3092 CString branchName;
3093 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3095 CString pullRemote, pullBranch;
3096 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3097 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3099 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3106 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3108 SafeTerminateThread();
3110 this->SetItemCountEx(0);
3111 this->Clear();
3113 ResetWcRev();
3115 // HACK to hide graph column
3116 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3117 SetColumnWidth(0, 0);
3118 else
3119 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3121 //Update branch and Tag info
3122 ReloadHashMap();
3123 if (m_pFindDialog)
3124 m_pFindDialog->RefreshList();
3125 //Assume Thread have exited
3126 //if(!m_bThreadRunning)
3128 m_logEntries.clear();
3130 if(IsCleanFilter)
3132 m_sFilterText.Empty();
3133 m_From=-1;
3134 m_To=-1;
3137 InterlockedExchange(&m_bExitThread,FALSE);
3139 InterlockedExchange(&m_bThreadRunning, TRUE);
3140 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3141 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3143 InterlockedExchange(&m_bThreadRunning, FALSE);
3144 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3145 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3149 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3153 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3154 if (!bMatchCase)
3155 type |= std::tr1::regex_constants::icase;
3156 pat = std::tr1::wregex(regexp_str, type);
3157 return true;
3159 catch (std::exception) {}
3160 return false;
3162 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3164 BOOL result = TRUE;
3165 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3166 CString sRev;
3168 if ((bRegex)&&(m_bFilterWithRegex))
3170 if (m_SelectedFilters & LOGFILTER_BUGID)
3172 if(this->m_bShowBugtraqColumn)
3174 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3176 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3177 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3179 return TRUE;
3184 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3186 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3187 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3189 return TRUE;
3193 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3195 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3196 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3198 return TRUE;
3202 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3204 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3206 return TRUE;
3209 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3211 return TRUE;
3215 if (m_SelectedFilters & LOGFILTER_EMAILS)
3217 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3219 return TRUE;
3222 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3224 return TRUE;
3228 if (m_SelectedFilters & LOGFILTER_REVS)
3230 sRev = pRev->m_CommitHash.ToString();
3231 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3233 return TRUE;
3237 if (m_SelectedFilters & LOGFILTER_REFNAME)
3239 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3240 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3242 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3244 return TRUE;
3249 if (m_SelectedFilters & LOGFILTER_PATHS)
3251 CTGitPathList *pathList=NULL;
3252 if( pRev->m_IsDiffFiles)
3253 pathList = &pRev->GetFiles(this);
3254 else
3256 if(!pRev->m_IsSimpleListReady)
3257 pRev->SafeGetSimpleList(&g_Git);
3260 if(pathList)
3261 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3263 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3265 return true;
3267 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3269 return true;
3273 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3275 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3277 return true;
3282 else
3284 CString find = m_sFilterText;
3285 if (!m_bFilterCaseSensitively)
3286 find.MakeLower();
3287 result = find[0] == '!' ? FALSE : TRUE;
3288 if (!result)
3289 find = find.Mid(1);
3291 if (m_SelectedFilters & LOGFILTER_BUGID)
3293 if(this->m_bShowBugtraqColumn)
3295 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3297 if (!m_bFilterCaseSensitively)
3298 sBugIds.MakeLower();
3299 if ((sBugIds.Find(find) >= 0))
3301 return result;
3306 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3308 CString msg = pRev->GetSubject();
3310 if (!m_bFilterCaseSensitively)
3311 msg = msg.MakeLower();
3312 if ((msg.Find(find) >= 0))
3314 return result;
3318 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3320 CString msg = pRev->GetBody();
3322 if (!m_bFilterCaseSensitively)
3323 msg = msg.MakeLower();
3324 if ((msg.Find(find) >= 0))
3326 return result;
3330 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3332 CString msg = pRev->GetAuthorName();
3333 if (!m_bFilterCaseSensitively)
3334 msg = msg.MakeLower();
3335 if ((msg.Find(find) >= 0))
3337 return result;
3341 if (m_SelectedFilters & LOGFILTER_EMAILS)
3343 CString msg = pRev->GetAuthorEmail();
3344 if (!m_bFilterCaseSensitively)
3345 msg = msg.MakeLower();
3346 if ((msg.Find(find) >= 0))
3348 return result;
3352 if (m_SelectedFilters & LOGFILTER_REVS)
3354 sRev = pRev->m_CommitHash.ToString();
3355 if ((sRev.Find(find) >= 0))
3357 return result;
3361 if (m_SelectedFilters & LOGFILTER_REFNAME)
3363 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3364 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3366 if (it->Find(find) >= 0)
3368 return result;
3373 if (m_SelectedFilters & LOGFILTER_PATHS)
3375 CTGitPathList *pathList=NULL;
3376 if( pRev->m_IsDiffFiles)
3377 pathList = &pRev->GetFiles(this);
3378 else
3380 if(!pRev->m_IsSimpleListReady)
3381 pRev->SafeGetSimpleList(&g_Git);
3383 if(pathList)
3384 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3386 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3387 CString path = cpath->GetGitOldPathString();
3388 if (!m_bFilterCaseSensitively)
3389 path.MakeLower();
3390 if ((path.Find(find)>=0))
3392 return result;
3394 path = cpath->GetGitPathString();
3395 if (!m_bFilterCaseSensitively)
3396 path.MakeLower();
3397 if ((path.Find(find)>=0))
3399 return result;
3403 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3405 CString path = pRev->m_SimpleFileList[i];
3406 if (!m_bFilterCaseSensitively)
3407 path.MakeLower();
3408 if ((path.Find(find)>=0))
3410 return result;
3414 } // else (from if (bRegex))
3415 return !result;
3418 static bool CStringStartsWith(const CString &str, const CString &prefix)
3420 return str.Left(prefix.GetLength()) == prefix;
3422 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3424 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3425 return true;
3427 if (m_ShowFilter & FILTERSHOW_REFS)
3429 // Keep all refs.
3430 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3431 for (size_t i = 0; i < refList.size(); ++i)
3433 const CString &str = refList[i];
3434 if (CStringStartsWith(str, _T("refs/heads/")))
3436 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3437 return true;
3439 else if (CStringStartsWith(str, _T("refs/remotes/")))
3441 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3442 return true;
3444 else if (CStringStartsWith(str, _T("refs/tags/")))
3446 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3447 return true;
3449 else if (CStringStartsWith(str, _T("refs/stash")))
3451 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3452 return true;
3454 else if (CStringStartsWith(str, _T("refs/bisect/")))
3456 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3457 return true;
3460 // Keep the head too.
3461 if (pRev->m_CommitHash == m_HeadHash)
3462 return true;
3465 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3467 if (pRev->ParentsCount() > 1)
3468 return true;
3469 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3470 if (childrenIt != commitChildren.end())
3472 const std::set<CGitHash> &children = childrenIt->second;
3473 if (children.size() > 1)
3474 return true;
3477 return false;
3480 void CGitLogListBase::ShowGraphColumn(bool bShow)
3482 // HACK to hide graph column
3483 if (bShow)
3484 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3485 else
3486 SetColumnWidth(0, 0);
3489 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3491 CString cmd;
3492 CString output;
3494 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3496 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3497 for (size_t i = 0; i < vector.size(); ++i)
3499 if (vector[i].Find(_T("refs/tags/")) == 0)
3501 CString tag = vector[i];
3502 int start = vector[i].Find(_T("^{}"));
3503 if (start > 0)
3504 tag = tag.Left(start);
3505 else
3506 continue;
3508 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3509 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3510 output.AppendChar(_T('\n'));
3515 return output;
3518 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3521 pShownlist->SafeRemoveAll();
3523 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3524 bool bRegex = false;
3525 if (m_bFilterWithRegex)
3526 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3528 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3529 CString sRev;
3530 for (DWORD i=0; i<m_logEntries.size(); ++i)
3532 if ((bRegex)&&(m_bFilterWithRegex))
3534 #if 0
3535 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3537 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3538 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3540 pShownlist->SafeAdd(m_logEntries[i]);
3541 continue;
3544 #endif
3545 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3547 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3548 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3550 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3551 continue;
3554 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3556 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3557 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3559 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3560 continue;
3563 if (m_SelectedFilters & LOGFILTER_PATHS)
3565 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3567 bool bGoing = true;
3568 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3570 CTGitPath cpath = pathList[cpPathIndex];
3571 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3573 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3574 bGoing = false;
3575 continue;
3577 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3579 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3580 bGoing = false;
3581 continue;
3583 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3585 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3586 bGoing = false;
3587 continue;
3591 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3593 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3595 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3596 continue;
3599 if (m_SelectedFilters & LOGFILTER_EMAILS)
3601 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3603 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3604 continue;
3607 if (m_SelectedFilters & LOGFILTER_REVS)
3609 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3610 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3612 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3613 continue;
3616 if (m_SelectedFilters & LOGFILTER_REFNAME)
3618 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3619 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3621 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3623 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3624 continue;
3628 } // if (bRegex)
3629 else
3631 CString find = m_sFilterText;
3632 if (!m_bFilterCaseSensitively)
3633 find.MakeLower();
3634 #if 0
3635 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3637 CString sBugIDs = m_logEntries[i]->sBugIDs;
3639 if (!m_bFilterCaseSensitively)
3640 sBugIDs = sBugIDs.MakeLower();
3641 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3643 pShownlist->SafeAdd(m_logEntries[i]);
3644 continue;
3647 #endif
3648 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3650 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3652 if (!m_bFilterCaseSensitively)
3653 msg = msg.MakeLower();
3654 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3656 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3657 continue;
3660 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3662 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3664 if (!m_bFilterCaseSensitively)
3665 msg = msg.MakeLower();
3666 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3668 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3669 continue;
3672 if (m_SelectedFilters & LOGFILTER_PATHS)
3674 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3676 bool bGoing = true;
3677 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3679 CTGitPath cpath = pathList[cpPathIndex];
3680 CString path = cpath.GetGitOldPathString();
3681 if (!m_bFilterCaseSensitively)
3682 path.MakeLower();
3683 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3685 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3686 bGoing = false;
3687 continue;
3689 path = cpath.GetGitPathString();
3690 if (!m_bFilterCaseSensitively)
3691 path.MakeLower();
3692 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3694 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3695 bGoing = false;
3696 continue;
3698 path = cpath.GetActionName();
3699 if (!m_bFilterCaseSensitively)
3700 path.MakeLower();
3701 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3703 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3704 bGoing = false;
3705 continue;
3709 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3711 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3712 if (!m_bFilterCaseSensitively)
3713 msg = msg.MakeLower();
3714 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3716 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3717 continue;
3720 if (m_SelectedFilters & LOGFILTER_EMAILS)
3722 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3723 if (!m_bFilterCaseSensitively)
3724 msg = msg.MakeLower();
3725 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3727 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3728 continue;
3731 if (m_SelectedFilters & LOGFILTER_REVS)
3733 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3734 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3736 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3737 continue;
3740 if (m_SelectedFilters & LOGFILTER_REFNAME)
3742 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3743 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3745 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3747 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3748 continue;
3752 } // else (from if (bRegex))
3753 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3757 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3760 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3762 if(m_From == -1)
3763 if(m_To == -1)
3764 return true;
3765 else
3766 return time <= m_To;
3767 else
3768 if(m_To == -1)
3769 return time >= m_From;
3770 else
3771 return ((time >= m_From)&&(time <= m_To));
3773 return TRUE; /* git dll will filter time range */
3775 // return TRUE;
3777 void CGitLogListBase::StartFilter()
3779 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3780 RecalculateShownList(&m_arShownList);
3781 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3784 DeleteAllItems();
3785 SetItemCountEx(ShownCountWithStopped());
3786 RedrawItems(0, ShownCountWithStopped());
3787 Invalidate();
3790 void CGitLogListBase::RemoveFilter()
3793 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3795 m_arShownList.SafeRemoveAll();
3797 // reset the time filter too
3798 #if 0
3799 m_timFrom = (__time64_t(m_tFrom));
3800 m_timTo = (__time64_t(m_tTo));
3801 m_DateFrom.SetTime(&m_timFrom);
3802 m_DateTo.SetTime(&m_timTo);
3803 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3804 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3805 #endif
3807 for (DWORD i=0; i<m_logEntries.size(); ++i)
3809 if(this->m_IsOldFirst)
3811 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3813 else
3815 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3818 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3819 DeleteAllItems();
3820 SetItemCountEx(ShownCountWithStopped());
3821 RedrawItems(0, ShownCountWithStopped());
3823 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3826 void CGitLogListBase::Clear()
3828 m_arShownList.SafeRemoveAll();
3829 DeleteAllItems();
3831 m_logEntries.ClearAll();
3835 void CGitLogListBase::OnDestroy()
3837 // save the column widths to the registry
3838 SaveColumnWidths();
3840 SafeTerminateThread();
3841 SafeTerminateAsyncDiffThread();
3843 int retry = 0;
3844 while(m_LogCache.SaveCache())
3846 if(retry > 5)
3847 break;
3848 Sleep(1000);
3850 ++retry;
3852 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3853 // MB_YESNO) == IDNO)
3854 // break;
3857 CHintListCtrl::OnDestroy();
3860 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3862 CRect rect;
3863 int i=(int)wParam;
3864 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3865 this->InvalidateRect(rect);
3867 return 0;
3871 * Save column widths to the registry
3873 void CGitLogListBase::SaveColumnWidths()
3875 int maxcol = m_ColumnManager.GetColumnCount();
3877 // HACK that graph column is always shown
3878 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3880 for (int col = 0; col < maxcol; ++col)
3881 if (m_ColumnManager.IsVisible (col))
3882 m_ColumnManager.ColumnResized (col);
3884 m_ColumnManager.WriteSettings();
3887 int CGitLogListBase::GetHeadIndex()
3889 if(m_HeadHash.IsEmpty())
3890 return -1;
3892 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3894 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3895 if(pRev)
3897 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3898 return i;
3901 return -1;
3903 void CGitLogListBase::OnFind()
3905 if (!m_pFindDialog)
3907 m_pFindDialog = new CFindDlg(this);
3908 m_pFindDialog->Create(this);
3911 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3913 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3915 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3917 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3918 Default();
3920 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3922 if (GetSelectedCount() != 0)
3923 return 0;
3925 CGitHash theSelectedHash = m_lastSelectedHash;
3926 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3927 m_lastSelectedHash = theSelectedHash;
3929 int countPerPage = GetCountPerPage();
3930 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3931 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3932 EnsureVisible((int)itemToSelect, FALSE);
3933 return 0;
3935 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3938 ASSERT(m_pFindDialog != NULL);
3939 bool bFound = false;
3940 int i=0;
3942 if (m_pFindDialog->IsTerminating())
3944 // invalidate the handle identifying the dialog box.
3945 m_pFindDialog = NULL;
3946 return 0;
3949 INT_PTR cnt = m_arShownList.GetCount();
3951 if(m_pFindDialog->IsRef())
3953 CString str;
3954 str=m_pFindDialog->GetFindString();
3956 CGitHash hash;
3958 if(!str.IsEmpty())
3960 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3961 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3964 if(!hash.IsEmpty())
3966 for (i = 0; i < cnt; ++i)
3968 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3969 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3971 bFound = true;
3972 break;
3976 if (!bFound)
3978 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3979 return 0;
3983 if (m_pFindDialog->FindNext() && !bFound)
3985 //read data from dialog
3986 CString findText = m_pFindDialog->GetFindString();
3987 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3989 std::tr1::wregex pat;
3990 bool bRegex = false;
3991 if (m_pFindDialog->Regex())
3992 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3994 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3996 for (i = m_nSearchIndex + 1; ; ++i)
3998 if (i >= cnt)
4000 i = 0;
4001 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
4003 if (m_nSearchIndex >= 0)
4005 if (i == m_nSearchIndex)
4007 ::MessageBeep(0xFFFFFFFF);
4008 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
4009 break;
4013 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
4015 CString str;
4016 str+=pLogEntry->m_CommitHash.ToString();
4017 str+=_T("\n");
4019 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4021 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4022 str+=_T("\n");
4025 str+=pLogEntry->GetAuthorEmail();
4026 str+=_T("\n");
4027 str+=pLogEntry->GetAuthorName();
4028 str+=_T("\n");
4029 str+=pLogEntry->GetBody();
4030 str+=_T("\n");
4031 str+=pLogEntry->GetCommitterEmail();
4032 str+=_T("\n");
4033 str+=pLogEntry->GetCommitterName();
4034 str+=_T("\n");
4035 str+=pLogEntry->GetSubject();
4036 str+=_T("\n");
4037 str+=pLogEntry->m_Notes;
4038 str+=_T("\n");
4039 str+=GetTagInfo(pLogEntry);
4040 str+=_T("\n");
4043 /*Because changed files list is loaded on demand when gui show,
4044 files will empty when files have not fetched.
4046 we can add it back by using one-way diff(with outnumber changed and rename detect.
4047 here just need changed filename list. one-way is much quicker.
4049 if(pLogEntry->m_IsFull)
4051 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4053 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4054 str+=_T("\n");
4055 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4056 str+=_T("\n");
4059 else
4061 if(!pLogEntry->m_IsSimpleListReady)
4062 pLogEntry->SafeGetSimpleList(&g_Git);
4064 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4066 str += pLogEntry->m_SimpleFileList[j];
4067 str+=_T("\n");
4073 if (bRegex)
4075 if (std::regex_search(std::wstring(str), pat, flags))
4077 bFound = true;
4078 break;
4081 else
4083 if (bMatchCase)
4085 if (str.Find(findText) >= 0)
4087 bFound = true;
4088 break;
4092 else
4094 CString msg = str;
4095 msg = msg.MakeLower();
4096 CString find = findText.MakeLower();
4097 if (msg.Find(find) >= 0)
4099 bFound = TRUE;
4100 break;
4104 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4106 } // if(m_pFindDialog->FindNext())
4107 //UpdateLogInfoLabel();
4109 if (bFound)
4111 m_nSearchIndex = i;
4112 EnsureVisible(i, FALSE);
4113 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4115 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4116 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4117 SetSelectionMark(i);
4119 else
4121 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4122 if (pLogEntry)
4123 m_highlight = pLogEntry->m_CommitHash;
4125 Invalidate();
4126 //FillLogMessageCtrl();
4127 UpdateData(FALSE);
4130 return 0;
4133 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4135 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4137 *pResult = FALSE;
4140 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4142 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4144 Invalidate(FALSE);
4147 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4149 LVHITTESTINFO lvhitTestInfo;
4151 lvhitTestInfo.pt = point;
4153 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4154 int nSubItem = lvhitTestInfo.iSubItem;
4156 UINT nFlags = lvhitTestInfo.flags;
4158 // nFlags is 0 if the SubItemHitTest fails
4159 // Therefore, 0 & <anything> will equal false
4160 if (nFlags & LVHT_ONITEM)
4162 // Get the client area occupied by this control
4163 RECT rcClient;
4164 GetClientRect(&rcClient);
4166 // Fill in the TOOLINFO structure
4167 pTI->hwnd = m_hWnd;
4168 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4169 pTI->lpszText = LPSTR_TEXTCALLBACK;
4170 pTI->rect = rcClient;
4172 return pTI->uId; // By returning a unique value per listItem,
4173 // we ensure that when the mouse moves over another list item,
4174 // the tooltip will change
4176 else
4178 // Otherwise, we aren't interested, so let the message propagate
4179 return -1;
4183 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4185 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4186 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4188 *pResult = 0;
4190 // Ignore messages from the built in tooltip, we are processing them internally
4191 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4192 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4193 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4194 return FALSE;
4196 // Get the mouse position
4197 const MSG* pMessage = GetCurrentMessage();
4199 CPoint pt;
4200 pt = pMessage->pt;
4201 ScreenToClient(&pt);
4203 // Check if the point falls onto a list item
4204 LVHITTESTINFO lvhitTestInfo;
4205 lvhitTestInfo.pt = pt;
4207 int nItem = SubItemHitTest(&lvhitTestInfo);
4209 if (lvhitTestInfo.flags & LVHT_ONITEM)
4211 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4212 if (strTipText.IsEmpty())
4213 return FALSE;
4215 // we want multiline tooltips
4216 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4218 wcscpy_s(m_wszTip, strTipText);
4219 // handle Unicode as well as non-Unicode requests
4220 if (pNMHDR->code == TTN_NEEDTEXTA)
4222 pTTTA->hinst = nullptr;
4223 pTTTA->lpszText = m_szTip;
4224 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4226 else
4228 pTTTW->hinst = nullptr;
4229 pTTTW->lpszText = m_wszTip;
4232 CRect rect;
4233 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4234 ClientToScreen(rect);
4235 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4237 return TRUE; // We found a tool tip,
4238 // tell the framework this message has been handled
4241 return FALSE; // We didn't handle the message,
4242 // let the framework continue propagating the message
4245 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4247 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4249 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4250 if (pLogEntry == nullptr)
4251 return CString();
4252 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4253 return CString();
4254 return pLogEntry->GetSubject();
4256 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4258 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4259 if (pLogEntry == nullptr)
4260 return CString();
4261 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4263 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4265 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4266 if (pLogEntry == nullptr)
4267 return CString();
4268 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4270 else if (nSubItem == LOGLIST_ACTION)
4272 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4273 if (pLogEntry == nullptr)
4274 return CString();
4276 if (!pLogEntry->m_IsDiffFiles)
4277 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4279 int actions = pLogEntry->GetAction(this);
4280 CString sToolTipText;
4282 CString actionText;
4283 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4284 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4286 if (actions & CTGitPath::LOGACTIONS_ADDED)
4288 if (!actionText.IsEmpty())
4289 actionText += L"\r\n";
4290 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4293 if (actions & CTGitPath::LOGACTIONS_DELETED)
4295 if (!actionText.IsEmpty())
4296 actionText += L"\r\n";
4297 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4300 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4302 if (!actionText.IsEmpty())
4303 actionText += L"\r\n";
4304 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4307 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4309 if (!actionText.IsEmpty())
4310 actionText += L"\r\n";
4311 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4314 if (!actionText.IsEmpty())
4316 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4317 sToolTipText = sTitle + L":\r\n" + actionText;
4319 return sToolTipText;
4321 return CString();