fixed possible crash in TortoiseGitBlame
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob247f92e2a223a14301e162fda9c2e56134ae1d40
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2012 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "GitLogListBase.h"
26 #include "GitRev.h"
27 //#include "VssStyle.h"
28 #include "IconMenu.h"
29 // CGitLogListBase
30 #include "cursor.h"
31 #include "InputDlg.h"
32 #include "GITProgressDlg.h"
33 #include "ProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
37 #include "Logdlg.h"
38 #include "MessageBox.h"
39 #include "Registry.h"
40 #include "LoglistUtils.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
44 #include "TempFile.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
47 #include "IconMenu.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.h"
51 //#include "Blame.h"
52 //#include "GitHelpers.h"
53 #include "GitStatus.h"
54 //#include "LogDlgHelper.h"
55 //#include "CachedLogInfo.h"
56 //#include "RepositoryInfo.h"
57 //#include "EditPropertiesDlg.h"
58 #include "FileDiffDlg.h"
59 #include "..\\TortoiseShell\\Resource.h"
60 #include "FindDlg.h"
61 #include "SysInfo.h"
63 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
65 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
67 CGitLogListBase::CGitLogListBase():CHintListCtrl()
68 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
69 ,m_nSearchIndex(0)
70 ,m_bNoDispUpdates(FALSE)
71 , m_bThreadRunning(FALSE)
72 , m_bStrictStopped(false)
73 , m_pStoreSelection(NULL)
74 , m_SelectedFilters(LOGFILTER_ALL)
75 , m_bShowWC(false)
76 , m_logEntries(&m_LogCache)
77 , m_pFindDialog(NULL)
78 , m_ColumnManager(this)
79 , m_dwDefaultColumns(0)
80 , m_arShownList(&m_critSec)
81 , m_hasWC(true)
83 // use the default GUI font, create a copy of it and
84 // change the copy to BOLD (leave the rest of the font
85 // the same)
86 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
87 LOGFONT lf = {0};
88 GetObject(hFont, sizeof(LOGFONT), &lf);
89 lf.lfWeight = FW_BOLD;
90 m_boldFont = CreateFontIndirect(&lf);
92 m_bShowBugtraqColumn=false;
94 m_IsIDReplaceAction=FALSE;
96 this->m_critSec.Init();
97 m_wcRev.m_CommitHash.Empty();
98 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
99 m_wcRev.m_ParentHash.clear();
100 m_wcRev.m_Mark=_T('-');
101 m_wcRev.m_IsUpdateing=FALSE;
102 m_wcRev.m_IsFull = TRUE;
104 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
105 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
106 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
112 g_Git.GetMapHashToFriendName(m_HashMap);
113 if (CTGitPath(g_Git.m_CurrentDir).HasAdminDir())
115 m_CurrentBranch=g_Git.GetCurrentBranch();
116 m_HeadHash=g_Git.GetHash(_T("HEAD"));
119 m_From=-1;;
120 m_To=-1;
122 m_ShowMask = 0;
123 m_LoadingThread = NULL;
125 InterlockedExchange(&m_bExitThread,FALSE);
126 m_IsOldFirst = FALSE;
127 m_IsRebaseReplaceGraph = FALSE;
130 for(int i=0;i<Lanes::COLORS_NUM;i++)
132 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
134 // get short/long datetime setting from registry
135 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
136 if ( RegUseShortDateFormat )
138 m_DateFormat = DATE_SHORTDATE;
140 else
142 m_DateFormat = DATE_LONGDATE;
144 // get relative time display setting from registry
145 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
146 m_bRelativeTimes = (regRelativeTimes != 0);
147 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
149 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
150 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
151 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
152 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
153 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
154 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
156 m_ColumnRegKey=_T("log");
158 m_AsyncThreadExit = FALSE;
159 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
160 m_AsynDiffListLock.Init();
162 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
163 if (m_DiffingThread ==NULL)
165 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
166 return;
171 int CGitLogListBase::AsyncDiffThread()
173 m_AsyncThreadExited = false;
174 while(!m_AsyncThreadExit)
176 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
178 GitRev *pRev = NULL;
179 while(!m_AsyncThreadExit && m_AsynDiffList.size() > 0)
181 m_AsynDiffListLock.Lock();
182 pRev = m_AsynDiffList.back();
183 m_AsynDiffList.pop_back();
184 m_AsynDiffListLock.Unlock();
186 if( pRev->m_CommitHash.IsEmpty() )
188 if(pRev->m_IsDiffFiles)
189 continue;
191 pRev->GetFiles(this).Clear();
192 pRev->m_ParentHash.clear();
193 pRev->m_ParentHash.push_back(m_HeadHash);
194 if(g_Git.IsInitRepos())
196 g_Git.GetInitAddList(pRev->GetFiles(this));
199 else
201 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
203 pRev->GetAction(this) = 0;
205 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
206 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
208 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
209 InterlockedExchange(&pRev->m_IsFull, TRUE);
211 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
212 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
213 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
216 if(!pRev->CheckAndDiff())
217 { // fetch change file list
218 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
220 if(i < m_arShownList.GetCount())
222 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
223 if(data->m_CommitHash == pRev->m_CommitHash)
225 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
226 break;
231 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
233 POSITION pos = GetFirstSelectedItemPosition();
234 int nItem = GetNextSelectedItem(pos);
236 if(nItem>=0)
238 GitRev* data = (GitRev*)m_arShownList[nItem];
239 if(data)
240 if(data->m_CommitHash == pRev->m_CommitHash)
242 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
249 m_AsyncThreadExited = true;
250 return 0;
252 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
254 if (exclusivelyShow)
256 m_ContextMenuMask &= hideMask;
258 else
260 m_ContextMenuMask &= ~hideMask;
264 CGitLogListBase::~CGitLogListBase()
266 InterlockedExchange(&m_bNoDispUpdates, TRUE);
267 this->m_arShownList.SafeRemoveAll();
269 DestroyIcon(m_hModifiedIcon);
270 DestroyIcon(m_hReplacedIcon);
271 DestroyIcon(m_hAddedIcon);
272 DestroyIcon(m_hDeletedIcon);
273 m_logEntries.ClearAll();
275 if (m_boldFont)
276 DeleteObject(m_boldFont);
278 if ( m_pStoreSelection )
280 delete m_pStoreSelection;
281 m_pStoreSelection = NULL;
284 SafeTerminateThread();
285 SafeTerminateAsyncDiffThread();
287 if(m_AsyncDiffEvent)
288 CloseHandle(m_AsyncDiffEvent);
292 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
293 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
294 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
295 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
296 ON_WM_CONTEXTMENU()
297 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
298 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
299 ON_WM_CREATE()
300 ON_WM_DESTROY()
301 ON_MESSAGE(MSG_LOADED,OnLoad)
302 ON_WM_MEASUREITEM()
303 ON_WM_MEASUREITEM_REFLECT()
304 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
305 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
306 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
307 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
308 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
309 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
310 END_MESSAGE_MAP()
312 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
314 //if (m_nRowHeight>0)
316 lpMeasureItemStruct->itemHeight = 50;
320 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
322 PreSubclassWindow();
323 return CHintListCtrl::OnCreate(lpCreateStruct);
326 void CGitLogListBase::PreSubclassWindow()
328 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
329 // load the icons for the action columns
330 // m_Theme.Open(m_hWnd, L"ListView");
331 SetWindowTheme(m_hWnd, L"Explorer", NULL);
332 CHintListCtrl::PreSubclassWindow();
335 void CGitLogListBase::InsertGitColumn()
337 CString temp;
339 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
340 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
341 if (DWORD(regFullRowSelect))
342 exStyle |= LVS_EX_FULLROWSELECT;
343 SetExtendedStyle(exStyle);
345 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);
421 * Resizes all columns in a list control to values in registry.
423 void CGitLogListBase::ResizeAllListCtrlCols()
425 // column max and min widths to allow
426 static const int nMinimumWidth = 10;
427 static const int nMaximumWidth = 1000;
428 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
429 if (pHdrCtrl)
431 int numcols = pHdrCtrl->GetItemCount();
432 for (int col = 0; col < numcols; col++)
434 // get width for this col last time from registry
435 CString regentry;
436 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
437 CRegDWORD regwidth(regentry, 0);
438 int cx = regwidth;
439 if ( cx == 0 )
441 // no saved value, setup sensible defaults
442 if (col == this->LOGLIST_MESSAGE)
444 cx = LOGLIST_MESSAGE_MIN;
446 else
448 cx = ICONITEMBORDER+16*4;
451 if (cx < nMinimumWidth)
453 cx = nMinimumWidth;
455 else if (cx > nMaximumWidth)
457 cx = nMaximumWidth;
460 SetColumnWidth(col, cx);
467 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
469 //TRACE(_T("%s %s\r\n"),ref,prefix);
470 if(ref.Left(prefix.GetLength()) == prefix)
472 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
473 if(shortname.Right(3)==_T("^{}"))
474 shortname=shortname.Left(shortname.GetLength()-3);
475 return TRUE;
477 return FALSE;
480 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
482 LVITEM rItem;
483 SecureZeroMemory(&rItem, sizeof(LVITEM));
484 rItem.mask = LVIF_STATE;
485 rItem.iItem = Index;
486 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
487 GetItem(&rItem);
489 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
490 HBRUSH brush = NULL;
492 if (!(rItem.state & LVIS_SELECTED))
494 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
495 brush = ::CreateSolidBrush(RGB(156,156,156));
496 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
497 brush = ::CreateSolidBrush(RGB(200,200,128));
499 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
501 if (rItem.state & LVIS_SELECTED)
503 if (::GetFocus() == m_hWnd)
504 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
505 else
506 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
510 if (brush != NULL)
512 ::FillRect(hdc, &rect, brush);
513 ::DeleteObject(brush);
517 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
519 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
520 CRect rt=rect;
521 LVITEM rItem;
522 SecureZeroMemory(&rItem, sizeof(LVITEM));
523 rItem.mask = LVIF_STATE;
524 rItem.iItem = index;
525 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
526 GetItem(&rItem);
528 CDC W_Dc;
529 W_Dc.Attach(hdc);
531 HTHEME hTheme = NULL;
532 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
533 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
535 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
537 CString str;
538 str=m_HashMap[data->m_CommitHash][i];
540 CString shortname;
541 HBRUSH brush = 0;
542 shortname = _T("");
543 COLORREF colRef = 0;
545 //Determine label color
546 if(GetShortName(str,shortname,_T("refs/heads/")))
548 if( shortname == m_CurrentBranch )
549 colRef = m_Colors.GetColor(CColors::CurrentBranch);
550 else
551 colRef = m_Colors.GetColor(CColors::LocalBranch);
554 else if(GetShortName(str,shortname,_T("refs/remotes/")))
556 colRef = m_Colors.GetColor(CColors::RemoteBranch);
558 else if(GetShortName(str,shortname,_T("refs/tags/")))
560 colRef = m_Colors.GetColor(CColors::Tag);
562 else if(GetShortName(str,shortname,_T("refs/stash")))
564 colRef = m_Colors.GetColor(CColors::Stash);
565 shortname=_T("stash");
567 else if(GetShortName(str,shortname,_T("refs/bisect/")))
569 if(shortname.Find(_T("good")) == 0)
571 colRef = m_Colors.GetColor(CColors::BisectGood);
572 shortname = _T("good");
575 if(shortname.Find(_T("bad")) == 0)
577 colRef = m_Colors.GetColor(CColors::BisectBad);
578 shortname = _T("bad");
582 //When row selected, ajust label color
583 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
584 if (rItem.state & LVIS_SELECTED)
585 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
587 brush = ::CreateSolidBrush(colRef);
589 if(!shortname.IsEmpty() && (rt.left<rect.right) )
591 SIZE size;
592 memset(&size,0,sizeof(SIZE));
593 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
595 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
596 rt.right+=8;
598 int textpos = DT_CENTER;
600 if(rt.right > rect.right)
602 rt.right = rect.right;
603 textpos =0;
606 //Fill interior of ref label
607 ::FillRect(hdc, &rt, brush);
609 //Draw edge of label
611 CRect rectEdge = rt;
613 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
614 rectEdge.DeflateRect(1,1);
615 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
617 //Draw text inside label
618 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
620 int txtState = LISS_NORMAL;
621 if (rItem.state & LVIS_SELECTED)
622 txtState = LISS_SELECTED;
624 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
626 else
628 W_Dc.SetBkMode(TRANSPARENT);
629 if (rItem.state & LVIS_SELECTED)
631 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
632 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
633 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
634 ::SetTextColor(hdc,clrOld);
636 else
638 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
642 //::MoveToEx(hdc,rt.left,rt.top,NULL);
643 //::LineTo(hdc,rt.right,rt.top);
644 //::LineTo(hdc,rt.right,rt.bottom);
645 //::LineTo(hdc,rt.left,rt.bottom);
646 //::LineTo(hdc,rt.left,rt.top);
648 rt.left=rt.right+1;
650 if(brush)
651 ::DeleteObject(brush);
653 rt.right=rect.right;
655 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
657 int txtState = LISS_NORMAL;
658 if (rItem.state & LVIS_SELECTED)
659 txtState = LISS_SELECTED;
661 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
663 else
665 if (rItem.state & LVIS_SELECTED)
667 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
668 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
669 ::SetTextColor(hdc,clrOld);
671 else
673 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
677 if (hTheme)
678 CloseThemeData(hTheme);
680 W_Dc.Detach();
683 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
685 // Returns ((256 - amount)*col1 + amount*col2) / 256;
686 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
687 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
688 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
691 Gdiplus::Color GetGdiColor(COLORREF col)
693 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
695 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
696 const COLORREF& col,const COLORREF& activeColor, int top
699 int h = laneHeight / 2;
700 int m = (x1 + x2) / 2;
701 int r = (x2 - x1) / 3;
702 int d = 2 * r;
704 #define P_CENTER m , h+top
705 #define P_0 x2, h+top
706 #define P_90 m , 0+top-1
707 #define P_180 x1, h+top
708 #define P_270 m , 2 * h+top +1
709 #define R_CENTER m - r, h - r+top, d, d
712 #define DELTA_UR_B 2*(x1 - m), 2*h +top
713 #define DELTA_UR_E 0*16, 90*16 +top // -,
715 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
716 #define DELTA_DR_E 270*16, 90*16 +top // -'
718 #define DELTA_UL_B 2*(x2 - m), 2*h +top
719 #define DELTA_UL_E 90*16, 90*16 +top // ,-
721 #define DELTA_DL_B 2*(x2 - m),2*-h +top
722 #define DELTA_DL_E 180*16, 90*16 // '-
724 #define CENTER_UR x1, 2*h, 225
725 #define CENTER_DR x1, 0 , 135
726 #define CENTER_UL x2, 2*h, 315
727 #define CENTER_DL x2, 0 , 45
730 Gdiplus::Graphics graphics( hdc );
732 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
734 // arc
735 switch (type) {
736 case Lanes::JOIN:
737 case Lanes::JOIN_R:
738 case Lanes::HEAD:
739 case Lanes::HEAD_R:
741 Gdiplus::LinearGradientBrush gradient(
742 Gdiplus::Point(x1-2, h+top-2),
743 Gdiplus::Point(P_270),
744 GetGdiColor(activeColor),GetGdiColor(col));
747 Gdiplus::Pen mypen(&gradient,2);
748 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
750 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
751 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
752 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
754 break;
756 case Lanes::JOIN_L:
759 Gdiplus::LinearGradientBrush gradient(
760 Gdiplus::Point(P_270),
761 Gdiplus::Point(x2+1, h+top-1),
762 GetGdiColor(col),GetGdiColor(activeColor));
765 Gdiplus::Pen mypen(&gradient,2);
766 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
768 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
769 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
770 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
773 break;
775 case Lanes::TAIL:
776 case Lanes::TAIL_R:
779 Gdiplus::LinearGradientBrush gradient(
780 Gdiplus::Point(x1-2, h+top-2),
781 Gdiplus::Point(P_90),
782 GetGdiColor(activeColor),GetGdiColor(col));
784 Gdiplus::Pen mypen(&gradient,2);
786 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
788 #if 0
789 QConicalGradient gradient(CENTER_DR);
790 gradient.setColorAt(0.375, activeCol);
791 gradient.setColorAt(0.625, col);
792 myPen.setBrush(gradient);
793 p->setPen(myPen);
794 p->drawArc(P_CENTER, DELTA_DR);
795 #endif
796 break;
798 default:
799 break;
803 //static QPen myPen(Qt::black, 2); // fast path here
804 CPen pen;
805 pen.CreatePen(PS_SOLID,2,col);
806 //myPen.setColor(col);
807 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
809 Gdiplus::Pen myPen(GetGdiColor(col),2);
811 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
813 //p->setPen(myPen);
815 // vertical line
816 switch (type) {
817 case Lanes::ACTIVE:
818 case Lanes::NOT_ACTIVE:
819 case Lanes::MERGE_FORK:
820 case Lanes::MERGE_FORK_R:
821 case Lanes::MERGE_FORK_L:
822 case Lanes::JOIN:
823 case Lanes::JOIN_R:
824 case Lanes::JOIN_L:
825 case Lanes::CROSS:
826 //DrawLine(hdc,P_90,P_270);
827 graphics.DrawLine(&myPen,P_90,P_270);
828 //p->drawLine(P_90, P_270);
829 break;
830 case Lanes::HEAD_L:
831 case Lanes::BRANCH:
832 //DrawLine(hdc,P_CENTER,P_270);
833 graphics.DrawLine(&myPen,P_CENTER,P_270);
834 //p->drawLine(P_CENTER, P_270);
835 break;
836 case Lanes::TAIL_L:
837 case Lanes::INITIAL:
838 case Lanes::BOUNDARY:
839 case Lanes::BOUNDARY_C:
840 case Lanes::BOUNDARY_R:
841 case Lanes::BOUNDARY_L:
842 //DrawLine(hdc,P_90, P_CENTER);
843 graphics.DrawLine(&myPen,P_90,P_CENTER);
844 //p->drawLine(P_90, P_CENTER);
845 break;
846 default:
847 break;
850 myPen.SetColor(GetGdiColor(activeColor));
852 // horizontal line
853 switch (type) {
854 case Lanes::MERGE_FORK:
855 case Lanes::JOIN:
856 case Lanes::HEAD:
857 case Lanes::TAIL:
858 case Lanes::CROSS:
859 case Lanes::CROSS_EMPTY:
860 case Lanes::BOUNDARY_C:
861 //DrawLine(hdc,P_180,P_0);
862 graphics.DrawLine(&myPen,P_180,P_0);
863 //p->drawLine(P_180, P_0);
864 break;
865 case Lanes::MERGE_FORK_R:
866 case Lanes::BOUNDARY_R:
867 //DrawLine(hdc,P_180,P_CENTER);
868 graphics.DrawLine(&myPen,P_180,P_CENTER);
869 //p->drawLine(P_180, P_CENTER);
870 break;
871 case Lanes::MERGE_FORK_L:
872 case Lanes::HEAD_L:
873 case Lanes::TAIL_L:
874 case Lanes::BOUNDARY_L:
875 //DrawLine(hdc,P_CENTER,P_0);
876 graphics.DrawLine(&myPen,P_CENTER,P_0);
877 //p->drawLine(P_CENTER, P_0);
878 break;
879 default:
880 break;
883 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
885 CBrush brush;
886 brush.CreateSolidBrush(col);
887 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
889 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
890 // center symbol, e.g. rect or ellipse
891 switch (type) {
892 case Lanes::ACTIVE:
893 case Lanes::INITIAL:
894 case Lanes::BRANCH:
896 //p->setPen(Qt::NoPen);
897 //p->setBrush(col);
898 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
899 graphics.FillEllipse(&myBrush, R_CENTER);
900 //p->drawEllipse(R_CENTER);
901 break;
902 case Lanes::MERGE_FORK:
903 case Lanes::MERGE_FORK_R:
904 case Lanes::MERGE_FORK_L:
905 //p->setPen(Qt::NoPen);
906 //p->setBrush(col);
907 //p->drawRect(R_CENTER);
908 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
909 graphics.FillRectangle(&myBrush, R_CENTER);
910 break;
911 case Lanes::UNAPPLIED:
912 // Red minus sign
913 //p->setPen(Qt::NoPen);
914 //p->setBrush(Qt::red);
915 //p->drawRect(m - r, h - 1, d, 2);
916 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
917 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
918 break;
919 case Lanes::APPLIED:
920 // Green plus sign
921 //p->setPen(Qt::NoPen);
922 //p->setBrush(DARK_GREEN);
923 //p->drawRect(m - r, h - 1, d, 2);
924 //p->drawRect(m - 1, h - r, 2, d);
925 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
926 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
927 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
928 break;
929 case Lanes::BOUNDARY:
930 //p->setBrush(back);
931 //p->drawEllipse(R_CENTER);
932 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
933 graphics.DrawEllipse(&myPen, R_CENTER);
934 break;
935 case Lanes::BOUNDARY_C:
936 case Lanes::BOUNDARY_R:
937 case Lanes::BOUNDARY_L:
938 //p->setBrush(back);
939 //p->drawRect(R_CENTER);
940 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
941 graphics.FillRectangle(&myBrush,R_CENTER);
942 break;
943 default:
944 break;
947 ::SelectObject(hdc,oldpen);
948 ::SelectObject(hdc,oldbrush);
949 #undef P_CENTER
950 #undef P_0
951 #undef P_90
952 #undef P_180
953 #undef P_270
954 #undef R_CENTER
957 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
959 // TODO: unfinished
960 // return;
961 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
962 if(data->m_CommitHash.IsEmpty())
963 return;
965 CRect rt=rect;
966 LVITEM rItem;
967 SecureZeroMemory(&rItem, sizeof(LVITEM));
968 rItem.mask = LVIF_STATE;
969 rItem.iItem = index;
970 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
971 GetItem(&rItem);
973 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
975 if (data->m_Lanes.size() == 0)
976 m_logEntries.setLane(data->m_CommitHash);
978 std::vector<int>& lanes=data->m_Lanes;
979 UINT laneNum = lanes.size();
980 UINT activeLane = 0;
981 for (UINT i = 0; i < laneNum; i++)
982 if (Lanes::isMerge(lanes[i])) {
983 activeLane = i;
984 break;
987 int x1 = 0, x2 = 0;
988 int maxWidth = rect.Width();
989 int lw = 3 * rect.Height() / 4; //laneWidth()
991 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
992 //if (opt.state & QStyle::State_Selected)
993 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
995 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
998 x1 = x2;
999 x2 += lw;
1001 int ln = lanes[i];
1002 if (ln == Lanes::EMPTY)
1003 continue;
1005 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1006 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1009 #if 0
1010 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1012 x1 = x2;
1013 x2 += lw;
1015 int ln = lanes[i];
1016 if (ln == Lanes::EMPTY)
1017 continue;
1019 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1020 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1022 if (ln == Lanes::CROSS)
1024 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1025 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1027 else
1028 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1030 #endif
1034 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1037 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1038 // Take the default processing unless we set this to something else below.
1039 *pResult = CDRF_DODEFAULT;
1041 if (m_bNoDispUpdates)
1042 return;
1044 switch (pLVCD->nmcd.dwDrawStage)
1046 case CDDS_PREPAINT:
1048 *pResult = CDRF_NOTIFYITEMDRAW;
1049 return;
1051 break;
1052 case CDDS_ITEMPREPAINT:
1054 // This is the prepaint stage for an item. Here's where we set the
1055 // item's text color.
1057 // Tell Windows to send draw notifications for each subitem.
1058 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1060 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1062 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1064 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1065 if (data)
1067 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1068 crText = RGB(128,128,128);
1070 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1071 pLVCD->clrTextBk = RGB(156,156,156);
1072 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1073 pLVCD->clrTextBk = RGB(200,200,128);
1074 else
1075 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1077 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1079 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1080 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1083 if(data->m_CommitHash.ToString() == m_HeadHash)
1085 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1086 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1089 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1090 // crText = GetSysColor(COLOR_GRAYTEXT);
1092 if (data->m_CommitHash.IsEmpty())
1094 //crText = GetSysColor(RGB(200,200,0));
1095 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1096 // We changed the font, so we're returning CDRF_NEWFONT. This
1097 // tells the control to recalculate the extent of the text.
1098 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1102 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1104 if (m_bStrictStopped)
1105 crText = GetSysColor(COLOR_GRAYTEXT);
1107 // Store the color back in the NMLVCUSTOMDRAW struct.
1108 pLVCD->clrText = crText;
1109 return;
1111 break;
1112 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1114 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1116 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1119 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1121 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1123 CRect rect;
1124 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1126 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1127 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1129 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1130 if( !data ->m_CommitHash.IsEmpty())
1131 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1133 *pResult = CDRF_SKIPDEFAULT;
1134 return;
1138 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1140 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1142 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1143 //if(!data->m_IsFull)
1145 //if(data->SafeFetchFullInfo(&g_Git))
1146 // this->Invalidate();
1147 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1150 if(m_HashMap[data->m_CommitHash].size()!=0)
1152 CRect rect;
1154 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1156 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1157 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1159 *pResult = CDRF_SKIPDEFAULT;
1160 return;
1167 if (pLVCD->iSubItem == LOGLIST_ACTION)
1169 if(this->m_IsIDReplaceAction)
1171 *pResult = CDRF_DODEFAULT;
1172 return;
1174 *pResult = CDRF_DODEFAULT;
1176 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1177 return;
1179 int nIcons = 0;
1180 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1181 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1183 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1184 CRect rect;
1185 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1186 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1187 // Get the selected state of the
1188 // item being drawn.
1190 // Fill the background if necessary
1191 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1193 // Draw the icon(s) into the compatible DC
1194 pLogEntry->GetAction(this);
1196 if (!pLogEntry->m_IsDiffFiles)
1197 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1199 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1200 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1201 nIcons++;
1203 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1204 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1205 nIcons++;
1207 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1208 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1209 nIcons++;
1211 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1212 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1213 nIcons++;
1214 *pResult = CDRF_SKIPDEFAULT;
1215 return;
1218 break;
1220 *pResult = CDRF_DODEFAULT;
1223 // CGitLogListBase message handlers
1225 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1227 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1229 // Create a pointer to the item
1230 LV_ITEM* pItem = &(pDispInfo)->item;
1232 // Do the list need text information?
1233 if (!(pItem->mask & LVIF_TEXT))
1234 return;
1236 // By default, clear text buffer.
1237 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1239 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1241 *pResult = 0;
1242 if (m_bNoDispUpdates || bOutOfRange)
1243 return;
1245 // Which item number?
1246 int itemid = pItem->iItem;
1247 GitRev * pLogEntry = NULL;
1248 if (itemid < m_arShownList.GetCount())
1249 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1251 CString temp;
1252 if(m_IsOldFirst)
1254 temp.Format(_T("%d"),pItem->iItem+1);
1257 else
1259 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1262 // Which column?
1263 switch (pItem->iSubItem)
1265 case this->LOGLIST_GRAPH: //Graphic
1266 break;
1267 case this->LOGLIST_REBASE:
1269 if(this->m_IsRebaseReplaceGraph)
1271 CTGitPath path;
1272 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1273 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1276 break;
1277 case this->LOGLIST_ACTION: //action -- no text in the column
1278 break;
1279 case this->LOGLIST_HASH:
1280 if(pLogEntry)
1281 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1282 break;
1283 case this->LOGLIST_ID:
1284 if(this->m_IsIDReplaceAction)
1285 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1286 break;
1287 case this->LOGLIST_MESSAGE: //Message
1288 if (pLogEntry)
1289 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1290 break;
1291 case this->LOGLIST_AUTHOR: //Author
1292 if (pLogEntry)
1293 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1294 break;
1295 case this->LOGLIST_DATE: //Date
1296 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1297 lstrcpyn(pItem->pszText,
1298 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1299 pItem->cchTextMax);
1300 break;
1302 case this->LOGLIST_EMAIL:
1303 if (pLogEntry)
1304 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1305 break;
1307 case this->LOGLIST_COMMIT_NAME: //Commit
1308 if (pLogEntry)
1309 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1310 break;
1312 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1313 if (pLogEntry)
1314 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1315 break;
1317 case this->LOGLIST_COMMIT_DATE: //Commit Date
1318 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1319 lstrcpyn(pItem->pszText,
1320 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1321 pItem->cchTextMax);
1322 break;
1323 case this->LOGLIST_BUG: //Bug ID
1324 if(pLogEntry)
1325 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1326 break;
1328 default:
1329 ASSERT(false);
1333 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1336 if (pWnd == GetHeaderCtrl())
1338 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1341 int selIndex = GetSelectionMark();
1342 if (selIndex < 0)
1343 return; // nothing selected, nothing to do with a context menu
1345 // if the user selected the info text telling about not all revisions shown due to
1346 // the "stop on copy/rename" option, we also don't show the context menu
1347 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1348 return;
1350 // if the context menu is invoked through the keyboard, we have to use
1351 // a calculated position on where to anchor the menu on
1352 if ((point.x == -1) && (point.y == -1))
1354 CRect rect;
1355 GetItemRect(selIndex, &rect, LVIR_LABEL);
1356 ClientToScreen(&rect);
1357 point = rect.CenterPoint();
1359 m_nSearchIndex = selIndex;
1360 m_bCancelled = FALSE;
1362 // calculate some information the context menu commands can use
1363 // CString pathURL = GetURLFromPath(m_path);
1365 POSITION pos = GetFirstSelectedItemPosition();
1366 int indexNext = GetNextSelectedItem(pos);
1367 if (indexNext < 0)
1368 return;
1370 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1371 #if 0
1372 GitRev revSelected = pSelLogEntry->Rev;
1373 GitRev revPrevious = git_revnum_t(revSelected)-1;
1374 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1376 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1378 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1379 if (changedpath->lCopyFromRev)
1380 revPrevious = changedpath->lCopyFromRev;
1383 GitRev revSelected2;
1384 if (pos)
1386 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1387 revSelected2 = pLogEntry->Rev;
1389 bool bAllFromTheSameAuthor = true;
1390 CString firstAuthor;
1391 CLogDataVector selEntries;
1392 GitRev revLowest, revHighest;
1393 GitRevRangeArray revisionRanges;
1395 POSITION pos = GetFirstSelectedItemPosition();
1396 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1397 revisionRanges.AddRevision(pLogEntry->Rev);
1398 selEntries.push_back(pLogEntry);
1399 firstAuthor = pLogEntry->sAuthor;
1400 revLowest = pLogEntry->Rev;
1401 revHighest = pLogEntry->Rev;
1402 while (pos)
1404 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1405 revisionRanges.AddRevision(pLogEntry->Rev);
1406 selEntries.push_back(pLogEntry);
1407 if (firstAuthor.Compare(pLogEntry->sAuthor))
1408 bAllFromTheSameAuthor = false;
1409 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1410 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1414 #endif
1416 int FirstSelect=-1, LastSelect=-1;
1417 pos = GetFirstSelectedItemPosition();
1418 FirstSelect = GetNextSelectedItem(pos);
1419 while(pos)
1421 LastSelect = GetNextSelectedItem(pos);
1423 //entry is selected, now show the popup menu
1424 CIconMenu popup;
1425 CIconMenu subbranchmenu, submenu, gnudiffmenu,diffmenu;
1427 if (popup.CreatePopupMenu())
1429 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1430 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1432 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1433 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1435 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1436 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1438 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1439 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1441 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1442 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1444 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1445 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1446 popup.AppendMenu(MF_SEPARATOR, NULL);
1448 if (GetSelectedCount() == 1)
1452 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1454 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1455 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1457 else
1459 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1460 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1462 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1464 GitRev *pRev=pSelLogEntry;
1465 if(pSelLogEntry->m_ParentHash.size()==0)
1467 pRev->GetParentFromHash(pRev->m_CommitHash);
1469 if(pRev->m_ParentHash.size()<=1)
1471 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1474 else
1476 gnudiffmenu.CreatePopupMenu();
1477 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1479 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1 + (0xFFFF << 16), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1480 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1 + (0xFFFE << 16), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1482 for(int i=0;i<pRev->m_ParentHash.size();i++)
1484 CString str;
1485 str.Format(IDS_PARENT, i + 1);
1486 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1491 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1494 GitRev *pRev=pSelLogEntry;
1495 if(pSelLogEntry->m_ParentHash.size()==0)
1497 pRev->GetParentFromHash(pRev->m_CommitHash);
1499 if(pRev->m_ParentHash.size()<=1)
1501 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1502 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1503 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1505 else
1507 diffmenu.CreatePopupMenu();
1508 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1509 for(int i=0;i<pRev->m_ParentHash.size();i++)
1511 CString str;
1512 str.Format(IDS_PARENT, i + 1);
1513 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1514 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1516 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1517 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1523 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1524 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1526 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1527 popup.AppendMenu(MF_SEPARATOR, NULL);
1529 if (pSelLogEntry->m_CommitHash.IsEmpty())
1531 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1532 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1534 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir())
1536 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1537 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1539 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1540 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1543 popup.AppendMenu(MF_SEPARATOR, NULL);
1545 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1546 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1548 popup.AppendMenu(MF_SEPARATOR, NULL);
1552 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1553 // {
1554 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1555 // }
1556 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1557 // {
1558 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1559 // }
1560 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1561 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1562 // {
1563 // popup.AppendMenu(MF_SEPARATOR, NULL);
1564 // }
1566 CString str,format;
1567 //if (m_hasWC)
1568 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1570 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1572 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1573 GetSelectedCount() == 1)
1574 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1576 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1577 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1579 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1580 str.Format(format,g_Git.GetCurrentBranch());
1582 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1583 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1585 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1586 str.Format(format,g_Git.GetCurrentBranch());
1588 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1589 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1592 // Add Switch Branch express Menu
1593 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1594 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1597 std::vector<CString *> branchs;
1598 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1600 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1601 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1603 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1607 CString str;
1608 str.LoadString(IDS_SWITCH_BRANCH);
1610 if(branchs.size() == 1)
1612 str+=_T(" ");
1613 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1614 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1616 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1619 else if(branchs.size() > 1)
1621 subbranchmenu.CreatePopupMenu();
1622 for(int i=0;i<branchs.size();i++)
1624 if (*branchs[i] != currentBranch)
1626 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1627 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1631 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1635 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1636 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1638 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1639 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1641 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1642 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1644 format.LoadString(IDS_REBASE_THIS_FORMAT);
1645 str.Format(format,g_Git.GetCurrentBranch());
1647 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1648 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1649 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1651 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1652 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1654 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1655 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1657 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1658 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1660 popup.AppendMenu(MF_SEPARATOR, NULL);
1665 if(!pSelLogEntry->m_Ref.IsEmpty())
1667 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1668 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1669 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1670 popup.AppendMenu(MF_SEPARATOR, NULL);
1673 if (GetSelectedCount() >= 2)
1675 bool bAddSeparator = false;
1676 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1678 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1679 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1682 if (GetSelectedCount() == 2)
1684 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1685 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1686 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1687 bAddSeparator = true;
1690 if (m_hasWC)
1692 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1693 // if (m_hasWC)
1694 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1695 bAddSeparator = true;
1698 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1699 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1701 if (bAddSeparator)
1702 popup.AppendMenu(MF_SEPARATOR, NULL);
1705 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1707 bool bAddSeparator = false;
1708 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1710 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1712 CString head;
1713 int headindex;
1714 headindex = this->GetHeadIndex();
1715 if(headindex>=0)
1717 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1718 CGitHash hash=g_Git.GetHash(head);
1719 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1720 if(pLastEntry->m_CommitHash == hash) {
1721 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1722 bAddSeparator = true;
1727 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1728 if (GetSelectedCount() >= 2)
1729 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1730 else
1731 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1732 bAddSeparator = true;
1735 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1736 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1737 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1738 bAddSeparator = true;
1741 if (bAddSeparator)
1742 popup.AppendMenu(MF_SEPARATOR, NULL);
1745 #if 0
1746 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1747 // {
1748 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1749 // }
1750 // if (GetSelectedCount() == 1)
1751 // {
1752 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1753 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1754 // popup.AppendMenu(MF_SEPARATOR, NULL);
1755 // }
1756 #endif
1758 if (GetSelectedCount() == 1)
1760 bool bAddSeparator = false;
1761 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && m_HashMap[pSelLogEntry->m_CommitHash].size() >= 1)
1763 // show the push-option only if the log entry has an associated local branch
1764 bool isLocal = false;
1765 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1767 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1768 isLocal = true;
1770 if (isLocal)
1772 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1773 bAddSeparator = true;
1777 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1779 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1781 std::vector<CString *> branchs;
1782 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1784 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1785 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1787 CString str;
1788 if (branchs.size() == 1)
1790 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1791 str+=_T(" ");
1792 str += *branchs[0];
1793 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1794 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1795 bAddSeparator = true;
1797 else if (branchs.size() > 1)
1799 str.LoadString(IDS_DELETE_BRANCHTAG);
1800 submenu.CreatePopupMenu();
1801 for (int i = 0; i < branchs.size(); i++)
1803 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1804 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1807 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1808 bAddSeparator = true;
1811 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1812 if (bAddSeparator)
1813 popup.AppendMenu(MF_SEPARATOR, NULL);
1814 } // GetSelectedCount() == 1
1816 if (GetSelectedCount() == 1)
1818 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1819 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1821 if (GetSelectedCount() != 0)
1823 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1824 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1827 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1828 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1830 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
1831 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
1833 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1834 // DialogEnableWindow(IDOK, FALSE);
1835 // SetPromptApp(&theApp);
1837 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1839 // EnableOKButton();
1840 } // if (popup.CreatePopupMenu())
1844 bool CGitLogListBase::IsSelectionContinuous()
1846 if ( GetSelectedCount()==1 )
1848 // if only one revision is selected, the selection is of course
1849 // continuous
1850 return true;
1853 POSITION pos = GetFirstSelectedItemPosition();
1854 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1855 if (bContinuous)
1857 int itemindex = GetNextSelectedItem(pos);
1858 while (pos)
1860 int nextindex = GetNextSelectedItem(pos);
1861 if (nextindex - itemindex > 1)
1863 bContinuous = false;
1864 break;
1866 itemindex = nextindex;
1869 return bContinuous;
1872 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
1875 CString sClipdata;
1876 POSITION pos = GetFirstSelectedItemPosition();
1877 if (pos != NULL)
1879 CString sRev;
1880 sRev.LoadString(IDS_LOG_REVISION);
1881 CString sAuthor;
1882 sAuthor.LoadString(IDS_LOG_AUTHOR);
1883 CString sDate;
1884 sDate.LoadString(IDS_LOG_DATE);
1885 CString sMessage;
1886 sMessage.LoadString(IDS_LOG_MESSAGE);
1887 while (pos)
1889 CString sLogCopyText;
1890 CString sPaths;
1891 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1893 if(!HashOnly)
1895 //pLogEntry->GetFiles(this)
1896 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1898 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1900 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1901 sPaths += _T("\r\n");
1903 sPaths.Trim();
1904 CString body = pLogEntry->GetBody();
1905 body.Replace(_T("\n"), _T("\r\n"));
1906 sLogCopyText.Format(_T("%s: %s\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
1907 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1908 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(),
1909 (LPCTSTR)sDate,
1910 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1911 (LPCTSTR)sMessage, pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim(),
1912 (LPCTSTR)sPaths);
1913 sClipdata += sLogCopyText;
1915 else
1917 sClipdata += pLogEntry->m_CommitHash;
1918 break;
1922 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1927 void CGitLogListBase::DiffSelectedRevWithPrevious()
1929 if (m_bThreadRunning)
1930 return;
1932 int FirstSelect=-1, LastSelect=-1;
1933 POSITION pos = GetFirstSelectedItemPosition();
1934 FirstSelect = GetNextSelectedItem(pos);
1935 while(pos)
1937 LastSelect = GetNextSelectedItem(pos);
1940 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1942 #if 0
1943 UpdateLogInfoLabel();
1944 int selIndex = m_LogList.GetSelectionMark();
1945 if (selIndex < 0)
1946 return;
1947 int selCount = m_LogList.GetSelectedCount();
1948 if (selCount != 1)
1949 return;
1951 // Find selected entry in the log list
1952 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1953 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
1954 long rev1 = pLogEntry->Rev;
1955 long rev2 = rev1-1;
1956 CTGitPath path = m_path;
1958 // See how many files under the relative root were changed in selected revision
1959 int nChanged = 0;
1960 LogChangedPath * changed = NULL;
1961 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
1963 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
1964 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1966 ++nChanged;
1967 changed = cpath;
1971 if (m_path.IsDirectory() && nChanged == 1)
1973 // We're looking at the log for a directory and only one file under dir was changed in the revision
1974 // Do diff on that file instead of whole directory
1975 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
1978 m_bCancelled = FALSE;
1979 DialogEnableWindow(IDOK, FALSE);
1980 SetPromptApp(&theApp);
1981 theApp.DoWaitCursor(1);
1983 if (PromptShown())
1985 GitDiff diff(this, m_hWnd, true);
1986 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1987 diff.SetHEADPeg(m_LogRevision);
1988 diff.ShowCompare(path, rev2, path, rev1);
1990 else
1992 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1995 theApp.DoWaitCursor(-1);
1996 EnableOKButton();
1997 #endif
2000 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2002 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2003 *pResult = -1;
2005 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2006 return;
2007 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2008 return;
2009 if (pFindInfo->lvfi.psz == 0)
2010 return;
2011 #if 0
2012 CString sCmp = pFindInfo->lvfi.psz;
2013 CString sRev;
2014 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2016 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2017 sRev.Format(_T("%ld"), pLogEntry->Rev);
2018 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2020 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2022 *pResult = i;
2023 return;
2026 else
2028 if (sCmp.Compare(sRev)==0)
2030 *pResult = i;
2031 return;
2035 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2037 for (int i=0; i<pFindInfo->iStart; ++i)
2039 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2040 sRev.Format(_T("%ld"), pLogEntry->Rev);
2041 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2043 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2045 *pResult = i;
2046 return;
2049 else
2051 if (sCmp.Compare(sRev)==0)
2053 *pResult = i;
2054 return;
2059 #endif
2060 *pResult = -1;
2063 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2065 ClearText();
2067 this->m_arShownList.SafeRemoveAll();
2069 this->m_logEntries.ClearAll();
2070 this->m_logEntries.ParserFromLog(path,-1,info,from,to);
2072 //this->m_logEntries.ParserFromLog();
2073 SetItemCountEx(this->m_logEntries.size());
2075 for(unsigned int i=0;i<m_logEntries.size();i++)
2077 if(m_IsOldFirst)
2079 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2080 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2083 else
2085 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2086 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2090 m_CurrentBranch = g_Git.GetCurrentBranch();
2091 m_HeadHash = g_Git.GetHash(_T("HEAD"));
2093 if(path)
2094 m_Path=*path;
2095 return 0;
2099 int CGitLogListBase::BeginFetchLog()
2101 ClearText();
2103 this->m_arShownList.SafeRemoveAll();
2105 this->m_logEntries.ClearAll();
2106 git_init();
2108 this->m_LogCache.ClearAllParent();
2110 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2112 CTGitPath *path;
2113 if(this->m_Path.IsEmpty())
2114 path=NULL;
2115 else
2116 path=&this->m_Path;
2118 CString hash;
2119 int mask;
2120 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2121 // if(this->m_bAllBranch)
2122 mask |= m_ShowMask ;
2124 if(m_bShowWC)
2126 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2127 ResetWcRev();
2128 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2131 CString *pFrom, *pTo;
2132 pFrom = pTo = NULL;
2133 CString head(_T("HEAD"));
2134 if(!this->m_startrev.IsEmpty())
2136 pFrom = &this->m_startrev;
2137 if(!this->m_endrev.IsEmpty())
2138 pTo = &this->m_endrev;
2139 else
2140 pTo = &head;
2143 CFilterData data;
2144 data.m_From = m_From;
2145 data.m_To =m_To;
2147 #if 0 /* use tortoiegit filter */
2148 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2149 data.m_Author = this->m_sFilterText;
2151 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2152 data.m_MessageFilter = this->m_sFilterText;
2154 data.m_IsRegex = m_bFilterWithRegex;
2155 #endif
2157 // follow does not work for directories
2158 if (!path || path->IsDirectory())
2159 mask &= ~CGit::LOG_INFO_FOLLOW;
2160 // follow does not work with all branches 8at least in TGit)
2161 if (mask & CGit::LOG_INFO_FOLLOW)
2162 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2164 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2166 //this->m_logEntries.ParserFromLog();
2167 if(IsInWorkingThread())
2169 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2171 else
2173 SetItemCountEx(this->m_logEntries.size());
2176 git_init();
2178 if(g_Git.IsInitRepos())
2179 return 0;
2181 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2183 return -1;
2186 return 0;
2189 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2191 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2193 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2195 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2197 DiffSelectedRevWithPrevious();
2198 return TRUE;
2201 #if 0
2202 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2204 DiffSelectedFile();
2205 return TRUE;
2207 #endif
2209 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2211 // select all entries
2212 for (int i=0; i<GetItemCount(); ++i)
2214 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2216 return TRUE;
2219 #if 0
2220 if (m_hAccel && !bSkipAccelerator)
2222 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2223 if (ret)
2224 return TRUE;
2227 #endif
2228 //m_tooltips.RelayEvent(pMsg);
2229 return __super::PreTranslateMessage(pMsg);
2232 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2234 // a double click on an entry in the revision list has happened
2235 *pResult = 0;
2237 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2238 DiffSelectedRevWithPrevious();
2241 int CGitLogListBase::FetchLogAsync(void * data)
2243 m_ProcData=data;
2244 m_bExitThread=FALSE;
2245 InterlockedExchange(&m_bThreadRunning, TRUE);
2246 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2247 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2248 if (m_LoadingThread ==NULL)
2250 InterlockedExchange(&m_bThreadRunning, FALSE);
2251 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2252 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2253 return -1;
2255 return 0;
2258 //this is the thread function which calls the subversion function
2259 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2261 return ((CGitLogListBase*)pVoid)->LogThread();
2264 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2266 //CTime time;
2267 oldest=CTime::GetCurrentTime();
2268 latest=CTime(1971,1,2,0,0,0);
2269 for(unsigned int i=0;i<m_logEntries.size();i++)
2271 if(m_logEntries[i].IsEmpty())
2272 continue;
2274 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2275 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2277 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2278 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2282 if(latest<oldest)
2283 latest=oldest;
2286 UINT CGitLogListBase::LogThread()
2288 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2290 InterlockedExchange(&m_bThreadRunning, TRUE);
2291 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2293 ULONGLONG t1,t2;
2295 if(BeginFetchLog())
2297 InterlockedExchange(&m_bThreadRunning, FALSE);
2298 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2300 return -1;
2303 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2304 bool bRegex = false;
2305 if (m_bFilterWithRegex)
2306 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2308 TRACE(_T("\n===Begin===\n"));
2309 //Update work copy item;
2311 if( m_logEntries.size() > 0)
2313 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2315 m_arShownList.SafeAdd(pRev);
2319 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2321 // store commit number of the last selected commit/line before the refresh or -1
2322 int lastSelectedHashNItem = -1;
2324 if(!g_Git.IsInitRepos())
2326 g_Git.m_critGitDllSec.Lock();
2327 git_get_log_firstcommit(m_DllGitLog);
2328 int total = git_get_log_estimate_commit_count(m_DllGitLog);
2329 g_Git.m_critGitDllSec.Unlock();
2331 GIT_COMMIT commit;
2332 t2=t1=GetTickCount();
2333 int oldprecentage = 0;
2334 int oldsize=m_logEntries.size();
2335 int ret=0;
2336 while( ret== 0)
2338 g_Git.m_critGitDllSec.Lock();
2339 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2340 g_Git.m_critGitDllSec.Unlock();
2342 if(ret)
2343 break;
2345 if (commit.m_ignore == 1)
2347 git_free_commit(&commit);
2348 continue;
2351 //printf("%s\r\n",commit.GetSubject());
2352 if(m_bExitThread)
2353 break;
2355 CGitHash hash = (char*)commit.m_hash ;
2357 GitRev *pRev = m_LogCache.GetCacheData(hash);
2358 pRev->m_GitCommit = commit;
2359 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2361 char *note=NULL;
2362 g_Git.m_critGitDllSec.Lock();
2363 git_get_notes(commit.m_hash,&note);
2364 g_Git.m_critGitDllSec.Unlock();
2366 if(note)
2368 pRev->m_Notes.Empty();
2369 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2372 if(!pRev->m_IsDiffFiles)
2374 pRev->m_CallDiffAsync = DiffAsync;
2377 pRev->ParserParentFromCommit(&commit);
2379 #ifdef DEBUG
2380 pRev->DbgPrint();
2381 TRACE(_T("\n"));
2382 #endif
2384 if(!m_sFilterText.IsEmpty())
2386 if(!IsMatchFilter(bRegex,pRev,pat))
2387 continue;
2389 this->m_critSec.Lock();
2390 m_logEntries.push_back(hash);
2391 m_arShownList.SafeAdd(pRev);
2392 this->m_critSec.Unlock();
2394 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2395 lastSelectedHashNItem = m_arShownList.GetCount() - 1;
2397 t2=GetTickCount();
2399 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2401 //update UI
2402 int percent=m_logEntries.size()*100/total + GITLOG_START+1;
2403 if(percent > 99)
2404 percent =99;
2405 if(percent < GITLOG_START)
2406 percent = GITLOG_START +1;
2408 oldsize = m_logEntries.size();
2409 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2411 //if( percent > oldprecentage )
2413 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2414 oldprecentage = percent;
2416 t1 = t2;
2419 g_Git.m_critGitDllSec.Lock();
2420 git_close_log(m_DllGitLog);
2421 g_Git.m_critGitDllSec.Unlock();
2425 // restore last selected item
2426 if (lastSelectedHashNItem >= 0)
2428 SetItemState(lastSelectedHashNItem, LVIS_SELECTED, LVIS_SELECTED);
2429 EnsureVisible(lastSelectedHashNItem, FALSE);
2432 //Update UI;
2433 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2434 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2436 InterlockedExchange(&m_bThreadRunning, FALSE);
2438 return 0;
2441 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2443 SafeTerminateThread();
2445 this->SetItemCountEx(0);
2446 this->Clear();
2448 ResetWcRev();
2450 // HACK to hide graph column
2451 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2452 SetColumnWidth(0, 0);
2453 else
2454 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2456 //Update branch and Tag info
2457 ReloadHashMap();
2458 //Assume Thread have exited
2459 //if(!m_bThreadRunning)
2461 m_logEntries.clear();
2463 if(IsCleanFilter)
2465 m_sFilterText.Empty();
2466 m_From=-1;
2467 m_To=-1;
2470 InterlockedExchange(&m_bExitThread,FALSE);
2472 InterlockedExchange(&m_bThreadRunning, TRUE);
2473 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2474 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2476 InterlockedExchange(&m_bThreadRunning, FALSE);
2477 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2478 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2482 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2486 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2487 if (!bMatchCase)
2488 type |= tr1::regex_constants::icase;
2489 pat = tr1::wregex(regexp_str, type);
2490 return true;
2492 catch (exception) {}
2493 return false;
2495 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2498 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2499 CString sRev;
2501 if ((bRegex)&&(m_bFilterWithRegex))
2503 if (m_SelectedFilters & LOGFILTER_BUGID)
2505 if(this->m_bShowBugtraqColumn)
2507 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2509 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2510 if (regex_search(wstring(sBugIds), pat, flags))
2512 return TRUE;
2517 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2519 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2520 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2522 return TRUE;
2526 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2528 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2529 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2531 return TRUE;
2535 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2537 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2539 return TRUE;
2542 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2544 return TRUE;
2548 if (m_SelectedFilters & LOGFILTER_REVS)
2550 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2551 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2553 return TRUE;
2557 if (m_SelectedFilters & LOGFILTER_PATHS)
2559 CTGitPathList *pathList=NULL;
2560 if( pRev->m_IsDiffFiles)
2561 pathList = &pRev->GetFiles(this);
2562 else
2564 if(!pRev->m_IsSimpleListReady)
2565 pRev->SafeGetSimpleList(&g_Git);
2568 if(pathList)
2569 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2571 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2573 return true;
2575 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2577 return true;
2581 for(INT_PTR i=0;i<pRev->m_SimpleFileList.size();i++)
2583 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2585 return true;
2590 else
2592 CString find = m_sFilterText;
2593 find.MakeLower();
2595 if (m_SelectedFilters & LOGFILTER_BUGID)
2597 if(this->m_bShowBugtraqColumn)
2599 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2601 sBugIds.MakeLower();
2602 if ((sBugIds.Find(find) >= 0))
2604 return TRUE;
2609 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2611 CString msg = pRev->GetSubject();
2613 msg = msg.MakeLower();
2614 if ((msg.Find(find) >= 0))
2616 return TRUE;
2620 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2622 CString msg = pRev->GetBody();
2624 msg = msg.MakeLower();
2625 if ((msg.Find(find) >= 0))
2627 return TRUE;
2631 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2633 CString msg = pRev->GetAuthorName();
2634 msg = msg.MakeLower();
2635 if ((msg.Find(find) >= 0))
2637 return TRUE;
2641 if (m_SelectedFilters & LOGFILTER_REVS)
2643 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2644 if ((sRev.Find(find) >= 0))
2646 return TRUE;
2650 if (m_SelectedFilters & LOGFILTER_PATHS)
2652 CTGitPathList *pathList=NULL;
2653 if( pRev->m_IsDiffFiles)
2654 pathList = &pRev->GetFiles(this);
2655 else
2657 if(!pRev->m_IsSimpleListReady)
2658 pRev->SafeGetSimpleList(&g_Git);
2660 if(pathList)
2661 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2663 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2664 CString path = cpath->GetGitOldPathString();
2665 path.MakeLower();
2666 if ((path.Find(find)>=0))
2668 return true;
2670 path = cpath->GetGitPathString();
2671 path.MakeLower();
2672 if ((path.Find(find)>=0))
2674 return true;
2678 for (INT_PTR i=0;i<pRev->m_SimpleFileList.size();i++)
2680 CString path = pRev->m_SimpleFileList[i];
2681 path.MakeLower();
2682 if ((path.Find(find)>=0))
2684 return true;
2688 } // else (from if (bRegex))
2689 return FALSE;
2693 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2696 pShownlist->SafeRemoveAll();
2698 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2699 bool bRegex = false;
2700 if (m_bFilterWithRegex)
2701 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2703 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2704 CString sRev;
2705 for (DWORD i=0; i<m_logEntries.size(); ++i)
2707 if ((bRegex)&&(m_bFilterWithRegex))
2709 #if 0
2710 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2712 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2713 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2715 pShownlist->SafeAdd(m_logEntries[i]);
2716 continue;
2719 #endif
2720 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2722 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2723 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2725 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2726 continue;
2729 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2731 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2732 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2734 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2735 continue;
2738 if (m_SelectedFilters & LOGFILTER_PATHS)
2740 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2742 bool bGoing = true;
2743 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2745 CTGitPath cpath = pathList[cpPathIndex];
2746 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2748 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2749 bGoing = false;
2750 continue;
2752 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2754 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2755 bGoing = false;
2756 continue;
2758 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2760 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2761 bGoing = false;
2762 continue;
2766 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2768 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2770 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2771 continue;
2774 if (m_SelectedFilters & LOGFILTER_REVS)
2776 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2777 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2779 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2780 continue;
2783 } // if (bRegex)
2784 else
2786 CString find = m_sFilterText;
2787 find.MakeLower();
2788 #if 0
2789 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2791 CString sBugIDs = m_logEntries[i]->sBugIDs;
2793 sBugIDs = sBugIDs.MakeLower();
2794 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2796 pShownlist->SafeAdd(m_logEntries[i]);
2797 continue;
2800 #endif
2801 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2803 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2805 msg = msg.MakeLower();
2806 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2808 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2809 continue;
2812 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2814 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
2816 msg = msg.MakeLower();
2817 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2819 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2820 continue;
2823 if (m_SelectedFilters & LOGFILTER_PATHS)
2825 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2827 bool bGoing = true;
2828 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2830 CTGitPath cpath = pathList[cpPathIndex];
2831 CString path = cpath.GetGitOldPathString();
2832 path.MakeLower();
2833 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2835 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2836 bGoing = false;
2837 continue;
2839 path = cpath.GetGitPathString();
2840 path.MakeLower();
2841 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2843 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2844 bGoing = false;
2845 continue;
2847 path = cpath.GetActionName();
2848 path.MakeLower();
2849 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2851 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2852 bGoing = false;
2853 continue;
2857 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2859 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2860 msg = msg.MakeLower();
2861 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2863 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2864 continue;
2867 if (m_SelectedFilters & LOGFILTER_REVS)
2869 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2870 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2872 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2873 continue;
2876 } // else (from if (bRegex))
2877 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2881 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
2884 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2886 if(m_From == -1)
2887 if(m_To == -1)
2888 return true;
2889 else
2890 return time <= m_To;
2891 else
2892 if(m_To == -1)
2893 return time >= m_From;
2894 else
2895 return ((time >= m_From)&&(time <= m_To));
2897 return TRUE; /* git dll will filter time range */
2899 // return TRUE;
2901 void CGitLogListBase::StartFilter()
2903 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2904 RecalculateShownList(&m_arShownList);
2905 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2908 DeleteAllItems();
2909 SetItemCountEx(ShownCountWithStopped());
2910 RedrawItems(0, ShownCountWithStopped());
2911 Invalidate();
2914 void CGitLogListBase::RemoveFilter()
2917 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2919 m_arShownList.SafeRemoveAll();
2921 // reset the time filter too
2922 #if 0
2923 m_timFrom = (__time64_t(m_tFrom));
2924 m_timTo = (__time64_t(m_tTo));
2925 m_DateFrom.SetTime(&m_timFrom);
2926 m_DateTo.SetTime(&m_timTo);
2927 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2928 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2929 #endif
2931 for (DWORD i=0; i<m_logEntries.size(); ++i)
2933 if(this->m_IsOldFirst)
2935 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2937 else
2939 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2942 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2943 DeleteAllItems();
2944 SetItemCountEx(ShownCountWithStopped());
2945 RedrawItems(0, ShownCountWithStopped());
2947 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2950 void CGitLogListBase::Clear()
2952 m_arShownList.SafeRemoveAll();
2953 DeleteAllItems();
2955 m_logEntries.ClearAll();
2959 void CGitLogListBase::OnDestroy()
2961 // save the column widths to the registry
2962 SaveColumnWidths();
2964 SafeTerminateThread();
2965 SafeTerminateAsyncDiffThread();
2967 int retry = 0;
2968 while(m_LogCache.SaveCache())
2970 if(retry > 5)
2971 break;
2972 Sleep(1000);
2974 retry++;
2976 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2977 // MB_YESNO) == IDNO)
2978 // break;
2981 CHintListCtrl::OnDestroy();
2984 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
2986 UNREFERENCED_PARAMETER(lParam);
2987 CRect rect;
2988 int i=(int)wParam;
2989 this->GetItemRect(i,&rect,LVIR_BOUNDS);
2990 this->InvalidateRect(rect);
2992 return 0;
2996 * Save column widths to the registry
2998 void CGitLogListBase::SaveColumnWidths()
3000 int maxcol = m_ColumnManager.GetColumnCount();
3002 // HACK that graph column is always shown
3003 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3005 for (int col = 0; col < maxcol; col++)
3006 if (m_ColumnManager.IsVisible (col))
3007 m_ColumnManager.ColumnResized (col);
3009 m_ColumnManager.WriteSettings();
3012 int CGitLogListBase::GetHeadIndex()
3014 if(m_HeadHash.IsEmpty())
3015 return -1;
3017 for(int i=0;i<m_arShownList.GetCount();i++)
3019 GitRev *pRev = (GitRev*)m_arShownList[i];
3020 if(pRev)
3022 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3023 return i;
3026 return -1;
3028 void CGitLogListBase::OnFind()
3030 if (!m_pFindDialog)
3032 m_pFindDialog = new CFindDlg(this);
3033 m_pFindDialog->Create(this);
3036 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3038 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3040 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3042 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3043 Default();
3045 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3048 ASSERT(m_pFindDialog != NULL);
3049 bool bFound = false;
3050 int i=0;
3052 if (m_pFindDialog->IsTerminating())
3054 // invalidate the handle identifying the dialog box.
3055 m_pFindDialog = NULL;
3056 return 0;
3059 if(m_pFindDialog->IsRef())
3061 CString str;
3062 str=m_pFindDialog->GetFindString();
3064 CGitHash hash;
3066 if(!str.IsEmpty())
3067 hash = g_Git.GetHash(str);
3069 if(!hash.IsEmpty())
3071 for (i = 0; i<m_arShownList.GetCount(); i++)
3073 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3074 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3076 bFound = true;
3077 break;
3084 if(m_pFindDialog->FindNext())
3086 //read data from dialog
3087 CString FindText = m_pFindDialog->GetFindString();
3088 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3090 tr1::wregex pat;
3091 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3093 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3096 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3098 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3100 CString str;
3101 str+=pLogEntry->m_CommitHash.ToString();
3102 str+=_T("\n");
3104 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3106 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3107 str+=_T("\n");
3110 str+=pLogEntry->GetAuthorEmail();
3111 str+=_T("\n");
3112 str+=pLogEntry->GetAuthorName();
3113 str+=_T("\n");
3114 str+=pLogEntry->GetBody();
3115 str+=_T("\n");
3116 str+=pLogEntry->GetCommitterEmail();
3117 str+=_T("\n");
3118 str+=pLogEntry->GetCommitterName();
3119 str+=_T("\n");
3120 str+=pLogEntry->GetSubject();
3121 str+=_T("\n");
3124 /*Because changed files list is loaded on demand when gui show,
3125 files will empty when files have not fetched.
3127 we can add it back by using one-way diff(with outnumber changed and rename detect.
3128 here just need changed filename list. one-way is much quicker.
3130 if(pLogEntry->m_IsFull)
3132 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3134 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3135 str+=_T("\n");
3136 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3137 str+=_T("\n");
3140 else
3142 if(!pLogEntry->m_IsSimpleListReady)
3143 pLogEntry->SafeGetSimpleList(&g_Git);
3145 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3147 str+=pLogEntry->m_SimpleFileList[i];
3148 str+=_T("\n");
3154 if (bRegex)
3156 if (regex_search(wstring(str), pat, flags))
3158 bFound = true;
3159 break;
3162 else
3164 if (bMatchCase)
3166 if (str.Find(FindText) >= 0)
3168 bFound = true;
3169 break;
3173 else
3175 CString msg = str;
3176 msg = msg.MakeLower();
3177 CString find = FindText.MakeLower();
3178 if (msg.Find(find) >= 0)
3180 bFound = TRUE;
3181 break;
3185 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3187 } // if(m_pFindDialog->FindNext())
3188 //UpdateLogInfoLabel();
3190 if (bFound)
3192 this->m_nSearchIndex = i;
3193 EnsureVisible(i, FALSE);
3194 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3195 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3196 SetSelectionMark(i);
3197 //FillLogMessageCtrl();
3198 UpdateData(FALSE);
3199 m_nSearchIndex++;
3200 if (m_nSearchIndex >= m_arShownList.GetCount())
3201 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3204 return 0;
3207 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3209 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3211 *pResult = FALSE;
3214 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3216 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3218 Invalidate(FALSE);