SyncDlg: Make check if local branch fast-fowards to remote branch work again
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob3885cbcdb4e643adc078029bb70b10cb1da7682f
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((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1489 gnudiffmenu.AppendMenuIcon((UINT_PTR)(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 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1729 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1730 bAddSeparator = true;
1733 if (m_hasWC)
1735 bAddSeparator = true;
1738 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1739 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1741 if (bAddSeparator)
1742 popup.AppendMenu(MF_SEPARATOR, NULL);
1745 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1747 bool bAddSeparator = false;
1748 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1750 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1752 CString head;
1753 int headindex;
1754 headindex = this->GetHeadIndex();
1755 if(headindex>=0)
1757 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1758 CGitHash hash=g_Git.GetHash(head);
1759 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1760 if(pLastEntry->m_CommitHash == hash) {
1761 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1762 bAddSeparator = true;
1767 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1768 if (GetSelectedCount() >= 2)
1769 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1770 else
1771 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1772 bAddSeparator = true;
1775 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1776 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1777 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1778 bAddSeparator = true;
1781 if (bAddSeparator)
1782 popup.AppendMenu(MF_SEPARATOR, NULL);
1785 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())
1787 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
1788 popup.AppendMenu(MF_SEPARATOR, NULL);
1791 if (GetSelectedCount() == 1)
1793 bool bAddSeparator = false;
1794 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1796 // show the push-option only if the log entry has an associated local branch
1797 bool isLocal = false;
1798 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1800 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1801 isLocal = true;
1803 if (isLocal)
1805 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1806 bAddSeparator = true;
1810 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1812 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1814 std::vector<CString *> branchs;
1815 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1817 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1818 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1820 CString str;
1821 if (branchs.size() == 1)
1823 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1824 str+=_T(" ");
1825 str += *branchs[0];
1826 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1827 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1828 bAddSeparator = true;
1830 else if (branchs.size() > 1)
1832 str.LoadString(IDS_DELETE_BRANCHTAG);
1833 submenu.CreatePopupMenu();
1834 for (int i = 0; i < branchs.size(); i++)
1836 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1837 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1840 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1841 bAddSeparator = true;
1844 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1845 if (bAddSeparator)
1846 popup.AppendMenu(MF_SEPARATOR, NULL);
1847 } // GetSelectedCount() == 1
1849 if (GetSelectedCount() == 1)
1851 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1852 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
1854 if (GetSelectedCount() != 0)
1856 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1857 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
1858 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
1859 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
1862 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1863 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
1865 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
1866 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
1868 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1869 // DialogEnableWindow(IDOK, FALSE);
1870 // SetPromptApp(&theApp);
1872 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
1874 // EnableOKButton();
1875 } // if (popup.CreatePopupMenu())
1879 bool CGitLogListBase::IsSelectionContinuous()
1881 if ( GetSelectedCount()==1 )
1883 // if only one revision is selected, the selection is of course
1884 // continuous
1885 return true;
1888 POSITION pos = GetFirstSelectedItemPosition();
1889 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1890 if (bContinuous)
1892 int itemindex = GetNextSelectedItem(pos);
1893 while (pos)
1895 int nextindex = GetNextSelectedItem(pos);
1896 if (nextindex - itemindex > 1)
1898 bContinuous = false;
1899 break;
1901 itemindex = nextindex;
1904 return bContinuous;
1907 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
1910 CString sClipdata;
1911 POSITION pos = GetFirstSelectedItemPosition();
1912 if (pos != NULL)
1914 CString sRev;
1915 sRev.LoadString(IDS_LOG_REVISION);
1916 CString sAuthor;
1917 sAuthor.LoadString(IDS_LOG_AUTHOR);
1918 CString sDate;
1919 sDate.LoadString(IDS_LOG_DATE);
1920 CString sMessage;
1921 sMessage.LoadString(IDS_LOG_MESSAGE);
1922 while (pos)
1924 CString sLogCopyText;
1925 CString sPaths;
1926 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1928 if (toCopy == ID_COPY_ALL)
1930 //pLogEntry->GetFiles(this)
1931 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1933 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
1934 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
1936 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
1937 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
1939 CString rename;
1940 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
1941 sPaths += _T(" ") + rename;
1943 sPaths += _T("\r\n");
1945 sPaths.Trim();
1946 CString body = pLogEntry->GetBody();
1947 body.Replace(_T("\n"), _T("\r\n"));
1948 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"),
1949 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1950 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
1951 (LPCTSTR)sDate,
1952 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1953 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
1954 (LPCTSTR)sPaths);
1955 sClipdata += sLogCopyText;
1957 else if (toCopy == ID_COPY_MESSAGE)
1959 CString body = pLogEntry->GetBody();
1960 body.Replace(_T("\n"), _T("\r\n"));
1961 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
1963 else if (toCopy == ID_COPY_SUBJECT)
1965 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
1967 else
1969 sClipdata += pLogEntry->m_CommitHash;
1970 break;
1974 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1979 void CGitLogListBase::DiffSelectedRevWithPrevious()
1981 if (m_bThreadRunning)
1982 return;
1984 int FirstSelect=-1, LastSelect=-1;
1985 POSITION pos = GetFirstSelectedItemPosition();
1986 FirstSelect = GetNextSelectedItem(pos);
1987 while(pos)
1989 LastSelect = GetNextSelectedItem(pos);
1992 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
1994 #if 0
1995 UpdateLogInfoLabel();
1996 int selIndex = m_LogList.GetSelectionMark();
1997 if (selIndex < 0)
1998 return;
1999 int selCount = m_LogList.GetSelectedCount();
2000 if (selCount != 1)
2001 return;
2003 // Find selected entry in the log list
2004 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2005 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2006 long rev1 = pLogEntry->Rev;
2007 long rev2 = rev1-1;
2008 CTGitPath path = m_path;
2010 // See how many files under the relative root were changed in selected revision
2011 int nChanged = 0;
2012 LogChangedPath * changed = NULL;
2013 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2015 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2016 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2018 ++nChanged;
2019 changed = cpath;
2023 if (m_path.IsDirectory() && nChanged == 1)
2025 // We're looking at the log for a directory and only one file under dir was changed in the revision
2026 // Do diff on that file instead of whole directory
2027 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2030 m_bCancelled = FALSE;
2031 DialogEnableWindow(IDOK, FALSE);
2032 SetPromptApp(&theApp);
2033 theApp.DoWaitCursor(1);
2035 if (PromptShown())
2037 GitDiff diff(this, m_hWnd, true);
2038 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2039 diff.SetHEADPeg(m_LogRevision);
2040 diff.ShowCompare(path, rev2, path, rev1);
2042 else
2044 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2047 theApp.DoWaitCursor(-1);
2048 EnableOKButton();
2049 #endif
2052 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2054 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2055 *pResult = -1;
2057 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2058 return;
2059 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2060 return;
2061 if (pFindInfo->lvfi.psz == 0)
2062 return;
2063 #if 0
2064 CString sCmp = pFindInfo->lvfi.psz;
2065 CString sRev;
2066 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2068 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2069 sRev.Format(_T("%ld"), pLogEntry->Rev);
2070 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2072 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2074 *pResult = i;
2075 return;
2078 else
2080 if (sCmp.Compare(sRev)==0)
2082 *pResult = i;
2083 return;
2087 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2089 for (int i=0; i<pFindInfo->iStart; ++i)
2091 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2092 sRev.Format(_T("%ld"), pLogEntry->Rev);
2093 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2095 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2097 *pResult = i;
2098 return;
2101 else
2103 if (sCmp.Compare(sRev)==0)
2105 *pResult = i;
2106 return;
2111 #endif
2112 *pResult = -1;
2115 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2117 ClearText();
2119 this->m_arShownList.SafeRemoveAll();
2121 this->m_logEntries.ClearAll();
2122 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2123 return -1;
2125 //this->m_logEntries.ParserFromLog();
2126 SetItemCountEx((int)m_logEntries.size());
2128 for(unsigned int i=0;i<m_logEntries.size();i++)
2130 if(m_IsOldFirst)
2132 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2133 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2136 else
2138 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2139 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2143 ReloadHashMap();
2145 if(path)
2146 m_Path=*path;
2147 return 0;
2151 int CGitLogListBase::BeginFetchLog()
2153 ClearText();
2155 this->m_arShownList.SafeRemoveAll();
2157 this->m_logEntries.ClearAll();
2159 this->m_LogCache.ClearAllParent();
2161 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2163 CTGitPath *path;
2164 if(this->m_Path.IsEmpty())
2165 path=NULL;
2166 else
2167 path=&this->m_Path;
2169 CString hash;
2170 int mask;
2171 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2172 // if(this->m_bAllBranch)
2173 mask |= m_ShowMask ;
2175 if(m_bShowWC)
2177 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2178 ResetWcRev();
2179 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2182 CString *pFrom, *pTo;
2183 pFrom = pTo = NULL;
2184 CString head(_T("HEAD"));
2185 if(!this->m_startrev.IsEmpty())
2187 pFrom = &this->m_startrev;
2188 if(!this->m_endrev.IsEmpty())
2189 pTo = &this->m_endrev;
2190 else
2191 pTo = &head;
2194 CFilterData data;
2195 data.m_From = m_From;
2196 data.m_To =m_To;
2198 #if 0 /* use tortoiegit filter */
2199 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2200 data.m_Author = this->m_sFilterText;
2202 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2203 data.m_MessageFilter = this->m_sFilterText;
2205 data.m_IsRegex = m_bFilterWithRegex;
2206 #endif
2208 // follow does not work for directories
2209 if (!path || path->IsDirectory())
2210 mask &= ~CGit::LOG_INFO_FOLLOW;
2211 // follow does not work with all branches 8at least in TGit)
2212 if (mask & CGit::LOG_INFO_FOLLOW)
2213 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2215 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2217 //this->m_logEntries.ParserFromLog();
2218 if(IsInWorkingThread())
2220 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2222 else
2224 SetItemCountEx((int)m_logEntries.size());
2229 git_init();
2231 catch (char* msg)
2233 CString err(msg);
2234 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2235 return -1;
2238 if(g_Git.IsInitRepos())
2239 return 0;
2241 try {
2242 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2244 return -1;
2247 catch (char* msg)
2249 CString err(msg);
2250 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2251 return -1;
2254 return 0;
2257 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2259 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2261 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2263 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2265 DiffSelectedRevWithPrevious();
2266 return TRUE;
2269 #if 0
2270 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2272 DiffSelectedFile();
2273 return TRUE;
2275 #endif
2277 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2279 // select all entries
2280 for (int i=0; i<GetItemCount(); ++i)
2282 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2284 return TRUE;
2287 #if 0
2288 if (m_hAccel && !bSkipAccelerator)
2290 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2291 if (ret)
2292 return TRUE;
2295 #endif
2296 //m_tooltips.RelayEvent(pMsg);
2297 return __super::PreTranslateMessage(pMsg);
2300 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2302 // a double click on an entry in the revision list has happened
2303 *pResult = 0;
2305 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2306 DiffSelectedRevWithPrevious();
2309 int CGitLogListBase::FetchLogAsync(void * data)
2311 m_ProcData=data;
2312 m_bExitThread=FALSE;
2313 InterlockedExchange(&m_bThreadRunning, TRUE);
2314 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2315 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2316 if (m_LoadingThread ==NULL)
2318 InterlockedExchange(&m_bThreadRunning, FALSE);
2319 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2320 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2321 return -1;
2323 return 0;
2326 //this is the thread function which calls the subversion function
2327 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2329 return ((CGitLogListBase*)pVoid)->LogThread();
2332 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2334 //CTime time;
2335 oldest=CTime::GetCurrentTime();
2336 latest=CTime(1971,1,2,0,0,0);
2337 for(unsigned int i=0;i<m_logEntries.size();i++)
2339 if(m_logEntries[i].IsEmpty())
2340 continue;
2342 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2343 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2345 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2346 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2350 if(latest<oldest)
2351 latest=oldest;
2354 UINT CGitLogListBase::LogThread()
2356 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2358 InterlockedExchange(&m_bThreadRunning, TRUE);
2359 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2361 ULONGLONG t1,t2;
2363 if(BeginFetchLog())
2365 InterlockedExchange(&m_bThreadRunning, FALSE);
2366 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2368 return 1;
2371 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2372 bool bRegex = false;
2373 if (m_bFilterWithRegex)
2374 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2376 TRACE(_T("\n===Begin===\n"));
2377 //Update work copy item;
2379 if (!m_logEntries.empty())
2381 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2383 m_arShownList.SafeAdd(pRev);
2387 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2389 // store commit number of the last selected commit/line before the refresh or -1
2390 int lastSelectedHashNItem = -1;
2391 int ret = 0;
2393 if(!g_Git.IsInitRepos())
2395 g_Git.m_critGitDllSec.Lock();
2396 int total = 0;
2399 git_get_log_firstcommit(m_DllGitLog);
2400 total = git_get_log_estimate_commit_count(m_DllGitLog);
2402 catch (char* msg)
2404 CString err(msg);
2405 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2406 ret = -1;
2408 g_Git.m_critGitDllSec.Unlock();
2410 GIT_COMMIT commit;
2411 t2=t1=GetTickCount();
2412 int oldprecentage = 0;
2413 size_t oldsize = m_logEntries.size();
2414 while( ret== 0)
2416 g_Git.m_critGitDllSec.Lock();
2419 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2421 catch (char* msg)
2423 g_Git.m_critGitDllSec.Unlock();
2424 CString err(msg);
2425 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2426 break;
2428 g_Git.m_critGitDllSec.Unlock();
2430 if(ret)
2431 break;
2433 if (commit.m_ignore == 1)
2435 git_free_commit(&commit);
2436 continue;
2439 //printf("%s\r\n",commit.GetSubject());
2440 if(m_bExitThread)
2441 break;
2443 CGitHash hash = (char*)commit.m_hash ;
2445 GitRev *pRev = m_LogCache.GetCacheData(hash);
2446 pRev->m_GitCommit = commit;
2447 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2449 char *note=NULL;
2450 g_Git.m_critGitDllSec.Lock();
2451 git_get_notes(commit.m_hash,&note);
2452 g_Git.m_critGitDllSec.Unlock();
2454 if(note)
2456 pRev->m_Notes.Empty();
2457 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2460 if(!pRev->m_IsDiffFiles)
2462 pRev->m_CallDiffAsync = DiffAsync;
2465 pRev->ParserParentFromCommit(&commit);
2467 #ifdef DEBUG
2468 pRev->DbgPrint();
2469 TRACE(_T("\n"));
2470 #endif
2472 if(!m_sFilterText.IsEmpty())
2474 if(!IsMatchFilter(bRegex,pRev,pat))
2475 continue;
2477 this->m_critSec.Lock();
2478 m_logEntries.push_back(hash);
2479 m_arShownList.SafeAdd(pRev);
2480 this->m_critSec.Unlock();
2482 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2483 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2485 t2=GetTickCount();
2487 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2489 //update UI
2490 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2491 if(percent > 99)
2492 percent =99;
2493 if(percent < GITLOG_START)
2494 percent = GITLOG_START +1;
2496 oldsize = m_logEntries.size();
2497 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2499 //if( percent > oldprecentage )
2501 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2502 oldprecentage = percent;
2504 t1 = t2;
2507 g_Git.m_critGitDllSec.Lock();
2508 git_close_log(m_DllGitLog);
2509 g_Git.m_critGitDllSec.Unlock();
2513 // restore last selected item
2514 if (lastSelectedHashNItem >= 0)
2516 SetItemState(lastSelectedHashNItem, LVIS_SELECTED, LVIS_SELECTED);
2517 EnsureVisible(lastSelectedHashNItem, FALSE);
2520 //Update UI;
2521 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2522 if (this->m_hWnd)
2523 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2525 InterlockedExchange(&m_bThreadRunning, FALSE);
2527 return 0;
2530 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2532 SafeTerminateThread();
2534 this->SetItemCountEx(0);
2535 this->Clear();
2537 ResetWcRev();
2539 // HACK to hide graph column
2540 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2541 SetColumnWidth(0, 0);
2542 else
2543 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2545 //Update branch and Tag info
2546 ReloadHashMap();
2547 //Assume Thread have exited
2548 //if(!m_bThreadRunning)
2550 m_logEntries.clear();
2552 if(IsCleanFilter)
2554 m_sFilterText.Empty();
2555 m_From=-1;
2556 m_To=-1;
2559 InterlockedExchange(&m_bExitThread,FALSE);
2561 InterlockedExchange(&m_bThreadRunning, TRUE);
2562 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2563 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2565 InterlockedExchange(&m_bThreadRunning, FALSE);
2566 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2567 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2571 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2575 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2576 if (!bMatchCase)
2577 type |= tr1::regex_constants::icase;
2578 pat = tr1::wregex(regexp_str, type);
2579 return true;
2581 catch (exception) {}
2582 return false;
2584 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2587 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2588 CString sRev;
2590 if ((bRegex)&&(m_bFilterWithRegex))
2592 if (m_SelectedFilters & LOGFILTER_BUGID)
2594 if(this->m_bShowBugtraqColumn)
2596 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2598 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2599 if (regex_search(wstring(sBugIds), pat, flags))
2601 return TRUE;
2606 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2608 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2609 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2611 return TRUE;
2615 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2617 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2618 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2620 return TRUE;
2624 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2626 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2628 return TRUE;
2631 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2633 return TRUE;
2637 if (m_SelectedFilters & LOGFILTER_REVS)
2639 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2640 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2642 return TRUE;
2646 if (m_SelectedFilters & LOGFILTER_PATHS)
2648 CTGitPathList *pathList=NULL;
2649 if( pRev->m_IsDiffFiles)
2650 pathList = &pRev->GetFiles(this);
2651 else
2653 if(!pRev->m_IsSimpleListReady)
2654 pRev->SafeGetSimpleList(&g_Git);
2657 if(pathList)
2658 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2660 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2662 return true;
2664 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2666 return true;
2670 for(size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2672 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2674 return true;
2679 else
2681 CString find = m_sFilterText;
2682 find.MakeLower();
2684 if (m_SelectedFilters & LOGFILTER_BUGID)
2686 if(this->m_bShowBugtraqColumn)
2688 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2690 sBugIds.MakeLower();
2691 if ((sBugIds.Find(find) >= 0))
2693 return TRUE;
2698 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2700 CString msg = pRev->GetSubject();
2702 msg = msg.MakeLower();
2703 if ((msg.Find(find) >= 0))
2705 return TRUE;
2709 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2711 CString msg = pRev->GetBody();
2713 msg = msg.MakeLower();
2714 if ((msg.Find(find) >= 0))
2716 return TRUE;
2720 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2722 CString msg = pRev->GetAuthorName();
2723 msg = msg.MakeLower();
2724 if ((msg.Find(find) >= 0))
2726 return TRUE;
2730 if (m_SelectedFilters & LOGFILTER_REVS)
2732 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2733 if ((sRev.Find(find) >= 0))
2735 return TRUE;
2739 if (m_SelectedFilters & LOGFILTER_PATHS)
2741 CTGitPathList *pathList=NULL;
2742 if( pRev->m_IsDiffFiles)
2743 pathList = &pRev->GetFiles(this);
2744 else
2746 if(!pRev->m_IsSimpleListReady)
2747 pRev->SafeGetSimpleList(&g_Git);
2749 if(pathList)
2750 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2752 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2753 CString path = cpath->GetGitOldPathString();
2754 path.MakeLower();
2755 if ((path.Find(find)>=0))
2757 return true;
2759 path = cpath->GetGitPathString();
2760 path.MakeLower();
2761 if ((path.Find(find)>=0))
2763 return true;
2767 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2769 CString path = pRev->m_SimpleFileList[i];
2770 path.MakeLower();
2771 if ((path.Find(find)>=0))
2773 return true;
2777 } // else (from if (bRegex))
2778 return FALSE;
2782 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
2785 pShownlist->SafeRemoveAll();
2787 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2788 bool bRegex = false;
2789 if (m_bFilterWithRegex)
2790 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2792 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2793 CString sRev;
2794 for (DWORD i=0; i<m_logEntries.size(); ++i)
2796 if ((bRegex)&&(m_bFilterWithRegex))
2798 #if 0
2799 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2801 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2802 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2804 pShownlist->SafeAdd(m_logEntries[i]);
2805 continue;
2808 #endif
2809 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2811 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
2812 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
2814 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2815 continue;
2818 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2820 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
2821 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
2823 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2824 continue;
2827 if (m_SelectedFilters & LOGFILTER_PATHS)
2829 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2831 bool bGoing = true;
2832 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2834 CTGitPath cpath = pathList[cpPathIndex];
2835 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
2837 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2838 bGoing = false;
2839 continue;
2841 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
2843 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2844 bGoing = false;
2845 continue;
2847 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
2849 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2850 bGoing = false;
2851 continue;
2855 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2857 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
2859 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2860 continue;
2863 if (m_SelectedFilters & LOGFILTER_REVS)
2865 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2866 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2868 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2869 continue;
2872 } // if (bRegex)
2873 else
2875 CString find = m_sFilterText;
2876 find.MakeLower();
2877 #if 0
2878 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2880 CString sBugIDs = m_logEntries[i]->sBugIDs;
2882 sBugIDs = sBugIDs.MakeLower();
2883 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2885 pShownlist->SafeAdd(m_logEntries[i]);
2886 continue;
2889 #endif
2890 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2892 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
2894 msg = msg.MakeLower();
2895 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2897 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2898 continue;
2901 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2903 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
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_PATHS)
2914 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
2916 bool bGoing = true;
2917 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
2919 CTGitPath cpath = pathList[cpPathIndex];
2920 CString path = cpath.GetGitOldPathString();
2921 path.MakeLower();
2922 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2924 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2925 bGoing = false;
2926 continue;
2928 path = cpath.GetGitPathString();
2929 path.MakeLower();
2930 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2932 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2933 bGoing = false;
2934 continue;
2936 path = cpath.GetActionName();
2937 path.MakeLower();
2938 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2940 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2941 bGoing = false;
2942 continue;
2946 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2948 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
2949 msg = msg.MakeLower();
2950 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2952 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2953 continue;
2956 if (m_SelectedFilters & LOGFILTER_REVS)
2958 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2959 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2961 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
2962 continue;
2965 } // else (from if (bRegex))
2966 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2970 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
2973 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2975 if(m_From == -1)
2976 if(m_To == -1)
2977 return true;
2978 else
2979 return time <= m_To;
2980 else
2981 if(m_To == -1)
2982 return time >= m_From;
2983 else
2984 return ((time >= m_From)&&(time <= m_To));
2986 return TRUE; /* git dll will filter time range */
2988 // return TRUE;
2990 void CGitLogListBase::StartFilter()
2992 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2993 RecalculateShownList(&m_arShownList);
2994 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2997 DeleteAllItems();
2998 SetItemCountEx(ShownCountWithStopped());
2999 RedrawItems(0, ShownCountWithStopped());
3000 Invalidate();
3003 void CGitLogListBase::RemoveFilter()
3006 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3008 m_arShownList.SafeRemoveAll();
3010 // reset the time filter too
3011 #if 0
3012 m_timFrom = (__time64_t(m_tFrom));
3013 m_timTo = (__time64_t(m_tTo));
3014 m_DateFrom.SetTime(&m_timFrom);
3015 m_DateTo.SetTime(&m_timTo);
3016 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3017 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3018 #endif
3020 for (DWORD i=0; i<m_logEntries.size(); ++i)
3022 if(this->m_IsOldFirst)
3024 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3026 else
3028 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3031 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3032 DeleteAllItems();
3033 SetItemCountEx(ShownCountWithStopped());
3034 RedrawItems(0, ShownCountWithStopped());
3036 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3039 void CGitLogListBase::Clear()
3041 m_arShownList.SafeRemoveAll();
3042 DeleteAllItems();
3044 m_logEntries.ClearAll();
3048 void CGitLogListBase::OnDestroy()
3050 // save the column widths to the registry
3051 SaveColumnWidths();
3053 SafeTerminateThread();
3054 SafeTerminateAsyncDiffThread();
3056 int retry = 0;
3057 while(m_LogCache.SaveCache())
3059 if(retry > 5)
3060 break;
3061 Sleep(1000);
3063 retry++;
3065 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3066 // MB_YESNO) == IDNO)
3067 // break;
3070 CHintListCtrl::OnDestroy();
3073 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
3075 UNREFERENCED_PARAMETER(lParam);
3076 CRect rect;
3077 int i=(int)wParam;
3078 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3079 this->InvalidateRect(rect);
3081 return 0;
3085 * Save column widths to the registry
3087 void CGitLogListBase::SaveColumnWidths()
3089 int maxcol = m_ColumnManager.GetColumnCount();
3091 // HACK that graph column is always shown
3092 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3094 for (int col = 0; col < maxcol; col++)
3095 if (m_ColumnManager.IsVisible (col))
3096 m_ColumnManager.ColumnResized (col);
3098 m_ColumnManager.WriteSettings();
3101 int CGitLogListBase::GetHeadIndex()
3103 if(m_HeadHash.IsEmpty())
3104 return -1;
3106 for(int i=0;i<m_arShownList.GetCount();i++)
3108 GitRev *pRev = (GitRev*)m_arShownList[i];
3109 if(pRev)
3111 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3112 return i;
3115 return -1;
3117 void CGitLogListBase::OnFind()
3119 if (!m_pFindDialog)
3121 m_pFindDialog = new CFindDlg(this);
3122 m_pFindDialog->Create(this);
3125 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3127 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3129 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3131 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3132 Default();
3134 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3137 ASSERT(m_pFindDialog != NULL);
3138 bool bFound = false;
3139 int i=0;
3141 if (m_pFindDialog->IsTerminating())
3143 // invalidate the handle identifying the dialog box.
3144 m_pFindDialog = NULL;
3145 return 0;
3148 if(m_pFindDialog->IsRef())
3150 CString str;
3151 str=m_pFindDialog->GetFindString();
3153 CGitHash hash;
3155 if(!str.IsEmpty())
3156 hash = g_Git.GetHash(str + _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3158 if(!hash.IsEmpty())
3160 for (i = 0; i<m_arShownList.GetCount(); i++)
3162 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3163 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3165 bFound = true;
3166 break;
3173 if(m_pFindDialog->FindNext())
3175 //read data from dialog
3176 CString FindText = m_pFindDialog->GetFindString();
3177 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3179 tr1::wregex pat;
3180 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3182 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3185 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3187 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3189 CString str;
3190 str+=pLogEntry->m_CommitHash.ToString();
3191 str+=_T("\n");
3193 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3195 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3196 str+=_T("\n");
3199 str+=pLogEntry->GetAuthorEmail();
3200 str+=_T("\n");
3201 str+=pLogEntry->GetAuthorName();
3202 str+=_T("\n");
3203 str+=pLogEntry->GetBody();
3204 str+=_T("\n");
3205 str+=pLogEntry->GetCommitterEmail();
3206 str+=_T("\n");
3207 str+=pLogEntry->GetCommitterName();
3208 str+=_T("\n");
3209 str+=pLogEntry->GetSubject();
3210 str+=_T("\n");
3213 /*Because changed files list is loaded on demand when gui show,
3214 files will empty when files have not fetched.
3216 we can add it back by using one-way diff(with outnumber changed and rename detect.
3217 here just need changed filename list. one-way is much quicker.
3219 if(pLogEntry->m_IsFull)
3221 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3223 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3224 str+=_T("\n");
3225 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3226 str+=_T("\n");
3229 else
3231 if(!pLogEntry->m_IsSimpleListReady)
3232 pLogEntry->SafeGetSimpleList(&g_Git);
3234 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3236 str+=pLogEntry->m_SimpleFileList[i];
3237 str+=_T("\n");
3243 if (bRegex)
3245 if (regex_search(wstring(str), pat, flags))
3247 bFound = true;
3248 break;
3251 else
3253 if (bMatchCase)
3255 if (str.Find(FindText) >= 0)
3257 bFound = true;
3258 break;
3262 else
3264 CString msg = str;
3265 msg = msg.MakeLower();
3266 CString find = FindText.MakeLower();
3267 if (msg.Find(find) >= 0)
3269 bFound = TRUE;
3270 break;
3274 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3276 } // if(m_pFindDialog->FindNext())
3277 //UpdateLogInfoLabel();
3279 if (bFound)
3281 this->m_nSearchIndex = i;
3282 EnsureVisible(i, FALSE);
3283 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3284 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3285 SetSelectionMark(i);
3286 //FillLogMessageCtrl();
3287 UpdateData(FALSE);
3288 m_nSearchIndex++;
3289 if (m_nSearchIndex >= m_arShownList.GetCount())
3290 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3293 return 0;
3296 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3298 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3300 *pResult = FALSE;
3303 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3305 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3307 Invalidate(FALSE);