git fetch show progress
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobf9876fcf63d0c209bb23aff6bd0f894c3e7a1fca
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "GitLogListBase.h"
26 #include "GitRev.h"
27 #include "IconMenu.h"
28 #include "cursor.h"
29 #include "InputDlg.h"
30 #include "GitProgressDlg.h"
31 #include "ProgressDlg.h"
32 #include "LogDlg.h"
33 #include "MessageBox.h"
34 #include "registry.h"
35 #include "LoglistUtils.h"
36 #include "PathUtils.h"
37 #include "StringUtils.h"
38 #include "UnicodeUtils.h"
39 #include "TempFile.h"
40 #include "IconMenu.h"
41 #include "GitStatus.h"
42 #include "..\\TortoiseShell\\Resource.h"
43 #include "FindDlg.h"
44 #include "SysInfo.h"
46 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
47 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
48 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
54 ,m_nSearchIndex(0)
55 ,m_bNoDispUpdates(FALSE)
56 , m_bThreadRunning(FALSE)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL)
59 , m_SelectedFilters(LOGFILTER_ALL)
60 , m_ShowFilter(FILTERSHOW_ALL)
61 , m_bShowWC(false)
62 , m_logEntries(&m_LogCache)
63 , m_pFindDialog(NULL)
64 , m_ColumnManager(this)
65 , m_dwDefaultColumns(0)
66 , m_arShownList(&m_critSec)
67 , m_hasWC(true)
68 , m_bNoHightlightHead(FALSE)
69 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
71 // use the default GUI font, create a copy of it and
72 // change the copy to BOLD (leave the rest of the font
73 // the same)
74 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
75 LOGFONT lf = {0};
76 GetObject(hFont, sizeof(LOGFONT), &lf);
77 lf.lfWeight = FW_BOLD;
78 m_boldFont = CreateFontIndirect(&lf);
79 lf.lfWeight = FW_DONTCARE;
80 lf.lfItalic = TRUE;
81 m_FontItalics = CreateFontIndirect(&lf);
82 lf.lfWeight = FW_BOLD;
83 m_boldItalicsFont = CreateFontIndirect(&lf);
85 m_bShowBugtraqColumn=false;
87 m_IsIDReplaceAction=FALSE;
89 this->m_critSec.Init();
90 m_critSec_AsyncDiff.Init();
91 m_wcRev.m_CommitHash.Empty();
92 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
93 m_wcRev.m_ParentHash.clear();
94 m_wcRev.m_Mark=_T('-');
95 m_wcRev.m_IsUpdateing=FALSE;
96 m_wcRev.m_IsFull = TRUE;
98 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
99 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
100 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
101 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
102 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
104 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
105 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
107 m_From = -1;
108 m_To = -1;
110 m_ShowMask = 0;
111 m_LoadingThread = NULL;
113 InterlockedExchange(&m_bExitThread,FALSE);
114 m_IsOldFirst = FALSE;
115 m_IsRebaseReplaceGraph = FALSE;
117 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
119 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
121 // get short/long datetime setting from registry
122 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
123 if ( RegUseShortDateFormat )
125 m_DateFormat = DATE_SHORTDATE;
127 else
129 m_DateFormat = DATE_LONGDATE;
131 // get relative time display setting from registry
132 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
133 m_bRelativeTimes = (regRelativeTimes != 0);
134 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
136 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
137 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
141 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
142 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
144 m_ColumnRegKey=_T("log");
146 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
147 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
148 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
150 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
151 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
153 m_AsyncThreadExit = FALSE;
154 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
155 m_AsynDiffListLock.Init();
157 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
158 if (m_DiffingThread ==NULL)
160 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
161 return;
166 int CGitLogListBase::AsyncDiffThread()
168 m_AsyncThreadExited = false;
169 while(!m_AsyncThreadExit)
171 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
173 GitRev *pRev = NULL;
174 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
176 m_AsynDiffListLock.Lock();
177 pRev = m_AsynDiffList.back();
178 m_AsynDiffList.pop_back();
179 m_AsynDiffListLock.Unlock();
181 if( pRev->m_CommitHash.IsEmpty() )
183 if(pRev->m_IsDiffFiles)
184 continue;
186 pRev->GetFiles(this).Clear();
187 pRev->m_ParentHash.clear();
188 pRev->m_ParentHash.push_back(m_HeadHash);
189 if(g_Git.IsInitRepos())
191 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
192 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
195 else
197 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
199 int dummyAction = 0;
200 int *action = &dummyAction;
201 SafeGetAction(pRev, &action);
202 *action = 0;
204 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
205 *action |= pRev->GetFiles(this)[j].m_Action;
207 CString err;
208 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
210 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
211 return -1;
214 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
215 InterlockedExchange(&pRev->m_IsFull, TRUE);
217 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
218 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
219 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
222 m_critSec_AsyncDiff.Lock();
223 int ret = pRev->CheckAndDiff();
224 m_critSec_AsyncDiff.Unlock();
225 if (!ret)
226 { // fetch change file list
227 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
229 if(i < m_arShownList.GetCount())
231 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
232 if(data->m_CommitHash == pRev->m_CommitHash)
234 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
235 break;
240 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
242 POSITION pos = GetFirstSelectedItemPosition();
243 int nItem = GetNextSelectedItem(pos);
245 if(nItem>=0)
247 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(nItem);
248 if(data)
249 if(data->m_CommitHash == pRev->m_CommitHash)
251 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
258 m_AsyncThreadExited = true;
259 return 0;
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
263 if (exclusivelyShow)
265 m_ContextMenuMask &= hideMask;
267 else
269 m_ContextMenuMask &= ~hideMask;
273 CGitLogListBase::~CGitLogListBase()
275 InterlockedExchange(&m_bNoDispUpdates, TRUE);
276 this->m_arShownList.SafeRemoveAll();
278 DestroyIcon(m_hModifiedIcon);
279 DestroyIcon(m_hReplacedIcon);
280 DestroyIcon(m_hAddedIcon);
281 DestroyIcon(m_hDeletedIcon);
282 m_logEntries.ClearAll();
284 if (m_boldFont)
285 DeleteObject(m_boldFont);
287 if (m_FontItalics)
288 DeleteObject(m_FontItalics);
290 if (m_boldItalicsFont)
291 DeleteObject(m_boldItalicsFont);
293 if ( m_pStoreSelection )
295 delete m_pStoreSelection;
296 m_pStoreSelection = NULL;
299 SafeTerminateThread();
300 SafeTerminateAsyncDiffThread();
302 if(m_AsyncDiffEvent)
303 CloseHandle(m_AsyncDiffEvent);
307 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
308 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
309 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
310 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
311 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
312 ON_WM_CONTEXTMENU()
313 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
314 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
315 ON_WM_CREATE()
316 ON_WM_DESTROY()
317 ON_MESSAGE(MSG_LOADED,OnLoad)
318 ON_WM_MEASUREITEM()
319 ON_WM_MEASUREITEM_REFLECT()
320 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
321 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
322 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
323 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
324 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
325 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
326 END_MESSAGE_MAP()
328 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
330 //if (m_nRowHeight>0)
332 lpMeasureItemStruct->itemHeight = 50;
336 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
338 PreSubclassWindow();
339 return CHintListCtrl::OnCreate(lpCreateStruct);
342 void CGitLogListBase::PreSubclassWindow()
344 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
345 // load the icons for the action columns
346 // m_Theme.Open(m_hWnd, L"ListView");
347 SetWindowTheme(m_hWnd, L"Explorer", NULL);
348 CHintListCtrl::PreSubclassWindow();
351 CString CGitLogListBase::GetRebaseActionName(int action)
353 if (action & LOGACTIONS_REBASE_EDIT)
354 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
355 if (action & LOGACTIONS_REBASE_SQUASH)
356 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
357 if (action & LOGACTIONS_REBASE_PICK)
358 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
359 if (action & LOGACTIONS_REBASE_SKIP)
360 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
362 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
365 void CGitLogListBase::InsertGitColumn()
367 CString temp;
369 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
370 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
371 if (DWORD(regFullRowSelect))
372 exStyle |= LVS_EX_FULLROWSELECT;
373 SetExtendedStyle(exStyle);
375 // only load properties if we have a repository
376 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
377 UpdateProjectProperties();
379 static UINT normal[] =
381 IDS_LOG_GRAPH,
382 IDS_LOG_REBASE,
383 IDS_LOG_ID,
384 IDS_LOG_HASH,
385 IDS_LOG_ACTIONS,
386 IDS_LOG_MESSAGE,
387 IDS_LOG_AUTHOR,
388 IDS_LOG_DATE,
389 IDS_LOG_EMAIL,
390 IDS_LOG_COMMIT_NAME,
391 IDS_LOG_COMMIT_EMAIL,
392 IDS_LOG_COMMIT_DATE,
393 IDS_LOG_BUGIDS,
394 IDS_LOG_SVNREV,
397 static int with[] =
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 ICONITEMBORDER+16*4,
402 ICONITEMBORDER+16*4,
403 ICONITEMBORDER+16*4,
404 LOGLIST_MESSAGE_MIN,
405 ICONITEMBORDER+16*4,
406 ICONITEMBORDER+16*4,
407 ICONITEMBORDER+16*4,
408 ICONITEMBORDER+16*4,
409 ICONITEMBORDER+16*4,
410 ICONITEMBORDER+16*4,
411 ICONITEMBORDER+16*4,
412 ICONITEMBORDER+16*4,
414 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
416 DWORD hideColumns = 0;
417 if(this->m_IsRebaseReplaceGraph)
419 hideColumns |= GIT_LOG_GRAPH;
420 m_dwDefaultColumns |= GIT_LOG_REBASE;
422 else
424 hideColumns |= GIT_LOG_REBASE;
427 if(this->m_IsIDReplaceAction)
429 hideColumns |= GIT_LOG_ACTIONS;
430 m_dwDefaultColumns |= GIT_LOG_ID;
431 m_dwDefaultColumns |= GIT_LOG_HASH;
433 else
435 hideColumns |= GIT_LOG_ID;
437 if(this->m_bShowBugtraqColumn)
439 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
441 else
443 hideColumns |= GIT_LOGLIST_BUG;
445 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
446 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
447 else
448 hideColumns |= GIT_LOGLIST_SVNREV;
449 SetRedraw(false);
451 m_ColumnManager.SetNames(normal, _countof(normal));
452 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
454 SetRedraw(true);
458 * Resizes all columns in a list control to values in registry.
460 void CGitLogListBase::ResizeAllListCtrlCols()
462 // column max and min widths to allow
463 static const int nMinimumWidth = 10;
464 static const int nMaximumWidth = 1000;
465 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
466 if (pHdrCtrl)
468 int numcols = pHdrCtrl->GetItemCount();
469 for (int col = 0; col < numcols; ++col)
471 // get width for this col last time from registry
472 CString regentry;
473 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
474 CRegDWORD regwidth(regentry, 0);
475 int cx = regwidth;
476 if ( cx == 0 )
478 // no saved value, setup sensible defaults
479 if (col == this->LOGLIST_MESSAGE)
481 cx = LOGLIST_MESSAGE_MIN;
483 else
485 cx = ICONITEMBORDER+16*4;
488 if (cx < nMinimumWidth)
490 cx = nMinimumWidth;
492 else if (cx > nMaximumWidth)
494 cx = nMaximumWidth;
497 SetColumnWidth(col, cx);
504 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
506 LVITEM rItem;
507 SecureZeroMemory(&rItem, sizeof(LVITEM));
508 rItem.mask = LVIF_STATE;
509 rItem.iItem = (int)Index;
510 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
511 GetItem(&rItem);
513 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
514 HBRUSH brush = NULL;
516 if (!(rItem.state & LVIS_SELECTED))
518 int action = pLogEntry->GetRebaseAction();
519 if (action & LOGACTIONS_REBASE_SQUASH)
520 brush = ::CreateSolidBrush(RGB(156,156,156));
521 else if (action & LOGACTIONS_REBASE_EDIT)
522 brush = ::CreateSolidBrush(RGB(200,200,128));
524 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
526 if (rItem.state & LVIS_SELECTED)
528 if (::GetFocus() == m_hWnd)
529 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
530 else
531 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
534 if (brush != NULL)
536 ::FillRect(hdc, &rect, brush);
537 ::DeleteObject(brush);
541 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
543 POINT point = { 4, 4 };
544 CRect rt2 = rect;
545 rt2.DeflateRect(1, 1);
546 rt2.OffsetRect(2, 2);
548 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
549 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
550 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
551 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
552 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
554 ::SelectObject(hdc, brush);
555 rt2.OffsetRect(-2, -2);
556 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
557 ::SelectObject(hdc, oldbrush);
558 ::SelectObject(hdc, oldpen);
559 ::DeleteObject(nullPen);
560 ::DeleteObject(darkBrush);
563 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
565 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
566 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
567 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
568 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
569 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
570 ::LineTo(hdc, rect.left, rect.bottom);
571 ::SelectObject(hdc, oldpen);
572 ::DeleteObject(pen);
575 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
577 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
578 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
579 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
580 ::LineTo(hdc, rect.left, rect.bottom);
581 ::LineTo(hdc, rect.right, rect.bottom);
582 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
583 ::SelectObject(hdc, oldpen);
584 ::DeleteObject(pen);
587 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
589 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
590 CRect rt=rect;
591 LVITEM rItem;
592 SecureZeroMemory(&rItem, sizeof(LVITEM));
593 rItem.mask = LVIF_STATE;
594 rItem.iItem = (int)index;
595 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
596 GetItem(&rItem);
598 CDC W_Dc;
599 W_Dc.Attach(hdc);
601 HTHEME hTheme = NULL;
602 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
603 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
605 SIZE oneSpaceSize;
606 if (m_bTagsBranchesOnRightSide)
608 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
609 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
610 SelectObject(hdc, oldFont);
611 rt.left += oneSpaceSize.cx * 2;
613 else
615 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
616 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
617 rt.left += oneSpaceSize.cx;
620 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
622 int txtState = LISS_NORMAL;
623 if (rItem.state & LVIS_SELECTED)
624 txtState = LISS_SELECTED;
626 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
628 else
630 if (rItem.state & LVIS_SELECTED)
632 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
633 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
634 ::SetTextColor(hdc, clrOld);
636 else
638 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
642 if (m_bTagsBranchesOnRightSide)
644 SIZE size;
645 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
647 rt.left += oneSpaceSize.cx + size.cx;
649 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
652 if (hTheme)
653 CloseThemeData(hTheme);
655 W_Dc.Detach();
658 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
660 for (unsigned int i = 0; i < refList.size(); ++i)
662 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
663 HBRUSH brush = 0;
664 COLORREF colRef = refList[i].color;
665 bool singleRemote = refList[i].singleRemote;
666 bool hasTracking = refList[i].hasTracking;
667 bool sameName = refList[i].sameName;
668 bool annotatedTag = refList[i].annotatedTag;
670 //When row selected, ajust label color
671 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
673 if (rItem.state & LVIS_SELECTED)
674 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
677 brush = ::CreateSolidBrush(colRef);
679 if (!shortname.IsEmpty() && (rt.left < rect.right))
681 SIZE size;
682 memset(&size,0,sizeof(SIZE));
683 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
685 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
686 rt.right += 8;
688 int textpos = DT_CENTER;
690 if (rt.right > rect.right)
692 rt.right = rect.right;
693 textpos = 0;
696 CRect textRect = rt;
698 if (singleRemote)
700 rt.right += 8;
701 textRect.OffsetRect(8, 0);
704 if (sameName)
705 rt.right += 8;
707 if (hasTracking)
709 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
711 else
713 //Fill interior of ref label
714 ::FillRect(hdc, &rt, brush);
717 //Draw edge of label
718 CRect rectEdge = rt;
720 if (!hasTracking)
722 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
723 rectEdge.DeflateRect(1, 1);
724 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
727 if (annotatedTag)
729 rt.right += 8;
730 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
731 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
732 ::FillRgn(hdc, hrgn, brush);
733 ::DeleteObject(hrgn);
734 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
735 HPEN pen;
736 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
737 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
738 ::DeleteObject(pen);
739 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
740 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
741 ::DeleteObject(pen);
742 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
743 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
744 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
745 ::DeleteObject(pen);
746 SelectObject(hdc, oldpen);
749 //Draw text inside label
750 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
751 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
753 int txtState = LISS_NORMAL;
754 if (rItem.state & LVIS_SELECTED)
755 txtState = LISS_SELECTED;
757 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
759 else
761 W_Dc.SetBkMode(TRANSPARENT);
762 if (customColor || (rItem.state & LVIS_SELECTED))
764 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
765 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
766 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
767 ::SetTextColor(hdc,clrOld);
769 else
771 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
775 if (singleRemote)
777 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
778 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
779 CRect newRect;
780 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
781 DrawLightning(hdc, newRect, color, bold);
784 if (sameName)
786 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
787 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
788 CRect newRect;
789 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
790 DrawUpTriangle(hdc, newRect, color, bold);
793 rt.left = rt.right + 1;
795 if (brush)
796 ::DeleteObject(brush);
798 rt.right = rect.right;
801 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
803 // Returns ((256 - amount)*col1 + amount*col2) / 256;
804 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
805 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
806 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
809 Gdiplus::Color GetGdiColor(COLORREF col)
811 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
813 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
814 const COLORREF& col,const COLORREF& activeColor, int top
817 int h = laneHeight / 2;
818 int m = (x1 + x2) / 2;
819 int r = (x2 - x1) * m_NodeSize / 30;
820 int d = 2 * r;
822 #define P_CENTER m , h+top
823 #define P_0 x2, h+top
824 #define P_90 m , 0+top-1
825 #define P_180 x1, h+top
826 #define P_270 m , 2 * h+top +1
827 #define R_CENTER m - r, h - r+top, d, d
830 #define DELTA_UR_B 2*(x1 - m), 2*h +top
831 #define DELTA_UR_E 0*16, 90*16 +top // -,
833 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
834 #define DELTA_DR_E 270*16, 90*16 +top // -'
836 #define DELTA_UL_B 2*(x2 - m), 2*h +top
837 #define DELTA_UL_E 90*16, 90*16 +top // ,-
839 #define DELTA_DL_B 2*(x2 - m),2*-h +top
840 #define DELTA_DL_E 180*16, 90*16 // '-
842 #define CENTER_UR x1, 2*h, 225
843 #define CENTER_DR x1, 0 , 135
844 #define CENTER_UL x2, 2*h, 315
845 #define CENTER_DL x2, 0 , 45
848 Gdiplus::Graphics graphics( hdc );
850 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
852 // arc
853 switch (type) {
854 case Lanes::JOIN:
855 case Lanes::JOIN_R:
856 case Lanes::HEAD:
857 case Lanes::HEAD_R:
859 Gdiplus::LinearGradientBrush gradient(
860 Gdiplus::Point(x1-2, h+top-2),
861 Gdiplus::Point(P_270),
862 GetGdiColor(activeColor),GetGdiColor(col));
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-1,top+h-1, x2-x1,laneHeight,270,90);
870 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
872 break;
874 case Lanes::JOIN_L:
877 Gdiplus::LinearGradientBrush gradient(
878 Gdiplus::Point(P_270),
879 Gdiplus::Point(x2+1, h+top-1),
880 GetGdiColor(col),GetGdiColor(activeColor));
883 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
884 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
886 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
887 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
888 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
891 break;
893 case Lanes::TAIL:
894 case Lanes::TAIL_R:
897 Gdiplus::LinearGradientBrush gradient(
898 Gdiplus::Point(x1-2, h+top-2),
899 Gdiplus::Point(P_90),
900 GetGdiColor(activeColor),GetGdiColor(col));
902 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
904 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
906 #if 0
907 QConicalGradient gradient(CENTER_DR);
908 gradient.setColorAt(0.375, activeCol);
909 gradient.setColorAt(0.625, col);
910 myPen.setBrush(gradient);
911 p->setPen(myPen);
912 p->drawArc(P_CENTER, DELTA_DR);
913 #endif
914 break;
916 default:
917 break;
921 //static QPen myPen(Qt::black, 2); // fast path here
922 CPen pen;
923 pen.CreatePen(PS_SOLID,2,col);
924 //myPen.setColor(col);
925 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
927 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
929 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
931 //p->setPen(myPen);
933 // vertical line
934 switch (type) {
935 case Lanes::ACTIVE:
936 case Lanes::NOT_ACTIVE:
937 case Lanes::MERGE_FORK:
938 case Lanes::MERGE_FORK_R:
939 case Lanes::MERGE_FORK_L:
940 case Lanes::JOIN:
941 case Lanes::JOIN_R:
942 case Lanes::JOIN_L:
943 case Lanes::CROSS:
944 //DrawLine(hdc,P_90,P_270);
945 graphics.DrawLine(&myPen,P_90,P_270);
946 //p->drawLine(P_90, P_270);
947 break;
948 case Lanes::HEAD_L:
949 case Lanes::BRANCH:
950 //DrawLine(hdc,P_CENTER,P_270);
951 graphics.DrawLine(&myPen,P_CENTER,P_270);
952 //p->drawLine(P_CENTER, P_270);
953 break;
954 case Lanes::TAIL_L:
955 case Lanes::INITIAL:
956 case Lanes::BOUNDARY:
957 case Lanes::BOUNDARY_C:
958 case Lanes::BOUNDARY_R:
959 case Lanes::BOUNDARY_L:
960 //DrawLine(hdc,P_90, P_CENTER);
961 graphics.DrawLine(&myPen,P_90,P_CENTER);
962 //p->drawLine(P_90, P_CENTER);
963 break;
964 default:
965 break;
968 myPen.SetColor(GetGdiColor(activeColor));
970 // horizontal line
971 switch (type) {
972 case Lanes::MERGE_FORK:
973 case Lanes::JOIN:
974 case Lanes::HEAD:
975 case Lanes::TAIL:
976 case Lanes::CROSS:
977 case Lanes::CROSS_EMPTY:
978 case Lanes::BOUNDARY_C:
979 //DrawLine(hdc,P_180,P_0);
980 graphics.DrawLine(&myPen,P_180,P_0);
981 //p->drawLine(P_180, P_0);
982 break;
983 case Lanes::MERGE_FORK_R:
984 case Lanes::BOUNDARY_R:
985 //DrawLine(hdc,P_180,P_CENTER);
986 graphics.DrawLine(&myPen,P_180,P_CENTER);
987 //p->drawLine(P_180, P_CENTER);
988 break;
989 case Lanes::MERGE_FORK_L:
990 case Lanes::HEAD_L:
991 case Lanes::TAIL_L:
992 case Lanes::BOUNDARY_L:
993 //DrawLine(hdc,P_CENTER,P_0);
994 graphics.DrawLine(&myPen,P_CENTER,P_0);
995 //p->drawLine(P_CENTER, P_0);
996 break;
997 default:
998 break;
1001 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1003 CBrush brush;
1004 brush.CreateSolidBrush(col);
1005 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1007 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1008 // center symbol, e.g. rect or ellipse
1009 switch (type) {
1010 case Lanes::ACTIVE:
1011 case Lanes::INITIAL:
1012 case Lanes::BRANCH:
1014 //p->setPen(Qt::NoPen);
1015 //p->setBrush(col);
1016 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1017 graphics.FillEllipse(&myBrush, R_CENTER);
1018 //p->drawEllipse(R_CENTER);
1019 break;
1020 case Lanes::MERGE_FORK:
1021 case Lanes::MERGE_FORK_R:
1022 case Lanes::MERGE_FORK_L:
1023 //p->setPen(Qt::NoPen);
1024 //p->setBrush(col);
1025 //p->drawRect(R_CENTER);
1026 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1027 graphics.FillRectangle(&myBrush, R_CENTER);
1028 break;
1029 case Lanes::UNAPPLIED:
1030 // Red minus sign
1031 //p->setPen(Qt::NoPen);
1032 //p->setBrush(Qt::red);
1033 //p->drawRect(m - r, h - 1, d, 2);
1034 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1035 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1036 break;
1037 case Lanes::APPLIED:
1038 // Green plus sign
1039 //p->setPen(Qt::NoPen);
1040 //p->setBrush(DARK_GREEN);
1041 //p->drawRect(m - r, h - 1, d, 2);
1042 //p->drawRect(m - 1, h - r, 2, d);
1043 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1044 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1045 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1046 break;
1047 case Lanes::BOUNDARY:
1048 //p->setBrush(back);
1049 //p->drawEllipse(R_CENTER);
1050 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1051 graphics.DrawEllipse(&myPen, R_CENTER);
1052 break;
1053 case Lanes::BOUNDARY_C:
1054 case Lanes::BOUNDARY_R:
1055 case Lanes::BOUNDARY_L:
1056 //p->setBrush(back);
1057 //p->drawRect(R_CENTER);
1058 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1059 graphics.FillRectangle(&myBrush,R_CENTER);
1060 break;
1061 default:
1062 break;
1065 ::SelectObject(hdc,oldpen);
1066 ::SelectObject(hdc,oldbrush);
1067 #undef P_CENTER
1068 #undef P_0
1069 #undef P_90
1070 #undef P_180
1071 #undef P_270
1072 #undef R_CENTER
1075 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1077 // TODO: unfinished
1078 // return;
1079 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1080 if(data->m_CommitHash.IsEmpty())
1081 return;
1083 CRect rt=rect;
1084 LVITEM rItem;
1085 SecureZeroMemory(&rItem, sizeof(LVITEM));
1086 rItem.mask = LVIF_STATE;
1087 rItem.iItem = (int)index;
1088 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1089 GetItem(&rItem);
1091 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1093 if (data->m_Lanes.empty())
1094 m_logEntries.setLane(data->m_CommitHash);
1096 std::vector<int>& lanes=data->m_Lanes;
1097 size_t laneNum = lanes.size();
1098 UINT activeLane = 0;
1099 for (UINT i = 0; i < laneNum; ++i)
1100 if (Lanes::isMerge(lanes[i])) {
1101 activeLane = i;
1102 break;
1105 int x2 = 0;
1106 int maxWidth = rect.Width();
1107 int lw = 3 * rect.Height() / 4; //laneWidth()
1109 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1110 //if (opt.state & QStyle::State_Selected)
1111 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1113 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1116 int x1 = x2;
1117 x2 += lw;
1119 int ln = lanes[i];
1120 if (ln == Lanes::EMPTY)
1121 continue;
1123 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1124 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1127 #if 0
1128 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1130 int x1 = x2;
1131 x2 += lw;
1133 int ln = lanes[i];
1134 if (ln == Lanes::EMPTY)
1135 continue;
1137 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1138 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1140 if (ln == Lanes::CROSS)
1142 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1143 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1145 else
1146 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1148 #endif
1152 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1155 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1156 // Take the default processing unless we set this to something else below.
1157 *pResult = CDRF_DODEFAULT;
1159 if (m_bNoDispUpdates)
1160 return;
1162 switch (pLVCD->nmcd.dwDrawStage)
1164 case CDDS_PREPAINT:
1166 *pResult = CDRF_NOTIFYITEMDRAW;
1167 return;
1169 break;
1170 case CDDS_ITEMPREPAINT:
1172 // This is the prepaint stage for an item. Here's where we set the
1173 // item's text color.
1175 // Tell Windows to send draw notifications for each subitem.
1176 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1178 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1180 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1182 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1183 if (data)
1185 HGDIOBJ hGdiObj = nullptr;
1186 int action = data->GetRebaseAction();
1187 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1188 crText = RGB(128,128,128);
1190 if (action & LOGACTIONS_REBASE_SQUASH)
1191 pLVCD->clrTextBk = RGB(156,156,156);
1192 else if (action & LOGACTIONS_REBASE_EDIT)
1193 pLVCD->clrTextBk = RGB(200,200,128);
1194 else
1195 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1197 if (action & LOGACTIONS_REBASE_CURRENT)
1198 hGdiObj = m_boldFont;
1200 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1201 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1202 if (isHeadHash && isHighlight)
1203 hGdiObj = m_boldItalicsFont;
1204 else if (isHeadHash)
1205 hGdiObj = m_boldFont;
1206 else if (isHighlight)
1207 hGdiObj = m_FontItalics;
1209 if (hGdiObj)
1211 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1212 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1215 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1216 // crText = GetSysColor(COLOR_GRAYTEXT);
1218 if (data->m_CommitHash.IsEmpty())
1220 //crText = GetSysColor(RGB(200,200,0));
1221 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1222 // We changed the font, so we're returning CDRF_NEWFONT. This
1223 // tells the control to recalculate the extent of the text.
1224 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1228 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1230 if (m_bStrictStopped)
1231 crText = GetSysColor(COLOR_GRAYTEXT);
1233 // Store the color back in the NMLVCUSTOMDRAW struct.
1234 pLVCD->clrText = crText;
1235 return;
1237 break;
1238 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1240 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1242 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1245 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1247 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1249 CRect rect;
1250 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1252 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1253 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1255 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1256 if( !data ->m_CommitHash.IsEmpty())
1257 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1259 *pResult = CDRF_SKIPDEFAULT;
1260 return;
1264 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1266 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1268 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1270 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1272 CRect rect;
1273 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1275 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1276 // not in FillBackGround method, because this only affected the message subitem
1277 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1278 return;
1280 int index = (int)pLVCD->nmcd.dwItemSpec;
1281 int state = GetItemState(index, LVIS_SELECTED);
1282 int txtState = LISS_NORMAL;
1283 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1285 if (state & LVIS_SELECTED)
1286 txtState = LISS_HOTSELECTED;
1287 else
1288 txtState = LISS_HOT;
1290 else if (state & LVIS_SELECTED)
1292 if (::GetFocus() == m_hWnd)
1293 txtState = LISS_SELECTED;
1294 else
1295 txtState = LISS_SELECTEDNOTFOCUS;
1298 HTHEME hTheme = nullptr;
1299 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1300 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1302 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1303 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1304 else
1306 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1307 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1308 ::DeleteObject(brush);
1310 if (hTheme)
1312 CRect rt;
1313 // get rect of whole line
1314 GetItemRect(index, rt, LVIR_BOUNDS);
1315 CRect rect2 = rect;
1316 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1317 rect2.DeflateRect(1, 1, 1, 1);
1319 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1320 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1322 CloseThemeData(hTheme);
1324 // END: extended redraw
1326 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1328 std::vector<REFLABEL> refsToShow;
1329 STRING_VECTOR remoteTrackingList;
1330 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1331 for (unsigned int i = 0; i < refList.size(); ++i)
1333 CString str = refList[i];
1335 REFLABEL refLabel;
1336 refLabel.color = RGB(255, 255, 255);
1337 refLabel.singleRemote = false;
1338 refLabel.hasTracking = false;
1339 refLabel.sameName = false;
1340 refLabel.annotatedTag = false;
1341 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1343 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1344 continue;
1345 if (refLabel.name == m_CurrentBranch )
1346 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1347 else
1348 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1350 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1351 CString pullRemote = trackingEntry.first;
1352 CString pullBranch = trackingEntry.second;
1353 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1355 CString defaultUpstream;
1356 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1357 refLabel.hasTracking = true;
1358 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1360 bool found = false;
1361 for (size_t j = i + 1; j < refList.size(); ++j)
1363 if (refList[j] == defaultUpstream)
1365 found = true;
1366 break;
1370 if (found)
1372 bool sameName = pullBranch == refLabel.name;
1373 refsToShow.push_back(refLabel);
1374 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1375 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1376 if (m_bSymbolizeRefNames)
1378 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1380 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1381 refLabel.singleRemote = true;
1383 else if (sameName)
1384 refLabel.simplifiedName = pullRemote + _T("/");
1385 refLabel.sameName = sameName;
1387 refsToShow.push_back(refLabel);
1388 remoteTrackingList.push_back(defaultUpstream);
1389 continue;
1394 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1396 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1397 continue;
1399 bool found = false;
1400 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1402 if (remoteTrackingList[j] == str)
1404 found = true;
1405 break;
1408 if (found)
1409 continue;
1411 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1412 if (m_bSymbolizeRefNames)
1414 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1416 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1417 refLabel.singleRemote = true;
1421 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1423 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1424 continue;
1425 refLabel.color = m_Colors.GetColor(CColors::Tag);
1426 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1428 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1430 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1431 continue;
1432 refLabel.color = m_Colors.GetColor(CColors::Stash);
1433 refLabel.name = _T("stash");
1435 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1437 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1438 continue;
1439 if (refLabel.name.Find(_T("good")) == 0)
1441 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1442 refLabel.name = _T("good");
1444 if (refLabel.name.Find(_T("bad")) == 0)
1446 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1447 refLabel.name = _T("bad");
1450 else
1451 continue;
1453 refsToShow.push_back(refLabel);
1456 if (refsToShow.empty())
1458 *pResult = CDRF_DODEFAULT;
1459 return;
1462 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1464 *pResult = CDRF_SKIPDEFAULT;
1465 return;
1472 if (pLVCD->iSubItem == LOGLIST_ACTION)
1474 if(this->m_IsIDReplaceAction)
1476 *pResult = CDRF_DODEFAULT;
1477 return;
1479 *pResult = CDRF_DODEFAULT;
1481 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1482 return;
1484 int nIcons = 0;
1485 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1486 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1488 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1489 CRect rect;
1490 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1491 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1492 // Get the selected state of the
1493 // item being drawn.
1495 // Fill the background if necessary
1496 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1498 // Draw the icon(s) into the compatible DC
1499 int action = SafeGetAction(pLogEntry);
1501 if (!pLogEntry->m_IsDiffFiles)
1502 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1504 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1505 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1506 ++nIcons;
1508 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1509 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1510 ++nIcons;
1512 if (action & CTGitPath::LOGACTIONS_DELETED)
1513 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1514 ++nIcons;
1516 if (action & CTGitPath::LOGACTIONS_REPLACED)
1517 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1518 ++nIcons;
1519 *pResult = CDRF_SKIPDEFAULT;
1520 return;
1523 break;
1525 *pResult = CDRF_DODEFAULT;
1528 CString FindSVNRev(const CString& msg)
1532 const std::tr1::wsregex_iterator end;
1533 std::wstring s = msg;
1534 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), std::tr1::wregex(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"))); it != end; ++it)
1536 const std::tr1::wsmatch match = *it;
1537 if (match.size() == 4)
1539 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1540 return std::wstring(match[2]).c_str();
1543 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), std::tr1::wregex(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+"))); it != end; ++it)
1545 const std::tr1::wsmatch match = *it;
1546 if (match.size() == 3)
1548 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1549 return std::wstring(match[1]).c_str();
1553 catch (std::exception) {}
1555 return _T("");
1558 // CGitLogListBase message handlers
1560 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1562 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1564 // Create a pointer to the item
1565 LV_ITEM* pItem = &(pDispInfo)->item;
1567 // Do the list need text information?
1568 if (!(pItem->mask & LVIF_TEXT))
1569 return;
1571 // By default, clear text buffer.
1572 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1574 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1576 *pResult = 0;
1577 if (m_bNoDispUpdates || bOutOfRange)
1578 return;
1580 // Which item number?
1581 int itemid = pItem->iItem;
1582 GitRev * pLogEntry = NULL;
1583 if (itemid < m_arShownList.GetCount())
1584 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1586 CString temp;
1587 if(m_IsOldFirst)
1589 temp.Format(_T("%d"),pItem->iItem+1);
1592 else
1594 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1597 // Which column?
1598 switch (pItem->iSubItem)
1600 case this->LOGLIST_GRAPH: //Graphic
1601 break;
1602 case this->LOGLIST_REBASE:
1604 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1605 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax);
1607 break;
1608 case this->LOGLIST_ACTION: //action -- no text in the column
1609 break;
1610 case this->LOGLIST_HASH:
1611 if(pLogEntry)
1612 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1613 break;
1614 case this->LOGLIST_ID:
1615 if(this->m_IsIDReplaceAction)
1616 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1617 break;
1618 case this->LOGLIST_MESSAGE: //Message
1619 if (pLogEntry)
1620 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1621 break;
1622 case this->LOGLIST_AUTHOR: //Author
1623 if (pLogEntry)
1624 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1625 break;
1626 case this->LOGLIST_DATE: //Date
1627 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1628 lstrcpyn(pItem->pszText,
1629 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1630 pItem->cchTextMax);
1631 break;
1633 case this->LOGLIST_EMAIL:
1634 if (pLogEntry)
1635 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1636 break;
1638 case this->LOGLIST_COMMIT_NAME: //Commit
1639 if (pLogEntry)
1640 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1641 break;
1643 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1644 if (pLogEntry)
1645 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1646 break;
1648 case this->LOGLIST_COMMIT_DATE: //Commit Date
1649 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1650 lstrcpyn(pItem->pszText,
1651 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1652 pItem->cchTextMax);
1653 break;
1654 case this->LOGLIST_BUG: //Bug ID
1655 if(pLogEntry)
1656 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1657 break;
1658 case this->LOGLIST_SVNREV: //SVN revision
1659 if (pLogEntry)
1660 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1661 break;
1663 default:
1664 ASSERT(false);
1668 bool CGitLogListBase::IsOnStash(int index)
1670 GitRev *rev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index));
1671 if (IsStash(rev))
1672 return true;
1673 if (index > 0)
1675 GitRev *preRev = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1));
1676 if (IsStash(preRev))
1677 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1679 return false;
1682 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1684 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1686 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1687 return true;
1689 return false;
1692 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1694 if (pRev->m_ParentHash.empty())
1698 pRev->GetParentFromHash(pRev->m_CommitHash);
1700 catch (const char* msg)
1702 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1705 parentHash = pRev->m_ParentHash;
1708 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1711 if (pWnd == GetHeaderCtrl())
1713 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1716 int selIndex = GetSelectionMark();
1717 if (selIndex < 0)
1718 return; // nothing selected, nothing to do with a context menu
1720 // if the user selected the info text telling about not all revisions shown due to
1721 // the "stop on copy/rename" option, we also don't show the context menu
1722 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1723 return;
1725 // if the context menu is invoked through the keyboard, we have to use
1726 // a calculated position on where to anchor the menu on
1727 if ((point.x == -1) && (point.y == -1))
1729 CRect rect;
1730 GetItemRect(selIndex, &rect, LVIR_LABEL);
1731 ClientToScreen(&rect);
1732 point = rect.CenterPoint();
1734 m_nSearchIndex = selIndex;
1735 m_bCancelled = FALSE;
1737 // calculate some information the context menu commands can use
1738 // CString pathURL = GetURLFromPath(m_path);
1740 POSITION pos = GetFirstSelectedItemPosition();
1741 int indexNext = GetNextSelectedItem(pos);
1742 if (indexNext < 0)
1743 return;
1745 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1746 if (pSelLogEntry == nullptr)
1747 return;
1748 #if 0
1749 GitRev revSelected = pSelLogEntry->Rev;
1750 GitRev revPrevious = git_revnum_t(revSelected)-1;
1751 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1753 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1755 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1756 if (changedpath->lCopyFromRev)
1757 revPrevious = changedpath->lCopyFromRev;
1760 GitRev revSelected2;
1761 if (pos)
1763 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1764 revSelected2 = pLogEntry->Rev;
1766 bool bAllFromTheSameAuthor = true;
1767 CString firstAuthor;
1768 CLogDataVector selEntries;
1769 GitRev revLowest, revHighest;
1770 GitRevRangeArray revisionRanges;
1772 POSITION pos = GetFirstSelectedItemPosition();
1773 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1774 revisionRanges.AddRevision(pLogEntry->Rev);
1775 selEntries.push_back(pLogEntry);
1776 firstAuthor = pLogEntry->sAuthor;
1777 revLowest = pLogEntry->Rev;
1778 revHighest = pLogEntry->Rev;
1779 while (pos)
1781 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1782 revisionRanges.AddRevision(pLogEntry->Rev);
1783 selEntries.push_back(pLogEntry);
1784 if (firstAuthor.Compare(pLogEntry->sAuthor))
1785 bAllFromTheSameAuthor = false;
1786 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1787 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1791 #endif
1793 int FirstSelect=-1, LastSelect=-1;
1794 pos = GetFirstSelectedItemPosition();
1795 FirstSelect = GetNextSelectedItem(pos);
1796 while(pos)
1798 LastSelect = GetNextSelectedItem(pos);
1800 //entry is selected, now show the popup menu
1801 CIconMenu popup;
1802 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1804 if (popup.CreatePopupMenu())
1806 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1807 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1808 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1809 bool isStash = IsOnStash(indexNext);
1810 GIT_REV_LIST parentHash;
1811 GetParentHashes(pSelLogEntry, parentHash);
1813 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1814 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1816 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1817 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1819 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1820 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1822 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1823 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1825 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)))
1826 popup.AppendMenu(MF_SEPARATOR, NULL);
1828 if (GetSelectedCount() == 1)
1831 bool requiresSeparator = false;
1832 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1834 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1836 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1837 requiresSeparator = true;
1840 else
1842 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1844 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1845 requiresSeparator = true;
1847 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1849 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1850 requiresSeparator = true;
1854 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1856 if (parentHash.size() == 1)
1858 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1859 requiresSeparator = true;
1861 else if (parentHash.size() > 1)
1863 blamemenu.CreatePopupMenu();
1864 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1865 for (size_t i = 0; i < parentHash.size(); ++i)
1867 CString str;
1868 str.Format(IDS_PARENT, i + 1);
1869 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1871 requiresSeparator = true;
1875 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1877 if (parentHash.size() == 1)
1879 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1880 requiresSeparator = true;
1882 else if (parentHash.size() > 1)
1884 gnudiffmenu.CreatePopupMenu();
1885 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1887 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1888 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1890 for (size_t i = 0; i < parentHash.size(); ++i)
1892 CString str;
1893 str.Format(IDS_PARENT, i + 1);
1894 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1896 requiresSeparator = true;
1900 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1902 if (parentHash.size() == 1)
1904 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1905 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1906 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1907 requiresSeparator = true;
1909 else if (parentHash.size() > 1)
1911 diffmenu.CreatePopupMenu();
1912 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1913 for (size_t i = 0; i < parentHash.size(); ++i)
1915 CString str;
1916 str.Format(IDS_PARENT, i + 1);
1917 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1918 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1920 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1921 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1924 requiresSeparator = true;
1928 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1930 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1931 requiresSeparator = true;
1934 if (requiresSeparator)
1935 popup.AppendMenu(MF_SEPARATOR, NULL);
1937 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1939 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1940 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1943 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1945 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1946 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1948 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1949 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1951 popup.AppendMenu(MF_SEPARATOR, NULL);
1954 if (pSelLogEntry->m_CommitHash.IsEmpty())
1956 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1957 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1959 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1960 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1962 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
1963 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
1965 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1966 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
1968 popup.AppendMenu(MF_SEPARATOR, NULL);
1972 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1973 // {
1974 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1975 // }
1976 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1977 // {
1978 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1979 // }
1980 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1981 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1982 // {
1983 // popup.AppendMenu(MF_SEPARATOR, NULL);
1984 // }
1986 CString str,format;
1987 //if (m_hasWC)
1988 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1990 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1992 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1993 GetSelectedCount() == 1)
1994 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1996 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1997 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1999 format.LoadString(IDS_LOG_POPUP_MERGEREV);
2000 str.Format(format,g_Git.GetCurrentBranch());
2002 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2003 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2005 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
2006 str.Format(format,g_Git.GetCurrentBranch());
2008 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2009 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2012 // Add Switch Branch express Menu
2013 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2014 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2017 std::vector<CString *> branchs;
2018 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2020 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2021 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2023 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2027 CString str;
2028 str.LoadString(IDS_SWITCH_BRANCH);
2030 if(branchs.size() == 1)
2032 str+=_T(" ");
2033 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
2034 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
2036 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2039 else if(branchs.size() > 1)
2041 subbranchmenu.CreatePopupMenu();
2042 for (size_t i = 0 ; i < branchs.size(); ++i)
2044 if (*branchs[i] != currentBranch)
2046 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2047 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2051 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
2055 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2056 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2058 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2059 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2061 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2062 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2064 format.LoadString(IDS_REBASE_THIS_FORMAT);
2065 str.Format(format,g_Git.GetCurrentBranch());
2067 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2068 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2069 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2071 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2072 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2074 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2076 if (parentHash.size() == 1)
2078 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2080 else if (parentHash.size() > 1)
2082 revertmenu.CreatePopupMenu();
2083 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2085 for (size_t i = 0; i < parentHash.size(); ++i)
2087 CString str;
2088 str.Format(IDS_PARENT, i + 1);
2089 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
2094 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2095 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2097 popup.AppendMenu(MF_SEPARATOR, NULL);
2102 if(!pSelLogEntry->m_Ref.IsEmpty())
2104 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2105 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2106 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2107 popup.AppendMenu(MF_SEPARATOR, NULL);
2110 if (GetSelectedCount() >= 2)
2112 bool bAddSeparator = false;
2113 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2115 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2116 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2119 if (GetSelectedCount() == 2)
2121 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2122 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2124 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2126 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2127 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2128 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2129 CString menu;
2130 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
2131 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2132 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
2133 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2136 bAddSeparator = true;
2139 if (m_hasWC)
2141 bAddSeparator = true;
2144 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2145 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2147 if (bAddSeparator)
2148 popup.AppendMenu(MF_SEPARATOR, NULL);
2151 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2153 bool bAddSeparator = false;
2154 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2156 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2158 CString head;
2159 int headindex;
2160 headindex = this->GetHeadIndex();
2161 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2163 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2164 CGitHash hashFirst;
2165 if (g_Git.GetHash(hashFirst, head))
2166 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2167 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2168 CGitHash hash;
2169 if (g_Git.GetHash(hash, head))
2170 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2171 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect));
2172 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2173 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2174 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2175 bAddSeparator = true;
2180 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2181 if (GetSelectedCount() >= 2)
2182 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2183 else
2184 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2185 bAddSeparator = true;
2188 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2189 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2190 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2191 bAddSeparator = true;
2194 if (bAddSeparator)
2195 popup.AppendMenu(MF_SEPARATOR, NULL);
2198 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())
2200 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2201 popup.AppendMenu(MF_SEPARATOR, NULL);
2204 if (GetSelectedCount() == 1)
2206 bool bAddSeparator = false;
2207 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2209 // show the push-option only if the log entry has an associated local branch
2210 bool isLocal = false;
2211 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2213 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2214 isLocal = true;
2216 if (isLocal)
2218 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2219 bAddSeparator = true;
2222 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2224 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2225 bAddSeparator = true;
2229 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2231 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2233 std::vector<CString *> branchs;
2234 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2236 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2237 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2239 CString str;
2240 if (branchs.size() == 1)
2242 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2243 str+=_T(" ");
2244 str += *branchs[0];
2245 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2246 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2247 bAddSeparator = true;
2249 else if (branchs.size() > 1)
2251 str.LoadString(IDS_DELETE_BRANCHTAG);
2252 submenu.CreatePopupMenu();
2253 for (size_t i = 0; i < branchs.size(); ++i)
2255 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2256 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2259 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2260 bAddSeparator = true;
2263 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2264 if (bAddSeparator)
2265 popup.AppendMenu(MF_SEPARATOR, NULL);
2266 } // GetSelectedCount() == 1
2268 if (GetSelectedCount() != 0)
2270 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2271 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2272 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2273 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2274 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2275 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2278 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2279 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2281 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2282 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2284 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2285 // DialogEnableWindow(IDOK, FALSE);
2286 // SetPromptApp(&theApp);
2288 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2290 // EnableOKButton();
2291 } // if (popup.CreatePopupMenu())
2295 bool CGitLogListBase::IsSelectionContinuous()
2297 if ( GetSelectedCount()==1 )
2299 // if only one revision is selected, the selection is of course
2300 // continuous
2301 return true;
2304 POSITION pos = GetFirstSelectedItemPosition();
2305 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2306 if (bContinuous)
2308 int itemindex = GetNextSelectedItem(pos);
2309 while (pos)
2311 int nextindex = GetNextSelectedItem(pos);
2312 if (nextindex - itemindex > 1)
2314 bContinuous = false;
2315 break;
2317 itemindex = nextindex;
2320 return bContinuous;
2323 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2326 CString sClipdata;
2327 POSITION pos = GetFirstSelectedItemPosition();
2328 if (pos != NULL)
2330 CString sRev;
2331 sRev.LoadString(IDS_LOG_REVISION);
2332 CString sAuthor;
2333 sAuthor.LoadString(IDS_LOG_AUTHOR);
2334 CString sDate;
2335 sDate.LoadString(IDS_LOG_DATE);
2336 CString sMessage;
2337 sMessage.LoadString(IDS_LOG_MESSAGE);
2338 bool first = true;
2339 while (pos)
2341 CString sLogCopyText;
2342 CString sPaths;
2343 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2345 if (toCopy == ID_COPY_ALL)
2347 //pLogEntry->GetFiles(this)
2348 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2350 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2351 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2353 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2354 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2356 CString rename;
2357 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2358 sPaths += _T(" ") + rename;
2360 sPaths += _T("\r\n");
2362 sPaths.Trim();
2363 CString body = pLogEntry->GetBody();
2364 body.Replace(_T("\n"), _T("\r\n"));
2365 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"),
2366 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2367 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2368 (LPCTSTR)sDate,
2369 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2370 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2371 (LPCTSTR)sPaths);
2372 sClipdata += sLogCopyText;
2374 else if (toCopy == ID_COPY_MESSAGE)
2376 CString body = pLogEntry->GetBody();
2377 body.Replace(_T("\n"), _T("\r\n"));
2378 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2380 else if (toCopy == ID_COPY_SUBJECT)
2382 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2384 else
2386 if (!first)
2387 sClipdata += _T("\r\n");
2388 sClipdata += pLogEntry->m_CommitHash;
2391 first = false;
2393 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2398 void CGitLogListBase::DiffSelectedRevWithPrevious()
2400 if (m_bThreadRunning)
2401 return;
2403 int FirstSelect=-1, LastSelect=-1;
2404 POSITION pos = GetFirstSelectedItemPosition();
2405 FirstSelect = GetNextSelectedItem(pos);
2406 while(pos)
2408 LastSelect = GetNextSelectedItem(pos);
2411 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2413 #if 0
2414 UpdateLogInfoLabel();
2415 int selIndex = m_LogList.GetSelectionMark();
2416 if (selIndex < 0)
2417 return;
2418 int selCount = m_LogList.GetSelectedCount();
2419 if (selCount != 1)
2420 return;
2422 // Find selected entry in the log list
2423 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2424 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2425 long rev1 = pLogEntry->Rev;
2426 long rev2 = rev1-1;
2427 CTGitPath path = m_path;
2429 // See how many files under the relative root were changed in selected revision
2430 int nChanged = 0;
2431 LogChangedPath * changed = NULL;
2432 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2434 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2435 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2437 ++nChanged;
2438 changed = cpath;
2442 if (m_path.IsDirectory() && nChanged == 1)
2444 // We're looking at the log for a directory and only one file under dir was changed in the revision
2445 // Do diff on that file instead of whole directory
2446 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2449 m_bCancelled = FALSE;
2450 DialogEnableWindow(IDOK, FALSE);
2451 SetPromptApp(&theApp);
2452 theApp.DoWaitCursor(1);
2454 if (PromptShown())
2456 GitDiff diff(this, m_hWnd, true);
2457 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2458 diff.SetHEADPeg(m_LogRevision);
2459 diff.ShowCompare(path, rev2, path, rev1);
2461 else
2463 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2466 theApp.DoWaitCursor(-1);
2467 EnableOKButton();
2468 #endif
2471 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2473 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2474 *pResult = -1;
2476 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2477 return;
2478 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2479 return;
2480 if (pFindInfo->lvfi.psz == 0)
2481 return;
2482 #if 0
2483 CString sCmp = pFindInfo->lvfi.psz;
2484 CString sRev;
2485 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2487 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2488 sRev.Format(_T("%ld"), pLogEntry->Rev);
2489 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2491 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2493 *pResult = i;
2494 return;
2497 else
2499 if (sCmp.Compare(sRev)==0)
2501 *pResult = i;
2502 return;
2506 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2508 for (int i=0; i<pFindInfo->iStart; ++i)
2510 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2511 sRev.Format(_T("%ld"), pLogEntry->Rev);
2512 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2514 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2516 *pResult = i;
2517 return;
2520 else
2522 if (sCmp.Compare(sRev)==0)
2524 *pResult = i;
2525 return;
2530 #endif
2531 *pResult = -1;
2534 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2536 ClearText();
2538 this->m_arShownList.SafeRemoveAll();
2540 this->m_logEntries.ClearAll();
2541 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2542 return -1;
2544 //this->m_logEntries.ParserFromLog();
2545 SetItemCountEx((int)m_logEntries.size());
2547 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2549 if(m_IsOldFirst)
2551 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2552 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2555 else
2557 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2558 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2562 ReloadHashMap();
2564 if(path)
2565 m_Path=*path;
2566 return 0;
2570 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2572 ClearText();
2574 m_arShownList.SafeRemoveAll();
2576 m_logEntries.ClearAll();
2577 if (m_logEntries.Fill(hashes))
2578 return -1;
2580 SetItemCountEx((int)m_logEntries.size());
2582 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2584 if (m_IsOldFirst)
2586 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2587 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2589 else
2591 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2592 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2596 ReloadHashMap();
2598 return 0;
2601 int CGitLogListBase::BeginFetchLog()
2603 ClearText();
2605 this->m_arShownList.SafeRemoveAll();
2607 this->m_logEntries.ClearAll();
2609 this->m_LogCache.ClearAllParent();
2611 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2613 CTGitPath *path;
2614 if(this->m_Path.IsEmpty())
2615 path=NULL;
2616 else
2617 path=&this->m_Path;
2619 int mask;
2620 mask = CGit::LOG_INFO_ONLY_HASH;
2621 if (m_bIncludeBoundaryCommits)
2622 mask |= CGit::LOG_INFO_BOUNDARY;
2623 // if(this->m_bAllBranch)
2624 mask |= m_ShowMask ;
2626 if(m_bShowWC)
2628 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2629 ResetWcRev();
2630 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2633 if (m_sRange.IsEmpty())
2634 m_sRange = _T("HEAD");
2636 CFilterData data;
2637 data.m_From = m_From;
2638 data.m_To =m_To;
2640 #if 0 /* use tortoiegit filter */
2641 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2642 data.m_Author = this->m_sFilterText;
2644 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2645 data.m_MessageFilter = this->m_sFilterText;
2647 data.m_IsRegex = m_bFilterWithRegex;
2648 #endif
2650 // follow does not work for directories
2651 if (!path || path->IsDirectory())
2652 mask &= ~CGit::LOG_INFO_FOLLOW;
2653 // follow does not work with all branches 8at least in TGit)
2654 if (mask & CGit::LOG_INFO_FOLLOW)
2655 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2657 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2659 //this->m_logEntries.ParserFromLog();
2660 if(IsInWorkingThread())
2662 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2664 else
2666 SetItemCountEx((int)m_logEntries.size());
2671 [] { git_init(); } ();
2673 catch (char* msg)
2675 CString err(msg);
2676 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2677 return -1;
2680 if (!g_Git.CanParseRev(m_sRange))
2682 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2683 return 0;
2685 // if show all branches, pick any ref as dummy entry ref
2686 STRING_VECTOR list;
2687 if (g_Git.GetRefList(list))
2688 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2689 if (list.size() == 0)
2690 return 0;
2692 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2695 g_Git.m_critGitDllSec.Lock();
2696 try {
2697 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2699 g_Git.m_critGitDllSec.Unlock();
2700 return -1;
2703 catch (char* msg)
2705 g_Git.m_critGitDllSec.Unlock();
2706 CString err(msg);
2707 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2708 return -1;
2710 g_Git.m_critGitDllSec.Unlock();
2712 return 0;
2715 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2717 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2719 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2721 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2723 DiffSelectedRevWithPrevious();
2724 return TRUE;
2727 #if 0
2728 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2730 DiffSelectedFile();
2731 return TRUE;
2733 #endif
2735 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2737 // select all entries
2738 for (int i=0; i<GetItemCount(); ++i)
2740 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2742 return TRUE;
2745 #if 0
2746 if (m_hAccel && !bSkipAccelerator)
2748 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2749 if (ret)
2750 return TRUE;
2753 #endif
2754 //m_tooltips.RelayEvent(pMsg);
2755 return __super::PreTranslateMessage(pMsg);
2758 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2760 // a double click on an entry in the revision list has happened
2761 *pResult = 0;
2763 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2764 DiffSelectedRevWithPrevious();
2767 int CGitLogListBase::FetchLogAsync(void * data)
2769 ReloadHashMap();
2770 m_ProcData=data;
2771 m_bExitThread=FALSE;
2772 InterlockedExchange(&m_bThreadRunning, TRUE);
2773 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2774 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2775 if (m_LoadingThread ==NULL)
2777 InterlockedExchange(&m_bThreadRunning, FALSE);
2778 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2779 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2780 return -1;
2782 return 0;
2785 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2787 return ((CGitLogListBase*)pVoid)->LogThread();
2790 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2792 //CTime time;
2793 oldest=CTime::GetCurrentTime();
2794 latest=CTime(1971,1,2,0,0,0);
2795 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2797 if(m_logEntries[i].IsEmpty())
2798 continue;
2800 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2801 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2803 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2804 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2808 if(latest<oldest)
2809 latest=oldest;
2812 UINT CGitLogListBase::LogThread()
2814 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2816 InterlockedExchange(&m_bThreadRunning, TRUE);
2817 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2819 ULONGLONG t1,t2;
2821 if(BeginFetchLog())
2823 InterlockedExchange(&m_bThreadRunning, FALSE);
2824 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2826 return 1;
2829 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2830 bool bRegex = false;
2831 if (m_bFilterWithRegex)
2832 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2834 TRACE(_T("\n===Begin===\n"));
2835 //Update work copy item;
2837 if (!m_logEntries.empty())
2839 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2841 m_arShownList.SafeAdd(pRev);
2845 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2847 // store commit number of the last selected commit/line before the refresh or -1
2848 int lastSelectedHashNItem = -1;
2849 int ret = 0;
2851 bool shouldWalk = true;
2852 if (!g_Git.CanParseRev(m_sRange))
2854 // walk revisions if show all branches and there exists any ref
2855 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2856 shouldWalk = false;
2857 else
2859 STRING_VECTOR list;
2860 if (g_Git.GetRefList(list))
2861 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2862 if (list.size() == 0)
2863 shouldWalk = false;
2867 if (shouldWalk)
2869 g_Git.m_critGitDllSec.Lock();
2870 int total = 0;
2873 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2874 total = git_get_log_estimate_commit_count(m_DllGitLog);
2876 catch (char* msg)
2878 CString err(msg);
2879 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2880 ret = -1;
2882 g_Git.m_critGitDllSec.Unlock();
2884 GIT_COMMIT commit;
2885 t2=t1=GetTickCount();
2886 int oldprecentage = 0;
2887 size_t oldsize = m_logEntries.size();
2888 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2889 while (ret== 0 && !m_bExitThread)
2891 g_Git.m_critGitDllSec.Lock();
2894 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2896 catch (char* msg)
2898 g_Git.m_critGitDllSec.Unlock();
2899 CString err(msg);
2900 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2901 break;
2903 g_Git.m_critGitDllSec.Unlock();
2905 if(ret)
2907 if (ret != -2) // other than end of revision walking
2908 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2909 break;
2912 if (commit.m_ignore == 1)
2914 git_free_commit(&commit);
2915 continue;
2918 //printf("%s\r\n",commit.GetSubject());
2919 if(m_bExitThread)
2920 break;
2922 CGitHash hash = (char*)commit.m_hash ;
2924 GitRev *pRev = m_LogCache.GetCacheData(hash);
2925 pRev->m_GitCommit = commit;
2926 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2928 char *note=NULL;
2929 g_Git.m_critGitDllSec.Lock();
2932 git_get_notes(commit.m_hash, &note);
2934 catch (char* msg)
2936 g_Git.m_critGitDllSec.Unlock();
2937 CString err(msg);
2938 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2939 break;
2941 g_Git.m_critGitDllSec.Unlock();
2943 if(note)
2945 pRev->m_Notes.Empty();
2946 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2947 free(note);
2948 note = nullptr;
2951 if(!pRev->m_IsDiffFiles)
2953 pRev->m_CallDiffAsync = DiffAsync;
2956 pRev->ParserParentFromCommit(&commit);
2957 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2959 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2961 const CGitHash &parentHash = pRev->m_ParentHash[i];
2962 auto it = commitChildren.find(parentHash);
2963 if (it == commitChildren.end())
2965 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2967 it->second.insert(pRev->m_CommitHash);
2971 #ifdef DEBUG
2972 pRev->DbgPrint();
2973 TRACE(_T("\n"));
2974 #endif
2976 bool visible = true;
2977 if (HasFilterText())
2979 if(!IsMatchFilter(bRegex,pRev,pat))
2980 visible = false;
2982 if (visible && !ShouldShowFilter(pRev, commitChildren))
2983 visible = false;
2984 this->m_critSec.Lock();
2985 m_logEntries.append(hash, visible);
2986 if (visible)
2987 m_arShownList.SafeAdd(pRev);
2988 this->m_critSec.Unlock();
2990 if (!visible)
2991 continue;
2993 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2994 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2996 t2=GetTickCount();
2998 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3000 //update UI
3001 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3002 if(percent > 99)
3003 percent =99;
3004 if(percent < GITLOG_START)
3005 percent = GITLOG_START +1;
3007 oldsize = m_logEntries.size();
3008 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3010 //if( percent > oldprecentage )
3012 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3013 oldprecentage = percent;
3016 if (lastSelectedHashNItem >= 0)
3017 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3019 t1 = t2;
3022 g_Git.m_critGitDllSec.Lock();
3023 git_close_log(m_DllGitLog);
3024 g_Git.m_critGitDllSec.Unlock();
3028 if (m_bExitThread)
3030 InterlockedExchange(&m_bThreadRunning, FALSE);
3031 return 0;
3034 //Update UI;
3035 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3037 if (lastSelectedHashNItem >= 0)
3038 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3040 if (this->m_hWnd)
3041 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3043 InterlockedExchange(&m_bThreadRunning, FALSE);
3045 return 0;
3048 void CGitLogListBase::FetchRemoteList()
3050 STRING_VECTOR remoteList;
3051 if (!g_Git.GetRemoteList(remoteList))
3052 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
3053 else
3054 m_SingleRemote = _T("");
3057 void CGitLogListBase::FetchTrackingBranchList()
3059 m_TrackingMap.clear();
3060 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3062 for (size_t j = 0; j < it->second.size(); ++j)
3064 CString branchName;
3065 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3067 CString pullRemote, pullBranch;
3068 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3069 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3071 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3078 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3080 SafeTerminateThread();
3082 this->SetItemCountEx(0);
3083 this->Clear();
3085 ResetWcRev();
3087 // HACK to hide graph column
3088 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3089 SetColumnWidth(0, 0);
3090 else
3091 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3093 //Update branch and Tag info
3094 ReloadHashMap();
3095 if (m_pFindDialog)
3096 m_pFindDialog->RefreshList();
3097 //Assume Thread have exited
3098 //if(!m_bThreadRunning)
3100 m_logEntries.clear();
3102 if(IsCleanFilter)
3104 m_sFilterText.Empty();
3105 m_From=-1;
3106 m_To=-1;
3109 InterlockedExchange(&m_bExitThread,FALSE);
3111 InterlockedExchange(&m_bThreadRunning, TRUE);
3112 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3113 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3115 InterlockedExchange(&m_bThreadRunning, FALSE);
3116 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3117 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3121 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3125 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3126 if (!bMatchCase)
3127 type |= std::tr1::regex_constants::icase;
3128 pat = std::tr1::wregex(regexp_str, type);
3129 return true;
3131 catch (std::exception) {}
3132 return false;
3134 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
3136 BOOL result = TRUE;
3137 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3138 CString sRev;
3140 if ((bRegex)&&(m_bFilterWithRegex))
3142 if (m_SelectedFilters & LOGFILTER_BUGID)
3144 if(this->m_bShowBugtraqColumn)
3146 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3148 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
3149 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3151 return TRUE;
3156 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3158 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
3159 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3161 return TRUE;
3165 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3167 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
3168 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3170 return TRUE;
3174 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3176 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3178 return TRUE;
3181 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3183 return TRUE;
3187 if (m_SelectedFilters & LOGFILTER_EMAILS)
3189 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3191 return TRUE;
3194 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3196 return TRUE;
3200 if (m_SelectedFilters & LOGFILTER_REVS)
3202 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3203 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3205 return TRUE;
3209 if (m_SelectedFilters & LOGFILTER_REFNAME)
3211 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3212 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3214 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3216 return TRUE;
3221 if (m_SelectedFilters & LOGFILTER_PATHS)
3223 CTGitPathList *pathList=NULL;
3224 if( pRev->m_IsDiffFiles)
3225 pathList = &pRev->GetFiles(this);
3226 else
3228 if(!pRev->m_IsSimpleListReady)
3229 pRev->SafeGetSimpleList(&g_Git);
3232 if(pathList)
3233 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3235 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3237 return true;
3239 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3241 return true;
3245 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3247 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3249 return true;
3254 else
3256 CString find = m_sFilterText;
3257 if (!m_bFilterCaseSensitively)
3258 find.MakeLower();
3259 result = find[0] == '!' ? FALSE : TRUE;
3260 if (!result)
3261 find = find.Mid(1);
3263 if (m_SelectedFilters & LOGFILTER_BUGID)
3265 if(this->m_bShowBugtraqColumn)
3267 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3269 if (!m_bFilterCaseSensitively)
3270 sBugIds.MakeLower();
3271 if ((sBugIds.Find(find) >= 0))
3273 return result;
3278 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3280 CString msg = pRev->GetSubject();
3282 if (!m_bFilterCaseSensitively)
3283 msg = msg.MakeLower();
3284 if ((msg.Find(find) >= 0))
3286 return result;
3290 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3292 CString msg = pRev->GetBody();
3294 if (!m_bFilterCaseSensitively)
3295 msg = msg.MakeLower();
3296 if ((msg.Find(find) >= 0))
3298 return result;
3302 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3304 CString msg = pRev->GetAuthorName();
3305 if (!m_bFilterCaseSensitively)
3306 msg = msg.MakeLower();
3307 if ((msg.Find(find) >= 0))
3309 return result;
3313 if (m_SelectedFilters & LOGFILTER_EMAILS)
3315 CString msg = pRev->GetAuthorEmail();
3316 if (!m_bFilterCaseSensitively)
3317 msg = msg.MakeLower();
3318 if ((msg.Find(find) >= 0))
3320 return result;
3324 if (m_SelectedFilters & LOGFILTER_REVS)
3326 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3327 if ((sRev.Find(find) >= 0))
3329 return result;
3333 if (m_SelectedFilters & LOGFILTER_REFNAME)
3335 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3336 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3338 if (it->Find(find) >= 0)
3340 return result;
3345 if (m_SelectedFilters & LOGFILTER_PATHS)
3347 CTGitPathList *pathList=NULL;
3348 if( pRev->m_IsDiffFiles)
3349 pathList = &pRev->GetFiles(this);
3350 else
3352 if(!pRev->m_IsSimpleListReady)
3353 pRev->SafeGetSimpleList(&g_Git);
3355 if(pathList)
3356 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3358 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3359 CString path = cpath->GetGitOldPathString();
3360 if (!m_bFilterCaseSensitively)
3361 path.MakeLower();
3362 if ((path.Find(find)>=0))
3364 return result;
3366 path = cpath->GetGitPathString();
3367 if (!m_bFilterCaseSensitively)
3368 path.MakeLower();
3369 if ((path.Find(find)>=0))
3371 return result;
3375 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3377 CString path = pRev->m_SimpleFileList[i];
3378 if (!m_bFilterCaseSensitively)
3379 path.MakeLower();
3380 if ((path.Find(find)>=0))
3382 return result;
3386 } // else (from if (bRegex))
3387 return !result;
3390 static bool CStringStartsWith(const CString &str, const CString &prefix)
3392 return str.Left(prefix.GetLength()) == prefix;
3394 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3396 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3397 return true;
3399 if (m_ShowFilter & FILTERSHOW_REFS)
3401 // Keep all refs.
3402 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3403 for (size_t i = 0; i < refList.size(); ++i)
3405 const CString &str = refList[i];
3406 if (CStringStartsWith(str, _T("refs/heads/")))
3408 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3409 return true;
3411 else if (CStringStartsWith(str, _T("refs/remotes/")))
3413 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3414 return true;
3416 else if (CStringStartsWith(str, _T("refs/tags/")))
3418 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3419 return true;
3421 else if (CStringStartsWith(str, _T("refs/stash")))
3423 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3424 return true;
3426 else if (CStringStartsWith(str, _T("refs/bisect/")))
3428 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3429 return true;
3432 // Keep the head too.
3433 if (pRev->m_CommitHash == m_HeadHash)
3434 return true;
3437 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3439 if (pRev->ParentsCount() > 1)
3440 return true;
3441 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3442 if (childrenIt != commitChildren.end())
3444 const std::set<CGitHash> &children = childrenIt->second;
3445 if (children.size() > 1)
3446 return true;
3449 return false;
3452 void CGitLogListBase::ShowGraphColumn(bool bShow)
3454 // HACK to hide graph column
3455 if (bShow)
3456 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3457 else
3458 SetColumnWidth(0, 0);
3461 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3463 CString cmd;
3464 CString output;
3466 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3468 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3469 for (size_t i = 0; i < vector.size(); ++i)
3471 if (vector[i].Find(_T("refs/tags/")) == 0)
3473 CString tag = vector[i];
3474 int start = vector[i].Find(_T("^{}"));
3475 if (start > 0)
3476 tag = tag.Left(start);
3477 else
3478 continue;
3480 cmd.Format(_T("git.exe cat-file tag %s"), tag);
3481 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3482 output.AppendChar(_T('\n'));
3487 return output;
3490 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3493 pShownlist->SafeRemoveAll();
3495 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3496 bool bRegex = false;
3497 if (m_bFilterWithRegex)
3498 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3500 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3501 CString sRev;
3502 for (DWORD i=0; i<m_logEntries.size(); ++i)
3504 if ((bRegex)&&(m_bFilterWithRegex))
3506 #if 0
3507 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3509 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3510 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3512 pShownlist->SafeAdd(m_logEntries[i]);
3513 continue;
3516 #endif
3517 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3519 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3520 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3522 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3523 continue;
3526 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3528 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3529 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3531 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3532 continue;
3535 if (m_SelectedFilters & LOGFILTER_PATHS)
3537 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3539 bool bGoing = true;
3540 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3542 CTGitPath cpath = pathList[cpPathIndex];
3543 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3545 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3546 bGoing = false;
3547 continue;
3549 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3551 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3552 bGoing = false;
3553 continue;
3555 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3557 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3558 bGoing = false;
3559 continue;
3563 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3565 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3567 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3568 continue;
3571 if (m_SelectedFilters & LOGFILTER_EMAILS)
3573 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3575 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3576 continue;
3579 if (m_SelectedFilters & LOGFILTER_REVS)
3581 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3582 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3584 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3585 continue;
3588 if (m_SelectedFilters & LOGFILTER_REFNAME)
3590 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3591 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3593 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3595 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3596 continue;
3600 } // if (bRegex)
3601 else
3603 CString find = m_sFilterText;
3604 if (!m_bFilterCaseSensitively)
3605 find.MakeLower();
3606 #if 0
3607 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3609 CString sBugIDs = m_logEntries[i]->sBugIDs;
3611 if (!m_bFilterCaseSensitively)
3612 sBugIDs = sBugIDs.MakeLower();
3613 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3615 pShownlist->SafeAdd(m_logEntries[i]);
3616 continue;
3619 #endif
3620 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3622 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3624 if (!m_bFilterCaseSensitively)
3625 msg = msg.MakeLower();
3626 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3628 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3629 continue;
3632 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3634 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3636 if (!m_bFilterCaseSensitively)
3637 msg = msg.MakeLower();
3638 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3640 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3641 continue;
3644 if (m_SelectedFilters & LOGFILTER_PATHS)
3646 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3648 bool bGoing = true;
3649 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3651 CTGitPath cpath = pathList[cpPathIndex];
3652 CString path = cpath.GetGitOldPathString();
3653 if (!m_bFilterCaseSensitively)
3654 path.MakeLower();
3655 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3657 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3658 bGoing = false;
3659 continue;
3661 path = cpath.GetGitPathString();
3662 if (!m_bFilterCaseSensitively)
3663 path.MakeLower();
3664 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3666 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3667 bGoing = false;
3668 continue;
3670 path = cpath.GetActionName();
3671 if (!m_bFilterCaseSensitively)
3672 path.MakeLower();
3673 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3675 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3676 bGoing = false;
3677 continue;
3681 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3683 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3684 if (!m_bFilterCaseSensitively)
3685 msg = msg.MakeLower();
3686 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3688 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3689 continue;
3692 if (m_SelectedFilters & LOGFILTER_EMAILS)
3694 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3695 if (!m_bFilterCaseSensitively)
3696 msg = msg.MakeLower();
3697 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3699 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3700 continue;
3703 if (m_SelectedFilters & LOGFILTER_REVS)
3705 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3706 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3708 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3709 continue;
3712 if (m_SelectedFilters & LOGFILTER_REFNAME)
3714 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3715 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3717 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3719 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3720 continue;
3724 } // else (from if (bRegex))
3725 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3729 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3732 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3734 if(m_From == -1)
3735 if(m_To == -1)
3736 return true;
3737 else
3738 return time <= m_To;
3739 else
3740 if(m_To == -1)
3741 return time >= m_From;
3742 else
3743 return ((time >= m_From)&&(time <= m_To));
3745 return TRUE; /* git dll will filter time range */
3747 // return TRUE;
3749 void CGitLogListBase::StartFilter()
3751 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3752 RecalculateShownList(&m_arShownList);
3753 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3756 DeleteAllItems();
3757 SetItemCountEx(ShownCountWithStopped());
3758 RedrawItems(0, ShownCountWithStopped());
3759 Invalidate();
3762 void CGitLogListBase::RemoveFilter()
3765 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3767 m_arShownList.SafeRemoveAll();
3769 // reset the time filter too
3770 #if 0
3771 m_timFrom = (__time64_t(m_tFrom));
3772 m_timTo = (__time64_t(m_tTo));
3773 m_DateFrom.SetTime(&m_timFrom);
3774 m_DateTo.SetTime(&m_timTo);
3775 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3776 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3777 #endif
3779 for (DWORD i=0; i<m_logEntries.size(); ++i)
3781 if(this->m_IsOldFirst)
3783 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3785 else
3787 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3790 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3791 DeleteAllItems();
3792 SetItemCountEx(ShownCountWithStopped());
3793 RedrawItems(0, ShownCountWithStopped());
3795 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3798 void CGitLogListBase::Clear()
3800 m_arShownList.SafeRemoveAll();
3801 DeleteAllItems();
3803 m_logEntries.ClearAll();
3807 void CGitLogListBase::OnDestroy()
3809 // save the column widths to the registry
3810 SaveColumnWidths();
3812 SafeTerminateThread();
3813 SafeTerminateAsyncDiffThread();
3815 int retry = 0;
3816 while(m_LogCache.SaveCache())
3818 if(retry > 5)
3819 break;
3820 Sleep(1000);
3822 ++retry;
3824 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3825 // MB_YESNO) == IDNO)
3826 // break;
3829 CHintListCtrl::OnDestroy();
3832 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3834 CRect rect;
3835 int i=(int)wParam;
3836 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3837 this->InvalidateRect(rect);
3839 return 0;
3843 * Save column widths to the registry
3845 void CGitLogListBase::SaveColumnWidths()
3847 int maxcol = m_ColumnManager.GetColumnCount();
3849 // HACK that graph column is always shown
3850 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3852 for (int col = 0; col < maxcol; ++col)
3853 if (m_ColumnManager.IsVisible (col))
3854 m_ColumnManager.ColumnResized (col);
3856 m_ColumnManager.WriteSettings();
3859 int CGitLogListBase::GetHeadIndex()
3861 if(m_HeadHash.IsEmpty())
3862 return -1;
3864 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3866 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3867 if(pRev)
3869 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3870 return i;
3873 return -1;
3875 void CGitLogListBase::OnFind()
3877 if (!m_pFindDialog)
3879 m_pFindDialog = new CFindDlg(this);
3880 m_pFindDialog->Create(this);
3883 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3885 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3887 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3889 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3890 Default();
3892 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3894 if (GetSelectedCount() != 0)
3895 return 0;
3897 CGitHash theSelectedHash = m_lastSelectedHash;
3898 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3899 m_lastSelectedHash = theSelectedHash;
3901 int countPerPage = GetCountPerPage();
3902 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3903 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3904 EnsureVisible((int)itemToSelect, FALSE);
3905 return 0;
3907 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3910 ASSERT(m_pFindDialog != NULL);
3911 bool bFound = false;
3912 int i=0;
3914 if (m_pFindDialog->IsTerminating())
3916 // invalidate the handle identifying the dialog box.
3917 m_pFindDialog = NULL;
3918 return 0;
3921 INT_PTR cnt = m_arShownList.GetCount();
3923 if(m_pFindDialog->IsRef())
3925 CString str;
3926 str=m_pFindDialog->GetFindString();
3928 CGitHash hash;
3930 if(!str.IsEmpty())
3932 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3933 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3936 if(!hash.IsEmpty())
3938 for (i = 0; i < cnt; ++i)
3940 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3941 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3943 bFound = true;
3944 break;
3948 if (!bFound)
3950 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3951 return 0;
3955 if (m_pFindDialog->FindNext() && !bFound)
3957 //read data from dialog
3958 CString findText = m_pFindDialog->GetFindString();
3959 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3961 std::tr1::wregex pat;
3962 bool bRegex = false;
3963 if (m_pFindDialog->Regex())
3964 bRegex = ValidateRegexp(findText, pat, bMatchCase);
3966 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3968 for (i = m_nSearchIndex + 1; ; ++i)
3970 if (i >= cnt)
3972 i = 0;
3973 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3975 if (m_nSearchIndex >= 0)
3977 if (i == m_nSearchIndex)
3979 ::MessageBeep(0xFFFFFFFF);
3980 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3981 break;
3985 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3987 CString str;
3988 str+=pLogEntry->m_CommitHash.ToString();
3989 str+=_T("\n");
3991 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3993 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3994 str+=_T("\n");
3997 str+=pLogEntry->GetAuthorEmail();
3998 str+=_T("\n");
3999 str+=pLogEntry->GetAuthorName();
4000 str+=_T("\n");
4001 str+=pLogEntry->GetBody();
4002 str+=_T("\n");
4003 str+=pLogEntry->GetCommitterEmail();
4004 str+=_T("\n");
4005 str+=pLogEntry->GetCommitterName();
4006 str+=_T("\n");
4007 str+=pLogEntry->GetSubject();
4008 str+=_T("\n");
4009 str+=pLogEntry->m_Notes;
4010 str+=_T("\n");
4011 str+=GetTagInfo(pLogEntry);
4012 str+=_T("\n");
4015 /*Because changed files list is loaded on demand when gui show,
4016 files will empty when files have not fetched.
4018 we can add it back by using one-way diff(with outnumber changed and rename detect.
4019 here just need changed filename list. one-way is much quicker.
4021 if(pLogEntry->m_IsFull)
4023 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
4025 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
4026 str+=_T("\n");
4027 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
4028 str+=_T("\n");
4031 else
4033 if(!pLogEntry->m_IsSimpleListReady)
4034 pLogEntry->SafeGetSimpleList(&g_Git);
4036 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
4038 str+=pLogEntry->m_SimpleFileList[i];
4039 str+=_T("\n");
4045 if (bRegex)
4047 if (std::regex_search(std::wstring(str), pat, flags))
4049 bFound = true;
4050 break;
4053 else
4055 if (bMatchCase)
4057 if (str.Find(findText) >= 0)
4059 bFound = true;
4060 break;
4064 else
4066 CString msg = str;
4067 msg = msg.MakeLower();
4068 CString find = findText.MakeLower();
4069 if (msg.Find(find) >= 0)
4071 bFound = TRUE;
4072 break;
4076 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4078 } // if(m_pFindDialog->FindNext())
4079 //UpdateLogInfoLabel();
4081 if (bFound)
4083 m_nSearchIndex = i;
4084 EnsureVisible(i, FALSE);
4085 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4087 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4088 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4089 SetSelectionMark(i);
4091 else
4093 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4094 if (pLogEntry)
4095 m_highlight = pLogEntry->m_CommitHash;
4097 Invalidate();
4098 //FillLogMessageCtrl();
4099 UpdateData(FALSE);
4102 return 0;
4105 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4107 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4109 *pResult = FALSE;
4112 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4114 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4116 Invalidate(FALSE);