Fixed issue #1557: Submodule Diff Dialog should launch diff with working copy if...
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
bloba477bbc0a5b3800f2df8c0cb3d02396b1230832b
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);
64 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
66 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
68 CGitLogListBase::CGitLogListBase():CHintListCtrl()
69 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
70 ,m_nSearchIndex(0)
71 ,m_bNoDispUpdates(FALSE)
72 , m_bThreadRunning(FALSE)
73 , m_bStrictStopped(false)
74 , m_pStoreSelection(NULL)
75 , m_SelectedFilters(LOGFILTER_ALL)
76 , m_bShowWC(false)
77 , m_logEntries(&m_LogCache)
78 , m_pFindDialog(NULL)
79 , m_ColumnManager(this)
80 , m_dwDefaultColumns(0)
81 , m_arShownList(&m_critSec)
82 , m_hasWC(true)
83 , m_bNoHightlightHead(FALSE)
85 // use the default GUI font, create a copy of it and
86 // change the copy to BOLD (leave the rest of the font
87 // the same)
88 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
89 LOGFONT lf = {0};
90 GetObject(hFont, sizeof(LOGFONT), &lf);
91 lf.lfWeight = FW_BOLD;
92 m_boldFont = CreateFontIndirect(&lf);
94 m_bShowBugtraqColumn=false;
96 m_IsIDReplaceAction=FALSE;
98 this->m_critSec.Init();
99 m_wcRev.m_CommitHash.Empty();
100 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
101 m_wcRev.m_ParentHash.clear();
102 m_wcRev.m_Mark=_T('-');
103 m_wcRev.m_IsUpdateing=FALSE;
104 m_wcRev.m_IsFull = TRUE;
106 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
112 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
114 g_Git.GetMapHashToFriendName(m_HashMap);
115 if (CTGitPath(g_Git.m_CurrentDir).HasAdminDir())
117 m_CurrentBranch=g_Git.GetCurrentBranch();
118 try {
119 m_HeadHash=g_Git.GetHash(_T("HEAD"));
121 catch (char* msg)
123 CString err(msg);
124 MessageBox(_T("Could not get HEAD hash. Quitting...\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
125 ExitProcess(1);
129 m_From = -1;
130 m_To = -1;
132 m_ShowMask = 0;
133 m_LoadingThread = NULL;
135 InterlockedExchange(&m_bExitThread,FALSE);
136 m_IsOldFirst = FALSE;
137 m_IsRebaseReplaceGraph = FALSE;
140 for(int i=0;i<Lanes::COLORS_NUM;i++)
142 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
144 // get short/long datetime setting from registry
145 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
146 if ( RegUseShortDateFormat )
148 m_DateFormat = DATE_SHORTDATE;
150 else
152 m_DateFormat = DATE_LONGDATE;
154 // get relative time display setting from registry
155 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
156 m_bRelativeTimes = (regRelativeTimes != 0);
157 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
159 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
160 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
161 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
162 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
163 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
164 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
166 m_ColumnRegKey=_T("log");
168 m_AsyncThreadExit = FALSE;
169 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
170 m_AsynDiffListLock.Init();
172 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
173 if (m_DiffingThread ==NULL)
175 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
176 return;
181 int CGitLogListBase::AsyncDiffThread()
183 m_AsyncThreadExited = false;
184 while(!m_AsyncThreadExit)
186 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
188 GitRev *pRev = NULL;
189 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
191 m_AsynDiffListLock.Lock();
192 pRev = m_AsynDiffList.back();
193 m_AsynDiffList.pop_back();
194 m_AsynDiffListLock.Unlock();
196 if( pRev->m_CommitHash.IsEmpty() )
198 if(pRev->m_IsDiffFiles)
199 continue;
201 pRev->GetFiles(this).Clear();
202 pRev->m_ParentHash.clear();
203 pRev->m_ParentHash.push_back(m_HeadHash);
204 if(g_Git.IsInitRepos())
206 g_Git.GetInitAddList(pRev->GetFiles(this));
209 else
211 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
213 pRev->GetAction(this) = 0;
215 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
216 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
218 pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER);
220 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
221 InterlockedExchange(&pRev->m_IsFull, TRUE);
223 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
224 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
225 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
228 if(!pRev->CheckAndDiff())
229 { // fetch change file list
230 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
232 if(i < m_arShownList.GetCount())
234 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
235 if(data->m_CommitHash == pRev->m_CommitHash)
237 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
238 break;
243 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
245 POSITION pos = GetFirstSelectedItemPosition();
246 int nItem = GetNextSelectedItem(pos);
248 if(nItem>=0)
250 GitRev* data = (GitRev*)m_arShownList[nItem];
251 if(data)
252 if(data->m_CommitHash == pRev->m_CommitHash)
254 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
261 m_AsyncThreadExited = true;
262 return 0;
264 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
266 if (exclusivelyShow)
268 m_ContextMenuMask &= hideMask;
270 else
272 m_ContextMenuMask &= ~hideMask;
276 CGitLogListBase::~CGitLogListBase()
278 InterlockedExchange(&m_bNoDispUpdates, TRUE);
279 this->m_arShownList.SafeRemoveAll();
281 DestroyIcon(m_hModifiedIcon);
282 DestroyIcon(m_hReplacedIcon);
283 DestroyIcon(m_hAddedIcon);
284 DestroyIcon(m_hDeletedIcon);
285 m_logEntries.ClearAll();
287 if (m_boldFont)
288 DeleteObject(m_boldFont);
290 if ( m_pStoreSelection )
292 delete m_pStoreSelection;
293 m_pStoreSelection = NULL;
296 SafeTerminateThread();
297 SafeTerminateAsyncDiffThread();
299 if(m_AsyncDiffEvent)
300 CloseHandle(m_AsyncDiffEvent);
304 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
305 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
306 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
307 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
308 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
309 ON_WM_CONTEXTMENU()
310 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
311 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
312 ON_WM_CREATE()
313 ON_WM_DESTROY()
314 ON_MESSAGE(MSG_LOADED,OnLoad)
315 ON_WM_MEASUREITEM()
316 ON_WM_MEASUREITEM_REFLECT()
317 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
318 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
319 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
320 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
321 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
322 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
323 END_MESSAGE_MAP()
325 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
327 //if (m_nRowHeight>0)
329 lpMeasureItemStruct->itemHeight = 50;
333 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
335 PreSubclassWindow();
336 return CHintListCtrl::OnCreate(lpCreateStruct);
339 void CGitLogListBase::PreSubclassWindow()
341 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
342 // load the icons for the action columns
343 // m_Theme.Open(m_hWnd, L"ListView");
344 SetWindowTheme(m_hWnd, L"Explorer", NULL);
345 CHintListCtrl::PreSubclassWindow();
348 void CGitLogListBase::InsertGitColumn()
350 CString temp;
352 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
353 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
354 if (DWORD(regFullRowSelect))
355 exStyle |= LVS_EX_FULLROWSELECT;
356 SetExtendedStyle(exStyle);
358 UpdateProjectProperties();
360 static UINT normal[] =
362 IDS_LOG_GRAPH,
363 IDS_LOG_REBASE,
364 IDS_LOG_ID,
365 IDS_LOG_HASH,
366 IDS_LOG_ACTIONS,
367 IDS_LOG_MESSAGE,
368 IDS_LOG_AUTHOR,
369 IDS_LOG_DATE,
370 IDS_LOG_EMAIL,
371 IDS_LOG_COMMIT_NAME,
372 IDS_LOG_COMMIT_EMAIL,
373 IDS_LOG_COMMIT_DATE,
374 IDS_LOG_BUGIDS,
377 static int with[] =
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
381 ICONITEMBORDER+16*4,
382 ICONITEMBORDER+16*4,
383 ICONITEMBORDER+16*4,
384 LOGLIST_MESSAGE_MIN,
385 ICONITEMBORDER+16*4,
386 ICONITEMBORDER+16*4,
387 ICONITEMBORDER+16*4,
388 ICONITEMBORDER+16*4,
389 ICONITEMBORDER+16*4,
390 ICONITEMBORDER+16*4,
391 ICONITEMBORDER+16*4,
393 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
395 DWORD hideColumns = 0;
396 if(this->m_IsRebaseReplaceGraph)
398 hideColumns |= GIT_LOG_GRAPH;
399 m_dwDefaultColumns |= GIT_LOG_REBASE;
401 else
403 hideColumns |= GIT_LOG_REBASE;
406 if(this->m_IsIDReplaceAction)
408 hideColumns |= GIT_LOG_ACTIONS;
409 m_dwDefaultColumns |= GIT_LOG_ID;
410 m_dwDefaultColumns |= GIT_LOG_HASH;
412 else
414 hideColumns |= GIT_LOG_ID;
416 if(this->m_bShowBugtraqColumn)
418 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
420 else
422 hideColumns |= GIT_LOGLIST_BUG;
424 SetRedraw(false);
426 m_ColumnManager.SetNames(normal, _countof(normal));
427 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
429 SetRedraw(true);
434 * Resizes all columns in a list control to values in registry.
436 void CGitLogListBase::ResizeAllListCtrlCols()
438 // column max and min widths to allow
439 static const int nMinimumWidth = 10;
440 static const int nMaximumWidth = 1000;
441 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
442 if (pHdrCtrl)
444 int numcols = pHdrCtrl->GetItemCount();
445 for (int col = 0; col < numcols; col++)
447 // get width for this col last time from registry
448 CString regentry;
449 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
450 CRegDWORD regwidth(regentry, 0);
451 int cx = regwidth;
452 if ( cx == 0 )
454 // no saved value, setup sensible defaults
455 if (col == this->LOGLIST_MESSAGE)
457 cx = LOGLIST_MESSAGE_MIN;
459 else
461 cx = ICONITEMBORDER+16*4;
464 if (cx < nMinimumWidth)
466 cx = nMinimumWidth;
468 else if (cx > nMaximumWidth)
470 cx = nMaximumWidth;
473 SetColumnWidth(col, cx);
480 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
482 //TRACE(_T("%s %s\r\n"),ref,prefix);
483 if(ref.Left(prefix.GetLength()) == prefix)
485 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
486 if(shortname.Right(3)==_T("^{}"))
487 shortname=shortname.Left(shortname.GetLength()-3);
488 return TRUE;
490 return FALSE;
493 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
495 LVITEM rItem;
496 SecureZeroMemory(&rItem, sizeof(LVITEM));
497 rItem.mask = LVIF_STATE;
498 rItem.iItem = (int)Index;
499 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
500 GetItem(&rItem);
502 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
503 HBRUSH brush = NULL;
505 if (!(rItem.state & LVIS_SELECTED))
507 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
508 brush = ::CreateSolidBrush(RGB(156,156,156));
509 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
510 brush = ::CreateSolidBrush(RGB(200,200,128));
512 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
514 if (rItem.state & LVIS_SELECTED)
516 if (::GetFocus() == m_hWnd)
517 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
518 else
519 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
523 if (brush != NULL)
525 ::FillRect(hdc, &rect, brush);
526 ::DeleteObject(brush);
530 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
532 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
533 CRect rt=rect;
534 LVITEM rItem;
535 SecureZeroMemory(&rItem, sizeof(LVITEM));
536 rItem.mask = LVIF_STATE;
537 rItem.iItem = (int)index;
538 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
539 GetItem(&rItem);
541 CDC W_Dc;
542 W_Dc.Attach(hdc);
544 HTHEME hTheme = NULL;
545 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
546 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
548 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
550 CString str;
551 str=m_HashMap[data->m_CommitHash][i];
553 CString shortname;
554 HBRUSH brush = 0;
555 shortname = _T("");
556 COLORREF colRef = 0;
558 //Determine label color
559 if(GetShortName(str,shortname,_T("refs/heads/")))
561 if( shortname == m_CurrentBranch )
562 colRef = m_Colors.GetColor(CColors::CurrentBranch);
563 else
564 colRef = m_Colors.GetColor(CColors::LocalBranch);
567 else if(GetShortName(str,shortname,_T("refs/remotes/")))
569 colRef = m_Colors.GetColor(CColors::RemoteBranch);
571 else if(GetShortName(str,shortname,_T("refs/tags/")))
573 colRef = m_Colors.GetColor(CColors::Tag);
575 else if(GetShortName(str,shortname,_T("refs/stash")))
577 colRef = m_Colors.GetColor(CColors::Stash);
578 shortname=_T("stash");
580 else if(GetShortName(str,shortname,_T("refs/bisect/")))
582 if(shortname.Find(_T("good")) == 0)
584 colRef = m_Colors.GetColor(CColors::BisectGood);
585 shortname = _T("good");
588 if(shortname.Find(_T("bad")) == 0)
590 colRef = m_Colors.GetColor(CColors::BisectBad);
591 shortname = _T("bad");
595 //When row selected, ajust label color
596 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
597 if (rItem.state & LVIS_SELECTED)
598 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
600 brush = ::CreateSolidBrush(colRef);
602 if(!shortname.IsEmpty() && (rt.left<rect.right) )
604 SIZE size;
605 memset(&size,0,sizeof(SIZE));
606 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
608 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
609 rt.right+=8;
611 int textpos = DT_CENTER;
613 if(rt.right > rect.right)
615 rt.right = rect.right;
616 textpos =0;
619 //Fill interior of ref label
620 ::FillRect(hdc, &rt, brush);
622 //Draw edge of label
624 CRect rectEdge = rt;
626 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
627 rectEdge.DeflateRect(1,1);
628 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
630 //Draw text inside label
631 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
633 int txtState = LISS_NORMAL;
634 if (rItem.state & LVIS_SELECTED)
635 txtState = LISS_SELECTED;
637 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
639 else
641 W_Dc.SetBkMode(TRANSPARENT);
642 if (rItem.state & LVIS_SELECTED)
644 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
645 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
646 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
647 ::SetTextColor(hdc,clrOld);
649 else
651 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
655 //::MoveToEx(hdc,rt.left,rt.top,NULL);
656 //::LineTo(hdc,rt.right,rt.top);
657 //::LineTo(hdc,rt.right,rt.bottom);
658 //::LineTo(hdc,rt.left,rt.bottom);
659 //::LineTo(hdc,rt.left,rt.top);
661 rt.left=rt.right+1;
663 if(brush)
664 ::DeleteObject(brush);
666 rt.right=rect.right;
668 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
670 int txtState = LISS_NORMAL;
671 if (rItem.state & LVIS_SELECTED)
672 txtState = LISS_SELECTED;
674 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
676 else
678 if (rItem.state & LVIS_SELECTED)
680 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
681 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
682 ::SetTextColor(hdc,clrOld);
684 else
686 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
690 if (hTheme)
691 CloseThemeData(hTheme);
693 W_Dc.Detach();
696 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
698 // Returns ((256 - amount)*col1 + amount*col2) / 256;
699 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
700 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
701 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
704 Gdiplus::Color GetGdiColor(COLORREF col)
706 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
708 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
709 const COLORREF& col,const COLORREF& activeColor, int top
712 int h = laneHeight / 2;
713 int m = (x1 + x2) / 2;
714 int r = (x2 - x1) / 3;
715 int d = 2 * r;
717 #define P_CENTER m , h+top
718 #define P_0 x2, h+top
719 #define P_90 m , 0+top-1
720 #define P_180 x1, h+top
721 #define P_270 m , 2 * h+top +1
722 #define R_CENTER m - r, h - r+top, d, d
725 #define DELTA_UR_B 2*(x1 - m), 2*h +top
726 #define DELTA_UR_E 0*16, 90*16 +top // -,
728 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
729 #define DELTA_DR_E 270*16, 90*16 +top // -'
731 #define DELTA_UL_B 2*(x2 - m), 2*h +top
732 #define DELTA_UL_E 90*16, 90*16 +top // ,-
734 #define DELTA_DL_B 2*(x2 - m),2*-h +top
735 #define DELTA_DL_E 180*16, 90*16 // '-
737 #define CENTER_UR x1, 2*h, 225
738 #define CENTER_DR x1, 0 , 135
739 #define CENTER_UL x2, 2*h, 315
740 #define CENTER_DL x2, 0 , 45
743 Gdiplus::Graphics graphics( hdc );
745 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
747 // arc
748 switch (type) {
749 case Lanes::JOIN:
750 case Lanes::JOIN_R:
751 case Lanes::HEAD:
752 case Lanes::HEAD_R:
754 Gdiplus::LinearGradientBrush gradient(
755 Gdiplus::Point(x1-2, h+top-2),
756 Gdiplus::Point(P_270),
757 GetGdiColor(activeColor),GetGdiColor(col));
760 Gdiplus::Pen mypen(&gradient,2);
761 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
763 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
764 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
765 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
767 break;
769 case Lanes::JOIN_L:
772 Gdiplus::LinearGradientBrush gradient(
773 Gdiplus::Point(P_270),
774 Gdiplus::Point(x2+1, h+top-1),
775 GetGdiColor(col),GetGdiColor(activeColor));
778 Gdiplus::Pen mypen(&gradient,2);
779 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
781 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
782 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
783 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
786 break;
788 case Lanes::TAIL:
789 case Lanes::TAIL_R:
792 Gdiplus::LinearGradientBrush gradient(
793 Gdiplus::Point(x1-2, h+top-2),
794 Gdiplus::Point(P_90),
795 GetGdiColor(activeColor),GetGdiColor(col));
797 Gdiplus::Pen mypen(&gradient,2);
799 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
801 #if 0
802 QConicalGradient gradient(CENTER_DR);
803 gradient.setColorAt(0.375, activeCol);
804 gradient.setColorAt(0.625, col);
805 myPen.setBrush(gradient);
806 p->setPen(myPen);
807 p->drawArc(P_CENTER, DELTA_DR);
808 #endif
809 break;
811 default:
812 break;
816 //static QPen myPen(Qt::black, 2); // fast path here
817 CPen pen;
818 pen.CreatePen(PS_SOLID,2,col);
819 //myPen.setColor(col);
820 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
822 Gdiplus::Pen myPen(GetGdiColor(col),2);
824 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
826 //p->setPen(myPen);
828 // vertical line
829 switch (type) {
830 case Lanes::ACTIVE:
831 case Lanes::NOT_ACTIVE:
832 case Lanes::MERGE_FORK:
833 case Lanes::MERGE_FORK_R:
834 case Lanes::MERGE_FORK_L:
835 case Lanes::JOIN:
836 case Lanes::JOIN_R:
837 case Lanes::JOIN_L:
838 case Lanes::CROSS:
839 //DrawLine(hdc,P_90,P_270);
840 graphics.DrawLine(&myPen,P_90,P_270);
841 //p->drawLine(P_90, P_270);
842 break;
843 case Lanes::HEAD_L:
844 case Lanes::BRANCH:
845 //DrawLine(hdc,P_CENTER,P_270);
846 graphics.DrawLine(&myPen,P_CENTER,P_270);
847 //p->drawLine(P_CENTER, P_270);
848 break;
849 case Lanes::TAIL_L:
850 case Lanes::INITIAL:
851 case Lanes::BOUNDARY:
852 case Lanes::BOUNDARY_C:
853 case Lanes::BOUNDARY_R:
854 case Lanes::BOUNDARY_L:
855 //DrawLine(hdc,P_90, P_CENTER);
856 graphics.DrawLine(&myPen,P_90,P_CENTER);
857 //p->drawLine(P_90, P_CENTER);
858 break;
859 default:
860 break;
863 myPen.SetColor(GetGdiColor(activeColor));
865 // horizontal line
866 switch (type) {
867 case Lanes::MERGE_FORK:
868 case Lanes::JOIN:
869 case Lanes::HEAD:
870 case Lanes::TAIL:
871 case Lanes::CROSS:
872 case Lanes::CROSS_EMPTY:
873 case Lanes::BOUNDARY_C:
874 //DrawLine(hdc,P_180,P_0);
875 graphics.DrawLine(&myPen,P_180,P_0);
876 //p->drawLine(P_180, P_0);
877 break;
878 case Lanes::MERGE_FORK_R:
879 case Lanes::BOUNDARY_R:
880 //DrawLine(hdc,P_180,P_CENTER);
881 graphics.DrawLine(&myPen,P_180,P_CENTER);
882 //p->drawLine(P_180, P_CENTER);
883 break;
884 case Lanes::MERGE_FORK_L:
885 case Lanes::HEAD_L:
886 case Lanes::TAIL_L:
887 case Lanes::BOUNDARY_L:
888 //DrawLine(hdc,P_CENTER,P_0);
889 graphics.DrawLine(&myPen,P_CENTER,P_0);
890 //p->drawLine(P_CENTER, P_0);
891 break;
892 default:
893 break;
896 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
898 CBrush brush;
899 brush.CreateSolidBrush(col);
900 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
902 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
903 // center symbol, e.g. rect or ellipse
904 switch (type) {
905 case Lanes::ACTIVE:
906 case Lanes::INITIAL:
907 case Lanes::BRANCH:
909 //p->setPen(Qt::NoPen);
910 //p->setBrush(col);
911 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
912 graphics.FillEllipse(&myBrush, R_CENTER);
913 //p->drawEllipse(R_CENTER);
914 break;
915 case Lanes::MERGE_FORK:
916 case Lanes::MERGE_FORK_R:
917 case Lanes::MERGE_FORK_L:
918 //p->setPen(Qt::NoPen);
919 //p->setBrush(col);
920 //p->drawRect(R_CENTER);
921 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
922 graphics.FillRectangle(&myBrush, R_CENTER);
923 break;
924 case Lanes::UNAPPLIED:
925 // Red minus sign
926 //p->setPen(Qt::NoPen);
927 //p->setBrush(Qt::red);
928 //p->drawRect(m - r, h - 1, d, 2);
929 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
930 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
931 break;
932 case Lanes::APPLIED:
933 // Green plus sign
934 //p->setPen(Qt::NoPen);
935 //p->setBrush(DARK_GREEN);
936 //p->drawRect(m - r, h - 1, d, 2);
937 //p->drawRect(m - 1, h - r, 2, d);
938 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
939 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
940 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
941 break;
942 case Lanes::BOUNDARY:
943 //p->setBrush(back);
944 //p->drawEllipse(R_CENTER);
945 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
946 graphics.DrawEllipse(&myPen, R_CENTER);
947 break;
948 case Lanes::BOUNDARY_C:
949 case Lanes::BOUNDARY_R:
950 case Lanes::BOUNDARY_L:
951 //p->setBrush(back);
952 //p->drawRect(R_CENTER);
953 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
954 graphics.FillRectangle(&myBrush,R_CENTER);
955 break;
956 default:
957 break;
960 ::SelectObject(hdc,oldpen);
961 ::SelectObject(hdc,oldbrush);
962 #undef P_CENTER
963 #undef P_0
964 #undef P_90
965 #undef P_180
966 #undef P_270
967 #undef R_CENTER
970 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
972 // TODO: unfinished
973 // return;
974 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
975 if(data->m_CommitHash.IsEmpty())
976 return;
978 CRect rt=rect;
979 LVITEM rItem;
980 SecureZeroMemory(&rItem, sizeof(LVITEM));
981 rItem.mask = LVIF_STATE;
982 rItem.iItem = (int)index;
983 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
984 GetItem(&rItem);
986 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
988 if (data->m_Lanes.empty())
989 m_logEntries.setLane(data->m_CommitHash);
991 std::vector<int>& lanes=data->m_Lanes;
992 size_t laneNum = lanes.size();
993 UINT activeLane = 0;
994 for (UINT i = 0; i < laneNum; i++)
995 if (Lanes::isMerge(lanes[i])) {
996 activeLane = i;
997 break;
1000 int x1 = 0, x2 = 0;
1001 int maxWidth = rect.Width();
1002 int lw = 3 * rect.Height() / 4; //laneWidth()
1004 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1005 //if (opt.state & QStyle::State_Selected)
1006 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1008 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1011 x1 = x2;
1012 x2 += lw;
1014 int ln = lanes[i];
1015 if (ln == Lanes::EMPTY)
1016 continue;
1018 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1019 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1022 #if 0
1023 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1025 x1 = x2;
1026 x2 += lw;
1028 int ln = lanes[i];
1029 if (ln == Lanes::EMPTY)
1030 continue;
1032 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1033 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1035 if (ln == Lanes::CROSS)
1037 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1038 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1040 else
1041 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1043 #endif
1047 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1050 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1051 // Take the default processing unless we set this to something else below.
1052 *pResult = CDRF_DODEFAULT;
1054 if (m_bNoDispUpdates)
1055 return;
1057 switch (pLVCD->nmcd.dwDrawStage)
1059 case CDDS_PREPAINT:
1061 *pResult = CDRF_NOTIFYITEMDRAW;
1062 return;
1064 break;
1065 case CDDS_ITEMPREPAINT:
1067 // This is the prepaint stage for an item. Here's where we set the
1068 // item's text color.
1070 // Tell Windows to send draw notifications for each subitem.
1071 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1073 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1075 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1077 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1078 if (data)
1080 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1081 crText = RGB(128,128,128);
1083 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1084 pLVCD->clrTextBk = RGB(156,156,156);
1085 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1086 pLVCD->clrTextBk = RGB(200,200,128);
1087 else
1088 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1090 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1092 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1093 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1096 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1098 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1099 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1102 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1103 // crText = GetSysColor(COLOR_GRAYTEXT);
1105 if (data->m_CommitHash.IsEmpty())
1107 //crText = GetSysColor(RGB(200,200,0));
1108 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1109 // We changed the font, so we're returning CDRF_NEWFONT. This
1110 // tells the control to recalculate the extent of the text.
1111 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1115 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1117 if (m_bStrictStopped)
1118 crText = GetSysColor(COLOR_GRAYTEXT);
1120 // Store the color back in the NMLVCUSTOMDRAW struct.
1121 pLVCD->clrText = crText;
1122 return;
1124 break;
1125 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1127 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1129 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1132 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1134 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1136 CRect rect;
1137 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1139 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1140 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1142 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1143 if( !data ->m_CommitHash.IsEmpty())
1144 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1146 *pResult = CDRF_SKIPDEFAULT;
1147 return;
1151 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1153 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1155 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1156 //if(!data->m_IsFull)
1158 //if(data->SafeFetchFullInfo(&g_Git))
1159 // this->Invalidate();
1160 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1163 if (!m_HashMap[data->m_CommitHash].empty())
1165 CRect rect;
1167 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1169 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1170 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1172 *pResult = CDRF_SKIPDEFAULT;
1173 return;
1180 if (pLVCD->iSubItem == LOGLIST_ACTION)
1182 if(this->m_IsIDReplaceAction)
1184 *pResult = CDRF_DODEFAULT;
1185 return;
1187 *pResult = CDRF_DODEFAULT;
1189 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1190 return;
1192 int nIcons = 0;
1193 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1194 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1196 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1197 CRect rect;
1198 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1199 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1200 // Get the selected state of the
1201 // item being drawn.
1203 // Fill the background if necessary
1204 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1206 // Draw the icon(s) into the compatible DC
1207 pLogEntry->GetAction(this);
1209 if (!pLogEntry->m_IsDiffFiles)
1210 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1212 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1213 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1214 nIcons++;
1216 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1217 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1218 nIcons++;
1220 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1221 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1222 nIcons++;
1224 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1225 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1226 nIcons++;
1227 *pResult = CDRF_SKIPDEFAULT;
1228 return;
1231 break;
1233 *pResult = CDRF_DODEFAULT;
1236 // CGitLogListBase message handlers
1238 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1240 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1242 // Create a pointer to the item
1243 LV_ITEM* pItem = &(pDispInfo)->item;
1245 // Do the list need text information?
1246 if (!(pItem->mask & LVIF_TEXT))
1247 return;
1249 // By default, clear text buffer.
1250 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1252 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1254 *pResult = 0;
1255 if (m_bNoDispUpdates || bOutOfRange)
1256 return;
1258 // Which item number?
1259 int itemid = pItem->iItem;
1260 GitRev * pLogEntry = NULL;
1261 if (itemid < m_arShownList.GetCount())
1262 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1264 CString temp;
1265 if(m_IsOldFirst)
1267 temp.Format(_T("%d"),pItem->iItem+1);
1270 else
1272 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1275 // Which column?
1276 switch (pItem->iSubItem)
1278 case this->LOGLIST_GRAPH: //Graphic
1279 break;
1280 case this->LOGLIST_REBASE:
1282 if(this->m_IsRebaseReplaceGraph)
1284 CTGitPath path;
1285 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1286 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1289 break;
1290 case this->LOGLIST_ACTION: //action -- no text in the column
1291 break;
1292 case this->LOGLIST_HASH:
1293 if(pLogEntry)
1294 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1295 break;
1296 case this->LOGLIST_ID:
1297 if(this->m_IsIDReplaceAction)
1298 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1299 break;
1300 case this->LOGLIST_MESSAGE: //Message
1301 if (pLogEntry)
1302 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1303 break;
1304 case this->LOGLIST_AUTHOR: //Author
1305 if (pLogEntry)
1306 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1307 break;
1308 case this->LOGLIST_DATE: //Date
1309 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1310 lstrcpyn(pItem->pszText,
1311 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1312 pItem->cchTextMax);
1313 break;
1315 case this->LOGLIST_EMAIL:
1316 if (pLogEntry)
1317 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1318 break;
1320 case this->LOGLIST_COMMIT_NAME: //Commit
1321 if (pLogEntry)
1322 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1323 break;
1325 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1326 if (pLogEntry)
1327 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1328 break;
1330 case this->LOGLIST_COMMIT_DATE: //Commit Date
1331 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1332 lstrcpyn(pItem->pszText,
1333 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1334 pItem->cchTextMax);
1335 break;
1336 case this->LOGLIST_BUG: //Bug ID
1337 if(pLogEntry)
1338 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1339 break;
1341 default:
1342 ASSERT(false);
1346 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1349 if (pWnd == GetHeaderCtrl())
1351 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1354 int selIndex = GetSelectionMark();
1355 if (selIndex < 0)
1356 return; // nothing selected, nothing to do with a context menu
1358 // if the user selected the info text telling about not all revisions shown due to
1359 // the "stop on copy/rename" option, we also don't show the context menu
1360 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1361 return;
1363 // if the context menu is invoked through the keyboard, we have to use
1364 // a calculated position on where to anchor the menu on
1365 if ((point.x == -1) && (point.y == -1))
1367 CRect rect;
1368 GetItemRect(selIndex, &rect, LVIR_LABEL);
1369 ClientToScreen(&rect);
1370 point = rect.CenterPoint();
1372 m_nSearchIndex = selIndex;
1373 m_bCancelled = FALSE;
1375 // calculate some information the context menu commands can use
1376 // CString pathURL = GetURLFromPath(m_path);
1378 POSITION pos = GetFirstSelectedItemPosition();
1379 int indexNext = GetNextSelectedItem(pos);
1380 if (indexNext < 0)
1381 return;
1383 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1384 #if 0
1385 GitRev revSelected = pSelLogEntry->Rev;
1386 GitRev revPrevious = git_revnum_t(revSelected)-1;
1387 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1389 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1391 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1392 if (changedpath->lCopyFromRev)
1393 revPrevious = changedpath->lCopyFromRev;
1396 GitRev revSelected2;
1397 if (pos)
1399 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1400 revSelected2 = pLogEntry->Rev;
1402 bool bAllFromTheSameAuthor = true;
1403 CString firstAuthor;
1404 CLogDataVector selEntries;
1405 GitRev revLowest, revHighest;
1406 GitRevRangeArray revisionRanges;
1408 POSITION pos = GetFirstSelectedItemPosition();
1409 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1410 revisionRanges.AddRevision(pLogEntry->Rev);
1411 selEntries.push_back(pLogEntry);
1412 firstAuthor = pLogEntry->sAuthor;
1413 revLowest = pLogEntry->Rev;
1414 revHighest = pLogEntry->Rev;
1415 while (pos)
1417 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1418 revisionRanges.AddRevision(pLogEntry->Rev);
1419 selEntries.push_back(pLogEntry);
1420 if (firstAuthor.Compare(pLogEntry->sAuthor))
1421 bAllFromTheSameAuthor = false;
1422 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1423 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1427 #endif
1429 int FirstSelect=-1, LastSelect=-1;
1430 pos = GetFirstSelectedItemPosition();
1431 FirstSelect = GetNextSelectedItem(pos);
1432 while(pos)
1434 LastSelect = GetNextSelectedItem(pos);
1436 //entry is selected, now show the popup menu
1437 CIconMenu popup;
1438 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1440 if (popup.CreatePopupMenu())
1442 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1443 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1445 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1446 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1448 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1449 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1451 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1452 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1454 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1455 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1457 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1458 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1459 popup.AppendMenu(MF_SEPARATOR, NULL);
1461 if (GetSelectedCount() == 1)
1465 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1467 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1468 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1470 else
1472 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1473 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1475 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1477 GitRev *pRev=pSelLogEntry;
1478 if (pSelLogEntry->m_ParentHash.empty())
1480 pRev->GetParentFromHash(pRev->m_CommitHash);
1482 if(pRev->m_ParentHash.size()<=1)
1484 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1487 else
1489 gnudiffmenu.CreatePopupMenu();
1490 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1492 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1493 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1495 for(int i=0;i<pRev->m_ParentHash.size();i++)
1497 CString str;
1498 str.Format(IDS_PARENT, i + 1);
1499 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1504 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1507 GitRev *pRev=pSelLogEntry;
1508 if (pSelLogEntry->m_ParentHash.empty())
1510 pRev->GetParentFromHash(pRev->m_CommitHash);
1512 if(pRev->m_ParentHash.size()<=1)
1514 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1515 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1516 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1518 else
1520 diffmenu.CreatePopupMenu();
1521 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1522 for(int i=0;i<pRev->m_ParentHash.size();i++)
1524 CString str;
1525 str.Format(IDS_PARENT, i + 1);
1526 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1527 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1529 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1530 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1536 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1537 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1539 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1540 popup.AppendMenu(MF_SEPARATOR, NULL);
1542 if (pSelLogEntry->m_CommitHash.IsEmpty())
1544 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1545 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1548 bool isStash = false;
1549 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1551 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1553 isStash = true;
1554 break;
1558 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1560 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1561 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1563 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1564 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1566 popup.AppendMenu(MF_SEPARATOR, NULL);
1569 if (pSelLogEntry->m_CommitHash.IsEmpty())
1571 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1572 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1574 popup.AppendMenu(MF_SEPARATOR, NULL);
1578 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1579 // {
1580 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1581 // }
1582 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1583 // {
1584 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1585 // }
1586 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1587 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1588 // {
1589 // popup.AppendMenu(MF_SEPARATOR, NULL);
1590 // }
1592 CString str,format;
1593 //if (m_hasWC)
1594 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1596 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1598 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1599 GetSelectedCount() == 1)
1600 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1602 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1603 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1605 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1606 str.Format(format,g_Git.GetCurrentBranch());
1608 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1609 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1611 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1612 str.Format(format,g_Git.GetCurrentBranch());
1614 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1615 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1618 // Add Switch Branch express Menu
1619 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1620 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1623 std::vector<CString *> branchs;
1624 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1626 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1627 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1629 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1633 CString str;
1634 str.LoadString(IDS_SWITCH_BRANCH);
1636 if(branchs.size() == 1)
1638 str+=_T(" ");
1639 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1640 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1642 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1645 else if(branchs.size() > 1)
1647 subbranchmenu.CreatePopupMenu();
1648 for(int i=0;i<branchs.size();i++)
1650 if (*branchs[i] != currentBranch)
1652 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1653 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1657 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1661 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1662 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1664 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1665 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1667 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1668 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1670 format.LoadString(IDS_REBASE_THIS_FORMAT);
1671 str.Format(format,g_Git.GetCurrentBranch());
1673 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1674 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1675 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1677 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1678 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1680 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1682 GitRev *pRev = pSelLogEntry;
1683 if (pSelLogEntry->m_ParentHash.empty())
1685 pRev->GetParentFromHash(pRev->m_CommitHash);
1687 if (pRev->m_ParentHash.size() == 1)
1689 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1691 else
1693 revertmenu.CreatePopupMenu();
1694 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1696 for (int i = 0; i < pRev->m_ParentHash.size(); i++)
1698 CString str;
1699 str.Format(IDS_PARENT, i + 1);
1700 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1705 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1706 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1708 popup.AppendMenu(MF_SEPARATOR, NULL);
1713 if(!pSelLogEntry->m_Ref.IsEmpty())
1715 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1716 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1717 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1718 popup.AppendMenu(MF_SEPARATOR, NULL);
1721 if (GetSelectedCount() >= 2)
1723 bool bAddSeparator = false;
1724 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1726 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1727 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1730 if (GetSelectedCount() == 2)
1732 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1733 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1734 bAddSeparator = true;
1737 if (m_hasWC)
1739 bAddSeparator = true;
1742 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1743 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1745 if (bAddSeparator)
1746 popup.AppendMenu(MF_SEPARATOR, NULL);
1749 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1751 bool bAddSeparator = false;
1752 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1754 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1756 CString head;
1757 int headindex;
1758 headindex = this->GetHeadIndex();
1759 if(headindex>=0)
1761 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1762 CGitHash hash=g_Git.GetHash(head);
1763 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1764 if(pLastEntry->m_CommitHash == hash) {
1765 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1766 bAddSeparator = true;
1771 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1772 if (GetSelectedCount() >= 2)
1773 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1774 else
1775 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1776 bAddSeparator = true;
1779 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1780 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1781 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1782 bAddSeparator = true;
1785 if (bAddSeparator)
1786 popup.AppendMenu(MF_SEPARATOR, NULL);
1789 if (m_hasWC && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1791 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
1792 popup.AppendMenu(MF_SEPARATOR, NULL);
1795 if (GetSelectedCount() == 1)
1797 bool bAddSeparator = false;
1798 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1800 // show the push-option only if the log entry has an associated local branch
1801 bool isLocal = false;
1802 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1804 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1805 isLocal = true;
1807 if (isLocal)
1809 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1810 bAddSeparator = true;
1814 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1816 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1818 std::vector<CString *> branchs;
1819 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1821 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1822 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1824 CString str;
1825 if (branchs.size() == 1)
1827 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1828 str+=_T(" ");
1829 str += *branchs[0];
1830 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1831 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1832 bAddSeparator = true;
1834 else if (branchs.size() > 1)
1836 str.LoadString(IDS_DELETE_BRANCHTAG);
1837 submenu.CreatePopupMenu();
1838 for (int i = 0; i < branchs.size(); i++)
1840 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1841 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1844 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1845 bAddSeparator = true;
1848 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1849 if (bAddSeparator)
1850 popup.AppendMenu(MF_SEPARATOR, NULL);
1851 } // GetSelectedCount() == 1
1853 if (GetSelectedCount() != 0)
1855 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1856 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1857 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1858 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1859 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
1860 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
1863 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1864 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1866 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
1867 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
1869 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1870 // DialogEnableWindow(IDOK, FALSE);
1871 // SetPromptApp(&theApp);
1873 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1875 // EnableOKButton();
1876 } // if (popup.CreatePopupMenu())
1880 bool CGitLogListBase::IsSelectionContinuous()
1882 if ( GetSelectedCount()==1 )
1884 // if only one revision is selected, the selection is of course
1885 // continuous
1886 return true;
1889 POSITION pos = GetFirstSelectedItemPosition();
1890 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1891 if (bContinuous)
1893 int itemindex = GetNextSelectedItem(pos);
1894 while (pos)
1896 int nextindex = GetNextSelectedItem(pos);
1897 if (nextindex - itemindex > 1)
1899 bContinuous = false;
1900 break;
1902 itemindex = nextindex;
1905 return bContinuous;
1908 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
1911 CString sClipdata;
1912 POSITION pos = GetFirstSelectedItemPosition();
1913 if (pos != NULL)
1915 CString sRev;
1916 sRev.LoadString(IDS_LOG_REVISION);
1917 CString sAuthor;
1918 sAuthor.LoadString(IDS_LOG_AUTHOR);
1919 CString sDate;
1920 sDate.LoadString(IDS_LOG_DATE);
1921 CString sMessage;
1922 sMessage.LoadString(IDS_LOG_MESSAGE);
1923 bool first = true;
1924 while (pos)
1926 CString sLogCopyText;
1927 CString sPaths;
1928 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1930 if (toCopy == ID_COPY_ALL)
1932 //pLogEntry->GetFiles(this)
1933 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1935 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
1936 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1938 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1939 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
1941 CString rename;
1942 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
1943 sPaths += _T(" ") + rename;
1945 sPaths += _T("\r\n");
1947 sPaths.Trim();
1948 CString body = pLogEntry->GetBody();
1949 body.Replace(_T("\n"), _T("\r\n"));
1950 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"),
1951 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1952 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
1953 (LPCTSTR)sDate,
1954 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1955 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
1956 (LPCTSTR)sPaths);
1957 sClipdata += sLogCopyText;
1959 else if (toCopy == ID_COPY_MESSAGE)
1961 CString body = pLogEntry->GetBody();
1962 body.Replace(_T("\n"), _T("\r\n"));
1963 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
1965 else if (toCopy == ID_COPY_SUBJECT)
1967 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
1969 else
1971 if (!first)
1972 sClipdata += _T("\r\n");
1973 sClipdata += pLogEntry->m_CommitHash;
1976 first = false;
1978 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1983 void CGitLogListBase::DiffSelectedRevWithPrevious()
1985 if (m_bThreadRunning)
1986 return;
1988 int FirstSelect=-1, LastSelect=-1;
1989 POSITION pos = GetFirstSelectedItemPosition();
1990 FirstSelect = GetNextSelectedItem(pos);
1991 while(pos)
1993 LastSelect = GetNextSelectedItem(pos);
1996 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1998 #if 0
1999 UpdateLogInfoLabel();
2000 int selIndex = m_LogList.GetSelectionMark();
2001 if (selIndex < 0)
2002 return;
2003 int selCount = m_LogList.GetSelectedCount();
2004 if (selCount != 1)
2005 return;
2007 // Find selected entry in the log list
2008 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2009 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2010 long rev1 = pLogEntry->Rev;
2011 long rev2 = rev1-1;
2012 CTGitPath path = m_path;
2014 // See how many files under the relative root were changed in selected revision
2015 int nChanged = 0;
2016 LogChangedPath * changed = NULL;
2017 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2019 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2020 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2022 ++nChanged;
2023 changed = cpath;
2027 if (m_path.IsDirectory() && nChanged == 1)
2029 // We're looking at the log for a directory and only one file under dir was changed in the revision
2030 // Do diff on that file instead of whole directory
2031 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2034 m_bCancelled = FALSE;
2035 DialogEnableWindow(IDOK, FALSE);
2036 SetPromptApp(&theApp);
2037 theApp.DoWaitCursor(1);
2039 if (PromptShown())
2041 GitDiff diff(this, m_hWnd, true);
2042 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2043 diff.SetHEADPeg(m_LogRevision);
2044 diff.ShowCompare(path, rev2, path, rev1);
2046 else
2048 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2051 theApp.DoWaitCursor(-1);
2052 EnableOKButton();
2053 #endif
2056 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2058 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2059 *pResult = -1;
2061 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2062 return;
2063 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2064 return;
2065 if (pFindInfo->lvfi.psz == 0)
2066 return;
2067 #if 0
2068 CString sCmp = pFindInfo->lvfi.psz;
2069 CString sRev;
2070 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2072 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2073 sRev.Format(_T("%ld"), pLogEntry->Rev);
2074 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2076 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2078 *pResult = i;
2079 return;
2082 else
2084 if (sCmp.Compare(sRev)==0)
2086 *pResult = i;
2087 return;
2091 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2093 for (int i=0; i<pFindInfo->iStart; ++i)
2095 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2096 sRev.Format(_T("%ld"), pLogEntry->Rev);
2097 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2099 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2101 *pResult = i;
2102 return;
2105 else
2107 if (sCmp.Compare(sRev)==0)
2109 *pResult = i;
2110 return;
2115 #endif
2116 *pResult = -1;
2119 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2121 ClearText();
2123 this->m_arShownList.SafeRemoveAll();
2125 this->m_logEntries.ClearAll();
2126 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2127 return -1;
2129 //this->m_logEntries.ParserFromLog();
2130 SetItemCountEx((int)m_logEntries.size());
2132 for(unsigned int i=0;i<m_logEntries.size();i++)
2134 if(m_IsOldFirst)
2136 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2137 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2140 else
2142 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2143 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2147 ReloadHashMap();
2149 if(path)
2150 m_Path=*path;
2151 return 0;
2155 int CGitLogListBase::BeginFetchLog()
2157 ClearText();
2159 this->m_arShownList.SafeRemoveAll();
2161 this->m_logEntries.ClearAll();
2163 this->m_LogCache.ClearAllParent();
2165 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2167 CTGitPath *path;
2168 if(this->m_Path.IsEmpty())
2169 path=NULL;
2170 else
2171 path=&this->m_Path;
2173 CString hash;
2174 int mask;
2175 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2176 // if(this->m_bAllBranch)
2177 mask |= m_ShowMask ;
2179 if(m_bShowWC)
2181 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2182 ResetWcRev();
2183 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2186 CString *pFrom, *pTo;
2187 pFrom = pTo = NULL;
2188 CString head(_T("HEAD"));
2189 if(!this->m_startrev.IsEmpty())
2191 pFrom = &this->m_startrev;
2192 if(!this->m_endrev.IsEmpty())
2193 pTo = &this->m_endrev;
2194 else
2195 pTo = &head;
2198 CFilterData data;
2199 data.m_From = m_From;
2200 data.m_To =m_To;
2202 #if 0 /* use tortoiegit filter */
2203 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2204 data.m_Author = this->m_sFilterText;
2206 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2207 data.m_MessageFilter = this->m_sFilterText;
2209 data.m_IsRegex = m_bFilterWithRegex;
2210 #endif
2212 // follow does not work for directories
2213 if (!path || path->IsDirectory())
2214 mask &= ~CGit::LOG_INFO_FOLLOW;
2215 // follow does not work with all branches 8at least in TGit)
2216 if (mask & CGit::LOG_INFO_FOLLOW)
2217 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2219 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2221 //this->m_logEntries.ParserFromLog();
2222 if(IsInWorkingThread())
2224 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2226 else
2228 SetItemCountEx((int)m_logEntries.size());
2233 git_init();
2235 catch (char* msg)
2237 CString err(msg);
2238 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2239 return -1;
2242 if (g_Git.IsOrphanBranch(m_StartRef))
2244 if (!(mask & CGit::LOG_INFO_ALL_BRANCH))
2245 return 0;
2247 // if show all branches, pick any ref as dummy entry ref
2248 STRING_VECTOR list;
2249 g_Git.GetRefList(list);
2250 if (list.size() == 0)
2251 return 0;
2253 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, pFrom, pTo, true, &data);
2256 try {
2257 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2259 return -1;
2262 catch (char* msg)
2264 CString err(msg);
2265 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2266 return -1;
2269 return 0;
2272 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2274 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2276 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2278 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2280 DiffSelectedRevWithPrevious();
2281 return TRUE;
2284 #if 0
2285 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2287 DiffSelectedFile();
2288 return TRUE;
2290 #endif
2292 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2294 // select all entries
2295 for (int i=0; i<GetItemCount(); ++i)
2297 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2299 return TRUE;
2302 #if 0
2303 if (m_hAccel && !bSkipAccelerator)
2305 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2306 if (ret)
2307 return TRUE;
2310 #endif
2311 //m_tooltips.RelayEvent(pMsg);
2312 return __super::PreTranslateMessage(pMsg);
2315 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2317 // a double click on an entry in the revision list has happened
2318 *pResult = 0;
2320 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2321 DiffSelectedRevWithPrevious();
2324 int CGitLogListBase::FetchLogAsync(void * data)
2326 m_ProcData=data;
2327 m_bExitThread=FALSE;
2328 InterlockedExchange(&m_bThreadRunning, TRUE);
2329 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2330 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2331 if (m_LoadingThread ==NULL)
2333 InterlockedExchange(&m_bThreadRunning, FALSE);
2334 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2335 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2336 return -1;
2338 return 0;
2341 //this is the thread function which calls the subversion function
2342 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2344 return ((CGitLogListBase*)pVoid)->LogThread();
2347 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2349 //CTime time;
2350 oldest=CTime::GetCurrentTime();
2351 latest=CTime(1971,1,2,0,0,0);
2352 for(unsigned int i=0;i<m_logEntries.size();i++)
2354 if(m_logEntries[i].IsEmpty())
2355 continue;
2357 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2358 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2360 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2361 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2365 if(latest<oldest)
2366 latest=oldest;
2369 UINT CGitLogListBase::LogThread()
2371 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2373 InterlockedExchange(&m_bThreadRunning, TRUE);
2374 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2376 ULONGLONG t1,t2;
2378 if(BeginFetchLog())
2380 InterlockedExchange(&m_bThreadRunning, FALSE);
2381 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2383 return 1;
2386 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2387 bool bRegex = false;
2388 if (m_bFilterWithRegex)
2389 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2391 TRACE(_T("\n===Begin===\n"));
2392 //Update work copy item;
2394 if (!m_logEntries.empty())
2396 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2398 m_arShownList.SafeAdd(pRev);
2402 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2404 // store commit number of the last selected commit/line before the refresh or -1
2405 int lastSelectedHashNItem = -1;
2406 int ret = 0;
2408 bool shouldWalk = true;
2409 if (g_Git.IsOrphanBranch(m_StartRef))
2411 // walk revisions if show all branches and there exists any ref
2412 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH))
2413 shouldWalk = false;
2414 else
2416 STRING_VECTOR list;
2417 g_Git.GetRefList(list);
2418 if (list.size() == 0)
2419 shouldWalk = false;
2423 if (shouldWalk)
2425 g_Git.m_critGitDllSec.Lock();
2426 int total = 0;
2429 git_get_log_firstcommit(m_DllGitLog);
2430 total = git_get_log_estimate_commit_count(m_DllGitLog);
2432 catch (char* msg)
2434 CString err(msg);
2435 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2436 ret = -1;
2438 g_Git.m_critGitDllSec.Unlock();
2440 GIT_COMMIT commit;
2441 t2=t1=GetTickCount();
2442 int oldprecentage = 0;
2443 size_t oldsize = m_logEntries.size();
2444 while (ret== 0 && !m_bExitThread)
2446 g_Git.m_critGitDllSec.Lock();
2449 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2451 catch (char* msg)
2453 g_Git.m_critGitDllSec.Unlock();
2454 CString err(msg);
2455 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2456 break;
2458 g_Git.m_critGitDllSec.Unlock();
2460 if(ret)
2461 break;
2463 if (commit.m_ignore == 1)
2465 git_free_commit(&commit);
2466 continue;
2469 //printf("%s\r\n",commit.GetSubject());
2470 if(m_bExitThread)
2471 break;
2473 CGitHash hash = (char*)commit.m_hash ;
2475 GitRev *pRev = m_LogCache.GetCacheData(hash);
2476 pRev->m_GitCommit = commit;
2477 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2479 char *note=NULL;
2480 g_Git.m_critGitDllSec.Lock();
2481 git_get_notes(commit.m_hash,&note);
2482 g_Git.m_critGitDllSec.Unlock();
2484 if(note)
2486 pRev->m_Notes.Empty();
2487 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2490 if(!pRev->m_IsDiffFiles)
2492 pRev->m_CallDiffAsync = DiffAsync;
2495 pRev->ParserParentFromCommit(&commit);
2497 #ifdef DEBUG
2498 pRev->DbgPrint();
2499 TRACE(_T("\n"));
2500 #endif
2502 if(!m_sFilterText.IsEmpty())
2504 if(!IsMatchFilter(bRegex,pRev,pat))
2505 continue;
2507 this->m_critSec.Lock();
2508 m_logEntries.push_back(hash);
2509 m_arShownList.SafeAdd(pRev);
2510 this->m_critSec.Unlock();
2512 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2513 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2515 t2=GetTickCount();
2517 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2519 //update UI
2520 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2521 if(percent > 99)
2522 percent =99;
2523 if(percent < GITLOG_START)
2524 percent = GITLOG_START +1;
2526 oldsize = m_logEntries.size();
2527 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2529 //if( percent > oldprecentage )
2531 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2532 oldprecentage = percent;
2534 t1 = t2;
2537 g_Git.m_critGitDllSec.Lock();
2538 git_close_log(m_DllGitLog);
2539 g_Git.m_critGitDllSec.Unlock();
2543 if (m_bExitThread)
2545 InterlockedExchange(&m_bThreadRunning, FALSE);
2546 return 0;
2549 //Update UI;
2550 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2552 if (lastSelectedHashNItem >= 0)
2553 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2555 if (this->m_hWnd)
2556 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2558 InterlockedExchange(&m_bThreadRunning, FALSE);
2560 return 0;
2563 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2565 SafeTerminateThread();
2567 this->SetItemCountEx(0);
2568 this->Clear();
2570 ResetWcRev();
2572 // HACK to hide graph column
2573 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2574 SetColumnWidth(0, 0);
2575 else
2576 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2578 //Update branch and Tag info
2579 ReloadHashMap();
2580 //Assume Thread have exited
2581 //if(!m_bThreadRunning)
2583 m_logEntries.clear();
2585 if(IsCleanFilter)
2587 m_sFilterText.Empty();
2588 m_From=-1;
2589 m_To=-1;
2592 InterlockedExchange(&m_bExitThread,FALSE);
2594 InterlockedExchange(&m_bThreadRunning, TRUE);
2595 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2596 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2598 InterlockedExchange(&m_bThreadRunning, FALSE);
2599 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2600 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2604 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2608 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2609 if (!bMatchCase)
2610 type |= tr1::regex_constants::icase;
2611 pat = tr1::wregex(regexp_str, type);
2612 return true;
2614 catch (exception) {}
2615 return false;
2617 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2620 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2621 CString sRev;
2623 if ((bRegex)&&(m_bFilterWithRegex))
2625 if (m_SelectedFilters & LOGFILTER_BUGID)
2627 if(this->m_bShowBugtraqColumn)
2629 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2631 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2632 if (regex_search(wstring(sBugIds), pat, flags))
2634 return TRUE;
2639 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2641 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2642 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2644 return TRUE;
2648 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2650 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2651 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2653 return TRUE;
2657 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2659 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2661 return TRUE;
2664 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2666 return TRUE;
2670 if (m_SelectedFilters & LOGFILTER_REVS)
2672 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2673 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2675 return TRUE;
2679 if (m_SelectedFilters & LOGFILTER_PATHS)
2681 CTGitPathList *pathList=NULL;
2682 if( pRev->m_IsDiffFiles)
2683 pathList = &pRev->GetFiles(this);
2684 else
2686 if(!pRev->m_IsSimpleListReady)
2687 pRev->SafeGetSimpleList(&g_Git);
2690 if(pathList)
2691 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2693 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2695 return true;
2697 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2699 return true;
2703 for(size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2705 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2707 return true;
2712 else
2714 CString find = m_sFilterText;
2715 find.MakeLower();
2717 if (m_SelectedFilters & LOGFILTER_BUGID)
2719 if(this->m_bShowBugtraqColumn)
2721 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2723 sBugIds.MakeLower();
2724 if ((sBugIds.Find(find) >= 0))
2726 return TRUE;
2731 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2733 CString msg = pRev->GetSubject();
2735 msg = msg.MakeLower();
2736 if ((msg.Find(find) >= 0))
2738 return TRUE;
2742 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2744 CString msg = pRev->GetBody();
2746 msg = msg.MakeLower();
2747 if ((msg.Find(find) >= 0))
2749 return TRUE;
2753 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2755 CString msg = pRev->GetAuthorName();
2756 msg = msg.MakeLower();
2757 if ((msg.Find(find) >= 0))
2759 return TRUE;
2763 if (m_SelectedFilters & LOGFILTER_REVS)
2765 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2766 if ((sRev.Find(find) >= 0))
2768 return TRUE;
2772 if (m_SelectedFilters & LOGFILTER_PATHS)
2774 CTGitPathList *pathList=NULL;
2775 if( pRev->m_IsDiffFiles)
2776 pathList = &pRev->GetFiles(this);
2777 else
2779 if(!pRev->m_IsSimpleListReady)
2780 pRev->SafeGetSimpleList(&g_Git);
2782 if(pathList)
2783 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2785 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2786 CString path = cpath->GetGitOldPathString();
2787 path.MakeLower();
2788 if ((path.Find(find)>=0))
2790 return true;
2792 path = cpath->GetGitPathString();
2793 path.MakeLower();
2794 if ((path.Find(find)>=0))
2796 return true;
2800 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2802 CString path = pRev->m_SimpleFileList[i];
2803 path.MakeLower();
2804 if ((path.Find(find)>=0))
2806 return true;
2810 } // else (from if (bRegex))
2811 return FALSE;
2815 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2818 pShownlist->SafeRemoveAll();
2820 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2821 bool bRegex = false;
2822 if (m_bFilterWithRegex)
2823 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2825 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2826 CString sRev;
2827 for (DWORD i=0; i<m_logEntries.size(); ++i)
2829 if ((bRegex)&&(m_bFilterWithRegex))
2831 #if 0
2832 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2834 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2835 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2837 pShownlist->SafeAdd(m_logEntries[i]);
2838 continue;
2841 #endif
2842 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2844 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2845 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2847 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2848 continue;
2851 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2853 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2854 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2856 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2857 continue;
2860 if (m_SelectedFilters & LOGFILTER_PATHS)
2862 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2864 bool bGoing = true;
2865 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2867 CTGitPath cpath = pathList[cpPathIndex];
2868 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2870 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2871 bGoing = false;
2872 continue;
2874 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2876 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2877 bGoing = false;
2878 continue;
2880 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2882 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2883 bGoing = false;
2884 continue;
2888 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2890 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2892 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2893 continue;
2896 if (m_SelectedFilters & LOGFILTER_REVS)
2898 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2899 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2901 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2902 continue;
2905 } // if (bRegex)
2906 else
2908 CString find = m_sFilterText;
2909 find.MakeLower();
2910 #if 0
2911 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2913 CString sBugIDs = m_logEntries[i]->sBugIDs;
2915 sBugIDs = sBugIDs.MakeLower();
2916 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2918 pShownlist->SafeAdd(m_logEntries[i]);
2919 continue;
2922 #endif
2923 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2925 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2927 msg = msg.MakeLower();
2928 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2930 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2931 continue;
2934 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2936 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
2938 msg = msg.MakeLower();
2939 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2941 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2942 continue;
2945 if (m_SelectedFilters & LOGFILTER_PATHS)
2947 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2949 bool bGoing = true;
2950 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2952 CTGitPath cpath = pathList[cpPathIndex];
2953 CString path = cpath.GetGitOldPathString();
2954 path.MakeLower();
2955 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2957 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2958 bGoing = false;
2959 continue;
2961 path = cpath.GetGitPathString();
2962 path.MakeLower();
2963 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2965 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2966 bGoing = false;
2967 continue;
2969 path = cpath.GetActionName();
2970 path.MakeLower();
2971 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2973 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2974 bGoing = false;
2975 continue;
2979 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2981 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2982 msg = msg.MakeLower();
2983 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2985 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2986 continue;
2989 if (m_SelectedFilters & LOGFILTER_REVS)
2991 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2992 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2994 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2995 continue;
2998 } // else (from if (bRegex))
2999 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3003 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3006 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3008 if(m_From == -1)
3009 if(m_To == -1)
3010 return true;
3011 else
3012 return time <= m_To;
3013 else
3014 if(m_To == -1)
3015 return time >= m_From;
3016 else
3017 return ((time >= m_From)&&(time <= m_To));
3019 return TRUE; /* git dll will filter time range */
3021 // return TRUE;
3023 void CGitLogListBase::StartFilter()
3025 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3026 RecalculateShownList(&m_arShownList);
3027 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3030 DeleteAllItems();
3031 SetItemCountEx(ShownCountWithStopped());
3032 RedrawItems(0, ShownCountWithStopped());
3033 Invalidate();
3036 void CGitLogListBase::RemoveFilter()
3039 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3041 m_arShownList.SafeRemoveAll();
3043 // reset the time filter too
3044 #if 0
3045 m_timFrom = (__time64_t(m_tFrom));
3046 m_timTo = (__time64_t(m_tTo));
3047 m_DateFrom.SetTime(&m_timFrom);
3048 m_DateTo.SetTime(&m_timTo);
3049 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3050 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3051 #endif
3053 for (DWORD i=0; i<m_logEntries.size(); ++i)
3055 if(this->m_IsOldFirst)
3057 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3059 else
3061 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3064 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3065 DeleteAllItems();
3066 SetItemCountEx(ShownCountWithStopped());
3067 RedrawItems(0, ShownCountWithStopped());
3069 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3072 void CGitLogListBase::Clear()
3074 m_arShownList.SafeRemoveAll();
3075 DeleteAllItems();
3077 m_logEntries.ClearAll();
3081 void CGitLogListBase::OnDestroy()
3083 // save the column widths to the registry
3084 SaveColumnWidths();
3086 SafeTerminateThread();
3087 SafeTerminateAsyncDiffThread();
3089 int retry = 0;
3090 while(m_LogCache.SaveCache())
3092 if(retry > 5)
3093 break;
3094 Sleep(1000);
3096 retry++;
3098 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3099 // MB_YESNO) == IDNO)
3100 // break;
3103 CHintListCtrl::OnDestroy();
3106 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
3108 UNREFERENCED_PARAMETER(lParam);
3109 CRect rect;
3110 int i=(int)wParam;
3111 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3112 this->InvalidateRect(rect);
3114 return 0;
3118 * Save column widths to the registry
3120 void CGitLogListBase::SaveColumnWidths()
3122 int maxcol = m_ColumnManager.GetColumnCount();
3124 // HACK that graph column is always shown
3125 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3127 for (int col = 0; col < maxcol; col++)
3128 if (m_ColumnManager.IsVisible (col))
3129 m_ColumnManager.ColumnResized (col);
3131 m_ColumnManager.WriteSettings();
3134 int CGitLogListBase::GetHeadIndex()
3136 if(m_HeadHash.IsEmpty())
3137 return -1;
3139 for(int i=0;i<m_arShownList.GetCount();i++)
3141 GitRev *pRev = (GitRev*)m_arShownList[i];
3142 if(pRev)
3144 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3145 return i;
3148 return -1;
3150 void CGitLogListBase::OnFind()
3152 if (!m_pFindDialog)
3154 m_pFindDialog = new CFindDlg(this);
3155 m_pFindDialog->Create(this);
3158 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3160 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3162 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3164 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3165 Default();
3167 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3169 SetItemState((int)itemToSelect, LVIS_SELECTED, LVIS_SELECTED);
3170 EnsureVisible((int)itemToSelect, FALSE);
3171 return 0;
3173 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3176 ASSERT(m_pFindDialog != NULL);
3177 bool bFound = false;
3178 int i=0;
3180 if (m_pFindDialog->IsTerminating())
3182 // invalidate the handle identifying the dialog box.
3183 m_pFindDialog = NULL;
3184 return 0;
3187 if(m_pFindDialog->IsRef())
3189 CString str;
3190 str=m_pFindDialog->GetFindString();
3192 CGitHash hash;
3194 if(!str.IsEmpty())
3195 hash = g_Git.GetHash(str + _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3197 if(!hash.IsEmpty())
3199 for (i = 0; i<m_arShownList.GetCount(); i++)
3201 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3202 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3204 bFound = true;
3205 break;
3212 if(m_pFindDialog->FindNext())
3214 //read data from dialog
3215 CString FindText = m_pFindDialog->GetFindString();
3216 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3218 tr1::wregex pat;
3219 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3221 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3224 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3226 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3228 CString str;
3229 str+=pLogEntry->m_CommitHash.ToString();
3230 str+=_T("\n");
3232 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3234 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3235 str+=_T("\n");
3238 str+=pLogEntry->GetAuthorEmail();
3239 str+=_T("\n");
3240 str+=pLogEntry->GetAuthorName();
3241 str+=_T("\n");
3242 str+=pLogEntry->GetBody();
3243 str+=_T("\n");
3244 str+=pLogEntry->GetCommitterEmail();
3245 str+=_T("\n");
3246 str+=pLogEntry->GetCommitterName();
3247 str+=_T("\n");
3248 str+=pLogEntry->GetSubject();
3249 str+=_T("\n");
3252 /*Because changed files list is loaded on demand when gui show,
3253 files will empty when files have not fetched.
3255 we can add it back by using one-way diff(with outnumber changed and rename detect.
3256 here just need changed filename list. one-way is much quicker.
3258 if(pLogEntry->m_IsFull)
3260 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3262 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3263 str+=_T("\n");
3264 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3265 str+=_T("\n");
3268 else
3270 if(!pLogEntry->m_IsSimpleListReady)
3271 pLogEntry->SafeGetSimpleList(&g_Git);
3273 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3275 str+=pLogEntry->m_SimpleFileList[i];
3276 str+=_T("\n");
3282 if (bRegex)
3284 if (regex_search(wstring(str), pat, flags))
3286 bFound = true;
3287 break;
3290 else
3292 if (bMatchCase)
3294 if (str.Find(FindText) >= 0)
3296 bFound = true;
3297 break;
3301 else
3303 CString msg = str;
3304 msg = msg.MakeLower();
3305 CString find = FindText.MakeLower();
3306 if (msg.Find(find) >= 0)
3308 bFound = TRUE;
3309 break;
3313 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3315 } // if(m_pFindDialog->FindNext())
3316 //UpdateLogInfoLabel();
3318 if (bFound)
3320 this->m_nSearchIndex = i;
3321 EnsureVisible(i, FALSE);
3322 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3323 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3324 SetSelectionMark(i);
3325 //FillLogMessageCtrl();
3326 UpdateData(FALSE);
3327 m_nSearchIndex++;
3328 if (m_nSearchIndex >= m_arShownList.GetCount())
3329 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3332 return 0;
3335 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3337 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3339 *pResult = FALSE;
3342 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3344 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3346 Invalidate(FALSE);