LogDlg: Fix possible null pointer exception
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
bloba0c5ec9fc6717c9f982e9c96419ed2f49ba27c52
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // GitLogList.cpp : implementation file
22 #include "stdafx.h"
23 #include "resource.h"
24 #include "GitLogListBase.h"
25 #include "IconMenu.h"
26 #include "cursor.h"
27 #include "GitProgressDlg.h"
28 #include "ProgressDlg.h"
29 #include "MessageBox.h"
30 #include "registry.h"
31 #include "LoglistUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
34 #include "IconMenu.h"
35 #include "GitStatus.h"
36 #include "..\TortoiseShell\Resource.h"
37 #include "FindDlg.h"
38 #include "SysInfo.h"
40 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
41 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
42 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
44 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
46 CGitLogListBase::CGitLogListBase():CHintListCtrl()
47 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
48 ,m_nSearchIndex(0)
49 ,m_bNoDispUpdates(FALSE)
50 , m_bThreadRunning(FALSE)
51 , m_bStrictStopped(false)
52 , m_SelectedFilters(LOGFILTER_ALL)
53 , m_ShowFilter(FILTERSHOW_ALL)
54 , m_bShowWC(false)
55 , m_logEntries(&m_LogCache)
56 , m_pFindDialog(NULL)
57 , m_ColumnManager(this)
58 , m_dwDefaultColumns(0)
59 , m_arShownList(&m_critSec)
60 , m_hasWC(true)
61 , m_bNoHightlightHead(FALSE)
62 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
63 , m_bFullCommitMessageOnLogLine(false)
65 // use the default GUI font, create a copy of it and
66 // change the copy to BOLD (leave the rest of the font
67 // the same)
68 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
69 LOGFONT lf = {0};
70 GetObject(hFont, sizeof(LOGFONT), &lf);
71 lf.lfWeight = FW_BOLD;
72 m_boldFont = CreateFontIndirect(&lf);
73 lf.lfWeight = FW_DONTCARE;
74 lf.lfItalic = TRUE;
75 m_FontItalics = CreateFontIndirect(&lf);
76 lf.lfWeight = FW_BOLD;
77 m_boldItalicsFont = CreateFontIndirect(&lf);
79 m_bShowBugtraqColumn=false;
81 m_IsIDReplaceAction=FALSE;
83 this->m_critSec.Init();
84 m_critSec_AsyncDiff.Init();
85 ResetWcRev(false);
87 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
88 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
89 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
90 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
91 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
92 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
94 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
95 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
97 m_Filter.m_NumberOfLogsScale = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT);
98 if (m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE)
100 CString key;
101 key.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR)g_Git.m_CurrentDir);
102 key.Replace(_T(':'), _T('_'));
103 CString lastSelFromDate = CRegString(key);
104 if (lastSelFromDate.GetLength() == 10)
106 CTime time = CTime(_wtoi((LPCTSTR)lastSelFromDate.Mid(0, 4)), _wtoi((LPCTSTR)lastSelFromDate.Mid(5, 2)), _wtoi((LPCTSTR)lastSelFromDate.Mid(8, 2)), 0, 0, 0);
107 m_Filter.m_From = (DWORD)time.GetTime();
110 m_Filter.m_NumberOfLogs = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
112 m_ShowMask = 0;
113 m_LoadingThread = NULL;
115 InterlockedExchange(&m_bExitThread,FALSE);
116 m_IsOldFirst = FALSE;
117 m_IsRebaseReplaceGraph = FALSE;
119 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
121 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
123 // get short/long datetime setting from registry
124 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
125 if ( RegUseShortDateFormat )
127 m_DateFormat = DATE_SHORTDATE;
129 else
131 m_DateFormat = DATE_LONGDATE;
133 // get relative time display setting from registry
134 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
135 m_bRelativeTimes = (regRelativeTimes != 0);
136 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
138 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
141 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
142 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
143 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
144 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
146 m_ColumnRegKey=_T("log");
148 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
149 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
150 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
151 m_bFullCommitMessageOnLogLine = !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE);
153 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
154 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
156 m_AsyncThreadExit = FALSE;
157 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
158 m_AsynDiffListLock.Init();
160 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
161 if (hUxTheme)
162 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
164 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL, 0, CREATE_SUSPENDED);
165 if (m_DiffingThread ==NULL)
167 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
168 return;
170 m_DiffingThread->m_bAutoDelete = FALSE;
171 m_DiffingThread->ResumeThread();
174 int CGitLogListBase::AsyncDiffThread()
176 m_AsyncThreadExited = false;
177 while(!m_AsyncThreadExit)
179 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
181 GitRevLoglist* pRev = nullptr;
182 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
184 m_AsynDiffListLock.Lock();
185 pRev = m_AsynDiffList.back();
186 m_AsynDiffList.pop_back();
187 m_AsynDiffListLock.Unlock();
189 if( pRev->m_CommitHash.IsEmpty() )
191 if(pRev->m_IsDiffFiles)
192 continue;
194 CTGitPathList& files = pRev->GetFiles(this);
195 files.Clear();
196 pRev->m_ParentHash.clear();
197 pRev->m_ParentHash.push_back(m_HeadHash);
198 g_Git.GetWorkingTreeChanges(files);
199 int& action = pRev->GetAction(this);
200 action = 0;
201 for (int j = 0; j < files.GetCount(); ++j)
202 action |= files[j].m_Action;
204 CString err;
205 if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err))
207 CMessageBox::Show(NULL, _T("Failed to get UnRev file list\n") + err, _T("TortoiseGit"), MB_OK);
208 return -1;
211 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
212 InterlockedExchange(&pRev->m_IsFull, TRUE);
214 pRev->GetBody().Format(IDS_FILESCHANGES, files.GetCount());
215 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
216 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
219 m_critSec_AsyncDiff.Lock();
220 int ret = pRev->CheckAndDiff();
221 m_critSec_AsyncDiff.Unlock();
222 if (!ret)
223 { // fetch change file list
224 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
226 if(i < m_arShownList.GetCount())
228 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
229 if(data->m_CommitHash == pRev->m_CommitHash)
231 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
232 break;
237 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
239 POSITION pos = GetFirstSelectedItemPosition();
240 int nItem = GetNextSelectedItem(pos);
242 if(nItem>=0)
244 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
245 if(data)
246 if(data->m_CommitHash == pRev->m_CommitHash)
248 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
255 m_AsyncThreadExited = true;
256 return 0;
258 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
260 if (exclusivelyShow)
262 m_ContextMenuMask &= hideMask;
264 else
266 m_ContextMenuMask &= ~hideMask;
270 CGitLogListBase::~CGitLogListBase()
272 InterlockedExchange(&m_bNoDispUpdates, TRUE);
273 this->m_arShownList.SafeRemoveAll();
275 DestroyIcon(m_hModifiedIcon);
276 DestroyIcon(m_hReplacedIcon);
277 DestroyIcon(m_hConflictedIcon);
278 DestroyIcon(m_hAddedIcon);
279 DestroyIcon(m_hDeletedIcon);
280 m_logEntries.ClearAll();
282 if (m_boldFont)
283 DeleteObject(m_boldFont);
285 if (m_FontItalics)
286 DeleteObject(m_FontItalics);
288 if (m_boldItalicsFont)
289 DeleteObject(m_boldItalicsFont);
291 SafeTerminateThread();
292 SafeTerminateAsyncDiffThread();
294 if(m_AsyncDiffEvent)
295 CloseHandle(m_AsyncDiffEvent);
297 if (hUxTheme)
298 FreeLibrary(hUxTheme);
302 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
303 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
304 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
305 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
306 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
307 ON_WM_CONTEXTMENU()
308 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
309 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
310 ON_WM_CREATE()
311 ON_WM_DESTROY()
312 ON_MESSAGE(MSG_LOADED,OnLoad)
313 ON_WM_MEASUREITEM()
314 ON_WM_MEASUREITEM_REFLECT()
315 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
316 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
317 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
318 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
319 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
320 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
321 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
322 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
323 END_MESSAGE_MAP()
325 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
327 //if (m_nRowHeight>0)
329 lpMeasureItemStruct->itemHeight = 50;
333 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
335 PreSubclassWindow();
336 return CHintListCtrl::OnCreate(lpCreateStruct);
339 void CGitLogListBase::PreSubclassWindow()
341 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
342 // load the icons for the action columns
343 // m_Theme.Open(m_hWnd, L"ListView");
344 SetWindowTheme(m_hWnd, L"Explorer", NULL);
345 CHintListCtrl::PreSubclassWindow();
348 CString CGitLogListBase::GetRebaseActionName(int action)
350 if (action & LOGACTIONS_REBASE_EDIT)
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
352 if (action & LOGACTIONS_REBASE_SQUASH)
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
354 if (action & LOGACTIONS_REBASE_PICK)
355 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
356 if (action & LOGACTIONS_REBASE_SKIP)
357 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
359 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
362 void CGitLogListBase::InsertGitColumn()
364 CString temp;
366 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
367 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
368 if (DWORD(regFullRowSelect))
369 exStyle |= LVS_EX_FULLROWSELECT;
370 SetExtendedStyle(exStyle);
372 // only load properties if we have a repository
373 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
374 UpdateProjectProperties();
376 static UINT normal[] =
378 IDS_LOG_GRAPH,
379 IDS_LOG_REBASE,
380 IDS_LOG_ID,
381 IDS_LOG_HASH,
382 IDS_LOG_ACTIONS,
383 IDS_LOG_MESSAGE,
384 IDS_LOG_AUTHOR,
385 IDS_LOG_DATE,
386 IDS_LOG_EMAIL,
387 IDS_LOG_COMMIT_NAME,
388 IDS_LOG_COMMIT_EMAIL,
389 IDS_LOG_COMMIT_DATE,
390 IDS_LOG_BUGIDS,
391 IDS_LOG_SVNREV,
394 static int with[] =
396 ICONITEMBORDER+16*4,
397 ICONITEMBORDER+16*4,
398 ICONITEMBORDER+16*4,
399 ICONITEMBORDER+16*4,
400 ICONITEMBORDER+16*4,
401 LOGLIST_MESSAGE_MIN,
402 ICONITEMBORDER+16*4,
403 ICONITEMBORDER+16*4,
404 ICONITEMBORDER+16*4,
405 ICONITEMBORDER+16*4,
406 ICONITEMBORDER+16*4,
407 ICONITEMBORDER+16*4,
408 ICONITEMBORDER+16*4,
409 ICONITEMBORDER+16*4,
411 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
413 DWORD hideColumns = 0;
414 if(this->m_IsRebaseReplaceGraph)
416 hideColumns |= GIT_LOG_GRAPH;
417 m_dwDefaultColumns |= GIT_LOG_REBASE;
419 else
421 hideColumns |= GIT_LOG_REBASE;
424 if(this->m_IsIDReplaceAction)
426 hideColumns |= GIT_LOG_ACTIONS;
427 m_dwDefaultColumns |= GIT_LOG_ID;
428 m_dwDefaultColumns |= GIT_LOG_HASH;
430 else
432 hideColumns |= GIT_LOG_ID;
434 if(this->m_bShowBugtraqColumn)
436 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
438 else
440 hideColumns |= GIT_LOGLIST_BUG;
442 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
443 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
444 else
445 hideColumns |= GIT_LOGLIST_SVNREV;
446 SetRedraw(false);
448 m_ColumnManager.SetNames(normal, _countof(normal));
449 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
451 SetRedraw(true);
455 * Resizes all columns in a list control to values in registry.
457 void CGitLogListBase::ResizeAllListCtrlCols()
459 // column max and min widths to allow
460 static const int nMinimumWidth = 10;
461 static const int nMaximumWidth = 1000;
462 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
463 if (pHdrCtrl)
465 int numcols = pHdrCtrl->GetItemCount();
466 for (int col = 0; col < numcols; ++col)
468 // get width for this col last time from registry
469 CString regentry;
470 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR)m_ColumnRegKey, col);
471 CRegDWORD regwidth(regentry, 0);
472 int cx = regwidth;
473 if ( cx == 0 )
475 // no saved value, setup sensible defaults
476 if (col == this->LOGLIST_MESSAGE)
478 cx = LOGLIST_MESSAGE_MIN;
480 else
482 cx = ICONITEMBORDER+16*4;
485 if (cx < nMinimumWidth)
487 cx = nMinimumWidth;
489 else if (cx > nMaximumWidth)
491 cx = nMaximumWidth;
494 SetColumnWidth(col, cx);
501 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
503 LVITEM rItem;
504 SecureZeroMemory(&rItem, sizeof(LVITEM));
505 rItem.mask = LVIF_STATE;
506 rItem.iItem = (int)Index;
507 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
508 GetItem(&rItem);
510 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index);
511 HBRUSH brush = NULL;
513 if (!(rItem.state & LVIS_SELECTED))
515 int action = pLogEntry->GetRebaseAction();
516 if (action & LOGACTIONS_REBASE_SQUASH)
517 brush = ::CreateSolidBrush(RGB(156,156,156));
518 else if (action & LOGACTIONS_REBASE_EDIT)
519 brush = ::CreateSolidBrush(RGB(200,200,128));
521 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
523 if (rItem.state & LVIS_SELECTED)
525 if (::GetFocus() == m_hWnd)
526 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
527 else
528 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
531 if (brush != NULL)
533 ::FillRect(hdc, &rect, brush);
534 ::DeleteObject(brush);
538 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
540 POINT point = { 4, 4 };
541 CRect rt2 = rect;
542 rt2.DeflateRect(1, 1);
543 rt2.OffsetRect(2, 2);
545 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
546 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
547 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
548 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
549 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
551 ::SelectObject(hdc, brush);
552 rt2.OffsetRect(-2, -2);
553 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
554 ::SelectObject(hdc, oldbrush);
555 ::SelectObject(hdc, oldpen);
556 ::DeleteObject(nullPen);
557 ::DeleteObject(darkBrush);
560 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
562 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
563 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
564 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
565 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
566 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
567 ::LineTo(hdc, rect.left, rect.bottom);
568 ::SelectObject(hdc, oldpen);
569 ::DeleteObject(pen);
572 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
574 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
575 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
576 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
577 ::LineTo(hdc, rect.left, rect.bottom);
578 ::LineTo(hdc, rect.right, rect.bottom);
579 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
580 ::SelectObject(hdc, oldpen);
581 ::DeleteObject(pen);
584 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
586 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
587 CRect rt=rect;
588 LVITEM rItem;
589 SecureZeroMemory(&rItem, sizeof(LVITEM));
590 rItem.mask = LVIF_STATE;
591 rItem.iItem = (int)index;
592 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
593 GetItem(&rItem);
595 CDC W_Dc;
596 W_Dc.Attach(hdc);
598 HTHEME hTheme = NULL;
599 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
600 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
602 SIZE oneSpaceSize;
603 if (m_bTagsBranchesOnRightSide)
605 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
606 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
607 SelectObject(hdc, oldFont);
608 rt.left += oneSpaceSize.cx * 2;
610 else
612 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
613 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
614 rt.left += oneSpaceSize.cx;
617 CString msg = MessageDisplayStr(data);
618 int action = data->GetRebaseAction();
619 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
620 if (IsAppThemed() && pfnDrawThemeTextEx)
622 int txtState = LISS_NORMAL;
623 if (rItem.state & LVIS_SELECTED)
624 txtState = LISS_SELECTED;
626 DTTOPTS opts = { 0 };
627 opts.dwSize = sizeof(opts);
628 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
629 opts.dwFlags = DTT_TEXTCOLOR;
630 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, msg, -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
632 else
634 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
636 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
637 ::DrawText(hdc,msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
638 ::SetTextColor(hdc, clrOld);
640 else
642 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
643 ::DrawText(hdc, msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
644 ::SetTextColor(hdc, clrOld);
648 if (m_bTagsBranchesOnRightSide)
650 SIZE size;
651 GetTextExtentPoint32(hdc, msg, msg.GetLength(), &size);
653 rt.left += oneSpaceSize.cx + size.cx;
655 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
658 if (hTheme)
659 CloseThemeData(hTheme);
661 W_Dc.Detach();
664 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
666 for (unsigned int i = 0; i < refList.size(); ++i)
668 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
669 HBRUSH brush = 0;
670 COLORREF colRef = refList[i].color;
671 bool singleRemote = refList[i].singleRemote;
672 bool hasTracking = refList[i].hasTracking;
673 bool sameName = refList[i].sameName;
674 bool annotatedTag = refList[i].annotatedTag;
676 //When row selected, ajust label color
677 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
679 if (rItem.state & LVIS_SELECTED)
680 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
683 brush = ::CreateSolidBrush(colRef);
685 if (!shortname.IsEmpty() && (rt.left < rect.right))
687 SIZE size;
688 memset(&size,0,sizeof(SIZE));
689 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
691 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
692 rt.right += 8;
694 int textpos = DT_CENTER;
696 if (rt.right > rect.right)
698 rt.right = rect.right;
699 textpos = 0;
702 CRect textRect = rt;
704 if (singleRemote)
706 rt.right += 8;
707 textRect.OffsetRect(8, 0);
710 if (sameName)
711 rt.right += 8;
713 if (hasTracking)
715 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
717 else
719 //Fill interior of ref label
720 ::FillRect(hdc, &rt, brush);
723 //Draw edge of label
724 CRect rectEdge = rt;
726 if (!hasTracking)
728 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
729 rectEdge.DeflateRect(1, 1);
730 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
733 if (annotatedTag)
735 rt.right += 8;
736 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
737 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
738 ::FillRgn(hdc, hrgn, brush);
739 ::DeleteObject(hrgn);
740 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
741 HPEN pen;
742 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
743 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
744 ::DeleteObject(pen);
745 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
746 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
747 ::DeleteObject(pen);
748 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
749 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
750 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
751 ::DeleteObject(pen);
752 SelectObject(hdc, oldpen);
755 //Draw text inside label
756 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
757 if (!customColor && IsAppThemed() && pfnDrawThemeTextEx)
759 int txtState = LISS_NORMAL;
760 if (rItem.state & LVIS_SELECTED)
761 txtState = LISS_SELECTED;
763 DTTOPTS opts = { 0 };
764 opts.dwSize = sizeof(opts);
765 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
766 opts.dwFlags = DTT_TEXTCOLOR;
767 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
769 else
771 W_Dc.SetBkMode(TRANSPARENT);
772 if (customColor || (rItem.state & LVIS_SELECTED))
774 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
775 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
776 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
777 ::SetTextColor(hdc,clrOld);
779 else
781 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
782 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
783 ::SetTextColor(hdc, clrOld);
787 if (singleRemote)
789 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
790 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
791 CRect newRect;
792 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
793 DrawLightning(hdc, newRect, color, bold);
796 if (sameName)
798 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
799 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
800 CRect newRect;
801 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
802 DrawUpTriangle(hdc, newRect, color, bold);
805 rt.left = rt.right + 1;
807 if (brush)
808 ::DeleteObject(brush);
810 rt.right = rect.right;
813 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
815 // Returns ((256 - amount)*col1 + amount*col2) / 256;
816 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
817 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
818 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
821 Gdiplus::Color GetGdiColor(COLORREF col)
823 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
825 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
826 const COLORREF& col,const COLORREF& activeColor, int top
829 int h = laneHeight / 2;
830 int m = (x1 + x2) / 2;
831 int r = (x2 - x1) * m_NodeSize / 30;
832 int d = 2 * r;
834 #define P_CENTER m , h+top
835 #define P_0 x2, h+top
836 #define P_90 m , 0+top-1
837 #define P_180 x1, h+top
838 #define P_270 m , 2 * h+top +1
839 #define R_CENTER m - r, h - r+top, d, d
842 #define DELTA_UR_B 2*(x1 - m), 2*h +top
843 #define DELTA_UR_E 0*16, 90*16 +top // -,
845 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
846 #define DELTA_DR_E 270*16, 90*16 +top // -'
848 #define DELTA_UL_B 2*(x2 - m), 2*h +top
849 #define DELTA_UL_E 90*16, 90*16 +top // ,-
851 #define DELTA_DL_B 2*(x2 - m),2*-h +top
852 #define DELTA_DL_E 180*16, 90*16 // '-
854 #define CENTER_UR x1, 2*h, 225
855 #define CENTER_DR x1, 0 , 135
856 #define CENTER_UL x2, 2*h, 315
857 #define CENTER_DL x2, 0 , 45
860 Gdiplus::Graphics graphics( hdc );
862 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
864 // arc
865 switch (type) {
866 case Lanes::JOIN:
867 case Lanes::JOIN_R:
868 case Lanes::HEAD:
869 case Lanes::HEAD_R:
871 Gdiplus::LinearGradientBrush gradient(
872 Gdiplus::Point(x1-2, h+top-2),
873 Gdiplus::Point(P_270),
874 GetGdiColor(activeColor),GetGdiColor(col));
877 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
878 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
880 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
881 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
882 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
884 break;
886 case Lanes::JOIN_L:
889 Gdiplus::LinearGradientBrush gradient(
890 Gdiplus::Point(P_270),
891 Gdiplus::Point(x2+1, h+top-1),
892 GetGdiColor(col),GetGdiColor(activeColor));
895 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
896 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
898 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
899 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
900 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
903 break;
905 case Lanes::TAIL:
906 case Lanes::TAIL_R:
909 Gdiplus::LinearGradientBrush gradient(
910 Gdiplus::Point(x1-2, h+top-2),
911 Gdiplus::Point(P_90),
912 GetGdiColor(activeColor),GetGdiColor(col));
914 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
916 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
918 #if 0
919 QConicalGradient gradient(CENTER_DR);
920 gradient.setColorAt(0.375, activeCol);
921 gradient.setColorAt(0.625, col);
922 myPen.setBrush(gradient);
923 p->setPen(myPen);
924 p->drawArc(P_CENTER, DELTA_DR);
925 #endif
926 break;
928 default:
929 break;
933 //static QPen myPen(Qt::black, 2); // fast path here
934 CPen pen;
935 pen.CreatePen(PS_SOLID,2,col);
936 //myPen.setColor(col);
937 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
939 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
941 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
943 //p->setPen(myPen);
945 // vertical line
946 switch (type) {
947 case Lanes::ACTIVE:
948 case Lanes::NOT_ACTIVE:
949 case Lanes::MERGE_FORK:
950 case Lanes::MERGE_FORK_R:
951 case Lanes::MERGE_FORK_L:
952 case Lanes::JOIN:
953 case Lanes::JOIN_R:
954 case Lanes::JOIN_L:
955 case Lanes::CROSS:
956 //DrawLine(hdc,P_90,P_270);
957 graphics.DrawLine(&myPen,P_90,P_270);
958 //p->drawLine(P_90, P_270);
959 break;
960 case Lanes::HEAD_L:
961 case Lanes::BRANCH:
962 //DrawLine(hdc,P_CENTER,P_270);
963 graphics.DrawLine(&myPen,P_CENTER,P_270);
964 //p->drawLine(P_CENTER, P_270);
965 break;
966 case Lanes::TAIL_L:
967 case Lanes::INITIAL:
968 case Lanes::BOUNDARY:
969 case Lanes::BOUNDARY_C:
970 case Lanes::BOUNDARY_R:
971 case Lanes::BOUNDARY_L:
972 //DrawLine(hdc,P_90, P_CENTER);
973 graphics.DrawLine(&myPen,P_90,P_CENTER);
974 //p->drawLine(P_90, P_CENTER);
975 break;
976 default:
977 break;
980 myPen.SetColor(GetGdiColor(activeColor));
982 // horizontal line
983 switch (type) {
984 case Lanes::MERGE_FORK:
985 case Lanes::JOIN:
986 case Lanes::HEAD:
987 case Lanes::TAIL:
988 case Lanes::CROSS:
989 case Lanes::CROSS_EMPTY:
990 case Lanes::BOUNDARY_C:
991 //DrawLine(hdc,P_180,P_0);
992 graphics.DrawLine(&myPen,P_180,P_0);
993 //p->drawLine(P_180, P_0);
994 break;
995 case Lanes::MERGE_FORK_R:
996 case Lanes::BOUNDARY_R:
997 //DrawLine(hdc,P_180,P_CENTER);
998 graphics.DrawLine(&myPen,P_180,P_CENTER);
999 //p->drawLine(P_180, P_CENTER);
1000 break;
1001 case Lanes::MERGE_FORK_L:
1002 case Lanes::HEAD_L:
1003 case Lanes::TAIL_L:
1004 case Lanes::BOUNDARY_L:
1005 //DrawLine(hdc,P_CENTER,P_0);
1006 graphics.DrawLine(&myPen,P_CENTER,P_0);
1007 //p->drawLine(P_CENTER, P_0);
1008 break;
1009 default:
1010 break;
1013 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1015 CBrush brush;
1016 brush.CreateSolidBrush(col);
1017 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1019 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1020 // center symbol, e.g. rect or ellipse
1021 switch (type) {
1022 case Lanes::ACTIVE:
1023 case Lanes::INITIAL:
1024 case Lanes::BRANCH:
1026 //p->setPen(Qt::NoPen);
1027 //p->setBrush(col);
1028 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1029 graphics.FillEllipse(&myBrush, R_CENTER);
1030 //p->drawEllipse(R_CENTER);
1031 break;
1032 case Lanes::MERGE_FORK:
1033 case Lanes::MERGE_FORK_R:
1034 case Lanes::MERGE_FORK_L:
1035 //p->setPen(Qt::NoPen);
1036 //p->setBrush(col);
1037 //p->drawRect(R_CENTER);
1038 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1039 graphics.FillRectangle(&myBrush, R_CENTER);
1040 break;
1041 case Lanes::UNAPPLIED:
1042 // Red minus sign
1043 //p->setPen(Qt::NoPen);
1044 //p->setBrush(Qt::red);
1045 //p->drawRect(m - r, h - 1, d, 2);
1046 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1047 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1048 break;
1049 case Lanes::APPLIED:
1050 // Green plus sign
1051 //p->setPen(Qt::NoPen);
1052 //p->setBrush(DARK_GREEN);
1053 //p->drawRect(m - r, h - 1, d, 2);
1054 //p->drawRect(m - 1, h - r, 2, d);
1055 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1056 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1057 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1058 break;
1059 case Lanes::BOUNDARY:
1060 //p->setBrush(back);
1061 //p->drawEllipse(R_CENTER);
1062 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1063 graphics.DrawEllipse(&myPen, R_CENTER);
1064 break;
1065 case Lanes::BOUNDARY_C:
1066 case Lanes::BOUNDARY_R:
1067 case Lanes::BOUNDARY_L:
1068 //p->setBrush(back);
1069 //p->drawRect(R_CENTER);
1070 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1071 graphics.FillRectangle(&myBrush,R_CENTER);
1072 break;
1073 default:
1074 break;
1077 ::SelectObject(hdc,oldpen);
1078 ::SelectObject(hdc,oldbrush);
1079 #undef P_CENTER
1080 #undef P_0
1081 #undef P_90
1082 #undef P_180
1083 #undef P_270
1084 #undef R_CENTER
1087 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1089 // TODO: unfinished
1090 // return;
1091 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
1092 if(data->m_CommitHash.IsEmpty())
1093 return;
1095 CRect rt=rect;
1096 LVITEM rItem;
1097 SecureZeroMemory(&rItem, sizeof(LVITEM));
1098 rItem.mask = LVIF_STATE;
1099 rItem.iItem = (int)index;
1100 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1101 GetItem(&rItem);
1103 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1105 if (data->m_Lanes.empty())
1106 m_logEntries.setLane(data->m_CommitHash);
1108 std::vector<int>& lanes=data->m_Lanes;
1109 size_t laneNum = lanes.size();
1110 UINT activeLane = 0;
1111 for (UINT i = 0; i < laneNum; ++i)
1112 if (Lanes::isMerge(lanes[i])) {
1113 activeLane = i;
1114 break;
1117 int x2 = 0;
1118 int maxWidth = rect.Width();
1119 int lw = 3 * rect.Height() / 4; //laneWidth()
1121 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1122 //if (opt.state & QStyle::State_Selected)
1123 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1125 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1128 int x1 = x2;
1129 x2 += lw;
1131 int ln = lanes[i];
1132 if (ln == Lanes::EMPTY)
1133 continue;
1135 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1136 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1139 #if 0
1140 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1142 int x1 = x2;
1143 x2 += lw;
1145 int ln = lanes[i];
1146 if (ln == Lanes::EMPTY)
1147 continue;
1149 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1150 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1152 if (ln == Lanes::CROSS)
1154 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1155 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1157 else
1158 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1160 #endif
1164 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1167 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1168 // Take the default processing unless we set this to something else below.
1169 *pResult = CDRF_DODEFAULT;
1171 if (m_bNoDispUpdates)
1172 return;
1174 switch (pLVCD->nmcd.dwDrawStage)
1176 case CDDS_PREPAINT:
1178 *pResult = CDRF_NOTIFYITEMDRAW;
1179 return;
1181 break;
1182 case CDDS_ITEMPREPAINT:
1184 // This is the prepaint stage for an item. Here's where we set the
1185 // item's text color.
1187 // Tell Windows to send draw notifications for each subitem.
1188 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1190 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1192 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1194 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1195 if (data)
1197 HGDIOBJ hGdiObj = nullptr;
1198 int action = data->GetRebaseAction();
1199 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1200 crText = RGB(128,128,128);
1202 if (action & LOGACTIONS_REBASE_SQUASH)
1203 pLVCD->clrTextBk = RGB(156,156,156);
1204 else if (action & LOGACTIONS_REBASE_EDIT)
1205 pLVCD->clrTextBk = RGB(200,200,128);
1206 else
1207 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1209 if (action & LOGACTIONS_REBASE_CURRENT)
1210 hGdiObj = m_boldFont;
1212 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1213 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1214 if (isHeadHash && isHighlight)
1215 hGdiObj = m_boldItalicsFont;
1216 else if (isHeadHash)
1217 hGdiObj = m_boldFont;
1218 else if (isHighlight)
1219 hGdiObj = m_FontItalics;
1221 if (hGdiObj)
1223 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1224 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1227 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1228 // crText = GetSysColor(COLOR_GRAYTEXT);
1230 if (data->m_CommitHash.IsEmpty())
1232 //crText = GetSysColor(RGB(200,200,0));
1233 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1234 // We changed the font, so we're returning CDRF_NEWFONT. This
1235 // tells the control to recalculate the extent of the text.
1236 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1240 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1242 if (m_bStrictStopped)
1243 crText = GetSysColor(COLOR_GRAYTEXT);
1245 // Store the color back in the NMLVCUSTOMDRAW struct.
1246 pLVCD->clrText = crText;
1247 return;
1249 break;
1250 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1252 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1254 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1257 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1259 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1261 CRect rect;
1262 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1264 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1265 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1267 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1268 if( !data ->m_CommitHash.IsEmpty())
1269 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1271 *pResult = CDRF_SKIPDEFAULT;
1272 return;
1276 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1278 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1280 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1282 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1284 CRect rect;
1285 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1287 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1288 // not in FillBackGround method, because this only affected the message subitem
1289 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1290 return;
1292 int index = (int)pLVCD->nmcd.dwItemSpec;
1293 int state = GetItemState(index, LVIS_SELECTED);
1294 int txtState = LISS_NORMAL;
1295 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1297 if (state & LVIS_SELECTED)
1298 txtState = LISS_HOTSELECTED;
1299 else
1300 txtState = LISS_HOT;
1302 else if (state & LVIS_SELECTED)
1304 if (::GetFocus() == m_hWnd)
1305 txtState = LISS_SELECTED;
1306 else
1307 txtState = LISS_SELECTEDNOTFOCUS;
1310 HTHEME hTheme = nullptr;
1311 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1312 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1314 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1315 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1316 else
1318 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1319 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1320 ::DeleteObject(brush);
1322 if (hTheme)
1324 CRect rt;
1325 // get rect of whole line
1326 GetItemRect(index, rt, LVIR_BOUNDS);
1327 CRect rect2 = rect;
1328 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1329 rect2.DeflateRect(1, 1, 1, 1);
1331 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1332 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1334 CloseThemeData(hTheme);
1336 // END: extended redraw
1338 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1340 std::vector<REFLABEL> refsToShow;
1341 STRING_VECTOR remoteTrackingList;
1342 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1343 for (unsigned int i = 0; i < refList.size(); ++i)
1345 CString str = refList[i];
1347 REFLABEL refLabel;
1348 refLabel.color = RGB(255, 255, 255);
1349 refLabel.singleRemote = false;
1350 refLabel.hasTracking = false;
1351 refLabel.sameName = false;
1352 refLabel.annotatedTag = false;
1353 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1355 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1356 continue;
1357 if (refLabel.name == m_CurrentBranch )
1358 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1359 else
1360 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1362 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1363 CString pullRemote = trackingEntry.first;
1364 CString pullBranch = trackingEntry.second;
1365 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1367 CString defaultUpstream;
1368 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1369 refLabel.hasTracking = true;
1370 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1372 bool found = false;
1373 for (size_t j = i + 1; j < refList.size(); ++j)
1375 if (refList[j] == defaultUpstream)
1377 found = true;
1378 break;
1382 if (found)
1384 bool sameName = pullBranch == refLabel.name;
1385 refsToShow.push_back(refLabel);
1386 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1387 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1388 if (m_bSymbolizeRefNames)
1390 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1392 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1393 refLabel.singleRemote = true;
1395 else if (sameName)
1396 refLabel.simplifiedName = pullRemote + _T("/");
1397 refLabel.sameName = sameName;
1399 refsToShow.push_back(refLabel);
1400 remoteTrackingList.push_back(defaultUpstream);
1401 continue;
1406 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1408 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1409 continue;
1411 bool found = false;
1412 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1414 if (remoteTrackingList[j] == str)
1416 found = true;
1417 break;
1420 if (found)
1421 continue;
1423 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1424 if (m_bSymbolizeRefNames)
1426 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1428 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1429 refLabel.singleRemote = true;
1433 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1435 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1436 continue;
1437 refLabel.color = m_Colors.GetColor(CColors::Tag);
1438 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1440 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1442 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1443 continue;
1444 refLabel.color = m_Colors.GetColor(CColors::Stash);
1445 refLabel.name = _T("stash");
1447 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1449 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1450 continue;
1451 if (refLabel.name.Find(_T("good")) == 0)
1453 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1454 refLabel.name = _T("good");
1456 if (refLabel.name.Find(_T("bad")) == 0)
1458 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1459 refLabel.name = _T("bad");
1462 else
1463 continue;
1465 refsToShow.push_back(refLabel);
1468 if (refsToShow.empty())
1470 *pResult = CDRF_DODEFAULT;
1471 return;
1474 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1476 *pResult = CDRF_SKIPDEFAULT;
1477 return;
1484 if (pLVCD->iSubItem == LOGLIST_ACTION)
1486 if(this->m_IsIDReplaceAction)
1488 *pResult = CDRF_DODEFAULT;
1489 return;
1491 *pResult = CDRF_DODEFAULT;
1493 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1494 return;
1496 int nIcons = 0;
1497 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1498 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1500 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1501 CRect rect;
1502 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1503 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1504 // Get the selected state of the
1505 // item being drawn.
1507 // Fill the background if necessary
1508 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1510 // Draw the icon(s) into the compatible DC
1511 int action = pLogEntry->GetAction(this);
1512 if (!pLogEntry->m_IsDiffFiles)
1514 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1515 *pResult = CDRF_SKIPDEFAULT;
1516 return;
1519 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1520 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1521 ++nIcons;
1523 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1524 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1525 ++nIcons;
1527 if (action & CTGitPath::LOGACTIONS_DELETED)
1528 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1529 ++nIcons;
1531 if (action & CTGitPath::LOGACTIONS_REPLACED)
1532 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1533 ++nIcons;
1535 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1536 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1537 ++nIcons;
1539 *pResult = CDRF_SKIPDEFAULT;
1540 return;
1543 break;
1545 *pResult = CDRF_DODEFAULT;
1548 CString FindSVNRev(const CString& msg)
1552 const std::tr1::wsregex_iterator end;
1553 std::wstring s = msg;
1554 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1555 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex1); it != end; ++it)
1557 const std::tr1::wsmatch match = *it;
1558 if (match.size() == 4)
1560 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1561 return std::wstring(match[2]).c_str();
1564 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1565 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex2); it != end; ++it)
1567 const std::tr1::wsmatch match = *it;
1568 if (match.size() == 3)
1570 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1571 return std::wstring(match[1]).c_str();
1575 catch (std::exception) {}
1577 return _T("");
1580 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1582 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1583 return pLogEntry->GetSubject();
1585 CString txt(pLogEntry->GetSubject());
1586 txt += _T(' ');
1587 txt += pLogEntry->GetBody();
1589 // Deal with CRLF
1590 txt.Replace(_T('\n'), _T(' '));
1591 txt.Replace(_T('\r'), _T(' '));
1593 return txt;
1596 // CGitLogListBase message handlers
1598 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1600 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1602 // Create a pointer to the item
1603 LV_ITEM* pItem = &(pDispInfo)->item;
1605 // Do the list need text information?
1606 if (!(pItem->mask & LVIF_TEXT))
1607 return;
1609 // By default, clear text buffer.
1610 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1612 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1614 *pResult = 0;
1615 if (m_bNoDispUpdates || bOutOfRange)
1616 return;
1618 // Which item number?
1619 int itemid = pItem->iItem;
1620 GitRevLoglist* pLogEntry = nullptr;
1621 if (itemid < m_arShownList.GetCount())
1622 pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(pItem->iItem));
1624 CString temp;
1625 if(m_IsOldFirst)
1627 temp.Format(_T("%d"),pItem->iItem+1);
1630 else
1632 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1635 // Which column?
1636 switch (pItem->iSubItem)
1638 case LOGLIST_GRAPH: //Graphic
1639 break;
1640 case LOGLIST_REBASE:
1642 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1643 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1645 break;
1646 case LOGLIST_ACTION: //action -- no text in the column
1647 break;
1648 case LOGLIST_HASH:
1649 if(pLogEntry)
1650 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1651 break;
1652 case LOGLIST_ID:
1653 if(this->m_IsIDReplaceAction)
1654 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1655 break;
1656 case LOGLIST_MESSAGE: //Message
1657 if (pLogEntry)
1658 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1659 break;
1660 case LOGLIST_AUTHOR: //Author
1661 if (pLogEntry)
1662 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1663 break;
1664 case LOGLIST_DATE: //Date
1665 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1666 lstrcpyn(pItem->pszText,
1667 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1668 pItem->cchTextMax - 1);
1669 break;
1671 case LOGLIST_EMAIL:
1672 if (pLogEntry)
1673 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1674 break;
1676 case LOGLIST_COMMIT_NAME: //Commit
1677 if (pLogEntry)
1678 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1679 break;
1681 case LOGLIST_COMMIT_EMAIL: //Commit Email
1682 if (pLogEntry)
1683 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1684 break;
1686 case LOGLIST_COMMIT_DATE: //Commit Date
1687 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1688 lstrcpyn(pItem->pszText,
1689 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1690 pItem->cchTextMax - 1);
1691 break;
1692 case LOGLIST_BUG: //Bug ID
1693 if(pLogEntry)
1694 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1695 break;
1696 case LOGLIST_SVNREV: //SVN revision
1697 if (pLogEntry)
1698 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1699 break;
1701 default:
1702 ASSERT(false);
1706 bool CGitLogListBase::IsOnStash(int index)
1708 GitRevLoglist* rev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index));
1709 if (IsStash(rev))
1710 return true;
1711 if (index > 0)
1713 GitRevLoglist* preRev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index - 1));
1714 if (IsStash(preRev))
1715 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1717 return false;
1720 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1722 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1724 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1725 return true;
1727 return false;
1730 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1732 if (pRev->m_ParentHash.empty())
1734 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1735 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1737 parentHash = pRev->m_ParentHash;
1740 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1743 if (pWnd == GetHeaderCtrl())
1745 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1748 int selIndex = GetSelectionMark();
1749 if (selIndex < 0)
1750 return; // nothing selected, nothing to do with a context menu
1752 // if the user selected the info text telling about not all revisions shown due to
1753 // the "stop on copy/rename" option, we also don't show the context menu
1754 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1755 return;
1757 // if the context menu is invoked through the keyboard, we have to use
1758 // a calculated position on where to anchor the menu on
1759 if ((point.x == -1) && (point.y == -1))
1761 CRect rect;
1762 GetItemRect(selIndex, &rect, LVIR_LABEL);
1763 ClientToScreen(&rect);
1764 point = rect.CenterPoint();
1766 m_nSearchIndex = selIndex;
1767 m_bCancelled = FALSE;
1769 // calculate some information the context menu commands can use
1770 // CString pathURL = GetURLFromPath(m_path);
1772 POSITION pos = GetFirstSelectedItemPosition();
1773 int indexNext = GetNextSelectedItem(pos);
1774 if (indexNext < 0)
1775 return;
1777 GitRevLoglist* pSelLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(indexNext));
1778 if (pSelLogEntry == nullptr)
1779 return;
1780 #if 0
1781 GitRev revSelected = pSelLogEntry->Rev;
1782 GitRev revPrevious = git_revnum_t(revSelected)-1;
1783 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1785 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1787 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1788 if (changedpath->lCopyFromRev)
1789 revPrevious = changedpath->lCopyFromRev;
1792 GitRev revSelected2;
1793 if (pos)
1795 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1796 revSelected2 = pLogEntry->Rev;
1798 bool bAllFromTheSameAuthor = true;
1799 CString firstAuthor;
1800 CLogDataVector selEntries;
1801 GitRev revLowest, revHighest;
1802 GitRevRangeArray revisionRanges;
1804 POSITION pos = GetFirstSelectedItemPosition();
1805 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1806 revisionRanges.AddRevision(pLogEntry->Rev);
1807 selEntries.push_back(pLogEntry);
1808 firstAuthor = pLogEntry->sAuthor;
1809 revLowest = pLogEntry->Rev;
1810 revHighest = pLogEntry->Rev;
1811 while (pos)
1813 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1814 revisionRanges.AddRevision(pLogEntry->Rev);
1815 selEntries.push_back(pLogEntry);
1816 if (firstAuthor.Compare(pLogEntry->sAuthor))
1817 bAllFromTheSameAuthor = false;
1818 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1819 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1823 #endif
1825 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1827 int FirstSelect=-1, LastSelect=-1;
1828 pos = GetFirstSelectedItemPosition();
1829 FirstSelect = GetNextSelectedItem(pos);
1830 while(pos)
1832 LastSelect = GetNextSelectedItem(pos);
1834 //entry is selected, now show the popup menu
1835 CIconMenu popup;
1836 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1838 if (popup.CreatePopupMenu())
1840 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1841 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1842 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1843 bool isStash = IsOnStash(indexNext);
1844 GIT_REV_LIST parentHash;
1845 GetParentHashes(pSelLogEntry, parentHash);
1847 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1848 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1850 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)) && FirstSelect != GetItemCount() - 1 && LastSelect != GetItemCount() - 1)
1851 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1853 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1854 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1856 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1857 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1859 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)))
1860 popup.AppendMenu(MF_SEPARATOR, NULL);
1862 if (GetSelectedCount() == 1)
1865 bool requiresSeparator = false;
1866 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1868 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1870 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1871 requiresSeparator = true;
1874 else
1876 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1878 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1879 requiresSeparator = true;
1881 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1883 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1884 requiresSeparator = true;
1888 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1890 if (parentHash.size() == 1)
1892 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1893 requiresSeparator = true;
1895 else if (parentHash.size() > 1)
1897 blamemenu.CreatePopupMenu();
1898 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1899 for (size_t i = 0; i < parentHash.size(); ++i)
1901 CString str;
1902 str.Format(IDS_PARENT, i + 1);
1903 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1905 requiresSeparator = true;
1909 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1911 if (parentHash.size() == 1)
1913 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1914 requiresSeparator = true;
1916 else if (parentHash.size() > 1)
1918 gnudiffmenu.CreatePopupMenu();
1919 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1921 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1922 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1923 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1925 for (size_t i = 0; i < parentHash.size(); ++i)
1927 CString str;
1928 str.Format(IDS_PARENT, i + 1);
1929 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1931 requiresSeparator = true;
1935 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1937 if (parentHash.size() == 1)
1939 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1940 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1941 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1942 requiresSeparator = true;
1944 else if (parentHash.size() > 1)
1946 diffmenu.CreatePopupMenu();
1947 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1948 for (size_t i = 0; i < parentHash.size(); ++i)
1950 CString str;
1951 str.Format(IDS_PARENT, i + 1);
1952 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1953 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1955 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1956 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1959 requiresSeparator = true;
1963 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1965 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1966 requiresSeparator = true;
1969 if (requiresSeparator)
1970 popup.AppendMenu(MF_SEPARATOR, NULL);
1972 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1974 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1975 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1978 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1980 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1981 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1983 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1984 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1986 popup.AppendMenu(MF_SEPARATOR, NULL);
1989 if (pSelLogEntry->m_CommitHash.IsEmpty())
1991 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1992 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
1994 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1995 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1997 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
1998 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
2000 popup.AppendMenu(MF_SEPARATOR, NULL);
2002 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
2003 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
2005 popup.AppendMenu(MF_SEPARATOR, NULL);
2009 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2010 // {
2011 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2012 // }
2013 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2014 // {
2015 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2016 // }
2017 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2018 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2019 // {
2020 // popup.AppendMenu(MF_SEPARATOR, NULL);
2021 // }
2023 CString str;
2024 //if (m_hasWC)
2025 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2027 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2029 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2030 GetSelectedCount() == 1)
2031 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2033 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2034 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2036 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
2038 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2039 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2041 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2043 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2044 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2047 // Add Switch Branch express Menu
2048 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2049 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2052 std::vector<CString *> branchs;
2053 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2055 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2056 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2058 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2062 CString str2;
2063 str2.LoadString(IDS_SWITCH_BRANCH);
2065 if(branchs.size() == 1)
2067 str2 += _T(' ');
2068 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2069 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2071 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2074 else if(branchs.size() > 1)
2076 subbranchmenu.CreatePopupMenu();
2077 for (size_t i = 0 ; i < branchs.size(); ++i)
2079 if (*branchs[i] != currentBranch)
2081 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2082 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2086 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2090 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2091 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2093 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2094 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2096 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2097 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2099 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2101 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2102 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2103 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2105 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2106 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2108 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2110 if (parentHash.size() == 1)
2112 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2114 else if (parentHash.size() > 1)
2116 revertmenu.CreatePopupMenu();
2117 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2119 for (size_t i = 0; i < parentHash.size(); ++i)
2121 CString str2;
2122 str2.Format(IDS_PARENT, i + 1);
2123 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2128 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2129 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2131 popup.AppendMenu(MF_SEPARATOR, NULL);
2136 if(!pSelLogEntry->m_Ref.IsEmpty())
2138 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2139 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2140 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2141 popup.AppendMenu(MF_SEPARATOR, NULL);
2144 if (GetSelectedCount() >= 2)
2146 bool bAddSeparator = false;
2147 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2149 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2150 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2153 if (GetSelectedCount() == 2)
2155 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2156 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2158 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2160 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2161 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2162 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2163 CString menu;
2164 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2165 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2166 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2167 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2170 bAddSeparator = true;
2173 if (m_hasWC)
2175 bAddSeparator = true;
2178 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2179 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2181 if (bAddSeparator)
2182 popup.AppendMenu(MF_SEPARATOR, NULL);
2185 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2187 bool bAddSeparator = false;
2188 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2190 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2192 CString head;
2193 int headindex;
2194 headindex = this->GetHeadIndex();
2195 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2197 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2198 CGitHash hashFirst;
2199 if (g_Git.GetHash(hashFirst, head))
2200 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2201 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2202 CGitHash hash;
2203 if (g_Git.GetHash(hash, head))
2204 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2205 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2206 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2207 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2208 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2209 bAddSeparator = true;
2214 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2215 if (GetSelectedCount() >= 2)
2216 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2217 else
2218 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2219 bAddSeparator = true;
2222 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2223 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2224 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2225 bAddSeparator = true;
2228 if (bAddSeparator)
2229 popup.AppendMenu(MF_SEPARATOR, NULL);
2232 if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2234 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2235 popup.AppendMenu(MF_SEPARATOR, NULL);
2238 if (GetSelectedCount() == 1)
2240 bool bAddSeparator = false;
2241 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2243 // show the push-option only if the log entry has an associated local branch
2244 bool isLocal = false;
2245 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2247 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2248 isLocal = true;
2250 if (isLocal || showExtendedMenu)
2252 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2253 bAddSeparator = true;
2256 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2258 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2259 bAddSeparator = true;
2263 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2265 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2267 std::vector<CString *> branchs;
2268 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2270 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2271 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2273 CString str;
2274 if (branchs.size() == 1)
2276 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2277 str+=_T(' ');
2278 str += *branchs[0];
2279 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2280 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2281 bAddSeparator = true;
2283 else if (branchs.size() > 1)
2285 str.LoadString(IDS_DELETE_BRANCHTAG);
2286 submenu.CreatePopupMenu();
2287 for (size_t i = 0; i < branchs.size(); ++i)
2289 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2290 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2293 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2294 bAddSeparator = true;
2297 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2298 if (bAddSeparator)
2299 popup.AppendMenu(MF_SEPARATOR, NULL);
2300 } // GetSelectedCount() == 1
2302 if (GetSelectedCount() != 0)
2304 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2305 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2306 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2307 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2308 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2309 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2312 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2313 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2315 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2316 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2318 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2319 // DialogEnableWindow(IDOK, FALSE);
2320 // SetPromptApp(&theApp);
2322 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2324 // EnableOKButton();
2325 } // if (popup.CreatePopupMenu())
2329 bool CGitLogListBase::IsSelectionContinuous()
2331 if ( GetSelectedCount()==1 )
2333 // if only one revision is selected, the selection is of course
2334 // continuous
2335 return true;
2338 POSITION pos = GetFirstSelectedItemPosition();
2339 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2340 if (bContinuous)
2342 int itemindex = GetNextSelectedItem(pos);
2343 while (pos)
2345 int nextindex = GetNextSelectedItem(pos);
2346 if (nextindex - itemindex > 1)
2348 bContinuous = false;
2349 break;
2351 itemindex = nextindex;
2354 return bContinuous;
2357 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2360 CString sClipdata;
2361 POSITION pos = GetFirstSelectedItemPosition();
2362 if (pos != NULL)
2364 CString sRev;
2365 sRev.LoadString(IDS_LOG_REVISION);
2366 CString sAuthor;
2367 sAuthor.LoadString(IDS_LOG_AUTHOR);
2368 CString sDate;
2369 sDate.LoadString(IDS_LOG_DATE);
2370 CString sMessage;
2371 sMessage.LoadString(IDS_LOG_MESSAGE);
2372 bool first = true;
2373 while (pos)
2375 CString sLogCopyText;
2376 CString sPaths;
2377 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2379 if (toCopy == ID_COPY_ALL)
2381 //pLogEntry->GetFiles(this)
2382 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2384 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2385 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2387 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2388 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2390 CString rename;
2391 rename.Format(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2392 sPaths += _T(' ');
2393 sPaths += rename;
2395 sPaths += _T("\r\n");
2397 sPaths.Trim();
2398 CString body = pLogEntry->GetBody();
2399 body.Replace(_T("\n"), _T("\r\n"));
2400 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"),
2401 (LPCTSTR)sRev, (LPCTSTR)pLogEntry->m_CommitHash.ToString(),
2402 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2403 (LPCTSTR)sDate,
2404 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2405 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->GetSubjectBody(true),
2406 (LPCTSTR)sPaths);
2407 sClipdata += sLogCopyText;
2409 else if (toCopy == ID_COPY_MESSAGE)
2411 sClipdata += _T("* ");
2412 sClipdata += pLogEntry->GetSubjectBody(true);
2413 sClipdata += _T("\r\n\r\n");
2415 else if (toCopy == ID_COPY_SUBJECT)
2417 sClipdata += _T("* ");
2418 sClipdata += pLogEntry->GetSubject().Trim();
2419 sClipdata += _T("\r\n\r\n");
2421 else
2423 if (!first)
2424 sClipdata += _T("\r\n");
2425 sClipdata += pLogEntry->m_CommitHash;
2428 first = false;
2430 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2435 void CGitLogListBase::DiffSelectedRevWithPrevious()
2437 if (m_bThreadRunning)
2438 return;
2440 int FirstSelect=-1, LastSelect=-1;
2441 POSITION pos = GetFirstSelectedItemPosition();
2442 FirstSelect = GetNextSelectedItem(pos);
2443 while(pos)
2445 LastSelect = GetNextSelectedItem(pos);
2448 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2450 #if 0
2451 UpdateLogInfoLabel();
2452 int selIndex = m_LogList.GetSelectionMark();
2453 if (selIndex < 0)
2454 return;
2455 int selCount = m_LogList.GetSelectedCount();
2456 if (selCount != 1)
2457 return;
2459 // Find selected entry in the log list
2460 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2461 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2462 long rev1 = pLogEntry->Rev;
2463 long rev2 = rev1-1;
2464 CTGitPath path = m_path;
2466 // See how many files under the relative root were changed in selected revision
2467 int nChanged = 0;
2468 LogChangedPath * changed = NULL;
2469 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2471 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2472 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2474 ++nChanged;
2475 changed = cpath;
2479 if (m_path.IsDirectory() && nChanged == 1)
2481 // We're looking at the log for a directory and only one file under dir was changed in the revision
2482 // Do diff on that file instead of whole directory
2483 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2486 m_bCancelled = FALSE;
2487 DialogEnableWindow(IDOK, FALSE);
2488 SetPromptApp(&theApp);
2489 theApp.DoWaitCursor(1);
2491 if (PromptShown())
2493 GitDiff diff(this, m_hWnd, true);
2494 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2495 diff.SetHEADPeg(m_LogRevision);
2496 diff.ShowCompare(path, rev2, path, rev1);
2498 else
2500 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2503 theApp.DoWaitCursor(-1);
2504 EnableOKButton();
2505 #endif
2508 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2510 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2511 *pResult = -1;
2513 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2514 return;
2515 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2516 return;
2517 if (pFindInfo->lvfi.psz == 0)
2518 return;
2519 #if 0
2520 CString sCmp = pFindInfo->lvfi.psz;
2521 CString sRev;
2522 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2524 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2525 sRev.Format(_T("%ld"), pLogEntry->Rev);
2526 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2528 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2530 *pResult = i;
2531 return;
2534 else
2536 if (sCmp.Compare(sRev)==0)
2538 *pResult = i;
2539 return;
2543 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2545 for (int i=0; i<pFindInfo->iStart; ++i)
2547 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2548 sRev.Format(_T("%ld"), pLogEntry->Rev);
2549 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2551 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2553 *pResult = i;
2554 return;
2557 else
2559 if (sCmp.Compare(sRev)==0)
2561 *pResult = i;
2562 return;
2567 #endif
2568 *pResult = -1;
2571 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2573 ClearText();
2575 this->m_arShownList.SafeRemoveAll();
2577 this->m_logEntries.ClearAll();
2578 if (this->m_logEntries.ParserFromLog(path, 0, info, range))
2579 return -1;
2581 SetItemCountEx((int)m_logEntries.size());
2583 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2585 if(m_IsOldFirst)
2587 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2588 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2591 else
2593 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2594 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2598 ReloadHashMap();
2600 if(path)
2601 m_Path=*path;
2602 return 0;
2606 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2608 ClearText();
2610 m_arShownList.SafeRemoveAll();
2612 m_logEntries.ClearAll();
2613 if (m_logEntries.Fill(hashes))
2614 return -1;
2616 SetItemCountEx((int)m_logEntries.size());
2618 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2620 if (m_IsOldFirst)
2622 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2623 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2625 else
2627 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2628 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2632 ReloadHashMap();
2634 return 0;
2637 int CGitLogListBase::BeginFetchLog()
2639 ClearText();
2641 this->m_arShownList.SafeRemoveAll();
2643 this->m_logEntries.ClearAll();
2645 this->m_LogCache.ClearAllParent();
2647 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2649 CTGitPath *path;
2650 if(this->m_Path.IsEmpty())
2651 path=NULL;
2652 else
2653 path=&this->m_Path;
2655 int mask;
2656 mask = CGit::LOG_INFO_ONLY_HASH;
2657 if (m_bIncludeBoundaryCommits)
2658 mask |= CGit::LOG_INFO_BOUNDARY;
2659 // if(this->m_bAllBranch)
2660 mask |= m_ShowMask ;
2662 if(m_bShowWC)
2664 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2665 ResetWcRev();
2666 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2669 if (m_sRange.IsEmpty())
2670 m_sRange = _T("HEAD");
2672 #if 0 /* use tortoiegit filter */
2673 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2674 data.m_Author = this->m_sFilterText;
2676 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2677 data.m_MessageFilter = this->m_sFilterText;
2679 data.m_IsRegex = m_bFilterWithRegex;
2680 #endif
2682 // follow does not work for directories
2683 if (!path || path->IsDirectory())
2684 mask &= ~CGit::LOG_INFO_FOLLOW;
2685 // follow does not work with all branches 8at least in TGit)
2686 if (mask & CGit::LOG_INFO_FOLLOW)
2687 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2689 CString cmd = g_Git.GetLogCmd(m_sRange, path, mask, true, &m_Filter);
2691 //this->m_logEntries.ParserFromLog();
2692 if(IsInWorkingThread())
2694 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2696 else
2698 SetItemCountEx((int)m_logEntries.size());
2703 [] { git_init(); } ();
2705 catch (char* msg)
2707 CString err(msg);
2708 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2709 return -1;
2712 if (!g_Git.CanParseRev(m_sRange))
2714 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2715 return 0;
2717 // if show all branches, pick any ref as dummy entry ref
2718 STRING_VECTOR list;
2719 if (g_Git.GetRefList(list))
2720 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2721 if (list.size() == 0)
2722 return 0;
2724 cmd = g_Git.GetLogCmd(list[0], path, mask, true, &m_Filter);
2727 g_Git.m_critGitDllSec.Lock();
2728 try {
2729 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2731 g_Git.m_critGitDllSec.Unlock();
2732 return -1;
2735 catch (char* msg)
2737 g_Git.m_critGitDllSec.Unlock();
2738 CString err(msg);
2739 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2740 return -1;
2742 g_Git.m_critGitDllSec.Unlock();
2744 return 0;
2747 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2749 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2751 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2753 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2755 DiffSelectedRevWithPrevious();
2756 return TRUE;
2759 #if 0
2760 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2762 DiffSelectedFile();
2763 return TRUE;
2765 #endif
2767 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2769 // select all entries
2770 for (int i=0; i<GetItemCount(); ++i)
2772 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2774 return TRUE;
2777 #if 0
2778 if (m_hAccel && !bSkipAccelerator)
2780 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2781 if (ret)
2782 return TRUE;
2785 #endif
2786 //m_tooltips.RelayEvent(pMsg);
2787 return __super::PreTranslateMessage(pMsg);
2790 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2792 // a double click on an entry in the revision list has happened
2793 *pResult = 0;
2795 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2796 DiffSelectedRevWithPrevious();
2799 int CGitLogListBase::FetchLogAsync(void * data)
2801 ReloadHashMap();
2802 m_ProcData=data;
2803 m_bExitThread=FALSE;
2804 InterlockedExchange(&m_bThreadRunning, TRUE);
2805 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2806 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2807 if (m_LoadingThread ==NULL)
2809 InterlockedExchange(&m_bThreadRunning, FALSE);
2810 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2811 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2812 return -1;
2814 return 0;
2817 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2819 return ((CGitLogListBase*)pVoid)->LogThread();
2822 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2824 //CTime time;
2825 oldest=CTime::GetCurrentTime();
2826 latest=CTime(1971,1,2,0,0,0);
2827 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2829 if(m_logEntries[i].IsEmpty())
2830 continue;
2832 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() < oldest.GetTime())
2833 oldest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2835 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() > latest.GetTime())
2836 latest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2840 if(latest<oldest)
2841 latest=oldest;
2844 UINT CGitLogListBase::LogThread()
2846 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2848 InterlockedExchange(&m_bThreadRunning, TRUE);
2849 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2851 ULONGLONG t1,t2;
2853 if(BeginFetchLog())
2855 InterlockedExchange(&m_bThreadRunning, FALSE);
2856 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2858 return 1;
2861 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2862 bool bRegex = false;
2863 if (m_bFilterWithRegex)
2864 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2866 TRACE(_T("\n===Begin===\n"));
2867 //Update work copy item;
2869 if (!m_logEntries.empty())
2871 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2873 m_arShownList.SafeAdd(pRev);
2877 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2879 // store commit number of the last selected commit/line before the refresh or -1
2880 int lastSelectedHashNItem = -1;
2881 if (m_lastSelectedHash.IsEmpty())
2882 lastSelectedHashNItem = 0;
2884 int ret = 0;
2886 bool shouldWalk = true;
2887 if (!g_Git.CanParseRev(m_sRange))
2889 // walk revisions if show all branches and there exists any ref
2890 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2891 shouldWalk = false;
2892 else
2894 STRING_VECTOR list;
2895 if (g_Git.GetRefList(list))
2896 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2897 if (list.size() == 0)
2898 shouldWalk = false;
2902 if (shouldWalk)
2904 g_Git.m_critGitDllSec.Lock();
2905 int total = 0;
2908 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2909 total = git_get_log_estimate_commit_count(m_DllGitLog);
2911 catch (char* msg)
2913 CString err(msg);
2914 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2915 ret = -1;
2917 g_Git.m_critGitDllSec.Unlock();
2919 GIT_COMMIT commit;
2920 t2=t1=GetTickCount();
2921 int oldprecentage = 0;
2922 size_t oldsize = m_logEntries.size();
2923 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2924 while (ret== 0 && !m_bExitThread)
2926 g_Git.m_critGitDllSec.Lock();
2929 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2931 catch (char* msg)
2933 g_Git.m_critGitDllSec.Unlock();
2934 CString err(msg);
2935 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2936 break;
2938 g_Git.m_critGitDllSec.Unlock();
2940 if(ret)
2942 if (ret != -2) // other than end of revision walking
2943 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2944 break;
2947 if (commit.m_ignore == 1)
2949 git_free_commit(&commit);
2950 continue;
2953 //printf("%s\r\n",commit.GetSubject());
2954 if(m_bExitThread)
2955 break;
2957 CGitHash hash = (char*)commit.m_hash ;
2959 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2960 pRev->m_GitCommit = commit;
2961 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2963 char *note=NULL;
2964 g_Git.m_critGitDllSec.Lock();
2967 git_get_notes(commit.m_hash, &note);
2969 catch (char* msg)
2971 g_Git.m_critGitDllSec.Unlock();
2972 CString err(msg);
2973 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2974 break;
2976 g_Git.m_critGitDllSec.Unlock();
2978 if(note)
2980 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2981 free(note);
2982 note = nullptr;
2985 if(!pRev->m_IsDiffFiles)
2987 pRev->m_CallDiffAsync = DiffAsync;
2990 pRev->ParserParentFromCommit(&commit);
2991 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2993 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2995 const CGitHash &parentHash = pRev->m_ParentHash[i];
2996 auto it = commitChildren.find(parentHash);
2997 if (it == commitChildren.end())
2999 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
3001 it->second.insert(pRev->m_CommitHash);
3005 #ifdef DEBUG
3006 pRev->DbgPrint();
3007 TRACE(_T("\n"));
3008 #endif
3010 bool visible = true;
3011 if (HasFilterText())
3013 if(!IsMatchFilter(bRegex,pRev,pat))
3014 visible = false;
3016 if (visible && !ShouldShowFilter(pRev, commitChildren))
3017 visible = false;
3018 this->m_critSec.Lock();
3019 m_logEntries.append(hash, visible);
3020 if (visible)
3021 m_arShownList.SafeAdd(pRev);
3022 this->m_critSec.Unlock();
3024 if (!visible)
3025 continue;
3027 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3028 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3030 t2=GetTickCount();
3032 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3034 //update UI
3035 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3036 if(percent > 99)
3037 percent =99;
3038 if(percent < GITLOG_START)
3039 percent = GITLOG_START +1;
3041 oldsize = m_logEntries.size();
3042 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3044 //if( percent > oldprecentage )
3046 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3047 oldprecentage = percent;
3050 if (lastSelectedHashNItem >= 0)
3051 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3053 t1 = t2;
3056 g_Git.m_critGitDllSec.Lock();
3057 git_close_log(m_DllGitLog);
3058 g_Git.m_critGitDllSec.Unlock();
3062 if (m_bExitThread)
3064 InterlockedExchange(&m_bThreadRunning, FALSE);
3065 return 0;
3068 //Update UI;
3069 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3071 if (lastSelectedHashNItem >= 0)
3072 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3074 if (this->m_hWnd)
3075 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3077 InterlockedExchange(&m_bThreadRunning, FALSE);
3079 return 0;
3082 void CGitLogListBase::FetchRemoteList()
3084 STRING_VECTOR remoteList;
3085 m_SingleRemote.Empty();
3086 if (!g_Git.GetRemoteList(remoteList) && remoteList.size() == 1)
3087 m_SingleRemote = remoteList[0];
3090 void CGitLogListBase::FetchTrackingBranchList()
3092 m_TrackingMap.clear();
3093 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3095 for (size_t j = 0; j < it->second.size(); ++j)
3097 CString branchName;
3098 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3100 CString pullRemote, pullBranch;
3101 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3102 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3104 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3111 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3113 SafeTerminateThread();
3115 this->SetItemCountEx(0);
3116 this->Clear();
3118 ResetWcRev();
3120 // HACK to hide graph column
3121 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3122 SetColumnWidth(0, 0);
3123 else
3124 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3126 //Update branch and Tag info
3127 ReloadHashMap();
3128 if (m_pFindDialog)
3129 m_pFindDialog->RefreshList();
3130 //Assume Thread have exited
3131 //if(!m_bThreadRunning)
3133 m_logEntries.clear();
3135 if(IsCleanFilter)
3137 m_sFilterText.Empty();
3140 InterlockedExchange(&m_bExitThread,FALSE);
3142 InterlockedExchange(&m_bThreadRunning, TRUE);
3143 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3145 SafeTerminateAsyncDiffThread();
3146 m_AsynDiffListLock.Lock();
3147 m_AsynDiffList.clear();
3148 m_AsynDiffListLock.Unlock();
3149 InterlockedExchange(&m_AsyncThreadExit, FALSE);
3150 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL, 0, CREATE_SUSPENDED);
3151 if (!m_DiffingThread)
3152 CMessageBox::Show(nullptr, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3153 else
3155 m_DiffingThread->m_bAutoDelete = FALSE;
3156 m_DiffingThread->ResumeThread();
3158 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3160 InterlockedExchange(&m_bThreadRunning, FALSE);
3161 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3162 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3166 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3170 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3171 if (!bMatchCase)
3172 type |= std::tr1::regex_constants::icase;
3173 pat = std::tr1::wregex(regexp_str, type);
3174 return true;
3176 catch (std::exception) {}
3177 return false;
3179 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3181 BOOL result = TRUE;
3182 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3183 CString sRev;
3185 if ((bRegex)&&(m_bFilterWithRegex))
3187 if (m_SelectedFilters & LOGFILTER_BUGID)
3189 if(this->m_bShowBugtraqColumn)
3191 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3193 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3194 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3196 return TRUE;
3201 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3203 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3204 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3206 return TRUE;
3210 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3212 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3213 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3215 return TRUE;
3219 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3221 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3223 return TRUE;
3226 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3228 return TRUE;
3232 if (m_SelectedFilters & LOGFILTER_EMAILS)
3234 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3236 return TRUE;
3239 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3241 return TRUE;
3245 if (m_SelectedFilters & LOGFILTER_REVS)
3247 sRev = pRev->m_CommitHash.ToString();
3248 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3250 return TRUE;
3254 if (m_SelectedFilters & LOGFILTER_REFNAME)
3256 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3257 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3259 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3261 return TRUE;
3266 if (m_SelectedFilters & LOGFILTER_PATHS)
3268 CTGitPathList *pathList=NULL;
3269 if( pRev->m_IsDiffFiles)
3270 pathList = &pRev->GetFiles(this);
3271 else
3273 if(!pRev->m_IsSimpleListReady)
3274 pRev->SafeGetSimpleList(&g_Git);
3277 if(pathList)
3278 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3280 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3282 return true;
3284 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3286 return true;
3290 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3292 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3294 return true;
3299 else
3301 CString find = m_sFilterText;
3302 if (!m_bFilterCaseSensitively)
3303 find.MakeLower();
3304 result = find[0] == '!' ? FALSE : TRUE;
3305 if (!result)
3306 find = find.Mid(1);
3308 if (m_SelectedFilters & LOGFILTER_BUGID)
3310 if(this->m_bShowBugtraqColumn)
3312 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3314 if (!m_bFilterCaseSensitively)
3315 sBugIds.MakeLower();
3316 if ((sBugIds.Find(find) >= 0))
3318 return result;
3323 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3325 CString msg = pRev->GetSubject();
3327 if (!m_bFilterCaseSensitively)
3328 msg = msg.MakeLower();
3329 if ((msg.Find(find) >= 0))
3331 return result;
3335 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3337 CString msg = pRev->GetBody();
3339 if (!m_bFilterCaseSensitively)
3340 msg = msg.MakeLower();
3341 if ((msg.Find(find) >= 0))
3343 return result;
3347 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3349 CString msg = pRev->GetAuthorName();
3350 if (!m_bFilterCaseSensitively)
3351 msg = msg.MakeLower();
3352 if ((msg.Find(find) >= 0))
3354 return result;
3358 if (m_SelectedFilters & LOGFILTER_EMAILS)
3360 CString msg = pRev->GetAuthorEmail();
3361 if (!m_bFilterCaseSensitively)
3362 msg = msg.MakeLower();
3363 if ((msg.Find(find) >= 0))
3365 return result;
3369 if (m_SelectedFilters & LOGFILTER_REVS)
3371 sRev = pRev->m_CommitHash.ToString();
3372 if ((sRev.Find(find) >= 0))
3374 return result;
3378 if (m_SelectedFilters & LOGFILTER_REFNAME)
3380 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3381 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3383 if (it->Find(find) >= 0)
3385 return result;
3390 if (m_SelectedFilters & LOGFILTER_PATHS)
3392 CTGitPathList *pathList=NULL;
3393 if( pRev->m_IsDiffFiles)
3394 pathList = &pRev->GetFiles(this);
3395 else
3397 if(!pRev->m_IsSimpleListReady)
3398 pRev->SafeGetSimpleList(&g_Git);
3400 if(pathList)
3401 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3403 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3404 CString path = cpath->GetGitOldPathString();
3405 if (!m_bFilterCaseSensitively)
3406 path.MakeLower();
3407 if ((path.Find(find)>=0))
3409 return result;
3411 path = cpath->GetGitPathString();
3412 if (!m_bFilterCaseSensitively)
3413 path.MakeLower();
3414 if ((path.Find(find)>=0))
3416 return result;
3420 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3422 CString path = pRev->m_SimpleFileList[i];
3423 if (!m_bFilterCaseSensitively)
3424 path.MakeLower();
3425 if ((path.Find(find)>=0))
3427 return result;
3431 } // else (from if (bRegex))
3432 return !result;
3435 static bool CStringStartsWith(const CString &str, const CString &prefix)
3437 return str.Left(prefix.GetLength()) == prefix;
3439 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3441 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3442 return true;
3444 if (m_ShowFilter & FILTERSHOW_REFS)
3446 // Keep all refs.
3447 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3448 for (size_t i = 0; i < refList.size(); ++i)
3450 const CString &str = refList[i];
3451 if (CStringStartsWith(str, _T("refs/heads/")))
3453 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3454 return true;
3456 else if (CStringStartsWith(str, _T("refs/remotes/")))
3458 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3459 return true;
3461 else if (CStringStartsWith(str, _T("refs/tags/")))
3463 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3464 return true;
3466 else if (CStringStartsWith(str, _T("refs/stash")))
3468 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3469 return true;
3471 else if (CStringStartsWith(str, _T("refs/bisect/")))
3473 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3474 return true;
3477 // Keep the head too.
3478 if (pRev->m_CommitHash == m_HeadHash)
3479 return true;
3482 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3484 if (pRev->ParentsCount() > 1)
3485 return true;
3486 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3487 if (childrenIt != commitChildren.end())
3489 const std::set<CGitHash> &children = childrenIt->second;
3490 if (children.size() > 1)
3491 return true;
3494 return false;
3497 void CGitLogListBase::ShowGraphColumn(bool bShow)
3499 // HACK to hide graph column
3500 if (bShow)
3501 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3502 else
3503 SetColumnWidth(0, 0);
3506 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3508 CString cmd;
3509 CString output;
3511 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3513 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3514 for (size_t i = 0; i < vector.size(); ++i)
3516 if (vector[i].Find(_T("refs/tags/")) == 0)
3518 CString tag = vector[i];
3519 int start = vector[i].Find(_T("^{}"));
3520 if (start > 0)
3521 tag = tag.Left(start);
3522 else
3523 continue;
3525 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3526 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3527 output.AppendChar(_T('\n'));
3532 return output;
3535 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3538 pShownlist->SafeRemoveAll();
3540 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3541 bool bRegex = false;
3542 if (m_bFilterWithRegex)
3543 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3545 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3546 CString sRev;
3547 for (DWORD i=0; i<m_logEntries.size(); ++i)
3549 if ((bRegex)&&(m_bFilterWithRegex))
3551 #if 0
3552 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3554 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3555 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3557 pShownlist->SafeAdd(m_logEntries[i]);
3558 continue;
3561 #endif
3562 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3564 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3565 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3567 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3568 continue;
3571 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3573 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3574 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3576 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3577 continue;
3580 if (m_SelectedFilters & LOGFILTER_PATHS)
3582 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3584 bool bGoing = true;
3585 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3587 CTGitPath cpath = pathList[cpPathIndex];
3588 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3590 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3591 bGoing = false;
3592 continue;
3594 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3596 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3597 bGoing = false;
3598 continue;
3600 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3602 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3603 bGoing = false;
3604 continue;
3608 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3610 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3612 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3613 continue;
3616 if (m_SelectedFilters & LOGFILTER_EMAILS)
3618 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3620 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3621 continue;
3624 if (m_SelectedFilters & LOGFILTER_REVS)
3626 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3627 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3629 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3630 continue;
3633 if (m_SelectedFilters & LOGFILTER_REFNAME)
3635 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3636 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3638 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3640 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3641 continue;
3645 } // if (bRegex)
3646 else
3648 CString find = m_sFilterText;
3649 if (!m_bFilterCaseSensitively)
3650 find.MakeLower();
3651 #if 0
3652 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3654 CString sBugIDs = m_logEntries[i]->sBugIDs;
3656 if (!m_bFilterCaseSensitively)
3657 sBugIDs = sBugIDs.MakeLower();
3658 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3660 pShownlist->SafeAdd(m_logEntries[i]);
3661 continue;
3664 #endif
3665 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3667 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3669 if (!m_bFilterCaseSensitively)
3670 msg = msg.MakeLower();
3671 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3673 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3674 continue;
3677 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3679 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3681 if (!m_bFilterCaseSensitively)
3682 msg = msg.MakeLower();
3683 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3685 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3686 continue;
3689 if (m_SelectedFilters & LOGFILTER_PATHS)
3691 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3693 bool bGoing = true;
3694 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3696 CTGitPath cpath = pathList[cpPathIndex];
3697 CString path = cpath.GetGitOldPathString();
3698 if (!m_bFilterCaseSensitively)
3699 path.MakeLower();
3700 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3702 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3703 bGoing = false;
3704 continue;
3706 path = cpath.GetGitPathString();
3707 if (!m_bFilterCaseSensitively)
3708 path.MakeLower();
3709 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3711 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3712 bGoing = false;
3713 continue;
3715 path = cpath.GetActionName();
3716 if (!m_bFilterCaseSensitively)
3717 path.MakeLower();
3718 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3720 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3721 bGoing = false;
3722 continue;
3726 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3728 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3729 if (!m_bFilterCaseSensitively)
3730 msg = msg.MakeLower();
3731 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3733 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3734 continue;
3737 if (m_SelectedFilters & LOGFILTER_EMAILS)
3739 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3740 if (!m_bFilterCaseSensitively)
3741 msg = msg.MakeLower();
3742 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3744 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3745 continue;
3748 if (m_SelectedFilters & LOGFILTER_REVS)
3750 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3751 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3753 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3754 continue;
3757 if (m_SelectedFilters & LOGFILTER_REFNAME)
3759 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3760 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3762 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3764 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3765 continue;
3769 } // else (from if (bRegex))
3770 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3774 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3777 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3779 if(m_From == -1)
3780 if(m_To == -1)
3781 return true;
3782 else
3783 return time <= m_To;
3784 else
3785 if(m_To == -1)
3786 return time >= m_From;
3787 else
3788 return ((time >= m_From)&&(time <= m_To));
3790 return TRUE; /* git dll will filter time range */
3792 // return TRUE;
3794 void CGitLogListBase::StartFilter()
3796 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3797 RecalculateShownList(&m_arShownList);
3798 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3801 DeleteAllItems();
3802 SetItemCountEx(ShownCountWithStopped());
3803 RedrawItems(0, ShownCountWithStopped());
3804 Invalidate();
3807 void CGitLogListBase::RemoveFilter()
3810 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3812 m_arShownList.SafeRemoveAll();
3814 // reset the time filter too
3815 #if 0
3816 m_timFrom = (__time64_t(m_tFrom));
3817 m_timTo = (__time64_t(m_tTo));
3818 m_DateFrom.SetTime(&m_timFrom);
3819 m_DateTo.SetTime(&m_timTo);
3820 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3821 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3822 #endif
3824 for (DWORD i=0; i<m_logEntries.size(); ++i)
3826 if(this->m_IsOldFirst)
3828 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3830 else
3832 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3835 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3836 DeleteAllItems();
3837 SetItemCountEx(ShownCountWithStopped());
3838 RedrawItems(0, ShownCountWithStopped());
3840 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3843 void CGitLogListBase::Clear()
3845 m_arShownList.SafeRemoveAll();
3846 DeleteAllItems();
3848 m_logEntries.ClearAll();
3852 void CGitLogListBase::OnDestroy()
3854 // save the column widths to the registry
3855 SaveColumnWidths();
3857 SafeTerminateThread();
3858 SafeTerminateAsyncDiffThread();
3860 int retry = 0;
3861 while(m_LogCache.SaveCache())
3863 if(retry > 5)
3864 break;
3865 Sleep(1000);
3867 ++retry;
3869 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3870 // MB_YESNO) == IDNO)
3871 // break;
3874 CHintListCtrl::OnDestroy();
3877 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3879 CRect rect;
3880 int i=(int)wParam;
3881 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3882 this->InvalidateRect(rect);
3884 return 0;
3888 * Save column widths to the registry
3890 void CGitLogListBase::SaveColumnWidths()
3892 int maxcol = m_ColumnManager.GetColumnCount();
3894 // HACK that graph column is always shown
3895 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3897 for (int col = 0; col < maxcol; ++col)
3898 if (m_ColumnManager.IsVisible (col))
3899 m_ColumnManager.ColumnResized (col);
3901 m_ColumnManager.WriteSettings();
3904 int CGitLogListBase::GetHeadIndex()
3906 if(m_HeadHash.IsEmpty())
3907 return -1;
3909 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3911 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3912 if(pRev)
3914 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3915 return i;
3918 return -1;
3920 void CGitLogListBase::OnFind()
3922 if (!m_pFindDialog)
3924 m_pFindDialog = new CFindDlg(this);
3925 m_pFindDialog->Create(this);
3928 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3930 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3932 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3934 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3935 Default();
3937 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3939 if (GetSelectedCount() != 0)
3940 return 0;
3942 CGitHash theSelectedHash = m_lastSelectedHash;
3943 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3944 m_lastSelectedHash = theSelectedHash;
3946 int countPerPage = GetCountPerPage();
3947 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3948 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3949 EnsureVisible((int)itemToSelect, FALSE);
3950 return 0;
3952 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3955 ASSERT(m_pFindDialog != NULL);
3956 bool bFound = false;
3957 int i=0;
3959 if (m_pFindDialog->IsTerminating())
3961 // invalidate the handle identifying the dialog box.
3962 m_pFindDialog = NULL;
3963 return 0;
3966 INT_PTR cnt = m_arShownList.GetCount();
3968 if(m_pFindDialog->IsRef())
3970 CString str;
3971 str=m_pFindDialog->GetFindString();
3973 CGitHash hash;
3975 if(!str.IsEmpty())
3977 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3978 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3981 if(!hash.IsEmpty())
3983 for (i = 0; i < cnt; ++i)
3985 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3986 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3988 bFound = true;
3989 break;
3993 if (!bFound)
3995 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3996 return 0;
4000 if (m_pFindDialog->FindNext() && !bFound)
4002 //read data from dialog
4003 CString findText = m_pFindDialog->GetFindString();
4004 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
4006 std::tr1::wregex pat;
4007 bool bRegex = false;
4008 if (m_pFindDialog->Regex())
4009 bRegex = ValidateRegexp(findText, pat, bMatchCase);
4011 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
4013 for (i = m_nSearchIndex + 1; ; ++i)
4015 if (i >= cnt)
4017 i = 0;
4018 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
4020 if (m_nSearchIndex >= 0)
4022 if (i == m_nSearchIndex)
4024 ::MessageBeep(0xFFFFFFFF);
4025 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
4026 break;
4030 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
4032 CString str;
4033 str+=pLogEntry->m_CommitHash.ToString();
4034 str += _T('\n');
4036 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4038 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4039 str += _T('\n');
4042 str+=pLogEntry->GetAuthorEmail();
4043 str += _T('\n');
4044 str+=pLogEntry->GetAuthorName();
4045 str += _T('\n');
4046 str+=pLogEntry->GetBody();
4047 str += _T('\n');
4048 str+=pLogEntry->GetCommitterEmail();
4049 str += _T('\n');
4050 str+=pLogEntry->GetCommitterName();
4051 str += _T('\n');
4052 str+=pLogEntry->GetSubject();
4053 str += _T('\n');
4054 str+=pLogEntry->m_Notes;
4055 str += _T('\n');
4056 str+=GetTagInfo(pLogEntry);
4057 str += _T('\n');
4060 /*Because changed files list is loaded on demand when gui show,
4061 files will empty when files have not fetched.
4063 we can add it back by using one-way diff(with outnumber changed and rename detect.
4064 here just need changed filename list. one-way is much quicker.
4066 if(pLogEntry->m_IsFull)
4068 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4070 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4071 str += _T('\n');
4072 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4073 str += _T('\n');
4076 else
4078 if(!pLogEntry->m_IsSimpleListReady)
4079 pLogEntry->SafeGetSimpleList(&g_Git);
4081 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4083 str += pLogEntry->m_SimpleFileList[j];
4084 str += _T('\n');
4090 if (bRegex)
4092 if (std::regex_search(std::wstring(str), pat, flags))
4094 bFound = true;
4095 break;
4098 else
4100 if (bMatchCase)
4102 if (str.Find(findText) >= 0)
4104 bFound = true;
4105 break;
4109 else
4111 CString msg = str;
4112 msg = msg.MakeLower();
4113 CString find = findText.MakeLower();
4114 if (msg.Find(find) >= 0)
4116 bFound = TRUE;
4117 break;
4121 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4123 } // if(m_pFindDialog->FindNext())
4124 //UpdateLogInfoLabel();
4126 if (bFound)
4128 m_nSearchIndex = i;
4129 EnsureVisible(i, FALSE);
4130 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4132 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4133 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4134 SetSelectionMark(i);
4136 else
4138 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4139 if (pLogEntry)
4140 m_highlight = pLogEntry->m_CommitHash;
4142 Invalidate();
4143 //FillLogMessageCtrl();
4144 UpdateData(FALSE);
4147 return 0;
4150 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4152 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4154 *pResult = FALSE;
4157 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4159 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4161 Invalidate(FALSE);
4164 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4166 LVHITTESTINFO lvhitTestInfo;
4168 lvhitTestInfo.pt = point;
4170 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4171 int nSubItem = lvhitTestInfo.iSubItem;
4173 UINT nFlags = lvhitTestInfo.flags;
4175 // nFlags is 0 if the SubItemHitTest fails
4176 // Therefore, 0 & <anything> will equal false
4177 if (nFlags & LVHT_ONITEM)
4179 // Get the client area occupied by this control
4180 RECT rcClient;
4181 GetClientRect(&rcClient);
4183 // Fill in the TOOLINFO structure
4184 pTI->hwnd = m_hWnd;
4185 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4186 pTI->lpszText = LPSTR_TEXTCALLBACK;
4187 pTI->rect = rcClient;
4189 return pTI->uId; // By returning a unique value per listItem,
4190 // we ensure that when the mouse moves over another list item,
4191 // the tooltip will change
4193 else
4195 // Otherwise, we aren't interested, so let the message propagate
4196 return -1;
4200 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4202 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4203 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4205 *pResult = 0;
4207 // Ignore messages from the built in tooltip, we are processing them internally
4208 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4209 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4210 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4211 return FALSE;
4213 // Get the mouse position
4214 const MSG* pMessage = GetCurrentMessage();
4216 CPoint pt;
4217 pt = pMessage->pt;
4218 ScreenToClient(&pt);
4220 // Check if the point falls onto a list item
4221 LVHITTESTINFO lvhitTestInfo;
4222 lvhitTestInfo.pt = pt;
4224 int nItem = SubItemHitTest(&lvhitTestInfo);
4226 if (lvhitTestInfo.flags & LVHT_ONITEM)
4228 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4229 if (strTipText.IsEmpty())
4230 return FALSE;
4232 // we want multiline tooltips
4233 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4235 wcscpy_s(m_wszTip, strTipText);
4236 // handle Unicode as well as non-Unicode requests
4237 if (pNMHDR->code == TTN_NEEDTEXTA)
4239 pTTTA->hinst = nullptr;
4240 pTTTA->lpszText = m_szTip;
4241 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4243 else
4245 pTTTW->hinst = nullptr;
4246 pTTTW->lpszText = m_wszTip;
4249 CRect rect;
4250 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4251 ClientToScreen(rect);
4252 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4254 return TRUE; // We found a tool tip,
4255 // tell the framework this message has been handled
4258 return FALSE; // We didn't handle the message,
4259 // let the framework continue propagating the message
4262 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4264 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4266 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4267 if (pLogEntry == nullptr)
4268 return CString();
4269 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4270 return CString();
4271 return pLogEntry->GetSubject();
4273 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4275 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4276 if (pLogEntry == nullptr)
4277 return CString();
4278 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4280 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4282 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4283 if (pLogEntry == nullptr)
4284 return CString();
4285 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4287 else if (nSubItem == LOGLIST_ACTION)
4289 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4290 if (pLogEntry == nullptr)
4291 return CString();
4293 if (!pLogEntry->m_IsDiffFiles)
4294 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4296 int actions = pLogEntry->GetAction(this);
4297 CString sToolTipText;
4299 CString actionText;
4300 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4301 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4303 if (actions & CTGitPath::LOGACTIONS_ADDED)
4305 if (!actionText.IsEmpty())
4306 actionText += L"\r\n";
4307 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4310 if (actions & CTGitPath::LOGACTIONS_DELETED)
4312 if (!actionText.IsEmpty())
4313 actionText += L"\r\n";
4314 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4317 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4319 if (!actionText.IsEmpty())
4320 actionText += L"\r\n";
4321 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4324 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4326 if (!actionText.IsEmpty())
4327 actionText += L"\r\n";
4328 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4331 if (!actionText.IsEmpty())
4333 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4334 sToolTipText = sTitle + L":\r\n" + actionText;
4336 return sToolTipText;
4338 return CString();