Fixed some warnings
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob653e5c01861d75fc1c8d91dfbdd0a7a57121baf4
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)
82 , m_bNoHightlightHead(FALSE)
84 // use the default GUI font, create a copy of it and
85 // change the copy to BOLD (leave the rest of the font
86 // the same)
87 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
88 LOGFONT lf = {0};
89 GetObject(hFont, sizeof(LOGFONT), &lf);
90 lf.lfWeight = FW_BOLD;
91 m_boldFont = CreateFontIndirect(&lf);
93 m_bShowBugtraqColumn=false;
95 m_IsIDReplaceAction=FALSE;
97 this->m_critSec.Init();
98 m_wcRev.m_CommitHash.Empty();
99 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
100 m_wcRev.m_ParentHash.clear();
101 m_wcRev.m_Mark=_T('-');
102 m_wcRev.m_IsUpdateing=FALSE;
103 m_wcRev.m_IsFull = TRUE;
105 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
106 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
107 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
111 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
113 g_Git.GetMapHashToFriendName(m_HashMap);
114 if (CTGitPath(g_Git.m_CurrentDir).HasAdminDir())
116 m_CurrentBranch=g_Git.GetCurrentBranch();
117 try {
118 m_HeadHash=g_Git.GetHash(_T("HEAD"));
120 catch (char* msg)
122 CString err(msg);
123 MessageBox(_T("Could not get HEAD hash. Quitting...\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
124 ExitProcess(1);
128 m_From=-1;;
129 m_To=-1;
131 m_ShowMask = 0;
132 m_LoadingThread = NULL;
134 InterlockedExchange(&m_bExitThread,FALSE);
135 m_IsOldFirst = FALSE;
136 m_IsRebaseReplaceGraph = FALSE;
139 for(int i=0;i<Lanes::COLORS_NUM;i++)
141 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
143 // get short/long datetime setting from registry
144 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
145 if ( RegUseShortDateFormat )
147 m_DateFormat = DATE_SHORTDATE;
149 else
151 m_DateFormat = DATE_LONGDATE;
153 // get relative time display setting from registry
154 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
155 m_bRelativeTimes = (regRelativeTimes != 0);
156 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
158 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
159 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
160 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
161 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
162 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
163 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
165 m_ColumnRegKey=_T("log");
167 m_AsyncThreadExit = FALSE;
168 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
169 m_AsynDiffListLock.Init();
171 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
172 if (m_DiffingThread ==NULL)
174 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
175 return;
180 int CGitLogListBase::AsyncDiffThread()
182 m_AsyncThreadExited = false;
183 while(!m_AsyncThreadExit)
185 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
187 GitRev *pRev = NULL;
188 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
190 m_AsynDiffListLock.Lock();
191 pRev = m_AsynDiffList.back();
192 m_AsynDiffList.pop_back();
193 m_AsynDiffListLock.Unlock();
195 if( pRev->m_CommitHash.IsEmpty() )
197 if(pRev->m_IsDiffFiles)
198 continue;
200 pRev->GetFiles(this).Clear();
201 pRev->m_ParentHash.clear();
202 pRev->m_ParentHash.push_back(m_HeadHash);
203 if(g_Git.IsInitRepos())
205 g_Git.GetInitAddList(pRev->GetFiles(this));
208 else
210 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
212 pRev->GetAction(this) = 0;
214 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
215 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
217 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
218 InterlockedExchange(&pRev->m_IsFull, TRUE);
220 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
221 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
222 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
225 if(!pRev->CheckAndDiff())
226 { // fetch change file list
227 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
229 if(i < m_arShownList.GetCount())
231 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
232 if(data->m_CommitHash == pRev->m_CommitHash)
234 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
235 break;
240 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
242 POSITION pos = GetFirstSelectedItemPosition();
243 int nItem = GetNextSelectedItem(pos);
245 if(nItem>=0)
247 GitRev* data = (GitRev*)m_arShownList[nItem];
248 if(data)
249 if(data->m_CommitHash == pRev->m_CommitHash)
251 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
258 m_AsyncThreadExited = true;
259 return 0;
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
263 if (exclusivelyShow)
265 m_ContextMenuMask &= hideMask;
267 else
269 m_ContextMenuMask &= ~hideMask;
273 CGitLogListBase::~CGitLogListBase()
275 InterlockedExchange(&m_bNoDispUpdates, TRUE);
276 this->m_arShownList.SafeRemoveAll();
278 DestroyIcon(m_hModifiedIcon);
279 DestroyIcon(m_hReplacedIcon);
280 DestroyIcon(m_hAddedIcon);
281 DestroyIcon(m_hDeletedIcon);
282 m_logEntries.ClearAll();
284 if (m_boldFont)
285 DeleteObject(m_boldFont);
287 if ( m_pStoreSelection )
289 delete m_pStoreSelection;
290 m_pStoreSelection = NULL;
293 SafeTerminateThread();
294 SafeTerminateAsyncDiffThread();
296 if(m_AsyncDiffEvent)
297 CloseHandle(m_AsyncDiffEvent);
301 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
302 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
303 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
304 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
305 ON_WM_CONTEXTMENU()
306 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
307 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
308 ON_WM_CREATE()
309 ON_WM_DESTROY()
310 ON_MESSAGE(MSG_LOADED,OnLoad)
311 ON_WM_MEASUREITEM()
312 ON_WM_MEASUREITEM_REFLECT()
313 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
314 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
315 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
316 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
317 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
318 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
319 END_MESSAGE_MAP()
321 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
323 //if (m_nRowHeight>0)
325 lpMeasureItemStruct->itemHeight = 50;
329 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
331 PreSubclassWindow();
332 return CHintListCtrl::OnCreate(lpCreateStruct);
335 void CGitLogListBase::PreSubclassWindow()
337 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
338 // load the icons for the action columns
339 // m_Theme.Open(m_hWnd, L"ListView");
340 SetWindowTheme(m_hWnd, L"Explorer", NULL);
341 CHintListCtrl::PreSubclassWindow();
344 void CGitLogListBase::InsertGitColumn()
346 CString temp;
348 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
349 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
350 if (DWORD(regFullRowSelect))
351 exStyle |= LVS_EX_FULLROWSELECT;
352 SetExtendedStyle(exStyle);
354 UpdateProjectProperties();
356 static UINT normal[] =
358 IDS_LOG_GRAPH,
359 IDS_LOG_REBASE,
360 IDS_LOG_ID,
361 IDS_LOG_HASH,
362 IDS_LOG_ACTIONS,
363 IDS_LOG_MESSAGE,
364 IDS_LOG_AUTHOR,
365 IDS_LOG_DATE,
366 IDS_LOG_EMAIL,
367 IDS_LOG_COMMIT_NAME,
368 IDS_LOG_COMMIT_EMAIL,
369 IDS_LOG_COMMIT_DATE,
370 IDS_LOG_BUGIDS,
373 static int with[] =
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 LOGLIST_MESSAGE_MIN,
381 ICONITEMBORDER+16*4,
382 ICONITEMBORDER+16*4,
383 ICONITEMBORDER+16*4,
384 ICONITEMBORDER+16*4,
385 ICONITEMBORDER+16*4,
386 ICONITEMBORDER+16*4,
387 ICONITEMBORDER+16*4,
389 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
391 DWORD hideColumns = 0;
392 if(this->m_IsRebaseReplaceGraph)
394 hideColumns |= GIT_LOG_GRAPH;
395 m_dwDefaultColumns |= GIT_LOG_REBASE;
397 else
399 hideColumns |= GIT_LOG_REBASE;
402 if(this->m_IsIDReplaceAction)
404 hideColumns |= GIT_LOG_ACTIONS;
405 m_dwDefaultColumns |= GIT_LOG_ID;
406 m_dwDefaultColumns |= GIT_LOG_HASH;
408 else
410 hideColumns |= GIT_LOG_ID;
412 if(this->m_bShowBugtraqColumn)
414 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
416 else
418 hideColumns |= GIT_LOGLIST_BUG;
420 SetRedraw(false);
422 m_ColumnManager.SetNames(normal, _countof(normal));
423 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
425 SetRedraw(true);
430 * Resizes all columns in a list control to values in registry.
432 void CGitLogListBase::ResizeAllListCtrlCols()
434 // column max and min widths to allow
435 static const int nMinimumWidth = 10;
436 static const int nMaximumWidth = 1000;
437 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
438 if (pHdrCtrl)
440 int numcols = pHdrCtrl->GetItemCount();
441 for (int col = 0; col < numcols; col++)
443 // get width for this col last time from registry
444 CString regentry;
445 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
446 CRegDWORD regwidth(regentry, 0);
447 int cx = regwidth;
448 if ( cx == 0 )
450 // no saved value, setup sensible defaults
451 if (col == this->LOGLIST_MESSAGE)
453 cx = LOGLIST_MESSAGE_MIN;
455 else
457 cx = ICONITEMBORDER+16*4;
460 if (cx < nMinimumWidth)
462 cx = nMinimumWidth;
464 else if (cx > nMaximumWidth)
466 cx = nMaximumWidth;
469 SetColumnWidth(col, cx);
476 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
478 //TRACE(_T("%s %s\r\n"),ref,prefix);
479 if(ref.Left(prefix.GetLength()) == prefix)
481 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
482 if(shortname.Right(3)==_T("^{}"))
483 shortname=shortname.Left(shortname.GetLength()-3);
484 return TRUE;
486 return FALSE;
489 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
491 LVITEM rItem;
492 SecureZeroMemory(&rItem, sizeof(LVITEM));
493 rItem.mask = LVIF_STATE;
494 rItem.iItem = (int)Index;
495 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
496 GetItem(&rItem);
498 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
499 HBRUSH brush = NULL;
501 if (!(rItem.state & LVIS_SELECTED))
503 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
504 brush = ::CreateSolidBrush(RGB(156,156,156));
505 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
506 brush = ::CreateSolidBrush(RGB(200,200,128));
508 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
510 if (rItem.state & LVIS_SELECTED)
512 if (::GetFocus() == m_hWnd)
513 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
514 else
515 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
519 if (brush != NULL)
521 ::FillRect(hdc, &rect, brush);
522 ::DeleteObject(brush);
526 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
528 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
529 CRect rt=rect;
530 LVITEM rItem;
531 SecureZeroMemory(&rItem, sizeof(LVITEM));
532 rItem.mask = LVIF_STATE;
533 rItem.iItem = (int)index;
534 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
535 GetItem(&rItem);
537 CDC W_Dc;
538 W_Dc.Attach(hdc);
540 HTHEME hTheme = NULL;
541 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
542 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
544 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
546 CString str;
547 str=m_HashMap[data->m_CommitHash][i];
549 CString shortname;
550 HBRUSH brush = 0;
551 shortname = _T("");
552 COLORREF colRef = 0;
554 //Determine label color
555 if(GetShortName(str,shortname,_T("refs/heads/")))
557 if( shortname == m_CurrentBranch )
558 colRef = m_Colors.GetColor(CColors::CurrentBranch);
559 else
560 colRef = m_Colors.GetColor(CColors::LocalBranch);
563 else if(GetShortName(str,shortname,_T("refs/remotes/")))
565 colRef = m_Colors.GetColor(CColors::RemoteBranch);
567 else if(GetShortName(str,shortname,_T("refs/tags/")))
569 colRef = m_Colors.GetColor(CColors::Tag);
571 else if(GetShortName(str,shortname,_T("refs/stash")))
573 colRef = m_Colors.GetColor(CColors::Stash);
574 shortname=_T("stash");
576 else if(GetShortName(str,shortname,_T("refs/bisect/")))
578 if(shortname.Find(_T("good")) == 0)
580 colRef = m_Colors.GetColor(CColors::BisectGood);
581 shortname = _T("good");
584 if(shortname.Find(_T("bad")) == 0)
586 colRef = m_Colors.GetColor(CColors::BisectBad);
587 shortname = _T("bad");
591 //When row selected, ajust label color
592 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
593 if (rItem.state & LVIS_SELECTED)
594 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
596 brush = ::CreateSolidBrush(colRef);
598 if(!shortname.IsEmpty() && (rt.left<rect.right) )
600 SIZE size;
601 memset(&size,0,sizeof(SIZE));
602 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
604 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
605 rt.right+=8;
607 int textpos = DT_CENTER;
609 if(rt.right > rect.right)
611 rt.right = rect.right;
612 textpos =0;
615 //Fill interior of ref label
616 ::FillRect(hdc, &rt, brush);
618 //Draw edge of label
620 CRect rectEdge = rt;
622 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
623 rectEdge.DeflateRect(1,1);
624 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
626 //Draw text inside label
627 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
629 int txtState = LISS_NORMAL;
630 if (rItem.state & LVIS_SELECTED)
631 txtState = LISS_SELECTED;
633 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &rt);
635 else
637 W_Dc.SetBkMode(TRANSPARENT);
638 if (rItem.state & LVIS_SELECTED)
640 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
641 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
642 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
643 ::SetTextColor(hdc,clrOld);
645 else
647 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,textpos | DT_SINGLELINE | DT_VCENTER);
651 //::MoveToEx(hdc,rt.left,rt.top,NULL);
652 //::LineTo(hdc,rt.right,rt.top);
653 //::LineTo(hdc,rt.right,rt.bottom);
654 //::LineTo(hdc,rt.left,rt.bottom);
655 //::LineTo(hdc,rt.left,rt.top);
657 rt.left=rt.right+1;
659 if(brush)
660 ::DeleteObject(brush);
662 rt.right=rect.right;
664 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
666 int txtState = LISS_NORMAL;
667 if (rItem.state & LVIS_SELECTED)
668 txtState = LISS_SELECTED;
670 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
672 else
674 if (rItem.state & LVIS_SELECTED)
676 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
677 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
678 ::SetTextColor(hdc,clrOld);
680 else
682 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER);
686 if (hTheme)
687 CloseThemeData(hTheme);
689 W_Dc.Detach();
692 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
694 // Returns ((256 - amount)*col1 + amount*col2) / 256;
695 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
696 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
697 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
700 Gdiplus::Color GetGdiColor(COLORREF col)
702 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
704 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
705 const COLORREF& col,const COLORREF& activeColor, int top
708 int h = laneHeight / 2;
709 int m = (x1 + x2) / 2;
710 int r = (x2 - x1) / 3;
711 int d = 2 * r;
713 #define P_CENTER m , h+top
714 #define P_0 x2, h+top
715 #define P_90 m , 0+top-1
716 #define P_180 x1, h+top
717 #define P_270 m , 2 * h+top +1
718 #define R_CENTER m - r, h - r+top, d, d
721 #define DELTA_UR_B 2*(x1 - m), 2*h +top
722 #define DELTA_UR_E 0*16, 90*16 +top // -,
724 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
725 #define DELTA_DR_E 270*16, 90*16 +top // -'
727 #define DELTA_UL_B 2*(x2 - m), 2*h +top
728 #define DELTA_UL_E 90*16, 90*16 +top // ,-
730 #define DELTA_DL_B 2*(x2 - m),2*-h +top
731 #define DELTA_DL_E 180*16, 90*16 // '-
733 #define CENTER_UR x1, 2*h, 225
734 #define CENTER_DR x1, 0 , 135
735 #define CENTER_UL x2, 2*h, 315
736 #define CENTER_DL x2, 0 , 45
739 Gdiplus::Graphics graphics( hdc );
741 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
743 // arc
744 switch (type) {
745 case Lanes::JOIN:
746 case Lanes::JOIN_R:
747 case Lanes::HEAD:
748 case Lanes::HEAD_R:
750 Gdiplus::LinearGradientBrush gradient(
751 Gdiplus::Point(x1-2, h+top-2),
752 Gdiplus::Point(P_270),
753 GetGdiColor(activeColor),GetGdiColor(col));
756 Gdiplus::Pen mypen(&gradient,2);
757 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
759 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
760 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
761 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
763 break;
765 case Lanes::JOIN_L:
768 Gdiplus::LinearGradientBrush gradient(
769 Gdiplus::Point(P_270),
770 Gdiplus::Point(x2+1, h+top-1),
771 GetGdiColor(col),GetGdiColor(activeColor));
774 Gdiplus::Pen mypen(&gradient,2);
775 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
777 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
778 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
779 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
782 break;
784 case Lanes::TAIL:
785 case Lanes::TAIL_R:
788 Gdiplus::LinearGradientBrush gradient(
789 Gdiplus::Point(x1-2, h+top-2),
790 Gdiplus::Point(P_90),
791 GetGdiColor(activeColor),GetGdiColor(col));
793 Gdiplus::Pen mypen(&gradient,2);
795 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
797 #if 0
798 QConicalGradient gradient(CENTER_DR);
799 gradient.setColorAt(0.375, activeCol);
800 gradient.setColorAt(0.625, col);
801 myPen.setBrush(gradient);
802 p->setPen(myPen);
803 p->drawArc(P_CENTER, DELTA_DR);
804 #endif
805 break;
807 default:
808 break;
812 //static QPen myPen(Qt::black, 2); // fast path here
813 CPen pen;
814 pen.CreatePen(PS_SOLID,2,col);
815 //myPen.setColor(col);
816 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
818 Gdiplus::Pen myPen(GetGdiColor(col),2);
820 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
822 //p->setPen(myPen);
824 // vertical line
825 switch (type) {
826 case Lanes::ACTIVE:
827 case Lanes::NOT_ACTIVE:
828 case Lanes::MERGE_FORK:
829 case Lanes::MERGE_FORK_R:
830 case Lanes::MERGE_FORK_L:
831 case Lanes::JOIN:
832 case Lanes::JOIN_R:
833 case Lanes::JOIN_L:
834 case Lanes::CROSS:
835 //DrawLine(hdc,P_90,P_270);
836 graphics.DrawLine(&myPen,P_90,P_270);
837 //p->drawLine(P_90, P_270);
838 break;
839 case Lanes::HEAD_L:
840 case Lanes::BRANCH:
841 //DrawLine(hdc,P_CENTER,P_270);
842 graphics.DrawLine(&myPen,P_CENTER,P_270);
843 //p->drawLine(P_CENTER, P_270);
844 break;
845 case Lanes::TAIL_L:
846 case Lanes::INITIAL:
847 case Lanes::BOUNDARY:
848 case Lanes::BOUNDARY_C:
849 case Lanes::BOUNDARY_R:
850 case Lanes::BOUNDARY_L:
851 //DrawLine(hdc,P_90, P_CENTER);
852 graphics.DrawLine(&myPen,P_90,P_CENTER);
853 //p->drawLine(P_90, P_CENTER);
854 break;
855 default:
856 break;
859 myPen.SetColor(GetGdiColor(activeColor));
861 // horizontal line
862 switch (type) {
863 case Lanes::MERGE_FORK:
864 case Lanes::JOIN:
865 case Lanes::HEAD:
866 case Lanes::TAIL:
867 case Lanes::CROSS:
868 case Lanes::CROSS_EMPTY:
869 case Lanes::BOUNDARY_C:
870 //DrawLine(hdc,P_180,P_0);
871 graphics.DrawLine(&myPen,P_180,P_0);
872 //p->drawLine(P_180, P_0);
873 break;
874 case Lanes::MERGE_FORK_R:
875 case Lanes::BOUNDARY_R:
876 //DrawLine(hdc,P_180,P_CENTER);
877 graphics.DrawLine(&myPen,P_180,P_CENTER);
878 //p->drawLine(P_180, P_CENTER);
879 break;
880 case Lanes::MERGE_FORK_L:
881 case Lanes::HEAD_L:
882 case Lanes::TAIL_L:
883 case Lanes::BOUNDARY_L:
884 //DrawLine(hdc,P_CENTER,P_0);
885 graphics.DrawLine(&myPen,P_CENTER,P_0);
886 //p->drawLine(P_CENTER, P_0);
887 break;
888 default:
889 break;
892 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
894 CBrush brush;
895 brush.CreateSolidBrush(col);
896 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
898 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
899 // center symbol, e.g. rect or ellipse
900 switch (type) {
901 case Lanes::ACTIVE:
902 case Lanes::INITIAL:
903 case Lanes::BRANCH:
905 //p->setPen(Qt::NoPen);
906 //p->setBrush(col);
907 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
908 graphics.FillEllipse(&myBrush, R_CENTER);
909 //p->drawEllipse(R_CENTER);
910 break;
911 case Lanes::MERGE_FORK:
912 case Lanes::MERGE_FORK_R:
913 case Lanes::MERGE_FORK_L:
914 //p->setPen(Qt::NoPen);
915 //p->setBrush(col);
916 //p->drawRect(R_CENTER);
917 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
918 graphics.FillRectangle(&myBrush, R_CENTER);
919 break;
920 case Lanes::UNAPPLIED:
921 // Red minus sign
922 //p->setPen(Qt::NoPen);
923 //p->setBrush(Qt::red);
924 //p->drawRect(m - r, h - 1, d, 2);
925 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
926 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
927 break;
928 case Lanes::APPLIED:
929 // Green plus sign
930 //p->setPen(Qt::NoPen);
931 //p->setBrush(DARK_GREEN);
932 //p->drawRect(m - r, h - 1, d, 2);
933 //p->drawRect(m - 1, h - r, 2, d);
934 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
935 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
936 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
937 break;
938 case Lanes::BOUNDARY:
939 //p->setBrush(back);
940 //p->drawEllipse(R_CENTER);
941 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
942 graphics.DrawEllipse(&myPen, R_CENTER);
943 break;
944 case Lanes::BOUNDARY_C:
945 case Lanes::BOUNDARY_R:
946 case Lanes::BOUNDARY_L:
947 //p->setBrush(back);
948 //p->drawRect(R_CENTER);
949 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
950 graphics.FillRectangle(&myBrush,R_CENTER);
951 break;
952 default:
953 break;
956 ::SelectObject(hdc,oldpen);
957 ::SelectObject(hdc,oldbrush);
958 #undef P_CENTER
959 #undef P_0
960 #undef P_90
961 #undef P_180
962 #undef P_270
963 #undef R_CENTER
966 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
968 // TODO: unfinished
969 // return;
970 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
971 if(data->m_CommitHash.IsEmpty())
972 return;
974 CRect rt=rect;
975 LVITEM rItem;
976 SecureZeroMemory(&rItem, sizeof(LVITEM));
977 rItem.mask = LVIF_STATE;
978 rItem.iItem = (int)index;
979 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
980 GetItem(&rItem);
982 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
984 if (data->m_Lanes.empty())
985 m_logEntries.setLane(data->m_CommitHash);
987 std::vector<int>& lanes=data->m_Lanes;
988 size_t laneNum = lanes.size();
989 UINT activeLane = 0;
990 for (UINT i = 0; i < laneNum; i++)
991 if (Lanes::isMerge(lanes[i])) {
992 activeLane = i;
993 break;
996 int x1 = 0, x2 = 0;
997 int maxWidth = rect.Width();
998 int lw = 3 * rect.Height() / 4; //laneWidth()
1000 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1001 //if (opt.state & QStyle::State_Selected)
1002 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1004 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1007 x1 = x2;
1008 x2 += lw;
1010 int ln = lanes[i];
1011 if (ln == Lanes::EMPTY)
1012 continue;
1014 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1015 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1018 #if 0
1019 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1021 x1 = x2;
1022 x2 += lw;
1024 int ln = lanes[i];
1025 if (ln == Lanes::EMPTY)
1026 continue;
1028 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1029 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1031 if (ln == Lanes::CROSS)
1033 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1034 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1036 else
1037 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1039 #endif
1043 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1046 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1047 // Take the default processing unless we set this to something else below.
1048 *pResult = CDRF_DODEFAULT;
1050 if (m_bNoDispUpdates)
1051 return;
1053 switch (pLVCD->nmcd.dwDrawStage)
1055 case CDDS_PREPAINT:
1057 *pResult = CDRF_NOTIFYITEMDRAW;
1058 return;
1060 break;
1061 case CDDS_ITEMPREPAINT:
1063 // This is the prepaint stage for an item. Here's where we set the
1064 // item's text color.
1066 // Tell Windows to send draw notifications for each subitem.
1067 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1069 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1071 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1073 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1074 if (data)
1076 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1077 crText = RGB(128,128,128);
1079 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1080 pLVCD->clrTextBk = RGB(156,156,156);
1081 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1082 pLVCD->clrTextBk = RGB(200,200,128);
1083 else
1084 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1086 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1088 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1089 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1092 if (data->m_CommitHash.ToString() == m_HeadHash && m_bNoHightlightHead == FALSE)
1094 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1095 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1098 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1099 // crText = GetSysColor(COLOR_GRAYTEXT);
1101 if (data->m_CommitHash.IsEmpty())
1103 //crText = GetSysColor(RGB(200,200,0));
1104 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1105 // We changed the font, so we're returning CDRF_NEWFONT. This
1106 // tells the control to recalculate the extent of the text.
1107 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1111 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1113 if (m_bStrictStopped)
1114 crText = GetSysColor(COLOR_GRAYTEXT);
1116 // Store the color back in the NMLVCUSTOMDRAW struct.
1117 pLVCD->clrText = crText;
1118 return;
1120 break;
1121 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1123 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1125 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1128 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1130 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1132 CRect rect;
1133 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1135 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1136 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1138 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1139 if( !data ->m_CommitHash.IsEmpty())
1140 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1142 *pResult = CDRF_SKIPDEFAULT;
1143 return;
1147 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1149 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1151 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1152 //if(!data->m_IsFull)
1154 //if(data->SafeFetchFullInfo(&g_Git))
1155 // this->Invalidate();
1156 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1159 if (!m_HashMap[data->m_CommitHash].empty())
1161 CRect rect;
1163 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1165 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1166 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1168 *pResult = CDRF_SKIPDEFAULT;
1169 return;
1176 if (pLVCD->iSubItem == LOGLIST_ACTION)
1178 if(this->m_IsIDReplaceAction)
1180 *pResult = CDRF_DODEFAULT;
1181 return;
1183 *pResult = CDRF_DODEFAULT;
1185 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1186 return;
1188 int nIcons = 0;
1189 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1190 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1192 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1193 CRect rect;
1194 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1195 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1196 // Get the selected state of the
1197 // item being drawn.
1199 // Fill the background if necessary
1200 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1202 // Draw the icon(s) into the compatible DC
1203 pLogEntry->GetAction(this);
1205 if (!pLogEntry->m_IsDiffFiles)
1206 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1208 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1209 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1210 nIcons++;
1212 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1213 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1214 nIcons++;
1216 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1217 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1218 nIcons++;
1220 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1221 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1222 nIcons++;
1223 *pResult = CDRF_SKIPDEFAULT;
1224 return;
1227 break;
1229 *pResult = CDRF_DODEFAULT;
1232 // CGitLogListBase message handlers
1234 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1236 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1238 // Create a pointer to the item
1239 LV_ITEM* pItem = &(pDispInfo)->item;
1241 // Do the list need text information?
1242 if (!(pItem->mask & LVIF_TEXT))
1243 return;
1245 // By default, clear text buffer.
1246 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1248 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1250 *pResult = 0;
1251 if (m_bNoDispUpdates || bOutOfRange)
1252 return;
1254 // Which item number?
1255 int itemid = pItem->iItem;
1256 GitRev * pLogEntry = NULL;
1257 if (itemid < m_arShownList.GetCount())
1258 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1260 CString temp;
1261 if(m_IsOldFirst)
1263 temp.Format(_T("%d"),pItem->iItem+1);
1266 else
1268 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1271 // Which column?
1272 switch (pItem->iSubItem)
1274 case this->LOGLIST_GRAPH: //Graphic
1275 break;
1276 case this->LOGLIST_REBASE:
1278 if(this->m_IsRebaseReplaceGraph)
1280 CTGitPath path;
1281 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1282 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1285 break;
1286 case this->LOGLIST_ACTION: //action -- no text in the column
1287 break;
1288 case this->LOGLIST_HASH:
1289 if(pLogEntry)
1290 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1291 break;
1292 case this->LOGLIST_ID:
1293 if(this->m_IsIDReplaceAction)
1294 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1295 break;
1296 case this->LOGLIST_MESSAGE: //Message
1297 if (pLogEntry)
1298 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1299 break;
1300 case this->LOGLIST_AUTHOR: //Author
1301 if (pLogEntry)
1302 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1303 break;
1304 case this->LOGLIST_DATE: //Date
1305 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1306 lstrcpyn(pItem->pszText,
1307 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1308 pItem->cchTextMax);
1309 break;
1311 case this->LOGLIST_EMAIL:
1312 if (pLogEntry)
1313 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1314 break;
1316 case this->LOGLIST_COMMIT_NAME: //Commit
1317 if (pLogEntry)
1318 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1319 break;
1321 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1322 if (pLogEntry)
1323 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1324 break;
1326 case this->LOGLIST_COMMIT_DATE: //Commit Date
1327 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1328 lstrcpyn(pItem->pszText,
1329 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1330 pItem->cchTextMax);
1331 break;
1332 case this->LOGLIST_BUG: //Bug ID
1333 if(pLogEntry)
1334 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1335 break;
1337 default:
1338 ASSERT(false);
1342 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1345 if (pWnd == GetHeaderCtrl())
1347 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1350 int selIndex = GetSelectionMark();
1351 if (selIndex < 0)
1352 return; // nothing selected, nothing to do with a context menu
1354 // if the user selected the info text telling about not all revisions shown due to
1355 // the "stop on copy/rename" option, we also don't show the context menu
1356 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1357 return;
1359 // if the context menu is invoked through the keyboard, we have to use
1360 // a calculated position on where to anchor the menu on
1361 if ((point.x == -1) && (point.y == -1))
1363 CRect rect;
1364 GetItemRect(selIndex, &rect, LVIR_LABEL);
1365 ClientToScreen(&rect);
1366 point = rect.CenterPoint();
1368 m_nSearchIndex = selIndex;
1369 m_bCancelled = FALSE;
1371 // calculate some information the context menu commands can use
1372 // CString pathURL = GetURLFromPath(m_path);
1374 POSITION pos = GetFirstSelectedItemPosition();
1375 int indexNext = GetNextSelectedItem(pos);
1376 if (indexNext < 0)
1377 return;
1379 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1380 #if 0
1381 GitRev revSelected = pSelLogEntry->Rev;
1382 GitRev revPrevious = git_revnum_t(revSelected)-1;
1383 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1385 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1387 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1388 if (changedpath->lCopyFromRev)
1389 revPrevious = changedpath->lCopyFromRev;
1392 GitRev revSelected2;
1393 if (pos)
1395 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1396 revSelected2 = pLogEntry->Rev;
1398 bool bAllFromTheSameAuthor = true;
1399 CString firstAuthor;
1400 CLogDataVector selEntries;
1401 GitRev revLowest, revHighest;
1402 GitRevRangeArray revisionRanges;
1404 POSITION pos = GetFirstSelectedItemPosition();
1405 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1406 revisionRanges.AddRevision(pLogEntry->Rev);
1407 selEntries.push_back(pLogEntry);
1408 firstAuthor = pLogEntry->sAuthor;
1409 revLowest = pLogEntry->Rev;
1410 revHighest = pLogEntry->Rev;
1411 while (pos)
1413 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1414 revisionRanges.AddRevision(pLogEntry->Rev);
1415 selEntries.push_back(pLogEntry);
1416 if (firstAuthor.Compare(pLogEntry->sAuthor))
1417 bAllFromTheSameAuthor = false;
1418 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1419 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1423 #endif
1425 int FirstSelect=-1, LastSelect=-1;
1426 pos = GetFirstSelectedItemPosition();
1427 FirstSelect = GetNextSelectedItem(pos);
1428 while(pos)
1430 LastSelect = GetNextSelectedItem(pos);
1432 //entry is selected, now show the popup menu
1433 CIconMenu popup;
1434 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1436 if (popup.CreatePopupMenu())
1438 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1439 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1441 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1442 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1444 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1445 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1447 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1448 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1450 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1451 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1453 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1454 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1455 popup.AppendMenu(MF_SEPARATOR, NULL);
1457 if (GetSelectedCount() == 1)
1461 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1463 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1464 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1466 else
1468 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1469 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1471 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1473 GitRev *pRev=pSelLogEntry;
1474 if (pSelLogEntry->m_ParentHash.empty())
1476 pRev->GetParentFromHash(pRev->m_CommitHash);
1478 if(pRev->m_ParentHash.size()<=1)
1480 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1483 else
1485 gnudiffmenu.CreatePopupMenu();
1486 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1488 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1 + (0xFFFF << 16), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1489 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1 + (0xFFFE << 16), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1491 for(int i=0;i<pRev->m_ParentHash.size();i++)
1493 CString str;
1494 str.Format(IDS_PARENT, i + 1);
1495 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1500 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1503 GitRev *pRev=pSelLogEntry;
1504 if (pSelLogEntry->m_ParentHash.empty())
1506 pRev->GetParentFromHash(pRev->m_CommitHash);
1508 if(pRev->m_ParentHash.size()<=1)
1510 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1511 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1512 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1514 else
1516 diffmenu.CreatePopupMenu();
1517 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1518 for(int i=0;i<pRev->m_ParentHash.size();i++)
1520 CString str;
1521 str.Format(IDS_PARENT, i + 1);
1522 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1523 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1525 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1526 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1532 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1533 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1535 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1536 popup.AppendMenu(MF_SEPARATOR, NULL);
1538 if (pSelLogEntry->m_CommitHash.IsEmpty())
1540 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1541 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1544 bool isStash = false;
1545 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1547 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1549 isStash = true;
1550 break;
1554 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1556 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1557 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1559 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1560 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1562 popup.AppendMenu(MF_SEPARATOR, NULL);
1565 if (pSelLogEntry->m_CommitHash.IsEmpty())
1567 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1568 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1570 popup.AppendMenu(MF_SEPARATOR, NULL);
1574 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1575 // {
1576 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1577 // }
1578 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1579 // {
1580 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1581 // }
1582 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1583 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1584 // {
1585 // popup.AppendMenu(MF_SEPARATOR, NULL);
1586 // }
1588 CString str,format;
1589 //if (m_hasWC)
1590 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1592 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1594 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1595 GetSelectedCount() == 1)
1596 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1598 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1599 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1601 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1602 str.Format(format,g_Git.GetCurrentBranch());
1604 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1605 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1607 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1608 str.Format(format,g_Git.GetCurrentBranch());
1610 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1611 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1614 // Add Switch Branch express Menu
1615 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1616 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1619 std::vector<CString *> branchs;
1620 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1622 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1623 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1625 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1629 CString str;
1630 str.LoadString(IDS_SWITCH_BRANCH);
1632 if(branchs.size() == 1)
1634 str+=_T(" ");
1635 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1636 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1638 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1641 else if(branchs.size() > 1)
1643 subbranchmenu.CreatePopupMenu();
1644 for(int i=0;i<branchs.size();i++)
1646 if (*branchs[i] != currentBranch)
1648 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1649 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1653 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1657 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1658 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1660 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1661 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1663 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1664 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1666 format.LoadString(IDS_REBASE_THIS_FORMAT);
1667 str.Format(format,g_Git.GetCurrentBranch());
1669 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1670 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1671 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1673 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1674 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1676 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1678 GitRev *pRev = pSelLogEntry;
1679 if (pSelLogEntry->m_ParentHash.empty())
1681 pRev->GetParentFromHash(pRev->m_CommitHash);
1683 if (pRev->m_ParentHash.size() == 1)
1685 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1687 else
1689 revertmenu.CreatePopupMenu();
1690 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1692 for (int i = 0; i < pRev->m_ParentHash.size(); i++)
1694 CString str;
1695 str.Format(IDS_PARENT, i + 1);
1696 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1701 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1702 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1704 popup.AppendMenu(MF_SEPARATOR, NULL);
1709 if(!pSelLogEntry->m_Ref.IsEmpty())
1711 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1712 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1713 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1714 popup.AppendMenu(MF_SEPARATOR, NULL);
1717 if (GetSelectedCount() >= 2)
1719 bool bAddSeparator = false;
1720 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1722 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1723 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1726 if (GetSelectedCount() == 2)
1728 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1729 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1730 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1731 bAddSeparator = true;
1734 if (m_hasWC)
1736 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1737 // if (m_hasWC)
1738 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
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 0
1790 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1791 // {
1792 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1793 // }
1794 // if (GetSelectedCount() == 1)
1795 // {
1796 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1797 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1798 // popup.AppendMenu(MF_SEPARATOR, NULL);
1799 // }
1800 #endif
1802 if (GetSelectedCount() == 1)
1804 bool bAddSeparator = false;
1805 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1807 // show the push-option only if the log entry has an associated local branch
1808 bool isLocal = false;
1809 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1811 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1812 isLocal = true;
1814 if (isLocal)
1816 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1817 bAddSeparator = true;
1821 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1823 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1825 std::vector<CString *> branchs;
1826 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1828 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1829 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1831 CString str;
1832 if (branchs.size() == 1)
1834 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1835 str+=_T(" ");
1836 str += *branchs[0];
1837 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1838 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1839 bAddSeparator = true;
1841 else if (branchs.size() > 1)
1843 str.LoadString(IDS_DELETE_BRANCHTAG);
1844 submenu.CreatePopupMenu();
1845 for (int i = 0; i < branchs.size(); i++)
1847 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1848 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1851 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1852 bAddSeparator = true;
1855 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1856 if (bAddSeparator)
1857 popup.AppendMenu(MF_SEPARATOR, NULL);
1858 } // GetSelectedCount() == 1
1860 if (GetSelectedCount() == 1)
1862 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1863 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1865 if (GetSelectedCount() != 0)
1867 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1868 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1869 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
1870 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
1873 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1874 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1876 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
1877 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
1879 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1880 // DialogEnableWindow(IDOK, FALSE);
1881 // SetPromptApp(&theApp);
1883 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1885 // EnableOKButton();
1886 } // if (popup.CreatePopupMenu())
1890 bool CGitLogListBase::IsSelectionContinuous()
1892 if ( GetSelectedCount()==1 )
1894 // if only one revision is selected, the selection is of course
1895 // continuous
1896 return true;
1899 POSITION pos = GetFirstSelectedItemPosition();
1900 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1901 if (bContinuous)
1903 int itemindex = GetNextSelectedItem(pos);
1904 while (pos)
1906 int nextindex = GetNextSelectedItem(pos);
1907 if (nextindex - itemindex > 1)
1909 bContinuous = false;
1910 break;
1912 itemindex = nextindex;
1915 return bContinuous;
1918 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
1921 CString sClipdata;
1922 POSITION pos = GetFirstSelectedItemPosition();
1923 if (pos != NULL)
1925 CString sRev;
1926 sRev.LoadString(IDS_LOG_REVISION);
1927 CString sAuthor;
1928 sAuthor.LoadString(IDS_LOG_AUTHOR);
1929 CString sDate;
1930 sDate.LoadString(IDS_LOG_DATE);
1931 CString sMessage;
1932 sMessage.LoadString(IDS_LOG_MESSAGE);
1933 while (pos)
1935 CString sLogCopyText;
1936 CString sPaths;
1937 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1939 if (toCopy == ID_COPY_ALL)
1941 //pLogEntry->GetFiles(this)
1942 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1944 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
1945 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1947 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1948 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
1950 CString rename;
1951 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
1952 sPaths += _T(" ") + rename;
1954 sPaths += _T("\r\n");
1956 sPaths.Trim();
1957 CString body = pLogEntry->GetBody();
1958 body.Replace(_T("\n"), _T("\r\n"));
1959 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"),
1960 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1961 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(),
1962 (LPCTSTR)sDate,
1963 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1964 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
1965 (LPCTSTR)sPaths);
1966 sClipdata += sLogCopyText;
1968 else if (toCopy == ID_COPY_MESSAGE)
1970 CString body = pLogEntry->GetBody();
1971 body.Replace(_T("\n"), _T("\r\n"));
1972 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
1974 else if (toCopy == ID_COPY_SUBJECT)
1976 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
1978 else
1980 sClipdata += pLogEntry->m_CommitHash;
1981 break;
1985 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1990 void CGitLogListBase::DiffSelectedRevWithPrevious()
1992 if (m_bThreadRunning)
1993 return;
1995 int FirstSelect=-1, LastSelect=-1;
1996 POSITION pos = GetFirstSelectedItemPosition();
1997 FirstSelect = GetNextSelectedItem(pos);
1998 while(pos)
2000 LastSelect = GetNextSelectedItem(pos);
2003 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2005 #if 0
2006 UpdateLogInfoLabel();
2007 int selIndex = m_LogList.GetSelectionMark();
2008 if (selIndex < 0)
2009 return;
2010 int selCount = m_LogList.GetSelectedCount();
2011 if (selCount != 1)
2012 return;
2014 // Find selected entry in the log list
2015 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2016 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2017 long rev1 = pLogEntry->Rev;
2018 long rev2 = rev1-1;
2019 CTGitPath path = m_path;
2021 // See how many files under the relative root were changed in selected revision
2022 int nChanged = 0;
2023 LogChangedPath * changed = NULL;
2024 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2026 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2027 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2029 ++nChanged;
2030 changed = cpath;
2034 if (m_path.IsDirectory() && nChanged == 1)
2036 // We're looking at the log for a directory and only one file under dir was changed in the revision
2037 // Do diff on that file instead of whole directory
2038 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2041 m_bCancelled = FALSE;
2042 DialogEnableWindow(IDOK, FALSE);
2043 SetPromptApp(&theApp);
2044 theApp.DoWaitCursor(1);
2046 if (PromptShown())
2048 GitDiff diff(this, m_hWnd, true);
2049 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2050 diff.SetHEADPeg(m_LogRevision);
2051 diff.ShowCompare(path, rev2, path, rev1);
2053 else
2055 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2058 theApp.DoWaitCursor(-1);
2059 EnableOKButton();
2060 #endif
2063 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2065 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2066 *pResult = -1;
2068 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2069 return;
2070 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2071 return;
2072 if (pFindInfo->lvfi.psz == 0)
2073 return;
2074 #if 0
2075 CString sCmp = pFindInfo->lvfi.psz;
2076 CString sRev;
2077 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2079 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2080 sRev.Format(_T("%ld"), pLogEntry->Rev);
2081 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2083 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2085 *pResult = i;
2086 return;
2089 else
2091 if (sCmp.Compare(sRev)==0)
2093 *pResult = i;
2094 return;
2098 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2100 for (int i=0; i<pFindInfo->iStart; ++i)
2102 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2103 sRev.Format(_T("%ld"), pLogEntry->Rev);
2104 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2106 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2108 *pResult = i;
2109 return;
2112 else
2114 if (sCmp.Compare(sRev)==0)
2116 *pResult = i;
2117 return;
2122 #endif
2123 *pResult = -1;
2126 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2128 ClearText();
2130 this->m_arShownList.SafeRemoveAll();
2132 this->m_logEntries.ClearAll();
2133 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2134 return -1;
2136 //this->m_logEntries.ParserFromLog();
2137 SetItemCountEx((int)m_logEntries.size());
2139 for(unsigned int i=0;i<m_logEntries.size();i++)
2141 if(m_IsOldFirst)
2143 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2144 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2147 else
2149 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2150 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2154 ReloadHashMap();
2156 if(path)
2157 m_Path=*path;
2158 return 0;
2162 int CGitLogListBase::BeginFetchLog()
2164 ClearText();
2166 this->m_arShownList.SafeRemoveAll();
2168 this->m_logEntries.ClearAll();
2170 this->m_LogCache.ClearAllParent();
2172 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2174 CTGitPath *path;
2175 if(this->m_Path.IsEmpty())
2176 path=NULL;
2177 else
2178 path=&this->m_Path;
2180 CString hash;
2181 int mask;
2182 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2183 // if(this->m_bAllBranch)
2184 mask |= m_ShowMask ;
2186 if(m_bShowWC)
2188 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2189 ResetWcRev();
2190 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2193 CString *pFrom, *pTo;
2194 pFrom = pTo = NULL;
2195 CString head(_T("HEAD"));
2196 if(!this->m_startrev.IsEmpty())
2198 pFrom = &this->m_startrev;
2199 if(!this->m_endrev.IsEmpty())
2200 pTo = &this->m_endrev;
2201 else
2202 pTo = &head;
2205 CFilterData data;
2206 data.m_From = m_From;
2207 data.m_To =m_To;
2209 #if 0 /* use tortoiegit filter */
2210 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2211 data.m_Author = this->m_sFilterText;
2213 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2214 data.m_MessageFilter = this->m_sFilterText;
2216 data.m_IsRegex = m_bFilterWithRegex;
2217 #endif
2219 // follow does not work for directories
2220 if (!path || path->IsDirectory())
2221 mask &= ~CGit::LOG_INFO_FOLLOW;
2222 // follow does not work with all branches 8at least in TGit)
2223 if (mask & CGit::LOG_INFO_FOLLOW)
2224 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2226 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2228 //this->m_logEntries.ParserFromLog();
2229 if(IsInWorkingThread())
2231 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2233 else
2235 SetItemCountEx((int)m_logEntries.size());
2240 git_init();
2242 catch (char* msg)
2244 CString err(msg);
2245 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2246 return -1;
2249 if(g_Git.IsInitRepos())
2250 return 0;
2252 try {
2253 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2255 return -1;
2258 catch (char* msg)
2260 CString err(msg);
2261 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2262 return -1;
2265 return 0;
2268 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2270 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2272 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2274 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2276 DiffSelectedRevWithPrevious();
2277 return TRUE;
2280 #if 0
2281 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2283 DiffSelectedFile();
2284 return TRUE;
2286 #endif
2288 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2290 // select all entries
2291 for (int i=0; i<GetItemCount(); ++i)
2293 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2295 return TRUE;
2298 #if 0
2299 if (m_hAccel && !bSkipAccelerator)
2301 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2302 if (ret)
2303 return TRUE;
2306 #endif
2307 //m_tooltips.RelayEvent(pMsg);
2308 return __super::PreTranslateMessage(pMsg);
2311 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2313 // a double click on an entry in the revision list has happened
2314 *pResult = 0;
2316 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2317 DiffSelectedRevWithPrevious();
2320 int CGitLogListBase::FetchLogAsync(void * data)
2322 m_ProcData=data;
2323 m_bExitThread=FALSE;
2324 InterlockedExchange(&m_bThreadRunning, TRUE);
2325 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2326 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2327 if (m_LoadingThread ==NULL)
2329 InterlockedExchange(&m_bThreadRunning, FALSE);
2330 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2331 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2332 return -1;
2334 return 0;
2337 //this is the thread function which calls the subversion function
2338 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2340 return ((CGitLogListBase*)pVoid)->LogThread();
2343 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2345 //CTime time;
2346 oldest=CTime::GetCurrentTime();
2347 latest=CTime(1971,1,2,0,0,0);
2348 for(unsigned int i=0;i<m_logEntries.size();i++)
2350 if(m_logEntries[i].IsEmpty())
2351 continue;
2353 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2354 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2356 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2357 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2361 if(latest<oldest)
2362 latest=oldest;
2365 UINT CGitLogListBase::LogThread()
2367 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2369 InterlockedExchange(&m_bThreadRunning, TRUE);
2370 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2372 ULONGLONG t1,t2;
2374 if(BeginFetchLog())
2376 InterlockedExchange(&m_bThreadRunning, FALSE);
2377 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2379 return 1;
2382 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2383 bool bRegex = false;
2384 if (m_bFilterWithRegex)
2385 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2387 TRACE(_T("\n===Begin===\n"));
2388 //Update work copy item;
2390 if (!m_logEntries.empty())
2392 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2394 m_arShownList.SafeAdd(pRev);
2398 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2400 // store commit number of the last selected commit/line before the refresh or -1
2401 int lastSelectedHashNItem = -1;
2402 int ret = 0;
2404 if(!g_Git.IsInitRepos())
2406 g_Git.m_critGitDllSec.Lock();
2407 int total = 0;
2410 git_get_log_firstcommit(m_DllGitLog);
2411 total = git_get_log_estimate_commit_count(m_DllGitLog);
2413 catch (char* msg)
2415 CString err(msg);
2416 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2417 ret = -1;
2419 g_Git.m_critGitDllSec.Unlock();
2421 GIT_COMMIT commit;
2422 t2=t1=GetTickCount();
2423 int oldprecentage = 0;
2424 size_t oldsize = m_logEntries.size();
2425 while( ret== 0)
2427 g_Git.m_critGitDllSec.Lock();
2430 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2432 catch (char* msg)
2434 g_Git.m_critGitDllSec.Unlock();
2435 CString err(msg);
2436 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2437 break;
2439 g_Git.m_critGitDllSec.Unlock();
2441 if(ret)
2442 break;
2444 if (commit.m_ignore == 1)
2446 git_free_commit(&commit);
2447 continue;
2450 //printf("%s\r\n",commit.GetSubject());
2451 if(m_bExitThread)
2452 break;
2454 CGitHash hash = (char*)commit.m_hash ;
2456 GitRev *pRev = m_LogCache.GetCacheData(hash);
2457 pRev->m_GitCommit = commit;
2458 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2460 char *note=NULL;
2461 g_Git.m_critGitDllSec.Lock();
2462 git_get_notes(commit.m_hash,&note);
2463 g_Git.m_critGitDllSec.Unlock();
2465 if(note)
2467 pRev->m_Notes.Empty();
2468 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2471 if(!pRev->m_IsDiffFiles)
2473 pRev->m_CallDiffAsync = DiffAsync;
2476 pRev->ParserParentFromCommit(&commit);
2478 #ifdef DEBUG
2479 pRev->DbgPrint();
2480 TRACE(_T("\n"));
2481 #endif
2483 if(!m_sFilterText.IsEmpty())
2485 if(!IsMatchFilter(bRegex,pRev,pat))
2486 continue;
2488 this->m_critSec.Lock();
2489 m_logEntries.push_back(hash);
2490 m_arShownList.SafeAdd(pRev);
2491 this->m_critSec.Unlock();
2493 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2494 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2496 t2=GetTickCount();
2498 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2500 //update UI
2501 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2502 if(percent > 99)
2503 percent =99;
2504 if(percent < GITLOG_START)
2505 percent = GITLOG_START +1;
2507 oldsize = m_logEntries.size();
2508 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2510 //if( percent > oldprecentage )
2512 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2513 oldprecentage = percent;
2515 t1 = t2;
2518 g_Git.m_critGitDllSec.Lock();
2519 git_close_log(m_DllGitLog);
2520 g_Git.m_critGitDllSec.Unlock();
2524 // restore last selected item
2525 if (lastSelectedHashNItem >= 0)
2527 SetItemState(lastSelectedHashNItem, LVIS_SELECTED, LVIS_SELECTED);
2528 EnsureVisible(lastSelectedHashNItem, FALSE);
2531 //Update UI;
2532 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2533 if (this->m_hWnd)
2534 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2536 InterlockedExchange(&m_bThreadRunning, FALSE);
2538 return 0;
2541 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2543 SafeTerminateThread();
2545 this->SetItemCountEx(0);
2546 this->Clear();
2548 ResetWcRev();
2550 // HACK to hide graph column
2551 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2552 SetColumnWidth(0, 0);
2553 else
2554 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2556 //Update branch and Tag info
2557 ReloadHashMap();
2558 //Assume Thread have exited
2559 //if(!m_bThreadRunning)
2561 m_logEntries.clear();
2563 if(IsCleanFilter)
2565 m_sFilterText.Empty();
2566 m_From=-1;
2567 m_To=-1;
2570 InterlockedExchange(&m_bExitThread,FALSE);
2572 InterlockedExchange(&m_bThreadRunning, TRUE);
2573 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2574 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2576 InterlockedExchange(&m_bThreadRunning, FALSE);
2577 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2578 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2582 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2586 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2587 if (!bMatchCase)
2588 type |= tr1::regex_constants::icase;
2589 pat = tr1::wregex(regexp_str, type);
2590 return true;
2592 catch (exception) {}
2593 return false;
2595 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2598 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2599 CString sRev;
2601 if ((bRegex)&&(m_bFilterWithRegex))
2603 if (m_SelectedFilters & LOGFILTER_BUGID)
2605 if(this->m_bShowBugtraqColumn)
2607 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2609 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2610 if (regex_search(wstring(sBugIds), pat, flags))
2612 return TRUE;
2617 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2619 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2620 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2622 return TRUE;
2626 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2628 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2629 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2631 return TRUE;
2635 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2637 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2639 return TRUE;
2642 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2644 return TRUE;
2648 if (m_SelectedFilters & LOGFILTER_REVS)
2650 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2651 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2653 return TRUE;
2657 if (m_SelectedFilters & LOGFILTER_PATHS)
2659 CTGitPathList *pathList=NULL;
2660 if( pRev->m_IsDiffFiles)
2661 pathList = &pRev->GetFiles(this);
2662 else
2664 if(!pRev->m_IsSimpleListReady)
2665 pRev->SafeGetSimpleList(&g_Git);
2668 if(pathList)
2669 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2671 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2673 return true;
2675 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2677 return true;
2681 for(size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2683 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2685 return true;
2690 else
2692 CString find = m_sFilterText;
2693 find.MakeLower();
2695 if (m_SelectedFilters & LOGFILTER_BUGID)
2697 if(this->m_bShowBugtraqColumn)
2699 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2701 sBugIds.MakeLower();
2702 if ((sBugIds.Find(find) >= 0))
2704 return TRUE;
2709 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2711 CString msg = pRev->GetSubject();
2713 msg = msg.MakeLower();
2714 if ((msg.Find(find) >= 0))
2716 return TRUE;
2720 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2722 CString msg = pRev->GetBody();
2724 msg = msg.MakeLower();
2725 if ((msg.Find(find) >= 0))
2727 return TRUE;
2731 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2733 CString msg = pRev->GetAuthorName();
2734 msg = msg.MakeLower();
2735 if ((msg.Find(find) >= 0))
2737 return TRUE;
2741 if (m_SelectedFilters & LOGFILTER_REVS)
2743 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2744 if ((sRev.Find(find) >= 0))
2746 return TRUE;
2750 if (m_SelectedFilters & LOGFILTER_PATHS)
2752 CTGitPathList *pathList=NULL;
2753 if( pRev->m_IsDiffFiles)
2754 pathList = &pRev->GetFiles(this);
2755 else
2757 if(!pRev->m_IsSimpleListReady)
2758 pRev->SafeGetSimpleList(&g_Git);
2760 if(pathList)
2761 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2763 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2764 CString path = cpath->GetGitOldPathString();
2765 path.MakeLower();
2766 if ((path.Find(find)>=0))
2768 return true;
2770 path = cpath->GetGitPathString();
2771 path.MakeLower();
2772 if ((path.Find(find)>=0))
2774 return true;
2778 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2780 CString path = pRev->m_SimpleFileList[i];
2781 path.MakeLower();
2782 if ((path.Find(find)>=0))
2784 return true;
2788 } // else (from if (bRegex))
2789 return FALSE;
2793 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2796 pShownlist->SafeRemoveAll();
2798 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2799 bool bRegex = false;
2800 if (m_bFilterWithRegex)
2801 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2803 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2804 CString sRev;
2805 for (DWORD i=0; i<m_logEntries.size(); ++i)
2807 if ((bRegex)&&(m_bFilterWithRegex))
2809 #if 0
2810 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2812 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2813 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2815 pShownlist->SafeAdd(m_logEntries[i]);
2816 continue;
2819 #endif
2820 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2822 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2823 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2825 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2826 continue;
2829 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2831 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2832 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2834 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2835 continue;
2838 if (m_SelectedFilters & LOGFILTER_PATHS)
2840 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2842 bool bGoing = true;
2843 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2845 CTGitPath cpath = pathList[cpPathIndex];
2846 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2848 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2849 bGoing = false;
2850 continue;
2852 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2854 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2855 bGoing = false;
2856 continue;
2858 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2860 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2861 bGoing = false;
2862 continue;
2866 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2868 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2870 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2871 continue;
2874 if (m_SelectedFilters & LOGFILTER_REVS)
2876 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2877 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2879 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2880 continue;
2883 } // if (bRegex)
2884 else
2886 CString find = m_sFilterText;
2887 find.MakeLower();
2888 #if 0
2889 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2891 CString sBugIDs = m_logEntries[i]->sBugIDs;
2893 sBugIDs = sBugIDs.MakeLower();
2894 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2896 pShownlist->SafeAdd(m_logEntries[i]);
2897 continue;
2900 #endif
2901 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2903 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2905 msg = msg.MakeLower();
2906 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2908 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2909 continue;
2912 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2914 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
2916 msg = msg.MakeLower();
2917 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2919 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2920 continue;
2923 if (m_SelectedFilters & LOGFILTER_PATHS)
2925 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2927 bool bGoing = true;
2928 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2930 CTGitPath cpath = pathList[cpPathIndex];
2931 CString path = cpath.GetGitOldPathString();
2932 path.MakeLower();
2933 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2935 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2936 bGoing = false;
2937 continue;
2939 path = cpath.GetGitPathString();
2940 path.MakeLower();
2941 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2943 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2944 bGoing = false;
2945 continue;
2947 path = cpath.GetActionName();
2948 path.MakeLower();
2949 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2951 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2952 bGoing = false;
2953 continue;
2957 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2959 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2960 msg = msg.MakeLower();
2961 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2963 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2964 continue;
2967 if (m_SelectedFilters & LOGFILTER_REVS)
2969 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2970 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2972 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2973 continue;
2976 } // else (from if (bRegex))
2977 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2981 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
2984 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2986 if(m_From == -1)
2987 if(m_To == -1)
2988 return true;
2989 else
2990 return time <= m_To;
2991 else
2992 if(m_To == -1)
2993 return time >= m_From;
2994 else
2995 return ((time >= m_From)&&(time <= m_To));
2997 return TRUE; /* git dll will filter time range */
2999 // return TRUE;
3001 void CGitLogListBase::StartFilter()
3003 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3004 RecalculateShownList(&m_arShownList);
3005 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3008 DeleteAllItems();
3009 SetItemCountEx(ShownCountWithStopped());
3010 RedrawItems(0, ShownCountWithStopped());
3011 Invalidate();
3014 void CGitLogListBase::RemoveFilter()
3017 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3019 m_arShownList.SafeRemoveAll();
3021 // reset the time filter too
3022 #if 0
3023 m_timFrom = (__time64_t(m_tFrom));
3024 m_timTo = (__time64_t(m_tTo));
3025 m_DateFrom.SetTime(&m_timFrom);
3026 m_DateTo.SetTime(&m_timTo);
3027 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3028 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3029 #endif
3031 for (DWORD i=0; i<m_logEntries.size(); ++i)
3033 if(this->m_IsOldFirst)
3035 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3037 else
3039 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3042 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3043 DeleteAllItems();
3044 SetItemCountEx(ShownCountWithStopped());
3045 RedrawItems(0, ShownCountWithStopped());
3047 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3050 void CGitLogListBase::Clear()
3052 m_arShownList.SafeRemoveAll();
3053 DeleteAllItems();
3055 m_logEntries.ClearAll();
3059 void CGitLogListBase::OnDestroy()
3061 // save the column widths to the registry
3062 SaveColumnWidths();
3064 SafeTerminateThread();
3065 SafeTerminateAsyncDiffThread();
3067 int retry = 0;
3068 while(m_LogCache.SaveCache())
3070 if(retry > 5)
3071 break;
3072 Sleep(1000);
3074 retry++;
3076 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3077 // MB_YESNO) == IDNO)
3078 // break;
3081 CHintListCtrl::OnDestroy();
3084 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
3086 UNREFERENCED_PARAMETER(lParam);
3087 CRect rect;
3088 int i=(int)wParam;
3089 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3090 this->InvalidateRect(rect);
3092 return 0;
3096 * Save column widths to the registry
3098 void CGitLogListBase::SaveColumnWidths()
3100 int maxcol = m_ColumnManager.GetColumnCount();
3102 // HACK that graph column is always shown
3103 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3105 for (int col = 0; col < maxcol; col++)
3106 if (m_ColumnManager.IsVisible (col))
3107 m_ColumnManager.ColumnResized (col);
3109 m_ColumnManager.WriteSettings();
3112 int CGitLogListBase::GetHeadIndex()
3114 if(m_HeadHash.IsEmpty())
3115 return -1;
3117 for(int i=0;i<m_arShownList.GetCount();i++)
3119 GitRev *pRev = (GitRev*)m_arShownList[i];
3120 if(pRev)
3122 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3123 return i;
3126 return -1;
3128 void CGitLogListBase::OnFind()
3130 if (!m_pFindDialog)
3132 m_pFindDialog = new CFindDlg(this);
3133 m_pFindDialog->Create(this);
3136 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3138 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3140 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3142 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3143 Default();
3145 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3148 ASSERT(m_pFindDialog != NULL);
3149 bool bFound = false;
3150 int i=0;
3152 if (m_pFindDialog->IsTerminating())
3154 // invalidate the handle identifying the dialog box.
3155 m_pFindDialog = NULL;
3156 return 0;
3159 if(m_pFindDialog->IsRef())
3161 CString str;
3162 str=m_pFindDialog->GetFindString();
3164 CGitHash hash;
3166 if(!str.IsEmpty())
3167 hash = g_Git.GetHash(str + _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3169 if(!hash.IsEmpty())
3171 for (i = 0; i<m_arShownList.GetCount(); i++)
3173 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3174 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3176 bFound = true;
3177 break;
3184 if(m_pFindDialog->FindNext())
3186 //read data from dialog
3187 CString FindText = m_pFindDialog->GetFindString();
3188 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3190 tr1::wregex pat;
3191 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3193 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3196 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3198 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3200 CString str;
3201 str+=pLogEntry->m_CommitHash.ToString();
3202 str+=_T("\n");
3204 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3206 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3207 str+=_T("\n");
3210 str+=pLogEntry->GetAuthorEmail();
3211 str+=_T("\n");
3212 str+=pLogEntry->GetAuthorName();
3213 str+=_T("\n");
3214 str+=pLogEntry->GetBody();
3215 str+=_T("\n");
3216 str+=pLogEntry->GetCommitterEmail();
3217 str+=_T("\n");
3218 str+=pLogEntry->GetCommitterName();
3219 str+=_T("\n");
3220 str+=pLogEntry->GetSubject();
3221 str+=_T("\n");
3224 /*Because changed files list is loaded on demand when gui show,
3225 files will empty when files have not fetched.
3227 we can add it back by using one-way diff(with outnumber changed and rename detect.
3228 here just need changed filename list. one-way is much quicker.
3230 if(pLogEntry->m_IsFull)
3232 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3234 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3235 str+=_T("\n");
3236 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3237 str+=_T("\n");
3240 else
3242 if(!pLogEntry->m_IsSimpleListReady)
3243 pLogEntry->SafeGetSimpleList(&g_Git);
3245 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3247 str+=pLogEntry->m_SimpleFileList[i];
3248 str+=_T("\n");
3254 if (bRegex)
3256 if (regex_search(wstring(str), pat, flags))
3258 bFound = true;
3259 break;
3262 else
3264 if (bMatchCase)
3266 if (str.Find(FindText) >= 0)
3268 bFound = true;
3269 break;
3273 else
3275 CString msg = str;
3276 msg = msg.MakeLower();
3277 CString find = FindText.MakeLower();
3278 if (msg.Find(find) >= 0)
3280 bFound = TRUE;
3281 break;
3285 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3287 } // if(m_pFindDialog->FindNext())
3288 //UpdateLogInfoLabel();
3290 if (bFound)
3292 this->m_nSearchIndex = i;
3293 EnsureVisible(i, FALSE);
3294 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3295 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3296 SetSelectionMark(i);
3297 //FillLogMessageCtrl();
3298 UpdateData(FALSE);
3299 m_nSearchIndex++;
3300 if (m_nSearchIndex >= m_arShownList.GetCount())
3301 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3304 return 0;
3307 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3309 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3311 *pResult = FALSE;
3314 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3316 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3318 Invalidate(FALSE);