Correctly set text color on annotated commits
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob5426456d5c185d088e412a0af3ee93b176f7ad6b
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"), FALSE);
105 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
107 m_From = -1;
108 m_To = -1;
110 m_ShowMask = 0;
111 m_LoadingThread = NULL;
113 InterlockedExchange(&m_bExitThread,FALSE);
114 m_IsOldFirst = FALSE;
115 m_IsRebaseReplaceGraph = FALSE;
117 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
119 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
121 // get short/long datetime setting from registry
122 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
123 if ( RegUseShortDateFormat )
125 m_DateFormat = DATE_SHORTDATE;
127 else
129 m_DateFormat = DATE_LONGDATE;
131 // get relative time display setting from registry
132 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
133 m_bRelativeTimes = (regRelativeTimes != 0);
134 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
136 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
137 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
141 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
142 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
144 m_ColumnRegKey=_T("log");
146 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
147 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
148 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
150 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
151 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
153 m_AsyncThreadExit = FALSE;
154 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
155 m_AsynDiffListLock.Init();
157 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
158 if (m_DiffingThread ==NULL)
160 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
161 return;
166 int CGitLogListBase::AsyncDiffThread()
168 m_AsyncThreadExited = false;
169 while(!m_AsyncThreadExit)
171 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
173 GitRev *pRev = NULL;
174 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
176 m_AsynDiffListLock.Lock();
177 pRev = m_AsynDiffList.back();
178 m_AsynDiffList.pop_back();
179 m_AsynDiffListLock.Unlock();
181 if( pRev->m_CommitHash.IsEmpty() )
183 if(pRev->m_IsDiffFiles)
184 continue;
186 pRev->GetFiles(this).Clear();
187 pRev->m_ParentHash.clear();
188 pRev->m_ParentHash.push_back(m_HeadHash);
189 if(g_Git.IsInitRepos())
191 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
192 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
195 else
197 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
199 int dummyAction = 0;
200 int *action = &dummyAction;
201 SafeGetAction(pRev, &action);
202 *action = 0;
204 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
205 *action |= pRev->GetFiles(this)[j].m_Action;
207 CString err;
208 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
210 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
211 return -1;
214 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
215 InterlockedExchange(&pRev->m_IsFull, TRUE);
217 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
218 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
219 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
222 m_critSec_AsyncDiff.Lock();
223 int ret = pRev->CheckAndDiff();
224 m_critSec_AsyncDiff.Unlock();
225 if (!ret)
226 { // fetch change file list
227 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
229 if(i < m_arShownList.GetCount())
231 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
232 if(data->m_CommitHash == pRev->m_CommitHash)
234 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
235 break;
240 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
242 POSITION pos = GetFirstSelectedItemPosition();
243 int nItem = GetNextSelectedItem(pos);
245 if(nItem>=0)
247 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(nItem);
248 if(data)
249 if(data->m_CommitHash == pRev->m_CommitHash)
251 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
258 m_AsyncThreadExited = true;
259 return 0;
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
263 if (exclusivelyShow)
265 m_ContextMenuMask &= hideMask;
267 else
269 m_ContextMenuMask &= ~hideMask;
273 CGitLogListBase::~CGitLogListBase()
275 InterlockedExchange(&m_bNoDispUpdates, TRUE);
276 this->m_arShownList.SafeRemoveAll();
278 DestroyIcon(m_hModifiedIcon);
279 DestroyIcon(m_hReplacedIcon);
280 DestroyIcon(m_hAddedIcon);
281 DestroyIcon(m_hDeletedIcon);
282 m_logEntries.ClearAll();
284 if (m_boldFont)
285 DeleteObject(m_boldFont);
287 if (m_FontItalics)
288 DeleteObject(m_FontItalics);
290 if (m_boldItalicsFont)
291 DeleteObject(m_boldItalicsFont);
293 if ( m_pStoreSelection )
295 delete m_pStoreSelection;
296 m_pStoreSelection = NULL;
299 SafeTerminateThread();
300 SafeTerminateAsyncDiffThread();
302 if(m_AsyncDiffEvent)
303 CloseHandle(m_AsyncDiffEvent);
307 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
308 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
309 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
310 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
311 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
312 ON_WM_CONTEXTMENU()
313 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
314 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
315 ON_WM_CREATE()
316 ON_WM_DESTROY()
317 ON_MESSAGE(MSG_LOADED,OnLoad)
318 ON_WM_MEASUREITEM()
319 ON_WM_MEASUREITEM_REFLECT()
320 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
321 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
322 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
323 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
324 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
325 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
326 END_MESSAGE_MAP()
328 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
330 //if (m_nRowHeight>0)
332 lpMeasureItemStruct->itemHeight = 50;
336 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
338 PreSubclassWindow();
339 return CHintListCtrl::OnCreate(lpCreateStruct);
342 void CGitLogListBase::PreSubclassWindow()
344 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
345 // load the icons for the action columns
346 // m_Theme.Open(m_hWnd, L"ListView");
347 SetWindowTheme(m_hWnd, L"Explorer", NULL);
348 CHintListCtrl::PreSubclassWindow();
351 CString CGitLogListBase::GetRebaseActionName(int action)
353 if (action & LOGACTIONS_REBASE_EDIT)
354 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
355 if (action & LOGACTIONS_REBASE_SQUASH)
356 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
357 if (action & LOGACTIONS_REBASE_PICK)
358 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
359 if (action & LOGACTIONS_REBASE_SKIP)
360 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
362 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
365 void CGitLogListBase::InsertGitColumn()
367 CString temp;
369 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
370 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
371 if (DWORD(regFullRowSelect))
372 exStyle |= LVS_EX_FULLROWSELECT;
373 SetExtendedStyle(exStyle);
375 // only load properties if we have a repository
376 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
377 UpdateProjectProperties();
379 static UINT normal[] =
381 IDS_LOG_GRAPH,
382 IDS_LOG_REBASE,
383 IDS_LOG_ID,
384 IDS_LOG_HASH,
385 IDS_LOG_ACTIONS,
386 IDS_LOG_MESSAGE,
387 IDS_LOG_AUTHOR,
388 IDS_LOG_DATE,
389 IDS_LOG_EMAIL,
390 IDS_LOG_COMMIT_NAME,
391 IDS_LOG_COMMIT_EMAIL,
392 IDS_LOG_COMMIT_DATE,
393 IDS_LOG_BUGIDS,
394 IDS_LOG_SVNREV,
397 static int with[] =
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 ICONITEMBORDER+16*4,
402 ICONITEMBORDER+16*4,
403 ICONITEMBORDER+16*4,
404 LOGLIST_MESSAGE_MIN,
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,
412 ICONITEMBORDER+16*4,
414 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
416 DWORD hideColumns = 0;
417 if(this->m_IsRebaseReplaceGraph)
419 hideColumns |= GIT_LOG_GRAPH;
420 m_dwDefaultColumns |= GIT_LOG_REBASE;
422 else
424 hideColumns |= GIT_LOG_REBASE;
427 if(this->m_IsIDReplaceAction)
429 hideColumns |= GIT_LOG_ACTIONS;
430 m_dwDefaultColumns |= GIT_LOG_ID;
431 m_dwDefaultColumns |= GIT_LOG_HASH;
433 else
435 hideColumns |= GIT_LOG_ID;
437 if(this->m_bShowBugtraqColumn)
439 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
441 else
443 hideColumns |= GIT_LOGLIST_BUG;
445 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
446 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
447 else
448 hideColumns |= GIT_LOGLIST_SVNREV;
449 SetRedraw(false);
451 m_ColumnManager.SetNames(normal, _countof(normal));
452 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
454 SetRedraw(true);
458 * Resizes all columns in a list control to values in registry.
460 void CGitLogListBase::ResizeAllListCtrlCols()
462 // column max and min widths to allow
463 static const int nMinimumWidth = 10;
464 static const int nMaximumWidth = 1000;
465 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
466 if (pHdrCtrl)
468 int numcols = pHdrCtrl->GetItemCount();
469 for (int col = 0; col < numcols; ++col)
471 // get width for this col last time from registry
472 CString regentry;
473 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
474 CRegDWORD regwidth(regentry, 0);
475 int cx = regwidth;
476 if ( cx == 0 )
478 // no saved value, setup sensible defaults
479 if (col == this->LOGLIST_MESSAGE)
481 cx = LOGLIST_MESSAGE_MIN;
483 else
485 cx = ICONITEMBORDER+16*4;
488 if (cx < nMinimumWidth)
490 cx = nMinimumWidth;
492 else if (cx > nMaximumWidth)
494 cx = nMaximumWidth;
497 SetColumnWidth(col, cx);
504 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
506 LVITEM rItem;
507 SecureZeroMemory(&rItem, sizeof(LVITEM));
508 rItem.mask = LVIF_STATE;
509 rItem.iItem = (int)Index;
510 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
511 GetItem(&rItem);
513 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
514 HBRUSH brush = NULL;
516 if (!(rItem.state & LVIS_SELECTED))
518 int action = pLogEntry->GetRebaseAction();
519 if (action & LOGACTIONS_REBASE_SQUASH)
520 brush = ::CreateSolidBrush(RGB(156,156,156));
521 else if (action & LOGACTIONS_REBASE_EDIT)
522 brush = ::CreateSolidBrush(RGB(200,200,128));
524 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
526 if (rItem.state & LVIS_SELECTED)
528 if (::GetFocus() == m_hWnd)
529 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
530 else
531 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
534 if (brush != NULL)
536 ::FillRect(hdc, &rect, brush);
537 ::DeleteObject(brush);
541 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
543 POINT point = { 4, 4 };
544 CRect rt2 = rect;
545 rt2.DeflateRect(1, 1);
546 rt2.OffsetRect(2, 2);
548 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
549 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
550 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
551 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
552 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
554 ::SelectObject(hdc, brush);
555 rt2.OffsetRect(-2, -2);
556 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
557 ::SelectObject(hdc, oldbrush);
558 ::SelectObject(hdc, oldpen);
559 ::DeleteObject(nullPen);
560 ::DeleteObject(darkBrush);
563 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
565 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
566 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
567 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
568 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
569 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
570 ::LineTo(hdc, rect.left, rect.bottom);
571 ::SelectObject(hdc, oldpen);
572 ::DeleteObject(pen);
575 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
577 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
578 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
579 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
580 ::LineTo(hdc, rect.left, rect.bottom);
581 ::LineTo(hdc, rect.right, rect.bottom);
582 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
583 ::SelectObject(hdc, oldpen);
584 ::DeleteObject(pen);
587 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
589 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
590 CRect rt=rect;
591 LVITEM rItem;
592 SecureZeroMemory(&rItem, sizeof(LVITEM));
593 rItem.mask = LVIF_STATE;
594 rItem.iItem = (int)index;
595 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
596 GetItem(&rItem);
598 CDC W_Dc;
599 W_Dc.Attach(hdc);
601 HTHEME hTheme = NULL;
602 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
603 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
605 SIZE oneSpaceSize;
606 if (m_bTagsBranchesOnRightSide)
608 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
609 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
610 SelectObject(hdc, oldFont);
611 rt.left += oneSpaceSize.cx * 2;
613 else
615 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
616 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
617 rt.left += oneSpaceSize.cx;
620 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
622 int txtState = LISS_NORMAL;
623 if (rItem.state & LVIS_SELECTED)
624 txtState = LISS_SELECTED;
626 DTTOPTS opts = { 0 };
627 opts.dwSize = sizeof(opts);
628 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
629 opts.dwFlags = DTT_TEXTCOLOR;
630 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
632 else
634 if (rItem.state & LVIS_SELECTED)
636 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
637 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
638 ::SetTextColor(hdc, clrOld);
640 else
642 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
643 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
644 ::SetTextColor(hdc, clrOld);
648 if (m_bTagsBranchesOnRightSide)
650 SIZE size;
651 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
653 rt.left += oneSpaceSize.cx + size.cx;
655 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
658 if (hTheme)
659 CloseThemeData(hTheme);
661 W_Dc.Detach();
664 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
666 for (unsigned int i = 0; i < refList.size(); ++i)
668 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
669 HBRUSH brush = 0;
670 COLORREF colRef = refList[i].color;
671 bool singleRemote = refList[i].singleRemote;
672 bool hasTracking = refList[i].hasTracking;
673 bool sameName = refList[i].sameName;
674 bool annotatedTag = refList[i].annotatedTag;
676 //When row selected, ajust label color
677 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
679 if (rItem.state & LVIS_SELECTED)
680 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
683 brush = ::CreateSolidBrush(colRef);
685 if (!shortname.IsEmpty() && (rt.left < rect.right))
687 SIZE size;
688 memset(&size,0,sizeof(SIZE));
689 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
691 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
692 rt.right += 8;
694 int textpos = DT_CENTER;
696 if (rt.right > rect.right)
698 rt.right = rect.right;
699 textpos = 0;
702 CRect textRect = rt;
704 if (singleRemote)
706 rt.right += 8;
707 textRect.OffsetRect(8, 0);
710 if (sameName)
711 rt.right += 8;
713 if (hasTracking)
715 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
717 else
719 //Fill interior of ref label
720 ::FillRect(hdc, &rt, brush);
723 //Draw edge of label
724 CRect rectEdge = rt;
726 if (!hasTracking)
728 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
729 rectEdge.DeflateRect(1, 1);
730 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
733 if (annotatedTag)
735 rt.right += 8;
736 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
737 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
738 ::FillRgn(hdc, hrgn, brush);
739 ::DeleteObject(hrgn);
740 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
741 HPEN pen;
742 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
743 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
744 ::DeleteObject(pen);
745 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
746 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
747 ::DeleteObject(pen);
748 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
749 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
750 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
751 ::DeleteObject(pen);
752 SelectObject(hdc, oldpen);
755 //Draw text inside label
756 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
757 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
759 int txtState = LISS_NORMAL;
760 if (rItem.state & LVIS_SELECTED)
761 txtState = LISS_SELECTED;
763 DTTOPTS opts = { 0 };
764 opts.dwSize = sizeof(opts);
765 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
766 opts.dwFlags = DTT_TEXTCOLOR;
767 DrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
769 else
771 W_Dc.SetBkMode(TRANSPARENT);
772 if (customColor || (rItem.state & LVIS_SELECTED))
774 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
775 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
776 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
777 ::SetTextColor(hdc,clrOld);
779 else
781 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
782 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
783 ::SetTextColor(hdc, clrOld);
787 if (singleRemote)
789 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
790 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
791 CRect newRect;
792 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
793 DrawLightning(hdc, newRect, color, bold);
796 if (sameName)
798 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
799 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
800 CRect newRect;
801 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
802 DrawUpTriangle(hdc, newRect, color, bold);
805 rt.left = rt.right + 1;
807 if (brush)
808 ::DeleteObject(brush);
810 rt.right = rect.right;
813 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
815 // Returns ((256 - amount)*col1 + amount*col2) / 256;
816 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
817 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
818 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
821 Gdiplus::Color GetGdiColor(COLORREF col)
823 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
825 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
826 const COLORREF& col,const COLORREF& activeColor, int top
829 int h = laneHeight / 2;
830 int m = (x1 + x2) / 2;
831 int r = (x2 - x1) * m_NodeSize / 30;
832 int d = 2 * r;
834 #define P_CENTER m , h+top
835 #define P_0 x2, h+top
836 #define P_90 m , 0+top-1
837 #define P_180 x1, h+top
838 #define P_270 m , 2 * h+top +1
839 #define R_CENTER m - r, h - r+top, d, d
842 #define DELTA_UR_B 2*(x1 - m), 2*h +top
843 #define DELTA_UR_E 0*16, 90*16 +top // -,
845 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
846 #define DELTA_DR_E 270*16, 90*16 +top // -'
848 #define DELTA_UL_B 2*(x2 - m), 2*h +top
849 #define DELTA_UL_E 90*16, 90*16 +top // ,-
851 #define DELTA_DL_B 2*(x2 - m),2*-h +top
852 #define DELTA_DL_E 180*16, 90*16 // '-
854 #define CENTER_UR x1, 2*h, 225
855 #define CENTER_DR x1, 0 , 135
856 #define CENTER_UL x2, 2*h, 315
857 #define CENTER_DL x2, 0 , 45
860 Gdiplus::Graphics graphics( hdc );
862 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
864 // arc
865 switch (type) {
866 case Lanes::JOIN:
867 case Lanes::JOIN_R:
868 case Lanes::HEAD:
869 case Lanes::HEAD_R:
871 Gdiplus::LinearGradientBrush gradient(
872 Gdiplus::Point(x1-2, h+top-2),
873 Gdiplus::Point(P_270),
874 GetGdiColor(activeColor),GetGdiColor(col));
877 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
878 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
880 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
881 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
882 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
884 break;
886 case Lanes::JOIN_L:
889 Gdiplus::LinearGradientBrush gradient(
890 Gdiplus::Point(P_270),
891 Gdiplus::Point(x2+1, h+top-1),
892 GetGdiColor(col),GetGdiColor(activeColor));
895 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
896 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
898 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
899 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
900 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
903 break;
905 case Lanes::TAIL:
906 case Lanes::TAIL_R:
909 Gdiplus::LinearGradientBrush gradient(
910 Gdiplus::Point(x1-2, h+top-2),
911 Gdiplus::Point(P_90),
912 GetGdiColor(activeColor),GetGdiColor(col));
914 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
916 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
918 #if 0
919 QConicalGradient gradient(CENTER_DR);
920 gradient.setColorAt(0.375, activeCol);
921 gradient.setColorAt(0.625, col);
922 myPen.setBrush(gradient);
923 p->setPen(myPen);
924 p->drawArc(P_CENTER, DELTA_DR);
925 #endif
926 break;
928 default:
929 break;
933 //static QPen myPen(Qt::black, 2); // fast path here
934 CPen pen;
935 pen.CreatePen(PS_SOLID,2,col);
936 //myPen.setColor(col);
937 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
939 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
941 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
943 //p->setPen(myPen);
945 // vertical line
946 switch (type) {
947 case Lanes::ACTIVE:
948 case Lanes::NOT_ACTIVE:
949 case Lanes::MERGE_FORK:
950 case Lanes::MERGE_FORK_R:
951 case Lanes::MERGE_FORK_L:
952 case Lanes::JOIN:
953 case Lanes::JOIN_R:
954 case Lanes::JOIN_L:
955 case Lanes::CROSS:
956 //DrawLine(hdc,P_90,P_270);
957 graphics.DrawLine(&myPen,P_90,P_270);
958 //p->drawLine(P_90, P_270);
959 break;
960 case Lanes::HEAD_L:
961 case Lanes::BRANCH:
962 //DrawLine(hdc,P_CENTER,P_270);
963 graphics.DrawLine(&myPen,P_CENTER,P_270);
964 //p->drawLine(P_CENTER, P_270);
965 break;
966 case Lanes::TAIL_L:
967 case Lanes::INITIAL:
968 case Lanes::BOUNDARY:
969 case Lanes::BOUNDARY_C:
970 case Lanes::BOUNDARY_R:
971 case Lanes::BOUNDARY_L:
972 //DrawLine(hdc,P_90, P_CENTER);
973 graphics.DrawLine(&myPen,P_90,P_CENTER);
974 //p->drawLine(P_90, P_CENTER);
975 break;
976 default:
977 break;
980 myPen.SetColor(GetGdiColor(activeColor));
982 // horizontal line
983 switch (type) {
984 case Lanes::MERGE_FORK:
985 case Lanes::JOIN:
986 case Lanes::HEAD:
987 case Lanes::TAIL:
988 case Lanes::CROSS:
989 case Lanes::CROSS_EMPTY:
990 case Lanes::BOUNDARY_C:
991 //DrawLine(hdc,P_180,P_0);
992 graphics.DrawLine(&myPen,P_180,P_0);
993 //p->drawLine(P_180, P_0);
994 break;
995 case Lanes::MERGE_FORK_R:
996 case Lanes::BOUNDARY_R:
997 //DrawLine(hdc,P_180,P_CENTER);
998 graphics.DrawLine(&myPen,P_180,P_CENTER);
999 //p->drawLine(P_180, P_CENTER);
1000 break;
1001 case Lanes::MERGE_FORK_L:
1002 case Lanes::HEAD_L:
1003 case Lanes::TAIL_L:
1004 case Lanes::BOUNDARY_L:
1005 //DrawLine(hdc,P_CENTER,P_0);
1006 graphics.DrawLine(&myPen,P_CENTER,P_0);
1007 //p->drawLine(P_CENTER, P_0);
1008 break;
1009 default:
1010 break;
1013 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1015 CBrush brush;
1016 brush.CreateSolidBrush(col);
1017 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1019 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1020 // center symbol, e.g. rect or ellipse
1021 switch (type) {
1022 case Lanes::ACTIVE:
1023 case Lanes::INITIAL:
1024 case Lanes::BRANCH:
1026 //p->setPen(Qt::NoPen);
1027 //p->setBrush(col);
1028 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1029 graphics.FillEllipse(&myBrush, R_CENTER);
1030 //p->drawEllipse(R_CENTER);
1031 break;
1032 case Lanes::MERGE_FORK:
1033 case Lanes::MERGE_FORK_R:
1034 case Lanes::MERGE_FORK_L:
1035 //p->setPen(Qt::NoPen);
1036 //p->setBrush(col);
1037 //p->drawRect(R_CENTER);
1038 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1039 graphics.FillRectangle(&myBrush, R_CENTER);
1040 break;
1041 case Lanes::UNAPPLIED:
1042 // Red minus sign
1043 //p->setPen(Qt::NoPen);
1044 //p->setBrush(Qt::red);
1045 //p->drawRect(m - r, h - 1, d, 2);
1046 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1047 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1048 break;
1049 case Lanes::APPLIED:
1050 // Green plus sign
1051 //p->setPen(Qt::NoPen);
1052 //p->setBrush(DARK_GREEN);
1053 //p->drawRect(m - r, h - 1, d, 2);
1054 //p->drawRect(m - 1, h - r, 2, d);
1055 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1056 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1057 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1058 break;
1059 case Lanes::BOUNDARY:
1060 //p->setBrush(back);
1061 //p->drawEllipse(R_CENTER);
1062 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1063 graphics.DrawEllipse(&myPen, R_CENTER);
1064 break;
1065 case Lanes::BOUNDARY_C:
1066 case Lanes::BOUNDARY_R:
1067 case Lanes::BOUNDARY_L:
1068 //p->setBrush(back);
1069 //p->drawRect(R_CENTER);
1070 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1071 graphics.FillRectangle(&myBrush,R_CENTER);
1072 break;
1073 default:
1074 break;
1077 ::SelectObject(hdc,oldpen);
1078 ::SelectObject(hdc,oldbrush);
1079 #undef P_CENTER
1080 #undef P_0
1081 #undef P_90
1082 #undef P_180
1083 #undef P_270
1084 #undef R_CENTER
1087 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1089 // TODO: unfinished
1090 // return;
1091 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1092 if(data->m_CommitHash.IsEmpty())
1093 return;
1095 CRect rt=rect;
1096 LVITEM rItem;
1097 SecureZeroMemory(&rItem, sizeof(LVITEM));
1098 rItem.mask = LVIF_STATE;
1099 rItem.iItem = (int)index;
1100 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1101 GetItem(&rItem);
1103 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1105 if (data->m_Lanes.empty())
1106 m_logEntries.setLane(data->m_CommitHash);
1108 std::vector<int>& lanes=data->m_Lanes;
1109 size_t laneNum = lanes.size();
1110 UINT activeLane = 0;
1111 for (UINT i = 0; i < laneNum; ++i)
1112 if (Lanes::isMerge(lanes[i])) {
1113 activeLane = i;
1114 break;
1117 int x2 = 0;
1118 int maxWidth = rect.Width();
1119 int lw = 3 * rect.Height() / 4; //laneWidth()
1121 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1122 //if (opt.state & QStyle::State_Selected)
1123 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1125 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1128 int x1 = x2;
1129 x2 += lw;
1131 int ln = lanes[i];
1132 if (ln == Lanes::EMPTY)
1133 continue;
1135 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1136 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1139 #if 0
1140 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1142 int x1 = x2;
1143 x2 += lw;
1145 int ln = lanes[i];
1146 if (ln == Lanes::EMPTY)
1147 continue;
1149 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1150 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1152 if (ln == Lanes::CROSS)
1154 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1155 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1157 else
1158 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1160 #endif
1164 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1167 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1168 // Take the default processing unless we set this to something else below.
1169 *pResult = CDRF_DODEFAULT;
1171 if (m_bNoDispUpdates)
1172 return;
1174 switch (pLVCD->nmcd.dwDrawStage)
1176 case CDDS_PREPAINT:
1178 *pResult = CDRF_NOTIFYITEMDRAW;
1179 return;
1181 break;
1182 case CDDS_ITEMPREPAINT:
1184 // This is the prepaint stage for an item. Here's where we set the
1185 // item's text color.
1187 // Tell Windows to send draw notifications for each subitem.
1188 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1190 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1192 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1194 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1195 if (data)
1197 HGDIOBJ hGdiObj = nullptr;
1198 int action = data->GetRebaseAction();
1199 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1200 crText = RGB(128,128,128);
1202 if (action & LOGACTIONS_REBASE_SQUASH)
1203 pLVCD->clrTextBk = RGB(156,156,156);
1204 else if (action & LOGACTIONS_REBASE_EDIT)
1205 pLVCD->clrTextBk = RGB(200,200,128);
1206 else
1207 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1209 if (action & LOGACTIONS_REBASE_CURRENT)
1210 hGdiObj = m_boldFont;
1212 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1213 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1214 if (isHeadHash && isHighlight)
1215 hGdiObj = m_boldItalicsFont;
1216 else if (isHeadHash)
1217 hGdiObj = m_boldFont;
1218 else if (isHighlight)
1219 hGdiObj = m_FontItalics;
1221 if (hGdiObj)
1223 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1224 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1227 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1228 // crText = GetSysColor(COLOR_GRAYTEXT);
1230 if (data->m_CommitHash.IsEmpty())
1232 //crText = GetSysColor(RGB(200,200,0));
1233 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1234 // We changed the font, so we're returning CDRF_NEWFONT. This
1235 // tells the control to recalculate the extent of the text.
1236 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1240 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1242 if (m_bStrictStopped)
1243 crText = GetSysColor(COLOR_GRAYTEXT);
1245 // Store the color back in the NMLVCUSTOMDRAW struct.
1246 pLVCD->clrText = crText;
1247 return;
1249 break;
1250 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1252 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1254 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1257 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1259 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1261 CRect rect;
1262 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1264 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1265 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1267 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1268 if( !data ->m_CommitHash.IsEmpty())
1269 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1271 *pResult = CDRF_SKIPDEFAULT;
1272 return;
1276 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1278 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1280 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1282 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1284 CRect rect;
1285 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1287 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1288 // not in FillBackGround method, because this only affected the message subitem
1289 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1290 return;
1292 int index = (int)pLVCD->nmcd.dwItemSpec;
1293 int state = GetItemState(index, LVIS_SELECTED);
1294 int txtState = LISS_NORMAL;
1295 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1297 if (state & LVIS_SELECTED)
1298 txtState = LISS_HOTSELECTED;
1299 else
1300 txtState = LISS_HOT;
1302 else if (state & LVIS_SELECTED)
1304 if (::GetFocus() == m_hWnd)
1305 txtState = LISS_SELECTED;
1306 else
1307 txtState = LISS_SELECTEDNOTFOCUS;
1310 HTHEME hTheme = nullptr;
1311 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1312 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1314 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1315 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1316 else
1318 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1319 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1320 ::DeleteObject(brush);
1322 if (hTheme)
1324 CRect rt;
1325 // get rect of whole line
1326 GetItemRect(index, rt, LVIR_BOUNDS);
1327 CRect rect2 = rect;
1328 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1329 rect2.DeflateRect(1, 1, 1, 1);
1331 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1332 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1334 CloseThemeData(hTheme);
1336 // END: extended redraw
1338 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1340 std::vector<REFLABEL> refsToShow;
1341 STRING_VECTOR remoteTrackingList;
1342 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1343 for (unsigned int i = 0; i < refList.size(); ++i)
1345 CString str = refList[i];
1347 REFLABEL refLabel;
1348 refLabel.color = RGB(255, 255, 255);
1349 refLabel.singleRemote = false;
1350 refLabel.hasTracking = false;
1351 refLabel.sameName = false;
1352 refLabel.annotatedTag = false;
1353 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1355 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1356 continue;
1357 if (refLabel.name == m_CurrentBranch )
1358 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1359 else
1360 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1362 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1363 CString pullRemote = trackingEntry.first;
1364 CString pullBranch = trackingEntry.second;
1365 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1367 CString defaultUpstream;
1368 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1369 refLabel.hasTracking = true;
1370 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1372 bool found = false;
1373 for (size_t j = i + 1; j < refList.size(); ++j)
1375 if (refList[j] == defaultUpstream)
1377 found = true;
1378 break;
1382 if (found)
1384 bool sameName = pullBranch == refLabel.name;
1385 refsToShow.push_back(refLabel);
1386 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1387 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1388 if (m_bSymbolizeRefNames)
1390 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1392 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1393 refLabel.singleRemote = true;
1395 else if (sameName)
1396 refLabel.simplifiedName = pullRemote + _T("/");
1397 refLabel.sameName = sameName;
1399 refsToShow.push_back(refLabel);
1400 remoteTrackingList.push_back(defaultUpstream);
1401 continue;
1406 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1408 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1409 continue;
1411 bool found = false;
1412 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1414 if (remoteTrackingList[j] == str)
1416 found = true;
1417 break;
1420 if (found)
1421 continue;
1423 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1424 if (m_bSymbolizeRefNames)
1426 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1428 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1429 refLabel.singleRemote = true;
1433 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1435 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1436 continue;
1437 refLabel.color = m_Colors.GetColor(CColors::Tag);
1438 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1440 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1442 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1443 continue;
1444 refLabel.color = m_Colors.GetColor(CColors::Stash);
1445 refLabel.name = _T("stash");
1447 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1449 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1450 continue;
1451 if (refLabel.name.Find(_T("good")) == 0)
1453 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1454 refLabel.name = _T("good");
1456 if (refLabel.name.Find(_T("bad")) == 0)
1458 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1459 refLabel.name = _T("bad");
1462 else
1463 continue;
1465 refsToShow.push_back(refLabel);
1468 if (refsToShow.empty())
1470 *pResult = CDRF_DODEFAULT;
1471 return;
1474 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1476 *pResult = CDRF_SKIPDEFAULT;
1477 return;
1484 if (pLVCD->iSubItem == LOGLIST_ACTION)
1486 if(this->m_IsIDReplaceAction)
1488 *pResult = CDRF_DODEFAULT;
1489 return;
1491 *pResult = CDRF_DODEFAULT;
1493 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1494 return;
1496 int nIcons = 0;
1497 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1498 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1500 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1501 CRect rect;
1502 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1503 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1504 // Get the selected state of the
1505 // item being drawn.
1507 // Fill the background if necessary
1508 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1510 // Draw the icon(s) into the compatible DC
1511 int action = SafeGetAction(pLogEntry);
1513 if (!pLogEntry->m_IsDiffFiles)
1514 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1516 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1517 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1518 ++nIcons;
1520 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1521 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1522 ++nIcons;
1524 if (action & CTGitPath::LOGACTIONS_DELETED)
1525 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1526 ++nIcons;
1528 if (action & CTGitPath::LOGACTIONS_REPLACED)
1529 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1530 ++nIcons;
1531 *pResult = CDRF_SKIPDEFAULT;
1532 return;
1535 break;
1537 *pResult = CDRF_DODEFAULT;
1540 CString FindSVNRev(const CString& msg)
1544 const std::tr1::wsregex_iterator end;
1545 std::wstring s = msg;
1546 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)
1548 const std::tr1::wsmatch match = *it;
1549 if (match.size() == 4)
1551 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1552 return std::wstring(match[2]).c_str();
1555 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)
1557 const std::tr1::wsmatch match = *it;
1558 if (match.size() == 3)
1560 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1561 return std::wstring(match[1]).c_str();
1565 catch (std::exception) {}
1567 return _T("");
1570 // CGitLogListBase message handlers
1572 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1574 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1576 // Create a pointer to the item
1577 LV_ITEM* pItem = &(pDispInfo)->item;
1579 // Do the list need text information?
1580 if (!(pItem->mask & LVIF_TEXT))
1581 return;
1583 // By default, clear text buffer.
1584 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1586 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1588 *pResult = 0;
1589 if (m_bNoDispUpdates || bOutOfRange)
1590 return;
1592 // Which item number?
1593 int itemid = pItem->iItem;
1594 GitRev * pLogEntry = NULL;
1595 if (itemid < m_arShownList.GetCount())
1596 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1598 CString temp;
1599 if(m_IsOldFirst)
1601 temp.Format(_T("%d"),pItem->iItem+1);
1604 else
1606 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1609 // Which column?
1610 switch (pItem->iSubItem)
1612 case this->LOGLIST_GRAPH: //Graphic
1613 break;
1614 case this->LOGLIST_REBASE:
1616 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1617 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1619 break;
1620 case this->LOGLIST_ACTION: //action -- no text in the column
1621 break;
1622 case this->LOGLIST_HASH:
1623 if(pLogEntry)
1624 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1625 break;
1626 case this->LOGLIST_ID:
1627 if(this->m_IsIDReplaceAction)
1628 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1629 break;
1630 case this->LOGLIST_MESSAGE: //Message
1631 if (pLogEntry)
1632 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1633 break;
1634 case this->LOGLIST_AUTHOR: //Author
1635 if (pLogEntry)
1636 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1637 break;
1638 case this->LOGLIST_DATE: //Date
1639 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1640 lstrcpyn(pItem->pszText,
1641 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1642 pItem->cchTextMax);
1643 break;
1645 case this->LOGLIST_EMAIL:
1646 if (pLogEntry)
1647 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1648 break;
1650 case this->LOGLIST_COMMIT_NAME: //Commit
1651 if (pLogEntry)
1652 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1653 break;
1655 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1656 if (pLogEntry)
1657 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1658 break;
1660 case this->LOGLIST_COMMIT_DATE: //Commit Date
1661 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1662 lstrcpyn(pItem->pszText,
1663 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1664 pItem->cchTextMax);
1665 break;
1666 case this->LOGLIST_BUG: //Bug ID
1667 if(pLogEntry)
1668 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1669 break;
1670 case this->LOGLIST_SVNREV: //SVN revision
1671 if (pLogEntry)
1672 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1673 break;
1675 default:
1676 ASSERT(false);
1680 bool CGitLogListBase::IsOnStash(int index)
1682 GitRev *rev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index));
1683 if (IsStash(rev))
1684 return true;
1685 if (index > 0)
1687 GitRev *preRev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1));
1688 if (IsStash(preRev))
1689 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1691 return false;
1694 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1696 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1698 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1699 return true;
1701 return false;
1704 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1706 if (pRev->m_ParentHash.empty())
1710 pRev->GetParentFromHash(pRev->m_CommitHash);
1712 catch (const char* msg)
1714 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1717 parentHash = pRev->m_ParentHash;
1720 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1723 if (pWnd == GetHeaderCtrl())
1725 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1728 int selIndex = GetSelectionMark();
1729 if (selIndex < 0)
1730 return; // nothing selected, nothing to do with a context menu
1732 // if the user selected the info text telling about not all revisions shown due to
1733 // the "stop on copy/rename" option, we also don't show the context menu
1734 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1735 return;
1737 // if the context menu is invoked through the keyboard, we have to use
1738 // a calculated position on where to anchor the menu on
1739 if ((point.x == -1) && (point.y == -1))
1741 CRect rect;
1742 GetItemRect(selIndex, &rect, LVIR_LABEL);
1743 ClientToScreen(&rect);
1744 point = rect.CenterPoint();
1746 m_nSearchIndex = selIndex;
1747 m_bCancelled = FALSE;
1749 // calculate some information the context menu commands can use
1750 // CString pathURL = GetURLFromPath(m_path);
1752 POSITION pos = GetFirstSelectedItemPosition();
1753 int indexNext = GetNextSelectedItem(pos);
1754 if (indexNext < 0)
1755 return;
1757 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1758 if (pSelLogEntry == nullptr)
1759 return;
1760 #if 0
1761 GitRev revSelected = pSelLogEntry->Rev;
1762 GitRev revPrevious = git_revnum_t(revSelected)-1;
1763 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1765 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1767 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1768 if (changedpath->lCopyFromRev)
1769 revPrevious = changedpath->lCopyFromRev;
1772 GitRev revSelected2;
1773 if (pos)
1775 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1776 revSelected2 = pLogEntry->Rev;
1778 bool bAllFromTheSameAuthor = true;
1779 CString firstAuthor;
1780 CLogDataVector selEntries;
1781 GitRev revLowest, revHighest;
1782 GitRevRangeArray revisionRanges;
1784 POSITION pos = GetFirstSelectedItemPosition();
1785 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1786 revisionRanges.AddRevision(pLogEntry->Rev);
1787 selEntries.push_back(pLogEntry);
1788 firstAuthor = pLogEntry->sAuthor;
1789 revLowest = pLogEntry->Rev;
1790 revHighest = pLogEntry->Rev;
1791 while (pos)
1793 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1794 revisionRanges.AddRevision(pLogEntry->Rev);
1795 selEntries.push_back(pLogEntry);
1796 if (firstAuthor.Compare(pLogEntry->sAuthor))
1797 bAllFromTheSameAuthor = false;
1798 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1799 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1803 #endif
1805 int FirstSelect=-1, LastSelect=-1;
1806 pos = GetFirstSelectedItemPosition();
1807 FirstSelect = GetNextSelectedItem(pos);
1808 while(pos)
1810 LastSelect = GetNextSelectedItem(pos);
1812 //entry is selected, now show the popup menu
1813 CIconMenu popup;
1814 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1816 if (popup.CreatePopupMenu())
1818 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1819 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1820 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1821 bool isStash = IsOnStash(indexNext);
1822 GIT_REV_LIST parentHash;
1823 GetParentHashes(pSelLogEntry, parentHash);
1825 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1826 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1828 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1829 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1831 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1832 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1834 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1835 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1837 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)))
1838 popup.AppendMenu(MF_SEPARATOR, NULL);
1840 if (GetSelectedCount() == 1)
1843 bool requiresSeparator = false;
1844 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1846 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1848 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1849 requiresSeparator = true;
1852 else
1854 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1856 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1857 requiresSeparator = true;
1859 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1861 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1862 requiresSeparator = true;
1866 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1868 if (parentHash.size() == 1)
1870 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1871 requiresSeparator = true;
1873 else if (parentHash.size() > 1)
1875 blamemenu.CreatePopupMenu();
1876 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1877 for (size_t i = 0; i < parentHash.size(); ++i)
1879 CString str;
1880 str.Format(IDS_PARENT, i + 1);
1881 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1883 requiresSeparator = true;
1887 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1889 if (parentHash.size() == 1)
1891 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1892 requiresSeparator = true;
1894 else if (parentHash.size() > 1)
1896 gnudiffmenu.CreatePopupMenu();
1897 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1899 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1900 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1902 for (size_t i = 0; i < parentHash.size(); ++i)
1904 CString str;
1905 str.Format(IDS_PARENT, i + 1);
1906 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1908 requiresSeparator = true;
1912 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1914 if (parentHash.size() == 1)
1916 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1917 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1918 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1919 requiresSeparator = true;
1921 else if (parentHash.size() > 1)
1923 diffmenu.CreatePopupMenu();
1924 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1925 for (size_t i = 0; i < parentHash.size(); ++i)
1927 CString str;
1928 str.Format(IDS_PARENT, i + 1);
1929 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1930 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1932 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1933 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1936 requiresSeparator = true;
1940 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1942 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1943 requiresSeparator = true;
1946 if (requiresSeparator)
1947 popup.AppendMenu(MF_SEPARATOR, NULL);
1949 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1951 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1952 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1955 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1957 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1958 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1960 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1961 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1963 popup.AppendMenu(MF_SEPARATOR, NULL);
1966 if (pSelLogEntry->m_CommitHash.IsEmpty())
1968 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1969 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1971 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1972 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1974 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1975 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1977 popup.AppendMenu(MF_SEPARATOR, NULL);
1979 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1980 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1982 popup.AppendMenu(MF_SEPARATOR, NULL);
1986 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1987 // {
1988 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1989 // }
1990 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1991 // {
1992 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1993 // }
1994 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1995 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1996 // {
1997 // popup.AppendMenu(MF_SEPARATOR, NULL);
1998 // }
2000 CString str,format;
2001 //if (m_hasWC)
2002 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2004 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2006 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2007 GetSelectedCount() == 1)
2008 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2010 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2011 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2013 format.LoadString(IDS_LOG_POPUP_MERGEREV);
2014 str.Format(format,g_Git.GetCurrentBranch());
2016 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2017 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2019 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2020 str.Format(format,g_Git.GetCurrentBranch());
2022 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2023 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2026 // Add Switch Branch express Menu
2027 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2028 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2031 std::vector<CString *> branchs;
2032 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2034 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2035 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2037 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2041 CString str;
2042 str.LoadString(IDS_SWITCH_BRANCH);
2044 if(branchs.size() == 1)
2046 str+=_T(" ");
2047 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
2048 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
2050 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2053 else if(branchs.size() > 1)
2055 subbranchmenu.CreatePopupMenu();
2056 for (size_t i = 0 ; i < branchs.size(); ++i)
2058 if (*branchs[i] != currentBranch)
2060 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2061 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2065 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2069 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2070 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2072 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2073 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2075 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2076 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2078 format.LoadString(IDS_REBASE_THIS_FORMAT);
2079 str.Format(format,g_Git.GetCurrentBranch());
2081 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2082 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2083 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2085 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2086 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2088 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2090 if (parentHash.size() == 1)
2092 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2094 else if (parentHash.size() > 1)
2096 revertmenu.CreatePopupMenu();
2097 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2099 for (size_t i = 0; i < parentHash.size(); ++i)
2101 CString str;
2102 str.Format(IDS_PARENT, i + 1);
2103 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2108 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2109 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2111 popup.AppendMenu(MF_SEPARATOR, NULL);
2116 if(!pSelLogEntry->m_Ref.IsEmpty())
2118 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2119 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2120 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2121 popup.AppendMenu(MF_SEPARATOR, NULL);
2124 if (GetSelectedCount() >= 2)
2126 bool bAddSeparator = false;
2127 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2129 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2130 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2133 if (GetSelectedCount() == 2)
2135 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2136 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2138 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2140 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2141 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2142 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2143 CString menu;
2144 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2145 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2146 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2147 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2150 bAddSeparator = true;
2153 if (m_hasWC)
2155 bAddSeparator = true;
2158 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2159 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2161 if (bAddSeparator)
2162 popup.AppendMenu(MF_SEPARATOR, NULL);
2165 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2167 bool bAddSeparator = false;
2168 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2170 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2172 CString head;
2173 int headindex;
2174 headindex = this->GetHeadIndex();
2175 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2177 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2178 CGitHash hashFirst;
2179 if (g_Git.GetHash(hashFirst, head))
2180 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2181 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2182 CGitHash hash;
2183 if (g_Git.GetHash(hash, head))
2184 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2185 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect));
2186 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2187 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2188 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2189 bAddSeparator = true;
2194 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2195 if (GetSelectedCount() >= 2)
2196 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2197 else
2198 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2199 bAddSeparator = true;
2202 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2203 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2204 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2205 bAddSeparator = true;
2208 if (bAddSeparator)
2209 popup.AppendMenu(MF_SEPARATOR, NULL);
2212 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())
2214 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2215 popup.AppendMenu(MF_SEPARATOR, NULL);
2218 if (GetSelectedCount() == 1)
2220 bool bAddSeparator = false;
2221 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2223 // show the push-option only if the log entry has an associated local branch
2224 bool isLocal = false;
2225 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2227 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2228 isLocal = true;
2230 if (isLocal)
2232 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2233 bAddSeparator = true;
2236 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2238 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2239 bAddSeparator = true;
2243 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2245 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2247 std::vector<CString *> branchs;
2248 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2250 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2251 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2253 CString str;
2254 if (branchs.size() == 1)
2256 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2257 str+=_T(" ");
2258 str += *branchs[0];
2259 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2260 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2261 bAddSeparator = true;
2263 else if (branchs.size() > 1)
2265 str.LoadString(IDS_DELETE_BRANCHTAG);
2266 submenu.CreatePopupMenu();
2267 for (size_t i = 0; i < branchs.size(); ++i)
2269 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2270 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2273 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2274 bAddSeparator = true;
2277 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2278 if (bAddSeparator)
2279 popup.AppendMenu(MF_SEPARATOR, NULL);
2280 } // GetSelectedCount() == 1
2282 if (GetSelectedCount() != 0)
2284 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2285 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2286 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2287 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2288 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2289 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2292 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2293 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2295 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2296 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2298 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2299 // DialogEnableWindow(IDOK, FALSE);
2300 // SetPromptApp(&theApp);
2302 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2304 // EnableOKButton();
2305 } // if (popup.CreatePopupMenu())
2309 bool CGitLogListBase::IsSelectionContinuous()
2311 if ( GetSelectedCount()==1 )
2313 // if only one revision is selected, the selection is of course
2314 // continuous
2315 return true;
2318 POSITION pos = GetFirstSelectedItemPosition();
2319 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2320 if (bContinuous)
2322 int itemindex = GetNextSelectedItem(pos);
2323 while (pos)
2325 int nextindex = GetNextSelectedItem(pos);
2326 if (nextindex - itemindex > 1)
2328 bContinuous = false;
2329 break;
2331 itemindex = nextindex;
2334 return bContinuous;
2337 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2340 CString sClipdata;
2341 POSITION pos = GetFirstSelectedItemPosition();
2342 if (pos != NULL)
2344 CString sRev;
2345 sRev.LoadString(IDS_LOG_REVISION);
2346 CString sAuthor;
2347 sAuthor.LoadString(IDS_LOG_AUTHOR);
2348 CString sDate;
2349 sDate.LoadString(IDS_LOG_DATE);
2350 CString sMessage;
2351 sMessage.LoadString(IDS_LOG_MESSAGE);
2352 bool first = true;
2353 while (pos)
2355 CString sLogCopyText;
2356 CString sPaths;
2357 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2359 if (toCopy == ID_COPY_ALL)
2361 //pLogEntry->GetFiles(this)
2362 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2364 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2365 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2367 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2368 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2370 CString rename;
2371 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2372 sPaths += _T(" ") + rename;
2374 sPaths += _T("\r\n");
2376 sPaths.Trim();
2377 CString body = pLogEntry->GetBody();
2378 body.Replace(_T("\n"), _T("\r\n"));
2379 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"),
2380 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2381 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2382 (LPCTSTR)sDate,
2383 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2384 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2385 (LPCTSTR)sPaths);
2386 sClipdata += sLogCopyText;
2388 else if (toCopy == ID_COPY_MESSAGE)
2390 CString body = pLogEntry->GetBody();
2391 body.Replace(_T("\n"), _T("\r\n"));
2392 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2394 else if (toCopy == ID_COPY_SUBJECT)
2396 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2398 else
2400 if (!first)
2401 sClipdata += _T("\r\n");
2402 sClipdata += pLogEntry->m_CommitHash;
2405 first = false;
2407 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2412 void CGitLogListBase::DiffSelectedRevWithPrevious()
2414 if (m_bThreadRunning)
2415 return;
2417 int FirstSelect=-1, LastSelect=-1;
2418 POSITION pos = GetFirstSelectedItemPosition();
2419 FirstSelect = GetNextSelectedItem(pos);
2420 while(pos)
2422 LastSelect = GetNextSelectedItem(pos);
2425 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2427 #if 0
2428 UpdateLogInfoLabel();
2429 int selIndex = m_LogList.GetSelectionMark();
2430 if (selIndex < 0)
2431 return;
2432 int selCount = m_LogList.GetSelectedCount();
2433 if (selCount != 1)
2434 return;
2436 // Find selected entry in the log list
2437 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2438 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2439 long rev1 = pLogEntry->Rev;
2440 long rev2 = rev1-1;
2441 CTGitPath path = m_path;
2443 // See how many files under the relative root were changed in selected revision
2444 int nChanged = 0;
2445 LogChangedPath * changed = NULL;
2446 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2448 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2449 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2451 ++nChanged;
2452 changed = cpath;
2456 if (m_path.IsDirectory() && nChanged == 1)
2458 // We're looking at the log for a directory and only one file under dir was changed in the revision
2459 // Do diff on that file instead of whole directory
2460 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2463 m_bCancelled = FALSE;
2464 DialogEnableWindow(IDOK, FALSE);
2465 SetPromptApp(&theApp);
2466 theApp.DoWaitCursor(1);
2468 if (PromptShown())
2470 GitDiff diff(this, m_hWnd, true);
2471 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2472 diff.SetHEADPeg(m_LogRevision);
2473 diff.ShowCompare(path, rev2, path, rev1);
2475 else
2477 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2480 theApp.DoWaitCursor(-1);
2481 EnableOKButton();
2482 #endif
2485 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2487 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2488 *pResult = -1;
2490 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2491 return;
2492 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2493 return;
2494 if (pFindInfo->lvfi.psz == 0)
2495 return;
2496 #if 0
2497 CString sCmp = pFindInfo->lvfi.psz;
2498 CString sRev;
2499 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2501 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2502 sRev.Format(_T("%ld"), pLogEntry->Rev);
2503 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2505 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2507 *pResult = i;
2508 return;
2511 else
2513 if (sCmp.Compare(sRev)==0)
2515 *pResult = i;
2516 return;
2520 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2522 for (int i=0; i<pFindInfo->iStart; ++i)
2524 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2525 sRev.Format(_T("%ld"), pLogEntry->Rev);
2526 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2528 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2530 *pResult = i;
2531 return;
2534 else
2536 if (sCmp.Compare(sRev)==0)
2538 *pResult = i;
2539 return;
2544 #endif
2545 *pResult = -1;
2548 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2550 ClearText();
2552 this->m_arShownList.SafeRemoveAll();
2554 this->m_logEntries.ClearAll();
2555 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2556 return -1;
2558 //this->m_logEntries.ParserFromLog();
2559 SetItemCountEx((int)m_logEntries.size());
2561 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2563 if(m_IsOldFirst)
2565 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2566 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2569 else
2571 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2572 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2576 ReloadHashMap();
2578 if(path)
2579 m_Path=*path;
2580 return 0;
2584 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2586 ClearText();
2588 m_arShownList.SafeRemoveAll();
2590 m_logEntries.ClearAll();
2591 if (m_logEntries.Fill(hashes))
2592 return -1;
2594 SetItemCountEx((int)m_logEntries.size());
2596 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2598 if (m_IsOldFirst)
2600 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2601 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2603 else
2605 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2606 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2610 ReloadHashMap();
2612 return 0;
2615 int CGitLogListBase::BeginFetchLog()
2617 ClearText();
2619 this->m_arShownList.SafeRemoveAll();
2621 this->m_logEntries.ClearAll();
2623 this->m_LogCache.ClearAllParent();
2625 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2627 CTGitPath *path;
2628 if(this->m_Path.IsEmpty())
2629 path=NULL;
2630 else
2631 path=&this->m_Path;
2633 int mask;
2634 mask = CGit::LOG_INFO_ONLY_HASH;
2635 if (m_bIncludeBoundaryCommits)
2636 mask |= CGit::LOG_INFO_BOUNDARY;
2637 // if(this->m_bAllBranch)
2638 mask |= m_ShowMask ;
2640 if(m_bShowWC)
2642 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2643 ResetWcRev();
2644 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2647 if (m_sRange.IsEmpty())
2648 m_sRange = _T("HEAD");
2650 CFilterData data;
2651 data.m_From = m_From;
2652 data.m_To =m_To;
2654 #if 0 /* use tortoiegit filter */
2655 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2656 data.m_Author = this->m_sFilterText;
2658 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2659 data.m_MessageFilter = this->m_sFilterText;
2661 data.m_IsRegex = m_bFilterWithRegex;
2662 #endif
2664 // follow does not work for directories
2665 if (!path || path->IsDirectory())
2666 mask &= ~CGit::LOG_INFO_FOLLOW;
2667 // follow does not work with all branches 8at least in TGit)
2668 if (mask & CGit::LOG_INFO_FOLLOW)
2669 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2671 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2673 //this->m_logEntries.ParserFromLog();
2674 if(IsInWorkingThread())
2676 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2678 else
2680 SetItemCountEx((int)m_logEntries.size());
2685 [] { git_init(); } ();
2687 catch (char* msg)
2689 CString err(msg);
2690 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2691 return -1;
2694 if (!g_Git.CanParseRev(m_sRange))
2696 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2697 return 0;
2699 // if show all branches, pick any ref as dummy entry ref
2700 STRING_VECTOR list;
2701 if (g_Git.GetRefList(list))
2702 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2703 if (list.size() == 0)
2704 return 0;
2706 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2709 g_Git.m_critGitDllSec.Lock();
2710 try {
2711 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2713 g_Git.m_critGitDllSec.Unlock();
2714 return -1;
2717 catch (char* msg)
2719 g_Git.m_critGitDllSec.Unlock();
2720 CString err(msg);
2721 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2722 return -1;
2724 g_Git.m_critGitDllSec.Unlock();
2726 return 0;
2729 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2731 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2733 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2735 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2737 DiffSelectedRevWithPrevious();
2738 return TRUE;
2741 #if 0
2742 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2744 DiffSelectedFile();
2745 return TRUE;
2747 #endif
2749 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2751 // select all entries
2752 for (int i=0; i<GetItemCount(); ++i)
2754 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2756 return TRUE;
2759 #if 0
2760 if (m_hAccel && !bSkipAccelerator)
2762 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2763 if (ret)
2764 return TRUE;
2767 #endif
2768 //m_tooltips.RelayEvent(pMsg);
2769 return __super::PreTranslateMessage(pMsg);
2772 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2774 // a double click on an entry in the revision list has happened
2775 *pResult = 0;
2777 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2778 DiffSelectedRevWithPrevious();
2781 int CGitLogListBase::FetchLogAsync(void * data)
2783 ReloadHashMap();
2784 m_ProcData=data;
2785 m_bExitThread=FALSE;
2786 InterlockedExchange(&m_bThreadRunning, TRUE);
2787 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2788 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2789 if (m_LoadingThread ==NULL)
2791 InterlockedExchange(&m_bThreadRunning, FALSE);
2792 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2793 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2794 return -1;
2796 return 0;
2799 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2801 return ((CGitLogListBase*)pVoid)->LogThread();
2804 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2806 //CTime time;
2807 oldest=CTime::GetCurrentTime();
2808 latest=CTime(1971,1,2,0,0,0);
2809 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2811 if(m_logEntries[i].IsEmpty())
2812 continue;
2814 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2815 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2817 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2818 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2822 if(latest<oldest)
2823 latest=oldest;
2826 UINT CGitLogListBase::LogThread()
2828 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2830 InterlockedExchange(&m_bThreadRunning, TRUE);
2831 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2833 ULONGLONG t1,t2;
2835 if(BeginFetchLog())
2837 InterlockedExchange(&m_bThreadRunning, FALSE);
2838 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2840 return 1;
2843 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2844 bool bRegex = false;
2845 if (m_bFilterWithRegex)
2846 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2848 TRACE(_T("\n===Begin===\n"));
2849 //Update work copy item;
2851 if (!m_logEntries.empty())
2853 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2855 m_arShownList.SafeAdd(pRev);
2859 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2861 // store commit number of the last selected commit/line before the refresh or -1
2862 int lastSelectedHashNItem = -1;
2863 int ret = 0;
2865 bool shouldWalk = true;
2866 if (!g_Git.CanParseRev(m_sRange))
2868 // walk revisions if show all branches and there exists any ref
2869 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2870 shouldWalk = false;
2871 else
2873 STRING_VECTOR list;
2874 if (g_Git.GetRefList(list))
2875 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2876 if (list.size() == 0)
2877 shouldWalk = false;
2881 if (shouldWalk)
2883 g_Git.m_critGitDllSec.Lock();
2884 int total = 0;
2887 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2888 total = git_get_log_estimate_commit_count(m_DllGitLog);
2890 catch (char* msg)
2892 CString err(msg);
2893 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2894 ret = -1;
2896 g_Git.m_critGitDllSec.Unlock();
2898 GIT_COMMIT commit;
2899 t2=t1=GetTickCount();
2900 int oldprecentage = 0;
2901 size_t oldsize = m_logEntries.size();
2902 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2903 while (ret== 0 && !m_bExitThread)
2905 g_Git.m_critGitDllSec.Lock();
2908 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2910 catch (char* msg)
2912 g_Git.m_critGitDllSec.Unlock();
2913 CString err(msg);
2914 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2915 break;
2917 g_Git.m_critGitDllSec.Unlock();
2919 if(ret)
2921 if (ret != -2) // other than end of revision walking
2922 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2923 break;
2926 if (commit.m_ignore == 1)
2928 git_free_commit(&commit);
2929 continue;
2932 //printf("%s\r\n",commit.GetSubject());
2933 if(m_bExitThread)
2934 break;
2936 CGitHash hash = (char*)commit.m_hash ;
2938 GitRev *pRev = m_LogCache.GetCacheData(hash);
2939 pRev->m_GitCommit = commit;
2940 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2942 char *note=NULL;
2943 g_Git.m_critGitDllSec.Lock();
2946 git_get_notes(commit.m_hash, &note);
2948 catch (char* msg)
2950 g_Git.m_critGitDllSec.Unlock();
2951 CString err(msg);
2952 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2953 break;
2955 g_Git.m_critGitDllSec.Unlock();
2957 if(note)
2959 pRev->m_Notes.Empty();
2960 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2961 free(note);
2962 note = nullptr;
2965 if(!pRev->m_IsDiffFiles)
2967 pRev->m_CallDiffAsync = DiffAsync;
2970 pRev->ParserParentFromCommit(&commit);
2971 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2973 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2975 const CGitHash &parentHash = pRev->m_ParentHash[i];
2976 auto it = commitChildren.find(parentHash);
2977 if (it == commitChildren.end())
2979 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2981 it->second.insert(pRev->m_CommitHash);
2985 #ifdef DEBUG
2986 pRev->DbgPrint();
2987 TRACE(_T("\n"));
2988 #endif
2990 bool visible = true;
2991 if (HasFilterText())
2993 if(!IsMatchFilter(bRegex,pRev,pat))
2994 visible = false;
2996 if (visible && !ShouldShowFilter(pRev, commitChildren))
2997 visible = false;
2998 this->m_critSec.Lock();
2999 m_logEntries.append(hash, visible);
3000 if (visible)
3001 m_arShownList.SafeAdd(pRev);
3002 this->m_critSec.Unlock();
3004 if (!visible)
3005 continue;
3007 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3008 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3010 t2=GetTickCount();
3012 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3014 //update UI
3015 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3016 if(percent > 99)
3017 percent =99;
3018 if(percent < GITLOG_START)
3019 percent = GITLOG_START +1;
3021 oldsize = m_logEntries.size();
3022 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3024 //if( percent > oldprecentage )
3026 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3027 oldprecentage = percent;
3030 if (lastSelectedHashNItem >= 0)
3031 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3033 t1 = t2;
3036 g_Git.m_critGitDllSec.Lock();
3037 git_close_log(m_DllGitLog);
3038 g_Git.m_critGitDllSec.Unlock();
3042 if (m_bExitThread)
3044 InterlockedExchange(&m_bThreadRunning, FALSE);
3045 return 0;
3048 //Update UI;
3049 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3051 if (lastSelectedHashNItem >= 0)
3052 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3054 if (this->m_hWnd)
3055 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3057 InterlockedExchange(&m_bThreadRunning, FALSE);
3059 return 0;
3062 void CGitLogListBase::FetchRemoteList()
3064 STRING_VECTOR remoteList;
3065 if (!g_Git.GetRemoteList(remoteList))
3066 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3067 else
3068 m_SingleRemote = _T("");
3071 void CGitLogListBase::FetchTrackingBranchList()
3073 m_TrackingMap.clear();
3074 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3076 for (size_t j = 0; j < it->second.size(); ++j)
3078 CString branchName;
3079 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3081 CString pullRemote, pullBranch;
3082 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3083 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3085 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3092 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3094 SafeTerminateThread();
3096 this->SetItemCountEx(0);
3097 this->Clear();
3099 ResetWcRev();
3101 // HACK to hide graph column
3102 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3103 SetColumnWidth(0, 0);
3104 else
3105 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3107 //Update branch and Tag info
3108 ReloadHashMap();
3109 if (m_pFindDialog)
3110 m_pFindDialog->RefreshList();
3111 //Assume Thread have exited
3112 //if(!m_bThreadRunning)
3114 m_logEntries.clear();
3116 if(IsCleanFilter)
3118 m_sFilterText.Empty();
3119 m_From=-1;
3120 m_To=-1;
3123 InterlockedExchange(&m_bExitThread,FALSE);
3125 InterlockedExchange(&m_bThreadRunning, TRUE);
3126 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3127 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3129 InterlockedExchange(&m_bThreadRunning, FALSE);
3130 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3131 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3135 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3139 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3140 if (!bMatchCase)
3141 type |= std::tr1::regex_constants::icase;
3142 pat = std::tr1::wregex(regexp_str, type);
3143 return true;
3145 catch (std::exception) {}
3146 return false;
3148 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
3150 BOOL result = TRUE;
3151 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3152 CString sRev;
3154 if ((bRegex)&&(m_bFilterWithRegex))
3156 if (m_SelectedFilters & LOGFILTER_BUGID)
3158 if(this->m_bShowBugtraqColumn)
3160 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3162 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3163 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3165 return TRUE;
3170 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3172 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3173 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3175 return TRUE;
3179 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3181 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3182 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3184 return TRUE;
3188 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3190 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3192 return TRUE;
3195 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3197 return TRUE;
3201 if (m_SelectedFilters & LOGFILTER_EMAILS)
3203 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3205 return TRUE;
3208 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3210 return TRUE;
3214 if (m_SelectedFilters & LOGFILTER_REVS)
3216 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3217 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3219 return TRUE;
3223 if (m_SelectedFilters & LOGFILTER_REFNAME)
3225 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3226 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3228 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3230 return TRUE;
3235 if (m_SelectedFilters & LOGFILTER_PATHS)
3237 CTGitPathList *pathList=NULL;
3238 if( pRev->m_IsDiffFiles)
3239 pathList = &pRev->GetFiles(this);
3240 else
3242 if(!pRev->m_IsSimpleListReady)
3243 pRev->SafeGetSimpleList(&g_Git);
3246 if(pathList)
3247 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3249 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3251 return true;
3253 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3255 return true;
3259 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3261 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3263 return true;
3268 else
3270 CString find = m_sFilterText;
3271 if (!m_bFilterCaseSensitively)
3272 find.MakeLower();
3273 result = find[0] == '!' ? FALSE : TRUE;
3274 if (!result)
3275 find = find.Mid(1);
3277 if (m_SelectedFilters & LOGFILTER_BUGID)
3279 if(this->m_bShowBugtraqColumn)
3281 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3283 if (!m_bFilterCaseSensitively)
3284 sBugIds.MakeLower();
3285 if ((sBugIds.Find(find) >= 0))
3287 return result;
3292 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3294 CString msg = pRev->GetSubject();
3296 if (!m_bFilterCaseSensitively)
3297 msg = msg.MakeLower();
3298 if ((msg.Find(find) >= 0))
3300 return result;
3304 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3306 CString msg = pRev->GetBody();
3308 if (!m_bFilterCaseSensitively)
3309 msg = msg.MakeLower();
3310 if ((msg.Find(find) >= 0))
3312 return result;
3316 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3318 CString msg = pRev->GetAuthorName();
3319 if (!m_bFilterCaseSensitively)
3320 msg = msg.MakeLower();
3321 if ((msg.Find(find) >= 0))
3323 return result;
3327 if (m_SelectedFilters & LOGFILTER_EMAILS)
3329 CString msg = pRev->GetAuthorEmail();
3330 if (!m_bFilterCaseSensitively)
3331 msg = msg.MakeLower();
3332 if ((msg.Find(find) >= 0))
3334 return result;
3338 if (m_SelectedFilters & LOGFILTER_REVS)
3340 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3341 if ((sRev.Find(find) >= 0))
3343 return result;
3347 if (m_SelectedFilters & LOGFILTER_REFNAME)
3349 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3350 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3352 if (it->Find(find) >= 0)
3354 return result;
3359 if (m_SelectedFilters & LOGFILTER_PATHS)
3361 CTGitPathList *pathList=NULL;
3362 if( pRev->m_IsDiffFiles)
3363 pathList = &pRev->GetFiles(this);
3364 else
3366 if(!pRev->m_IsSimpleListReady)
3367 pRev->SafeGetSimpleList(&g_Git);
3369 if(pathList)
3370 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3372 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3373 CString path = cpath->GetGitOldPathString();
3374 if (!m_bFilterCaseSensitively)
3375 path.MakeLower();
3376 if ((path.Find(find)>=0))
3378 return result;
3380 path = cpath->GetGitPathString();
3381 if (!m_bFilterCaseSensitively)
3382 path.MakeLower();
3383 if ((path.Find(find)>=0))
3385 return result;
3389 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3391 CString path = pRev->m_SimpleFileList[i];
3392 if (!m_bFilterCaseSensitively)
3393 path.MakeLower();
3394 if ((path.Find(find)>=0))
3396 return result;
3400 } // else (from if (bRegex))
3401 return !result;
3404 static bool CStringStartsWith(const CString &str, const CString &prefix)
3406 return str.Left(prefix.GetLength()) == prefix;
3408 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3410 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3411 return true;
3413 if (m_ShowFilter & FILTERSHOW_REFS)
3415 // Keep all refs.
3416 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3417 for (size_t i = 0; i < refList.size(); ++i)
3419 const CString &str = refList[i];
3420 if (CStringStartsWith(str, _T("refs/heads/")))
3422 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3423 return true;
3425 else if (CStringStartsWith(str, _T("refs/remotes/")))
3427 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3428 return true;
3430 else if (CStringStartsWith(str, _T("refs/tags/")))
3432 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3433 return true;
3435 else if (CStringStartsWith(str, _T("refs/stash")))
3437 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3438 return true;
3440 else if (CStringStartsWith(str, _T("refs/bisect/")))
3442 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3443 return true;
3446 // Keep the head too.
3447 if (pRev->m_CommitHash == m_HeadHash)
3448 return true;
3451 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3453 if (pRev->ParentsCount() > 1)
3454 return true;
3455 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3456 if (childrenIt != commitChildren.end())
3458 const std::set<CGitHash> &children = childrenIt->second;
3459 if (children.size() > 1)
3460 return true;
3463 return false;
3466 void CGitLogListBase::ShowGraphColumn(bool bShow)
3468 // HACK to hide graph column
3469 if (bShow)
3470 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3471 else
3472 SetColumnWidth(0, 0);
3475 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3477 CString cmd;
3478 CString output;
3480 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3482 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3483 for (size_t i = 0; i < vector.size(); ++i)
3485 if (vector[i].Find(_T("refs/tags/")) == 0)
3487 CString tag = vector[i];
3488 int start = vector[i].Find(_T("^{}"));
3489 if (start > 0)
3490 tag = tag.Left(start);
3491 else
3492 continue;
3494 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3495 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3496 output.AppendChar(_T('\n'));
3501 return output;
3504 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3507 pShownlist->SafeRemoveAll();
3509 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3510 bool bRegex = false;
3511 if (m_bFilterWithRegex)
3512 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3514 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3515 CString sRev;
3516 for (DWORD i=0; i<m_logEntries.size(); ++i)
3518 if ((bRegex)&&(m_bFilterWithRegex))
3520 #if 0
3521 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3523 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3524 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3526 pShownlist->SafeAdd(m_logEntries[i]);
3527 continue;
3530 #endif
3531 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3533 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3534 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3536 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3537 continue;
3540 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3542 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3543 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3545 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3546 continue;
3549 if (m_SelectedFilters & LOGFILTER_PATHS)
3551 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3553 bool bGoing = true;
3554 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3556 CTGitPath cpath = pathList[cpPathIndex];
3557 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3559 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3560 bGoing = false;
3561 continue;
3563 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3565 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3566 bGoing = false;
3567 continue;
3569 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3571 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3572 bGoing = false;
3573 continue;
3577 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3579 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3581 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3582 continue;
3585 if (m_SelectedFilters & LOGFILTER_EMAILS)
3587 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3589 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3590 continue;
3593 if (m_SelectedFilters & LOGFILTER_REVS)
3595 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3596 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3598 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3599 continue;
3602 if (m_SelectedFilters & LOGFILTER_REFNAME)
3604 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3605 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3607 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3609 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3610 continue;
3614 } // if (bRegex)
3615 else
3617 CString find = m_sFilterText;
3618 if (!m_bFilterCaseSensitively)
3619 find.MakeLower();
3620 #if 0
3621 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3623 CString sBugIDs = m_logEntries[i]->sBugIDs;
3625 if (!m_bFilterCaseSensitively)
3626 sBugIDs = sBugIDs.MakeLower();
3627 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3629 pShownlist->SafeAdd(m_logEntries[i]);
3630 continue;
3633 #endif
3634 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3636 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3638 if (!m_bFilterCaseSensitively)
3639 msg = msg.MakeLower();
3640 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3642 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3643 continue;
3646 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3648 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3650 if (!m_bFilterCaseSensitively)
3651 msg = msg.MakeLower();
3652 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3654 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3655 continue;
3658 if (m_SelectedFilters & LOGFILTER_PATHS)
3660 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3662 bool bGoing = true;
3663 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3665 CTGitPath cpath = pathList[cpPathIndex];
3666 CString path = cpath.GetGitOldPathString();
3667 if (!m_bFilterCaseSensitively)
3668 path.MakeLower();
3669 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3671 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3672 bGoing = false;
3673 continue;
3675 path = cpath.GetGitPathString();
3676 if (!m_bFilterCaseSensitively)
3677 path.MakeLower();
3678 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3680 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3681 bGoing = false;
3682 continue;
3684 path = cpath.GetActionName();
3685 if (!m_bFilterCaseSensitively)
3686 path.MakeLower();
3687 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3689 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3690 bGoing = false;
3691 continue;
3695 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3697 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3698 if (!m_bFilterCaseSensitively)
3699 msg = msg.MakeLower();
3700 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3702 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3703 continue;
3706 if (m_SelectedFilters & LOGFILTER_EMAILS)
3708 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3709 if (!m_bFilterCaseSensitively)
3710 msg = msg.MakeLower();
3711 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3713 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3714 continue;
3717 if (m_SelectedFilters & LOGFILTER_REVS)
3719 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3720 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3722 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3723 continue;
3726 if (m_SelectedFilters & LOGFILTER_REFNAME)
3728 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3729 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3731 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3733 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3734 continue;
3738 } // else (from if (bRegex))
3739 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3743 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3746 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3748 if(m_From == -1)
3749 if(m_To == -1)
3750 return true;
3751 else
3752 return time <= m_To;
3753 else
3754 if(m_To == -1)
3755 return time >= m_From;
3756 else
3757 return ((time >= m_From)&&(time <= m_To));
3759 return TRUE; /* git dll will filter time range */
3761 // return TRUE;
3763 void CGitLogListBase::StartFilter()
3765 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3766 RecalculateShownList(&m_arShownList);
3767 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3770 DeleteAllItems();
3771 SetItemCountEx(ShownCountWithStopped());
3772 RedrawItems(0, ShownCountWithStopped());
3773 Invalidate();
3776 void CGitLogListBase::RemoveFilter()
3779 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3781 m_arShownList.SafeRemoveAll();
3783 // reset the time filter too
3784 #if 0
3785 m_timFrom = (__time64_t(m_tFrom));
3786 m_timTo = (__time64_t(m_tTo));
3787 m_DateFrom.SetTime(&m_timFrom);
3788 m_DateTo.SetTime(&m_timTo);
3789 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3790 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3791 #endif
3793 for (DWORD i=0; i<m_logEntries.size(); ++i)
3795 if(this->m_IsOldFirst)
3797 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3799 else
3801 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3804 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3805 DeleteAllItems();
3806 SetItemCountEx(ShownCountWithStopped());
3807 RedrawItems(0, ShownCountWithStopped());
3809 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3812 void CGitLogListBase::Clear()
3814 m_arShownList.SafeRemoveAll();
3815 DeleteAllItems();
3817 m_logEntries.ClearAll();
3821 void CGitLogListBase::OnDestroy()
3823 // save the column widths to the registry
3824 SaveColumnWidths();
3826 SafeTerminateThread();
3827 SafeTerminateAsyncDiffThread();
3829 int retry = 0;
3830 while(m_LogCache.SaveCache())
3832 if(retry > 5)
3833 break;
3834 Sleep(1000);
3836 ++retry;
3838 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3839 // MB_YESNO) == IDNO)
3840 // break;
3843 CHintListCtrl::OnDestroy();
3846 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3848 CRect rect;
3849 int i=(int)wParam;
3850 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3851 this->InvalidateRect(rect);
3853 return 0;
3857 * Save column widths to the registry
3859 void CGitLogListBase::SaveColumnWidths()
3861 int maxcol = m_ColumnManager.GetColumnCount();
3863 // HACK that graph column is always shown
3864 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3866 for (int col = 0; col < maxcol; ++col)
3867 if (m_ColumnManager.IsVisible (col))
3868 m_ColumnManager.ColumnResized (col);
3870 m_ColumnManager.WriteSettings();
3873 int CGitLogListBase::GetHeadIndex()
3875 if(m_HeadHash.IsEmpty())
3876 return -1;
3878 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3880 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3881 if(pRev)
3883 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3884 return i;
3887 return -1;
3889 void CGitLogListBase::OnFind()
3891 if (!m_pFindDialog)
3893 m_pFindDialog = new CFindDlg(this);
3894 m_pFindDialog->Create(this);
3897 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3899 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3901 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3903 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3904 Default();
3906 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3908 if (GetSelectedCount() != 0)
3909 return 0;
3911 CGitHash theSelectedHash = m_lastSelectedHash;
3912 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3913 m_lastSelectedHash = theSelectedHash;
3915 int countPerPage = GetCountPerPage();
3916 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3917 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3918 EnsureVisible((int)itemToSelect, FALSE);
3919 return 0;
3921 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3924 ASSERT(m_pFindDialog != NULL);
3925 bool bFound = false;
3926 int i=0;
3928 if (m_pFindDialog->IsTerminating())
3930 // invalidate the handle identifying the dialog box.
3931 m_pFindDialog = NULL;
3932 return 0;
3935 INT_PTR cnt = m_arShownList.GetCount();
3937 if(m_pFindDialog->IsRef())
3939 CString str;
3940 str=m_pFindDialog->GetFindString();
3942 CGitHash hash;
3944 if(!str.IsEmpty())
3946 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3947 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3950 if(!hash.IsEmpty())
3952 for (i = 0; i < cnt; ++i)
3954 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3955 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3957 bFound = true;
3958 break;
3962 if (!bFound)
3964 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3965 return 0;
3969 if (m_pFindDialog->FindNext() && !bFound)
3971 //read data from dialog
3972 CString findText = m_pFindDialog->GetFindString();
3973 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3975 std::tr1::wregex pat;
3976 bool bRegex = false;
3977 if (m_pFindDialog->Regex())
3978 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3980 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3982 for (i = m_nSearchIndex + 1; ; ++i)
3984 if (i >= cnt)
3986 i = 0;
3987 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3989 if (m_nSearchIndex >= 0)
3991 if (i == m_nSearchIndex)
3993 ::MessageBeep(0xFFFFFFFF);
3994 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3995 break;
3999 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4001 CString str;
4002 str+=pLogEntry->m_CommitHash.ToString();
4003 str+=_T("\n");
4005 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4007 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4008 str+=_T("\n");
4011 str+=pLogEntry->GetAuthorEmail();
4012 str+=_T("\n");
4013 str+=pLogEntry->GetAuthorName();
4014 str+=_T("\n");
4015 str+=pLogEntry->GetBody();
4016 str+=_T("\n");
4017 str+=pLogEntry->GetCommitterEmail();
4018 str+=_T("\n");
4019 str+=pLogEntry->GetCommitterName();
4020 str+=_T("\n");
4021 str+=pLogEntry->GetSubject();
4022 str+=_T("\n");
4023 str+=pLogEntry->m_Notes;
4024 str+=_T("\n");
4025 str+=GetTagInfo(pLogEntry);
4026 str+=_T("\n");
4029 /*Because changed files list is loaded on demand when gui show,
4030 files will empty when files have not fetched.
4032 we can add it back by using one-way diff(with outnumber changed and rename detect.
4033 here just need changed filename list. one-way is much quicker.
4035 if(pLogEntry->m_IsFull)
4037 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
4039 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
4040 str+=_T("\n");
4041 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
4042 str+=_T("\n");
4045 else
4047 if(!pLogEntry->m_IsSimpleListReady)
4048 pLogEntry->SafeGetSimpleList(&g_Git);
4050 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
4052 str+=pLogEntry->m_SimpleFileList[i];
4053 str+=_T("\n");
4059 if (bRegex)
4061 if (std::regex_search(std::wstring(str), pat, flags))
4063 bFound = true;
4064 break;
4067 else
4069 if (bMatchCase)
4071 if (str.Find(findText) >= 0)
4073 bFound = true;
4074 break;
4078 else
4080 CString msg = str;
4081 msg = msg.MakeLower();
4082 CString find = findText.MakeLower();
4083 if (msg.Find(find) >= 0)
4085 bFound = TRUE;
4086 break;
4090 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4092 } // if(m_pFindDialog->FindNext())
4093 //UpdateLogInfoLabel();
4095 if (bFound)
4097 m_nSearchIndex = i;
4098 EnsureVisible(i, FALSE);
4099 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4101 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4102 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4103 SetSelectionMark(i);
4105 else
4107 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4108 if (pLogEntry)
4109 m_highlight = pLogEntry->m_CommitHash;
4111 Invalidate();
4112 //FillLogMessageCtrl();
4113 UpdateData(FALSE);
4116 return 0;
4119 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4121 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4123 *pResult = FALSE;
4126 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4128 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4130 Invalidate(FALSE);