Fixed issue #1646: TortoiseGit Log gives undeterministic results (log does not apply...
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob8747ad544c8d3e8b0cc007bd0f697e2ad4bc270b
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 try {
2409 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2411 return -1;
2414 catch (char* msg)
2416 CString err(msg);
2417 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2418 return -1;
2421 return 0;
2424 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2426 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2428 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2430 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2432 DiffSelectedRevWithPrevious();
2433 return TRUE;
2436 #if 0
2437 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2439 DiffSelectedFile();
2440 return TRUE;
2442 #endif
2444 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2446 // select all entries
2447 for (int i=0; i<GetItemCount(); ++i)
2449 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2451 return TRUE;
2454 #if 0
2455 if (m_hAccel && !bSkipAccelerator)
2457 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2458 if (ret)
2459 return TRUE;
2462 #endif
2463 //m_tooltips.RelayEvent(pMsg);
2464 return __super::PreTranslateMessage(pMsg);
2467 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2469 // a double click on an entry in the revision list has happened
2470 *pResult = 0;
2472 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2473 DiffSelectedRevWithPrevious();
2476 int CGitLogListBase::FetchLogAsync(void * data)
2478 ReloadHashMap();
2479 m_ProcData=data;
2480 m_bExitThread=FALSE;
2481 InterlockedExchange(&m_bThreadRunning, TRUE);
2482 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2483 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2484 if (m_LoadingThread ==NULL)
2486 InterlockedExchange(&m_bThreadRunning, FALSE);
2487 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2488 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2489 return -1;
2491 return 0;
2494 //this is the thread function which calls the subversion function
2495 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2497 return ((CGitLogListBase*)pVoid)->LogThread();
2500 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2502 //CTime time;
2503 oldest=CTime::GetCurrentTime();
2504 latest=CTime(1971,1,2,0,0,0);
2505 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2507 if(m_logEntries[i].IsEmpty())
2508 continue;
2510 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2511 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2513 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2514 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2518 if(latest<oldest)
2519 latest=oldest;
2522 UINT CGitLogListBase::LogThread()
2524 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2526 InterlockedExchange(&m_bThreadRunning, TRUE);
2527 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2529 ULONGLONG t1,t2;
2531 if(BeginFetchLog())
2533 InterlockedExchange(&m_bThreadRunning, FALSE);
2534 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2536 return 1;
2539 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2540 bool bRegex = false;
2541 if (m_bFilterWithRegex)
2542 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2544 TRACE(_T("\n===Begin===\n"));
2545 //Update work copy item;
2547 if (!m_logEntries.empty())
2549 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2551 m_arShownList.SafeAdd(pRev);
2555 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2557 // store commit number of the last selected commit/line before the refresh or -1
2558 int lastSelectedHashNItem = -1;
2559 int ret = 0;
2561 bool shouldWalk = true;
2562 if (!g_Git.CanParseRev(m_sRange))
2564 // walk revisions if show all branches and there exists any ref
2565 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH))
2566 shouldWalk = false;
2567 else
2569 STRING_VECTOR list;
2570 if (g_Git.GetRefList(list))
2571 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2572 if (list.size() == 0)
2573 shouldWalk = false;
2577 if (shouldWalk)
2579 g_Git.m_critGitDllSec.Lock();
2580 int total = 0;
2583 git_get_log_firstcommit(m_DllGitLog);
2584 total = git_get_log_estimate_commit_count(m_DllGitLog);
2586 catch (char* msg)
2588 CString err(msg);
2589 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2590 ret = -1;
2592 g_Git.m_critGitDllSec.Unlock();
2594 GIT_COMMIT commit;
2595 t2=t1=GetTickCount();
2596 int oldprecentage = 0;
2597 size_t oldsize = m_logEntries.size();
2598 while (ret== 0 && !m_bExitThread)
2600 g_Git.m_critGitDllSec.Lock();
2603 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2605 catch (char* msg)
2607 g_Git.m_critGitDllSec.Unlock();
2608 CString err(msg);
2609 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2610 break;
2612 g_Git.m_critGitDllSec.Unlock();
2614 if(ret)
2615 break;
2617 if (commit.m_ignore == 1)
2619 git_free_commit(&commit);
2620 continue;
2623 //printf("%s\r\n",commit.GetSubject());
2624 if(m_bExitThread)
2625 break;
2627 CGitHash hash = (char*)commit.m_hash ;
2629 GitRev *pRev = m_LogCache.GetCacheData(hash);
2630 pRev->m_GitCommit = commit;
2631 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2633 char *note=NULL;
2634 g_Git.m_critGitDllSec.Lock();
2635 git_get_notes(commit.m_hash,&note);
2636 g_Git.m_critGitDllSec.Unlock();
2638 if(note)
2640 pRev->m_Notes.Empty();
2641 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2644 if(!pRev->m_IsDiffFiles)
2646 pRev->m_CallDiffAsync = DiffAsync;
2649 pRev->ParserParentFromCommit(&commit);
2651 #ifdef DEBUG
2652 pRev->DbgPrint();
2653 TRACE(_T("\n"));
2654 #endif
2656 if(!m_sFilterText.IsEmpty())
2658 if(!IsMatchFilter(bRegex,pRev,pat))
2659 continue;
2661 this->m_critSec.Lock();
2662 m_logEntries.push_back(hash);
2663 m_arShownList.SafeAdd(pRev);
2664 this->m_critSec.Unlock();
2666 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2667 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2669 t2=GetTickCount();
2671 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2673 //update UI
2674 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2675 if(percent > 99)
2676 percent =99;
2677 if(percent < GITLOG_START)
2678 percent = GITLOG_START +1;
2680 oldsize = m_logEntries.size();
2681 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2683 //if( percent > oldprecentage )
2685 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2686 oldprecentage = percent;
2688 t1 = t2;
2691 g_Git.m_critGitDllSec.Lock();
2692 git_close_log(m_DllGitLog);
2693 g_Git.m_critGitDllSec.Unlock();
2697 if (m_bExitThread)
2699 InterlockedExchange(&m_bThreadRunning, FALSE);
2700 return 0;
2703 //Update UI;
2704 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2706 if (lastSelectedHashNItem >= 0)
2707 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2709 if (this->m_hWnd)
2710 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2712 InterlockedExchange(&m_bThreadRunning, FALSE);
2714 return 0;
2717 void CGitLogListBase::FetchRemoteList()
2719 STRING_VECTOR remoteList;
2720 if (!g_Git.GetRemoteList(remoteList))
2721 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
2722 else
2723 m_SingleRemote = _T("");
2726 void CGitLogListBase::FetchTrackingBranchList()
2728 m_TrackingMap.clear();
2729 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
2731 for (int j = 0; j < it->second.size(); ++j)
2733 CString branchName;
2734 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
2736 CString configName;
2737 configName.Format(_T("branch.%s.remote"), branchName);
2738 CString pullRemote = g_Git.GetConfigValue(configName);
2740 configName.Format(_T("branch.%s.merge"), branchName);
2741 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
2743 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
2745 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
2752 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2754 SafeTerminateThread();
2756 this->SetItemCountEx(0);
2757 this->Clear();
2759 ResetWcRev();
2761 // HACK to hide graph column
2762 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2763 SetColumnWidth(0, 0);
2764 else
2765 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2767 //Update branch and Tag info
2768 ReloadHashMap();
2769 //Assume Thread have exited
2770 //if(!m_bThreadRunning)
2772 m_logEntries.clear();
2774 if(IsCleanFilter)
2776 m_sFilterText.Empty();
2777 m_From=-1;
2778 m_To=-1;
2781 InterlockedExchange(&m_bExitThread,FALSE);
2783 InterlockedExchange(&m_bThreadRunning, TRUE);
2784 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2785 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2787 InterlockedExchange(&m_bThreadRunning, FALSE);
2788 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2789 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2793 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2797 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2798 if (!bMatchCase)
2799 type |= tr1::regex_constants::icase;
2800 pat = tr1::wregex(regexp_str, type);
2801 return true;
2803 catch (exception) {}
2804 return false;
2806 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2809 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2810 CString sRev;
2812 if ((bRegex)&&(m_bFilterWithRegex))
2814 if (m_SelectedFilters & LOGFILTER_BUGID)
2816 if(this->m_bShowBugtraqColumn)
2818 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2820 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2821 if (regex_search(wstring(sBugIds), pat, flags))
2823 return TRUE;
2828 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2830 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2831 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2833 return TRUE;
2837 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2839 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2840 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2842 return TRUE;
2846 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2848 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2850 return TRUE;
2853 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2855 return TRUE;
2859 if (m_SelectedFilters & LOGFILTER_EMAILS)
2861 if (regex_search(wstring(pRev->GetAuthorEmail()), pat, flags))
2863 return TRUE;
2866 if (regex_search(wstring(pRev->GetCommitterEmail()), pat, flags))
2868 return TRUE;
2872 if (m_SelectedFilters & LOGFILTER_REVS)
2874 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2875 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2877 return TRUE;
2881 if (m_SelectedFilters & LOGFILTER_REFNAME)
2883 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
2884 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
2886 if (regex_search(wstring((LPCTSTR)*it), pat, flags))
2888 return TRUE;
2893 if (m_SelectedFilters & LOGFILTER_PATHS)
2895 CTGitPathList *pathList=NULL;
2896 if( pRev->m_IsDiffFiles)
2897 pathList = &pRev->GetFiles(this);
2898 else
2900 if(!pRev->m_IsSimpleListReady)
2901 pRev->SafeGetSimpleList(&g_Git);
2904 if(pathList)
2905 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2907 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2909 return true;
2911 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2913 return true;
2917 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
2919 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2921 return true;
2926 else
2928 CString find = m_sFilterText;
2929 find.MakeLower();
2931 if (m_SelectedFilters & LOGFILTER_BUGID)
2933 if(this->m_bShowBugtraqColumn)
2935 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2937 sBugIds.MakeLower();
2938 if ((sBugIds.Find(find) >= 0))
2940 return TRUE;
2945 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2947 CString msg = pRev->GetSubject();
2949 msg = msg.MakeLower();
2950 if ((msg.Find(find) >= 0))
2952 return TRUE;
2956 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2958 CString msg = pRev->GetBody();
2960 msg = msg.MakeLower();
2961 if ((msg.Find(find) >= 0))
2963 return TRUE;
2967 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2969 CString msg = pRev->GetAuthorName();
2970 msg = msg.MakeLower();
2971 if ((msg.Find(find) >= 0))
2973 return TRUE;
2977 if (m_SelectedFilters & LOGFILTER_EMAILS)
2979 CString msg = pRev->GetAuthorEmail();
2980 msg = msg.MakeLower();
2981 if ((msg.Find(find) >= 0))
2983 return TRUE;
2987 if (m_SelectedFilters & LOGFILTER_REVS)
2989 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2990 if ((sRev.Find(find) >= 0))
2992 return TRUE;
2996 if (m_SelectedFilters & LOGFILTER_REFNAME)
2998 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
2999 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3001 if (it->Find(find) >= 0)
3003 return TRUE;
3008 if (m_SelectedFilters & LOGFILTER_PATHS)
3010 CTGitPathList *pathList=NULL;
3011 if( pRev->m_IsDiffFiles)
3012 pathList = &pRev->GetFiles(this);
3013 else
3015 if(!pRev->m_IsSimpleListReady)
3016 pRev->SafeGetSimpleList(&g_Git);
3018 if(pathList)
3019 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3021 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3022 CString path = cpath->GetGitOldPathString();
3023 path.MakeLower();
3024 if ((path.Find(find)>=0))
3026 return true;
3028 path = cpath->GetGitPathString();
3029 path.MakeLower();
3030 if ((path.Find(find)>=0))
3032 return true;
3036 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3038 CString path = pRev->m_SimpleFileList[i];
3039 path.MakeLower();
3040 if ((path.Find(find)>=0))
3042 return true;
3046 } // else (from if (bRegex))
3047 return FALSE;
3051 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3054 pShownlist->SafeRemoveAll();
3056 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3057 bool bRegex = false;
3058 if (m_bFilterWithRegex)
3059 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3061 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
3062 CString sRev;
3063 for (DWORD i=0; i<m_logEntries.size(); ++i)
3065 if ((bRegex)&&(m_bFilterWithRegex))
3067 #if 0
3068 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3070 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3071 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3073 pShownlist->SafeAdd(m_logEntries[i]);
3074 continue;
3077 #endif
3078 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3080 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3081 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3083 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3084 continue;
3087 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3089 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3090 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3092 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3093 continue;
3096 if (m_SelectedFilters & LOGFILTER_PATHS)
3098 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3100 bool bGoing = true;
3101 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3103 CTGitPath cpath = pathList[cpPathIndex];
3104 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3106 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3107 bGoing = false;
3108 continue;
3110 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3112 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3113 bGoing = false;
3114 continue;
3116 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3118 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3119 bGoing = false;
3120 continue;
3124 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3126 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3128 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3129 continue;
3132 if (m_SelectedFilters & LOGFILTER_EMAILS)
3134 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3136 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3137 continue;
3140 if (m_SelectedFilters & LOGFILTER_REVS)
3142 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3143 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3145 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3146 continue;
3149 if (m_SelectedFilters & LOGFILTER_REFNAME)
3151 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3152 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3154 if (regex_search(wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3156 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3157 continue;
3161 } // if (bRegex)
3162 else
3164 CString find = m_sFilterText;
3165 find.MakeLower();
3166 #if 0
3167 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3169 CString sBugIDs = m_logEntries[i]->sBugIDs;
3171 sBugIDs = sBugIDs.MakeLower();
3172 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3174 pShownlist->SafeAdd(m_logEntries[i]);
3175 continue;
3178 #endif
3179 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3181 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3183 msg = msg.MakeLower();
3184 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3186 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3187 continue;
3190 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3192 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3194 msg = msg.MakeLower();
3195 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3197 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3198 continue;
3201 if (m_SelectedFilters & LOGFILTER_PATHS)
3203 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3205 bool bGoing = true;
3206 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3208 CTGitPath cpath = pathList[cpPathIndex];
3209 CString path = cpath.GetGitOldPathString();
3210 path.MakeLower();
3211 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3213 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3214 bGoing = false;
3215 continue;
3217 path = cpath.GetGitPathString();
3218 path.MakeLower();
3219 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3221 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3222 bGoing = false;
3223 continue;
3225 path = cpath.GetActionName();
3226 path.MakeLower();
3227 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3229 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3230 bGoing = false;
3231 continue;
3235 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3237 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3238 msg = msg.MakeLower();
3239 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3241 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3242 continue;
3245 if (m_SelectedFilters & LOGFILTER_EMAILS)
3247 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3248 msg = msg.MakeLower();
3249 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3251 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3252 continue;
3255 if (m_SelectedFilters & LOGFILTER_REVS)
3257 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3258 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3260 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3261 continue;
3264 if (m_SelectedFilters & LOGFILTER_REFNAME)
3266 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3267 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3269 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3271 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3272 continue;
3276 } // else (from if (bRegex))
3277 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3281 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3284 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3286 if(m_From == -1)
3287 if(m_To == -1)
3288 return true;
3289 else
3290 return time <= m_To;
3291 else
3292 if(m_To == -1)
3293 return time >= m_From;
3294 else
3295 return ((time >= m_From)&&(time <= m_To));
3297 return TRUE; /* git dll will filter time range */
3299 // return TRUE;
3301 void CGitLogListBase::StartFilter()
3303 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3304 RecalculateShownList(&m_arShownList);
3305 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3308 DeleteAllItems();
3309 SetItemCountEx(ShownCountWithStopped());
3310 RedrawItems(0, ShownCountWithStopped());
3311 Invalidate();
3314 void CGitLogListBase::RemoveFilter()
3317 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3319 m_arShownList.SafeRemoveAll();
3321 // reset the time filter too
3322 #if 0
3323 m_timFrom = (__time64_t(m_tFrom));
3324 m_timTo = (__time64_t(m_tTo));
3325 m_DateFrom.SetTime(&m_timFrom);
3326 m_DateTo.SetTime(&m_timTo);
3327 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3328 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3329 #endif
3331 for (DWORD i=0; i<m_logEntries.size(); ++i)
3333 if(this->m_IsOldFirst)
3335 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3337 else
3339 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3342 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3343 DeleteAllItems();
3344 SetItemCountEx(ShownCountWithStopped());
3345 RedrawItems(0, ShownCountWithStopped());
3347 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3350 void CGitLogListBase::Clear()
3352 m_arShownList.SafeRemoveAll();
3353 DeleteAllItems();
3355 m_logEntries.ClearAll();
3359 void CGitLogListBase::OnDestroy()
3361 // save the column widths to the registry
3362 SaveColumnWidths();
3364 SafeTerminateThread();
3365 SafeTerminateAsyncDiffThread();
3367 int retry = 0;
3368 while(m_LogCache.SaveCache())
3370 if(retry > 5)
3371 break;
3372 Sleep(1000);
3374 ++retry;
3376 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3377 // MB_YESNO) == IDNO)
3378 // break;
3381 CHintListCtrl::OnDestroy();
3384 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3386 CRect rect;
3387 int i=(int)wParam;
3388 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3389 this->InvalidateRect(rect);
3391 return 0;
3395 * Save column widths to the registry
3397 void CGitLogListBase::SaveColumnWidths()
3399 int maxcol = m_ColumnManager.GetColumnCount();
3401 // HACK that graph column is always shown
3402 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3404 for (int col = 0; col < maxcol; ++col)
3405 if (m_ColumnManager.IsVisible (col))
3406 m_ColumnManager.ColumnResized (col);
3408 m_ColumnManager.WriteSettings();
3411 int CGitLogListBase::GetHeadIndex()
3413 if(m_HeadHash.IsEmpty())
3414 return -1;
3416 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3418 GitRev *pRev = (GitRev*)m_arShownList[i];
3419 if(pRev)
3421 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3422 return i;
3425 return -1;
3427 void CGitLogListBase::OnFind()
3429 if (!m_pFindDialog)
3431 m_pFindDialog = new CFindDlg(this);
3432 m_pFindDialog->Create(this);
3435 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3437 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3439 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3441 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3442 Default();
3444 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3446 if (GetSelectedCount() != 0)
3447 return 0;
3448 SetItemState((int)itemToSelect, LVIS_SELECTED, LVIS_SELECTED);
3449 EnsureVisible((int)itemToSelect, FALSE);
3450 return 0;
3452 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3455 ASSERT(m_pFindDialog != NULL);
3456 bool bFound = false;
3457 int i=0;
3459 if (m_pFindDialog->IsTerminating())
3461 // invalidate the handle identifying the dialog box.
3462 m_pFindDialog = NULL;
3463 return 0;
3466 if(m_pFindDialog->IsRef())
3468 CString str;
3469 str=m_pFindDialog->GetFindString();
3471 CGitHash hash;
3473 if(!str.IsEmpty())
3475 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3476 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3479 if(!hash.IsEmpty())
3481 for (i = 0; i<m_arShownList.GetCount(); ++i)
3483 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3484 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3486 bFound = true;
3487 break;
3494 if(m_pFindDialog->FindNext())
3496 //read data from dialog
3497 CString FindText = m_pFindDialog->GetFindString();
3498 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3500 tr1::wregex pat;
3501 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3503 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3506 for (i = this->m_nSearchIndex; i < m_arShownList.GetCount() && !bFound; ++i)
3508 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3510 CString str;
3511 str+=pLogEntry->m_CommitHash.ToString();
3512 str+=_T("\n");
3514 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3516 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3517 str+=_T("\n");
3520 str+=pLogEntry->GetAuthorEmail();
3521 str+=_T("\n");
3522 str+=pLogEntry->GetAuthorName();
3523 str+=_T("\n");
3524 str+=pLogEntry->GetBody();
3525 str+=_T("\n");
3526 str+=pLogEntry->GetCommitterEmail();
3527 str+=_T("\n");
3528 str+=pLogEntry->GetCommitterName();
3529 str+=_T("\n");
3530 str+=pLogEntry->GetSubject();
3531 str+=_T("\n");
3534 /*Because changed files list is loaded on demand when gui show,
3535 files will empty when files have not fetched.
3537 we can add it back by using one-way diff(with outnumber changed and rename detect.
3538 here just need changed filename list. one-way is much quicker.
3540 if(pLogEntry->m_IsFull)
3542 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
3544 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3545 str+=_T("\n");
3546 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3547 str+=_T("\n");
3550 else
3552 if(!pLogEntry->m_IsSimpleListReady)
3553 pLogEntry->SafeGetSimpleList(&g_Git);
3555 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
3557 str+=pLogEntry->m_SimpleFileList[i];
3558 str+=_T("\n");
3564 if (bRegex)
3566 if (regex_search(wstring(str), pat, flags))
3568 bFound = true;
3569 break;
3572 else
3574 if (bMatchCase)
3576 if (str.Find(FindText) >= 0)
3578 bFound = true;
3579 break;
3583 else
3585 CString msg = str;
3586 msg = msg.MakeLower();
3587 CString find = FindText.MakeLower();
3588 if (msg.Find(find) >= 0)
3590 bFound = TRUE;
3591 break;
3595 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3597 } // if(m_pFindDialog->FindNext())
3598 //UpdateLogInfoLabel();
3600 if (bFound)
3602 this->m_nSearchIndex = i;
3603 EnsureVisible(i, FALSE);
3604 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3605 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3606 SetSelectionMark(i);
3607 //FillLogMessageCtrl();
3608 UpdateData(FALSE);
3609 ++m_nSearchIndex;
3610 if (m_nSearchIndex >= m_arShownList.GetCount())
3611 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3614 return 0;
3617 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3619 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3621 *pResult = FALSE;
3624 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3626 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3628 Invalidate(FALSE);