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
)
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()=_T("Working dir changes");
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 m_CurrentBranch
=g_Git
.GetCurrentBranch();
114 this->m_HeadHash
=g_Git
.GetHash(_T("HEAD"));
120 m_LoadingThread
= NULL
;
122 InterlockedExchange(&m_bExitThread
,FALSE
);
123 m_IsOldFirst
= FALSE
;
124 m_IsRebaseReplaceGraph
= FALSE
;
127 for(int i
=0;i
<Lanes::COLORS_NUM
;i
++)
129 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
131 // get short/long datetime setting from registry
132 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
133 if ( RegUseShortDateFormat
)
135 m_DateFormat
= DATE_SHORTDATE
;
139 m_DateFormat
= DATE_LONGDATE
;
141 // get relative time display setting from registry
142 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
143 m_bRelativeTimes
= (regRelativeTimes
!= 0);
144 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
146 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
147 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
148 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
149 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
150 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
151 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
153 m_ColumnRegKey
=_T("log");
155 m_AsyncThreadExit
= FALSE
;
156 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
157 m_AsynDiffListLock
.Init();
159 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
160 if (m_DiffingThread
==NULL
)
162 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
168 int CGitLogListBase::AsyncDiffThread()
170 m_AsyncThreadExited
= false;
171 while(!m_AsyncThreadExit
)
173 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
176 while(!m_AsyncThreadExit
&& m_AsynDiffList
.size() > 0)
178 m_AsynDiffListLock
.Lock();
179 pRev
= m_AsynDiffList
.back();
180 m_AsynDiffList
.pop_back();
181 m_AsynDiffListLock
.Unlock();
183 if( pRev
->m_CommitHash
.IsEmpty() )
185 if(pRev
->m_IsDiffFiles
)
188 pRev
->GetFiles(this).Clear();
189 pRev
->m_ParentHash
.clear();
190 pRev
->m_ParentHash
.push_back(m_HeadHash
);
191 if(g_Git
.IsInitRepos())
193 g_Git
.GetInitAddList(pRev
->GetFiles(this));
198 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
200 pRev
->GetAction(this) = 0;
202 for(int j
=0;j
< pRev
->GetFiles(this).GetCount();j
++)
203 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
205 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
206 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
208 pRev
->GetBody().Format(_T("%d files changed"),pRev
->GetFiles(this).GetCount());
209 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
210 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
213 if(!pRev
->CheckAndDiff())
214 { // fetch change file list
215 for(int i
=GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex()+GetCountPerPage(); i
++)
217 if(i
< m_arShownList
.GetCount())
219 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
220 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
222 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
228 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
230 POSITION pos
= GetFirstSelectedItemPosition();
231 int nItem
= GetNextSelectedItem(pos
);
235 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
237 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
239 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
246 m_AsyncThreadExited
= true;
249 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
253 m_ContextMenuMask
&= hideMask
;
257 m_ContextMenuMask
&= ~hideMask
;
261 CGitLogListBase::~CGitLogListBase()
263 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
264 this->m_arShownList
.SafeRemoveAll();
266 DestroyIcon(m_hModifiedIcon
);
267 DestroyIcon(m_hReplacedIcon
);
268 DestroyIcon(m_hAddedIcon
);
269 DestroyIcon(m_hDeletedIcon
);
270 m_logEntries
.ClearAll();
273 DeleteObject(m_boldFont
);
275 if ( m_pStoreSelection
)
277 delete m_pStoreSelection
;
278 m_pStoreSelection
= NULL
;
281 SafeTerminateThread();
282 SafeTerminateAsyncDiffThread();
285 CloseHandle(m_AsyncDiffEvent
);
289 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
290 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
291 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
292 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
294 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
295 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
298 ON_MESSAGE(MSG_LOADED
,OnLoad
)
300 ON_WM_MEASUREITEM_REFLECT()
301 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
302 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
303 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
304 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
305 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
306 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
309 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
311 //if (m_nRowHeight>0)
313 lpMeasureItemStruct
->itemHeight
= 50;
317 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
320 return CHintListCtrl::OnCreate(lpCreateStruct
);
323 void CGitLogListBase::PreSubclassWindow()
325 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
326 // load the icons for the action columns
327 // m_Theme.Open(m_hWnd, L"ListView");
328 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
329 CHintListCtrl::PreSubclassWindow();
332 void CGitLogListBase::InsertGitColumn()
336 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
337 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
338 if (DWORD(regFullRowSelect
))
339 exStyle
|= LVS_EX_FULLROWSELECT
;
340 SetExtendedStyle(exStyle
);
342 UpdateProjectProperties();
344 static UINT normal
[] =
356 IDS_LOG_COMMIT_EMAIL
,
377 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
379 DWORD hideColumns
= 0;
380 if(this->m_IsRebaseReplaceGraph
)
382 hideColumns
|= GIT_LOG_GRAPH
;
383 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
387 hideColumns
|= GIT_LOG_REBASE
;
390 if(this->m_IsIDReplaceAction
)
392 hideColumns
|= GIT_LOG_ACTIONS
;
393 m_dwDefaultColumns
|= GIT_LOG_ID
;
394 m_dwDefaultColumns
|= GIT_LOG_HASH
;
398 hideColumns
|= GIT_LOG_ID
;
400 if(this->m_bShowBugtraqColumn
)
402 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
406 hideColumns
|= GIT_LOGLIST_BUG
;
410 m_ColumnManager
.SetNames(normal
, _countof(normal
));
411 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
418 * Resizes all columns in a list control to values in registry.
420 void CGitLogListBase::ResizeAllListCtrlCols()
422 // column max and min widths to allow
423 static const int nMinimumWidth
= 10;
424 static const int nMaximumWidth
= 1000;
425 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
428 int numcols
= pHdrCtrl
->GetItemCount();
429 for (int col
= 0; col
< numcols
; col
++)
431 // get width for this col last time from registry
433 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
434 CRegDWORD
regwidth(regentry
, 0);
438 // no saved value, setup sensible defaults
439 if (col
== this->LOGLIST_MESSAGE
)
441 cx
= LOGLIST_MESSAGE_MIN
;
445 cx
= ICONITEMBORDER
+16*4;
448 if (cx
< nMinimumWidth
)
452 else if (cx
> nMaximumWidth
)
457 SetColumnWidth(col
, cx
);
464 BOOL
CGitLogListBase::GetShortName(CString ref
, CString
&shortname
,CString prefix
)
466 //TRACE(_T("%s %s\r\n"),ref,prefix);
467 if(ref
.Left(prefix
.GetLength()) == prefix
)
469 shortname
= ref
.Right(ref
.GetLength()-prefix
.GetLength());
470 if(shortname
.Right(3)==_T("^{}"))
471 shortname
=shortname
.Left(shortname
.GetLength()-3);
477 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 (!(rItem
.state
& LVIS_SELECTED
))
491 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
492 brush
= ::CreateSolidBrush(RGB(156,156,156));
493 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
494 brush
= ::CreateSolidBrush(RGB(200,200,128));
496 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
498 if (rItem
.state
& LVIS_SELECTED
)
500 if (::GetFocus() == m_hWnd
)
501 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
503 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
509 ::FillRect(hdc
, &rect
, brush
);
510 ::DeleteObject(brush
);
514 void CGitLogListBase::DrawTagBranch(HDC hdc
,CRect
&rect
,INT_PTR index
)
516 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
519 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
520 rItem
.mask
= LVIF_STATE
;
522 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
528 HTHEME hTheme
= NULL
;
529 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
530 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
532 for(unsigned int i
=0;i
<m_HashMap
[data
->m_CommitHash
].size();i
++)
535 str
=m_HashMap
[data
->m_CommitHash
][i
];
542 //Determine label color
543 if(GetShortName(str
,shortname
,_T("refs/heads/")))
545 if( shortname
== m_CurrentBranch
)
546 colRef
= m_Colors
.GetColor(CColors::CurrentBranch
);
548 colRef
= m_Colors
.GetColor(CColors::LocalBranch
);
551 else if(GetShortName(str
,shortname
,_T("refs/remotes/")))
553 colRef
= m_Colors
.GetColor(CColors::RemoteBranch
);
555 else if(GetShortName(str
,shortname
,_T("refs/tags/")))
557 colRef
= m_Colors
.GetColor(CColors::Tag
);
559 else if(GetShortName(str
,shortname
,_T("refs/stash")))
561 colRef
= m_Colors
.GetColor(CColors::Stash
);
562 shortname
=_T("stash");
564 else if(GetShortName(str
,shortname
,_T("refs/bisect/")))
566 if(shortname
.Find(_T("good")) == 0)
568 colRef
= m_Colors
.GetColor(CColors::BisectGood
);
569 shortname
= _T("good");
572 if(shortname
.Find(_T("bad")) == 0)
574 colRef
= m_Colors
.GetColor(CColors::BisectBad
);
575 shortname
= _T("bad");
579 //When row selected, ajust label color
580 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
581 if (rItem
.state
& LVIS_SELECTED
)
582 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
584 brush
= ::CreateSolidBrush(colRef
);
586 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
589 memset(&size
,0,sizeof(SIZE
));
590 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
592 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
595 int textpos
= DT_CENTER
;
597 if(rt
.right
> rect
.right
)
599 rt
.right
= rect
.right
;
603 //Fill interior of ref label
604 ::FillRect(hdc
, &rt
, brush
);
610 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,100), m_Colors
.Darken(colRef
,100));
611 rectEdge
.DeflateRect(1,1);
612 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,50), m_Colors
.Darken(colRef
,50));
614 //Draw text inside label
615 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
617 int txtState
= LISS_NORMAL
;
618 if (rItem
.state
& LVIS_SELECTED
)
619 txtState
= LISS_SELECTED
;
621 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
625 W_Dc
.SetBkMode(TRANSPARENT
);
626 if (rItem
.state
& LVIS_SELECTED
)
628 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
629 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
630 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
631 ::SetTextColor(hdc
,clrOld
);
635 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
639 //::MoveToEx(hdc,rt.left,rt.top,NULL);
640 //::LineTo(hdc,rt.right,rt.top);
641 //::LineTo(hdc,rt.right,rt.bottom);
642 //::LineTo(hdc,rt.left,rt.bottom);
643 //::LineTo(hdc,rt.left,rt.top);
648 ::DeleteObject(brush
);
652 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
654 int txtState
= LISS_NORMAL
;
655 if (rItem
.state
& LVIS_SELECTED
)
656 txtState
= LISS_SELECTED
;
658 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
662 if (rItem
.state
& LVIS_SELECTED
)
664 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
665 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
666 ::SetTextColor(hdc
,clrOld
);
670 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
675 CloseThemeData(hTheme
);
680 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
682 // Returns ((256 - amount)*col1 + amount*col2) / 256;
683 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
684 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
685 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
688 Gdiplus::Color
GetGdiColor(COLORREF col
)
690 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
692 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
693 const COLORREF
& col
,const COLORREF
& activeColor
, int top
696 int h
= laneHeight
/ 2;
697 int m
= (x1
+ x2
) / 2;
698 int r
= (x2
- x1
) / 3;
701 #define P_CENTER m , h+top
702 #define P_0 x2, h+top
703 #define P_90 m , 0+top-1
704 #define P_180 x1, h+top
705 #define P_270 m , 2 * h+top +1
706 #define R_CENTER m - r, h - r+top, d, d
709 #define DELTA_UR_B 2*(x1 - m), 2*h +top
710 #define DELTA_UR_E 0*16, 90*16 +top // -,
712 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
713 #define DELTA_DR_E 270*16, 90*16 +top // -'
715 #define DELTA_UL_B 2*(x2 - m), 2*h +top
716 #define DELTA_UL_E 90*16, 90*16 +top // ,-
718 #define DELTA_DL_B 2*(x2 - m),2*-h +top
719 #define DELTA_DL_E 180*16, 90*16 // '-
721 #define CENTER_UR x1, 2*h, 225
722 #define CENTER_DR x1, 0 , 135
723 #define CENTER_UL x2, 2*h, 315
724 #define CENTER_DL x2, 0 , 45
727 Gdiplus::Graphics
graphics( hdc
);
729 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
738 Gdiplus::LinearGradientBrush
gradient(
739 Gdiplus::Point(x1
-2, h
+top
-2),
740 Gdiplus::Point(P_270
),
741 GetGdiColor(activeColor
),GetGdiColor(col
));
744 Gdiplus::Pen
mypen(&gradient
,2);
745 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
747 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
748 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
749 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
756 Gdiplus::LinearGradientBrush
gradient(
757 Gdiplus::Point(P_270
),
758 Gdiplus::Point(x2
+1, h
+top
-1),
759 GetGdiColor(col
),GetGdiColor(activeColor
));
762 Gdiplus::Pen
mypen(&gradient
,2);
763 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
765 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
766 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
767 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
776 Gdiplus::LinearGradientBrush
gradient(
777 Gdiplus::Point(x1
-2, h
+top
-2),
778 Gdiplus::Point(P_90
),
779 GetGdiColor(activeColor
),GetGdiColor(col
));
781 Gdiplus::Pen
mypen(&gradient
,2);
783 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
786 QConicalGradient
gradient(CENTER_DR
);
787 gradient
.setColorAt(0.375, activeCol
);
788 gradient
.setColorAt(0.625, col
);
789 myPen
.setBrush(gradient
);
791 p
->drawArc(P_CENTER
, DELTA_DR
);
800 //static QPen myPen(Qt::black, 2); // fast path here
802 pen
.CreatePen(PS_SOLID
,2,col
);
803 //myPen.setColor(col);
804 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
806 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
808 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
815 case Lanes::NOT_ACTIVE
:
816 case Lanes::MERGE_FORK
:
817 case Lanes::MERGE_FORK_R
:
818 case Lanes::MERGE_FORK_L
:
823 //DrawLine(hdc,P_90,P_270);
824 graphics
.DrawLine(&myPen
,P_90
,P_270
);
825 //p->drawLine(P_90, P_270);
829 //DrawLine(hdc,P_CENTER,P_270);
830 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
831 //p->drawLine(P_CENTER, P_270);
835 case Lanes::BOUNDARY
:
836 case Lanes::BOUNDARY_C
:
837 case Lanes::BOUNDARY_R
:
838 case Lanes::BOUNDARY_L
:
839 //DrawLine(hdc,P_90, P_CENTER);
840 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
841 //p->drawLine(P_90, P_CENTER);
847 myPen
.SetColor(GetGdiColor(activeColor
));
851 case Lanes::MERGE_FORK
:
856 case Lanes::CROSS_EMPTY
:
857 case Lanes::BOUNDARY_C
:
858 //DrawLine(hdc,P_180,P_0);
859 graphics
.DrawLine(&myPen
,P_180
,P_0
);
860 //p->drawLine(P_180, P_0);
862 case Lanes::MERGE_FORK_R
:
863 case Lanes::BOUNDARY_R
:
864 //DrawLine(hdc,P_180,P_CENTER);
865 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
866 //p->drawLine(P_180, P_CENTER);
868 case Lanes::MERGE_FORK_L
:
871 case Lanes::BOUNDARY_L
:
872 //DrawLine(hdc,P_CENTER,P_0);
873 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
874 //p->drawLine(P_CENTER, P_0);
880 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
883 brush
.CreateSolidBrush(col
);
884 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
886 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
887 // center symbol, e.g. rect or ellipse
893 //p->setPen(Qt::NoPen);
895 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
896 graphics
.FillEllipse(&myBrush
, R_CENTER
);
897 //p->drawEllipse(R_CENTER);
899 case Lanes::MERGE_FORK
:
900 case Lanes::MERGE_FORK_R
:
901 case Lanes::MERGE_FORK_L
:
902 //p->setPen(Qt::NoPen);
904 //p->drawRect(R_CENTER);
905 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
906 graphics
.FillRectangle(&myBrush
, R_CENTER
);
908 case Lanes::UNAPPLIED
:
910 //p->setPen(Qt::NoPen);
911 //p->setBrush(Qt::red);
912 //p->drawRect(m - r, h - 1, d, 2);
913 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
914 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
918 //p->setPen(Qt::NoPen);
919 //p->setBrush(DARK_GREEN);
920 //p->drawRect(m - r, h - 1, d, 2);
921 //p->drawRect(m - 1, h - r, 2, d);
922 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
923 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
924 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
926 case Lanes::BOUNDARY
:
928 //p->drawEllipse(R_CENTER);
929 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
930 graphics
.DrawEllipse(&myPen
, R_CENTER
);
932 case Lanes::BOUNDARY_C
:
933 case Lanes::BOUNDARY_R
:
934 case Lanes::BOUNDARY_L
:
936 //p->drawRect(R_CENTER);
937 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
938 graphics
.FillRectangle(&myBrush
,R_CENTER
);
944 ::SelectObject(hdc
,oldpen
);
945 ::SelectObject(hdc
,oldbrush
);
954 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
958 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
959 if(data
->m_CommitHash
.IsEmpty())
964 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
965 rItem
.mask
= LVIF_STATE
;
967 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
970 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
972 if (data
->m_Lanes
.size() == 0)
973 m_logEntries
.setLane(data
->m_CommitHash
);
975 std::vector
<int>& lanes
=data
->m_Lanes
;
976 UINT laneNum
= lanes
.size();
978 for (UINT i
= 0; i
< laneNum
; i
++)
979 if (Lanes::isMerge(lanes
[i
])) {
985 int maxWidth
= rect
.Width();
986 int lw
= 3 * rect
.Height() / 4; //laneWidth()
988 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
989 //if (opt.state & QStyle::State_Selected)
990 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
992 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++)
999 if (ln
== Lanes::EMPTY
)
1002 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1003 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1007 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++) {
1013 if (ln
== Lanes::EMPTY
)
1016 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1017 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1019 if (ln
== Lanes::CROSS
)
1021 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1022 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1025 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1031 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1034 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1035 // Take the default processing unless we set this to something else below.
1036 *pResult
= CDRF_DODEFAULT
;
1038 if (m_bNoDispUpdates
)
1043 switch (pLVCD
->nmcd
.dwDrawStage
)
1047 *pResult
= CDRF_NOTIFYITEMDRAW
;
1051 case CDDS_ITEMPREPAINT
:
1053 // This is the prepaint stage for an item. Here's where we set the
1054 // item's text color.
1056 // Tell Windows to send draw notifications for each subitem.
1057 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1059 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1061 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1063 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1067 if (data
->bCopiedSelf
)
1069 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
1070 if (!IsAppThemed()) || !m_bVista
|| ((pLVCD
->nmcd
.uItemState
& CDIS_HOT
)==0))
1071 pLVCD
->clrTextBk
= GetSysColor(COLOR_MENU
);
1075 crText
= m_Colors
.GetColor(CColors::Modified
);
1077 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1078 crText
= RGB(128,128,128);
1080 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1081 pLVCD
->clrTextBk
= RGB(156,156,156);
1082 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1083 pLVCD
->clrTextBk
= RGB(200,200,128);
1085 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1087 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1089 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1090 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1093 if(data
->m_CommitHash
.ToString() == m_HeadHash
)
1095 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1096 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1099 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1100 // crText = GetSysColor(COLOR_GRAYTEXT);
1102 if (data
->m_CommitHash
.IsEmpty())
1104 //crText = GetSysColor(RGB(200,200,0));
1105 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1106 // We changed the font, so we're returning CDRF_NEWFONT. This
1107 // tells the control to recalculate the extent of the text.
1108 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1112 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1114 if (m_bStrictStopped
)
1115 crText
= GetSysColor(COLOR_GRAYTEXT
);
1117 // Store the color back in the NMLVCUSTOMDRAW struct.
1118 pLVCD
->clrText
= crText
;
1122 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1124 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1126 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1129 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
)
1131 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1134 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1136 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1137 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1139 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1140 if( !data
->m_CommitHash
.IsEmpty())
1141 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1143 *pResult
= CDRF_SKIPDEFAULT
;
1148 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1150 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1152 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1153 //if(!data->m_IsFull)
1155 //if(data->SafeFetchFullInfo(&g_Git))
1156 // this->Invalidate();
1157 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1160 if(m_HashMap
[data
->m_CommitHash
].size()!=0)
1164 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1166 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1167 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1169 *pResult
= CDRF_SKIPDEFAULT
;
1177 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1179 if(this->m_IsIDReplaceAction
)
1181 *pResult
= CDRF_DODEFAULT
;
1184 *pResult
= CDRF_DODEFAULT
;
1186 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1190 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1191 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1193 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1195 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1196 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1197 // Get the selected state of the
1198 // item being drawn.
1200 // Fill the background if necessary
1201 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1203 // Draw the icon(s) into the compatible DC
1204 pLogEntry
->GetAction(this);
1206 if (!pLogEntry
->m_IsDiffFiles
)
1207 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1209 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1210 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1213 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1214 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1217 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1218 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1221 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1222 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1224 *pResult
= CDRF_SKIPDEFAULT
;
1230 *pResult
= CDRF_DODEFAULT
;
1233 // CGitLogListBase message handlers
1235 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1237 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1239 // Create a pointer to the item
1240 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1242 // Do the list need text information?
1243 if (!(pItem
->mask
& LVIF_TEXT
))
1246 // By default, clear text buffer.
1247 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1249 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1252 if (m_bNoDispUpdates
|| bOutOfRange
)
1255 // Which item number?
1256 int itemid
= pItem
->iItem
;
1257 GitRev
* pLogEntry
= NULL
;
1258 if (itemid
< m_arShownList
.GetCount())
1259 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1264 temp
.Format(_T("%d"),pItem
->iItem
+1);
1269 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1273 switch (pItem
->iSubItem
)
1275 case this->LOGLIST_GRAPH
: //Graphic
1277 case this->LOGLIST_REBASE
:
1279 if(this->m_IsRebaseReplaceGraph
)
1282 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1283 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1287 case this->LOGLIST_ACTION
: //action -- no text in the column
1289 case this->LOGLIST_HASH
:
1291 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1293 case this->LOGLIST_ID
:
1294 if(this->m_IsIDReplaceAction
)
1295 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1297 case this->LOGLIST_MESSAGE
: //Message
1299 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1301 case this->LOGLIST_AUTHOR
: //Author
1303 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1305 case this->LOGLIST_DATE
: //Date
1306 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1307 lstrcpyn(pItem
->pszText
,
1308 CAppUtils::FormatDateAndTime( pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1312 case this->LOGLIST_EMAIL
:
1314 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1317 case this->LOGLIST_COMMIT_NAME
: //Commit
1319 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1322 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1324 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1327 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1329 lstrcpyn(pItem
->pszText
,
1330 CAppUtils::FormatDateAndTime( pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1333 case this->LOGLIST_BUG
: //Bug ID
1335 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject()), pItem
->cchTextMax
);
1343 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1346 if (pWnd
== GetHeaderCtrl())
1348 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1351 int selIndex
= GetSelectionMark();
1353 return; // nothing selected, nothing to do with a context menu
1355 // if the user selected the info text telling about not all revisions shown due to
1356 // the "stop on copy/rename" option, we also don't show the context menu
1357 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1360 // if the context menu is invoked through the keyboard, we have to use
1361 // a calculated position on where to anchor the menu on
1362 if ((point
.x
== -1) && (point
.y
== -1))
1365 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1366 ClientToScreen(&rect
);
1367 point
= rect
.CenterPoint();
1369 m_nSearchIndex
= selIndex
;
1370 m_bCancelled
= FALSE
;
1372 // calculate some information the context menu commands can use
1373 // CString pathURL = GetURLFromPath(m_path);
1375 POSITION pos
= GetFirstSelectedItemPosition();
1376 int indexNext
= GetNextSelectedItem(pos
);
1380 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1382 GitRev revSelected
= pSelLogEntry
->Rev
;
1383 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1384 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1386 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1388 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1389 if (changedpath
->lCopyFromRev
)
1390 revPrevious
= changedpath
->lCopyFromRev
;
1393 GitRev revSelected2
;
1396 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1397 revSelected2
= pLogEntry
->Rev
;
1399 bool bAllFromTheSameAuthor
= true;
1400 CString firstAuthor
;
1401 CLogDataVector selEntries
;
1402 GitRev revLowest
, revHighest
;
1403 GitRevRangeArray revisionRanges
;
1405 POSITION pos
= GetFirstSelectedItemPosition();
1406 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1407 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1408 selEntries
.push_back(pLogEntry
);
1409 firstAuthor
= pLogEntry
->sAuthor
;
1410 revLowest
= pLogEntry
->Rev
;
1411 revHighest
= pLogEntry
->Rev
;
1414 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1415 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1416 selEntries
.push_back(pLogEntry
);
1417 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1418 bAllFromTheSameAuthor
= false;
1419 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1420 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1426 int FirstSelect
=-1, LastSelect
=-1;
1427 pos
= GetFirstSelectedItemPosition();
1428 FirstSelect
= GetNextSelectedItem(pos
);
1431 LastSelect
= GetNextSelectedItem(pos
);
1433 //entry is selected, now show the popup menu
1435 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
,diffmenu
;
1437 if (popup
.CreatePopupMenu())
1439 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1441 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1442 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1444 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1445 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1447 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1448 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1450 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1451 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1453 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1454 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1455 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1457 if (GetSelectedCount() == 1)
1461 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1463 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1464 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1466 // TortoiseMerge could be improved to take a /blame switch
1467 // and then not 'cat' the files from a unified diff but
1469 // But until that's implemented, the context menu entry for
1470 // this feature is commented out.
1471 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1475 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1476 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1478 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1480 GitRev
*pRev
=pSelLogEntry
;
1481 if(pSelLogEntry
->m_ParentHash
.size()==0)
1483 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1485 if(pRev
->m_ParentHash
.size()<=1)
1487 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1492 gnudiffmenu
.CreatePopupMenu();
1493 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1495 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+(0xFFFF<<16),_T("All Parents"));
1496 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+(0xFFFE<<16),_T("Only Merged Files"));
1498 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1501 str
.Format(_T("Parent %d"), i
+1);
1502 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1507 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1510 GitRev
*pRev
=pSelLogEntry
;
1511 if(pSelLogEntry
->m_ParentHash
.size()==0)
1513 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1515 if(pRev
->m_ParentHash
.size()<=1)
1517 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1518 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1519 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1523 diffmenu
.CreatePopupMenu();
1524 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1525 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1528 str
.Format(_T("Parent %d"), i
+1);
1529 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1530 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1532 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1533 diffmenu
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16), FALSE
);
1539 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1540 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1542 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1543 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1546 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1548 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1550 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1552 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1554 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1555 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1557 // popup.AppendMenu(MF_SEPARATOR, NULL);
1562 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1564 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1566 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1567 GetSelectedCount() == 1)
1568 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1570 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1571 str
.Format(format
,g_Git
.GetCurrentBranch());
1573 bool thisbranch
= false;
1574 CString currentBranch
= _T("refs/heads/")+g_Git
.GetCurrentBranch();
1575 for(int i
=0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1577 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == currentBranch
)
1582 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
)
1583 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1585 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1586 str
.Format(format
,g_Git
.GetCurrentBranch());
1588 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1589 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1592 // Add Switch Branch express Menu
1593 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1594 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1597 std::vector
<CString
*> branchs
;
1600 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1602 ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1603 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1605 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1610 str
.LoadString(IDS_SWITCH_BRANCH
);
1612 if(branchs
.size() == 1)
1615 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1616 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1618 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1621 else if(branchs
.size() > 1)
1623 subbranchmenu
.CreatePopupMenu();
1624 for(int i
=0;i
<branchs
.size();i
++)
1626 if (*branchs
[i
] != currentBranch
)
1628 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1629 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1633 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1637 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1638 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1640 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1641 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1643 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1644 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1646 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1647 str
.Format(format
,g_Git
.GetCurrentBranch());
1649 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
)
1650 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1651 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1653 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1654 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1656 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1657 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1659 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1660 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1662 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1667 if(!pSelLogEntry
->m_Ref
.IsEmpty() && GetSelectedCount() == 1)
1669 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1670 if (pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1671 popup
.AppendMenuIcon(ID_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1672 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1675 if (GetSelectedCount() >= 2)
1677 bool bAddSeparator
= false;
1678 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1680 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1681 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1684 if (GetSelectedCount() == 2)
1686 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1687 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1688 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1689 bAddSeparator
= true;
1694 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1696 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1697 bAddSeparator
= true;
1700 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1701 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1704 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1707 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1709 bool bAddSeparator
= false;
1710 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1712 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
)
1716 headindex
= this->GetHeadIndex();
1719 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1720 CGitHash hash
=g_Git
.GetHash(head
);
1721 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1722 if(pLastEntry
->m_CommitHash
== hash
) {
1723 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1724 bAddSeparator
= true;
1729 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
) {
1730 if (GetSelectedCount() >= 2)
1731 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
1733 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1734 bAddSeparator
= true;
1737 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1738 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1739 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1740 bAddSeparator
= true;
1744 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1748 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1750 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1752 // if (GetSelectedCount() == 1)
1754 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1755 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1756 // popup.AppendMenu(MF_SEPARATOR, NULL);
1760 if (GetSelectedCount() == 1)
1762 bool bAddSeparator
= false;
1763 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && m_HashMap
[pSelLogEntry
->m_CommitHash
].size() >= 1)
1765 // show the push-option only if the log entry has an associated local branch
1766 bool isLocal
= false;
1767 for(int i
=0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1769 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1774 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1775 bAddSeparator
= true;
1779 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1781 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1784 if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() == 1 )
1786 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1788 str
+=m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
1789 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1790 bAddSeparator
= true;
1792 else if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() > 1 )
1794 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1795 submenu
.CreatePopupMenu();
1796 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1798 submenu
.AppendMenuIcon(ID_DELETE
+(i
<<16),m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1801 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
1802 bAddSeparator
= true;
1805 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1807 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1808 } // GetSelectedCount() == 1
1810 if (GetSelectedCount() == 1)
1812 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1813 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
1815 if (GetSelectedCount() != 0)
1817 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1818 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
1821 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1822 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
1824 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1825 // DialogEnableWindow(IDOK, FALSE);
1826 // SetPromptApp(&theApp);
1828 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
1830 // EnableOKButton();
1831 } // if (popup.CreatePopupMenu())
1835 bool CGitLogListBase::IsSelectionContinuous()
1837 if ( GetSelectedCount()==1 )
1839 // if only one revision is selected, the selection is of course
1844 POSITION pos
= GetFirstSelectedItemPosition();
1845 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1848 int itemindex
= GetNextSelectedItem(pos
);
1851 int nextindex
= GetNextSelectedItem(pos
);
1852 if (nextindex
- itemindex
> 1)
1854 bContinuous
= false;
1857 itemindex
= nextindex
;
1863 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly
)
1867 POSITION pos
= GetFirstSelectedItemPosition();
1871 sRev
.LoadString(IDS_LOG_REVISION
);
1873 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1875 sDate
.LoadString(IDS_LOG_DATE
);
1877 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1880 CString sLogCopyText
;
1882 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1886 //pLogEntry->GetFiles(this)
1887 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1889 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
1891 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(" : ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
1892 sPaths
+= _T("\r\n");
1895 CString body
= pLogEntry
->GetBody();
1896 body
.Replace(_T("\n"), _T("\r\n"));
1897 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"),
1898 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
1899 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(),
1901 (LPCTSTR
)CAppUtils::FormatDateAndTime( pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1902 (LPCTSTR
)sMessage
, pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim(),
1904 sClipdata
+= sLogCopyText
;
1908 sClipdata
+= pLogEntry
->m_CommitHash
;
1913 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1918 void CGitLogListBase::DiffSelectedRevWithPrevious()
1920 if (m_bThreadRunning
)
1923 int FirstSelect
=-1, LastSelect
=-1;
1924 POSITION pos
= GetFirstSelectedItemPosition();
1925 FirstSelect
= GetNextSelectedItem(pos
);
1928 LastSelect
= GetNextSelectedItem(pos
);
1931 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
1934 UpdateLogInfoLabel();
1935 int selIndex
= m_LogList
.GetSelectionMark();
1938 int selCount
= m_LogList
.GetSelectedCount();
1942 // Find selected entry in the log list
1943 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
1944 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
1945 long rev1
= pLogEntry
->Rev
;
1947 CTGitPath path
= m_path
;
1949 // See how many files under the relative root were changed in selected revision
1951 LogChangedPath
* changed
= NULL
;
1952 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
1954 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
1955 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
1962 if (m_path
.IsDirectory() && nChanged
== 1)
1964 // We're looking at the log for a directory and only one file under dir was changed in the revision
1965 // Do diff on that file instead of whole directory
1966 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
1969 m_bCancelled
= FALSE
;
1970 DialogEnableWindow(IDOK
, FALSE
);
1971 SetPromptApp(&theApp
);
1972 theApp
.DoWaitCursor(1);
1976 GitDiff
diff(this, m_hWnd
, true);
1977 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1978 diff
.SetHEADPeg(m_LogRevision
);
1979 diff
.ShowCompare(path
, rev2
, path
, rev1
);
1983 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1986 theApp
.DoWaitCursor(-1);
1991 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1993 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
1996 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
1998 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2000 if (pFindInfo
->lvfi
.psz
== 0)
2003 CString sCmp
= pFindInfo
->lvfi
.psz
;
2005 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2007 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2008 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2009 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2011 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2019 if (sCmp
.Compare(sRev
)==0)
2026 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2028 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2030 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2031 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2032 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2034 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2042 if (sCmp
.Compare(sRev
)==0)
2054 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
2059 this->m_arShownList
.SafeRemoveAll();
2061 this->m_logEntries
.ClearAll();
2062 this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
);
2064 //this->m_logEntries.ParserFromLog();
2065 SetItemCountEx(this->m_logEntries
.size());
2067 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2071 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2072 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2077 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2078 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2088 int CGitLogListBase::BeginFetchLog()
2092 this->m_arShownList
.SafeRemoveAll();
2094 this->m_logEntries
.ClearAll();
2097 this->m_LogCache
.ClearAllParent();
2099 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2102 if(this->m_Path
.IsEmpty())
2109 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2110 // if(this->m_bAllBranch)
2111 mask
|= m_ShowMask
;
2115 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2117 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2120 CString
*pFrom
, *pTo
;
2122 CString
head(_T("HEAD"));
2123 if(!this->m_startrev
.IsEmpty())
2125 pFrom
= &this->m_startrev
;
2126 if(!this->m_endrev
.IsEmpty())
2127 pTo
= &this->m_endrev
;
2133 data
.m_From
= m_From
;
2136 #if 0 /* use tortoiegit filter */
2137 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2138 data
.m_Author
= this->m_sFilterText
;
2140 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2141 data
.m_MessageFilter
= this->m_sFilterText
;
2143 data
.m_IsRegex
= m_bFilterWithRegex
;
2146 CString cmd
=g_Git
.GetLogCmd(m_StartRef
,path
,-1,mask
,pFrom
,pTo
,true,&data
);
2148 //this->m_logEntries.ParserFromLog();
2149 if(IsInWorkingThread())
2151 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2155 SetItemCountEx(this->m_logEntries
.size());
2160 if(g_Git
.IsInitRepos())
2163 if(git_open_log(&m_DllGitLog
,CUnicodeUtils::GetMulti(cmd
,CP_ACP
).GetBuffer()))
2171 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2173 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2175 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2177 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2179 DiffSelectedRevWithPrevious();
2184 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2191 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2193 // select all entries
2194 for (int i
=0; i
<GetItemCount(); ++i
)
2196 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2202 if (m_hAccel
&& !bSkipAccelerator
)
2204 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2210 //m_tooltips.RelayEvent(pMsg);
2211 return __super::PreTranslateMessage(pMsg
);
2214 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2216 // a double click on an entry in the revision list has happened
2219 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2220 DiffSelectedRevWithPrevious();
2223 int CGitLogListBase::FetchLogAsync(void * data
)
2226 m_bExitThread
=FALSE
;
2227 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2228 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2229 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2230 if (m_LoadingThread
==NULL
)
2232 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2233 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2234 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2240 //this is the thread function which calls the subversion function
2241 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2243 return ((CGitLogListBase
*)pVoid
)->LogThread();
2246 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2249 oldest
=CTime::GetCurrentTime();
2250 latest
=CTime(1971,1,2,0,0,0);
2251 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2253 if(m_logEntries
[i
].IsEmpty())
2256 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2257 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2259 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2260 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2268 UINT
CGitLogListBase::LogThread()
2270 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2272 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2273 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2279 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2280 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2285 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2286 bool bRegex
= false;
2287 if (m_bFilterWithRegex
)
2288 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2290 TRACE(_T("\n===Begin===\n"));
2291 //Update work copy item;
2293 if( m_logEntries
.size() > 0)
2295 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2297 m_arShownList
.SafeAdd(pRev
);
2301 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2303 // store commit number of the last selected commit/line before the refresh or -1
2304 int lastSelectedHashNItem
= -1;
2306 if(!g_Git
.IsInitRepos())
2308 g_Git
.m_critGitDllSec
.Lock();
2309 git_get_log_firstcommit(m_DllGitLog
);
2310 int total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2311 g_Git
.m_critGitDllSec
.Unlock();
2314 t2
=t1
=GetTickCount();
2315 int oldprecentage
= 0;
2316 int oldsize
=m_logEntries
.size();
2320 g_Git
.m_critGitDllSec
.Lock();
2321 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, 0);
2322 g_Git
.m_critGitDllSec
.Unlock();
2327 //printf("%s\r\n",commit.GetSubject());
2331 CGitHash hash
= (char*)commit
.m_hash
;
2333 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2334 pRev
->m_GitCommit
= commit
;
2335 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2338 g_Git
.m_critGitDllSec
.Lock();
2339 git_get_notes(commit
.m_hash
,¬e
);
2340 g_Git
.m_critGitDllSec
.Unlock();
2344 pRev
->m_Notes
.Empty();
2345 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2348 if(!pRev
->m_IsDiffFiles
)
2350 pRev
->m_CallDiffAsync
= DiffAsync
;
2353 pRev
->ParserParentFromCommit(&commit
);
2360 if(!m_sFilterText
.IsEmpty())
2362 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2365 this->m_critSec
.Lock();
2366 m_logEntries
.push_back(hash
);
2367 m_arShownList
.SafeAdd(pRev
);
2368 this->m_critSec
.Unlock();
2370 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2371 lastSelectedHashNItem
= m_arShownList
.GetCount() - 1;
2375 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2378 int percent
=m_logEntries
.size()*100/total
+ GITLOG_START
+1;
2381 if(percent
< GITLOG_START
)
2382 percent
= GITLOG_START
+1;
2384 oldsize
= m_logEntries
.size();
2385 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2387 //if( percent > oldprecentage )
2389 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2390 oldprecentage
= percent
;
2395 g_Git
.m_critGitDllSec
.Lock();
2396 git_close_log(m_DllGitLog
);
2397 g_Git
.m_critGitDllSec
.Unlock();
2401 // restore last selected item
2402 if (lastSelectedHashNItem
>= 0)
2404 SetItemState(lastSelectedHashNItem
, LVIS_SELECTED
, LVIS_SELECTED
);
2405 EnsureVisible(lastSelectedHashNItem
, FALSE
);
2409 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2410 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2412 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2417 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2419 SafeTerminateThread();
2421 this->SetItemCountEx(0);
2426 //Update branch and Tag info
2428 //Assume Thread have exited
2429 //if(!m_bThreadRunning)
2431 m_logEntries
.clear();
2435 m_sFilterText
.Empty();
2440 InterlockedExchange(&m_bExitThread
,FALSE
);
2442 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2443 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2444 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2446 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2447 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2448 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2452 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2456 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2458 type
|= tr1::regex_constants::icase
;
2459 pat
= tr1::wregex(regexp_str
, type
);
2462 catch (exception
) {}
2465 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2468 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2471 if ((bRegex
)&&(m_bFilterWithRegex
))
2473 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2475 if(this->m_bShowBugtraqColumn
)
2477 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject());
2479 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2480 if (regex_search(wstring(sBugIds
), pat
, flags
))
2487 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2489 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2490 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2496 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2498 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2499 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2505 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2507 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2512 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2518 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2520 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2521 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2527 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2529 CTGitPathList
*pathList
=NULL
;
2530 if( pRev
->m_IsDiffFiles
)
2531 pathList
= &pRev
->GetFiles(this);
2534 if(!pRev
->m_IsSimpleListReady
)
2535 pRev
->SafeGetSimpleList(&g_Git
);
2539 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2541 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2545 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2551 for(INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2553 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2562 CString find
= m_sFilterText
;
2565 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2567 if(this->m_bShowBugtraqColumn
)
2569 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject());
2571 sBugIds
.MakeLower();
2572 if ((sBugIds
.Find(find
) >= 0))
2579 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2581 CString msg
= pRev
->GetSubject();
2583 msg
= msg
.MakeLower();
2584 if ((msg
.Find(find
) >= 0))
2590 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2592 CString msg
= pRev
->GetBody();
2594 msg
= msg
.MakeLower();
2595 if ((msg
.Find(find
) >= 0))
2601 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2603 CString msg
= pRev
->GetAuthorName();
2604 msg
= msg
.MakeLower();
2605 if ((msg
.Find(find
) >= 0))
2611 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2613 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2614 if ((sRev
.Find(find
) >= 0))
2620 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2622 CTGitPathList
*pathList
=NULL
;
2623 if( pRev
->m_IsDiffFiles
)
2624 pathList
= &pRev
->GetFiles(this);
2627 if(!pRev
->m_IsSimpleListReady
)
2628 pRev
->SafeGetSimpleList(&g_Git
);
2631 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
2633 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
2634 CString path
= cpath
->GetGitOldPathString();
2636 if ((path
.Find(find
)>=0))
2640 path
= cpath
->GetGitPathString();
2642 if ((path
.Find(find
)>=0))
2648 for (INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2650 CString path
= pRev
->m_SimpleFileList
[i
];
2652 if ((path
.Find(find
)>=0))
2658 } // else (from if (bRegex))
2663 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
2666 pShownlist
->SafeRemoveAll();
2668 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2669 bool bRegex
= false;
2670 if (m_bFilterWithRegex
)
2671 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2673 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2675 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2677 if ((bRegex
)&&(m_bFilterWithRegex
))
2680 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2682 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2683 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2685 pShownlist
->SafeAdd(m_logEntries
[i
]);
2690 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2692 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
2693 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
2695 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2699 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2701 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
2702 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
2704 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2708 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2710 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2713 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2715 CTGitPath cpath
= pathList
[cpPathIndex
];
2716 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2718 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2722 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2724 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2728 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
2730 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2736 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2738 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
2740 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2744 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2746 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2747 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2749 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2756 CString find
= m_sFilterText
;
2759 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2761 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2763 sBugIDs
= sBugIDs
.MakeLower();
2764 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2766 pShownlist
->SafeAdd(m_logEntries
[i
]);
2771 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_SUBJECT
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2773 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
2775 msg
= msg
.MakeLower();
2776 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2778 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2782 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2784 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
2786 msg
= msg
.MakeLower();
2787 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2789 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2793 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2795 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2798 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2800 CTGitPath cpath
= pathList
[cpPathIndex
];
2801 CString path
= cpath
.GetGitOldPathString();
2803 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2805 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2809 path
= cpath
.GetGitPathString();
2811 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2813 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2817 path
= cpath
.GetActionName();
2819 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2821 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2827 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2829 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
2830 msg
= msg
.MakeLower();
2831 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2833 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2837 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2839 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2840 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2842 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2846 } // else (from if (bRegex))
2847 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2851 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
2854 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2860 return time <= m_To;
2863 return time >= m_From;
2865 return ((time >= m_From)&&(time <= m_To));
2867 return TRUE
; /* git dll will filter time range */
2871 void CGitLogListBase::StartFilter()
2873 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2874 RecalculateShownList(&m_arShownList
);
2875 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2879 SetItemCountEx(ShownCountWithStopped());
2880 RedrawItems(0, ShownCountWithStopped());
2884 void CGitLogListBase::RemoveFilter()
2887 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2889 m_arShownList
.SafeRemoveAll();
2891 // reset the time filter too
2893 m_timFrom
= (__time64_t(m_tFrom
));
2894 m_timTo
= (__time64_t(m_tTo
));
2895 m_DateFrom
.SetTime(&m_timFrom
);
2896 m_DateTo
.SetTime(&m_timTo
);
2897 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
2898 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
2901 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2903 if(this->m_IsOldFirst
)
2905 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2909 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2912 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2914 SetItemCountEx(ShownCountWithStopped());
2915 RedrawItems(0, ShownCountWithStopped());
2917 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2920 void CGitLogListBase::Clear()
2922 m_arShownList
.SafeRemoveAll();
2925 m_logEntries
.ClearAll();
2929 void CGitLogListBase::OnDestroy()
2931 // save the column widths to the registry
2934 SafeTerminateThread();
2935 SafeTerminateAsyncDiffThread();
2938 while(m_LogCache
.SaveCache())
2946 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2947 // MB_YESNO) == IDNO)
2951 CHintListCtrl::OnDestroy();
2954 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
2956 UNREFERENCED_PARAMETER(lParam
);
2959 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
2960 this->InvalidateRect(rect
);
2966 * Save column widths to the registry
2968 void CGitLogListBase::SaveColumnWidths()
2970 int maxcol
= m_ColumnManager
.GetColumnCount();
2972 for (int col
= 0; col
< maxcol
; col
++)
2973 if (m_ColumnManager
.IsVisible (col
))
2974 m_ColumnManager
.ColumnResized (col
);
2976 m_ColumnManager
.WriteSettings();
2979 int CGitLogListBase::GetHeadIndex()
2981 if(m_HeadHash
.IsEmpty())
2984 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
2986 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
2989 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
2995 void CGitLogListBase::OnFind()
2999 m_pFindDialog
= new CFindDlg(this);
3000 m_pFindDialog
->Create(this);
3003 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3005 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3007 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3009 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3012 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3015 ASSERT(m_pFindDialog
!= NULL
);
3016 bool bFound
= false;
3019 if (m_pFindDialog
->IsTerminating())
3021 // invalidate the handle identifying the dialog box.
3022 m_pFindDialog
= NULL
;
3026 if(m_pFindDialog
->IsRef())
3029 str
=m_pFindDialog
->GetFindString();
3034 hash
= g_Git
.GetHash(str
);
3038 for (i
= 0; i
<m_arShownList
.GetCount(); i
++)
3040 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3041 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3051 if(m_pFindDialog
->FindNext())
3053 //read data from dialog
3054 CString FindText
= m_pFindDialog
->GetFindString();
3055 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3058 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3060 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3063 for (i
= this->m_nSearchIndex
; i
<m_arShownList
.GetCount()&&!bFound
; i
++)
3065 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3068 str
+=pLogEntry
->m_CommitHash
.ToString();
3071 for(int j
=0;j
<this->m_HashMap
[pLogEntry
->m_CommitHash
].size();j
++)
3073 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3077 str
+=pLogEntry
->GetAuthorEmail();
3079 str
+=pLogEntry
->GetAuthorName();
3081 str
+=pLogEntry
->GetBody();
3083 str
+=pLogEntry
->GetCommitterEmail();
3085 str
+=pLogEntry
->GetCommitterName();
3087 str
+=pLogEntry
->GetSubject();
3091 /*Because changed files list is loaded on demand when gui show,
3092 files will empty when files have not fetched.
3094 we can add it back by using one-way diff(with outnumber changed and rename detect.
3095 here just need changed filename list. one-way is much quicker.
3097 if(pLogEntry
->m_IsFull
)
3099 for(int i
=0;i
<pLogEntry
->GetFiles(this).GetCount();i
++)
3101 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3103 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3109 if(!pLogEntry
->m_IsSimpleListReady
)
3110 pLogEntry
->SafeGetSimpleList(&g_Git
);
3112 for(int i
=0;i
<pLogEntry
->m_SimpleFileList
.size();i
++)
3114 str
+=pLogEntry
->m_SimpleFileList
[i
];
3123 if (regex_search(wstring(str
), pat
, flags
))
3133 if (str
.Find(FindText
) >= 0)
3143 msg
= msg
.MakeLower();
3144 CString find
= FindText
.MakeLower();
3145 if (msg
.Find(find
) >= 0)
3152 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3154 } // if(m_pFindDialog->FindNext())
3155 //UpdateLogInfoLabel();
3159 this->m_nSearchIndex
= i
;
3160 EnsureVisible(i
, FALSE
);
3161 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3162 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3163 SetSelectionMark(i
);
3164 //FillLogMessageCtrl();
3167 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3168 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3174 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3176 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3181 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3183 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);