Make sure member variables are initialized correctly
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobcc64a7bfd8b878390fe7fd649507743ee97f1417
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 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
158 if (hUxTheme)
159 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
161 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
162 if (m_DiffingThread ==NULL)
164 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
165 return;
170 int CGitLogListBase::AsyncDiffThread()
172 m_AsyncThreadExited = false;
173 while(!m_AsyncThreadExit)
175 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
177 GitRev *pRev = NULL;
178 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
180 m_AsynDiffListLock.Lock();
181 pRev = m_AsynDiffList.back();
182 m_AsynDiffList.pop_back();
183 m_AsynDiffListLock.Unlock();
185 if( pRev->m_CommitHash.IsEmpty() )
187 if(pRev->m_IsDiffFiles)
188 continue;
190 pRev->GetFiles(this).Clear();
191 pRev->m_ParentHash.clear();
192 pRev->m_ParentHash.push_back(m_HeadHash);
193 if(g_Git.IsInitRepos())
195 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
196 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
199 else
201 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
203 int dummyAction = 0;
204 int *action = &dummyAction;
205 SafeGetAction(pRev, &action);
206 *action = 0;
208 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
209 *action |= pRev->GetFiles(this)[j].m_Action;
211 CString err;
212 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
214 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
215 return -1;
218 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
219 InterlockedExchange(&pRev->m_IsFull, TRUE);
221 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
222 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
223 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
226 m_critSec_AsyncDiff.Lock();
227 int ret = pRev->CheckAndDiff();
228 m_critSec_AsyncDiff.Unlock();
229 if (!ret)
230 { // fetch change file list
231 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
233 if(i < m_arShownList.GetCount())
235 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
236 if(data->m_CommitHash == pRev->m_CommitHash)
238 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
239 break;
244 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
246 POSITION pos = GetFirstSelectedItemPosition();
247 int nItem = GetNextSelectedItem(pos);
249 if(nItem>=0)
251 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(nItem);
252 if(data)
253 if(data->m_CommitHash == pRev->m_CommitHash)
255 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
262 m_AsyncThreadExited = true;
263 return 0;
265 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
267 if (exclusivelyShow)
269 m_ContextMenuMask &= hideMask;
271 else
273 m_ContextMenuMask &= ~hideMask;
277 CGitLogListBase::~CGitLogListBase()
279 InterlockedExchange(&m_bNoDispUpdates, TRUE);
280 this->m_arShownList.SafeRemoveAll();
282 DestroyIcon(m_hModifiedIcon);
283 DestroyIcon(m_hReplacedIcon);
284 DestroyIcon(m_hAddedIcon);
285 DestroyIcon(m_hDeletedIcon);
286 m_logEntries.ClearAll();
288 if (m_boldFont)
289 DeleteObject(m_boldFont);
291 if (m_FontItalics)
292 DeleteObject(m_FontItalics);
294 if (m_boldItalicsFont)
295 DeleteObject(m_boldItalicsFont);
297 if ( m_pStoreSelection )
299 delete m_pStoreSelection;
300 m_pStoreSelection = NULL;
303 SafeTerminateThread();
304 SafeTerminateAsyncDiffThread();
306 if(m_AsyncDiffEvent)
307 CloseHandle(m_AsyncDiffEvent);
309 if (hUxTheme)
310 FreeLibrary(hUxTheme);
314 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
315 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
316 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
317 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
318 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
319 ON_WM_CONTEXTMENU()
320 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
321 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
322 ON_WM_CREATE()
323 ON_WM_DESTROY()
324 ON_MESSAGE(MSG_LOADED,OnLoad)
325 ON_WM_MEASUREITEM()
326 ON_WM_MEASUREITEM_REFLECT()
327 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
328 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
329 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
330 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
331 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
332 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
333 END_MESSAGE_MAP()
335 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
337 //if (m_nRowHeight>0)
339 lpMeasureItemStruct->itemHeight = 50;
343 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
345 PreSubclassWindow();
346 return CHintListCtrl::OnCreate(lpCreateStruct);
349 void CGitLogListBase::PreSubclassWindow()
351 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
352 // load the icons for the action columns
353 // m_Theme.Open(m_hWnd, L"ListView");
354 SetWindowTheme(m_hWnd, L"Explorer", NULL);
355 CHintListCtrl::PreSubclassWindow();
358 CString CGitLogListBase::GetRebaseActionName(int action)
360 if (action & LOGACTIONS_REBASE_EDIT)
361 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
362 if (action & LOGACTIONS_REBASE_SQUASH)
363 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
364 if (action & LOGACTIONS_REBASE_PICK)
365 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
366 if (action & LOGACTIONS_REBASE_SKIP)
367 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
369 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
372 void CGitLogListBase::InsertGitColumn()
374 CString temp;
376 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
377 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
378 if (DWORD(regFullRowSelect))
379 exStyle |= LVS_EX_FULLROWSELECT;
380 SetExtendedStyle(exStyle);
382 // only load properties if we have a repository
383 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
384 UpdateProjectProperties();
386 static UINT normal[] =
388 IDS_LOG_GRAPH,
389 IDS_LOG_REBASE,
390 IDS_LOG_ID,
391 IDS_LOG_HASH,
392 IDS_LOG_ACTIONS,
393 IDS_LOG_MESSAGE,
394 IDS_LOG_AUTHOR,
395 IDS_LOG_DATE,
396 IDS_LOG_EMAIL,
397 IDS_LOG_COMMIT_NAME,
398 IDS_LOG_COMMIT_EMAIL,
399 IDS_LOG_COMMIT_DATE,
400 IDS_LOG_BUGIDS,
401 IDS_LOG_SVNREV,
404 static int with[] =
406 ICONITEMBORDER+16*4,
407 ICONITEMBORDER+16*4,
408 ICONITEMBORDER+16*4,
409 ICONITEMBORDER+16*4,
410 ICONITEMBORDER+16*4,
411 LOGLIST_MESSAGE_MIN,
412 ICONITEMBORDER+16*4,
413 ICONITEMBORDER+16*4,
414 ICONITEMBORDER+16*4,
415 ICONITEMBORDER+16*4,
416 ICONITEMBORDER+16*4,
417 ICONITEMBORDER+16*4,
418 ICONITEMBORDER+16*4,
419 ICONITEMBORDER+16*4,
421 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
423 DWORD hideColumns = 0;
424 if(this->m_IsRebaseReplaceGraph)
426 hideColumns |= GIT_LOG_GRAPH;
427 m_dwDefaultColumns |= GIT_LOG_REBASE;
429 else
431 hideColumns |= GIT_LOG_REBASE;
434 if(this->m_IsIDReplaceAction)
436 hideColumns |= GIT_LOG_ACTIONS;
437 m_dwDefaultColumns |= GIT_LOG_ID;
438 m_dwDefaultColumns |= GIT_LOG_HASH;
440 else
442 hideColumns |= GIT_LOG_ID;
444 if(this->m_bShowBugtraqColumn)
446 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
448 else
450 hideColumns |= GIT_LOGLIST_BUG;
452 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
453 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
454 else
455 hideColumns |= GIT_LOGLIST_SVNREV;
456 SetRedraw(false);
458 m_ColumnManager.SetNames(normal, _countof(normal));
459 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
461 SetRedraw(true);
465 * Resizes all columns in a list control to values in registry.
467 void CGitLogListBase::ResizeAllListCtrlCols()
469 // column max and min widths to allow
470 static const int nMinimumWidth = 10;
471 static const int nMaximumWidth = 1000;
472 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
473 if (pHdrCtrl)
475 int numcols = pHdrCtrl->GetItemCount();
476 for (int col = 0; col < numcols; ++col)
478 // get width for this col last time from registry
479 CString regentry;
480 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
481 CRegDWORD regwidth(regentry, 0);
482 int cx = regwidth;
483 if ( cx == 0 )
485 // no saved value, setup sensible defaults
486 if (col == this->LOGLIST_MESSAGE)
488 cx = LOGLIST_MESSAGE_MIN;
490 else
492 cx = ICONITEMBORDER+16*4;
495 if (cx < nMinimumWidth)
497 cx = nMinimumWidth;
499 else if (cx > nMaximumWidth)
501 cx = nMaximumWidth;
504 SetColumnWidth(col, cx);
511 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
513 LVITEM rItem;
514 SecureZeroMemory(&rItem, sizeof(LVITEM));
515 rItem.mask = LVIF_STATE;
516 rItem.iItem = (int)Index;
517 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
518 GetItem(&rItem);
520 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
521 HBRUSH brush = NULL;
523 if (!(rItem.state & LVIS_SELECTED))
525 int action = pLogEntry->GetRebaseAction();
526 if (action & LOGACTIONS_REBASE_SQUASH)
527 brush = ::CreateSolidBrush(RGB(156,156,156));
528 else if (action & LOGACTIONS_REBASE_EDIT)
529 brush = ::CreateSolidBrush(RGB(200,200,128));
531 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
533 if (rItem.state & LVIS_SELECTED)
535 if (::GetFocus() == m_hWnd)
536 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
537 else
538 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
541 if (brush != NULL)
543 ::FillRect(hdc, &rect, brush);
544 ::DeleteObject(brush);
548 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
550 POINT point = { 4, 4 };
551 CRect rt2 = rect;
552 rt2.DeflateRect(1, 1);
553 rt2.OffsetRect(2, 2);
555 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
556 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
557 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
558 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
559 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
561 ::SelectObject(hdc, brush);
562 rt2.OffsetRect(-2, -2);
563 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
564 ::SelectObject(hdc, oldbrush);
565 ::SelectObject(hdc, oldpen);
566 ::DeleteObject(nullPen);
567 ::DeleteObject(darkBrush);
570 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
572 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
573 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
574 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
575 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
576 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
577 ::LineTo(hdc, rect.left, rect.bottom);
578 ::SelectObject(hdc, oldpen);
579 ::DeleteObject(pen);
582 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
584 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
585 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
586 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
587 ::LineTo(hdc, rect.left, rect.bottom);
588 ::LineTo(hdc, rect.right, rect.bottom);
589 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
590 ::SelectObject(hdc, oldpen);
591 ::DeleteObject(pen);
594 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
596 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
597 CRect rt=rect;
598 LVITEM rItem;
599 SecureZeroMemory(&rItem, sizeof(LVITEM));
600 rItem.mask = LVIF_STATE;
601 rItem.iItem = (int)index;
602 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
603 GetItem(&rItem);
605 CDC W_Dc;
606 W_Dc.Attach(hdc);
608 HTHEME hTheme = NULL;
609 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
610 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
612 SIZE oneSpaceSize;
613 if (m_bTagsBranchesOnRightSide)
615 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
616 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
617 SelectObject(hdc, oldFont);
618 rt.left += oneSpaceSize.cx * 2;
620 else
622 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
623 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
624 rt.left += oneSpaceSize.cx;
627 if (IsAppThemed() && pfnDrawThemeTextEx)
629 int txtState = LISS_NORMAL;
630 if (rItem.state & LVIS_SELECTED)
631 txtState = LISS_SELECTED;
633 DTTOPTS opts = { 0 };
634 opts.dwSize = sizeof(opts);
635 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
636 opts.dwFlags = DTT_TEXTCOLOR;
637 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
639 else
641 if (rItem.state & LVIS_SELECTED)
643 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
644 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
645 ::SetTextColor(hdc, clrOld);
647 else
649 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
650 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
651 ::SetTextColor(hdc, clrOld);
655 if (m_bTagsBranchesOnRightSide)
657 SIZE size;
658 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
660 rt.left += oneSpaceSize.cx + size.cx;
662 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
665 if (hTheme)
666 CloseThemeData(hTheme);
668 W_Dc.Detach();
671 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
673 for (unsigned int i = 0; i < refList.size(); ++i)
675 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
676 HBRUSH brush = 0;
677 COLORREF colRef = refList[i].color;
678 bool singleRemote = refList[i].singleRemote;
679 bool hasTracking = refList[i].hasTracking;
680 bool sameName = refList[i].sameName;
681 bool annotatedTag = refList[i].annotatedTag;
683 //When row selected, ajust label color
684 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
686 if (rItem.state & LVIS_SELECTED)
687 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
690 brush = ::CreateSolidBrush(colRef);
692 if (!shortname.IsEmpty() && (rt.left < rect.right))
694 SIZE size;
695 memset(&size,0,sizeof(SIZE));
696 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
698 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
699 rt.right += 8;
701 int textpos = DT_CENTER;
703 if (rt.right > rect.right)
705 rt.right = rect.right;
706 textpos = 0;
709 CRect textRect = rt;
711 if (singleRemote)
713 rt.right += 8;
714 textRect.OffsetRect(8, 0);
717 if (sameName)
718 rt.right += 8;
720 if (hasTracking)
722 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
724 else
726 //Fill interior of ref label
727 ::FillRect(hdc, &rt, brush);
730 //Draw edge of label
731 CRect rectEdge = rt;
733 if (!hasTracking)
735 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
736 rectEdge.DeflateRect(1, 1);
737 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
740 if (annotatedTag)
742 rt.right += 8;
743 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
744 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
745 ::FillRgn(hdc, hrgn, brush);
746 ::DeleteObject(hrgn);
747 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
748 HPEN pen;
749 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
750 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
751 ::DeleteObject(pen);
752 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
753 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
754 ::DeleteObject(pen);
755 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
756 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
757 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
758 ::DeleteObject(pen);
759 SelectObject(hdc, oldpen);
762 //Draw text inside label
763 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
764 if (!customColor && IsAppThemed() && pfnDrawThemeTextEx)
766 int txtState = LISS_NORMAL;
767 if (rItem.state & LVIS_SELECTED)
768 txtState = LISS_SELECTED;
770 DTTOPTS opts = { 0 };
771 opts.dwSize = sizeof(opts);
772 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
773 opts.dwFlags = DTT_TEXTCOLOR;
774 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
776 else
778 W_Dc.SetBkMode(TRANSPARENT);
779 if (customColor || (rItem.state & LVIS_SELECTED))
781 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
782 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
783 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
784 ::SetTextColor(hdc,clrOld);
786 else
788 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
789 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
790 ::SetTextColor(hdc, clrOld);
794 if (singleRemote)
796 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
797 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
798 CRect newRect;
799 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
800 DrawLightning(hdc, newRect, color, bold);
803 if (sameName)
805 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
806 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
807 CRect newRect;
808 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
809 DrawUpTriangle(hdc, newRect, color, bold);
812 rt.left = rt.right + 1;
814 if (brush)
815 ::DeleteObject(brush);
817 rt.right = rect.right;
820 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
822 // Returns ((256 - amount)*col1 + amount*col2) / 256;
823 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
824 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
825 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
828 Gdiplus::Color GetGdiColor(COLORREF col)
830 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
832 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
833 const COLORREF& col,const COLORREF& activeColor, int top
836 int h = laneHeight / 2;
837 int m = (x1 + x2) / 2;
838 int r = (x2 - x1) * m_NodeSize / 30;
839 int d = 2 * r;
841 #define P_CENTER m , h+top
842 #define P_0 x2, h+top
843 #define P_90 m , 0+top-1
844 #define P_180 x1, h+top
845 #define P_270 m , 2 * h+top +1
846 #define R_CENTER m - r, h - r+top, d, d
849 #define DELTA_UR_B 2*(x1 - m), 2*h +top
850 #define DELTA_UR_E 0*16, 90*16 +top // -,
852 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
853 #define DELTA_DR_E 270*16, 90*16 +top // -'
855 #define DELTA_UL_B 2*(x2 - m), 2*h +top
856 #define DELTA_UL_E 90*16, 90*16 +top // ,-
858 #define DELTA_DL_B 2*(x2 - m),2*-h +top
859 #define DELTA_DL_E 180*16, 90*16 // '-
861 #define CENTER_UR x1, 2*h, 225
862 #define CENTER_DR x1, 0 , 135
863 #define CENTER_UL x2, 2*h, 315
864 #define CENTER_DL x2, 0 , 45
867 Gdiplus::Graphics graphics( hdc );
869 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
871 // arc
872 switch (type) {
873 case Lanes::JOIN:
874 case Lanes::JOIN_R:
875 case Lanes::HEAD:
876 case Lanes::HEAD_R:
878 Gdiplus::LinearGradientBrush gradient(
879 Gdiplus::Point(x1-2, h+top-2),
880 Gdiplus::Point(P_270),
881 GetGdiColor(activeColor),GetGdiColor(col));
884 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
885 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
887 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
888 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
889 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
891 break;
893 case Lanes::JOIN_L:
896 Gdiplus::LinearGradientBrush gradient(
897 Gdiplus::Point(P_270),
898 Gdiplus::Point(x2+1, h+top-1),
899 GetGdiColor(col),GetGdiColor(activeColor));
902 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
903 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
905 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
906 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
907 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
910 break;
912 case Lanes::TAIL:
913 case Lanes::TAIL_R:
916 Gdiplus::LinearGradientBrush gradient(
917 Gdiplus::Point(x1-2, h+top-2),
918 Gdiplus::Point(P_90),
919 GetGdiColor(activeColor),GetGdiColor(col));
921 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
923 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
925 #if 0
926 QConicalGradient gradient(CENTER_DR);
927 gradient.setColorAt(0.375, activeCol);
928 gradient.setColorAt(0.625, col);
929 myPen.setBrush(gradient);
930 p->setPen(myPen);
931 p->drawArc(P_CENTER, DELTA_DR);
932 #endif
933 break;
935 default:
936 break;
940 //static QPen myPen(Qt::black, 2); // fast path here
941 CPen pen;
942 pen.CreatePen(PS_SOLID,2,col);
943 //myPen.setColor(col);
944 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
946 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
948 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
950 //p->setPen(myPen);
952 // vertical line
953 switch (type) {
954 case Lanes::ACTIVE:
955 case Lanes::NOT_ACTIVE:
956 case Lanes::MERGE_FORK:
957 case Lanes::MERGE_FORK_R:
958 case Lanes::MERGE_FORK_L:
959 case Lanes::JOIN:
960 case Lanes::JOIN_R:
961 case Lanes::JOIN_L:
962 case Lanes::CROSS:
963 //DrawLine(hdc,P_90,P_270);
964 graphics.DrawLine(&myPen,P_90,P_270);
965 //p->drawLine(P_90, P_270);
966 break;
967 case Lanes::HEAD_L:
968 case Lanes::BRANCH:
969 //DrawLine(hdc,P_CENTER,P_270);
970 graphics.DrawLine(&myPen,P_CENTER,P_270);
971 //p->drawLine(P_CENTER, P_270);
972 break;
973 case Lanes::TAIL_L:
974 case Lanes::INITIAL:
975 case Lanes::BOUNDARY:
976 case Lanes::BOUNDARY_C:
977 case Lanes::BOUNDARY_R:
978 case Lanes::BOUNDARY_L:
979 //DrawLine(hdc,P_90, P_CENTER);
980 graphics.DrawLine(&myPen,P_90,P_CENTER);
981 //p->drawLine(P_90, P_CENTER);
982 break;
983 default:
984 break;
987 myPen.SetColor(GetGdiColor(activeColor));
989 // horizontal line
990 switch (type) {
991 case Lanes::MERGE_FORK:
992 case Lanes::JOIN:
993 case Lanes::HEAD:
994 case Lanes::TAIL:
995 case Lanes::CROSS:
996 case Lanes::CROSS_EMPTY:
997 case Lanes::BOUNDARY_C:
998 //DrawLine(hdc,P_180,P_0);
999 graphics.DrawLine(&myPen,P_180,P_0);
1000 //p->drawLine(P_180, P_0);
1001 break;
1002 case Lanes::MERGE_FORK_R:
1003 case Lanes::BOUNDARY_R:
1004 //DrawLine(hdc,P_180,P_CENTER);
1005 graphics.DrawLine(&myPen,P_180,P_CENTER);
1006 //p->drawLine(P_180, P_CENTER);
1007 break;
1008 case Lanes::MERGE_FORK_L:
1009 case Lanes::HEAD_L:
1010 case Lanes::TAIL_L:
1011 case Lanes::BOUNDARY_L:
1012 //DrawLine(hdc,P_CENTER,P_0);
1013 graphics.DrawLine(&myPen,P_CENTER,P_0);
1014 //p->drawLine(P_CENTER, P_0);
1015 break;
1016 default:
1017 break;
1020 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1022 CBrush brush;
1023 brush.CreateSolidBrush(col);
1024 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1026 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1027 // center symbol, e.g. rect or ellipse
1028 switch (type) {
1029 case Lanes::ACTIVE:
1030 case Lanes::INITIAL:
1031 case Lanes::BRANCH:
1033 //p->setPen(Qt::NoPen);
1034 //p->setBrush(col);
1035 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1036 graphics.FillEllipse(&myBrush, R_CENTER);
1037 //p->drawEllipse(R_CENTER);
1038 break;
1039 case Lanes::MERGE_FORK:
1040 case Lanes::MERGE_FORK_R:
1041 case Lanes::MERGE_FORK_L:
1042 //p->setPen(Qt::NoPen);
1043 //p->setBrush(col);
1044 //p->drawRect(R_CENTER);
1045 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1046 graphics.FillRectangle(&myBrush, R_CENTER);
1047 break;
1048 case Lanes::UNAPPLIED:
1049 // Red minus sign
1050 //p->setPen(Qt::NoPen);
1051 //p->setBrush(Qt::red);
1052 //p->drawRect(m - r, h - 1, d, 2);
1053 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1054 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1055 break;
1056 case Lanes::APPLIED:
1057 // Green plus sign
1058 //p->setPen(Qt::NoPen);
1059 //p->setBrush(DARK_GREEN);
1060 //p->drawRect(m - r, h - 1, d, 2);
1061 //p->drawRect(m - 1, h - r, 2, d);
1062 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1063 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1064 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1065 break;
1066 case Lanes::BOUNDARY:
1067 //p->setBrush(back);
1068 //p->drawEllipse(R_CENTER);
1069 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1070 graphics.DrawEllipse(&myPen, R_CENTER);
1071 break;
1072 case Lanes::BOUNDARY_C:
1073 case Lanes::BOUNDARY_R:
1074 case Lanes::BOUNDARY_L:
1075 //p->setBrush(back);
1076 //p->drawRect(R_CENTER);
1077 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1078 graphics.FillRectangle(&myBrush,R_CENTER);
1079 break;
1080 default:
1081 break;
1084 ::SelectObject(hdc,oldpen);
1085 ::SelectObject(hdc,oldbrush);
1086 #undef P_CENTER
1087 #undef P_0
1088 #undef P_90
1089 #undef P_180
1090 #undef P_270
1091 #undef R_CENTER
1094 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1096 // TODO: unfinished
1097 // return;
1098 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1099 if(data->m_CommitHash.IsEmpty())
1100 return;
1102 CRect rt=rect;
1103 LVITEM rItem;
1104 SecureZeroMemory(&rItem, sizeof(LVITEM));
1105 rItem.mask = LVIF_STATE;
1106 rItem.iItem = (int)index;
1107 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1108 GetItem(&rItem);
1110 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1112 if (data->m_Lanes.empty())
1113 m_logEntries.setLane(data->m_CommitHash);
1115 std::vector<int>& lanes=data->m_Lanes;
1116 size_t laneNum = lanes.size();
1117 UINT activeLane = 0;
1118 for (UINT i = 0; i < laneNum; ++i)
1119 if (Lanes::isMerge(lanes[i])) {
1120 activeLane = i;
1121 break;
1124 int x2 = 0;
1125 int maxWidth = rect.Width();
1126 int lw = 3 * rect.Height() / 4; //laneWidth()
1128 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1129 //if (opt.state & QStyle::State_Selected)
1130 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1132 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1135 int x1 = x2;
1136 x2 += lw;
1138 int ln = lanes[i];
1139 if (ln == Lanes::EMPTY)
1140 continue;
1142 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1143 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1146 #if 0
1147 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1149 int x1 = x2;
1150 x2 += lw;
1152 int ln = lanes[i];
1153 if (ln == Lanes::EMPTY)
1154 continue;
1156 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1157 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1159 if (ln == Lanes::CROSS)
1161 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1162 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1164 else
1165 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1167 #endif
1171 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1174 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1175 // Take the default processing unless we set this to something else below.
1176 *pResult = CDRF_DODEFAULT;
1178 if (m_bNoDispUpdates)
1179 return;
1181 switch (pLVCD->nmcd.dwDrawStage)
1183 case CDDS_PREPAINT:
1185 *pResult = CDRF_NOTIFYITEMDRAW;
1186 return;
1188 break;
1189 case CDDS_ITEMPREPAINT:
1191 // This is the prepaint stage for an item. Here's where we set the
1192 // item's text color.
1194 // Tell Windows to send draw notifications for each subitem.
1195 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1197 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1199 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1201 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1202 if (data)
1204 HGDIOBJ hGdiObj = nullptr;
1205 int action = data->GetRebaseAction();
1206 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1207 crText = RGB(128,128,128);
1209 if (action & LOGACTIONS_REBASE_SQUASH)
1210 pLVCD->clrTextBk = RGB(156,156,156);
1211 else if (action & LOGACTIONS_REBASE_EDIT)
1212 pLVCD->clrTextBk = RGB(200,200,128);
1213 else
1214 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1216 if (action & LOGACTIONS_REBASE_CURRENT)
1217 hGdiObj = m_boldFont;
1219 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1220 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1221 if (isHeadHash && isHighlight)
1222 hGdiObj = m_boldItalicsFont;
1223 else if (isHeadHash)
1224 hGdiObj = m_boldFont;
1225 else if (isHighlight)
1226 hGdiObj = m_FontItalics;
1228 if (hGdiObj)
1230 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1231 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1234 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1235 // crText = GetSysColor(COLOR_GRAYTEXT);
1237 if (data->m_CommitHash.IsEmpty())
1239 //crText = GetSysColor(RGB(200,200,0));
1240 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1241 // We changed the font, so we're returning CDRF_NEWFONT. This
1242 // tells the control to recalculate the extent of the text.
1243 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1247 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1249 if (m_bStrictStopped)
1250 crText = GetSysColor(COLOR_GRAYTEXT);
1252 // Store the color back in the NMLVCUSTOMDRAW struct.
1253 pLVCD->clrText = crText;
1254 return;
1256 break;
1257 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1259 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1261 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1264 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1266 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1268 CRect rect;
1269 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1271 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1272 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1274 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1275 if( !data ->m_CommitHash.IsEmpty())
1276 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1278 *pResult = CDRF_SKIPDEFAULT;
1279 return;
1283 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1285 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1287 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1289 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1291 CRect rect;
1292 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1294 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1295 // not in FillBackGround method, because this only affected the message subitem
1296 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1297 return;
1299 int index = (int)pLVCD->nmcd.dwItemSpec;
1300 int state = GetItemState(index, LVIS_SELECTED);
1301 int txtState = LISS_NORMAL;
1302 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1304 if (state & LVIS_SELECTED)
1305 txtState = LISS_HOTSELECTED;
1306 else
1307 txtState = LISS_HOT;
1309 else if (state & LVIS_SELECTED)
1311 if (::GetFocus() == m_hWnd)
1312 txtState = LISS_SELECTED;
1313 else
1314 txtState = LISS_SELECTEDNOTFOCUS;
1317 HTHEME hTheme = nullptr;
1318 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1319 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1321 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1322 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1323 else
1325 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1326 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1327 ::DeleteObject(brush);
1329 if (hTheme)
1331 CRect rt;
1332 // get rect of whole line
1333 GetItemRect(index, rt, LVIR_BOUNDS);
1334 CRect rect2 = rect;
1335 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1336 rect2.DeflateRect(1, 1, 1, 1);
1338 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1339 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1341 CloseThemeData(hTheme);
1343 // END: extended redraw
1345 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1347 std::vector<REFLABEL> refsToShow;
1348 STRING_VECTOR remoteTrackingList;
1349 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1350 for (unsigned int i = 0; i < refList.size(); ++i)
1352 CString str = refList[i];
1354 REFLABEL refLabel;
1355 refLabel.color = RGB(255, 255, 255);
1356 refLabel.singleRemote = false;
1357 refLabel.hasTracking = false;
1358 refLabel.sameName = false;
1359 refLabel.annotatedTag = false;
1360 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1362 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1363 continue;
1364 if (refLabel.name == m_CurrentBranch )
1365 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1366 else
1367 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1369 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1370 CString pullRemote = trackingEntry.first;
1371 CString pullBranch = trackingEntry.second;
1372 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1374 CString defaultUpstream;
1375 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1376 refLabel.hasTracking = true;
1377 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1379 bool found = false;
1380 for (size_t j = i + 1; j < refList.size(); ++j)
1382 if (refList[j] == defaultUpstream)
1384 found = true;
1385 break;
1389 if (found)
1391 bool sameName = pullBranch == refLabel.name;
1392 refsToShow.push_back(refLabel);
1393 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1394 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1395 if (m_bSymbolizeRefNames)
1397 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1399 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1400 refLabel.singleRemote = true;
1402 else if (sameName)
1403 refLabel.simplifiedName = pullRemote + _T("/");
1404 refLabel.sameName = sameName;
1406 refsToShow.push_back(refLabel);
1407 remoteTrackingList.push_back(defaultUpstream);
1408 continue;
1413 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1415 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1416 continue;
1418 bool found = false;
1419 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1421 if (remoteTrackingList[j] == str)
1423 found = true;
1424 break;
1427 if (found)
1428 continue;
1430 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1431 if (m_bSymbolizeRefNames)
1433 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1435 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1436 refLabel.singleRemote = true;
1440 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1442 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1443 continue;
1444 refLabel.color = m_Colors.GetColor(CColors::Tag);
1445 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1447 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1449 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1450 continue;
1451 refLabel.color = m_Colors.GetColor(CColors::Stash);
1452 refLabel.name = _T("stash");
1454 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1456 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1457 continue;
1458 if (refLabel.name.Find(_T("good")) == 0)
1460 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1461 refLabel.name = _T("good");
1463 if (refLabel.name.Find(_T("bad")) == 0)
1465 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1466 refLabel.name = _T("bad");
1469 else
1470 continue;
1472 refsToShow.push_back(refLabel);
1475 if (refsToShow.empty())
1477 *pResult = CDRF_DODEFAULT;
1478 return;
1481 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1483 *pResult = CDRF_SKIPDEFAULT;
1484 return;
1491 if (pLVCD->iSubItem == LOGLIST_ACTION)
1493 if(this->m_IsIDReplaceAction)
1495 *pResult = CDRF_DODEFAULT;
1496 return;
1498 *pResult = CDRF_DODEFAULT;
1500 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1501 return;
1503 int nIcons = 0;
1504 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1505 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1507 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1508 CRect rect;
1509 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1510 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1511 // Get the selected state of the
1512 // item being drawn.
1514 // Fill the background if necessary
1515 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1517 // Draw the icon(s) into the compatible DC
1518 int action = SafeGetAction(pLogEntry);
1520 if (!pLogEntry->m_IsDiffFiles)
1521 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1523 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1524 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1525 ++nIcons;
1527 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1528 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1529 ++nIcons;
1531 if (action & CTGitPath::LOGACTIONS_DELETED)
1532 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1533 ++nIcons;
1535 if (action & CTGitPath::LOGACTIONS_REPLACED)
1536 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1537 ++nIcons;
1538 *pResult = CDRF_SKIPDEFAULT;
1539 return;
1542 break;
1544 *pResult = CDRF_DODEFAULT;
1547 CString FindSVNRev(const CString& msg)
1551 const std::tr1::wsregex_iterator end;
1552 std::wstring s = msg;
1553 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)
1555 const std::tr1::wsmatch match = *it;
1556 if (match.size() == 4)
1558 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1559 return std::wstring(match[2]).c_str();
1562 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)
1564 const std::tr1::wsmatch match = *it;
1565 if (match.size() == 3)
1567 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1568 return std::wstring(match[1]).c_str();
1572 catch (std::exception) {}
1574 return _T("");
1577 // CGitLogListBase message handlers
1579 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1581 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1583 // Create a pointer to the item
1584 LV_ITEM* pItem = &(pDispInfo)->item;
1586 // Do the list need text information?
1587 if (!(pItem->mask & LVIF_TEXT))
1588 return;
1590 // By default, clear text buffer.
1591 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1593 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1595 *pResult = 0;
1596 if (m_bNoDispUpdates || bOutOfRange)
1597 return;
1599 // Which item number?
1600 int itemid = pItem->iItem;
1601 GitRev * pLogEntry = NULL;
1602 if (itemid < m_arShownList.GetCount())
1603 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1605 CString temp;
1606 if(m_IsOldFirst)
1608 temp.Format(_T("%d"),pItem->iItem+1);
1611 else
1613 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1616 // Which column?
1617 switch (pItem->iSubItem)
1619 case this->LOGLIST_GRAPH: //Graphic
1620 break;
1621 case this->LOGLIST_REBASE:
1623 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1624 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1626 break;
1627 case this->LOGLIST_ACTION: //action -- no text in the column
1628 break;
1629 case this->LOGLIST_HASH:
1630 if(pLogEntry)
1631 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1632 break;
1633 case this->LOGLIST_ID:
1634 if(this->m_IsIDReplaceAction)
1635 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1636 break;
1637 case this->LOGLIST_MESSAGE: //Message
1638 if (pLogEntry)
1639 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1640 break;
1641 case this->LOGLIST_AUTHOR: //Author
1642 if (pLogEntry)
1643 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1644 break;
1645 case this->LOGLIST_DATE: //Date
1646 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1647 lstrcpyn(pItem->pszText,
1648 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1649 pItem->cchTextMax);
1650 break;
1652 case this->LOGLIST_EMAIL:
1653 if (pLogEntry)
1654 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1655 break;
1657 case this->LOGLIST_COMMIT_NAME: //Commit
1658 if (pLogEntry)
1659 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1660 break;
1662 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1663 if (pLogEntry)
1664 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1665 break;
1667 case this->LOGLIST_COMMIT_DATE: //Commit Date
1668 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1669 lstrcpyn(pItem->pszText,
1670 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1671 pItem->cchTextMax);
1672 break;
1673 case this->LOGLIST_BUG: //Bug ID
1674 if(pLogEntry)
1675 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1676 break;
1677 case this->LOGLIST_SVNREV: //SVN revision
1678 if (pLogEntry)
1679 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1680 break;
1682 default:
1683 ASSERT(false);
1687 bool CGitLogListBase::IsOnStash(int index)
1689 GitRev *rev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index));
1690 if (IsStash(rev))
1691 return true;
1692 if (index > 0)
1694 GitRev *preRev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1));
1695 if (IsStash(preRev))
1696 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1698 return false;
1701 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1703 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1705 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1706 return true;
1708 return false;
1711 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1713 if (pRev->m_ParentHash.empty())
1717 pRev->GetParentFromHash(pRev->m_CommitHash);
1719 catch (const char* msg)
1721 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1724 parentHash = pRev->m_ParentHash;
1727 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1730 if (pWnd == GetHeaderCtrl())
1732 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1735 int selIndex = GetSelectionMark();
1736 if (selIndex < 0)
1737 return; // nothing selected, nothing to do with a context menu
1739 // if the user selected the info text telling about not all revisions shown due to
1740 // the "stop on copy/rename" option, we also don't show the context menu
1741 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1742 return;
1744 // if the context menu is invoked through the keyboard, we have to use
1745 // a calculated position on where to anchor the menu on
1746 if ((point.x == -1) && (point.y == -1))
1748 CRect rect;
1749 GetItemRect(selIndex, &rect, LVIR_LABEL);
1750 ClientToScreen(&rect);
1751 point = rect.CenterPoint();
1753 m_nSearchIndex = selIndex;
1754 m_bCancelled = FALSE;
1756 // calculate some information the context menu commands can use
1757 // CString pathURL = GetURLFromPath(m_path);
1759 POSITION pos = GetFirstSelectedItemPosition();
1760 int indexNext = GetNextSelectedItem(pos);
1761 if (indexNext < 0)
1762 return;
1764 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1765 if (pSelLogEntry == nullptr)
1766 return;
1767 #if 0
1768 GitRev revSelected = pSelLogEntry->Rev;
1769 GitRev revPrevious = git_revnum_t(revSelected)-1;
1770 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1772 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1774 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1775 if (changedpath->lCopyFromRev)
1776 revPrevious = changedpath->lCopyFromRev;
1779 GitRev revSelected2;
1780 if (pos)
1782 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1783 revSelected2 = pLogEntry->Rev;
1785 bool bAllFromTheSameAuthor = true;
1786 CString firstAuthor;
1787 CLogDataVector selEntries;
1788 GitRev revLowest, revHighest;
1789 GitRevRangeArray revisionRanges;
1791 POSITION pos = GetFirstSelectedItemPosition();
1792 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1793 revisionRanges.AddRevision(pLogEntry->Rev);
1794 selEntries.push_back(pLogEntry);
1795 firstAuthor = pLogEntry->sAuthor;
1796 revLowest = pLogEntry->Rev;
1797 revHighest = pLogEntry->Rev;
1798 while (pos)
1800 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1801 revisionRanges.AddRevision(pLogEntry->Rev);
1802 selEntries.push_back(pLogEntry);
1803 if (firstAuthor.Compare(pLogEntry->sAuthor))
1804 bAllFromTheSameAuthor = false;
1805 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1806 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1810 #endif
1812 int FirstSelect=-1, LastSelect=-1;
1813 pos = GetFirstSelectedItemPosition();
1814 FirstSelect = GetNextSelectedItem(pos);
1815 while(pos)
1817 LastSelect = GetNextSelectedItem(pos);
1819 //entry is selected, now show the popup menu
1820 CIconMenu popup;
1821 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1823 if (popup.CreatePopupMenu())
1825 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1826 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1827 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1828 bool isStash = IsOnStash(indexNext);
1829 GIT_REV_LIST parentHash;
1830 GetParentHashes(pSelLogEntry, parentHash);
1832 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1833 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1835 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1836 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1838 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1839 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1841 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1842 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1844 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)))
1845 popup.AppendMenu(MF_SEPARATOR, NULL);
1847 if (GetSelectedCount() == 1)
1850 bool requiresSeparator = false;
1851 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1853 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1855 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1856 requiresSeparator = true;
1859 else
1861 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1863 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1864 requiresSeparator = true;
1866 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1868 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1869 requiresSeparator = true;
1873 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1875 if (parentHash.size() == 1)
1877 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1878 requiresSeparator = true;
1880 else if (parentHash.size() > 1)
1882 blamemenu.CreatePopupMenu();
1883 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1884 for (size_t i = 0; i < parentHash.size(); ++i)
1886 CString str;
1887 str.Format(IDS_PARENT, i + 1);
1888 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1890 requiresSeparator = true;
1894 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1896 if (parentHash.size() == 1)
1898 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1899 requiresSeparator = true;
1901 else if (parentHash.size() > 1)
1903 gnudiffmenu.CreatePopupMenu();
1904 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1906 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1907 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1909 for (size_t i = 0; i < parentHash.size(); ++i)
1911 CString str;
1912 str.Format(IDS_PARENT, i + 1);
1913 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1915 requiresSeparator = true;
1919 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1921 if (parentHash.size() == 1)
1923 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1924 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1925 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1926 requiresSeparator = true;
1928 else if (parentHash.size() > 1)
1930 diffmenu.CreatePopupMenu();
1931 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1932 for (size_t i = 0; i < parentHash.size(); ++i)
1934 CString str;
1935 str.Format(IDS_PARENT, i + 1);
1936 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1937 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1939 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1940 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1943 requiresSeparator = true;
1947 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1949 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1950 requiresSeparator = true;
1953 if (requiresSeparator)
1954 popup.AppendMenu(MF_SEPARATOR, NULL);
1956 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1958 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1959 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1962 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1964 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1965 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1967 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1968 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1970 popup.AppendMenu(MF_SEPARATOR, NULL);
1973 if (pSelLogEntry->m_CommitHash.IsEmpty())
1975 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1976 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1978 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1979 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1981 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1982 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1984 popup.AppendMenu(MF_SEPARATOR, NULL);
1986 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1987 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1989 popup.AppendMenu(MF_SEPARATOR, NULL);
1993 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1994 // {
1995 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1996 // }
1997 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1998 // {
1999 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2000 // }
2001 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2002 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2003 // {
2004 // popup.AppendMenu(MF_SEPARATOR, NULL);
2005 // }
2007 CString str,format;
2008 //if (m_hasWC)
2009 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2011 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2013 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2014 GetSelectedCount() == 1)
2015 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2017 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2018 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2020 format.LoadString(IDS_LOG_POPUP_MERGEREV);
2021 str.Format(format,g_Git.GetCurrentBranch());
2023 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2024 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2026 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2027 str.Format(format,g_Git.GetCurrentBranch());
2029 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2030 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2033 // Add Switch Branch express Menu
2034 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2035 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2038 std::vector<CString *> branchs;
2039 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2041 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2042 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2044 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2048 CString str;
2049 str.LoadString(IDS_SWITCH_BRANCH);
2051 if(branchs.size() == 1)
2053 str+=_T(" ");
2054 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
2055 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
2057 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2060 else if(branchs.size() > 1)
2062 subbranchmenu.CreatePopupMenu();
2063 for (size_t i = 0 ; i < branchs.size(); ++i)
2065 if (*branchs[i] != currentBranch)
2067 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2068 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2072 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2076 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2077 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2079 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2080 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2082 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2083 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2085 format.LoadString(IDS_REBASE_THIS_FORMAT);
2086 str.Format(format,g_Git.GetCurrentBranch());
2088 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2089 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2090 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2092 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2093 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2095 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2097 if (parentHash.size() == 1)
2099 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2101 else if (parentHash.size() > 1)
2103 revertmenu.CreatePopupMenu();
2104 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2106 for (size_t i = 0; i < parentHash.size(); ++i)
2108 CString str;
2109 str.Format(IDS_PARENT, i + 1);
2110 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2115 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2116 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2118 popup.AppendMenu(MF_SEPARATOR, NULL);
2123 if(!pSelLogEntry->m_Ref.IsEmpty())
2125 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2126 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2127 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2128 popup.AppendMenu(MF_SEPARATOR, NULL);
2131 if (GetSelectedCount() >= 2)
2133 bool bAddSeparator = false;
2134 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2136 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2137 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2140 if (GetSelectedCount() == 2)
2142 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2143 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2145 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2147 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2148 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2149 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2150 CString menu;
2151 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2152 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2153 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2154 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2157 bAddSeparator = true;
2160 if (m_hasWC)
2162 bAddSeparator = true;
2165 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2166 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2168 if (bAddSeparator)
2169 popup.AppendMenu(MF_SEPARATOR, NULL);
2172 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2174 bool bAddSeparator = false;
2175 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2177 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2179 CString head;
2180 int headindex;
2181 headindex = this->GetHeadIndex();
2182 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2184 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2185 CGitHash hashFirst;
2186 if (g_Git.GetHash(hashFirst, head))
2187 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2188 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2189 CGitHash hash;
2190 if (g_Git.GetHash(hash, head))
2191 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2192 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect));
2193 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2194 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2195 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2196 bAddSeparator = true;
2201 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2202 if (GetSelectedCount() >= 2)
2203 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2204 else
2205 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2206 bAddSeparator = true;
2209 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2210 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2211 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2212 bAddSeparator = true;
2215 if (bAddSeparator)
2216 popup.AppendMenu(MF_SEPARATOR, NULL);
2219 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())
2221 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2222 popup.AppendMenu(MF_SEPARATOR, NULL);
2225 if (GetSelectedCount() == 1)
2227 bool bAddSeparator = false;
2228 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2230 // show the push-option only if the log entry has an associated local branch
2231 bool isLocal = false;
2232 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2234 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2235 isLocal = true;
2237 if (isLocal)
2239 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2240 bAddSeparator = true;
2243 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2245 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2246 bAddSeparator = true;
2250 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2252 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2254 std::vector<CString *> branchs;
2255 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2257 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2258 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2260 CString str;
2261 if (branchs.size() == 1)
2263 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2264 str+=_T(" ");
2265 str += *branchs[0];
2266 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2267 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2268 bAddSeparator = true;
2270 else if (branchs.size() > 1)
2272 str.LoadString(IDS_DELETE_BRANCHTAG);
2273 submenu.CreatePopupMenu();
2274 for (size_t i = 0; i < branchs.size(); ++i)
2276 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2277 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2280 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2281 bAddSeparator = true;
2284 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2285 if (bAddSeparator)
2286 popup.AppendMenu(MF_SEPARATOR, NULL);
2287 } // GetSelectedCount() == 1
2289 if (GetSelectedCount() != 0)
2291 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2292 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2293 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2294 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2295 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2296 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2299 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2300 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2302 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2303 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2305 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2306 // DialogEnableWindow(IDOK, FALSE);
2307 // SetPromptApp(&theApp);
2309 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2311 // EnableOKButton();
2312 } // if (popup.CreatePopupMenu())
2316 bool CGitLogListBase::IsSelectionContinuous()
2318 if ( GetSelectedCount()==1 )
2320 // if only one revision is selected, the selection is of course
2321 // continuous
2322 return true;
2325 POSITION pos = GetFirstSelectedItemPosition();
2326 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2327 if (bContinuous)
2329 int itemindex = GetNextSelectedItem(pos);
2330 while (pos)
2332 int nextindex = GetNextSelectedItem(pos);
2333 if (nextindex - itemindex > 1)
2335 bContinuous = false;
2336 break;
2338 itemindex = nextindex;
2341 return bContinuous;
2344 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2347 CString sClipdata;
2348 POSITION pos = GetFirstSelectedItemPosition();
2349 if (pos != NULL)
2351 CString sRev;
2352 sRev.LoadString(IDS_LOG_REVISION);
2353 CString sAuthor;
2354 sAuthor.LoadString(IDS_LOG_AUTHOR);
2355 CString sDate;
2356 sDate.LoadString(IDS_LOG_DATE);
2357 CString sMessage;
2358 sMessage.LoadString(IDS_LOG_MESSAGE);
2359 bool first = true;
2360 while (pos)
2362 CString sLogCopyText;
2363 CString sPaths;
2364 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2366 if (toCopy == ID_COPY_ALL)
2368 //pLogEntry->GetFiles(this)
2369 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2371 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2372 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2374 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2375 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2377 CString rename;
2378 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2379 sPaths += _T(" ") + rename;
2381 sPaths += _T("\r\n");
2383 sPaths.Trim();
2384 CString body = pLogEntry->GetBody();
2385 body.Replace(_T("\n"), _T("\r\n"));
2386 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"),
2387 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2388 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2389 (LPCTSTR)sDate,
2390 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2391 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2392 (LPCTSTR)sPaths);
2393 sClipdata += sLogCopyText;
2395 else if (toCopy == ID_COPY_MESSAGE)
2397 CString body = pLogEntry->GetBody();
2398 body.Replace(_T("\n"), _T("\r\n"));
2399 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2401 else if (toCopy == ID_COPY_SUBJECT)
2403 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2405 else
2407 if (!first)
2408 sClipdata += _T("\r\n");
2409 sClipdata += pLogEntry->m_CommitHash;
2412 first = false;
2414 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2419 void CGitLogListBase::DiffSelectedRevWithPrevious()
2421 if (m_bThreadRunning)
2422 return;
2424 int FirstSelect=-1, LastSelect=-1;
2425 POSITION pos = GetFirstSelectedItemPosition();
2426 FirstSelect = GetNextSelectedItem(pos);
2427 while(pos)
2429 LastSelect = GetNextSelectedItem(pos);
2432 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2434 #if 0
2435 UpdateLogInfoLabel();
2436 int selIndex = m_LogList.GetSelectionMark();
2437 if (selIndex < 0)
2438 return;
2439 int selCount = m_LogList.GetSelectedCount();
2440 if (selCount != 1)
2441 return;
2443 // Find selected entry in the log list
2444 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2445 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2446 long rev1 = pLogEntry->Rev;
2447 long rev2 = rev1-1;
2448 CTGitPath path = m_path;
2450 // See how many files under the relative root were changed in selected revision
2451 int nChanged = 0;
2452 LogChangedPath * changed = NULL;
2453 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2455 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2456 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2458 ++nChanged;
2459 changed = cpath;
2463 if (m_path.IsDirectory() && nChanged == 1)
2465 // We're looking at the log for a directory and only one file under dir was changed in the revision
2466 // Do diff on that file instead of whole directory
2467 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2470 m_bCancelled = FALSE;
2471 DialogEnableWindow(IDOK, FALSE);
2472 SetPromptApp(&theApp);
2473 theApp.DoWaitCursor(1);
2475 if (PromptShown())
2477 GitDiff diff(this, m_hWnd, true);
2478 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2479 diff.SetHEADPeg(m_LogRevision);
2480 diff.ShowCompare(path, rev2, path, rev1);
2482 else
2484 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2487 theApp.DoWaitCursor(-1);
2488 EnableOKButton();
2489 #endif
2492 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2494 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2495 *pResult = -1;
2497 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2498 return;
2499 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2500 return;
2501 if (pFindInfo->lvfi.psz == 0)
2502 return;
2503 #if 0
2504 CString sCmp = pFindInfo->lvfi.psz;
2505 CString sRev;
2506 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2508 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2509 sRev.Format(_T("%ld"), pLogEntry->Rev);
2510 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2512 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2514 *pResult = i;
2515 return;
2518 else
2520 if (sCmp.Compare(sRev)==0)
2522 *pResult = i;
2523 return;
2527 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2529 for (int i=0; i<pFindInfo->iStart; ++i)
2531 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2532 sRev.Format(_T("%ld"), pLogEntry->Rev);
2533 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2535 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2537 *pResult = i;
2538 return;
2541 else
2543 if (sCmp.Compare(sRev)==0)
2545 *pResult = i;
2546 return;
2551 #endif
2552 *pResult = -1;
2555 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2557 ClearText();
2559 this->m_arShownList.SafeRemoveAll();
2561 this->m_logEntries.ClearAll();
2562 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2563 return -1;
2565 //this->m_logEntries.ParserFromLog();
2566 SetItemCountEx((int)m_logEntries.size());
2568 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2570 if(m_IsOldFirst)
2572 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2573 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2576 else
2578 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2579 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2583 ReloadHashMap();
2585 if(path)
2586 m_Path=*path;
2587 return 0;
2591 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2593 ClearText();
2595 m_arShownList.SafeRemoveAll();
2597 m_logEntries.ClearAll();
2598 if (m_logEntries.Fill(hashes))
2599 return -1;
2601 SetItemCountEx((int)m_logEntries.size());
2603 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2605 if (m_IsOldFirst)
2607 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2608 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2610 else
2612 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2613 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2617 ReloadHashMap();
2619 return 0;
2622 int CGitLogListBase::BeginFetchLog()
2624 ClearText();
2626 this->m_arShownList.SafeRemoveAll();
2628 this->m_logEntries.ClearAll();
2630 this->m_LogCache.ClearAllParent();
2632 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2634 CTGitPath *path;
2635 if(this->m_Path.IsEmpty())
2636 path=NULL;
2637 else
2638 path=&this->m_Path;
2640 int mask;
2641 mask = CGit::LOG_INFO_ONLY_HASH;
2642 if (m_bIncludeBoundaryCommits)
2643 mask |= CGit::LOG_INFO_BOUNDARY;
2644 // if(this->m_bAllBranch)
2645 mask |= m_ShowMask ;
2647 if(m_bShowWC)
2649 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2650 ResetWcRev();
2651 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2654 if (m_sRange.IsEmpty())
2655 m_sRange = _T("HEAD");
2657 CFilterData data;
2658 data.m_From = m_From;
2659 data.m_To =m_To;
2661 #if 0 /* use tortoiegit filter */
2662 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2663 data.m_Author = this->m_sFilterText;
2665 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2666 data.m_MessageFilter = this->m_sFilterText;
2668 data.m_IsRegex = m_bFilterWithRegex;
2669 #endif
2671 // follow does not work for directories
2672 if (!path || path->IsDirectory())
2673 mask &= ~CGit::LOG_INFO_FOLLOW;
2674 // follow does not work with all branches 8at least in TGit)
2675 if (mask & CGit::LOG_INFO_FOLLOW)
2676 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2678 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2680 //this->m_logEntries.ParserFromLog();
2681 if(IsInWorkingThread())
2683 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2685 else
2687 SetItemCountEx((int)m_logEntries.size());
2692 [] { git_init(); } ();
2694 catch (char* msg)
2696 CString err(msg);
2697 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2698 return -1;
2701 if (!g_Git.CanParseRev(m_sRange))
2703 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2704 return 0;
2706 // if show all branches, pick any ref as dummy entry ref
2707 STRING_VECTOR list;
2708 if (g_Git.GetRefList(list))
2709 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2710 if (list.size() == 0)
2711 return 0;
2713 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2716 g_Git.m_critGitDllSec.Lock();
2717 try {
2718 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2720 g_Git.m_critGitDllSec.Unlock();
2721 return -1;
2724 catch (char* msg)
2726 g_Git.m_critGitDllSec.Unlock();
2727 CString err(msg);
2728 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2729 return -1;
2731 g_Git.m_critGitDllSec.Unlock();
2733 return 0;
2736 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2738 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2740 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2742 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2744 DiffSelectedRevWithPrevious();
2745 return TRUE;
2748 #if 0
2749 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2751 DiffSelectedFile();
2752 return TRUE;
2754 #endif
2756 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2758 // select all entries
2759 for (int i=0; i<GetItemCount(); ++i)
2761 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2763 return TRUE;
2766 #if 0
2767 if (m_hAccel && !bSkipAccelerator)
2769 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2770 if (ret)
2771 return TRUE;
2774 #endif
2775 //m_tooltips.RelayEvent(pMsg);
2776 return __super::PreTranslateMessage(pMsg);
2779 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2781 // a double click on an entry in the revision list has happened
2782 *pResult = 0;
2784 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2785 DiffSelectedRevWithPrevious();
2788 int CGitLogListBase::FetchLogAsync(void * data)
2790 ReloadHashMap();
2791 m_ProcData=data;
2792 m_bExitThread=FALSE;
2793 InterlockedExchange(&m_bThreadRunning, TRUE);
2794 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2795 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2796 if (m_LoadingThread ==NULL)
2798 InterlockedExchange(&m_bThreadRunning, FALSE);
2799 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2800 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2801 return -1;
2803 return 0;
2806 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2808 return ((CGitLogListBase*)pVoid)->LogThread();
2811 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2813 //CTime time;
2814 oldest=CTime::GetCurrentTime();
2815 latest=CTime(1971,1,2,0,0,0);
2816 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2818 if(m_logEntries[i].IsEmpty())
2819 continue;
2821 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2822 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2824 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2825 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2829 if(latest<oldest)
2830 latest=oldest;
2833 UINT CGitLogListBase::LogThread()
2835 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2837 InterlockedExchange(&m_bThreadRunning, TRUE);
2838 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2840 ULONGLONG t1,t2;
2842 if(BeginFetchLog())
2844 InterlockedExchange(&m_bThreadRunning, FALSE);
2845 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2847 return 1;
2850 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2851 bool bRegex = false;
2852 if (m_bFilterWithRegex)
2853 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2855 TRACE(_T("\n===Begin===\n"));
2856 //Update work copy item;
2858 if (!m_logEntries.empty())
2860 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2862 m_arShownList.SafeAdd(pRev);
2866 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2868 // store commit number of the last selected commit/line before the refresh or -1
2869 int lastSelectedHashNItem = -1;
2870 int ret = 0;
2872 bool shouldWalk = true;
2873 if (!g_Git.CanParseRev(m_sRange))
2875 // walk revisions if show all branches and there exists any ref
2876 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2877 shouldWalk = false;
2878 else
2880 STRING_VECTOR list;
2881 if (g_Git.GetRefList(list))
2882 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2883 if (list.size() == 0)
2884 shouldWalk = false;
2888 if (shouldWalk)
2890 g_Git.m_critGitDllSec.Lock();
2891 int total = 0;
2894 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2895 total = git_get_log_estimate_commit_count(m_DllGitLog);
2897 catch (char* msg)
2899 CString err(msg);
2900 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2901 ret = -1;
2903 g_Git.m_critGitDllSec.Unlock();
2905 GIT_COMMIT commit;
2906 t2=t1=GetTickCount();
2907 int oldprecentage = 0;
2908 size_t oldsize = m_logEntries.size();
2909 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2910 while (ret== 0 && !m_bExitThread)
2912 g_Git.m_critGitDllSec.Lock();
2915 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2917 catch (char* msg)
2919 g_Git.m_critGitDllSec.Unlock();
2920 CString err(msg);
2921 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2922 break;
2924 g_Git.m_critGitDllSec.Unlock();
2926 if(ret)
2928 if (ret != -2) // other than end of revision walking
2929 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2930 break;
2933 if (commit.m_ignore == 1)
2935 git_free_commit(&commit);
2936 continue;
2939 //printf("%s\r\n",commit.GetSubject());
2940 if(m_bExitThread)
2941 break;
2943 CGitHash hash = (char*)commit.m_hash ;
2945 GitRev *pRev = m_LogCache.GetCacheData(hash);
2946 pRev->m_GitCommit = commit;
2947 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2949 char *note=NULL;
2950 g_Git.m_critGitDllSec.Lock();
2953 git_get_notes(commit.m_hash, &note);
2955 catch (char* msg)
2957 g_Git.m_critGitDllSec.Unlock();
2958 CString err(msg);
2959 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2960 break;
2962 g_Git.m_critGitDllSec.Unlock();
2964 if(note)
2966 pRev->m_Notes.Empty();
2967 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2968 free(note);
2969 note = nullptr;
2972 if(!pRev->m_IsDiffFiles)
2974 pRev->m_CallDiffAsync = DiffAsync;
2977 pRev->ParserParentFromCommit(&commit);
2978 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2980 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2982 const CGitHash &parentHash = pRev->m_ParentHash[i];
2983 auto it = commitChildren.find(parentHash);
2984 if (it == commitChildren.end())
2986 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2988 it->second.insert(pRev->m_CommitHash);
2992 #ifdef DEBUG
2993 pRev->DbgPrint();
2994 TRACE(_T("\n"));
2995 #endif
2997 bool visible = true;
2998 if (HasFilterText())
3000 if(!IsMatchFilter(bRegex,pRev,pat))
3001 visible = false;
3003 if (visible && !ShouldShowFilter(pRev, commitChildren))
3004 visible = false;
3005 this->m_critSec.Lock();
3006 m_logEntries.append(hash, visible);
3007 if (visible)
3008 m_arShownList.SafeAdd(pRev);
3009 this->m_critSec.Unlock();
3011 if (!visible)
3012 continue;
3014 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3015 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3017 t2=GetTickCount();
3019 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3021 //update UI
3022 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3023 if(percent > 99)
3024 percent =99;
3025 if(percent < GITLOG_START)
3026 percent = GITLOG_START +1;
3028 oldsize = m_logEntries.size();
3029 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3031 //if( percent > oldprecentage )
3033 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3034 oldprecentage = percent;
3037 if (lastSelectedHashNItem >= 0)
3038 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3040 t1 = t2;
3043 g_Git.m_critGitDllSec.Lock();
3044 git_close_log(m_DllGitLog);
3045 g_Git.m_critGitDllSec.Unlock();
3049 if (m_bExitThread)
3051 InterlockedExchange(&m_bThreadRunning, FALSE);
3052 return 0;
3055 //Update UI;
3056 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3058 if (lastSelectedHashNItem >= 0)
3059 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3061 if (this->m_hWnd)
3062 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3064 InterlockedExchange(&m_bThreadRunning, FALSE);
3066 return 0;
3069 void CGitLogListBase::FetchRemoteList()
3071 STRING_VECTOR remoteList;
3072 if (!g_Git.GetRemoteList(remoteList))
3073 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3074 else
3075 m_SingleRemote = _T("");
3078 void CGitLogListBase::FetchTrackingBranchList()
3080 m_TrackingMap.clear();
3081 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3083 for (size_t j = 0; j < it->second.size(); ++j)
3085 CString branchName;
3086 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3088 CString pullRemote, pullBranch;
3089 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3090 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3092 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3099 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3101 SafeTerminateThread();
3103 this->SetItemCountEx(0);
3104 this->Clear();
3106 ResetWcRev();
3108 // HACK to hide graph column
3109 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3110 SetColumnWidth(0, 0);
3111 else
3112 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3114 //Update branch and Tag info
3115 ReloadHashMap();
3116 if (m_pFindDialog)
3117 m_pFindDialog->RefreshList();
3118 //Assume Thread have exited
3119 //if(!m_bThreadRunning)
3121 m_logEntries.clear();
3123 if(IsCleanFilter)
3125 m_sFilterText.Empty();
3126 m_From=-1;
3127 m_To=-1;
3130 InterlockedExchange(&m_bExitThread,FALSE);
3132 InterlockedExchange(&m_bThreadRunning, TRUE);
3133 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3134 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3136 InterlockedExchange(&m_bThreadRunning, FALSE);
3137 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3138 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3142 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3146 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3147 if (!bMatchCase)
3148 type |= std::tr1::regex_constants::icase;
3149 pat = std::tr1::wregex(regexp_str, type);
3150 return true;
3152 catch (std::exception) {}
3153 return false;
3155 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
3157 BOOL result = TRUE;
3158 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3159 CString sRev;
3161 if ((bRegex)&&(m_bFilterWithRegex))
3163 if (m_SelectedFilters & LOGFILTER_BUGID)
3165 if(this->m_bShowBugtraqColumn)
3167 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3169 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3170 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3172 return TRUE;
3177 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3179 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3180 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3182 return TRUE;
3186 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3188 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3189 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3191 return TRUE;
3195 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3197 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3199 return TRUE;
3202 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3204 return TRUE;
3208 if (m_SelectedFilters & LOGFILTER_EMAILS)
3210 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3212 return TRUE;
3215 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3217 return TRUE;
3221 if (m_SelectedFilters & LOGFILTER_REVS)
3223 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3224 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3226 return TRUE;
3230 if (m_SelectedFilters & LOGFILTER_REFNAME)
3232 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3233 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3235 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3237 return TRUE;
3242 if (m_SelectedFilters & LOGFILTER_PATHS)
3244 CTGitPathList *pathList=NULL;
3245 if( pRev->m_IsDiffFiles)
3246 pathList = &pRev->GetFiles(this);
3247 else
3249 if(!pRev->m_IsSimpleListReady)
3250 pRev->SafeGetSimpleList(&g_Git);
3253 if(pathList)
3254 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3256 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3258 return true;
3260 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3262 return true;
3266 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3268 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3270 return true;
3275 else
3277 CString find = m_sFilterText;
3278 if (!m_bFilterCaseSensitively)
3279 find.MakeLower();
3280 result = find[0] == '!' ? FALSE : TRUE;
3281 if (!result)
3282 find = find.Mid(1);
3284 if (m_SelectedFilters & LOGFILTER_BUGID)
3286 if(this->m_bShowBugtraqColumn)
3288 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3290 if (!m_bFilterCaseSensitively)
3291 sBugIds.MakeLower();
3292 if ((sBugIds.Find(find) >= 0))
3294 return result;
3299 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3301 CString msg = pRev->GetSubject();
3303 if (!m_bFilterCaseSensitively)
3304 msg = msg.MakeLower();
3305 if ((msg.Find(find) >= 0))
3307 return result;
3311 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3313 CString msg = pRev->GetBody();
3315 if (!m_bFilterCaseSensitively)
3316 msg = msg.MakeLower();
3317 if ((msg.Find(find) >= 0))
3319 return result;
3323 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3325 CString msg = pRev->GetAuthorName();
3326 if (!m_bFilterCaseSensitively)
3327 msg = msg.MakeLower();
3328 if ((msg.Find(find) >= 0))
3330 return result;
3334 if (m_SelectedFilters & LOGFILTER_EMAILS)
3336 CString msg = pRev->GetAuthorEmail();
3337 if (!m_bFilterCaseSensitively)
3338 msg = msg.MakeLower();
3339 if ((msg.Find(find) >= 0))
3341 return result;
3345 if (m_SelectedFilters & LOGFILTER_REVS)
3347 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3348 if ((sRev.Find(find) >= 0))
3350 return result;
3354 if (m_SelectedFilters & LOGFILTER_REFNAME)
3356 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3357 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3359 if (it->Find(find) >= 0)
3361 return result;
3366 if (m_SelectedFilters & LOGFILTER_PATHS)
3368 CTGitPathList *pathList=NULL;
3369 if( pRev->m_IsDiffFiles)
3370 pathList = &pRev->GetFiles(this);
3371 else
3373 if(!pRev->m_IsSimpleListReady)
3374 pRev->SafeGetSimpleList(&g_Git);
3376 if(pathList)
3377 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3379 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3380 CString path = cpath->GetGitOldPathString();
3381 if (!m_bFilterCaseSensitively)
3382 path.MakeLower();
3383 if ((path.Find(find)>=0))
3385 return result;
3387 path = cpath->GetGitPathString();
3388 if (!m_bFilterCaseSensitively)
3389 path.MakeLower();
3390 if ((path.Find(find)>=0))
3392 return result;
3396 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3398 CString path = pRev->m_SimpleFileList[i];
3399 if (!m_bFilterCaseSensitively)
3400 path.MakeLower();
3401 if ((path.Find(find)>=0))
3403 return result;
3407 } // else (from if (bRegex))
3408 return !result;
3411 static bool CStringStartsWith(const CString &str, const CString &prefix)
3413 return str.Left(prefix.GetLength()) == prefix;
3415 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3417 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3418 return true;
3420 if (m_ShowFilter & FILTERSHOW_REFS)
3422 // Keep all refs.
3423 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3424 for (size_t i = 0; i < refList.size(); ++i)
3426 const CString &str = refList[i];
3427 if (CStringStartsWith(str, _T("refs/heads/")))
3429 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3430 return true;
3432 else if (CStringStartsWith(str, _T("refs/remotes/")))
3434 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3435 return true;
3437 else if (CStringStartsWith(str, _T("refs/tags/")))
3439 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3440 return true;
3442 else if (CStringStartsWith(str, _T("refs/stash")))
3444 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3445 return true;
3447 else if (CStringStartsWith(str, _T("refs/bisect/")))
3449 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3450 return true;
3453 // Keep the head too.
3454 if (pRev->m_CommitHash == m_HeadHash)
3455 return true;
3458 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3460 if (pRev->ParentsCount() > 1)
3461 return true;
3462 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3463 if (childrenIt != commitChildren.end())
3465 const std::set<CGitHash> &children = childrenIt->second;
3466 if (children.size() > 1)
3467 return true;
3470 return false;
3473 void CGitLogListBase::ShowGraphColumn(bool bShow)
3475 // HACK to hide graph column
3476 if (bShow)
3477 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3478 else
3479 SetColumnWidth(0, 0);
3482 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3484 CString cmd;
3485 CString output;
3487 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3489 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3490 for (size_t i = 0; i < vector.size(); ++i)
3492 if (vector[i].Find(_T("refs/tags/")) == 0)
3494 CString tag = vector[i];
3495 int start = vector[i].Find(_T("^{}"));
3496 if (start > 0)
3497 tag = tag.Left(start);
3498 else
3499 continue;
3501 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3502 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3503 output.AppendChar(_T('\n'));
3508 return output;
3511 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3514 pShownlist->SafeRemoveAll();
3516 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3517 bool bRegex = false;
3518 if (m_bFilterWithRegex)
3519 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3521 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3522 CString sRev;
3523 for (DWORD i=0; i<m_logEntries.size(); ++i)
3525 if ((bRegex)&&(m_bFilterWithRegex))
3527 #if 0
3528 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3530 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3531 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3533 pShownlist->SafeAdd(m_logEntries[i]);
3534 continue;
3537 #endif
3538 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3540 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3541 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3543 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3544 continue;
3547 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3549 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3550 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3552 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3553 continue;
3556 if (m_SelectedFilters & LOGFILTER_PATHS)
3558 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3560 bool bGoing = true;
3561 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3563 CTGitPath cpath = pathList[cpPathIndex];
3564 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3566 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3567 bGoing = false;
3568 continue;
3570 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3572 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3573 bGoing = false;
3574 continue;
3576 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3578 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3579 bGoing = false;
3580 continue;
3584 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3586 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3588 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3589 continue;
3592 if (m_SelectedFilters & LOGFILTER_EMAILS)
3594 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3596 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3597 continue;
3600 if (m_SelectedFilters & LOGFILTER_REVS)
3602 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3603 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3605 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3606 continue;
3609 if (m_SelectedFilters & LOGFILTER_REFNAME)
3611 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3612 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3614 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3616 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3617 continue;
3621 } // if (bRegex)
3622 else
3624 CString find = m_sFilterText;
3625 if (!m_bFilterCaseSensitively)
3626 find.MakeLower();
3627 #if 0
3628 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3630 CString sBugIDs = m_logEntries[i]->sBugIDs;
3632 if (!m_bFilterCaseSensitively)
3633 sBugIDs = sBugIDs.MakeLower();
3634 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3636 pShownlist->SafeAdd(m_logEntries[i]);
3637 continue;
3640 #endif
3641 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3643 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3645 if (!m_bFilterCaseSensitively)
3646 msg = msg.MakeLower();
3647 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3649 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3650 continue;
3653 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3655 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3657 if (!m_bFilterCaseSensitively)
3658 msg = msg.MakeLower();
3659 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3661 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3662 continue;
3665 if (m_SelectedFilters & LOGFILTER_PATHS)
3667 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3669 bool bGoing = true;
3670 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3672 CTGitPath cpath = pathList[cpPathIndex];
3673 CString path = cpath.GetGitOldPathString();
3674 if (!m_bFilterCaseSensitively)
3675 path.MakeLower();
3676 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3678 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3679 bGoing = false;
3680 continue;
3682 path = cpath.GetGitPathString();
3683 if (!m_bFilterCaseSensitively)
3684 path.MakeLower();
3685 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3687 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3688 bGoing = false;
3689 continue;
3691 path = cpath.GetActionName();
3692 if (!m_bFilterCaseSensitively)
3693 path.MakeLower();
3694 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3696 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3697 bGoing = false;
3698 continue;
3702 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3704 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3705 if (!m_bFilterCaseSensitively)
3706 msg = msg.MakeLower();
3707 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3709 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3710 continue;
3713 if (m_SelectedFilters & LOGFILTER_EMAILS)
3715 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3716 if (!m_bFilterCaseSensitively)
3717 msg = msg.MakeLower();
3718 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3720 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3721 continue;
3724 if (m_SelectedFilters & LOGFILTER_REVS)
3726 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3727 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3729 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3730 continue;
3733 if (m_SelectedFilters & LOGFILTER_REFNAME)
3735 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3736 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3738 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3740 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3741 continue;
3745 } // else (from if (bRegex))
3746 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3750 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3753 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3755 if(m_From == -1)
3756 if(m_To == -1)
3757 return true;
3758 else
3759 return time <= m_To;
3760 else
3761 if(m_To == -1)
3762 return time >= m_From;
3763 else
3764 return ((time >= m_From)&&(time <= m_To));
3766 return TRUE; /* git dll will filter time range */
3768 // return TRUE;
3770 void CGitLogListBase::StartFilter()
3772 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3773 RecalculateShownList(&m_arShownList);
3774 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3777 DeleteAllItems();
3778 SetItemCountEx(ShownCountWithStopped());
3779 RedrawItems(0, ShownCountWithStopped());
3780 Invalidate();
3783 void CGitLogListBase::RemoveFilter()
3786 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3788 m_arShownList.SafeRemoveAll();
3790 // reset the time filter too
3791 #if 0
3792 m_timFrom = (__time64_t(m_tFrom));
3793 m_timTo = (__time64_t(m_tTo));
3794 m_DateFrom.SetTime(&m_timFrom);
3795 m_DateTo.SetTime(&m_timTo);
3796 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3797 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3798 #endif
3800 for (DWORD i=0; i<m_logEntries.size(); ++i)
3802 if(this->m_IsOldFirst)
3804 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3806 else
3808 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3811 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3812 DeleteAllItems();
3813 SetItemCountEx(ShownCountWithStopped());
3814 RedrawItems(0, ShownCountWithStopped());
3816 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3819 void CGitLogListBase::Clear()
3821 m_arShownList.SafeRemoveAll();
3822 DeleteAllItems();
3824 m_logEntries.ClearAll();
3828 void CGitLogListBase::OnDestroy()
3830 // save the column widths to the registry
3831 SaveColumnWidths();
3833 SafeTerminateThread();
3834 SafeTerminateAsyncDiffThread();
3836 int retry = 0;
3837 while(m_LogCache.SaveCache())
3839 if(retry > 5)
3840 break;
3841 Sleep(1000);
3843 ++retry;
3845 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3846 // MB_YESNO) == IDNO)
3847 // break;
3850 CHintListCtrl::OnDestroy();
3853 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3855 CRect rect;
3856 int i=(int)wParam;
3857 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3858 this->InvalidateRect(rect);
3860 return 0;
3864 * Save column widths to the registry
3866 void CGitLogListBase::SaveColumnWidths()
3868 int maxcol = m_ColumnManager.GetColumnCount();
3870 // HACK that graph column is always shown
3871 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3873 for (int col = 0; col < maxcol; ++col)
3874 if (m_ColumnManager.IsVisible (col))
3875 m_ColumnManager.ColumnResized (col);
3877 m_ColumnManager.WriteSettings();
3880 int CGitLogListBase::GetHeadIndex()
3882 if(m_HeadHash.IsEmpty())
3883 return -1;
3885 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3887 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3888 if(pRev)
3890 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3891 return i;
3894 return -1;
3896 void CGitLogListBase::OnFind()
3898 if (!m_pFindDialog)
3900 m_pFindDialog = new CFindDlg(this);
3901 m_pFindDialog->Create(this);
3904 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3906 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3908 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3910 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3911 Default();
3913 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3915 if (GetSelectedCount() != 0)
3916 return 0;
3918 CGitHash theSelectedHash = m_lastSelectedHash;
3919 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3920 m_lastSelectedHash = theSelectedHash;
3922 int countPerPage = GetCountPerPage();
3923 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3924 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3925 EnsureVisible((int)itemToSelect, FALSE);
3926 return 0;
3928 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3931 ASSERT(m_pFindDialog != NULL);
3932 bool bFound = false;
3933 int i=0;
3935 if (m_pFindDialog->IsTerminating())
3937 // invalidate the handle identifying the dialog box.
3938 m_pFindDialog = NULL;
3939 return 0;
3942 INT_PTR cnt = m_arShownList.GetCount();
3944 if(m_pFindDialog->IsRef())
3946 CString str;
3947 str=m_pFindDialog->GetFindString();
3949 CGitHash hash;
3951 if(!str.IsEmpty())
3953 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3954 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3957 if(!hash.IsEmpty())
3959 for (i = 0; i < cnt; ++i)
3961 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3962 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3964 bFound = true;
3965 break;
3969 if (!bFound)
3971 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3972 return 0;
3976 if (m_pFindDialog->FindNext() && !bFound)
3978 //read data from dialog
3979 CString findText = m_pFindDialog->GetFindString();
3980 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3982 std::tr1::wregex pat;
3983 bool bRegex = false;
3984 if (m_pFindDialog->Regex())
3985 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3987 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3989 for (i = m_nSearchIndex + 1; ; ++i)
3991 if (i >= cnt)
3993 i = 0;
3994 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3996 if (m_nSearchIndex >= 0)
3998 if (i == m_nSearchIndex)
4000 ::MessageBeep(0xFFFFFFFF);
4001 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
4002 break;
4006 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4008 CString str;
4009 str+=pLogEntry->m_CommitHash.ToString();
4010 str+=_T("\n");
4012 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4014 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4015 str+=_T("\n");
4018 str+=pLogEntry->GetAuthorEmail();
4019 str+=_T("\n");
4020 str+=pLogEntry->GetAuthorName();
4021 str+=_T("\n");
4022 str+=pLogEntry->GetBody();
4023 str+=_T("\n");
4024 str+=pLogEntry->GetCommitterEmail();
4025 str+=_T("\n");
4026 str+=pLogEntry->GetCommitterName();
4027 str+=_T("\n");
4028 str+=pLogEntry->GetSubject();
4029 str+=_T("\n");
4030 str+=pLogEntry->m_Notes;
4031 str+=_T("\n");
4032 str+=GetTagInfo(pLogEntry);
4033 str+=_T("\n");
4036 /*Because changed files list is loaded on demand when gui show,
4037 files will empty when files have not fetched.
4039 we can add it back by using one-way diff(with outnumber changed and rename detect.
4040 here just need changed filename list. one-way is much quicker.
4042 if(pLogEntry->m_IsFull)
4044 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
4046 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
4047 str+=_T("\n");
4048 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
4049 str+=_T("\n");
4052 else
4054 if(!pLogEntry->m_IsSimpleListReady)
4055 pLogEntry->SafeGetSimpleList(&g_Git);
4057 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
4059 str+=pLogEntry->m_SimpleFileList[i];
4060 str+=_T("\n");
4066 if (bRegex)
4068 if (std::regex_search(std::wstring(str), pat, flags))
4070 bFound = true;
4071 break;
4074 else
4076 if (bMatchCase)
4078 if (str.Find(findText) >= 0)
4080 bFound = true;
4081 break;
4085 else
4087 CString msg = str;
4088 msg = msg.MakeLower();
4089 CString find = findText.MakeLower();
4090 if (msg.Find(find) >= 0)
4092 bFound = TRUE;
4093 break;
4097 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4099 } // if(m_pFindDialog->FindNext())
4100 //UpdateLogInfoLabel();
4102 if (bFound)
4104 m_nSearchIndex = i;
4105 EnsureVisible(i, FALSE);
4106 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4108 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4109 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4110 SetSelectionMark(i);
4112 else
4114 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4115 if (pLogEntry)
4116 m_highlight = pLogEntry->m_CommitHash;
4118 Invalidate();
4119 //FillLogMessageCtrl();
4120 UpdateData(FALSE);
4123 return 0;
4126 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4128 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4130 *pResult = FALSE;
4133 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4135 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4137 Invalidate(FALSE);