1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011 - 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
25 #include "GitLogListBase.h"
27 //#include "VssStyle.h"
32 #include "GITProgressDlg.h"
33 #include "ProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
38 #include "MessageBox.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.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"
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)
70 ,m_bNoDispUpdates(FALSE
)
71 , m_bThreadRunning(FALSE
)
72 , m_bStrictStopped(false)
73 , m_pStoreSelection(NULL
)
74 , m_nSelectedFilter(LOGFILTER_ALL
)
76 , m_logEntries(&m_LogCache
)
78 , m_ColumnManager(this)
79 , m_dwDefaultColumns(0)
80 , m_arShownList(&m_critSec
)
82 // use the default GUI font, create a copy of it and
83 // change the copy to BOLD (leave the rest of the font
85 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
87 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
88 lf
.lfWeight
= FW_BOLD
;
89 m_boldFont
= CreateFontIndirect(&lf
);
91 m_bShowBugtraqColumn
=false;
93 m_IsIDReplaceAction
=FALSE
;
95 this->m_critSec
.Init();
96 m_wcRev
.m_CommitHash
.Empty();
97 m_wcRev
.GetSubject()=_T("Working dir changes");
98 m_wcRev
.m_ParentHash
.clear();
99 m_wcRev
.m_Mark
=_T('-');
100 m_wcRev
.m_IsUpdateing
=FALSE
;
101 m_wcRev
.m_IsFull
= TRUE
;
103 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
104 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
105 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
106 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
107 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
109 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
111 g_Git
.GetMapHashToFriendName(m_HashMap
);
112 m_CurrentBranch
=g_Git
.GetCurrentBranch();
113 this->m_HeadHash
=g_Git
.GetHash(_T("HEAD"));
119 m_LoadingThread
= NULL
;
121 InterlockedExchange(&m_bExitThread
,FALSE
);
122 m_IsOldFirst
= FALSE
;
123 m_IsRebaseReplaceGraph
= FALSE
;
126 for(int i
=0;i
<Lanes::COLORS_NUM
;i
++)
128 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
130 // get short/long datetime setting from registry
131 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
132 if ( RegUseShortDateFormat
)
134 m_DateFormat
= DATE_SHORTDATE
;
138 m_DateFormat
= DATE_LONGDATE
;
140 // get relative time display setting from registry
141 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
142 m_bRelativeTimes
= (regRelativeTimes
!= 0);
143 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
145 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
146 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
147 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
148 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
149 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
150 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
152 m_ColumnRegKey
=_T("log");
154 m_AsyncThreadExit
= FALSE
;
155 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
156 m_AsynDiffListLock
.Init();
158 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
159 if (m_DiffingThread
==NULL
)
161 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
167 int CGitLogListBase::AsyncDiffThread()
169 m_AsyncThreadExited
= false;
170 while(!m_AsyncThreadExit
)
172 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
175 while(!m_AsyncThreadExit
&& m_AsynDiffList
.size() > 0)
177 m_AsynDiffListLock
.Lock();
178 pRev
= m_AsynDiffList
.back();
179 m_AsynDiffList
.pop_back();
180 m_AsynDiffListLock
.Unlock();
182 if( pRev
->m_CommitHash
.IsEmpty() )
184 if(pRev
->m_IsDiffFiles
)
187 pRev
->GetFiles(this).Clear();
188 pRev
->m_ParentHash
.clear();
189 pRev
->m_ParentHash
.push_back(m_HeadHash
);
190 if(g_Git
.IsInitRepos())
192 g_Git
.GetInitAddList(pRev
->GetFiles(this));
197 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
199 pRev
->GetAction(this) = 0;
201 for(int j
=0;j
< pRev
->GetFiles(this).GetCount();j
++)
202 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
204 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
205 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
207 pRev
->GetBody().Format(_T("%d files changed"),pRev
->GetFiles(this).GetCount());
208 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
209 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
212 if(!pRev
->CheckAndDiff())
213 { // fetch change file list
214 for(int i
=GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex()+GetCountPerPage(); i
++)
216 if(i
< m_arShownList
.GetCount())
218 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
219 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
221 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
227 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
229 POSITION pos
= GetFirstSelectedItemPosition();
230 int nItem
= GetNextSelectedItem(pos
);
234 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
236 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
238 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
245 m_AsyncThreadExited
= true;
248 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
252 m_ContextMenuMask
&= hideMask
;
256 m_ContextMenuMask
&= ~hideMask
;
260 CGitLogListBase::~CGitLogListBase()
262 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
263 this->m_arShownList
.SafeRemoveAll();
265 DestroyIcon(m_hModifiedIcon
);
266 DestroyIcon(m_hReplacedIcon
);
267 DestroyIcon(m_hAddedIcon
);
268 DestroyIcon(m_hDeletedIcon
);
269 m_logEntries
.ClearAll();
272 DeleteObject(m_boldFont
);
274 if ( m_pStoreSelection
)
276 delete m_pStoreSelection
;
277 m_pStoreSelection
= NULL
;
280 SafeTerminateThread();
281 SafeTerminateAsyncDiffThread();
284 CloseHandle(m_AsyncDiffEvent
);
288 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
289 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
290 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
291 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
293 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
294 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
297 ON_MESSAGE(MSG_LOADED
,OnLoad
)
299 ON_WM_MEASUREITEM_REFLECT()
300 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
301 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
302 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
303 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
304 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
305 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
308 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
310 //if (m_nRowHeight>0)
312 lpMeasureItemStruct
->itemHeight
= 50;
316 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
319 return CHintListCtrl::OnCreate(lpCreateStruct
);
322 void CGitLogListBase::PreSubclassWindow()
324 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
325 // load the icons for the action columns
326 // m_Theme.Open(m_hWnd, L"ListView");
327 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
328 CHintListCtrl::PreSubclassWindow();
331 void CGitLogListBase::InsertGitColumn()
335 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
336 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
337 if (DWORD(regFullRowSelect
))
338 exStyle
|= LVS_EX_FULLROWSELECT
;
339 SetExtendedStyle(exStyle
);
341 UpdateProjectProperties();
343 static UINT normal
[] =
355 IDS_LOG_COMMIT_EMAIL
,
376 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
378 DWORD hideColumns
= 0;
379 if(this->m_IsRebaseReplaceGraph
)
381 hideColumns
|= GIT_LOG_GRAPH
;
382 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
386 hideColumns
|= GIT_LOG_REBASE
;
389 if(this->m_IsIDReplaceAction
)
391 hideColumns
|= GIT_LOG_ACTIONS
;
392 m_dwDefaultColumns
|= GIT_LOG_ID
;
393 m_dwDefaultColumns
|= GIT_LOG_HASH
;
397 hideColumns
|= GIT_LOG_ID
;
399 if(this->m_bShowBugtraqColumn
)
401 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
405 hideColumns
|= GIT_LOGLIST_BUG
;
409 m_ColumnManager
.SetNames(normal
, _countof(normal
));
410 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
417 * Resizes all columns in a list control to values in registry.
419 void CGitLogListBase::ResizeAllListCtrlCols()
421 // column max and min widths to allow
422 static const int nMinimumWidth
= 10;
423 static const int nMaximumWidth
= 1000;
424 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
427 int numcols
= pHdrCtrl
->GetItemCount();
428 for (int col
= 0; col
< numcols
; col
++)
430 // get width for this col last time from registry
432 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
433 CRegDWORD
regwidth(regentry
, 0);
437 // no saved value, setup sensible defaults
438 if (col
== this->LOGLIST_MESSAGE
)
440 cx
= LOGLIST_MESSAGE_MIN
;
444 cx
= ICONITEMBORDER
+16*4;
447 if (cx
< nMinimumWidth
)
451 else if (cx
> nMaximumWidth
)
456 SetColumnWidth(col
, cx
);
463 BOOL
CGitLogListBase::GetShortName(CString ref
, CString
&shortname
,CString prefix
)
465 //TRACE(_T("%s %s\r\n"),ref,prefix);
466 if(ref
.Left(prefix
.GetLength()) == prefix
)
468 shortname
= ref
.Right(ref
.GetLength()-prefix
.GetLength());
469 if(shortname
.Right(3)==_T("^{}"))
470 shortname
=shortname
.Left(shortname
.GetLength()-3);
476 void CGitLogListBase::FillBackGround(HDC hdc
, int Index
,CRect
&rect
)
480 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
481 rItem
.mask
= LVIF_STATE
;
483 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
486 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
489 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
491 HTHEME hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
492 int state
= LISS_NORMAL
;
493 if (rItem
.state
& LVIS_SELECTED
)
495 if (::GetFocus() == m_hWnd
)
496 state
|= LISS_SELECTED
;
498 state
|= LISS_SELECTEDNOTFOCUS
;
502 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
503 brush
= ::CreateSolidBrush(RGB(156,156,156));
504 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
505 brush
= ::CreateSolidBrush(RGB(200,200,128));
510 ::FillRect(hdc
, &rect
, brush
);
511 ::DeleteObject(brush
);
515 if (IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTITEM
, state
))
516 DrawThemeParentBackground(m_hWnd
, hdc
, &rect
);
518 CRect rectDraw
= rect
;
519 if(rItem
.state
& LVIS_SELECTED
)
520 rectDraw
.InflateRect(1,0);
522 rectDraw
.InflateRect(1,1);
524 DrawThemeBackground(hTheme
, hdc
, LVP_LISTITEM
, state
, rectDraw
, &rect
);
526 CloseThemeData(hTheme
);
530 if (rItem
.state
& LVIS_SELECTED
)
532 if (::GetFocus() == m_hWnd
)
533 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
535 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
539 //if (pLogEntry->bCopiedSelf)
540 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
542 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
543 brush
= ::CreateSolidBrush(RGB(156,156,156));
544 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
545 brush
= ::CreateSolidBrush(RGB(200,200,128));
547 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
552 ::FillRect(hdc
, &rect
, brush
);
553 ::DeleteObject(brush
);
557 void CGitLogListBase::DrawTagBranch(HDC hdc
,CRect
&rect
,INT_PTR index
)
559 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
562 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
563 rItem
.mask
= LVIF_STATE
;
565 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
571 HTHEME hTheme
= NULL
;
572 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
573 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
575 for(unsigned int i
=0;i
<m_HashMap
[data
->m_CommitHash
].size();i
++)
578 str
=m_HashMap
[data
->m_CommitHash
][i
];
585 //Determine label color
586 if(GetShortName(str
,shortname
,_T("refs/heads/")))
588 if( shortname
== m_CurrentBranch
)
589 colRef
= m_Colors
.GetColor(CColors::CurrentBranch
);
591 colRef
= m_Colors
.GetColor(CColors::LocalBranch
);
594 else if(GetShortName(str
,shortname
,_T("refs/remotes/")))
596 colRef
= m_Colors
.GetColor(CColors::RemoteBranch
);
598 else if(GetShortName(str
,shortname
,_T("refs/tags/")))
600 colRef
= m_Colors
.GetColor(CColors::Tag
);
602 else if(GetShortName(str
,shortname
,_T("refs/stash")))
604 colRef
= m_Colors
.GetColor(CColors::Stash
);
605 shortname
=_T("stash");
607 else if(GetShortName(str
,shortname
,_T("refs/bisect/")))
609 if(shortname
.Find(_T("good")) == 0)
611 colRef
= m_Colors
.GetColor(CColors::BisectGood
);
612 shortname
= _T("good");
615 if(shortname
.Find(_T("bad")) == 0)
617 colRef
= m_Colors
.GetColor(CColors::BisectBad
);
618 shortname
= _T("bad");
622 //When row selected, ajust label color
623 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
624 if (rItem
.state
& LVIS_SELECTED
)
625 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
627 brush
= ::CreateSolidBrush(colRef
);
629 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
632 memset(&size
,0,sizeof(SIZE
));
633 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
635 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
638 int textpos
= DT_CENTER
;
640 if(rt
.right
> rect
.right
)
642 rt
.right
= rect
.right
;
646 //Fill interior of ref label
647 ::FillRect(hdc
, &rt
, brush
);
653 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,100), m_Colors
.Darken(colRef
,100));
654 rectEdge
.DeflateRect(1,1);
655 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,50), m_Colors
.Darken(colRef
,50));
657 //Draw text inside label
658 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
660 int txtState
= LISS_NORMAL
;
661 if (rItem
.state
& LVIS_SELECTED
)
662 txtState
= LISS_SELECTED
;
664 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
668 W_Dc
.SetBkMode(TRANSPARENT
);
669 if (rItem
.state
& LVIS_SELECTED
)
671 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
672 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
673 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
674 ::SetTextColor(hdc
,clrOld
);
678 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
682 //::MoveToEx(hdc,rt.left,rt.top,NULL);
683 //::LineTo(hdc,rt.right,rt.top);
684 //::LineTo(hdc,rt.right,rt.bottom);
685 //::LineTo(hdc,rt.left,rt.bottom);
686 //::LineTo(hdc,rt.left,rt.top);
691 ::DeleteObject(brush
);
695 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
697 int txtState
= LISS_NORMAL
;
698 if (rItem
.state
& LVIS_SELECTED
)
699 txtState
= LISS_SELECTED
;
701 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
705 if (rItem
.state
& LVIS_SELECTED
)
707 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
708 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
709 ::SetTextColor(hdc
,clrOld
);
713 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
718 CloseThemeData(hTheme
);
723 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
725 // Returns ((256 - amount)*col1 + amount*col2) / 256;
726 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
727 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
728 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
731 Gdiplus::Color
GetGdiColor(COLORREF col
)
733 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
735 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
736 const COLORREF
& col
,const COLORREF
& activeColor
, int top
739 int h
= laneHeight
/ 2;
740 int m
= (x1
+ x2
) / 2;
741 int r
= (x2
- x1
) / 3;
744 #define P_CENTER m , h+top
745 #define P_0 x2, h+top
746 #define P_90 m , 0+top-1
747 #define P_180 x1, h+top
748 #define P_270 m , 2 * h+top +1
749 #define R_CENTER m - r, h - r+top, d, d
752 #define DELTA_UR_B 2*(x1 - m), 2*h +top
753 #define DELTA_UR_E 0*16, 90*16 +top // -,
755 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
756 #define DELTA_DR_E 270*16, 90*16 +top // -'
758 #define DELTA_UL_B 2*(x2 - m), 2*h +top
759 #define DELTA_UL_E 90*16, 90*16 +top // ,-
761 #define DELTA_DL_B 2*(x2 - m),2*-h +top
762 #define DELTA_DL_E 180*16, 90*16 // '-
764 #define CENTER_UR x1, 2*h, 225
765 #define CENTER_DR x1, 0 , 135
766 #define CENTER_UL x2, 2*h, 315
767 #define CENTER_DL x2, 0 , 45
770 Gdiplus::Graphics
graphics( hdc
);
772 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
781 Gdiplus::LinearGradientBrush
gradient(
782 Gdiplus::Point(x1
-2, h
+top
-2),
783 Gdiplus::Point(P_270
),
784 GetGdiColor(activeColor
),GetGdiColor(col
));
787 Gdiplus::Pen
mypen(&gradient
,2);
788 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
790 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
791 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
792 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
799 Gdiplus::LinearGradientBrush
gradient(
800 Gdiplus::Point(P_270
),
801 Gdiplus::Point(x2
+1, h
+top
-1),
802 GetGdiColor(col
),GetGdiColor(activeColor
));
805 Gdiplus::Pen
mypen(&gradient
,2);
806 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
808 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
809 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
810 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
819 Gdiplus::LinearGradientBrush
gradient(
820 Gdiplus::Point(x1
-2, h
+top
-2),
821 Gdiplus::Point(P_90
),
822 GetGdiColor(activeColor
),GetGdiColor(col
));
824 Gdiplus::Pen
mypen(&gradient
,2);
826 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
829 QConicalGradient
gradient(CENTER_DR
);
830 gradient
.setColorAt(0.375, activeCol
);
831 gradient
.setColorAt(0.625, col
);
832 myPen
.setBrush(gradient
);
834 p
->drawArc(P_CENTER
, DELTA_DR
);
843 //static QPen myPen(Qt::black, 2); // fast path here
845 pen
.CreatePen(PS_SOLID
,2,col
);
846 //myPen.setColor(col);
847 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
849 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
851 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
858 case Lanes::NOT_ACTIVE
:
859 case Lanes::MERGE_FORK
:
860 case Lanes::MERGE_FORK_R
:
861 case Lanes::MERGE_FORK_L
:
866 //DrawLine(hdc,P_90,P_270);
867 graphics
.DrawLine(&myPen
,P_90
,P_270
);
868 //p->drawLine(P_90, P_270);
872 //DrawLine(hdc,P_CENTER,P_270);
873 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
874 //p->drawLine(P_CENTER, P_270);
878 case Lanes::BOUNDARY
:
879 case Lanes::BOUNDARY_C
:
880 case Lanes::BOUNDARY_R
:
881 case Lanes::BOUNDARY_L
:
882 //DrawLine(hdc,P_90, P_CENTER);
883 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
884 //p->drawLine(P_90, P_CENTER);
890 myPen
.SetColor(GetGdiColor(activeColor
));
894 case Lanes::MERGE_FORK
:
899 case Lanes::CROSS_EMPTY
:
900 case Lanes::BOUNDARY_C
:
901 //DrawLine(hdc,P_180,P_0);
902 graphics
.DrawLine(&myPen
,P_180
,P_0
);
903 //p->drawLine(P_180, P_0);
905 case Lanes::MERGE_FORK_R
:
906 case Lanes::BOUNDARY_R
:
907 //DrawLine(hdc,P_180,P_CENTER);
908 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
909 //p->drawLine(P_180, P_CENTER);
911 case Lanes::MERGE_FORK_L
:
914 case Lanes::BOUNDARY_L
:
915 //DrawLine(hdc,P_CENTER,P_0);
916 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
917 //p->drawLine(P_CENTER, P_0);
923 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
926 brush
.CreateSolidBrush(col
);
927 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
929 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
930 // center symbol, e.g. rect or ellipse
936 //p->setPen(Qt::NoPen);
938 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
939 graphics
.FillEllipse(&myBrush
, R_CENTER
);
940 //p->drawEllipse(R_CENTER);
942 case Lanes::MERGE_FORK
:
943 case Lanes::MERGE_FORK_R
:
944 case Lanes::MERGE_FORK_L
:
945 //p->setPen(Qt::NoPen);
947 //p->drawRect(R_CENTER);
948 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
949 graphics
.FillRectangle(&myBrush
, R_CENTER
);
951 case Lanes::UNAPPLIED
:
953 //p->setPen(Qt::NoPen);
954 //p->setBrush(Qt::red);
955 //p->drawRect(m - r, h - 1, d, 2);
956 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
957 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
961 //p->setPen(Qt::NoPen);
962 //p->setBrush(DARK_GREEN);
963 //p->drawRect(m - r, h - 1, d, 2);
964 //p->drawRect(m - 1, h - r, 2, d);
965 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
966 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
967 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
969 case Lanes::BOUNDARY
:
971 //p->drawEllipse(R_CENTER);
972 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
973 graphics
.DrawEllipse(&myPen
, R_CENTER
);
975 case Lanes::BOUNDARY_C
:
976 case Lanes::BOUNDARY_R
:
977 case Lanes::BOUNDARY_L
:
979 //p->drawRect(R_CENTER);
980 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
981 graphics
.FillRectangle(&myBrush
,R_CENTER
);
987 ::SelectObject(hdc
,oldpen
);
988 ::SelectObject(hdc
,oldbrush
);
997 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1001 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1002 if(data
->m_CommitHash
.IsEmpty())
1007 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1008 rItem
.mask
= LVIF_STATE
;
1009 rItem
.iItem
= index
;
1010 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1013 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1015 if (data
->m_Lanes
.size() == 0)
1016 m_logEntries
.setLane(data
->m_CommitHash
);
1018 std::vector
<int>& lanes
=data
->m_Lanes
;
1019 UINT laneNum
= lanes
.size();
1020 UINT activeLane
= 0;
1021 for (UINT i
= 0; i
< laneNum
; i
++)
1022 if (Lanes::isMerge(lanes
[i
])) {
1028 int maxWidth
= rect
.Width();
1029 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1031 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1032 //if (opt.state & QStyle::State_Selected)
1033 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1035 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++)
1042 if (ln
== Lanes::EMPTY
)
1045 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1046 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1050 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++) {
1056 if (ln
== Lanes::EMPTY
)
1059 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1060 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1062 if (ln
== Lanes::CROSS
)
1064 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1065 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1068 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1074 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1077 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1078 // Take the default processing unless we set this to something else below.
1079 *pResult
= CDRF_DODEFAULT
;
1081 if (m_bNoDispUpdates
)
1086 switch (pLVCD
->nmcd
.dwDrawStage
)
1090 *pResult
= CDRF_NOTIFYITEMDRAW
;
1094 case CDDS_ITEMPREPAINT
:
1096 // This is the prepaint stage for an item. Here's where we set the
1097 // item's text color.
1099 // Tell Windows to send draw notifications for each subitem.
1100 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1102 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1104 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1106 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1110 if (data
->bCopiedSelf
)
1112 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
1113 if (!IsAppThemed()) || !m_bVista
|| ((pLVCD
->nmcd
.uItemState
& CDIS_HOT
)==0))
1114 pLVCD
->clrTextBk
= GetSysColor(COLOR_MENU
);
1118 crText
= m_Colors
.GetColor(CColors::Modified
);
1120 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1121 crText
= RGB(128,128,128);
1123 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1124 pLVCD
->clrTextBk
= RGB(156,156,156);
1125 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1126 pLVCD
->clrTextBk
= RGB(200,200,128);
1128 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1130 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1132 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1133 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1136 if(data
->m_CommitHash
.ToString() == m_HeadHash
)
1138 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1139 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1142 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1143 // crText = GetSysColor(COLOR_GRAYTEXT);
1145 if (data
->m_CommitHash
.IsEmpty())
1147 //crText = GetSysColor(RGB(200,200,0));
1148 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1149 // We changed the font, so we're returning CDRF_NEWFONT. This
1150 // tells the control to recalculate the extent of the text.
1151 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1155 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1157 if (m_bStrictStopped
)
1158 crText
= GetSysColor(COLOR_GRAYTEXT
);
1160 // Store the color back in the NMLVCUSTOMDRAW struct.
1161 pLVCD
->clrText
= crText
;
1165 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1167 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1169 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1172 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
)
1174 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1177 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1179 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1180 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1182 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1183 if( !data
->m_CommitHash
.IsEmpty())
1184 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1186 *pResult
= CDRF_SKIPDEFAULT
;
1191 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1193 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1195 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1196 //if(!data->m_IsFull)
1198 //if(data->SafeFetchFullInfo(&g_Git))
1199 // this->Invalidate();
1200 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1203 if(m_HashMap
[data
->m_CommitHash
].size()!=0)
1207 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1209 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1210 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1212 *pResult
= CDRF_SKIPDEFAULT
;
1220 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1222 if(this->m_IsIDReplaceAction
)
1224 *pResult
= CDRF_DODEFAULT
;
1227 *pResult
= CDRF_DODEFAULT
;
1229 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1233 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1234 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1236 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1238 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1239 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1240 // Get the selected state of the
1241 // item being drawn.
1243 // Fill the background
1244 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1246 // Draw the icon(s) into the compatible DC
1247 pLogEntry
->GetAction(this);
1249 if (!pLogEntry
->m_IsDiffFiles
)
1250 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1252 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1253 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1256 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1257 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1260 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1261 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1264 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1265 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1267 *pResult
= CDRF_SKIPDEFAULT
;
1273 *pResult
= CDRF_DODEFAULT
;
1276 // CGitLogListBase message handlers
1278 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1280 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1282 // Create a pointer to the item
1283 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1285 // Do the list need text information?
1286 if (!(pItem
->mask
& LVIF_TEXT
))
1289 // By default, clear text buffer.
1290 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1292 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1295 if (m_bNoDispUpdates
|| bOutOfRange
)
1298 // Which item number?
1299 int itemid
= pItem
->iItem
;
1300 GitRev
* pLogEntry
= NULL
;
1301 if (itemid
< m_arShownList
.GetCount())
1302 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1307 temp
.Format(_T("%d"),pItem
->iItem
+1);
1312 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1316 switch (pItem
->iSubItem
)
1318 case this->LOGLIST_GRAPH
: //Graphic
1320 case this->LOGLIST_REBASE
:
1322 if(this->m_IsRebaseReplaceGraph
)
1325 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1326 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1330 case this->LOGLIST_ACTION
: //action -- no text in the column
1332 case this->LOGLIST_HASH
:
1334 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1336 case this->LOGLIST_ID
:
1337 if(this->m_IsIDReplaceAction
)
1338 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1340 case this->LOGLIST_MESSAGE
: //Message
1342 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1344 case this->LOGLIST_AUTHOR
: //Author
1346 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1348 case this->LOGLIST_DATE
: //Date
1349 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1350 lstrcpyn(pItem
->pszText
,
1351 CAppUtils::FormatDateAndTime( pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1355 case this->LOGLIST_EMAIL
:
1357 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1360 case this->LOGLIST_COMMIT_NAME
: //Commit
1362 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1365 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1367 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1370 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1372 lstrcpyn(pItem
->pszText
,
1373 CAppUtils::FormatDateAndTime( pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1376 case this->LOGLIST_BUG
: //Bug ID
1378 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject()), pItem
->cchTextMax
);
1386 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1389 if (pWnd
== GetHeaderCtrl())
1391 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1394 int selIndex
= GetSelectionMark();
1396 return; // nothing selected, nothing to do with a context menu
1398 // if the user selected the info text telling about not all revisions shown due to
1399 // the "stop on copy/rename" option, we also don't show the context menu
1400 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1403 // if the context menu is invoked through the keyboard, we have to use
1404 // a calculated position on where to anchor the menu on
1405 if ((point
.x
== -1) && (point
.y
== -1))
1408 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1409 ClientToScreen(&rect
);
1410 point
= rect
.CenterPoint();
1412 m_nSearchIndex
= selIndex
;
1413 m_bCancelled
= FALSE
;
1415 // calculate some information the context menu commands can use
1416 // CString pathURL = GetURLFromPath(m_path);
1418 POSITION pos
= GetFirstSelectedItemPosition();
1419 int indexNext
= GetNextSelectedItem(pos
);
1423 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1425 GitRev revSelected
= pSelLogEntry
->Rev
;
1426 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1427 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1429 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1431 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1432 if (changedpath
->lCopyFromRev
)
1433 revPrevious
= changedpath
->lCopyFromRev
;
1436 GitRev revSelected2
;
1439 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1440 revSelected2
= pLogEntry
->Rev
;
1442 bool bAllFromTheSameAuthor
= true;
1443 CString firstAuthor
;
1444 CLogDataVector selEntries
;
1445 GitRev revLowest
, revHighest
;
1446 GitRevRangeArray revisionRanges
;
1448 POSITION pos
= GetFirstSelectedItemPosition();
1449 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1450 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1451 selEntries
.push_back(pLogEntry
);
1452 firstAuthor
= pLogEntry
->sAuthor
;
1453 revLowest
= pLogEntry
->Rev
;
1454 revHighest
= pLogEntry
->Rev
;
1457 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1458 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1459 selEntries
.push_back(pLogEntry
);
1460 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1461 bAllFromTheSameAuthor
= false;
1462 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1463 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1469 int FirstSelect
=-1, LastSelect
=-1;
1470 pos
= GetFirstSelectedItemPosition();
1471 FirstSelect
= GetNextSelectedItem(pos
);
1474 LastSelect
= GetNextSelectedItem(pos
);
1476 //entry is selected, now show the popup menu
1478 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
,diffmenu
;
1480 if (popup
.CreatePopupMenu())
1482 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1484 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1485 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1487 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1488 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1490 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1491 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1493 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1494 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1496 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1497 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1498 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1500 if (GetSelectedCount() == 1)
1504 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1506 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
))
1507 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1509 // TortoiseMerge could be improved to take a /blame switch
1510 // and then not 'cat' the files from a unified diff but
1512 // But until that's implemented, the context menu entry for
1513 // this feature is commented out.
1514 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1518 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1519 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1521 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
))
1523 GitRev
*pRev
=pSelLogEntry
;
1524 if(pSelLogEntry
->m_ParentHash
.size()==0)
1526 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1528 if(pRev
->m_ParentHash
.size()<=1)
1530 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1535 gnudiffmenu
.CreatePopupMenu();
1536 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1538 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+(0xFFFF<<16),_T("All Parents"));
1539 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+(0xFFFE<<16),_T("Only Merged Files"));
1541 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1544 str
.Format(_T("Parent %d"), i
+1);
1545 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1550 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1553 GitRev
*pRev
=pSelLogEntry
;
1554 if(pSelLogEntry
->m_ParentHash
.size()==0)
1556 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1558 if(pRev
->m_ParentHash
.size()<=1)
1560 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1561 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1562 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1566 diffmenu
.CreatePopupMenu();
1567 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1568 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1571 str
.Format(_T("Parent %d"), i
+1);
1572 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1573 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1575 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1576 diffmenu
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16), FALSE
);
1582 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1583 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1585 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1586 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1589 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1591 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1593 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1595 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1597 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1598 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1600 // popup.AppendMenu(MF_SEPARATOR, NULL);
1605 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1607 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1609 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1610 GetSelectedCount() == 1)
1611 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1613 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1614 str
.Format(format
,g_Git
.GetCurrentBranch());
1616 bool thisbranch
= false;
1617 CString currentBranch
= _T("refs/heads/")+g_Git
.GetCurrentBranch();
1618 for(int i
=0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1620 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == currentBranch
)
1625 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
)
1626 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1628 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1629 str
.Format(format
,g_Git
.GetCurrentBranch());
1631 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
))
1632 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1635 // Add Switch Branch express Menu
1636 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1637 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
))
1640 std::vector
<CString
*> branchs
;
1643 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1645 ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1646 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1648 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1653 str
.LoadString(IDS_SWITCH_BRANCH
);
1655 if(branchs
.size() == 1)
1658 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1659 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1661 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1664 else if(branchs
.size() > 1)
1666 subbranchmenu
.CreatePopupMenu();
1667 for(int i
=0;i
<branchs
.size();i
++)
1669 if (*branchs
[i
] != currentBranch
)
1671 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1672 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1676 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1680 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
)
1681 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1683 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1684 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1686 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1687 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1689 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1690 str
.Format(format
,g_Git
.GetCurrentBranch());
1692 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
)
1693 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1694 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1696 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1697 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1699 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
))
1700 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1702 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1703 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1705 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1710 if(!pSelLogEntry
->m_Ref
.IsEmpty() && GetSelectedCount() == 1)
1712 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1713 popup
.AppendMenuIcon(ID_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
))
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
))
1730 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1731 bAddSeparator
= true;
1736 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1738 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1739 bAddSeparator
= true;
1742 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
))
1743 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
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
))
1758 headindex
= this->GetHeadIndex();
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
) {
1772 if (GetSelectedCount() >= 2)
1773 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
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;
1786 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1790 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1792 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1794 // if (GetSelectedCount() == 1)
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);
1802 if (GetSelectedCount() == 1)
1804 bool bAddSeparator
= false;
1805 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && m_HashMap
[pSelLogEntry
->m_CommitHash
].size() >= 1)
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)
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() )
1826 if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() == 1 )
1828 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1830 str
+=m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
1831 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1832 bAddSeparator
= true;
1834 else if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() > 1 )
1836 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1837 submenu
.CreatePopupMenu();
1838 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1840 submenu
.AppendMenuIcon(ID_DELETE
+(i
<<16),m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1843 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
1844 bAddSeparator
= true;
1847 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1849 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1850 } // GetSelectedCount() == 1
1852 if (GetSelectedCount() == 1)
1854 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1855 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
1857 if (GetSelectedCount() != 0)
1859 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1860 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
1863 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1864 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
1866 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1867 // DialogEnableWindow(IDOK, FALSE);
1868 // SetPromptApp(&theApp);
1870 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
1872 // EnableOKButton();
1873 } // if (popup.CreatePopupMenu())
1877 bool CGitLogListBase::IsSelectionContinuous()
1879 if ( GetSelectedCount()==1 )
1881 // if only one revision is selected, the selection is of course
1886 POSITION pos
= GetFirstSelectedItemPosition();
1887 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1890 int itemindex
= GetNextSelectedItem(pos
);
1893 int nextindex
= GetNextSelectedItem(pos
);
1894 if (nextindex
- itemindex
> 1)
1896 bContinuous
= false;
1899 itemindex
= nextindex
;
1905 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly
)
1909 POSITION pos
= GetFirstSelectedItemPosition();
1913 sRev
.LoadString(IDS_LOG_REVISION
);
1915 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1917 sDate
.LoadString(IDS_LOG_DATE
);
1919 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1922 CString sLogCopyText
;
1924 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1928 //pLogEntry->GetFiles(this)
1929 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1931 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
1933 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(" : ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
1934 sPaths
+= _T("\r\n");
1937 CString body
= pLogEntry
->GetBody();
1938 body
.Replace(_T("\n"), _T("\r\n"));
1939 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"),
1940 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
1941 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(),
1943 (LPCTSTR
)CAppUtils::FormatDateAndTime( pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1944 (LPCTSTR
)sMessage
, pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim(),
1946 sClipdata
+= sLogCopyText
;
1950 sClipdata
+= pLogEntry
->m_CommitHash
;
1955 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1960 void CGitLogListBase::DiffSelectedRevWithPrevious()
1962 if (m_bThreadRunning
)
1965 int FirstSelect
=-1, LastSelect
=-1;
1966 POSITION pos
= GetFirstSelectedItemPosition();
1967 FirstSelect
= GetNextSelectedItem(pos
);
1970 LastSelect
= GetNextSelectedItem(pos
);
1973 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
1976 UpdateLogInfoLabel();
1977 int selIndex
= m_LogList
.GetSelectionMark();
1980 int selCount
= m_LogList
.GetSelectedCount();
1984 // Find selected entry in the log list
1985 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
1986 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
1987 long rev1
= pLogEntry
->Rev
;
1989 CTGitPath path
= m_path
;
1991 // See how many files under the relative root were changed in selected revision
1993 LogChangedPath
* changed
= NULL
;
1994 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
1996 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
1997 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2004 if (m_path
.IsDirectory() && nChanged
== 1)
2006 // We're looking at the log for a directory and only one file under dir was changed in the revision
2007 // Do diff on that file instead of whole directory
2008 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2011 m_bCancelled
= FALSE
;
2012 DialogEnableWindow(IDOK
, FALSE
);
2013 SetPromptApp(&theApp
);
2014 theApp
.DoWaitCursor(1);
2018 GitDiff
diff(this, m_hWnd
, true);
2019 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2020 diff
.SetHEADPeg(m_LogRevision
);
2021 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2025 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2028 theApp
.DoWaitCursor(-1);
2033 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2035 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2038 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2040 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2042 if (pFindInfo
->lvfi
.psz
== 0)
2045 CString sCmp
= pFindInfo
->lvfi
.psz
;
2047 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2049 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2050 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2051 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2053 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2061 if (sCmp
.Compare(sRev
)==0)
2068 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2070 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2072 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2073 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2074 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2076 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2084 if (sCmp
.Compare(sRev
)==0)
2096 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
2101 this->m_arShownList
.SafeRemoveAll();
2103 this->m_logEntries
.ClearAll();
2104 this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
);
2106 //this->m_logEntries.ParserFromLog();
2107 SetItemCountEx(this->m_logEntries
.size());
2109 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2113 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2114 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2119 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2120 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2130 int CGitLogListBase::BeginFetchLog()
2134 this->m_arShownList
.SafeRemoveAll();
2136 this->m_logEntries
.ClearAll();
2139 this->m_LogCache
.ClearAllParent();
2141 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2144 if(this->m_Path
.IsEmpty())
2151 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2152 // if(this->m_bAllBranch)
2153 mask
|= m_ShowMask
;
2157 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2159 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2162 CString
*pFrom
, *pTo
;
2164 CString
head(_T("HEAD"));
2165 if(!this->m_startrev
.IsEmpty())
2167 pFrom
= &this->m_startrev
;
2168 if(!this->m_endrev
.IsEmpty())
2169 pTo
= &this->m_endrev
;
2175 data
.m_From
= m_From
;
2178 #if 0 /* use tortoiegit filter */
2179 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2180 data
.m_Author
= this->m_sFilterText
;
2182 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2183 data
.m_MessageFilter
= this->m_sFilterText
;
2185 data
.m_IsRegex
= m_bFilterWithRegex
;
2188 CString cmd
=g_Git
.GetLogCmd(m_StartRef
,path
,-1,mask
,pFrom
,pTo
,true,&data
);
2190 //this->m_logEntries.ParserFromLog();
2191 if(IsInWorkingThread())
2193 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2197 SetItemCountEx(this->m_logEntries
.size());
2202 if(g_Git
.IsInitRepos())
2205 if(git_open_log(&m_DllGitLog
,CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
2213 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2215 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2217 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2219 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2221 DiffSelectedRevWithPrevious();
2226 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2233 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2235 // select all entries
2236 for (int i
=0; i
<GetItemCount(); ++i
)
2238 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2244 if (m_hAccel
&& !bSkipAccelerator
)
2246 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2252 //m_tooltips.RelayEvent(pMsg);
2253 return __super::PreTranslateMessage(pMsg
);
2256 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2258 // a double click on an entry in the revision list has happened
2261 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2262 DiffSelectedRevWithPrevious();
2265 int CGitLogListBase::FetchLogAsync(void * data
)
2268 m_bExitThread
=FALSE
;
2269 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2270 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2271 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2272 if (m_LoadingThread
==NULL
)
2274 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2275 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2276 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2282 //this is the thread function which calls the subversion function
2283 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2285 return ((CGitLogListBase
*)pVoid
)->LogThread();
2288 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2291 oldest
=CTime::GetCurrentTime();
2292 latest
=CTime(1971,1,2,0,0,0);
2293 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2295 if(m_logEntries
[i
].IsEmpty())
2298 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2299 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2301 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2302 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2310 UINT
CGitLogListBase::LogThread()
2312 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2314 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2315 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2321 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2322 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2327 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2328 bool bRegex
= false;
2329 if (m_bFilterWithRegex
)
2330 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2332 TRACE(_T("\n===Begin===\n"));
2333 //Update work copy item;
2335 if( m_logEntries
.size() > 0)
2337 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2339 m_arShownList
.SafeAdd(pRev
);
2343 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2345 // store commit number of the last selected commit/line before the refresh or -1
2346 int lastSelectedHashNItem
= -1;
2348 if(!g_Git
.IsInitRepos())
2350 g_Git
.m_critGitDllSec
.Lock();
2351 git_get_log_firstcommit(m_DllGitLog
);
2352 int total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2353 g_Git
.m_critGitDllSec
.Unlock();
2356 t2
=t1
=GetTickCount();
2357 int oldprecentage
= 0;
2358 int oldsize
=m_logEntries
.size();
2362 g_Git
.m_critGitDllSec
.Lock();
2363 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, 0);
2364 g_Git
.m_critGitDllSec
.Unlock();
2369 //printf("%s\r\n",commit.GetSubject());
2373 CGitHash hash
= (char*)commit
.m_hash
;
2375 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2376 pRev
->m_GitCommit
= commit
;
2377 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2380 g_Git
.m_critGitDllSec
.Lock();
2381 git_get_notes(commit
.m_hash
,¬e
);
2382 g_Git
.m_critGitDllSec
.Unlock();
2386 pRev
->m_Notes
.Empty();
2387 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2390 if(!pRev
->m_IsDiffFiles
)
2392 pRev
->m_CallDiffAsync
= DiffAsync
;
2395 pRev
->ParserParentFromCommit(&commit
);
2402 if(!m_sFilterText
.IsEmpty())
2404 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2407 this->m_critSec
.Lock();
2408 m_logEntries
.push_back(hash
);
2409 m_arShownList
.SafeAdd(pRev
);
2410 this->m_critSec
.Unlock();
2412 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2413 lastSelectedHashNItem
= m_arShownList
.GetCount() - 1;
2417 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2420 int percent
=m_logEntries
.size()*100/total
+ GITLOG_START
+1;
2423 if(percent
< GITLOG_START
)
2424 percent
= GITLOG_START
+1;
2426 oldsize
= m_logEntries
.size();
2427 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2429 //if( percent > oldprecentage )
2431 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2432 oldprecentage
= percent
;
2437 g_Git
.m_critGitDllSec
.Lock();
2438 git_close_log(m_DllGitLog
);
2439 g_Git
.m_critGitDllSec
.Unlock();
2443 // restore last selected item
2444 if (lastSelectedHashNItem
>= 0)
2446 SetItemState(lastSelectedHashNItem
, LVIS_SELECTED
, LVIS_SELECTED
);
2447 EnsureVisible(lastSelectedHashNItem
, FALSE
);
2451 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2452 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2454 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2459 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2461 SafeTerminateThread();
2463 this->SetItemCountEx(0);
2468 //Update branch and Tag info
2470 //Assume Thread have exited
2471 //if(!m_bThreadRunning)
2473 m_logEntries
.clear();
2477 m_sFilterText
.Empty();
2482 InterlockedExchange(&m_bExitThread
,FALSE
);
2484 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2485 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2486 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2488 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2489 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2490 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2494 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2498 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2500 type
|= tr1::regex_constants::icase
;
2501 pat
= tr1::wregex(regexp_str
, type
);
2504 catch (exception
) {}
2507 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2510 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2513 if ((bRegex
)&&(m_bFilterWithRegex
))
2515 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2517 if(this->m_bShowBugtraqColumn
)
2519 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject());
2521 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2522 if (regex_search(wstring(sBugIds
), pat
, flags
))
2529 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2531 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2532 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2538 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2540 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2541 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2547 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2549 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2554 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2560 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2562 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2563 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2569 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2571 CTGitPathList
*pathList
=NULL
;
2572 if( pRev
->m_IsDiffFiles
)
2573 pathList
= &pRev
->GetFiles(this);
2576 if(!pRev
->m_IsSimpleListReady
)
2577 pRev
->SafeGetSimpleList(&g_Git
);
2581 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2583 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2587 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2593 for(INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2595 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2604 CString find
= m_sFilterText
;
2607 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2609 if(this->m_bShowBugtraqColumn
)
2611 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject());
2613 sBugIds
.MakeLower();
2614 if ((sBugIds
.Find(find
) >= 0))
2621 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2623 CString msg
= pRev
->GetSubject();
2625 msg
= msg
.MakeLower();
2626 if ((msg
.Find(find
) >= 0))
2632 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2634 CString msg
= pRev
->GetBody();
2636 msg
= msg
.MakeLower();
2637 if ((msg
.Find(find
) >= 0))
2643 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2645 CString msg
= pRev
->GetAuthorName();
2646 msg
= msg
.MakeLower();
2647 if ((msg
.Find(find
) >= 0))
2653 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2655 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2656 if ((sRev
.Find(find
) >= 0))
2662 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2664 CTGitPathList
*pathList
=NULL
;
2665 if( pRev
->m_IsDiffFiles
)
2666 pathList
= &pRev
->GetFiles(this);
2669 if(!pRev
->m_IsSimpleListReady
)
2670 pRev
->SafeGetSimpleList(&g_Git
);
2673 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
2675 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
2676 CString path
= cpath
->GetGitOldPathString();
2678 if ((path
.Find(find
)>=0))
2682 path
= cpath
->GetGitPathString();
2684 if ((path
.Find(find
)>=0))
2690 for (INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2692 CString path
= pRev
->m_SimpleFileList
[i
];
2694 if ((path
.Find(find
)>=0))
2700 } // else (from if (bRegex))
2705 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
2708 pShownlist
->SafeRemoveAll();
2710 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2711 bool bRegex
= false;
2712 if (m_bFilterWithRegex
)
2713 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2715 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2717 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2719 if ((bRegex
)&&(m_bFilterWithRegex
))
2722 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2724 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2725 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2727 pShownlist
->SafeAdd(m_logEntries
[i
]);
2732 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2734 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
2735 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
2737 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2741 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2743 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
2744 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
2746 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2750 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2752 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2755 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2757 CTGitPath cpath
= pathList
[cpPathIndex
];
2758 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2760 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2764 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2766 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2770 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
2772 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2778 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2780 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
2782 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2786 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2788 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2789 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2791 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2798 CString find
= m_sFilterText
;
2801 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2803 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2805 sBugIDs
= sBugIDs
.MakeLower();
2806 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2808 pShownlist
->SafeAdd(m_logEntries
[i
]);
2813 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2815 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
2817 msg
= msg
.MakeLower();
2818 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2820 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2824 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2826 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
2828 msg
= msg
.MakeLower();
2829 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2831 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2835 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2837 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2840 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2842 CTGitPath cpath
= pathList
[cpPathIndex
];
2843 CString path
= cpath
.GetGitOldPathString();
2845 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2847 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2851 path
= cpath
.GetGitPathString();
2853 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2855 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2859 path
= cpath
.GetActionName();
2861 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2863 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2869 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2871 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
2872 msg
= msg
.MakeLower();
2873 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2875 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2879 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2881 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2882 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2884 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2888 } // else (from if (bRegex))
2889 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2893 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
2896 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2902 return time <= m_To;
2905 return time >= m_From;
2907 return ((time >= m_From)&&(time <= m_To));
2909 return TRUE
; /* git dll will filter time range */
2913 void CGitLogListBase::StartFilter()
2915 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2916 RecalculateShownList(&m_arShownList
);
2917 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2921 SetItemCountEx(ShownCountWithStopped());
2922 RedrawItems(0, ShownCountWithStopped());
2926 void CGitLogListBase::RemoveFilter()
2929 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2931 m_arShownList
.SafeRemoveAll();
2933 // reset the time filter too
2935 m_timFrom
= (__time64_t(m_tFrom
));
2936 m_timTo
= (__time64_t(m_tTo
));
2937 m_DateFrom
.SetTime(&m_timFrom
);
2938 m_DateTo
.SetTime(&m_timTo
);
2939 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
2940 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
2943 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2945 if(this->m_IsOldFirst
)
2947 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2951 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2954 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2956 SetItemCountEx(ShownCountWithStopped());
2957 RedrawItems(0, ShownCountWithStopped());
2959 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2962 void CGitLogListBase::Clear()
2964 m_arShownList
.SafeRemoveAll();
2967 m_logEntries
.ClearAll();
2971 void CGitLogListBase::OnDestroy()
2973 // save the column widths to the registry
2976 SafeTerminateThread();
2977 SafeTerminateAsyncDiffThread();
2980 while(m_LogCache
.SaveCache())
2988 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2989 // MB_YESNO) == IDNO)
2993 CHintListCtrl::OnDestroy();
2996 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
2998 UNREFERENCED_PARAMETER(lParam
);
3001 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3002 this->InvalidateRect(rect
);
3008 * Save column widths to the registry
3010 void CGitLogListBase::SaveColumnWidths()
3012 int maxcol
= m_ColumnManager
.GetColumnCount();
3014 for (int col
= 0; col
< maxcol
; col
++)
3015 if (m_ColumnManager
.IsVisible (col
))
3016 m_ColumnManager
.ColumnResized (col
);
3018 m_ColumnManager
.WriteSettings();
3021 int CGitLogListBase::GetHeadIndex()
3023 if(m_HeadHash
.IsEmpty())
3026 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
3028 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
3031 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3037 void CGitLogListBase::OnFind()
3041 m_pFindDialog
= new CFindDlg(this);
3042 m_pFindDialog
->Create(this);
3045 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3047 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3049 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3051 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3054 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3057 ASSERT(m_pFindDialog
!= NULL
);
3058 bool bFound
= false;
3061 if (m_pFindDialog
->IsTerminating())
3063 // invalidate the handle identifying the dialog box.
3064 m_pFindDialog
= NULL
;
3068 if(m_pFindDialog
->IsRef())
3071 str
=m_pFindDialog
->GetFindString();
3076 hash
= g_Git
.GetHash(str
);
3080 for (i
= 0; i
<m_arShownList
.GetCount(); i
++)
3082 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3083 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3093 if(m_pFindDialog
->FindNext())
3095 //read data from dialog
3096 CString FindText
= m_pFindDialog
->GetFindString();
3097 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3100 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3102 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3105 for (i
= this->m_nSearchIndex
; i
<m_arShownList
.GetCount()&&!bFound
; i
++)
3107 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3110 str
+=pLogEntry
->m_CommitHash
.ToString();
3113 for(int j
=0;j
<this->m_HashMap
[pLogEntry
->m_CommitHash
].size();j
++)
3115 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3119 str
+=pLogEntry
->GetAuthorEmail();
3121 str
+=pLogEntry
->GetAuthorName();
3123 str
+=pLogEntry
->GetBody();
3125 str
+=pLogEntry
->GetCommitterEmail();
3127 str
+=pLogEntry
->GetCommitterName();
3129 str
+=pLogEntry
->GetSubject();
3133 /*Because changed files list is loaded on demand when gui show,
3134 files will empty when files have not fetched.
3136 we can add it back by using one-way diff(with outnumber changed and rename detect.
3137 here just need changed filename list. one-way is much quicker.
3139 if(pLogEntry
->m_IsFull
)
3141 for(int i
=0;i
<pLogEntry
->GetFiles(this).GetCount();i
++)
3143 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3145 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3151 if(!pLogEntry
->m_IsSimpleListReady
)
3152 pLogEntry
->SafeGetSimpleList(&g_Git
);
3154 for(int i
=0;i
<pLogEntry
->m_SimpleFileList
.size();i
++)
3156 str
+=pLogEntry
->m_SimpleFileList
[i
];
3165 if (regex_search(wstring(str
), pat
, flags
))
3175 if (str
.Find(FindText
) >= 0)
3185 msg
= msg
.MakeLower();
3186 CString find
= FindText
.MakeLower();
3187 if (msg
.Find(find
) >= 0)
3194 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3196 } // if(m_pFindDialog->FindNext())
3197 //UpdateLogInfoLabel();
3201 this->m_nSearchIndex
= i
;
3202 EnsureVisible(i
, FALSE
);
3203 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3204 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3205 SetSelectionMark(i
);
3206 //FillLogMessageCtrl();
3209 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3210 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3216 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3218 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3223 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3225 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);