No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobf9d55829596b9fdf6b253064377f1517146d800e
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_pStoreSelection(NULL)
53 , m_SelectedFilters(LOGFILTER_ALL)
54 , m_ShowFilter(FILTERSHOW_ALL)
55 , m_bShowWC(false)
56 , m_logEntries(&m_LogCache)
57 , m_pFindDialog(NULL)
58 , m_ColumnManager(this)
59 , m_dwDefaultColumns(0)
60 , m_arShownList(&m_critSec)
61 , m_hasWC(true)
62 , m_bNoHightlightHead(FALSE)
63 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
64 , m_bFullCommitMessageOnLogLine(false)
66 // use the default GUI font, create a copy of it and
67 // change the copy to BOLD (leave the rest of the font
68 // the same)
69 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
70 LOGFONT lf = {0};
71 GetObject(hFont, sizeof(LOGFONT), &lf);
72 lf.lfWeight = FW_BOLD;
73 m_boldFont = CreateFontIndirect(&lf);
74 lf.lfWeight = FW_DONTCARE;
75 lf.lfItalic = TRUE;
76 m_FontItalics = CreateFontIndirect(&lf);
77 lf.lfWeight = FW_BOLD;
78 m_boldItalicsFont = CreateFontIndirect(&lf);
80 m_bShowBugtraqColumn=false;
82 m_IsIDReplaceAction=FALSE;
84 this->m_critSec.Init();
85 m_critSec_AsyncDiff.Init();
86 ResetWcRev(false);
88 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
89 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
90 m_hConflictedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
91 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
92 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
93 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
95 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
96 m_bFilterCaseSensitively = !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE);
98 m_Filter.m_NumberOfLogsScale = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT);
99 if (m_Filter.m_NumberOfLogsScale == CFilterData::SHOW_LAST_SEL_DATE)
101 CString key;
102 key.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR)g_Git.m_CurrentDir);
103 key.Replace(_T(':'), _T('_'));
104 CString lastSelFromDate = CRegString(key);
105 if (lastSelFromDate.GetLength() == 10)
107 CTime time = CTime(_wtoi((LPCTSTR)lastSelFromDate.Mid(0, 4)), _wtoi((LPCTSTR)lastSelFromDate.Mid(5, 2)), _wtoi((LPCTSTR)lastSelFromDate.Mid(8, 2)), 0, 0, 0);
108 m_Filter.m_From = (DWORD)time.GetTime();
111 m_Filter.m_NumberOfLogs = (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
113 m_ShowMask = 0;
114 m_LoadingThread = NULL;
116 InterlockedExchange(&m_bExitThread,FALSE);
117 m_IsOldFirst = FALSE;
118 m_IsRebaseReplaceGraph = FALSE;
120 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
122 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
124 // get short/long datetime setting from registry
125 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
126 if ( RegUseShortDateFormat )
128 m_DateFormat = DATE_SHORTDATE;
130 else
132 m_DateFormat = DATE_LONGDATE;
134 // get relative time display setting from registry
135 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
136 m_bRelativeTimes = (regRelativeTimes != 0);
137 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
139 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
140 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
141 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
142 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
143 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
144 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
145 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAMEPREVIOUS);
147 m_ColumnRegKey=_T("log");
149 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
150 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
151 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
152 m_bFullCommitMessageOnLogLine = !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE);
154 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
155 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
157 m_AsyncThreadExit = FALSE;
158 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
159 m_AsynDiffListLock.Init();
161 hUxTheme = AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
162 if (hUxTheme)
163 pfnDrawThemeTextEx = (FNDRAWTHEMETEXTEX)::GetProcAddress(hUxTheme, "DrawThemeTextEx");
165 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
166 if (m_DiffingThread ==NULL)
168 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
169 return;
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 if ( m_pStoreSelection )
293 delete m_pStoreSelection;
294 m_pStoreSelection = NULL;
297 SafeTerminateThread();
298 SafeTerminateAsyncDiffThread();
300 if(m_AsyncDiffEvent)
301 CloseHandle(m_AsyncDiffEvent);
303 if (hUxTheme)
304 FreeLibrary(hUxTheme);
308 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
309 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
310 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
311 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
312 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
313 ON_WM_CONTEXTMENU()
314 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
315 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
316 ON_WM_CREATE()
317 ON_WM_DESTROY()
318 ON_MESSAGE(MSG_LOADED,OnLoad)
319 ON_WM_MEASUREITEM()
320 ON_WM_MEASUREITEM_REFLECT()
321 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
322 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
323 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
324 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
325 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
326 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
327 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &OnToolTipText)
328 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &OnToolTipText)
329 END_MESSAGE_MAP()
331 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
333 //if (m_nRowHeight>0)
335 lpMeasureItemStruct->itemHeight = 50;
339 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
341 PreSubclassWindow();
342 return CHintListCtrl::OnCreate(lpCreateStruct);
345 void CGitLogListBase::PreSubclassWindow()
347 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
348 // load the icons for the action columns
349 // m_Theme.Open(m_hWnd, L"ListView");
350 SetWindowTheme(m_hWnd, L"Explorer", NULL);
351 CHintListCtrl::PreSubclassWindow();
354 CString CGitLogListBase::GetRebaseActionName(int action)
356 if (action & LOGACTIONS_REBASE_EDIT)
357 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT);
358 if (action & LOGACTIONS_REBASE_SQUASH)
359 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH);
360 if (action & LOGACTIONS_REBASE_PICK)
361 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK);
362 if (action & LOGACTIONS_REBASE_SKIP)
363 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP);
365 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
368 void CGitLogListBase::InsertGitColumn()
370 CString temp;
372 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
373 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
374 if (DWORD(regFullRowSelect))
375 exStyle |= LVS_EX_FULLROWSELECT;
376 SetExtendedStyle(exStyle);
378 // only load properties if we have a repository
379 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
380 UpdateProjectProperties();
382 static UINT normal[] =
384 IDS_LOG_GRAPH,
385 IDS_LOG_REBASE,
386 IDS_LOG_ID,
387 IDS_LOG_HASH,
388 IDS_LOG_ACTIONS,
389 IDS_LOG_MESSAGE,
390 IDS_LOG_AUTHOR,
391 IDS_LOG_DATE,
392 IDS_LOG_EMAIL,
393 IDS_LOG_COMMIT_NAME,
394 IDS_LOG_COMMIT_EMAIL,
395 IDS_LOG_COMMIT_DATE,
396 IDS_LOG_BUGIDS,
397 IDS_LOG_SVNREV,
400 static int with[] =
402 ICONITEMBORDER+16*4,
403 ICONITEMBORDER+16*4,
404 ICONITEMBORDER+16*4,
405 ICONITEMBORDER+16*4,
406 ICONITEMBORDER+16*4,
407 LOGLIST_MESSAGE_MIN,
408 ICONITEMBORDER+16*4,
409 ICONITEMBORDER+16*4,
410 ICONITEMBORDER+16*4,
411 ICONITEMBORDER+16*4,
412 ICONITEMBORDER+16*4,
413 ICONITEMBORDER+16*4,
414 ICONITEMBORDER+16*4,
415 ICONITEMBORDER+16*4,
417 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
419 DWORD hideColumns = 0;
420 if(this->m_IsRebaseReplaceGraph)
422 hideColumns |= GIT_LOG_GRAPH;
423 m_dwDefaultColumns |= GIT_LOG_REBASE;
425 else
427 hideColumns |= GIT_LOG_REBASE;
430 if(this->m_IsIDReplaceAction)
432 hideColumns |= GIT_LOG_ACTIONS;
433 m_dwDefaultColumns |= GIT_LOG_ID;
434 m_dwDefaultColumns |= GIT_LOG_HASH;
436 else
438 hideColumns |= GIT_LOG_ID;
440 if(this->m_bShowBugtraqColumn)
442 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
444 else
446 hideColumns |= GIT_LOGLIST_BUG;
448 if (CTGitPath(g_Git.m_CurrentDir).HasGitSVNDir())
449 m_dwDefaultColumns |= GIT_LOGLIST_SVNREV;
450 else
451 hideColumns |= GIT_LOGLIST_SVNREV;
452 SetRedraw(false);
454 m_ColumnManager.SetNames(normal, _countof(normal));
455 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
457 SetRedraw(true);
461 * Resizes all columns in a list control to values in registry.
463 void CGitLogListBase::ResizeAllListCtrlCols()
465 // column max and min widths to allow
466 static const int nMinimumWidth = 10;
467 static const int nMaximumWidth = 1000;
468 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
469 if (pHdrCtrl)
471 int numcols = pHdrCtrl->GetItemCount();
472 for (int col = 0; col < numcols; ++col)
474 // get width for this col last time from registry
475 CString regentry;
476 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR)m_ColumnRegKey, col);
477 CRegDWORD regwidth(regentry, 0);
478 int cx = regwidth;
479 if ( cx == 0 )
481 // no saved value, setup sensible defaults
482 if (col == this->LOGLIST_MESSAGE)
484 cx = LOGLIST_MESSAGE_MIN;
486 else
488 cx = ICONITEMBORDER+16*4;
491 if (cx < nMinimumWidth)
493 cx = nMinimumWidth;
495 else if (cx > nMaximumWidth)
497 cx = nMaximumWidth;
500 SetColumnWidth(col, cx);
507 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
509 LVITEM rItem;
510 SecureZeroMemory(&rItem, sizeof(LVITEM));
511 rItem.mask = LVIF_STATE;
512 rItem.iItem = (int)Index;
513 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
514 GetItem(&rItem);
516 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index);
517 HBRUSH brush = NULL;
519 if (!(rItem.state & LVIS_SELECTED))
521 int action = pLogEntry->GetRebaseAction();
522 if (action & LOGACTIONS_REBASE_SQUASH)
523 brush = ::CreateSolidBrush(RGB(156,156,156));
524 else if (action & LOGACTIONS_REBASE_EDIT)
525 brush = ::CreateSolidBrush(RGB(200,200,128));
527 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
529 if (rItem.state & LVIS_SELECTED)
531 if (::GetFocus() == m_hWnd)
532 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
533 else
534 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
537 if (brush != NULL)
539 ::FillRect(hdc, &rect, brush);
540 ::DeleteObject(brush);
544 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
546 POINT point = { 4, 4 };
547 CRect rt2 = rect;
548 rt2.DeflateRect(1, 1);
549 rt2.OffsetRect(2, 2);
551 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
552 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
553 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
554 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
555 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
557 ::SelectObject(hdc, brush);
558 rt2.OffsetRect(-2, -2);
559 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
560 ::SelectObject(hdc, oldbrush);
561 ::SelectObject(hdc, oldpen);
562 ::DeleteObject(nullPen);
563 ::DeleteObject(darkBrush);
566 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
568 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
569 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
570 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
571 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
572 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
573 ::LineTo(hdc, rect.left, rect.bottom);
574 ::SelectObject(hdc, oldpen);
575 ::DeleteObject(pen);
578 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
580 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
581 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
582 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
583 ::LineTo(hdc, rect.left, rect.bottom);
584 ::LineTo(hdc, rect.right, rect.bottom);
585 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
586 ::SelectObject(hdc, oldpen);
587 ::DeleteObject(pen);
590 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
592 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
593 CRect rt=rect;
594 LVITEM rItem;
595 SecureZeroMemory(&rItem, sizeof(LVITEM));
596 rItem.mask = LVIF_STATE;
597 rItem.iItem = (int)index;
598 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
599 GetItem(&rItem);
601 CDC W_Dc;
602 W_Dc.Attach(hdc);
604 HTHEME hTheme = NULL;
605 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
606 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
608 SIZE oneSpaceSize;
609 if (m_bTagsBranchesOnRightSide)
611 HFONT oldFont = (HFONT)SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
612 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
613 SelectObject(hdc, oldFont);
614 rt.left += oneSpaceSize.cx * 2;
616 else
618 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
619 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
620 rt.left += oneSpaceSize.cx;
623 CString msg = MessageDisplayStr(data);
624 int action = data->GetRebaseAction();
625 bool skip = !!(action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP));
626 if (IsAppThemed() && pfnDrawThemeTextEx)
628 int txtState = LISS_NORMAL;
629 if (rItem.state & LVIS_SELECTED)
630 txtState = LISS_SELECTED;
632 DTTOPTS opts = { 0 };
633 opts.dwSize = sizeof(opts);
634 opts.crText = skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT);
635 opts.dwFlags = DTT_TEXTCOLOR;
636 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, msg, -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, &rt, &opts);
638 else
640 if ((rItem.state & LVIS_SELECTED) && (::GetFocus() == m_hWnd))
642 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT));
643 ::DrawText(hdc,msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
644 ::SetTextColor(hdc, clrOld);
646 else
648 COLORREF clrOld = ::SetTextColor(hdc, skip ? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT));
649 ::DrawText(hdc, msg, msg.GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
650 ::SetTextColor(hdc, clrOld);
654 if (m_bTagsBranchesOnRightSide)
656 SIZE size;
657 GetTextExtentPoint32(hdc, msg, msg.GetLength(), &size);
659 rt.left += oneSpaceSize.cx + size.cx;
661 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
664 if (hTheme)
665 CloseThemeData(hTheme);
667 W_Dc.Detach();
670 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC& W_Dc, HTHEME hTheme, CRect& rect, CRect& rt, LVITEM& rItem, GitRevLoglist* data, std::vector<REFLABEL>& refList)
672 for (unsigned int i = 0; i < refList.size(); ++i)
674 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
675 HBRUSH brush = 0;
676 COLORREF colRef = refList[i].color;
677 bool singleRemote = refList[i].singleRemote;
678 bool hasTracking = refList[i].hasTracking;
679 bool sameName = refList[i].sameName;
680 bool annotatedTag = refList[i].annotatedTag;
682 //When row selected, ajust label color
683 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
685 if (rItem.state & LVIS_SELECTED)
686 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
689 brush = ::CreateSolidBrush(colRef);
691 if (!shortname.IsEmpty() && (rt.left < rect.right))
693 SIZE size;
694 memset(&size,0,sizeof(SIZE));
695 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
697 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
698 rt.right += 8;
700 int textpos = DT_CENTER;
702 if (rt.right > rect.right)
704 rt.right = rect.right;
705 textpos = 0;
708 CRect textRect = rt;
710 if (singleRemote)
712 rt.right += 8;
713 textRect.OffsetRect(8, 0);
716 if (sameName)
717 rt.right += 8;
719 if (hasTracking)
721 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
723 else
725 //Fill interior of ref label
726 ::FillRect(hdc, &rt, brush);
729 //Draw edge of label
730 CRect rectEdge = rt;
732 if (!hasTracking)
734 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
735 rectEdge.DeflateRect(1, 1);
736 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
739 if (annotatedTag)
741 rt.right += 8;
742 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
743 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
744 ::FillRgn(hdc, hrgn, brush);
745 ::DeleteObject(hrgn);
746 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
747 HPEN pen;
748 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
749 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
750 ::DeleteObject(pen);
751 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
752 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
753 ::DeleteObject(pen);
754 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
755 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
756 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
757 ::DeleteObject(pen);
758 SelectObject(hdc, oldpen);
761 //Draw text inside label
762 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
763 if (!customColor && IsAppThemed() && pfnDrawThemeTextEx)
765 int txtState = LISS_NORMAL;
766 if (rItem.state & LVIS_SELECTED)
767 txtState = LISS_SELECTED;
769 DTTOPTS opts = { 0 };
770 opts.dwSize = sizeof(opts);
771 opts.crText = ::GetSysColor(COLOR_WINDOWTEXT);
772 opts.dwFlags = DTT_TEXTCOLOR;
773 pfnDrawThemeTextEx(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, &textRect, &opts);
775 else
777 W_Dc.SetBkMode(TRANSPARENT);
778 if (customColor || (rItem.state & LVIS_SELECTED))
780 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
781 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
782 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
783 ::SetTextColor(hdc,clrOld);
785 else
787 COLORREF clrOld = ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
788 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
789 ::SetTextColor(hdc, clrOld);
793 if (singleRemote)
795 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
796 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
797 CRect newRect;
798 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
799 DrawLightning(hdc, newRect, color, bold);
802 if (sameName)
804 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
805 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
806 CRect newRect;
807 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
808 DrawUpTriangle(hdc, newRect, color, bold);
811 rt.left = rt.right + 1;
813 if (brush)
814 ::DeleteObject(brush);
816 rt.right = rect.right;
819 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
821 // Returns ((256 - amount)*col1 + amount*col2) / 256;
822 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
823 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
824 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
827 Gdiplus::Color GetGdiColor(COLORREF col)
829 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
831 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
832 const COLORREF& col,const COLORREF& activeColor, int top
835 int h = laneHeight / 2;
836 int m = (x1 + x2) / 2;
837 int r = (x2 - x1) * m_NodeSize / 30;
838 int d = 2 * r;
840 #define P_CENTER m , h+top
841 #define P_0 x2, h+top
842 #define P_90 m , 0+top-1
843 #define P_180 x1, h+top
844 #define P_270 m , 2 * h+top +1
845 #define R_CENTER m - r, h - r+top, d, d
848 #define DELTA_UR_B 2*(x1 - m), 2*h +top
849 #define DELTA_UR_E 0*16, 90*16 +top // -,
851 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
852 #define DELTA_DR_E 270*16, 90*16 +top // -'
854 #define DELTA_UL_B 2*(x2 - m), 2*h +top
855 #define DELTA_UL_E 90*16, 90*16 +top // ,-
857 #define DELTA_DL_B 2*(x2 - m),2*-h +top
858 #define DELTA_DL_E 180*16, 90*16 // '-
860 #define CENTER_UR x1, 2*h, 225
861 #define CENTER_DR x1, 0 , 135
862 #define CENTER_UL x2, 2*h, 315
863 #define CENTER_DL x2, 0 , 45
866 Gdiplus::Graphics graphics( hdc );
868 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
870 // arc
871 switch (type) {
872 case Lanes::JOIN:
873 case Lanes::JOIN_R:
874 case Lanes::HEAD:
875 case Lanes::HEAD_R:
877 Gdiplus::LinearGradientBrush gradient(
878 Gdiplus::Point(x1-2, h+top-2),
879 Gdiplus::Point(P_270),
880 GetGdiColor(activeColor),GetGdiColor(col));
883 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
884 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
886 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
887 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
888 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
890 break;
892 case Lanes::JOIN_L:
895 Gdiplus::LinearGradientBrush gradient(
896 Gdiplus::Point(P_270),
897 Gdiplus::Point(x2+1, h+top-1),
898 GetGdiColor(col),GetGdiColor(activeColor));
901 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
902 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
904 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
905 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
906 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
909 break;
911 case Lanes::TAIL:
912 case Lanes::TAIL_R:
915 Gdiplus::LinearGradientBrush gradient(
916 Gdiplus::Point(x1-2, h+top-2),
917 Gdiplus::Point(P_90),
918 GetGdiColor(activeColor),GetGdiColor(col));
920 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
922 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
924 #if 0
925 QConicalGradient gradient(CENTER_DR);
926 gradient.setColorAt(0.375, activeCol);
927 gradient.setColorAt(0.625, col);
928 myPen.setBrush(gradient);
929 p->setPen(myPen);
930 p->drawArc(P_CENTER, DELTA_DR);
931 #endif
932 break;
934 default:
935 break;
939 //static QPen myPen(Qt::black, 2); // fast path here
940 CPen pen;
941 pen.CreatePen(PS_SOLID,2,col);
942 //myPen.setColor(col);
943 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
945 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
947 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
949 //p->setPen(myPen);
951 // vertical line
952 switch (type) {
953 case Lanes::ACTIVE:
954 case Lanes::NOT_ACTIVE:
955 case Lanes::MERGE_FORK:
956 case Lanes::MERGE_FORK_R:
957 case Lanes::MERGE_FORK_L:
958 case Lanes::JOIN:
959 case Lanes::JOIN_R:
960 case Lanes::JOIN_L:
961 case Lanes::CROSS:
962 //DrawLine(hdc,P_90,P_270);
963 graphics.DrawLine(&myPen,P_90,P_270);
964 //p->drawLine(P_90, P_270);
965 break;
966 case Lanes::HEAD_L:
967 case Lanes::BRANCH:
968 //DrawLine(hdc,P_CENTER,P_270);
969 graphics.DrawLine(&myPen,P_CENTER,P_270);
970 //p->drawLine(P_CENTER, P_270);
971 break;
972 case Lanes::TAIL_L:
973 case Lanes::INITIAL:
974 case Lanes::BOUNDARY:
975 case Lanes::BOUNDARY_C:
976 case Lanes::BOUNDARY_R:
977 case Lanes::BOUNDARY_L:
978 //DrawLine(hdc,P_90, P_CENTER);
979 graphics.DrawLine(&myPen,P_90,P_CENTER);
980 //p->drawLine(P_90, P_CENTER);
981 break;
982 default:
983 break;
986 myPen.SetColor(GetGdiColor(activeColor));
988 // horizontal line
989 switch (type) {
990 case Lanes::MERGE_FORK:
991 case Lanes::JOIN:
992 case Lanes::HEAD:
993 case Lanes::TAIL:
994 case Lanes::CROSS:
995 case Lanes::CROSS_EMPTY:
996 case Lanes::BOUNDARY_C:
997 //DrawLine(hdc,P_180,P_0);
998 graphics.DrawLine(&myPen,P_180,P_0);
999 //p->drawLine(P_180, P_0);
1000 break;
1001 case Lanes::MERGE_FORK_R:
1002 case Lanes::BOUNDARY_R:
1003 //DrawLine(hdc,P_180,P_CENTER);
1004 graphics.DrawLine(&myPen,P_180,P_CENTER);
1005 //p->drawLine(P_180, P_CENTER);
1006 break;
1007 case Lanes::MERGE_FORK_L:
1008 case Lanes::HEAD_L:
1009 case Lanes::TAIL_L:
1010 case Lanes::BOUNDARY_L:
1011 //DrawLine(hdc,P_CENTER,P_0);
1012 graphics.DrawLine(&myPen,P_CENTER,P_0);
1013 //p->drawLine(P_CENTER, P_0);
1014 break;
1015 default:
1016 break;
1019 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1021 CBrush brush;
1022 brush.CreateSolidBrush(col);
1023 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
1025 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
1026 // center symbol, e.g. rect or ellipse
1027 switch (type) {
1028 case Lanes::ACTIVE:
1029 case Lanes::INITIAL:
1030 case Lanes::BRANCH:
1032 //p->setPen(Qt::NoPen);
1033 //p->setBrush(col);
1034 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1035 graphics.FillEllipse(&myBrush, R_CENTER);
1036 //p->drawEllipse(R_CENTER);
1037 break;
1038 case Lanes::MERGE_FORK:
1039 case Lanes::MERGE_FORK_R:
1040 case Lanes::MERGE_FORK_L:
1041 //p->setPen(Qt::NoPen);
1042 //p->setBrush(col);
1043 //p->drawRect(R_CENTER);
1044 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1045 graphics.FillRectangle(&myBrush, R_CENTER);
1046 break;
1047 case Lanes::UNAPPLIED:
1048 // Red minus sign
1049 //p->setPen(Qt::NoPen);
1050 //p->setBrush(Qt::red);
1051 //p->drawRect(m - r, h - 1, d, 2);
1052 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1053 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1054 break;
1055 case Lanes::APPLIED:
1056 // Green plus sign
1057 //p->setPen(Qt::NoPen);
1058 //p->setBrush(DARK_GREEN);
1059 //p->drawRect(m - r, h - 1, d, 2);
1060 //p->drawRect(m - 1, h - r, 2, d);
1061 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1062 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1063 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1064 break;
1065 case Lanes::BOUNDARY:
1066 //p->setBrush(back);
1067 //p->drawEllipse(R_CENTER);
1068 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1069 graphics.DrawEllipse(&myPen, R_CENTER);
1070 break;
1071 case Lanes::BOUNDARY_C:
1072 case Lanes::BOUNDARY_R:
1073 case Lanes::BOUNDARY_L:
1074 //p->setBrush(back);
1075 //p->drawRect(R_CENTER);
1076 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1077 graphics.FillRectangle(&myBrush,R_CENTER);
1078 break;
1079 default:
1080 break;
1083 ::SelectObject(hdc,oldpen);
1084 ::SelectObject(hdc,oldbrush);
1085 #undef P_CENTER
1086 #undef P_0
1087 #undef P_90
1088 #undef P_180
1089 #undef P_270
1090 #undef R_CENTER
1093 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1095 // TODO: unfinished
1096 // return;
1097 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index);
1098 if(data->m_CommitHash.IsEmpty())
1099 return;
1101 CRect rt=rect;
1102 LVITEM rItem;
1103 SecureZeroMemory(&rItem, sizeof(LVITEM));
1104 rItem.mask = LVIF_STATE;
1105 rItem.iItem = (int)index;
1106 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1107 GetItem(&rItem);
1109 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1111 if (data->m_Lanes.empty())
1112 m_logEntries.setLane(data->m_CommitHash);
1114 std::vector<int>& lanes=data->m_Lanes;
1115 size_t laneNum = lanes.size();
1116 UINT activeLane = 0;
1117 for (UINT i = 0; i < laneNum; ++i)
1118 if (Lanes::isMerge(lanes[i])) {
1119 activeLane = i;
1120 break;
1123 int x2 = 0;
1124 int maxWidth = rect.Width();
1125 int lw = 3 * rect.Height() / 4; //laneWidth()
1127 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1128 //if (opt.state & QStyle::State_Selected)
1129 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1131 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1134 int x1 = x2;
1135 x2 += lw;
1137 int ln = lanes[i];
1138 if (ln == Lanes::EMPTY)
1139 continue;
1141 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1142 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1145 #if 0
1146 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1148 int x1 = x2;
1149 x2 += lw;
1151 int ln = lanes[i];
1152 if (ln == Lanes::EMPTY)
1153 continue;
1155 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1156 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1158 if (ln == Lanes::CROSS)
1160 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1161 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1163 else
1164 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1166 #endif
1170 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1173 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1174 // Take the default processing unless we set this to something else below.
1175 *pResult = CDRF_DODEFAULT;
1177 if (m_bNoDispUpdates)
1178 return;
1180 switch (pLVCD->nmcd.dwDrawStage)
1182 case CDDS_PREPAINT:
1184 *pResult = CDRF_NOTIFYITEMDRAW;
1185 return;
1187 break;
1188 case CDDS_ITEMPREPAINT:
1190 // This is the prepaint stage for an item. Here's where we set the
1191 // item's text color.
1193 // Tell Windows to send draw notifications for each subitem.
1194 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1196 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1198 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1200 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1201 if (data)
1203 HGDIOBJ hGdiObj = nullptr;
1204 int action = data->GetRebaseAction();
1205 if (action & (LOGACTIONS_REBASE_DONE | LOGACTIONS_REBASE_SKIP))
1206 crText = RGB(128,128,128);
1208 if (action & LOGACTIONS_REBASE_SQUASH)
1209 pLVCD->clrTextBk = RGB(156,156,156);
1210 else if (action & LOGACTIONS_REBASE_EDIT)
1211 pLVCD->clrTextBk = RGB(200,200,128);
1212 else
1213 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1215 if (action & LOGACTIONS_REBASE_CURRENT)
1216 hGdiObj = m_boldFont;
1218 BOOL isHeadHash = data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE;
1219 BOOL isHighlight = data->m_CommitHash == m_highlight && !m_highlight.IsEmpty();
1220 if (isHeadHash && isHighlight)
1221 hGdiObj = m_boldItalicsFont;
1222 else if (isHeadHash)
1223 hGdiObj = m_boldFont;
1224 else if (isHighlight)
1225 hGdiObj = m_FontItalics;
1227 if (hGdiObj)
1229 SelectObject(pLVCD->nmcd.hdc, hGdiObj);
1230 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1233 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1234 // crText = GetSysColor(COLOR_GRAYTEXT);
1236 if (data->m_CommitHash.IsEmpty())
1238 //crText = GetSysColor(RGB(200,200,0));
1239 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1240 // We changed the font, so we're returning CDRF_NEWFONT. This
1241 // tells the control to recalculate the extent of the text.
1242 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1246 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1248 if (m_bStrictStopped)
1249 crText = GetSysColor(COLOR_GRAYTEXT);
1251 // Store the color back in the NMLVCUSTOMDRAW struct.
1252 pLVCD->clrText = crText;
1253 return;
1255 break;
1256 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1258 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1260 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1263 if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1265 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1267 CRect rect;
1268 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1270 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1271 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1273 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1274 if( !data ->m_CommitHash.IsEmpty())
1275 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1277 *pResult = CDRF_SKIPDEFAULT;
1278 return;
1282 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1284 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1286 GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1288 if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE))
1290 CRect rect;
1291 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1293 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1294 // not in FillBackGround method, because this only affected the message subitem
1295 if (0 != pLVCD->iStateId) // don't know why, but this helps against loosing the focus rect
1296 return;
1298 int index = (int)pLVCD->nmcd.dwItemSpec;
1299 int state = GetItemState(index, LVIS_SELECTED);
1300 int txtState = LISS_NORMAL;
1301 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index)
1303 if (state & LVIS_SELECTED)
1304 txtState = LISS_HOTSELECTED;
1305 else
1306 txtState = LISS_HOT;
1308 else if (state & LVIS_SELECTED)
1310 if (::GetFocus() == m_hWnd)
1311 txtState = LISS_SELECTED;
1312 else
1313 txtState = LISS_SELECTEDNOTFOCUS;
1316 HTHEME hTheme = nullptr;
1317 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1318 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
1320 if (hTheme && IsThemeBackgroundPartiallyTransparent(hTheme, LVP_LISTDETAIL, txtState))
1321 DrawThemeParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect);
1322 else
1324 HBRUSH brush = ::CreateSolidBrush(pLVCD->clrTextBk);
1325 ::FillRect(pLVCD->nmcd.hdc, rect, brush);
1326 ::DeleteObject(brush);
1328 if (hTheme)
1330 CRect rt;
1331 // get rect of whole line
1332 GetItemRect(index, rt, LVIR_BOUNDS);
1333 CRect rect2 = rect;
1334 if (txtState == LISS_NORMAL) // avoid drawing of grey borders
1335 rect2.DeflateRect(1, 1, 1, 1);
1337 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1338 DrawThemeBackground(hTheme, pLVCD->nmcd.hdc, LVP_LISTITEM, txtState, rt, rect2);
1340 CloseThemeData(hTheme);
1342 // END: extended redraw
1344 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1346 std::vector<REFLABEL> refsToShow;
1347 STRING_VECTOR remoteTrackingList;
1348 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1349 for (unsigned int i = 0; i < refList.size(); ++i)
1351 CString str = refList[i];
1353 REFLABEL refLabel;
1354 refLabel.color = RGB(255, 255, 255);
1355 refLabel.singleRemote = false;
1356 refLabel.hasTracking = false;
1357 refLabel.sameName = false;
1358 refLabel.annotatedTag = false;
1359 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1361 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1362 continue;
1363 if (refLabel.name == m_CurrentBranch )
1364 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1365 else
1366 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1368 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1369 CString pullRemote = trackingEntry.first;
1370 CString pullBranch = trackingEntry.second;
1371 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1373 CString defaultUpstream;
1374 defaultUpstream.Format(_T("refs/remotes/%s/%s"), (LPCTSTR)pullRemote, (LPCTSTR)pullBranch);
1375 refLabel.hasTracking = true;
1376 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1378 bool found = false;
1379 for (size_t j = i + 1; j < refList.size(); ++j)
1381 if (refList[j] == defaultUpstream)
1383 found = true;
1384 break;
1388 if (found)
1390 bool sameName = pullBranch == refLabel.name;
1391 refsToShow.push_back(refLabel);
1392 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1393 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1394 if (m_bSymbolizeRefNames)
1396 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1398 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1399 refLabel.singleRemote = true;
1401 else if (sameName)
1402 refLabel.simplifiedName = pullRemote + _T("/");
1403 refLabel.sameName = sameName;
1405 refsToShow.push_back(refLabel);
1406 remoteTrackingList.push_back(defaultUpstream);
1407 continue;
1412 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1414 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1415 continue;
1417 bool found = false;
1418 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1420 if (remoteTrackingList[j] == str)
1422 found = true;
1423 break;
1426 if (found)
1427 continue;
1429 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1430 if (m_bSymbolizeRefNames)
1432 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1434 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1435 refLabel.singleRemote = true;
1439 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1441 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1442 continue;
1443 refLabel.color = m_Colors.GetColor(CColors::Tag);
1444 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1446 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1448 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1449 continue;
1450 refLabel.color = m_Colors.GetColor(CColors::Stash);
1451 refLabel.name = _T("stash");
1453 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1455 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1456 continue;
1457 if (refLabel.name.Find(_T("good")) == 0)
1459 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1460 refLabel.name = _T("good");
1462 if (refLabel.name.Find(_T("bad")) == 0)
1464 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1465 refLabel.name = _T("bad");
1468 else
1469 continue;
1471 refsToShow.push_back(refLabel);
1474 if (refsToShow.empty())
1476 *pResult = CDRF_DODEFAULT;
1477 return;
1480 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1482 *pResult = CDRF_SKIPDEFAULT;
1483 return;
1490 if (pLVCD->iSubItem == LOGLIST_ACTION)
1492 if(this->m_IsIDReplaceAction)
1494 *pResult = CDRF_DODEFAULT;
1495 return;
1497 *pResult = CDRF_DODEFAULT;
1499 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1500 return;
1502 int nIcons = 0;
1503 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1504 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1506 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1507 CRect rect;
1508 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1509 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1510 // Get the selected state of the
1511 // item being drawn.
1513 // Fill the background if necessary
1514 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1516 // Draw the icon(s) into the compatible DC
1517 int action = pLogEntry->GetAction(this);
1518 if (!pLogEntry->m_IsDiffFiles)
1520 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1521 *pResult = CDRF_SKIPDEFAULT;
1522 return;
1525 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1526 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1527 ++nIcons;
1529 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1530 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1531 ++nIcons;
1533 if (action & CTGitPath::LOGACTIONS_DELETED)
1534 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1535 ++nIcons;
1537 if (action & CTGitPath::LOGACTIONS_REPLACED)
1538 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1539 ++nIcons;
1541 if (action & CTGitPath::LOGACTIONS_UNMERGED)
1542 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hConflictedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1543 ++nIcons;
1545 *pResult = CDRF_SKIPDEFAULT;
1546 return;
1549 break;
1551 *pResult = CDRF_DODEFAULT;
1554 CString FindSVNRev(const CString& msg)
1558 const std::tr1::wsregex_iterator end;
1559 std::wstring s = msg;
1560 std::tr1::wregex regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1561 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex1); it != end; ++it)
1563 const std::tr1::wsmatch match = *it;
1564 if (match.size() == 4)
1566 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[2]).c_str());
1567 return std::wstring(match[2]).c_str();
1570 std::tr1::wregex regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1571 for (std::tr1::wsregex_iterator it(s.begin(), s.end(), regex2); it != end; ++it)
1573 const std::tr1::wsmatch match = *it;
1574 if (match.size() == 3)
1576 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match[1]).c_str());
1577 return std::wstring(match[1]).c_str();
1581 catch (std::exception) {}
1583 return _T("");
1586 CString CGitLogListBase::MessageDisplayStr(GitRev* pLogEntry)
1588 if (!m_bFullCommitMessageOnLogLine || pLogEntry->GetBody().IsEmpty())
1589 return pLogEntry->GetSubject();
1591 CString txt(pLogEntry->GetSubject());
1592 txt += _T(' ');
1593 txt += pLogEntry->GetBody();
1595 // Deal with CRLF
1596 txt.Replace(_T('\n'), _T(' '));
1597 txt.Replace(_T('\r'), _T(' '));
1599 return txt;
1602 // CGitLogListBase message handlers
1604 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1606 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1608 // Create a pointer to the item
1609 LV_ITEM* pItem = &(pDispInfo)->item;
1611 // Do the list need text information?
1612 if (!(pItem->mask & LVIF_TEXT))
1613 return;
1615 // By default, clear text buffer.
1616 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax - 1);
1618 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1620 *pResult = 0;
1621 if (m_bNoDispUpdates || bOutOfRange)
1622 return;
1624 // Which item number?
1625 int itemid = pItem->iItem;
1626 GitRevLoglist* pLogEntry = nullptr;
1627 if (itemid < m_arShownList.GetCount())
1628 pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(pItem->iItem));
1630 CString temp;
1631 if(m_IsOldFirst)
1633 temp.Format(_T("%d"),pItem->iItem+1);
1636 else
1638 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1641 // Which column?
1642 switch (pItem->iSubItem)
1644 case LOGLIST_GRAPH: //Graphic
1645 break;
1646 case LOGLIST_REBASE:
1648 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1649 lstrcpyn(pItem->pszText, GetRebaseActionName(pLogEntry->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK), pItem->cchTextMax - 1);
1651 break;
1652 case LOGLIST_ACTION: //action -- no text in the column
1653 break;
1654 case LOGLIST_HASH:
1655 if(pLogEntry)
1656 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax - 1);
1657 break;
1658 case LOGLIST_ID:
1659 if(this->m_IsIDReplaceAction)
1660 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax - 1);
1661 break;
1662 case LOGLIST_MESSAGE: //Message
1663 if (pLogEntry)
1664 lstrcpyn(pItem->pszText, (LPCTSTR)MessageDisplayStr(pLogEntry), pItem->cchTextMax - 1);
1665 break;
1666 case LOGLIST_AUTHOR: //Author
1667 if (pLogEntry)
1668 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax - 1);
1669 break;
1670 case LOGLIST_DATE: //Date
1671 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1672 lstrcpyn(pItem->pszText,
1673 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1674 pItem->cchTextMax - 1);
1675 break;
1677 case LOGLIST_EMAIL:
1678 if (pLogEntry)
1679 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax - 1);
1680 break;
1682 case LOGLIST_COMMIT_NAME: //Commit
1683 if (pLogEntry)
1684 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax - 1);
1685 break;
1687 case LOGLIST_COMMIT_EMAIL: //Commit Email
1688 if (pLogEntry)
1689 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax - 1);
1690 break;
1692 case LOGLIST_COMMIT_DATE: //Commit Date
1693 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1694 lstrcpyn(pItem->pszText,
1695 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1696 pItem->cchTextMax - 1);
1697 break;
1698 case LOGLIST_BUG: //Bug ID
1699 if(pLogEntry)
1700 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1701 break;
1702 case LOGLIST_SVNREV: //SVN revision
1703 if (pLogEntry)
1704 lstrcpyn(pItem->pszText, (LPCTSTR)FindSVNRev(pLogEntry->GetSubjectBody()), pItem->cchTextMax - 1);
1705 break;
1707 default:
1708 ASSERT(false);
1712 bool CGitLogListBase::IsOnStash(int index)
1714 GitRevLoglist* rev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index));
1715 if (IsStash(rev))
1716 return true;
1717 if (index > 0)
1719 GitRevLoglist* preRev = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(index - 1));
1720 if (IsStash(preRev))
1721 return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash;
1723 return false;
1726 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1728 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1730 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1731 return true;
1733 return false;
1736 void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash)
1738 if (pRev->m_ParentHash.empty())
1740 if (pRev->GetParentFromHash(pRev->m_CommitHash))
1741 MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR);
1743 parentHash = pRev->m_ParentHash;
1746 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1749 if (pWnd == GetHeaderCtrl())
1751 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1754 int selIndex = GetSelectionMark();
1755 if (selIndex < 0)
1756 return; // nothing selected, nothing to do with a context menu
1758 // if the user selected the info text telling about not all revisions shown due to
1759 // the "stop on copy/rename" option, we also don't show the context menu
1760 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1761 return;
1763 // if the context menu is invoked through the keyboard, we have to use
1764 // a calculated position on where to anchor the menu on
1765 if ((point.x == -1) && (point.y == -1))
1767 CRect rect;
1768 GetItemRect(selIndex, &rect, LVIR_LABEL);
1769 ClientToScreen(&rect);
1770 point = rect.CenterPoint();
1772 m_nSearchIndex = selIndex;
1773 m_bCancelled = FALSE;
1775 // calculate some information the context menu commands can use
1776 // CString pathURL = GetURLFromPath(m_path);
1778 POSITION pos = GetFirstSelectedItemPosition();
1779 int indexNext = GetNextSelectedItem(pos);
1780 if (indexNext < 0)
1781 return;
1783 GitRevLoglist* pSelLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(indexNext));
1784 if (pSelLogEntry == nullptr)
1785 return;
1786 #if 0
1787 GitRev revSelected = pSelLogEntry->Rev;
1788 GitRev revPrevious = git_revnum_t(revSelected)-1;
1789 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1791 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1793 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1794 if (changedpath->lCopyFromRev)
1795 revPrevious = changedpath->lCopyFromRev;
1798 GitRev revSelected2;
1799 if (pos)
1801 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1802 revSelected2 = pLogEntry->Rev;
1804 bool bAllFromTheSameAuthor = true;
1805 CString firstAuthor;
1806 CLogDataVector selEntries;
1807 GitRev revLowest, revHighest;
1808 GitRevRangeArray revisionRanges;
1810 POSITION pos = GetFirstSelectedItemPosition();
1811 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1812 revisionRanges.AddRevision(pLogEntry->Rev);
1813 selEntries.push_back(pLogEntry);
1814 firstAuthor = pLogEntry->sAuthor;
1815 revLowest = pLogEntry->Rev;
1816 revHighest = pLogEntry->Rev;
1817 while (pos)
1819 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1820 revisionRanges.AddRevision(pLogEntry->Rev);
1821 selEntries.push_back(pLogEntry);
1822 if (firstAuthor.Compare(pLogEntry->sAuthor))
1823 bAllFromTheSameAuthor = false;
1824 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1825 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1829 #endif
1831 bool showExtendedMenu = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
1833 int FirstSelect=-1, LastSelect=-1;
1834 pos = GetFirstSelectedItemPosition();
1835 FirstSelect = GetNextSelectedItem(pos);
1836 while(pos)
1838 LastSelect = GetNextSelectedItem(pos);
1840 //entry is selected, now show the popup menu
1841 CIconMenu popup;
1842 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, blamemenu, revertmenu;
1844 if (popup.CreatePopupMenu())
1846 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1847 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1848 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1849 bool isStash = IsOnStash(indexNext);
1850 GIT_REV_LIST parentHash;
1851 GetParentHashes(pSelLogEntry, parentHash);
1853 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_PICK) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1854 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1856 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SQUASH) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)) && FirstSelect != GetItemCount() - 1 && LastSelect != GetItemCount() - 1)
1857 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1859 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_EDIT) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1860 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1862 if (m_ContextMenuMask & GetContextMenuBit(ID_REBASE_SKIP) && !(pSelLogEntry->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE)))
1863 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1865 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)))
1866 popup.AppendMenu(MF_SEPARATOR, NULL);
1868 if (GetSelectedCount() == 1)
1871 bool requiresSeparator = false;
1872 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1874 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1876 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1877 requiresSeparator = true;
1880 else
1882 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1884 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1885 requiresSeparator = true;
1887 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1889 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1890 requiresSeparator = true;
1894 if (m_ContextMenuMask & GetContextMenuBit(ID_BLAMEPREVIOUS))
1896 if (parentHash.size() == 1)
1898 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME);
1899 requiresSeparator = true;
1901 else if (parentHash.size() > 1)
1903 blamemenu.CreatePopupMenu();
1904 popup.AppendMenuIcon(ID_BLAMEPREVIOUS, IDS_LOG_POPUP_BLAMEPREVIOUS, IDI_BLAME, blamemenu.m_hMenu);
1905 for (size_t i = 0; i < parentHash.size(); ++i)
1907 CString str;
1908 str.Format(IDS_PARENT, i + 1);
1909 blamemenu.AppendMenuIcon(ID_BLAMEPREVIOUS +((i + 1) << 16), str);
1911 requiresSeparator = true;
1915 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1917 if (parentHash.size() == 1)
1919 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1920 requiresSeparator = true;
1922 else if (parentHash.size() > 1)
1924 gnudiffmenu.CreatePopupMenu();
1925 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1927 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1928 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1929 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE)));
1931 for (size_t i = 0; i < parentHash.size(); ++i)
1933 CString str;
1934 str.Format(IDS_PARENT, i + 1);
1935 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1937 requiresSeparator = true;
1941 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1943 if (parentHash.size() == 1)
1945 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1946 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1947 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1948 requiresSeparator = true;
1950 else if (parentHash.size() > 1)
1952 diffmenu.CreatePopupMenu();
1953 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1954 for (size_t i = 0; i < parentHash.size(); ++i)
1956 CString str;
1957 str.Format(IDS_PARENT, i + 1);
1958 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1959 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1961 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1962 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1965 requiresSeparator = true;
1969 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1971 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1972 requiresSeparator = true;
1975 if (requiresSeparator)
1976 popup.AppendMenu(MF_SEPARATOR, NULL);
1978 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1980 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1981 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1984 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1986 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1987 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1989 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1990 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1992 popup.AppendMenu(MF_SEPARATOR, NULL);
1995 if (pSelLogEntry->m_CommitHash.IsEmpty())
1997 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && !isMergeActive)
1998 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2000 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
2001 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
2003 if (CTGitPath(g_Git.m_CurrentDir).HasSubmodules() && m_ContextMenuMask & GetContextMenuBit(ID_SUBMODULE_UPDATE))
2004 popup.AppendMenuIcon(ID_SUBMODULE_UPDATE, IDS_PROC_SYNC_SUBKODULEUPDATE, IDI_UPDATE);
2006 popup.AppendMenu(MF_SEPARATOR, NULL);
2008 if (m_ContextMenuMask & GetContextMenuBit(ID_CLEANUP))
2009 popup.AppendMenuIcon(ID_CLEANUP, IDS_MENUCLEANUP, IDI_CLEANUP);
2011 popup.AppendMenu(MF_SEPARATOR, NULL);
2015 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2016 // {
2017 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2018 // }
2019 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2020 // {
2021 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2022 // }
2023 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2024 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2025 // {
2026 // popup.AppendMenu(MF_SEPARATOR, NULL);
2027 // }
2029 CString str;
2030 //if (m_hasWC)
2031 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2033 if(!pSelLogEntry->m_CommitHash.IsEmpty())
2035 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
2036 GetSelectedCount() == 1)
2037 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
2039 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
2040 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
2042 str.Format(IDS_LOG_POPUP_MERGEREV, (LPCTSTR)g_Git.GetCurrentBranch());
2044 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
2045 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
2047 str.Format(IDS_RESET_TO_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2049 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
2050 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
2053 // Add Switch Branch express Menu
2054 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
2055 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
2058 std::vector<CString *> branchs;
2059 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2061 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
2062 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
2064 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2068 CString str2;
2069 str2.LoadString(IDS_SWITCH_BRANCH);
2071 if(branchs.size() == 1)
2073 str2 += _T(' ');
2074 str2 += _T('"') + branchs[0]->Mid(11) + _T('"');
2075 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH);
2077 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
2080 else if(branchs.size() > 1)
2082 subbranchmenu.CreatePopupMenu();
2083 for (size_t i = 0 ; i < branchs.size(); ++i)
2085 if (*branchs[i] != currentBranch)
2087 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
2088 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
2092 popup.AppendMenuIcon(ID_SWITCHBRANCH, str2, IDI_SWITCH, subbranchmenu.m_hMenu);
2096 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
2097 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
2099 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
2100 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
2102 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
2103 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
2105 str.Format(IDS_REBASE_THIS_FORMAT, (LPCTSTR)g_Git.GetCurrentBranch());
2107 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
2108 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
2109 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
2111 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
2112 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
2114 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
2116 if (parentHash.size() == 1)
2118 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2120 else if (parentHash.size() > 1)
2122 revertmenu.CreatePopupMenu();
2123 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
2125 for (size_t i = 0; i < parentHash.size(); ++i)
2127 CString str2;
2128 str2.Format(IDS_PARENT, i + 1);
2129 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str2);
2134 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
2135 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
2137 popup.AppendMenu(MF_SEPARATOR, NULL);
2142 if(!pSelLogEntry->m_Ref.IsEmpty())
2144 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
2145 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
2146 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
2147 popup.AppendMenu(MF_SEPARATOR, NULL);
2150 if (GetSelectedCount() >= 2)
2152 bool bAddSeparator = false;
2153 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2155 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
2156 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
2159 if (GetSelectedCount() == 2)
2161 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
2162 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
2164 if (!pSelLogEntry->m_CommitHash.IsEmpty())
2166 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2167 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2168 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
2169 CString menu;
2170 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash));
2171 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
2172 menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("...") + firstSelHash));
2173 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
2176 bAddSeparator = true;
2179 if (m_hasWC)
2181 bAddSeparator = true;
2184 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
2185 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
2187 if (bAddSeparator)
2188 popup.AppendMenu(MF_SEPARATOR, NULL);
2191 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
2193 bool bAddSeparator = false;
2194 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2196 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
2198 CString head;
2199 int headindex;
2200 headindex = this->GetHeadIndex();
2201 if(headindex>=0 && LastSelect >= headindex && FirstSelect >= headindex)
2203 head.Format(_T("HEAD~%d"), FirstSelect - headindex);
2204 CGitHash hashFirst;
2205 if (g_Git.GetHash(hashFirst, head))
2206 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2207 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2208 CGitHash hash;
2209 if (g_Git.GetHash(hash, head))
2210 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2211 GitRevLoglist* pFirstEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(FirstSelect));
2212 GitRevLoglist* pLastEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(LastSelect));
2213 if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) {
2214 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2215 bAddSeparator = true;
2220 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2221 if (GetSelectedCount() >= 2)
2222 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2223 else
2224 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2225 bAddSeparator = true;
2228 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2229 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2230 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2231 bAddSeparator = true;
2234 if (bAddSeparator)
2235 popup.AppendMenu(MF_SEPARATOR, NULL);
2238 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())
2240 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT);
2241 popup.AppendMenu(MF_SEPARATOR, NULL);
2244 if (GetSelectedCount() == 1)
2246 bool bAddSeparator = false;
2247 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && ((!isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty()) || showExtendedMenu))
2249 // show the push-option only if the log entry has an associated local branch
2250 bool isLocal = false;
2251 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2253 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2254 isLocal = true;
2256 if (isLocal || showExtendedMenu)
2258 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2259 bAddSeparator = true;
2262 if (m_ContextMenuMask & GetContextMenuBit(ID_PULL) && isHeadCommit && !isMergeActive && m_hasWC)
2264 popup.AppendMenuIcon(ID_PULL, IDS_MENUPULL, IDI_PULL);
2265 bAddSeparator = true;
2269 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2271 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2273 std::vector<CString *> branchs;
2274 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2276 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2277 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2279 CString str;
2280 if (branchs.size() == 1)
2282 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2283 str+=_T(' ');
2284 str += *branchs[0];
2285 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2286 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2287 bAddSeparator = true;
2289 else if (branchs.size() > 1)
2291 str.LoadString(IDS_DELETE_BRANCHTAG);
2292 submenu.CreatePopupMenu();
2293 for (size_t i = 0; i < branchs.size(); ++i)
2295 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2296 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2299 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2300 bAddSeparator = true;
2303 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2304 if (bAddSeparator)
2305 popup.AppendMenu(MF_SEPARATOR, NULL);
2306 } // GetSelectedCount() == 1
2308 if (GetSelectedCount() != 0)
2310 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2311 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2312 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2313 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2314 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2315 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2318 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2319 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2321 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2322 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2324 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2325 // DialogEnableWindow(IDOK, FALSE);
2326 // SetPromptApp(&theApp);
2328 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2330 // EnableOKButton();
2331 } // if (popup.CreatePopupMenu())
2335 bool CGitLogListBase::IsSelectionContinuous()
2337 if ( GetSelectedCount()==1 )
2339 // if only one revision is selected, the selection is of course
2340 // continuous
2341 return true;
2344 POSITION pos = GetFirstSelectedItemPosition();
2345 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2346 if (bContinuous)
2348 int itemindex = GetNextSelectedItem(pos);
2349 while (pos)
2351 int nextindex = GetNextSelectedItem(pos);
2352 if (nextindex - itemindex > 1)
2354 bContinuous = false;
2355 break;
2357 itemindex = nextindex;
2360 return bContinuous;
2363 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2366 CString sClipdata;
2367 POSITION pos = GetFirstSelectedItemPosition();
2368 if (pos != NULL)
2370 CString sRev;
2371 sRev.LoadString(IDS_LOG_REVISION);
2372 CString sAuthor;
2373 sAuthor.LoadString(IDS_LOG_AUTHOR);
2374 CString sDate;
2375 sDate.LoadString(IDS_LOG_DATE);
2376 CString sMessage;
2377 sMessage.LoadString(IDS_LOG_MESSAGE);
2378 bool first = true;
2379 while (pos)
2381 CString sLogCopyText;
2382 CString sPaths;
2383 GitRevLoglist* pLogEntry = reinterpret_cast<GitRevLoglist*>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2385 if (toCopy == ID_COPY_ALL)
2387 //pLogEntry->GetFiles(this)
2388 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2390 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2391 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2393 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2394 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2396 CString rename;
2397 rename.Format(from, (LPCTSTR)((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2398 sPaths += _T(' ');
2399 sPaths += rename;
2401 sPaths += _T("\r\n");
2403 sPaths.Trim();
2404 CString body = pLogEntry->GetBody();
2405 body.Replace(_T("\n"), _T("\r\n"));
2406 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"),
2407 (LPCTSTR)sRev, (LPCTSTR)pLogEntry->m_CommitHash.ToString(),
2408 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2409 (LPCTSTR)sDate,
2410 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2411 (LPCTSTR)sMessage, (LPCTSTR)pLogEntry->GetSubjectBody(true),
2412 (LPCTSTR)sPaths);
2413 sClipdata += sLogCopyText;
2415 else if (toCopy == ID_COPY_MESSAGE)
2417 sClipdata += _T("* ");
2418 sClipdata += pLogEntry->GetSubjectBody(true);
2419 sClipdata += _T("\r\n\r\n");
2421 else if (toCopy == ID_COPY_SUBJECT)
2423 sClipdata += _T("* ");
2424 sClipdata += pLogEntry->GetSubject().Trim();
2425 sClipdata += _T("\r\n\r\n");
2427 else
2429 if (!first)
2430 sClipdata += _T("\r\n");
2431 sClipdata += pLogEntry->m_CommitHash;
2434 first = false;
2436 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2441 void CGitLogListBase::DiffSelectedRevWithPrevious()
2443 if (m_bThreadRunning)
2444 return;
2446 int FirstSelect=-1, LastSelect=-1;
2447 POSITION pos = GetFirstSelectedItemPosition();
2448 FirstSelect = GetNextSelectedItem(pos);
2449 while(pos)
2451 LastSelect = GetNextSelectedItem(pos);
2454 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2456 #if 0
2457 UpdateLogInfoLabel();
2458 int selIndex = m_LogList.GetSelectionMark();
2459 if (selIndex < 0)
2460 return;
2461 int selCount = m_LogList.GetSelectedCount();
2462 if (selCount != 1)
2463 return;
2465 // Find selected entry in the log list
2466 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2467 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2468 long rev1 = pLogEntry->Rev;
2469 long rev2 = rev1-1;
2470 CTGitPath path = m_path;
2472 // See how many files under the relative root were changed in selected revision
2473 int nChanged = 0;
2474 LogChangedPath * changed = NULL;
2475 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2477 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2478 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2480 ++nChanged;
2481 changed = cpath;
2485 if (m_path.IsDirectory() && nChanged == 1)
2487 // We're looking at the log for a directory and only one file under dir was changed in the revision
2488 // Do diff on that file instead of whole directory
2489 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2492 m_bCancelled = FALSE;
2493 DialogEnableWindow(IDOK, FALSE);
2494 SetPromptApp(&theApp);
2495 theApp.DoWaitCursor(1);
2497 if (PromptShown())
2499 GitDiff diff(this, m_hWnd, true);
2500 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2501 diff.SetHEADPeg(m_LogRevision);
2502 diff.ShowCompare(path, rev2, path, rev1);
2504 else
2506 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2509 theApp.DoWaitCursor(-1);
2510 EnableOKButton();
2511 #endif
2514 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2516 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2517 *pResult = -1;
2519 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2520 return;
2521 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2522 return;
2523 if (pFindInfo->lvfi.psz == 0)
2524 return;
2525 #if 0
2526 CString sCmp = pFindInfo->lvfi.psz;
2527 CString sRev;
2528 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2530 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2531 sRev.Format(_T("%ld"), pLogEntry->Rev);
2532 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2534 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2536 *pResult = i;
2537 return;
2540 else
2542 if (sCmp.Compare(sRev)==0)
2544 *pResult = i;
2545 return;
2549 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2551 for (int i=0; i<pFindInfo->iStart; ++i)
2553 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2554 sRev.Format(_T("%ld"), pLogEntry->Rev);
2555 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2557 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2559 *pResult = i;
2560 return;
2563 else
2565 if (sCmp.Compare(sRev)==0)
2567 *pResult = i;
2568 return;
2573 #endif
2574 *pResult = -1;
2577 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2579 ClearText();
2581 this->m_arShownList.SafeRemoveAll();
2583 this->m_logEntries.ClearAll();
2584 if (this->m_logEntries.ParserFromLog(path, 0, info, range))
2585 return -1;
2587 SetItemCountEx((int)m_logEntries.size());
2589 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2591 if(m_IsOldFirst)
2593 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2594 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2597 else
2599 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2600 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2604 ReloadHashMap();
2606 if(path)
2607 m_Path=*path;
2608 return 0;
2612 int CGitLogListBase::FillGitLog(std::set<CGitHash>& hashes)
2614 ClearText();
2616 m_arShownList.SafeRemoveAll();
2618 m_logEntries.ClearAll();
2619 if (m_logEntries.Fill(hashes))
2620 return -1;
2622 SetItemCountEx((int)m_logEntries.size());
2624 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2626 if (m_IsOldFirst)
2628 m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1).m_IsFull = TRUE;
2629 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size() - i - 1));
2631 else
2633 m_logEntries.GetGitRevAt(i).m_IsFull = TRUE;
2634 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2638 ReloadHashMap();
2640 return 0;
2643 int CGitLogListBase::BeginFetchLog()
2645 ClearText();
2647 this->m_arShownList.SafeRemoveAll();
2649 this->m_logEntries.ClearAll();
2651 this->m_LogCache.ClearAllParent();
2653 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2655 CTGitPath *path;
2656 if(this->m_Path.IsEmpty())
2657 path=NULL;
2658 else
2659 path=&this->m_Path;
2661 int mask;
2662 mask = CGit::LOG_INFO_ONLY_HASH;
2663 if (m_bIncludeBoundaryCommits)
2664 mask |= CGit::LOG_INFO_BOUNDARY;
2665 // if(this->m_bAllBranch)
2666 mask |= m_ShowMask ;
2668 if(m_bShowWC)
2670 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2671 ResetWcRev();
2672 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2675 if (m_sRange.IsEmpty())
2676 m_sRange = _T("HEAD");
2678 #if 0 /* use tortoiegit filter */
2679 if (this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2680 data.m_Author = this->m_sFilterText;
2682 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2683 data.m_MessageFilter = this->m_sFilterText;
2685 data.m_IsRegex = m_bFilterWithRegex;
2686 #endif
2688 // follow does not work for directories
2689 if (!path || path->IsDirectory())
2690 mask &= ~CGit::LOG_INFO_FOLLOW;
2691 // follow does not work with all branches 8at least in TGit)
2692 if (mask & CGit::LOG_INFO_FOLLOW)
2693 mask &= ~CGit::LOG_INFO_ALL_BRANCH | CGit::LOG_INFO_LOCAL_BRANCHES;
2695 CString cmd = g_Git.GetLogCmd(m_sRange, path, mask, true, &m_Filter);
2697 //this->m_logEntries.ParserFromLog();
2698 if(IsInWorkingThread())
2700 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2702 else
2704 SetItemCountEx((int)m_logEntries.size());
2709 [] { git_init(); } ();
2711 catch (char* msg)
2713 CString err(msg);
2714 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2715 return -1;
2718 if (!g_Git.CanParseRev(m_sRange))
2720 if (!(mask & CGit::LOG_INFO_ALL_BRANCH) && !(mask & CGit::LOG_INFO_LOCAL_BRANCHES))
2721 return 0;
2723 // if show all branches, pick any ref as dummy entry ref
2724 STRING_VECTOR list;
2725 if (g_Git.GetRefList(list))
2726 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2727 if (list.size() == 0)
2728 return 0;
2730 cmd = g_Git.GetLogCmd(list[0], path, mask, true, &m_Filter);
2733 g_Git.m_critGitDllSec.Lock();
2734 try {
2735 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2737 g_Git.m_critGitDllSec.Unlock();
2738 return -1;
2741 catch (char* msg)
2743 g_Git.m_critGitDllSec.Unlock();
2744 CString err(msg);
2745 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2746 return -1;
2748 g_Git.m_critGitDllSec.Unlock();
2750 return 0;
2753 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2755 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2757 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2759 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2761 DiffSelectedRevWithPrevious();
2762 return TRUE;
2765 #if 0
2766 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2768 DiffSelectedFile();
2769 return TRUE;
2771 #endif
2773 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2775 // select all entries
2776 for (int i=0; i<GetItemCount(); ++i)
2778 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2780 return TRUE;
2783 #if 0
2784 if (m_hAccel && !bSkipAccelerator)
2786 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2787 if (ret)
2788 return TRUE;
2791 #endif
2792 //m_tooltips.RelayEvent(pMsg);
2793 return __super::PreTranslateMessage(pMsg);
2796 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2798 // a double click on an entry in the revision list has happened
2799 *pResult = 0;
2801 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2802 DiffSelectedRevWithPrevious();
2805 int CGitLogListBase::FetchLogAsync(void * data)
2807 ReloadHashMap();
2808 m_ProcData=data;
2809 m_bExitThread=FALSE;
2810 InterlockedExchange(&m_bThreadRunning, TRUE);
2811 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2812 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2813 if (m_LoadingThread ==NULL)
2815 InterlockedExchange(&m_bThreadRunning, FALSE);
2816 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2817 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2818 return -1;
2820 return 0;
2823 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2825 return ((CGitLogListBase*)pVoid)->LogThread();
2828 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2830 //CTime time;
2831 oldest=CTime::GetCurrentTime();
2832 latest=CTime(1971,1,2,0,0,0);
2833 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2835 if(m_logEntries[i].IsEmpty())
2836 continue;
2838 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() < oldest.GetTime())
2839 oldest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2841 if (m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime() > latest.GetTime())
2842 latest = m_logEntries.GetGitRevAt(i).GetCommitterDate().GetTime();
2846 if(latest<oldest)
2847 latest=oldest;
2850 UINT CGitLogListBase::LogThread()
2852 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2854 InterlockedExchange(&m_bThreadRunning, TRUE);
2855 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2857 ULONGLONG t1,t2;
2859 if(BeginFetchLog())
2861 InterlockedExchange(&m_bThreadRunning, FALSE);
2862 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2864 return 1;
2867 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2868 bool bRegex = false;
2869 if (m_bFilterWithRegex)
2870 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2872 TRACE(_T("\n===Begin===\n"));
2873 //Update work copy item;
2875 if (!m_logEntries.empty())
2877 GitRevLoglist* pRev = &m_logEntries.GetGitRevAt(0);
2879 m_arShownList.SafeAdd(pRev);
2883 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2885 // store commit number of the last selected commit/line before the refresh or -1
2886 int lastSelectedHashNItem = -1;
2887 if (m_lastSelectedHash.IsEmpty())
2888 lastSelectedHashNItem = 0;
2890 int ret = 0;
2892 bool shouldWalk = true;
2893 if (!g_Git.CanParseRev(m_sRange))
2895 // walk revisions if show all branches and there exists any ref
2896 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH) && !(m_ShowMask & CGit::LOG_INFO_LOCAL_BRANCHES))
2897 shouldWalk = false;
2898 else
2900 STRING_VECTOR list;
2901 if (g_Git.GetRefList(list))
2902 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2903 if (list.size() == 0)
2904 shouldWalk = false;
2908 if (shouldWalk)
2910 g_Git.m_critGitDllSec.Lock();
2911 int total = 0;
2914 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2915 total = git_get_log_estimate_commit_count(m_DllGitLog);
2917 catch (char* msg)
2919 CString err(msg);
2920 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2921 ret = -1;
2923 g_Git.m_critGitDllSec.Unlock();
2925 GIT_COMMIT commit;
2926 t2=t1=GetTickCount();
2927 int oldprecentage = 0;
2928 size_t oldsize = m_logEntries.size();
2929 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2930 while (ret== 0 && !m_bExitThread)
2932 g_Git.m_critGitDllSec.Lock();
2935 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2937 catch (char* msg)
2939 g_Git.m_critGitDllSec.Unlock();
2940 CString err(msg);
2941 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2942 break;
2944 g_Git.m_critGitDllSec.Unlock();
2946 if(ret)
2948 if (ret != -2) // other than end of revision walking
2949 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret)).c_str(), _T("TortoiseGit"), MB_ICONERROR);
2950 break;
2953 if (commit.m_ignore == 1)
2955 git_free_commit(&commit);
2956 continue;
2959 //printf("%s\r\n",commit.GetSubject());
2960 if(m_bExitThread)
2961 break;
2963 CGitHash hash = (char*)commit.m_hash ;
2965 GitRevLoglist* pRev = m_LogCache.GetCacheData(hash);
2966 pRev->m_GitCommit = commit;
2967 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2969 char *note=NULL;
2970 g_Git.m_critGitDllSec.Lock();
2973 git_get_notes(commit.m_hash, &note);
2975 catch (char* msg)
2977 g_Git.m_critGitDllSec.Unlock();
2978 CString err(msg);
2979 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2980 break;
2982 g_Git.m_critGitDllSec.Unlock();
2984 if(note)
2986 pRev->m_Notes = CUnicodeUtils::GetUnicode(note);
2987 free(note);
2988 note = nullptr;
2991 if(!pRev->m_IsDiffFiles)
2993 pRev->m_CallDiffAsync = DiffAsync;
2996 pRev->ParserParentFromCommit(&commit);
2997 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2999 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
3001 const CGitHash &parentHash = pRev->m_ParentHash[i];
3002 auto it = commitChildren.find(parentHash);
3003 if (it == commitChildren.end())
3005 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
3007 it->second.insert(pRev->m_CommitHash);
3011 #ifdef DEBUG
3012 pRev->DbgPrint();
3013 TRACE(_T("\n"));
3014 #endif
3016 bool visible = true;
3017 if (HasFilterText())
3019 if(!IsMatchFilter(bRegex,pRev,pat))
3020 visible = false;
3022 if (visible && !ShouldShowFilter(pRev, commitChildren))
3023 visible = false;
3024 this->m_critSec.Lock();
3025 m_logEntries.append(hash, visible);
3026 if (visible)
3027 m_arShownList.SafeAdd(pRev);
3028 this->m_critSec.Unlock();
3030 if (!visible)
3031 continue;
3033 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
3034 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
3036 t2=GetTickCount();
3038 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
3040 //update UI
3041 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
3042 if(percent > 99)
3043 percent =99;
3044 if(percent < GITLOG_START)
3045 percent = GITLOG_START +1;
3047 oldsize = m_logEntries.size();
3048 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3050 //if( percent > oldprecentage )
3052 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
3053 oldprecentage = percent;
3056 if (lastSelectedHashNItem >= 0)
3057 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3059 t1 = t2;
3062 g_Git.m_critGitDllSec.Lock();
3063 git_close_log(m_DllGitLog);
3064 g_Git.m_critGitDllSec.Unlock();
3068 if (m_bExitThread)
3070 InterlockedExchange(&m_bThreadRunning, FALSE);
3071 return 0;
3074 //Update UI;
3075 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
3077 if (lastSelectedHashNItem >= 0)
3078 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
3080 if (this->m_hWnd)
3081 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
3083 InterlockedExchange(&m_bThreadRunning, FALSE);
3085 return 0;
3088 void CGitLogListBase::FetchRemoteList()
3090 STRING_VECTOR remoteList;
3091 m_SingleRemote.Empty();
3092 if (!g_Git.GetRemoteList(remoteList) && remoteList.size() == 1)
3093 m_SingleRemote = remoteList[0];
3096 void CGitLogListBase::FetchTrackingBranchList()
3098 m_TrackingMap.clear();
3099 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
3101 for (size_t j = 0; j < it->second.size(); ++j)
3103 CString branchName;
3104 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
3106 CString pullRemote, pullBranch;
3107 g_Git.GetRemoteTrackedBranch(branchName, pullRemote, pullBranch);
3108 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
3110 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
3117 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
3119 SafeTerminateThread();
3121 this->SetItemCountEx(0);
3122 this->Clear();
3124 ResetWcRev();
3126 // HACK to hide graph column
3127 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
3128 SetColumnWidth(0, 0);
3129 else
3130 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3132 //Update branch and Tag info
3133 ReloadHashMap();
3134 if (m_pFindDialog)
3135 m_pFindDialog->RefreshList();
3136 //Assume Thread have exited
3137 //if(!m_bThreadRunning)
3139 m_logEntries.clear();
3141 if(IsCleanFilter)
3143 m_sFilterText.Empty();
3146 InterlockedExchange(&m_bExitThread,FALSE);
3148 InterlockedExchange(&m_bThreadRunning, TRUE);
3149 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3151 SafeTerminateAsyncDiffThread();
3152 m_AsynDiffListLock.Lock();
3153 m_AsynDiffList.clear();
3154 m_AsynDiffListLock.Unlock();
3155 InterlockedExchange(&m_AsyncThreadExit, FALSE);
3156 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
3157 if (!m_DiffingThread)
3158 CMessageBox::Show(nullptr, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3160 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
3162 InterlockedExchange(&m_bThreadRunning, FALSE);
3163 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3164 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
3168 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
3172 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
3173 if (!bMatchCase)
3174 type |= std::tr1::regex_constants::icase;
3175 pat = std::tr1::wregex(regexp_str, type);
3176 return true;
3178 catch (std::exception) {}
3179 return false;
3181 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRevLoglist* pRev, std::tr1::wregex& pat)
3183 BOOL result = TRUE;
3184 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3185 CString sRev;
3187 if ((bRegex)&&(m_bFilterWithRegex))
3189 if (m_SelectedFilters & LOGFILTER_BUGID)
3191 if(this->m_bShowBugtraqColumn)
3193 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3195 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)sBugIds);
3196 if (std::regex_search(std::wstring(sBugIds), pat, flags))
3198 return TRUE;
3203 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3205 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetSubject());
3206 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
3208 return TRUE;
3212 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3214 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR)pRev->GetBody());
3215 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
3217 return TRUE;
3221 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3223 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
3225 return TRUE;
3228 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
3230 return TRUE;
3234 if (m_SelectedFilters & LOGFILTER_EMAILS)
3236 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
3238 return TRUE;
3241 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
3243 return TRUE;
3247 if (m_SelectedFilters & LOGFILTER_REVS)
3249 sRev = pRev->m_CommitHash.ToString();
3250 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3252 return TRUE;
3256 if (m_SelectedFilters & LOGFILTER_REFNAME)
3258 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3259 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3261 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3263 return TRUE;
3268 if (m_SelectedFilters & LOGFILTER_PATHS)
3270 CTGitPathList *pathList=NULL;
3271 if( pRev->m_IsDiffFiles)
3272 pathList = &pRev->GetFiles(this);
3273 else
3275 if(!pRev->m_IsSimpleListReady)
3276 pRev->SafeGetSimpleList(&g_Git);
3279 if(pathList)
3280 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3282 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3284 return true;
3286 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3288 return true;
3292 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3294 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3296 return true;
3301 else
3303 CString find = m_sFilterText;
3304 if (!m_bFilterCaseSensitively)
3305 find.MakeLower();
3306 result = find[0] == '!' ? FALSE : TRUE;
3307 if (!result)
3308 find = find.Mid(1);
3310 if (m_SelectedFilters & LOGFILTER_BUGID)
3312 if(this->m_bShowBugtraqColumn)
3314 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubjectBody());
3316 if (!m_bFilterCaseSensitively)
3317 sBugIds.MakeLower();
3318 if ((sBugIds.Find(find) >= 0))
3320 return result;
3325 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3327 CString msg = pRev->GetSubject();
3329 if (!m_bFilterCaseSensitively)
3330 msg = msg.MakeLower();
3331 if ((msg.Find(find) >= 0))
3333 return result;
3337 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3339 CString msg = pRev->GetBody();
3341 if (!m_bFilterCaseSensitively)
3342 msg = msg.MakeLower();
3343 if ((msg.Find(find) >= 0))
3345 return result;
3349 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3351 CString msg = pRev->GetAuthorName();
3352 if (!m_bFilterCaseSensitively)
3353 msg = msg.MakeLower();
3354 if ((msg.Find(find) >= 0))
3356 return result;
3360 if (m_SelectedFilters & LOGFILTER_EMAILS)
3362 CString msg = pRev->GetAuthorEmail();
3363 if (!m_bFilterCaseSensitively)
3364 msg = msg.MakeLower();
3365 if ((msg.Find(find) >= 0))
3367 return result;
3371 if (m_SelectedFilters & LOGFILTER_REVS)
3373 sRev = pRev->m_CommitHash.ToString();
3374 if ((sRev.Find(find) >= 0))
3376 return result;
3380 if (m_SelectedFilters & LOGFILTER_REFNAME)
3382 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3383 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3385 if (it->Find(find) >= 0)
3387 return result;
3392 if (m_SelectedFilters & LOGFILTER_PATHS)
3394 CTGitPathList *pathList=NULL;
3395 if( pRev->m_IsDiffFiles)
3396 pathList = &pRev->GetFiles(this);
3397 else
3399 if(!pRev->m_IsSimpleListReady)
3400 pRev->SafeGetSimpleList(&g_Git);
3402 if(pathList)
3403 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3405 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3406 CString path = cpath->GetGitOldPathString();
3407 if (!m_bFilterCaseSensitively)
3408 path.MakeLower();
3409 if ((path.Find(find)>=0))
3411 return result;
3413 path = cpath->GetGitPathString();
3414 if (!m_bFilterCaseSensitively)
3415 path.MakeLower();
3416 if ((path.Find(find)>=0))
3418 return result;
3422 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3424 CString path = pRev->m_SimpleFileList[i];
3425 if (!m_bFilterCaseSensitively)
3426 path.MakeLower();
3427 if ((path.Find(find)>=0))
3429 return result;
3433 } // else (from if (bRegex))
3434 return !result;
3437 static bool CStringStartsWith(const CString &str, const CString &prefix)
3439 return str.Left(prefix.GetLength()) == prefix;
3441 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist* pRev, const std::map<CGitHash, std::set<CGitHash>>& commitChildren)
3443 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3444 return true;
3446 if (m_ShowFilter & FILTERSHOW_REFS)
3448 // Keep all refs.
3449 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3450 for (size_t i = 0; i < refList.size(); ++i)
3452 const CString &str = refList[i];
3453 if (CStringStartsWith(str, _T("refs/heads/")))
3455 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3456 return true;
3458 else if (CStringStartsWith(str, _T("refs/remotes/")))
3460 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3461 return true;
3463 else if (CStringStartsWith(str, _T("refs/tags/")))
3465 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3466 return true;
3468 else if (CStringStartsWith(str, _T("refs/stash")))
3470 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3471 return true;
3473 else if (CStringStartsWith(str, _T("refs/bisect/")))
3475 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3476 return true;
3479 // Keep the head too.
3480 if (pRev->m_CommitHash == m_HeadHash)
3481 return true;
3484 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3486 if (pRev->ParentsCount() > 1)
3487 return true;
3488 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3489 if (childrenIt != commitChildren.end())
3491 const std::set<CGitHash> &children = childrenIt->second;
3492 if (children.size() > 1)
3493 return true;
3496 return false;
3499 void CGitLogListBase::ShowGraphColumn(bool bShow)
3501 // HACK to hide graph column
3502 if (bShow)
3503 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3504 else
3505 SetColumnWidth(0, 0);
3508 CString CGitLogListBase::GetTagInfo(GitRev* pLogEntry)
3510 CString cmd;
3511 CString output;
3513 if (m_HashMap.find(pLogEntry->m_CommitHash) != m_HashMap.end())
3515 STRING_VECTOR &vector = m_HashMap[pLogEntry->m_CommitHash];
3516 for (size_t i = 0; i < vector.size(); ++i)
3518 if (vector[i].Find(_T("refs/tags/")) == 0)
3520 CString tag = vector[i];
3521 int start = vector[i].Find(_T("^{}"));
3522 if (start > 0)
3523 tag = tag.Left(start);
3524 else
3525 continue;
3527 cmd.Format(_T("git.exe cat-file tag %s"), (LPCTSTR)tag);
3528 if (g_Git.Run(cmd, &output, nullptr, CP_UTF8) == 0)
3529 output.AppendChar(_T('\n'));
3534 return output;
3537 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3540 pShownlist->SafeRemoveAll();
3542 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3543 bool bRegex = false;
3544 if (m_bFilterWithRegex)
3545 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3547 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3548 CString sRev;
3549 for (DWORD i=0; i<m_logEntries.size(); ++i)
3551 if ((bRegex)&&(m_bFilterWithRegex))
3553 #if 0
3554 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3556 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3557 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3559 pShownlist->SafeAdd(m_logEntries[i]);
3560 continue;
3563 #endif
3564 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3566 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3567 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3569 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3570 continue;
3573 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3575 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3576 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3578 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3579 continue;
3582 if (m_SelectedFilters & LOGFILTER_PATHS)
3584 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3586 bool bGoing = true;
3587 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3589 CTGitPath cpath = pathList[cpPathIndex];
3590 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3592 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3593 bGoing = false;
3594 continue;
3596 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3598 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3599 bGoing = false;
3600 continue;
3602 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3604 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3605 bGoing = false;
3606 continue;
3610 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3612 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3614 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3615 continue;
3618 if (m_SelectedFilters & LOGFILTER_EMAILS)
3620 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3622 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3623 continue;
3626 if (m_SelectedFilters & LOGFILTER_REVS)
3628 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3629 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3631 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3632 continue;
3635 if (m_SelectedFilters & LOGFILTER_REFNAME)
3637 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3638 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3640 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3642 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3643 continue;
3647 } // if (bRegex)
3648 else
3650 CString find = m_sFilterText;
3651 if (!m_bFilterCaseSensitively)
3652 find.MakeLower();
3653 #if 0
3654 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3656 CString sBugIDs = m_logEntries[i]->sBugIDs;
3658 if (!m_bFilterCaseSensitively)
3659 sBugIDs = sBugIDs.MakeLower();
3660 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3662 pShownlist->SafeAdd(m_logEntries[i]);
3663 continue;
3666 #endif
3667 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3669 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3671 if (!m_bFilterCaseSensitively)
3672 msg = msg.MakeLower();
3673 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3675 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3676 continue;
3679 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3681 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3683 if (!m_bFilterCaseSensitively)
3684 msg = msg.MakeLower();
3685 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3687 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3688 continue;
3691 if (m_SelectedFilters & LOGFILTER_PATHS)
3693 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3695 bool bGoing = true;
3696 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3698 CTGitPath cpath = pathList[cpPathIndex];
3699 CString path = cpath.GetGitOldPathString();
3700 if (!m_bFilterCaseSensitively)
3701 path.MakeLower();
3702 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3704 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3705 bGoing = false;
3706 continue;
3708 path = cpath.GetGitPathString();
3709 if (!m_bFilterCaseSensitively)
3710 path.MakeLower();
3711 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3713 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3714 bGoing = false;
3715 continue;
3717 path = cpath.GetActionName();
3718 if (!m_bFilterCaseSensitively)
3719 path.MakeLower();
3720 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3722 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3723 bGoing = false;
3724 continue;
3728 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3730 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3731 if (!m_bFilterCaseSensitively)
3732 msg = msg.MakeLower();
3733 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3735 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3736 continue;
3739 if (m_SelectedFilters & LOGFILTER_EMAILS)
3741 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3742 if (!m_bFilterCaseSensitively)
3743 msg = msg.MakeLower();
3744 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3746 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3747 continue;
3750 if (m_SelectedFilters & LOGFILTER_REVS)
3752 sRev = m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
3753 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3755 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3756 continue;
3759 if (m_SelectedFilters & LOGFILTER_REFNAME)
3761 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3762 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3764 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3766 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3767 continue;
3771 } // else (from if (bRegex))
3772 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3776 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3779 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3781 if(m_From == -1)
3782 if(m_To == -1)
3783 return true;
3784 else
3785 return time <= m_To;
3786 else
3787 if(m_To == -1)
3788 return time >= m_From;
3789 else
3790 return ((time >= m_From)&&(time <= m_To));
3792 return TRUE; /* git dll will filter time range */
3794 // return TRUE;
3796 void CGitLogListBase::StartFilter()
3798 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3799 RecalculateShownList(&m_arShownList);
3800 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3803 DeleteAllItems();
3804 SetItemCountEx(ShownCountWithStopped());
3805 RedrawItems(0, ShownCountWithStopped());
3806 Invalidate();
3809 void CGitLogListBase::RemoveFilter()
3812 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3814 m_arShownList.SafeRemoveAll();
3816 // reset the time filter too
3817 #if 0
3818 m_timFrom = (__time64_t(m_tFrom));
3819 m_timTo = (__time64_t(m_tTo));
3820 m_DateFrom.SetTime(&m_timFrom);
3821 m_DateTo.SetTime(&m_timTo);
3822 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3823 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3824 #endif
3826 for (DWORD i=0; i<m_logEntries.size(); ++i)
3828 if(this->m_IsOldFirst)
3830 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3832 else
3834 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3837 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3838 DeleteAllItems();
3839 SetItemCountEx(ShownCountWithStopped());
3840 RedrawItems(0, ShownCountWithStopped());
3842 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3845 void CGitLogListBase::Clear()
3847 m_arShownList.SafeRemoveAll();
3848 DeleteAllItems();
3850 m_logEntries.ClearAll();
3854 void CGitLogListBase::OnDestroy()
3856 // save the column widths to the registry
3857 SaveColumnWidths();
3859 SafeTerminateThread();
3860 SafeTerminateAsyncDiffThread();
3862 int retry = 0;
3863 while(m_LogCache.SaveCache())
3865 if(retry > 5)
3866 break;
3867 Sleep(1000);
3869 ++retry;
3871 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3872 // MB_YESNO) == IDNO)
3873 // break;
3876 CHintListCtrl::OnDestroy();
3879 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3881 CRect rect;
3882 int i=(int)wParam;
3883 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3884 this->InvalidateRect(rect);
3886 return 0;
3890 * Save column widths to the registry
3892 void CGitLogListBase::SaveColumnWidths()
3894 int maxcol = m_ColumnManager.GetColumnCount();
3896 // HACK that graph column is always shown
3897 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3899 for (int col = 0; col < maxcol; ++col)
3900 if (m_ColumnManager.IsVisible (col))
3901 m_ColumnManager.ColumnResized (col);
3903 m_ColumnManager.WriteSettings();
3906 int CGitLogListBase::GetHeadIndex()
3908 if(m_HeadHash.IsEmpty())
3909 return -1;
3911 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3913 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3914 if(pRev)
3916 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3917 return i;
3920 return -1;
3922 void CGitLogListBase::OnFind()
3924 if (!m_pFindDialog)
3926 m_pFindDialog = new CFindDlg(this);
3927 m_pFindDialog->Create(this);
3930 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3932 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3934 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3936 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3937 Default();
3939 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3941 if (GetSelectedCount() != 0)
3942 return 0;
3944 CGitHash theSelectedHash = m_lastSelectedHash;
3945 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3946 m_lastSelectedHash = theSelectedHash;
3948 int countPerPage = GetCountPerPage();
3949 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3950 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3951 EnsureVisible((int)itemToSelect, FALSE);
3952 return 0;
3954 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3957 ASSERT(m_pFindDialog != NULL);
3958 bool bFound = false;
3959 int i=0;
3961 if (m_pFindDialog->IsTerminating())
3963 // invalidate the handle identifying the dialog box.
3964 m_pFindDialog = NULL;
3965 return 0;
3968 INT_PTR cnt = m_arShownList.GetCount();
3970 if(m_pFindDialog->IsRef())
3972 CString str;
3973 str=m_pFindDialog->GetFindString();
3975 CGitHash hash;
3977 if(!str.IsEmpty())
3979 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3980 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3983 if(!hash.IsEmpty())
3985 for (i = 0; i < cnt; ++i)
3987 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3988 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3990 bFound = true;
3991 break;
3995 if (!bFound)
3997 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3998 return 0;
4002 if (m_pFindDialog->FindNext() && !bFound)
4004 //read data from dialog
4005 CString findText = m_pFindDialog->GetFindString();
4006 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
4008 std::tr1::wregex pat;
4009 bool bRegex = false;
4010 if (m_pFindDialog->Regex())
4011 bRegex = ValidateRegexp(findText, pat, bMatchCase);
4013 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
4015 for (i = m_nSearchIndex + 1; ; ++i)
4017 if (i >= cnt)
4019 i = 0;
4020 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
4022 if (m_nSearchIndex >= 0)
4024 if (i == m_nSearchIndex)
4026 ::MessageBeep(0xFFFFFFFF);
4027 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
4028 break;
4032 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i);
4034 CString str;
4035 str+=pLogEntry->m_CommitHash.ToString();
4036 str += _T('\n');
4038 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
4040 str+=m_HashMap[pLogEntry->m_CommitHash][j];
4041 str += _T('\n');
4044 str+=pLogEntry->GetAuthorEmail();
4045 str += _T('\n');
4046 str+=pLogEntry->GetAuthorName();
4047 str += _T('\n');
4048 str+=pLogEntry->GetBody();
4049 str += _T('\n');
4050 str+=pLogEntry->GetCommitterEmail();
4051 str += _T('\n');
4052 str+=pLogEntry->GetCommitterName();
4053 str += _T('\n');
4054 str+=pLogEntry->GetSubject();
4055 str += _T('\n');
4056 str+=pLogEntry->m_Notes;
4057 str += _T('\n');
4058 str+=GetTagInfo(pLogEntry);
4059 str += _T('\n');
4062 /*Because changed files list is loaded on demand when gui show,
4063 files will empty when files have not fetched.
4065 we can add it back by using one-way diff(with outnumber changed and rename detect.
4066 here just need changed filename list. one-way is much quicker.
4068 if(pLogEntry->m_IsFull)
4070 for (int j = 0; j < pLogEntry->GetFiles(this).GetCount(); ++j)
4072 str += pLogEntry->GetFiles(this)[j].GetWinPath();
4073 str += _T('\n');
4074 str += pLogEntry->GetFiles(this)[j].GetGitOldPathString();
4075 str += _T('\n');
4078 else
4080 if(!pLogEntry->m_IsSimpleListReady)
4081 pLogEntry->SafeGetSimpleList(&g_Git);
4083 for (size_t j = 0; j < pLogEntry->m_SimpleFileList.size(); ++j)
4085 str += pLogEntry->m_SimpleFileList[j];
4086 str += _T('\n');
4092 if (bRegex)
4094 if (std::regex_search(std::wstring(str), pat, flags))
4096 bFound = true;
4097 break;
4100 else
4102 if (bMatchCase)
4104 if (str.Find(findText) >= 0)
4106 bFound = true;
4107 break;
4111 else
4113 CString msg = str;
4114 msg = msg.MakeLower();
4115 CString find = findText.MakeLower();
4116 if (msg.Find(find) >= 0)
4118 bFound = TRUE;
4119 break;
4123 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4125 } // if(m_pFindDialog->FindNext())
4126 //UpdateLogInfoLabel();
4128 if (bFound)
4130 m_nSearchIndex = i;
4131 EnsureVisible(i, FALSE);
4132 if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0)
4134 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
4135 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
4136 SetSelectionMark(i);
4138 else
4140 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
4141 if (pLogEntry)
4142 m_highlight = pLogEntry->m_CommitHash;
4144 Invalidate();
4145 //FillLogMessageCtrl();
4146 UpdateData(FALSE);
4149 return 0;
4152 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
4154 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
4156 *pResult = FALSE;
4159 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
4161 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
4163 Invalidate(FALSE);
4166 INT_PTR CGitLogListBase::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
4168 LVHITTESTINFO lvhitTestInfo;
4170 lvhitTestInfo.pt = point;
4172 int nItem = ListView_SubItemHitTest(m_hWnd, &lvhitTestInfo);
4173 int nSubItem = lvhitTestInfo.iSubItem;
4175 UINT nFlags = lvhitTestInfo.flags;
4177 // nFlags is 0 if the SubItemHitTest fails
4178 // Therefore, 0 & <anything> will equal false
4179 if (nFlags & LVHT_ONITEM)
4181 // Get the client area occupied by this control
4182 RECT rcClient;
4183 GetClientRect(&rcClient);
4185 // Fill in the TOOLINFO structure
4186 pTI->hwnd = m_hWnd;
4187 pTI->uId = (UINT)((nItem<<10)+(nSubItem&0x3ff)+1);
4188 pTI->lpszText = LPSTR_TEXTCALLBACK;
4189 pTI->rect = rcClient;
4191 return pTI->uId; // By returning a unique value per listItem,
4192 // we ensure that when the mouse moves over another list item,
4193 // the tooltip will change
4195 else
4197 // Otherwise, we aren't interested, so let the message propagate
4198 return -1;
4202 BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
4204 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
4205 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
4207 *pResult = 0;
4209 // Ignore messages from the built in tooltip, we are processing them internally
4210 if ((pNMHDR->idFrom == (UINT_PTR)m_hWnd) &&
4211 (((pNMHDR->code == TTN_NEEDTEXTA) && (pTTTA->uFlags & TTF_IDISHWND)) ||
4212 ((pNMHDR->code == TTN_NEEDTEXTW) && (pTTTW->uFlags & TTF_IDISHWND))))
4213 return FALSE;
4215 // Get the mouse position
4216 const MSG* pMessage = GetCurrentMessage();
4218 CPoint pt;
4219 pt = pMessage->pt;
4220 ScreenToClient(&pt);
4222 // Check if the point falls onto a list item
4223 LVHITTESTINFO lvhitTestInfo;
4224 lvhitTestInfo.pt = pt;
4226 int nItem = SubItemHitTest(&lvhitTestInfo);
4228 if (lvhitTestInfo.flags & LVHT_ONITEM)
4230 CString strTipText = GetToolTipText(nItem, lvhitTestInfo.iSubItem);
4231 if (strTipText.IsEmpty())
4232 return FALSE;
4234 // we want multiline tooltips
4235 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, INT_MAX);
4237 wcscpy_s(m_wszTip, strTipText);
4238 // handle Unicode as well as non-Unicode requests
4239 if (pNMHDR->code == TTN_NEEDTEXTA)
4241 pTTTA->hinst = nullptr;
4242 pTTTA->lpszText = m_szTip;
4243 ::WideCharToMultiByte(CP_ACP, 0, m_wszTip, -1, m_szTip, 8192, NULL, NULL);
4245 else
4247 pTTTW->hinst = nullptr;
4248 pTTTW->lpszText = m_wszTip;
4251 CRect rect;
4252 GetSubItemRect(nItem, lvhitTestInfo.iSubItem, LVIR_LABEL, rect);
4253 ClientToScreen(rect);
4254 ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, rect.left, rect.top, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER);
4256 return TRUE; // We found a tool tip,
4257 // tell the framework this message has been handled
4260 return FALSE; // We didn't handle the message,
4261 // let the framework continue propagating the message
4264 CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem)
4266 if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide)
4268 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4269 if (pLogEntry == nullptr)
4270 return CString();
4271 if (m_HashMap[pLogEntry->m_CommitHash].empty())
4272 return CString();
4273 return pLogEntry->GetSubject();
4275 else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes)
4277 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4278 if (pLogEntry == nullptr)
4279 return CString();
4280 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false);
4282 else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes)
4284 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4285 if (pLogEntry == nullptr)
4286 return CString();
4287 return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false);
4289 else if (nSubItem == LOGLIST_ACTION)
4291 GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem);
4292 if (pLogEntry == nullptr)
4293 return CString();
4295 if (!pLogEntry->m_IsDiffFiles)
4296 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES));
4298 int actions = pLogEntry->GetAction(this);
4299 CString sToolTipText;
4301 CString actionText;
4302 if (actions & CTGitPath::LOGACTIONS_MODIFIED)
4303 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED);
4305 if (actions & CTGitPath::LOGACTIONS_ADDED)
4307 if (!actionText.IsEmpty())
4308 actionText += L"\r\n";
4309 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED);
4312 if (actions & CTGitPath::LOGACTIONS_DELETED)
4314 if (!actionText.IsEmpty())
4315 actionText += L"\r\n";
4316 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED);
4319 if (actions & CTGitPath::LOGACTIONS_REPLACED)
4321 if (!actionText.IsEmpty())
4322 actionText += L"\r\n";
4323 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED);
4326 if (actions & CTGitPath::LOGACTIONS_UNMERGED)
4328 if (!actionText.IsEmpty())
4329 actionText += L"\r\n";
4330 actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED);
4333 if (!actionText.IsEmpty())
4335 CString sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS));
4336 sToolTipText = sTitle + L":\r\n" + actionText;
4338 return sToolTipText;
4340 return CString();