Improve error handling in GitRev
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobc5d79b2164fb0029b4d97d9e036f3804992d3c74
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 "InputDlg.h"
28 #include "GitProgressDlg.h"
29 #include "ProgressDlg.h"
30 #include "LogDlg.h"
31 #include "MessageBox.h"
32 #include "registry.h"
33 #include "LoglistUtils.h"
34 #include "PathUtils.h"
35 #include "StringUtils.h"
36 #include "UnicodeUtils.h"
37 #include "TempFile.h"
38 #include "IconMenu.h"
39 #include "GitStatus.h"
40 #include "..\\TortoiseShell\\Resource.h"
41 #include "FindDlg.h"
42 #include "SysInfo.h"
44 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
45 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
46 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
48 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
50 CGitLogListBase::CGitLogListBase():CHintListCtrl()
51 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
52 ,m_nSearchIndex(0)
53 ,m_bNoDispUpdates(FALSE)
54 , m_bThreadRunning(FALSE)
55 , m_bStrictStopped(false)
56 , m_pStoreSelection(NULL)
57 , m_SelectedFilters(LOGFILTER_ALL)
58 , m_ShowFilter(FILTERSHOW_ALL)
59 , m_bShowWC(false)
60 , m_logEntries(&m_LogCache)
61 , m_pFindDialog(NULL)
62 , m_ColumnManager(this)
63 , m_dwDefaultColumns(0)
64 , m_arShownList(&m_critSec)
65 , m_hasWC(true)
66 , m_bNoHightlightHead(FALSE)
67 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
69 // use the default GUI font, create a copy of it and
70 // change the copy to BOLD (leave the rest of the font
71 // the same)
72 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
73 LOGFONT lf = {0};
74 GetObject(hFont, sizeof(LOGFONT), &lf);
75 lf.lfWeight = FW_BOLD;
76 m_boldFont = CreateFontIndirect(&lf);
77 lf.lfWeight = FW_DONTCARE;
78 lf.lfItalic = TRUE;
79 m_FontItalics = CreateFontIndirect(&lf);
80 lf.lfWeight = FW_BOLD;
81 m_boldItalicsFont = CreateFontIndirect(&lf);
83 m_bShowBugtraqColumn=false;
85 m_IsIDReplaceAction=FALSE;
87 this->m_critSec.Init();
88 m_critSec_AsyncDiff.Init();
89 m_wcRev.m_CommitHash.Empty();
90 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
91 m_wcRev.m_ParentHash.clear();
92 m_wcRev.m_Mark=_T('-');
93 m_wcRev.m_IsUpdateing=FALSE;
94 m_wcRev.m_IsFull = TRUE;
96 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
97 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
98 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
99 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
100 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
102 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
103 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
105 m_From = -1;
106 m_To = -1;
108 m_ShowMask = 0;
109 m_LoadingThread = NULL;
111 InterlockedExchange(&m_bExitThread,FALSE);
112 m_IsOldFirst = FALSE;
113 m_IsRebaseReplaceGraph = FALSE;
115 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
117 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
119 // get short/long datetime setting from registry
120 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
121 if ( RegUseShortDateFormat )
123 m_DateFormat = DATE_SHORTDATE;
125 else
127 m_DateFormat = DATE_LONGDATE;
129 // get relative time display setting from registry
130 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
131 m_bRelativeTimes = (regRelativeTimes != 0);
132 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
134 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
135 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
136 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
137 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
142 m_ColumnRegKey=_T("log");
144 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
145 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
146 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
148 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
149 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
151 m_AsyncThreadExit = FALSE;
152 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
153 m_AsynDiffListLock.Init();
155 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
156 if (hUxTheme)
157 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
159 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
160 if (m_DiffingThread ==NULL)
162 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
163 return;
168 int CGitLogListBase::AsyncDiffThread()
170 m_AsyncThreadExited = false;
171 while(!m_AsyncThreadExit)
173 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
175 GitRevLoglist* pRev = nullptr;
176 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
178 m_AsynDiffListLock.Lock();
179 pRev = m_AsynDiffList.back();
180 m_AsynDiffList.pop_back();
181 m_AsynDiffListLock.Unlock();
183 if( pRev->m_CommitHash.IsEmpty() )
185 if(pRev->m_IsDiffFiles)
186 continue;
188 pRev->GetFiles(this).Clear();
189 pRev->m_ParentHash.clear();
190 pRev->m_ParentHash.push_back(m_HeadHash);
191 if(g_Git.IsInitRepos())
193 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
194 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
197 else
199 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
201 int& action = pRev->GetAction(this);
202 action = 0;
203 const CTGitPathList& files = pRev->GetFiles(this);
204 for (int j = 0; j < files.GetCount(); ++j)
205 action |= files[j].m_Action;
207 CString err;
208 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
210 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
211 return -1;
214 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
215 InterlockedExchange(&pRev->m_IsFull, TRUE);
217 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
218 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
219 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
222 m_critSec_AsyncDiff.Lock();
223 int ret = pRev->CheckAndDiff();
224 m_critSec_AsyncDiff.Unlock();
225 if (!ret)
226 { // fetch change file list
227 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
229 if(i < m_arShownList.GetCount())
231 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
232 if(data->m_CommitHash == pRev->m_CommitHash)
234 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
235 break;
240 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
242 POSITION pos = GetFirstSelectedItemPosition();
243 int nItem = GetNextSelectedItem(pos);
245 if(nItem>=0)
247 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
248 if(data)
249 if(data->m_CommitHash == pRev->m_CommitHash)
251 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
258 m_AsyncThreadExited = true;
259 return 0;
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
263 if (exclusivelyShow)
265 m_ContextMenuMask &= hideMask;
267 else
269 m_ContextMenuMask &= ~hideMask;
273 CGitLogListBase::~CGitLogListBase()
275 InterlockedExchange(&m_bNoDispUpdates, TRUE);
276 this->m_arShownList.SafeRemoveAll();
278 DestroyIcon(m_hModifiedIcon);
279 DestroyIcon(m_hReplacedIcon);
280 DestroyIcon(m_hAddedIcon);
281 DestroyIcon(m_hDeletedIcon);
282 m_logEntries.ClearAll();
284 if (m_boldFont)
285 DeleteObject(m_boldFont);
287 if (m_FontItalics)
288 DeleteObject(m_FontItalics);
290 if (m_boldItalicsFont)
291 DeleteObject(m_boldItalicsFont);
293 if ( m_pStoreSelection )
295 delete m_pStoreSelection;
296 m_pStoreSelection = NULL;
299 SafeTerminateThread();
300 SafeTerminateAsyncDiffThread();
302 if(m_AsyncDiffEvent)
303 CloseHandle(m_AsyncDiffEvent);
305 if (hUxTheme)
306 FreeLibrary(hUxTheme);
310 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
311 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
312 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
313 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
314 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
315 ON_WM_CONTEXTMENU()
316 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
317 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
318 ON_WM_CREATE()
319 ON_WM_DESTROY()
320 ON_MESSAGE(MSG_LOADED,OnLoad)
321 ON_WM_MEASUREITEM()
322 ON_WM_MEASUREITEM_REFLECT()
323 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
324 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
325 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
326 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
327 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
328 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
329 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
330 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
331 END_MESSAGE_MAP()
333 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
335 //if (m_nRowHeight>0)
337 lpMeasureItemStruct->itemHeight = 50;
341 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
343 PreSubclassWindow();
344 return CHintListCtrl::OnCreate(lpCreateStruct);
347 void CGitLogListBase::PreSubclassWindow()
349 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
350 // load the icons for the action columns
351 // m_Theme.Open(m_hWnd, L"ListView");
352 SetWindowTheme(m_hWnd, L"Explorer", NULL);
353 CHintListCtrl::PreSubclassWindow();
356 CString CGitLogListBase::GetRebaseActionName(int action)
358 if (action & LOGACTIONS_REBASE_EDIT)
359 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
360 if (action & LOGACTIONS_REBASE_SQUASH)
361 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
362 if (action & LOGACTIONS_REBASE_PICK)
363 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
364 if (action & LOGACTIONS_REBASE_SKIP)
365 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
367 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
370 void CGitLogListBase::InsertGitColumn()
372 CString temp;
374 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
375 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
376 if (DWORD(regFullRowSelect))
377 exStyle |= LVS_EX_FULLROWSELECT;
378 SetExtendedStyle(exStyle);
380 // only load properties if we have a repository
381 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
382 UpdateProjectProperties();
384 static UINT normal[] =
386 IDS_LOG_GRAPH,
387 IDS_LOG_REBASE,
388 IDS_LOG_ID,
389 IDS_LOG_HASH,
390 IDS_LOG_ACTIONS,
391 IDS_LOG_MESSAGE,
392 IDS_LOG_AUTHOR,
393 IDS_LOG_DATE,
394 IDS_LOG_EMAIL,
395 IDS_LOG_COMMIT_NAME,
396 IDS_LOG_COMMIT_EMAIL,
397 IDS_LOG_COMMIT_DATE,
398 IDS_LOG_BUGIDS,
399 IDS_LOG_SVNREV,
402 static int with[] =
404 ICONITEMBORDER+16*4,
405 ICONITEMBORDER+16*4,
406 ICONITEMBORDER+16*4,
407 ICONITEMBORDER+16*4,
408 ICONITEMBORDER+16*4,
409 LOGLIST_MESSAGE_MIN,
410 ICONITEMBORDER+16*4,
411 ICONITEMBORDER+16*4,
412 ICONITEMBORDER+16*4,
413 ICONITEMBORDER+16*4,
414 ICONITEMBORDER+16*4,
415 ICONITEMBORDER+16*4,
416 ICONITEMBORDER+16*4,
417 ICONITEMBORDER+16*4,
419 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
421 DWORD hideColumns = 0;
422 if(this->m_IsRebaseReplaceGraph)
424 hideColumns |= GIT_LOG_GRAPH;
425 m_dwDefaultColumns |= GIT_LOG_REBASE;
427 else
429 hideColumns |= GIT_LOG_REBASE;
432 if(this->m_IsIDReplaceAction)
434 hideColumns |= GIT_LOG_ACTIONS;
435 m_dwDefaultColumns |= GIT_LOG_ID;
436 m_dwDefaultColumns |= GIT_LOG_HASH;
438 else
440 hideColumns |= GIT_LOG_ID;
442 if(this->m_bShowBugtraqColumn)
444 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
446 else
448 hideColumns |= GIT_LOGLIST_BUG;
450 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
451 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
452 else
453 hideColumns |= GIT_LOGLIST_SVNREV;
454 SetRedraw(false);
456 m_ColumnManager.SetNames(normal, _countof(normal));
457 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
459 SetRedraw(true);
463 * Resizes all columns in a list control to values in registry.
465 void CGitLogListBase::ResizeAllListCtrlCols()
467 // column max and min widths to allow
468 static const int nMinimumWidth = 10;
469 static const int nMaximumWidth = 1000;
470 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
471 if (pHdrCtrl)
473 int numcols = pHdrCtrl->GetItemCount();
474 for (int col = 0; col < numcols; ++col)
476 // get width for this col last time from registry
477 CString regentry;
478 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
479 CRegDWORD regwidth(regentry, 0);
480 int cx = regwidth;
481 if ( cx == 0 )
483 // no saved value, setup sensible defaults
484 if (col == this->LOGLIST_MESSAGE)
486 cx = LOGLIST_MESSAGE_MIN;
488 else
490 cx = ICONITEMBORDER+16*4;
493 if (cx < nMinimumWidth)
495 cx = nMinimumWidth;
497 else if (cx > nMaximumWidth)
499 cx = nMaximumWidth;
502 SetColumnWidth(col, cx);
509 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
511 LVITEM rItem;
512 SecureZeroMemory(&rItem, sizeof(LVITEM));
513 rItem.mask = LVIF_STATE;
514 rItem.iItem = (int)Index;
515 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
516 GetItem(&rItem);
518 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index);
519 HBRUSH brush = NULL;
521 if (!(rItem.state & LVIS_SELECTED))
523 int action = pLogEntry->GetRebaseAction();
524 if (action & LOGACTIONS_REBASE_SQUASH)
525 brush = ::CreateSolidBrush(RGB(156,156,156));
526 else if (action & LOGACTIONS_REBASE_EDIT)
527 brush = ::CreateSolidBrush(RGB(200,200,128));
529 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
531 if (rItem.state & LVIS_SELECTED)
533 if (::GetFocus() == m_hWnd)
534 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
535 else
536 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
539 if (brush != NULL)
541 ::FillRect(hdc, &rect, brush);
542 ::DeleteObject(brush);
546 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
548 POINT point = { 4, 4 };
549 CRect rt2 = rect;
550 rt2.DeflateRect(1, 1);
551 rt2.OffsetRect(2, 2);
553 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
554 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
555 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
556 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
557 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
559 ::SelectObject(hdc, brush);
560 rt2.OffsetRect(-2, -2);
561 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
562 ::SelectObject(hdc, oldbrush);
563 ::SelectObject(hdc, oldpen);
564 ::DeleteObject(nullPen);
565 ::DeleteObject(darkBrush);
568 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
570 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
571 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
572 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
573 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
574 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
575 ::LineTo(hdc, rect.left, rect.bottom);
576 ::SelectObject(hdc, oldpen);
577 ::DeleteObject(pen);
580 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
582 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
583 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
584 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
585 ::LineTo(hdc, rect.left, rect.bottom);
586 ::LineTo(hdc, rect.right, rect.bottom);
587 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
588 ::SelectObject(hdc, oldpen);
589 ::DeleteObject(pen);
592 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
594 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
595 CRect rt=rect;
596 LVITEM rItem;
597 SecureZeroMemory(&rItem, sizeof(LVITEM));
598 rItem.mask = LVIF_STATE;
599 rItem.iItem = (int)index;
600 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
601 GetItem(&rItem);
603 CDC W_Dc;
604 W_Dc.Attach(hdc);
606 HTHEME hTheme = NULL;
607 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
608 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
610 SIZE oneSpaceSize;
611 if (m_bTagsBranchesOnRightSide)
613 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
614 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
615 SelectObject(hdc, oldFont);
616 rt.left += oneSpaceSize.cx * 2;
618 else
620 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
621 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
622 rt.left += oneSpaceSize.cx;
625 int action = data->GetRebaseAction();
626 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
627 if (IsAppThemed() && pfnDrawThemeTextEx)
629 int txtState = LISS_NORMAL;
630 if (rItem.state & LVIS_SELECTED)
631 txtState = LISS_SELECTED;
633 DTTOPTS opts = { 0 };
634 opts.dwSize = sizeof(opts);
635 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
636 opts.dwFlags = DTT_TEXTCOLOR;
637 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
639 else
641 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
643 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
644 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
645 ::SetTextColor(hdc, clrOld);
647 else
649 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
650 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
651 ::SetTextColor(hdc, clrOld);
655 if (m_bTagsBranchesOnRightSide)
657 SIZE size;
658 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
660 rt.left += oneSpaceSize.cx + size.cx;
662 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
665 if (hTheme)
666 CloseThemeData(hTheme);
668 W_Dc.Detach();
671 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
673 for (unsigned int i = 0; i < refList.size(); ++i)
675 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
676 HBRUSH brush = 0;
677 COLORREF colRef = refList[i].color;
678 bool singleRemote = refList[i].singleRemote;
679 bool hasTracking = refList[i].hasTracking;
680 bool sameName = refList[i].sameName;
681 bool annotatedTag = refList[i].annotatedTag;
683 //When row selected, ajust label color
684 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
686 if (rItem.state & LVIS_SELECTED)
687 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
690 brush = ::CreateSolidBrush(colRef);
692 if (!shortname.IsEmpty() && (rt.left < rect.right))
694 SIZE size;
695 memset(&size,0,sizeof(SIZE));
696 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
698 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
699 rt.right += 8;
701 int textpos = DT_CENTER;
703 if (rt.right > rect.right)
705 rt.right = rect.right;
706 textpos = 0;
709 CRect textRect = rt;
711 if (singleRemote)
713 rt.right += 8;
714 textRect.OffsetRect(8, 0);
717 if (sameName)
718 rt.right += 8;
720 if (hasTracking)
722 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
724 else
726 //Fill interior of ref label
727 ::FillRect(hdc, &rt, brush);
730 //Draw edge of label
731 CRect rectEdge = rt;
733 if (!hasTracking)
735 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
736 rectEdge.DeflateRect(1, 1);
737 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
740 if (annotatedTag)
742 rt.right += 8;
743 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
744 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
745 ::FillRgn(hdc, hrgn, brush);
746 ::DeleteObject(hrgn);
747 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
748 HPEN pen;
749 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
750 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
751 ::DeleteObject(pen);
752 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
753 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
754 ::DeleteObject(pen);
755 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
756 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
757 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
758 ::DeleteObject(pen);
759 SelectObject(hdc, oldpen);
762 //Draw text inside label
763 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
764 if (!customColor && IsAppThemed() && pfnDrawThemeTextEx)
766 int txtState = LISS_NORMAL;
767 if (rItem.state & LVIS_SELECTED)
768 txtState = LISS_SELECTED;
770 DTTOPTS opts = { 0 };
771 opts.dwSize = sizeof(opts);
772 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
773 opts.dwFlags = DTT_TEXTCOLOR;
774 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
776 else
778 W_Dc.SetBkMode(TRANSPARENT);
779 if (customColor || (rItem.state & LVIS_SELECTED))
781 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
782 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
783 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
784 ::SetTextColor(hdc,clrOld);
786 else
788 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
789 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
790 ::SetTextColor(hdc, clrOld);
794 if (singleRemote)
796 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
797 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
798 CRect newRect;
799 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
800 DrawLightning(hdc, newRect, color, bold);
803 if (sameName)
805 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
806 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
807 CRect newRect;
808 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
809 DrawUpTriangle(hdc, newRect, color, bold);
812 rt.left = rt.right + 1;
814 if (brush)
815 ::DeleteObject(brush);
817 rt.right = rect.right;
820 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
822 // Returns ((256 - amount)*col1 + amount*col2) / 256;
823 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
824 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
825 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
828 Gdiplus::Color GetGdiColor(COLORREF col)
830 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
832 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
833 const COLORREF& col,const COLORREF& activeColor, int top
836 int h = laneHeight / 2;
837 int m = (x1 + x2) / 2;
838 int r = (x2 - x1) * m_NodeSize / 30;
839 int d = 2 * r;
841 #define P_CENTER m , h+top
842 #define P_0 x2, h+top
843 #define P_90 m , 0+top-1
844 #define P_180 x1, h+top
845 #define P_270 m , 2 * h+top +1
846 #define R_CENTER m - r, h - r+top, d, d
849 #define DELTA_UR_B 2*(x1 - m), 2*h +top
850 #define DELTA_UR_E 0*16, 90*16 +top // -,
852 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
853 #define DELTA_DR_E 270*16, 90*16 +top // -'
855 #define DELTA_UL_B 2*(x2 - m), 2*h +top
856 #define DELTA_UL_E 90*16, 90*16 +top // ,-
858 #define DELTA_DL_B 2*(x2 - m),2*-h +top
859 #define DELTA_DL_E 180*16, 90*16 // '-
861 #define CENTER_UR x1, 2*h, 225
862 #define CENTER_DR x1, 0 , 135
863 #define CENTER_UL x2, 2*h, 315
864 #define CENTER_DL x2, 0 , 45
867 Gdiplus::Graphics graphics( hdc );
869 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
871 // arc
872 switch (type) {
873 case Lanes::JOIN:
874 case Lanes::JOIN_R:
875 case Lanes::HEAD:
876 case Lanes::HEAD_R:
878 Gdiplus::LinearGradientBrush gradient(
879 Gdiplus::Point(x1-2, h+top-2),
880 Gdiplus::Point(P_270),
881 GetGdiColor(activeColor),GetGdiColor(col));
884 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
885 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
887 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
888 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
889 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
891 break;
893 case Lanes::JOIN_L:
896 Gdiplus::LinearGradientBrush gradient(
897 Gdiplus::Point(P_270),
898 Gdiplus::Point(x2+1, h+top-1),
899 GetGdiColor(col),GetGdiColor(activeColor));
902 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
903 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
905 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
906 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
907 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
910 break;
912 case Lanes::TAIL:
913 case Lanes::TAIL_R:
916 Gdiplus::LinearGradientBrush gradient(
917 Gdiplus::Point(x1-2, h+top-2),
918 Gdiplus::Point(P_90),
919 GetGdiColor(activeColor),GetGdiColor(col));
921 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
923 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
925 #if 0
926 QConicalGradient gradient(CENTER_DR);
927 gradient.setColorAt(0.375, activeCol);
928 gradient.setColorAt(0.625, col);
929 myPen.setBrush(gradient);
930 p->setPen(myPen);
931 p->drawArc(P_CENTER, DELTA_DR);
932 #endif
933 break;
935 default:
936 break;
940 //static QPen myPen(Qt::black, 2); // fast path here
941 CPen pen;
942 pen.CreatePen(PS_SOLID,2,col);
943 //myPen.setColor(col);
944 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
946 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
948 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
950 //p->setPen(myPen);
952 // vertical line
953 switch (type) {
954 case Lanes::ACTIVE:
955 case Lanes::NOT_ACTIVE:
956 case Lanes::MERGE_FORK:
957 case Lanes::MERGE_FORK_R:
958 case Lanes::MERGE_FORK_L:
959 case Lanes::JOIN:
960 case Lanes::JOIN_R:
961 case Lanes::JOIN_L:
962 case Lanes::CROSS:
963 //DrawLine(hdc,P_90,P_270);
964 graphics.DrawLine(&myPen,P_90,P_270);
965 //p->drawLine(P_90, P_270);
966 break;
967 case Lanes::HEAD_L:
968 case Lanes::BRANCH:
969 //DrawLine(hdc,P_CENTER,P_270);
970 graphics.DrawLine(&myPen,P_CENTER,P_270);
971 //p->drawLine(P_CENTER, P_270);
972 break;
973 case Lanes::TAIL_L:
974 case Lanes::INITIAL:
975 case Lanes::BOUNDARY:
976 case Lanes::BOUNDARY_C:
977 case Lanes::BOUNDARY_R:
978 case Lanes::BOUNDARY_L:
979 //DrawLine(hdc,P_90, P_CENTER);
980 graphics.DrawLine(&myPen,P_90,P_CENTER);
981 //p->drawLine(P_90, P_CENTER);
982 break;
983 default:
984 break;
987 myPen.SetColor(GetGdiColor(activeColor));
989 // horizontal line
990 switch (type) {
991 case Lanes::MERGE_FORK:
992 case Lanes::JOIN:
993 case Lanes::HEAD:
994 case Lanes::TAIL:
995 case Lanes::CROSS:
996 case Lanes::CROSS_EMPTY:
997 case Lanes::BOUNDARY_C:
998 //DrawLine(hdc,P_180,P_0);
999 graphics.DrawLine(&myPen,P_180,P_0);
1000 //p->drawLine(P_180, P_0);
1001 break;
1002 case Lanes::MERGE_FORK_R:
1003 case Lanes::BOUNDARY_R:
1004 //DrawLine(hdc,P_180,P_CENTER);
1005 graphics.DrawLine(&myPen,P_180,P_CENTER);
1006 //p->drawLine(P_180, P_CENTER);
1007 break;
1008 case Lanes::MERGE_FORK_L:
1009 case Lanes::HEAD_L:
1010 case Lanes::TAIL_L:
1011 case Lanes::BOUNDARY_L:
1012 //DrawLine(hdc,P_CENTER,P_0);
1013 graphics.DrawLine(&myPen,P_CENTER,P_0);
1014 //p->drawLine(P_CENTER, P_0);
1015 break;
1016 default:
1017 break;
1020 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1022 CBrush brush;
1023 brush.CreateSolidBrush(col);
1024 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1026 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1027 // center symbol, e.g. rect or ellipse
1028 switch (type) {
1029 case Lanes::ACTIVE:
1030 case Lanes::INITIAL:
1031 case Lanes::BRANCH:
1033 //p->setPen(Qt::NoPen);
1034 //p->setBrush(col);
1035 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1036 graphics.FillEllipse(&myBrush, R_CENTER);
1037 //p->drawEllipse(R_CENTER);
1038 break;
1039 case Lanes::MERGE_FORK:
1040 case Lanes::MERGE_FORK_R:
1041 case Lanes::MERGE_FORK_L:
1042 //p->setPen(Qt::NoPen);
1043 //p->setBrush(col);
1044 //p->drawRect(R_CENTER);
1045 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1046 graphics.FillRectangle(&myBrush, R_CENTER);
1047 break;
1048 case Lanes::UNAPPLIED:
1049 // Red minus sign
1050 //p->setPen(Qt::NoPen);
1051 //p->setBrush(Qt::red);
1052 //p->drawRect(m - r, h - 1, d, 2);
1053 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1054 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1055 break;
1056 case Lanes::APPLIED:
1057 // Green plus sign
1058 //p->setPen(Qt::NoPen);
1059 //p->setBrush(DARK_GREEN);
1060 //p->drawRect(m - r, h - 1, d, 2);
1061 //p->drawRect(m - 1, h - r, 2, d);
1062 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1063 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1064 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1065 break;
1066 case Lanes::BOUNDARY:
1067 //p->setBrush(back);
1068 //p->drawEllipse(R_CENTER);
1069 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1070 graphics.DrawEllipse(&myPen, R_CENTER);
1071 break;
1072 case Lanes::BOUNDARY_C:
1073 case Lanes::BOUNDARY_R:
1074 case Lanes::BOUNDARY_L:
1075 //p->setBrush(back);
1076 //p->drawRect(R_CENTER);
1077 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1078 graphics.FillRectangle(&myBrush,R_CENTER);
1079 break;
1080 default:
1081 break;
1084 ::SelectObject(hdc,oldpen);
1085 ::SelectObject(hdc,oldbrush);
1086 #undef P_CENTER
1087 #undef P_0
1088 #undef P_90
1089 #undef P_180
1090 #undef P_270
1091 #undef R_CENTER
1094 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1096 // TODO: unfinished
1097 // return;
1098 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
1099 if(data->m_CommitHash.IsEmpty())
1100 return;
1102 CRect rt=rect;
1103 LVITEM rItem;
1104 SecureZeroMemory(&rItem, sizeof(LVITEM));
1105 rItem.mask = LVIF_STATE;
1106 rItem.iItem = (int)index;
1107 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1108 GetItem(&rItem);
1110 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1112 if (data->m_Lanes.empty())
1113 m_logEntries.setLane(data->m_CommitHash);
1115 std::vector<int>& lanes=data->m_Lanes;
1116 size_t laneNum = lanes.size();
1117 UINT activeLane = 0;
1118 for (UINT i = 0; i < laneNum; ++i)
1119 if (Lanes::isMerge(lanes[i])) {
1120 activeLane = i;
1121 break;
1124 int x2 = 0;
1125 int maxWidth = rect.Width();
1126 int lw = 3 * rect.Height() / 4; //laneWidth()
1128 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1129 //if (opt.state & QStyle::State_Selected)
1130 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1132 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1135 int x1 = x2;
1136 x2 += lw;
1138 int ln = lanes[i];
1139 if (ln == Lanes::EMPTY)
1140 continue;
1142 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1143 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1146 #if 0
1147 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1149 int x1 = x2;
1150 x2 += lw;
1152 int ln = lanes[i];
1153 if (ln == Lanes::EMPTY)
1154 continue;
1156 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1157 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1159 if (ln == Lanes::CROSS)
1161 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1162 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1164 else
1165 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1167 #endif
1171 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1174 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1175 // Take the default processing unless we set this to something else below.
1176 *pResult = CDRF_DODEFAULT;
1178 if (m_bNoDispUpdates)
1179 return;
1181 switch (pLVCD->nmcd.dwDrawStage)
1183 case CDDS_PREPAINT:
1185 *pResult = CDRF_NOTIFYITEMDRAW;
1186 return;
1188 break;
1189 case CDDS_ITEMPREPAINT:
1191 // This is the prepaint stage for an item. Here's where we set the
1192 // item's text color.
1194 // Tell Windows to send draw notifications for each subitem.
1195 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1197 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1199 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1201 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1202 if (data)
1204 HGDIOBJ hGdiObj = nullptr;
1205 int action = data->GetRebaseAction();
1206 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1207 crText = RGB(128,128,128);
1209 if (action & LOGACTIONS_REBASE_SQUASH)
1210 pLVCD->clrTextBk = RGB(156,156,156);
1211 else if (action & LOGACTIONS_REBASE_EDIT)
1212 pLVCD->clrTextBk = RGB(200,200,128);
1213 else
1214 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1216 if (action & LOGACTIONS_REBASE_CURRENT)
1217 hGdiObj = m_boldFont;
1219 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1220 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1221 if (isHeadHash && isHighlight)
1222 hGdiObj = m_boldItalicsFont;
1223 else if (isHeadHash)
1224 hGdiObj = m_boldFont;
1225 else if (isHighlight)
1226 hGdiObj = m_FontItalics;
1228 if (hGdiObj)
1230 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1231 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1234 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1235 // crText = GetSysColor(COLOR_GRAYTEXT);
1237 if (data->m_CommitHash.IsEmpty())
1239 //crText = GetSysColor(RGB(200,200,0));
1240 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1241 // We changed the font, so we're returning CDRF_NEWFONT. This
1242 // tells the control to recalculate the extent of the text.
1243 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1247 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1249 if (m_bStrictStopped)
1250 crText = GetSysColor(COLOR_GRAYTEXT);
1252 // Store the color back in the NMLVCUSTOMDRAW struct.
1253 pLVCD->clrText = crText;
1254 return;
1256 break;
1257 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1259 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1261 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1264 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1266 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1268 CRect rect;
1269 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1271 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1272 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1274 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1275 if( !data ->m_CommitHash.IsEmpty())
1276 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1278 *pResult = CDRF_SKIPDEFAULT;
1279 return;
1283 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1285 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1287 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1289 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1291 CRect rect;
1292 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1294 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1295 // not in FillBackGround method, because this only affected the message subitem
1296 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1297 return;
1299 int index = (int)pLVCD->nmcd.dwItemSpec;
1300 int state = GetItemState(index, LVIS_SELECTED);
1301 int txtState = LISS_NORMAL;
1302 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1304 if (state & LVIS_SELECTED)
1305 txtState = LISS_HOTSELECTED;
1306 else
1307 txtState = LISS_HOT;
1309 else if (state & LVIS_SELECTED)
1311 if (::GetFocus() == m_hWnd)
1312 txtState = LISS_SELECTED;
1313 else
1314 txtState = LISS_SELECTEDNOTFOCUS;
1317 HTHEME hTheme = nullptr;
1318 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1319 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1321 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1322 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1323 else
1325 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1326 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1327 ::DeleteObject(brush);
1329 if (hTheme)
1331 CRect rt;
1332 // get rect of whole line
1333 GetItemRect(index, rt, LVIR_BOUNDS);
1334 CRect rect2 = rect;
1335 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1336 rect2.DeflateRect(1, 1, 1, 1);
1338 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1339 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1341 CloseThemeData(hTheme);
1343 // END: extended redraw
1345 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1347 std::vector<REFLABEL> refsToShow;
1348 STRING_VECTOR remoteTrackingList;
1349 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1350 for (unsigned int i = 0; i < refList.size(); ++i)
1352 CString str = refList[i];
1354 REFLABEL refLabel;
1355 refLabel.color = RGB(255, 255, 255);
1356 refLabel.singleRemote = false;
1357 refLabel.hasTracking = false;
1358 refLabel.sameName = false;
1359 refLabel.annotatedTag = false;
1360 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1362 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1363 continue;
1364 if (refLabel.name == m_CurrentBranch )
1365 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1366 else
1367 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1369 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1370 CString pullRemote = trackingEntry.first;
1371 CString pullBranch = trackingEntry.second;
1372 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1374 CString defaultUpstream;
1375 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1376 refLabel.hasTracking = true;
1377 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1379 bool found = false;
1380 for (size_t j = i + 1; j < refList.size(); ++j)
1382 if (refList[j] == defaultUpstream)
1384 found = true;
1385 break;
1389 if (found)
1391 bool sameName = pullBranch == refLabel.name;
1392 refsToShow.push_back(refLabel);
1393 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1394 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1395 if (m_bSymbolizeRefNames)
1397 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1399 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1400 refLabel.singleRemote = true;
1402 else if (sameName)
1403 refLabel.simplifiedName = pullRemote + _T("/");
1404 refLabel.sameName = sameName;
1406 refsToShow.push_back(refLabel);
1407 remoteTrackingList.push_back(defaultUpstream);
1408 continue;
1413 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1415 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1416 continue;
1418 bool found = false;
1419 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1421 if (remoteTrackingList[j] == str)
1423 found = true;
1424 break;
1427 if (found)
1428 continue;
1430 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1431 if (m_bSymbolizeRefNames)
1433 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1435 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1436 refLabel.singleRemote = true;
1440 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1442 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1443 continue;
1444 refLabel.color = m_Colors.GetColor(CColors::Tag);
1445 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1447 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1449 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1450 continue;
1451 refLabel.color = m_Colors.GetColor(CColors::Stash);
1452 refLabel.name = _T("stash");
1454 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1456 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1457 continue;
1458 if (refLabel.name.Find(_T("good")) == 0)
1460 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1461 refLabel.name = _T("good");
1463 if (refLabel.name.Find(_T("bad")) == 0)
1465 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1466 refLabel.name = _T("bad");
1469 else
1470 continue;
1472 refsToShow.push_back(refLabel);
1475 if (refsToShow.empty())
1477 *pResult = CDRF_DODEFAULT;
1478 return;
1481 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1483 *pResult = CDRF_SKIPDEFAULT;
1484 return;
1491 if (pLVCD->iSubItem == LOGLIST_ACTION)
1493 if(this->m_IsIDReplaceAction)
1495 *pResult = CDRF_DODEFAULT;
1496 return;
1498 *pResult = CDRF_DODEFAULT;
1500 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1501 return;
1503 int nIcons = 0;
1504 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1505 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1507 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1508 CRect rect;
1509 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1510 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1511 // Get the selected state of the
1512 // item being drawn.
1514 // Fill the background if necessary
1515 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1517 // Draw the icon(s) into the compatible DC
1518 int action = pLogEntry->GetAction(this);
1519 if (!pLogEntry->m_IsDiffFiles)
1521 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1522 *pResult = CDRF_SKIPDEFAULT;
1523 return;
1526 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1527 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1528 ++nIcons;
1530 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1531 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1532 ++nIcons;
1534 if (action & CTGitPath::LOGACTIONS_DELETED)
1535 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1536 ++nIcons;
1538 if (action & CTGitPath::LOGACTIONS_REPLACED)
1539 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1540 ++nIcons;
1541 *pResult = CDRF_SKIPDEFAULT;
1542 return;
1545 break;
1547 *pResult = CDRF_DODEFAULT;
1550 CString FindSVNRev(const CString& msg)
1554 const std::tr1::wsregex_iterator end;
1555 std::wstring s = msg;
1556 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), std::tr1::wregex(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"))); it != end; ++it)
1558 const std::tr1::wsmatch match = *it;
1559 if (match.size() == 4)
1561 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1562 return std::wstring(match[2]).c_str();
1565 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), std::tr1::wregex(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"))); it != end; ++it)
1567 const std::tr1::wsmatch match = *it;
1568 if (match.size() == 3)
1570 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1571 return std::wstring(match[1]).c_str();
1575 catch (std::exception) {}
1577 return _T("");
1580 // CGitLogListBase message handlers
1582 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1584 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1586 // Create a pointer to the item
1587 LV_ITEM* pItem = &(pDispInfo)->item;
1589 // Do the list need text information?
1590 if (!(pItem->mask & LVIF_TEXT))
1591 return;
1593 // By default, clear text buffer.
1594 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1596 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1598 *pResult = 0;
1599 if (m_bNoDispUpdates || bOutOfRange)
1600 return;
1602 // Which item number?
1603 int itemid = pItem->iItem;
1604 GitRevLoglist* pLogEntry = nullptr;
1605 if (itemid < m_arShownList.GetCount())
1606 pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(pItem->iItem));
1608 CString temp;
1609 if(m_IsOldFirst)
1611 temp.Format(_T("%d"),pItem->iItem+1);
1614 else
1616 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1619 // Which column?
1620 switch (pItem->iSubItem)
1622 case this->LOGLIST_GRAPH: //Graphic
1623 break;
1624 case this->LOGLIST_REBASE:
1626 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1627 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1629 break;
1630 case this->LOGLIST_ACTION: //action -- no text in the column
1631 break;
1632 case this->LOGLIST_HASH:
1633 if(pLogEntry)
1634 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1635 break;
1636 case this->LOGLIST_ID:
1637 if(this->m_IsIDReplaceAction)
1638 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1639 break;
1640 case this->LOGLIST_MESSAGE: //Message
1641 if (pLogEntry)
1642 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1643 break;
1644 case this->LOGLIST_AUTHOR: //Author
1645 if (pLogEntry)
1646 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1647 break;
1648 case this->LOGLIST_DATE: //Date
1649 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1650 lstrcpyn(pItem->pszText,
1651 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1652 pItem->cchTextMax);
1653 break;
1655 case this->LOGLIST_EMAIL:
1656 if (pLogEntry)
1657 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1658 break;
1660 case this->LOGLIST_COMMIT_NAME: //Commit
1661 if (pLogEntry)
1662 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1663 break;
1665 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1666 if (pLogEntry)
1667 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1668 break;
1670 case this->LOGLIST_COMMIT_DATE: //Commit Date
1671 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1672 lstrcpyn(pItem->pszText,
1673 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1674 pItem->cchTextMax);
1675 break;
1676 case this->LOGLIST_BUG: //Bug ID
1677 if(pLogEntry)
1678 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1679 break;
1680 case this->LOGLIST_SVNREV: //SVN revision
1681 if (pLogEntry)
1682 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1683 break;
1685 default:
1686 ASSERT(false);
1690 bool CGitLogListBase::IsOnStash(int index)
1692 GitRevLoglist* rev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index));
1693 if (IsStash(rev))
1694 return true;
1695 if (index > 0)
1697 GitRevLoglist* preRev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index - 1));
1698 if (IsStash(preRev))
1699 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1701 return false;
1704 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1706 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1708 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1709 return true;
1711 return false;
1714 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1716 if (pRev->m_ParentHash.empty())
1718 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1719 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1721 parentHash = pRev->m_ParentHash;
1724 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1727 if (pWnd == GetHeaderCtrl())
1729 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1732 int selIndex = GetSelectionMark();
1733 if (selIndex < 0)
1734 return; // nothing selected, nothing to do with a context menu
1736 // if the user selected the info text telling about not all revisions shown due to
1737 // the "stop on copy/rename" option, we also don't show the context menu
1738 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1739 return;
1741 // if the context menu is invoked through the keyboard, we have to use
1742 // a calculated position on where to anchor the menu on
1743 if ((point.x == -1) && (point.y == -1))
1745 CRect rect;
1746 GetItemRect(selIndex, &rect, LVIR_LABEL);
1747 ClientToScreen(&rect);
1748 point = rect.CenterPoint();
1750 m_nSearchIndex = selIndex;
1751 m_bCancelled = FALSE;
1753 // calculate some information the context menu commands can use
1754 // CString pathURL = GetURLFromPath(m_path);
1756 POSITION pos = GetFirstSelectedItemPosition();
1757 int indexNext = GetNextSelectedItem(pos);
1758 if (indexNext < 0)
1759 return;
1761 GitRevLoglist* pSelLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(indexNext));
1762 if (pSelLogEntry == nullptr)
1763 return;
1764 #if 0
1765 GitRev revSelected = pSelLogEntry->Rev;
1766 GitRev revPrevious = git_revnum_t(revSelected)-1;
1767 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1769 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1771 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1772 if (changedpath->lCopyFromRev)
1773 revPrevious = changedpath->lCopyFromRev;
1776 GitRev revSelected2;
1777 if (pos)
1779 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1780 revSelected2 = pLogEntry->Rev;
1782 bool bAllFromTheSameAuthor = true;
1783 CString firstAuthor;
1784 CLogDataVector selEntries;
1785 GitRev revLowest, revHighest;
1786 GitRevRangeArray revisionRanges;
1788 POSITION pos = GetFirstSelectedItemPosition();
1789 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1790 revisionRanges.AddRevision(pLogEntry->Rev);
1791 selEntries.push_back(pLogEntry);
1792 firstAuthor = pLogEntry->sAuthor;
1793 revLowest = pLogEntry->Rev;
1794 revHighest = pLogEntry->Rev;
1795 while (pos)
1797 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1798 revisionRanges.AddRevision(pLogEntry->Rev);
1799 selEntries.push_back(pLogEntry);
1800 if (firstAuthor.Compare(pLogEntry->sAuthor))
1801 bAllFromTheSameAuthor = false;
1802 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1803 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1807 #endif
1809 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1811 int FirstSelect=-1, LastSelect=-1;
1812 pos = GetFirstSelectedItemPosition();
1813 FirstSelect = GetNextSelectedItem(pos);
1814 while(pos)
1816 LastSelect = GetNextSelectedItem(pos);
1818 //entry is selected, now show the popup menu
1819 CIconMenu popup;
1820 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1822 if (popup.CreatePopupMenu())
1824 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1825 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1826 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1827 bool isStash = IsOnStash(indexNext);
1828 GIT_REV_LIST parentHash;
1829 GetParentHashes(pSelLogEntry, parentHash);
1831 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1832 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1834 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1835 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1837 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1838 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1840 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1841 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1843 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)))
1844 popup.AppendMenu(MF_SEPARATOR, NULL);
1846 if (GetSelectedCount() == 1)
1849 bool requiresSeparator = false;
1850 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1852 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1854 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1855 requiresSeparator = true;
1858 else
1860 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1862 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1863 requiresSeparator = true;
1865 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1867 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1868 requiresSeparator = true;
1872 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1874 if (parentHash.size() == 1)
1876 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1877 requiresSeparator = true;
1879 else if (parentHash.size() > 1)
1881 blamemenu.CreatePopupMenu();
1882 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1883 for (size_t i = 0; i < parentHash.size(); ++i)
1885 CString str;
1886 str.Format(IDS_PARENT, i + 1);
1887 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1889 requiresSeparator = true;
1893 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1895 if (parentHash.size() == 1)
1897 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1898 requiresSeparator = true;
1900 else if (parentHash.size() > 1)
1902 gnudiffmenu.CreatePopupMenu();
1903 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1905 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1906 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1908 for (size_t i = 0; i < parentHash.size(); ++i)
1910 CString str;
1911 str.Format(IDS_PARENT, i + 1);
1912 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1914 requiresSeparator = true;
1918 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1920 if (parentHash.size() == 1)
1922 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1923 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1924 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1925 requiresSeparator = true;
1927 else if (parentHash.size() > 1)
1929 diffmenu.CreatePopupMenu();
1930 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1931 for (size_t i = 0; i < parentHash.size(); ++i)
1933 CString str;
1934 str.Format(IDS_PARENT, i + 1);
1935 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1936 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1938 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1939 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1942 requiresSeparator = true;
1946 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1948 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1949 requiresSeparator = true;
1952 if (requiresSeparator)
1953 popup.AppendMenu(MF_SEPARATOR, NULL);
1955 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1957 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1958 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1961 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1963 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1964 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1966 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1967 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1969 popup.AppendMenu(MF_SEPARATOR, NULL);
1972 if (pSelLogEntry->m_CommitHash.IsEmpty())
1974 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1975 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1977 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1978 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1980 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1981 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1983 popup.AppendMenu(MF_SEPARATOR, NULL);
1985 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1986 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1988 popup.AppendMenu(MF_SEPARATOR, NULL);
1992 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1993 // {
1994 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1995 // }
1996 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1997 // {
1998 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1999 // }
2000 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2001 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2002 // {
2003 // popup.AppendMenu(MF_SEPARATOR, NULL);
2004 // }
2006 CString str,format;
2007 //if (m_hasWC)
2008 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2010 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2012 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2013 GetSelectedCount() == 1)
2014 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2016 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2017 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2019 format.LoadString(IDS_LOG_POPUP_MERGEREV);
2020 str.Format(format,g_Git.GetCurrentBranch());
2022 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2023 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2025 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2026 str.Format(format,g_Git.GetCurrentBranch());
2028 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2029 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2032 // Add Switch Branch express Menu
2033 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2034 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2037 std::vector<CString *> branchs;
2038 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2040 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2041 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2043 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2047 CString str;
2048 str.LoadString(IDS_SWITCH_BRANCH);
2050 if(branchs.size() == 1)
2052 str+=_T(" ");
2053 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
2054 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
2056 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2059 else if(branchs.size() > 1)
2061 subbranchmenu.CreatePopupMenu();
2062 for (size_t i = 0 ; i < branchs.size(); ++i)
2064 if (*branchs[i] != currentBranch)
2066 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2067 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2071 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2075 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2076 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2078 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2079 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2081 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2082 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2084 format.LoadString(IDS_REBASE_THIS_FORMAT);
2085 str.Format(format,g_Git.GetCurrentBranch());
2087 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2088 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2089 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2091 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2092 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2094 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2096 if (parentHash.size() == 1)
2098 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2100 else if (parentHash.size() > 1)
2102 revertmenu.CreatePopupMenu();
2103 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2105 for (size_t i = 0; i < parentHash.size(); ++i)
2107 CString str;
2108 str.Format(IDS_PARENT, i + 1);
2109 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2114 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2115 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2117 popup.AppendMenu(MF_SEPARATOR, NULL);
2122 if(!pSelLogEntry->m_Ref.IsEmpty())
2124 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2125 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2126 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2127 popup.AppendMenu(MF_SEPARATOR, NULL);
2130 if (GetSelectedCount() >= 2)
2132 bool bAddSeparator = false;
2133 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2135 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2136 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2139 if (GetSelectedCount() == 2)
2141 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2142 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2144 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2146 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2147 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2148 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2149 CString menu;
2150 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2151 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2152 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2153 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2156 bAddSeparator = true;
2159 if (m_hasWC)
2161 bAddSeparator = true;
2164 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2165 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2167 if (bAddSeparator)
2168 popup.AppendMenu(MF_SEPARATOR, NULL);
2171 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2173 bool bAddSeparator = false;
2174 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2176 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2178 CString head;
2179 int headindex;
2180 headindex = this->GetHeadIndex();
2181 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2183 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2184 CGitHash hashFirst;
2185 if (g_Git.GetHash(hashFirst, head))
2186 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2187 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2188 CGitHash hash;
2189 if (g_Git.GetHash(hash, head))
2190 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2191 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2192 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2193 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2194 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2195 bAddSeparator = true;
2200 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2201 if (GetSelectedCount() >= 2)
2202 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2203 else
2204 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2205 bAddSeparator = true;
2208 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2209 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2210 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2211 bAddSeparator = true;
2214 if (bAddSeparator)
2215 popup.AppendMenu(MF_SEPARATOR, NULL);
2218 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())
2220 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2221 popup.AppendMenu(MF_SEPARATOR, NULL);
2224 if (GetSelectedCount() == 1)
2226 bool bAddSeparator = false;
2227 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2229 // show the push-option only if the log entry has an associated local branch
2230 bool isLocal = false;
2231 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2233 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2234 isLocal = true;
2236 if (isLocal || showExtendedMenu)
2238 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2239 bAddSeparator = true;
2242 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2244 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2245 bAddSeparator = true;
2249 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2251 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2253 std::vector<CString *> branchs;
2254 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2256 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2257 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2259 CString str;
2260 if (branchs.size() == 1)
2262 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2263 str+=_T(" ");
2264 str += *branchs[0];
2265 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2266 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2267 bAddSeparator = true;
2269 else if (branchs.size() > 1)
2271 str.LoadString(IDS_DELETE_BRANCHTAG);
2272 submenu.CreatePopupMenu();
2273 for (size_t i = 0; i < branchs.size(); ++i)
2275 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2276 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2279 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2280 bAddSeparator = true;
2283 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2284 if (bAddSeparator)
2285 popup.AppendMenu(MF_SEPARATOR, NULL);
2286 } // GetSelectedCount() == 1
2288 if (GetSelectedCount() != 0)
2290 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2291 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2292 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2293 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2294 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2295 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2298 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2299 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2301 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2302 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2304 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2305 // DialogEnableWindow(IDOK, FALSE);
2306 // SetPromptApp(&theApp);
2308 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2310 // EnableOKButton();
2311 } // if (popup.CreatePopupMenu())
2315 bool CGitLogListBase::IsSelectionContinuous()
2317 if ( GetSelectedCount()==1 )
2319 // if only one revision is selected, the selection is of course
2320 // continuous
2321 return true;
2324 POSITION pos = GetFirstSelectedItemPosition();
2325 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2326 if (bContinuous)
2328 int itemindex = GetNextSelectedItem(pos);
2329 while (pos)
2331 int nextindex = GetNextSelectedItem(pos);
2332 if (nextindex - itemindex > 1)
2334 bContinuous = false;
2335 break;
2337 itemindex = nextindex;
2340 return bContinuous;
2343 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2346 CString sClipdata;
2347 POSITION pos = GetFirstSelectedItemPosition();
2348 if (pos != NULL)
2350 CString sRev;
2351 sRev.LoadString(IDS_LOG_REVISION);
2352 CString sAuthor;
2353 sAuthor.LoadString(IDS_LOG_AUTHOR);
2354 CString sDate;
2355 sDate.LoadString(IDS_LOG_DATE);
2356 CString sMessage;
2357 sMessage.LoadString(IDS_LOG_MESSAGE);
2358 bool first = true;
2359 while (pos)
2361 CString sLogCopyText;
2362 CString sPaths;
2363 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2365 if (toCopy == ID_COPY_ALL)
2367 //pLogEntry->GetFiles(this)
2368 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2370 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2371 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2373 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2374 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2376 CString rename;
2377 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2378 sPaths += _T(" ") + rename;
2380 sPaths += _T("\r\n");
2382 sPaths.Trim();
2383 CString body = pLogEntry->GetBody();
2384 body.Replace(_T("\n"), _T("\r\n"));
2385 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"),
2386 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2387 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2388 (LPCTSTR)sDate,
2389 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2390 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2391 (LPCTSTR)sPaths);
2392 sClipdata += sLogCopyText;
2394 else if (toCopy == ID_COPY_MESSAGE)
2396 CString body = pLogEntry->GetBody();
2397 body.Replace(_T("\n"), _T("\r\n"));
2398 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2400 else if (toCopy == ID_COPY_SUBJECT)
2402 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2404 else
2406 if (!first)
2407 sClipdata += _T("\r\n");
2408 sClipdata += pLogEntry->m_CommitHash;
2411 first = false;
2413 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2418 void CGitLogListBase::DiffSelectedRevWithPrevious()
2420 if (m_bThreadRunning)
2421 return;
2423 int FirstSelect=-1, LastSelect=-1;
2424 POSITION pos = GetFirstSelectedItemPosition();
2425 FirstSelect = GetNextSelectedItem(pos);
2426 while(pos)
2428 LastSelect = GetNextSelectedItem(pos);
2431 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2433 #if 0
2434 UpdateLogInfoLabel();
2435 int selIndex = m_LogList.GetSelectionMark();
2436 if (selIndex < 0)
2437 return;
2438 int selCount = m_LogList.GetSelectedCount();
2439 if (selCount != 1)
2440 return;
2442 // Find selected entry in the log list
2443 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2444 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2445 long rev1 = pLogEntry->Rev;
2446 long rev2 = rev1-1;
2447 CTGitPath path = m_path;
2449 // See how many files under the relative root were changed in selected revision
2450 int nChanged = 0;
2451 LogChangedPath * changed = NULL;
2452 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2454 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2455 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2457 ++nChanged;
2458 changed = cpath;
2462 if (m_path.IsDirectory() && nChanged == 1)
2464 // We're looking at the log for a directory and only one file under dir was changed in the revision
2465 // Do diff on that file instead of whole directory
2466 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2469 m_bCancelled = FALSE;
2470 DialogEnableWindow(IDOK, FALSE);
2471 SetPromptApp(&theApp);
2472 theApp.DoWaitCursor(1);
2474 if (PromptShown())
2476 GitDiff diff(this, m_hWnd, true);
2477 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2478 diff.SetHEADPeg(m_LogRevision);
2479 diff.ShowCompare(path, rev2, path, rev1);
2481 else
2483 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2486 theApp.DoWaitCursor(-1);
2487 EnableOKButton();
2488 #endif
2491 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2493 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2494 *pResult = -1;
2496 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2497 return;
2498 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2499 return;
2500 if (pFindInfo->lvfi.psz == 0)
2501 return;
2502 #if 0
2503 CString sCmp = pFindInfo->lvfi.psz;
2504 CString sRev;
2505 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2507 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2508 sRev.Format(_T("%ld"), pLogEntry->Rev);
2509 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2511 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2513 *pResult = i;
2514 return;
2517 else
2519 if (sCmp.Compare(sRev)==0)
2521 *pResult = i;
2522 return;
2526 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2528 for (int i=0; i<pFindInfo->iStart; ++i)
2530 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2531 sRev.Format(_T("%ld"), pLogEntry->Rev);
2532 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2534 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2536 *pResult = i;
2537 return;
2540 else
2542 if (sCmp.Compare(sRev)==0)
2544 *pResult = i;
2545 return;
2550 #endif
2551 *pResult = -1;
2554 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2556 ClearText();
2558 this->m_arShownList.SafeRemoveAll();
2560 this->m_logEntries.ClearAll();
2561 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2562 return -1;
2564 SetItemCountEx((int)m_logEntries.size());
2566 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2568 if(m_IsOldFirst)
2570 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2571 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2574 else
2576 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2577 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2581 ReloadHashMap();
2583 if(path)
2584 m_Path=*path;
2585 return 0;
2589 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2591 ClearText();
2593 m_arShownList.SafeRemoveAll();
2595 m_logEntries.ClearAll();
2596 if (m_logEntries.Fill(hashes))
2597 return -1;
2599 SetItemCountEx((int)m_logEntries.size());
2601 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2603 if (m_IsOldFirst)
2605 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2606 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2608 else
2610 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2611 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2615 ReloadHashMap();
2617 return 0;
2620 int CGitLogListBase::BeginFetchLog()
2622 ClearText();
2624 this->m_arShownList.SafeRemoveAll();
2626 this->m_logEntries.ClearAll();
2628 this->m_LogCache.ClearAllParent();
2630 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2632 CTGitPath *path;
2633 if(this->m_Path.IsEmpty())
2634 path=NULL;
2635 else
2636 path=&this->m_Path;
2638 int mask;
2639 mask = CGit::LOG_INFO_ONLY_HASH;
2640 if (m_bIncludeBoundaryCommits)
2641 mask |= CGit::LOG_INFO_BOUNDARY;
2642 // if(this->m_bAllBranch)
2643 mask |= m_ShowMask ;
2645 if(m_bShowWC)
2647 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2648 ResetWcRev();
2649 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2652 if (m_sRange.IsEmpty())
2653 m_sRange = _T("HEAD");
2655 CFilterData data;
2656 data.m_From = m_From;
2657 data.m_To =m_To;
2659 #if 0 /* use tortoiegit filter */
2660 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2661 data.m_Author = this->m_sFilterText;
2663 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2664 data.m_MessageFilter = this->m_sFilterText;
2666 data.m_IsRegex = m_bFilterWithRegex;
2667 #endif
2669 // follow does not work for directories
2670 if (!path || path->IsDirectory())
2671 mask &= ~CGit::LOG_INFO_FOLLOW;
2672 // follow does not work with all branches 8at least in TGit)
2673 if (mask & CGit::LOG_INFO_FOLLOW)
2674 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2676 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2678 //this->m_logEntries.ParserFromLog();
2679 if(IsInWorkingThread())
2681 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2683 else
2685 SetItemCountEx((int)m_logEntries.size());
2690 [] { git_init(); } ();
2692 catch (char* msg)
2694 CString err(msg);
2695 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2696 return -1;
2699 if (!g_Git.CanParseRev(m_sRange))
2701 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2702 return 0;
2704 // if show all branches, pick any ref as dummy entry ref
2705 STRING_VECTOR list;
2706 if (g_Git.GetRefList(list))
2707 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2708 if (list.size() == 0)
2709 return 0;
2711 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2714 g_Git.m_critGitDllSec.Lock();
2715 try {
2716 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2718 g_Git.m_critGitDllSec.Unlock();
2719 return -1;
2722 catch (char* msg)
2724 g_Git.m_critGitDllSec.Unlock();
2725 CString err(msg);
2726 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2727 return -1;
2729 g_Git.m_critGitDllSec.Unlock();
2731 return 0;
2734 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2736 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2738 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2740 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2742 DiffSelectedRevWithPrevious();
2743 return TRUE;
2746 #if 0
2747 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2749 DiffSelectedFile();
2750 return TRUE;
2752 #endif
2754 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2756 // select all entries
2757 for (int i=0; i<GetItemCount(); ++i)
2759 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2761 return TRUE;
2764 #if 0
2765 if (m_hAccel && !bSkipAccelerator)
2767 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2768 if (ret)
2769 return TRUE;
2772 #endif
2773 //m_tooltips.RelayEvent(pMsg);
2774 return __super::PreTranslateMessage(pMsg);
2777 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2779 // a double click on an entry in the revision list has happened
2780 *pResult = 0;
2782 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2783 DiffSelectedRevWithPrevious();
2786 int CGitLogListBase::FetchLogAsync(void * data)
2788 ReloadHashMap();
2789 m_ProcData=data;
2790 m_bExitThread=FALSE;
2791 InterlockedExchange(&m_bThreadRunning, TRUE);
2792 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2793 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2794 if (m_LoadingThread ==NULL)
2796 InterlockedExchange(&m_bThreadRunning, FALSE);
2797 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2798 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2799 return -1;
2801 return 0;
2804 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2806 return ((CGitLogListBase*)pVoid)->LogThread();
2809 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2811 //CTime time;
2812 oldest=CTime::GetCurrentTime();
2813 latest=CTime(1971,1,2,0,0,0);
2814 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2816 if(m_logEntries[i].IsEmpty())
2817 continue;
2819 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2820 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2822 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2823 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2827 if(latest<oldest)
2828 latest=oldest;
2831 UINT CGitLogListBase::LogThread()
2833 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2835 InterlockedExchange(&m_bThreadRunning, TRUE);
2836 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2838 ULONGLONG t1,t2;
2840 if(BeginFetchLog())
2842 InterlockedExchange(&m_bThreadRunning, FALSE);
2843 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2845 return 1;
2848 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2849 bool bRegex = false;
2850 if (m_bFilterWithRegex)
2851 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2853 TRACE(_T("\n===Begin===\n"));
2854 //Update work copy item;
2856 if (!m_logEntries.empty())
2858 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2860 m_arShownList.SafeAdd(pRev);
2864 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2866 // store commit number of the last selected commit/line before the refresh or -1
2867 int lastSelectedHashNItem = -1;
2868 int ret = 0;
2870 bool shouldWalk = true;
2871 if (!g_Git.CanParseRev(m_sRange))
2873 // walk revisions if show all branches and there exists any ref
2874 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2875 shouldWalk = false;
2876 else
2878 STRING_VECTOR list;
2879 if (g_Git.GetRefList(list))
2880 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2881 if (list.size() == 0)
2882 shouldWalk = false;
2886 if (shouldWalk)
2888 g_Git.m_critGitDllSec.Lock();
2889 int total = 0;
2892 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2893 total = git_get_log_estimate_commit_count(m_DllGitLog);
2895 catch (char* msg)
2897 CString err(msg);
2898 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2899 ret = -1;
2901 g_Git.m_critGitDllSec.Unlock();
2903 GIT_COMMIT commit;
2904 t2=t1=GetTickCount();
2905 int oldprecentage = 0;
2906 size_t oldsize = m_logEntries.size();
2907 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2908 while (ret== 0 && !m_bExitThread)
2910 g_Git.m_critGitDllSec.Lock();
2913 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2915 catch (char* msg)
2917 g_Git.m_critGitDllSec.Unlock();
2918 CString err(msg);
2919 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2920 break;
2922 g_Git.m_critGitDllSec.Unlock();
2924 if(ret)
2926 if (ret != -2) // other than end of revision walking
2927 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2928 break;
2931 if (commit.m_ignore == 1)
2933 git_free_commit(&commit);
2934 continue;
2937 //printf("%s\r\n",commit.GetSubject());
2938 if(m_bExitThread)
2939 break;
2941 CGitHash hash = (char*)commit.m_hash ;
2943 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2944 pRev->m_GitCommit = commit;
2945 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2947 char *note=NULL;
2948 g_Git.m_critGitDllSec.Lock();
2951 git_get_notes(commit.m_hash, &note);
2953 catch (char* msg)
2955 g_Git.m_critGitDllSec.Unlock();
2956 CString err(msg);
2957 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2958 break;
2960 g_Git.m_critGitDllSec.Unlock();
2962 if(note)
2964 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2965 free(note);
2966 note = nullptr;
2969 if(!pRev->m_IsDiffFiles)
2971 pRev->m_CallDiffAsync = DiffAsync;
2974 pRev->ParserParentFromCommit(&commit);
2975 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2977 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2979 const CGitHash &parentHash = pRev->m_ParentHash[i];
2980 auto it = commitChildren.find(parentHash);
2981 if (it == commitChildren.end())
2983 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2985 it->second.insert(pRev->m_CommitHash);
2989 #ifdef DEBUG
2990 pRev->DbgPrint();
2991 TRACE(_T("\n"));
2992 #endif
2994 bool visible = true;
2995 if (HasFilterText())
2997 if(!IsMatchFilter(bRegex,pRev,pat))
2998 visible = false;
3000 if (visible && !ShouldShowFilter(pRev, commitChildren))
3001 visible = false;
3002 this->m_critSec.Lock();
3003 m_logEntries.append(hash, visible);
3004 if (visible)
3005 m_arShownList.SafeAdd(pRev);
3006 this->m_critSec.Unlock();
3008 if (!visible)
3009 continue;
3011 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3012 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3014 t2=GetTickCount();
3016 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3018 //update UI
3019 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3020 if(percent > 99)
3021 percent =99;
3022 if(percent < GITLOG_START)
3023 percent = GITLOG_START +1;
3025 oldsize = m_logEntries.size();
3026 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3028 //if( percent > oldprecentage )
3030 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3031 oldprecentage = percent;
3034 if (lastSelectedHashNItem >= 0)
3035 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3037 t1 = t2;
3040 g_Git.m_critGitDllSec.Lock();
3041 git_close_log(m_DllGitLog);
3042 g_Git.m_critGitDllSec.Unlock();
3046 if (m_bExitThread)
3048 InterlockedExchange(&m_bThreadRunning, FALSE);
3049 return 0;
3052 //Update UI;
3053 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3055 if (lastSelectedHashNItem >= 0)
3056 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3058 if (this->m_hWnd)
3059 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3061 InterlockedExchange(&m_bThreadRunning, FALSE);
3063 return 0;
3066 void CGitLogListBase::FetchRemoteList()
3068 STRING_VECTOR remoteList;
3069 if (!g_Git.GetRemoteList(remoteList))
3070 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3071 else
3072 m_SingleRemote = _T("");
3075 void CGitLogListBase::FetchTrackingBranchList()
3077 m_TrackingMap.clear();
3078 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3080 for (size_t j = 0; j < it->second.size(); ++j)
3082 CString branchName;
3083 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3085 CString pullRemote, pullBranch;
3086 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3087 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3089 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3096 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3098 SafeTerminateThread();
3100 this->SetItemCountEx(0);
3101 this->Clear();
3103 ResetWcRev();
3105 // HACK to hide graph column
3106 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3107 SetColumnWidth(0, 0);
3108 else
3109 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3111 //Update branch and Tag info
3112 ReloadHashMap();
3113 if (m_pFindDialog)
3114 m_pFindDialog->RefreshList();
3115 //Assume Thread have exited
3116 //if(!m_bThreadRunning)
3118 m_logEntries.clear();
3120 if(IsCleanFilter)
3122 m_sFilterText.Empty();
3123 m_From=-1;
3124 m_To=-1;
3127 InterlockedExchange(&m_bExitThread,FALSE);
3129 InterlockedExchange(&m_bThreadRunning, TRUE);
3130 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3131 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3133 InterlockedExchange(&m_bThreadRunning, FALSE);
3134 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3135 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3139 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3143 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3144 if (!bMatchCase)
3145 type |= std::tr1::regex_constants::icase;
3146 pat = std::tr1::wregex(regexp_str, type);
3147 return true;
3149 catch (std::exception) {}
3150 return false;
3152 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3154 BOOL result = TRUE;
3155 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3156 CString sRev;
3158 if ((bRegex)&&(m_bFilterWithRegex))
3160 if (m_SelectedFilters & LOGFILTER_BUGID)
3162 if(this->m_bShowBugtraqColumn)
3164 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3166 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3167 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3169 return TRUE;
3174 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3176 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3177 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3179 return TRUE;
3183 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3185 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3186 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3188 return TRUE;
3192 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3194 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3196 return TRUE;
3199 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3201 return TRUE;
3205 if (m_SelectedFilters & LOGFILTER_EMAILS)
3207 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3209 return TRUE;
3212 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3214 return TRUE;
3218 if (m_SelectedFilters & LOGFILTER_REVS)
3220 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3221 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3223 return TRUE;
3227 if (m_SelectedFilters & LOGFILTER_REFNAME)
3229 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3230 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3232 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3234 return TRUE;
3239 if (m_SelectedFilters & LOGFILTER_PATHS)
3241 CTGitPathList *pathList=NULL;
3242 if( pRev->m_IsDiffFiles)
3243 pathList = &pRev->GetFiles(this);
3244 else
3246 if(!pRev->m_IsSimpleListReady)
3247 pRev->SafeGetSimpleList(&g_Git);
3250 if(pathList)
3251 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3253 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3255 return true;
3257 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3259 return true;
3263 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3265 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3267 return true;
3272 else
3274 CString find = m_sFilterText;
3275 if (!m_bFilterCaseSensitively)
3276 find.MakeLower();
3277 result = find[0] == '!' ? FALSE : TRUE;
3278 if (!result)
3279 find = find.Mid(1);
3281 if (m_SelectedFilters & LOGFILTER_BUGID)
3283 if(this->m_bShowBugtraqColumn)
3285 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3287 if (!m_bFilterCaseSensitively)
3288 sBugIds.MakeLower();
3289 if ((sBugIds.Find(find) >= 0))
3291 return result;
3296 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3298 CString msg = pRev->GetSubject();
3300 if (!m_bFilterCaseSensitively)
3301 msg = msg.MakeLower();
3302 if ((msg.Find(find) >= 0))
3304 return result;
3308 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3310 CString msg = pRev->GetBody();
3312 if (!m_bFilterCaseSensitively)
3313 msg = msg.MakeLower();
3314 if ((msg.Find(find) >= 0))
3316 return result;
3320 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3322 CString msg = pRev->GetAuthorName();
3323 if (!m_bFilterCaseSensitively)
3324 msg = msg.MakeLower();
3325 if ((msg.Find(find) >= 0))
3327 return result;
3331 if (m_SelectedFilters & LOGFILTER_EMAILS)
3333 CString msg = pRev->GetAuthorEmail();
3334 if (!m_bFilterCaseSensitively)
3335 msg = msg.MakeLower();
3336 if ((msg.Find(find) >= 0))
3338 return result;
3342 if (m_SelectedFilters & LOGFILTER_REVS)
3344 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3345 if ((sRev.Find(find) >= 0))
3347 return result;
3351 if (m_SelectedFilters & LOGFILTER_REFNAME)
3353 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3354 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3356 if (it->Find(find) >= 0)
3358 return result;
3363 if (m_SelectedFilters & LOGFILTER_PATHS)
3365 CTGitPathList *pathList=NULL;
3366 if( pRev->m_IsDiffFiles)
3367 pathList = &pRev->GetFiles(this);
3368 else
3370 if(!pRev->m_IsSimpleListReady)
3371 pRev->SafeGetSimpleList(&g_Git);
3373 if(pathList)
3374 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3376 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3377 CString path = cpath->GetGitOldPathString();
3378 if (!m_bFilterCaseSensitively)
3379 path.MakeLower();
3380 if ((path.Find(find)>=0))
3382 return result;
3384 path = cpath->GetGitPathString();
3385 if (!m_bFilterCaseSensitively)
3386 path.MakeLower();
3387 if ((path.Find(find)>=0))
3389 return result;
3393 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3395 CString path = pRev->m_SimpleFileList[i];
3396 if (!m_bFilterCaseSensitively)
3397 path.MakeLower();
3398 if ((path.Find(find)>=0))
3400 return result;
3404 } // else (from if (bRegex))
3405 return !result;
3408 static bool CStringStartsWith(const CString &str, const CString &prefix)
3410 return str.Left(prefix.GetLength()) == prefix;
3412 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3414 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3415 return true;
3417 if (m_ShowFilter & FILTERSHOW_REFS)
3419 // Keep all refs.
3420 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3421 for (size_t i = 0; i < refList.size(); ++i)
3423 const CString &str = refList[i];
3424 if (CStringStartsWith(str, _T("refs/heads/")))
3426 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3427 return true;
3429 else if (CStringStartsWith(str, _T("refs/remotes/")))
3431 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3432 return true;
3434 else if (CStringStartsWith(str, _T("refs/tags/")))
3436 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3437 return true;
3439 else if (CStringStartsWith(str, _T("refs/stash")))
3441 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3442 return true;
3444 else if (CStringStartsWith(str, _T("refs/bisect/")))
3446 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3447 return true;
3450 // Keep the head too.
3451 if (pRev->m_CommitHash == m_HeadHash)
3452 return true;
3455 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3457 if (pRev->ParentsCount() > 1)
3458 return true;
3459 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3460 if (childrenIt != commitChildren.end())
3462 const std::set<CGitHash> &children = childrenIt->second;
3463 if (children.size() > 1)
3464 return true;
3467 return false;
3470 void CGitLogListBase::ShowGraphColumn(bool bShow)
3472 // HACK to hide graph column
3473 if (bShow)
3474 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3475 else
3476 SetColumnWidth(0, 0);
3479 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3481 CString cmd;
3482 CString output;
3484 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3486 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3487 for (size_t i = 0; i < vector.size(); ++i)
3489 if (vector[i].Find(_T("refs/tags/")) == 0)
3491 CString tag = vector[i];
3492 int start = vector[i].Find(_T("^{}"));
3493 if (start > 0)
3494 tag = tag.Left(start);
3495 else
3496 continue;
3498 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3499 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3500 output.AppendChar(_T('\n'));
3505 return output;
3508 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3511 pShownlist->SafeRemoveAll();
3513 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3514 bool bRegex = false;
3515 if (m_bFilterWithRegex)
3516 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3518 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3519 CString sRev;
3520 for (DWORD i=0; i<m_logEntries.size(); ++i)
3522 if ((bRegex)&&(m_bFilterWithRegex))
3524 #if 0
3525 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3527 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3528 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3530 pShownlist->SafeAdd(m_logEntries[i]);
3531 continue;
3534 #endif
3535 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3537 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3538 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3540 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3541 continue;
3544 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3546 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3547 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3549 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3550 continue;
3553 if (m_SelectedFilters & LOGFILTER_PATHS)
3555 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3557 bool bGoing = true;
3558 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3560 CTGitPath cpath = pathList[cpPathIndex];
3561 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3563 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3564 bGoing = false;
3565 continue;
3567 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3569 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3570 bGoing = false;
3571 continue;
3573 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3575 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3576 bGoing = false;
3577 continue;
3581 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3583 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3585 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3586 continue;
3589 if (m_SelectedFilters & LOGFILTER_EMAILS)
3591 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3593 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3594 continue;
3597 if (m_SelectedFilters & LOGFILTER_REVS)
3599 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3600 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3602 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3603 continue;
3606 if (m_SelectedFilters & LOGFILTER_REFNAME)
3608 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3609 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3611 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3613 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3614 continue;
3618 } // if (bRegex)
3619 else
3621 CString find = m_sFilterText;
3622 if (!m_bFilterCaseSensitively)
3623 find.MakeLower();
3624 #if 0
3625 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3627 CString sBugIDs = m_logEntries[i]->sBugIDs;
3629 if (!m_bFilterCaseSensitively)
3630 sBugIDs = sBugIDs.MakeLower();
3631 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3633 pShownlist->SafeAdd(m_logEntries[i]);
3634 continue;
3637 #endif
3638 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3640 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3642 if (!m_bFilterCaseSensitively)
3643 msg = msg.MakeLower();
3644 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3646 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3647 continue;
3650 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3652 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3654 if (!m_bFilterCaseSensitively)
3655 msg = msg.MakeLower();
3656 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3658 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3659 continue;
3662 if (m_SelectedFilters & LOGFILTER_PATHS)
3664 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3666 bool bGoing = true;
3667 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3669 CTGitPath cpath = pathList[cpPathIndex];
3670 CString path = cpath.GetGitOldPathString();
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.GetGitPathString();
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;
3688 path = cpath.GetActionName();
3689 if (!m_bFilterCaseSensitively)
3690 path.MakeLower();
3691 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3693 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3694 bGoing = false;
3695 continue;
3699 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3701 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3702 if (!m_bFilterCaseSensitively)
3703 msg = msg.MakeLower();
3704 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3706 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3707 continue;
3710 if (m_SelectedFilters & LOGFILTER_EMAILS)
3712 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3713 if (!m_bFilterCaseSensitively)
3714 msg = msg.MakeLower();
3715 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3717 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3718 continue;
3721 if (m_SelectedFilters & LOGFILTER_REVS)
3723 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3724 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3726 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3727 continue;
3730 if (m_SelectedFilters & LOGFILTER_REFNAME)
3732 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3733 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3735 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3737 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3738 continue;
3742 } // else (from if (bRegex))
3743 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3747 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3750 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3752 if(m_From == -1)
3753 if(m_To == -1)
3754 return true;
3755 else
3756 return time <= m_To;
3757 else
3758 if(m_To == -1)
3759 return time >= m_From;
3760 else
3761 return ((time >= m_From)&&(time <= m_To));
3763 return TRUE; /* git dll will filter time range */
3765 // return TRUE;
3767 void CGitLogListBase::StartFilter()
3769 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3770 RecalculateShownList(&m_arShownList);
3771 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3774 DeleteAllItems();
3775 SetItemCountEx(ShownCountWithStopped());
3776 RedrawItems(0, ShownCountWithStopped());
3777 Invalidate();
3780 void CGitLogListBase::RemoveFilter()
3783 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3785 m_arShownList.SafeRemoveAll();
3787 // reset the time filter too
3788 #if 0
3789 m_timFrom = (__time64_t(m_tFrom));
3790 m_timTo = (__time64_t(m_tTo));
3791 m_DateFrom.SetTime(&m_timFrom);
3792 m_DateTo.SetTime(&m_timTo);
3793 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3794 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3795 #endif
3797 for (DWORD i=0; i<m_logEntries.size(); ++i)
3799 if(this->m_IsOldFirst)
3801 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3803 else
3805 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3808 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3809 DeleteAllItems();
3810 SetItemCountEx(ShownCountWithStopped());
3811 RedrawItems(0, ShownCountWithStopped());
3813 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3816 void CGitLogListBase::Clear()
3818 m_arShownList.SafeRemoveAll();
3819 DeleteAllItems();
3821 m_logEntries.ClearAll();
3825 void CGitLogListBase::OnDestroy()
3827 // save the column widths to the registry
3828 SaveColumnWidths();
3830 SafeTerminateThread();
3831 SafeTerminateAsyncDiffThread();
3833 int retry = 0;
3834 while(m_LogCache.SaveCache())
3836 if(retry > 5)
3837 break;
3838 Sleep(1000);
3840 ++retry;
3842 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3843 // MB_YESNO) == IDNO)
3844 // break;
3847 CHintListCtrl::OnDestroy();
3850 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3852 CRect rect;
3853 int i=(int)wParam;
3854 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3855 this->InvalidateRect(rect);
3857 return 0;
3861 * Save column widths to the registry
3863 void CGitLogListBase::SaveColumnWidths()
3865 int maxcol = m_ColumnManager.GetColumnCount();
3867 // HACK that graph column is always shown
3868 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3870 for (int col = 0; col < maxcol; ++col)
3871 if (m_ColumnManager.IsVisible (col))
3872 m_ColumnManager.ColumnResized (col);
3874 m_ColumnManager.WriteSettings();
3877 int CGitLogListBase::GetHeadIndex()
3879 if(m_HeadHash.IsEmpty())
3880 return -1;
3882 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3884 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3885 if(pRev)
3887 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3888 return i;
3891 return -1;
3893 void CGitLogListBase::OnFind()
3895 if (!m_pFindDialog)
3897 m_pFindDialog = new CFindDlg(this);
3898 m_pFindDialog->Create(this);
3901 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3903 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3905 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3907 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3908 Default();
3910 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3912 if (GetSelectedCount() != 0)
3913 return 0;
3915 CGitHash theSelectedHash = m_lastSelectedHash;
3916 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3917 m_lastSelectedHash = theSelectedHash;
3919 int countPerPage = GetCountPerPage();
3920 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3921 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3922 EnsureVisible((int)itemToSelect, FALSE);
3923 return 0;
3925 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3928 ASSERT(m_pFindDialog != NULL);
3929 bool bFound = false;
3930 int i=0;
3932 if (m_pFindDialog->IsTerminating())
3934 // invalidate the handle identifying the dialog box.
3935 m_pFindDialog = NULL;
3936 return 0;
3939 INT_PTR cnt = m_arShownList.GetCount();
3941 if(m_pFindDialog->IsRef())
3943 CString str;
3944 str=m_pFindDialog->GetFindString();
3946 CGitHash hash;
3948 if(!str.IsEmpty())
3950 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3951 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3954 if(!hash.IsEmpty())
3956 for (i = 0; i < cnt; ++i)
3958 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3959 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3961 bFound = true;
3962 break;
3966 if (!bFound)
3968 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3969 return 0;
3973 if (m_pFindDialog->FindNext() && !bFound)
3975 //read data from dialog
3976 CString findText = m_pFindDialog->GetFindString();
3977 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3979 std::tr1::wregex pat;
3980 bool bRegex = false;
3981 if (m_pFindDialog->Regex())
3982 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3984 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3986 for (i = m_nSearchIndex + 1; ; ++i)
3988 if (i >= cnt)
3990 i = 0;
3991 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3993 if (m_nSearchIndex >= 0)
3995 if (i == m_nSearchIndex)
3997 ::MessageBeep(0xFFFFFFFF);
3998 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3999 break;
4003 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
4005 CString str;
4006 str+=pLogEntry->m_CommitHash.ToString();
4007 str+=_T("\n");
4009 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4011 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4012 str+=_T("\n");
4015 str+=pLogEntry->GetAuthorEmail();
4016 str+=_T("\n");
4017 str+=pLogEntry->GetAuthorName();
4018 str+=_T("\n");
4019 str+=pLogEntry->GetBody();
4020 str+=_T("\n");
4021 str+=pLogEntry->GetCommitterEmail();
4022 str+=_T("\n");
4023 str+=pLogEntry->GetCommitterName();
4024 str+=_T("\n");
4025 str+=pLogEntry->GetSubject();
4026 str+=_T("\n");
4027 str+=pLogEntry->m_Notes;
4028 str+=_T("\n");
4029 str+=GetTagInfo(pLogEntry);
4030 str+=_T("\n");
4033 /*Because changed files list is loaded on demand when gui show,
4034 files will empty when files have not fetched.
4036 we can add it back by using one-way diff(with outnumber changed and rename detect.
4037 here just need changed filename list. one-way is much quicker.
4039 if(pLogEntry->m_IsFull)
4041 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
4043 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
4044 str+=_T("\n");
4045 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
4046 str+=_T("\n");
4049 else
4051 if(!pLogEntry->m_IsSimpleListReady)
4052 pLogEntry->SafeGetSimpleList(&g_Git);
4054 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
4056 str+=pLogEntry->m_SimpleFileList[i];
4057 str+=_T("\n");
4063 if (bRegex)
4065 if (std::regex_search(std::wstring(str), pat, flags))
4067 bFound = true;
4068 break;
4071 else
4073 if (bMatchCase)
4075 if (str.Find(findText) >= 0)
4077 bFound = true;
4078 break;
4082 else
4084 CString msg = str;
4085 msg = msg.MakeLower();
4086 CString find = findText.MakeLower();
4087 if (msg.Find(find) >= 0)
4089 bFound = TRUE;
4090 break;
4094 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4096 } // if(m_pFindDialog->FindNext())
4097 //UpdateLogInfoLabel();
4099 if (bFound)
4101 m_nSearchIndex = i;
4102 EnsureVisible(i, FALSE);
4103 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4105 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4106 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4107 SetSelectionMark(i);
4109 else
4111 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4112 if (pLogEntry)
4113 m_highlight = pLogEntry->m_CommitHash;
4115 Invalidate();
4116 //FillLogMessageCtrl();
4117 UpdateData(FALSE);
4120 return 0;
4123 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4125 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4127 *pResult = FALSE;
4130 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4132 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4134 Invalidate(FALSE);
4137 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4139 LVHITTESTINFO lvhitTestInfo;
4141 lvhitTestInfo.pt = point;
4143 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4144 int nSubItem = lvhitTestInfo.iSubItem;
4146 UINT nFlags = lvhitTestInfo.flags;
4148 // nFlags is 0 if the SubItemHitTest fails
4149 // Therefore, 0 & <anything> will equal false
4150 if (nFlags & LVHT_ONITEM)
4152 // Get the client area occupied by this control
4153 RECT rcClient;
4154 GetClientRect(&rcClient);
4156 // Fill in the TOOLINFO structure
4157 pTI->hwnd = m_hWnd;
4158 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4159 pTI->lpszText = LPSTR_TEXTCALLBACK;
4160 pTI->rect = rcClient;
4162 return pTI->uId; // By returning a unique value per listItem,
4163 // we ensure that when the mouse moves over another list item,
4164 // the tooltip will change
4166 else
4168 // Otherwise, we aren't interested, so let the message propagate
4169 return -1;
4173 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4175 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4176 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4178 *pResult = 0;
4180 // Ignore messages from the built in tooltip, we are processing them internally
4181 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4182 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4183 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4184 return FALSE;
4186 // Get the mouse position
4187 const MSG* pMessage = GetCurrentMessage();
4189 CPoint pt;
4190 pt = pMessage->pt;
4191 ScreenToClient(&pt);
4193 // Check if the point falls onto a list item
4194 LVHITTESTINFO lvhitTestInfo;
4195 lvhitTestInfo.pt = pt;
4197 int nItem = SubItemHitTest(&lvhitTestInfo);
4199 if (lvhitTestInfo.flags & LVHT_ONITEM)
4201 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4202 if (strTipText.IsEmpty())
4203 return FALSE;
4205 // we want multiline tooltips
4206 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4208 wcscpy_s(m_wszTip, strTipText);
4209 // handle Unicode as well as non-Unicode requests
4210 if (pNMHDR->code == TTN_NEEDTEXTA)
4212 pTTTA->hinst = nullptr;
4213 pTTTA->lpszText = m_szTip;
4214 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4216 else
4218 pTTTW->hinst = nullptr;
4219 pTTTW->lpszText = m_wszTip;
4222 CRect rect;
4223 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4224 ClientToScreen(rect);
4225 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4227 return TRUE; // We found a tool tip,
4228 // tell the framework this message has been handled
4231 return FALSE; // We didn't handle the message,
4232 // let the framework continue propagating the message
4235 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4237 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4239 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4240 if (pLogEntry == nullptr)
4241 return CString();
4242 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4243 return CString();
4244 return pLogEntry->GetSubject();
4246 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4248 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4249 if (pLogEntry == nullptr)
4250 return CString();
4251 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4253 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4255 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4256 if (pLogEntry == nullptr)
4257 return CString();
4258 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4260 else if (nSubItem == LOGLIST_ACTION)
4262 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4263 if (pLogEntry == nullptr)
4264 return CString();
4266 if (!pLogEntry->m_IsDiffFiles)
4267 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4269 int actions = pLogEntry->GetAction(this);
4270 CString sToolTipText;
4272 CString actionText;
4273 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4274 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4276 if (actions & CTGitPath::LOGACTIONS_ADDED)
4278 if (!actionText.IsEmpty())
4279 actionText += L"\r\n";
4280 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4283 if (actions & CTGitPath::LOGACTIONS_DELETED)
4285 if (!actionText.IsEmpty())
4286 actionText += L"\r\n";
4287 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4290 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4292 if (!actionText.IsEmpty())
4293 actionText += L"\r\n";
4294 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4297 if (!actionText.IsEmpty())
4299 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4300 sToolTipText = sTitle + L":\r\n" + actionText;
4302 return sToolTipText;
4304 return CString();