Fixed issue #1991: Disable (by default) certain operations with stash commits
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob9424a2cab6c2f502c5de2f647b91d59596d17ebc
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 "IconMenu.h"
28 #include "cursor.h"
29 #include "InputDlg.h"
30 #include "GitProgressDlg.h"
31 #include "ProgressDlg.h"
32 #include "LogDlg.h"
33 #include "MessageBox.h"
34 #include "registry.h"
35 #include "LoglistUtils.h"
36 #include "PathUtils.h"
37 #include "StringUtils.h"
38 #include "UnicodeUtils.h"
39 #include "TempFile.h"
40 #include "IconMenu.h"
41 #include "GitStatus.h"
42 #include "..\\TortoiseShell\\Resource.h"
43 #include "FindDlg.h"
44 #include "SysInfo.h"
46 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
47 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
48 const UINT CGitLogListBase::m_RebaseActionMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
54 ,m_nSearchIndex(0)
55 ,m_bNoDispUpdates(FALSE)
56 , m_bThreadRunning(FALSE)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL)
59 , m_SelectedFilters(LOGFILTER_ALL)
60 , m_ShowFilter(FILTERSHOW_ALL)
61 , m_bShowWC(false)
62 , m_logEntries(&m_LogCache)
63 , m_pFindDialog(NULL)
64 , m_ColumnManager(this)
65 , m_dwDefaultColumns(0)
66 , m_arShownList(&m_critSec)
67 , m_hasWC(true)
68 , m_bNoHightlightHead(FALSE)
69 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
71 // use the default GUI font, create a copy of it and
72 // change the copy to BOLD (leave the rest of the font
73 // the same)
74 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
75 LOGFONT lf = {0};
76 GetObject(hFont, sizeof(LOGFONT), &lf);
77 lf.lfWeight = FW_BOLD;
78 m_boldFont = CreateFontIndirect(&lf);
80 m_bShowBugtraqColumn=false;
82 m_IsIDReplaceAction=FALSE;
84 this->m_critSec.Init();
85 m_critSec_AsyncDiff.Init();
86 m_wcRev.m_CommitHash.Empty();
87 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
88 m_wcRev.m_ParentHash.clear();
89 m_wcRev.m_Mark=_T('-');
90 m_wcRev.m_IsUpdateing=FALSE;
91 m_wcRev.m_IsFull = TRUE;
93 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
94 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
95 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
96 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
97 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
99 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
101 m_From = -1;
102 m_To = -1;
104 m_ShowMask = 0;
105 m_LoadingThread = NULL;
107 InterlockedExchange(&m_bExitThread,FALSE);
108 m_IsOldFirst = FALSE;
109 m_IsRebaseReplaceGraph = FALSE;
111 for (int i = 0; i < Lanes::COLORS_NUM; ++i)
113 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
115 // get short/long datetime setting from registry
116 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
117 if ( RegUseShortDateFormat )
119 m_DateFormat = DATE_SHORTDATE;
121 else
123 m_DateFormat = DATE_LONGDATE;
125 // get relative time display setting from registry
126 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
127 m_bRelativeTimes = (regRelativeTimes != 0);
128 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
130 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
131 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
132 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
133 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
134 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
135 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
137 m_ColumnRegKey=_T("log");
139 m_bTagsBranchesOnRightSide = !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE);
140 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
141 m_bIncludeBoundaryCommits = !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE);
143 m_LineWidth = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
144 m_NodeSize = max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
146 m_AsyncThreadExit = FALSE;
147 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
148 m_AsynDiffListLock.Init();
150 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
151 if (m_DiffingThread ==NULL)
153 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
154 return;
159 int CGitLogListBase::AsyncDiffThread()
161 m_AsyncThreadExited = false;
162 while(!m_AsyncThreadExit)
164 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
166 GitRev *pRev = NULL;
167 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
169 m_AsynDiffListLock.Lock();
170 pRev = m_AsynDiffList.back();
171 m_AsynDiffList.pop_back();
172 m_AsynDiffListLock.Unlock();
174 if( pRev->m_CommitHash.IsEmpty() )
176 if(pRev->m_IsDiffFiles)
177 continue;
179 pRev->GetFiles(this).Clear();
180 pRev->m_ParentHash.clear();
181 pRev->m_ParentHash.push_back(m_HeadHash);
182 if(g_Git.IsInitRepos())
184 if (g_Git.GetInitAddList(pRev->GetFiles(this)))
185 CMessageBox::Show(NULL, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
188 else
190 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
192 int dummyAction = 0;
193 int *action = &dummyAction;
194 SafeGetAction(pRev, &action);
195 *action = 0;
197 for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j)
198 *action |= pRev->GetFiles(this)[j].m_Action;
200 pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER);
202 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
203 InterlockedExchange(&pRev->m_IsFull, TRUE);
205 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
206 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
207 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
210 m_critSec_AsyncDiff.Lock();
211 int ret = pRev->CheckAndDiff();
212 m_critSec_AsyncDiff.Unlock();
213 if (!ret)
214 { // fetch change file list
215 for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i)
217 if(i < m_arShownList.GetCount())
219 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
220 if(data->m_CommitHash == pRev->m_CommitHash)
222 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
223 break;
228 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
230 POSITION pos = GetFirstSelectedItemPosition();
231 int nItem = GetNextSelectedItem(pos);
233 if(nItem>=0)
235 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(nItem);
236 if(data)
237 if(data->m_CommitHash == pRev->m_CommitHash)
239 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
246 m_AsyncThreadExited = true;
247 return 0;
249 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
251 if (exclusivelyShow)
253 m_ContextMenuMask &= hideMask;
255 else
257 m_ContextMenuMask &= ~hideMask;
261 CGitLogListBase::~CGitLogListBase()
263 InterlockedExchange(&m_bNoDispUpdates, TRUE);
264 this->m_arShownList.SafeRemoveAll();
266 DestroyIcon(m_hModifiedIcon);
267 DestroyIcon(m_hReplacedIcon);
268 DestroyIcon(m_hAddedIcon);
269 DestroyIcon(m_hDeletedIcon);
270 m_logEntries.ClearAll();
272 if (m_boldFont)
273 DeleteObject(m_boldFont);
275 if ( m_pStoreSelection )
277 delete m_pStoreSelection;
278 m_pStoreSelection = NULL;
281 SafeTerminateThread();
282 SafeTerminateAsyncDiffThread();
284 if(m_AsyncDiffEvent)
285 CloseHandle(m_AsyncDiffEvent);
289 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
290 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
291 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
292 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
293 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
294 ON_WM_CONTEXTMENU()
295 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
296 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
297 ON_WM_CREATE()
298 ON_WM_DESTROY()
299 ON_MESSAGE(MSG_LOADED,OnLoad)
300 ON_WM_MEASUREITEM()
301 ON_WM_MEASUREITEM_REFLECT()
302 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
303 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
304 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
305 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
306 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
307 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
308 END_MESSAGE_MAP()
310 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
312 //if (m_nRowHeight>0)
314 lpMeasureItemStruct->itemHeight = 50;
318 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
320 PreSubclassWindow();
321 return CHintListCtrl::OnCreate(lpCreateStruct);
324 void CGitLogListBase::PreSubclassWindow()
326 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
327 // load the icons for the action columns
328 // m_Theme.Open(m_hWnd, L"ListView");
329 SetWindowTheme(m_hWnd, L"Explorer", NULL);
330 CHintListCtrl::PreSubclassWindow();
333 void CGitLogListBase::InsertGitColumn()
335 CString temp;
337 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
338 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
339 if (DWORD(regFullRowSelect))
340 exStyle |= LVS_EX_FULLROWSELECT;
341 SetExtendedStyle(exStyle);
343 // only load properties if we have a repository
344 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
345 UpdateProjectProperties();
347 static UINT normal[] =
349 IDS_LOG_GRAPH,
350 IDS_LOG_REBASE,
351 IDS_LOG_ID,
352 IDS_LOG_HASH,
353 IDS_LOG_ACTIONS,
354 IDS_LOG_MESSAGE,
355 IDS_LOG_AUTHOR,
356 IDS_LOG_DATE,
357 IDS_LOG_EMAIL,
358 IDS_LOG_COMMIT_NAME,
359 IDS_LOG_COMMIT_EMAIL,
360 IDS_LOG_COMMIT_DATE,
361 IDS_LOG_BUGIDS,
364 static int with[] =
366 ICONITEMBORDER+16*4,
367 ICONITEMBORDER+16*4,
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 LOGLIST_MESSAGE_MIN,
372 ICONITEMBORDER+16*4,
373 ICONITEMBORDER+16*4,
374 ICONITEMBORDER+16*4,
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
380 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
382 DWORD hideColumns = 0;
383 if(this->m_IsRebaseReplaceGraph)
385 hideColumns |= GIT_LOG_GRAPH;
386 m_dwDefaultColumns |= GIT_LOG_REBASE;
388 else
390 hideColumns |= GIT_LOG_REBASE;
393 if(this->m_IsIDReplaceAction)
395 hideColumns |= GIT_LOG_ACTIONS;
396 m_dwDefaultColumns |= GIT_LOG_ID;
397 m_dwDefaultColumns |= GIT_LOG_HASH;
399 else
401 hideColumns |= GIT_LOG_ID;
403 if(this->m_bShowBugtraqColumn)
405 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
407 else
409 hideColumns |= GIT_LOGLIST_BUG;
411 SetRedraw(false);
413 m_ColumnManager.SetNames(normal, _countof(normal));
414 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
416 SetRedraw(true);
420 * Resizes all columns in a list control to values in registry.
422 void CGitLogListBase::ResizeAllListCtrlCols()
424 // column max and min widths to allow
425 static const int nMinimumWidth = 10;
426 static const int nMaximumWidth = 1000;
427 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
428 if (pHdrCtrl)
430 int numcols = pHdrCtrl->GetItemCount();
431 for (int col = 0; col < numcols; ++col)
433 // get width for this col last time from registry
434 CString regentry;
435 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
436 CRegDWORD regwidth(regentry, 0);
437 int cx = regwidth;
438 if ( cx == 0 )
440 // no saved value, setup sensible defaults
441 if (col == this->LOGLIST_MESSAGE)
443 cx = LOGLIST_MESSAGE_MIN;
445 else
447 cx = ICONITEMBORDER+16*4;
450 if (cx < nMinimumWidth)
452 cx = nMinimumWidth;
454 else if (cx > nMaximumWidth)
456 cx = nMaximumWidth;
459 SetColumnWidth(col, cx);
466 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
468 LVITEM rItem;
469 SecureZeroMemory(&rItem, sizeof(LVITEM));
470 rItem.mask = LVIF_STATE;
471 rItem.iItem = (int)Index;
472 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
473 GetItem(&rItem);
475 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
476 HBRUSH brush = NULL;
478 if (!(rItem.state & LVIS_SELECTED))
480 int action = SafeGetAction(pLogEntry);
481 if (action & CTGitPath::LOGACTIONS_REBASE_SQUASH)
482 brush = ::CreateSolidBrush(RGB(156,156,156));
483 else if (action & CTGitPath::LOGACTIONS_REBASE_EDIT)
484 brush = ::CreateSolidBrush(RGB(200,200,128));
486 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
488 if (rItem.state & LVIS_SELECTED)
490 if (::GetFocus() == m_hWnd)
491 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
492 else
493 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
496 InvalidateRect(rect);
497 if (brush != NULL)
499 ::FillRect(hdc, &rect, brush);
500 ::DeleteObject(brush);
504 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
506 POINT point = { 4, 4 };
507 CRect rt2 = rect;
508 rt2.DeflateRect(1, 1);
509 rt2.OffsetRect(2, 2);
511 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
512 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
513 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
514 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
515 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
517 ::SelectObject(hdc, brush);
518 rt2.OffsetRect(-2, -2);
519 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
520 ::SelectObject(hdc, oldbrush);
521 ::SelectObject(hdc, oldpen);
522 ::DeleteObject(nullPen);
523 ::DeleteObject(darkBrush);
526 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
528 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
529 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
530 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
531 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
532 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
533 ::LineTo(hdc, rect.left, rect.bottom);
534 ::SelectObject(hdc, oldpen);
535 ::DeleteObject(pen);
538 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
540 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
541 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
542 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
543 ::LineTo(hdc, rect.left, rect.bottom);
544 ::LineTo(hdc, rect.right, rect.bottom);
545 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
546 ::SelectObject(hdc, oldpen);
547 ::DeleteObject(pen);
550 void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> &refList)
552 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
553 CRect rt=rect;
554 LVITEM rItem;
555 SecureZeroMemory(&rItem, sizeof(LVITEM));
556 rItem.mask = LVIF_STATE;
557 rItem.iItem = (int)index;
558 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
559 GetItem(&rItem);
561 CDC W_Dc;
562 W_Dc.Attach(hdc);
564 HTHEME hTheme = NULL;
565 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
566 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
568 if (!m_bTagsBranchesOnRightSide)
569 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
571 SIZE oneSpaceSize;
572 GetTextExtentPoint32(hdc, L" ", 1, &oneSpaceSize);
573 rt.left += oneSpaceSize.cx;
575 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
577 int txtState = LISS_NORMAL;
578 if (rItem.state & LVIS_SELECTED)
579 txtState = LISS_SELECTED;
581 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
583 else
585 if (rItem.state & LVIS_SELECTED)
587 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
588 ::DrawText(hdc,data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
589 ::SetTextColor(hdc, clrOld);
591 else
593 ::DrawText(hdc, data->GetSubject(), data->GetSubject().GetLength(), &rt, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
597 if (m_bTagsBranchesOnRightSide)
599 SIZE size;
600 GetTextExtentPoint32(hdc, data->GetSubject(), data->GetSubject().GetLength(), &size);
602 rt.left += oneSpaceSize.cx + size.cx;
604 DrawTagBranch(hdc, W_Dc, hTheme, rect, rt, rItem, data, refList);
607 if (hTheme)
608 CloseThemeData(hTheme);
610 W_Dc.Detach();
613 void CGitLogListBase::DrawTagBranch(HDC hdc, CDC &W_Dc, HTHEME hTheme, CRect &rect, CRect &rt, LVITEM &rItem, GitRev* data, std::vector<REFLABEL> &refList)
615 for (unsigned int i = 0; i < refList.size(); ++i)
617 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
618 HBRUSH brush = 0;
619 COLORREF colRef = refList[i].color;
620 bool singleRemote = refList[i].singleRemote;
621 bool hasTracking = refList[i].hasTracking;
622 bool sameName = refList[i].sameName;
623 bool annotatedTag = refList[i].annotatedTag;
625 //When row selected, ajust label color
626 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
628 if (rItem.state & LVIS_SELECTED)
629 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
632 brush = ::CreateSolidBrush(colRef);
634 if (!shortname.IsEmpty() && (rt.left < rect.right))
636 SIZE size;
637 memset(&size,0,sizeof(SIZE));
638 GetTextExtentPoint32(hdc, shortname, shortname.GetLength(), &size);
640 rt.SetRect(rt.left, rt.top, rt.left + size.cx, rt.bottom);
641 rt.right += 8;
643 int textpos = DT_CENTER;
645 if (rt.right > rect.right)
647 rt.right = rect.right;
648 textpos = 0;
651 CRect textRect = rt;
653 if (singleRemote)
655 rt.right += 8;
656 textRect.OffsetRect(8, 0);
659 if (sameName)
660 rt.right += 8;
662 if (hasTracking)
664 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
666 else
668 //Fill interior of ref label
669 ::FillRect(hdc, &rt, brush);
672 //Draw edge of label
673 CRect rectEdge = rt;
675 if (!hasTracking)
677 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
678 rectEdge.DeflateRect(1, 1);
679 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
682 if (annotatedTag)
684 rt.right += 8;
685 POINT trianglept[3] = { { rt.right - 8, rt.top }, { rt.right, (rt.top + rt.bottom) / 2 }, { rt.right - 8, rt.bottom } };
686 HRGN hrgn = ::CreatePolygonRgn(trianglept, 3, ALTERNATE);
687 ::FillRgn(hdc, hrgn, brush);
688 ::DeleteObject(hrgn);
689 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[0].y, NULL);
690 HPEN pen;
691 HPEN oldpen = (HPEN)SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Lighten(colRef, 50)));
692 ::LineTo(hdc, trianglept[1].x - 1, trianglept[1].y - 1);
693 ::DeleteObject(pen);
694 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, m_Colors.Darken(colRef, 50)));
695 ::LineTo(hdc, trianglept[2].x - 1, trianglept[2].y - 1);
696 ::DeleteObject(pen);
697 SelectObject(hdc, pen = ::CreatePen(PS_SOLID, 2, colRef));
698 ::MoveToEx(hdc, trianglept[0].x - 1, trianglept[2].y - 3, NULL);
699 ::LineTo(hdc, trianglept[0].x - 1, trianglept[0].y);
700 ::DeleteObject(pen);
701 SelectObject(hdc, oldpen);
704 //Draw text inside label
705 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
706 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
708 int txtState = LISS_NORMAL;
709 if (rItem.state & LVIS_SELECTED)
710 txtState = LISS_SELECTED;
712 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
714 else
716 W_Dc.SetBkMode(TRANSPARENT);
717 if (customColor || (rItem.state & LVIS_SELECTED))
719 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
720 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
721 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
722 ::SetTextColor(hdc,clrOld);
724 else
726 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
730 if (singleRemote)
732 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
733 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
734 CRect newRect;
735 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
736 DrawLightning(hdc, newRect, color, bold);
739 if (sameName)
741 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
742 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
743 CRect newRect;
744 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
745 DrawUpTriangle(hdc, newRect, color, bold);
748 rt.left = rt.right + 1;
750 if (brush)
751 ::DeleteObject(brush);
753 rt.right = rect.right;
756 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
758 // Returns ((256 - amount)*col1 + amount*col2) / 256;
759 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
760 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
761 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
764 Gdiplus::Color GetGdiColor(COLORREF col)
766 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
768 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
769 const COLORREF& col,const COLORREF& activeColor, int top
772 int h = laneHeight / 2;
773 int m = (x1 + x2) / 2;
774 int r = (x2 - x1) * m_NodeSize / 30;
775 int d = 2 * r;
777 #define P_CENTER m , h+top
778 #define P_0 x2, h+top
779 #define P_90 m , 0+top-1
780 #define P_180 x1, h+top
781 #define P_270 m , 2 * h+top +1
782 #define R_CENTER m - r, h - r+top, d, d
785 #define DELTA_UR_B 2*(x1 - m), 2*h +top
786 #define DELTA_UR_E 0*16, 90*16 +top // -,
788 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
789 #define DELTA_DR_E 270*16, 90*16 +top // -'
791 #define DELTA_UL_B 2*(x2 - m), 2*h +top
792 #define DELTA_UL_E 90*16, 90*16 +top // ,-
794 #define DELTA_DL_B 2*(x2 - m),2*-h +top
795 #define DELTA_DL_E 180*16, 90*16 // '-
797 #define CENTER_UR x1, 2*h, 225
798 #define CENTER_DR x1, 0 , 135
799 #define CENTER_UL x2, 2*h, 315
800 #define CENTER_DL x2, 0 , 45
803 Gdiplus::Graphics graphics( hdc );
805 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
807 // arc
808 switch (type) {
809 case Lanes::JOIN:
810 case Lanes::JOIN_R:
811 case Lanes::HEAD:
812 case Lanes::HEAD_R:
814 Gdiplus::LinearGradientBrush gradient(
815 Gdiplus::Point(x1-2, h+top-2),
816 Gdiplus::Point(P_270),
817 GetGdiColor(activeColor),GetGdiColor(col));
820 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
821 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
823 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
824 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
825 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
827 break;
829 case Lanes::JOIN_L:
832 Gdiplus::LinearGradientBrush gradient(
833 Gdiplus::Point(P_270),
834 Gdiplus::Point(x2+1, h+top-1),
835 GetGdiColor(col),GetGdiColor(activeColor));
838 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
839 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
841 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
842 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
843 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
846 break;
848 case Lanes::TAIL:
849 case Lanes::TAIL_R:
852 Gdiplus::LinearGradientBrush gradient(
853 Gdiplus::Point(x1-2, h+top-2),
854 Gdiplus::Point(P_90),
855 GetGdiColor(activeColor),GetGdiColor(col));
857 Gdiplus::Pen mypen(&gradient, (Gdiplus::REAL)m_LineWidth);
859 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
861 #if 0
862 QConicalGradient gradient(CENTER_DR);
863 gradient.setColorAt(0.375, activeCol);
864 gradient.setColorAt(0.625, col);
865 myPen.setBrush(gradient);
866 p->setPen(myPen);
867 p->drawArc(P_CENTER, DELTA_DR);
868 #endif
869 break;
871 default:
872 break;
876 //static QPen myPen(Qt::black, 2); // fast path here
877 CPen pen;
878 pen.CreatePen(PS_SOLID,2,col);
879 //myPen.setColor(col);
880 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
882 Gdiplus::Pen myPen(GetGdiColor(col), (Gdiplus::REAL)m_LineWidth);
884 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
886 //p->setPen(myPen);
888 // vertical line
889 switch (type) {
890 case Lanes::ACTIVE:
891 case Lanes::NOT_ACTIVE:
892 case Lanes::MERGE_FORK:
893 case Lanes::MERGE_FORK_R:
894 case Lanes::MERGE_FORK_L:
895 case Lanes::JOIN:
896 case Lanes::JOIN_R:
897 case Lanes::JOIN_L:
898 case Lanes::CROSS:
899 //DrawLine(hdc,P_90,P_270);
900 graphics.DrawLine(&myPen,P_90,P_270);
901 //p->drawLine(P_90, P_270);
902 break;
903 case Lanes::HEAD_L:
904 case Lanes::BRANCH:
905 //DrawLine(hdc,P_CENTER,P_270);
906 graphics.DrawLine(&myPen,P_CENTER,P_270);
907 //p->drawLine(P_CENTER, P_270);
908 break;
909 case Lanes::TAIL_L:
910 case Lanes::INITIAL:
911 case Lanes::BOUNDARY:
912 case Lanes::BOUNDARY_C:
913 case Lanes::BOUNDARY_R:
914 case Lanes::BOUNDARY_L:
915 //DrawLine(hdc,P_90, P_CENTER);
916 graphics.DrawLine(&myPen,P_90,P_CENTER);
917 //p->drawLine(P_90, P_CENTER);
918 break;
919 default:
920 break;
923 myPen.SetColor(GetGdiColor(activeColor));
925 // horizontal line
926 switch (type) {
927 case Lanes::MERGE_FORK:
928 case Lanes::JOIN:
929 case Lanes::HEAD:
930 case Lanes::TAIL:
931 case Lanes::CROSS:
932 case Lanes::CROSS_EMPTY:
933 case Lanes::BOUNDARY_C:
934 //DrawLine(hdc,P_180,P_0);
935 graphics.DrawLine(&myPen,P_180,P_0);
936 //p->drawLine(P_180, P_0);
937 break;
938 case Lanes::MERGE_FORK_R:
939 case Lanes::BOUNDARY_R:
940 //DrawLine(hdc,P_180,P_CENTER);
941 graphics.DrawLine(&myPen,P_180,P_CENTER);
942 //p->drawLine(P_180, P_CENTER);
943 break;
944 case Lanes::MERGE_FORK_L:
945 case Lanes::HEAD_L:
946 case Lanes::TAIL_L:
947 case Lanes::BOUNDARY_L:
948 //DrawLine(hdc,P_CENTER,P_0);
949 graphics.DrawLine(&myPen,P_CENTER,P_0);
950 //p->drawLine(P_CENTER, P_0);
951 break;
952 default:
953 break;
956 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
958 CBrush brush;
959 brush.CreateSolidBrush(col);
960 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
962 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
963 // center symbol, e.g. rect or ellipse
964 switch (type) {
965 case Lanes::ACTIVE:
966 case Lanes::INITIAL:
967 case Lanes::BRANCH:
969 //p->setPen(Qt::NoPen);
970 //p->setBrush(col);
971 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
972 graphics.FillEllipse(&myBrush, R_CENTER);
973 //p->drawEllipse(R_CENTER);
974 break;
975 case Lanes::MERGE_FORK:
976 case Lanes::MERGE_FORK_R:
977 case Lanes::MERGE_FORK_L:
978 //p->setPen(Qt::NoPen);
979 //p->setBrush(col);
980 //p->drawRect(R_CENTER);
981 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
982 graphics.FillRectangle(&myBrush, R_CENTER);
983 break;
984 case Lanes::UNAPPLIED:
985 // Red minus sign
986 //p->setPen(Qt::NoPen);
987 //p->setBrush(Qt::red);
988 //p->drawRect(m - r, h - 1, d, 2);
989 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
990 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
991 break;
992 case Lanes::APPLIED:
993 // Green plus sign
994 //p->setPen(Qt::NoPen);
995 //p->setBrush(DARK_GREEN);
996 //p->drawRect(m - r, h - 1, d, 2);
997 //p->drawRect(m - 1, h - r, 2, d);
998 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
999 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
1000 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
1001 break;
1002 case Lanes::BOUNDARY:
1003 //p->setBrush(back);
1004 //p->drawEllipse(R_CENTER);
1005 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
1006 graphics.DrawEllipse(&myPen, R_CENTER);
1007 break;
1008 case Lanes::BOUNDARY_C:
1009 case Lanes::BOUNDARY_R:
1010 case Lanes::BOUNDARY_L:
1011 //p->setBrush(back);
1012 //p->drawRect(R_CENTER);
1013 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
1014 graphics.FillRectangle(&myBrush,R_CENTER);
1015 break;
1016 default:
1017 break;
1020 ::SelectObject(hdc,oldpen);
1021 ::SelectObject(hdc,oldbrush);
1022 #undef P_CENTER
1023 #undef P_0
1024 #undef P_90
1025 #undef P_180
1026 #undef P_270
1027 #undef R_CENTER
1030 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
1032 // TODO: unfinished
1033 // return;
1034 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
1035 if(data->m_CommitHash.IsEmpty())
1036 return;
1038 CRect rt=rect;
1039 LVITEM rItem;
1040 SecureZeroMemory(&rItem, sizeof(LVITEM));
1041 rItem.mask = LVIF_STATE;
1042 rItem.iItem = (int)index;
1043 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1044 GetItem(&rItem);
1046 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1048 if (data->m_Lanes.empty())
1049 m_logEntries.setLane(data->m_CommitHash);
1051 std::vector<int>& lanes=data->m_Lanes;
1052 size_t laneNum = lanes.size();
1053 UINT activeLane = 0;
1054 for (UINT i = 0; i < laneNum; ++i)
1055 if (Lanes::isMerge(lanes[i])) {
1056 activeLane = i;
1057 break;
1060 int x2 = 0;
1061 int maxWidth = rect.Width();
1062 int lw = 3 * rect.Height() / 4; //laneWidth()
1064 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1065 //if (opt.state & QStyle::State_Selected)
1066 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1068 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; ++i)
1071 int x1 = x2;
1072 x2 += lw;
1074 int ln = lanes[i];
1075 if (ln == Lanes::EMPTY)
1076 continue;
1078 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1079 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1082 #if 0
1083 for (UINT i = 0; i < laneNum && x2 < maxWidth; ++i) {
1085 int x1 = x2;
1086 x2 += lw;
1088 int ln = lanes[i];
1089 if (ln == Lanes::EMPTY)
1090 continue;
1092 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1093 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1095 if (ln == Lanes::CROSS)
1097 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1098 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1100 else
1101 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1103 #endif
1107 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1110 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1111 // Take the default processing unless we set this to something else below.
1112 *pResult = CDRF_DODEFAULT;
1114 if (m_bNoDispUpdates)
1115 return;
1117 switch (pLVCD->nmcd.dwDrawStage)
1119 case CDDS_PREPAINT:
1121 *pResult = CDRF_NOTIFYITEMDRAW;
1122 return;
1124 break;
1125 case CDDS_ITEMPREPAINT:
1127 // This is the prepaint stage for an item. Here's where we set the
1128 // item's text color.
1130 // Tell Windows to send draw notifications for each subitem.
1131 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1133 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1135 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1137 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1138 if (data)
1140 int action = SafeGetAction(data);
1141 if (action & (CTGitPath::LOGACTIONS_REBASE_DONE | CTGitPath::LOGACTIONS_REBASE_SKIP))
1142 crText = RGB(128,128,128);
1144 if (action & CTGitPath::LOGACTIONS_REBASE_SQUASH)
1145 pLVCD->clrTextBk = RGB(156,156,156);
1146 else if (action & CTGitPath::LOGACTIONS_REBASE_EDIT)
1147 pLVCD->clrTextBk = RGB(200,200,128);
1148 else
1149 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1151 if (action & CTGitPath::LOGACTIONS_REBASE_CURRENT)
1153 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1154 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1157 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1159 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1160 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1163 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1164 // crText = GetSysColor(COLOR_GRAYTEXT);
1166 if (data->m_CommitHash.IsEmpty())
1168 //crText = GetSysColor(RGB(200,200,0));
1169 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1170 // We changed the font, so we're returning CDRF_NEWFONT. This
1171 // tells the control to recalculate the extent of the text.
1172 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1176 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1178 if (m_bStrictStopped)
1179 crText = GetSysColor(COLOR_GRAYTEXT);
1181 // Store the color back in the NMLVCUSTOMDRAW struct.
1182 pLVCD->clrText = crText;
1183 return;
1185 break;
1186 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1188 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1190 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1193 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS))
1195 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1197 CRect rect;
1198 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1200 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1201 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1203 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1204 if( !data ->m_CommitHash.IsEmpty())
1205 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1207 *pResult = CDRF_SKIPDEFAULT;
1208 return;
1212 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1214 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1216 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1217 //if(!data->m_IsFull)
1219 //if(data->SafeFetchFullInfo(&g_Git))
1220 // this->Invalidate();
1221 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1224 if (!m_HashMap[data->m_CommitHash].empty())
1226 CRect rect;
1228 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1230 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1232 std::vector<REFLABEL> refsToShow;
1233 STRING_VECTOR remoteTrackingList;
1234 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1235 for (unsigned int i = 0; i < refList.size(); ++i)
1237 CString str = refList[i];
1239 REFLABEL refLabel;
1240 refLabel.color = RGB(255, 255, 255);
1241 refLabel.singleRemote = false;
1242 refLabel.hasTracking = false;
1243 refLabel.sameName = false;
1244 refLabel.annotatedTag = false;
1245 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1247 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1248 continue;
1249 if (refLabel.name == m_CurrentBranch )
1250 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1251 else
1252 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1254 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1255 CString pullRemote = trackingEntry.first;
1256 CString pullBranch = trackingEntry.second;
1257 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1259 CString defaultUpstream;
1260 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1261 refLabel.hasTracking = true;
1262 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1264 bool found = false;
1265 for (size_t j = i + 1; j < refList.size(); ++j)
1267 if (refList[j] == defaultUpstream)
1269 found = true;
1270 break;
1274 if (found)
1276 bool sameName = pullBranch == refLabel.name;
1277 refsToShow.push_back(refLabel);
1278 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1279 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1280 if (m_bSymbolizeRefNames)
1282 if (!m_SingleRemote.IsEmpty() && m_SingleRemote == pullRemote)
1284 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1285 refLabel.singleRemote = true;
1287 else if (sameName)
1288 refLabel.simplifiedName = pullRemote + _T("/");
1289 refLabel.sameName = sameName;
1291 refsToShow.push_back(refLabel);
1292 remoteTrackingList.push_back(defaultUpstream);
1293 continue;
1298 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1300 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1301 continue;
1303 bool found = false;
1304 for (size_t j = 0; j < remoteTrackingList.size(); ++j)
1306 if (remoteTrackingList[j] == str)
1308 found = true;
1309 break;
1312 if (found)
1313 continue;
1315 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1316 if (m_bSymbolizeRefNames)
1318 if (!m_SingleRemote.IsEmpty() && refLabel.name.Left(m_SingleRemote.GetLength() + 1) == m_SingleRemote + _T("/"))
1320 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1321 refLabel.singleRemote = true;
1325 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1327 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1328 continue;
1329 refLabel.color = m_Colors.GetColor(CColors::Tag);
1330 refLabel.annotatedTag = str.Right(3) == _T("^{}");
1332 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1334 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1335 continue;
1336 refLabel.color = m_Colors.GetColor(CColors::Stash);
1337 refLabel.name = _T("stash");
1339 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1341 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1342 continue;
1343 if (refLabel.name.Find(_T("good")) == 0)
1345 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1346 refLabel.name = _T("good");
1348 if (refLabel.name.Find(_T("bad")) == 0)
1350 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1351 refLabel.name = _T("bad");
1354 else
1355 continue;
1357 refsToShow.push_back(refLabel);
1360 if (refsToShow.empty())
1362 *pResult = CDRF_DODEFAULT;
1363 return;
1366 DrawTagBranchMessage(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1368 *pResult = CDRF_SKIPDEFAULT;
1369 return;
1376 if (pLVCD->iSubItem == LOGLIST_ACTION)
1378 if(this->m_IsIDReplaceAction)
1380 *pResult = CDRF_DODEFAULT;
1381 return;
1383 *pResult = CDRF_DODEFAULT;
1385 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1386 return;
1388 int nIcons = 0;
1389 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1390 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1392 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1393 CRect rect;
1394 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1395 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1396 // Get the selected state of the
1397 // item being drawn.
1399 // Fill the background if necessary
1400 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1402 // Draw the icon(s) into the compatible DC
1403 int action = SafeGetAction(pLogEntry);
1405 if (!pLogEntry->m_IsDiffFiles)
1406 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1408 if (action & CTGitPath::LOGACTIONS_MODIFIED)
1409 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1410 ++nIcons;
1412 if (action & (CTGitPath::LOGACTIONS_ADDED | CTGitPath::LOGACTIONS_COPY))
1413 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1414 ++nIcons;
1416 if (action & CTGitPath::LOGACTIONS_DELETED)
1417 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1418 ++nIcons;
1420 if (action & CTGitPath::LOGACTIONS_REPLACED)
1421 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1422 ++nIcons;
1423 *pResult = CDRF_SKIPDEFAULT;
1424 return;
1427 break;
1429 *pResult = CDRF_DODEFAULT;
1432 // CGitLogListBase message handlers
1434 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1436 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1438 // Create a pointer to the item
1439 LV_ITEM* pItem = &(pDispInfo)->item;
1441 // Do the list need text information?
1442 if (!(pItem->mask & LVIF_TEXT))
1443 return;
1445 // By default, clear text buffer.
1446 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1448 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1450 *pResult = 0;
1451 if (m_bNoDispUpdates || bOutOfRange)
1452 return;
1454 // Which item number?
1455 int itemid = pItem->iItem;
1456 GitRev * pLogEntry = NULL;
1457 if (itemid < m_arShownList.GetCount())
1458 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1460 CString temp;
1461 if(m_IsOldFirst)
1463 temp.Format(_T("%d"),pItem->iItem+1);
1466 else
1468 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1471 // Which column?
1472 switch (pItem->iSubItem)
1474 case this->LOGLIST_GRAPH: //Graphic
1475 break;
1476 case this->LOGLIST_REBASE:
1478 if (this->m_IsRebaseReplaceGraph && pLogEntry)
1480 CTGitPath path;
1481 path.m_Action = SafeGetAction(pLogEntry) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1482 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1485 break;
1486 case this->LOGLIST_ACTION: //action -- no text in the column
1487 break;
1488 case this->LOGLIST_HASH:
1489 if(pLogEntry)
1490 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1491 break;
1492 case this->LOGLIST_ID:
1493 if(this->m_IsIDReplaceAction)
1494 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1495 break;
1496 case this->LOGLIST_MESSAGE: //Message
1497 if (pLogEntry)
1498 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1499 break;
1500 case this->LOGLIST_AUTHOR: //Author
1501 if (pLogEntry)
1502 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1503 break;
1504 case this->LOGLIST_DATE: //Date
1505 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1506 lstrcpyn(pItem->pszText,
1507 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1508 pItem->cchTextMax);
1509 break;
1511 case this->LOGLIST_EMAIL:
1512 if (pLogEntry)
1513 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1514 break;
1516 case this->LOGLIST_COMMIT_NAME: //Commit
1517 if (pLogEntry)
1518 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1519 break;
1521 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1522 if (pLogEntry)
1523 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1524 break;
1526 case this->LOGLIST_COMMIT_DATE: //Commit Date
1527 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1528 lstrcpyn(pItem->pszText,
1529 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1530 pItem->cchTextMax);
1531 break;
1532 case this->LOGLIST_BUG: //Bug ID
1533 if(pLogEntry)
1534 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1535 break;
1537 default:
1538 ASSERT(false);
1542 bool CGitLogListBase::IsOnStash(int index)
1544 if (IsStash(reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index))))
1545 return true;
1546 if (index > 0 && IsStash(reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(index - 1))))
1547 return true;
1548 return false;
1551 bool CGitLogListBase::IsStash(const GitRev * pSelLogEntry)
1553 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1555 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1556 return true;
1558 return false;
1561 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1564 if (pWnd == GetHeaderCtrl())
1566 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1569 int selIndex = GetSelectionMark();
1570 if (selIndex < 0)
1571 return; // nothing selected, nothing to do with a context menu
1573 // if the user selected the info text telling about not all revisions shown due to
1574 // the "stop on copy/rename" option, we also don't show the context menu
1575 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1576 return;
1578 // if the context menu is invoked through the keyboard, we have to use
1579 // a calculated position on where to anchor the menu on
1580 if ((point.x == -1) && (point.y == -1))
1582 CRect rect;
1583 GetItemRect(selIndex, &rect, LVIR_LABEL);
1584 ClientToScreen(&rect);
1585 point = rect.CenterPoint();
1587 m_nSearchIndex = selIndex;
1588 m_bCancelled = FALSE;
1590 // calculate some information the context menu commands can use
1591 // CString pathURL = GetURLFromPath(m_path);
1593 POSITION pos = GetFirstSelectedItemPosition();
1594 int indexNext = GetNextSelectedItem(pos);
1595 if (indexNext < 0)
1596 return;
1598 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1599 #if 0
1600 GitRev revSelected = pSelLogEntry->Rev;
1601 GitRev revPrevious = git_revnum_t(revSelected)-1;
1602 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1604 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1606 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1607 if (changedpath->lCopyFromRev)
1608 revPrevious = changedpath->lCopyFromRev;
1611 GitRev revSelected2;
1612 if (pos)
1614 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1615 revSelected2 = pLogEntry->Rev;
1617 bool bAllFromTheSameAuthor = true;
1618 CString firstAuthor;
1619 CLogDataVector selEntries;
1620 GitRev revLowest, revHighest;
1621 GitRevRangeArray revisionRanges;
1623 POSITION pos = GetFirstSelectedItemPosition();
1624 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1625 revisionRanges.AddRevision(pLogEntry->Rev);
1626 selEntries.push_back(pLogEntry);
1627 firstAuthor = pLogEntry->sAuthor;
1628 revLowest = pLogEntry->Rev;
1629 revHighest = pLogEntry->Rev;
1630 while (pos)
1632 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1633 revisionRanges.AddRevision(pLogEntry->Rev);
1634 selEntries.push_back(pLogEntry);
1635 if (firstAuthor.Compare(pLogEntry->sAuthor))
1636 bAllFromTheSameAuthor = false;
1637 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1638 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1642 #endif
1644 int FirstSelect=-1, LastSelect=-1;
1645 pos = GetFirstSelectedItemPosition();
1646 FirstSelect = GetNextSelectedItem(pos);
1647 while(pos)
1649 LastSelect = GetNextSelectedItem(pos);
1651 //entry is selected, now show the popup menu
1652 CIconMenu popup;
1653 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1655 if (popup.CreatePopupMenu())
1657 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1658 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1659 bool isMergeActive = CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1660 bool isStash = IsOnStash(indexNext);
1662 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1663 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1665 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1666 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1668 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1669 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1671 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1672 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1674 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1675 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1676 popup.AppendMenu(MF_SEPARATOR, NULL);
1678 if (GetSelectedCount() == 1)
1682 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1684 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1685 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1687 else
1689 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1690 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1691 if (isMergeActive && (m_ContextMenuMask & GetContextMenuBit(ID_MERGE_ABORT)))
1692 popup.AppendMenuIcon(ID_MERGE_ABORT, IDS_MENUMERGEABORT, IDI_MERGEABORT);
1694 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1696 GitRev *pRev=pSelLogEntry;
1697 if (pSelLogEntry->m_ParentHash.empty())
1701 pRev->GetParentFromHash(pRev->m_CommitHash);
1703 catch (const char* msg)
1705 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1708 if(pRev->m_ParentHash.size()<=1)
1710 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1713 else
1715 gnudiffmenu.CreatePopupMenu();
1716 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1718 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1719 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1721 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
1723 CString str;
1724 str.Format(IDS_PARENT, i + 1);
1725 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1730 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1733 GitRev *pRev=pSelLogEntry;
1734 if (pSelLogEntry->m_ParentHash.empty())
1738 pRev->GetParentFromHash(pRev->m_CommitHash);
1740 catch (const char* msg)
1742 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1745 if(pRev->m_ParentHash.size()<=1)
1747 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1748 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1749 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1751 else
1753 diffmenu.CreatePopupMenu();
1754 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1755 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
1757 CString str;
1758 str.Format(IDS_PARENT, i + 1);
1759 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1760 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1762 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1763 diffmenu.SetDefaultItem((UINT)(ID_COMPAREWITHPREVIOUS + ((i + 1) << 16)), FALSE);
1769 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1770 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1772 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1773 popup.AppendMenu(MF_SEPARATOR, NULL);
1775 if (pSelLogEntry->m_CommitHash.IsEmpty() && !isMergeActive)
1777 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1778 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1781 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1783 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1784 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1786 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1787 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1789 popup.AppendMenu(MF_SEPARATOR, NULL);
1792 if (pSelLogEntry->m_CommitHash.IsEmpty())
1794 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1795 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1797 popup.AppendMenu(MF_SEPARATOR, NULL);
1801 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1802 // {
1803 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1804 // }
1805 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1806 // {
1807 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1808 // }
1809 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1810 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1811 // {
1812 // popup.AppendMenu(MF_SEPARATOR, NULL);
1813 // }
1815 CString str,format;
1816 //if (m_hasWC)
1817 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1819 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1821 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1822 GetSelectedCount() == 1)
1823 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1825 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1826 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1828 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1829 str.Format(format,g_Git.GetCurrentBranch());
1831 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC && !isMergeActive && !isStash)
1832 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1834 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1835 str.Format(format,g_Git.GetCurrentBranch());
1837 if (m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC && !isStash)
1838 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1841 // Add Switch Branch express Menu
1842 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1843 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC && !isStash)
1846 std::vector<CString *> branchs;
1847 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
1849 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1850 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1852 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1856 CString str;
1857 str.LoadString(IDS_SWITCH_BRANCH);
1859 if(branchs.size() == 1)
1861 str+=_T(" ");
1862 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1863 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1865 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1868 else if(branchs.size() > 1)
1870 subbranchmenu.CreatePopupMenu();
1871 for (size_t i = 0 ; i < branchs.size(); ++i)
1873 if (*branchs[i] != currentBranch)
1875 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1876 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1880 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1884 if (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC && !isStash)
1885 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1887 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH) && !isStash)
1888 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1890 if (m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG) && !isStash)
1891 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1893 format.LoadString(IDS_REBASE_THIS_FORMAT);
1894 str.Format(format,g_Git.GetCurrentBranch());
1896 if (pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC && !isMergeActive && !isStash)
1897 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1898 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1900 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1901 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1903 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive && !isStash)
1905 GitRev *pRev = pSelLogEntry;
1906 if (pSelLogEntry->m_ParentHash.empty())
1910 pRev->GetParentFromHash(pRev->m_CommitHash);
1912 catch (const char* msg)
1914 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
1917 if (pRev->m_ParentHash.size() == 1)
1919 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1921 else
1923 revertmenu.CreatePopupMenu();
1924 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1926 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
1928 CString str;
1929 str.Format(IDS_PARENT, i + 1);
1930 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1935 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE) && !isStash)
1936 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1938 popup.AppendMenu(MF_SEPARATOR, NULL);
1943 if(!pSelLogEntry->m_Ref.IsEmpty())
1945 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1946 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1947 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1948 popup.AppendMenu(MF_SEPARATOR, NULL);
1951 if (GetSelectedCount() >= 2)
1953 bool bAddSeparator = false;
1954 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1956 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1957 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1960 if (GetSelectedCount() == 2)
1962 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1963 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1965 if (!pSelLogEntry->m_CommitHash.IsEmpty())
1967 CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
1968 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1969 CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength());
1970 CString menu;
1971 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("..") + firstSelHash);
1972 popup.AppendMenuIcon(ID_LOG_VIEWRANGE, menu, IDI_LOG);
1973 menu.Format(IDS_SHOWLOG_OF, lastSelHash + _T("...") + firstSelHash);
1974 popup.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE, menu, IDI_LOG);
1977 bAddSeparator = true;
1980 if (m_hasWC)
1982 bAddSeparator = true;
1985 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC && !isMergeActive)
1986 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1988 if (bAddSeparator)
1989 popup.AppendMenu(MF_SEPARATOR, NULL);
1992 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1994 bool bAddSeparator = false;
1995 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1997 if (m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC && !isMergeActive)
1999 CString head;
2000 int headindex;
2001 headindex = this->GetHeadIndex();
2002 if(headindex>=0 && LastSelect >= headindex)
2004 head.Format(_T("HEAD~%d"),LastSelect-headindex);
2005 CGitHash hash;
2006 if (g_Git.GetHash(hash, head))
2007 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR);
2008 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
2009 if(pLastEntry->m_CommitHash == hash) {
2010 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
2011 bAddSeparator = true;
2016 if (m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC && !isMergeActive) {
2017 if (GetSelectedCount() >= 2)
2018 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
2019 else
2020 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
2021 bAddSeparator = true;
2024 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash))
2025 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
2026 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
2027 bAddSeparator = true;
2030 if (bAddSeparator)
2031 popup.AppendMenu(MF_SEPARATOR, NULL);
2034 if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
2036 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
2037 popup.AppendMenu(MF_SEPARATOR, NULL);
2040 if (GetSelectedCount() == 1)
2042 bool bAddSeparator = false;
2043 if (m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !isStash && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
2045 // show the push-option only if the log entry has an associated local branch
2046 bool isLocal = false;
2047 for (size_t i = 0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2049 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
2050 isLocal = true;
2052 if (isLocal)
2054 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
2055 bAddSeparator = true;
2059 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
2061 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
2063 std::vector<CString *> branchs;
2064 for (size_t i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); ++i)
2066 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
2067 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
2069 CString str;
2070 if (branchs.size() == 1)
2072 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
2073 str+=_T(" ");
2074 str += *branchs[0];
2075 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
2076 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
2077 bAddSeparator = true;
2079 else if (branchs.size() > 1)
2081 str.LoadString(IDS_DELETE_BRANCHTAG);
2082 submenu.CreatePopupMenu();
2083 for (size_t i = 0; i < branchs.size(); ++i)
2085 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
2086 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
2089 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
2090 bAddSeparator = true;
2093 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2094 if (bAddSeparator)
2095 popup.AppendMenu(MF_SEPARATOR, NULL);
2096 } // GetSelectedCount() == 1
2098 if (GetSelectedCount() != 0)
2100 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2101 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2102 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2103 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2104 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2105 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2108 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2109 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2111 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2112 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2114 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2115 // DialogEnableWindow(IDOK, FALSE);
2116 // SetPromptApp(&theApp);
2118 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2120 // EnableOKButton();
2121 } // if (popup.CreatePopupMenu())
2125 bool CGitLogListBase::IsSelectionContinuous()
2127 if ( GetSelectedCount()==1 )
2129 // if only one revision is selected, the selection is of course
2130 // continuous
2131 return true;
2134 POSITION pos = GetFirstSelectedItemPosition();
2135 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2136 if (bContinuous)
2138 int itemindex = GetNextSelectedItem(pos);
2139 while (pos)
2141 int nextindex = GetNextSelectedItem(pos);
2142 if (nextindex - itemindex > 1)
2144 bContinuous = false;
2145 break;
2147 itemindex = nextindex;
2150 return bContinuous;
2153 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2156 CString sClipdata;
2157 POSITION pos = GetFirstSelectedItemPosition();
2158 if (pos != NULL)
2160 CString sRev;
2161 sRev.LoadString(IDS_LOG_REVISION);
2162 CString sAuthor;
2163 sAuthor.LoadString(IDS_LOG_AUTHOR);
2164 CString sDate;
2165 sDate.LoadString(IDS_LOG_DATE);
2166 CString sMessage;
2167 sMessage.LoadString(IDS_LOG_MESSAGE);
2168 bool first = true;
2169 while (pos)
2171 CString sLogCopyText;
2172 CString sPaths;
2173 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2175 if (toCopy == ID_COPY_ALL)
2177 //pLogEntry->GetFiles(this)
2178 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2180 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2181 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2183 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2184 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2186 CString rename;
2187 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2188 sPaths += _T(" ") + rename;
2190 sPaths += _T("\r\n");
2192 sPaths.Trim();
2193 CString body = pLogEntry->GetBody();
2194 body.Replace(_T("\n"), _T("\r\n"));
2195 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"),
2196 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2197 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2198 (LPCTSTR)sDate,
2199 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2200 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2201 (LPCTSTR)sPaths);
2202 sClipdata += sLogCopyText;
2204 else if (toCopy == ID_COPY_MESSAGE)
2206 CString body = pLogEntry->GetBody();
2207 body.Replace(_T("\n"), _T("\r\n"));
2208 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2210 else if (toCopy == ID_COPY_SUBJECT)
2212 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2214 else
2216 if (!first)
2217 sClipdata += _T("\r\n");
2218 sClipdata += pLogEntry->m_CommitHash;
2221 first = false;
2223 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2228 void CGitLogListBase::DiffSelectedRevWithPrevious()
2230 if (m_bThreadRunning)
2231 return;
2233 int FirstSelect=-1, LastSelect=-1;
2234 POSITION pos = GetFirstSelectedItemPosition();
2235 FirstSelect = GetNextSelectedItem(pos);
2236 while(pos)
2238 LastSelect = GetNextSelectedItem(pos);
2241 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2243 #if 0
2244 UpdateLogInfoLabel();
2245 int selIndex = m_LogList.GetSelectionMark();
2246 if (selIndex < 0)
2247 return;
2248 int selCount = m_LogList.GetSelectedCount();
2249 if (selCount != 1)
2250 return;
2252 // Find selected entry in the log list
2253 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2254 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2255 long rev1 = pLogEntry->Rev;
2256 long rev2 = rev1-1;
2257 CTGitPath path = m_path;
2259 // See how many files under the relative root were changed in selected revision
2260 int nChanged = 0;
2261 LogChangedPath * changed = NULL;
2262 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2264 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2265 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2267 ++nChanged;
2268 changed = cpath;
2272 if (m_path.IsDirectory() && nChanged == 1)
2274 // We're looking at the log for a directory and only one file under dir was changed in the revision
2275 // Do diff on that file instead of whole directory
2276 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2279 m_bCancelled = FALSE;
2280 DialogEnableWindow(IDOK, FALSE);
2281 SetPromptApp(&theApp);
2282 theApp.DoWaitCursor(1);
2284 if (PromptShown())
2286 GitDiff diff(this, m_hWnd, true);
2287 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2288 diff.SetHEADPeg(m_LogRevision);
2289 diff.ShowCompare(path, rev2, path, rev1);
2291 else
2293 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2296 theApp.DoWaitCursor(-1);
2297 EnableOKButton();
2298 #endif
2301 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2303 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2304 *pResult = -1;
2306 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2307 return;
2308 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2309 return;
2310 if (pFindInfo->lvfi.psz == 0)
2311 return;
2312 #if 0
2313 CString sCmp = pFindInfo->lvfi.psz;
2314 CString sRev;
2315 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2317 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2318 sRev.Format(_T("%ld"), pLogEntry->Rev);
2319 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2321 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2323 *pResult = i;
2324 return;
2327 else
2329 if (sCmp.Compare(sRev)==0)
2331 *pResult = i;
2332 return;
2336 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2338 for (int i=0; i<pFindInfo->iStart; ++i)
2340 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2341 sRev.Format(_T("%ld"), pLogEntry->Rev);
2342 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2344 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2346 *pResult = i;
2347 return;
2350 else
2352 if (sCmp.Compare(sRev)==0)
2354 *pResult = i;
2355 return;
2360 #endif
2361 *pResult = -1;
2364 int CGitLogListBase::FillGitLog(CTGitPath *path, CString *range, int info)
2366 ClearText();
2368 this->m_arShownList.SafeRemoveAll();
2370 this->m_logEntries.ClearAll();
2371 if (this->m_logEntries.ParserFromLog(path, -1, info, range))
2372 return -1;
2374 //this->m_logEntries.ParserFromLog();
2375 SetItemCountEx((int)m_logEntries.size());
2377 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2379 if(m_IsOldFirst)
2381 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2382 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2385 else
2387 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2388 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2392 ReloadHashMap();
2394 if(path)
2395 m_Path=*path;
2396 return 0;
2400 int CGitLogListBase::BeginFetchLog()
2402 ClearText();
2404 this->m_arShownList.SafeRemoveAll();
2406 this->m_logEntries.ClearAll();
2408 this->m_LogCache.ClearAllParent();
2410 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2412 CTGitPath *path;
2413 if(this->m_Path.IsEmpty())
2414 path=NULL;
2415 else
2416 path=&this->m_Path;
2418 int mask;
2419 mask = CGit::LOG_INFO_ONLY_HASH;
2420 if (m_bIncludeBoundaryCommits)
2421 mask |= CGit::LOG_INFO_BOUNDARY;
2422 // if(this->m_bAllBranch)
2423 mask |= m_ShowMask ;
2425 if(m_bShowWC)
2427 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2428 ResetWcRev();
2429 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2432 if (m_sRange.IsEmpty())
2433 m_sRange = _T("HEAD");
2435 CFilterData data;
2436 data.m_From = m_From;
2437 data.m_To =m_To;
2439 #if 0 /* use tortoiegit filter */
2440 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2441 data.m_Author = this->m_sFilterText;
2443 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2444 data.m_MessageFilter = this->m_sFilterText;
2446 data.m_IsRegex = m_bFilterWithRegex;
2447 #endif
2449 // follow does not work for directories
2450 if (!path || path->IsDirectory())
2451 mask &= ~CGit::LOG_INFO_FOLLOW;
2452 // follow does not work with all branches 8at least in TGit)
2453 if (mask & CGit::LOG_INFO_FOLLOW)
2454 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2456 CString cmd = g_Git.GetLogCmd(m_sRange, path, -1, mask, true, &data);
2458 //this->m_logEntries.ParserFromLog();
2459 if(IsInWorkingThread())
2461 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2463 else
2465 SetItemCountEx((int)m_logEntries.size());
2470 [] { git_init(); } ();
2472 catch (char* msg)
2474 CString err(msg);
2475 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2476 return -1;
2479 if (!g_Git.CanParseRev(m_sRange))
2481 if (!(mask & CGit::LOG_INFO_ALL_BRANCH))
2482 return 0;
2484 // if show all branches, pick any ref as dummy entry ref
2485 STRING_VECTOR list;
2486 if (g_Git.GetRefList(list))
2487 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2488 if (list.size() == 0)
2489 return 0;
2491 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, true, &data);
2494 g_Git.m_critGitDllSec.Lock();
2495 try {
2496 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2498 g_Git.m_critGitDllSec.Unlock();
2499 return -1;
2502 catch (char* msg)
2504 g_Git.m_critGitDllSec.Unlock();
2505 CString err(msg);
2506 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2507 return -1;
2509 g_Git.m_critGitDllSec.Unlock();
2511 return 0;
2514 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2516 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2518 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2520 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2522 DiffSelectedRevWithPrevious();
2523 return TRUE;
2526 #if 0
2527 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2529 DiffSelectedFile();
2530 return TRUE;
2532 #endif
2534 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2536 // select all entries
2537 for (int i=0; i<GetItemCount(); ++i)
2539 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2541 return TRUE;
2544 #if 0
2545 if (m_hAccel && !bSkipAccelerator)
2547 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2548 if (ret)
2549 return TRUE;
2552 #endif
2553 //m_tooltips.RelayEvent(pMsg);
2554 return __super::PreTranslateMessage(pMsg);
2557 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2559 // a double click on an entry in the revision list has happened
2560 *pResult = 0;
2562 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2563 DiffSelectedRevWithPrevious();
2566 int CGitLogListBase::FetchLogAsync(void * data)
2568 ReloadHashMap();
2569 m_ProcData=data;
2570 m_bExitThread=FALSE;
2571 InterlockedExchange(&m_bThreadRunning, TRUE);
2572 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2573 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2574 if (m_LoadingThread ==NULL)
2576 InterlockedExchange(&m_bThreadRunning, FALSE);
2577 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2578 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2579 return -1;
2581 return 0;
2584 //this is the thread function which calls the subversion function
2585 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2587 return ((CGitLogListBase*)pVoid)->LogThread();
2590 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2592 //CTime time;
2593 oldest=CTime::GetCurrentTime();
2594 latest=CTime(1971,1,2,0,0,0);
2595 for (unsigned int i = 0; i < m_logEntries.size(); ++i)
2597 if(m_logEntries[i].IsEmpty())
2598 continue;
2600 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2601 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2603 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2604 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2608 if(latest<oldest)
2609 latest=oldest;
2612 UINT CGitLogListBase::LogThread()
2614 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2616 InterlockedExchange(&m_bThreadRunning, TRUE);
2617 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2619 ULONGLONG t1,t2;
2621 if(BeginFetchLog())
2623 InterlockedExchange(&m_bThreadRunning, FALSE);
2624 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2626 return 1;
2629 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2630 bool bRegex = false;
2631 if (m_bFilterWithRegex)
2632 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2634 TRACE(_T("\n===Begin===\n"));
2635 //Update work copy item;
2637 if (!m_logEntries.empty())
2639 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2641 m_arShownList.SafeAdd(pRev);
2645 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2647 // store commit number of the last selected commit/line before the refresh or -1
2648 int lastSelectedHashNItem = -1;
2649 int ret = 0;
2651 bool shouldWalk = true;
2652 if (!g_Git.CanParseRev(m_sRange))
2654 // walk revisions if show all branches and there exists any ref
2655 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH))
2656 shouldWalk = false;
2657 else
2659 STRING_VECTOR list;
2660 if (g_Git.GetRefList(list))
2661 MessageBox(g_Git.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR);
2662 if (list.size() == 0)
2663 shouldWalk = false;
2667 if (shouldWalk)
2669 g_Git.m_critGitDllSec.Lock();
2670 int total = 0;
2673 [&] {git_get_log_firstcommit(m_DllGitLog);}();
2674 total = git_get_log_estimate_commit_count(m_DllGitLog);
2676 catch (char* msg)
2678 CString err(msg);
2679 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2680 ret = -1;
2682 g_Git.m_critGitDllSec.Unlock();
2684 GIT_COMMIT commit;
2685 t2=t1=GetTickCount();
2686 int oldprecentage = 0;
2687 size_t oldsize = m_logEntries.size();
2688 std::map<CGitHash, std::set<CGitHash>> commitChildren;
2689 while (ret== 0 && !m_bExitThread)
2691 g_Git.m_critGitDllSec.Lock();
2694 [&] { ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW); } ();
2696 catch (char* msg)
2698 g_Git.m_critGitDllSec.Unlock();
2699 CString err(msg);
2700 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2701 break;
2703 g_Git.m_critGitDllSec.Unlock();
2705 if(ret)
2706 break;
2708 if (commit.m_ignore == 1)
2710 git_free_commit(&commit);
2711 continue;
2714 //printf("%s\r\n",commit.GetSubject());
2715 if(m_bExitThread)
2716 break;
2718 CGitHash hash = (char*)commit.m_hash ;
2720 GitRev *pRev = m_LogCache.GetCacheData(hash);
2721 pRev->m_GitCommit = commit;
2722 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2724 char *note=NULL;
2725 g_Git.m_critGitDllSec.Lock();
2728 git_get_notes(commit.m_hash, &note);
2730 catch (char* msg)
2732 g_Git.m_critGitDllSec.Unlock();
2733 CString err(msg);
2734 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2735 break;
2737 g_Git.m_critGitDllSec.Unlock();
2739 if(note)
2741 pRev->m_Notes.Empty();
2742 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2745 if(!pRev->m_IsDiffFiles)
2747 pRev->m_CallDiffAsync = DiffAsync;
2750 pRev->ParserParentFromCommit(&commit);
2751 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS) // See also ShouldShowFilter()
2753 for (size_t i = 0; i < pRev->m_ParentHash.size(); ++i)
2755 const CGitHash &parentHash = pRev->m_ParentHash[i];
2756 auto it = commitChildren.find(parentHash);
2757 if (it == commitChildren.end())
2759 it = commitChildren.insert(make_pair(parentHash, std::set<CGitHash>())).first;
2761 it->second.insert(pRev->m_CommitHash);
2765 #ifdef DEBUG
2766 pRev->DbgPrint();
2767 TRACE(_T("\n"));
2768 #endif
2770 bool visible = true;
2771 if(!m_sFilterText.IsEmpty())
2773 if(!IsMatchFilter(bRegex,pRev,pat))
2774 visible = false;
2776 if (visible && !ShouldShowFilter(pRev, commitChildren))
2777 visible = false;
2778 this->m_critSec.Lock();
2779 m_logEntries.append(hash, visible);
2780 if (visible)
2781 m_arShownList.SafeAdd(pRev);
2782 this->m_critSec.Unlock();
2784 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2785 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2787 if (!visible)
2788 continue;
2790 t2=GetTickCount();
2792 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2794 //update UI
2795 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2796 if(percent > 99)
2797 percent =99;
2798 if(percent < GITLOG_START)
2799 percent = GITLOG_START +1;
2801 oldsize = m_logEntries.size();
2802 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2804 //if( percent > oldprecentage )
2806 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2807 oldprecentage = percent;
2810 if (lastSelectedHashNItem >= 0)
2811 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2813 t1 = t2;
2816 g_Git.m_critGitDllSec.Lock();
2817 git_close_log(m_DllGitLog);
2818 g_Git.m_critGitDllSec.Unlock();
2822 if (m_bExitThread)
2824 InterlockedExchange(&m_bThreadRunning, FALSE);
2825 return 0;
2828 //Update UI;
2829 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2831 if (lastSelectedHashNItem >= 0)
2832 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2834 if (this->m_hWnd)
2835 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2837 InterlockedExchange(&m_bThreadRunning, FALSE);
2839 return 0;
2842 void CGitLogListBase::FetchRemoteList()
2844 STRING_VECTOR remoteList;
2845 if (!g_Git.GetRemoteList(remoteList))
2846 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
2847 else
2848 m_SingleRemote = _T("");
2851 void CGitLogListBase::FetchTrackingBranchList()
2853 m_TrackingMap.clear();
2854 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
2856 for (size_t j = 0; j < it->second.size(); ++j)
2858 CString branchName;
2859 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
2861 CString configName;
2862 configName.Format(_T("branch.%s.remote"), branchName);
2863 CString pullRemote = g_Git.GetConfigValue(configName);
2865 configName.Format(_T("branch.%s.merge"), branchName);
2866 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
2868 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
2870 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
2877 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2879 SafeTerminateThread();
2881 this->SetItemCountEx(0);
2882 this->Clear();
2884 ResetWcRev();
2886 // HACK to hide graph column
2887 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2888 SetColumnWidth(0, 0);
2889 else
2890 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2892 //Update branch and Tag info
2893 ReloadHashMap();
2894 //Assume Thread have exited
2895 //if(!m_bThreadRunning)
2897 m_logEntries.clear();
2899 if(IsCleanFilter)
2901 m_sFilterText.Empty();
2902 m_From=-1;
2903 m_To=-1;
2906 InterlockedExchange(&m_bExitThread,FALSE);
2908 InterlockedExchange(&m_bThreadRunning, TRUE);
2909 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2910 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2912 InterlockedExchange(&m_bThreadRunning, FALSE);
2913 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2914 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2918 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, std::tr1::wregex& pat, bool bMatchCase /* = false */)
2922 std::tr1::regex_constants::syntax_option_type type = std::tr1::regex_constants::ECMAScript;
2923 if (!bMatchCase)
2924 type |= std::tr1::regex_constants::icase;
2925 pat = std::tr1::wregex(regexp_str, type);
2926 return true;
2928 catch (std::exception) {}
2929 return false;
2931 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, std::tr1::wregex &pat)
2934 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
2935 CString sRev;
2937 if ((bRegex)&&(m_bFilterWithRegex))
2939 if (m_SelectedFilters & LOGFILTER_BUGID)
2941 if(this->m_bShowBugtraqColumn)
2943 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2945 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2946 if (std::regex_search(std::wstring(sBugIds), pat, flags))
2948 return TRUE;
2953 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2955 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2956 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2958 return TRUE;
2962 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2964 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2965 if (std::regex_search(std::wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2967 return TRUE;
2971 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2973 if (std::regex_search(std::wstring(pRev->GetAuthorName()), pat, flags))
2975 return TRUE;
2978 if (std::regex_search(std::wstring(pRev->GetCommitterName()), pat, flags))
2980 return TRUE;
2984 if (m_SelectedFilters & LOGFILTER_EMAILS)
2986 if (std::regex_search(std::wstring(pRev->GetAuthorEmail()), pat, flags))
2988 return TRUE;
2991 if (std::regex_search(std::wstring(pRev->GetCommitterEmail()), pat, flags))
2993 return TRUE;
2997 if (m_SelectedFilters & LOGFILTER_REVS)
2999 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3000 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags))
3002 return TRUE;
3006 if (m_SelectedFilters & LOGFILTER_REFNAME)
3008 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3009 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3011 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags))
3013 return TRUE;
3018 if (m_SelectedFilters & LOGFILTER_PATHS)
3020 CTGitPathList *pathList=NULL;
3021 if( pRev->m_IsDiffFiles)
3022 pathList = &pRev->GetFiles(this);
3023 else
3025 if(!pRev->m_IsSimpleListReady)
3026 pRev->SafeGetSimpleList(&g_Git);
3029 if(pathList)
3030 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
3032 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
3034 return true;
3036 if (std::regex_search(std::wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
3038 return true;
3042 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3044 if (std::regex_search(std::wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
3046 return true;
3051 else
3053 CString find = m_sFilterText;
3054 find.MakeLower();
3056 if (m_SelectedFilters & LOGFILTER_BUGID)
3058 if(this->m_bShowBugtraqColumn)
3060 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
3062 sBugIds.MakeLower();
3063 if ((sBugIds.Find(find) >= 0))
3065 return TRUE;
3070 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3072 CString msg = pRev->GetSubject();
3074 msg = msg.MakeLower();
3075 if ((msg.Find(find) >= 0))
3077 return TRUE;
3081 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3083 CString msg = pRev->GetBody();
3085 msg = msg.MakeLower();
3086 if ((msg.Find(find) >= 0))
3088 return TRUE;
3092 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3094 CString msg = pRev->GetAuthorName();
3095 msg = msg.MakeLower();
3096 if ((msg.Find(find) >= 0))
3098 return TRUE;
3102 if (m_SelectedFilters & LOGFILTER_EMAILS)
3104 CString msg = pRev->GetAuthorEmail();
3105 msg = msg.MakeLower();
3106 if ((msg.Find(find) >= 0))
3108 return TRUE;
3112 if (m_SelectedFilters & LOGFILTER_REVS)
3114 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
3115 if ((sRev.Find(find) >= 0))
3117 return TRUE;
3121 if (m_SelectedFilters & LOGFILTER_REFNAME)
3123 STRING_VECTOR refs = m_HashMap[pRev->m_CommitHash];
3124 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3126 if (it->Find(find) >= 0)
3128 return TRUE;
3133 if (m_SelectedFilters & LOGFILTER_PATHS)
3135 CTGitPathList *pathList=NULL;
3136 if( pRev->m_IsDiffFiles)
3137 pathList = &pRev->GetFiles(this);
3138 else
3140 if(!pRev->m_IsSimpleListReady)
3141 pRev->SafeGetSimpleList(&g_Git);
3143 if(pathList)
3144 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
3146 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
3147 CString path = cpath->GetGitOldPathString();
3148 path.MakeLower();
3149 if ((path.Find(find)>=0))
3151 return true;
3153 path = cpath->GetGitPathString();
3154 path.MakeLower();
3155 if ((path.Find(find)>=0))
3157 return true;
3161 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); ++i)
3163 CString path = pRev->m_SimpleFileList[i];
3164 path.MakeLower();
3165 if ((path.Find(find)>=0))
3167 return true;
3171 } // else (from if (bRegex))
3172 return FALSE;
3175 static bool CStringStartsWith(const CString &str, const CString &prefix)
3177 return str.Left(prefix.GetLength()) == prefix;
3179 bool CGitLogListBase::ShouldShowFilter(GitRev *pRev, const std::map<CGitHash, std::set<CGitHash>> &commitChildren)
3181 if (m_ShowFilter & FILTERSHOW_ANYCOMMIT)
3182 return true;
3184 if (m_ShowFilter & FILTERSHOW_REFS)
3186 // Keep all refs.
3187 const STRING_VECTOR &refList = m_HashMap[pRev->m_CommitHash];
3188 for (size_t i = 0; i < refList.size(); ++i)
3190 const CString &str = refList[i];
3191 if (CStringStartsWith(str, _T("refs/heads/")))
3193 if (m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES)
3194 return true;
3196 else if (CStringStartsWith(str, _T("refs/remotes/")))
3198 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
3199 return true;
3201 else if (CStringStartsWith(str, _T("refs/tags/")))
3203 if (m_ShowRefMask & LOGLIST_SHOWTAGS)
3204 return true;
3206 else if (CStringStartsWith(str, _T("refs/stash")))
3208 if (m_ShowRefMask & LOGLIST_SHOWSTASH)
3209 return true;
3211 else if (CStringStartsWith(str, _T("refs/bisect/")))
3213 if (m_ShowRefMask & LOGLIST_SHOWBISECT)
3214 return true;
3217 // Keep the head too.
3218 if (pRev->m_CommitHash == m_HeadHash)
3219 return true;
3222 if (m_ShowFilter & FILTERSHOW_MERGEPOINTS)
3224 if (pRev->ParentsCount() > 1)
3225 return true;
3226 auto childrenIt = commitChildren.find(pRev->m_CommitHash);
3227 if (childrenIt != commitChildren.end())
3229 const std::set<CGitHash> &children = childrenIt->second;
3230 if (children.size() > 1)
3231 return true;
3234 return false;
3238 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3241 pShownlist->SafeRemoveAll();
3243 std::tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3244 bool bRegex = false;
3245 if (m_bFilterWithRegex)
3246 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3248 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_any;
3249 CString sRev;
3250 for (DWORD i=0; i<m_logEntries.size(); ++i)
3252 if ((bRegex)&&(m_bFilterWithRegex))
3254 #if 0
3255 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3257 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3258 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3260 pShownlist->SafeAdd(m_logEntries[i]);
3261 continue;
3264 #endif
3265 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3267 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3268 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3270 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3271 continue;
3274 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3276 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3277 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3279 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3280 continue;
3283 if (m_SelectedFilters & LOGFILTER_PATHS)
3285 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3287 bool bGoing = true;
3288 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3290 CTGitPath cpath = pathList[cpPathIndex];
3291 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3293 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3294 bGoing = false;
3295 continue;
3297 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3299 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3300 bGoing = false;
3301 continue;
3303 if (std::regex_search(std::wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3305 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3306 bGoing = false;
3307 continue;
3311 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3313 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3315 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3316 continue;
3319 if (m_SelectedFilters & LOGFILTER_EMAILS)
3321 if (std::regex_search(std::wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorEmail()), pat, flags) && IsEntryInDateRange(i))
3323 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3324 continue;
3327 if (m_SelectedFilters & LOGFILTER_REVS)
3329 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3330 if (std::regex_search(std::wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3332 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3333 continue;
3336 if (m_SelectedFilters & LOGFILTER_REFNAME)
3338 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3339 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3341 if (std::regex_search(std::wstring((LPCTSTR)*it), pat, flags) && IsEntryInDateRange(i))
3343 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3344 continue;
3348 } // if (bRegex)
3349 else
3351 CString find = m_sFilterText;
3352 find.MakeLower();
3353 #if 0
3354 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3356 CString sBugIDs = m_logEntries[i]->sBugIDs;
3358 sBugIDs = sBugIDs.MakeLower();
3359 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3361 pShownlist->SafeAdd(m_logEntries[i]);
3362 continue;
3365 #endif
3366 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3368 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3370 msg = msg.MakeLower();
3371 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3373 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3374 continue;
3377 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3379 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3381 msg = msg.MakeLower();
3382 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3384 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3385 continue;
3388 if (m_SelectedFilters & LOGFILTER_PATHS)
3390 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3392 bool bGoing = true;
3393 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3395 CTGitPath cpath = pathList[cpPathIndex];
3396 CString path = cpath.GetGitOldPathString();
3397 path.MakeLower();
3398 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3400 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3401 bGoing = false;
3402 continue;
3404 path = cpath.GetGitPathString();
3405 path.MakeLower();
3406 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3408 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3409 bGoing = false;
3410 continue;
3412 path = cpath.GetActionName();
3413 path.MakeLower();
3414 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3416 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3417 bGoing = false;
3418 continue;
3422 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3424 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3425 msg = msg.MakeLower();
3426 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3428 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3429 continue;
3432 if (m_SelectedFilters & LOGFILTER_EMAILS)
3434 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorEmail();
3435 msg = msg.MakeLower();
3436 if ((msg.Find(find) >= 0) && (IsEntryInDateRange(i)))
3438 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3439 continue;
3442 if (m_SelectedFilters & LOGFILTER_REVS)
3444 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3445 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3447 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3448 continue;
3451 if (m_SelectedFilters & LOGFILTER_REFNAME)
3453 STRING_VECTOR refs = m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash];
3454 for (auto it = refs.cbegin(); it != refs.cend(); ++it)
3456 if (it->Find(find) >= 0 && IsEntryInDateRange(i))
3458 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3459 continue;
3463 } // else (from if (bRegex))
3464 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3468 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3471 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3473 if(m_From == -1)
3474 if(m_To == -1)
3475 return true;
3476 else
3477 return time <= m_To;
3478 else
3479 if(m_To == -1)
3480 return time >= m_From;
3481 else
3482 return ((time >= m_From)&&(time <= m_To));
3484 return TRUE; /* git dll will filter time range */
3486 // return TRUE;
3488 void CGitLogListBase::StartFilter()
3490 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3491 RecalculateShownList(&m_arShownList);
3492 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3495 DeleteAllItems();
3496 SetItemCountEx(ShownCountWithStopped());
3497 RedrawItems(0, ShownCountWithStopped());
3498 Invalidate();
3501 void CGitLogListBase::RemoveFilter()
3504 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3506 m_arShownList.SafeRemoveAll();
3508 // reset the time filter too
3509 #if 0
3510 m_timFrom = (__time64_t(m_tFrom));
3511 m_timTo = (__time64_t(m_tTo));
3512 m_DateFrom.SetTime(&m_timFrom);
3513 m_DateTo.SetTime(&m_timTo);
3514 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3515 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3516 #endif
3518 for (DWORD i=0; i<m_logEntries.size(); ++i)
3520 if(this->m_IsOldFirst)
3522 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3524 else
3526 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3529 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3530 DeleteAllItems();
3531 SetItemCountEx(ShownCountWithStopped());
3532 RedrawItems(0, ShownCountWithStopped());
3534 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3537 void CGitLogListBase::Clear()
3539 m_arShownList.SafeRemoveAll();
3540 DeleteAllItems();
3542 m_logEntries.ClearAll();
3546 void CGitLogListBase::OnDestroy()
3548 // save the column widths to the registry
3549 SaveColumnWidths();
3551 SafeTerminateThread();
3552 SafeTerminateAsyncDiffThread();
3554 int retry = 0;
3555 while(m_LogCache.SaveCache())
3557 if(retry > 5)
3558 break;
3559 Sleep(1000);
3561 ++retry;
3563 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3564 // MB_YESNO) == IDNO)
3565 // break;
3568 CHintListCtrl::OnDestroy();
3571 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM /*lParam*/)
3573 CRect rect;
3574 int i=(int)wParam;
3575 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3576 this->InvalidateRect(rect);
3578 return 0;
3582 * Save column widths to the registry
3584 void CGitLogListBase::SaveColumnWidths()
3586 int maxcol = m_ColumnManager.GetColumnCount();
3588 // HACK that graph column is always shown
3589 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3591 for (int col = 0; col < maxcol; ++col)
3592 if (m_ColumnManager.IsVisible (col))
3593 m_ColumnManager.ColumnResized (col);
3595 m_ColumnManager.WriteSettings();
3598 int CGitLogListBase::GetHeadIndex()
3600 if(m_HeadHash.IsEmpty())
3601 return -1;
3603 for (int i = 0; i < m_arShownList.GetCount(); ++i)
3605 GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i);
3606 if(pRev)
3608 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3609 return i;
3612 return -1;
3614 void CGitLogListBase::OnFind()
3616 if (!m_pFindDialog)
3618 m_pFindDialog = new CFindDlg(this);
3619 m_pFindDialog->Create(this);
3622 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3624 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3626 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3628 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3629 Default();
3631 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3633 if (GetSelectedCount() != 0)
3634 return 0;
3636 CGitHash theSelectedHash = m_lastSelectedHash;
3637 SetItemState((int)itemToSelect, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3638 m_lastSelectedHash = theSelectedHash;
3640 int countPerPage = GetCountPerPage();
3641 EnsureVisible(max(0, (int)itemToSelect-countPerPage/2), FALSE);
3642 EnsureVisible(min(GetItemCount(), (int)itemToSelect+countPerPage/2), FALSE);
3643 EnsureVisible((int)itemToSelect, FALSE);
3644 return 0;
3646 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3649 ASSERT(m_pFindDialog != NULL);
3650 bool bFound = false;
3651 int i=0;
3653 if (m_pFindDialog->IsTerminating())
3655 // invalidate the handle identifying the dialog box.
3656 m_pFindDialog = NULL;
3657 return 0;
3660 INT_PTR cnt = m_arShownList.GetCount();
3662 if(m_pFindDialog->IsRef())
3664 CString str;
3665 str=m_pFindDialog->GetFindString();
3667 CGitHash hash;
3669 if(!str.IsEmpty())
3671 if (g_Git.GetHash(hash, str + _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3672 MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ref \"") + str + _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR);
3675 if(!hash.IsEmpty())
3677 for (i = 0; i < cnt; ++i)
3679 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3680 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3682 bFound = true;
3683 break;
3687 if (!bFound)
3689 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3690 return 0;
3694 if (m_pFindDialog->FindNext() && !bFound)
3696 //read data from dialog
3697 CString FindText = m_pFindDialog->GetFindString();
3698 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3700 std::tr1::wregex pat;
3701 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3703 std::tr1::regex_constants::match_flag_type flags = std::tr1::regex_constants::match_not_null;
3705 for (i = m_nSearchIndex + 1; ; ++i)
3707 if (i >= cnt)
3709 i = 0;
3710 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 2, 100);
3712 if (m_nSearchIndex >= 0)
3714 if (i == m_nSearchIndex)
3716 ::MessageBeep(0xFFFFFFFF);
3717 m_pFindDialog->FlashWindowEx(FLASHW_ALL, 3, 100);
3718 break;
3722 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3724 CString str;
3725 str+=pLogEntry->m_CommitHash.ToString();
3726 str+=_T("\n");
3728 for (size_t j = 0; j < this->m_HashMap[pLogEntry->m_CommitHash].size(); ++j)
3730 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3731 str+=_T("\n");
3734 str+=pLogEntry->GetAuthorEmail();
3735 str+=_T("\n");
3736 str+=pLogEntry->GetAuthorName();
3737 str+=_T("\n");
3738 str+=pLogEntry->GetBody();
3739 str+=_T("\n");
3740 str+=pLogEntry->GetCommitterEmail();
3741 str+=_T("\n");
3742 str+=pLogEntry->GetCommitterName();
3743 str+=_T("\n");
3744 str+=pLogEntry->GetSubject();
3745 str+=_T("\n");
3748 /*Because changed files list is loaded on demand when gui show,
3749 files will empty when files have not fetched.
3751 we can add it back by using one-way diff(with outnumber changed and rename detect.
3752 here just need changed filename list. one-way is much quicker.
3754 if(pLogEntry->m_IsFull)
3756 for (int i = 0; i < pLogEntry->GetFiles(this).GetCount(); ++i)
3758 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3759 str+=_T("\n");
3760 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3761 str+=_T("\n");
3764 else
3766 if(!pLogEntry->m_IsSimpleListReady)
3767 pLogEntry->SafeGetSimpleList(&g_Git);
3769 for (size_t i = 0; i < pLogEntry->m_SimpleFileList.size(); ++i)
3771 str+=pLogEntry->m_SimpleFileList[i];
3772 str+=_T("\n");
3778 if (bRegex)
3780 if (std::regex_search(std::wstring(str), pat, flags))
3782 bFound = true;
3783 break;
3786 else
3788 if (bMatchCase)
3790 if (str.Find(FindText) >= 0)
3792 bFound = true;
3793 break;
3797 else
3799 CString msg = str;
3800 msg = msg.MakeLower();
3801 CString find = FindText.MakeLower();
3802 if (msg.Find(find) >= 0)
3804 bFound = TRUE;
3805 break;
3809 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3811 } // if(m_pFindDialog->FindNext())
3812 //UpdateLogInfoLabel();
3814 if (bFound)
3816 m_nSearchIndex = i;
3817 EnsureVisible(i, FALSE);
3818 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3819 SetItemState(i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
3820 SetSelectionMark(i);
3821 //FillLogMessageCtrl();
3822 UpdateData(FALSE);
3825 return 0;
3828 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3830 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3832 *pResult = FALSE;
3835 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3837 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3839 Invalidate(FALSE);