No need to beep after displaying Commit Not Visible message
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobe1886baf7f92f06c5089206ddd314271c49a498e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "GitLogListBase.h"
26 #include "GitRev.h"
27 #include "IconMenu.h"
28 #include "cursor.h"
29 #include "InputDlg.h"
30 #include "GitProgressDlg.h"
31 #include "ProgressDlg.h"
32 #include "LogDlg.h"
33 #include "MessageBox.h"
34 #include "registry.h"
35 #include "LoglistUtils.h"
36 #include "PathUtils.h"
37 #include "StringUtils.h"
38 #include "UnicodeUtils.h"
39 #include "TempFile.h"
40 #include "IconMenu.h"
41 #include "GitStatus.h"
42 #include "..\\TortoiseShell\\Resource.h"
43 #include "FindDlg.h"
44 #include "SysInfo.h"
46 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
47 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
48 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
54 ,m_nSearchIndex(0)
55 ,m_bNoDispUpdates(FALSE)
56 , m_bThreadRunning(FALSE)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL)
59 , m_SelectedFilters(LOGFILTER_ALL)
60 , m_ShowFilter(FILTERSHOW_ALL)
61 , m_bShowWC(false)
62 , m_logEntries(&m_LogCache)
63 , m_pFindDialog(NULL)
64 , m_ColumnManager(this)
65 , m_dwDefaultColumns(0)
66 , m_arShownList(&m_critSec)
67 , m_hasWC(true)
68 , m_bNoHightlightHead(FALSE)
69 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
71 // use the default GUI font, create a copy of it and
72 // change the copy to BOLD (leave the rest of the font
73 // the same)
74 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
75 LOGFONT lf = {0};
76 GetObject(hFont, sizeof(LOGFONT), &lf);
77 lf.lfWeight = FW_BOLD;
78 m_boldFont = CreateFontIndirect(&lf);
79 lf.lfWeight = FW_DONTCARE;
80 lf.lfItalic = TRUE;
81 m_FontItalics = CreateFontIndirect(&lf);
82 lf.lfWeight = FW_BOLD;
83 m_boldItalicsFont = CreateFontIndirect(&lf);
85 m_bShowBugtraqColumn=false;
87 m_IsIDReplaceAction=FALSE;
89 this->m_critSec.Init();
90 m_critSec_AsyncDiff.Init();
91 m_wcRev.m_CommitHash.Empty();
92 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
93 m_wcRev.m_ParentHash.clear();
94 m_wcRev.m_Mark=_T('-');
95 m_wcRev.m_IsUpdateing=FALSE;
96 m_wcRev.m_IsFull = TRUE;
98 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
99 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
100 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
101 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
102 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
104 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
106 m_From = -1;
107 m_To = -1;
109 m_ShowMask = 0;
110 m_LoadingThread = NULL;
112 InterlockedExchange(&m_bExitThread,FALSE);
113 m_IsOldFirst = FALSE;
114 m_IsRebaseReplaceGraph = FALSE;
116 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
118 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
120 // get short/long datetime setting from registry
121 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
122 if ( RegUseShortDateFormat )
124 m_DateFormat = DATE_SHORTDATE;
126 else
128 m_DateFormat = DATE_LONGDATE;
130 // get relative time display setting from registry
131 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
132 m_bRelativeTimes = (regRelativeTimes != 0);
133 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
135 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
136 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
137 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
141 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
143 m_ColumnRegKey=_T("log");
145 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
146 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
147 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
149 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
150 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
152 m_AsyncThreadExit = FALSE;
153 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
154 m_AsynDiffListLock.Init();
156 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
157 if (m_DiffingThread ==NULL)
159 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
160 return;
165 int CGitLogListBase::AsyncDiffThread()
167 m_AsyncThreadExited = false;
168 while(!m_AsyncThreadExit)
170 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
172 GitRev *pRev = NULL;
173 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
175 m_AsynDiffListLock.Lock();
176 pRev = m_AsynDiffList.back();
177 m_AsynDiffList.pop_back();
178 m_AsynDiffListLock.Unlock();
180 if( pRev->m_CommitHash.IsEmpty() )
182 if(pRev->m_IsDiffFiles)
183 continue;
185 pRev->GetFiles(this).Clear();
186 pRev->m_ParentHash.clear();
187 pRev->m_ParentHash.push_back(m_HeadHash);
188 if(g_Git.IsInitRepos())
190 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
191 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
194 else
196 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
198 int dummyAction = 0;
199 int *action = &dummyAction;
200 SafeGetAction(pRev, &action);
201 *action = 0;
203 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
204 *action |= pRev->GetFiles(this)[j].m_Action;
206 CString err;
207 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
209 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
210 return -1;
213 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
214 InterlockedExchange(&pRev->m_IsFull, TRUE);
216 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
217 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
218 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
221 m_critSec_AsyncDiff.Lock();
222 int ret = pRev->CheckAndDiff();
223 m_critSec_AsyncDiff.Unlock();
224 if (!ret)
225 { // fetch change file list
226 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
228 if(i < m_arShownList.GetCount())
230 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
231 if(data->m_CommitHash == pRev->m_CommitHash)
233 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
234 break;
239 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
241 POSITION pos = GetFirstSelectedItemPosition();
242 int nItem = GetNextSelectedItem(pos);
244 if(nItem>=0)
246 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(nItem);
247 if(data)
248 if(data->m_CommitHash == pRev->m_CommitHash)
250 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
257 m_AsyncThreadExited = true;
258 return 0;
260 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
262 if (exclusivelyShow)
264 m_ContextMenuMask &= hideMask;
266 else
268 m_ContextMenuMask &= ~hideMask;
272 CGitLogListBase::~CGitLogListBase()
274 InterlockedExchange(&m_bNoDispUpdates, TRUE);
275 this->m_arShownList.SafeRemoveAll();
277 DestroyIcon(m_hModifiedIcon);
278 DestroyIcon(m_hReplacedIcon);
279 DestroyIcon(m_hAddedIcon);
280 DestroyIcon(m_hDeletedIcon);
281 m_logEntries.ClearAll();
283 if (m_boldFont)
284 DeleteObject(m_boldFont);
286 if (m_FontItalics)
287 DeleteObject(m_FontItalics);
289 if (m_boldItalicsFont)
290 DeleteObject(m_boldItalicsFont);
292 if ( m_pStoreSelection )
294 delete m_pStoreSelection;
295 m_pStoreSelection = NULL;
298 SafeTerminateThread();
299 SafeTerminateAsyncDiffThread();
301 if(m_AsyncDiffEvent)
302 CloseHandle(m_AsyncDiffEvent);
306 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
307 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
308 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
309 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
310 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
311 ON_WM_CONTEXTMENU()
312 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
313 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
314 ON_WM_CREATE()
315 ON_WM_DESTROY()
316 ON_MESSAGE(MSG_LOADED,OnLoad)
317 ON_WM_MEASUREITEM()
318 ON_WM_MEASUREITEM_REFLECT()
319 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
320 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
321 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
322 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
323 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
324 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
325 END_MESSAGE_MAP()
327 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
329 //if (m_nRowHeight>0)
331 lpMeasureItemStruct->itemHeight = 50;
335 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
337 PreSubclassWindow();
338 return CHintListCtrl::OnCreate(lpCreateStruct);
341 void CGitLogListBase::PreSubclassWindow()
343 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
344 // load the icons for the action columns
345 // m_Theme.Open(m_hWnd, L"ListView");
346 SetWindowTheme(m_hWnd, L"Explorer", NULL);
347 CHintListCtrl::PreSubclassWindow();
350 CString CGitLogListBase::GetRebaseActionName(int action)
352 if (action & LOGACTIONS_REBASE_EDIT)
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
354 if (action & LOGACTIONS_REBASE_SQUASH)
355 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
356 if (action & LOGACTIONS_REBASE_PICK)
357 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
358 if (action & LOGACTIONS_REBASE_SKIP)
359 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
361 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
364 void CGitLogListBase::InsertGitColumn()
366 CString temp;
368 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
369 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
370 if (DWORD(regFullRowSelect))
371 exStyle |= LVS_EX_FULLROWSELECT;
372 SetExtendedStyle(exStyle);
374 // only load properties if we have a repository
375 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
376 UpdateProjectProperties();
378 static UINT normal[] =
380 IDS_LOG_GRAPH,
381 IDS_LOG_REBASE,
382 IDS_LOG_ID,
383 IDS_LOG_HASH,
384 IDS_LOG_ACTIONS,
385 IDS_LOG_MESSAGE,
386 IDS_LOG_AUTHOR,
387 IDS_LOG_DATE,
388 IDS_LOG_EMAIL,
389 IDS_LOG_COMMIT_NAME,
390 IDS_LOG_COMMIT_EMAIL,
391 IDS_LOG_COMMIT_DATE,
392 IDS_LOG_BUGIDS,
393 IDS_LOG_SVNREV,
396 static int with[] =
398 ICONITEMBORDER+16*4,
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 ICONITEMBORDER+16*4,
402 ICONITEMBORDER+16*4,
403 LOGLIST_MESSAGE_MIN,
404 ICONITEMBORDER+16*4,
405 ICONITEMBORDER+16*4,
406 ICONITEMBORDER+16*4,
407 ICONITEMBORDER+16*4,
408 ICONITEMBORDER+16*4,
409 ICONITEMBORDER+16*4,
410 ICONITEMBORDER+16*4,
411 ICONITEMBORDER+16*4,
413 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
415 DWORD hideColumns = 0;
416 if(this->m_IsRebaseReplaceGraph)
418 hideColumns |= GIT_LOG_GRAPH;
419 m_dwDefaultColumns |= GIT_LOG_REBASE;
421 else
423 hideColumns |= GIT_LOG_REBASE;
426 if(this->m_IsIDReplaceAction)
428 hideColumns |= GIT_LOG_ACTIONS;
429 m_dwDefaultColumns |= GIT_LOG_ID;
430 m_dwDefaultColumns |= GIT_LOG_HASH;
432 else
434 hideColumns |= GIT_LOG_ID;
436 if(this->m_bShowBugtraqColumn)
438 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
440 else
442 hideColumns |= GIT_LOGLIST_BUG;
444 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
445 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
446 else
447 hideColumns |= GIT_LOGLIST_SVNREV;
448 SetRedraw(false);
450 m_ColumnManager.SetNames(normal, _countof(normal));
451 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
453 SetRedraw(true);
457 * Resizes all columns in a list control to values in registry.
459 void CGitLogListBase::ResizeAllListCtrlCols()
461 // column max and min widths to allow
462 static const int nMinimumWidth = 10;
463 static const int nMaximumWidth = 1000;
464 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
465 if (pHdrCtrl)
467 int numcols = pHdrCtrl->GetItemCount();
468 for (int col = 0; col < numcols; ++col)
470 // get width for this col last time from registry
471 CString regentry;
472 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
473 CRegDWORD regwidth(regentry, 0);
474 int cx = regwidth;
475 if ( cx == 0 )
477 // no saved value, setup sensible defaults
478 if (col == this->LOGLIST_MESSAGE)
480 cx = LOGLIST_MESSAGE_MIN;
482 else
484 cx = ICONITEMBORDER+16*4;
487 if (cx < nMinimumWidth)
489 cx = nMinimumWidth;
491 else if (cx > nMaximumWidth)
493 cx = nMaximumWidth;
496 SetColumnWidth(col, cx);
503 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
505 LVITEM rItem;
506 SecureZeroMemory(&rItem, sizeof(LVITEM));
507 rItem.mask = LVIF_STATE;
508 rItem.iItem = (int)Index;
509 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
510 GetItem(&rItem);
512 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
513 HBRUSH brush = NULL;
515 if (!(rItem.state & LVIS_SELECTED))
517 int action = pLogEntry->GetRebaseAction();
518 if (action & LOGACTIONS_REBASE_SQUASH)
519 brush = ::CreateSolidBrush(RGB(156,156,156));
520 else if (action & LOGACTIONS_REBASE_EDIT)
521 brush = ::CreateSolidBrush(RGB(200,200,128));
523 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
525 if (rItem.state & LVIS_SELECTED)
527 if (::GetFocus() == m_hWnd)
528 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
529 else
530 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
533 if (brush != NULL)
535 ::FillRect(hdc, &rect, brush);
536 ::DeleteObject(brush);
540 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
542 POINT point = { 4, 4 };
543 CRect rt2 = rect;
544 rt2.DeflateRect(1, 1);
545 rt2.OffsetRect(2, 2);
547 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
548 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
549 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
550 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
551 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
553 ::SelectObject(hdc, brush);
554 rt2.OffsetRect(-2, -2);
555 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
556 ::SelectObject(hdc, oldbrush);
557 ::SelectObject(hdc, oldpen);
558 ::DeleteObject(nullPen);
559 ::DeleteObject(darkBrush);
562 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
564 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
565 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
566 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
567 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
568 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
569 ::LineTo(hdc, rect.left, rect.bottom);
570 ::SelectObject(hdc, oldpen);
571 ::DeleteObject(pen);
574 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
576 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
577 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
578 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
579 ::LineTo(hdc, rect.left, rect.bottom);
580 ::LineTo(hdc, rect.right, rect.bottom);
581 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
582 ::SelectObject(hdc, oldpen);
583 ::DeleteObject(pen);
586 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
588 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
589 CRect rt=rect;
590 LVITEM rItem;
591 SecureZeroMemory(&rItem, sizeof(LVITEM));
592 rItem.mask = LVIF_STATE;
593 rItem.iItem = (int)index;
594 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
595 GetItem(&rItem);
597 CDC W_Dc;
598 W_Dc.Attach(hdc);
600 HTHEME hTheme = NULL;
601 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
602 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
604 SIZE oneSpaceSize;
605 if (m_bTagsBranchesOnRightSide)
607 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
608 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
609 SelectObject(hdc, oldFont);
610 rt.left += oneSpaceSize.cx * 2;
612 else
614 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
615 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
616 rt.left += oneSpaceSize.cx;
619 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
621 int txtState = LISS_NORMAL;
622 if (rItem.state & LVIS_SELECTED)
623 txtState = LISS_SELECTED;
625 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
627 else
629 if (rItem.state & LVIS_SELECTED)
631 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
632 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
633 ::SetTextColor(hdc, clrOld);
635 else
637 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
641 if (m_bTagsBranchesOnRightSide)
643 SIZE size;
644 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
646 rt.left += oneSpaceSize.cx + size.cx;
648 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
651 if (hTheme)
652 CloseThemeData(hTheme);
654 W_Dc.Detach();
657 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
659 for (unsigned int i = 0; i < refList.size(); ++i)
661 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
662 HBRUSH brush = 0;
663 COLORREF colRef = refList[i].color;
664 bool singleRemote = refList[i].singleRemote;
665 bool hasTracking = refList[i].hasTracking;
666 bool sameName = refList[i].sameName;
667 bool annotatedTag = refList[i].annotatedTag;
669 //When row selected, ajust label color
670 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
672 if (rItem.state & LVIS_SELECTED)
673 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
676 brush = ::CreateSolidBrush(colRef);
678 if (!shortname.IsEmpty() && (rt.left < rect.right))
680 SIZE size;
681 memset(&size,0,sizeof(SIZE));
682 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
684 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
685 rt.right += 8;
687 int textpos = DT_CENTER;
689 if (rt.right > rect.right)
691 rt.right = rect.right;
692 textpos = 0;
695 CRect textRect = rt;
697 if (singleRemote)
699 rt.right += 8;
700 textRect.OffsetRect(8, 0);
703 if (sameName)
704 rt.right += 8;
706 if (hasTracking)
708 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
710 else
712 //Fill interior of ref label
713 ::FillRect(hdc, &rt, brush);
716 //Draw edge of label
717 CRect rectEdge = rt;
719 if (!hasTracking)
721 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
722 rectEdge.DeflateRect(1, 1);
723 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
726 if (annotatedTag)
728 rt.right += 8;
729 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
730 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
731 ::FillRgn(hdc, hrgn, brush);
732 ::DeleteObject(hrgn);
733 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
734 HPEN pen;
735 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
736 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
737 ::DeleteObject(pen);
738 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
739 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
740 ::DeleteObject(pen);
741 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
742 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
743 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
744 ::DeleteObject(pen);
745 SelectObject(hdc, oldpen);
748 //Draw text inside label
749 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
750 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
752 int txtState = LISS_NORMAL;
753 if (rItem.state & LVIS_SELECTED)
754 txtState = LISS_SELECTED;
756 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
758 else
760 W_Dc.SetBkMode(TRANSPARENT);
761 if (customColor || (rItem.state & LVIS_SELECTED))
763 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
764 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
765 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
766 ::SetTextColor(hdc,clrOld);
768 else
770 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
774 if (singleRemote)
776 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
777 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
778 CRect newRect;
779 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
780 DrawLightning(hdc, newRect, color, bold);
783 if (sameName)
785 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
786 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
787 CRect newRect;
788 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
789 DrawUpTriangle(hdc, newRect, color, bold);
792 rt.left = rt.right + 1;
794 if (brush)
795 ::DeleteObject(brush);
797 rt.right = rect.right;
800 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
802 // Returns ((256 - amount)*col1 + amount*col2) / 256;
803 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
804 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
805 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
808 Gdiplus::Color GetGdiColor(COLORREF col)
810 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
812 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
813 const COLORREF& col,const COLORREF& activeColor, int top
816 int h = laneHeight / 2;
817 int m = (x1 + x2) / 2;
818 int r = (x2 - x1) * m_NodeSize / 30;
819 int d = 2 * r;
821 #define P_CENTER m , h+top
822 #define P_0 x2, h+top
823 #define P_90 m , 0+top-1
824 #define P_180 x1, h+top
825 #define P_270 m , 2 * h+top +1
826 #define R_CENTER m - r, h - r+top, d, d
829 #define DELTA_UR_B 2*(x1 - m), 2*h +top
830 #define DELTA_UR_E 0*16, 90*16 +top // -,
832 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
833 #define DELTA_DR_E 270*16, 90*16 +top // -'
835 #define DELTA_UL_B 2*(x2 - m), 2*h +top
836 #define DELTA_UL_E 90*16, 90*16 +top // ,-
838 #define DELTA_DL_B 2*(x2 - m),2*-h +top
839 #define DELTA_DL_E 180*16, 90*16 // '-
841 #define CENTER_UR x1, 2*h, 225
842 #define CENTER_DR x1, 0 , 135
843 #define CENTER_UL x2, 2*h, 315
844 #define CENTER_DL x2, 0 , 45
847 Gdiplus::Graphics graphics( hdc );
849 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
851 // arc
852 switch (type) {
853 case Lanes::JOIN:
854 case Lanes::JOIN_R:
855 case Lanes::HEAD:
856 case Lanes::HEAD_R:
858 Gdiplus::LinearGradientBrush gradient(
859 Gdiplus::Point(x1-2, h+top-2),
860 Gdiplus::Point(P_270),
861 GetGdiColor(activeColor),GetGdiColor(col));
864 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
865 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
867 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
868 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
869 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
871 break;
873 case Lanes::JOIN_L:
876 Gdiplus::LinearGradientBrush gradient(
877 Gdiplus::Point(P_270),
878 Gdiplus::Point(x2+1, h+top-1),
879 GetGdiColor(col),GetGdiColor(activeColor));
882 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
883 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
885 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
886 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
887 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
890 break;
892 case Lanes::TAIL:
893 case Lanes::TAIL_R:
896 Gdiplus::LinearGradientBrush gradient(
897 Gdiplus::Point(x1-2, h+top-2),
898 Gdiplus::Point(P_90),
899 GetGdiColor(activeColor),GetGdiColor(col));
901 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
903 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
905 #if 0
906 QConicalGradient gradient(CENTER_DR);
907 gradient.setColorAt(0.375, activeCol);
908 gradient.setColorAt(0.625, col);
909 myPen.setBrush(gradient);
910 p->setPen(myPen);
911 p->drawArc(P_CENTER, DELTA_DR);
912 #endif
913 break;
915 default:
916 break;
920 //static QPen myPen(Qt::black, 2); // fast path here
921 CPen pen;
922 pen.CreatePen(PS_SOLID,2,col);
923 //myPen.setColor(col);
924 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
926 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
928 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
930 //p->setPen(myPen);
932 // vertical line
933 switch (type) {
934 case Lanes::ACTIVE:
935 case Lanes::NOT_ACTIVE:
936 case Lanes::MERGE_FORK:
937 case Lanes::MERGE_FORK_R:
938 case Lanes::MERGE_FORK_L:
939 case Lanes::JOIN:
940 case Lanes::JOIN_R:
941 case Lanes::JOIN_L:
942 case Lanes::CROSS:
943 //DrawLine(hdc,P_90,P_270);
944 graphics.DrawLine(&myPen,P_90,P_270);
945 //p->drawLine(P_90, P_270);
946 break;
947 case Lanes::HEAD_L:
948 case Lanes::BRANCH:
949 //DrawLine(hdc,P_CENTER,P_270);
950 graphics.DrawLine(&myPen,P_CENTER,P_270);
951 //p->drawLine(P_CENTER, P_270);
952 break;
953 case Lanes::TAIL_L:
954 case Lanes::INITIAL:
955 case Lanes::BOUNDARY:
956 case Lanes::BOUNDARY_C:
957 case Lanes::BOUNDARY_R:
958 case Lanes::BOUNDARY_L:
959 //DrawLine(hdc,P_90, P_CENTER);
960 graphics.DrawLine(&myPen,P_90,P_CENTER);
961 //p->drawLine(P_90, P_CENTER);
962 break;
963 default:
964 break;
967 myPen.SetColor(GetGdiColor(activeColor));
969 // horizontal line
970 switch (type) {
971 case Lanes::MERGE_FORK:
972 case Lanes::JOIN:
973 case Lanes::HEAD:
974 case Lanes::TAIL:
975 case Lanes::CROSS:
976 case Lanes::CROSS_EMPTY:
977 case Lanes::BOUNDARY_C:
978 //DrawLine(hdc,P_180,P_0);
979 graphics.DrawLine(&myPen,P_180,P_0);
980 //p->drawLine(P_180, P_0);
981 break;
982 case Lanes::MERGE_FORK_R:
983 case Lanes::BOUNDARY_R:
984 //DrawLine(hdc,P_180,P_CENTER);
985 graphics.DrawLine(&myPen,P_180,P_CENTER);
986 //p->drawLine(P_180, P_CENTER);
987 break;
988 case Lanes::MERGE_FORK_L:
989 case Lanes::HEAD_L:
990 case Lanes::TAIL_L:
991 case Lanes::BOUNDARY_L:
992 //DrawLine(hdc,P_CENTER,P_0);
993 graphics.DrawLine(&myPen,P_CENTER,P_0);
994 //p->drawLine(P_CENTER, P_0);
995 break;
996 default:
997 break;
1000 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1002 CBrush brush;
1003 brush.CreateSolidBrush(col);
1004 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1006 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1007 // center symbol, e.g. rect or ellipse
1008 switch (type) {
1009 case Lanes::ACTIVE:
1010 case Lanes::INITIAL:
1011 case Lanes::BRANCH:
1013 //p->setPen(Qt::NoPen);
1014 //p->setBrush(col);
1015 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1016 graphics.FillEllipse(&myBrush, R_CENTER);
1017 //p->drawEllipse(R_CENTER);
1018 break;
1019 case Lanes::MERGE_FORK:
1020 case Lanes::MERGE_FORK_R:
1021 case Lanes::MERGE_FORK_L:
1022 //p->setPen(Qt::NoPen);
1023 //p->setBrush(col);
1024 //p->drawRect(R_CENTER);
1025 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1026 graphics.FillRectangle(&myBrush, R_CENTER);
1027 break;
1028 case Lanes::UNAPPLIED:
1029 // Red minus sign
1030 //p->setPen(Qt::NoPen);
1031 //p->setBrush(Qt::red);
1032 //p->drawRect(m - r, h - 1, d, 2);
1033 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1034 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1035 break;
1036 case Lanes::APPLIED:
1037 // Green plus sign
1038 //p->setPen(Qt::NoPen);
1039 //p->setBrush(DARK_GREEN);
1040 //p->drawRect(m - r, h - 1, d, 2);
1041 //p->drawRect(m - 1, h - r, 2, d);
1042 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1043 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1044 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1045 break;
1046 case Lanes::BOUNDARY:
1047 //p->setBrush(back);
1048 //p->drawEllipse(R_CENTER);
1049 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1050 graphics.DrawEllipse(&myPen, R_CENTER);
1051 break;
1052 case Lanes::BOUNDARY_C:
1053 case Lanes::BOUNDARY_R:
1054 case Lanes::BOUNDARY_L:
1055 //p->setBrush(back);
1056 //p->drawRect(R_CENTER);
1057 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1058 graphics.FillRectangle(&myBrush,R_CENTER);
1059 break;
1060 default:
1061 break;
1064 ::SelectObject(hdc,oldpen);
1065 ::SelectObject(hdc,oldbrush);
1066 #undef P_CENTER
1067 #undef P_0
1068 #undef P_90
1069 #undef P_180
1070 #undef P_270
1071 #undef R_CENTER
1074 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1076 // TODO: unfinished
1077 // return;
1078 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1079 if(data->m_CommitHash.IsEmpty())
1080 return;
1082 CRect rt=rect;
1083 LVITEM rItem;
1084 SecureZeroMemory(&rItem, sizeof(LVITEM));
1085 rItem.mask = LVIF_STATE;
1086 rItem.iItem = (int)index;
1087 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1088 GetItem(&rItem);
1090 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1092 if (data->m_Lanes.empty())
1093 m_logEntries.setLane(data->m_CommitHash);
1095 std::vector<int>& lanes=data->m_Lanes;
1096 size_t laneNum = lanes.size();
1097 UINT activeLane = 0;
1098 for (UINT i = 0; i < laneNum; ++i)
1099 if (Lanes::isMerge(lanes[i])) {
1100 activeLane = i;
1101 break;
1104 int x2 = 0;
1105 int maxWidth = rect.Width();
1106 int lw = 3 * rect.Height() / 4; //laneWidth()
1108 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1109 //if (opt.state & QStyle::State_Selected)
1110 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1112 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1115 int x1 = x2;
1116 x2 += lw;
1118 int ln = lanes[i];
1119 if (ln == Lanes::EMPTY)
1120 continue;
1122 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1123 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1126 #if 0
1127 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1129 int x1 = x2;
1130 x2 += lw;
1132 int ln = lanes[i];
1133 if (ln == Lanes::EMPTY)
1134 continue;
1136 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1137 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1139 if (ln == Lanes::CROSS)
1141 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1142 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1144 else
1145 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1147 #endif
1151 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1154 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1155 // Take the default processing unless we set this to something else below.
1156 *pResult = CDRF_DODEFAULT;
1158 if (m_bNoDispUpdates)
1159 return;
1161 switch (pLVCD->nmcd.dwDrawStage)
1163 case CDDS_PREPAINT:
1165 *pResult = CDRF_NOTIFYITEMDRAW;
1166 return;
1168 break;
1169 case CDDS_ITEMPREPAINT:
1171 // This is the prepaint stage for an item. Here's where we set the
1172 // item's text color.
1174 // Tell Windows to send draw notifications for each subitem.
1175 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1177 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1179 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1181 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1182 if (data)
1184 HGDIOBJ hGdiObj = nullptr;
1185 int action = data->GetRebaseAction();
1186 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1187 crText = RGB(128,128,128);
1189 if (action & LOGACTIONS_REBASE_SQUASH)
1190 pLVCD->clrTextBk = RGB(156,156,156);
1191 else if (action & LOGACTIONS_REBASE_EDIT)
1192 pLVCD->clrTextBk = RGB(200,200,128);
1193 else
1194 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1196 if (action & LOGACTIONS_REBASE_CURRENT)
1197 hGdiObj = m_boldFont;
1199 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1200 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1201 if (isHeadHash && isHighlight)
1202 hGdiObj = m_boldItalicsFont;
1203 else if (isHeadHash)
1204 hGdiObj = m_boldFont;
1205 else if (isHighlight)
1206 hGdiObj = m_FontItalics;
1208 if (hGdiObj)
1210 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1211 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1214 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1215 // crText = GetSysColor(COLOR_GRAYTEXT);
1217 if (data->m_CommitHash.IsEmpty())
1219 //crText = GetSysColor(RGB(200,200,0));
1220 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1221 // We changed the font, so we're returning CDRF_NEWFONT. This
1222 // tells the control to recalculate the extent of the text.
1223 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1227 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1229 if (m_bStrictStopped)
1230 crText = GetSysColor(COLOR_GRAYTEXT);
1232 // Store the color back in the NMLVCUSTOMDRAW struct.
1233 pLVCD->clrText = crText;
1234 return;
1236 break;
1237 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1239 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1241 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1244 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1246 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1248 CRect rect;
1249 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1251 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1252 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1254 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1255 if( !data ->m_CommitHash.IsEmpty())
1256 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1258 *pResult = CDRF_SKIPDEFAULT;
1259 return;
1263 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1265 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1267 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1269 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1271 CRect rect;
1272 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1274 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1275 // not in FillBackGround method, because this only affected the message subitem
1276 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1277 return;
1279 int index = (int)pLVCD->nmcd.dwItemSpec;
1280 int state = GetItemState(index, LVIS_SELECTED);
1281 int txtState = LISS_NORMAL;
1282 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1284 if (state & LVIS_SELECTED)
1285 txtState = LISS_HOTSELECTED;
1286 else
1287 txtState = LISS_HOT;
1289 else if (state & LVIS_SELECTED)
1291 if (::GetFocus() == m_hWnd)
1292 txtState = LISS_SELECTED;
1293 else
1294 txtState = LISS_SELECTEDNOTFOCUS;
1297 HTHEME hTheme = nullptr;
1298 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1299 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1301 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1302 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1303 else
1305 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1306 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1307 ::DeleteObject(brush);
1309 if (hTheme)
1311 CRect rt;
1312 // get rect of whole line
1313 GetItemRect(index, rt, LVIR_BOUNDS);
1314 CRect rect2 = rect;
1315 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1316 rect2.DeflateRect(1, 1, 1, 1);
1318 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1319 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1321 CloseThemeData(hTheme);
1323 // END: extended redraw
1325 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1327 std::vector<REFLABEL> refsToShow;
1328 STRING_VECTOR remoteTrackingList;
1329 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1330 for (unsigned int i = 0; i < refList.size(); ++i)
1332 CString str = refList[i];
1334 REFLABEL refLabel;
1335 refLabel.color = RGB(255, 255, 255);
1336 refLabel.singleRemote = false;
1337 refLabel.hasTracking = false;
1338 refLabel.sameName = false;
1339 refLabel.annotatedTag = false;
1340 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1342 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1343 continue;
1344 if (refLabel.name == m_CurrentBranch )
1345 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1346 else
1347 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1349 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1350 CString pullRemote = trackingEntry.first;
1351 CString pullBranch = trackingEntry.second;
1352 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1354 CString defaultUpstream;
1355 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1356 refLabel.hasTracking = true;
1357 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1359 bool found = false;
1360 for (size_t j = i + 1; j < refList.size(); ++j)
1362 if (refList[j] == defaultUpstream)
1364 found = true;
1365 break;
1369 if (found)
1371 bool sameName = pullBranch == refLabel.name;
1372 refsToShow.push_back(refLabel);
1373 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1374 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1375 if (m_bSymbolizeRefNames)
1377 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1379 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1380 refLabel.singleRemote = true;
1382 else if (sameName)
1383 refLabel.simplifiedName = pullRemote + _T("/");
1384 refLabel.sameName = sameName;
1386 refsToShow.push_back(refLabel);
1387 remoteTrackingList.push_back(defaultUpstream);
1388 continue;
1393 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1395 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1396 continue;
1398 bool found = false;
1399 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1401 if (remoteTrackingList[j] == str)
1403 found = true;
1404 break;
1407 if (found)
1408 continue;
1410 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1411 if (m_bSymbolizeRefNames)
1413 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1415 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1416 refLabel.singleRemote = true;
1420 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1422 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1423 continue;
1424 refLabel.color = m_Colors.GetColor(CColors::Tag);
1425 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1427 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1429 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1430 continue;
1431 refLabel.color = m_Colors.GetColor(CColors::Stash);
1432 refLabel.name = _T("stash");
1434 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1436 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1437 continue;
1438 if (refLabel.name.Find(_T("good")) == 0)
1440 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1441 refLabel.name = _T("good");
1443 if (refLabel.name.Find(_T("bad")) == 0)
1445 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1446 refLabel.name = _T("bad");
1449 else
1450 continue;
1452 refsToShow.push_back(refLabel);
1455 if (refsToShow.empty())
1457 *pResult = CDRF_DODEFAULT;
1458 return;
1461 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1463 *pResult = CDRF_SKIPDEFAULT;
1464 return;
1471 if (pLVCD->iSubItem == LOGLIST_ACTION)
1473 if(this->m_IsIDReplaceAction)
1475 *pResult = CDRF_DODEFAULT;
1476 return;
1478 *pResult = CDRF_DODEFAULT;
1480 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1481 return;
1483 int nIcons = 0;
1484 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1485 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1487 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1488 CRect rect;
1489 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1490 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1491 // Get the selected state of the
1492 // item being drawn.
1494 // Fill the background if necessary
1495 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1497 // Draw the icon(s) into the compatible DC
1498 int action = SafeGetAction(pLogEntry);
1500 if (!pLogEntry->m_IsDiffFiles)
1501 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1503 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1504 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1505 ++nIcons;
1507 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1508 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1509 ++nIcons;
1511 if (action & CTGitPath::LOGACTIONS_DELETED)
1512 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1513 ++nIcons;
1515 if (action & CTGitPath::LOGACTIONS_REPLACED)
1516 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1517 ++nIcons;
1518 *pResult = CDRF_SKIPDEFAULT;
1519 return;
1522 break;
1524 *pResult = CDRF_DODEFAULT;
1527 CString FindSVNRev(const CString& msg)
1531 const std::tr1::wsregex_iterator end;
1532 std::wstring s = msg;
1533 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)
1535 const std::tr1::wsmatch match = *it;
1536 if (match.size() == 4)
1538 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1539 return std::wstring(match[2]).c_str();
1542 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)
1544 const std::tr1::wsmatch match = *it;
1545 if (match.size() == 3)
1547 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1548 return std::wstring(match[1]).c_str();
1552 catch (std::exception) {}
1554 return _T("");
1557 // CGitLogListBase message handlers
1559 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1561 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1563 // Create a pointer to the item
1564 LV_ITEM* pItem = &(pDispInfo)->item;
1566 // Do the list need text information?
1567 if (!(pItem->mask & LVIF_TEXT))
1568 return;
1570 // By default, clear text buffer.
1571 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1573 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1575 *pResult = 0;
1576 if (m_bNoDispUpdates || bOutOfRange)
1577 return;
1579 // Which item number?
1580 int itemid = pItem->iItem;
1581 GitRev * pLogEntry = NULL;
1582 if (itemid < m_arShownList.GetCount())
1583 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1585 CString temp;
1586 if(m_IsOldFirst)
1588 temp.Format(_T("%d"),pItem->iItem+1);
1591 else
1593 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1596 // Which column?
1597 switch (pItem->iSubItem)
1599 case this->LOGLIST_GRAPH: //Graphic
1600 break;
1601 case this->LOGLIST_REBASE:
1603 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1604 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1606 break;
1607 case this->LOGLIST_ACTION: //action -- no text in the column
1608 break;
1609 case this->LOGLIST_HASH:
1610 if(pLogEntry)
1611 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1612 break;
1613 case this->LOGLIST_ID:
1614 if(this->m_IsIDReplaceAction)
1615 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1616 break;
1617 case this->LOGLIST_MESSAGE: //Message
1618 if (pLogEntry)
1619 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1620 break;
1621 case this->LOGLIST_AUTHOR: //Author
1622 if (pLogEntry)
1623 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1624 break;
1625 case this->LOGLIST_DATE: //Date
1626 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1627 lstrcpyn(pItem->pszText,
1628 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1629 pItem->cchTextMax);
1630 break;
1632 case this->LOGLIST_EMAIL:
1633 if (pLogEntry)
1634 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1635 break;
1637 case this->LOGLIST_COMMIT_NAME: //Commit
1638 if (pLogEntry)
1639 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1640 break;
1642 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1643 if (pLogEntry)
1644 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1645 break;
1647 case this->LOGLIST_COMMIT_DATE: //Commit Date
1648 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1649 lstrcpyn(pItem->pszText,
1650 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1651 pItem->cchTextMax);
1652 break;
1653 case this->LOGLIST_BUG: //Bug ID
1654 if(pLogEntry)
1655 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1656 break;
1657 case this->LOGLIST_SVNREV: //SVN revision
1658 if (pLogEntry)
1659 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1660 break;
1662 default:
1663 ASSERT(false);
1667 bool CGitLogListBase::IsOnStash(int index)
1669 GitRev *rev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index));
1670 if (IsStash(rev))
1671 return true;
1672 if (index > 0)
1674 GitRev *preRev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1));
1675 if (IsStash(preRev))
1676 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1678 return false;
1681 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1683 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1685 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1686 return true;
1688 return false;
1691 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1693 if (pRev->m_ParentHash.empty())
1697 pRev->GetParentFromHash(pRev->m_CommitHash);
1699 catch (const char* msg)
1701 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1704 parentHash = pRev->m_ParentHash;
1707 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1710 if (pWnd == GetHeaderCtrl())
1712 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1715 int selIndex = GetSelectionMark();
1716 if (selIndex < 0)
1717 return; // nothing selected, nothing to do with a context menu
1719 // if the user selected the info text telling about not all revisions shown due to
1720 // the "stop on copy/rename" option, we also don't show the context menu
1721 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1722 return;
1724 // if the context menu is invoked through the keyboard, we have to use
1725 // a calculated position on where to anchor the menu on
1726 if ((point.x == -1) && (point.y == -1))
1728 CRect rect;
1729 GetItemRect(selIndex, &rect, LVIR_LABEL);
1730 ClientToScreen(&rect);
1731 point = rect.CenterPoint();
1733 m_nSearchIndex = selIndex;
1734 m_bCancelled = FALSE;
1736 // calculate some information the context menu commands can use
1737 // CString pathURL = GetURLFromPath(m_path);
1739 POSITION pos = GetFirstSelectedItemPosition();
1740 int indexNext = GetNextSelectedItem(pos);
1741 if (indexNext < 0)
1742 return;
1744 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1745 if (pSelLogEntry == nullptr)
1746 return;
1747 #if 0
1748 GitRev revSelected = pSelLogEntry->Rev;
1749 GitRev revPrevious = git_revnum_t(revSelected)-1;
1750 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1752 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1754 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1755 if (changedpath->lCopyFromRev)
1756 revPrevious = changedpath->lCopyFromRev;
1759 GitRev revSelected2;
1760 if (pos)
1762 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1763 revSelected2 = pLogEntry->Rev;
1765 bool bAllFromTheSameAuthor = true;
1766 CString firstAuthor;
1767 CLogDataVector selEntries;
1768 GitRev revLowest, revHighest;
1769 GitRevRangeArray revisionRanges;
1771 POSITION pos = GetFirstSelectedItemPosition();
1772 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1773 revisionRanges.AddRevision(pLogEntry->Rev);
1774 selEntries.push_back(pLogEntry);
1775 firstAuthor = pLogEntry->sAuthor;
1776 revLowest = pLogEntry->Rev;
1777 revHighest = pLogEntry->Rev;
1778 while (pos)
1780 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1781 revisionRanges.AddRevision(pLogEntry->Rev);
1782 selEntries.push_back(pLogEntry);
1783 if (firstAuthor.Compare(pLogEntry->sAuthor))
1784 bAllFromTheSameAuthor = false;
1785 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1786 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1790 #endif
1792 int FirstSelect=-1, LastSelect=-1;
1793 pos = GetFirstSelectedItemPosition();
1794 FirstSelect = GetNextSelectedItem(pos);
1795 while(pos)
1797 LastSelect = GetNextSelectedItem(pos);
1799 //entry is selected, now show the popup menu
1800 CIconMenu popup;
1801 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1803 if (popup.CreatePopupMenu())
1805 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1806 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1807 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1808 bool isStash = IsOnStash(indexNext);
1809 GIT_REV_LIST parentHash;
1810 GetParentHashes(pSelLogEntry, parentHash);
1812 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1813 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1815 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1816 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1818 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1819 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1821 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1822 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1824 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)))
1825 popup.AppendMenu(MF_SEPARATOR, NULL);
1827 if (GetSelectedCount() == 1)
1830 bool requiresSeparator = false;
1831 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1833 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1835 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1836 requiresSeparator = true;
1839 else
1841 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1843 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1844 requiresSeparator = true;
1846 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1848 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1849 requiresSeparator = true;
1853 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1855 if (parentHash.size() == 1)
1857 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1858 requiresSeparator = true;
1860 else if (parentHash.size() > 1)
1862 blamemenu.CreatePopupMenu();
1863 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1864 for (size_t i = 0; i < parentHash.size(); ++i)
1866 CString str;
1867 str.Format(IDS_PARENT, i + 1);
1868 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1870 requiresSeparator = true;
1874 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1876 if (parentHash.size() == 1)
1878 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1879 requiresSeparator = true;
1881 else if (parentHash.size() > 1)
1883 gnudiffmenu.CreatePopupMenu();
1884 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1886 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1887 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1889 for (size_t i = 0; i < parentHash.size(); ++i)
1891 CString str;
1892 str.Format(IDS_PARENT, i + 1);
1893 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1895 requiresSeparator = true;
1899 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1901 if (parentHash.size() == 1)
1903 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1904 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1905 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1906 requiresSeparator = true;
1908 else if (parentHash.size() > 1)
1910 diffmenu.CreatePopupMenu();
1911 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1912 for (size_t i = 0; i < parentHash.size(); ++i)
1914 CString str;
1915 str.Format(IDS_PARENT, i + 1);
1916 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1917 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1919 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1920 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1923 requiresSeparator = true;
1927 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1929 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1930 requiresSeparator = true;
1933 if (requiresSeparator)
1934 popup.AppendMenu(MF_SEPARATOR, NULL);
1936 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1938 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1939 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1942 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1944 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1945 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1947 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1948 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1950 popup.AppendMenu(MF_SEPARATOR, NULL);
1953 if (pSelLogEntry->m_CommitHash.IsEmpty())
1955 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1956 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1958 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1959 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1961 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1962 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1964 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1965 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1967 popup.AppendMenu(MF_SEPARATOR, NULL);
1971 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1972 // {
1973 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1974 // }
1975 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1976 // {
1977 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1978 // }
1979 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1980 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1981 // {
1982 // popup.AppendMenu(MF_SEPARATOR, NULL);
1983 // }
1985 CString str,format;
1986 //if (m_hasWC)
1987 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1989 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1991 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1992 GetSelectedCount() == 1)
1993 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1995 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1996 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1998 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1999 str.Format(format,g_Git.GetCurrentBranch());
2001 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2002 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2004 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2005 str.Format(format,g_Git.GetCurrentBranch());
2007 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2008 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2011 // Add Switch Branch express Menu
2012 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2013 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2016 std::vector<CString *> branchs;
2017 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2019 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2020 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2022 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2026 CString str;
2027 str.LoadString(IDS_SWITCH_BRANCH);
2029 if(branchs.size() == 1)
2031 str+=_T(" ");
2032 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
2033 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
2035 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2038 else if(branchs.size() > 1)
2040 subbranchmenu.CreatePopupMenu();
2041 for (size_t i = 0 ; i < branchs.size(); ++i)
2043 if (*branchs[i] != currentBranch)
2045 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2046 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2050 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2054 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2055 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2057 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2058 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2060 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2061 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2063 format.LoadString(IDS_REBASE_THIS_FORMAT);
2064 str.Format(format,g_Git.GetCurrentBranch());
2066 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2067 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2068 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2070 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2071 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2073 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2075 if (parentHash.size() == 1)
2077 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2079 else if (parentHash.size() > 1)
2081 revertmenu.CreatePopupMenu();
2082 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2084 for (size_t i = 0; i < parentHash.size(); ++i)
2086 CString str;
2087 str.Format(IDS_PARENT, i + 1);
2088 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2093 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2094 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2096 popup.AppendMenu(MF_SEPARATOR, NULL);
2101 if(!pSelLogEntry->m_Ref.IsEmpty())
2103 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2104 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2105 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2106 popup.AppendMenu(MF_SEPARATOR, NULL);
2109 if (GetSelectedCount() >= 2)
2111 bool bAddSeparator = false;
2112 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2114 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2115 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2118 if (GetSelectedCount() == 2)
2120 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2121 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2123 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2125 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2126 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2127 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2128 CString menu;
2129 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2130 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2131 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2132 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2135 bAddSeparator = true;
2138 if (m_hasWC)
2140 bAddSeparator = true;
2143 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2144 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2146 if (bAddSeparator)
2147 popup.AppendMenu(MF_SEPARATOR, NULL);
2150 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2152 bool bAddSeparator = false;
2153 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2155 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2157 CString head;
2158 int headindex;
2159 headindex = this->GetHeadIndex();
2160 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2162 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2163 CGitHash hashFirst;
2164 if (g_Git.GetHash(hashFirst, head))
2165 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2166 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2167 CGitHash hash;
2168 if (g_Git.GetHash(hash, head))
2169 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2170 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect));
2171 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2172 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2173 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2174 bAddSeparator = true;
2179 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2180 if (GetSelectedCount() >= 2)
2181 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2182 else
2183 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2184 bAddSeparator = true;
2187 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2188 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2189 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2190 bAddSeparator = true;
2193 if (bAddSeparator)
2194 popup.AppendMenu(MF_SEPARATOR, NULL);
2197 if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2199 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2200 popup.AppendMenu(MF_SEPARATOR, NULL);
2203 if (GetSelectedCount() == 1)
2205 bool bAddSeparator = false;
2206 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2208 // show the push-option only if the log entry has an associated local branch
2209 bool isLocal = false;
2210 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2212 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2213 isLocal = true;
2215 if (isLocal)
2217 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2218 bAddSeparator = true;
2221 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2223 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2224 bAddSeparator = true;
2228 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2230 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2232 std::vector<CString *> branchs;
2233 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2235 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2236 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2238 CString str;
2239 if (branchs.size() == 1)
2241 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2242 str+=_T(" ");
2243 str += *branchs[0];
2244 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2245 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2246 bAddSeparator = true;
2248 else if (branchs.size() > 1)
2250 str.LoadString(IDS_DELETE_BRANCHTAG);
2251 submenu.CreatePopupMenu();
2252 for (size_t i = 0; i < branchs.size(); ++i)
2254 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2255 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2258 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2259 bAddSeparator = true;
2262 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2263 if (bAddSeparator)
2264 popup.AppendMenu(MF_SEPARATOR, NULL);
2265 } // GetSelectedCount() == 1
2267 if (GetSelectedCount() != 0)
2269 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2270 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2271 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2272 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2273 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2274 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2277 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2278 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2280 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2281 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2283 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2284 // DialogEnableWindow(IDOK, FALSE);
2285 // SetPromptApp(&theApp);
2287 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2289 // EnableOKButton();
2290 } // if (popup.CreatePopupMenu())
2294 bool CGitLogListBase::IsSelectionContinuous()
2296 if ( GetSelectedCount()==1 )
2298 // if only one revision is selected, the selection is of course
2299 // continuous
2300 return true;
2303 POSITION pos = GetFirstSelectedItemPosition();
2304 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2305 if (bContinuous)
2307 int itemindex = GetNextSelectedItem(pos);
2308 while (pos)
2310 int nextindex = GetNextSelectedItem(pos);
2311 if (nextindex - itemindex > 1)
2313 bContinuous = false;
2314 break;
2316 itemindex = nextindex;
2319 return bContinuous;
2322 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2325 CString sClipdata;
2326 POSITION pos = GetFirstSelectedItemPosition();
2327 if (pos != NULL)
2329 CString sRev;
2330 sRev.LoadString(IDS_LOG_REVISION);
2331 CString sAuthor;
2332 sAuthor.LoadString(IDS_LOG_AUTHOR);
2333 CString sDate;
2334 sDate.LoadString(IDS_LOG_DATE);
2335 CString sMessage;
2336 sMessage.LoadString(IDS_LOG_MESSAGE);
2337 bool first = true;
2338 while (pos)
2340 CString sLogCopyText;
2341 CString sPaths;
2342 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2344 if (toCopy == ID_COPY_ALL)
2346 //pLogEntry->GetFiles(this)
2347 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2349 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2350 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2352 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2353 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2355 CString rename;
2356 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2357 sPaths += _T(" ") + rename;
2359 sPaths += _T("\r\n");
2361 sPaths.Trim();
2362 CString body = pLogEntry->GetBody();
2363 body.Replace(_T("\n"), _T("\r\n"));
2364 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"),
2365 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2366 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2367 (LPCTSTR)sDate,
2368 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2369 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2370 (LPCTSTR)sPaths);
2371 sClipdata += sLogCopyText;
2373 else if (toCopy == ID_COPY_MESSAGE)
2375 CString body = pLogEntry->GetBody();
2376 body.Replace(_T("\n"), _T("\r\n"));
2377 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2379 else if (toCopy == ID_COPY_SUBJECT)
2381 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2383 else
2385 if (!first)
2386 sClipdata += _T("\r\n");
2387 sClipdata += pLogEntry->m_CommitHash;
2390 first = false;
2392 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2397 void CGitLogListBase::DiffSelectedRevWithPrevious()
2399 if (m_bThreadRunning)
2400 return;
2402 int FirstSelect=-1, LastSelect=-1;
2403 POSITION pos = GetFirstSelectedItemPosition();
2404 FirstSelect = GetNextSelectedItem(pos);
2405 while(pos)
2407 LastSelect = GetNextSelectedItem(pos);
2410 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2412 #if 0
2413 UpdateLogInfoLabel();
2414 int selIndex = m_LogList.GetSelectionMark();
2415 if (selIndex < 0)
2416 return;
2417 int selCount = m_LogList.GetSelectedCount();
2418 if (selCount != 1)
2419 return;
2421 // Find selected entry in the log list
2422 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2423 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2424 long rev1 = pLogEntry->Rev;
2425 long rev2 = rev1-1;
2426 CTGitPath path = m_path;
2428 // See how many files under the relative root were changed in selected revision
2429 int nChanged = 0;
2430 LogChangedPath * changed = NULL;
2431 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2433 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2434 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2436 ++nChanged;
2437 changed = cpath;
2441 if (m_path.IsDirectory() && nChanged == 1)
2443 // We're looking at the log for a directory and only one file under dir was changed in the revision
2444 // Do diff on that file instead of whole directory
2445 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2448 m_bCancelled = FALSE;
2449 DialogEnableWindow(IDOK, FALSE);
2450 SetPromptApp(&theApp);
2451 theApp.DoWaitCursor(1);
2453 if (PromptShown())
2455 GitDiff diff(this, m_hWnd, true);
2456 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2457 diff.SetHEADPeg(m_LogRevision);
2458 diff.ShowCompare(path, rev2, path, rev1);
2460 else
2462 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2465 theApp.DoWaitCursor(-1);
2466 EnableOKButton();
2467 #endif
2470 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2472 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2473 *pResult = -1;
2475 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2476 return;
2477 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2478 return;
2479 if (pFindInfo->lvfi.psz == 0)
2480 return;
2481 #if 0
2482 CString sCmp = pFindInfo->lvfi.psz;
2483 CString sRev;
2484 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2486 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2487 sRev.Format(_T("%ld"), pLogEntry->Rev);
2488 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2490 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2492 *pResult = i;
2493 return;
2496 else
2498 if (sCmp.Compare(sRev)==0)
2500 *pResult = i;
2501 return;
2505 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2507 for (int i=0; i<pFindInfo->iStart; ++i)
2509 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2510 sRev.Format(_T("%ld"), pLogEntry->Rev);
2511 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2513 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2515 *pResult = i;
2516 return;
2519 else
2521 if (sCmp.Compare(sRev)==0)
2523 *pResult = i;
2524 return;
2529 #endif
2530 *pResult = -1;
2533 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2535 ClearText();
2537 this->m_arShownList.SafeRemoveAll();
2539 this->m_logEntries.ClearAll();
2540 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2541 return -1;
2543 //this->m_logEntries.ParserFromLog();
2544 SetItemCountEx((int)m_logEntries.size());
2546 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2548 if(m_IsOldFirst)
2550 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2551 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2554 else
2556 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2557 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2561 ReloadHashMap();
2563 if(path)
2564 m_Path=*path;
2565 return 0;
2569 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2571 ClearText();
2573 m_arShownList.SafeRemoveAll();
2575 m_logEntries.ClearAll();
2576 if (m_logEntries.Fill(hashes))
2577 return -1;
2579 SetItemCountEx((int)m_logEntries.size());
2581 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2583 if (m_IsOldFirst)
2585 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2586 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2588 else
2590 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2591 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2595 ReloadHashMap();
2597 return 0;
2600 int CGitLogListBase::BeginFetchLog()
2602 ClearText();
2604 this->m_arShownList.SafeRemoveAll();
2606 this->m_logEntries.ClearAll();
2608 this->m_LogCache.ClearAllParent();
2610 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2612 CTGitPath *path;
2613 if(this->m_Path.IsEmpty())
2614 path=NULL;
2615 else
2616 path=&this->m_Path;
2618 int mask;
2619 mask = CGit::LOG_INFO_ONLY_HASH;
2620 if (m_bIncludeBoundaryCommits)
2621 mask |= CGit::LOG_INFO_BOUNDARY;
2622 // if(this->m_bAllBranch)
2623 mask |= m_ShowMask ;
2625 if(m_bShowWC)
2627 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2628 ResetWcRev();
2629 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2632 if (m_sRange.IsEmpty())
2633 m_sRange = _T("HEAD");
2635 CFilterData data;
2636 data.m_From = m_From;
2637 data.m_To =m_To;
2639 #if 0 /* use tortoiegit filter */
2640 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2641 data.m_Author = this->m_sFilterText;
2643 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2644 data.m_MessageFilter = this->m_sFilterText;
2646 data.m_IsRegex = m_bFilterWithRegex;
2647 #endif
2649 // follow does not work for directories
2650 if (!path || path->IsDirectory())
2651 mask &= ~CGit::LOG_INFO_FOLLOW;
2652 // follow does not work with all branches 8at least in TGit)
2653 if (mask & CGit::LOG_INFO_FOLLOW)
2654 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2656 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2658 //this->m_logEntries.ParserFromLog();
2659 if(IsInWorkingThread())
2661 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2663 else
2665 SetItemCountEx((int)m_logEntries.size());
2670 [] { git_init(); } ();
2672 catch (char* msg)
2674 CString err(msg);
2675 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2676 return -1;
2679 if (!g_Git.CanParseRev(m_sRange))
2681 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2682 return 0;
2684 // if show all branches, pick any ref as dummy entry ref
2685 STRING_VECTOR list;
2686 if (g_Git.GetRefList(list))
2687 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2688 if (list.size() == 0)
2689 return 0;
2691 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2694 g_Git.m_critGitDllSec.Lock();
2695 try {
2696 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2698 g_Git.m_critGitDllSec.Unlock();
2699 return -1;
2702 catch (char* msg)
2704 g_Git.m_critGitDllSec.Unlock();
2705 CString err(msg);
2706 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2707 return -1;
2709 g_Git.m_critGitDllSec.Unlock();
2711 return 0;
2714 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2716 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2718 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2720 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2722 DiffSelectedRevWithPrevious();
2723 return TRUE;
2726 #if 0
2727 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2729 DiffSelectedFile();
2730 return TRUE;
2732 #endif
2734 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2736 // select all entries
2737 for (int i=0; i<GetItemCount(); ++i)
2739 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2741 return TRUE;
2744 #if 0
2745 if (m_hAccel && !bSkipAccelerator)
2747 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2748 if (ret)
2749 return TRUE;
2752 #endif
2753 //m_tooltips.RelayEvent(pMsg);
2754 return __super::PreTranslateMessage(pMsg);
2757 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2759 // a double click on an entry in the revision list has happened
2760 *pResult = 0;
2762 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2763 DiffSelectedRevWithPrevious();
2766 int CGitLogListBase::FetchLogAsync(void * data)
2768 ReloadHashMap();
2769 m_ProcData=data;
2770 m_bExitThread=FALSE;
2771 InterlockedExchange(&m_bThreadRunning, TRUE);
2772 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2773 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2774 if (m_LoadingThread ==NULL)
2776 InterlockedExchange(&m_bThreadRunning, FALSE);
2777 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2778 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2779 return -1;
2781 return 0;
2784 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2786 return ((CGitLogListBase*)pVoid)->LogThread();
2789 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2791 //CTime time;
2792 oldest=CTime::GetCurrentTime();
2793 latest=CTime(1971,1,2,0,0,0);
2794 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2796 if(m_logEntries[i].IsEmpty())
2797 continue;
2799 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2800 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2802 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2803 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2807 if(latest<oldest)
2808 latest=oldest;
2811 UINT CGitLogListBase::LogThread()
2813 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2815 InterlockedExchange(&m_bThreadRunning, TRUE);
2816 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2818 ULONGLONG t1,t2;
2820 if(BeginFetchLog())
2822 InterlockedExchange(&m_bThreadRunning, FALSE);
2823 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2825 return 1;
2828 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2829 bool bRegex = false;
2830 if (m_bFilterWithRegex)
2831 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2833 TRACE(_T("\n===Begin===\n"));
2834 //Update work copy item;
2836 if (!m_logEntries.empty())
2838 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2840 m_arShownList.SafeAdd(pRev);
2844 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2846 // store commit number of the last selected commit/line before the refresh or -1
2847 int lastSelectedHashNItem = -1;
2848 int ret = 0;
2850 bool shouldWalk = true;
2851 if (!g_Git.CanParseRev(m_sRange))
2853 // walk revisions if show all branches and there exists any ref
2854 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2855 shouldWalk = false;
2856 else
2858 STRING_VECTOR list;
2859 if (g_Git.GetRefList(list))
2860 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2861 if (list.size() == 0)
2862 shouldWalk = false;
2866 if (shouldWalk)
2868 g_Git.m_critGitDllSec.Lock();
2869 int total = 0;
2872 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2873 total = git_get_log_estimate_commit_count(m_DllGitLog);
2875 catch (char* msg)
2877 CString err(msg);
2878 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2879 ret = -1;
2881 g_Git.m_critGitDllSec.Unlock();
2883 GIT_COMMIT commit;
2884 t2=t1=GetTickCount();
2885 int oldprecentage = 0;
2886 size_t oldsize = m_logEntries.size();
2887 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2888 while (ret== 0 && !m_bExitThread)
2890 g_Git.m_critGitDllSec.Lock();
2893 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2895 catch (char* msg)
2897 g_Git.m_critGitDllSec.Unlock();
2898 CString err(msg);
2899 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2900 break;
2902 g_Git.m_critGitDllSec.Unlock();
2904 if(ret)
2906 if (ret != -2) // other than end of revision walking
2907 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2908 break;
2911 if (commit.m_ignore == 1)
2913 git_free_commit(&commit);
2914 continue;
2917 //printf("%s\r\n",commit.GetSubject());
2918 if(m_bExitThread)
2919 break;
2921 CGitHash hash = (char*)commit.m_hash ;
2923 GitRev *pRev = m_LogCache.GetCacheData(hash);
2924 pRev->m_GitCommit = commit;
2925 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2927 char *note=NULL;
2928 g_Git.m_critGitDllSec.Lock();
2931 git_get_notes(commit.m_hash, &note);
2933 catch (char* msg)
2935 g_Git.m_critGitDllSec.Unlock();
2936 CString err(msg);
2937 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2938 break;
2940 g_Git.m_critGitDllSec.Unlock();
2942 if(note)
2944 pRev->m_Notes.Empty();
2945 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2946 free(note);
2947 note = nullptr;
2950 if(!pRev->m_IsDiffFiles)
2952 pRev->m_CallDiffAsync = DiffAsync;
2955 pRev->ParserParentFromCommit(&commit);
2956 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2958 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2960 const CGitHash &parentHash = pRev->m_ParentHash[i];
2961 auto it = commitChildren.find(parentHash);
2962 if (it == commitChildren.end())
2964 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2966 it->second.insert(pRev->m_CommitHash);
2970 #ifdef DEBUG
2971 pRev->DbgPrint();
2972 TRACE(_T("\n"));
2973 #endif
2975 bool visible = true;
2976 if (HasFilterText())
2978 if(!IsMatchFilter(bRegex,pRev,pat))
2979 visible = false;
2981 if (visible && !ShouldShowFilter(pRev, commitChildren))
2982 visible = false;
2983 this->m_critSec.Lock();
2984 m_logEntries.append(hash, visible);
2985 if (visible)
2986 m_arShownList.SafeAdd(pRev);
2987 this->m_critSec.Unlock();
2989 if (!visible)
2990 continue;
2992 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2993 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2995 t2=GetTickCount();
2997 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2999 //update UI
3000 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3001 if(percent > 99)
3002 percent =99;
3003 if(percent < GITLOG_START)
3004 percent = GITLOG_START +1;
3006 oldsize = m_logEntries.size();
3007 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3009 //if( percent > oldprecentage )
3011 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3012 oldprecentage = percent;
3015 if (lastSelectedHashNItem >= 0)
3016 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3018 t1 = t2;
3021 g_Git.m_critGitDllSec.Lock();
3022 git_close_log(m_DllGitLog);
3023 g_Git.m_critGitDllSec.Unlock();
3027 if (m_bExitThread)
3029 InterlockedExchange(&m_bThreadRunning, FALSE);
3030 return 0;
3033 //Update UI;
3034 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3036 if (lastSelectedHashNItem >= 0)
3037 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3039 if (this->m_hWnd)
3040 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3042 InterlockedExchange(&m_bThreadRunning, FALSE);
3044 return 0;
3047 void CGitLogListBase::FetchRemoteList()
3049 STRING_VECTOR remoteList;
3050 if (!g_Git.GetRemoteList(remoteList))
3051 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3052 else
3053 m_SingleRemote = _T("");
3056 void CGitLogListBase::FetchTrackingBranchList()
3058 m_TrackingMap.clear();
3059 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3061 for (size_t j = 0; j < it->second.size(); ++j)
3063 CString branchName;
3064 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3066 CString pullRemote, pullBranch;
3067 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3068 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3070 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3077 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3079 SafeTerminateThread();
3081 this->SetItemCountEx(0);
3082 this->Clear();
3084 ResetWcRev();
3086 // HACK to hide graph column
3087 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3088 SetColumnWidth(0, 0);
3089 else
3090 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3092 //Update branch and Tag info
3093 ReloadHashMap();
3094 //Assume Thread have exited
3095 //if(!m_bThreadRunning)
3097 m_logEntries.clear();
3099 if(IsCleanFilter)
3101 m_sFilterText.Empty();
3102 m_From=-1;
3103 m_To=-1;
3106 InterlockedExchange(&m_bExitThread,FALSE);
3108 InterlockedExchange(&m_bThreadRunning, TRUE);
3109 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3110 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3112 InterlockedExchange(&m_bThreadRunning, FALSE);
3113 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3114 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3118 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3122 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3123 if (!bMatchCase)
3124 type |= std::tr1::regex_constants::icase;
3125 pat = std::tr1::wregex(regexp_str, type);
3126 return true;
3128 catch (std::exception) {}
3129 return false;
3131 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
3133 BOOL result = TRUE;
3134 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3135 CString sRev;
3137 if ((bRegex)&&(m_bFilterWithRegex))
3139 if (m_SelectedFilters & LOGFILTER_BUGID)
3141 if(this->m_bShowBugtraqColumn)
3143 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3145 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3146 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3148 return TRUE;
3153 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3155 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3156 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3158 return TRUE;
3162 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3164 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3165 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3167 return TRUE;
3171 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3173 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3175 return TRUE;
3178 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3180 return TRUE;
3184 if (m_SelectedFilters & LOGFILTER_EMAILS)
3186 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3188 return TRUE;
3191 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3193 return TRUE;
3197 if (m_SelectedFilters & LOGFILTER_REVS)
3199 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3200 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3202 return TRUE;
3206 if (m_SelectedFilters & LOGFILTER_REFNAME)
3208 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3209 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3211 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3213 return TRUE;
3218 if (m_SelectedFilters & LOGFILTER_PATHS)
3220 CTGitPathList *pathList=NULL;
3221 if( pRev->m_IsDiffFiles)
3222 pathList = &pRev->GetFiles(this);
3223 else
3225 if(!pRev->m_IsSimpleListReady)
3226 pRev->SafeGetSimpleList(&g_Git);
3229 if(pathList)
3230 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3232 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3234 return true;
3236 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3238 return true;
3242 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3244 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3246 return true;
3251 else
3253 CString find = m_sFilterText;
3254 find.MakeLower();
3255 result = find[0] == '!' ? FALSE : TRUE;
3256 if (!result)
3257 find = find.Mid(1);
3259 if (m_SelectedFilters & LOGFILTER_BUGID)
3261 if(this->m_bShowBugtraqColumn)
3263 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3265 sBugIds.MakeLower();
3266 if ((sBugIds.Find(find) >= 0))
3268 return result;
3273 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3275 CString msg = pRev->GetSubject();
3277 msg = msg.MakeLower();
3278 if ((msg.Find(find) >= 0))
3280 return result;
3284 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3286 CString msg = pRev->GetBody();
3288 msg = msg.MakeLower();
3289 if ((msg.Find(find) >= 0))
3291 return result;
3295 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3297 CString msg = pRev->GetAuthorName();
3298 msg = msg.MakeLower();
3299 if ((msg.Find(find) >= 0))
3301 return result;
3305 if (m_SelectedFilters & LOGFILTER_EMAILS)
3307 CString msg = pRev->GetAuthorEmail();
3308 msg = msg.MakeLower();
3309 if ((msg.Find(find) >= 0))
3311 return result;
3315 if (m_SelectedFilters & LOGFILTER_REVS)
3317 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3318 if ((sRev.Find(find) >= 0))
3320 return result;
3324 if (m_SelectedFilters & LOGFILTER_REFNAME)
3326 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3327 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3329 if (it->Find(find) >= 0)
3331 return result;
3336 if (m_SelectedFilters & LOGFILTER_PATHS)
3338 CTGitPathList *pathList=NULL;
3339 if( pRev->m_IsDiffFiles)
3340 pathList = &pRev->GetFiles(this);
3341 else
3343 if(!pRev->m_IsSimpleListReady)
3344 pRev->SafeGetSimpleList(&g_Git);
3346 if(pathList)
3347 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3349 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3350 CString path = cpath->GetGitOldPathString();
3351 path.MakeLower();
3352 if ((path.Find(find)>=0))
3354 return result;
3356 path = cpath->GetGitPathString();
3357 path.MakeLower();
3358 if ((path.Find(find)>=0))
3360 return result;
3364 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3366 CString path = pRev->m_SimpleFileList[i];
3367 path.MakeLower();
3368 if ((path.Find(find)>=0))
3370 return result;
3374 } // else (from if (bRegex))
3375 return !result;
3378 static bool CStringStartsWith(const CString &str, const CString &prefix)
3380 return str.Left(prefix.GetLength()) == prefix;
3382 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3384 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3385 return true;
3387 if (m_ShowFilter & FILTERSHOW_REFS)
3389 // Keep all refs.
3390 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3391 for (size_t i = 0; i < refList.size(); ++i)
3393 const CString &str = refList[i];
3394 if (CStringStartsWith(str, _T("refs/heads/")))
3396 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3397 return true;
3399 else if (CStringStartsWith(str, _T("refs/remotes/")))
3401 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3402 return true;
3404 else if (CStringStartsWith(str, _T("refs/tags/")))
3406 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3407 return true;
3409 else if (CStringStartsWith(str, _T("refs/stash")))
3411 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3412 return true;
3414 else if (CStringStartsWith(str, _T("refs/bisect/")))
3416 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3417 return true;
3420 // Keep the head too.
3421 if (pRev->m_CommitHash == m_HeadHash)
3422 return true;
3425 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3427 if (pRev->ParentsCount() > 1)
3428 return true;
3429 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3430 if (childrenIt != commitChildren.end())
3432 const std::set<CGitHash> &children = childrenIt->second;
3433 if (children.size() > 1)
3434 return true;
3437 return false;
3440 void CGitLogListBase::ShowGraphColumn(bool bShow)
3442 // HACK to hide graph column
3443 if (bShow)
3444 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3445 else
3446 SetColumnWidth(0, 0);
3449 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3451 CString cmd;
3452 CString output;
3454 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3456 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3457 for (size_t i = 0; i < vector.size(); ++i)
3459 if (vector[i].Find(_T("refs/tags/")) == 0)
3461 CString tag = vector[i];
3462 int start = vector[i].Find(_T("^{}"));
3463 if (start > 0)
3464 tag = tag.Left(start);
3465 else
3466 continue;
3468 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3469 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3470 output.AppendChar(_T('\n'));
3475 return output;
3478 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3481 pShownlist->SafeRemoveAll();
3483 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3484 bool bRegex = false;
3485 if (m_bFilterWithRegex)
3486 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3488 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3489 CString sRev;
3490 for (DWORD i=0; i<m_logEntries.size(); ++i)
3492 if ((bRegex)&&(m_bFilterWithRegex))
3494 #if 0
3495 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3497 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3498 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3500 pShownlist->SafeAdd(m_logEntries[i]);
3501 continue;
3504 #endif
3505 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3507 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3508 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3510 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3511 continue;
3514 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3516 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3517 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3519 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3520 continue;
3523 if (m_SelectedFilters & LOGFILTER_PATHS)
3525 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3527 bool bGoing = true;
3528 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3530 CTGitPath cpath = pathList[cpPathIndex];
3531 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3533 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3534 bGoing = false;
3535 continue;
3537 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3539 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3540 bGoing = false;
3541 continue;
3543 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3545 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3546 bGoing = false;
3547 continue;
3551 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3553 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3555 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3556 continue;
3559 if (m_SelectedFilters & LOGFILTER_EMAILS)
3561 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3563 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3564 continue;
3567 if (m_SelectedFilters & LOGFILTER_REVS)
3569 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3570 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3572 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3573 continue;
3576 if (m_SelectedFilters & LOGFILTER_REFNAME)
3578 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3579 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3581 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3583 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3584 continue;
3588 } // if (bRegex)
3589 else
3591 CString find = m_sFilterText;
3592 find.MakeLower();
3593 #if 0
3594 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3596 CString sBugIDs = m_logEntries[i]->sBugIDs;
3598 sBugIDs = sBugIDs.MakeLower();
3599 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3601 pShownlist->SafeAdd(m_logEntries[i]);
3602 continue;
3605 #endif
3606 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3608 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3610 msg = msg.MakeLower();
3611 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3613 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3614 continue;
3617 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3619 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3621 msg = msg.MakeLower();
3622 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3624 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3625 continue;
3628 if (m_SelectedFilters & LOGFILTER_PATHS)
3630 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3632 bool bGoing = true;
3633 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3635 CTGitPath cpath = pathList[cpPathIndex];
3636 CString path = cpath.GetGitOldPathString();
3637 path.MakeLower();
3638 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3640 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3641 bGoing = false;
3642 continue;
3644 path = cpath.GetGitPathString();
3645 path.MakeLower();
3646 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3648 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3649 bGoing = false;
3650 continue;
3652 path = cpath.GetActionName();
3653 path.MakeLower();
3654 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3656 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3657 bGoing = false;
3658 continue;
3662 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3664 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3665 msg = msg.MakeLower();
3666 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3668 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3669 continue;
3672 if (m_SelectedFilters & LOGFILTER_EMAILS)
3674 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3675 msg = msg.MakeLower();
3676 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3678 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3679 continue;
3682 if (m_SelectedFilters & LOGFILTER_REVS)
3684 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3685 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3687 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3688 continue;
3691 if (m_SelectedFilters & LOGFILTER_REFNAME)
3693 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3694 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3696 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3698 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3699 continue;
3703 } // else (from if (bRegex))
3704 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3708 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3711 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3713 if(m_From == -1)
3714 if(m_To == -1)
3715 return true;
3716 else
3717 return time <= m_To;
3718 else
3719 if(m_To == -1)
3720 return time >= m_From;
3721 else
3722 return ((time >= m_From)&&(time <= m_To));
3724 return TRUE; /* git dll will filter time range */
3726 // return TRUE;
3728 void CGitLogListBase::StartFilter()
3730 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3731 RecalculateShownList(&m_arShownList);
3732 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3735 DeleteAllItems();
3736 SetItemCountEx(ShownCountWithStopped());
3737 RedrawItems(0, ShownCountWithStopped());
3738 Invalidate();
3741 void CGitLogListBase::RemoveFilter()
3744 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3746 m_arShownList.SafeRemoveAll();
3748 // reset the time filter too
3749 #if 0
3750 m_timFrom = (__time64_t(m_tFrom));
3751 m_timTo = (__time64_t(m_tTo));
3752 m_DateFrom.SetTime(&m_timFrom);
3753 m_DateTo.SetTime(&m_timTo);
3754 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3755 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3756 #endif
3758 for (DWORD i=0; i<m_logEntries.size(); ++i)
3760 if(this->m_IsOldFirst)
3762 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3764 else
3766 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3769 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3770 DeleteAllItems();
3771 SetItemCountEx(ShownCountWithStopped());
3772 RedrawItems(0, ShownCountWithStopped());
3774 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3777 void CGitLogListBase::Clear()
3779 m_arShownList.SafeRemoveAll();
3780 DeleteAllItems();
3782 m_logEntries.ClearAll();
3786 void CGitLogListBase::OnDestroy()
3788 // save the column widths to the registry
3789 SaveColumnWidths();
3791 SafeTerminateThread();
3792 SafeTerminateAsyncDiffThread();
3794 int retry = 0;
3795 while(m_LogCache.SaveCache())
3797 if(retry > 5)
3798 break;
3799 Sleep(1000);
3801 ++retry;
3803 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3804 // MB_YESNO) == IDNO)
3805 // break;
3808 CHintListCtrl::OnDestroy();
3811 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3813 CRect rect;
3814 int i=(int)wParam;
3815 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3816 this->InvalidateRect(rect);
3818 return 0;
3822 * Save column widths to the registry
3824 void CGitLogListBase::SaveColumnWidths()
3826 int maxcol = m_ColumnManager.GetColumnCount();
3828 // HACK that graph column is always shown
3829 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3831 for (int col = 0; col < maxcol; ++col)
3832 if (m_ColumnManager.IsVisible (col))
3833 m_ColumnManager.ColumnResized (col);
3835 m_ColumnManager.WriteSettings();
3838 int CGitLogListBase::GetHeadIndex()
3840 if(m_HeadHash.IsEmpty())
3841 return -1;
3843 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3845 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3846 if(pRev)
3848 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3849 return i;
3852 return -1;
3854 void CGitLogListBase::OnFind()
3856 if (!m_pFindDialog)
3858 m_pFindDialog = new CFindDlg(this);
3859 m_pFindDialog->Create(this);
3862 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3864 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3866 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3868 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3869 Default();
3871 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3873 if (GetSelectedCount() != 0)
3874 return 0;
3876 CGitHash theSelectedHash = m_lastSelectedHash;
3877 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3878 m_lastSelectedHash = theSelectedHash;
3880 int countPerPage = GetCountPerPage();
3881 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3882 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3883 EnsureVisible((int)itemToSelect, FALSE);
3884 return 0;
3886 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3889 ASSERT(m_pFindDialog != NULL);
3890 bool bFound = false;
3891 int i=0;
3893 if (m_pFindDialog->IsTerminating())
3895 // invalidate the handle identifying the dialog box.
3896 m_pFindDialog = NULL;
3897 return 0;
3900 INT_PTR cnt = m_arShownList.GetCount();
3902 if(m_pFindDialog->IsRef())
3904 CString str;
3905 str=m_pFindDialog->GetFindString();
3907 CGitHash hash;
3909 if(!str.IsEmpty())
3911 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3912 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3915 if(!hash.IsEmpty())
3917 for (i = 0; i < cnt; ++i)
3919 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3920 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3922 bFound = true;
3923 break;
3927 if (!bFound)
3929 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3930 return 0;
3934 if (m_pFindDialog->FindNext() && !bFound)
3936 //read data from dialog
3937 CString findText = m_pFindDialog->GetFindString();
3938 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3940 std::tr1::wregex pat;
3941 bool bRegex = false;
3942 if (m_pFindDialog->Regex())
3943 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3945 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3947 for (i = m_nSearchIndex + 1; ; ++i)
3949 if (i >= cnt)
3951 i = 0;
3952 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3954 if (m_nSearchIndex >= 0)
3956 if (i == m_nSearchIndex)
3958 ::MessageBeep(0xFFFFFFFF);
3959 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3960 break;
3964 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3966 CString str;
3967 str+=pLogEntry->m_CommitHash.ToString();
3968 str+=_T("\n");
3970 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3972 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3973 str+=_T("\n");
3976 str+=pLogEntry->GetAuthorEmail();
3977 str+=_T("\n");
3978 str+=pLogEntry->GetAuthorName();
3979 str+=_T("\n");
3980 str+=pLogEntry->GetBody();
3981 str+=_T("\n");
3982 str+=pLogEntry->GetCommitterEmail();
3983 str+=_T("\n");
3984 str+=pLogEntry->GetCommitterName();
3985 str+=_T("\n");
3986 str+=pLogEntry->GetSubject();
3987 str+=_T("\n");
3988 str+=pLogEntry->m_Notes;
3989 str+=_T("\n");
3990 str+=GetTagInfo(pLogEntry);
3991 str+=_T("\n");
3994 /*Because changed files list is loaded on demand when gui show,
3995 files will empty when files have not fetched.
3997 we can add it back by using one-way diff(with outnumber changed and rename detect.
3998 here just need changed filename list. one-way is much quicker.
4000 if(pLogEntry->m_IsFull)
4002 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
4004 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
4005 str+=_T("\n");
4006 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
4007 str+=_T("\n");
4010 else
4012 if(!pLogEntry->m_IsSimpleListReady)
4013 pLogEntry->SafeGetSimpleList(&g_Git);
4015 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
4017 str+=pLogEntry->m_SimpleFileList[i];
4018 str+=_T("\n");
4024 if (bRegex)
4026 if (std::regex_search(std::wstring(str), pat, flags))
4028 bFound = true;
4029 break;
4032 else
4034 if (bMatchCase)
4036 if (str.Find(findText) >= 0)
4038 bFound = true;
4039 break;
4043 else
4045 CString msg = str;
4046 msg = msg.MakeLower();
4047 CString find = findText.MakeLower();
4048 if (msg.Find(find) >= 0)
4050 bFound = TRUE;
4051 break;
4055 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4057 } // if(m_pFindDialog->FindNext())
4058 //UpdateLogInfoLabel();
4060 if (bFound)
4062 m_nSearchIndex = i;
4063 EnsureVisible(i, FALSE);
4064 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4065 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4066 SetSelectionMark(i);
4067 //FillLogMessageCtrl();
4068 UpdateData(FALSE);
4071 return 0;
4074 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4076 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4078 *pResult = FALSE;
4081 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4083 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4085 Invalidate(FALSE);