Fix IntelliSense error: expression must have a constant value
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob115f542dab44f677e355b151cb25405cd93149bb
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)));
1899 for (size_t i = 0; i < parentHash.size(); ++i)
1901 CString str;
1902 str.Format(IDS_PARENT, i + 1);
1903 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1905 requiresSeparator = true;
1909 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1911 if (parentHash.size() == 1)
1913 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1914 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1915 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1916 requiresSeparator = true;
1918 else if (parentHash.size() > 1)
1920 diffmenu.CreatePopupMenu();
1921 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1922 for (size_t i = 0; i < parentHash.size(); ++i)
1924 CString str;
1925 str.Format(IDS_PARENT, i + 1);
1926 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1927 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1929 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1930 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1933 requiresSeparator = true;
1937 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1939 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1940 requiresSeparator = true;
1943 if (requiresSeparator)
1944 popup.AppendMenu(MF_SEPARATOR, NULL);
1946 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1948 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1949 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1952 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1954 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1955 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1957 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1958 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1960 popup.AppendMenu(MF_SEPARATOR, NULL);
1963 if (pSelLogEntry->m_CommitHash.IsEmpty())
1965 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1966 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1968 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1969 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1971 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1972 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1974 popup.AppendMenu(MF_SEPARATOR, NULL);
1976 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1977 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1979 popup.AppendMenu(MF_SEPARATOR, NULL);
1983 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1984 // {
1985 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1986 // }
1987 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1988 // {
1989 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1990 // }
1991 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1992 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1993 // {
1994 // popup.AppendMenu(MF_SEPARATOR, NULL);
1995 // }
1997 CString str,format;
1998 //if (m_hasWC)
1999 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2001 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2003 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2004 GetSelectedCount() == 1)
2005 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2007 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2008 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2010 format.LoadString(IDS_LOG_POPUP_MERGEREV);
2011 str.Format(format,g_Git.GetCurrentBranch());
2013 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2014 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2016 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2017 str.Format(format,g_Git.GetCurrentBranch());
2019 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2020 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2023 // Add Switch Branch express Menu
2024 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2025 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2028 std::vector<CString *> branchs;
2029 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2031 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2032 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2034 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2038 CString str2;
2039 str2.LoadString(IDS_SWITCH_BRANCH);
2041 if(branchs.size() == 1)
2043 str2 += _T(" ");
2044 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2045 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2047 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2050 else if(branchs.size() > 1)
2052 subbranchmenu.CreatePopupMenu();
2053 for (size_t i = 0 ; i < branchs.size(); ++i)
2055 if (*branchs[i] != currentBranch)
2057 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2058 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2062 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2066 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2067 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2069 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2070 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2072 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2073 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2075 format.LoadString(IDS_REBASE_THIS_FORMAT);
2076 str.Format(format,g_Git.GetCurrentBranch());
2078 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2079 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2080 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2082 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2083 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2085 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2087 if (parentHash.size() == 1)
2089 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2091 else if (parentHash.size() > 1)
2093 revertmenu.CreatePopupMenu();
2094 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2096 for (size_t i = 0; i < parentHash.size(); ++i)
2098 CString str2;
2099 str2.Format(IDS_PARENT, i + 1);
2100 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2105 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2106 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2108 popup.AppendMenu(MF_SEPARATOR, NULL);
2113 if(!pSelLogEntry->m_Ref.IsEmpty())
2115 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2116 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2117 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2118 popup.AppendMenu(MF_SEPARATOR, NULL);
2121 if (GetSelectedCount() >= 2)
2123 bool bAddSeparator = false;
2124 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2126 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2127 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2130 if (GetSelectedCount() == 2)
2132 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2133 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2135 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2137 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2138 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2139 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2140 CString menu;
2141 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2142 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2143 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2144 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2147 bAddSeparator = true;
2150 if (m_hasWC)
2152 bAddSeparator = true;
2155 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2156 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2158 if (bAddSeparator)
2159 popup.AppendMenu(MF_SEPARATOR, NULL);
2162 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2164 bool bAddSeparator = false;
2165 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2167 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2169 CString head;
2170 int headindex;
2171 headindex = this->GetHeadIndex();
2172 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2174 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2175 CGitHash hashFirst;
2176 if (g_Git.GetHash(hashFirst, head))
2177 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2178 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2179 CGitHash hash;
2180 if (g_Git.GetHash(hash, head))
2181 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2182 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2183 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2184 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2185 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2186 bAddSeparator = true;
2191 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2192 if (GetSelectedCount() >= 2)
2193 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2194 else
2195 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2196 bAddSeparator = true;
2199 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2200 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2201 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2202 bAddSeparator = true;
2205 if (bAddSeparator)
2206 popup.AppendMenu(MF_SEPARATOR, NULL);
2209 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())
2211 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2212 popup.AppendMenu(MF_SEPARATOR, NULL);
2215 if (GetSelectedCount() == 1)
2217 bool bAddSeparator = false;
2218 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2220 // show the push-option only if the log entry has an associated local branch
2221 bool isLocal = false;
2222 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2224 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2225 isLocal = true;
2227 if (isLocal || showExtendedMenu)
2229 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2230 bAddSeparator = true;
2233 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2235 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2236 bAddSeparator = true;
2240 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2242 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2244 std::vector<CString *> branchs;
2245 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2247 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2248 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2250 CString str;
2251 if (branchs.size() == 1)
2253 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2254 str+=_T(" ");
2255 str += *branchs[0];
2256 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2257 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2258 bAddSeparator = true;
2260 else if (branchs.size() > 1)
2262 str.LoadString(IDS_DELETE_BRANCHTAG);
2263 submenu.CreatePopupMenu();
2264 for (size_t i = 0; i < branchs.size(); ++i)
2266 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2267 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2270 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2271 bAddSeparator = true;
2274 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2275 if (bAddSeparator)
2276 popup.AppendMenu(MF_SEPARATOR, NULL);
2277 } // GetSelectedCount() == 1
2279 if (GetSelectedCount() != 0)
2281 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2282 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2283 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2284 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2285 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2286 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2289 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2290 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2292 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2293 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2295 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2296 // DialogEnableWindow(IDOK, FALSE);
2297 // SetPromptApp(&theApp);
2299 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2301 // EnableOKButton();
2302 } // if (popup.CreatePopupMenu())
2306 bool CGitLogListBase::IsSelectionContinuous()
2308 if ( GetSelectedCount()==1 )
2310 // if only one revision is selected, the selection is of course
2311 // continuous
2312 return true;
2315 POSITION pos = GetFirstSelectedItemPosition();
2316 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2317 if (bContinuous)
2319 int itemindex = GetNextSelectedItem(pos);
2320 while (pos)
2322 int nextindex = GetNextSelectedItem(pos);
2323 if (nextindex - itemindex > 1)
2325 bContinuous = false;
2326 break;
2328 itemindex = nextindex;
2331 return bContinuous;
2334 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2337 CString sClipdata;
2338 POSITION pos = GetFirstSelectedItemPosition();
2339 if (pos != NULL)
2341 CString sRev;
2342 sRev.LoadString(IDS_LOG_REVISION);
2343 CString sAuthor;
2344 sAuthor.LoadString(IDS_LOG_AUTHOR);
2345 CString sDate;
2346 sDate.LoadString(IDS_LOG_DATE);
2347 CString sMessage;
2348 sMessage.LoadString(IDS_LOG_MESSAGE);
2349 bool first = true;
2350 while (pos)
2352 CString sLogCopyText;
2353 CString sPaths;
2354 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2356 if (toCopy == ID_COPY_ALL)
2358 //pLogEntry->GetFiles(this)
2359 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2361 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2362 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2364 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2365 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2367 CString rename;
2368 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2369 sPaths += _T(" ") + rename;
2371 sPaths += _T("\r\n");
2373 sPaths.Trim();
2374 CString body = pLogEntry->GetBody();
2375 body.Replace(_T("\n"), _T("\r\n"));
2376 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"),
2377 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2378 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2379 (LPCTSTR)sDate,
2380 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2381 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2382 (LPCTSTR)sPaths);
2383 sClipdata += sLogCopyText;
2385 else if (toCopy == ID_COPY_MESSAGE)
2387 CString body = pLogEntry->GetBody();
2388 body.Replace(_T("\n"), _T("\r\n"));
2389 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2391 else if (toCopy == ID_COPY_SUBJECT)
2393 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2395 else
2397 if (!first)
2398 sClipdata += _T("\r\n");
2399 sClipdata += pLogEntry->m_CommitHash;
2402 first = false;
2404 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2409 void CGitLogListBase::DiffSelectedRevWithPrevious()
2411 if (m_bThreadRunning)
2412 return;
2414 int FirstSelect=-1, LastSelect=-1;
2415 POSITION pos = GetFirstSelectedItemPosition();
2416 FirstSelect = GetNextSelectedItem(pos);
2417 while(pos)
2419 LastSelect = GetNextSelectedItem(pos);
2422 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2424 #if 0
2425 UpdateLogInfoLabel();
2426 int selIndex = m_LogList.GetSelectionMark();
2427 if (selIndex < 0)
2428 return;
2429 int selCount = m_LogList.GetSelectedCount();
2430 if (selCount != 1)
2431 return;
2433 // Find selected entry in the log list
2434 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2435 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2436 long rev1 = pLogEntry->Rev;
2437 long rev2 = rev1-1;
2438 CTGitPath path = m_path;
2440 // See how many files under the relative root were changed in selected revision
2441 int nChanged = 0;
2442 LogChangedPath * changed = NULL;
2443 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2445 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2446 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2448 ++nChanged;
2449 changed = cpath;
2453 if (m_path.IsDirectory() && nChanged == 1)
2455 // We're looking at the log for a directory and only one file under dir was changed in the revision
2456 // Do diff on that file instead of whole directory
2457 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2460 m_bCancelled = FALSE;
2461 DialogEnableWindow(IDOK, FALSE);
2462 SetPromptApp(&theApp);
2463 theApp.DoWaitCursor(1);
2465 if (PromptShown())
2467 GitDiff diff(this, m_hWnd, true);
2468 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2469 diff.SetHEADPeg(m_LogRevision);
2470 diff.ShowCompare(path, rev2, path, rev1);
2472 else
2474 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2477 theApp.DoWaitCursor(-1);
2478 EnableOKButton();
2479 #endif
2482 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2484 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2485 *pResult = -1;
2487 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2488 return;
2489 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2490 return;
2491 if (pFindInfo->lvfi.psz == 0)
2492 return;
2493 #if 0
2494 CString sCmp = pFindInfo->lvfi.psz;
2495 CString sRev;
2496 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2498 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2499 sRev.Format(_T("%ld"), pLogEntry->Rev);
2500 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2502 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2504 *pResult = i;
2505 return;
2508 else
2510 if (sCmp.Compare(sRev)==0)
2512 *pResult = i;
2513 return;
2517 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2519 for (int i=0; i<pFindInfo->iStart; ++i)
2521 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2522 sRev.Format(_T("%ld"), pLogEntry->Rev);
2523 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2525 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2527 *pResult = i;
2528 return;
2531 else
2533 if (sCmp.Compare(sRev)==0)
2535 *pResult = i;
2536 return;
2541 #endif
2542 *pResult = -1;
2545 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2547 ClearText();
2549 this->m_arShownList.SafeRemoveAll();
2551 this->m_logEntries.ClearAll();
2552 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2553 return -1;
2555 SetItemCountEx((int)m_logEntries.size());
2557 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2559 if(m_IsOldFirst)
2561 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2562 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2565 else
2567 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2568 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2572 ReloadHashMap();
2574 if(path)
2575 m_Path=*path;
2576 return 0;
2580 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2582 ClearText();
2584 m_arShownList.SafeRemoveAll();
2586 m_logEntries.ClearAll();
2587 if (m_logEntries.Fill(hashes))
2588 return -1;
2590 SetItemCountEx((int)m_logEntries.size());
2592 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2594 if (m_IsOldFirst)
2596 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2597 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2599 else
2601 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2602 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2606 ReloadHashMap();
2608 return 0;
2611 int CGitLogListBase::BeginFetchLog()
2613 ClearText();
2615 this->m_arShownList.SafeRemoveAll();
2617 this->m_logEntries.ClearAll();
2619 this->m_LogCache.ClearAllParent();
2621 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2623 CTGitPath *path;
2624 if(this->m_Path.IsEmpty())
2625 path=NULL;
2626 else
2627 path=&this->m_Path;
2629 int mask;
2630 mask = CGit::LOG_INFO_ONLY_HASH;
2631 if (m_bIncludeBoundaryCommits)
2632 mask |= CGit::LOG_INFO_BOUNDARY;
2633 // if(this->m_bAllBranch)
2634 mask |= m_ShowMask ;
2636 if(m_bShowWC)
2638 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2639 ResetWcRev();
2640 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2643 if (m_sRange.IsEmpty())
2644 m_sRange = _T("HEAD");
2646 CFilterData data;
2647 data.m_From = m_From;
2648 data.m_To =m_To;
2650 #if 0 /* use tortoiegit filter */
2651 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2652 data.m_Author = this->m_sFilterText;
2654 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2655 data.m_MessageFilter = this->m_sFilterText;
2657 data.m_IsRegex = m_bFilterWithRegex;
2658 #endif
2660 // follow does not work for directories
2661 if (!path || path->IsDirectory())
2662 mask &= ~CGit::LOG_INFO_FOLLOW;
2663 // follow does not work with all branches 8at least in TGit)
2664 if (mask & CGit::LOG_INFO_FOLLOW)
2665 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2667 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2669 //this->m_logEntries.ParserFromLog();
2670 if(IsInWorkingThread())
2672 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2674 else
2676 SetItemCountEx((int)m_logEntries.size());
2681 [] { git_init(); } ();
2683 catch (char* msg)
2685 CString err(msg);
2686 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2687 return -1;
2690 if (!g_Git.CanParseRev(m_sRange))
2692 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2693 return 0;
2695 // if show all branches, pick any ref as dummy entry ref
2696 STRING_VECTOR list;
2697 if (g_Git.GetRefList(list))
2698 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2699 if (list.size() == 0)
2700 return 0;
2702 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2705 g_Git.m_critGitDllSec.Lock();
2706 try {
2707 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2709 g_Git.m_critGitDllSec.Unlock();
2710 return -1;
2713 catch (char* msg)
2715 g_Git.m_critGitDllSec.Unlock();
2716 CString err(msg);
2717 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2718 return -1;
2720 g_Git.m_critGitDllSec.Unlock();
2722 return 0;
2725 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2727 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2729 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2731 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2733 DiffSelectedRevWithPrevious();
2734 return TRUE;
2737 #if 0
2738 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2740 DiffSelectedFile();
2741 return TRUE;
2743 #endif
2745 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2747 // select all entries
2748 for (int i=0; i<GetItemCount(); ++i)
2750 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2752 return TRUE;
2755 #if 0
2756 if (m_hAccel && !bSkipAccelerator)
2758 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2759 if (ret)
2760 return TRUE;
2763 #endif
2764 //m_tooltips.RelayEvent(pMsg);
2765 return __super::PreTranslateMessage(pMsg);
2768 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2770 // a double click on an entry in the revision list has happened
2771 *pResult = 0;
2773 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2774 DiffSelectedRevWithPrevious();
2777 int CGitLogListBase::FetchLogAsync(void * data)
2779 ReloadHashMap();
2780 m_ProcData=data;
2781 m_bExitThread=FALSE;
2782 InterlockedExchange(&m_bThreadRunning, TRUE);
2783 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2784 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2785 if (m_LoadingThread ==NULL)
2787 InterlockedExchange(&m_bThreadRunning, FALSE);
2788 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2789 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2790 return -1;
2792 return 0;
2795 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2797 return ((CGitLogListBase*)pVoid)->LogThread();
2800 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2802 //CTime time;
2803 oldest=CTime::GetCurrentTime();
2804 latest=CTime(1971,1,2,0,0,0);
2805 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2807 if(m_logEntries[i].IsEmpty())
2808 continue;
2810 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2811 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2813 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2814 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2818 if(latest<oldest)
2819 latest=oldest;
2822 UINT CGitLogListBase::LogThread()
2824 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2826 InterlockedExchange(&m_bThreadRunning, TRUE);
2827 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2829 ULONGLONG t1,t2;
2831 if(BeginFetchLog())
2833 InterlockedExchange(&m_bThreadRunning, FALSE);
2834 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2836 return 1;
2839 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2840 bool bRegex = false;
2841 if (m_bFilterWithRegex)
2842 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2844 TRACE(_T("\n===Begin===\n"));
2845 //Update work copy item;
2847 if (!m_logEntries.empty())
2849 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2851 m_arShownList.SafeAdd(pRev);
2855 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2857 // store commit number of the last selected commit/line before the refresh or -1
2858 int lastSelectedHashNItem = -1;
2859 int ret = 0;
2861 bool shouldWalk = true;
2862 if (!g_Git.CanParseRev(m_sRange))
2864 // walk revisions if show all branches and there exists any ref
2865 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2866 shouldWalk = false;
2867 else
2869 STRING_VECTOR list;
2870 if (g_Git.GetRefList(list))
2871 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2872 if (list.size() == 0)
2873 shouldWalk = false;
2877 if (shouldWalk)
2879 g_Git.m_critGitDllSec.Lock();
2880 int total = 0;
2883 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2884 total = git_get_log_estimate_commit_count(m_DllGitLog);
2886 catch (char* msg)
2888 CString err(msg);
2889 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2890 ret = -1;
2892 g_Git.m_critGitDllSec.Unlock();
2894 GIT_COMMIT commit;
2895 t2=t1=GetTickCount();
2896 int oldprecentage = 0;
2897 size_t oldsize = m_logEntries.size();
2898 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2899 while (ret== 0 && !m_bExitThread)
2901 g_Git.m_critGitDllSec.Lock();
2904 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2906 catch (char* msg)
2908 g_Git.m_critGitDllSec.Unlock();
2909 CString err(msg);
2910 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2911 break;
2913 g_Git.m_critGitDllSec.Unlock();
2915 if(ret)
2917 if (ret != -2) // other than end of revision walking
2918 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2919 break;
2922 if (commit.m_ignore == 1)
2924 git_free_commit(&commit);
2925 continue;
2928 //printf("%s\r\n",commit.GetSubject());
2929 if(m_bExitThread)
2930 break;
2932 CGitHash hash = (char*)commit.m_hash ;
2934 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2935 pRev->m_GitCommit = commit;
2936 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2938 char *note=NULL;
2939 g_Git.m_critGitDllSec.Lock();
2942 git_get_notes(commit.m_hash, &note);
2944 catch (char* msg)
2946 g_Git.m_critGitDllSec.Unlock();
2947 CString err(msg);
2948 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2949 break;
2951 g_Git.m_critGitDllSec.Unlock();
2953 if(note)
2955 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2956 free(note);
2957 note = nullptr;
2960 if(!pRev->m_IsDiffFiles)
2962 pRev->m_CallDiffAsync = DiffAsync;
2965 pRev->ParserParentFromCommit(&commit);
2966 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2968 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2970 const CGitHash &parentHash = pRev->m_ParentHash[i];
2971 auto it = commitChildren.find(parentHash);
2972 if (it == commitChildren.end())
2974 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2976 it->second.insert(pRev->m_CommitHash);
2980 #ifdef DEBUG
2981 pRev->DbgPrint();
2982 TRACE(_T("\n"));
2983 #endif
2985 bool visible = true;
2986 if (HasFilterText())
2988 if(!IsMatchFilter(bRegex,pRev,pat))
2989 visible = false;
2991 if (visible && !ShouldShowFilter(pRev, commitChildren))
2992 visible = false;
2993 this->m_critSec.Lock();
2994 m_logEntries.append(hash, visible);
2995 if (visible)
2996 m_arShownList.SafeAdd(pRev);
2997 this->m_critSec.Unlock();
2999 if (!visible)
3000 continue;
3002 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3003 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3005 t2=GetTickCount();
3007 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3009 //update UI
3010 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3011 if(percent > 99)
3012 percent =99;
3013 if(percent < GITLOG_START)
3014 percent = GITLOG_START +1;
3016 oldsize = m_logEntries.size();
3017 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3019 //if( percent > oldprecentage )
3021 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3022 oldprecentage = percent;
3025 if (lastSelectedHashNItem >= 0)
3026 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3028 t1 = t2;
3031 g_Git.m_critGitDllSec.Lock();
3032 git_close_log(m_DllGitLog);
3033 g_Git.m_critGitDllSec.Unlock();
3037 if (m_bExitThread)
3039 InterlockedExchange(&m_bThreadRunning, FALSE);
3040 return 0;
3043 //Update UI;
3044 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3046 if (lastSelectedHashNItem >= 0)
3047 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3049 if (this->m_hWnd)
3050 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3052 InterlockedExchange(&m_bThreadRunning, FALSE);
3054 return 0;
3057 void CGitLogListBase::FetchRemoteList()
3059 STRING_VECTOR remoteList;
3060 if (!g_Git.GetRemoteList(remoteList))
3061 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3062 else
3063 m_SingleRemote = _T("");
3066 void CGitLogListBase::FetchTrackingBranchList()
3068 m_TrackingMap.clear();
3069 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3071 for (size_t j = 0; j < it->second.size(); ++j)
3073 CString branchName;
3074 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3076 CString pullRemote, pullBranch;
3077 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3078 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3080 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3087 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3089 SafeTerminateThread();
3091 this->SetItemCountEx(0);
3092 this->Clear();
3094 ResetWcRev();
3096 // HACK to hide graph column
3097 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3098 SetColumnWidth(0, 0);
3099 else
3100 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3102 //Update branch and Tag info
3103 ReloadHashMap();
3104 if (m_pFindDialog)
3105 m_pFindDialog->RefreshList();
3106 //Assume Thread have exited
3107 //if(!m_bThreadRunning)
3109 m_logEntries.clear();
3111 if(IsCleanFilter)
3113 m_sFilterText.Empty();
3114 m_From=-1;
3115 m_To=-1;
3118 InterlockedExchange(&m_bExitThread,FALSE);
3120 InterlockedExchange(&m_bThreadRunning, TRUE);
3121 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3122 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3124 InterlockedExchange(&m_bThreadRunning, FALSE);
3125 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3126 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3130 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3134 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3135 if (!bMatchCase)
3136 type |= std::tr1::regex_constants::icase;
3137 pat = std::tr1::wregex(regexp_str, type);
3138 return true;
3140 catch (std::exception) {}
3141 return false;
3143 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3145 BOOL result = TRUE;
3146 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3147 CString sRev;
3149 if ((bRegex)&&(m_bFilterWithRegex))
3151 if (m_SelectedFilters & LOGFILTER_BUGID)
3153 if(this->m_bShowBugtraqColumn)
3155 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3157 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3158 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3160 return TRUE;
3165 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3167 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3168 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3170 return TRUE;
3174 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3176 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3177 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3179 return TRUE;
3183 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3185 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3187 return TRUE;
3190 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3192 return TRUE;
3196 if (m_SelectedFilters & LOGFILTER_EMAILS)
3198 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3200 return TRUE;
3203 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3205 return TRUE;
3209 if (m_SelectedFilters & LOGFILTER_REVS)
3211 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3212 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3214 return TRUE;
3218 if (m_SelectedFilters & LOGFILTER_REFNAME)
3220 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3221 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3223 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3225 return TRUE;
3230 if (m_SelectedFilters & LOGFILTER_PATHS)
3232 CTGitPathList *pathList=NULL;
3233 if( pRev->m_IsDiffFiles)
3234 pathList = &pRev->GetFiles(this);
3235 else
3237 if(!pRev->m_IsSimpleListReady)
3238 pRev->SafeGetSimpleList(&g_Git);
3241 if(pathList)
3242 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3244 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3246 return true;
3248 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3250 return true;
3254 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3256 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3258 return true;
3263 else
3265 CString find = m_sFilterText;
3266 if (!m_bFilterCaseSensitively)
3267 find.MakeLower();
3268 result = find[0] == '!' ? FALSE : TRUE;
3269 if (!result)
3270 find = find.Mid(1);
3272 if (m_SelectedFilters & LOGFILTER_BUGID)
3274 if(this->m_bShowBugtraqColumn)
3276 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3278 if (!m_bFilterCaseSensitively)
3279 sBugIds.MakeLower();
3280 if ((sBugIds.Find(find) >= 0))
3282 return result;
3287 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3289 CString msg = pRev->GetSubject();
3291 if (!m_bFilterCaseSensitively)
3292 msg = msg.MakeLower();
3293 if ((msg.Find(find) >= 0))
3295 return result;
3299 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3301 CString msg = pRev->GetBody();
3303 if (!m_bFilterCaseSensitively)
3304 msg = msg.MakeLower();
3305 if ((msg.Find(find) >= 0))
3307 return result;
3311 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3313 CString msg = pRev->GetAuthorName();
3314 if (!m_bFilterCaseSensitively)
3315 msg = msg.MakeLower();
3316 if ((msg.Find(find) >= 0))
3318 return result;
3322 if (m_SelectedFilters & LOGFILTER_EMAILS)
3324 CString msg = pRev->GetAuthorEmail();
3325 if (!m_bFilterCaseSensitively)
3326 msg = msg.MakeLower();
3327 if ((msg.Find(find) >= 0))
3329 return result;
3333 if (m_SelectedFilters & LOGFILTER_REVS)
3335 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3336 if ((sRev.Find(find) >= 0))
3338 return result;
3342 if (m_SelectedFilters & LOGFILTER_REFNAME)
3344 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3345 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3347 if (it->Find(find) >= 0)
3349 return result;
3354 if (m_SelectedFilters & LOGFILTER_PATHS)
3356 CTGitPathList *pathList=NULL;
3357 if( pRev->m_IsDiffFiles)
3358 pathList = &pRev->GetFiles(this);
3359 else
3361 if(!pRev->m_IsSimpleListReady)
3362 pRev->SafeGetSimpleList(&g_Git);
3364 if(pathList)
3365 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3367 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3368 CString path = cpath->GetGitOldPathString();
3369 if (!m_bFilterCaseSensitively)
3370 path.MakeLower();
3371 if ((path.Find(find)>=0))
3373 return result;
3375 path = cpath->GetGitPathString();
3376 if (!m_bFilterCaseSensitively)
3377 path.MakeLower();
3378 if ((path.Find(find)>=0))
3380 return result;
3384 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3386 CString path = pRev->m_SimpleFileList[i];
3387 if (!m_bFilterCaseSensitively)
3388 path.MakeLower();
3389 if ((path.Find(find)>=0))
3391 return result;
3395 } // else (from if (bRegex))
3396 return !result;
3399 static bool CStringStartsWith(const CString &str, const CString &prefix)
3401 return str.Left(prefix.GetLength()) == prefix;
3403 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3405 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3406 return true;
3408 if (m_ShowFilter & FILTERSHOW_REFS)
3410 // Keep all refs.
3411 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3412 for (size_t i = 0; i < refList.size(); ++i)
3414 const CString &str = refList[i];
3415 if (CStringStartsWith(str, _T("refs/heads/")))
3417 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3418 return true;
3420 else if (CStringStartsWith(str, _T("refs/remotes/")))
3422 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3423 return true;
3425 else if (CStringStartsWith(str, _T("refs/tags/")))
3427 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3428 return true;
3430 else if (CStringStartsWith(str, _T("refs/stash")))
3432 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3433 return true;
3435 else if (CStringStartsWith(str, _T("refs/bisect/")))
3437 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3438 return true;
3441 // Keep the head too.
3442 if (pRev->m_CommitHash == m_HeadHash)
3443 return true;
3446 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3448 if (pRev->ParentsCount() > 1)
3449 return true;
3450 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3451 if (childrenIt != commitChildren.end())
3453 const std::set<CGitHash> &children = childrenIt->second;
3454 if (children.size() > 1)
3455 return true;
3458 return false;
3461 void CGitLogListBase::ShowGraphColumn(bool bShow)
3463 // HACK to hide graph column
3464 if (bShow)
3465 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3466 else
3467 SetColumnWidth(0, 0);
3470 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3472 CString cmd;
3473 CString output;
3475 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3477 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3478 for (size_t i = 0; i < vector.size(); ++i)
3480 if (vector[i].Find(_T("refs/tags/")) == 0)
3482 CString tag = vector[i];
3483 int start = vector[i].Find(_T("^{}"));
3484 if (start > 0)
3485 tag = tag.Left(start);
3486 else
3487 continue;
3489 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3490 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3491 output.AppendChar(_T('\n'));
3496 return output;
3499 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3502 pShownlist->SafeRemoveAll();
3504 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3505 bool bRegex = false;
3506 if (m_bFilterWithRegex)
3507 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3509 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3510 CString sRev;
3511 for (DWORD i=0; i<m_logEntries.size(); ++i)
3513 if ((bRegex)&&(m_bFilterWithRegex))
3515 #if 0
3516 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3518 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3519 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3521 pShownlist->SafeAdd(m_logEntries[i]);
3522 continue;
3525 #endif
3526 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3528 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3529 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3531 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3532 continue;
3535 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3537 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3538 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3540 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3541 continue;
3544 if (m_SelectedFilters & LOGFILTER_PATHS)
3546 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3548 bool bGoing = true;
3549 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3551 CTGitPath cpath = pathList[cpPathIndex];
3552 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3554 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3555 bGoing = false;
3556 continue;
3558 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3560 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3561 bGoing = false;
3562 continue;
3564 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3566 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3567 bGoing = false;
3568 continue;
3572 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3574 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3576 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3577 continue;
3580 if (m_SelectedFilters & LOGFILTER_EMAILS)
3582 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3584 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3585 continue;
3588 if (m_SelectedFilters & LOGFILTER_REVS)
3590 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3591 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3593 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3594 continue;
3597 if (m_SelectedFilters & LOGFILTER_REFNAME)
3599 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3600 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3602 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3604 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3605 continue;
3609 } // if (bRegex)
3610 else
3612 CString find = m_sFilterText;
3613 if (!m_bFilterCaseSensitively)
3614 find.MakeLower();
3615 #if 0
3616 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3618 CString sBugIDs = m_logEntries[i]->sBugIDs;
3620 if (!m_bFilterCaseSensitively)
3621 sBugIDs = sBugIDs.MakeLower();
3622 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3624 pShownlist->SafeAdd(m_logEntries[i]);
3625 continue;
3628 #endif
3629 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3631 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3633 if (!m_bFilterCaseSensitively)
3634 msg = msg.MakeLower();
3635 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3637 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3638 continue;
3641 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3643 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3645 if (!m_bFilterCaseSensitively)
3646 msg = msg.MakeLower();
3647 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3649 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3650 continue;
3653 if (m_SelectedFilters & LOGFILTER_PATHS)
3655 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3657 bool bGoing = true;
3658 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3660 CTGitPath cpath = pathList[cpPathIndex];
3661 CString path = cpath.GetGitOldPathString();
3662 if (!m_bFilterCaseSensitively)
3663 path.MakeLower();
3664 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3666 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3667 bGoing = false;
3668 continue;
3670 path = cpath.GetGitPathString();
3671 if (!m_bFilterCaseSensitively)
3672 path.MakeLower();
3673 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3675 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3676 bGoing = false;
3677 continue;
3679 path = cpath.GetActionName();
3680 if (!m_bFilterCaseSensitively)
3681 path.MakeLower();
3682 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3684 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3685 bGoing = false;
3686 continue;
3690 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3692 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3693 if (!m_bFilterCaseSensitively)
3694 msg = msg.MakeLower();
3695 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3697 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3698 continue;
3701 if (m_SelectedFilters & LOGFILTER_EMAILS)
3703 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3704 if (!m_bFilterCaseSensitively)
3705 msg = msg.MakeLower();
3706 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3708 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3709 continue;
3712 if (m_SelectedFilters & LOGFILTER_REVS)
3714 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3715 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3717 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3718 continue;
3721 if (m_SelectedFilters & LOGFILTER_REFNAME)
3723 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3724 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3726 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3728 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3729 continue;
3733 } // else (from if (bRegex))
3734 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3738 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3741 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3743 if(m_From == -1)
3744 if(m_To == -1)
3745 return true;
3746 else
3747 return time <= m_To;
3748 else
3749 if(m_To == -1)
3750 return time >= m_From;
3751 else
3752 return ((time >= m_From)&&(time <= m_To));
3754 return TRUE; /* git dll will filter time range */
3756 // return TRUE;
3758 void CGitLogListBase::StartFilter()
3760 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3761 RecalculateShownList(&m_arShownList);
3762 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3765 DeleteAllItems();
3766 SetItemCountEx(ShownCountWithStopped());
3767 RedrawItems(0, ShownCountWithStopped());
3768 Invalidate();
3771 void CGitLogListBase::RemoveFilter()
3774 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3776 m_arShownList.SafeRemoveAll();
3778 // reset the time filter too
3779 #if 0
3780 m_timFrom = (__time64_t(m_tFrom));
3781 m_timTo = (__time64_t(m_tTo));
3782 m_DateFrom.SetTime(&m_timFrom);
3783 m_DateTo.SetTime(&m_timTo);
3784 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3785 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3786 #endif
3788 for (DWORD i=0; i<m_logEntries.size(); ++i)
3790 if(this->m_IsOldFirst)
3792 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3794 else
3796 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3799 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3800 DeleteAllItems();
3801 SetItemCountEx(ShownCountWithStopped());
3802 RedrawItems(0, ShownCountWithStopped());
3804 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3807 void CGitLogListBase::Clear()
3809 m_arShownList.SafeRemoveAll();
3810 DeleteAllItems();
3812 m_logEntries.ClearAll();
3816 void CGitLogListBase::OnDestroy()
3818 // save the column widths to the registry
3819 SaveColumnWidths();
3821 SafeTerminateThread();
3822 SafeTerminateAsyncDiffThread();
3824 int retry = 0;
3825 while(m_LogCache.SaveCache())
3827 if(retry > 5)
3828 break;
3829 Sleep(1000);
3831 ++retry;
3833 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3834 // MB_YESNO) == IDNO)
3835 // break;
3838 CHintListCtrl::OnDestroy();
3841 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3843 CRect rect;
3844 int i=(int)wParam;
3845 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3846 this->InvalidateRect(rect);
3848 return 0;
3852 * Save column widths to the registry
3854 void CGitLogListBase::SaveColumnWidths()
3856 int maxcol = m_ColumnManager.GetColumnCount();
3858 // HACK that graph column is always shown
3859 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3861 for (int col = 0; col < maxcol; ++col)
3862 if (m_ColumnManager.IsVisible (col))
3863 m_ColumnManager.ColumnResized (col);
3865 m_ColumnManager.WriteSettings();
3868 int CGitLogListBase::GetHeadIndex()
3870 if(m_HeadHash.IsEmpty())
3871 return -1;
3873 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3875 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3876 if(pRev)
3878 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3879 return i;
3882 return -1;
3884 void CGitLogListBase::OnFind()
3886 if (!m_pFindDialog)
3888 m_pFindDialog = new CFindDlg(this);
3889 m_pFindDialog->Create(this);
3892 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3894 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3896 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3898 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3899 Default();
3901 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3903 if (GetSelectedCount() != 0)
3904 return 0;
3906 CGitHash theSelectedHash = m_lastSelectedHash;
3907 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3908 m_lastSelectedHash = theSelectedHash;
3910 int countPerPage = GetCountPerPage();
3911 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3912 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3913 EnsureVisible((int)itemToSelect, FALSE);
3914 return 0;
3916 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3919 ASSERT(m_pFindDialog != NULL);
3920 bool bFound = false;
3921 int i=0;
3923 if (m_pFindDialog->IsTerminating())
3925 // invalidate the handle identifying the dialog box.
3926 m_pFindDialog = NULL;
3927 return 0;
3930 INT_PTR cnt = m_arShownList.GetCount();
3932 if(m_pFindDialog->IsRef())
3934 CString str;
3935 str=m_pFindDialog->GetFindString();
3937 CGitHash hash;
3939 if(!str.IsEmpty())
3941 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3942 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3945 if(!hash.IsEmpty())
3947 for (i = 0; i < cnt; ++i)
3949 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3950 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3952 bFound = true;
3953 break;
3957 if (!bFound)
3959 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3960 return 0;
3964 if (m_pFindDialog->FindNext() && !bFound)
3966 //read data from dialog
3967 CString findText = m_pFindDialog->GetFindString();
3968 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3970 std::tr1::wregex pat;
3971 bool bRegex = false;
3972 if (m_pFindDialog->Regex())
3973 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3975 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3977 for (i = m_nSearchIndex + 1; ; ++i)
3979 if (i >= cnt)
3981 i = 0;
3982 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3984 if (m_nSearchIndex >= 0)
3986 if (i == m_nSearchIndex)
3988 ::MessageBeep(0xFFFFFFFF);
3989 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3990 break;
3994 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
3996 CString str;
3997 str+=pLogEntry->m_CommitHash.ToString();
3998 str+=_T("\n");
4000 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4002 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4003 str+=_T("\n");
4006 str+=pLogEntry->GetAuthorEmail();
4007 str+=_T("\n");
4008 str+=pLogEntry->GetAuthorName();
4009 str+=_T("\n");
4010 str+=pLogEntry->GetBody();
4011 str+=_T("\n");
4012 str+=pLogEntry->GetCommitterEmail();
4013 str+=_T("\n");
4014 str+=pLogEntry->GetCommitterName();
4015 str+=_T("\n");
4016 str+=pLogEntry->GetSubject();
4017 str+=_T("\n");
4018 str+=pLogEntry->m_Notes;
4019 str+=_T("\n");
4020 str+=GetTagInfo(pLogEntry);
4021 str+=_T("\n");
4024 /*Because changed files list is loaded on demand when gui show,
4025 files will empty when files have not fetched.
4027 we can add it back by using one-way diff(with outnumber changed and rename detect.
4028 here just need changed filename list. one-way is much quicker.
4030 if(pLogEntry->m_IsFull)
4032 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4034 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4035 str+=_T("\n");
4036 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4037 str+=_T("\n");
4040 else
4042 if(!pLogEntry->m_IsSimpleListReady)
4043 pLogEntry->SafeGetSimpleList(&g_Git);
4045 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4047 str += pLogEntry->m_SimpleFileList[j];
4048 str+=_T("\n");
4054 if (bRegex)
4056 if (std::regex_search(std::wstring(str), pat, flags))
4058 bFound = true;
4059 break;
4062 else
4064 if (bMatchCase)
4066 if (str.Find(findText) >= 0)
4068 bFound = true;
4069 break;
4073 else
4075 CString msg = str;
4076 msg = msg.MakeLower();
4077 CString find = findText.MakeLower();
4078 if (msg.Find(find) >= 0)
4080 bFound = TRUE;
4081 break;
4085 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4087 } // if(m_pFindDialog->FindNext())
4088 //UpdateLogInfoLabel();
4090 if (bFound)
4092 m_nSearchIndex = i;
4093 EnsureVisible(i, FALSE);
4094 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4096 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4097 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4098 SetSelectionMark(i);
4100 else
4102 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4103 if (pLogEntry)
4104 m_highlight = pLogEntry->m_CommitHash;
4106 Invalidate();
4107 //FillLogMessageCtrl();
4108 UpdateData(FALSE);
4111 return 0;
4114 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4116 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4118 *pResult = FALSE;
4121 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4123 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4125 Invalidate(FALSE);
4128 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4130 LVHITTESTINFO lvhitTestInfo;
4132 lvhitTestInfo.pt = point;
4134 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4135 int nSubItem = lvhitTestInfo.iSubItem;
4137 UINT nFlags = lvhitTestInfo.flags;
4139 // nFlags is 0 if the SubItemHitTest fails
4140 // Therefore, 0 & <anything> will equal false
4141 if (nFlags & LVHT_ONITEM)
4143 // Get the client area occupied by this control
4144 RECT rcClient;
4145 GetClientRect(&rcClient);
4147 // Fill in the TOOLINFO structure
4148 pTI->hwnd = m_hWnd;
4149 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4150 pTI->lpszText = LPSTR_TEXTCALLBACK;
4151 pTI->rect = rcClient;
4153 return pTI->uId; // By returning a unique value per listItem,
4154 // we ensure that when the mouse moves over another list item,
4155 // the tooltip will change
4157 else
4159 // Otherwise, we aren't interested, so let the message propagate
4160 return -1;
4164 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4166 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4167 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4169 *pResult = 0;
4171 // Ignore messages from the built in tooltip, we are processing them internally
4172 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4173 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4174 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4175 return FALSE;
4177 // Get the mouse position
4178 const MSG* pMessage = GetCurrentMessage();
4180 CPoint pt;
4181 pt = pMessage->pt;
4182 ScreenToClient(&pt);
4184 // Check if the point falls onto a list item
4185 LVHITTESTINFO lvhitTestInfo;
4186 lvhitTestInfo.pt = pt;
4188 int nItem = SubItemHitTest(&lvhitTestInfo);
4190 if (lvhitTestInfo.flags & LVHT_ONITEM)
4192 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4193 if (strTipText.IsEmpty())
4194 return FALSE;
4196 // we want multiline tooltips
4197 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4199 wcscpy_s(m_wszTip, strTipText);
4200 // handle Unicode as well as non-Unicode requests
4201 if (pNMHDR->code == TTN_NEEDTEXTA)
4203 pTTTA->hinst = nullptr;
4204 pTTTA->lpszText = m_szTip;
4205 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4207 else
4209 pTTTW->hinst = nullptr;
4210 pTTTW->lpszText = m_wszTip;
4213 CRect rect;
4214 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4215 ClientToScreen(rect);
4216 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4218 return TRUE; // We found a tool tip,
4219 // tell the framework this message has been handled
4222 return FALSE; // We didn't handle the message,
4223 // let the framework continue propagating the message
4226 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4228 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4230 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4231 if (pLogEntry == nullptr)
4232 return CString();
4233 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4234 return CString();
4235 return pLogEntry->GetSubject();
4237 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4239 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4240 if (pLogEntry == nullptr)
4241 return CString();
4242 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4244 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4246 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4247 if (pLogEntry == nullptr)
4248 return CString();
4249 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4251 else if (nSubItem == LOGLIST_ACTION)
4253 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4254 if (pLogEntry == nullptr)
4255 return CString();
4257 if (!pLogEntry->m_IsDiffFiles)
4258 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4260 int actions = pLogEntry->GetAction(this);
4261 CString sToolTipText;
4263 CString actionText;
4264 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4265 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4267 if (actions & CTGitPath::LOGACTIONS_ADDED)
4269 if (!actionText.IsEmpty())
4270 actionText += L"\r\n";
4271 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4274 if (actions & CTGitPath::LOGACTIONS_DELETED)
4276 if (!actionText.IsEmpty())
4277 actionText += L"\r\n";
4278 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4281 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4283 if (!actionText.IsEmpty())
4284 actionText += L"\r\n";
4285 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4288 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4290 if (!actionText.IsEmpty())
4291 actionText += L"\r\n";
4292 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4295 if (!actionText.IsEmpty())
4297 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4298 sToolTipText = sTitle + L":\r\n" + actionText;
4300 return sToolTipText;
4302 return CString();