Fixed issue #1566: Frequent crashes when searching log
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobf4498fa38924a2c694d7bfc12947ebf12d1db18d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "GitLogListBase.h"
26 #include "GitRev.h"
27 //#include "VssStyle.h"
28 #include "IconMenu.h"
29 // CGitLogListBase
30 #include "cursor.h"
31 #include "InputDlg.h"
32 #include "GITProgressDlg.h"
33 #include "ProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
37 #include "Logdlg.h"
38 #include "MessageBox.h"
39 #include "registry.h"
40 #include "LoglistUtils.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
44 #include "TempFile.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
47 #include "IconMenu.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.h"
51 //#include "Blame.h"
52 //#include "GitHelpers.h"
53 #include "GitStatus.h"
54 //#include "LogDlgHelper.h"
55 //#include "CachedLogInfo.h"
56 //#include "RepositoryInfo.h"
57 //#include "EditPropertiesDlg.h"
58 #include "FileDiffDlg.h"
59 #include "..\\TortoiseShell\\Resource.h"
60 #include "FindDlg.h"
61 #include "SysInfo.h"
63 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
64 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
66 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
68 CGitLogListBase::CGitLogListBase():CHintListCtrl()
69 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
70 ,m_nSearchIndex(0)
71 ,m_bNoDispUpdates(FALSE)
72 , m_bThreadRunning(FALSE)
73 , m_bStrictStopped(false)
74 , m_pStoreSelection(NULL)
75 , m_SelectedFilters(LOGFILTER_ALL)
76 , m_bShowWC(false)
77 , m_logEntries(&m_LogCache)
78 , m_pFindDialog(NULL)
79 , m_ColumnManager(this)
80 , m_dwDefaultColumns(0)
81 , m_arShownList(&m_critSec)
82 , m_hasWC(true)
83 , m_bNoHightlightHead(FALSE)
84 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
86 // use the default GUI font, create a copy of it and
87 // change the copy to BOLD (leave the rest of the font
88 // the same)
89 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
90 LOGFONT lf = {0};
91 GetObject(hFont, sizeof(LOGFONT), &lf);
92 lf.lfWeight = FW_BOLD;
93 m_boldFont = CreateFontIndirect(&lf);
95 m_bShowBugtraqColumn=false;
97 m_IsIDReplaceAction=FALSE;
99 this->m_critSec.Init();
100 m_wcRev.m_CommitHash.Empty();
101 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
102 m_wcRev.m_ParentHash.clear();
103 m_wcRev.m_Mark=_T('-');
104 m_wcRev.m_IsUpdateing=FALSE;
105 m_wcRev.m_IsFull = TRUE;
107 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
111 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
113 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
115 m_From = -1;
116 m_To = -1;
118 m_ShowMask = 0;
119 m_LoadingThread = NULL;
121 InterlockedExchange(&m_bExitThread,FALSE);
122 m_IsOldFirst = FALSE;
123 m_IsRebaseReplaceGraph = FALSE;
125 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
127 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
129 // get short/long datetime setting from registry
130 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
131 if ( RegUseShortDateFormat )
133 m_DateFormat = DATE_SHORTDATE;
135 else
137 m_DateFormat = DATE_LONGDATE;
139 // get relative time display setting from registry
140 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
141 m_bRelativeTimes = (regRelativeTimes != 0);
142 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
144 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
145 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
146 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
147 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
148 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
149 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
151 m_ColumnRegKey=_T("log");
153 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
154 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
156 m_AsyncThreadExit = FALSE;
157 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
158 m_AsynDiffListLock.Init();
160 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
161 if (m_DiffingThread ==NULL)
163 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
164 return;
169 int CGitLogListBase::AsyncDiffThread()
171 m_AsyncThreadExited = false;
172 while(!m_AsyncThreadExit)
174 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
176 GitRev *pRev = NULL;
177 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
179 m_AsynDiffListLock.Lock();
180 pRev = m_AsynDiffList.back();
181 m_AsynDiffList.pop_back();
182 m_AsynDiffListLock.Unlock();
184 if( pRev->m_CommitHash.IsEmpty() )
186 if(pRev->m_IsDiffFiles)
187 continue;
189 pRev->GetFiles(this).Clear();
190 pRev->m_ParentHash.clear();
191 pRev->m_ParentHash.push_back(m_HeadHash);
192 if(g_Git.IsInitRepos())
194 g_Git.GetInitAddList(pRev->GetFiles(this));
197 else
199 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
201 pRev->GetAction(this) = 0;
203 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
204 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
206 pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER);
208 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
209 InterlockedExchange(&pRev->m_IsFull, TRUE);
211 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
212 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
213 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
216 if(!pRev->CheckAndDiff())
217 { // fetch change file list
218 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
220 if(i < m_arShownList.GetCount())
222 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
223 if(data->m_CommitHash == pRev->m_CommitHash)
225 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
226 break;
231 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
233 POSITION pos = GetFirstSelectedItemPosition();
234 int nItem = GetNextSelectedItem(pos);
236 if(nItem>=0)
238 GitRev* data = (GitRev*)m_arShownList[nItem];
239 if(data)
240 if(data->m_CommitHash == pRev->m_CommitHash)
242 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
249 m_AsyncThreadExited = true;
250 return 0;
252 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
254 if (exclusivelyShow)
256 m_ContextMenuMask &= hideMask;
258 else
260 m_ContextMenuMask &= ~hideMask;
264 CGitLogListBase::~CGitLogListBase()
266 InterlockedExchange(&m_bNoDispUpdates, TRUE);
267 this->m_arShownList.SafeRemoveAll();
269 DestroyIcon(m_hModifiedIcon);
270 DestroyIcon(m_hReplacedIcon);
271 DestroyIcon(m_hAddedIcon);
272 DestroyIcon(m_hDeletedIcon);
273 m_logEntries.ClearAll();
275 if (m_boldFont)
276 DeleteObject(m_boldFont);
278 if ( m_pStoreSelection )
280 delete m_pStoreSelection;
281 m_pStoreSelection = NULL;
284 SafeTerminateThread();
285 SafeTerminateAsyncDiffThread();
287 if(m_AsyncDiffEvent)
288 CloseHandle(m_AsyncDiffEvent);
292 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
293 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
294 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
295 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
296 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
297 ON_WM_CONTEXTMENU()
298 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
299 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
300 ON_WM_CREATE()
301 ON_WM_DESTROY()
302 ON_MESSAGE(MSG_LOADED,OnLoad)
303 ON_WM_MEASUREITEM()
304 ON_WM_MEASUREITEM_REFLECT()
305 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
306 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
307 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
308 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
309 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
310 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
311 END_MESSAGE_MAP()
313 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
315 //if (m_nRowHeight>0)
317 lpMeasureItemStruct->itemHeight = 50;
321 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
323 PreSubclassWindow();
324 return CHintListCtrl::OnCreate(lpCreateStruct);
327 void CGitLogListBase::PreSubclassWindow()
329 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
330 // load the icons for the action columns
331 // m_Theme.Open(m_hWnd, L"ListView");
332 SetWindowTheme(m_hWnd, L"Explorer", NULL);
333 CHintListCtrl::PreSubclassWindow();
336 void CGitLogListBase::InsertGitColumn()
338 CString temp;
340 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
341 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
342 if (DWORD(regFullRowSelect))
343 exStyle |= LVS_EX_FULLROWSELECT;
344 SetExtendedStyle(exStyle);
346 // only load properties if we have a repository
347 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
348 UpdateProjectProperties();
350 static UINT normal[] =
352 IDS_LOG_GRAPH,
353 IDS_LOG_REBASE,
354 IDS_LOG_ID,
355 IDS_LOG_HASH,
356 IDS_LOG_ACTIONS,
357 IDS_LOG_MESSAGE,
358 IDS_LOG_AUTHOR,
359 IDS_LOG_DATE,
360 IDS_LOG_EMAIL,
361 IDS_LOG_COMMIT_NAME,
362 IDS_LOG_COMMIT_EMAIL,
363 IDS_LOG_COMMIT_DATE,
364 IDS_LOG_BUGIDS,
367 static int with[] =
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 ICONITEMBORDER+16*4,
372 ICONITEMBORDER+16*4,
373 ICONITEMBORDER+16*4,
374 LOGLIST_MESSAGE_MIN,
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
381 ICONITEMBORDER+16*4,
383 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
385 DWORD hideColumns = 0;
386 if(this->m_IsRebaseReplaceGraph)
388 hideColumns |= GIT_LOG_GRAPH;
389 m_dwDefaultColumns |= GIT_LOG_REBASE;
391 else
393 hideColumns |= GIT_LOG_REBASE;
396 if(this->m_IsIDReplaceAction)
398 hideColumns |= GIT_LOG_ACTIONS;
399 m_dwDefaultColumns |= GIT_LOG_ID;
400 m_dwDefaultColumns |= GIT_LOG_HASH;
402 else
404 hideColumns |= GIT_LOG_ID;
406 if(this->m_bShowBugtraqColumn)
408 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
410 else
412 hideColumns |= GIT_LOGLIST_BUG;
414 SetRedraw(false);
416 m_ColumnManager.SetNames(normal, _countof(normal));
417 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
419 SetRedraw(true);
423 * Resizes all columns in a list control to values in registry.
425 void CGitLogListBase::ResizeAllListCtrlCols()
427 // column max and min widths to allow
428 static const int nMinimumWidth = 10;
429 static const int nMaximumWidth = 1000;
430 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
431 if (pHdrCtrl)
433 int numcols = pHdrCtrl->GetItemCount();
434 for (int col = 0; col < numcols; ++col)
436 // get width for this col last time from registry
437 CString regentry;
438 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
439 CRegDWORD regwidth(regentry, 0);
440 int cx = regwidth;
441 if ( cx == 0 )
443 // no saved value, setup sensible defaults
444 if (col == this->LOGLIST_MESSAGE)
446 cx = LOGLIST_MESSAGE_MIN;
448 else
450 cx = ICONITEMBORDER+16*4;
453 if (cx < nMinimumWidth)
455 cx = nMinimumWidth;
457 else if (cx > nMaximumWidth)
459 cx = nMaximumWidth;
462 SetColumnWidth(col, cx);
469 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
471 LVITEM rItem;
472 SecureZeroMemory(&rItem, sizeof(LVITEM));
473 rItem.mask = LVIF_STATE;
474 rItem.iItem = (int)Index;
475 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
476 GetItem(&rItem);
478 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
479 HBRUSH brush = NULL;
481 if (!(rItem.state & LVIS_SELECTED))
483 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
484 brush = ::CreateSolidBrush(RGB(156,156,156));
485 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
486 brush = ::CreateSolidBrush(RGB(200,200,128));
488 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
490 if (rItem.state & LVIS_SELECTED)
492 if (::GetFocus() == m_hWnd)
493 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
494 else
495 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
499 if (brush != NULL)
501 ::FillRect(hdc, &rect, brush);
502 ::DeleteObject(brush);
506 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
508 POINT point = { 4, 4 };
509 CRect rt2 = rect;
510 rt2.DeflateRect(1, 1);
511 rt2.OffsetRect(2, 2);
513 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
514 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
515 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
516 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
517 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
519 ::SelectObject(hdc, brush);
520 rt2.OffsetRect(-2, -2);
521 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
522 ::SelectObject(hdc, oldbrush);
523 ::SelectObject(hdc, oldpen);
524 ::DeleteObject(nullPen);
525 ::DeleteObject(darkBrush);
528 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
530 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
531 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
532 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
533 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
534 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
535 ::LineTo(hdc, rect.left, rect.bottom);
536 ::SelectObject(hdc, oldpen);
537 ::DeleteObject(pen);
540 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
542 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
543 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
544 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
545 ::LineTo(hdc, rect.left, rect.bottom);
546 ::LineTo(hdc, rect.right, rect.bottom);
547 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
548 ::SelectObject(hdc, oldpen);
549 ::DeleteObject(pen);
552 void CGitLogListBase::DrawTagBranch(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> refList)
554 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
555 CRect rt=rect;
556 LVITEM rItem;
557 SecureZeroMemory(&rItem, sizeof(LVITEM));
558 rItem.mask = LVIF_STATE;
559 rItem.iItem = (int)index;
560 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
561 GetItem(&rItem);
563 CDC W_Dc;
564 W_Dc.Attach(hdc);
566 HTHEME hTheme = NULL;
567 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
568 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
570 for (unsigned int i = 0; i < refList.size(); ++i)
572 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
573 HBRUSH brush = 0;
574 COLORREF colRef = refList[i].color;
575 bool singleRemote = refList[i].singleRemote;
576 bool hasTracking = refList[i].hasTracking;
577 bool sameName = refList[i].sameName;
579 //When row selected, ajust label color
580 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
581 if (rItem.state & LVIS_SELECTED)
582 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
584 brush = ::CreateSolidBrush(colRef);
586 if(!shortname.IsEmpty() && (rt.left<rect.right) )
588 SIZE size;
589 memset(&size,0,sizeof(SIZE));
590 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
592 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
593 rt.right+=8;
595 int textpos = DT_CENTER;
597 if(rt.right > rect.right)
599 rt.right = rect.right;
600 textpos =0;
603 CRect textRect = rt;
605 if (singleRemote)
607 rt.right += 8;
608 textRect.OffsetRect(8, 0);
611 if (sameName)
612 rt.right += 8;
614 if (hasTracking)
616 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
618 else
620 //Fill interior of ref label
621 ::FillRect(hdc, &rt, brush);
624 //Draw edge of label
626 CRect rectEdge = rt;
628 if (!hasTracking)
630 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
631 rectEdge.DeflateRect(1, 1);
632 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
635 //Draw text inside label
636 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
637 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
639 int txtState = LISS_NORMAL;
640 if (rItem.state & LVIS_SELECTED)
641 txtState = LISS_SELECTED;
643 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
645 else
647 W_Dc.SetBkMode(TRANSPARENT);
648 if (customColor || (rItem.state & LVIS_SELECTED))
650 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
651 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
652 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
653 ::SetTextColor(hdc,clrOld);
655 else
657 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
661 if (singleRemote)
663 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
664 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
665 CRect newRect;
666 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
667 DrawLightning(hdc, newRect, color, bold);
670 if (sameName)
672 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
673 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
674 CRect newRect;
675 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
676 DrawUpTriangle(hdc, newRect, color, bold);
679 //::MoveToEx(hdc,rt.left,rt.top,NULL);
680 //::LineTo(hdc,rt.right,rt.top);
681 //::LineTo(hdc,rt.right,rt.bottom);
682 //::LineTo(hdc,rt.left,rt.bottom);
683 //::LineTo(hdc,rt.left,rt.top);
685 rt.left=rt.right+1;
687 if(brush)
688 ::DeleteObject(brush);
690 rt.right=rect.right;
692 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
694 int txtState = LISS_NORMAL;
695 if (rItem.state & LVIS_SELECTED)
696 txtState = LISS_SELECTED;
698 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
700 else
702 if (rItem.state & LVIS_SELECTED)
704 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
705 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
706 ::SetTextColor(hdc,clrOld);
708 else
710 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
714 if (hTheme)
715 CloseThemeData(hTheme);
717 W_Dc.Detach();
720 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
722 // Returns ((256 - amount)*col1 + amount*col2) / 256;
723 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
724 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
725 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
728 Gdiplus::Color GetGdiColor(COLORREF col)
730 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
732 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
733 const COLORREF& col,const COLORREF& activeColor, int top
736 int h = laneHeight / 2;
737 int m = (x1 + x2) / 2;
738 int r = (x2 - x1) / 3;
739 int d = 2 * r;
741 #define P_CENTER m , h+top
742 #define P_0 x2, h+top
743 #define P_90 m , 0+top-1
744 #define P_180 x1, h+top
745 #define P_270 m , 2 * h+top +1
746 #define R_CENTER m - r, h - r+top, d, d
749 #define DELTA_UR_B 2*(x1 - m), 2*h +top
750 #define DELTA_UR_E 0*16, 90*16 +top // -,
752 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
753 #define DELTA_DR_E 270*16, 90*16 +top // -'
755 #define DELTA_UL_B 2*(x2 - m), 2*h +top
756 #define DELTA_UL_E 90*16, 90*16 +top // ,-
758 #define DELTA_DL_B 2*(x2 - m),2*-h +top
759 #define DELTA_DL_E 180*16, 90*16 // '-
761 #define CENTER_UR x1, 2*h, 225
762 #define CENTER_DR x1, 0 , 135
763 #define CENTER_UL x2, 2*h, 315
764 #define CENTER_DL x2, 0 , 45
767 Gdiplus::Graphics graphics( hdc );
769 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
771 // arc
772 switch (type) {
773 case Lanes::JOIN:
774 case Lanes::JOIN_R:
775 case Lanes::HEAD:
776 case Lanes::HEAD_R:
778 Gdiplus::LinearGradientBrush gradient(
779 Gdiplus::Point(x1-2, h+top-2),
780 Gdiplus::Point(P_270),
781 GetGdiColor(activeColor),GetGdiColor(col));
784 Gdiplus::Pen mypen(&gradient,2);
785 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
787 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
788 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
789 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
791 break;
793 case Lanes::JOIN_L:
796 Gdiplus::LinearGradientBrush gradient(
797 Gdiplus::Point(P_270),
798 Gdiplus::Point(x2+1, h+top-1),
799 GetGdiColor(col),GetGdiColor(activeColor));
802 Gdiplus::Pen mypen(&gradient,2);
803 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
805 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
806 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
807 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
810 break;
812 case Lanes::TAIL:
813 case Lanes::TAIL_R:
816 Gdiplus::LinearGradientBrush gradient(
817 Gdiplus::Point(x1-2, h+top-2),
818 Gdiplus::Point(P_90),
819 GetGdiColor(activeColor),GetGdiColor(col));
821 Gdiplus::Pen mypen(&gradient,2);
823 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
825 #if 0
826 QConicalGradient gradient(CENTER_DR);
827 gradient.setColorAt(0.375, activeCol);
828 gradient.setColorAt(0.625, col);
829 myPen.setBrush(gradient);
830 p->setPen(myPen);
831 p->drawArc(P_CENTER, DELTA_DR);
832 #endif
833 break;
835 default:
836 break;
840 //static QPen myPen(Qt::black, 2); // fast path here
841 CPen pen;
842 pen.CreatePen(PS_SOLID,2,col);
843 //myPen.setColor(col);
844 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
846 Gdiplus::Pen myPen(GetGdiColor(col),2);
848 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
850 //p->setPen(myPen);
852 // vertical line
853 switch (type) {
854 case Lanes::ACTIVE:
855 case Lanes::NOT_ACTIVE:
856 case Lanes::MERGE_FORK:
857 case Lanes::MERGE_FORK_R:
858 case Lanes::MERGE_FORK_L:
859 case Lanes::JOIN:
860 case Lanes::JOIN_R:
861 case Lanes::JOIN_L:
862 case Lanes::CROSS:
863 //DrawLine(hdc,P_90,P_270);
864 graphics.DrawLine(&myPen,P_90,P_270);
865 //p->drawLine(P_90, P_270);
866 break;
867 case Lanes::HEAD_L:
868 case Lanes::BRANCH:
869 //DrawLine(hdc,P_CENTER,P_270);
870 graphics.DrawLine(&myPen,P_CENTER,P_270);
871 //p->drawLine(P_CENTER, P_270);
872 break;
873 case Lanes::TAIL_L:
874 case Lanes::INITIAL:
875 case Lanes::BOUNDARY:
876 case Lanes::BOUNDARY_C:
877 case Lanes::BOUNDARY_R:
878 case Lanes::BOUNDARY_L:
879 //DrawLine(hdc,P_90, P_CENTER);
880 graphics.DrawLine(&myPen,P_90,P_CENTER);
881 //p->drawLine(P_90, P_CENTER);
882 break;
883 default:
884 break;
887 myPen.SetColor(GetGdiColor(activeColor));
889 // horizontal line
890 switch (type) {
891 case Lanes::MERGE_FORK:
892 case Lanes::JOIN:
893 case Lanes::HEAD:
894 case Lanes::TAIL:
895 case Lanes::CROSS:
896 case Lanes::CROSS_EMPTY:
897 case Lanes::BOUNDARY_C:
898 //DrawLine(hdc,P_180,P_0);
899 graphics.DrawLine(&myPen,P_180,P_0);
900 //p->drawLine(P_180, P_0);
901 break;
902 case Lanes::MERGE_FORK_R:
903 case Lanes::BOUNDARY_R:
904 //DrawLine(hdc,P_180,P_CENTER);
905 graphics.DrawLine(&myPen,P_180,P_CENTER);
906 //p->drawLine(P_180, P_CENTER);
907 break;
908 case Lanes::MERGE_FORK_L:
909 case Lanes::HEAD_L:
910 case Lanes::TAIL_L:
911 case Lanes::BOUNDARY_L:
912 //DrawLine(hdc,P_CENTER,P_0);
913 graphics.DrawLine(&myPen,P_CENTER,P_0);
914 //p->drawLine(P_CENTER, P_0);
915 break;
916 default:
917 break;
920 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
922 CBrush brush;
923 brush.CreateSolidBrush(col);
924 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
926 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
927 // center symbol, e.g. rect or ellipse
928 switch (type) {
929 case Lanes::ACTIVE:
930 case Lanes::INITIAL:
931 case Lanes::BRANCH:
933 //p->setPen(Qt::NoPen);
934 //p->setBrush(col);
935 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
936 graphics.FillEllipse(&myBrush, R_CENTER);
937 //p->drawEllipse(R_CENTER);
938 break;
939 case Lanes::MERGE_FORK:
940 case Lanes::MERGE_FORK_R:
941 case Lanes::MERGE_FORK_L:
942 //p->setPen(Qt::NoPen);
943 //p->setBrush(col);
944 //p->drawRect(R_CENTER);
945 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
946 graphics.FillRectangle(&myBrush, R_CENTER);
947 break;
948 case Lanes::UNAPPLIED:
949 // Red minus sign
950 //p->setPen(Qt::NoPen);
951 //p->setBrush(Qt::red);
952 //p->drawRect(m - r, h - 1, d, 2);
953 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
954 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
955 break;
956 case Lanes::APPLIED:
957 // Green plus sign
958 //p->setPen(Qt::NoPen);
959 //p->setBrush(DARK_GREEN);
960 //p->drawRect(m - r, h - 1, d, 2);
961 //p->drawRect(m - 1, h - r, 2, d);
962 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
963 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
964 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
965 break;
966 case Lanes::BOUNDARY:
967 //p->setBrush(back);
968 //p->drawEllipse(R_CENTER);
969 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
970 graphics.DrawEllipse(&myPen, R_CENTER);
971 break;
972 case Lanes::BOUNDARY_C:
973 case Lanes::BOUNDARY_R:
974 case Lanes::BOUNDARY_L:
975 //p->setBrush(back);
976 //p->drawRect(R_CENTER);
977 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
978 graphics.FillRectangle(&myBrush,R_CENTER);
979 break;
980 default:
981 break;
984 ::SelectObject(hdc,oldpen);
985 ::SelectObject(hdc,oldbrush);
986 #undef P_CENTER
987 #undef P_0
988 #undef P_90
989 #undef P_180
990 #undef P_270
991 #undef R_CENTER
994 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
996 // TODO: unfinished
997 // return;
998 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
999 if(data->m_CommitHash.IsEmpty())
1000 return;
1002 CRect rt=rect;
1003 LVITEM rItem;
1004 SecureZeroMemory(&rItem, sizeof(LVITEM));
1005 rItem.mask = LVIF_STATE;
1006 rItem.iItem = (int)index;
1007 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1008 GetItem(&rItem);
1010 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1012 if (data->m_Lanes.empty())
1013 m_logEntries.setLane(data->m_CommitHash);
1015 std::vector<int>& lanes=data->m_Lanes;
1016 size_t laneNum = lanes.size();
1017 UINT activeLane = 0;
1018 for (UINT i = 0; i < laneNum; ++i)
1019 if (Lanes::isMerge(lanes[i])) {
1020 activeLane = i;
1021 break;
1024 int x1 = 0, x2 = 0;
1025 int maxWidth = rect.Width();
1026 int lw = 3 * rect.Height() / 4; //laneWidth()
1028 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1029 //if (opt.state & QStyle::State_Selected)
1030 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1032 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1035 x1 = x2;
1036 x2 += lw;
1038 int ln = lanes[i];
1039 if (ln == Lanes::EMPTY)
1040 continue;
1042 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1043 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1046 #if 0
1047 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1049 x1 = x2;
1050 x2 += lw;
1052 int ln = lanes[i];
1053 if (ln == Lanes::EMPTY)
1054 continue;
1056 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1057 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1059 if (ln == Lanes::CROSS)
1061 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1062 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1064 else
1065 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1067 #endif
1071 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1074 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1075 // Take the default processing unless we set this to something else below.
1076 *pResult = CDRF_DODEFAULT;
1078 if (m_bNoDispUpdates)
1079 return;
1081 switch (pLVCD->nmcd.dwDrawStage)
1083 case CDDS_PREPAINT:
1085 *pResult = CDRF_NOTIFYITEMDRAW;
1086 return;
1088 break;
1089 case CDDS_ITEMPREPAINT:
1091 // This is the prepaint stage for an item. Here's where we set the
1092 // item's text color.
1094 // Tell Windows to send draw notifications for each subitem.
1095 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1097 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1099 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1101 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1102 if (data)
1104 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1105 crText = RGB(128,128,128);
1107 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1108 pLVCD->clrTextBk = RGB(156,156,156);
1109 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1110 pLVCD->clrTextBk = RGB(200,200,128);
1111 else
1112 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1114 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1116 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1117 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1120 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1122 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1123 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1126 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1127 // crText = GetSysColor(COLOR_GRAYTEXT);
1129 if (data->m_CommitHash.IsEmpty())
1131 //crText = GetSysColor(RGB(200,200,0));
1132 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1133 // We changed the font, so we're returning CDRF_NEWFONT. This
1134 // tells the control to recalculate the extent of the text.
1135 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1139 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1141 if (m_bStrictStopped)
1142 crText = GetSysColor(COLOR_GRAYTEXT);
1144 // Store the color back in the NMLVCUSTOMDRAW struct.
1145 pLVCD->clrText = crText;
1146 return;
1148 break;
1149 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1151 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1153 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1156 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1158 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1160 CRect rect;
1161 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1163 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1164 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1166 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1167 if( !data ->m_CommitHash.IsEmpty())
1168 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1170 *pResult = CDRF_SKIPDEFAULT;
1171 return;
1175 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1177 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1179 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1180 //if(!data->m_IsFull)
1182 //if(data->SafeFetchFullInfo(&g_Git))
1183 // this->Invalidate();
1184 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1187 if (!m_HashMap[data->m_CommitHash].empty())
1189 CRect rect;
1191 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1193 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1195 std::vector<REFLABEL> refsToShow;
1196 STRING_VECTOR remoteTrackingList;
1197 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1198 for (unsigned int i = 0; i < refList.size(); ++i)
1200 CString str = refList[i];
1202 REFLABEL refLabel;
1203 refLabel.color = RGB(255, 255, 255);
1204 refLabel.singleRemote = false;
1205 refLabel.hasTracking = false;
1206 refLabel.sameName = false;
1207 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1209 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1210 continue;
1211 if (refLabel.name == m_CurrentBranch )
1212 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1213 else
1214 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1216 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1217 CString pullRemote = trackingEntry.first;
1218 CString pullBranch = trackingEntry.second;
1219 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1221 CString defaultUpstream;
1222 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1223 refLabel.hasTracking = true;
1224 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1226 bool found = false;
1227 for (int j = i + 1; j < refList.size(); ++j)
1229 if (refList[j] == defaultUpstream)
1231 found = true;
1232 break;
1236 if (found)
1238 bool sameName = pullBranch == refLabel.name;
1239 refsToShow.push_back(refLabel);
1240 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1241 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1242 if (m_bSymbolizeRefNames)
1244 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1246 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1247 refLabel.singleRemote = true;
1249 else if (sameName)
1250 refLabel.simplifiedName = pullRemote + _T("/");
1251 refLabel.sameName = sameName;
1253 refsToShow.push_back(refLabel);
1254 remoteTrackingList.push_back(defaultUpstream);
1255 continue;
1260 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1262 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1263 continue;
1265 bool found = false;
1266 for (int j = 0; j < remoteTrackingList.size(); ++j)
1268 if (remoteTrackingList[j] == str)
1270 found = true;
1271 break;
1274 if (found)
1275 continue;
1277 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1278 if (m_bSymbolizeRefNames)
1280 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1282 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1283 refLabel.singleRemote = true;
1287 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1289 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1290 continue;
1291 refLabel.color = m_Colors.GetColor(CColors::Tag);
1293 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1295 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1296 continue;
1297 refLabel.color = m_Colors.GetColor(CColors::Stash);
1298 refLabel.name = _T("stash");
1300 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1302 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1303 continue;
1304 if (refLabel.name.Find(_T("good")) == 0)
1306 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1307 refLabel.name = _T("good");
1309 if (refLabel.name.Find(_T("bad")) == 0)
1311 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1312 refLabel.name = _T("bad");
1315 else
1316 continue;
1318 refsToShow.push_back(refLabel);
1321 if (refsToShow.empty())
1323 *pResult = CDRF_DODEFAULT;
1324 return;
1327 DrawTagBranch(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1329 *pResult = CDRF_SKIPDEFAULT;
1330 return;
1337 if (pLVCD->iSubItem == LOGLIST_ACTION)
1339 if(this->m_IsIDReplaceAction)
1341 *pResult = CDRF_DODEFAULT;
1342 return;
1344 *pResult = CDRF_DODEFAULT;
1346 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1347 return;
1349 int nIcons = 0;
1350 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1351 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1353 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1354 CRect rect;
1355 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1356 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1357 // Get the selected state of the
1358 // item being drawn.
1360 // Fill the background if necessary
1361 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1363 // Draw the icon(s) into the compatible DC
1364 pLogEntry->GetAction(this);
1366 if (!pLogEntry->m_IsDiffFiles)
1367 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1369 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1370 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1371 ++nIcons;
1373 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1374 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1375 ++nIcons;
1377 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1378 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1379 ++nIcons;
1381 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1382 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1383 ++nIcons;
1384 *pResult = CDRF_SKIPDEFAULT;
1385 return;
1388 break;
1390 *pResult = CDRF_DODEFAULT;
1393 // CGitLogListBase message handlers
1395 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1397 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1399 // Create a pointer to the item
1400 LV_ITEM* pItem = &(pDispInfo)->item;
1402 // Do the list need text information?
1403 if (!(pItem->mask & LVIF_TEXT))
1404 return;
1406 // By default, clear text buffer.
1407 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1409 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1411 *pResult = 0;
1412 if (m_bNoDispUpdates || bOutOfRange)
1413 return;
1415 // Which item number?
1416 int itemid = pItem->iItem;
1417 GitRev * pLogEntry = NULL;
1418 if (itemid < m_arShownList.GetCount())
1419 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1421 CString temp;
1422 if(m_IsOldFirst)
1424 temp.Format(_T("%d"),pItem->iItem+1);
1427 else
1429 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1432 // Which column?
1433 switch (pItem->iSubItem)
1435 case this->LOGLIST_GRAPH: //Graphic
1436 break;
1437 case this->LOGLIST_REBASE:
1439 if(this->m_IsRebaseReplaceGraph)
1441 CTGitPath path;
1442 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1443 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1446 break;
1447 case this->LOGLIST_ACTION: //action -- no text in the column
1448 break;
1449 case this->LOGLIST_HASH:
1450 if(pLogEntry)
1451 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1452 break;
1453 case this->LOGLIST_ID:
1454 if(this->m_IsIDReplaceAction)
1455 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1456 break;
1457 case this->LOGLIST_MESSAGE: //Message
1458 if (pLogEntry)
1459 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1460 break;
1461 case this->LOGLIST_AUTHOR: //Author
1462 if (pLogEntry)
1463 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1464 break;
1465 case this->LOGLIST_DATE: //Date
1466 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1467 lstrcpyn(pItem->pszText,
1468 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1469 pItem->cchTextMax);
1470 break;
1472 case this->LOGLIST_EMAIL:
1473 if (pLogEntry)
1474 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1475 break;
1477 case this->LOGLIST_COMMIT_NAME: //Commit
1478 if (pLogEntry)
1479 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1480 break;
1482 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1483 if (pLogEntry)
1484 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1485 break;
1487 case this->LOGLIST_COMMIT_DATE: //Commit Date
1488 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1489 lstrcpyn(pItem->pszText,
1490 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1491 pItem->cchTextMax);
1492 break;
1493 case this->LOGLIST_BUG: //Bug ID
1494 if(pLogEntry)
1495 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1496 break;
1498 default:
1499 ASSERT(false);
1503 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1506 if (pWnd == GetHeaderCtrl())
1508 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1511 int selIndex = GetSelectionMark();
1512 if (selIndex < 0)
1513 return; // nothing selected, nothing to do with a context menu
1515 // if the user selected the info text telling about not all revisions shown due to
1516 // the "stop on copy/rename" option, we also don't show the context menu
1517 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1518 return;
1520 // if the context menu is invoked through the keyboard, we have to use
1521 // a calculated position on where to anchor the menu on
1522 if ((point.x == -1) && (point.y == -1))
1524 CRect rect;
1525 GetItemRect(selIndex, &rect, LVIR_LABEL);
1526 ClientToScreen(&rect);
1527 point = rect.CenterPoint();
1529 m_nSearchIndex = selIndex;
1530 m_bCancelled = FALSE;
1532 // calculate some information the context menu commands can use
1533 // CString pathURL = GetURLFromPath(m_path);
1535 POSITION pos = GetFirstSelectedItemPosition();
1536 int indexNext = GetNextSelectedItem(pos);
1537 if (indexNext < 0)
1538 return;
1540 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1541 #if 0
1542 GitRev revSelected = pSelLogEntry->Rev;
1543 GitRev revPrevious = git_revnum_t(revSelected)-1;
1544 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1546 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1548 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1549 if (changedpath->lCopyFromRev)
1550 revPrevious = changedpath->lCopyFromRev;
1553 GitRev revSelected2;
1554 if (pos)
1556 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1557 revSelected2 = pLogEntry->Rev;
1559 bool bAllFromTheSameAuthor = true;
1560 CString firstAuthor;
1561 CLogDataVector selEntries;
1562 GitRev revLowest, revHighest;
1563 GitRevRangeArray revisionRanges;
1565 POSITION pos = GetFirstSelectedItemPosition();
1566 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1567 revisionRanges.AddRevision(pLogEntry->Rev);
1568 selEntries.push_back(pLogEntry);
1569 firstAuthor = pLogEntry->sAuthor;
1570 revLowest = pLogEntry->Rev;
1571 revHighest = pLogEntry->Rev;
1572 while (pos)
1574 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1575 revisionRanges.AddRevision(pLogEntry->Rev);
1576 selEntries.push_back(pLogEntry);
1577 if (firstAuthor.Compare(pLogEntry->sAuthor))
1578 bAllFromTheSameAuthor = false;
1579 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1580 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1584 #endif
1586 int FirstSelect=-1, LastSelect=-1;
1587 pos = GetFirstSelectedItemPosition();
1588 FirstSelect = GetNextSelectedItem(pos);
1589 while(pos)
1591 LastSelect = GetNextSelectedItem(pos);
1593 //entry is selected, now show the popup menu
1594 CIconMenu popup;
1595 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1597 if (popup.CreatePopupMenu())
1599 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1600 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1602 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1603 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1605 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1606 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1608 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1609 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1611 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1612 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1614 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1615 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1616 popup.AppendMenu(MF_SEPARATOR, NULL);
1618 if (GetSelectedCount() == 1)
1622 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1624 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1625 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1627 else
1629 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1630 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1632 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1634 GitRev *pRev=pSelLogEntry;
1635 if (pSelLogEntry->m_ParentHash.empty())
1637 pRev->GetParentFromHash(pRev->m_CommitHash);
1639 if(pRev->m_ParentHash.size()<=1)
1641 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1644 else
1646 gnudiffmenu.CreatePopupMenu();
1647 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1649 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1650 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1652 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
1654 CString str;
1655 str.Format(IDS_PARENT, i + 1);
1656 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1661 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1664 GitRev *pRev=pSelLogEntry;
1665 if (pSelLogEntry->m_ParentHash.empty())
1667 pRev->GetParentFromHash(pRev->m_CommitHash);
1669 if(pRev->m_ParentHash.size()<=1)
1671 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1672 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1673 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1675 else
1677 diffmenu.CreatePopupMenu();
1678 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1679 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
1681 CString str;
1682 str.Format(IDS_PARENT, i + 1);
1683 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1684 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1686 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1687 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1693 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1694 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1696 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1697 popup.AppendMenu(MF_SEPARATOR, NULL);
1699 if (pSelLogEntry->m_CommitHash.IsEmpty())
1701 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1702 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1705 bool isStash = false;
1706 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1708 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1710 isStash = true;
1711 break;
1715 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1717 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1718 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1720 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1721 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1723 popup.AppendMenu(MF_SEPARATOR, NULL);
1726 if (pSelLogEntry->m_CommitHash.IsEmpty())
1728 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1729 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1731 popup.AppendMenu(MF_SEPARATOR, NULL);
1735 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1736 // {
1737 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1738 // }
1739 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1740 // {
1741 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1742 // }
1743 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1744 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1745 // {
1746 // popup.AppendMenu(MF_SEPARATOR, NULL);
1747 // }
1749 CString str,format;
1750 //if (m_hasWC)
1751 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1753 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1755 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1756 GetSelectedCount() == 1)
1757 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1759 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1760 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1762 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1763 str.Format(format,g_Git.GetCurrentBranch());
1765 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1766 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1768 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1769 str.Format(format,g_Git.GetCurrentBranch());
1771 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1772 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1775 // Add Switch Branch express Menu
1776 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1777 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1780 std::vector<CString *> branchs;
1781 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1783 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1784 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1786 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1790 CString str;
1791 str.LoadString(IDS_SWITCH_BRANCH);
1793 if(branchs.size() == 1)
1795 str+=_T(" ");
1796 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1797 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1799 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1802 else if(branchs.size() > 1)
1804 subbranchmenu.CreatePopupMenu();
1805 for (size_t i = 0 ; i < branchs.size(); ++i)
1807 if (*branchs[i] != currentBranch)
1809 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1810 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1814 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1818 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1819 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1821 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1822 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1824 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1825 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1827 format.LoadString(IDS_REBASE_THIS_FORMAT);
1828 str.Format(format,g_Git.GetCurrentBranch());
1830 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1831 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1832 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1834 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1835 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1837 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1839 GitRev *pRev = pSelLogEntry;
1840 if (pSelLogEntry->m_ParentHash.empty())
1842 pRev->GetParentFromHash(pRev->m_CommitHash);
1844 if (pRev->m_ParentHash.size() == 1)
1846 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1848 else
1850 revertmenu.CreatePopupMenu();
1851 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1853 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
1855 CString str;
1856 str.Format(IDS_PARENT, i + 1);
1857 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1862 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1863 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1865 popup.AppendMenu(MF_SEPARATOR, NULL);
1870 if(!pSelLogEntry->m_Ref.IsEmpty())
1872 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1873 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1874 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1875 popup.AppendMenu(MF_SEPARATOR, NULL);
1878 if (GetSelectedCount() >= 2)
1880 bool bAddSeparator = false;
1881 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1883 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1884 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1887 if (GetSelectedCount() == 2)
1889 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1890 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1891 bAddSeparator = true;
1894 if (m_hasWC)
1896 bAddSeparator = true;
1899 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1900 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1902 if (bAddSeparator)
1903 popup.AppendMenu(MF_SEPARATOR, NULL);
1906 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1908 bool bAddSeparator = false;
1909 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1911 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1913 CString head;
1914 int headindex;
1915 headindex = this->GetHeadIndex();
1916 if(headindex>=0 && LastSelect >= headindex)
1918 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1919 CGitHash hash;
1920 if (g_Git.GetHash(hash, head))
1921 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
1922 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1923 if(pLastEntry->m_CommitHash == hash) {
1924 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1925 bAddSeparator = true;
1930 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1931 if (GetSelectedCount() >= 2)
1932 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1933 else
1934 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1935 bAddSeparator = true;
1938 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1939 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1940 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1941 bAddSeparator = true;
1944 if (bAddSeparator)
1945 popup.AppendMenu(MF_SEPARATOR, NULL);
1948 if (m_hasWC && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1950 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
1951 popup.AppendMenu(MF_SEPARATOR, NULL);
1954 if (GetSelectedCount() == 1)
1956 bool bAddSeparator = false;
1957 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1959 // show the push-option only if the log entry has an associated local branch
1960 bool isLocal = false;
1961 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1963 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1964 isLocal = true;
1966 if (isLocal)
1968 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1969 bAddSeparator = true;
1973 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1975 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1977 std::vector<CString *> branchs;
1978 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1980 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1981 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1983 CString str;
1984 if (branchs.size() == 1)
1986 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1987 str+=_T(" ");
1988 str += *branchs[0];
1989 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1990 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1991 bAddSeparator = true;
1993 else if (branchs.size() > 1)
1995 str.LoadString(IDS_DELETE_BRANCHTAG);
1996 submenu.CreatePopupMenu();
1997 for (size_t i = 0; i < branchs.size(); ++i)
1999 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2000 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2003 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2004 bAddSeparator = true;
2007 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2008 if (bAddSeparator)
2009 popup.AppendMenu(MF_SEPARATOR, NULL);
2010 } // GetSelectedCount() == 1
2012 if (GetSelectedCount() != 0)
2014 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2015 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2016 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2017 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2018 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2019 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2022 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2023 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2025 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2026 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2028 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2029 // DialogEnableWindow(IDOK, FALSE);
2030 // SetPromptApp(&theApp);
2032 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2034 // EnableOKButton();
2035 } // if (popup.CreatePopupMenu())
2039 bool CGitLogListBase::IsSelectionContinuous()
2041 if ( GetSelectedCount()==1 )
2043 // if only one revision is selected, the selection is of course
2044 // continuous
2045 return true;
2048 POSITION pos = GetFirstSelectedItemPosition();
2049 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2050 if (bContinuous)
2052 int itemindex = GetNextSelectedItem(pos);
2053 while (pos)
2055 int nextindex = GetNextSelectedItem(pos);
2056 if (nextindex - itemindex > 1)
2058 bContinuous = false;
2059 break;
2061 itemindex = nextindex;
2064 return bContinuous;
2067 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2070 CString sClipdata;
2071 POSITION pos = GetFirstSelectedItemPosition();
2072 if (pos != NULL)
2074 CString sRev;
2075 sRev.LoadString(IDS_LOG_REVISION);
2076 CString sAuthor;
2077 sAuthor.LoadString(IDS_LOG_AUTHOR);
2078 CString sDate;
2079 sDate.LoadString(IDS_LOG_DATE);
2080 CString sMessage;
2081 sMessage.LoadString(IDS_LOG_MESSAGE);
2082 bool first = true;
2083 while (pos)
2085 CString sLogCopyText;
2086 CString sPaths;
2087 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2089 if (toCopy == ID_COPY_ALL)
2091 //pLogEntry->GetFiles(this)
2092 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2094 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2095 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2097 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2098 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2100 CString rename;
2101 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2102 sPaths += _T(" ") + rename;
2104 sPaths += _T("\r\n");
2106 sPaths.Trim();
2107 CString body = pLogEntry->GetBody();
2108 body.Replace(_T("\n"), _T("\r\n"));
2109 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"),
2110 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2111 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2112 (LPCTSTR)sDate,
2113 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2114 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2115 (LPCTSTR)sPaths);
2116 sClipdata += sLogCopyText;
2118 else if (toCopy == ID_COPY_MESSAGE)
2120 CString body = pLogEntry->GetBody();
2121 body.Replace(_T("\n"), _T("\r\n"));
2122 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2124 else if (toCopy == ID_COPY_SUBJECT)
2126 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2128 else
2130 if (!first)
2131 sClipdata += _T("\r\n");
2132 sClipdata += pLogEntry->m_CommitHash;
2135 first = false;
2137 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2142 void CGitLogListBase::DiffSelectedRevWithPrevious()
2144 if (m_bThreadRunning)
2145 return;
2147 int FirstSelect=-1, LastSelect=-1;
2148 POSITION pos = GetFirstSelectedItemPosition();
2149 FirstSelect = GetNextSelectedItem(pos);
2150 while(pos)
2152 LastSelect = GetNextSelectedItem(pos);
2155 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2157 #if 0
2158 UpdateLogInfoLabel();
2159 int selIndex = m_LogList.GetSelectionMark();
2160 if (selIndex < 0)
2161 return;
2162 int selCount = m_LogList.GetSelectedCount();
2163 if (selCount != 1)
2164 return;
2166 // Find selected entry in the log list
2167 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2168 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2169 long rev1 = pLogEntry->Rev;
2170 long rev2 = rev1-1;
2171 CTGitPath path = m_path;
2173 // See how many files under the relative root were changed in selected revision
2174 int nChanged = 0;
2175 LogChangedPath * changed = NULL;
2176 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2178 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2179 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2181 ++nChanged;
2182 changed = cpath;
2186 if (m_path.IsDirectory() && nChanged == 1)
2188 // We're looking at the log for a directory and only one file under dir was changed in the revision
2189 // Do diff on that file instead of whole directory
2190 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2193 m_bCancelled = FALSE;
2194 DialogEnableWindow(IDOK, FALSE);
2195 SetPromptApp(&theApp);
2196 theApp.DoWaitCursor(1);
2198 if (PromptShown())
2200 GitDiff diff(this, m_hWnd, true);
2201 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2202 diff.SetHEADPeg(m_LogRevision);
2203 diff.ShowCompare(path, rev2, path, rev1);
2205 else
2207 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2210 theApp.DoWaitCursor(-1);
2211 EnableOKButton();
2212 #endif
2215 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2217 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2218 *pResult = -1;
2220 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2221 return;
2222 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2223 return;
2224 if (pFindInfo->lvfi.psz == 0)
2225 return;
2226 #if 0
2227 CString sCmp = pFindInfo->lvfi.psz;
2228 CString sRev;
2229 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2231 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2232 sRev.Format(_T("%ld"), pLogEntry->Rev);
2233 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2235 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2237 *pResult = i;
2238 return;
2241 else
2243 if (sCmp.Compare(sRev)==0)
2245 *pResult = i;
2246 return;
2250 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2252 for (int i=0; i<pFindInfo->iStart; ++i)
2254 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2255 sRev.Format(_T("%ld"), pLogEntry->Rev);
2256 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2258 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2260 *pResult = i;
2261 return;
2264 else
2266 if (sCmp.Compare(sRev)==0)
2268 *pResult = i;
2269 return;
2274 #endif
2275 *pResult = -1;
2278 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2280 ClearText();
2282 this->m_arShownList.SafeRemoveAll();
2284 this->m_logEntries.ClearAll();
2285 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2286 return -1;
2288 //this->m_logEntries.ParserFromLog();
2289 SetItemCountEx((int)m_logEntries.size());
2291 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2293 if(m_IsOldFirst)
2295 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2296 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2299 else
2301 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2302 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2306 ReloadHashMap();
2308 if(path)
2309 m_Path=*path;
2310 return 0;
2314 int CGitLogListBase::BeginFetchLog()
2316 ClearText();
2318 this->m_arShownList.SafeRemoveAll();
2320 this->m_logEntries.ClearAll();
2322 this->m_LogCache.ClearAllParent();
2324 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2326 CTGitPath *path;
2327 if(this->m_Path.IsEmpty())
2328 path=NULL;
2329 else
2330 path=&this->m_Path;
2332 int mask;
2333 mask = CGit::LOG_INFO_ONLY_HASH;
2334 if (m_bIncludeBoundaryCommits)
2335 mask |= CGit::LOG_INFO_BOUNDARY;
2336 // if(this->m_bAllBranch)
2337 mask |= m_ShowMask ;
2339 if(m_bShowWC)
2341 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2342 ResetWcRev();
2343 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2346 if (m_sRange.IsEmpty())
2347 m_sRange = _T("HEAD");
2349 CFilterData data;
2350 data.m_From = m_From;
2351 data.m_To =m_To;
2353 #if 0 /* use tortoiegit filter */
2354 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2355 data.m_Author = this->m_sFilterText;
2357 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2358 data.m_MessageFilter = this->m_sFilterText;
2360 data.m_IsRegex = m_bFilterWithRegex;
2361 #endif
2363 // follow does not work for directories
2364 if (!path || path->IsDirectory())
2365 mask &= ~CGit::LOG_INFO_FOLLOW;
2366 // follow does not work with all branches 8at least in TGit)
2367 if (mask & CGit::LOG_INFO_FOLLOW)
2368 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2370 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2372 //this->m_logEntries.ParserFromLog();
2373 if(IsInWorkingThread())
2375 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2377 else
2379 SetItemCountEx((int)m_logEntries.size());
2384 [] { git_init(); } ();
2386 catch (char* msg)
2388 CString err(msg);
2389 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2390 return -1;
2393 if (!g_Git.CanParseRev(m_sRange))
2395 if (!(mask & CGit::LOG_INFO_ALL_BRANCH))
2396 return 0;
2398 // if show all branches, pick any ref as dummy entry ref
2399 STRING_VECTOR list;
2400 if (g_Git.GetRefList(list))
2401 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2402 if (list.size() == 0)
2403 return 0;
2405 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2408 g_Git.m_critGitDllSec.Lock();
2409 try {
2410 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2412 g_Git.m_critGitDllSec.Unlock();
2413 return -1;
2416 catch (char* msg)
2418 g_Git.m_critGitDllSec.Unlock();
2419 CString err(msg);
2420 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2421 return -1;
2423 g_Git.m_critGitDllSec.Unlock();
2425 return 0;
2428 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2430 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2432 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2434 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2436 DiffSelectedRevWithPrevious();
2437 return TRUE;
2440 #if 0
2441 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2443 DiffSelectedFile();
2444 return TRUE;
2446 #endif
2448 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2450 // select all entries
2451 for (int i=0; i<GetItemCount(); ++i)
2453 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2455 return TRUE;
2458 #if 0
2459 if (m_hAccel && !bSkipAccelerator)
2461 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2462 if (ret)
2463 return TRUE;
2466 #endif
2467 //m_tooltips.RelayEvent(pMsg);
2468 return __super::PreTranslateMessage(pMsg);
2471 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2473 // a double click on an entry in the revision list has happened
2474 *pResult = 0;
2476 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2477 DiffSelectedRevWithPrevious();
2480 int CGitLogListBase::FetchLogAsync(void * data)
2482 ReloadHashMap();
2483 m_ProcData=data;
2484 m_bExitThread=FALSE;
2485 InterlockedExchange(&m_bThreadRunning, TRUE);
2486 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2487 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2488 if (m_LoadingThread ==NULL)
2490 InterlockedExchange(&m_bThreadRunning, FALSE);
2491 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2492 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2493 return -1;
2495 return 0;
2498 //this is the thread function which calls the subversion function
2499 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2501 return ((CGitLogListBase*)pVoid)->LogThread();
2504 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2506 //CTime time;
2507 oldest=CTime::GetCurrentTime();
2508 latest=CTime(1971,1,2,0,0,0);
2509 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2511 if(m_logEntries[i].IsEmpty())
2512 continue;
2514 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2515 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2517 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2518 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2522 if(latest<oldest)
2523 latest=oldest;
2526 UINT CGitLogListBase::LogThread()
2528 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2530 InterlockedExchange(&m_bThreadRunning, TRUE);
2531 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2533 ULONGLONG t1,t2;
2535 if(BeginFetchLog())
2537 InterlockedExchange(&m_bThreadRunning, FALSE);
2538 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2540 return 1;
2543 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2544 bool bRegex = false;
2545 if (m_bFilterWithRegex)
2546 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2548 TRACE(_T("\n===Begin===\n"));
2549 //Update work copy item;
2551 if (!m_logEntries.empty())
2553 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2555 m_arShownList.SafeAdd(pRev);
2559 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2561 // store commit number of the last selected commit/line before the refresh or -1
2562 int lastSelectedHashNItem = -1;
2563 int ret = 0;
2565 bool shouldWalk = true;
2566 if (!g_Git.CanParseRev(m_sRange))
2568 // walk revisions if show all branches and there exists any ref
2569 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH))
2570 shouldWalk = false;
2571 else
2573 STRING_VECTOR list;
2574 if (g_Git.GetRefList(list))
2575 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2576 if (list.size() == 0)
2577 shouldWalk = false;
2581 if (shouldWalk)
2583 g_Git.m_critGitDllSec.Lock();
2584 int total = 0;
2587 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2588 total = git_get_log_estimate_commit_count(m_DllGitLog);
2590 catch (char* msg)
2592 CString err(msg);
2593 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2594 ret = -1;
2596 g_Git.m_critGitDllSec.Unlock();
2598 GIT_COMMIT commit;
2599 t2=t1=GetTickCount();
2600 int oldprecentage = 0;
2601 size_t oldsize = m_logEntries.size();
2602 while (ret== 0 && !m_bExitThread)
2604 g_Git.m_critGitDllSec.Lock();
2607 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2609 catch (char* msg)
2611 g_Git.m_critGitDllSec.Unlock();
2612 CString err(msg);
2613 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2614 break;
2616 g_Git.m_critGitDllSec.Unlock();
2618 if(ret)
2619 break;
2621 if (commit.m_ignore == 1)
2623 git_free_commit(&commit);
2624 continue;
2627 //printf("%s\r\n",commit.GetSubject());
2628 if(m_bExitThread)
2629 break;
2631 CGitHash hash = (char*)commit.m_hash ;
2633 GitRev *pRev = m_LogCache.GetCacheData(hash);
2634 pRev->m_GitCommit = commit;
2635 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2637 char *note=NULL;
2638 g_Git.m_critGitDllSec.Lock();
2639 git_get_notes(commit.m_hash,&note);
2640 g_Git.m_critGitDllSec.Unlock();
2642 if(note)
2644 pRev->m_Notes.Empty();
2645 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2648 if(!pRev->m_IsDiffFiles)
2650 pRev->m_CallDiffAsync = DiffAsync;
2653 pRev->ParserParentFromCommit(&commit);
2655 #ifdef DEBUG
2656 pRev->DbgPrint();
2657 TRACE(_T("\n"));
2658 #endif
2660 if(!m_sFilterText.IsEmpty())
2662 if(!IsMatchFilter(bRegex,pRev,pat))
2663 continue;
2665 this->m_critSec.Lock();
2666 m_logEntries.push_back(hash);
2667 m_arShownList.SafeAdd(pRev);
2668 this->m_critSec.Unlock();
2670 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2671 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2673 t2=GetTickCount();
2675 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2677 //update UI
2678 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2679 if(percent > 99)
2680 percent =99;
2681 if(percent < GITLOG_START)
2682 percent = GITLOG_START +1;
2684 oldsize = m_logEntries.size();
2685 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2687 //if( percent > oldprecentage )
2689 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2690 oldprecentage = percent;
2692 t1 = t2;
2695 g_Git.m_critGitDllSec.Lock();
2696 git_close_log(m_DllGitLog);
2697 g_Git.m_critGitDllSec.Unlock();
2701 if (m_bExitThread)
2703 InterlockedExchange(&m_bThreadRunning, FALSE);
2704 return 0;
2707 //Update UI;
2708 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2710 if (lastSelectedHashNItem >= 0)
2711 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2713 if (this->m_hWnd)
2714 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2716 InterlockedExchange(&m_bThreadRunning, FALSE);
2718 return 0;
2721 void CGitLogListBase::FetchRemoteList()
2723 STRING_VECTOR remoteList;
2724 if (!g_Git.GetRemoteList(remoteList))
2725 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
2726 else
2727 m_SingleRemote = _T("");
2730 void CGitLogListBase::FetchTrackingBranchList()
2732 m_TrackingMap.clear();
2733 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
2735 for (int j = 0; j < it->second.size(); ++j)
2737 CString branchName;
2738 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
2740 CString configName;
2741 configName.Format(_T("branch.%s.remote"), branchName);
2742 CString pullRemote = g_Git.GetConfigValue(configName);
2744 configName.Format(_T("branch.%s.merge"), branchName);
2745 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
2747 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
2749 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
2756 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2758 SafeTerminateThread();
2760 this->SetItemCountEx(0);
2761 this->Clear();
2763 ResetWcRev();
2765 // HACK to hide graph column
2766 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2767 SetColumnWidth(0, 0);
2768 else
2769 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2771 //Update branch and Tag info
2772 ReloadHashMap();
2773 //Assume Thread have exited
2774 //if(!m_bThreadRunning)
2776 m_logEntries.clear();
2778 if(IsCleanFilter)
2780 m_sFilterText.Empty();
2781 m_From=-1;
2782 m_To=-1;
2785 InterlockedExchange(&m_bExitThread,FALSE);
2787 InterlockedExchange(&m_bThreadRunning, TRUE);
2788 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2789 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2791 InterlockedExchange(&m_bThreadRunning, FALSE);
2792 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2793 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2797 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2801 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2802 if (!bMatchCase)
2803 type |= tr1::regex_constants::icase;
2804 pat = tr1::wregex(regexp_str, type);
2805 return true;
2807 catch (exception) {}
2808 return false;
2810 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2813 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2814 CString sRev;
2816 if ((bRegex)&&(m_bFilterWithRegex))
2818 if (m_SelectedFilters & LOGFILTER_BUGID)
2820 if(this->m_bShowBugtraqColumn)
2822 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2824 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2825 if (regex_search(wstring(sBugIds), pat, flags))
2827 return TRUE;
2832 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2834 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2835 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2837 return TRUE;
2841 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2843 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2844 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2846 return TRUE;
2850 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2852 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2854 return TRUE;
2857 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2859 return TRUE;
2863 if (m_SelectedFilters & LOGFILTER_EMAILS)
2865 if (regex_search(wstring(pRev->GetAuthorEmail()), pat, flags))
2867 return TRUE;
2870 if (regex_search(wstring(pRev->GetCommitterEmail()), pat, flags))
2872 return TRUE;
2876 if (m_SelectedFilters & LOGFILTER_REVS)
2878 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2879 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2881 return TRUE;
2885 if (m_SelectedFilters & LOGFILTER_REFNAME)
2887 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
2888 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
2890 if (regex_search(wstring((LPCTSTR)*it), pat, flags))
2892 return TRUE;
2897 if (m_SelectedFilters & LOGFILTER_PATHS)
2899 CTGitPathList *pathList=NULL;
2900 if( pRev->m_IsDiffFiles)
2901 pathList = &pRev->GetFiles(this);
2902 else
2904 if(!pRev->m_IsSimpleListReady)
2905 pRev->SafeGetSimpleList(&g_Git);
2908 if(pathList)
2909 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2911 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2913 return true;
2915 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2917 return true;
2921 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
2923 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2925 return true;
2930 else
2932 CString find = m_sFilterText;
2933 find.MakeLower();
2935 if (m_SelectedFilters & LOGFILTER_BUGID)
2937 if(this->m_bShowBugtraqColumn)
2939 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2941 sBugIds.MakeLower();
2942 if ((sBugIds.Find(find) >= 0))
2944 return TRUE;
2949 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2951 CString msg = pRev->GetSubject();
2953 msg = msg.MakeLower();
2954 if ((msg.Find(find) >= 0))
2956 return TRUE;
2960 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2962 CString msg = pRev->GetBody();
2964 msg = msg.MakeLower();
2965 if ((msg.Find(find) >= 0))
2967 return TRUE;
2971 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2973 CString msg = pRev->GetAuthorName();
2974 msg = msg.MakeLower();
2975 if ((msg.Find(find) >= 0))
2977 return TRUE;
2981 if (m_SelectedFilters & LOGFILTER_EMAILS)
2983 CString msg = pRev->GetAuthorEmail();
2984 msg = msg.MakeLower();
2985 if ((msg.Find(find) >= 0))
2987 return TRUE;
2991 if (m_SelectedFilters & LOGFILTER_REVS)
2993 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2994 if ((sRev.Find(find) >= 0))
2996 return TRUE;
3000 if (m_SelectedFilters & LOGFILTER_REFNAME)
3002 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3003 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3005 if (it->Find(find) >= 0)
3007 return TRUE;
3012 if (m_SelectedFilters & LOGFILTER_PATHS)
3014 CTGitPathList *pathList=NULL;
3015 if( pRev->m_IsDiffFiles)
3016 pathList = &pRev->GetFiles(this);
3017 else
3019 if(!pRev->m_IsSimpleListReady)
3020 pRev->SafeGetSimpleList(&g_Git);
3022 if(pathList)
3023 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3025 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3026 CString path = cpath->GetGitOldPathString();
3027 path.MakeLower();
3028 if ((path.Find(find)>=0))
3030 return true;
3032 path = cpath->GetGitPathString();
3033 path.MakeLower();
3034 if ((path.Find(find)>=0))
3036 return true;
3040 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3042 CString path = pRev->m_SimpleFileList[i];
3043 path.MakeLower();
3044 if ((path.Find(find)>=0))
3046 return true;
3050 } // else (from if (bRegex))
3051 return FALSE;
3055 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3058 pShownlist->SafeRemoveAll();
3060 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3061 bool bRegex = false;
3062 if (m_bFilterWithRegex)
3063 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3065 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
3066 CString sRev;
3067 for (DWORD i=0; i<m_logEntries.size(); ++i)
3069 if ((bRegex)&&(m_bFilterWithRegex))
3071 #if 0
3072 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3074 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3075 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3077 pShownlist->SafeAdd(m_logEntries[i]);
3078 continue;
3081 #endif
3082 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3084 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3085 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3087 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3088 continue;
3091 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3093 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3094 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3096 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3097 continue;
3100 if (m_SelectedFilters & LOGFILTER_PATHS)
3102 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3104 bool bGoing = true;
3105 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3107 CTGitPath cpath = pathList[cpPathIndex];
3108 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3110 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3111 bGoing = false;
3112 continue;
3114 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3116 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3117 bGoing = false;
3118 continue;
3120 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3122 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3123 bGoing = false;
3124 continue;
3128 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3130 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3132 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3133 continue;
3136 if (m_SelectedFilters & LOGFILTER_EMAILS)
3138 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3140 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3141 continue;
3144 if (m_SelectedFilters & LOGFILTER_REVS)
3146 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3147 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3149 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3150 continue;
3153 if (m_SelectedFilters & LOGFILTER_REFNAME)
3155 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3156 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3158 if (regex_search(wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3160 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3161 continue;
3165 } // if (bRegex)
3166 else
3168 CString find = m_sFilterText;
3169 find.MakeLower();
3170 #if 0
3171 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3173 CString sBugIDs = m_logEntries[i]->sBugIDs;
3175 sBugIDs = sBugIDs.MakeLower();
3176 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3178 pShownlist->SafeAdd(m_logEntries[i]);
3179 continue;
3182 #endif
3183 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3185 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3187 msg = msg.MakeLower();
3188 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3190 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3191 continue;
3194 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3196 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3198 msg = msg.MakeLower();
3199 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3201 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3202 continue;
3205 if (m_SelectedFilters & LOGFILTER_PATHS)
3207 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3209 bool bGoing = true;
3210 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3212 CTGitPath cpath = pathList[cpPathIndex];
3213 CString path = cpath.GetGitOldPathString();
3214 path.MakeLower();
3215 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3217 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3218 bGoing = false;
3219 continue;
3221 path = cpath.GetGitPathString();
3222 path.MakeLower();
3223 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3225 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3226 bGoing = false;
3227 continue;
3229 path = cpath.GetActionName();
3230 path.MakeLower();
3231 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3233 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3234 bGoing = false;
3235 continue;
3239 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3241 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3242 msg = msg.MakeLower();
3243 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3245 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3246 continue;
3249 if (m_SelectedFilters & LOGFILTER_EMAILS)
3251 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3252 msg = msg.MakeLower();
3253 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3255 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3256 continue;
3259 if (m_SelectedFilters & LOGFILTER_REVS)
3261 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3262 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3264 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3265 continue;
3268 if (m_SelectedFilters & LOGFILTER_REFNAME)
3270 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3271 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3273 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3275 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3276 continue;
3280 } // else (from if (bRegex))
3281 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3285 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3288 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3290 if(m_From == -1)
3291 if(m_To == -1)
3292 return true;
3293 else
3294 return time <= m_To;
3295 else
3296 if(m_To == -1)
3297 return time >= m_From;
3298 else
3299 return ((time >= m_From)&&(time <= m_To));
3301 return TRUE; /* git dll will filter time range */
3303 // return TRUE;
3305 void CGitLogListBase::StartFilter()
3307 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3308 RecalculateShownList(&m_arShownList);
3309 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3312 DeleteAllItems();
3313 SetItemCountEx(ShownCountWithStopped());
3314 RedrawItems(0, ShownCountWithStopped());
3315 Invalidate();
3318 void CGitLogListBase::RemoveFilter()
3321 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3323 m_arShownList.SafeRemoveAll();
3325 // reset the time filter too
3326 #if 0
3327 m_timFrom = (__time64_t(m_tFrom));
3328 m_timTo = (__time64_t(m_tTo));
3329 m_DateFrom.SetTime(&m_timFrom);
3330 m_DateTo.SetTime(&m_timTo);
3331 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3332 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3333 #endif
3335 for (DWORD i=0; i<m_logEntries.size(); ++i)
3337 if(this->m_IsOldFirst)
3339 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3341 else
3343 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3346 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3347 DeleteAllItems();
3348 SetItemCountEx(ShownCountWithStopped());
3349 RedrawItems(0, ShownCountWithStopped());
3351 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3354 void CGitLogListBase::Clear()
3356 m_arShownList.SafeRemoveAll();
3357 DeleteAllItems();
3359 m_logEntries.ClearAll();
3363 void CGitLogListBase::OnDestroy()
3365 // save the column widths to the registry
3366 SaveColumnWidths();
3368 SafeTerminateThread();
3369 SafeTerminateAsyncDiffThread();
3371 int retry = 0;
3372 while(m_LogCache.SaveCache())
3374 if(retry > 5)
3375 break;
3376 Sleep(1000);
3378 ++retry;
3380 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3381 // MB_YESNO) == IDNO)
3382 // break;
3385 CHintListCtrl::OnDestroy();
3388 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3390 CRect rect;
3391 int i=(int)wParam;
3392 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3393 this->InvalidateRect(rect);
3395 return 0;
3399 * Save column widths to the registry
3401 void CGitLogListBase::SaveColumnWidths()
3403 int maxcol = m_ColumnManager.GetColumnCount();
3405 // HACK that graph column is always shown
3406 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3408 for (int col = 0; col < maxcol; ++col)
3409 if (m_ColumnManager.IsVisible (col))
3410 m_ColumnManager.ColumnResized (col);
3412 m_ColumnManager.WriteSettings();
3415 int CGitLogListBase::GetHeadIndex()
3417 if(m_HeadHash.IsEmpty())
3418 return -1;
3420 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3422 GitRev *pRev = (GitRev*)m_arShownList[i];
3423 if(pRev)
3425 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3426 return i;
3429 return -1;
3431 void CGitLogListBase::OnFind()
3433 if (!m_pFindDialog)
3435 m_pFindDialog = new CFindDlg(this);
3436 m_pFindDialog->Create(this);
3439 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3441 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3443 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3445 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3446 Default();
3448 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3450 if (GetSelectedCount() != 0)
3451 return 0;
3452 SetItemState((int)itemToSelect, LVIS_SELECTED, LVIS_SELECTED);
3453 EnsureVisible((int)itemToSelect, FALSE);
3454 return 0;
3456 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3459 ASSERT(m_pFindDialog != NULL);
3460 bool bFound = false;
3461 int i=0;
3463 if (m_pFindDialog->IsTerminating())
3465 // invalidate the handle identifying the dialog box.
3466 m_pFindDialog = NULL;
3467 return 0;
3470 if(m_pFindDialog->IsRef())
3472 CString str;
3473 str=m_pFindDialog->GetFindString();
3475 CGitHash hash;
3477 if(!str.IsEmpty())
3479 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3480 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3483 if(!hash.IsEmpty())
3485 for (i = 0; i<m_arShownList.GetCount(); ++i)
3487 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3488 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3490 bFound = true;
3491 break;
3498 if(m_pFindDialog->FindNext())
3500 //read data from dialog
3501 CString FindText = m_pFindDialog->GetFindString();
3502 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3504 tr1::wregex pat;
3505 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3507 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3510 for (i = this->m_nSearchIndex; i < m_arShownList.GetCount() && !bFound; ++i)
3512 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3514 CString str;
3515 str+=pLogEntry->m_CommitHash.ToString();
3516 str+=_T("\n");
3518 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3520 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3521 str+=_T("\n");
3524 str+=pLogEntry->GetAuthorEmail();
3525 str+=_T("\n");
3526 str+=pLogEntry->GetAuthorName();
3527 str+=_T("\n");
3528 str+=pLogEntry->GetBody();
3529 str+=_T("\n");
3530 str+=pLogEntry->GetCommitterEmail();
3531 str+=_T("\n");
3532 str+=pLogEntry->GetCommitterName();
3533 str+=_T("\n");
3534 str+=pLogEntry->GetSubject();
3535 str+=_T("\n");
3538 /*Because changed files list is loaded on demand when gui show,
3539 files will empty when files have not fetched.
3541 we can add it back by using one-way diff(with outnumber changed and rename detect.
3542 here just need changed filename list. one-way is much quicker.
3544 if(pLogEntry->m_IsFull)
3546 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
3548 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3549 str+=_T("\n");
3550 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3551 str+=_T("\n");
3554 else
3556 if(!pLogEntry->m_IsSimpleListReady)
3557 pLogEntry->SafeGetSimpleList(&g_Git);
3559 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
3561 str+=pLogEntry->m_SimpleFileList[i];
3562 str+=_T("\n");
3568 if (bRegex)
3570 if (regex_search(wstring(str), pat, flags))
3572 bFound = true;
3573 break;
3576 else
3578 if (bMatchCase)
3580 if (str.Find(FindText) >= 0)
3582 bFound = true;
3583 break;
3587 else
3589 CString msg = str;
3590 msg = msg.MakeLower();
3591 CString find = FindText.MakeLower();
3592 if (msg.Find(find) >= 0)
3594 bFound = TRUE;
3595 break;
3599 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3601 } // if(m_pFindDialog->FindNext())
3602 //UpdateLogInfoLabel();
3604 if (bFound)
3606 this->m_nSearchIndex = i;
3607 EnsureVisible(i, FALSE);
3608 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3609 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3610 SetSelectionMark(i);
3611 //FillLogMessageCtrl();
3612 UpdateData(FALSE);
3613 ++m_nSearchIndex;
3614 if (m_nSearchIndex >= m_arShownList.GetCount())
3615 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3618 return 0;
3621 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3623 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3625 *pResult = FALSE;
3628 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3630 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3632 Invalidate(FALSE);