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
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"
40 #include "LoglistUtils.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_SelectedFilters(LOGFILTER_ALL
)
76 , m_logEntries(&m_LogCache
)
78 , m_ColumnManager(this)
79 , m_dwDefaultColumns(0)
80 , m_arShownList(&m_critSec
)
83 // use the default GUI font, create a copy of it and
84 // change the copy to BOLD (leave the rest of the font
86 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
88 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
89 lf
.lfWeight
= FW_BOLD
;
90 m_boldFont
= CreateFontIndirect(&lf
);
92 m_bShowBugtraqColumn
=false;
94 m_IsIDReplaceAction
=FALSE
;
96 this->m_critSec
.Init();
97 m_wcRev
.m_CommitHash
.Empty();
98 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
99 m_wcRev
.m_ParentHash
.clear();
100 m_wcRev
.m_Mark
=_T('-');
101 m_wcRev
.m_IsUpdateing
=FALSE
;
102 m_wcRev
.m_IsFull
= TRUE
;
104 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
105 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
106 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
107 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
108 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
110 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
112 g_Git
.GetMapHashToFriendName(m_HashMap
);
113 if (CTGitPath(g_Git
.m_CurrentDir
).HasAdminDir())
115 m_CurrentBranch
=g_Git
.GetCurrentBranch();
117 m_HeadHash
=g_Git
.GetHash(_T("HEAD"));
122 MessageBox(_T("Could not get HEAD hash.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
131 m_LoadingThread
= NULL
;
133 InterlockedExchange(&m_bExitThread
,FALSE
);
134 m_IsOldFirst
= FALSE
;
135 m_IsRebaseReplaceGraph
= FALSE
;
138 for(int i
=0;i
<Lanes::COLORS_NUM
;i
++)
140 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
142 // get short/long datetime setting from registry
143 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
144 if ( RegUseShortDateFormat
)
146 m_DateFormat
= DATE_SHORTDATE
;
150 m_DateFormat
= DATE_LONGDATE
;
152 // get relative time display setting from registry
153 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
154 m_bRelativeTimes
= (regRelativeTimes
!= 0);
155 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
157 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
158 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
159 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
160 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
161 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
162 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
164 m_ColumnRegKey
=_T("log");
166 m_AsyncThreadExit
= FALSE
;
167 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
168 m_AsynDiffListLock
.Init();
170 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
171 if (m_DiffingThread
==NULL
)
173 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
179 int CGitLogListBase::AsyncDiffThread()
181 m_AsyncThreadExited
= false;
182 while(!m_AsyncThreadExit
)
184 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
187 while(!m_AsyncThreadExit
&& m_AsynDiffList
.size() > 0)
189 m_AsynDiffListLock
.Lock();
190 pRev
= m_AsynDiffList
.back();
191 m_AsynDiffList
.pop_back();
192 m_AsynDiffListLock
.Unlock();
194 if( pRev
->m_CommitHash
.IsEmpty() )
196 if(pRev
->m_IsDiffFiles
)
199 pRev
->GetFiles(this).Clear();
200 pRev
->m_ParentHash
.clear();
201 pRev
->m_ParentHash
.push_back(m_HeadHash
);
202 if(g_Git
.IsInitRepos())
204 g_Git
.GetInitAddList(pRev
->GetFiles(this));
209 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
211 pRev
->GetAction(this) = 0;
213 for(int j
=0;j
< pRev
->GetFiles(this).GetCount();j
++)
214 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
216 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
217 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
219 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
220 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
221 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
224 if(!pRev
->CheckAndDiff())
225 { // fetch change file list
226 for(int i
=GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex()+GetCountPerPage(); i
++)
228 if(i
< m_arShownList
.GetCount())
230 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
231 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
233 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
239 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
241 POSITION pos
= GetFirstSelectedItemPosition();
242 int nItem
= GetNextSelectedItem(pos
);
246 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
248 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
250 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
257 m_AsyncThreadExited
= true;
260 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
264 m_ContextMenuMask
&= hideMask
;
268 m_ContextMenuMask
&= ~hideMask
;
272 CGitLogListBase::~CGitLogListBase()
274 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
275 this->m_arShownList
.SafeRemoveAll();
277 DestroyIcon(m_hModifiedIcon
);
278 DestroyIcon(m_hReplacedIcon
);
279 DestroyIcon(m_hAddedIcon
);
280 DestroyIcon(m_hDeletedIcon
);
281 m_logEntries
.ClearAll();
284 DeleteObject(m_boldFont
);
286 if ( m_pStoreSelection
)
288 delete m_pStoreSelection
;
289 m_pStoreSelection
= NULL
;
292 SafeTerminateThread();
293 SafeTerminateAsyncDiffThread();
296 CloseHandle(m_AsyncDiffEvent
);
300 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
301 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
302 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
303 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
305 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
306 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
309 ON_MESSAGE(MSG_LOADED
,OnLoad
)
311 ON_WM_MEASUREITEM_REFLECT()
312 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
313 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
314 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
315 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
316 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
317 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
320 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
322 //if (m_nRowHeight>0)
324 lpMeasureItemStruct
->itemHeight
= 50;
328 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
331 return CHintListCtrl::OnCreate(lpCreateStruct
);
334 void CGitLogListBase::PreSubclassWindow()
336 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
337 // load the icons for the action columns
338 // m_Theme.Open(m_hWnd, L"ListView");
339 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
340 CHintListCtrl::PreSubclassWindow();
343 void CGitLogListBase::InsertGitColumn()
347 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
348 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
349 if (DWORD(regFullRowSelect
))
350 exStyle
|= LVS_EX_FULLROWSELECT
;
351 SetExtendedStyle(exStyle
);
353 UpdateProjectProperties();
355 static UINT normal
[] =
367 IDS_LOG_COMMIT_EMAIL
,
388 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
390 DWORD hideColumns
= 0;
391 if(this->m_IsRebaseReplaceGraph
)
393 hideColumns
|= GIT_LOG_GRAPH
;
394 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
398 hideColumns
|= GIT_LOG_REBASE
;
401 if(this->m_IsIDReplaceAction
)
403 hideColumns
|= GIT_LOG_ACTIONS
;
404 m_dwDefaultColumns
|= GIT_LOG_ID
;
405 m_dwDefaultColumns
|= GIT_LOG_HASH
;
409 hideColumns
|= GIT_LOG_ID
;
411 if(this->m_bShowBugtraqColumn
)
413 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
417 hideColumns
|= GIT_LOGLIST_BUG
;
421 m_ColumnManager
.SetNames(normal
, _countof(normal
));
422 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
429 * Resizes all columns in a list control to values in registry.
431 void CGitLogListBase::ResizeAllListCtrlCols()
433 // column max and min widths to allow
434 static const int nMinimumWidth
= 10;
435 static const int nMaximumWidth
= 1000;
436 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
439 int numcols
= pHdrCtrl
->GetItemCount();
440 for (int col
= 0; col
< numcols
; col
++)
442 // get width for this col last time from registry
444 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
445 CRegDWORD
regwidth(regentry
, 0);
449 // no saved value, setup sensible defaults
450 if (col
== this->LOGLIST_MESSAGE
)
452 cx
= LOGLIST_MESSAGE_MIN
;
456 cx
= ICONITEMBORDER
+16*4;
459 if (cx
< nMinimumWidth
)
463 else if (cx
> nMaximumWidth
)
468 SetColumnWidth(col
, cx
);
475 BOOL
CGitLogListBase::GetShortName(CString ref
, CString
&shortname
,CString prefix
)
477 //TRACE(_T("%s %s\r\n"),ref,prefix);
478 if(ref
.Left(prefix
.GetLength()) == prefix
)
480 shortname
= ref
.Right(ref
.GetLength()-prefix
.GetLength());
481 if(shortname
.Right(3)==_T("^{}"))
482 shortname
=shortname
.Left(shortname
.GetLength()-3);
488 void CGitLogListBase::FillBackGround(HDC hdc
, int Index
,CRect
&rect
)
491 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
492 rItem
.mask
= LVIF_STATE
;
494 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
497 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
500 if (!(rItem
.state
& LVIS_SELECTED
))
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));
507 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
509 if (rItem
.state
& LVIS_SELECTED
)
511 if (::GetFocus() == m_hWnd
)
512 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
514 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
520 ::FillRect(hdc
, &rect
, brush
);
521 ::DeleteObject(brush
);
525 void CGitLogListBase::DrawTagBranch(HDC hdc
,CRect
&rect
,INT_PTR index
)
527 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
530 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
531 rItem
.mask
= LVIF_STATE
;
533 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
539 HTHEME hTheme
= NULL
;
540 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
541 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
543 for(unsigned int i
=0;i
<m_HashMap
[data
->m_CommitHash
].size();i
++)
546 str
=m_HashMap
[data
->m_CommitHash
][i
];
553 //Determine label color
554 if(GetShortName(str
,shortname
,_T("refs/heads/")))
556 if( shortname
== m_CurrentBranch
)
557 colRef
= m_Colors
.GetColor(CColors::CurrentBranch
);
559 colRef
= m_Colors
.GetColor(CColors::LocalBranch
);
562 else if(GetShortName(str
,shortname
,_T("refs/remotes/")))
564 colRef
= m_Colors
.GetColor(CColors::RemoteBranch
);
566 else if(GetShortName(str
,shortname
,_T("refs/tags/")))
568 colRef
= m_Colors
.GetColor(CColors::Tag
);
570 else if(GetShortName(str
,shortname
,_T("refs/stash")))
572 colRef
= m_Colors
.GetColor(CColors::Stash
);
573 shortname
=_T("stash");
575 else if(GetShortName(str
,shortname
,_T("refs/bisect/")))
577 if(shortname
.Find(_T("good")) == 0)
579 colRef
= m_Colors
.GetColor(CColors::BisectGood
);
580 shortname
= _T("good");
583 if(shortname
.Find(_T("bad")) == 0)
585 colRef
= m_Colors
.GetColor(CColors::BisectBad
);
586 shortname
= _T("bad");
590 //When row selected, ajust label color
591 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
592 if (rItem
.state
& LVIS_SELECTED
)
593 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
595 brush
= ::CreateSolidBrush(colRef
);
597 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
600 memset(&size
,0,sizeof(SIZE
));
601 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
603 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
606 int textpos
= DT_CENTER
;
608 if(rt
.right
> rect
.right
)
610 rt
.right
= rect
.right
;
614 //Fill interior of ref label
615 ::FillRect(hdc
, &rt
, brush
);
621 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,100), m_Colors
.Darken(colRef
,100));
622 rectEdge
.DeflateRect(1,1);
623 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,50), m_Colors
.Darken(colRef
,50));
625 //Draw text inside label
626 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
628 int txtState
= LISS_NORMAL
;
629 if (rItem
.state
& LVIS_SELECTED
)
630 txtState
= LISS_SELECTED
;
632 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
636 W_Dc
.SetBkMode(TRANSPARENT
);
637 if (rItem
.state
& LVIS_SELECTED
)
639 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
640 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
641 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
642 ::SetTextColor(hdc
,clrOld
);
646 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
650 //::MoveToEx(hdc,rt.left,rt.top,NULL);
651 //::LineTo(hdc,rt.right,rt.top);
652 //::LineTo(hdc,rt.right,rt.bottom);
653 //::LineTo(hdc,rt.left,rt.bottom);
654 //::LineTo(hdc,rt.left,rt.top);
659 ::DeleteObject(brush
);
663 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
665 int txtState
= LISS_NORMAL
;
666 if (rItem
.state
& LVIS_SELECTED
)
667 txtState
= LISS_SELECTED
;
669 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
673 if (rItem
.state
& LVIS_SELECTED
)
675 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
676 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
677 ::SetTextColor(hdc
,clrOld
);
681 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
686 CloseThemeData(hTheme
);
691 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
693 // Returns ((256 - amount)*col1 + amount*col2) / 256;
694 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
695 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
696 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
699 Gdiplus::Color
GetGdiColor(COLORREF col
)
701 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
703 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
704 const COLORREF
& col
,const COLORREF
& activeColor
, int top
707 int h
= laneHeight
/ 2;
708 int m
= (x1
+ x2
) / 2;
709 int r
= (x2
- x1
) / 3;
712 #define P_CENTER m , h+top
713 #define P_0 x2, h+top
714 #define P_90 m , 0+top-1
715 #define P_180 x1, h+top
716 #define P_270 m , 2 * h+top +1
717 #define R_CENTER m - r, h - r+top, d, d
720 #define DELTA_UR_B 2*(x1 - m), 2*h +top
721 #define DELTA_UR_E 0*16, 90*16 +top // -,
723 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
724 #define DELTA_DR_E 270*16, 90*16 +top // -'
726 #define DELTA_UL_B 2*(x2 - m), 2*h +top
727 #define DELTA_UL_E 90*16, 90*16 +top // ,-
729 #define DELTA_DL_B 2*(x2 - m),2*-h +top
730 #define DELTA_DL_E 180*16, 90*16 // '-
732 #define CENTER_UR x1, 2*h, 225
733 #define CENTER_DR x1, 0 , 135
734 #define CENTER_UL x2, 2*h, 315
735 #define CENTER_DL x2, 0 , 45
738 Gdiplus::Graphics
graphics( hdc
);
740 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
749 Gdiplus::LinearGradientBrush
gradient(
750 Gdiplus::Point(x1
-2, h
+top
-2),
751 Gdiplus::Point(P_270
),
752 GetGdiColor(activeColor
),GetGdiColor(col
));
755 Gdiplus::Pen
mypen(&gradient
,2);
756 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
758 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
759 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
760 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
767 Gdiplus::LinearGradientBrush
gradient(
768 Gdiplus::Point(P_270
),
769 Gdiplus::Point(x2
+1, h
+top
-1),
770 GetGdiColor(col
),GetGdiColor(activeColor
));
773 Gdiplus::Pen
mypen(&gradient
,2);
774 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
776 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
777 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
778 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
787 Gdiplus::LinearGradientBrush
gradient(
788 Gdiplus::Point(x1
-2, h
+top
-2),
789 Gdiplus::Point(P_90
),
790 GetGdiColor(activeColor
),GetGdiColor(col
));
792 Gdiplus::Pen
mypen(&gradient
,2);
794 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
797 QConicalGradient
gradient(CENTER_DR
);
798 gradient
.setColorAt(0.375, activeCol
);
799 gradient
.setColorAt(0.625, col
);
800 myPen
.setBrush(gradient
);
802 p
->drawArc(P_CENTER
, DELTA_DR
);
811 //static QPen myPen(Qt::black, 2); // fast path here
813 pen
.CreatePen(PS_SOLID
,2,col
);
814 //myPen.setColor(col);
815 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
817 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
819 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
826 case Lanes::NOT_ACTIVE
:
827 case Lanes::MERGE_FORK
:
828 case Lanes::MERGE_FORK_R
:
829 case Lanes::MERGE_FORK_L
:
834 //DrawLine(hdc,P_90,P_270);
835 graphics
.DrawLine(&myPen
,P_90
,P_270
);
836 //p->drawLine(P_90, P_270);
840 //DrawLine(hdc,P_CENTER,P_270);
841 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
842 //p->drawLine(P_CENTER, P_270);
846 case Lanes::BOUNDARY
:
847 case Lanes::BOUNDARY_C
:
848 case Lanes::BOUNDARY_R
:
849 case Lanes::BOUNDARY_L
:
850 //DrawLine(hdc,P_90, P_CENTER);
851 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
852 //p->drawLine(P_90, P_CENTER);
858 myPen
.SetColor(GetGdiColor(activeColor
));
862 case Lanes::MERGE_FORK
:
867 case Lanes::CROSS_EMPTY
:
868 case Lanes::BOUNDARY_C
:
869 //DrawLine(hdc,P_180,P_0);
870 graphics
.DrawLine(&myPen
,P_180
,P_0
);
871 //p->drawLine(P_180, P_0);
873 case Lanes::MERGE_FORK_R
:
874 case Lanes::BOUNDARY_R
:
875 //DrawLine(hdc,P_180,P_CENTER);
876 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
877 //p->drawLine(P_180, P_CENTER);
879 case Lanes::MERGE_FORK_L
:
882 case Lanes::BOUNDARY_L
:
883 //DrawLine(hdc,P_CENTER,P_0);
884 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
885 //p->drawLine(P_CENTER, P_0);
891 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
894 brush
.CreateSolidBrush(col
);
895 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
897 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
898 // center symbol, e.g. rect or ellipse
904 //p->setPen(Qt::NoPen);
906 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
907 graphics
.FillEllipse(&myBrush
, R_CENTER
);
908 //p->drawEllipse(R_CENTER);
910 case Lanes::MERGE_FORK
:
911 case Lanes::MERGE_FORK_R
:
912 case Lanes::MERGE_FORK_L
:
913 //p->setPen(Qt::NoPen);
915 //p->drawRect(R_CENTER);
916 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
917 graphics
.FillRectangle(&myBrush
, R_CENTER
);
919 case Lanes::UNAPPLIED
:
921 //p->setPen(Qt::NoPen);
922 //p->setBrush(Qt::red);
923 //p->drawRect(m - r, h - 1, d, 2);
924 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
925 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
929 //p->setPen(Qt::NoPen);
930 //p->setBrush(DARK_GREEN);
931 //p->drawRect(m - r, h - 1, d, 2);
932 //p->drawRect(m - 1, h - r, 2, d);
933 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
934 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
935 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
937 case Lanes::BOUNDARY
:
939 //p->drawEllipse(R_CENTER);
940 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
941 graphics
.DrawEllipse(&myPen
, R_CENTER
);
943 case Lanes::BOUNDARY_C
:
944 case Lanes::BOUNDARY_R
:
945 case Lanes::BOUNDARY_L
:
947 //p->drawRect(R_CENTER);
948 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
949 graphics
.FillRectangle(&myBrush
,R_CENTER
);
955 ::SelectObject(hdc
,oldpen
);
956 ::SelectObject(hdc
,oldbrush
);
965 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
969 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
970 if(data
->m_CommitHash
.IsEmpty())
975 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
976 rItem
.mask
= LVIF_STATE
;
978 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
981 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
983 if (data
->m_Lanes
.size() == 0)
984 m_logEntries
.setLane(data
->m_CommitHash
);
986 std::vector
<int>& lanes
=data
->m_Lanes
;
987 UINT laneNum
= lanes
.size();
989 for (UINT i
= 0; i
< laneNum
; i
++)
990 if (Lanes::isMerge(lanes
[i
])) {
996 int maxWidth
= rect
.Width();
997 int lw
= 3 * rect
.Height() / 4; //laneWidth()
999 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1000 //if (opt.state & QStyle::State_Selected)
1001 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1003 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++)
1010 if (ln
== Lanes::EMPTY
)
1013 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1014 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1018 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++) {
1024 if (ln
== Lanes::EMPTY
)
1027 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1028 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1030 if (ln
== Lanes::CROSS
)
1032 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1033 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1036 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1042 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1045 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1046 // Take the default processing unless we set this to something else below.
1047 *pResult
= CDRF_DODEFAULT
;
1049 if (m_bNoDispUpdates
)
1052 switch (pLVCD
->nmcd
.dwDrawStage
)
1056 *pResult
= CDRF_NOTIFYITEMDRAW
;
1060 case CDDS_ITEMPREPAINT
:
1062 // This is the prepaint stage for an item. Here's where we set the
1063 // item's text color.
1065 // Tell Windows to send draw notifications for each subitem.
1066 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1068 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1070 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1072 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1075 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1076 crText
= RGB(128,128,128);
1078 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1079 pLVCD
->clrTextBk
= RGB(156,156,156);
1080 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1081 pLVCD
->clrTextBk
= RGB(200,200,128);
1083 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1085 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1087 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1088 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1091 if(data
->m_CommitHash
.ToString() == m_HeadHash
)
1093 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1094 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1097 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1098 // crText = GetSysColor(COLOR_GRAYTEXT);
1100 if (data
->m_CommitHash
.IsEmpty())
1102 //crText = GetSysColor(RGB(200,200,0));
1103 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1104 // We changed the font, so we're returning CDRF_NEWFONT. This
1105 // tells the control to recalculate the extent of the text.
1106 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1110 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1112 if (m_bStrictStopped
)
1113 crText
= GetSysColor(COLOR_GRAYTEXT
);
1115 // Store the color back in the NMLVCUSTOMDRAW struct.
1116 pLVCD
->clrText
= crText
;
1120 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1122 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1124 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1127 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty())
1129 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1132 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1134 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1135 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1137 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1138 if( !data
->m_CommitHash
.IsEmpty())
1139 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1141 *pResult
= CDRF_SKIPDEFAULT
;
1146 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1148 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1150 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1151 //if(!data->m_IsFull)
1153 //if(data->SafeFetchFullInfo(&g_Git))
1154 // this->Invalidate();
1155 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1158 if(m_HashMap
[data
->m_CommitHash
].size()!=0)
1162 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1164 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1165 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1167 *pResult
= CDRF_SKIPDEFAULT
;
1175 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1177 if(this->m_IsIDReplaceAction
)
1179 *pResult
= CDRF_DODEFAULT
;
1182 *pResult
= CDRF_DODEFAULT
;
1184 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1188 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1189 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1191 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1193 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1194 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1195 // Get the selected state of the
1196 // item being drawn.
1198 // Fill the background if necessary
1199 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1201 // Draw the icon(s) into the compatible DC
1202 pLogEntry
->GetAction(this);
1204 if (!pLogEntry
->m_IsDiffFiles
)
1205 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1207 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1208 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1211 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1212 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1215 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1216 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1219 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1220 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1222 *pResult
= CDRF_SKIPDEFAULT
;
1228 *pResult
= CDRF_DODEFAULT
;
1231 // CGitLogListBase message handlers
1233 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1235 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1237 // Create a pointer to the item
1238 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1240 // Do the list need text information?
1241 if (!(pItem
->mask
& LVIF_TEXT
))
1244 // By default, clear text buffer.
1245 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1247 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1250 if (m_bNoDispUpdates
|| bOutOfRange
)
1253 // Which item number?
1254 int itemid
= pItem
->iItem
;
1255 GitRev
* pLogEntry
= NULL
;
1256 if (itemid
< m_arShownList
.GetCount())
1257 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1262 temp
.Format(_T("%d"),pItem
->iItem
+1);
1267 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1271 switch (pItem
->iSubItem
)
1273 case this->LOGLIST_GRAPH
: //Graphic
1275 case this->LOGLIST_REBASE
:
1277 if(this->m_IsRebaseReplaceGraph
)
1280 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1281 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1285 case this->LOGLIST_ACTION
: //action -- no text in the column
1287 case this->LOGLIST_HASH
:
1289 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1291 case this->LOGLIST_ID
:
1292 if(this->m_IsIDReplaceAction
)
1293 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1295 case this->LOGLIST_MESSAGE
: //Message
1297 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1299 case this->LOGLIST_AUTHOR
: //Author
1301 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1303 case this->LOGLIST_DATE
: //Date
1304 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1305 lstrcpyn(pItem
->pszText
,
1306 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1310 case this->LOGLIST_EMAIL
:
1312 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1315 case this->LOGLIST_COMMIT_NAME
: //Commit
1317 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1320 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1322 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1325 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1326 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1327 lstrcpyn(pItem
->pszText
,
1328 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1331 case this->LOGLIST_BUG
: //Bug ID
1333 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1341 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1344 if (pWnd
== GetHeaderCtrl())
1346 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1349 int selIndex
= GetSelectionMark();
1351 return; // nothing selected, nothing to do with a context menu
1353 // if the user selected the info text telling about not all revisions shown due to
1354 // the "stop on copy/rename" option, we also don't show the context menu
1355 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1358 // if the context menu is invoked through the keyboard, we have to use
1359 // a calculated position on where to anchor the menu on
1360 if ((point
.x
== -1) && (point
.y
== -1))
1363 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1364 ClientToScreen(&rect
);
1365 point
= rect
.CenterPoint();
1367 m_nSearchIndex
= selIndex
;
1368 m_bCancelled
= FALSE
;
1370 // calculate some information the context menu commands can use
1371 // CString pathURL = GetURLFromPath(m_path);
1373 POSITION pos
= GetFirstSelectedItemPosition();
1374 int indexNext
= GetNextSelectedItem(pos
);
1378 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1380 GitRev revSelected
= pSelLogEntry
->Rev
;
1381 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1382 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1384 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1386 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1387 if (changedpath
->lCopyFromRev
)
1388 revPrevious
= changedpath
->lCopyFromRev
;
1391 GitRev revSelected2
;
1394 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1395 revSelected2
= pLogEntry
->Rev
;
1397 bool bAllFromTheSameAuthor
= true;
1398 CString firstAuthor
;
1399 CLogDataVector selEntries
;
1400 GitRev revLowest
, revHighest
;
1401 GitRevRangeArray revisionRanges
;
1403 POSITION pos
= GetFirstSelectedItemPosition();
1404 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1405 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1406 selEntries
.push_back(pLogEntry
);
1407 firstAuthor
= pLogEntry
->sAuthor
;
1408 revLowest
= pLogEntry
->Rev
;
1409 revHighest
= pLogEntry
->Rev
;
1412 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1413 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1414 selEntries
.push_back(pLogEntry
);
1415 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1416 bAllFromTheSameAuthor
= false;
1417 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1418 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1424 int FirstSelect
=-1, LastSelect
=-1;
1425 pos
= GetFirstSelectedItemPosition();
1426 FirstSelect
= GetNextSelectedItem(pos
);
1429 LastSelect
= GetNextSelectedItem(pos
);
1431 //entry is selected, now show the popup menu
1433 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
,diffmenu
;
1435 if (popup
.CreatePopupMenu())
1437 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1438 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1440 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1441 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1443 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1444 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1446 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1447 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1449 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1450 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1452 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1453 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1454 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1456 if (GetSelectedCount() == 1)
1460 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1462 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1463 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1467 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1468 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1470 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1472 GitRev
*pRev
=pSelLogEntry
;
1473 if(pSelLogEntry
->m_ParentHash
.size()==0)
1475 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1477 if(pRev
->m_ParentHash
.size()<=1)
1479 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1484 gnudiffmenu
.CreatePopupMenu();
1485 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1487 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+ (0xFFFF << 16), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1488 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+ (0xFFFE << 16), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1490 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1493 str
.Format(IDS_PARENT
, i
+ 1);
1494 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1499 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1502 GitRev
*pRev
=pSelLogEntry
;
1503 if(pSelLogEntry
->m_ParentHash
.size()==0)
1505 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1507 if(pRev
->m_ParentHash
.size()<=1)
1509 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1510 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1511 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1515 diffmenu
.CreatePopupMenu();
1516 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1517 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1520 str
.Format(IDS_PARENT
, i
+ 1);
1521 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1522 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1524 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1525 diffmenu
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16), FALSE
);
1531 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1532 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1534 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1535 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1537 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1539 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1540 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1543 bool isStash
= false;
1544 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1546 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1553 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1555 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1556 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1558 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1559 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1561 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1564 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1566 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1567 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1569 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1573 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1575 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1577 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1579 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1581 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1582 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1584 // popup.AppendMenu(MF_SEPARATOR, NULL);
1589 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1591 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1593 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1594 GetSelectedCount() == 1)
1595 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1597 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1598 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1600 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1601 str
.Format(format
,g_Git
.GetCurrentBranch());
1603 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
)
1604 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1606 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1607 str
.Format(format
,g_Git
.GetCurrentBranch());
1609 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1610 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1613 // Add Switch Branch express Menu
1614 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1615 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1618 std::vector
<CString
*> branchs
;
1619 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1621 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1622 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1624 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1629 str
.LoadString(IDS_SWITCH_BRANCH
);
1631 if(branchs
.size() == 1)
1634 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1635 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1637 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1640 else if(branchs
.size() > 1)
1642 subbranchmenu
.CreatePopupMenu();
1643 for(int i
=0;i
<branchs
.size();i
++)
1645 if (*branchs
[i
] != currentBranch
)
1647 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1648 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1652 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1656 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1657 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1659 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1660 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1662 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1663 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1665 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1666 str
.Format(format
,g_Git
.GetCurrentBranch());
1668 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
)
1669 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1670 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1672 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1673 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1675 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1676 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1678 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1679 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1681 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1686 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1688 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1689 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1690 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1691 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1694 if (GetSelectedCount() >= 2)
1696 bool bAddSeparator
= false;
1697 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1699 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1700 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1703 if (GetSelectedCount() == 2)
1705 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1706 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1707 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1708 bAddSeparator
= true;
1713 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1715 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1716 bAddSeparator
= true;
1719 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1720 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1723 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1726 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1728 bool bAddSeparator
= false;
1729 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1731 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
)
1735 headindex
= this->GetHeadIndex();
1738 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1739 CGitHash hash
=g_Git
.GetHash(head
);
1740 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1741 if(pLastEntry
->m_CommitHash
== hash
) {
1742 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1743 bAddSeparator
= true;
1748 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
) {
1749 if (GetSelectedCount() >= 2)
1750 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
1752 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1753 bAddSeparator
= true;
1756 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1757 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1758 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1759 bAddSeparator
= true;
1763 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1767 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1769 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1771 // if (GetSelectedCount() == 1)
1773 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1774 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1775 // popup.AppendMenu(MF_SEPARATOR, NULL);
1779 if (GetSelectedCount() == 1)
1781 bool bAddSeparator
= false;
1782 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && m_HashMap
[pSelLogEntry
->m_CommitHash
].size() >= 1)
1784 // show the push-option only if the log entry has an associated local branch
1785 bool isLocal
= false;
1786 for(int i
=0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1788 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1793 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1794 bAddSeparator
= true;
1798 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1800 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1802 std::vector
<CString
*> branchs
;
1803 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1805 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
1806 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1809 if (branchs
.size() == 1)
1811 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1814 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1815 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
1816 bAddSeparator
= true;
1818 else if (branchs
.size() > 1)
1820 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1821 submenu
.CreatePopupMenu();
1822 for (int i
= 0; i
< branchs
.size(); i
++)
1824 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
1825 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
1828 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
1829 bAddSeparator
= true;
1832 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1834 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1835 } // GetSelectedCount() == 1
1837 if (GetSelectedCount() == 1)
1839 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1840 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
1842 if (GetSelectedCount() != 0)
1844 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1845 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
1848 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1849 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
1851 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
1852 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
1854 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1855 // DialogEnableWindow(IDOK, FALSE);
1856 // SetPromptApp(&theApp);
1858 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
1860 // EnableOKButton();
1861 } // if (popup.CreatePopupMenu())
1865 bool CGitLogListBase::IsSelectionContinuous()
1867 if ( GetSelectedCount()==1 )
1869 // if only one revision is selected, the selection is of course
1874 POSITION pos
= GetFirstSelectedItemPosition();
1875 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1878 int itemindex
= GetNextSelectedItem(pos
);
1881 int nextindex
= GetNextSelectedItem(pos
);
1882 if (nextindex
- itemindex
> 1)
1884 bContinuous
= false;
1887 itemindex
= nextindex
;
1893 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly
)
1897 POSITION pos
= GetFirstSelectedItemPosition();
1901 sRev
.LoadString(IDS_LOG_REVISION
);
1903 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1905 sDate
.LoadString(IDS_LOG_DATE
);
1907 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1910 CString sLogCopyText
;
1912 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1916 //pLogEntry->GetFiles(this)
1917 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1919 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
1920 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
1922 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
1923 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
1926 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
1927 sPaths
+= _T(" ") + rename
;
1929 sPaths
+= _T("\r\n");
1932 CString body
= pLogEntry
->GetBody();
1933 body
.Replace(_T("\n"), _T("\r\n"));
1934 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"),
1935 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
1936 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(),
1938 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1939 (LPCTSTR
)sMessage
, pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim(),
1941 sClipdata
+= sLogCopyText
;
1945 sClipdata
+= pLogEntry
->m_CommitHash
;
1950 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1955 void CGitLogListBase::DiffSelectedRevWithPrevious()
1957 if (m_bThreadRunning
)
1960 int FirstSelect
=-1, LastSelect
=-1;
1961 POSITION pos
= GetFirstSelectedItemPosition();
1962 FirstSelect
= GetNextSelectedItem(pos
);
1965 LastSelect
= GetNextSelectedItem(pos
);
1968 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
1971 UpdateLogInfoLabel();
1972 int selIndex
= m_LogList
.GetSelectionMark();
1975 int selCount
= m_LogList
.GetSelectedCount();
1979 // Find selected entry in the log list
1980 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
1981 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
1982 long rev1
= pLogEntry
->Rev
;
1984 CTGitPath path
= m_path
;
1986 // See how many files under the relative root were changed in selected revision
1988 LogChangedPath
* changed
= NULL
;
1989 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
1991 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
1992 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
1999 if (m_path
.IsDirectory() && nChanged
== 1)
2001 // We're looking at the log for a directory and only one file under dir was changed in the revision
2002 // Do diff on that file instead of whole directory
2003 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2006 m_bCancelled
= FALSE
;
2007 DialogEnableWindow(IDOK
, FALSE
);
2008 SetPromptApp(&theApp
);
2009 theApp
.DoWaitCursor(1);
2013 GitDiff
diff(this, m_hWnd
, true);
2014 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2015 diff
.SetHEADPeg(m_LogRevision
);
2016 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2020 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2023 theApp
.DoWaitCursor(-1);
2028 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2030 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2033 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2035 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2037 if (pFindInfo
->lvfi
.psz
== 0)
2040 CString sCmp
= pFindInfo
->lvfi
.psz
;
2042 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2044 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2045 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2046 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2048 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2056 if (sCmp
.Compare(sRev
)==0)
2063 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2065 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2067 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2068 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2069 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2071 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2079 if (sCmp
.Compare(sRev
)==0)
2091 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
2095 this->m_arShownList
.SafeRemoveAll();
2097 this->m_logEntries
.ClearAll();
2098 if (this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
))
2101 //this->m_logEntries.ParserFromLog();
2102 SetItemCountEx(this->m_logEntries
.size());
2104 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2108 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2109 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2114 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2115 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2119 m_CurrentBranch
= g_Git
.GetCurrentBranch();
2120 m_HeadHash
= g_Git
.GetHash(_T("HEAD"));
2128 int CGitLogListBase::BeginFetchLog()
2132 this->m_arShownList
.SafeRemoveAll();
2134 this->m_logEntries
.ClearAll();
2137 this->m_LogCache
.ClearAllParent();
2139 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2142 if(this->m_Path
.IsEmpty())
2149 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2150 // if(this->m_bAllBranch)
2151 mask
|= m_ShowMask
;
2155 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2157 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2160 CString
*pFrom
, *pTo
;
2162 CString
head(_T("HEAD"));
2163 if(!this->m_startrev
.IsEmpty())
2165 pFrom
= &this->m_startrev
;
2166 if(!this->m_endrev
.IsEmpty())
2167 pTo
= &this->m_endrev
;
2173 data
.m_From
= m_From
;
2176 #if 0 /* use tortoiegit filter */
2177 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2178 data
.m_Author
= this->m_sFilterText
;
2180 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2181 data
.m_MessageFilter
= this->m_sFilterText
;
2183 data
.m_IsRegex
= m_bFilterWithRegex
;
2186 // follow does not work for directories
2187 if (!path
|| path
->IsDirectory())
2188 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2189 // follow does not work with all branches 8at least in TGit)
2190 if (mask
& CGit::LOG_INFO_FOLLOW
)
2191 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
;
2193 CString cmd
=g_Git
.GetLogCmd(m_StartRef
,path
,-1,mask
,pFrom
,pTo
,true,&data
);
2195 //this->m_logEntries.ParserFromLog();
2196 if(IsInWorkingThread())
2198 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2202 SetItemCountEx(this->m_logEntries
.size());
2207 if(g_Git
.IsInitRepos())
2211 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2219 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2226 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2228 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2230 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2232 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2234 DiffSelectedRevWithPrevious();
2239 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2246 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2248 // select all entries
2249 for (int i
=0; i
<GetItemCount(); ++i
)
2251 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2257 if (m_hAccel
&& !bSkipAccelerator
)
2259 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2265 //m_tooltips.RelayEvent(pMsg);
2266 return __super::PreTranslateMessage(pMsg
);
2269 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2271 // a double click on an entry in the revision list has happened
2274 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2275 DiffSelectedRevWithPrevious();
2278 int CGitLogListBase::FetchLogAsync(void * data
)
2281 m_bExitThread
=FALSE
;
2282 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2283 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2284 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2285 if (m_LoadingThread
==NULL
)
2287 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2288 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2289 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2295 //this is the thread function which calls the subversion function
2296 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2298 return ((CGitLogListBase
*)pVoid
)->LogThread();
2301 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2304 oldest
=CTime::GetCurrentTime();
2305 latest
=CTime(1971,1,2,0,0,0);
2306 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2308 if(m_logEntries
[i
].IsEmpty())
2311 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2312 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2314 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2315 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2323 UINT
CGitLogListBase::LogThread()
2325 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2327 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2328 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2334 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2335 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2340 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2341 bool bRegex
= false;
2342 if (m_bFilterWithRegex
)
2343 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2345 TRACE(_T("\n===Begin===\n"));
2346 //Update work copy item;
2348 if( m_logEntries
.size() > 0)
2350 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2352 m_arShownList
.SafeAdd(pRev
);
2356 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2358 // store commit number of the last selected commit/line before the refresh or -1
2359 int lastSelectedHashNItem
= -1;
2361 if(!g_Git
.IsInitRepos())
2363 g_Git
.m_critGitDllSec
.Lock();
2367 git_get_log_firstcommit(m_DllGitLog
);
2368 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2373 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2376 g_Git
.m_critGitDllSec
.Unlock();
2379 t2
=t1
=GetTickCount();
2380 int oldprecentage
= 0;
2381 int oldsize
=m_logEntries
.size();
2385 g_Git
.m_critGitDllSec
.Lock();
2388 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
);
2393 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2396 g_Git
.m_critGitDllSec
.Unlock();
2401 if (commit
.m_ignore
== 1)
2403 git_free_commit(&commit
);
2407 //printf("%s\r\n",commit.GetSubject());
2411 CGitHash hash
= (char*)commit
.m_hash
;
2413 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2414 pRev
->m_GitCommit
= commit
;
2415 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2418 g_Git
.m_critGitDllSec
.Lock();
2419 git_get_notes(commit
.m_hash
,¬e
);
2420 g_Git
.m_critGitDllSec
.Unlock();
2424 pRev
->m_Notes
.Empty();
2425 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2428 if(!pRev
->m_IsDiffFiles
)
2430 pRev
->m_CallDiffAsync
= DiffAsync
;
2433 pRev
->ParserParentFromCommit(&commit
);
2440 if(!m_sFilterText
.IsEmpty())
2442 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2445 this->m_critSec
.Lock();
2446 m_logEntries
.push_back(hash
);
2447 m_arShownList
.SafeAdd(pRev
);
2448 this->m_critSec
.Unlock();
2450 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2451 lastSelectedHashNItem
= m_arShownList
.GetCount() - 1;
2455 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2458 int percent
=m_logEntries
.size()*100/total
+ GITLOG_START
+1;
2461 if(percent
< GITLOG_START
)
2462 percent
= GITLOG_START
+1;
2464 oldsize
= m_logEntries
.size();
2465 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2467 //if( percent > oldprecentage )
2469 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2470 oldprecentage
= percent
;
2475 g_Git
.m_critGitDllSec
.Lock();
2476 git_close_log(m_DllGitLog
);
2477 g_Git
.m_critGitDllSec
.Unlock();
2481 // restore last selected item
2482 if (lastSelectedHashNItem
>= 0)
2484 SetItemState(lastSelectedHashNItem
, LVIS_SELECTED
, LVIS_SELECTED
);
2485 EnsureVisible(lastSelectedHashNItem
, FALSE
);
2489 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2490 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2492 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2497 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2499 SafeTerminateThread();
2501 this->SetItemCountEx(0);
2506 // HACK to hide graph column
2507 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
2508 SetColumnWidth(0, 0);
2510 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
2512 //Update branch and Tag info
2514 //Assume Thread have exited
2515 //if(!m_bThreadRunning)
2517 m_logEntries
.clear();
2521 m_sFilterText
.Empty();
2526 InterlockedExchange(&m_bExitThread
,FALSE
);
2528 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2529 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2530 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2532 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2533 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2534 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2538 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2542 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2544 type
|= tr1::regex_constants::icase
;
2545 pat
= tr1::wregex(regexp_str
, type
);
2548 catch (exception
) {}
2551 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2554 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2557 if ((bRegex
)&&(m_bFilterWithRegex
))
2559 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2561 if(this->m_bShowBugtraqColumn
)
2563 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2565 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2566 if (regex_search(wstring(sBugIds
), pat
, flags
))
2573 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2575 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2576 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2582 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2584 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2585 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2591 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2593 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2598 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2604 if (m_SelectedFilters
& LOGFILTER_REVS
)
2606 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2607 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2613 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2615 CTGitPathList
*pathList
=NULL
;
2616 if( pRev
->m_IsDiffFiles
)
2617 pathList
= &pRev
->GetFiles(this);
2620 if(!pRev
->m_IsSimpleListReady
)
2621 pRev
->SafeGetSimpleList(&g_Git
);
2625 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2627 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2631 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2637 for(INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2639 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2648 CString find
= m_sFilterText
;
2651 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2653 if(this->m_bShowBugtraqColumn
)
2655 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2657 sBugIds
.MakeLower();
2658 if ((sBugIds
.Find(find
) >= 0))
2665 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2667 CString msg
= pRev
->GetSubject();
2669 msg
= msg
.MakeLower();
2670 if ((msg
.Find(find
) >= 0))
2676 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2678 CString msg
= pRev
->GetBody();
2680 msg
= msg
.MakeLower();
2681 if ((msg
.Find(find
) >= 0))
2687 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2689 CString msg
= pRev
->GetAuthorName();
2690 msg
= msg
.MakeLower();
2691 if ((msg
.Find(find
) >= 0))
2697 if (m_SelectedFilters
& LOGFILTER_REVS
)
2699 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2700 if ((sRev
.Find(find
) >= 0))
2706 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2708 CTGitPathList
*pathList
=NULL
;
2709 if( pRev
->m_IsDiffFiles
)
2710 pathList
= &pRev
->GetFiles(this);
2713 if(!pRev
->m_IsSimpleListReady
)
2714 pRev
->SafeGetSimpleList(&g_Git
);
2717 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
2719 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
2720 CString path
= cpath
->GetGitOldPathString();
2722 if ((path
.Find(find
)>=0))
2726 path
= cpath
->GetGitPathString();
2728 if ((path
.Find(find
)>=0))
2734 for (INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2736 CString path
= pRev
->m_SimpleFileList
[i
];
2738 if ((path
.Find(find
)>=0))
2744 } // else (from if (bRegex))
2749 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
2752 pShownlist
->SafeRemoveAll();
2754 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2755 bool bRegex
= false;
2756 if (m_bFilterWithRegex
)
2757 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2759 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2761 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2763 if ((bRegex
)&&(m_bFilterWithRegex
))
2766 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2768 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2769 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2771 pShownlist
->SafeAdd(m_logEntries
[i
]);
2776 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2778 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
2779 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
2781 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2785 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2787 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
2788 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
2790 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2794 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2796 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2799 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2801 CTGitPath cpath
= pathList
[cpPathIndex
];
2802 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2804 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2808 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2810 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2814 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
2816 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2822 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2824 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
2826 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2830 if (m_SelectedFilters
& LOGFILTER_REVS
)
2832 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2833 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2835 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2842 CString find
= m_sFilterText
;
2845 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2847 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2849 sBugIDs
= sBugIDs
.MakeLower();
2850 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2852 pShownlist
->SafeAdd(m_logEntries
[i
]);
2857 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2859 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
2861 msg
= msg
.MakeLower();
2862 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2864 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2868 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2870 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
2872 msg
= msg
.MakeLower();
2873 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2875 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2879 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2881 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2884 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2886 CTGitPath cpath
= pathList
[cpPathIndex
];
2887 CString path
= cpath
.GetGitOldPathString();
2889 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2891 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2895 path
= cpath
.GetGitPathString();
2897 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2899 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2903 path
= cpath
.GetActionName();
2905 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2907 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2913 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2915 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
2916 msg
= msg
.MakeLower();
2917 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2919 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2923 if (m_SelectedFilters
& LOGFILTER_REVS
)
2925 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2926 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2928 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2932 } // else (from if (bRegex))
2933 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2937 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
2940 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2946 return time <= m_To;
2949 return time >= m_From;
2951 return ((time >= m_From)&&(time <= m_To));
2953 return TRUE
; /* git dll will filter time range */
2957 void CGitLogListBase::StartFilter()
2959 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2960 RecalculateShownList(&m_arShownList
);
2961 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2965 SetItemCountEx(ShownCountWithStopped());
2966 RedrawItems(0, ShownCountWithStopped());
2970 void CGitLogListBase::RemoveFilter()
2973 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2975 m_arShownList
.SafeRemoveAll();
2977 // reset the time filter too
2979 m_timFrom
= (__time64_t(m_tFrom
));
2980 m_timTo
= (__time64_t(m_tTo
));
2981 m_DateFrom
.SetTime(&m_timFrom
);
2982 m_DateTo
.SetTime(&m_timTo
);
2983 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
2984 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
2987 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2989 if(this->m_IsOldFirst
)
2991 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2995 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2998 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3000 SetItemCountEx(ShownCountWithStopped());
3001 RedrawItems(0, ShownCountWithStopped());
3003 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3006 void CGitLogListBase::Clear()
3008 m_arShownList
.SafeRemoveAll();
3011 m_logEntries
.ClearAll();
3015 void CGitLogListBase::OnDestroy()
3017 // save the column widths to the registry
3020 SafeTerminateThread();
3021 SafeTerminateAsyncDiffThread();
3024 while(m_LogCache
.SaveCache())
3032 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3033 // MB_YESNO) == IDNO)
3037 CHintListCtrl::OnDestroy();
3040 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
3042 UNREFERENCED_PARAMETER(lParam
);
3045 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3046 this->InvalidateRect(rect
);
3052 * Save column widths to the registry
3054 void CGitLogListBase::SaveColumnWidths()
3056 int maxcol
= m_ColumnManager
.GetColumnCount();
3058 // HACK that graph column is always shown
3059 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3061 for (int col
= 0; col
< maxcol
; col
++)
3062 if (m_ColumnManager
.IsVisible (col
))
3063 m_ColumnManager
.ColumnResized (col
);
3065 m_ColumnManager
.WriteSettings();
3068 int CGitLogListBase::GetHeadIndex()
3070 if(m_HeadHash
.IsEmpty())
3073 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
3075 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
3078 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3084 void CGitLogListBase::OnFind()
3088 m_pFindDialog
= new CFindDlg(this);
3089 m_pFindDialog
->Create(this);
3092 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3094 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3096 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3098 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3101 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3104 ASSERT(m_pFindDialog
!= NULL
);
3105 bool bFound
= false;
3108 if (m_pFindDialog
->IsTerminating())
3110 // invalidate the handle identifying the dialog box.
3111 m_pFindDialog
= NULL
;
3115 if(m_pFindDialog
->IsRef())
3118 str
=m_pFindDialog
->GetFindString();
3123 hash
= g_Git
.GetHash(str
+ _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3127 for (i
= 0; i
<m_arShownList
.GetCount(); i
++)
3129 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3130 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3140 if(m_pFindDialog
->FindNext())
3142 //read data from dialog
3143 CString FindText
= m_pFindDialog
->GetFindString();
3144 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3147 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3149 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3152 for (i
= this->m_nSearchIndex
; i
<m_arShownList
.GetCount()&&!bFound
; i
++)
3154 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3157 str
+=pLogEntry
->m_CommitHash
.ToString();
3160 for(int j
=0;j
<this->m_HashMap
[pLogEntry
->m_CommitHash
].size();j
++)
3162 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3166 str
+=pLogEntry
->GetAuthorEmail();
3168 str
+=pLogEntry
->GetAuthorName();
3170 str
+=pLogEntry
->GetBody();
3172 str
+=pLogEntry
->GetCommitterEmail();
3174 str
+=pLogEntry
->GetCommitterName();
3176 str
+=pLogEntry
->GetSubject();
3180 /*Because changed files list is loaded on demand when gui show,
3181 files will empty when files have not fetched.
3183 we can add it back by using one-way diff(with outnumber changed and rename detect.
3184 here just need changed filename list. one-way is much quicker.
3186 if(pLogEntry
->m_IsFull
)
3188 for(int i
=0;i
<pLogEntry
->GetFiles(this).GetCount();i
++)
3190 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3192 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3198 if(!pLogEntry
->m_IsSimpleListReady
)
3199 pLogEntry
->SafeGetSimpleList(&g_Git
);
3201 for(int i
=0;i
<pLogEntry
->m_SimpleFileList
.size();i
++)
3203 str
+=pLogEntry
->m_SimpleFileList
[i
];
3212 if (regex_search(wstring(str
), pat
, flags
))
3222 if (str
.Find(FindText
) >= 0)
3232 msg
= msg
.MakeLower();
3233 CString find
= FindText
.MakeLower();
3234 if (msg
.Find(find
) >= 0)
3241 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3243 } // if(m_pFindDialog->FindNext())
3244 //UpdateLogInfoLabel();
3248 this->m_nSearchIndex
= i
;
3249 EnsureVisible(i
, FALSE
);
3250 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3251 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3252 SetSelectionMark(i
);
3253 //FillLogMessageCtrl();
3256 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3257 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3263 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3265 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3270 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3272 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);