Fixed issue #1623: Search by email in Log window
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob3ac2b54ca3a85bf917faecbe42d8e62dddec80f8
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);
155 m_AsyncThreadExit = FALSE;
156 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
157 m_AsynDiffListLock.Init();
159 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
160 if (m_DiffingThread ==NULL)
162 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
163 return;
168 int CGitLogListBase::AsyncDiffThread()
170 m_AsyncThreadExited = false;
171 while(!m_AsyncThreadExit)
173 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
175 GitRev *pRev = NULL;
176 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
178 m_AsynDiffListLock.Lock();
179 pRev = m_AsynDiffList.back();
180 m_AsynDiffList.pop_back();
181 m_AsynDiffListLock.Unlock();
183 if( pRev->m_CommitHash.IsEmpty() )
185 if(pRev->m_IsDiffFiles)
186 continue;
188 pRev->GetFiles(this).Clear();
189 pRev->m_ParentHash.clear();
190 pRev->m_ParentHash.push_back(m_HeadHash);
191 if(g_Git.IsInitRepos())
193 g_Git.GetInitAddList(pRev->GetFiles(this));
196 else
198 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
200 pRev->GetAction(this) = 0;
202 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
203 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
205 pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER);
207 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
208 InterlockedExchange(&pRev->m_IsFull, TRUE);
210 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
211 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
212 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
215 if(!pRev->CheckAndDiff())
216 { // fetch change file list
217 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
219 if(i < m_arShownList.GetCount())
221 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
222 if(data->m_CommitHash == pRev->m_CommitHash)
224 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
225 break;
230 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
232 POSITION pos = GetFirstSelectedItemPosition();
233 int nItem = GetNextSelectedItem(pos);
235 if(nItem>=0)
237 GitRev* data = (GitRev*)m_arShownList[nItem];
238 if(data)
239 if(data->m_CommitHash == pRev->m_CommitHash)
241 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
248 m_AsyncThreadExited = true;
249 return 0;
251 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
253 if (exclusivelyShow)
255 m_ContextMenuMask &= hideMask;
257 else
259 m_ContextMenuMask &= ~hideMask;
263 CGitLogListBase::~CGitLogListBase()
265 InterlockedExchange(&m_bNoDispUpdates, TRUE);
266 this->m_arShownList.SafeRemoveAll();
268 DestroyIcon(m_hModifiedIcon);
269 DestroyIcon(m_hReplacedIcon);
270 DestroyIcon(m_hAddedIcon);
271 DestroyIcon(m_hDeletedIcon);
272 m_logEntries.ClearAll();
274 if (m_boldFont)
275 DeleteObject(m_boldFont);
277 if ( m_pStoreSelection )
279 delete m_pStoreSelection;
280 m_pStoreSelection = NULL;
283 SafeTerminateThread();
284 SafeTerminateAsyncDiffThread();
286 if(m_AsyncDiffEvent)
287 CloseHandle(m_AsyncDiffEvent);
291 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
292 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
293 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
294 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
295 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
296 ON_WM_CONTEXTMENU()
297 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
298 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
299 ON_WM_CREATE()
300 ON_WM_DESTROY()
301 ON_MESSAGE(MSG_LOADED,OnLoad)
302 ON_WM_MEASUREITEM()
303 ON_WM_MEASUREITEM_REFLECT()
304 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
305 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
306 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
307 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
308 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
309 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
310 END_MESSAGE_MAP()
312 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
314 //if (m_nRowHeight>0)
316 lpMeasureItemStruct->itemHeight = 50;
320 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
322 PreSubclassWindow();
323 return CHintListCtrl::OnCreate(lpCreateStruct);
326 void CGitLogListBase::PreSubclassWindow()
328 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
329 // load the icons for the action columns
330 // m_Theme.Open(m_hWnd, L"ListView");
331 SetWindowTheme(m_hWnd, L"Explorer", NULL);
332 CHintListCtrl::PreSubclassWindow();
335 void CGitLogListBase::InsertGitColumn()
337 CString temp;
339 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
340 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
341 if (DWORD(regFullRowSelect))
342 exStyle |= LVS_EX_FULLROWSELECT;
343 SetExtendedStyle(exStyle);
345 // only load properties if we have a repository
346 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
347 UpdateProjectProperties();
349 static UINT normal[] =
351 IDS_LOG_GRAPH,
352 IDS_LOG_REBASE,
353 IDS_LOG_ID,
354 IDS_LOG_HASH,
355 IDS_LOG_ACTIONS,
356 IDS_LOG_MESSAGE,
357 IDS_LOG_AUTHOR,
358 IDS_LOG_DATE,
359 IDS_LOG_EMAIL,
360 IDS_LOG_COMMIT_NAME,
361 IDS_LOG_COMMIT_EMAIL,
362 IDS_LOG_COMMIT_DATE,
363 IDS_LOG_BUGIDS,
366 static int with[] =
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 ICONITEMBORDER+16*4,
372 ICONITEMBORDER+16*4,
373 LOGLIST_MESSAGE_MIN,
374 ICONITEMBORDER+16*4,
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
382 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
384 DWORD hideColumns = 0;
385 if(this->m_IsRebaseReplaceGraph)
387 hideColumns |= GIT_LOG_GRAPH;
388 m_dwDefaultColumns |= GIT_LOG_REBASE;
390 else
392 hideColumns |= GIT_LOG_REBASE;
395 if(this->m_IsIDReplaceAction)
397 hideColumns |= GIT_LOG_ACTIONS;
398 m_dwDefaultColumns |= GIT_LOG_ID;
399 m_dwDefaultColumns |= GIT_LOG_HASH;
401 else
403 hideColumns |= GIT_LOG_ID;
405 if(this->m_bShowBugtraqColumn)
407 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
409 else
411 hideColumns |= GIT_LOGLIST_BUG;
413 SetRedraw(false);
415 m_ColumnManager.SetNames(normal, _countof(normal));
416 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
418 SetRedraw(true);
422 * Resizes all columns in a list control to values in registry.
424 void CGitLogListBase::ResizeAllListCtrlCols()
426 // column max and min widths to allow
427 static const int nMinimumWidth = 10;
428 static const int nMaximumWidth = 1000;
429 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
430 if (pHdrCtrl)
432 int numcols = pHdrCtrl->GetItemCount();
433 for (int col = 0; col < numcols; col++)
435 // get width for this col last time from registry
436 CString regentry;
437 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
438 CRegDWORD regwidth(regentry, 0);
439 int cx = regwidth;
440 if ( cx == 0 )
442 // no saved value, setup sensible defaults
443 if (col == this->LOGLIST_MESSAGE)
445 cx = LOGLIST_MESSAGE_MIN;
447 else
449 cx = ICONITEMBORDER+16*4;
452 if (cx < nMinimumWidth)
454 cx = nMinimumWidth;
456 else if (cx > nMaximumWidth)
458 cx = nMaximumWidth;
461 SetColumnWidth(col, cx);
468 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
470 LVITEM rItem;
471 SecureZeroMemory(&rItem, sizeof(LVITEM));
472 rItem.mask = LVIF_STATE;
473 rItem.iItem = (int)Index;
474 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
475 GetItem(&rItem);
477 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
478 HBRUSH brush = NULL;
480 if (!(rItem.state & LVIS_SELECTED))
482 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
483 brush = ::CreateSolidBrush(RGB(156,156,156));
484 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
485 brush = ::CreateSolidBrush(RGB(200,200,128));
487 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
489 if (rItem.state & LVIS_SELECTED)
491 if (::GetFocus() == m_hWnd)
492 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
493 else
494 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
498 if (brush != NULL)
500 ::FillRect(hdc, &rect, brush);
501 ::DeleteObject(brush);
505 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
507 POINT point = { 4, 4 };
508 CRect rt2 = rect;
509 rt2.DeflateRect(1, 1);
510 rt2.OffsetRect(2, 2);
512 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
513 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
514 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
515 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
516 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
518 ::SelectObject(hdc, brush);
519 rt2.OffsetRect(-2, -2);
520 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
521 ::SelectObject(hdc, oldbrush);
522 ::SelectObject(hdc, oldpen);
523 ::DeleteObject(nullPen);
524 ::DeleteObject(darkBrush);
527 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
529 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
530 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
531 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
532 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
533 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
534 ::LineTo(hdc, rect.left, rect.bottom);
535 ::SelectObject(hdc, oldpen);
536 ::DeleteObject(pen);
539 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
541 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
542 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
543 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
544 ::LineTo(hdc, rect.left, rect.bottom);
545 ::LineTo(hdc, rect.right, rect.bottom);
546 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
547 ::SelectObject(hdc, oldpen);
548 ::DeleteObject(pen);
551 void CGitLogListBase::DrawTagBranch(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> refList)
553 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
554 CRect rt=rect;
555 LVITEM rItem;
556 SecureZeroMemory(&rItem, sizeof(LVITEM));
557 rItem.mask = LVIF_STATE;
558 rItem.iItem = (int)index;
559 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
560 GetItem(&rItem);
562 CDC W_Dc;
563 W_Dc.Attach(hdc);
565 HTHEME hTheme = NULL;
566 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
567 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
569 for (unsigned int i = 0; i < refList.size(); i++)
571 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
572 HBRUSH brush = 0;
573 COLORREF colRef = refList[i].color;
574 bool singleRemote = refList[i].singleRemote;
575 bool hasTracking = refList[i].hasTracking;
576 bool sameName = refList[i].sameName;
578 //When row selected, ajust label color
579 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
580 if (rItem.state & LVIS_SELECTED)
581 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
583 brush = ::CreateSolidBrush(colRef);
585 if(!shortname.IsEmpty() && (rt.left<rect.right) )
587 SIZE size;
588 memset(&size,0,sizeof(SIZE));
589 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
591 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
592 rt.right+=8;
594 int textpos = DT_CENTER;
596 if(rt.right > rect.right)
598 rt.right = rect.right;
599 textpos =0;
602 CRect textRect = rt;
604 if (singleRemote)
606 rt.right += 8;
607 textRect.OffsetRect(8, 0);
610 if (sameName)
611 rt.right += 8;
613 if (hasTracking)
615 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
617 else
619 //Fill interior of ref label
620 ::FillRect(hdc, &rt, brush);
623 //Draw edge of label
625 CRect rectEdge = rt;
627 if (!hasTracking)
629 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
630 rectEdge.DeflateRect(1, 1);
631 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
634 //Draw text inside label
635 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
636 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
638 int txtState = LISS_NORMAL;
639 if (rItem.state & LVIS_SELECTED)
640 txtState = LISS_SELECTED;
642 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
644 else
646 W_Dc.SetBkMode(TRANSPARENT);
647 if (customColor || (rItem.state & LVIS_SELECTED))
649 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
650 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
651 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
652 ::SetTextColor(hdc,clrOld);
654 else
656 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
660 if (singleRemote)
662 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
663 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
664 CRect newRect;
665 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
666 DrawLightning(hdc, newRect, color, bold);
669 if (sameName)
671 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
672 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
673 CRect newRect;
674 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
675 DrawUpTriangle(hdc, newRect, color, bold);
678 //::MoveToEx(hdc,rt.left,rt.top,NULL);
679 //::LineTo(hdc,rt.right,rt.top);
680 //::LineTo(hdc,rt.right,rt.bottom);
681 //::LineTo(hdc,rt.left,rt.bottom);
682 //::LineTo(hdc,rt.left,rt.top);
684 rt.left=rt.right+1;
686 if(brush)
687 ::DeleteObject(brush);
689 rt.right=rect.right;
691 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
693 int txtState = LISS_NORMAL;
694 if (rItem.state & LVIS_SELECTED)
695 txtState = LISS_SELECTED;
697 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
699 else
701 if (rItem.state & LVIS_SELECTED)
703 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
704 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
705 ::SetTextColor(hdc,clrOld);
707 else
709 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
713 if (hTheme)
714 CloseThemeData(hTheme);
716 W_Dc.Detach();
719 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
721 // Returns ((256 - amount)*col1 + amount*col2) / 256;
722 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
723 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
724 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
727 Gdiplus::Color GetGdiColor(COLORREF col)
729 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
731 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
732 const COLORREF& col,const COLORREF& activeColor, int top
735 int h = laneHeight / 2;
736 int m = (x1 + x2) / 2;
737 int r = (x2 - x1) / 3;
738 int d = 2 * r;
740 #define P_CENTER m , h+top
741 #define P_0 x2, h+top
742 #define P_90 m , 0+top-1
743 #define P_180 x1, h+top
744 #define P_270 m , 2 * h+top +1
745 #define R_CENTER m - r, h - r+top, d, d
748 #define DELTA_UR_B 2*(x1 - m), 2*h +top
749 #define DELTA_UR_E 0*16, 90*16 +top // -,
751 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
752 #define DELTA_DR_E 270*16, 90*16 +top // -'
754 #define DELTA_UL_B 2*(x2 - m), 2*h +top
755 #define DELTA_UL_E 90*16, 90*16 +top // ,-
757 #define DELTA_DL_B 2*(x2 - m),2*-h +top
758 #define DELTA_DL_E 180*16, 90*16 // '-
760 #define CENTER_UR x1, 2*h, 225
761 #define CENTER_DR x1, 0 , 135
762 #define CENTER_UL x2, 2*h, 315
763 #define CENTER_DL x2, 0 , 45
766 Gdiplus::Graphics graphics( hdc );
768 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
770 // arc
771 switch (type) {
772 case Lanes::JOIN:
773 case Lanes::JOIN_R:
774 case Lanes::HEAD:
775 case Lanes::HEAD_R:
777 Gdiplus::LinearGradientBrush gradient(
778 Gdiplus::Point(x1-2, h+top-2),
779 Gdiplus::Point(P_270),
780 GetGdiColor(activeColor),GetGdiColor(col));
783 Gdiplus::Pen mypen(&gradient,2);
784 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
786 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
787 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
788 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
790 break;
792 case Lanes::JOIN_L:
795 Gdiplus::LinearGradientBrush gradient(
796 Gdiplus::Point(P_270),
797 Gdiplus::Point(x2+1, h+top-1),
798 GetGdiColor(col),GetGdiColor(activeColor));
801 Gdiplus::Pen mypen(&gradient,2);
802 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
804 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
805 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
806 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
809 break;
811 case Lanes::TAIL:
812 case Lanes::TAIL_R:
815 Gdiplus::LinearGradientBrush gradient(
816 Gdiplus::Point(x1-2, h+top-2),
817 Gdiplus::Point(P_90),
818 GetGdiColor(activeColor),GetGdiColor(col));
820 Gdiplus::Pen mypen(&gradient,2);
822 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
824 #if 0
825 QConicalGradient gradient(CENTER_DR);
826 gradient.setColorAt(0.375, activeCol);
827 gradient.setColorAt(0.625, col);
828 myPen.setBrush(gradient);
829 p->setPen(myPen);
830 p->drawArc(P_CENTER, DELTA_DR);
831 #endif
832 break;
834 default:
835 break;
839 //static QPen myPen(Qt::black, 2); // fast path here
840 CPen pen;
841 pen.CreatePen(PS_SOLID,2,col);
842 //myPen.setColor(col);
843 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
845 Gdiplus::Pen myPen(GetGdiColor(col),2);
847 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
849 //p->setPen(myPen);
851 // vertical line
852 switch (type) {
853 case Lanes::ACTIVE:
854 case Lanes::NOT_ACTIVE:
855 case Lanes::MERGE_FORK:
856 case Lanes::MERGE_FORK_R:
857 case Lanes::MERGE_FORK_L:
858 case Lanes::JOIN:
859 case Lanes::JOIN_R:
860 case Lanes::JOIN_L:
861 case Lanes::CROSS:
862 //DrawLine(hdc,P_90,P_270);
863 graphics.DrawLine(&myPen,P_90,P_270);
864 //p->drawLine(P_90, P_270);
865 break;
866 case Lanes::HEAD_L:
867 case Lanes::BRANCH:
868 //DrawLine(hdc,P_CENTER,P_270);
869 graphics.DrawLine(&myPen,P_CENTER,P_270);
870 //p->drawLine(P_CENTER, P_270);
871 break;
872 case Lanes::TAIL_L:
873 case Lanes::INITIAL:
874 case Lanes::BOUNDARY:
875 case Lanes::BOUNDARY_C:
876 case Lanes::BOUNDARY_R:
877 case Lanes::BOUNDARY_L:
878 //DrawLine(hdc,P_90, P_CENTER);
879 graphics.DrawLine(&myPen,P_90,P_CENTER);
880 //p->drawLine(P_90, P_CENTER);
881 break;
882 default:
883 break;
886 myPen.SetColor(GetGdiColor(activeColor));
888 // horizontal line
889 switch (type) {
890 case Lanes::MERGE_FORK:
891 case Lanes::JOIN:
892 case Lanes::HEAD:
893 case Lanes::TAIL:
894 case Lanes::CROSS:
895 case Lanes::CROSS_EMPTY:
896 case Lanes::BOUNDARY_C:
897 //DrawLine(hdc,P_180,P_0);
898 graphics.DrawLine(&myPen,P_180,P_0);
899 //p->drawLine(P_180, P_0);
900 break;
901 case Lanes::MERGE_FORK_R:
902 case Lanes::BOUNDARY_R:
903 //DrawLine(hdc,P_180,P_CENTER);
904 graphics.DrawLine(&myPen,P_180,P_CENTER);
905 //p->drawLine(P_180, P_CENTER);
906 break;
907 case Lanes::MERGE_FORK_L:
908 case Lanes::HEAD_L:
909 case Lanes::TAIL_L:
910 case Lanes::BOUNDARY_L:
911 //DrawLine(hdc,P_CENTER,P_0);
912 graphics.DrawLine(&myPen,P_CENTER,P_0);
913 //p->drawLine(P_CENTER, P_0);
914 break;
915 default:
916 break;
919 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
921 CBrush brush;
922 brush.CreateSolidBrush(col);
923 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
925 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
926 // center symbol, e.g. rect or ellipse
927 switch (type) {
928 case Lanes::ACTIVE:
929 case Lanes::INITIAL:
930 case Lanes::BRANCH:
932 //p->setPen(Qt::NoPen);
933 //p->setBrush(col);
934 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
935 graphics.FillEllipse(&myBrush, R_CENTER);
936 //p->drawEllipse(R_CENTER);
937 break;
938 case Lanes::MERGE_FORK:
939 case Lanes::MERGE_FORK_R:
940 case Lanes::MERGE_FORK_L:
941 //p->setPen(Qt::NoPen);
942 //p->setBrush(col);
943 //p->drawRect(R_CENTER);
944 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
945 graphics.FillRectangle(&myBrush, R_CENTER);
946 break;
947 case Lanes::UNAPPLIED:
948 // Red minus sign
949 //p->setPen(Qt::NoPen);
950 //p->setBrush(Qt::red);
951 //p->drawRect(m - r, h - 1, d, 2);
952 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
953 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
954 break;
955 case Lanes::APPLIED:
956 // Green plus sign
957 //p->setPen(Qt::NoPen);
958 //p->setBrush(DARK_GREEN);
959 //p->drawRect(m - r, h - 1, d, 2);
960 //p->drawRect(m - 1, h - r, 2, d);
961 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
962 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
963 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
964 break;
965 case Lanes::BOUNDARY:
966 //p->setBrush(back);
967 //p->drawEllipse(R_CENTER);
968 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
969 graphics.DrawEllipse(&myPen, R_CENTER);
970 break;
971 case Lanes::BOUNDARY_C:
972 case Lanes::BOUNDARY_R:
973 case Lanes::BOUNDARY_L:
974 //p->setBrush(back);
975 //p->drawRect(R_CENTER);
976 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
977 graphics.FillRectangle(&myBrush,R_CENTER);
978 break;
979 default:
980 break;
983 ::SelectObject(hdc,oldpen);
984 ::SelectObject(hdc,oldbrush);
985 #undef P_CENTER
986 #undef P_0
987 #undef P_90
988 #undef P_180
989 #undef P_270
990 #undef R_CENTER
993 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
995 // TODO: unfinished
996 // return;
997 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
998 if(data->m_CommitHash.IsEmpty())
999 return;
1001 CRect rt=rect;
1002 LVITEM rItem;
1003 SecureZeroMemory(&rItem, sizeof(LVITEM));
1004 rItem.mask = LVIF_STATE;
1005 rItem.iItem = (int)index;
1006 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1007 GetItem(&rItem);
1009 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1011 if (data->m_Lanes.empty())
1012 m_logEntries.setLane(data->m_CommitHash);
1014 std::vector<int>& lanes=data->m_Lanes;
1015 size_t laneNum = lanes.size();
1016 UINT activeLane = 0;
1017 for (UINT i = 0; i < laneNum; i++)
1018 if (Lanes::isMerge(lanes[i])) {
1019 activeLane = i;
1020 break;
1023 int x1 = 0, x2 = 0;
1024 int maxWidth = rect.Width();
1025 int lw = 3 * rect.Height() / 4; //laneWidth()
1027 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1028 //if (opt.state & QStyle::State_Selected)
1029 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1031 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1034 x1 = x2;
1035 x2 += lw;
1037 int ln = lanes[i];
1038 if (ln == Lanes::EMPTY)
1039 continue;
1041 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1042 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1045 #if 0
1046 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1048 x1 = x2;
1049 x2 += lw;
1051 int ln = lanes[i];
1052 if (ln == Lanes::EMPTY)
1053 continue;
1055 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1056 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1058 if (ln == Lanes::CROSS)
1060 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1061 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1063 else
1064 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1066 #endif
1070 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1073 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1074 // Take the default processing unless we set this to something else below.
1075 *pResult = CDRF_DODEFAULT;
1077 if (m_bNoDispUpdates)
1078 return;
1080 switch (pLVCD->nmcd.dwDrawStage)
1082 case CDDS_PREPAINT:
1084 *pResult = CDRF_NOTIFYITEMDRAW;
1085 return;
1087 break;
1088 case CDDS_ITEMPREPAINT:
1090 // This is the prepaint stage for an item. Here's where we set the
1091 // item's text color.
1093 // Tell Windows to send draw notifications for each subitem.
1094 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1096 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1098 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1100 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1101 if (data)
1103 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1104 crText = RGB(128,128,128);
1106 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1107 pLVCD->clrTextBk = RGB(156,156,156);
1108 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1109 pLVCD->clrTextBk = RGB(200,200,128);
1110 else
1111 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1113 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1115 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1116 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1119 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1121 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1122 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1125 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1126 // crText = GetSysColor(COLOR_GRAYTEXT);
1128 if (data->m_CommitHash.IsEmpty())
1130 //crText = GetSysColor(RGB(200,200,0));
1131 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1132 // We changed the font, so we're returning CDRF_NEWFONT. This
1133 // tells the control to recalculate the extent of the text.
1134 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1138 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1140 if (m_bStrictStopped)
1141 crText = GetSysColor(COLOR_GRAYTEXT);
1143 // Store the color back in the NMLVCUSTOMDRAW struct.
1144 pLVCD->clrText = crText;
1145 return;
1147 break;
1148 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1150 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1152 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1155 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1157 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1159 CRect rect;
1160 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1162 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1163 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1165 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1166 if( !data ->m_CommitHash.IsEmpty())
1167 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1169 *pResult = CDRF_SKIPDEFAULT;
1170 return;
1174 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1176 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1178 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1179 //if(!data->m_IsFull)
1181 //if(data->SafeFetchFullInfo(&g_Git))
1182 // this->Invalidate();
1183 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1186 if (!m_HashMap[data->m_CommitHash].empty())
1188 CRect rect;
1190 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1192 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1194 std::vector<REFLABEL> refsToShow;
1195 STRING_VECTOR remoteTrackingList;
1196 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1197 for (unsigned int i = 0; i < refList.size(); i++)
1199 CString str = refList[i];
1201 REFLABEL refLabel;
1202 refLabel.color = RGB(255, 255, 255);
1203 refLabel.singleRemote = false;
1204 refLabel.hasTracking = false;
1205 refLabel.sameName = false;
1206 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1208 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1209 continue;
1210 if (refLabel.name == m_CurrentBranch )
1211 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1212 else
1213 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1215 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1216 CString pullRemote = trackingEntry.first;
1217 CString pullBranch = trackingEntry.second;
1218 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1220 CString defaultUpstream;
1221 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1222 refLabel.hasTracking = true;
1223 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1225 bool found = false;
1226 for (int j = i + 1; j < refList.size(); j++)
1228 if (refList[j] == defaultUpstream)
1230 found = true;
1231 break;
1235 if (found)
1237 bool sameName = pullBranch == refLabel.name;
1238 refsToShow.push_back(refLabel);
1239 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1240 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1241 if (m_bSymbolizeRefNames)
1243 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1245 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1246 refLabel.singleRemote = true;
1248 else if (sameName)
1249 refLabel.simplifiedName = pullRemote + _T("/");
1250 refLabel.sameName = sameName;
1252 refsToShow.push_back(refLabel);
1253 remoteTrackingList.push_back(defaultUpstream);
1254 continue;
1259 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1261 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1262 continue;
1264 bool found = false;
1265 for (int j = 0; j < remoteTrackingList.size(); j++)
1267 if (remoteTrackingList[j] == str)
1269 found = true;
1270 break;
1273 if (found)
1274 continue;
1276 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1277 if (m_bSymbolizeRefNames)
1279 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1281 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1282 refLabel.singleRemote = true;
1286 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1288 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1289 continue;
1290 refLabel.color = m_Colors.GetColor(CColors::Tag);
1292 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1294 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1295 continue;
1296 refLabel.color = m_Colors.GetColor(CColors::Stash);
1297 refLabel.name = _T("stash");
1299 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1301 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1302 continue;
1303 if (refLabel.name.Find(_T("good")) == 0)
1305 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1306 refLabel.name = _T("good");
1308 if (refLabel.name.Find(_T("bad")) == 0)
1310 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1311 refLabel.name = _T("bad");
1314 else
1315 continue;
1317 refsToShow.push_back(refLabel);
1320 if (refsToShow.empty())
1322 *pResult = CDRF_DODEFAULT;
1323 return;
1326 DrawTagBranch(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1328 *pResult = CDRF_SKIPDEFAULT;
1329 return;
1336 if (pLVCD->iSubItem == LOGLIST_ACTION)
1338 if(this->m_IsIDReplaceAction)
1340 *pResult = CDRF_DODEFAULT;
1341 return;
1343 *pResult = CDRF_DODEFAULT;
1345 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1346 return;
1348 int nIcons = 0;
1349 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1350 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1352 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1353 CRect rect;
1354 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1355 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1356 // Get the selected state of the
1357 // item being drawn.
1359 // Fill the background if necessary
1360 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1362 // Draw the icon(s) into the compatible DC
1363 pLogEntry->GetAction(this);
1365 if (!pLogEntry->m_IsDiffFiles)
1366 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1368 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1369 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1370 nIcons++;
1372 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1373 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1374 nIcons++;
1376 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1377 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1378 nIcons++;
1380 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1381 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1382 nIcons++;
1383 *pResult = CDRF_SKIPDEFAULT;
1384 return;
1387 break;
1389 *pResult = CDRF_DODEFAULT;
1392 // CGitLogListBase message handlers
1394 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1396 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1398 // Create a pointer to the item
1399 LV_ITEM* pItem = &(pDispInfo)->item;
1401 // Do the list need text information?
1402 if (!(pItem->mask & LVIF_TEXT))
1403 return;
1405 // By default, clear text buffer.
1406 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1408 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1410 *pResult = 0;
1411 if (m_bNoDispUpdates || bOutOfRange)
1412 return;
1414 // Which item number?
1415 int itemid = pItem->iItem;
1416 GitRev * pLogEntry = NULL;
1417 if (itemid < m_arShownList.GetCount())
1418 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1420 CString temp;
1421 if(m_IsOldFirst)
1423 temp.Format(_T("%d"),pItem->iItem+1);
1426 else
1428 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1431 // Which column?
1432 switch (pItem->iSubItem)
1434 case this->LOGLIST_GRAPH: //Graphic
1435 break;
1436 case this->LOGLIST_REBASE:
1438 if(this->m_IsRebaseReplaceGraph)
1440 CTGitPath path;
1441 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1442 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1445 break;
1446 case this->LOGLIST_ACTION: //action -- no text in the column
1447 break;
1448 case this->LOGLIST_HASH:
1449 if(pLogEntry)
1450 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1451 break;
1452 case this->LOGLIST_ID:
1453 if(this->m_IsIDReplaceAction)
1454 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1455 break;
1456 case this->LOGLIST_MESSAGE: //Message
1457 if (pLogEntry)
1458 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1459 break;
1460 case this->LOGLIST_AUTHOR: //Author
1461 if (pLogEntry)
1462 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1463 break;
1464 case this->LOGLIST_DATE: //Date
1465 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1466 lstrcpyn(pItem->pszText,
1467 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1468 pItem->cchTextMax);
1469 break;
1471 case this->LOGLIST_EMAIL:
1472 if (pLogEntry)
1473 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1474 break;
1476 case this->LOGLIST_COMMIT_NAME: //Commit
1477 if (pLogEntry)
1478 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1479 break;
1481 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1482 if (pLogEntry)
1483 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1484 break;
1486 case this->LOGLIST_COMMIT_DATE: //Commit Date
1487 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1488 lstrcpyn(pItem->pszText,
1489 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1490 pItem->cchTextMax);
1491 break;
1492 case this->LOGLIST_BUG: //Bug ID
1493 if(pLogEntry)
1494 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1495 break;
1497 default:
1498 ASSERT(false);
1502 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1505 if (pWnd == GetHeaderCtrl())
1507 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1510 int selIndex = GetSelectionMark();
1511 if (selIndex < 0)
1512 return; // nothing selected, nothing to do with a context menu
1514 // if the user selected the info text telling about not all revisions shown due to
1515 // the "stop on copy/rename" option, we also don't show the context menu
1516 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1517 return;
1519 // if the context menu is invoked through the keyboard, we have to use
1520 // a calculated position on where to anchor the menu on
1521 if ((point.x == -1) && (point.y == -1))
1523 CRect rect;
1524 GetItemRect(selIndex, &rect, LVIR_LABEL);
1525 ClientToScreen(&rect);
1526 point = rect.CenterPoint();
1528 m_nSearchIndex = selIndex;
1529 m_bCancelled = FALSE;
1531 // calculate some information the context menu commands can use
1532 // CString pathURL = GetURLFromPath(m_path);
1534 POSITION pos = GetFirstSelectedItemPosition();
1535 int indexNext = GetNextSelectedItem(pos);
1536 if (indexNext < 0)
1537 return;
1539 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1540 #if 0
1541 GitRev revSelected = pSelLogEntry->Rev;
1542 GitRev revPrevious = git_revnum_t(revSelected)-1;
1543 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1545 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1547 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1548 if (changedpath->lCopyFromRev)
1549 revPrevious = changedpath->lCopyFromRev;
1552 GitRev revSelected2;
1553 if (pos)
1555 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1556 revSelected2 = pLogEntry->Rev;
1558 bool bAllFromTheSameAuthor = true;
1559 CString firstAuthor;
1560 CLogDataVector selEntries;
1561 GitRev revLowest, revHighest;
1562 GitRevRangeArray revisionRanges;
1564 POSITION pos = GetFirstSelectedItemPosition();
1565 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1566 revisionRanges.AddRevision(pLogEntry->Rev);
1567 selEntries.push_back(pLogEntry);
1568 firstAuthor = pLogEntry->sAuthor;
1569 revLowest = pLogEntry->Rev;
1570 revHighest = pLogEntry->Rev;
1571 while (pos)
1573 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1574 revisionRanges.AddRevision(pLogEntry->Rev);
1575 selEntries.push_back(pLogEntry);
1576 if (firstAuthor.Compare(pLogEntry->sAuthor))
1577 bAllFromTheSameAuthor = false;
1578 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1579 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1583 #endif
1585 int FirstSelect=-1, LastSelect=-1;
1586 pos = GetFirstSelectedItemPosition();
1587 FirstSelect = GetNextSelectedItem(pos);
1588 while(pos)
1590 LastSelect = GetNextSelectedItem(pos);
1592 //entry is selected, now show the popup menu
1593 CIconMenu popup;
1594 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1596 if (popup.CreatePopupMenu())
1598 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1599 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1601 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1602 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1604 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1605 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1607 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1608 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1610 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1611 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1613 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1614 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1615 popup.AppendMenu(MF_SEPARATOR, NULL);
1617 if (GetSelectedCount() == 1)
1621 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1623 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1624 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1626 else
1628 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1629 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1631 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1633 GitRev *pRev=pSelLogEntry;
1634 if (pSelLogEntry->m_ParentHash.empty())
1636 pRev->GetParentFromHash(pRev->m_CommitHash);
1638 if(pRev->m_ParentHash.size()<=1)
1640 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1643 else
1645 gnudiffmenu.CreatePopupMenu();
1646 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1648 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1649 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1651 for(int i=0;i<pRev->m_ParentHash.size();i++)
1653 CString str;
1654 str.Format(IDS_PARENT, i + 1);
1655 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1660 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1663 GitRev *pRev=pSelLogEntry;
1664 if (pSelLogEntry->m_ParentHash.empty())
1666 pRev->GetParentFromHash(pRev->m_CommitHash);
1668 if(pRev->m_ParentHash.size()<=1)
1670 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1671 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1672 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1674 else
1676 diffmenu.CreatePopupMenu();
1677 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1678 for(int i=0;i<pRev->m_ParentHash.size();i++)
1680 CString str;
1681 str.Format(IDS_PARENT, i + 1);
1682 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1683 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1685 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1686 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1692 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1693 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1695 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1696 popup.AppendMenu(MF_SEPARATOR, NULL);
1698 if (pSelLogEntry->m_CommitHash.IsEmpty())
1700 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1701 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1704 bool isStash = false;
1705 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1707 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1709 isStash = true;
1710 break;
1714 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1716 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1717 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1719 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1720 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1722 popup.AppendMenu(MF_SEPARATOR, NULL);
1725 if (pSelLogEntry->m_CommitHash.IsEmpty())
1727 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1728 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1730 popup.AppendMenu(MF_SEPARATOR, NULL);
1734 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1735 // {
1736 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1737 // }
1738 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1739 // {
1740 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1741 // }
1742 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1743 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1744 // {
1745 // popup.AppendMenu(MF_SEPARATOR, NULL);
1746 // }
1748 CString str,format;
1749 //if (m_hasWC)
1750 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1752 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1754 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1755 GetSelectedCount() == 1)
1756 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1758 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1759 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1761 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1762 str.Format(format,g_Git.GetCurrentBranch());
1764 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1765 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1767 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1768 str.Format(format,g_Git.GetCurrentBranch());
1770 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1771 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1774 // Add Switch Branch express Menu
1775 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1776 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1779 std::vector<CString *> branchs;
1780 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1782 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1783 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1785 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1789 CString str;
1790 str.LoadString(IDS_SWITCH_BRANCH);
1792 if(branchs.size() == 1)
1794 str+=_T(" ");
1795 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1796 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1798 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1801 else if(branchs.size() > 1)
1803 subbranchmenu.CreatePopupMenu();
1804 for(int i=0;i<branchs.size();i++)
1806 if (*branchs[i] != currentBranch)
1808 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1809 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1813 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1817 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1818 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1820 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1821 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1823 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1824 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1826 format.LoadString(IDS_REBASE_THIS_FORMAT);
1827 str.Format(format,g_Git.GetCurrentBranch());
1829 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1830 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1831 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1833 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1834 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1836 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1838 GitRev *pRev = pSelLogEntry;
1839 if (pSelLogEntry->m_ParentHash.empty())
1841 pRev->GetParentFromHash(pRev->m_CommitHash);
1843 if (pRev->m_ParentHash.size() == 1)
1845 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1847 else
1849 revertmenu.CreatePopupMenu();
1850 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1852 for (int i = 0; i < pRev->m_ParentHash.size(); i++)
1854 CString str;
1855 str.Format(IDS_PARENT, i + 1);
1856 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1861 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1862 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1864 popup.AppendMenu(MF_SEPARATOR, NULL);
1869 if(!pSelLogEntry->m_Ref.IsEmpty())
1871 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1872 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1873 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1874 popup.AppendMenu(MF_SEPARATOR, NULL);
1877 if (GetSelectedCount() >= 2)
1879 bool bAddSeparator = false;
1880 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1882 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1883 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1886 if (GetSelectedCount() == 2)
1888 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1889 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1890 bAddSeparator = true;
1893 if (m_hasWC)
1895 bAddSeparator = true;
1898 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1899 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1901 if (bAddSeparator)
1902 popup.AppendMenu(MF_SEPARATOR, NULL);
1905 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1907 bool bAddSeparator = false;
1908 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1910 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1912 CString head;
1913 int headindex;
1914 headindex = this->GetHeadIndex();
1915 if(headindex>=0 && LastSelect >= headindex)
1917 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1918 CGitHash hash;
1919 if (g_Git.GetHash(hash, head))
1920 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
1921 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1922 if(pLastEntry->m_CommitHash == hash) {
1923 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1924 bAddSeparator = true;
1929 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1930 if (GetSelectedCount() >= 2)
1931 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1932 else
1933 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1934 bAddSeparator = true;
1937 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1938 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1939 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1940 bAddSeparator = true;
1943 if (bAddSeparator)
1944 popup.AppendMenu(MF_SEPARATOR, NULL);
1947 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())
1949 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
1950 popup.AppendMenu(MF_SEPARATOR, NULL);
1953 if (GetSelectedCount() == 1)
1955 bool bAddSeparator = false;
1956 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1958 // show the push-option only if the log entry has an associated local branch
1959 bool isLocal = false;
1960 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1962 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1963 isLocal = true;
1965 if (isLocal)
1967 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1968 bAddSeparator = true;
1972 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1974 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1976 std::vector<CString *> branchs;
1977 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1979 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1980 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1982 CString str;
1983 if (branchs.size() == 1)
1985 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1986 str+=_T(" ");
1987 str += *branchs[0];
1988 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1989 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1990 bAddSeparator = true;
1992 else if (branchs.size() > 1)
1994 str.LoadString(IDS_DELETE_BRANCHTAG);
1995 submenu.CreatePopupMenu();
1996 for (int i = 0; i < branchs.size(); i++)
1998 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1999 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2002 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2003 bAddSeparator = true;
2006 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2007 if (bAddSeparator)
2008 popup.AppendMenu(MF_SEPARATOR, NULL);
2009 } // GetSelectedCount() == 1
2011 if (GetSelectedCount() != 0)
2013 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2014 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2015 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2016 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2017 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2018 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2021 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2022 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2024 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2025 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2027 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2028 // DialogEnableWindow(IDOK, FALSE);
2029 // SetPromptApp(&theApp);
2031 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2033 // EnableOKButton();
2034 } // if (popup.CreatePopupMenu())
2038 bool CGitLogListBase::IsSelectionContinuous()
2040 if ( GetSelectedCount()==1 )
2042 // if only one revision is selected, the selection is of course
2043 // continuous
2044 return true;
2047 POSITION pos = GetFirstSelectedItemPosition();
2048 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2049 if (bContinuous)
2051 int itemindex = GetNextSelectedItem(pos);
2052 while (pos)
2054 int nextindex = GetNextSelectedItem(pos);
2055 if (nextindex - itemindex > 1)
2057 bContinuous = false;
2058 break;
2060 itemindex = nextindex;
2063 return bContinuous;
2066 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2069 CString sClipdata;
2070 POSITION pos = GetFirstSelectedItemPosition();
2071 if (pos != NULL)
2073 CString sRev;
2074 sRev.LoadString(IDS_LOG_REVISION);
2075 CString sAuthor;
2076 sAuthor.LoadString(IDS_LOG_AUTHOR);
2077 CString sDate;
2078 sDate.LoadString(IDS_LOG_DATE);
2079 CString sMessage;
2080 sMessage.LoadString(IDS_LOG_MESSAGE);
2081 bool first = true;
2082 while (pos)
2084 CString sLogCopyText;
2085 CString sPaths;
2086 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2088 if (toCopy == ID_COPY_ALL)
2090 //pLogEntry->GetFiles(this)
2091 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2093 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2094 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2096 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2097 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2099 CString rename;
2100 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2101 sPaths += _T(" ") + rename;
2103 sPaths += _T("\r\n");
2105 sPaths.Trim();
2106 CString body = pLogEntry->GetBody();
2107 body.Replace(_T("\n"), _T("\r\n"));
2108 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"),
2109 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2110 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2111 (LPCTSTR)sDate,
2112 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2113 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2114 (LPCTSTR)sPaths);
2115 sClipdata += sLogCopyText;
2117 else if (toCopy == ID_COPY_MESSAGE)
2119 CString body = pLogEntry->GetBody();
2120 body.Replace(_T("\n"), _T("\r\n"));
2121 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2123 else if (toCopy == ID_COPY_SUBJECT)
2125 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2127 else
2129 if (!first)
2130 sClipdata += _T("\r\n");
2131 sClipdata += pLogEntry->m_CommitHash;
2134 first = false;
2136 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2141 void CGitLogListBase::DiffSelectedRevWithPrevious()
2143 if (m_bThreadRunning)
2144 return;
2146 int FirstSelect=-1, LastSelect=-1;
2147 POSITION pos = GetFirstSelectedItemPosition();
2148 FirstSelect = GetNextSelectedItem(pos);
2149 while(pos)
2151 LastSelect = GetNextSelectedItem(pos);
2154 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2156 #if 0
2157 UpdateLogInfoLabel();
2158 int selIndex = m_LogList.GetSelectionMark();
2159 if (selIndex < 0)
2160 return;
2161 int selCount = m_LogList.GetSelectedCount();
2162 if (selCount != 1)
2163 return;
2165 // Find selected entry in the log list
2166 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2167 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2168 long rev1 = pLogEntry->Rev;
2169 long rev2 = rev1-1;
2170 CTGitPath path = m_path;
2172 // See how many files under the relative root were changed in selected revision
2173 int nChanged = 0;
2174 LogChangedPath * changed = NULL;
2175 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2177 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2178 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2180 ++nChanged;
2181 changed = cpath;
2185 if (m_path.IsDirectory() && nChanged == 1)
2187 // We're looking at the log for a directory and only one file under dir was changed in the revision
2188 // Do diff on that file instead of whole directory
2189 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2192 m_bCancelled = FALSE;
2193 DialogEnableWindow(IDOK, FALSE);
2194 SetPromptApp(&theApp);
2195 theApp.DoWaitCursor(1);
2197 if (PromptShown())
2199 GitDiff diff(this, m_hWnd, true);
2200 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2201 diff.SetHEADPeg(m_LogRevision);
2202 diff.ShowCompare(path, rev2, path, rev1);
2204 else
2206 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2209 theApp.DoWaitCursor(-1);
2210 EnableOKButton();
2211 #endif
2214 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2216 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2217 *pResult = -1;
2219 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2220 return;
2221 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2222 return;
2223 if (pFindInfo->lvfi.psz == 0)
2224 return;
2225 #if 0
2226 CString sCmp = pFindInfo->lvfi.psz;
2227 CString sRev;
2228 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2230 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2231 sRev.Format(_T("%ld"), pLogEntry->Rev);
2232 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2234 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2236 *pResult = i;
2237 return;
2240 else
2242 if (sCmp.Compare(sRev)==0)
2244 *pResult = i;
2245 return;
2249 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2251 for (int i=0; i<pFindInfo->iStart; ++i)
2253 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2254 sRev.Format(_T("%ld"), pLogEntry->Rev);
2255 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2257 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2259 *pResult = i;
2260 return;
2263 else
2265 if (sCmp.Compare(sRev)==0)
2267 *pResult = i;
2268 return;
2273 #endif
2274 *pResult = -1;
2277 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2279 ClearText();
2281 this->m_arShownList.SafeRemoveAll();
2283 this->m_logEntries.ClearAll();
2284 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2285 return -1;
2287 //this->m_logEntries.ParserFromLog();
2288 SetItemCountEx((int)m_logEntries.size());
2290 for(unsigned int i=0;i<m_logEntries.size();i++)
2292 if(m_IsOldFirst)
2294 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2295 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2298 else
2300 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2301 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2305 ReloadHashMap();
2307 if(path)
2308 m_Path=*path;
2309 return 0;
2313 int CGitLogListBase::BeginFetchLog()
2315 ClearText();
2317 this->m_arShownList.SafeRemoveAll();
2319 this->m_logEntries.ClearAll();
2321 this->m_LogCache.ClearAllParent();
2323 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2325 CTGitPath *path;
2326 if(this->m_Path.IsEmpty())
2327 path=NULL;
2328 else
2329 path=&this->m_Path;
2331 CString hash;
2332 int mask;
2333 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2334 // if(this->m_bAllBranch)
2335 mask |= m_ShowMask ;
2337 if(m_bShowWC)
2339 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2340 ResetWcRev();
2341 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2344 CString *pFrom, *pTo;
2345 pFrom = pTo = NULL;
2346 CString head(_T("HEAD"));
2347 if(!this->m_startrev.IsEmpty())
2349 pFrom = &this->m_startrev;
2350 if(!this->m_endrev.IsEmpty())
2351 pTo = &this->m_endrev;
2352 else
2353 pTo = &head;
2356 CFilterData data;
2357 data.m_From = m_From;
2358 data.m_To =m_To;
2360 #if 0 /* use tortoiegit filter */
2361 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2362 data.m_Author = this->m_sFilterText;
2364 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2365 data.m_MessageFilter = this->m_sFilterText;
2367 data.m_IsRegex = m_bFilterWithRegex;
2368 #endif
2370 // follow does not work for directories
2371 if (!path || path->IsDirectory())
2372 mask &= ~CGit::LOG_INFO_FOLLOW;
2373 // follow does not work with all branches 8at least in TGit)
2374 if (mask & CGit::LOG_INFO_FOLLOW)
2375 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2377 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2379 //this->m_logEntries.ParserFromLog();
2380 if(IsInWorkingThread())
2382 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2384 else
2386 SetItemCountEx((int)m_logEntries.size());
2391 git_init();
2393 catch (char* msg)
2395 CString err(msg);
2396 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2397 return -1;
2400 if (g_Git.IsOrphanBranch(m_StartRef))
2402 if (!(mask & CGit::LOG_INFO_ALL_BRANCH))
2403 return 0;
2405 // if show all branches, pick any ref as dummy entry ref
2406 STRING_VECTOR list;
2407 if (g_Git.GetRefList(list))
2408 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2409 if (list.size() == 0)
2410 return 0;
2412 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, pFrom, pTo, true, &data);
2415 try {
2416 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2418 return -1;
2421 catch (char* msg)
2423 CString err(msg);
2424 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2425 return -1;
2428 return 0;
2431 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2433 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2435 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2437 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2439 DiffSelectedRevWithPrevious();
2440 return TRUE;
2443 #if 0
2444 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2446 DiffSelectedFile();
2447 return TRUE;
2449 #endif
2451 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2453 // select all entries
2454 for (int i=0; i<GetItemCount(); ++i)
2456 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2458 return TRUE;
2461 #if 0
2462 if (m_hAccel && !bSkipAccelerator)
2464 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2465 if (ret)
2466 return TRUE;
2469 #endif
2470 //m_tooltips.RelayEvent(pMsg);
2471 return __super::PreTranslateMessage(pMsg);
2474 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2476 // a double click on an entry in the revision list has happened
2477 *pResult = 0;
2479 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2480 DiffSelectedRevWithPrevious();
2483 int CGitLogListBase::FetchLogAsync(void * data)
2485 ReloadHashMap();
2486 m_ProcData=data;
2487 m_bExitThread=FALSE;
2488 InterlockedExchange(&m_bThreadRunning, TRUE);
2489 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2490 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2491 if (m_LoadingThread ==NULL)
2493 InterlockedExchange(&m_bThreadRunning, FALSE);
2494 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2495 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2496 return -1;
2498 return 0;
2501 //this is the thread function which calls the subversion function
2502 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2504 return ((CGitLogListBase*)pVoid)->LogThread();
2507 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2509 //CTime time;
2510 oldest=CTime::GetCurrentTime();
2511 latest=CTime(1971,1,2,0,0,0);
2512 for(unsigned int i=0;i<m_logEntries.size();i++)
2514 if(m_logEntries[i].IsEmpty())
2515 continue;
2517 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2518 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2520 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2521 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2525 if(latest<oldest)
2526 latest=oldest;
2529 UINT CGitLogListBase::LogThread()
2531 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2533 InterlockedExchange(&m_bThreadRunning, TRUE);
2534 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2536 ULONGLONG t1,t2;
2538 if(BeginFetchLog())
2540 InterlockedExchange(&m_bThreadRunning, FALSE);
2541 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2543 return 1;
2546 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2547 bool bRegex = false;
2548 if (m_bFilterWithRegex)
2549 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2551 TRACE(_T("\n===Begin===\n"));
2552 //Update work copy item;
2554 if (!m_logEntries.empty())
2556 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2558 m_arShownList.SafeAdd(pRev);
2562 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2564 // store commit number of the last selected commit/line before the refresh or -1
2565 int lastSelectedHashNItem = -1;
2566 int ret = 0;
2568 bool shouldWalk = true;
2569 if (g_Git.IsOrphanBranch(m_StartRef))
2571 // walk revisions if show all branches and there exists any ref
2572 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH))
2573 shouldWalk = false;
2574 else
2576 STRING_VECTOR list;
2577 if (g_Git.GetRefList(list))
2578 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2579 if (list.size() == 0)
2580 shouldWalk = false;
2584 if (shouldWalk)
2586 g_Git.m_critGitDllSec.Lock();
2587 int total = 0;
2590 git_get_log_firstcommit(m_DllGitLog);
2591 total = git_get_log_estimate_commit_count(m_DllGitLog);
2593 catch (char* msg)
2595 CString err(msg);
2596 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2597 ret = -1;
2599 g_Git.m_critGitDllSec.Unlock();
2601 GIT_COMMIT commit;
2602 t2=t1=GetTickCount();
2603 int oldprecentage = 0;
2604 size_t oldsize = m_logEntries.size();
2605 while (ret== 0 && !m_bExitThread)
2607 g_Git.m_critGitDllSec.Lock();
2610 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2612 catch (char* msg)
2614 g_Git.m_critGitDllSec.Unlock();
2615 CString err(msg);
2616 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2617 break;
2619 g_Git.m_critGitDllSec.Unlock();
2621 if(ret)
2622 break;
2624 if (commit.m_ignore == 1)
2626 git_free_commit(&commit);
2627 continue;
2630 //printf("%s\r\n",commit.GetSubject());
2631 if(m_bExitThread)
2632 break;
2634 CGitHash hash = (char*)commit.m_hash ;
2636 GitRev *pRev = m_LogCache.GetCacheData(hash);
2637 pRev->m_GitCommit = commit;
2638 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2640 char *note=NULL;
2641 g_Git.m_critGitDllSec.Lock();
2642 git_get_notes(commit.m_hash,&note);
2643 g_Git.m_critGitDllSec.Unlock();
2645 if(note)
2647 pRev->m_Notes.Empty();
2648 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2651 if(!pRev->m_IsDiffFiles)
2653 pRev->m_CallDiffAsync = DiffAsync;
2656 pRev->ParserParentFromCommit(&commit);
2658 #ifdef DEBUG
2659 pRev->DbgPrint();
2660 TRACE(_T("\n"));
2661 #endif
2663 if(!m_sFilterText.IsEmpty())
2665 if(!IsMatchFilter(bRegex,pRev,pat))
2666 continue;
2668 this->m_critSec.Lock();
2669 m_logEntries.push_back(hash);
2670 m_arShownList.SafeAdd(pRev);
2671 this->m_critSec.Unlock();
2673 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2674 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2676 t2=GetTickCount();
2678 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2680 //update UI
2681 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2682 if(percent > 99)
2683 percent =99;
2684 if(percent < GITLOG_START)
2685 percent = GITLOG_START +1;
2687 oldsize = m_logEntries.size();
2688 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2690 //if( percent > oldprecentage )
2692 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2693 oldprecentage = percent;
2695 t1 = t2;
2698 g_Git.m_critGitDllSec.Lock();
2699 git_close_log(m_DllGitLog);
2700 g_Git.m_critGitDllSec.Unlock();
2704 if (m_bExitThread)
2706 InterlockedExchange(&m_bThreadRunning, FALSE);
2707 return 0;
2710 //Update UI;
2711 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2713 if (lastSelectedHashNItem >= 0)
2714 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2716 if (this->m_hWnd)
2717 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2719 InterlockedExchange(&m_bThreadRunning, FALSE);
2721 return 0;
2724 void CGitLogListBase::FetchRemoteList()
2726 STRING_VECTOR remoteList;
2727 if (!g_Git.GetRemoteList(remoteList))
2728 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
2729 else
2730 m_SingleRemote = _T("");
2733 void CGitLogListBase::FetchTrackingBranchList()
2735 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
2737 for (int j = 0; j < it->second.size(); j++)
2739 CString branchName;
2740 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
2742 CString configName;
2743 configName.Format(_T("branch.%s.remote"), branchName);
2744 CString pullRemote = g_Git.GetConfigValue(configName);
2746 configName.Format(_T("branch.%s.merge"), branchName);
2747 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
2749 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
2751 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
2758 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2760 SafeTerminateThread();
2762 this->SetItemCountEx(0);
2763 this->Clear();
2765 ResetWcRev();
2767 // HACK to hide graph column
2768 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2769 SetColumnWidth(0, 0);
2770 else
2771 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2773 //Update branch and Tag info
2774 ReloadHashMap();
2775 //Assume Thread have exited
2776 //if(!m_bThreadRunning)
2778 m_logEntries.clear();
2780 if(IsCleanFilter)
2782 m_sFilterText.Empty();
2783 m_From=-1;
2784 m_To=-1;
2787 InterlockedExchange(&m_bExitThread,FALSE);
2789 InterlockedExchange(&m_bThreadRunning, TRUE);
2790 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2791 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2793 InterlockedExchange(&m_bThreadRunning, FALSE);
2794 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2795 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2799 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2803 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2804 if (!bMatchCase)
2805 type |= tr1::regex_constants::icase;
2806 pat = tr1::wregex(regexp_str, type);
2807 return true;
2809 catch (exception) {}
2810 return false;
2812 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2815 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2816 CString sRev;
2818 if ((bRegex)&&(m_bFilterWithRegex))
2820 if (m_SelectedFilters & LOGFILTER_BUGID)
2822 if(this->m_bShowBugtraqColumn)
2824 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2826 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2827 if (regex_search(wstring(sBugIds), pat, flags))
2829 return TRUE;
2834 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2836 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2837 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2839 return TRUE;
2843 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2845 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2846 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2848 return TRUE;
2852 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2854 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2856 return TRUE;
2859 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2861 return TRUE;
2865 if (m_SelectedFilters & LOGFILTER_EMAILS)
2867 if (regex_search(wstring(pRev->GetAuthorEmail()), pat, flags))
2869 return TRUE;
2872 if (regex_search(wstring(pRev->GetCommitterEmail()), pat, flags))
2874 return TRUE;
2878 if (m_SelectedFilters & LOGFILTER_REVS)
2880 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2881 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2883 return TRUE;
2887 if (m_SelectedFilters & LOGFILTER_REFNAME)
2889 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
2890 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
2892 if (regex_search(wstring((LPCTSTR)*it), pat, flags))
2894 return TRUE;
2899 if (m_SelectedFilters & LOGFILTER_PATHS)
2901 CTGitPathList *pathList=NULL;
2902 if( pRev->m_IsDiffFiles)
2903 pathList = &pRev->GetFiles(this);
2904 else
2906 if(!pRev->m_IsSimpleListReady)
2907 pRev->SafeGetSimpleList(&g_Git);
2910 if(pathList)
2911 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2913 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2915 return true;
2917 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2919 return true;
2923 for(size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2925 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2927 return true;
2932 else
2934 CString find = m_sFilterText;
2935 find.MakeLower();
2937 if (m_SelectedFilters & LOGFILTER_BUGID)
2939 if(this->m_bShowBugtraqColumn)
2941 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2943 sBugIds.MakeLower();
2944 if ((sBugIds.Find(find) >= 0))
2946 return TRUE;
2951 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2953 CString msg = pRev->GetSubject();
2955 msg = msg.MakeLower();
2956 if ((msg.Find(find) >= 0))
2958 return TRUE;
2962 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2964 CString msg = pRev->GetBody();
2966 msg = msg.MakeLower();
2967 if ((msg.Find(find) >= 0))
2969 return TRUE;
2973 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2975 CString msg = pRev->GetAuthorName();
2976 msg = msg.MakeLower();
2977 if ((msg.Find(find) >= 0))
2979 return TRUE;
2983 if (m_SelectedFilters & LOGFILTER_EMAILS)
2985 CString msg = pRev->GetAuthorEmail();
2986 msg = msg.MakeLower();
2987 if ((msg.Find(find) >= 0))
2989 return TRUE;
2993 if (m_SelectedFilters & LOGFILTER_REVS)
2995 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2996 if ((sRev.Find(find) >= 0))
2998 return TRUE;
3002 if (m_SelectedFilters & LOGFILTER_REFNAME)
3004 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3005 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3007 if (it->Find(find) >= 0)
3009 return TRUE;
3014 if (m_SelectedFilters & LOGFILTER_PATHS)
3016 CTGitPathList *pathList=NULL;
3017 if( pRev->m_IsDiffFiles)
3018 pathList = &pRev->GetFiles(this);
3019 else
3021 if(!pRev->m_IsSimpleListReady)
3022 pRev->SafeGetSimpleList(&g_Git);
3024 if(pathList)
3025 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3027 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3028 CString path = cpath->GetGitOldPathString();
3029 path.MakeLower();
3030 if ((path.Find(find)>=0))
3032 return true;
3034 path = cpath->GetGitPathString();
3035 path.MakeLower();
3036 if ((path.Find(find)>=0))
3038 return true;
3042 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
3044 CString path = pRev->m_SimpleFileList[i];
3045 path.MakeLower();
3046 if ((path.Find(find)>=0))
3048 return true;
3052 } // else (from if (bRegex))
3053 return FALSE;
3057 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3060 pShownlist->SafeRemoveAll();
3062 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3063 bool bRegex = false;
3064 if (m_bFilterWithRegex)
3065 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3067 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
3068 CString sRev;
3069 for (DWORD i=0; i<m_logEntries.size(); ++i)
3071 if ((bRegex)&&(m_bFilterWithRegex))
3073 #if 0
3074 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3076 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3077 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3079 pShownlist->SafeAdd(m_logEntries[i]);
3080 continue;
3083 #endif
3084 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3086 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3087 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3089 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3090 continue;
3093 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3095 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3096 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3098 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3099 continue;
3102 if (m_SelectedFilters & LOGFILTER_PATHS)
3104 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3106 bool bGoing = true;
3107 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3109 CTGitPath cpath = pathList[cpPathIndex];
3110 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3112 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3113 bGoing = false;
3114 continue;
3116 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3118 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3119 bGoing = false;
3120 continue;
3122 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3124 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3125 bGoing = false;
3126 continue;
3130 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3132 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3134 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3135 continue;
3138 if (m_SelectedFilters & LOGFILTER_EMAILS)
3140 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3142 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3143 continue;
3146 if (m_SelectedFilters & LOGFILTER_REVS)
3148 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3149 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3151 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3152 continue;
3155 if (m_SelectedFilters & LOGFILTER_REFNAME)
3157 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3158 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3160 if (regex_search(wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3162 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3163 continue;
3167 } // if (bRegex)
3168 else
3170 CString find = m_sFilterText;
3171 find.MakeLower();
3172 #if 0
3173 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3175 CString sBugIDs = m_logEntries[i]->sBugIDs;
3177 sBugIDs = sBugIDs.MakeLower();
3178 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3180 pShownlist->SafeAdd(m_logEntries[i]);
3181 continue;
3184 #endif
3185 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3187 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3189 msg = msg.MakeLower();
3190 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3192 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3193 continue;
3196 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3198 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3200 msg = msg.MakeLower();
3201 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3203 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3204 continue;
3207 if (m_SelectedFilters & LOGFILTER_PATHS)
3209 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3211 bool bGoing = true;
3212 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3214 CTGitPath cpath = pathList[cpPathIndex];
3215 CString path = cpath.GetGitOldPathString();
3216 path.MakeLower();
3217 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3219 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3220 bGoing = false;
3221 continue;
3223 path = cpath.GetGitPathString();
3224 path.MakeLower();
3225 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3227 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3228 bGoing = false;
3229 continue;
3231 path = cpath.GetActionName();
3232 path.MakeLower();
3233 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3235 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3236 bGoing = false;
3237 continue;
3241 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3243 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3244 msg = msg.MakeLower();
3245 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3247 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3248 continue;
3251 if (m_SelectedFilters & LOGFILTER_EMAILS)
3253 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3254 msg = msg.MakeLower();
3255 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3257 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3258 continue;
3261 if (m_SelectedFilters & LOGFILTER_REVS)
3263 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3264 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3266 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3267 continue;
3270 if (m_SelectedFilters & LOGFILTER_REFNAME)
3272 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3273 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3275 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3277 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3278 continue;
3282 } // else (from if (bRegex))
3283 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3287 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3290 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3292 if(m_From == -1)
3293 if(m_To == -1)
3294 return true;
3295 else
3296 return time <= m_To;
3297 else
3298 if(m_To == -1)
3299 return time >= m_From;
3300 else
3301 return ((time >= m_From)&&(time <= m_To));
3303 return TRUE; /* git dll will filter time range */
3305 // return TRUE;
3307 void CGitLogListBase::StartFilter()
3309 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3310 RecalculateShownList(&m_arShownList);
3311 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3314 DeleteAllItems();
3315 SetItemCountEx(ShownCountWithStopped());
3316 RedrawItems(0, ShownCountWithStopped());
3317 Invalidate();
3320 void CGitLogListBase::RemoveFilter()
3323 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3325 m_arShownList.SafeRemoveAll();
3327 // reset the time filter too
3328 #if 0
3329 m_timFrom = (__time64_t(m_tFrom));
3330 m_timTo = (__time64_t(m_tTo));
3331 m_DateFrom.SetTime(&m_timFrom);
3332 m_DateTo.SetTime(&m_timTo);
3333 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3334 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3335 #endif
3337 for (DWORD i=0; i<m_logEntries.size(); ++i)
3339 if(this->m_IsOldFirst)
3341 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3343 else
3345 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3348 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3349 DeleteAllItems();
3350 SetItemCountEx(ShownCountWithStopped());
3351 RedrawItems(0, ShownCountWithStopped());
3353 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3356 void CGitLogListBase::Clear()
3358 m_arShownList.SafeRemoveAll();
3359 DeleteAllItems();
3361 m_logEntries.ClearAll();
3365 void CGitLogListBase::OnDestroy()
3367 // save the column widths to the registry
3368 SaveColumnWidths();
3370 SafeTerminateThread();
3371 SafeTerminateAsyncDiffThread();
3373 int retry = 0;
3374 while(m_LogCache.SaveCache())
3376 if(retry > 5)
3377 break;
3378 Sleep(1000);
3380 retry++;
3382 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3383 // MB_YESNO) == IDNO)
3384 // break;
3387 CHintListCtrl::OnDestroy();
3390 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3392 CRect rect;
3393 int i=(int)wParam;
3394 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3395 this->InvalidateRect(rect);
3397 return 0;
3401 * Save column widths to the registry
3403 void CGitLogListBase::SaveColumnWidths()
3405 int maxcol = m_ColumnManager.GetColumnCount();
3407 // HACK that graph column is always shown
3408 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3410 for (int col = 0; col < maxcol; col++)
3411 if (m_ColumnManager.IsVisible (col))
3412 m_ColumnManager.ColumnResized (col);
3414 m_ColumnManager.WriteSettings();
3417 int CGitLogListBase::GetHeadIndex()
3419 if(m_HeadHash.IsEmpty())
3420 return -1;
3422 for(int i=0;i<m_arShownList.GetCount();i++)
3424 GitRev *pRev = (GitRev*)m_arShownList[i];
3425 if(pRev)
3427 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3428 return i;
3431 return -1;
3433 void CGitLogListBase::OnFind()
3435 if (!m_pFindDialog)
3437 m_pFindDialog = new CFindDlg(this);
3438 m_pFindDialog->Create(this);
3441 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3443 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3445 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3447 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3448 Default();
3450 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3452 SetItemState((int)itemToSelect, LVIS_SELECTED, LVIS_SELECTED);
3453 EnsureVisible((int)itemToSelect, FALSE);
3454 return 0;
3456 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3459 ASSERT(m_pFindDialog != NULL);
3460 bool bFound = false;
3461 int i=0;
3463 if (m_pFindDialog->IsTerminating())
3465 // invalidate the handle identifying the dialog box.
3466 m_pFindDialog = NULL;
3467 return 0;
3470 if(m_pFindDialog->IsRef())
3472 CString str;
3473 str=m_pFindDialog->GetFindString();
3475 CGitHash hash;
3477 if(!str.IsEmpty())
3479 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3480 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3483 if(!hash.IsEmpty())
3485 for (i = 0; i<m_arShownList.GetCount(); i++)
3487 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3488 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3490 bFound = true;
3491 break;
3498 if(m_pFindDialog->FindNext())
3500 //read data from dialog
3501 CString FindText = m_pFindDialog->GetFindString();
3502 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3504 tr1::wregex pat;
3505 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3507 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3510 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3512 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3514 CString str;
3515 str+=pLogEntry->m_CommitHash.ToString();
3516 str+=_T("\n");
3518 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3520 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3521 str+=_T("\n");
3524 str+=pLogEntry->GetAuthorEmail();
3525 str+=_T("\n");
3526 str+=pLogEntry->GetAuthorName();
3527 str+=_T("\n");
3528 str+=pLogEntry->GetBody();
3529 str+=_T("\n");
3530 str+=pLogEntry->GetCommitterEmail();
3531 str+=_T("\n");
3532 str+=pLogEntry->GetCommitterName();
3533 str+=_T("\n");
3534 str+=pLogEntry->GetSubject();
3535 str+=_T("\n");
3538 /*Because changed files list is loaded on demand when gui show,
3539 files will empty when files have not fetched.
3541 we can add it back by using one-way diff(with outnumber changed and rename detect.
3542 here just need changed filename list. one-way is much quicker.
3544 if(pLogEntry->m_IsFull)
3546 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3548 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3549 str+=_T("\n");
3550 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3551 str+=_T("\n");
3554 else
3556 if(!pLogEntry->m_IsSimpleListReady)
3557 pLogEntry->SafeGetSimpleList(&g_Git);
3559 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3561 str+=pLogEntry->m_SimpleFileList[i];
3562 str+=_T("\n");
3568 if (bRegex)
3570 if (regex_search(wstring(str), pat, flags))
3572 bFound = true;
3573 break;
3576 else
3578 if (bMatchCase)
3580 if (str.Find(FindText) >= 0)
3582 bFound = true;
3583 break;
3587 else
3589 CString msg = str;
3590 msg = msg.MakeLower();
3591 CString find = FindText.MakeLower();
3592 if (msg.Find(find) >= 0)
3594 bFound = TRUE;
3595 break;
3599 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3601 } // if(m_pFindDialog->FindNext())
3602 //UpdateLogInfoLabel();
3604 if (bFound)
3606 this->m_nSearchIndex = i;
3607 EnsureVisible(i, FALSE);
3608 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3609 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3610 SetSelectionMark(i);
3611 //FillLogMessageCtrl();
3612 UpdateData(FALSE);
3613 m_nSearchIndex++;
3614 if (m_nSearchIndex >= m_arShownList.GetCount())
3615 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3618 return 0;
3621 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3623 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3625 *pResult = FALSE;
3628 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3630 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3632 Invalidate(FALSE);