Fixed issue #2170: Please add interface to "git svn log -v"
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob016a6d8c9d4e862d63ad60fb6a999f82914ee26d
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);
80 m_bShowBugtraqColumn=false;
82 m_IsIDReplaceAction=FALSE;
84 this->m_critSec.Init();
85 m_critSec_AsyncDiff.Init();
86 m_wcRev.m_CommitHash.Empty();
87 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
88 m_wcRev.m_ParentHash.clear();
89 m_wcRev.m_Mark=_T('-');
90 m_wcRev.m_IsUpdateing=FALSE;
91 m_wcRev.m_IsFull = TRUE;
93 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
94 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
95 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
96 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
97 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
99 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
101 m_From = -1;
102 m_To = -1;
104 m_ShowMask = 0;
105 m_LoadingThread = NULL;
107 InterlockedExchange(&m_bExitThread,FALSE);
108 m_IsOldFirst = FALSE;
109 m_IsRebaseReplaceGraph = FALSE;
111 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
113 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
115 // get short/long datetime setting from registry
116 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
117 if ( RegUseShortDateFormat )
119 m_DateFormat = DATE_SHORTDATE;
121 else
123 m_DateFormat = DATE_LONGDATE;
125 // get relative time display setting from registry
126 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
127 m_bRelativeTimes = (regRelativeTimes != 0);
128 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
130 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
131 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
132 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
133 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
134 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
135 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
136 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
138 m_ColumnRegKey=_T("log");
140 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
141 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
142 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
144 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
145 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
147 m_AsyncThreadExit = FALSE;
148 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
149 m_AsynDiffListLock.Init();
151 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
152 if (m_DiffingThread ==NULL)
154 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
155 return;
160 int CGitLogListBase::AsyncDiffThread()
162 m_AsyncThreadExited = false;
163 while(!m_AsyncThreadExit)
165 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
167 GitRev *pRev = NULL;
168 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
170 m_AsynDiffListLock.Lock();
171 pRev = m_AsynDiffList.back();
172 m_AsynDiffList.pop_back();
173 m_AsynDiffListLock.Unlock();
175 if( pRev->m_CommitHash.IsEmpty() )
177 if(pRev->m_IsDiffFiles)
178 continue;
180 pRev->GetFiles(this).Clear();
181 pRev->m_ParentHash.clear();
182 pRev->m_ParentHash.push_back(m_HeadHash);
183 if(g_Git.IsInitRepos())
185 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
186 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
189 else
191 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
193 int dummyAction = 0;
194 int *action = &dummyAction;
195 SafeGetAction(pRev, &action);
196 *action = 0;
198 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
199 *action |= pRev->GetFiles(this)[j].m_Action;
201 CString err;
202 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
204 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
205 return -1;
208 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
209 InterlockedExchange(&pRev->m_IsFull, TRUE);
211 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
212 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
213 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
216 m_critSec_AsyncDiff.Lock();
217 int ret = pRev->CheckAndDiff();
218 m_critSec_AsyncDiff.Unlock();
219 if (!ret)
220 { // fetch change file list
221 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
223 if(i < m_arShownList.GetCount())
225 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
226 if(data->m_CommitHash == pRev->m_CommitHash)
228 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
229 break;
234 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
236 POSITION pos = GetFirstSelectedItemPosition();
237 int nItem = GetNextSelectedItem(pos);
239 if(nItem>=0)
241 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(nItem);
242 if(data)
243 if(data->m_CommitHash == pRev->m_CommitHash)
245 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
252 m_AsyncThreadExited = true;
253 return 0;
255 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
257 if (exclusivelyShow)
259 m_ContextMenuMask &= hideMask;
261 else
263 m_ContextMenuMask &= ~hideMask;
267 CGitLogListBase::~CGitLogListBase()
269 InterlockedExchange(&m_bNoDispUpdates, TRUE);
270 this->m_arShownList.SafeRemoveAll();
272 DestroyIcon(m_hModifiedIcon);
273 DestroyIcon(m_hReplacedIcon);
274 DestroyIcon(m_hAddedIcon);
275 DestroyIcon(m_hDeletedIcon);
276 m_logEntries.ClearAll();
278 if (m_boldFont)
279 DeleteObject(m_boldFont);
281 if ( m_pStoreSelection )
283 delete m_pStoreSelection;
284 m_pStoreSelection = NULL;
287 SafeTerminateThread();
288 SafeTerminateAsyncDiffThread();
290 if(m_AsyncDiffEvent)
291 CloseHandle(m_AsyncDiffEvent);
295 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
296 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
297 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
298 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
299 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
300 ON_WM_CONTEXTMENU()
301 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
302 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
303 ON_WM_CREATE()
304 ON_WM_DESTROY()
305 ON_MESSAGE(MSG_LOADED,OnLoad)
306 ON_WM_MEASUREITEM()
307 ON_WM_MEASUREITEM_REFLECT()
308 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
309 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
310 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
311 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
312 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
313 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
314 END_MESSAGE_MAP()
316 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
318 //if (m_nRowHeight>0)
320 lpMeasureItemStruct->itemHeight = 50;
324 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
326 PreSubclassWindow();
327 return CHintListCtrl::OnCreate(lpCreateStruct);
330 void CGitLogListBase::PreSubclassWindow()
332 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
333 // load the icons for the action columns
334 // m_Theme.Open(m_hWnd, L"ListView");
335 SetWindowTheme(m_hWnd, L"Explorer", NULL);
336 CHintListCtrl::PreSubclassWindow();
339 CString CGitLogListBase::GetRebaseActionName(int action)
341 if (action & LOGACTIONS_REBASE_EDIT)
342 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
343 if (action & LOGACTIONS_REBASE_SQUASH)
344 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
345 if (action & LOGACTIONS_REBASE_PICK)
346 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
347 if (action & LOGACTIONS_REBASE_SKIP)
348 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
350 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
353 void CGitLogListBase::InsertGitColumn()
355 CString temp;
357 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
358 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
359 if (DWORD(regFullRowSelect))
360 exStyle |= LVS_EX_FULLROWSELECT;
361 SetExtendedStyle(exStyle);
363 // only load properties if we have a repository
364 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
365 UpdateProjectProperties();
367 static UINT normal[] =
369 IDS_LOG_GRAPH,
370 IDS_LOG_REBASE,
371 IDS_LOG_ID,
372 IDS_LOG_HASH,
373 IDS_LOG_ACTIONS,
374 IDS_LOG_MESSAGE,
375 IDS_LOG_AUTHOR,
376 IDS_LOG_DATE,
377 IDS_LOG_EMAIL,
378 IDS_LOG_COMMIT_NAME,
379 IDS_LOG_COMMIT_EMAIL,
380 IDS_LOG_COMMIT_DATE,
381 IDS_LOG_BUGIDS,
382 IDS_LOG_SVNREV,
385 static int with[] =
387 ICONITEMBORDER+16*4,
388 ICONITEMBORDER+16*4,
389 ICONITEMBORDER+16*4,
390 ICONITEMBORDER+16*4,
391 ICONITEMBORDER+16*4,
392 LOGLIST_MESSAGE_MIN,
393 ICONITEMBORDER+16*4,
394 ICONITEMBORDER+16*4,
395 ICONITEMBORDER+16*4,
396 ICONITEMBORDER+16*4,
397 ICONITEMBORDER+16*4,
398 ICONITEMBORDER+16*4,
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
402 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
404 DWORD hideColumns = 0;
405 if(this->m_IsRebaseReplaceGraph)
407 hideColumns |= GIT_LOG_GRAPH;
408 m_dwDefaultColumns |= GIT_LOG_REBASE;
410 else
412 hideColumns |= GIT_LOG_REBASE;
415 if(this->m_IsIDReplaceAction)
417 hideColumns |= GIT_LOG_ACTIONS;
418 m_dwDefaultColumns |= GIT_LOG_ID;
419 m_dwDefaultColumns |= GIT_LOG_HASH;
421 else
423 hideColumns |= GIT_LOG_ID;
425 if(this->m_bShowBugtraqColumn)
427 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
429 else
431 hideColumns |= GIT_LOGLIST_BUG;
433 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
434 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
435 else
436 hideColumns |= GIT_LOGLIST_SVNREV;
437 SetRedraw(false);
439 m_ColumnManager.SetNames(normal, _countof(normal));
440 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
442 SetRedraw(true);
446 * Resizes all columns in a list control to values in registry.
448 void CGitLogListBase::ResizeAllListCtrlCols()
450 // column max and min widths to allow
451 static const int nMinimumWidth = 10;
452 static const int nMaximumWidth = 1000;
453 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
454 if (pHdrCtrl)
456 int numcols = pHdrCtrl->GetItemCount();
457 for (int col = 0; col < numcols; ++col)
459 // get width for this col last time from registry
460 CString regentry;
461 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
462 CRegDWORD regwidth(regentry, 0);
463 int cx = regwidth;
464 if ( cx == 0 )
466 // no saved value, setup sensible defaults
467 if (col == this->LOGLIST_MESSAGE)
469 cx = LOGLIST_MESSAGE_MIN;
471 else
473 cx = ICONITEMBORDER+16*4;
476 if (cx < nMinimumWidth)
478 cx = nMinimumWidth;
480 else if (cx > nMaximumWidth)
482 cx = nMaximumWidth;
485 SetColumnWidth(col, cx);
492 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
494 LVITEM rItem;
495 SecureZeroMemory(&rItem, sizeof(LVITEM));
496 rItem.mask = LVIF_STATE;
497 rItem.iItem = (int)Index;
498 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
499 GetItem(&rItem);
501 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
502 HBRUSH brush = NULL;
504 if (!(rItem.state & LVIS_SELECTED))
506 int action = pLogEntry->GetRebaseAction();
507 if (action & LOGACTIONS_REBASE_SQUASH)
508 brush = ::CreateSolidBrush(RGB(156,156,156));
509 else if (action & LOGACTIONS_REBASE_EDIT)
510 brush = ::CreateSolidBrush(RGB(200,200,128));
512 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
514 if (rItem.state & LVIS_SELECTED)
516 if (::GetFocus() == m_hWnd)
517 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
518 else
519 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
522 if (brush != NULL)
524 ::FillRect(hdc, &rect, brush);
525 ::DeleteObject(brush);
529 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
531 POINT point = { 4, 4 };
532 CRect rt2 = rect;
533 rt2.DeflateRect(1, 1);
534 rt2.OffsetRect(2, 2);
536 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
537 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
538 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
539 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
540 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
542 ::SelectObject(hdc, brush);
543 rt2.OffsetRect(-2, -2);
544 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
545 ::SelectObject(hdc, oldbrush);
546 ::SelectObject(hdc, oldpen);
547 ::DeleteObject(nullPen);
548 ::DeleteObject(darkBrush);
551 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
553 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
554 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
555 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
556 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
557 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
558 ::LineTo(hdc, rect.left, rect.bottom);
559 ::SelectObject(hdc, oldpen);
560 ::DeleteObject(pen);
563 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
565 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
566 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
567 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
568 ::LineTo(hdc, rect.left, rect.bottom);
569 ::LineTo(hdc, rect.right, rect.bottom);
570 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
571 ::SelectObject(hdc, oldpen);
572 ::DeleteObject(pen);
575 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
577 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
578 CRect rt=rect;
579 LVITEM rItem;
580 SecureZeroMemory(&rItem, sizeof(LVITEM));
581 rItem.mask = LVIF_STATE;
582 rItem.iItem = (int)index;
583 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
584 GetItem(&rItem);
586 CDC W_Dc;
587 W_Dc.Attach(hdc);
589 HTHEME hTheme = NULL;
590 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
591 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
593 SIZE oneSpaceSize;
594 if (m_bTagsBranchesOnRightSide)
596 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
597 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
598 SelectObject(hdc, oldFont);
599 rt.left += oneSpaceSize.cx * 2;
601 else
603 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
604 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
605 rt.left += oneSpaceSize.cx;
608 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
610 int txtState = LISS_NORMAL;
611 if (rItem.state & LVIS_SELECTED)
612 txtState = LISS_SELECTED;
614 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
616 else
618 if (rItem.state & LVIS_SELECTED)
620 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
621 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
622 ::SetTextColor(hdc, clrOld);
624 else
626 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
630 if (m_bTagsBranchesOnRightSide)
632 SIZE size;
633 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
635 rt.left += oneSpaceSize.cx + size.cx;
637 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
640 if (hTheme)
641 CloseThemeData(hTheme);
643 W_Dc.Detach();
646 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
648 for (unsigned int i = 0; i < refList.size(); ++i)
650 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
651 HBRUSH brush = 0;
652 COLORREF colRef = refList[i].color;
653 bool singleRemote = refList[i].singleRemote;
654 bool hasTracking = refList[i].hasTracking;
655 bool sameName = refList[i].sameName;
656 bool annotatedTag = refList[i].annotatedTag;
658 //When row selected, ajust label color
659 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
661 if (rItem.state & LVIS_SELECTED)
662 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
665 brush = ::CreateSolidBrush(colRef);
667 if (!shortname.IsEmpty() && (rt.left < rect.right))
669 SIZE size;
670 memset(&size,0,sizeof(SIZE));
671 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
673 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
674 rt.right += 8;
676 int textpos = DT_CENTER;
678 if (rt.right > rect.right)
680 rt.right = rect.right;
681 textpos = 0;
684 CRect textRect = rt;
686 if (singleRemote)
688 rt.right += 8;
689 textRect.OffsetRect(8, 0);
692 if (sameName)
693 rt.right += 8;
695 if (hasTracking)
697 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
699 else
701 //Fill interior of ref label
702 ::FillRect(hdc, &rt, brush);
705 //Draw edge of label
706 CRect rectEdge = rt;
708 if (!hasTracking)
710 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
711 rectEdge.DeflateRect(1, 1);
712 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
715 if (annotatedTag)
717 rt.right += 8;
718 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
719 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
720 ::FillRgn(hdc, hrgn, brush);
721 ::DeleteObject(hrgn);
722 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
723 HPEN pen;
724 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
725 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
726 ::DeleteObject(pen);
727 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
728 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
729 ::DeleteObject(pen);
730 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
731 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
732 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
733 ::DeleteObject(pen);
734 SelectObject(hdc, oldpen);
737 //Draw text inside label
738 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
739 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
741 int txtState = LISS_NORMAL;
742 if (rItem.state & LVIS_SELECTED)
743 txtState = LISS_SELECTED;
745 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
747 else
749 W_Dc.SetBkMode(TRANSPARENT);
750 if (customColor || (rItem.state & LVIS_SELECTED))
752 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
753 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
754 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
755 ::SetTextColor(hdc,clrOld);
757 else
759 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
763 if (singleRemote)
765 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
766 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
767 CRect newRect;
768 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
769 DrawLightning(hdc, newRect, color, bold);
772 if (sameName)
774 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
775 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
776 CRect newRect;
777 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
778 DrawUpTriangle(hdc, newRect, color, bold);
781 rt.left = rt.right + 1;
783 if (brush)
784 ::DeleteObject(brush);
786 rt.right = rect.right;
789 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
791 // Returns ((256 - amount)*col1 + amount*col2) / 256;
792 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
793 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
794 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
797 Gdiplus::Color GetGdiColor(COLORREF col)
799 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
801 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
802 const COLORREF& col,const COLORREF& activeColor, int top
805 int h = laneHeight / 2;
806 int m = (x1 + x2) / 2;
807 int r = (x2 - x1) * m_NodeSize / 30;
808 int d = 2 * r;
810 #define P_CENTER m , h+top
811 #define P_0 x2, h+top
812 #define P_90 m , 0+top-1
813 #define P_180 x1, h+top
814 #define P_270 m , 2 * h+top +1
815 #define R_CENTER m - r, h - r+top, d, d
818 #define DELTA_UR_B 2*(x1 - m), 2*h +top
819 #define DELTA_UR_E 0*16, 90*16 +top // -,
821 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
822 #define DELTA_DR_E 270*16, 90*16 +top // -'
824 #define DELTA_UL_B 2*(x2 - m), 2*h +top
825 #define DELTA_UL_E 90*16, 90*16 +top // ,-
827 #define DELTA_DL_B 2*(x2 - m),2*-h +top
828 #define DELTA_DL_E 180*16, 90*16 // '-
830 #define CENTER_UR x1, 2*h, 225
831 #define CENTER_DR x1, 0 , 135
832 #define CENTER_UL x2, 2*h, 315
833 #define CENTER_DL x2, 0 , 45
836 Gdiplus::Graphics graphics( hdc );
838 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
840 // arc
841 switch (type) {
842 case Lanes::JOIN:
843 case Lanes::JOIN_R:
844 case Lanes::HEAD:
845 case Lanes::HEAD_R:
847 Gdiplus::LinearGradientBrush gradient(
848 Gdiplus::Point(x1-2, h+top-2),
849 Gdiplus::Point(P_270),
850 GetGdiColor(activeColor),GetGdiColor(col));
853 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
854 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
856 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
857 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
858 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
860 break;
862 case Lanes::JOIN_L:
865 Gdiplus::LinearGradientBrush gradient(
866 Gdiplus::Point(P_270),
867 Gdiplus::Point(x2+1, h+top-1),
868 GetGdiColor(col),GetGdiColor(activeColor));
871 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
872 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
874 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
875 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
876 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
879 break;
881 case Lanes::TAIL:
882 case Lanes::TAIL_R:
885 Gdiplus::LinearGradientBrush gradient(
886 Gdiplus::Point(x1-2, h+top-2),
887 Gdiplus::Point(P_90),
888 GetGdiColor(activeColor),GetGdiColor(col));
890 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
892 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
894 #if 0
895 QConicalGradient gradient(CENTER_DR);
896 gradient.setColorAt(0.375, activeCol);
897 gradient.setColorAt(0.625, col);
898 myPen.setBrush(gradient);
899 p->setPen(myPen);
900 p->drawArc(P_CENTER, DELTA_DR);
901 #endif
902 break;
904 default:
905 break;
909 //static QPen myPen(Qt::black, 2); // fast path here
910 CPen pen;
911 pen.CreatePen(PS_SOLID,2,col);
912 //myPen.setColor(col);
913 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
915 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
917 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
919 //p->setPen(myPen);
921 // vertical line
922 switch (type) {
923 case Lanes::ACTIVE:
924 case Lanes::NOT_ACTIVE:
925 case Lanes::MERGE_FORK:
926 case Lanes::MERGE_FORK_R:
927 case Lanes::MERGE_FORK_L:
928 case Lanes::JOIN:
929 case Lanes::JOIN_R:
930 case Lanes::JOIN_L:
931 case Lanes::CROSS:
932 //DrawLine(hdc,P_90,P_270);
933 graphics.DrawLine(&myPen,P_90,P_270);
934 //p->drawLine(P_90, P_270);
935 break;
936 case Lanes::HEAD_L:
937 case Lanes::BRANCH:
938 //DrawLine(hdc,P_CENTER,P_270);
939 graphics.DrawLine(&myPen,P_CENTER,P_270);
940 //p->drawLine(P_CENTER, P_270);
941 break;
942 case Lanes::TAIL_L:
943 case Lanes::INITIAL:
944 case Lanes::BOUNDARY:
945 case Lanes::BOUNDARY_C:
946 case Lanes::BOUNDARY_R:
947 case Lanes::BOUNDARY_L:
948 //DrawLine(hdc,P_90, P_CENTER);
949 graphics.DrawLine(&myPen,P_90,P_CENTER);
950 //p->drawLine(P_90, P_CENTER);
951 break;
952 default:
953 break;
956 myPen.SetColor(GetGdiColor(activeColor));
958 // horizontal line
959 switch (type) {
960 case Lanes::MERGE_FORK:
961 case Lanes::JOIN:
962 case Lanes::HEAD:
963 case Lanes::TAIL:
964 case Lanes::CROSS:
965 case Lanes::CROSS_EMPTY:
966 case Lanes::BOUNDARY_C:
967 //DrawLine(hdc,P_180,P_0);
968 graphics.DrawLine(&myPen,P_180,P_0);
969 //p->drawLine(P_180, P_0);
970 break;
971 case Lanes::MERGE_FORK_R:
972 case Lanes::BOUNDARY_R:
973 //DrawLine(hdc,P_180,P_CENTER);
974 graphics.DrawLine(&myPen,P_180,P_CENTER);
975 //p->drawLine(P_180, P_CENTER);
976 break;
977 case Lanes::MERGE_FORK_L:
978 case Lanes::HEAD_L:
979 case Lanes::TAIL_L:
980 case Lanes::BOUNDARY_L:
981 //DrawLine(hdc,P_CENTER,P_0);
982 graphics.DrawLine(&myPen,P_CENTER,P_0);
983 //p->drawLine(P_CENTER, P_0);
984 break;
985 default:
986 break;
989 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
991 CBrush brush;
992 brush.CreateSolidBrush(col);
993 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
995 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
996 // center symbol, e.g. rect or ellipse
997 switch (type) {
998 case Lanes::ACTIVE:
999 case Lanes::INITIAL:
1000 case Lanes::BRANCH:
1002 //p->setPen(Qt::NoPen);
1003 //p->setBrush(col);
1004 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1005 graphics.FillEllipse(&myBrush, R_CENTER);
1006 //p->drawEllipse(R_CENTER);
1007 break;
1008 case Lanes::MERGE_FORK:
1009 case Lanes::MERGE_FORK_R:
1010 case Lanes::MERGE_FORK_L:
1011 //p->setPen(Qt::NoPen);
1012 //p->setBrush(col);
1013 //p->drawRect(R_CENTER);
1014 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1015 graphics.FillRectangle(&myBrush, R_CENTER);
1016 break;
1017 case Lanes::UNAPPLIED:
1018 // Red minus sign
1019 //p->setPen(Qt::NoPen);
1020 //p->setBrush(Qt::red);
1021 //p->drawRect(m - r, h - 1, d, 2);
1022 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1023 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1024 break;
1025 case Lanes::APPLIED:
1026 // Green plus sign
1027 //p->setPen(Qt::NoPen);
1028 //p->setBrush(DARK_GREEN);
1029 //p->drawRect(m - r, h - 1, d, 2);
1030 //p->drawRect(m - 1, h - r, 2, d);
1031 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1032 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1033 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1034 break;
1035 case Lanes::BOUNDARY:
1036 //p->setBrush(back);
1037 //p->drawEllipse(R_CENTER);
1038 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1039 graphics.DrawEllipse(&myPen, R_CENTER);
1040 break;
1041 case Lanes::BOUNDARY_C:
1042 case Lanes::BOUNDARY_R:
1043 case Lanes::BOUNDARY_L:
1044 //p->setBrush(back);
1045 //p->drawRect(R_CENTER);
1046 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1047 graphics.FillRectangle(&myBrush,R_CENTER);
1048 break;
1049 default:
1050 break;
1053 ::SelectObject(hdc,oldpen);
1054 ::SelectObject(hdc,oldbrush);
1055 #undef P_CENTER
1056 #undef P_0
1057 #undef P_90
1058 #undef P_180
1059 #undef P_270
1060 #undef R_CENTER
1063 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1065 // TODO: unfinished
1066 // return;
1067 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1068 if(data->m_CommitHash.IsEmpty())
1069 return;
1071 CRect rt=rect;
1072 LVITEM rItem;
1073 SecureZeroMemory(&rItem, sizeof(LVITEM));
1074 rItem.mask = LVIF_STATE;
1075 rItem.iItem = (int)index;
1076 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1077 GetItem(&rItem);
1079 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1081 if (data->m_Lanes.empty())
1082 m_logEntries.setLane(data->m_CommitHash);
1084 std::vector<int>& lanes=data->m_Lanes;
1085 size_t laneNum = lanes.size();
1086 UINT activeLane = 0;
1087 for (UINT i = 0; i < laneNum; ++i)
1088 if (Lanes::isMerge(lanes[i])) {
1089 activeLane = i;
1090 break;
1093 int x2 = 0;
1094 int maxWidth = rect.Width();
1095 int lw = 3 * rect.Height() / 4; //laneWidth()
1097 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1098 //if (opt.state & QStyle::State_Selected)
1099 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1101 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1104 int x1 = x2;
1105 x2 += lw;
1107 int ln = lanes[i];
1108 if (ln == Lanes::EMPTY)
1109 continue;
1111 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1112 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1115 #if 0
1116 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1118 int x1 = x2;
1119 x2 += lw;
1121 int ln = lanes[i];
1122 if (ln == Lanes::EMPTY)
1123 continue;
1125 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1126 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1128 if (ln == Lanes::CROSS)
1130 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1131 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1133 else
1134 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1136 #endif
1140 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1143 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1144 // Take the default processing unless we set this to something else below.
1145 *pResult = CDRF_DODEFAULT;
1147 if (m_bNoDispUpdates)
1148 return;
1150 switch (pLVCD->nmcd.dwDrawStage)
1152 case CDDS_PREPAINT:
1154 *pResult = CDRF_NOTIFYITEMDRAW;
1155 return;
1157 break;
1158 case CDDS_ITEMPREPAINT:
1160 // This is the prepaint stage for an item. Here's where we set the
1161 // item's text color.
1163 // Tell Windows to send draw notifications for each subitem.
1164 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1166 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1168 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1170 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1171 if (data)
1173 int action = data->GetRebaseAction();
1174 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1175 crText = RGB(128,128,128);
1177 if (action & LOGACTIONS_REBASE_SQUASH)
1178 pLVCD->clrTextBk = RGB(156,156,156);
1179 else if (action & LOGACTIONS_REBASE_EDIT)
1180 pLVCD->clrTextBk = RGB(200,200,128);
1181 else
1182 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1184 if (action & LOGACTIONS_REBASE_CURRENT)
1186 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1187 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1190 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1192 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1193 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1196 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1197 // crText = GetSysColor(COLOR_GRAYTEXT);
1199 if (data->m_CommitHash.IsEmpty())
1201 //crText = GetSysColor(RGB(200,200,0));
1202 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1203 // We changed the font, so we're returning CDRF_NEWFONT. This
1204 // tells the control to recalculate the extent of the text.
1205 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1209 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1211 if (m_bStrictStopped)
1212 crText = GetSysColor(COLOR_GRAYTEXT);
1214 // Store the color back in the NMLVCUSTOMDRAW struct.
1215 pLVCD->clrText = crText;
1216 return;
1218 break;
1219 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1221 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1223 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1226 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1228 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1230 CRect rect;
1231 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1233 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1234 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1236 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1237 if( !data ->m_CommitHash.IsEmpty())
1238 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1240 *pResult = CDRF_SKIPDEFAULT;
1241 return;
1245 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1247 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1249 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1251 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1253 CRect rect;
1254 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1256 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1257 // not in FillBackGround method, because this only affected the message subitem
1258 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1259 return;
1261 int index = (int)pLVCD->nmcd.dwItemSpec;
1262 int state = GetItemState(index, LVIS_SELECTED);
1263 int txtState = LISS_NORMAL;
1264 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1266 if (state & LVIS_SELECTED)
1267 txtState = LISS_HOTSELECTED;
1268 else
1269 txtState = LISS_HOT;
1271 else if (state & LVIS_SELECTED)
1273 if (::GetFocus() == m_hWnd)
1274 txtState = LISS_SELECTED;
1275 else
1276 txtState = LISS_SELECTEDNOTFOCUS;
1279 HTHEME hTheme = nullptr;
1280 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1281 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1283 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1284 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1285 else
1287 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1288 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1289 ::DeleteObject(brush);
1291 if (hTheme)
1293 CRect rt;
1294 // get rect of whole line
1295 GetItemRect(index, rt, LVIR_BOUNDS);
1296 CRect rect2 = rect;
1297 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1298 rect2.DeflateRect(1, 1, 1, 1);
1300 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1301 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1303 CloseThemeData(hTheme);
1305 // END: extended redraw
1307 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1309 std::vector<REFLABEL> refsToShow;
1310 STRING_VECTOR remoteTrackingList;
1311 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1312 for (unsigned int i = 0; i < refList.size(); ++i)
1314 CString str = refList[i];
1316 REFLABEL refLabel;
1317 refLabel.color = RGB(255, 255, 255);
1318 refLabel.singleRemote = false;
1319 refLabel.hasTracking = false;
1320 refLabel.sameName = false;
1321 refLabel.annotatedTag = false;
1322 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1324 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1325 continue;
1326 if (refLabel.name == m_CurrentBranch )
1327 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1328 else
1329 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1331 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1332 CString pullRemote = trackingEntry.first;
1333 CString pullBranch = trackingEntry.second;
1334 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1336 CString defaultUpstream;
1337 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1338 refLabel.hasTracking = true;
1339 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1341 bool found = false;
1342 for (size_t j = i + 1; j < refList.size(); ++j)
1344 if (refList[j] == defaultUpstream)
1346 found = true;
1347 break;
1351 if (found)
1353 bool sameName = pullBranch == refLabel.name;
1354 refsToShow.push_back(refLabel);
1355 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1356 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1357 if (m_bSymbolizeRefNames)
1359 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1361 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1362 refLabel.singleRemote = true;
1364 else if (sameName)
1365 refLabel.simplifiedName = pullRemote + _T("/");
1366 refLabel.sameName = sameName;
1368 refsToShow.push_back(refLabel);
1369 remoteTrackingList.push_back(defaultUpstream);
1370 continue;
1375 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1377 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1378 continue;
1380 bool found = false;
1381 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1383 if (remoteTrackingList[j] == str)
1385 found = true;
1386 break;
1389 if (found)
1390 continue;
1392 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1393 if (m_bSymbolizeRefNames)
1395 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1397 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1398 refLabel.singleRemote = true;
1402 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1404 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1405 continue;
1406 refLabel.color = m_Colors.GetColor(CColors::Tag);
1407 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1409 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1411 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1412 continue;
1413 refLabel.color = m_Colors.GetColor(CColors::Stash);
1414 refLabel.name = _T("stash");
1416 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1418 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1419 continue;
1420 if (refLabel.name.Find(_T("good")) == 0)
1422 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1423 refLabel.name = _T("good");
1425 if (refLabel.name.Find(_T("bad")) == 0)
1427 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1428 refLabel.name = _T("bad");
1431 else
1432 continue;
1434 refsToShow.push_back(refLabel);
1437 if (refsToShow.empty())
1439 *pResult = CDRF_DODEFAULT;
1440 return;
1443 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1445 *pResult = CDRF_SKIPDEFAULT;
1446 return;
1453 if (pLVCD->iSubItem == LOGLIST_ACTION)
1455 if(this->m_IsIDReplaceAction)
1457 *pResult = CDRF_DODEFAULT;
1458 return;
1460 *pResult = CDRF_DODEFAULT;
1462 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1463 return;
1465 int nIcons = 0;
1466 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1467 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1469 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1470 CRect rect;
1471 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1472 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1473 // Get the selected state of the
1474 // item being drawn.
1476 // Fill the background if necessary
1477 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1479 // Draw the icon(s) into the compatible DC
1480 int action = SafeGetAction(pLogEntry);
1482 if (!pLogEntry->m_IsDiffFiles)
1483 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1485 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1486 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1487 ++nIcons;
1489 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1490 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1491 ++nIcons;
1493 if (action & CTGitPath::LOGACTIONS_DELETED)
1494 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1495 ++nIcons;
1497 if (action & CTGitPath::LOGACTIONS_REPLACED)
1498 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1499 ++nIcons;
1500 *pResult = CDRF_SKIPDEFAULT;
1501 return;
1504 break;
1506 *pResult = CDRF_DODEFAULT;
1509 CString FindSVNRev(const CString& msg)
1513 const std::tr1::wsregex_iterator end;
1514 std::wstring s = msg;
1515 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)
1517 const std::tr1::wsmatch match = *it;
1518 if (match.size() == 4)
1520 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1521 return std::wstring(match[2]).c_str();
1524 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)
1526 const std::tr1::wsmatch match = *it;
1527 if (match.size() == 3)
1529 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1530 return std::wstring(match[1]).c_str();
1534 catch (std::exception) {}
1536 return _T("");
1539 // CGitLogListBase message handlers
1541 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1543 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1545 // Create a pointer to the item
1546 LV_ITEM* pItem = &(pDispInfo)->item;
1548 // Do the list need text information?
1549 if (!(pItem->mask & LVIF_TEXT))
1550 return;
1552 // By default, clear text buffer.
1553 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1555 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1557 *pResult = 0;
1558 if (m_bNoDispUpdates || bOutOfRange)
1559 return;
1561 // Which item number?
1562 int itemid = pItem->iItem;
1563 GitRev * pLogEntry = NULL;
1564 if (itemid < m_arShownList.GetCount())
1565 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1567 CString temp;
1568 if(m_IsOldFirst)
1570 temp.Format(_T("%d"),pItem->iItem+1);
1573 else
1575 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1578 // Which column?
1579 switch (pItem->iSubItem)
1581 case this->LOGLIST_GRAPH: //Graphic
1582 break;
1583 case this->LOGLIST_REBASE:
1585 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1586 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1588 break;
1589 case this->LOGLIST_ACTION: //action -- no text in the column
1590 break;
1591 case this->LOGLIST_HASH:
1592 if(pLogEntry)
1593 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1594 break;
1595 case this->LOGLIST_ID:
1596 if(this->m_IsIDReplaceAction)
1597 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1598 break;
1599 case this->LOGLIST_MESSAGE: //Message
1600 if (pLogEntry)
1601 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1602 break;
1603 case this->LOGLIST_AUTHOR: //Author
1604 if (pLogEntry)
1605 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1606 break;
1607 case this->LOGLIST_DATE: //Date
1608 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1609 lstrcpyn(pItem->pszText,
1610 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1611 pItem->cchTextMax);
1612 break;
1614 case this->LOGLIST_EMAIL:
1615 if (pLogEntry)
1616 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1617 break;
1619 case this->LOGLIST_COMMIT_NAME: //Commit
1620 if (pLogEntry)
1621 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1622 break;
1624 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1625 if (pLogEntry)
1626 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1627 break;
1629 case this->LOGLIST_COMMIT_DATE: //Commit Date
1630 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1631 lstrcpyn(pItem->pszText,
1632 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1633 pItem->cchTextMax);
1634 break;
1635 case this->LOGLIST_BUG: //Bug ID
1636 if(pLogEntry)
1637 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1638 break;
1639 case this->LOGLIST_SVNREV: //SVN revision
1640 if (pLogEntry)
1641 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1642 break;
1644 default:
1645 ASSERT(false);
1649 bool CGitLogListBase::IsOnStash(int index)
1651 GitRev *rev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index));
1652 if (IsStash(rev))
1653 return true;
1654 if (index > 0)
1656 GitRev *preRev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1));
1657 if (IsStash(preRev))
1658 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1660 return false;
1663 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1665 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1667 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1668 return true;
1670 return false;
1673 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1675 if (pRev->m_ParentHash.empty())
1679 pRev->GetParentFromHash(pRev->m_CommitHash);
1681 catch (const char* msg)
1683 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1686 parentHash = pRev->m_ParentHash;
1689 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1692 if (pWnd == GetHeaderCtrl())
1694 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1697 int selIndex = GetSelectionMark();
1698 if (selIndex < 0)
1699 return; // nothing selected, nothing to do with a context menu
1701 // if the user selected the info text telling about not all revisions shown due to
1702 // the "stop on copy/rename" option, we also don't show the context menu
1703 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1704 return;
1706 // if the context menu is invoked through the keyboard, we have to use
1707 // a calculated position on where to anchor the menu on
1708 if ((point.x == -1) && (point.y == -1))
1710 CRect rect;
1711 GetItemRect(selIndex, &rect, LVIR_LABEL);
1712 ClientToScreen(&rect);
1713 point = rect.CenterPoint();
1715 m_nSearchIndex = selIndex;
1716 m_bCancelled = FALSE;
1718 // calculate some information the context menu commands can use
1719 // CString pathURL = GetURLFromPath(m_path);
1721 POSITION pos = GetFirstSelectedItemPosition();
1722 int indexNext = GetNextSelectedItem(pos);
1723 if (indexNext < 0)
1724 return;
1726 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1727 if (pSelLogEntry == nullptr)
1728 return;
1729 #if 0
1730 GitRev revSelected = pSelLogEntry->Rev;
1731 GitRev revPrevious = git_revnum_t(revSelected)-1;
1732 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1734 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1736 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1737 if (changedpath->lCopyFromRev)
1738 revPrevious = changedpath->lCopyFromRev;
1741 GitRev revSelected2;
1742 if (pos)
1744 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1745 revSelected2 = pLogEntry->Rev;
1747 bool bAllFromTheSameAuthor = true;
1748 CString firstAuthor;
1749 CLogDataVector selEntries;
1750 GitRev revLowest, revHighest;
1751 GitRevRangeArray revisionRanges;
1753 POSITION pos = GetFirstSelectedItemPosition();
1754 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1755 revisionRanges.AddRevision(pLogEntry->Rev);
1756 selEntries.push_back(pLogEntry);
1757 firstAuthor = pLogEntry->sAuthor;
1758 revLowest = pLogEntry->Rev;
1759 revHighest = pLogEntry->Rev;
1760 while (pos)
1762 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1763 revisionRanges.AddRevision(pLogEntry->Rev);
1764 selEntries.push_back(pLogEntry);
1765 if (firstAuthor.Compare(pLogEntry->sAuthor))
1766 bAllFromTheSameAuthor = false;
1767 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1768 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1772 #endif
1774 int FirstSelect=-1, LastSelect=-1;
1775 pos = GetFirstSelectedItemPosition();
1776 FirstSelect = GetNextSelectedItem(pos);
1777 while(pos)
1779 LastSelect = GetNextSelectedItem(pos);
1781 //entry is selected, now show the popup menu
1782 CIconMenu popup;
1783 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1785 if (popup.CreatePopupMenu())
1787 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1788 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1789 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1790 bool isStash = IsOnStash(indexNext);
1791 GIT_REV_LIST parentHash;
1792 GetParentHashes(pSelLogEntry, parentHash);
1794 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1795 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1797 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1798 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1800 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1801 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1803 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1804 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1806 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)))
1807 popup.AppendMenu(MF_SEPARATOR, NULL);
1809 if (GetSelectedCount() == 1)
1812 bool requiresSeparator = false;
1813 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1815 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1817 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1818 requiresSeparator = true;
1821 else
1823 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1825 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1826 requiresSeparator = true;
1828 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1830 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1831 requiresSeparator = true;
1835 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1837 if (parentHash.size() == 1)
1839 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1840 requiresSeparator = true;
1842 else if (parentHash.size() > 1)
1844 blamemenu.CreatePopupMenu();
1845 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1846 for (size_t i = 0; i < parentHash.size(); ++i)
1848 CString str;
1849 str.Format(IDS_PARENT, i + 1);
1850 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1852 requiresSeparator = true;
1856 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1858 if (parentHash.size() == 1)
1860 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1861 requiresSeparator = true;
1863 else if (parentHash.size() > 1)
1865 gnudiffmenu.CreatePopupMenu();
1866 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1868 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1869 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1871 for (size_t i = 0; i < parentHash.size(); ++i)
1873 CString str;
1874 str.Format(IDS_PARENT, i + 1);
1875 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1877 requiresSeparator = true;
1881 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1883 if (parentHash.size() == 1)
1885 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1886 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1887 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1888 requiresSeparator = true;
1890 else if (parentHash.size() > 1)
1892 diffmenu.CreatePopupMenu();
1893 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1894 for (size_t i = 0; i < parentHash.size(); ++i)
1896 CString str;
1897 str.Format(IDS_PARENT, i + 1);
1898 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1899 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1901 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1902 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1905 requiresSeparator = true;
1909 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1911 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1912 requiresSeparator = true;
1915 if (requiresSeparator)
1916 popup.AppendMenu(MF_SEPARATOR, NULL);
1918 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1920 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1921 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1924 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1926 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1927 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1929 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1930 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1932 popup.AppendMenu(MF_SEPARATOR, NULL);
1935 if (pSelLogEntry->m_CommitHash.IsEmpty())
1937 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1938 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1940 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1941 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1943 popup.AppendMenu(MF_SEPARATOR, NULL);
1947 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1948 // {
1949 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1950 // }
1951 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1952 // {
1953 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1954 // }
1955 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1956 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1957 // {
1958 // popup.AppendMenu(MF_SEPARATOR, NULL);
1959 // }
1961 CString str,format;
1962 //if (m_hasWC)
1963 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1965 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1967 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1968 GetSelectedCount() == 1)
1969 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1971 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1972 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1974 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1975 str.Format(format,g_Git.GetCurrentBranch());
1977 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
1978 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1980 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1981 str.Format(format,g_Git.GetCurrentBranch());
1983 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
1984 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1987 // Add Switch Branch express Menu
1988 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1989 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
1992 std::vector<CString *> branchs;
1993 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1995 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1996 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1998 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2002 CString str;
2003 str.LoadString(IDS_SWITCH_BRANCH);
2005 if(branchs.size() == 1)
2007 str+=_T(" ");
2008 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
2009 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
2011 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2014 else if(branchs.size() > 1)
2016 subbranchmenu.CreatePopupMenu();
2017 for (size_t i = 0 ; i < branchs.size(); ++i)
2019 if (*branchs[i] != currentBranch)
2021 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2022 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2026 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2030 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2031 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2033 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2034 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2036 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2037 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2039 format.LoadString(IDS_REBASE_THIS_FORMAT);
2040 str.Format(format,g_Git.GetCurrentBranch());
2042 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2043 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2044 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2046 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2047 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2049 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2051 if (parentHash.size() == 1)
2053 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2055 else if (parentHash.size() > 1)
2057 revertmenu.CreatePopupMenu();
2058 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2060 for (size_t i = 0; i < parentHash.size(); ++i)
2062 CString str;
2063 str.Format(IDS_PARENT, i + 1);
2064 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2069 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2070 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2072 popup.AppendMenu(MF_SEPARATOR, NULL);
2077 if(!pSelLogEntry->m_Ref.IsEmpty())
2079 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2080 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2081 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2082 popup.AppendMenu(MF_SEPARATOR, NULL);
2085 if (GetSelectedCount() >= 2)
2087 bool bAddSeparator = false;
2088 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2090 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2091 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2094 if (GetSelectedCount() == 2)
2096 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2097 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2099 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2101 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2102 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2103 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2104 CString menu;
2105 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2106 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2107 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2108 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2111 bAddSeparator = true;
2114 if (m_hasWC)
2116 bAddSeparator = true;
2119 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2120 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2122 if (bAddSeparator)
2123 popup.AppendMenu(MF_SEPARATOR, NULL);
2126 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2128 bool bAddSeparator = false;
2129 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2131 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2133 CString head;
2134 int headindex;
2135 headindex = this->GetHeadIndex();
2136 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2138 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2139 CGitHash hashFirst;
2140 if (g_Git.GetHash(hashFirst, head))
2141 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2142 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2143 CGitHash hash;
2144 if (g_Git.GetHash(hash, head))
2145 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2146 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect));
2147 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2148 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2149 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2150 bAddSeparator = true;
2155 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2156 if (GetSelectedCount() >= 2)
2157 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2158 else
2159 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2160 bAddSeparator = true;
2163 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2164 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2165 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2166 bAddSeparator = true;
2169 if (bAddSeparator)
2170 popup.AppendMenu(MF_SEPARATOR, NULL);
2173 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())
2175 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2176 popup.AppendMenu(MF_SEPARATOR, NULL);
2179 if (GetSelectedCount() == 1)
2181 bool bAddSeparator = false;
2182 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2184 // show the push-option only if the log entry has an associated local branch
2185 bool isLocal = false;
2186 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2188 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2189 isLocal = true;
2191 if (isLocal)
2193 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2194 bAddSeparator = true;
2197 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive)
2199 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2200 bAddSeparator = true;
2204 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2206 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2208 std::vector<CString *> branchs;
2209 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2211 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2212 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2214 CString str;
2215 if (branchs.size() == 1)
2217 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2218 str+=_T(" ");
2219 str += *branchs[0];
2220 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2221 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2222 bAddSeparator = true;
2224 else if (branchs.size() > 1)
2226 str.LoadString(IDS_DELETE_BRANCHTAG);
2227 submenu.CreatePopupMenu();
2228 for (size_t i = 0; i < branchs.size(); ++i)
2230 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2231 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2234 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2235 bAddSeparator = true;
2238 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2239 if (bAddSeparator)
2240 popup.AppendMenu(MF_SEPARATOR, NULL);
2241 } // GetSelectedCount() == 1
2243 if (GetSelectedCount() != 0)
2245 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2246 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2247 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2248 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2249 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2250 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2253 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2254 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2256 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2257 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2259 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2260 // DialogEnableWindow(IDOK, FALSE);
2261 // SetPromptApp(&theApp);
2263 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2265 // EnableOKButton();
2266 } // if (popup.CreatePopupMenu())
2270 bool CGitLogListBase::IsSelectionContinuous()
2272 if ( GetSelectedCount()==1 )
2274 // if only one revision is selected, the selection is of course
2275 // continuous
2276 return true;
2279 POSITION pos = GetFirstSelectedItemPosition();
2280 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2281 if (bContinuous)
2283 int itemindex = GetNextSelectedItem(pos);
2284 while (pos)
2286 int nextindex = GetNextSelectedItem(pos);
2287 if (nextindex - itemindex > 1)
2289 bContinuous = false;
2290 break;
2292 itemindex = nextindex;
2295 return bContinuous;
2298 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2301 CString sClipdata;
2302 POSITION pos = GetFirstSelectedItemPosition();
2303 if (pos != NULL)
2305 CString sRev;
2306 sRev.LoadString(IDS_LOG_REVISION);
2307 CString sAuthor;
2308 sAuthor.LoadString(IDS_LOG_AUTHOR);
2309 CString sDate;
2310 sDate.LoadString(IDS_LOG_DATE);
2311 CString sMessage;
2312 sMessage.LoadString(IDS_LOG_MESSAGE);
2313 bool first = true;
2314 while (pos)
2316 CString sLogCopyText;
2317 CString sPaths;
2318 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2320 if (toCopy == ID_COPY_ALL)
2322 //pLogEntry->GetFiles(this)
2323 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2325 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2326 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2328 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2329 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2331 CString rename;
2332 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2333 sPaths += _T(" ") + rename;
2335 sPaths += _T("\r\n");
2337 sPaths.Trim();
2338 CString body = pLogEntry->GetBody();
2339 body.Replace(_T("\n"), _T("\r\n"));
2340 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"),
2341 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2342 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2343 (LPCTSTR)sDate,
2344 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2345 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2346 (LPCTSTR)sPaths);
2347 sClipdata += sLogCopyText;
2349 else if (toCopy == ID_COPY_MESSAGE)
2351 CString body = pLogEntry->GetBody();
2352 body.Replace(_T("\n"), _T("\r\n"));
2353 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2355 else if (toCopy == ID_COPY_SUBJECT)
2357 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2359 else
2361 if (!first)
2362 sClipdata += _T("\r\n");
2363 sClipdata += pLogEntry->m_CommitHash;
2366 first = false;
2368 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2373 void CGitLogListBase::DiffSelectedRevWithPrevious()
2375 if (m_bThreadRunning)
2376 return;
2378 int FirstSelect=-1, LastSelect=-1;
2379 POSITION pos = GetFirstSelectedItemPosition();
2380 FirstSelect = GetNextSelectedItem(pos);
2381 while(pos)
2383 LastSelect = GetNextSelectedItem(pos);
2386 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2388 #if 0
2389 UpdateLogInfoLabel();
2390 int selIndex = m_LogList.GetSelectionMark();
2391 if (selIndex < 0)
2392 return;
2393 int selCount = m_LogList.GetSelectedCount();
2394 if (selCount != 1)
2395 return;
2397 // Find selected entry in the log list
2398 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2399 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2400 long rev1 = pLogEntry->Rev;
2401 long rev2 = rev1-1;
2402 CTGitPath path = m_path;
2404 // See how many files under the relative root were changed in selected revision
2405 int nChanged = 0;
2406 LogChangedPath * changed = NULL;
2407 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2409 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2410 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2412 ++nChanged;
2413 changed = cpath;
2417 if (m_path.IsDirectory() && nChanged == 1)
2419 // We're looking at the log for a directory and only one file under dir was changed in the revision
2420 // Do diff on that file instead of whole directory
2421 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2424 m_bCancelled = FALSE;
2425 DialogEnableWindow(IDOK, FALSE);
2426 SetPromptApp(&theApp);
2427 theApp.DoWaitCursor(1);
2429 if (PromptShown())
2431 GitDiff diff(this, m_hWnd, true);
2432 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2433 diff.SetHEADPeg(m_LogRevision);
2434 diff.ShowCompare(path, rev2, path, rev1);
2436 else
2438 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2441 theApp.DoWaitCursor(-1);
2442 EnableOKButton();
2443 #endif
2446 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2448 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2449 *pResult = -1;
2451 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2452 return;
2453 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2454 return;
2455 if (pFindInfo->lvfi.psz == 0)
2456 return;
2457 #if 0
2458 CString sCmp = pFindInfo->lvfi.psz;
2459 CString sRev;
2460 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2462 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2463 sRev.Format(_T("%ld"), pLogEntry->Rev);
2464 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2466 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2468 *pResult = i;
2469 return;
2472 else
2474 if (sCmp.Compare(sRev)==0)
2476 *pResult = i;
2477 return;
2481 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2483 for (int i=0; i<pFindInfo->iStart; ++i)
2485 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2486 sRev.Format(_T("%ld"), pLogEntry->Rev);
2487 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2489 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2491 *pResult = i;
2492 return;
2495 else
2497 if (sCmp.Compare(sRev)==0)
2499 *pResult = i;
2500 return;
2505 #endif
2506 *pResult = -1;
2509 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2511 ClearText();
2513 this->m_arShownList.SafeRemoveAll();
2515 this->m_logEntries.ClearAll();
2516 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2517 return -1;
2519 //this->m_logEntries.ParserFromLog();
2520 SetItemCountEx((int)m_logEntries.size());
2522 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2524 if(m_IsOldFirst)
2526 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2527 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2530 else
2532 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2533 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2537 ReloadHashMap();
2539 if(path)
2540 m_Path=*path;
2541 return 0;
2545 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2547 ClearText();
2549 m_arShownList.SafeRemoveAll();
2551 m_logEntries.ClearAll();
2552 if (m_logEntries.Fill(hashes))
2553 return -1;
2555 SetItemCountEx((int)m_logEntries.size());
2557 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2559 if (m_IsOldFirst)
2561 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2562 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2564 else
2566 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2567 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2571 ReloadHashMap();
2573 return 0;
2576 int CGitLogListBase::BeginFetchLog()
2578 ClearText();
2580 this->m_arShownList.SafeRemoveAll();
2582 this->m_logEntries.ClearAll();
2584 this->m_LogCache.ClearAllParent();
2586 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2588 CTGitPath *path;
2589 if(this->m_Path.IsEmpty())
2590 path=NULL;
2591 else
2592 path=&this->m_Path;
2594 int mask;
2595 mask = CGit::LOG_INFO_ONLY_HASH;
2596 if (m_bIncludeBoundaryCommits)
2597 mask |= CGit::LOG_INFO_BOUNDARY;
2598 // if(this->m_bAllBranch)
2599 mask |= m_ShowMask ;
2601 if(m_bShowWC)
2603 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2604 ResetWcRev();
2605 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2608 if (m_sRange.IsEmpty())
2609 m_sRange = _T("HEAD");
2611 CFilterData data;
2612 data.m_From = m_From;
2613 data.m_To =m_To;
2615 #if 0 /* use tortoiegit filter */
2616 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2617 data.m_Author = this->m_sFilterText;
2619 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2620 data.m_MessageFilter = this->m_sFilterText;
2622 data.m_IsRegex = m_bFilterWithRegex;
2623 #endif
2625 // follow does not work for directories
2626 if (!path || path->IsDirectory())
2627 mask &= ~CGit::LOG_INFO_FOLLOW;
2628 // follow does not work with all branches 8at least in TGit)
2629 if (mask & CGit::LOG_INFO_FOLLOW)
2630 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2632 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2634 //this->m_logEntries.ParserFromLog();
2635 if(IsInWorkingThread())
2637 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2639 else
2641 SetItemCountEx((int)m_logEntries.size());
2646 [] { git_init(); } ();
2648 catch (char* msg)
2650 CString err(msg);
2651 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2652 return -1;
2655 if (!g_Git.CanParseRev(m_sRange))
2657 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2658 return 0;
2660 // if show all branches, pick any ref as dummy entry ref
2661 STRING_VECTOR list;
2662 if (g_Git.GetRefList(list))
2663 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2664 if (list.size() == 0)
2665 return 0;
2667 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2670 g_Git.m_critGitDllSec.Lock();
2671 try {
2672 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2674 g_Git.m_critGitDllSec.Unlock();
2675 return -1;
2678 catch (char* msg)
2680 g_Git.m_critGitDllSec.Unlock();
2681 CString err(msg);
2682 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2683 return -1;
2685 g_Git.m_critGitDllSec.Unlock();
2687 return 0;
2690 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2692 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2694 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2696 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2698 DiffSelectedRevWithPrevious();
2699 return TRUE;
2702 #if 0
2703 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2705 DiffSelectedFile();
2706 return TRUE;
2708 #endif
2710 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2712 // select all entries
2713 for (int i=0; i<GetItemCount(); ++i)
2715 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2717 return TRUE;
2720 #if 0
2721 if (m_hAccel && !bSkipAccelerator)
2723 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2724 if (ret)
2725 return TRUE;
2728 #endif
2729 //m_tooltips.RelayEvent(pMsg);
2730 return __super::PreTranslateMessage(pMsg);
2733 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2735 // a double click on an entry in the revision list has happened
2736 *pResult = 0;
2738 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2739 DiffSelectedRevWithPrevious();
2742 int CGitLogListBase::FetchLogAsync(void * data)
2744 ReloadHashMap();
2745 m_ProcData=data;
2746 m_bExitThread=FALSE;
2747 InterlockedExchange(&m_bThreadRunning, TRUE);
2748 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2749 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2750 if (m_LoadingThread ==NULL)
2752 InterlockedExchange(&m_bThreadRunning, FALSE);
2753 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2754 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2755 return -1;
2757 return 0;
2760 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2762 return ((CGitLogListBase*)pVoid)->LogThread();
2765 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2767 //CTime time;
2768 oldest=CTime::GetCurrentTime();
2769 latest=CTime(1971,1,2,0,0,0);
2770 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2772 if(m_logEntries[i].IsEmpty())
2773 continue;
2775 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2776 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2778 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2779 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2783 if(latest<oldest)
2784 latest=oldest;
2787 UINT CGitLogListBase::LogThread()
2789 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2791 InterlockedExchange(&m_bThreadRunning, TRUE);
2792 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2794 ULONGLONG t1,t2;
2796 if(BeginFetchLog())
2798 InterlockedExchange(&m_bThreadRunning, FALSE);
2799 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2801 return 1;
2804 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2805 bool bRegex = false;
2806 if (m_bFilterWithRegex)
2807 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2809 TRACE(_T("\n===Begin===\n"));
2810 //Update work copy item;
2812 if (!m_logEntries.empty())
2814 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2816 m_arShownList.SafeAdd(pRev);
2820 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2822 // store commit number of the last selected commit/line before the refresh or -1
2823 int lastSelectedHashNItem = -1;
2824 int ret = 0;
2826 bool shouldWalk = true;
2827 if (!g_Git.CanParseRev(m_sRange))
2829 // walk revisions if show all branches and there exists any ref
2830 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2831 shouldWalk = false;
2832 else
2834 STRING_VECTOR list;
2835 if (g_Git.GetRefList(list))
2836 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2837 if (list.size() == 0)
2838 shouldWalk = false;
2842 if (shouldWalk)
2844 g_Git.m_critGitDllSec.Lock();
2845 int total = 0;
2848 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2849 total = git_get_log_estimate_commit_count(m_DllGitLog);
2851 catch (char* msg)
2853 CString err(msg);
2854 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2855 ret = -1;
2857 g_Git.m_critGitDllSec.Unlock();
2859 GIT_COMMIT commit;
2860 t2=t1=GetTickCount();
2861 int oldprecentage = 0;
2862 size_t oldsize = m_logEntries.size();
2863 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2864 while (ret== 0 && !m_bExitThread)
2866 g_Git.m_critGitDllSec.Lock();
2869 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2871 catch (char* msg)
2873 g_Git.m_critGitDllSec.Unlock();
2874 CString err(msg);
2875 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2876 break;
2878 g_Git.m_critGitDllSec.Unlock();
2880 if(ret)
2882 if (ret != -2) // other than end of revision walking
2883 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2884 break;
2887 if (commit.m_ignore == 1)
2889 git_free_commit(&commit);
2890 continue;
2893 //printf("%s\r\n",commit.GetSubject());
2894 if(m_bExitThread)
2895 break;
2897 CGitHash hash = (char*)commit.m_hash ;
2899 GitRev *pRev = m_LogCache.GetCacheData(hash);
2900 pRev->m_GitCommit = commit;
2901 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2903 char *note=NULL;
2904 g_Git.m_critGitDllSec.Lock();
2907 git_get_notes(commit.m_hash, &note);
2909 catch (char* msg)
2911 g_Git.m_critGitDllSec.Unlock();
2912 CString err(msg);
2913 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2914 break;
2916 g_Git.m_critGitDllSec.Unlock();
2918 if(note)
2920 pRev->m_Notes.Empty();
2921 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2922 free(note);
2923 note = nullptr;
2926 if(!pRev->m_IsDiffFiles)
2928 pRev->m_CallDiffAsync = DiffAsync;
2931 pRev->ParserParentFromCommit(&commit);
2932 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2934 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2936 const CGitHash &parentHash = pRev->m_ParentHash[i];
2937 auto it = commitChildren.find(parentHash);
2938 if (it == commitChildren.end())
2940 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2942 it->second.insert(pRev->m_CommitHash);
2946 #ifdef DEBUG
2947 pRev->DbgPrint();
2948 TRACE(_T("\n"));
2949 #endif
2951 bool visible = true;
2952 if (HasFilterText())
2954 if(!IsMatchFilter(bRegex,pRev,pat))
2955 visible = false;
2957 if (visible && !ShouldShowFilter(pRev, commitChildren))
2958 visible = false;
2959 this->m_critSec.Lock();
2960 m_logEntries.append(hash, visible);
2961 if (visible)
2962 m_arShownList.SafeAdd(pRev);
2963 this->m_critSec.Unlock();
2965 if (!visible)
2966 continue;
2968 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2969 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2971 t2=GetTickCount();
2973 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2975 //update UI
2976 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2977 if(percent > 99)
2978 percent =99;
2979 if(percent < GITLOG_START)
2980 percent = GITLOG_START +1;
2982 oldsize = m_logEntries.size();
2983 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2985 //if( percent > oldprecentage )
2987 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2988 oldprecentage = percent;
2991 if (lastSelectedHashNItem >= 0)
2992 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2994 t1 = t2;
2997 g_Git.m_critGitDllSec.Lock();
2998 git_close_log(m_DllGitLog);
2999 g_Git.m_critGitDllSec.Unlock();
3003 if (m_bExitThread)
3005 InterlockedExchange(&m_bThreadRunning, FALSE);
3006 return 0;
3009 //Update UI;
3010 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3012 if (lastSelectedHashNItem >= 0)
3013 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3015 if (this->m_hWnd)
3016 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3018 InterlockedExchange(&m_bThreadRunning, FALSE);
3020 return 0;
3023 void CGitLogListBase::FetchRemoteList()
3025 STRING_VECTOR remoteList;
3026 if (!g_Git.GetRemoteList(remoteList))
3027 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3028 else
3029 m_SingleRemote = _T("");
3032 void CGitLogListBase::FetchTrackingBranchList()
3034 m_TrackingMap.clear();
3035 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3037 for (size_t j = 0; j < it->second.size(); ++j)
3039 CString branchName;
3040 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3042 CString pullRemote, pullBranch;
3043 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3044 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3046 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3053 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3055 SafeTerminateThread();
3057 this->SetItemCountEx(0);
3058 this->Clear();
3060 ResetWcRev();
3062 // HACK to hide graph column
3063 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3064 SetColumnWidth(0, 0);
3065 else
3066 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3068 //Update branch and Tag info
3069 ReloadHashMap();
3070 //Assume Thread have exited
3071 //if(!m_bThreadRunning)
3073 m_logEntries.clear();
3075 if(IsCleanFilter)
3077 m_sFilterText.Empty();
3078 m_From=-1;
3079 m_To=-1;
3082 InterlockedExchange(&m_bExitThread,FALSE);
3084 InterlockedExchange(&m_bThreadRunning, TRUE);
3085 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3086 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3088 InterlockedExchange(&m_bThreadRunning, FALSE);
3089 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3090 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3094 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3098 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3099 if (!bMatchCase)
3100 type |= std::tr1::regex_constants::icase;
3101 pat = std::tr1::wregex(regexp_str, type);
3102 return true;
3104 catch (std::exception) {}
3105 return false;
3107 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
3109 BOOL result = TRUE;
3110 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3111 CString sRev;
3113 if ((bRegex)&&(m_bFilterWithRegex))
3115 if (m_SelectedFilters & LOGFILTER_BUGID)
3117 if(this->m_bShowBugtraqColumn)
3119 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3121 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3122 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3124 return TRUE;
3129 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3131 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3132 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3134 return TRUE;
3138 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3140 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3141 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3143 return TRUE;
3147 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3149 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3151 return TRUE;
3154 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3156 return TRUE;
3160 if (m_SelectedFilters & LOGFILTER_EMAILS)
3162 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3164 return TRUE;
3167 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3169 return TRUE;
3173 if (m_SelectedFilters & LOGFILTER_REVS)
3175 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3176 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3178 return TRUE;
3182 if (m_SelectedFilters & LOGFILTER_REFNAME)
3184 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3185 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3187 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3189 return TRUE;
3194 if (m_SelectedFilters & LOGFILTER_PATHS)
3196 CTGitPathList *pathList=NULL;
3197 if( pRev->m_IsDiffFiles)
3198 pathList = &pRev->GetFiles(this);
3199 else
3201 if(!pRev->m_IsSimpleListReady)
3202 pRev->SafeGetSimpleList(&g_Git);
3205 if(pathList)
3206 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3208 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3210 return true;
3212 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3214 return true;
3218 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3220 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3222 return true;
3227 else
3229 CString find = m_sFilterText;
3230 find.MakeLower();
3231 result = find[0] == '!' ? FALSE : TRUE;
3232 if (!result)
3233 find = find.Mid(1);
3235 if (m_SelectedFilters & LOGFILTER_BUGID)
3237 if(this->m_bShowBugtraqColumn)
3239 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3241 sBugIds.MakeLower();
3242 if ((sBugIds.Find(find) >= 0))
3244 return result;
3249 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3251 CString msg = pRev->GetSubject();
3253 msg = msg.MakeLower();
3254 if ((msg.Find(find) >= 0))
3256 return result;
3260 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3262 CString msg = pRev->GetBody();
3264 msg = msg.MakeLower();
3265 if ((msg.Find(find) >= 0))
3267 return result;
3271 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3273 CString msg = pRev->GetAuthorName();
3274 msg = msg.MakeLower();
3275 if ((msg.Find(find) >= 0))
3277 return result;
3281 if (m_SelectedFilters & LOGFILTER_EMAILS)
3283 CString msg = pRev->GetAuthorEmail();
3284 msg = msg.MakeLower();
3285 if ((msg.Find(find) >= 0))
3287 return result;
3291 if (m_SelectedFilters & LOGFILTER_REVS)
3293 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3294 if ((sRev.Find(find) >= 0))
3296 return result;
3300 if (m_SelectedFilters & LOGFILTER_REFNAME)
3302 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3303 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3305 if (it->Find(find) >= 0)
3307 return result;
3312 if (m_SelectedFilters & LOGFILTER_PATHS)
3314 CTGitPathList *pathList=NULL;
3315 if( pRev->m_IsDiffFiles)
3316 pathList = &pRev->GetFiles(this);
3317 else
3319 if(!pRev->m_IsSimpleListReady)
3320 pRev->SafeGetSimpleList(&g_Git);
3322 if(pathList)
3323 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3325 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3326 CString path = cpath->GetGitOldPathString();
3327 path.MakeLower();
3328 if ((path.Find(find)>=0))
3330 return result;
3332 path = cpath->GetGitPathString();
3333 path.MakeLower();
3334 if ((path.Find(find)>=0))
3336 return result;
3340 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3342 CString path = pRev->m_SimpleFileList[i];
3343 path.MakeLower();
3344 if ((path.Find(find)>=0))
3346 return result;
3350 } // else (from if (bRegex))
3351 return !result;
3354 static bool CStringStartsWith(const CString &str, const CString &prefix)
3356 return str.Left(prefix.GetLength()) == prefix;
3358 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3360 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3361 return true;
3363 if (m_ShowFilter & FILTERSHOW_REFS)
3365 // Keep all refs.
3366 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3367 for (size_t i = 0; i < refList.size(); ++i)
3369 const CString &str = refList[i];
3370 if (CStringStartsWith(str, _T("refs/heads/")))
3372 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3373 return true;
3375 else if (CStringStartsWith(str, _T("refs/remotes/")))
3377 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3378 return true;
3380 else if (CStringStartsWith(str, _T("refs/tags/")))
3382 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3383 return true;
3385 else if (CStringStartsWith(str, _T("refs/stash")))
3387 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3388 return true;
3390 else if (CStringStartsWith(str, _T("refs/bisect/")))
3392 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3393 return true;
3396 // Keep the head too.
3397 if (pRev->m_CommitHash == m_HeadHash)
3398 return true;
3401 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3403 if (pRev->ParentsCount() > 1)
3404 return true;
3405 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3406 if (childrenIt != commitChildren.end())
3408 const std::set<CGitHash> &children = childrenIt->second;
3409 if (children.size() > 1)
3410 return true;
3413 return false;
3416 void CGitLogListBase::ShowGraphColumn(bool bShow)
3418 // HACK to hide graph column
3419 if (bShow)
3420 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3421 else
3422 SetColumnWidth(0, 0);
3425 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3427 CString cmd;
3428 CString output;
3430 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3432 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3433 for (size_t i = 0; i < vector.size(); ++i)
3435 if (vector[i].Find(_T("refs/tags/")) == 0)
3437 CString tag = vector[i];
3438 int start = vector[i].Find(_T("^{}"));
3439 if (start > 0)
3440 tag = tag.Left(start);
3441 else
3442 continue;
3444 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3445 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3446 output.AppendChar(_T('\n'));
3451 return output;
3454 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3457 pShownlist->SafeRemoveAll();
3459 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3460 bool bRegex = false;
3461 if (m_bFilterWithRegex)
3462 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3464 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3465 CString sRev;
3466 for (DWORD i=0; i<m_logEntries.size(); ++i)
3468 if ((bRegex)&&(m_bFilterWithRegex))
3470 #if 0
3471 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3473 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3474 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3476 pShownlist->SafeAdd(m_logEntries[i]);
3477 continue;
3480 #endif
3481 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3483 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3484 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3486 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3487 continue;
3490 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3492 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3493 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3495 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3496 continue;
3499 if (m_SelectedFilters & LOGFILTER_PATHS)
3501 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3503 bool bGoing = true;
3504 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3506 CTGitPath cpath = pathList[cpPathIndex];
3507 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3509 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3510 bGoing = false;
3511 continue;
3513 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3515 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3516 bGoing = false;
3517 continue;
3519 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3521 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3522 bGoing = false;
3523 continue;
3527 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3529 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3531 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3532 continue;
3535 if (m_SelectedFilters & LOGFILTER_EMAILS)
3537 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3539 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3540 continue;
3543 if (m_SelectedFilters & LOGFILTER_REVS)
3545 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3546 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3548 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3549 continue;
3552 if (m_SelectedFilters & LOGFILTER_REFNAME)
3554 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3555 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3557 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3559 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3560 continue;
3564 } // if (bRegex)
3565 else
3567 CString find = m_sFilterText;
3568 find.MakeLower();
3569 #if 0
3570 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3572 CString sBugIDs = m_logEntries[i]->sBugIDs;
3574 sBugIDs = sBugIDs.MakeLower();
3575 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3577 pShownlist->SafeAdd(m_logEntries[i]);
3578 continue;
3581 #endif
3582 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3584 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3586 msg = msg.MakeLower();
3587 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3589 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3590 continue;
3593 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3595 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3597 msg = msg.MakeLower();
3598 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3600 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3601 continue;
3604 if (m_SelectedFilters & LOGFILTER_PATHS)
3606 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3608 bool bGoing = true;
3609 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3611 CTGitPath cpath = pathList[cpPathIndex];
3612 CString path = cpath.GetGitOldPathString();
3613 path.MakeLower();
3614 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3616 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3617 bGoing = false;
3618 continue;
3620 path = cpath.GetGitPathString();
3621 path.MakeLower();
3622 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3624 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3625 bGoing = false;
3626 continue;
3628 path = cpath.GetActionName();
3629 path.MakeLower();
3630 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3632 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3633 bGoing = false;
3634 continue;
3638 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3640 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3641 msg = msg.MakeLower();
3642 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3644 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3645 continue;
3648 if (m_SelectedFilters & LOGFILTER_EMAILS)
3650 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3651 msg = msg.MakeLower();
3652 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3654 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3655 continue;
3658 if (m_SelectedFilters & LOGFILTER_REVS)
3660 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3661 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3663 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3664 continue;
3667 if (m_SelectedFilters & LOGFILTER_REFNAME)
3669 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3670 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3672 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3674 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3675 continue;
3679 } // else (from if (bRegex))
3680 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3684 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3687 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3689 if(m_From == -1)
3690 if(m_To == -1)
3691 return true;
3692 else
3693 return time <= m_To;
3694 else
3695 if(m_To == -1)
3696 return time >= m_From;
3697 else
3698 return ((time >= m_From)&&(time <= m_To));
3700 return TRUE; /* git dll will filter time range */
3702 // return TRUE;
3704 void CGitLogListBase::StartFilter()
3706 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3707 RecalculateShownList(&m_arShownList);
3708 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3711 DeleteAllItems();
3712 SetItemCountEx(ShownCountWithStopped());
3713 RedrawItems(0, ShownCountWithStopped());
3714 Invalidate();
3717 void CGitLogListBase::RemoveFilter()
3720 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3722 m_arShownList.SafeRemoveAll();
3724 // reset the time filter too
3725 #if 0
3726 m_timFrom = (__time64_t(m_tFrom));
3727 m_timTo = (__time64_t(m_tTo));
3728 m_DateFrom.SetTime(&m_timFrom);
3729 m_DateTo.SetTime(&m_timTo);
3730 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3731 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3732 #endif
3734 for (DWORD i=0; i<m_logEntries.size(); ++i)
3736 if(this->m_IsOldFirst)
3738 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3740 else
3742 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3745 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3746 DeleteAllItems();
3747 SetItemCountEx(ShownCountWithStopped());
3748 RedrawItems(0, ShownCountWithStopped());
3750 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3753 void CGitLogListBase::Clear()
3755 m_arShownList.SafeRemoveAll();
3756 DeleteAllItems();
3758 m_logEntries.ClearAll();
3762 void CGitLogListBase::OnDestroy()
3764 // save the column widths to the registry
3765 SaveColumnWidths();
3767 SafeTerminateThread();
3768 SafeTerminateAsyncDiffThread();
3770 int retry = 0;
3771 while(m_LogCache.SaveCache())
3773 if(retry > 5)
3774 break;
3775 Sleep(1000);
3777 ++retry;
3779 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3780 // MB_YESNO) == IDNO)
3781 // break;
3784 CHintListCtrl::OnDestroy();
3787 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3789 CRect rect;
3790 int i=(int)wParam;
3791 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3792 this->InvalidateRect(rect);
3794 return 0;
3798 * Save column widths to the registry
3800 void CGitLogListBase::SaveColumnWidths()
3802 int maxcol = m_ColumnManager.GetColumnCount();
3804 // HACK that graph column is always shown
3805 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3807 for (int col = 0; col < maxcol; ++col)
3808 if (m_ColumnManager.IsVisible (col))
3809 m_ColumnManager.ColumnResized (col);
3811 m_ColumnManager.WriteSettings();
3814 int CGitLogListBase::GetHeadIndex()
3816 if(m_HeadHash.IsEmpty())
3817 return -1;
3819 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3821 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3822 if(pRev)
3824 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3825 return i;
3828 return -1;
3830 void CGitLogListBase::OnFind()
3832 if (!m_pFindDialog)
3834 m_pFindDialog = new CFindDlg(this);
3835 m_pFindDialog->Create(this);
3838 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3840 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3842 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3844 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3845 Default();
3847 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3849 if (GetSelectedCount() != 0)
3850 return 0;
3852 CGitHash theSelectedHash = m_lastSelectedHash;
3853 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3854 m_lastSelectedHash = theSelectedHash;
3856 int countPerPage = GetCountPerPage();
3857 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3858 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3859 EnsureVisible((int)itemToSelect, FALSE);
3860 return 0;
3862 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3865 ASSERT(m_pFindDialog != NULL);
3866 bool bFound = false;
3867 int i=0;
3869 if (m_pFindDialog->IsTerminating())
3871 // invalidate the handle identifying the dialog box.
3872 m_pFindDialog = NULL;
3873 return 0;
3876 INT_PTR cnt = m_arShownList.GetCount();
3878 if(m_pFindDialog->IsRef())
3880 CString str;
3881 str=m_pFindDialog->GetFindString();
3883 CGitHash hash;
3885 if(!str.IsEmpty())
3887 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3888 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3891 if(!hash.IsEmpty())
3893 for (i = 0; i < cnt; ++i)
3895 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3896 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3898 bFound = true;
3899 break;
3903 if (!bFound)
3905 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3906 return 0;
3910 if (m_pFindDialog->FindNext() && !bFound)
3912 //read data from dialog
3913 CString FindText = m_pFindDialog->GetFindString();
3914 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3916 std::tr1::wregex pat;
3917 bool bRegex = false;
3918 if (m_pFindDialog->Regex())
3919 bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3921 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3923 for (i = m_nSearchIndex + 1; ; ++i)
3925 if (i >= cnt)
3927 i = 0;
3928 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3930 if (m_nSearchIndex >= 0)
3932 if (i == m_nSearchIndex)
3934 ::MessageBeep(0xFFFFFFFF);
3935 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3936 break;
3940 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3942 CString str;
3943 str+=pLogEntry->m_CommitHash.ToString();
3944 str+=_T("\n");
3946 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3948 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3949 str+=_T("\n");
3952 str+=pLogEntry->GetAuthorEmail();
3953 str+=_T("\n");
3954 str+=pLogEntry->GetAuthorName();
3955 str+=_T("\n");
3956 str+=pLogEntry->GetBody();
3957 str+=_T("\n");
3958 str+=pLogEntry->GetCommitterEmail();
3959 str+=_T("\n");
3960 str+=pLogEntry->GetCommitterName();
3961 str+=_T("\n");
3962 str+=pLogEntry->GetSubject();
3963 str+=_T("\n");
3964 str+=pLogEntry->m_Notes;
3965 str+=_T("\n");
3966 str+=GetTagInfo(pLogEntry);
3967 str+=_T("\n");
3970 /*Because changed files list is loaded on demand when gui show,
3971 files will empty when files have not fetched.
3973 we can add it back by using one-way diff(with outnumber changed and rename detect.
3974 here just need changed filename list. one-way is much quicker.
3976 if(pLogEntry->m_IsFull)
3978 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
3980 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3981 str+=_T("\n");
3982 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3983 str+=_T("\n");
3986 else
3988 if(!pLogEntry->m_IsSimpleListReady)
3989 pLogEntry->SafeGetSimpleList(&g_Git);
3991 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
3993 str+=pLogEntry->m_SimpleFileList[i];
3994 str+=_T("\n");
4000 if (bRegex)
4002 if (std::regex_search(std::wstring(str), pat, flags))
4004 bFound = true;
4005 break;
4008 else
4010 if (bMatchCase)
4012 if (str.Find(FindText) >= 0)
4014 bFound = true;
4015 break;
4019 else
4021 CString msg = str;
4022 msg = msg.MakeLower();
4023 CString find = FindText.MakeLower();
4024 if (msg.Find(find) >= 0)
4026 bFound = TRUE;
4027 break;
4031 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4033 } // if(m_pFindDialog->FindNext())
4034 //UpdateLogInfoLabel();
4036 if (bFound)
4038 m_nSearchIndex = i;
4039 EnsureVisible(i, FALSE);
4040 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4041 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4042 SetSelectionMark(i);
4043 //FillLogMessageCtrl();
4044 UpdateData(FALSE);
4047 return 0;
4050 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4052 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4054 *pResult = FALSE;
4057 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4059 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4061 Invalidate(FALSE);