Fixed issue #2469: Support reviewing merge commits (git show merge-commit)
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob97a5cb0e3ecd0e411d47f2e265d385686d47b240
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)
65 // use the default GUI font, create a copy of it and
66 // change the copy to BOLD (leave the rest of the font
67 // the same)
68 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
69 LOGFONT lf = {0};
70 GetObject(hFont, sizeof(LOGFONT), &lf);
71 lf.lfWeight = FW_BOLD;
72 m_boldFont = CreateFontIndirect(&lf);
73 lf.lfWeight = FW_DONTCARE;
74 lf.lfItalic = TRUE;
75 m_FontItalics = CreateFontIndirect(&lf);
76 lf.lfWeight = FW_BOLD;
77 m_boldItalicsFont = CreateFontIndirect(&lf);
79 m_bShowBugtraqColumn=false;
81 m_IsIDReplaceAction=FALSE;
83 this->m_critSec.Init();
84 m_critSec_AsyncDiff.Init();
85 ResetWcRev(false);
87 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
88 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
89 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
90 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
91 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
92 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
94 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
95 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
97 m_From = -1;
98 m_To = -1;
100 m_ShowMask = 0;
101 m_LoadingThread = NULL;
103 InterlockedExchange(&m_bExitThread,FALSE);
104 m_IsOldFirst = FALSE;
105 m_IsRebaseReplaceGraph = FALSE;
107 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
109 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
111 // get short/long datetime setting from registry
112 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
113 if ( RegUseShortDateFormat )
115 m_DateFormat = DATE_SHORTDATE;
117 else
119 m_DateFormat = DATE_LONGDATE;
121 // get relative time display setting from registry
122 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
123 m_bRelativeTimes = (regRelativeTimes != 0);
124 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
126 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
127 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
128 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
129 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
130 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
131 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
132 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
134 m_ColumnRegKey=_T("log");
136 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
137 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
138 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
140 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
141 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
143 m_AsyncThreadExit = FALSE;
144 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
145 m_AsynDiffListLock.Init();
147 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
148 if (hUxTheme)
149 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
151 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
152 if (m_DiffingThread ==NULL)
154 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
155 return;
160 int CGitLogListBase::AsyncDiffThread()
162 m_AsyncThreadExited = false;
163 while(!m_AsyncThreadExit)
165 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
167 GitRevLoglist* pRev = nullptr;
168 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
170 m_AsynDiffListLock.Lock();
171 pRev = m_AsynDiffList.back();
172 m_AsynDiffList.pop_back();
173 m_AsynDiffListLock.Unlock();
175 if( pRev->m_CommitHash.IsEmpty() )
177 if(pRev->m_IsDiffFiles)
178 continue;
180 CTGitPathList& files = pRev->GetFiles(this);
181 files.Clear();
182 pRev->m_ParentHash.clear();
183 pRev->m_ParentHash.push_back(m_HeadHash);
184 g_Git.GetWorkingTreeChanges(files);
185 int& action = pRev->GetAction(this);
186 action = 0;
187 for (int j = 0; j < files.GetCount(); ++j)
188 action |= files[j].m_Action;
190 CString err;
191 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
193 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
194 return -1;
197 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
198 InterlockedExchange(&pRev->m_IsFull, TRUE);
200 pRev->GetBody().Format(IDS_FILESCHANGES, files.GetCount());
201 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
202 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
205 m_critSec_AsyncDiff.Lock();
206 int ret = pRev->CheckAndDiff();
207 m_critSec_AsyncDiff.Unlock();
208 if (!ret)
209 { // fetch change file list
210 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
212 if(i < m_arShownList.GetCount())
214 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
215 if(data->m_CommitHash == pRev->m_CommitHash)
217 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
218 break;
223 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
225 POSITION pos = GetFirstSelectedItemPosition();
226 int nItem = GetNextSelectedItem(pos);
228 if(nItem>=0)
230 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
231 if(data)
232 if(data->m_CommitHash == pRev->m_CommitHash)
234 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
241 m_AsyncThreadExited = true;
242 return 0;
244 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
246 if (exclusivelyShow)
248 m_ContextMenuMask &= hideMask;
250 else
252 m_ContextMenuMask &= ~hideMask;
256 CGitLogListBase::~CGitLogListBase()
258 InterlockedExchange(&m_bNoDispUpdates, TRUE);
259 this->m_arShownList.SafeRemoveAll();
261 DestroyIcon(m_hModifiedIcon);
262 DestroyIcon(m_hReplacedIcon);
263 DestroyIcon(m_hConflictedIcon);
264 DestroyIcon(m_hAddedIcon);
265 DestroyIcon(m_hDeletedIcon);
266 m_logEntries.ClearAll();
268 if (m_boldFont)
269 DeleteObject(m_boldFont);
271 if (m_FontItalics)
272 DeleteObject(m_FontItalics);
274 if (m_boldItalicsFont)
275 DeleteObject(m_boldItalicsFont);
277 if ( m_pStoreSelection )
279 delete m_pStoreSelection;
280 m_pStoreSelection = NULL;
283 SafeTerminateThread();
284 SafeTerminateAsyncDiffThread();
286 if(m_AsyncDiffEvent)
287 CloseHandle(m_AsyncDiffEvent);
289 if (hUxTheme)
290 FreeLibrary(hUxTheme);
294 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
295 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
296 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
297 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
298 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
299 ON_WM_CONTEXTMENU()
300 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
301 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
302 ON_WM_CREATE()
303 ON_WM_DESTROY()
304 ON_MESSAGE(MSG_LOADED,OnLoad)
305 ON_WM_MEASUREITEM()
306 ON_WM_MEASUREITEM_REFLECT()
307 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
308 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
309 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
310 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
311 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
312 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
313 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
314 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
315 END_MESSAGE_MAP()
317 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
319 //if (m_nRowHeight>0)
321 lpMeasureItemStruct->itemHeight = 50;
325 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
327 PreSubclassWindow();
328 return CHintListCtrl::OnCreate(lpCreateStruct);
331 void CGitLogListBase::PreSubclassWindow()
333 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
334 // load the icons for the action columns
335 // m_Theme.Open(m_hWnd, L"ListView");
336 SetWindowTheme(m_hWnd, L"Explorer", NULL);
337 CHintListCtrl::PreSubclassWindow();
340 CString CGitLogListBase::GetRebaseActionName(int action)
342 if (action & LOGACTIONS_REBASE_EDIT)
343 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
344 if (action & LOGACTIONS_REBASE_SQUASH)
345 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
346 if (action & LOGACTIONS_REBASE_PICK)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
348 if (action & LOGACTIONS_REBASE_SKIP)
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
354 void CGitLogListBase::InsertGitColumn()
356 CString temp;
358 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
359 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
360 if (DWORD(regFullRowSelect))
361 exStyle |= LVS_EX_FULLROWSELECT;
362 SetExtendedStyle(exStyle);
364 // only load properties if we have a repository
365 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
366 UpdateProjectProperties();
368 static UINT normal[] =
370 IDS_LOG_GRAPH,
371 IDS_LOG_REBASE,
372 IDS_LOG_ID,
373 IDS_LOG_HASH,
374 IDS_LOG_ACTIONS,
375 IDS_LOG_MESSAGE,
376 IDS_LOG_AUTHOR,
377 IDS_LOG_DATE,
378 IDS_LOG_EMAIL,
379 IDS_LOG_COMMIT_NAME,
380 IDS_LOG_COMMIT_EMAIL,
381 IDS_LOG_COMMIT_DATE,
382 IDS_LOG_BUGIDS,
383 IDS_LOG_SVNREV,
386 static int with[] =
388 ICONITEMBORDER+16*4,
389 ICONITEMBORDER+16*4,
390 ICONITEMBORDER+16*4,
391 ICONITEMBORDER+16*4,
392 ICONITEMBORDER+16*4,
393 LOGLIST_MESSAGE_MIN,
394 ICONITEMBORDER+16*4,
395 ICONITEMBORDER+16*4,
396 ICONITEMBORDER+16*4,
397 ICONITEMBORDER+16*4,
398 ICONITEMBORDER+16*4,
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 ICONITEMBORDER+16*4,
403 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
405 DWORD hideColumns = 0;
406 if(this->m_IsRebaseReplaceGraph)
408 hideColumns |= GIT_LOG_GRAPH;
409 m_dwDefaultColumns |= GIT_LOG_REBASE;
411 else
413 hideColumns |= GIT_LOG_REBASE;
416 if(this->m_IsIDReplaceAction)
418 hideColumns |= GIT_LOG_ACTIONS;
419 m_dwDefaultColumns |= GIT_LOG_ID;
420 m_dwDefaultColumns |= GIT_LOG_HASH;
422 else
424 hideColumns |= GIT_LOG_ID;
426 if(this->m_bShowBugtraqColumn)
428 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
430 else
432 hideColumns |= GIT_LOGLIST_BUG;
434 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
435 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
436 else
437 hideColumns |= GIT_LOGLIST_SVNREV;
438 SetRedraw(false);
440 m_ColumnManager.SetNames(normal, _countof(normal));
441 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
443 SetRedraw(true);
447 * Resizes all columns in a list control to values in registry.
449 void CGitLogListBase::ResizeAllListCtrlCols()
451 // column max and min widths to allow
452 static const int nMinimumWidth = 10;
453 static const int nMaximumWidth = 1000;
454 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
455 if (pHdrCtrl)
457 int numcols = pHdrCtrl->GetItemCount();
458 for (int col = 0; col < numcols; ++col)
460 // get width for this col last time from registry
461 CString regentry;
462 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
463 CRegDWORD regwidth(regentry, 0);
464 int cx = regwidth;
465 if ( cx == 0 )
467 // no saved value, setup sensible defaults
468 if (col == this->LOGLIST_MESSAGE)
470 cx = LOGLIST_MESSAGE_MIN;
472 else
474 cx = ICONITEMBORDER+16*4;
477 if (cx < nMinimumWidth)
479 cx = nMinimumWidth;
481 else if (cx > nMaximumWidth)
483 cx = nMaximumWidth;
486 SetColumnWidth(col, cx);
493 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
495 LVITEM rItem;
496 SecureZeroMemory(&rItem, sizeof(LVITEM));
497 rItem.mask = LVIF_STATE;
498 rItem.iItem = (int)Index;
499 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
500 GetItem(&rItem);
502 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index);
503 HBRUSH brush = NULL;
505 if (!(rItem.state & LVIS_SELECTED))
507 int action = pLogEntry->GetRebaseAction();
508 if (action & LOGACTIONS_REBASE_SQUASH)
509 brush = ::CreateSolidBrush(RGB(156,156,156));
510 else if (action & LOGACTIONS_REBASE_EDIT)
511 brush = ::CreateSolidBrush(RGB(200,200,128));
513 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
515 if (rItem.state & LVIS_SELECTED)
517 if (::GetFocus() == m_hWnd)
518 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
519 else
520 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
523 if (brush != NULL)
525 ::FillRect(hdc, &rect, brush);
526 ::DeleteObject(brush);
530 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
532 POINT point = { 4, 4 };
533 CRect rt2 = rect;
534 rt2.DeflateRect(1, 1);
535 rt2.OffsetRect(2, 2);
537 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
538 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
539 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
540 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
541 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
543 ::SelectObject(hdc, brush);
544 rt2.OffsetRect(-2, -2);
545 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
546 ::SelectObject(hdc, oldbrush);
547 ::SelectObject(hdc, oldpen);
548 ::DeleteObject(nullPen);
549 ::DeleteObject(darkBrush);
552 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
554 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
555 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
556 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
557 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
558 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
559 ::LineTo(hdc, rect.left, rect.bottom);
560 ::SelectObject(hdc, oldpen);
561 ::DeleteObject(pen);
564 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
566 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
567 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
568 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
569 ::LineTo(hdc, rect.left, rect.bottom);
570 ::LineTo(hdc, rect.right, rect.bottom);
571 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
572 ::SelectObject(hdc, oldpen);
573 ::DeleteObject(pen);
576 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
578 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
579 CRect rt=rect;
580 LVITEM rItem;
581 SecureZeroMemory(&rItem, sizeof(LVITEM));
582 rItem.mask = LVIF_STATE;
583 rItem.iItem = (int)index;
584 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
585 GetItem(&rItem);
587 CDC W_Dc;
588 W_Dc.Attach(hdc);
590 HTHEME hTheme = NULL;
591 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
592 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
594 SIZE oneSpaceSize;
595 if (m_bTagsBranchesOnRightSide)
597 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
598 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
599 SelectObject(hdc, oldFont);
600 rt.left += oneSpaceSize.cx * 2;
602 else
604 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
605 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
606 rt.left += oneSpaceSize.cx;
609 int action = data->GetRebaseAction();
610 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
611 if (IsAppThemed() && pfnDrawThemeTextEx)
613 int txtState = LISS_NORMAL;
614 if (rItem.state & LVIS_SELECTED)
615 txtState = LISS_SELECTED;
617 DTTOPTS opts = { 0 };
618 opts.dwSize = sizeof(opts);
619 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
620 opts.dwFlags = DTT_TEXTCOLOR;
621 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
623 else
625 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
627 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
628 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
629 ::SetTextColor(hdc, clrOld);
631 else
633 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
634 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
635 ::SetTextColor(hdc, clrOld);
639 if (m_bTagsBranchesOnRightSide)
641 SIZE size;
642 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
644 rt.left += oneSpaceSize.cx + size.cx;
646 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
649 if (hTheme)
650 CloseThemeData(hTheme);
652 W_Dc.Detach();
655 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
657 for (unsigned int i = 0; i < refList.size(); ++i)
659 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
660 HBRUSH brush = 0;
661 COLORREF colRef = refList[i].color;
662 bool singleRemote = refList[i].singleRemote;
663 bool hasTracking = refList[i].hasTracking;
664 bool sameName = refList[i].sameName;
665 bool annotatedTag = refList[i].annotatedTag;
667 //When row selected, ajust label color
668 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
670 if (rItem.state & LVIS_SELECTED)
671 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
674 brush = ::CreateSolidBrush(colRef);
676 if (!shortname.IsEmpty() && (rt.left < rect.right))
678 SIZE size;
679 memset(&size,0,sizeof(SIZE));
680 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
682 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
683 rt.right += 8;
685 int textpos = DT_CENTER;
687 if (rt.right > rect.right)
689 rt.right = rect.right;
690 textpos = 0;
693 CRect textRect = rt;
695 if (singleRemote)
697 rt.right += 8;
698 textRect.OffsetRect(8, 0);
701 if (sameName)
702 rt.right += 8;
704 if (hasTracking)
706 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
708 else
710 //Fill interior of ref label
711 ::FillRect(hdc, &rt, brush);
714 //Draw edge of label
715 CRect rectEdge = rt;
717 if (!hasTracking)
719 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
720 rectEdge.DeflateRect(1, 1);
721 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
724 if (annotatedTag)
726 rt.right += 8;
727 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
728 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
729 ::FillRgn(hdc, hrgn, brush);
730 ::DeleteObject(hrgn);
731 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
732 HPEN pen;
733 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
734 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
735 ::DeleteObject(pen);
736 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
737 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
738 ::DeleteObject(pen);
739 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
740 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
741 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
742 ::DeleteObject(pen);
743 SelectObject(hdc, oldpen);
746 //Draw text inside label
747 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
748 if (!customColor && IsAppThemed() && pfnDrawThemeTextEx)
750 int txtState = LISS_NORMAL;
751 if (rItem.state & LVIS_SELECTED)
752 txtState = LISS_SELECTED;
754 DTTOPTS opts = { 0 };
755 opts.dwSize = sizeof(opts);
756 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
757 opts.dwFlags = DTT_TEXTCOLOR;
758 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
760 else
762 W_Dc.SetBkMode(TRANSPARENT);
763 if (customColor || (rItem.state & LVIS_SELECTED))
765 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
766 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
767 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
768 ::SetTextColor(hdc,clrOld);
770 else
772 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
773 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
774 ::SetTextColor(hdc, clrOld);
778 if (singleRemote)
780 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
781 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
782 CRect newRect;
783 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
784 DrawLightning(hdc, newRect, color, bold);
787 if (sameName)
789 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
790 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
791 CRect newRect;
792 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
793 DrawUpTriangle(hdc, newRect, color, bold);
796 rt.left = rt.right + 1;
798 if (brush)
799 ::DeleteObject(brush);
801 rt.right = rect.right;
804 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
806 // Returns ((256 - amount)*col1 + amount*col2) / 256;
807 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
808 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
809 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
812 Gdiplus::Color GetGdiColor(COLORREF col)
814 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
816 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
817 const COLORREF& col,const COLORREF& activeColor, int top
820 int h = laneHeight / 2;
821 int m = (x1 + x2) / 2;
822 int r = (x2 - x1) * m_NodeSize / 30;
823 int d = 2 * r;
825 #define P_CENTER m , h+top
826 #define P_0 x2, h+top
827 #define P_90 m , 0+top-1
828 #define P_180 x1, h+top
829 #define P_270 m , 2 * h+top +1
830 #define R_CENTER m - r, h - r+top, d, d
833 #define DELTA_UR_B 2*(x1 - m), 2*h +top
834 #define DELTA_UR_E 0*16, 90*16 +top // -,
836 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
837 #define DELTA_DR_E 270*16, 90*16 +top // -'
839 #define DELTA_UL_B 2*(x2 - m), 2*h +top
840 #define DELTA_UL_E 90*16, 90*16 +top // ,-
842 #define DELTA_DL_B 2*(x2 - m),2*-h +top
843 #define DELTA_DL_E 180*16, 90*16 // '-
845 #define CENTER_UR x1, 2*h, 225
846 #define CENTER_DR x1, 0 , 135
847 #define CENTER_UL x2, 2*h, 315
848 #define CENTER_DL x2, 0 , 45
851 Gdiplus::Graphics graphics( hdc );
853 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
855 // arc
856 switch (type) {
857 case Lanes::JOIN:
858 case Lanes::JOIN_R:
859 case Lanes::HEAD:
860 case Lanes::HEAD_R:
862 Gdiplus::LinearGradientBrush gradient(
863 Gdiplus::Point(x1-2, h+top-2),
864 Gdiplus::Point(P_270),
865 GetGdiColor(activeColor),GetGdiColor(col));
868 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
869 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
871 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
872 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
873 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
875 break;
877 case Lanes::JOIN_L:
880 Gdiplus::LinearGradientBrush gradient(
881 Gdiplus::Point(P_270),
882 Gdiplus::Point(x2+1, h+top-1),
883 GetGdiColor(col),GetGdiColor(activeColor));
886 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
887 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
889 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
890 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
891 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
894 break;
896 case Lanes::TAIL:
897 case Lanes::TAIL_R:
900 Gdiplus::LinearGradientBrush gradient(
901 Gdiplus::Point(x1-2, h+top-2),
902 Gdiplus::Point(P_90),
903 GetGdiColor(activeColor),GetGdiColor(col));
905 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
907 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
909 #if 0
910 QConicalGradient gradient(CENTER_DR);
911 gradient.setColorAt(0.375, activeCol);
912 gradient.setColorAt(0.625, col);
913 myPen.setBrush(gradient);
914 p->setPen(myPen);
915 p->drawArc(P_CENTER, DELTA_DR);
916 #endif
917 break;
919 default:
920 break;
924 //static QPen myPen(Qt::black, 2); // fast path here
925 CPen pen;
926 pen.CreatePen(PS_SOLID,2,col);
927 //myPen.setColor(col);
928 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
930 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
932 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
934 //p->setPen(myPen);
936 // vertical line
937 switch (type) {
938 case Lanes::ACTIVE:
939 case Lanes::NOT_ACTIVE:
940 case Lanes::MERGE_FORK:
941 case Lanes::MERGE_FORK_R:
942 case Lanes::MERGE_FORK_L:
943 case Lanes::JOIN:
944 case Lanes::JOIN_R:
945 case Lanes::JOIN_L:
946 case Lanes::CROSS:
947 //DrawLine(hdc,P_90,P_270);
948 graphics.DrawLine(&myPen,P_90,P_270);
949 //p->drawLine(P_90, P_270);
950 break;
951 case Lanes::HEAD_L:
952 case Lanes::BRANCH:
953 //DrawLine(hdc,P_CENTER,P_270);
954 graphics.DrawLine(&myPen,P_CENTER,P_270);
955 //p->drawLine(P_CENTER, P_270);
956 break;
957 case Lanes::TAIL_L:
958 case Lanes::INITIAL:
959 case Lanes::BOUNDARY:
960 case Lanes::BOUNDARY_C:
961 case Lanes::BOUNDARY_R:
962 case Lanes::BOUNDARY_L:
963 //DrawLine(hdc,P_90, P_CENTER);
964 graphics.DrawLine(&myPen,P_90,P_CENTER);
965 //p->drawLine(P_90, P_CENTER);
966 break;
967 default:
968 break;
971 myPen.SetColor(GetGdiColor(activeColor));
973 // horizontal line
974 switch (type) {
975 case Lanes::MERGE_FORK:
976 case Lanes::JOIN:
977 case Lanes::HEAD:
978 case Lanes::TAIL:
979 case Lanes::CROSS:
980 case Lanes::CROSS_EMPTY:
981 case Lanes::BOUNDARY_C:
982 //DrawLine(hdc,P_180,P_0);
983 graphics.DrawLine(&myPen,P_180,P_0);
984 //p->drawLine(P_180, P_0);
985 break;
986 case Lanes::MERGE_FORK_R:
987 case Lanes::BOUNDARY_R:
988 //DrawLine(hdc,P_180,P_CENTER);
989 graphics.DrawLine(&myPen,P_180,P_CENTER);
990 //p->drawLine(P_180, P_CENTER);
991 break;
992 case Lanes::MERGE_FORK_L:
993 case Lanes::HEAD_L:
994 case Lanes::TAIL_L:
995 case Lanes::BOUNDARY_L:
996 //DrawLine(hdc,P_CENTER,P_0);
997 graphics.DrawLine(&myPen,P_CENTER,P_0);
998 //p->drawLine(P_CENTER, P_0);
999 break;
1000 default:
1001 break;
1004 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1006 CBrush brush;
1007 brush.CreateSolidBrush(col);
1008 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1010 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1011 // center symbol, e.g. rect or ellipse
1012 switch (type) {
1013 case Lanes::ACTIVE:
1014 case Lanes::INITIAL:
1015 case Lanes::BRANCH:
1017 //p->setPen(Qt::NoPen);
1018 //p->setBrush(col);
1019 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1020 graphics.FillEllipse(&myBrush, R_CENTER);
1021 //p->drawEllipse(R_CENTER);
1022 break;
1023 case Lanes::MERGE_FORK:
1024 case Lanes::MERGE_FORK_R:
1025 case Lanes::MERGE_FORK_L:
1026 //p->setPen(Qt::NoPen);
1027 //p->setBrush(col);
1028 //p->drawRect(R_CENTER);
1029 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1030 graphics.FillRectangle(&myBrush, R_CENTER);
1031 break;
1032 case Lanes::UNAPPLIED:
1033 // Red minus sign
1034 //p->setPen(Qt::NoPen);
1035 //p->setBrush(Qt::red);
1036 //p->drawRect(m - r, h - 1, d, 2);
1037 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1038 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1039 break;
1040 case Lanes::APPLIED:
1041 // Green plus sign
1042 //p->setPen(Qt::NoPen);
1043 //p->setBrush(DARK_GREEN);
1044 //p->drawRect(m - r, h - 1, d, 2);
1045 //p->drawRect(m - 1, h - r, 2, d);
1046 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1047 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1048 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1049 break;
1050 case Lanes::BOUNDARY:
1051 //p->setBrush(back);
1052 //p->drawEllipse(R_CENTER);
1053 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1054 graphics.DrawEllipse(&myPen, R_CENTER);
1055 break;
1056 case Lanes::BOUNDARY_C:
1057 case Lanes::BOUNDARY_R:
1058 case Lanes::BOUNDARY_L:
1059 //p->setBrush(back);
1060 //p->drawRect(R_CENTER);
1061 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1062 graphics.FillRectangle(&myBrush,R_CENTER);
1063 break;
1064 default:
1065 break;
1068 ::SelectObject(hdc,oldpen);
1069 ::SelectObject(hdc,oldbrush);
1070 #undef P_CENTER
1071 #undef P_0
1072 #undef P_90
1073 #undef P_180
1074 #undef P_270
1075 #undef R_CENTER
1078 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1080 // TODO: unfinished
1081 // return;
1082 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
1083 if(data->m_CommitHash.IsEmpty())
1084 return;
1086 CRect rt=rect;
1087 LVITEM rItem;
1088 SecureZeroMemory(&rItem, sizeof(LVITEM));
1089 rItem.mask = LVIF_STATE;
1090 rItem.iItem = (int)index;
1091 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1092 GetItem(&rItem);
1094 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1096 if (data->m_Lanes.empty())
1097 m_logEntries.setLane(data->m_CommitHash);
1099 std::vector<int>& lanes=data->m_Lanes;
1100 size_t laneNum = lanes.size();
1101 UINT activeLane = 0;
1102 for (UINT i = 0; i < laneNum; ++i)
1103 if (Lanes::isMerge(lanes[i])) {
1104 activeLane = i;
1105 break;
1108 int x2 = 0;
1109 int maxWidth = rect.Width();
1110 int lw = 3 * rect.Height() / 4; //laneWidth()
1112 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1113 //if (opt.state & QStyle::State_Selected)
1114 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1116 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1119 int x1 = x2;
1120 x2 += lw;
1122 int ln = lanes[i];
1123 if (ln == Lanes::EMPTY)
1124 continue;
1126 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1127 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1130 #if 0
1131 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1133 int x1 = x2;
1134 x2 += lw;
1136 int ln = lanes[i];
1137 if (ln == Lanes::EMPTY)
1138 continue;
1140 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1141 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1143 if (ln == Lanes::CROSS)
1145 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1146 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1148 else
1149 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1151 #endif
1155 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1158 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1159 // Take the default processing unless we set this to something else below.
1160 *pResult = CDRF_DODEFAULT;
1162 if (m_bNoDispUpdates)
1163 return;
1165 switch (pLVCD->nmcd.dwDrawStage)
1167 case CDDS_PREPAINT:
1169 *pResult = CDRF_NOTIFYITEMDRAW;
1170 return;
1172 break;
1173 case CDDS_ITEMPREPAINT:
1175 // This is the prepaint stage for an item. Here's where we set the
1176 // item's text color.
1178 // Tell Windows to send draw notifications for each subitem.
1179 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1181 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1183 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1185 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1186 if (data)
1188 HGDIOBJ hGdiObj = nullptr;
1189 int action = data->GetRebaseAction();
1190 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1191 crText = RGB(128,128,128);
1193 if (action & LOGACTIONS_REBASE_SQUASH)
1194 pLVCD->clrTextBk = RGB(156,156,156);
1195 else if (action & LOGACTIONS_REBASE_EDIT)
1196 pLVCD->clrTextBk = RGB(200,200,128);
1197 else
1198 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1200 if (action & LOGACTIONS_REBASE_CURRENT)
1201 hGdiObj = m_boldFont;
1203 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1204 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1205 if (isHeadHash && isHighlight)
1206 hGdiObj = m_boldItalicsFont;
1207 else if (isHeadHash)
1208 hGdiObj = m_boldFont;
1209 else if (isHighlight)
1210 hGdiObj = m_FontItalics;
1212 if (hGdiObj)
1214 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1215 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1218 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1219 // crText = GetSysColor(COLOR_GRAYTEXT);
1221 if (data->m_CommitHash.IsEmpty())
1223 //crText = GetSysColor(RGB(200,200,0));
1224 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1225 // We changed the font, so we're returning CDRF_NEWFONT. This
1226 // tells the control to recalculate the extent of the text.
1227 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1231 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1233 if (m_bStrictStopped)
1234 crText = GetSysColor(COLOR_GRAYTEXT);
1236 // Store the color back in the NMLVCUSTOMDRAW struct.
1237 pLVCD->clrText = crText;
1238 return;
1240 break;
1241 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1243 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1245 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1248 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1250 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1252 CRect rect;
1253 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1255 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1256 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1258 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1259 if( !data ->m_CommitHash.IsEmpty())
1260 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1262 *pResult = CDRF_SKIPDEFAULT;
1263 return;
1267 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1269 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1271 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1273 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1275 CRect rect;
1276 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1278 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1279 // not in FillBackGround method, because this only affected the message subitem
1280 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1281 return;
1283 int index = (int)pLVCD->nmcd.dwItemSpec;
1284 int state = GetItemState(index, LVIS_SELECTED);
1285 int txtState = LISS_NORMAL;
1286 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1288 if (state & LVIS_SELECTED)
1289 txtState = LISS_HOTSELECTED;
1290 else
1291 txtState = LISS_HOT;
1293 else if (state & LVIS_SELECTED)
1295 if (::GetFocus() == m_hWnd)
1296 txtState = LISS_SELECTED;
1297 else
1298 txtState = LISS_SELECTEDNOTFOCUS;
1301 HTHEME hTheme = nullptr;
1302 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1303 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1305 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1306 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1307 else
1309 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1310 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1311 ::DeleteObject(brush);
1313 if (hTheme)
1315 CRect rt;
1316 // get rect of whole line
1317 GetItemRect(index, rt, LVIR_BOUNDS);
1318 CRect rect2 = rect;
1319 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1320 rect2.DeflateRect(1, 1, 1, 1);
1322 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1323 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1325 CloseThemeData(hTheme);
1327 // END: extended redraw
1329 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1331 std::vector<REFLABEL> refsToShow;
1332 STRING_VECTOR remoteTrackingList;
1333 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1334 for (unsigned int i = 0; i < refList.size(); ++i)
1336 CString str = refList[i];
1338 REFLABEL refLabel;
1339 refLabel.color = RGB(255, 255, 255);
1340 refLabel.singleRemote = false;
1341 refLabel.hasTracking = false;
1342 refLabel.sameName = false;
1343 refLabel.annotatedTag = false;
1344 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1346 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1347 continue;
1348 if (refLabel.name == m_CurrentBranch )
1349 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1350 else
1351 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1353 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1354 CString pullRemote = trackingEntry.first;
1355 CString pullBranch = trackingEntry.second;
1356 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1358 CString defaultUpstream;
1359 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1360 refLabel.hasTracking = true;
1361 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1363 bool found = false;
1364 for (size_t j = i + 1; j < refList.size(); ++j)
1366 if (refList[j] == defaultUpstream)
1368 found = true;
1369 break;
1373 if (found)
1375 bool sameName = pullBranch == refLabel.name;
1376 refsToShow.push_back(refLabel);
1377 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1378 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1379 if (m_bSymbolizeRefNames)
1381 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1383 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1384 refLabel.singleRemote = true;
1386 else if (sameName)
1387 refLabel.simplifiedName = pullRemote + _T("/");
1388 refLabel.sameName = sameName;
1390 refsToShow.push_back(refLabel);
1391 remoteTrackingList.push_back(defaultUpstream);
1392 continue;
1397 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1399 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1400 continue;
1402 bool found = false;
1403 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1405 if (remoteTrackingList[j] == str)
1407 found = true;
1408 break;
1411 if (found)
1412 continue;
1414 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1415 if (m_bSymbolizeRefNames)
1417 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1419 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1420 refLabel.singleRemote = true;
1424 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1426 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1427 continue;
1428 refLabel.color = m_Colors.GetColor(CColors::Tag);
1429 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1431 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1433 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1434 continue;
1435 refLabel.color = m_Colors.GetColor(CColors::Stash);
1436 refLabel.name = _T("stash");
1438 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1440 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1441 continue;
1442 if (refLabel.name.Find(_T("good")) == 0)
1444 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1445 refLabel.name = _T("good");
1447 if (refLabel.name.Find(_T("bad")) == 0)
1449 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1450 refLabel.name = _T("bad");
1453 else
1454 continue;
1456 refsToShow.push_back(refLabel);
1459 if (refsToShow.empty())
1461 *pResult = CDRF_DODEFAULT;
1462 return;
1465 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1467 *pResult = CDRF_SKIPDEFAULT;
1468 return;
1475 if (pLVCD->iSubItem == LOGLIST_ACTION)
1477 if(this->m_IsIDReplaceAction)
1479 *pResult = CDRF_DODEFAULT;
1480 return;
1482 *pResult = CDRF_DODEFAULT;
1484 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1485 return;
1487 int nIcons = 0;
1488 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1489 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1491 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1492 CRect rect;
1493 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1494 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1495 // Get the selected state of the
1496 // item being drawn.
1498 // Fill the background if necessary
1499 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1501 // Draw the icon(s) into the compatible DC
1502 int action = pLogEntry->GetAction(this);
1503 if (!pLogEntry->m_IsDiffFiles)
1505 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1506 *pResult = CDRF_SKIPDEFAULT;
1507 return;
1510 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1511 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1512 ++nIcons;
1514 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1515 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1516 ++nIcons;
1518 if (action & CTGitPath::LOGACTIONS_DELETED)
1519 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1520 ++nIcons;
1522 if (action & CTGitPath::LOGACTIONS_REPLACED)
1523 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1524 ++nIcons;
1526 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1527 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1528 ++nIcons;
1530 *pResult = CDRF_SKIPDEFAULT;
1531 return;
1534 break;
1536 *pResult = CDRF_DODEFAULT;
1539 CString FindSVNRev(const CString& msg)
1543 const std::tr1::wsregex_iterator end;
1544 std::wstring s = msg;
1545 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1546 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex1); it != end; ++it)
1548 const std::tr1::wsmatch match = *it;
1549 if (match.size() == 4)
1551 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1552 return std::wstring(match[2]).c_str();
1555 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1556 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex2); it != end; ++it)
1558 const std::tr1::wsmatch match = *it;
1559 if (match.size() == 3)
1561 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1562 return std::wstring(match[1]).c_str();
1566 catch (std::exception) {}
1568 return _T("");
1571 // CGitLogListBase message handlers
1573 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1575 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1577 // Create a pointer to the item
1578 LV_ITEM* pItem = &(pDispInfo)->item;
1580 // Do the list need text information?
1581 if (!(pItem->mask & LVIF_TEXT))
1582 return;
1584 // By default, clear text buffer.
1585 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1587 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1589 *pResult = 0;
1590 if (m_bNoDispUpdates || bOutOfRange)
1591 return;
1593 // Which item number?
1594 int itemid = pItem->iItem;
1595 GitRevLoglist* pLogEntry = nullptr;
1596 if (itemid < m_arShownList.GetCount())
1597 pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(pItem->iItem));
1599 CString temp;
1600 if(m_IsOldFirst)
1602 temp.Format(_T("%d"),pItem->iItem+1);
1605 else
1607 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1610 // Which column?
1611 switch (pItem->iSubItem)
1613 case LOGLIST_GRAPH: //Graphic
1614 break;
1615 case LOGLIST_REBASE:
1617 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1618 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1620 break;
1621 case LOGLIST_ACTION: //action -- no text in the column
1622 break;
1623 case LOGLIST_HASH:
1624 if(pLogEntry)
1625 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1626 break;
1627 case LOGLIST_ID:
1628 if(this->m_IsIDReplaceAction)
1629 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1630 break;
1631 case LOGLIST_MESSAGE: //Message
1632 if (pLogEntry)
1633 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax - 1);
1634 break;
1635 case LOGLIST_AUTHOR: //Author
1636 if (pLogEntry)
1637 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1638 break;
1639 case LOGLIST_DATE: //Date
1640 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1641 lstrcpyn(pItem->pszText,
1642 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1643 pItem->cchTextMax - 1);
1644 break;
1646 case LOGLIST_EMAIL:
1647 if (pLogEntry)
1648 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1649 break;
1651 case LOGLIST_COMMIT_NAME: //Commit
1652 if (pLogEntry)
1653 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1654 break;
1656 case LOGLIST_COMMIT_EMAIL: //Commit Email
1657 if (pLogEntry)
1658 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1659 break;
1661 case LOGLIST_COMMIT_DATE: //Commit Date
1662 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1663 lstrcpyn(pItem->pszText,
1664 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1665 pItem->cchTextMax - 1);
1666 break;
1667 case LOGLIST_BUG: //Bug ID
1668 if(pLogEntry)
1669 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax - 1);
1670 break;
1671 case LOGLIST_SVNREV: //SVN revision
1672 if (pLogEntry)
1673 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax - 1);
1674 break;
1676 default:
1677 ASSERT(false);
1681 bool CGitLogListBase::IsOnStash(int index)
1683 GitRevLoglist* rev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index));
1684 if (IsStash(rev))
1685 return true;
1686 if (index > 0)
1688 GitRevLoglist* preRev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index - 1));
1689 if (IsStash(preRev))
1690 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1692 return false;
1695 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1697 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1699 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1700 return true;
1702 return false;
1705 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1707 if (pRev->m_ParentHash.empty())
1709 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1710 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1712 parentHash = pRev->m_ParentHash;
1715 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1718 if (pWnd == GetHeaderCtrl())
1720 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1723 int selIndex = GetSelectionMark();
1724 if (selIndex < 0)
1725 return; // nothing selected, nothing to do with a context menu
1727 // if the user selected the info text telling about not all revisions shown due to
1728 // the "stop on copy/rename" option, we also don't show the context menu
1729 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1730 return;
1732 // if the context menu is invoked through the keyboard, we have to use
1733 // a calculated position on where to anchor the menu on
1734 if ((point.x == -1) && (point.y == -1))
1736 CRect rect;
1737 GetItemRect(selIndex, &rect, LVIR_LABEL);
1738 ClientToScreen(&rect);
1739 point = rect.CenterPoint();
1741 m_nSearchIndex = selIndex;
1742 m_bCancelled = FALSE;
1744 // calculate some information the context menu commands can use
1745 // CString pathURL = GetURLFromPath(m_path);
1747 POSITION pos = GetFirstSelectedItemPosition();
1748 int indexNext = GetNextSelectedItem(pos);
1749 if (indexNext < 0)
1750 return;
1752 GitRevLoglist* pSelLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(indexNext));
1753 if (pSelLogEntry == nullptr)
1754 return;
1755 #if 0
1756 GitRev revSelected = pSelLogEntry->Rev;
1757 GitRev revPrevious = git_revnum_t(revSelected)-1;
1758 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1760 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1762 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1763 if (changedpath->lCopyFromRev)
1764 revPrevious = changedpath->lCopyFromRev;
1767 GitRev revSelected2;
1768 if (pos)
1770 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1771 revSelected2 = pLogEntry->Rev;
1773 bool bAllFromTheSameAuthor = true;
1774 CString firstAuthor;
1775 CLogDataVector selEntries;
1776 GitRev revLowest, revHighest;
1777 GitRevRangeArray revisionRanges;
1779 POSITION pos = GetFirstSelectedItemPosition();
1780 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1781 revisionRanges.AddRevision(pLogEntry->Rev);
1782 selEntries.push_back(pLogEntry);
1783 firstAuthor = pLogEntry->sAuthor;
1784 revLowest = pLogEntry->Rev;
1785 revHighest = pLogEntry->Rev;
1786 while (pos)
1788 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1789 revisionRanges.AddRevision(pLogEntry->Rev);
1790 selEntries.push_back(pLogEntry);
1791 if (firstAuthor.Compare(pLogEntry->sAuthor))
1792 bAllFromTheSameAuthor = false;
1793 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1794 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1798 #endif
1800 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1802 int FirstSelect=-1, LastSelect=-1;
1803 pos = GetFirstSelectedItemPosition();
1804 FirstSelect = GetNextSelectedItem(pos);
1805 while(pos)
1807 LastSelect = GetNextSelectedItem(pos);
1809 //entry is selected, now show the popup menu
1810 CIconMenu popup;
1811 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1813 if (popup.CreatePopupMenu())
1815 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1816 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1817 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1818 bool isStash = IsOnStash(indexNext);
1819 GIT_REV_LIST parentHash;
1820 GetParentHashes(pSelLogEntry, parentHash);
1822 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1823 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1825 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)) && FirstSelect != GetItemCount() - 1 && LastSelect != GetItemCount() - 1)
1826 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1828 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1829 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1831 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1832 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1834 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)))
1835 popup.AppendMenu(MF_SEPARATOR, NULL);
1837 if (GetSelectedCount() == 1)
1840 bool requiresSeparator = false;
1841 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1843 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1845 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1846 requiresSeparator = true;
1849 else
1851 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1853 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1854 requiresSeparator = true;
1856 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1858 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1859 requiresSeparator = true;
1863 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1865 if (parentHash.size() == 1)
1867 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1868 requiresSeparator = true;
1870 else if (parentHash.size() > 1)
1872 blamemenu.CreatePopupMenu();
1873 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1874 for (size_t i = 0; i < parentHash.size(); ++i)
1876 CString str;
1877 str.Format(IDS_PARENT, i + 1);
1878 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1880 requiresSeparator = true;
1884 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1886 if (parentHash.size() == 1)
1888 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1889 requiresSeparator = true;
1891 else if (parentHash.size() > 1)
1893 gnudiffmenu.CreatePopupMenu();
1894 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1896 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1897 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1898 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1900 for (size_t i = 0; i < parentHash.size(); ++i)
1902 CString str;
1903 str.Format(IDS_PARENT, i + 1);
1904 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1906 requiresSeparator = true;
1910 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1912 if (parentHash.size() == 1)
1914 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1915 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1916 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1917 requiresSeparator = true;
1919 else if (parentHash.size() > 1)
1921 diffmenu.CreatePopupMenu();
1922 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1923 for (size_t i = 0; i < parentHash.size(); ++i)
1925 CString str;
1926 str.Format(IDS_PARENT, i + 1);
1927 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1928 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1930 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1931 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1934 requiresSeparator = true;
1938 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1940 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1941 requiresSeparator = true;
1944 if (requiresSeparator)
1945 popup.AppendMenu(MF_SEPARATOR, NULL);
1947 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1949 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1950 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1953 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1955 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1956 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1958 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1959 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1961 popup.AppendMenu(MF_SEPARATOR, NULL);
1964 if (pSelLogEntry->m_CommitHash.IsEmpty())
1966 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1967 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1969 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1970 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1972 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1973 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1975 popup.AppendMenu(MF_SEPARATOR, NULL);
1977 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1978 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1980 popup.AppendMenu(MF_SEPARATOR, NULL);
1984 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1985 // {
1986 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1987 // }
1988 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1989 // {
1990 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1991 // }
1992 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1993 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1994 // {
1995 // popup.AppendMenu(MF_SEPARATOR, NULL);
1996 // }
1998 CString str,format;
1999 //if (m_hasWC)
2000 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2002 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2004 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2005 GetSelectedCount() == 1)
2006 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2008 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2009 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2011 format.LoadString(IDS_LOG_POPUP_MERGEREV);
2012 str.Format(format,g_Git.GetCurrentBranch());
2014 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2015 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2017 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2018 str.Format(format,g_Git.GetCurrentBranch());
2020 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2021 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2024 // Add Switch Branch express Menu
2025 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2026 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2029 std::vector<CString *> branchs;
2030 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2032 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2033 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2035 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2039 CString str2;
2040 str2.LoadString(IDS_SWITCH_BRANCH);
2042 if(branchs.size() == 1)
2044 str2 += _T(" ");
2045 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2046 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2048 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2051 else if(branchs.size() > 1)
2053 subbranchmenu.CreatePopupMenu();
2054 for (size_t i = 0 ; i < branchs.size(); ++i)
2056 if (*branchs[i] != currentBranch)
2058 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2059 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2063 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2067 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2068 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2070 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2071 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2073 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2074 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2076 format.LoadString(IDS_REBASE_THIS_FORMAT);
2077 str.Format(format,g_Git.GetCurrentBranch());
2079 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2080 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2081 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2083 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2084 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2086 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2088 if (parentHash.size() == 1)
2090 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2092 else if (parentHash.size() > 1)
2094 revertmenu.CreatePopupMenu();
2095 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2097 for (size_t i = 0; i < parentHash.size(); ++i)
2099 CString str2;
2100 str2.Format(IDS_PARENT, i + 1);
2101 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2106 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2107 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2109 popup.AppendMenu(MF_SEPARATOR, NULL);
2114 if(!pSelLogEntry->m_Ref.IsEmpty())
2116 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2117 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2118 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2119 popup.AppendMenu(MF_SEPARATOR, NULL);
2122 if (GetSelectedCount() >= 2)
2124 bool bAddSeparator = false;
2125 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2127 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2128 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2131 if (GetSelectedCount() == 2)
2133 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2134 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2136 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2138 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2139 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2140 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2141 CString menu;
2142 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2143 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2144 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2145 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2148 bAddSeparator = true;
2151 if (m_hasWC)
2153 bAddSeparator = true;
2156 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2157 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2159 if (bAddSeparator)
2160 popup.AppendMenu(MF_SEPARATOR, NULL);
2163 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2165 bool bAddSeparator = false;
2166 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2168 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2170 CString head;
2171 int headindex;
2172 headindex = this->GetHeadIndex();
2173 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2175 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2176 CGitHash hashFirst;
2177 if (g_Git.GetHash(hashFirst, head))
2178 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2179 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2180 CGitHash hash;
2181 if (g_Git.GetHash(hash, head))
2182 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2183 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2184 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2185 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2186 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2187 bAddSeparator = true;
2192 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2193 if (GetSelectedCount() >= 2)
2194 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2195 else
2196 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2197 bAddSeparator = true;
2200 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2201 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2202 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2203 bAddSeparator = true;
2206 if (bAddSeparator)
2207 popup.AppendMenu(MF_SEPARATOR, NULL);
2210 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())
2212 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2213 popup.AppendMenu(MF_SEPARATOR, NULL);
2216 if (GetSelectedCount() == 1)
2218 bool bAddSeparator = false;
2219 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2221 // show the push-option only if the log entry has an associated local branch
2222 bool isLocal = false;
2223 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2225 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2226 isLocal = true;
2228 if (isLocal || showExtendedMenu)
2230 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2231 bAddSeparator = true;
2234 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2236 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2237 bAddSeparator = true;
2241 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2243 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2245 std::vector<CString *> branchs;
2246 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2248 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2249 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2251 CString str;
2252 if (branchs.size() == 1)
2254 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2255 str+=_T(" ");
2256 str += *branchs[0];
2257 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2258 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2259 bAddSeparator = true;
2261 else if (branchs.size() > 1)
2263 str.LoadString(IDS_DELETE_BRANCHTAG);
2264 submenu.CreatePopupMenu();
2265 for (size_t i = 0; i < branchs.size(); ++i)
2267 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2268 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2271 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2272 bAddSeparator = true;
2275 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2276 if (bAddSeparator)
2277 popup.AppendMenu(MF_SEPARATOR, NULL);
2278 } // GetSelectedCount() == 1
2280 if (GetSelectedCount() != 0)
2282 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2283 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2284 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2285 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2286 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2287 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2290 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2291 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2293 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2294 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2296 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2297 // DialogEnableWindow(IDOK, FALSE);
2298 // SetPromptApp(&theApp);
2300 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2302 // EnableOKButton();
2303 } // if (popup.CreatePopupMenu())
2307 bool CGitLogListBase::IsSelectionContinuous()
2309 if ( GetSelectedCount()==1 )
2311 // if only one revision is selected, the selection is of course
2312 // continuous
2313 return true;
2316 POSITION pos = GetFirstSelectedItemPosition();
2317 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2318 if (bContinuous)
2320 int itemindex = GetNextSelectedItem(pos);
2321 while (pos)
2323 int nextindex = GetNextSelectedItem(pos);
2324 if (nextindex - itemindex > 1)
2326 bContinuous = false;
2327 break;
2329 itemindex = nextindex;
2332 return bContinuous;
2335 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2338 CString sClipdata;
2339 POSITION pos = GetFirstSelectedItemPosition();
2340 if (pos != NULL)
2342 CString sRev;
2343 sRev.LoadString(IDS_LOG_REVISION);
2344 CString sAuthor;
2345 sAuthor.LoadString(IDS_LOG_AUTHOR);
2346 CString sDate;
2347 sDate.LoadString(IDS_LOG_DATE);
2348 CString sMessage;
2349 sMessage.LoadString(IDS_LOG_MESSAGE);
2350 bool first = true;
2351 while (pos)
2353 CString sLogCopyText;
2354 CString sPaths;
2355 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2357 if (toCopy == ID_COPY_ALL)
2359 //pLogEntry->GetFiles(this)
2360 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2362 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2363 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2365 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2366 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2368 CString rename;
2369 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2370 sPaths += _T(" ") + rename;
2372 sPaths += _T("\r\n");
2374 sPaths.Trim();
2375 CString body = pLogEntry->GetBody();
2376 body.Replace(_T("\n"), _T("\r\n"));
2377 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"),
2378 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2379 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2380 (LPCTSTR)sDate,
2381 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2382 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2383 (LPCTSTR)sPaths);
2384 sClipdata += sLogCopyText;
2386 else if (toCopy == ID_COPY_MESSAGE)
2388 CString body = pLogEntry->GetBody();
2389 body.Replace(_T("\n"), _T("\r\n"));
2390 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2392 else if (toCopy == ID_COPY_SUBJECT)
2394 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2396 else
2398 if (!first)
2399 sClipdata += _T("\r\n");
2400 sClipdata += pLogEntry->m_CommitHash;
2403 first = false;
2405 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2410 void CGitLogListBase::DiffSelectedRevWithPrevious()
2412 if (m_bThreadRunning)
2413 return;
2415 int FirstSelect=-1, LastSelect=-1;
2416 POSITION pos = GetFirstSelectedItemPosition();
2417 FirstSelect = GetNextSelectedItem(pos);
2418 while(pos)
2420 LastSelect = GetNextSelectedItem(pos);
2423 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2425 #if 0
2426 UpdateLogInfoLabel();
2427 int selIndex = m_LogList.GetSelectionMark();
2428 if (selIndex < 0)
2429 return;
2430 int selCount = m_LogList.GetSelectedCount();
2431 if (selCount != 1)
2432 return;
2434 // Find selected entry in the log list
2435 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2436 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2437 long rev1 = pLogEntry->Rev;
2438 long rev2 = rev1-1;
2439 CTGitPath path = m_path;
2441 // See how many files under the relative root were changed in selected revision
2442 int nChanged = 0;
2443 LogChangedPath * changed = NULL;
2444 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2446 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2447 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2449 ++nChanged;
2450 changed = cpath;
2454 if (m_path.IsDirectory() && nChanged == 1)
2456 // We're looking at the log for a directory and only one file under dir was changed in the revision
2457 // Do diff on that file instead of whole directory
2458 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2461 m_bCancelled = FALSE;
2462 DialogEnableWindow(IDOK, FALSE);
2463 SetPromptApp(&theApp);
2464 theApp.DoWaitCursor(1);
2466 if (PromptShown())
2468 GitDiff diff(this, m_hWnd, true);
2469 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2470 diff.SetHEADPeg(m_LogRevision);
2471 diff.ShowCompare(path, rev2, path, rev1);
2473 else
2475 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2478 theApp.DoWaitCursor(-1);
2479 EnableOKButton();
2480 #endif
2483 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2485 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2486 *pResult = -1;
2488 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2489 return;
2490 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2491 return;
2492 if (pFindInfo->lvfi.psz == 0)
2493 return;
2494 #if 0
2495 CString sCmp = pFindInfo->lvfi.psz;
2496 CString sRev;
2497 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2499 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2500 sRev.Format(_T("%ld"), pLogEntry->Rev);
2501 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2503 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2505 *pResult = i;
2506 return;
2509 else
2511 if (sCmp.Compare(sRev)==0)
2513 *pResult = i;
2514 return;
2518 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2520 for (int i=0; i<pFindInfo->iStart; ++i)
2522 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2523 sRev.Format(_T("%ld"), pLogEntry->Rev);
2524 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2526 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2528 *pResult = i;
2529 return;
2532 else
2534 if (sCmp.Compare(sRev)==0)
2536 *pResult = i;
2537 return;
2542 #endif
2543 *pResult = -1;
2546 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2548 ClearText();
2550 this->m_arShownList.SafeRemoveAll();
2552 this->m_logEntries.ClearAll();
2553 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2554 return -1;
2556 SetItemCountEx((int)m_logEntries.size());
2558 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2560 if(m_IsOldFirst)
2562 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2563 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2566 else
2568 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2569 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2573 ReloadHashMap();
2575 if(path)
2576 m_Path=*path;
2577 return 0;
2581 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2583 ClearText();
2585 m_arShownList.SafeRemoveAll();
2587 m_logEntries.ClearAll();
2588 if (m_logEntries.Fill(hashes))
2589 return -1;
2591 SetItemCountEx((int)m_logEntries.size());
2593 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2595 if (m_IsOldFirst)
2597 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2598 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2600 else
2602 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2603 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2607 ReloadHashMap();
2609 return 0;
2612 int CGitLogListBase::BeginFetchLog()
2614 ClearText();
2616 this->m_arShownList.SafeRemoveAll();
2618 this->m_logEntries.ClearAll();
2620 this->m_LogCache.ClearAllParent();
2622 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2624 CTGitPath *path;
2625 if(this->m_Path.IsEmpty())
2626 path=NULL;
2627 else
2628 path=&this->m_Path;
2630 int mask;
2631 mask = CGit::LOG_INFO_ONLY_HASH;
2632 if (m_bIncludeBoundaryCommits)
2633 mask |= CGit::LOG_INFO_BOUNDARY;
2634 // if(this->m_bAllBranch)
2635 mask |= m_ShowMask ;
2637 if(m_bShowWC)
2639 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2640 ResetWcRev();
2641 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2644 if (m_sRange.IsEmpty())
2645 m_sRange = _T("HEAD");
2647 CFilterData data;
2648 data.m_From = m_From;
2649 data.m_To =m_To;
2651 #if 0 /* use tortoiegit filter */
2652 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2653 data.m_Author = this->m_sFilterText;
2655 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2656 data.m_MessageFilter = this->m_sFilterText;
2658 data.m_IsRegex = m_bFilterWithRegex;
2659 #endif
2661 // follow does not work for directories
2662 if (!path || path->IsDirectory())
2663 mask &= ~CGit::LOG_INFO_FOLLOW;
2664 // follow does not work with all branches 8at least in TGit)
2665 if (mask & CGit::LOG_INFO_FOLLOW)
2666 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2668 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2670 //this->m_logEntries.ParserFromLog();
2671 if(IsInWorkingThread())
2673 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2675 else
2677 SetItemCountEx((int)m_logEntries.size());
2682 [] { git_init(); } ();
2684 catch (char* msg)
2686 CString err(msg);
2687 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2688 return -1;
2691 if (!g_Git.CanParseRev(m_sRange))
2693 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2694 return 0;
2696 // if show all branches, pick any ref as dummy entry ref
2697 STRING_VECTOR list;
2698 if (g_Git.GetRefList(list))
2699 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2700 if (list.size() == 0)
2701 return 0;
2703 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2706 g_Git.m_critGitDllSec.Lock();
2707 try {
2708 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2710 g_Git.m_critGitDllSec.Unlock();
2711 return -1;
2714 catch (char* msg)
2716 g_Git.m_critGitDllSec.Unlock();
2717 CString err(msg);
2718 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2719 return -1;
2721 g_Git.m_critGitDllSec.Unlock();
2723 return 0;
2726 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2728 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2730 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2732 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2734 DiffSelectedRevWithPrevious();
2735 return TRUE;
2738 #if 0
2739 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2741 DiffSelectedFile();
2742 return TRUE;
2744 #endif
2746 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2748 // select all entries
2749 for (int i=0; i<GetItemCount(); ++i)
2751 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2753 return TRUE;
2756 #if 0
2757 if (m_hAccel && !bSkipAccelerator)
2759 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2760 if (ret)
2761 return TRUE;
2764 #endif
2765 //m_tooltips.RelayEvent(pMsg);
2766 return __super::PreTranslateMessage(pMsg);
2769 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2771 // a double click on an entry in the revision list has happened
2772 *pResult = 0;
2774 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2775 DiffSelectedRevWithPrevious();
2778 int CGitLogListBase::FetchLogAsync(void * data)
2780 ReloadHashMap();
2781 m_ProcData=data;
2782 m_bExitThread=FALSE;
2783 InterlockedExchange(&m_bThreadRunning, TRUE);
2784 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2785 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2786 if (m_LoadingThread ==NULL)
2788 InterlockedExchange(&m_bThreadRunning, FALSE);
2789 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2790 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2791 return -1;
2793 return 0;
2796 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2798 return ((CGitLogListBase*)pVoid)->LogThread();
2801 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2803 //CTime time;
2804 oldest=CTime::GetCurrentTime();
2805 latest=CTime(1971,1,2,0,0,0);
2806 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2808 if(m_logEntries[i].IsEmpty())
2809 continue;
2811 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2812 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2814 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2815 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2819 if(latest<oldest)
2820 latest=oldest;
2823 UINT CGitLogListBase::LogThread()
2825 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2827 InterlockedExchange(&m_bThreadRunning, TRUE);
2828 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2830 ULONGLONG t1,t2;
2832 if(BeginFetchLog())
2834 InterlockedExchange(&m_bThreadRunning, FALSE);
2835 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2837 return 1;
2840 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2841 bool bRegex = false;
2842 if (m_bFilterWithRegex)
2843 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2845 TRACE(_T("\n===Begin===\n"));
2846 //Update work copy item;
2848 if (!m_logEntries.empty())
2850 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2852 m_arShownList.SafeAdd(pRev);
2856 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2858 // store commit number of the last selected commit/line before the refresh or -1
2859 int lastSelectedHashNItem = -1;
2860 if (m_lastSelectedHash.IsEmpty())
2861 lastSelectedHashNItem = 0;
2863 int ret = 0;
2865 bool shouldWalk = true;
2866 if (!g_Git.CanParseRev(m_sRange))
2868 // walk revisions if show all branches and there exists any ref
2869 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2870 shouldWalk = false;
2871 else
2873 STRING_VECTOR list;
2874 if (g_Git.GetRefList(list))
2875 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2876 if (list.size() == 0)
2877 shouldWalk = false;
2881 if (shouldWalk)
2883 g_Git.m_critGitDllSec.Lock();
2884 int total = 0;
2887 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2888 total = git_get_log_estimate_commit_count(m_DllGitLog);
2890 catch (char* msg)
2892 CString err(msg);
2893 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2894 ret = -1;
2896 g_Git.m_critGitDllSec.Unlock();
2898 GIT_COMMIT commit;
2899 t2=t1=GetTickCount();
2900 int oldprecentage = 0;
2901 size_t oldsize = m_logEntries.size();
2902 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2903 while (ret== 0 && !m_bExitThread)
2905 g_Git.m_critGitDllSec.Lock();
2908 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2910 catch (char* msg)
2912 g_Git.m_critGitDllSec.Unlock();
2913 CString err(msg);
2914 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2915 break;
2917 g_Git.m_critGitDllSec.Unlock();
2919 if(ret)
2921 if (ret != -2) // other than end of revision walking
2922 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2923 break;
2926 if (commit.m_ignore == 1)
2928 git_free_commit(&commit);
2929 continue;
2932 //printf("%s\r\n",commit.GetSubject());
2933 if(m_bExitThread)
2934 break;
2936 CGitHash hash = (char*)commit.m_hash ;
2938 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2939 pRev->m_GitCommit = commit;
2940 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2942 char *note=NULL;
2943 g_Git.m_critGitDllSec.Lock();
2946 git_get_notes(commit.m_hash, &note);
2948 catch (char* msg)
2950 g_Git.m_critGitDllSec.Unlock();
2951 CString err(msg);
2952 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2953 break;
2955 g_Git.m_critGitDllSec.Unlock();
2957 if(note)
2959 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2960 free(note);
2961 note = nullptr;
2964 if(!pRev->m_IsDiffFiles)
2966 pRev->m_CallDiffAsync = DiffAsync;
2969 pRev->ParserParentFromCommit(&commit);
2970 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2972 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2974 const CGitHash &parentHash = pRev->m_ParentHash[i];
2975 auto it = commitChildren.find(parentHash);
2976 if (it == commitChildren.end())
2978 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2980 it->second.insert(pRev->m_CommitHash);
2984 #ifdef DEBUG
2985 pRev->DbgPrint();
2986 TRACE(_T("\n"));
2987 #endif
2989 bool visible = true;
2990 if (HasFilterText())
2992 if(!IsMatchFilter(bRegex,pRev,pat))
2993 visible = false;
2995 if (visible && !ShouldShowFilter(pRev, commitChildren))
2996 visible = false;
2997 this->m_critSec.Lock();
2998 m_logEntries.append(hash, visible);
2999 if (visible)
3000 m_arShownList.SafeAdd(pRev);
3001 this->m_critSec.Unlock();
3003 if (!visible)
3004 continue;
3006 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3007 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3009 t2=GetTickCount();
3011 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3013 //update UI
3014 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3015 if(percent > 99)
3016 percent =99;
3017 if(percent < GITLOG_START)
3018 percent = GITLOG_START +1;
3020 oldsize = m_logEntries.size();
3021 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3023 //if( percent > oldprecentage )
3025 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3026 oldprecentage = percent;
3029 if (lastSelectedHashNItem >= 0)
3030 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3032 t1 = t2;
3035 g_Git.m_critGitDllSec.Lock();
3036 git_close_log(m_DllGitLog);
3037 g_Git.m_critGitDllSec.Unlock();
3041 if (m_bExitThread)
3043 InterlockedExchange(&m_bThreadRunning, FALSE);
3044 return 0;
3047 //Update UI;
3048 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3050 if (lastSelectedHashNItem >= 0)
3051 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3053 if (this->m_hWnd)
3054 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3056 InterlockedExchange(&m_bThreadRunning, FALSE);
3058 return 0;
3061 void CGitLogListBase::FetchRemoteList()
3063 STRING_VECTOR remoteList;
3064 if (!g_Git.GetRemoteList(remoteList))
3065 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3066 else
3067 m_SingleRemote = _T("");
3070 void CGitLogListBase::FetchTrackingBranchList()
3072 m_TrackingMap.clear();
3073 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3075 for (size_t j = 0; j < it->second.size(); ++j)
3077 CString branchName;
3078 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3080 CString pullRemote, pullBranch;
3081 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3082 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3084 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3091 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3093 SafeTerminateThread();
3095 this->SetItemCountEx(0);
3096 this->Clear();
3098 ResetWcRev();
3100 // HACK to hide graph column
3101 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3102 SetColumnWidth(0, 0);
3103 else
3104 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3106 //Update branch and Tag info
3107 ReloadHashMap();
3108 if (m_pFindDialog)
3109 m_pFindDialog->RefreshList();
3110 //Assume Thread have exited
3111 //if(!m_bThreadRunning)
3113 m_logEntries.clear();
3115 if(IsCleanFilter)
3117 m_sFilterText.Empty();
3118 m_From=-1;
3119 m_To=-1;
3122 InterlockedExchange(&m_bExitThread,FALSE);
3124 InterlockedExchange(&m_bThreadRunning, TRUE);
3125 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3126 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3128 InterlockedExchange(&m_bThreadRunning, FALSE);
3129 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3130 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3134 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3138 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3139 if (!bMatchCase)
3140 type |= std::tr1::regex_constants::icase;
3141 pat = std::tr1::wregex(regexp_str, type);
3142 return true;
3144 catch (std::exception) {}
3145 return false;
3147 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3149 BOOL result = TRUE;
3150 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3151 CString sRev;
3153 if ((bRegex)&&(m_bFilterWithRegex))
3155 if (m_SelectedFilters & LOGFILTER_BUGID)
3157 if(this->m_bShowBugtraqColumn)
3159 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3161 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3162 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3164 return TRUE;
3169 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3171 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3172 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3174 return TRUE;
3178 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3180 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3181 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3183 return TRUE;
3187 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3189 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3191 return TRUE;
3194 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3196 return TRUE;
3200 if (m_SelectedFilters & LOGFILTER_EMAILS)
3202 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3204 return TRUE;
3207 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3209 return TRUE;
3213 if (m_SelectedFilters & LOGFILTER_REVS)
3215 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3216 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3218 return TRUE;
3222 if (m_SelectedFilters & LOGFILTER_REFNAME)
3224 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3225 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3227 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3229 return TRUE;
3234 if (m_SelectedFilters & LOGFILTER_PATHS)
3236 CTGitPathList *pathList=NULL;
3237 if( pRev->m_IsDiffFiles)
3238 pathList = &pRev->GetFiles(this);
3239 else
3241 if(!pRev->m_IsSimpleListReady)
3242 pRev->SafeGetSimpleList(&g_Git);
3245 if(pathList)
3246 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3248 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3250 return true;
3252 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3254 return true;
3258 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3260 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3262 return true;
3267 else
3269 CString find = m_sFilterText;
3270 if (!m_bFilterCaseSensitively)
3271 find.MakeLower();
3272 result = find[0] == '!' ? FALSE : TRUE;
3273 if (!result)
3274 find = find.Mid(1);
3276 if (m_SelectedFilters & LOGFILTER_BUGID)
3278 if(this->m_bShowBugtraqColumn)
3280 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3282 if (!m_bFilterCaseSensitively)
3283 sBugIds.MakeLower();
3284 if ((sBugIds.Find(find) >= 0))
3286 return result;
3291 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3293 CString msg = pRev->GetSubject();
3295 if (!m_bFilterCaseSensitively)
3296 msg = msg.MakeLower();
3297 if ((msg.Find(find) >= 0))
3299 return result;
3303 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3305 CString msg = pRev->GetBody();
3307 if (!m_bFilterCaseSensitively)
3308 msg = msg.MakeLower();
3309 if ((msg.Find(find) >= 0))
3311 return result;
3315 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3317 CString msg = pRev->GetAuthorName();
3318 if (!m_bFilterCaseSensitively)
3319 msg = msg.MakeLower();
3320 if ((msg.Find(find) >= 0))
3322 return result;
3326 if (m_SelectedFilters & LOGFILTER_EMAILS)
3328 CString msg = pRev->GetAuthorEmail();
3329 if (!m_bFilterCaseSensitively)
3330 msg = msg.MakeLower();
3331 if ((msg.Find(find) >= 0))
3333 return result;
3337 if (m_SelectedFilters & LOGFILTER_REVS)
3339 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3340 if ((sRev.Find(find) >= 0))
3342 return result;
3346 if (m_SelectedFilters & LOGFILTER_REFNAME)
3348 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3349 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3351 if (it->Find(find) >= 0)
3353 return result;
3358 if (m_SelectedFilters & LOGFILTER_PATHS)
3360 CTGitPathList *pathList=NULL;
3361 if( pRev->m_IsDiffFiles)
3362 pathList = &pRev->GetFiles(this);
3363 else
3365 if(!pRev->m_IsSimpleListReady)
3366 pRev->SafeGetSimpleList(&g_Git);
3368 if(pathList)
3369 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3371 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3372 CString path = cpath->GetGitOldPathString();
3373 if (!m_bFilterCaseSensitively)
3374 path.MakeLower();
3375 if ((path.Find(find)>=0))
3377 return result;
3379 path = cpath->GetGitPathString();
3380 if (!m_bFilterCaseSensitively)
3381 path.MakeLower();
3382 if ((path.Find(find)>=0))
3384 return result;
3388 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3390 CString path = pRev->m_SimpleFileList[i];
3391 if (!m_bFilterCaseSensitively)
3392 path.MakeLower();
3393 if ((path.Find(find)>=0))
3395 return result;
3399 } // else (from if (bRegex))
3400 return !result;
3403 static bool CStringStartsWith(const CString &str, const CString &prefix)
3405 return str.Left(prefix.GetLength()) == prefix;
3407 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3409 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3410 return true;
3412 if (m_ShowFilter & FILTERSHOW_REFS)
3414 // Keep all refs.
3415 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3416 for (size_t i = 0; i < refList.size(); ++i)
3418 const CString &str = refList[i];
3419 if (CStringStartsWith(str, _T("refs/heads/")))
3421 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3422 return true;
3424 else if (CStringStartsWith(str, _T("refs/remotes/")))
3426 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3427 return true;
3429 else if (CStringStartsWith(str, _T("refs/tags/")))
3431 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3432 return true;
3434 else if (CStringStartsWith(str, _T("refs/stash")))
3436 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3437 return true;
3439 else if (CStringStartsWith(str, _T("refs/bisect/")))
3441 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3442 return true;
3445 // Keep the head too.
3446 if (pRev->m_CommitHash == m_HeadHash)
3447 return true;
3450 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3452 if (pRev->ParentsCount() > 1)
3453 return true;
3454 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3455 if (childrenIt != commitChildren.end())
3457 const std::set<CGitHash> &children = childrenIt->second;
3458 if (children.size() > 1)
3459 return true;
3462 return false;
3465 void CGitLogListBase::ShowGraphColumn(bool bShow)
3467 // HACK to hide graph column
3468 if (bShow)
3469 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3470 else
3471 SetColumnWidth(0, 0);
3474 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3476 CString cmd;
3477 CString output;
3479 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3481 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3482 for (size_t i = 0; i < vector.size(); ++i)
3484 if (vector[i].Find(_T("refs/tags/")) == 0)
3486 CString tag = vector[i];
3487 int start = vector[i].Find(_T("^{}"));
3488 if (start > 0)
3489 tag = tag.Left(start);
3490 else
3491 continue;
3493 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3494 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3495 output.AppendChar(_T('\n'));
3500 return output;
3503 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3506 pShownlist->SafeRemoveAll();
3508 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3509 bool bRegex = false;
3510 if (m_bFilterWithRegex)
3511 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3513 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3514 CString sRev;
3515 for (DWORD i=0; i<m_logEntries.size(); ++i)
3517 if ((bRegex)&&(m_bFilterWithRegex))
3519 #if 0
3520 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3522 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3523 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3525 pShownlist->SafeAdd(m_logEntries[i]);
3526 continue;
3529 #endif
3530 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3532 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3533 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3535 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3536 continue;
3539 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3541 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3542 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3544 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3545 continue;
3548 if (m_SelectedFilters & LOGFILTER_PATHS)
3550 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3552 bool bGoing = true;
3553 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3555 CTGitPath cpath = pathList[cpPathIndex];
3556 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3558 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3559 bGoing = false;
3560 continue;
3562 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3564 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3565 bGoing = false;
3566 continue;
3568 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3570 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3571 bGoing = false;
3572 continue;
3576 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3578 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3580 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3581 continue;
3584 if (m_SelectedFilters & LOGFILTER_EMAILS)
3586 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3588 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3589 continue;
3592 if (m_SelectedFilters & LOGFILTER_REVS)
3594 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3595 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3597 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3598 continue;
3601 if (m_SelectedFilters & LOGFILTER_REFNAME)
3603 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3604 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3606 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3608 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3609 continue;
3613 } // if (bRegex)
3614 else
3616 CString find = m_sFilterText;
3617 if (!m_bFilterCaseSensitively)
3618 find.MakeLower();
3619 #if 0
3620 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3622 CString sBugIDs = m_logEntries[i]->sBugIDs;
3624 if (!m_bFilterCaseSensitively)
3625 sBugIDs = sBugIDs.MakeLower();
3626 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3628 pShownlist->SafeAdd(m_logEntries[i]);
3629 continue;
3632 #endif
3633 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3635 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3637 if (!m_bFilterCaseSensitively)
3638 msg = msg.MakeLower();
3639 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3641 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3642 continue;
3645 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3647 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3649 if (!m_bFilterCaseSensitively)
3650 msg = msg.MakeLower();
3651 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3653 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3654 continue;
3657 if (m_SelectedFilters & LOGFILTER_PATHS)
3659 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3661 bool bGoing = true;
3662 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3664 CTGitPath cpath = pathList[cpPathIndex];
3665 CString path = cpath.GetGitOldPathString();
3666 if (!m_bFilterCaseSensitively)
3667 path.MakeLower();
3668 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3670 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3671 bGoing = false;
3672 continue;
3674 path = cpath.GetGitPathString();
3675 if (!m_bFilterCaseSensitively)
3676 path.MakeLower();
3677 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3679 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3680 bGoing = false;
3681 continue;
3683 path = cpath.GetActionName();
3684 if (!m_bFilterCaseSensitively)
3685 path.MakeLower();
3686 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3688 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3689 bGoing = false;
3690 continue;
3694 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3696 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3697 if (!m_bFilterCaseSensitively)
3698 msg = msg.MakeLower();
3699 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3701 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3702 continue;
3705 if (m_SelectedFilters & LOGFILTER_EMAILS)
3707 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3708 if (!m_bFilterCaseSensitively)
3709 msg = msg.MakeLower();
3710 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3712 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3713 continue;
3716 if (m_SelectedFilters & LOGFILTER_REVS)
3718 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3719 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3721 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3722 continue;
3725 if (m_SelectedFilters & LOGFILTER_REFNAME)
3727 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3728 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3730 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3732 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3733 continue;
3737 } // else (from if (bRegex))
3738 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3742 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3745 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3747 if(m_From == -1)
3748 if(m_To == -1)
3749 return true;
3750 else
3751 return time <= m_To;
3752 else
3753 if(m_To == -1)
3754 return time >= m_From;
3755 else
3756 return ((time >= m_From)&&(time <= m_To));
3758 return TRUE; /* git dll will filter time range */
3760 // return TRUE;
3762 void CGitLogListBase::StartFilter()
3764 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3765 RecalculateShownList(&m_arShownList);
3766 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3769 DeleteAllItems();
3770 SetItemCountEx(ShownCountWithStopped());
3771 RedrawItems(0, ShownCountWithStopped());
3772 Invalidate();
3775 void CGitLogListBase::RemoveFilter()
3778 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3780 m_arShownList.SafeRemoveAll();
3782 // reset the time filter too
3783 #if 0
3784 m_timFrom = (__time64_t(m_tFrom));
3785 m_timTo = (__time64_t(m_tTo));
3786 m_DateFrom.SetTime(&m_timFrom);
3787 m_DateTo.SetTime(&m_timTo);
3788 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3789 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3790 #endif
3792 for (DWORD i=0; i<m_logEntries.size(); ++i)
3794 if(this->m_IsOldFirst)
3796 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3798 else
3800 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3803 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3804 DeleteAllItems();
3805 SetItemCountEx(ShownCountWithStopped());
3806 RedrawItems(0, ShownCountWithStopped());
3808 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3811 void CGitLogListBase::Clear()
3813 m_arShownList.SafeRemoveAll();
3814 DeleteAllItems();
3816 m_logEntries.ClearAll();
3820 void CGitLogListBase::OnDestroy()
3822 // save the column widths to the registry
3823 SaveColumnWidths();
3825 SafeTerminateThread();
3826 SafeTerminateAsyncDiffThread();
3828 int retry = 0;
3829 while(m_LogCache.SaveCache())
3831 if(retry > 5)
3832 break;
3833 Sleep(1000);
3835 ++retry;
3837 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3838 // MB_YESNO) == IDNO)
3839 // break;
3842 CHintListCtrl::OnDestroy();
3845 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3847 CRect rect;
3848 int i=(int)wParam;
3849 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3850 this->InvalidateRect(rect);
3852 return 0;
3856 * Save column widths to the registry
3858 void CGitLogListBase::SaveColumnWidths()
3860 int maxcol = m_ColumnManager.GetColumnCount();
3862 // HACK that graph column is always shown
3863 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3865 for (int col = 0; col < maxcol; ++col)
3866 if (m_ColumnManager.IsVisible (col))
3867 m_ColumnManager.ColumnResized (col);
3869 m_ColumnManager.WriteSettings();
3872 int CGitLogListBase::GetHeadIndex()
3874 if(m_HeadHash.IsEmpty())
3875 return -1;
3877 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3879 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3880 if(pRev)
3882 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3883 return i;
3886 return -1;
3888 void CGitLogListBase::OnFind()
3890 if (!m_pFindDialog)
3892 m_pFindDialog = new CFindDlg(this);
3893 m_pFindDialog->Create(this);
3896 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3898 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3900 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3902 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3903 Default();
3905 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3907 if (GetSelectedCount() != 0)
3908 return 0;
3910 CGitHash theSelectedHash = m_lastSelectedHash;
3911 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3912 m_lastSelectedHash = theSelectedHash;
3914 int countPerPage = GetCountPerPage();
3915 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3916 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3917 EnsureVisible((int)itemToSelect, FALSE);
3918 return 0;
3920 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3923 ASSERT(m_pFindDialog != NULL);
3924 bool bFound = false;
3925 int i=0;
3927 if (m_pFindDialog->IsTerminating())
3929 // invalidate the handle identifying the dialog box.
3930 m_pFindDialog = NULL;
3931 return 0;
3934 INT_PTR cnt = m_arShownList.GetCount();
3936 if(m_pFindDialog->IsRef())
3938 CString str;
3939 str=m_pFindDialog->GetFindString();
3941 CGitHash hash;
3943 if(!str.IsEmpty())
3945 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3946 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3949 if(!hash.IsEmpty())
3951 for (i = 0; i < cnt; ++i)
3953 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3954 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3956 bFound = true;
3957 break;
3961 if (!bFound)
3963 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3964 return 0;
3968 if (m_pFindDialog->FindNext() && !bFound)
3970 //read data from dialog
3971 CString findText = m_pFindDialog->GetFindString();
3972 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3974 std::tr1::wregex pat;
3975 bool bRegex = false;
3976 if (m_pFindDialog->Regex())
3977 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3979 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3981 for (i = m_nSearchIndex + 1; ; ++i)
3983 if (i >= cnt)
3985 i = 0;
3986 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3988 if (m_nSearchIndex >= 0)
3990 if (i == m_nSearchIndex)
3992 ::MessageBeep(0xFFFFFFFF);
3993 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3994 break;
3998 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
4000 CString str;
4001 str+=pLogEntry->m_CommitHash.ToString();
4002 str+=_T("\n");
4004 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4006 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4007 str+=_T("\n");
4010 str+=pLogEntry->GetAuthorEmail();
4011 str+=_T("\n");
4012 str+=pLogEntry->GetAuthorName();
4013 str+=_T("\n");
4014 str+=pLogEntry->GetBody();
4015 str+=_T("\n");
4016 str+=pLogEntry->GetCommitterEmail();
4017 str+=_T("\n");
4018 str+=pLogEntry->GetCommitterName();
4019 str+=_T("\n");
4020 str+=pLogEntry->GetSubject();
4021 str+=_T("\n");
4022 str+=pLogEntry->m_Notes;
4023 str+=_T("\n");
4024 str+=GetTagInfo(pLogEntry);
4025 str+=_T("\n");
4028 /*Because changed files list is loaded on demand when gui show,
4029 files will empty when files have not fetched.
4031 we can add it back by using one-way diff(with outnumber changed and rename detect.
4032 here just need changed filename list. one-way is much quicker.
4034 if(pLogEntry->m_IsFull)
4036 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4038 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4039 str+=_T("\n");
4040 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4041 str+=_T("\n");
4044 else
4046 if(!pLogEntry->m_IsSimpleListReady)
4047 pLogEntry->SafeGetSimpleList(&g_Git);
4049 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4051 str += pLogEntry->m_SimpleFileList[j];
4052 str+=_T("\n");
4058 if (bRegex)
4060 if (std::regex_search(std::wstring(str), pat, flags))
4062 bFound = true;
4063 break;
4066 else
4068 if (bMatchCase)
4070 if (str.Find(findText) >= 0)
4072 bFound = true;
4073 break;
4077 else
4079 CString msg = str;
4080 msg = msg.MakeLower();
4081 CString find = findText.MakeLower();
4082 if (msg.Find(find) >= 0)
4084 bFound = TRUE;
4085 break;
4089 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4091 } // if(m_pFindDialog->FindNext())
4092 //UpdateLogInfoLabel();
4094 if (bFound)
4096 m_nSearchIndex = i;
4097 EnsureVisible(i, FALSE);
4098 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4100 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4101 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4102 SetSelectionMark(i);
4104 else
4106 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4107 if (pLogEntry)
4108 m_highlight = pLogEntry->m_CommitHash;
4110 Invalidate();
4111 //FillLogMessageCtrl();
4112 UpdateData(FALSE);
4115 return 0;
4118 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4120 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4122 *pResult = FALSE;
4125 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4127 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4129 Invalidate(FALSE);
4132 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4134 LVHITTESTINFO lvhitTestInfo;
4136 lvhitTestInfo.pt = point;
4138 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4139 int nSubItem = lvhitTestInfo.iSubItem;
4141 UINT nFlags = lvhitTestInfo.flags;
4143 // nFlags is 0 if the SubItemHitTest fails
4144 // Therefore, 0 & <anything> will equal false
4145 if (nFlags & LVHT_ONITEM)
4147 // Get the client area occupied by this control
4148 RECT rcClient;
4149 GetClientRect(&rcClient);
4151 // Fill in the TOOLINFO structure
4152 pTI->hwnd = m_hWnd;
4153 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4154 pTI->lpszText = LPSTR_TEXTCALLBACK;
4155 pTI->rect = rcClient;
4157 return pTI->uId; // By returning a unique value per listItem,
4158 // we ensure that when the mouse moves over another list item,
4159 // the tooltip will change
4161 else
4163 // Otherwise, we aren't interested, so let the message propagate
4164 return -1;
4168 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4170 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4171 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4173 *pResult = 0;
4175 // Ignore messages from the built in tooltip, we are processing them internally
4176 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4177 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4178 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4179 return FALSE;
4181 // Get the mouse position
4182 const MSG* pMessage = GetCurrentMessage();
4184 CPoint pt;
4185 pt = pMessage->pt;
4186 ScreenToClient(&pt);
4188 // Check if the point falls onto a list item
4189 LVHITTESTINFO lvhitTestInfo;
4190 lvhitTestInfo.pt = pt;
4192 int nItem = SubItemHitTest(&lvhitTestInfo);
4194 if (lvhitTestInfo.flags & LVHT_ONITEM)
4196 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4197 if (strTipText.IsEmpty())
4198 return FALSE;
4200 // we want multiline tooltips
4201 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4203 wcscpy_s(m_wszTip, strTipText);
4204 // handle Unicode as well as non-Unicode requests
4205 if (pNMHDR->code == TTN_NEEDTEXTA)
4207 pTTTA->hinst = nullptr;
4208 pTTTA->lpszText = m_szTip;
4209 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4211 else
4213 pTTTW->hinst = nullptr;
4214 pTTTW->lpszText = m_wszTip;
4217 CRect rect;
4218 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4219 ClientToScreen(rect);
4220 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4222 return TRUE; // We found a tool tip,
4223 // tell the framework this message has been handled
4226 return FALSE; // We didn't handle the message,
4227 // let the framework continue propagating the message
4230 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4232 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4234 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4235 if (pLogEntry == nullptr)
4236 return CString();
4237 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4238 return CString();
4239 return pLogEntry->GetSubject();
4241 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4243 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4244 if (pLogEntry == nullptr)
4245 return CString();
4246 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4248 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4250 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4251 if (pLogEntry == nullptr)
4252 return CString();
4253 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4255 else if (nSubItem == LOGLIST_ACTION)
4257 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4258 if (pLogEntry == nullptr)
4259 return CString();
4261 if (!pLogEntry->m_IsDiffFiles)
4262 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4264 int actions = pLogEntry->GetAction(this);
4265 CString sToolTipText;
4267 CString actionText;
4268 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4269 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4271 if (actions & CTGitPath::LOGACTIONS_ADDED)
4273 if (!actionText.IsEmpty())
4274 actionText += L"\r\n";
4275 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4278 if (actions & CTGitPath::LOGACTIONS_DELETED)
4280 if (!actionText.IsEmpty())
4281 actionText += L"\r\n";
4282 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4285 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4287 if (!actionText.IsEmpty())
4288 actionText += L"\r\n";
4289 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4292 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4294 if (!actionText.IsEmpty())
4295 actionText += L"\r\n";
4296 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4299 if (!actionText.IsEmpty())
4301 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4302 sToolTipText = sTitle + L":\r\n" + actionText;
4304 return sToolTipText;
4306 return CString();