Disallow combine commit if selected commits above HEAD
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob84315718378305d9c521167ae20958a4fd81ffe8
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,
384 static int with[] =
386 ICONITEMBORDER+16*4,
387 ICONITEMBORDER+16*4,
388 ICONITEMBORDER+16*4,
389 ICONITEMBORDER+16*4,
390 ICONITEMBORDER+16*4,
391 LOGLIST_MESSAGE_MIN,
392 ICONITEMBORDER+16*4,
393 ICONITEMBORDER+16*4,
394 ICONITEMBORDER+16*4,
395 ICONITEMBORDER+16*4,
396 ICONITEMBORDER+16*4,
397 ICONITEMBORDER+16*4,
398 ICONITEMBORDER+16*4,
400 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
402 DWORD hideColumns = 0;
403 if(this->m_IsRebaseReplaceGraph)
405 hideColumns |= GIT_LOG_GRAPH;
406 m_dwDefaultColumns |= GIT_LOG_REBASE;
408 else
410 hideColumns |= GIT_LOG_REBASE;
413 if(this->m_IsIDReplaceAction)
415 hideColumns |= GIT_LOG_ACTIONS;
416 m_dwDefaultColumns |= GIT_LOG_ID;
417 m_dwDefaultColumns |= GIT_LOG_HASH;
419 else
421 hideColumns |= GIT_LOG_ID;
423 if(this->m_bShowBugtraqColumn)
425 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
427 else
429 hideColumns |= GIT_LOGLIST_BUG;
431 SetRedraw(false);
433 m_ColumnManager.SetNames(normal, _countof(normal));
434 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
436 SetRedraw(true);
440 * Resizes all columns in a list control to values in registry.
442 void CGitLogListBase::ResizeAllListCtrlCols()
444 // column max and min widths to allow
445 static const int nMinimumWidth = 10;
446 static const int nMaximumWidth = 1000;
447 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
448 if (pHdrCtrl)
450 int numcols = pHdrCtrl->GetItemCount();
451 for (int col = 0; col < numcols; ++col)
453 // get width for this col last time from registry
454 CString regentry;
455 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
456 CRegDWORD regwidth(regentry, 0);
457 int cx = regwidth;
458 if ( cx == 0 )
460 // no saved value, setup sensible defaults
461 if (col == this->LOGLIST_MESSAGE)
463 cx = LOGLIST_MESSAGE_MIN;
465 else
467 cx = ICONITEMBORDER+16*4;
470 if (cx < nMinimumWidth)
472 cx = nMinimumWidth;
474 else if (cx > nMaximumWidth)
476 cx = nMaximumWidth;
479 SetColumnWidth(col, cx);
486 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
488 LVITEM rItem;
489 SecureZeroMemory(&rItem, sizeof(LVITEM));
490 rItem.mask = LVIF_STATE;
491 rItem.iItem = (int)Index;
492 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
493 GetItem(&rItem);
495 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
496 HBRUSH brush = NULL;
498 if (!(rItem.state & LVIS_SELECTED))
500 int action = pLogEntry->GetRebaseAction();
501 if (action & LOGACTIONS_REBASE_SQUASH)
502 brush = ::CreateSolidBrush(RGB(156,156,156));
503 else if (action & LOGACTIONS_REBASE_EDIT)
504 brush = ::CreateSolidBrush(RGB(200,200,128));
506 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
508 if (rItem.state & LVIS_SELECTED)
510 if (::GetFocus() == m_hWnd)
511 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
512 else
513 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
516 if (brush != NULL)
518 ::FillRect(hdc, &rect, brush);
519 ::DeleteObject(brush);
523 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
525 POINT point = { 4, 4 };
526 CRect rt2 = rect;
527 rt2.DeflateRect(1, 1);
528 rt2.OffsetRect(2, 2);
530 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
531 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
532 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
533 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
534 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
536 ::SelectObject(hdc, brush);
537 rt2.OffsetRect(-2, -2);
538 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
539 ::SelectObject(hdc, oldbrush);
540 ::SelectObject(hdc, oldpen);
541 ::DeleteObject(nullPen);
542 ::DeleteObject(darkBrush);
545 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
547 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
548 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
549 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
550 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
551 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
552 ::LineTo(hdc, rect.left, rect.bottom);
553 ::SelectObject(hdc, oldpen);
554 ::DeleteObject(pen);
557 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
559 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
560 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
561 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
562 ::LineTo(hdc, rect.left, rect.bottom);
563 ::LineTo(hdc, rect.right, rect.bottom);
564 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
565 ::SelectObject(hdc, oldpen);
566 ::DeleteObject(pen);
569 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
571 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
572 CRect rt=rect;
573 LVITEM rItem;
574 SecureZeroMemory(&rItem, sizeof(LVITEM));
575 rItem.mask = LVIF_STATE;
576 rItem.iItem = (int)index;
577 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
578 GetItem(&rItem);
580 CDC W_Dc;
581 W_Dc.Attach(hdc);
583 HTHEME hTheme = NULL;
584 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
585 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
587 SIZE oneSpaceSize;
588 if (m_bTagsBranchesOnRightSide)
590 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
591 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
592 SelectObject(hdc, oldFont);
593 rt.left += oneSpaceSize.cx * 2;
595 else
597 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
598 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
599 rt.left += oneSpaceSize.cx;
602 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
604 int txtState = LISS_NORMAL;
605 if (rItem.state & LVIS_SELECTED)
606 txtState = LISS_SELECTED;
608 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
610 else
612 if (rItem.state & LVIS_SELECTED)
614 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
615 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
616 ::SetTextColor(hdc, clrOld);
618 else
620 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
624 if (m_bTagsBranchesOnRightSide)
626 SIZE size;
627 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
629 rt.left += oneSpaceSize.cx + size.cx;
631 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
634 if (hTheme)
635 CloseThemeData(hTheme);
637 W_Dc.Detach();
640 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
642 for (unsigned int i = 0; i < refList.size(); ++i)
644 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
645 HBRUSH brush = 0;
646 COLORREF colRef = refList[i].color;
647 bool singleRemote = refList[i].singleRemote;
648 bool hasTracking = refList[i].hasTracking;
649 bool sameName = refList[i].sameName;
650 bool annotatedTag = refList[i].annotatedTag;
652 //When row selected, ajust label color
653 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
655 if (rItem.state & LVIS_SELECTED)
656 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
659 brush = ::CreateSolidBrush(colRef);
661 if (!shortname.IsEmpty() && (rt.left < rect.right))
663 SIZE size;
664 memset(&size,0,sizeof(SIZE));
665 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
667 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
668 rt.right += 8;
670 int textpos = DT_CENTER;
672 if (rt.right > rect.right)
674 rt.right = rect.right;
675 textpos = 0;
678 CRect textRect = rt;
680 if (singleRemote)
682 rt.right += 8;
683 textRect.OffsetRect(8, 0);
686 if (sameName)
687 rt.right += 8;
689 if (hasTracking)
691 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
693 else
695 //Fill interior of ref label
696 ::FillRect(hdc, &rt, brush);
699 //Draw edge of label
700 CRect rectEdge = rt;
702 if (!hasTracking)
704 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
705 rectEdge.DeflateRect(1, 1);
706 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
709 if (annotatedTag)
711 rt.right += 8;
712 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
713 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
714 ::FillRgn(hdc, hrgn, brush);
715 ::DeleteObject(hrgn);
716 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
717 HPEN pen;
718 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
719 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
720 ::DeleteObject(pen);
721 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
722 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
723 ::DeleteObject(pen);
724 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
725 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
726 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
727 ::DeleteObject(pen);
728 SelectObject(hdc, oldpen);
731 //Draw text inside label
732 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
733 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
735 int txtState = LISS_NORMAL;
736 if (rItem.state & LVIS_SELECTED)
737 txtState = LISS_SELECTED;
739 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
741 else
743 W_Dc.SetBkMode(TRANSPARENT);
744 if (customColor || (rItem.state & LVIS_SELECTED))
746 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
747 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
748 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
749 ::SetTextColor(hdc,clrOld);
751 else
753 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
757 if (singleRemote)
759 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
760 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
761 CRect newRect;
762 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
763 DrawLightning(hdc, newRect, color, bold);
766 if (sameName)
768 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
769 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
770 CRect newRect;
771 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
772 DrawUpTriangle(hdc, newRect, color, bold);
775 rt.left = rt.right + 1;
777 if (brush)
778 ::DeleteObject(brush);
780 rt.right = rect.right;
783 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
785 // Returns ((256 - amount)*col1 + amount*col2) / 256;
786 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
787 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
788 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
791 Gdiplus::Color GetGdiColor(COLORREF col)
793 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
795 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
796 const COLORREF& col,const COLORREF& activeColor, int top
799 int h = laneHeight / 2;
800 int m = (x1 + x2) / 2;
801 int r = (x2 - x1) * m_NodeSize / 30;
802 int d = 2 * r;
804 #define P_CENTER m , h+top
805 #define P_0 x2, h+top
806 #define P_90 m , 0+top-1
807 #define P_180 x1, h+top
808 #define P_270 m , 2 * h+top +1
809 #define R_CENTER m - r, h - r+top, d, d
812 #define DELTA_UR_B 2*(x1 - m), 2*h +top
813 #define DELTA_UR_E 0*16, 90*16 +top // -,
815 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
816 #define DELTA_DR_E 270*16, 90*16 +top // -'
818 #define DELTA_UL_B 2*(x2 - m), 2*h +top
819 #define DELTA_UL_E 90*16, 90*16 +top // ,-
821 #define DELTA_DL_B 2*(x2 - m),2*-h +top
822 #define DELTA_DL_E 180*16, 90*16 // '-
824 #define CENTER_UR x1, 2*h, 225
825 #define CENTER_DR x1, 0 , 135
826 #define CENTER_UL x2, 2*h, 315
827 #define CENTER_DL x2, 0 , 45
830 Gdiplus::Graphics graphics( hdc );
832 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
834 // arc
835 switch (type) {
836 case Lanes::JOIN:
837 case Lanes::JOIN_R:
838 case Lanes::HEAD:
839 case Lanes::HEAD_R:
841 Gdiplus::LinearGradientBrush gradient(
842 Gdiplus::Point(x1-2, h+top-2),
843 Gdiplus::Point(P_270),
844 GetGdiColor(activeColor),GetGdiColor(col));
847 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
848 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
850 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
851 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
852 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
854 break;
856 case Lanes::JOIN_L:
859 Gdiplus::LinearGradientBrush gradient(
860 Gdiplus::Point(P_270),
861 Gdiplus::Point(x2+1, h+top-1),
862 GetGdiColor(col),GetGdiColor(activeColor));
865 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
866 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
868 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
869 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
870 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
873 break;
875 case Lanes::TAIL:
876 case Lanes::TAIL_R:
879 Gdiplus::LinearGradientBrush gradient(
880 Gdiplus::Point(x1-2, h+top-2),
881 Gdiplus::Point(P_90),
882 GetGdiColor(activeColor),GetGdiColor(col));
884 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
886 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
888 #if 0
889 QConicalGradient gradient(CENTER_DR);
890 gradient.setColorAt(0.375, activeCol);
891 gradient.setColorAt(0.625, col);
892 myPen.setBrush(gradient);
893 p->setPen(myPen);
894 p->drawArc(P_CENTER, DELTA_DR);
895 #endif
896 break;
898 default:
899 break;
903 //static QPen myPen(Qt::black, 2); // fast path here
904 CPen pen;
905 pen.CreatePen(PS_SOLID,2,col);
906 //myPen.setColor(col);
907 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
909 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
911 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
913 //p->setPen(myPen);
915 // vertical line
916 switch (type) {
917 case Lanes::ACTIVE:
918 case Lanes::NOT_ACTIVE:
919 case Lanes::MERGE_FORK:
920 case Lanes::MERGE_FORK_R:
921 case Lanes::MERGE_FORK_L:
922 case Lanes::JOIN:
923 case Lanes::JOIN_R:
924 case Lanes::JOIN_L:
925 case Lanes::CROSS:
926 //DrawLine(hdc,P_90,P_270);
927 graphics.DrawLine(&myPen,P_90,P_270);
928 //p->drawLine(P_90, P_270);
929 break;
930 case Lanes::HEAD_L:
931 case Lanes::BRANCH:
932 //DrawLine(hdc,P_CENTER,P_270);
933 graphics.DrawLine(&myPen,P_CENTER,P_270);
934 //p->drawLine(P_CENTER, P_270);
935 break;
936 case Lanes::TAIL_L:
937 case Lanes::INITIAL:
938 case Lanes::BOUNDARY:
939 case Lanes::BOUNDARY_C:
940 case Lanes::BOUNDARY_R:
941 case Lanes::BOUNDARY_L:
942 //DrawLine(hdc,P_90, P_CENTER);
943 graphics.DrawLine(&myPen,P_90,P_CENTER);
944 //p->drawLine(P_90, P_CENTER);
945 break;
946 default:
947 break;
950 myPen.SetColor(GetGdiColor(activeColor));
952 // horizontal line
953 switch (type) {
954 case Lanes::MERGE_FORK:
955 case Lanes::JOIN:
956 case Lanes::HEAD:
957 case Lanes::TAIL:
958 case Lanes::CROSS:
959 case Lanes::CROSS_EMPTY:
960 case Lanes::BOUNDARY_C:
961 //DrawLine(hdc,P_180,P_0);
962 graphics.DrawLine(&myPen,P_180,P_0);
963 //p->drawLine(P_180, P_0);
964 break;
965 case Lanes::MERGE_FORK_R:
966 case Lanes::BOUNDARY_R:
967 //DrawLine(hdc,P_180,P_CENTER);
968 graphics.DrawLine(&myPen,P_180,P_CENTER);
969 //p->drawLine(P_180, P_CENTER);
970 break;
971 case Lanes::MERGE_FORK_L:
972 case Lanes::HEAD_L:
973 case Lanes::TAIL_L:
974 case Lanes::BOUNDARY_L:
975 //DrawLine(hdc,P_CENTER,P_0);
976 graphics.DrawLine(&myPen,P_CENTER,P_0);
977 //p->drawLine(P_CENTER, P_0);
978 break;
979 default:
980 break;
983 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
985 CBrush brush;
986 brush.CreateSolidBrush(col);
987 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
989 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
990 // center symbol, e.g. rect or ellipse
991 switch (type) {
992 case Lanes::ACTIVE:
993 case Lanes::INITIAL:
994 case Lanes::BRANCH:
996 //p->setPen(Qt::NoPen);
997 //p->setBrush(col);
998 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
999 graphics.FillEllipse(&myBrush, R_CENTER);
1000 //p->drawEllipse(R_CENTER);
1001 break;
1002 case Lanes::MERGE_FORK:
1003 case Lanes::MERGE_FORK_R:
1004 case Lanes::MERGE_FORK_L:
1005 //p->setPen(Qt::NoPen);
1006 //p->setBrush(col);
1007 //p->drawRect(R_CENTER);
1008 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1009 graphics.FillRectangle(&myBrush, R_CENTER);
1010 break;
1011 case Lanes::UNAPPLIED:
1012 // Red minus sign
1013 //p->setPen(Qt::NoPen);
1014 //p->setBrush(Qt::red);
1015 //p->drawRect(m - r, h - 1, d, 2);
1016 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1017 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1018 break;
1019 case Lanes::APPLIED:
1020 // Green plus sign
1021 //p->setPen(Qt::NoPen);
1022 //p->setBrush(DARK_GREEN);
1023 //p->drawRect(m - r, h - 1, d, 2);
1024 //p->drawRect(m - 1, h - r, 2, d);
1025 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1026 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1027 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1028 break;
1029 case Lanes::BOUNDARY:
1030 //p->setBrush(back);
1031 //p->drawEllipse(R_CENTER);
1032 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1033 graphics.DrawEllipse(&myPen, R_CENTER);
1034 break;
1035 case Lanes::BOUNDARY_C:
1036 case Lanes::BOUNDARY_R:
1037 case Lanes::BOUNDARY_L:
1038 //p->setBrush(back);
1039 //p->drawRect(R_CENTER);
1040 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1041 graphics.FillRectangle(&myBrush,R_CENTER);
1042 break;
1043 default:
1044 break;
1047 ::SelectObject(hdc,oldpen);
1048 ::SelectObject(hdc,oldbrush);
1049 #undef P_CENTER
1050 #undef P_0
1051 #undef P_90
1052 #undef P_180
1053 #undef P_270
1054 #undef R_CENTER
1057 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1059 // TODO: unfinished
1060 // return;
1061 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1062 if(data->m_CommitHash.IsEmpty())
1063 return;
1065 CRect rt=rect;
1066 LVITEM rItem;
1067 SecureZeroMemory(&rItem, sizeof(LVITEM));
1068 rItem.mask = LVIF_STATE;
1069 rItem.iItem = (int)index;
1070 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1071 GetItem(&rItem);
1073 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1075 if (data->m_Lanes.empty())
1076 m_logEntries.setLane(data->m_CommitHash);
1078 std::vector<int>& lanes=data->m_Lanes;
1079 size_t laneNum = lanes.size();
1080 UINT activeLane = 0;
1081 for (UINT i = 0; i < laneNum; ++i)
1082 if (Lanes::isMerge(lanes[i])) {
1083 activeLane = i;
1084 break;
1087 int x2 = 0;
1088 int maxWidth = rect.Width();
1089 int lw = 3 * rect.Height() / 4; //laneWidth()
1091 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1092 //if (opt.state & QStyle::State_Selected)
1093 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1095 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1098 int x1 = x2;
1099 x2 += lw;
1101 int ln = lanes[i];
1102 if (ln == Lanes::EMPTY)
1103 continue;
1105 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1106 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1109 #if 0
1110 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1112 int x1 = x2;
1113 x2 += lw;
1115 int ln = lanes[i];
1116 if (ln == Lanes::EMPTY)
1117 continue;
1119 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1120 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1122 if (ln == Lanes::CROSS)
1124 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1125 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1127 else
1128 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1130 #endif
1134 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1137 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1138 // Take the default processing unless we set this to something else below.
1139 *pResult = CDRF_DODEFAULT;
1141 if (m_bNoDispUpdates)
1142 return;
1144 switch (pLVCD->nmcd.dwDrawStage)
1146 case CDDS_PREPAINT:
1148 *pResult = CDRF_NOTIFYITEMDRAW;
1149 return;
1151 break;
1152 case CDDS_ITEMPREPAINT:
1154 // This is the prepaint stage for an item. Here's where we set the
1155 // item's text color.
1157 // Tell Windows to send draw notifications for each subitem.
1158 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1160 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1162 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1164 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1165 if (data)
1167 int action = data->GetRebaseAction();
1168 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1169 crText = RGB(128,128,128);
1171 if (action & LOGACTIONS_REBASE_SQUASH)
1172 pLVCD->clrTextBk = RGB(156,156,156);
1173 else if (action & LOGACTIONS_REBASE_EDIT)
1174 pLVCD->clrTextBk = RGB(200,200,128);
1175 else
1176 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1178 if (action & LOGACTIONS_REBASE_CURRENT)
1180 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1181 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1184 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1186 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1187 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1190 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1191 // crText = GetSysColor(COLOR_GRAYTEXT);
1193 if (data->m_CommitHash.IsEmpty())
1195 //crText = GetSysColor(RGB(200,200,0));
1196 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1197 // We changed the font, so we're returning CDRF_NEWFONT. This
1198 // tells the control to recalculate the extent of the text.
1199 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1203 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1205 if (m_bStrictStopped)
1206 crText = GetSysColor(COLOR_GRAYTEXT);
1208 // Store the color back in the NMLVCUSTOMDRAW struct.
1209 pLVCD->clrText = crText;
1210 return;
1212 break;
1213 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1215 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1217 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1220 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1222 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1224 CRect rect;
1225 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1227 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1228 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1230 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1231 if( !data ->m_CommitHash.IsEmpty())
1232 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1234 *pResult = CDRF_SKIPDEFAULT;
1235 return;
1239 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1241 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1243 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1245 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1247 CRect rect;
1248 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1250 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1251 // not in FillBackGround method, because this only affected the message subitem
1252 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1253 return;
1255 int index = (int)pLVCD->nmcd.dwItemSpec;
1256 int state = GetItemState(index, LVIS_SELECTED);
1257 int txtState = LISS_NORMAL;
1258 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1260 if (state & LVIS_SELECTED)
1261 txtState = LISS_HOTSELECTED;
1262 else
1263 txtState = LISS_HOT;
1265 else if (state & LVIS_SELECTED)
1267 if (::GetFocus() == m_hWnd)
1268 txtState = LISS_SELECTED;
1269 else
1270 txtState = LISS_SELECTEDNOTFOCUS;
1273 HTHEME hTheme = nullptr;
1274 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1275 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1277 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1278 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1279 else
1281 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1282 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1283 ::DeleteObject(brush);
1285 if (hTheme)
1287 CRect rt;
1288 // get rect of whole line
1289 GetItemRect(index, rt, LVIR_BOUNDS);
1290 CRect rect2 = rect;
1291 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1292 rect2.DeflateRect(1, 1, 1, 1);
1294 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1295 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1297 CloseThemeData(hTheme);
1299 // END: extended redraw
1301 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1303 std::vector<REFLABEL> refsToShow;
1304 STRING_VECTOR remoteTrackingList;
1305 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1306 for (unsigned int i = 0; i < refList.size(); ++i)
1308 CString str = refList[i];
1310 REFLABEL refLabel;
1311 refLabel.color = RGB(255, 255, 255);
1312 refLabel.singleRemote = false;
1313 refLabel.hasTracking = false;
1314 refLabel.sameName = false;
1315 refLabel.annotatedTag = false;
1316 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1318 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1319 continue;
1320 if (refLabel.name == m_CurrentBranch )
1321 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1322 else
1323 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1325 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1326 CString pullRemote = trackingEntry.first;
1327 CString pullBranch = trackingEntry.second;
1328 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1330 CString defaultUpstream;
1331 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1332 refLabel.hasTracking = true;
1333 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1335 bool found = false;
1336 for (size_t j = i + 1; j < refList.size(); ++j)
1338 if (refList[j] == defaultUpstream)
1340 found = true;
1341 break;
1345 if (found)
1347 bool sameName = pullBranch == refLabel.name;
1348 refsToShow.push_back(refLabel);
1349 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1350 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1351 if (m_bSymbolizeRefNames)
1353 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1355 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1356 refLabel.singleRemote = true;
1358 else if (sameName)
1359 refLabel.simplifiedName = pullRemote + _T("/");
1360 refLabel.sameName = sameName;
1362 refsToShow.push_back(refLabel);
1363 remoteTrackingList.push_back(defaultUpstream);
1364 continue;
1369 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1371 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1372 continue;
1374 bool found = false;
1375 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1377 if (remoteTrackingList[j] == str)
1379 found = true;
1380 break;
1383 if (found)
1384 continue;
1386 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1387 if (m_bSymbolizeRefNames)
1389 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1391 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1392 refLabel.singleRemote = true;
1396 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1398 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1399 continue;
1400 refLabel.color = m_Colors.GetColor(CColors::Tag);
1401 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1403 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1405 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1406 continue;
1407 refLabel.color = m_Colors.GetColor(CColors::Stash);
1408 refLabel.name = _T("stash");
1410 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1412 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1413 continue;
1414 if (refLabel.name.Find(_T("good")) == 0)
1416 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1417 refLabel.name = _T("good");
1419 if (refLabel.name.Find(_T("bad")) == 0)
1421 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1422 refLabel.name = _T("bad");
1425 else
1426 continue;
1428 refsToShow.push_back(refLabel);
1431 if (refsToShow.empty())
1433 *pResult = CDRF_DODEFAULT;
1434 return;
1437 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1439 *pResult = CDRF_SKIPDEFAULT;
1440 return;
1447 if (pLVCD->iSubItem == LOGLIST_ACTION)
1449 if(this->m_IsIDReplaceAction)
1451 *pResult = CDRF_DODEFAULT;
1452 return;
1454 *pResult = CDRF_DODEFAULT;
1456 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1457 return;
1459 int nIcons = 0;
1460 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1461 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1463 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1464 CRect rect;
1465 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1466 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1467 // Get the selected state of the
1468 // item being drawn.
1470 // Fill the background if necessary
1471 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1473 // Draw the icon(s) into the compatible DC
1474 int action = SafeGetAction(pLogEntry);
1476 if (!pLogEntry->m_IsDiffFiles)
1477 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1479 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1480 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1481 ++nIcons;
1483 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1484 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1485 ++nIcons;
1487 if (action & CTGitPath::LOGACTIONS_DELETED)
1488 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1489 ++nIcons;
1491 if (action & CTGitPath::LOGACTIONS_REPLACED)
1492 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1493 ++nIcons;
1494 *pResult = CDRF_SKIPDEFAULT;
1495 return;
1498 break;
1500 *pResult = CDRF_DODEFAULT;
1503 // CGitLogListBase message handlers
1505 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1507 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1509 // Create a pointer to the item
1510 LV_ITEM* pItem = &(pDispInfo)->item;
1512 // Do the list need text information?
1513 if (!(pItem->mask & LVIF_TEXT))
1514 return;
1516 // By default, clear text buffer.
1517 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1519 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1521 *pResult = 0;
1522 if (m_bNoDispUpdates || bOutOfRange)
1523 return;
1525 // Which item number?
1526 int itemid = pItem->iItem;
1527 GitRev * pLogEntry = NULL;
1528 if (itemid < m_arShownList.GetCount())
1529 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1531 CString temp;
1532 if(m_IsOldFirst)
1534 temp.Format(_T("%d"),pItem->iItem+1);
1537 else
1539 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1542 // Which column?
1543 switch (pItem->iSubItem)
1545 case this->LOGLIST_GRAPH: //Graphic
1546 break;
1547 case this->LOGLIST_REBASE:
1549 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1550 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1552 break;
1553 case this->LOGLIST_ACTION: //action -- no text in the column
1554 break;
1555 case this->LOGLIST_HASH:
1556 if(pLogEntry)
1557 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1558 break;
1559 case this->LOGLIST_ID:
1560 if(this->m_IsIDReplaceAction)
1561 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1562 break;
1563 case this->LOGLIST_MESSAGE: //Message
1564 if (pLogEntry)
1565 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1566 break;
1567 case this->LOGLIST_AUTHOR: //Author
1568 if (pLogEntry)
1569 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1570 break;
1571 case this->LOGLIST_DATE: //Date
1572 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1573 lstrcpyn(pItem->pszText,
1574 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1575 pItem->cchTextMax);
1576 break;
1578 case this->LOGLIST_EMAIL:
1579 if (pLogEntry)
1580 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1581 break;
1583 case this->LOGLIST_COMMIT_NAME: //Commit
1584 if (pLogEntry)
1585 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1586 break;
1588 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1589 if (pLogEntry)
1590 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1591 break;
1593 case this->LOGLIST_COMMIT_DATE: //Commit Date
1594 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1595 lstrcpyn(pItem->pszText,
1596 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1597 pItem->cchTextMax);
1598 break;
1599 case this->LOGLIST_BUG: //Bug ID
1600 if(pLogEntry)
1601 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1602 break;
1604 default:
1605 ASSERT(false);
1609 bool CGitLogListBase::IsOnStash(int index)
1611 GitRev *rev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index));
1612 if (IsStash(rev))
1613 return true;
1614 if (index > 0)
1616 GitRev *preRev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1));
1617 if (IsStash(preRev))
1618 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1620 return false;
1623 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1625 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1627 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1628 return true;
1630 return false;
1633 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1635 if (pRev->m_ParentHash.empty())
1639 pRev->GetParentFromHash(pRev->m_CommitHash);
1641 catch (const char* msg)
1643 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1646 parentHash = pRev->m_ParentHash;
1649 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1652 if (pWnd == GetHeaderCtrl())
1654 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1657 int selIndex = GetSelectionMark();
1658 if (selIndex < 0)
1659 return; // nothing selected, nothing to do with a context menu
1661 // if the user selected the info text telling about not all revisions shown due to
1662 // the "stop on copy/rename" option, we also don't show the context menu
1663 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1664 return;
1666 // if the context menu is invoked through the keyboard, we have to use
1667 // a calculated position on where to anchor the menu on
1668 if ((point.x == -1) && (point.y == -1))
1670 CRect rect;
1671 GetItemRect(selIndex, &rect, LVIR_LABEL);
1672 ClientToScreen(&rect);
1673 point = rect.CenterPoint();
1675 m_nSearchIndex = selIndex;
1676 m_bCancelled = FALSE;
1678 // calculate some information the context menu commands can use
1679 // CString pathURL = GetURLFromPath(m_path);
1681 POSITION pos = GetFirstSelectedItemPosition();
1682 int indexNext = GetNextSelectedItem(pos);
1683 if (indexNext < 0)
1684 return;
1686 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1687 #if 0
1688 GitRev revSelected = pSelLogEntry->Rev;
1689 GitRev revPrevious = git_revnum_t(revSelected)-1;
1690 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1692 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1694 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1695 if (changedpath->lCopyFromRev)
1696 revPrevious = changedpath->lCopyFromRev;
1699 GitRev revSelected2;
1700 if (pos)
1702 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1703 revSelected2 = pLogEntry->Rev;
1705 bool bAllFromTheSameAuthor = true;
1706 CString firstAuthor;
1707 CLogDataVector selEntries;
1708 GitRev revLowest, revHighest;
1709 GitRevRangeArray revisionRanges;
1711 POSITION pos = GetFirstSelectedItemPosition();
1712 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1713 revisionRanges.AddRevision(pLogEntry->Rev);
1714 selEntries.push_back(pLogEntry);
1715 firstAuthor = pLogEntry->sAuthor;
1716 revLowest = pLogEntry->Rev;
1717 revHighest = pLogEntry->Rev;
1718 while (pos)
1720 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1721 revisionRanges.AddRevision(pLogEntry->Rev);
1722 selEntries.push_back(pLogEntry);
1723 if (firstAuthor.Compare(pLogEntry->sAuthor))
1724 bAllFromTheSameAuthor = false;
1725 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1726 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1730 #endif
1732 int FirstSelect=-1, LastSelect=-1;
1733 pos = GetFirstSelectedItemPosition();
1734 FirstSelect = GetNextSelectedItem(pos);
1735 while(pos)
1737 LastSelect = GetNextSelectedItem(pos);
1739 //entry is selected, now show the popup menu
1740 CIconMenu popup;
1741 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1743 if (popup.CreatePopupMenu())
1745 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1746 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1747 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1748 bool isStash = IsOnStash(indexNext);
1749 GIT_REV_LIST parentHash;
1750 GetParentHashes(pSelLogEntry, parentHash);
1752 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1753 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1755 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1756 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1758 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1759 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1761 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1762 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1764 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)))
1765 popup.AppendMenu(MF_SEPARATOR, NULL);
1767 if (GetSelectedCount() == 1)
1770 bool requiresSeparator = false;
1771 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1773 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1775 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1776 requiresSeparator = true;
1779 else
1781 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1783 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1784 requiresSeparator = true;
1786 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1788 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1789 requiresSeparator = true;
1793 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1795 if (parentHash.size() == 1)
1797 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1798 requiresSeparator = true;
1800 else if (parentHash.size() > 1)
1802 blamemenu.CreatePopupMenu();
1803 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1804 for (size_t i = 0; i < parentHash.size(); ++i)
1806 CString str;
1807 str.Format(IDS_PARENT, i + 1);
1808 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1810 requiresSeparator = true;
1814 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1816 if (parentHash.size() == 1)
1818 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1819 requiresSeparator = true;
1821 else if (parentHash.size() > 1)
1823 gnudiffmenu.CreatePopupMenu();
1824 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1826 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1827 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1829 for (size_t i = 0; i < parentHash.size(); ++i)
1831 CString str;
1832 str.Format(IDS_PARENT, i + 1);
1833 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1835 requiresSeparator = true;
1839 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1841 if (parentHash.size() == 1)
1843 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1844 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1845 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1846 requiresSeparator = true;
1848 else if (parentHash.size() > 1)
1850 diffmenu.CreatePopupMenu();
1851 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1852 for (size_t i = 0; i < parentHash.size(); ++i)
1854 CString str;
1855 str.Format(IDS_PARENT, i + 1);
1856 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1857 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1859 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1860 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1863 requiresSeparator = true;
1867 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1869 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1870 requiresSeparator = true;
1873 if (requiresSeparator)
1874 popup.AppendMenu(MF_SEPARATOR, NULL);
1876 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1878 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1879 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1882 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1884 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1885 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1887 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1888 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1890 popup.AppendMenu(MF_SEPARATOR, NULL);
1893 if (pSelLogEntry->m_CommitHash.IsEmpty())
1895 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1896 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1898 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1899 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1901 popup.AppendMenu(MF_SEPARATOR, NULL);
1905 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1906 // {
1907 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1908 // }
1909 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1910 // {
1911 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1912 // }
1913 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1914 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1915 // {
1916 // popup.AppendMenu(MF_SEPARATOR, NULL);
1917 // }
1919 CString str,format;
1920 //if (m_hasWC)
1921 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1923 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1925 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1926 GetSelectedCount() == 1)
1927 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1929 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1930 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1932 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1933 str.Format(format,g_Git.GetCurrentBranch());
1935 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
1936 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1938 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1939 str.Format(format,g_Git.GetCurrentBranch());
1941 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
1942 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1945 // Add Switch Branch express Menu
1946 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1947 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
1950 std::vector<CString *> branchs;
1951 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1953 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1954 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1956 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1960 CString str;
1961 str.LoadString(IDS_SWITCH_BRANCH);
1963 if(branchs.size() == 1)
1965 str+=_T(" ");
1966 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1967 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1969 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1972 else if(branchs.size() > 1)
1974 subbranchmenu.CreatePopupMenu();
1975 for (size_t i = 0 ; i < branchs.size(); ++i)
1977 if (*branchs[i] != currentBranch)
1979 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1980 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1984 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1988 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
1989 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1991 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
1992 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1994 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
1995 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1997 format.LoadString(IDS_REBASE_THIS_FORMAT);
1998 str.Format(format,g_Git.GetCurrentBranch());
2000 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2001 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2002 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2004 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2005 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2007 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2009 if (parentHash.size() == 1)
2011 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2013 else if (parentHash.size() > 1)
2015 revertmenu.CreatePopupMenu();
2016 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2018 for (size_t i = 0; i < parentHash.size(); ++i)
2020 CString str;
2021 str.Format(IDS_PARENT, i + 1);
2022 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2027 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2028 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2030 popup.AppendMenu(MF_SEPARATOR, NULL);
2035 if(!pSelLogEntry->m_Ref.IsEmpty())
2037 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2038 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2039 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2040 popup.AppendMenu(MF_SEPARATOR, NULL);
2043 if (GetSelectedCount() >= 2)
2045 bool bAddSeparator = false;
2046 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2048 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2049 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2052 if (GetSelectedCount() == 2)
2054 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2055 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2057 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2059 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2060 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2061 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2062 CString menu;
2063 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2064 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2065 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2066 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2069 bAddSeparator = true;
2072 if (m_hasWC)
2074 bAddSeparator = true;
2077 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2078 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2080 if (bAddSeparator)
2081 popup.AppendMenu(MF_SEPARATOR, NULL);
2084 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2086 bool bAddSeparator = false;
2087 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2089 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2091 CString head;
2092 int headindex;
2093 headindex = this->GetHeadIndex();
2094 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2096 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2097 CGitHash hashFirst;
2098 if (g_Git.GetHash(hashFirst, head))
2099 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2100 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2101 CGitHash hash;
2102 if (g_Git.GetHash(hash, head))
2103 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2104 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect));
2105 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2106 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2107 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2108 bAddSeparator = true;
2113 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2114 if (GetSelectedCount() >= 2)
2115 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2116 else
2117 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2118 bAddSeparator = true;
2121 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2122 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2123 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2124 bAddSeparator = true;
2127 if (bAddSeparator)
2128 popup.AppendMenu(MF_SEPARATOR, NULL);
2131 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())
2133 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2134 popup.AppendMenu(MF_SEPARATOR, NULL);
2137 if (GetSelectedCount() == 1)
2139 bool bAddSeparator = false;
2140 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2142 // show the push-option only if the log entry has an associated local branch
2143 bool isLocal = false;
2144 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2146 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2147 isLocal = true;
2149 if (isLocal)
2151 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2152 bAddSeparator = true;
2155 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive)
2157 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2158 bAddSeparator = true;
2162 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2164 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2166 std::vector<CString *> branchs;
2167 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2169 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2170 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2172 CString str;
2173 if (branchs.size() == 1)
2175 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2176 str+=_T(" ");
2177 str += *branchs[0];
2178 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2179 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2180 bAddSeparator = true;
2182 else if (branchs.size() > 1)
2184 str.LoadString(IDS_DELETE_BRANCHTAG);
2185 submenu.CreatePopupMenu();
2186 for (size_t i = 0; i < branchs.size(); ++i)
2188 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2189 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2192 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2193 bAddSeparator = true;
2196 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2197 if (bAddSeparator)
2198 popup.AppendMenu(MF_SEPARATOR, NULL);
2199 } // GetSelectedCount() == 1
2201 if (GetSelectedCount() != 0)
2203 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2204 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2205 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2206 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2207 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2208 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2211 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2212 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2214 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2215 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2217 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2218 // DialogEnableWindow(IDOK, FALSE);
2219 // SetPromptApp(&theApp);
2221 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2223 // EnableOKButton();
2224 } // if (popup.CreatePopupMenu())
2228 bool CGitLogListBase::IsSelectionContinuous()
2230 if ( GetSelectedCount()==1 )
2232 // if only one revision is selected, the selection is of course
2233 // continuous
2234 return true;
2237 POSITION pos = GetFirstSelectedItemPosition();
2238 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2239 if (bContinuous)
2241 int itemindex = GetNextSelectedItem(pos);
2242 while (pos)
2244 int nextindex = GetNextSelectedItem(pos);
2245 if (nextindex - itemindex > 1)
2247 bContinuous = false;
2248 break;
2250 itemindex = nextindex;
2253 return bContinuous;
2256 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2259 CString sClipdata;
2260 POSITION pos = GetFirstSelectedItemPosition();
2261 if (pos != NULL)
2263 CString sRev;
2264 sRev.LoadString(IDS_LOG_REVISION);
2265 CString sAuthor;
2266 sAuthor.LoadString(IDS_LOG_AUTHOR);
2267 CString sDate;
2268 sDate.LoadString(IDS_LOG_DATE);
2269 CString sMessage;
2270 sMessage.LoadString(IDS_LOG_MESSAGE);
2271 bool first = true;
2272 while (pos)
2274 CString sLogCopyText;
2275 CString sPaths;
2276 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2278 if (toCopy == ID_COPY_ALL)
2280 //pLogEntry->GetFiles(this)
2281 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2283 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2284 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2286 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2287 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2289 CString rename;
2290 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2291 sPaths += _T(" ") + rename;
2293 sPaths += _T("\r\n");
2295 sPaths.Trim();
2296 CString body = pLogEntry->GetBody();
2297 body.Replace(_T("\n"), _T("\r\n"));
2298 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"),
2299 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2300 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2301 (LPCTSTR)sDate,
2302 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2303 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2304 (LPCTSTR)sPaths);
2305 sClipdata += sLogCopyText;
2307 else if (toCopy == ID_COPY_MESSAGE)
2309 CString body = pLogEntry->GetBody();
2310 body.Replace(_T("\n"), _T("\r\n"));
2311 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2313 else if (toCopy == ID_COPY_SUBJECT)
2315 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2317 else
2319 if (!first)
2320 sClipdata += _T("\r\n");
2321 sClipdata += pLogEntry->m_CommitHash;
2324 first = false;
2326 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2331 void CGitLogListBase::DiffSelectedRevWithPrevious()
2333 if (m_bThreadRunning)
2334 return;
2336 int FirstSelect=-1, LastSelect=-1;
2337 POSITION pos = GetFirstSelectedItemPosition();
2338 FirstSelect = GetNextSelectedItem(pos);
2339 while(pos)
2341 LastSelect = GetNextSelectedItem(pos);
2344 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2346 #if 0
2347 UpdateLogInfoLabel();
2348 int selIndex = m_LogList.GetSelectionMark();
2349 if (selIndex < 0)
2350 return;
2351 int selCount = m_LogList.GetSelectedCount();
2352 if (selCount != 1)
2353 return;
2355 // Find selected entry in the log list
2356 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2357 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2358 long rev1 = pLogEntry->Rev;
2359 long rev2 = rev1-1;
2360 CTGitPath path = m_path;
2362 // See how many files under the relative root were changed in selected revision
2363 int nChanged = 0;
2364 LogChangedPath * changed = NULL;
2365 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2367 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2368 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2370 ++nChanged;
2371 changed = cpath;
2375 if (m_path.IsDirectory() && nChanged == 1)
2377 // We're looking at the log for a directory and only one file under dir was changed in the revision
2378 // Do diff on that file instead of whole directory
2379 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2382 m_bCancelled = FALSE;
2383 DialogEnableWindow(IDOK, FALSE);
2384 SetPromptApp(&theApp);
2385 theApp.DoWaitCursor(1);
2387 if (PromptShown())
2389 GitDiff diff(this, m_hWnd, true);
2390 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2391 diff.SetHEADPeg(m_LogRevision);
2392 diff.ShowCompare(path, rev2, path, rev1);
2394 else
2396 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2399 theApp.DoWaitCursor(-1);
2400 EnableOKButton();
2401 #endif
2404 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2406 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2407 *pResult = -1;
2409 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2410 return;
2411 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2412 return;
2413 if (pFindInfo->lvfi.psz == 0)
2414 return;
2415 #if 0
2416 CString sCmp = pFindInfo->lvfi.psz;
2417 CString sRev;
2418 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2420 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2421 sRev.Format(_T("%ld"), pLogEntry->Rev);
2422 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2424 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2426 *pResult = i;
2427 return;
2430 else
2432 if (sCmp.Compare(sRev)==0)
2434 *pResult = i;
2435 return;
2439 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2441 for (int i=0; i<pFindInfo->iStart; ++i)
2443 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2444 sRev.Format(_T("%ld"), pLogEntry->Rev);
2445 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2447 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2449 *pResult = i;
2450 return;
2453 else
2455 if (sCmp.Compare(sRev)==0)
2457 *pResult = i;
2458 return;
2463 #endif
2464 *pResult = -1;
2467 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2469 ClearText();
2471 this->m_arShownList.SafeRemoveAll();
2473 this->m_logEntries.ClearAll();
2474 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2475 return -1;
2477 //this->m_logEntries.ParserFromLog();
2478 SetItemCountEx((int)m_logEntries.size());
2480 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2482 if(m_IsOldFirst)
2484 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2485 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2488 else
2490 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2491 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2495 ReloadHashMap();
2497 if(path)
2498 m_Path=*path;
2499 return 0;
2503 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2505 ClearText();
2507 m_arShownList.SafeRemoveAll();
2509 m_logEntries.ClearAll();
2510 if (m_logEntries.Fill(hashes))
2511 return -1;
2513 SetItemCountEx((int)m_logEntries.size());
2515 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2517 if (m_IsOldFirst)
2519 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2520 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2522 else
2524 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2525 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2529 ReloadHashMap();
2531 return 0;
2534 int CGitLogListBase::BeginFetchLog()
2536 ClearText();
2538 this->m_arShownList.SafeRemoveAll();
2540 this->m_logEntries.ClearAll();
2542 this->m_LogCache.ClearAllParent();
2544 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2546 CTGitPath *path;
2547 if(this->m_Path.IsEmpty())
2548 path=NULL;
2549 else
2550 path=&this->m_Path;
2552 int mask;
2553 mask = CGit::LOG_INFO_ONLY_HASH;
2554 if (m_bIncludeBoundaryCommits)
2555 mask |= CGit::LOG_INFO_BOUNDARY;
2556 // if(this->m_bAllBranch)
2557 mask |= m_ShowMask ;
2559 if(m_bShowWC)
2561 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2562 ResetWcRev();
2563 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2566 if (m_sRange.IsEmpty())
2567 m_sRange = _T("HEAD");
2569 CFilterData data;
2570 data.m_From = m_From;
2571 data.m_To =m_To;
2573 #if 0 /* use tortoiegit filter */
2574 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2575 data.m_Author = this->m_sFilterText;
2577 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2578 data.m_MessageFilter = this->m_sFilterText;
2580 data.m_IsRegex = m_bFilterWithRegex;
2581 #endif
2583 // follow does not work for directories
2584 if (!path || path->IsDirectory())
2585 mask &= ~CGit::LOG_INFO_FOLLOW;
2586 // follow does not work with all branches 8at least in TGit)
2587 if (mask & CGit::LOG_INFO_FOLLOW)
2588 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2590 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2592 //this->m_logEntries.ParserFromLog();
2593 if(IsInWorkingThread())
2595 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2597 else
2599 SetItemCountEx((int)m_logEntries.size());
2604 [] { git_init(); } ();
2606 catch (char* msg)
2608 CString err(msg);
2609 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2610 return -1;
2613 if (!g_Git.CanParseRev(m_sRange))
2615 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2616 return 0;
2618 // if show all branches, pick any ref as dummy entry ref
2619 STRING_VECTOR list;
2620 if (g_Git.GetRefList(list))
2621 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2622 if (list.size() == 0)
2623 return 0;
2625 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2628 g_Git.m_critGitDllSec.Lock();
2629 try {
2630 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2632 g_Git.m_critGitDllSec.Unlock();
2633 return -1;
2636 catch (char* msg)
2638 g_Git.m_critGitDllSec.Unlock();
2639 CString err(msg);
2640 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2641 return -1;
2643 g_Git.m_critGitDllSec.Unlock();
2645 return 0;
2648 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2650 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2652 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2654 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2656 DiffSelectedRevWithPrevious();
2657 return TRUE;
2660 #if 0
2661 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2663 DiffSelectedFile();
2664 return TRUE;
2666 #endif
2668 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2670 // select all entries
2671 for (int i=0; i<GetItemCount(); ++i)
2673 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2675 return TRUE;
2678 #if 0
2679 if (m_hAccel && !bSkipAccelerator)
2681 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2682 if (ret)
2683 return TRUE;
2686 #endif
2687 //m_tooltips.RelayEvent(pMsg);
2688 return __super::PreTranslateMessage(pMsg);
2691 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2693 // a double click on an entry in the revision list has happened
2694 *pResult = 0;
2696 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2697 DiffSelectedRevWithPrevious();
2700 int CGitLogListBase::FetchLogAsync(void * data)
2702 ReloadHashMap();
2703 m_ProcData=data;
2704 m_bExitThread=FALSE;
2705 InterlockedExchange(&m_bThreadRunning, TRUE);
2706 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2707 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2708 if (m_LoadingThread ==NULL)
2710 InterlockedExchange(&m_bThreadRunning, FALSE);
2711 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2712 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2713 return -1;
2715 return 0;
2718 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2720 return ((CGitLogListBase*)pVoid)->LogThread();
2723 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2725 //CTime time;
2726 oldest=CTime::GetCurrentTime();
2727 latest=CTime(1971,1,2,0,0,0);
2728 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2730 if(m_logEntries[i].IsEmpty())
2731 continue;
2733 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2734 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2736 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2737 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2741 if(latest<oldest)
2742 latest=oldest;
2745 UINT CGitLogListBase::LogThread()
2747 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2749 InterlockedExchange(&m_bThreadRunning, TRUE);
2750 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2752 ULONGLONG t1,t2;
2754 if(BeginFetchLog())
2756 InterlockedExchange(&m_bThreadRunning, FALSE);
2757 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2759 return 1;
2762 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2763 bool bRegex = false;
2764 if (m_bFilterWithRegex)
2765 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2767 TRACE(_T("\n===Begin===\n"));
2768 //Update work copy item;
2770 if (!m_logEntries.empty())
2772 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2774 m_arShownList.SafeAdd(pRev);
2778 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2780 // store commit number of the last selected commit/line before the refresh or -1
2781 int lastSelectedHashNItem = -1;
2782 int ret = 0;
2784 bool shouldWalk = true;
2785 if (!g_Git.CanParseRev(m_sRange))
2787 // walk revisions if show all branches and there exists any ref
2788 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2789 shouldWalk = false;
2790 else
2792 STRING_VECTOR list;
2793 if (g_Git.GetRefList(list))
2794 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2795 if (list.size() == 0)
2796 shouldWalk = false;
2800 if (shouldWalk)
2802 g_Git.m_critGitDllSec.Lock();
2803 int total = 0;
2806 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2807 total = git_get_log_estimate_commit_count(m_DllGitLog);
2809 catch (char* msg)
2811 CString err(msg);
2812 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2813 ret = -1;
2815 g_Git.m_critGitDllSec.Unlock();
2817 GIT_COMMIT commit;
2818 t2=t1=GetTickCount();
2819 int oldprecentage = 0;
2820 size_t oldsize = m_logEntries.size();
2821 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2822 while (ret== 0 && !m_bExitThread)
2824 g_Git.m_critGitDllSec.Lock();
2827 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2829 catch (char* msg)
2831 g_Git.m_critGitDllSec.Unlock();
2832 CString err(msg);
2833 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2834 break;
2836 g_Git.m_critGitDllSec.Unlock();
2838 if(ret)
2839 break;
2841 if (commit.m_ignore == 1)
2843 git_free_commit(&commit);
2844 continue;
2847 //printf("%s\r\n",commit.GetSubject());
2848 if(m_bExitThread)
2849 break;
2851 CGitHash hash = (char*)commit.m_hash ;
2853 GitRev *pRev = m_LogCache.GetCacheData(hash);
2854 pRev->m_GitCommit = commit;
2855 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2857 char *note=NULL;
2858 g_Git.m_critGitDllSec.Lock();
2861 git_get_notes(commit.m_hash, &note);
2863 catch (char* msg)
2865 g_Git.m_critGitDllSec.Unlock();
2866 CString err(msg);
2867 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2868 break;
2870 g_Git.m_critGitDllSec.Unlock();
2872 if(note)
2874 pRev->m_Notes.Empty();
2875 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2878 if(!pRev->m_IsDiffFiles)
2880 pRev->m_CallDiffAsync = DiffAsync;
2883 pRev->ParserParentFromCommit(&commit);
2884 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2886 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2888 const CGitHash &parentHash = pRev->m_ParentHash[i];
2889 auto it = commitChildren.find(parentHash);
2890 if (it == commitChildren.end())
2892 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2894 it->second.insert(pRev->m_CommitHash);
2898 #ifdef DEBUG
2899 pRev->DbgPrint();
2900 TRACE(_T("\n"));
2901 #endif
2903 bool visible = true;
2904 if (HasFilterText())
2906 if(!IsMatchFilter(bRegex,pRev,pat))
2907 visible = false;
2909 if (visible && !ShouldShowFilter(pRev, commitChildren))
2910 visible = false;
2911 this->m_critSec.Lock();
2912 m_logEntries.append(hash, visible);
2913 if (visible)
2914 m_arShownList.SafeAdd(pRev);
2915 this->m_critSec.Unlock();
2917 if (!visible)
2918 continue;
2920 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2921 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2923 t2=GetTickCount();
2925 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2927 //update UI
2928 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2929 if(percent > 99)
2930 percent =99;
2931 if(percent < GITLOG_START)
2932 percent = GITLOG_START +1;
2934 oldsize = m_logEntries.size();
2935 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2937 //if( percent > oldprecentage )
2939 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2940 oldprecentage = percent;
2943 if (lastSelectedHashNItem >= 0)
2944 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2946 t1 = t2;
2949 g_Git.m_critGitDllSec.Lock();
2950 git_close_log(m_DllGitLog);
2951 g_Git.m_critGitDllSec.Unlock();
2955 if (m_bExitThread)
2957 InterlockedExchange(&m_bThreadRunning, FALSE);
2958 return 0;
2961 //Update UI;
2962 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2964 if (lastSelectedHashNItem >= 0)
2965 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2967 if (this->m_hWnd)
2968 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2970 InterlockedExchange(&m_bThreadRunning, FALSE);
2972 return 0;
2975 void CGitLogListBase::FetchRemoteList()
2977 STRING_VECTOR remoteList;
2978 if (!g_Git.GetRemoteList(remoteList))
2979 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
2980 else
2981 m_SingleRemote = _T("");
2984 void CGitLogListBase::FetchTrackingBranchList()
2986 m_TrackingMap.clear();
2987 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
2989 for (size_t j = 0; j < it->second.size(); ++j)
2991 CString branchName;
2992 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
2994 CString configName;
2995 configName.Format(_T("branch.%s.remote"), branchName);
2996 CString pullRemote = g_Git.GetConfigValue(configName);
2998 configName.Format(_T("branch.%s.merge"), branchName);
2999 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
3001 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3003 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3010 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3012 SafeTerminateThread();
3014 this->SetItemCountEx(0);
3015 this->Clear();
3017 ResetWcRev();
3019 // HACK to hide graph column
3020 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3021 SetColumnWidth(0, 0);
3022 else
3023 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3025 //Update branch and Tag info
3026 ReloadHashMap();
3027 //Assume Thread have exited
3028 //if(!m_bThreadRunning)
3030 m_logEntries.clear();
3032 if(IsCleanFilter)
3034 m_sFilterText.Empty();
3035 m_From=-1;
3036 m_To=-1;
3039 InterlockedExchange(&m_bExitThread,FALSE);
3041 InterlockedExchange(&m_bThreadRunning, TRUE);
3042 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3043 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3045 InterlockedExchange(&m_bThreadRunning, FALSE);
3046 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3047 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3051 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3055 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3056 if (!bMatchCase)
3057 type |= std::tr1::regex_constants::icase;
3058 pat = std::tr1::wregex(regexp_str, type);
3059 return true;
3061 catch (std::exception) {}
3062 return false;
3064 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
3066 BOOL result = TRUE;
3067 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3068 CString sRev;
3070 if ((bRegex)&&(m_bFilterWithRegex))
3072 if (m_SelectedFilters & LOGFILTER_BUGID)
3074 if(this->m_bShowBugtraqColumn)
3076 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3078 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3079 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3081 return TRUE;
3086 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3088 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3089 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3091 return TRUE;
3095 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3097 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3098 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3100 return TRUE;
3104 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3106 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3108 return TRUE;
3111 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3113 return TRUE;
3117 if (m_SelectedFilters & LOGFILTER_EMAILS)
3119 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3121 return TRUE;
3124 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3126 return TRUE;
3130 if (m_SelectedFilters & LOGFILTER_REVS)
3132 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3133 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3135 return TRUE;
3139 if (m_SelectedFilters & LOGFILTER_REFNAME)
3141 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3142 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3144 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3146 return TRUE;
3151 if (m_SelectedFilters & LOGFILTER_PATHS)
3153 CTGitPathList *pathList=NULL;
3154 if( pRev->m_IsDiffFiles)
3155 pathList = &pRev->GetFiles(this);
3156 else
3158 if(!pRev->m_IsSimpleListReady)
3159 pRev->SafeGetSimpleList(&g_Git);
3162 if(pathList)
3163 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3165 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3167 return true;
3169 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3171 return true;
3175 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3177 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3179 return true;
3184 else
3186 CString find = m_sFilterText;
3187 find.MakeLower();
3188 result = find[0] == '!' ? FALSE : TRUE;
3189 if (!result)
3190 find = find.Mid(1);
3192 if (m_SelectedFilters & LOGFILTER_BUGID)
3194 if(this->m_bShowBugtraqColumn)
3196 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3198 sBugIds.MakeLower();
3199 if ((sBugIds.Find(find) >= 0))
3201 return result;
3206 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3208 CString msg = pRev->GetSubject();
3210 msg = msg.MakeLower();
3211 if ((msg.Find(find) >= 0))
3213 return result;
3217 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3219 CString msg = pRev->GetBody();
3221 msg = msg.MakeLower();
3222 if ((msg.Find(find) >= 0))
3224 return result;
3228 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3230 CString msg = pRev->GetAuthorName();
3231 msg = msg.MakeLower();
3232 if ((msg.Find(find) >= 0))
3234 return result;
3238 if (m_SelectedFilters & LOGFILTER_EMAILS)
3240 CString msg = pRev->GetAuthorEmail();
3241 msg = msg.MakeLower();
3242 if ((msg.Find(find) >= 0))
3244 return result;
3248 if (m_SelectedFilters & LOGFILTER_REVS)
3250 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3251 if ((sRev.Find(find) >= 0))
3253 return result;
3257 if (m_SelectedFilters & LOGFILTER_REFNAME)
3259 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3260 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3262 if (it->Find(find) >= 0)
3264 return result;
3269 if (m_SelectedFilters & LOGFILTER_PATHS)
3271 CTGitPathList *pathList=NULL;
3272 if( pRev->m_IsDiffFiles)
3273 pathList = &pRev->GetFiles(this);
3274 else
3276 if(!pRev->m_IsSimpleListReady)
3277 pRev->SafeGetSimpleList(&g_Git);
3279 if(pathList)
3280 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3282 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3283 CString path = cpath->GetGitOldPathString();
3284 path.MakeLower();
3285 if ((path.Find(find)>=0))
3287 return result;
3289 path = cpath->GetGitPathString();
3290 path.MakeLower();
3291 if ((path.Find(find)>=0))
3293 return result;
3297 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3299 CString path = pRev->m_SimpleFileList[i];
3300 path.MakeLower();
3301 if ((path.Find(find)>=0))
3303 return result;
3307 } // else (from if (bRegex))
3308 return !result;
3311 static bool CStringStartsWith(const CString &str, const CString &prefix)
3313 return str.Left(prefix.GetLength()) == prefix;
3315 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3317 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3318 return true;
3320 if (m_ShowFilter & FILTERSHOW_REFS)
3322 // Keep all refs.
3323 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3324 for (size_t i = 0; i < refList.size(); ++i)
3326 const CString &str = refList[i];
3327 if (CStringStartsWith(str, _T("refs/heads/")))
3329 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3330 return true;
3332 else if (CStringStartsWith(str, _T("refs/remotes/")))
3334 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3335 return true;
3337 else if (CStringStartsWith(str, _T("refs/tags/")))
3339 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3340 return true;
3342 else if (CStringStartsWith(str, _T("refs/stash")))
3344 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3345 return true;
3347 else if (CStringStartsWith(str, _T("refs/bisect/")))
3349 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3350 return true;
3353 // Keep the head too.
3354 if (pRev->m_CommitHash == m_HeadHash)
3355 return true;
3358 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3360 if (pRev->ParentsCount() > 1)
3361 return true;
3362 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3363 if (childrenIt != commitChildren.end())
3365 const std::set<CGitHash> &children = childrenIt->second;
3366 if (children.size() > 1)
3367 return true;
3370 return false;
3373 void CGitLogListBase::ShowGraphColumn(bool bShow)
3375 // HACK to hide graph column
3376 if (bShow)
3377 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3378 else
3379 SetColumnWidth(0, 0);
3382 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3385 pShownlist->SafeRemoveAll();
3387 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3388 bool bRegex = false;
3389 if (m_bFilterWithRegex)
3390 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3392 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3393 CString sRev;
3394 for (DWORD i=0; i<m_logEntries.size(); ++i)
3396 if ((bRegex)&&(m_bFilterWithRegex))
3398 #if 0
3399 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3401 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3402 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3404 pShownlist->SafeAdd(m_logEntries[i]);
3405 continue;
3408 #endif
3409 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3411 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3412 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3414 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3415 continue;
3418 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3420 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3421 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3423 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3424 continue;
3427 if (m_SelectedFilters & LOGFILTER_PATHS)
3429 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3431 bool bGoing = true;
3432 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3434 CTGitPath cpath = pathList[cpPathIndex];
3435 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3437 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3438 bGoing = false;
3439 continue;
3441 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3443 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3444 bGoing = false;
3445 continue;
3447 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3449 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3450 bGoing = false;
3451 continue;
3455 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3457 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3459 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3460 continue;
3463 if (m_SelectedFilters & LOGFILTER_EMAILS)
3465 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3467 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3468 continue;
3471 if (m_SelectedFilters & LOGFILTER_REVS)
3473 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3474 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3476 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3477 continue;
3480 if (m_SelectedFilters & LOGFILTER_REFNAME)
3482 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3483 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3485 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3487 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3488 continue;
3492 } // if (bRegex)
3493 else
3495 CString find = m_sFilterText;
3496 find.MakeLower();
3497 #if 0
3498 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3500 CString sBugIDs = m_logEntries[i]->sBugIDs;
3502 sBugIDs = sBugIDs.MakeLower();
3503 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3505 pShownlist->SafeAdd(m_logEntries[i]);
3506 continue;
3509 #endif
3510 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3512 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3514 msg = msg.MakeLower();
3515 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3517 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3518 continue;
3521 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3523 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3525 msg = msg.MakeLower();
3526 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3528 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3529 continue;
3532 if (m_SelectedFilters & LOGFILTER_PATHS)
3534 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3536 bool bGoing = true;
3537 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3539 CTGitPath cpath = pathList[cpPathIndex];
3540 CString path = cpath.GetGitOldPathString();
3541 path.MakeLower();
3542 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3544 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3545 bGoing = false;
3546 continue;
3548 path = cpath.GetGitPathString();
3549 path.MakeLower();
3550 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3552 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3553 bGoing = false;
3554 continue;
3556 path = cpath.GetActionName();
3557 path.MakeLower();
3558 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3560 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3561 bGoing = false;
3562 continue;
3566 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3568 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3569 msg = msg.MakeLower();
3570 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3572 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3573 continue;
3576 if (m_SelectedFilters & LOGFILTER_EMAILS)
3578 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3579 msg = msg.MakeLower();
3580 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3582 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3583 continue;
3586 if (m_SelectedFilters & LOGFILTER_REVS)
3588 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3589 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3591 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3592 continue;
3595 if (m_SelectedFilters & LOGFILTER_REFNAME)
3597 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3598 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3600 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3602 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3603 continue;
3607 } // else (from if (bRegex))
3608 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3612 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3615 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3617 if(m_From == -1)
3618 if(m_To == -1)
3619 return true;
3620 else
3621 return time <= m_To;
3622 else
3623 if(m_To == -1)
3624 return time >= m_From;
3625 else
3626 return ((time >= m_From)&&(time <= m_To));
3628 return TRUE; /* git dll will filter time range */
3630 // return TRUE;
3632 void CGitLogListBase::StartFilter()
3634 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3635 RecalculateShownList(&m_arShownList);
3636 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3639 DeleteAllItems();
3640 SetItemCountEx(ShownCountWithStopped());
3641 RedrawItems(0, ShownCountWithStopped());
3642 Invalidate();
3645 void CGitLogListBase::RemoveFilter()
3648 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3650 m_arShownList.SafeRemoveAll();
3652 // reset the time filter too
3653 #if 0
3654 m_timFrom = (__time64_t(m_tFrom));
3655 m_timTo = (__time64_t(m_tTo));
3656 m_DateFrom.SetTime(&m_timFrom);
3657 m_DateTo.SetTime(&m_timTo);
3658 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3659 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3660 #endif
3662 for (DWORD i=0; i<m_logEntries.size(); ++i)
3664 if(this->m_IsOldFirst)
3666 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3668 else
3670 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3673 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3674 DeleteAllItems();
3675 SetItemCountEx(ShownCountWithStopped());
3676 RedrawItems(0, ShownCountWithStopped());
3678 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3681 void CGitLogListBase::Clear()
3683 m_arShownList.SafeRemoveAll();
3684 DeleteAllItems();
3686 m_logEntries.ClearAll();
3690 void CGitLogListBase::OnDestroy()
3692 // save the column widths to the registry
3693 SaveColumnWidths();
3695 SafeTerminateThread();
3696 SafeTerminateAsyncDiffThread();
3698 int retry = 0;
3699 while(m_LogCache.SaveCache())
3701 if(retry > 5)
3702 break;
3703 Sleep(1000);
3705 ++retry;
3707 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3708 // MB_YESNO) == IDNO)
3709 // break;
3712 CHintListCtrl::OnDestroy();
3715 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3717 CRect rect;
3718 int i=(int)wParam;
3719 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3720 this->InvalidateRect(rect);
3722 return 0;
3726 * Save column widths to the registry
3728 void CGitLogListBase::SaveColumnWidths()
3730 int maxcol = m_ColumnManager.GetColumnCount();
3732 // HACK that graph column is always shown
3733 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3735 for (int col = 0; col < maxcol; ++col)
3736 if (m_ColumnManager.IsVisible (col))
3737 m_ColumnManager.ColumnResized (col);
3739 m_ColumnManager.WriteSettings();
3742 int CGitLogListBase::GetHeadIndex()
3744 if(m_HeadHash.IsEmpty())
3745 return -1;
3747 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3749 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3750 if(pRev)
3752 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3753 return i;
3756 return -1;
3758 void CGitLogListBase::OnFind()
3760 if (!m_pFindDialog)
3762 m_pFindDialog = new CFindDlg(this);
3763 m_pFindDialog->Create(this);
3766 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3768 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3770 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3772 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3773 Default();
3775 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3777 if (GetSelectedCount() != 0)
3778 return 0;
3780 CGitHash theSelectedHash = m_lastSelectedHash;
3781 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3782 m_lastSelectedHash = theSelectedHash;
3784 int countPerPage = GetCountPerPage();
3785 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3786 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3787 EnsureVisible((int)itemToSelect, FALSE);
3788 return 0;
3790 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3793 ASSERT(m_pFindDialog != NULL);
3794 bool bFound = false;
3795 int i=0;
3797 if (m_pFindDialog->IsTerminating())
3799 // invalidate the handle identifying the dialog box.
3800 m_pFindDialog = NULL;
3801 return 0;
3804 INT_PTR cnt = m_arShownList.GetCount();
3806 if(m_pFindDialog->IsRef())
3808 CString str;
3809 str=m_pFindDialog->GetFindString();
3811 CGitHash hash;
3813 if(!str.IsEmpty())
3815 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3816 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3819 if(!hash.IsEmpty())
3821 for (i = 0; i < cnt; ++i)
3823 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3824 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3826 bFound = true;
3827 break;
3831 if (!bFound)
3833 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3834 return 0;
3838 if (m_pFindDialog->FindNext() && !bFound)
3840 //read data from dialog
3841 CString FindText = m_pFindDialog->GetFindString();
3842 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3844 std::tr1::wregex pat;
3845 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3847 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3849 for (i = m_nSearchIndex + 1; ; ++i)
3851 if (i >= cnt)
3853 i = 0;
3854 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3856 if (m_nSearchIndex >= 0)
3858 if (i == m_nSearchIndex)
3860 ::MessageBeep(0xFFFFFFFF);
3861 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3862 break;
3866 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3868 CString str;
3869 str+=pLogEntry->m_CommitHash.ToString();
3870 str+=_T("\n");
3872 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3874 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3875 str+=_T("\n");
3878 str+=pLogEntry->GetAuthorEmail();
3879 str+=_T("\n");
3880 str+=pLogEntry->GetAuthorName();
3881 str+=_T("\n");
3882 str+=pLogEntry->GetBody();
3883 str+=_T("\n");
3884 str+=pLogEntry->GetCommitterEmail();
3885 str+=_T("\n");
3886 str+=pLogEntry->GetCommitterName();
3887 str+=_T("\n");
3888 str+=pLogEntry->GetSubject();
3889 str+=_T("\n");
3892 /*Because changed files list is loaded on demand when gui show,
3893 files will empty when files have not fetched.
3895 we can add it back by using one-way diff(with outnumber changed and rename detect.
3896 here just need changed filename list. one-way is much quicker.
3898 if(pLogEntry->m_IsFull)
3900 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
3902 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3903 str+=_T("\n");
3904 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3905 str+=_T("\n");
3908 else
3910 if(!pLogEntry->m_IsSimpleListReady)
3911 pLogEntry->SafeGetSimpleList(&g_Git);
3913 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
3915 str+=pLogEntry->m_SimpleFileList[i];
3916 str+=_T("\n");
3922 if (bRegex)
3924 if (std::regex_search(std::wstring(str), pat, flags))
3926 bFound = true;
3927 break;
3930 else
3932 if (bMatchCase)
3934 if (str.Find(FindText) >= 0)
3936 bFound = true;
3937 break;
3941 else
3943 CString msg = str;
3944 msg = msg.MakeLower();
3945 CString find = FindText.MakeLower();
3946 if (msg.Find(find) >= 0)
3948 bFound = TRUE;
3949 break;
3953 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3955 } // if(m_pFindDialog->FindNext())
3956 //UpdateLogInfoLabel();
3958 if (bFound)
3960 m_nSearchIndex = i;
3961 EnsureVisible(i, FALSE);
3962 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3963 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3964 SetSelectionMark(i);
3965 //FillLogMessageCtrl();
3966 UpdateData(FALSE);
3969 return 0;
3972 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3974 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3976 *pResult = FALSE;
3979 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3981 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3983 Invalidate(FALSE);