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 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(IDS_FILESCHANGES
, 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
)
1041 switch (pLVCD
->nmcd
.dwDrawStage
)
1045 *pResult
= CDRF_NOTIFYITEMDRAW
;
1049 case CDDS_ITEMPREPAINT
:
1051 // This is the prepaint stage for an item. Here's where we set the
1052 // item's text color.
1054 // Tell Windows to send draw notifications for each subitem.
1055 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1057 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1059 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1061 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1064 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1065 crText
= RGB(128,128,128);
1067 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1068 pLVCD
->clrTextBk
= RGB(156,156,156);
1069 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1070 pLVCD
->clrTextBk
= RGB(200,200,128);
1072 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1074 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1076 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1077 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1080 if(data
->m_CommitHash
.ToString() == m_HeadHash
)
1082 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1083 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1086 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1087 // crText = GetSysColor(COLOR_GRAYTEXT);
1089 if (data
->m_CommitHash
.IsEmpty())
1091 //crText = GetSysColor(RGB(200,200,0));
1092 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1093 // We changed the font, so we're returning CDRF_NEWFONT. This
1094 // tells the control to recalculate the extent of the text.
1095 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1099 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1101 if (m_bStrictStopped
)
1102 crText
= GetSysColor(COLOR_GRAYTEXT
);
1104 // Store the color back in the NMLVCUSTOMDRAW struct.
1105 pLVCD
->clrText
= crText
;
1109 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1111 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1113 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1116 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty())
1118 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1121 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1123 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1124 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1126 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1127 if( !data
->m_CommitHash
.IsEmpty())
1128 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1130 *pResult
= CDRF_SKIPDEFAULT
;
1135 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1137 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1139 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1140 //if(!data->m_IsFull)
1142 //if(data->SafeFetchFullInfo(&g_Git))
1143 // this->Invalidate();
1144 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1147 if(m_HashMap
[data
->m_CommitHash
].size()!=0)
1151 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1153 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1154 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1156 *pResult
= CDRF_SKIPDEFAULT
;
1164 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1166 if(this->m_IsIDReplaceAction
)
1168 *pResult
= CDRF_DODEFAULT
;
1171 *pResult
= CDRF_DODEFAULT
;
1173 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1177 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1178 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1180 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1182 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1183 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1184 // Get the selected state of the
1185 // item being drawn.
1187 // Fill the background if necessary
1188 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1190 // Draw the icon(s) into the compatible DC
1191 pLogEntry
->GetAction(this);
1193 if (!pLogEntry
->m_IsDiffFiles
)
1194 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1196 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1197 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1200 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1201 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1204 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1205 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1208 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1209 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1211 *pResult
= CDRF_SKIPDEFAULT
;
1217 *pResult
= CDRF_DODEFAULT
;
1220 // CGitLogListBase message handlers
1222 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1224 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1226 // Create a pointer to the item
1227 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1229 // Do the list need text information?
1230 if (!(pItem
->mask
& LVIF_TEXT
))
1233 // By default, clear text buffer.
1234 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1236 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1239 if (m_bNoDispUpdates
|| bOutOfRange
)
1242 // Which item number?
1243 int itemid
= pItem
->iItem
;
1244 GitRev
* pLogEntry
= NULL
;
1245 if (itemid
< m_arShownList
.GetCount())
1246 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1251 temp
.Format(_T("%d"),pItem
->iItem
+1);
1256 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1260 switch (pItem
->iSubItem
)
1262 case this->LOGLIST_GRAPH
: //Graphic
1264 case this->LOGLIST_REBASE
:
1266 if(this->m_IsRebaseReplaceGraph
)
1269 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1270 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1274 case this->LOGLIST_ACTION
: //action -- no text in the column
1276 case this->LOGLIST_HASH
:
1278 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1280 case this->LOGLIST_ID
:
1281 if(this->m_IsIDReplaceAction
)
1282 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1284 case this->LOGLIST_MESSAGE
: //Message
1286 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1288 case this->LOGLIST_AUTHOR
: //Author
1290 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1292 case this->LOGLIST_DATE
: //Date
1293 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1294 lstrcpyn(pItem
->pszText
,
1295 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1299 case this->LOGLIST_EMAIL
:
1301 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1304 case this->LOGLIST_COMMIT_NAME
: //Commit
1306 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1309 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1311 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1314 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1315 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1316 lstrcpyn(pItem
->pszText
,
1317 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1320 case this->LOGLIST_BUG
: //Bug ID
1322 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1330 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1333 if (pWnd
== GetHeaderCtrl())
1335 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1338 int selIndex
= GetSelectionMark();
1340 return; // nothing selected, nothing to do with a context menu
1342 // if the user selected the info text telling about not all revisions shown due to
1343 // the "stop on copy/rename" option, we also don't show the context menu
1344 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1347 // if the context menu is invoked through the keyboard, we have to use
1348 // a calculated position on where to anchor the menu on
1349 if ((point
.x
== -1) && (point
.y
== -1))
1352 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1353 ClientToScreen(&rect
);
1354 point
= rect
.CenterPoint();
1356 m_nSearchIndex
= selIndex
;
1357 m_bCancelled
= FALSE
;
1359 // calculate some information the context menu commands can use
1360 // CString pathURL = GetURLFromPath(m_path);
1362 POSITION pos
= GetFirstSelectedItemPosition();
1363 int indexNext
= GetNextSelectedItem(pos
);
1367 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1369 GitRev revSelected
= pSelLogEntry
->Rev
;
1370 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1371 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1373 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1375 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1376 if (changedpath
->lCopyFromRev
)
1377 revPrevious
= changedpath
->lCopyFromRev
;
1380 GitRev revSelected2
;
1383 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1384 revSelected2
= pLogEntry
->Rev
;
1386 bool bAllFromTheSameAuthor
= true;
1387 CString firstAuthor
;
1388 CLogDataVector selEntries
;
1389 GitRev revLowest
, revHighest
;
1390 GitRevRangeArray revisionRanges
;
1392 POSITION pos
= GetFirstSelectedItemPosition();
1393 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1394 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1395 selEntries
.push_back(pLogEntry
);
1396 firstAuthor
= pLogEntry
->sAuthor
;
1397 revLowest
= pLogEntry
->Rev
;
1398 revHighest
= pLogEntry
->Rev
;
1401 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1402 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1403 selEntries
.push_back(pLogEntry
);
1404 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1405 bAllFromTheSameAuthor
= false;
1406 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1407 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1413 int FirstSelect
=-1, LastSelect
=-1;
1414 pos
= GetFirstSelectedItemPosition();
1415 FirstSelect
= GetNextSelectedItem(pos
);
1418 LastSelect
= GetNextSelectedItem(pos
);
1420 //entry is selected, now show the popup menu
1422 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
,diffmenu
;
1424 if (popup
.CreatePopupMenu())
1426 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1427 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1429 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1430 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1432 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1433 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1435 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1436 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1438 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1439 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1441 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1442 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1443 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1445 if (GetSelectedCount() == 1)
1449 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1451 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1452 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1456 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1457 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1459 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1461 GitRev
*pRev
=pSelLogEntry
;
1462 if(pSelLogEntry
->m_ParentHash
.size()==0)
1464 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1466 if(pRev
->m_ParentHash
.size()<=1)
1468 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1473 gnudiffmenu
.CreatePopupMenu();
1474 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1476 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+ (0xFFFF << 16), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1477 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+ (0xFFFE << 16), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1479 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1482 str
.Format(IDS_PARENT
, i
+ 1);
1483 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1488 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1491 GitRev
*pRev
=pSelLogEntry
;
1492 if(pSelLogEntry
->m_ParentHash
.size()==0)
1494 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1496 if(pRev
->m_ParentHash
.size()<=1)
1498 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1499 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1500 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1504 diffmenu
.CreatePopupMenu();
1505 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1506 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1509 str
.Format(IDS_PARENT
, i
+ 1);
1510 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1511 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1513 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1514 diffmenu
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16), FALSE
);
1520 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1521 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1523 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1524 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1526 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1528 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1529 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1531 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir())
1533 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1534 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1536 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1537 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1540 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1542 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1543 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1545 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1549 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1551 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1553 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1555 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1557 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1558 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1560 // popup.AppendMenu(MF_SEPARATOR, NULL);
1565 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1567 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1569 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1570 GetSelectedCount() == 1)
1571 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1573 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1574 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1576 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1577 str
.Format(format
,g_Git
.GetCurrentBranch());
1579 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
)
1580 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1582 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1583 str
.Format(format
,g_Git
.GetCurrentBranch());
1585 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1586 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1589 // Add Switch Branch express Menu
1590 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1591 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1594 std::vector
<CString
*> branchs
;
1595 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1597 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1598 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1600 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1605 str
.LoadString(IDS_SWITCH_BRANCH
);
1607 if(branchs
.size() == 1)
1610 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1611 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1613 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1616 else if(branchs
.size() > 1)
1618 subbranchmenu
.CreatePopupMenu();
1619 for(int i
=0;i
<branchs
.size();i
++)
1621 if (*branchs
[i
] != currentBranch
)
1623 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1624 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1628 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1632 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1633 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1635 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1636 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1638 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1639 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1641 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1642 str
.Format(format
,g_Git
.GetCurrentBranch());
1644 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
)
1645 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1646 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1648 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1649 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1651 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1652 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1654 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1655 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1657 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1662 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1664 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1665 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1666 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1667 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1670 if (GetSelectedCount() >= 2)
1672 bool bAddSeparator
= false;
1673 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1675 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1676 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1679 if (GetSelectedCount() == 2)
1681 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1682 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1683 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1684 bAddSeparator
= true;
1689 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1691 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1692 bAddSeparator
= true;
1695 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1696 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1699 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1702 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1704 bool bAddSeparator
= false;
1705 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1707 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
)
1711 headindex
= this->GetHeadIndex();
1714 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1715 CGitHash hash
=g_Git
.GetHash(head
);
1716 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1717 if(pLastEntry
->m_CommitHash
== hash
) {
1718 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1719 bAddSeparator
= true;
1724 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
) {
1725 if (GetSelectedCount() >= 2)
1726 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
1728 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1729 bAddSeparator
= true;
1732 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1733 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1734 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1735 bAddSeparator
= true;
1739 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1743 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1745 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1747 // if (GetSelectedCount() == 1)
1749 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1750 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1751 // popup.AppendMenu(MF_SEPARATOR, NULL);
1755 if (GetSelectedCount() == 1)
1757 bool bAddSeparator
= false;
1758 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && m_HashMap
[pSelLogEntry
->m_CommitHash
].size() >= 1)
1760 // show the push-option only if the log entry has an associated local branch
1761 bool isLocal
= false;
1762 for(int i
=0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1764 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1769 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1770 bAddSeparator
= true;
1774 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1776 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1778 std::vector
<CString
*> branchs
;
1779 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1781 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
1782 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1785 if (branchs
.size() == 1)
1787 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1790 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1791 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
1792 bAddSeparator
= true;
1794 else if (branchs
.size() > 1)
1796 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1797 submenu
.CreatePopupMenu();
1798 for (int i
= 0; i
< branchs
.size(); i
++)
1800 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
1801 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
1804 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
1805 bAddSeparator
= true;
1808 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1810 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1811 } // GetSelectedCount() == 1
1813 if (GetSelectedCount() == 1)
1815 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1816 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
1818 if (GetSelectedCount() != 0)
1820 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1821 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
1824 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1825 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
1827 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1828 // DialogEnableWindow(IDOK, FALSE);
1829 // SetPromptApp(&theApp);
1831 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
1833 // EnableOKButton();
1834 } // if (popup.CreatePopupMenu())
1838 bool CGitLogListBase::IsSelectionContinuous()
1840 if ( GetSelectedCount()==1 )
1842 // if only one revision is selected, the selection is of course
1847 POSITION pos
= GetFirstSelectedItemPosition();
1848 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1851 int itemindex
= GetNextSelectedItem(pos
);
1854 int nextindex
= GetNextSelectedItem(pos
);
1855 if (nextindex
- itemindex
> 1)
1857 bContinuous
= false;
1860 itemindex
= nextindex
;
1866 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly
)
1870 POSITION pos
= GetFirstSelectedItemPosition();
1874 sRev
.LoadString(IDS_LOG_REVISION
);
1876 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1878 sDate
.LoadString(IDS_LOG_DATE
);
1880 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1883 CString sLogCopyText
;
1885 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1889 //pLogEntry->GetFiles(this)
1890 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1892 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
1894 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(" : ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
1895 sPaths
+= _T("\r\n");
1898 CString body
= pLogEntry
->GetBody();
1899 body
.Replace(_T("\n"), _T("\r\n"));
1900 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"),
1901 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
1902 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(),
1904 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1905 (LPCTSTR
)sMessage
, pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim(),
1907 sClipdata
+= sLogCopyText
;
1911 sClipdata
+= pLogEntry
->m_CommitHash
;
1916 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1921 void CGitLogListBase::DiffSelectedRevWithPrevious()
1923 if (m_bThreadRunning
)
1926 int FirstSelect
=-1, LastSelect
=-1;
1927 POSITION pos
= GetFirstSelectedItemPosition();
1928 FirstSelect
= GetNextSelectedItem(pos
);
1931 LastSelect
= GetNextSelectedItem(pos
);
1934 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
1937 UpdateLogInfoLabel();
1938 int selIndex
= m_LogList
.GetSelectionMark();
1941 int selCount
= m_LogList
.GetSelectedCount();
1945 // Find selected entry in the log list
1946 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
1947 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
1948 long rev1
= pLogEntry
->Rev
;
1950 CTGitPath path
= m_path
;
1952 // See how many files under the relative root were changed in selected revision
1954 LogChangedPath
* changed
= NULL
;
1955 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
1957 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
1958 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
1965 if (m_path
.IsDirectory() && nChanged
== 1)
1967 // We're looking at the log for a directory and only one file under dir was changed in the revision
1968 // Do diff on that file instead of whole directory
1969 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
1972 m_bCancelled
= FALSE
;
1973 DialogEnableWindow(IDOK
, FALSE
);
1974 SetPromptApp(&theApp
);
1975 theApp
.DoWaitCursor(1);
1979 GitDiff
diff(this, m_hWnd
, true);
1980 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1981 diff
.SetHEADPeg(m_LogRevision
);
1982 diff
.ShowCompare(path
, rev2
, path
, rev1
);
1986 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1989 theApp
.DoWaitCursor(-1);
1994 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1996 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
1999 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2001 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2003 if (pFindInfo
->lvfi
.psz
== 0)
2006 CString sCmp
= pFindInfo
->lvfi
.psz
;
2008 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2010 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2011 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2012 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2014 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2022 if (sCmp
.Compare(sRev
)==0)
2029 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2031 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2033 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2034 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2035 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2037 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2045 if (sCmp
.Compare(sRev
)==0)
2057 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
2062 this->m_arShownList
.SafeRemoveAll();
2064 this->m_logEntries
.ClearAll();
2065 this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
);
2067 //this->m_logEntries.ParserFromLog();
2068 SetItemCountEx(this->m_logEntries
.size());
2070 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2074 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2075 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2080 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2081 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2091 int CGitLogListBase::BeginFetchLog()
2095 this->m_arShownList
.SafeRemoveAll();
2097 this->m_logEntries
.ClearAll();
2100 this->m_LogCache
.ClearAllParent();
2102 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2105 if(this->m_Path
.IsEmpty())
2112 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2113 // if(this->m_bAllBranch)
2114 mask
|= m_ShowMask
;
2118 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2120 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2123 CString
*pFrom
, *pTo
;
2125 CString
head(_T("HEAD"));
2126 if(!this->m_startrev
.IsEmpty())
2128 pFrom
= &this->m_startrev
;
2129 if(!this->m_endrev
.IsEmpty())
2130 pTo
= &this->m_endrev
;
2136 data
.m_From
= m_From
;
2139 #if 0 /* use tortoiegit filter */
2140 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2141 data
.m_Author
= this->m_sFilterText
;
2143 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2144 data
.m_MessageFilter
= this->m_sFilterText
;
2146 data
.m_IsRegex
= m_bFilterWithRegex
;
2149 CString cmd
=g_Git
.GetLogCmd(m_StartRef
,path
,-1,mask
,pFrom
,pTo
,true,&data
);
2151 //this->m_logEntries.ParserFromLog();
2152 if(IsInWorkingThread())
2154 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2158 SetItemCountEx(this->m_logEntries
.size());
2163 if(g_Git
.IsInitRepos())
2166 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2174 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2176 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2178 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2180 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2182 DiffSelectedRevWithPrevious();
2187 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2194 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2196 // select all entries
2197 for (int i
=0; i
<GetItemCount(); ++i
)
2199 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2205 if (m_hAccel
&& !bSkipAccelerator
)
2207 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2213 //m_tooltips.RelayEvent(pMsg);
2214 return __super::PreTranslateMessage(pMsg
);
2217 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2219 // a double click on an entry in the revision list has happened
2222 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2223 DiffSelectedRevWithPrevious();
2226 int CGitLogListBase::FetchLogAsync(void * data
)
2229 m_bExitThread
=FALSE
;
2230 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2231 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2232 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2233 if (m_LoadingThread
==NULL
)
2235 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2236 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2237 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2243 //this is the thread function which calls the subversion function
2244 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2246 return ((CGitLogListBase
*)pVoid
)->LogThread();
2249 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2252 oldest
=CTime::GetCurrentTime();
2253 latest
=CTime(1971,1,2,0,0,0);
2254 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2256 if(m_logEntries
[i
].IsEmpty())
2259 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2260 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2262 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2263 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2271 UINT
CGitLogListBase::LogThread()
2273 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2275 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2276 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2282 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2283 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2288 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2289 bool bRegex
= false;
2290 if (m_bFilterWithRegex
)
2291 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2293 TRACE(_T("\n===Begin===\n"));
2294 //Update work copy item;
2296 if( m_logEntries
.size() > 0)
2298 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2300 m_arShownList
.SafeAdd(pRev
);
2304 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2306 // store commit number of the last selected commit/line before the refresh or -1
2307 int lastSelectedHashNItem
= -1;
2309 if(!g_Git
.IsInitRepos())
2311 g_Git
.m_critGitDllSec
.Lock();
2312 git_get_log_firstcommit(m_DllGitLog
);
2313 int total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2314 g_Git
.m_critGitDllSec
.Unlock();
2317 t2
=t1
=GetTickCount();
2318 int oldprecentage
= 0;
2319 int oldsize
=m_logEntries
.size();
2323 g_Git
.m_critGitDllSec
.Lock();
2324 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, 0);
2325 g_Git
.m_critGitDllSec
.Unlock();
2330 //printf("%s\r\n",commit.GetSubject());
2334 CGitHash hash
= (char*)commit
.m_hash
;
2336 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2337 pRev
->m_GitCommit
= commit
;
2338 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2341 g_Git
.m_critGitDllSec
.Lock();
2342 git_get_notes(commit
.m_hash
,¬e
);
2343 g_Git
.m_critGitDllSec
.Unlock();
2347 pRev
->m_Notes
.Empty();
2348 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2351 if(!pRev
->m_IsDiffFiles
)
2353 pRev
->m_CallDiffAsync
= DiffAsync
;
2356 pRev
->ParserParentFromCommit(&commit
);
2363 if(!m_sFilterText
.IsEmpty())
2365 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2368 this->m_critSec
.Lock();
2369 m_logEntries
.push_back(hash
);
2370 m_arShownList
.SafeAdd(pRev
);
2371 this->m_critSec
.Unlock();
2373 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2374 lastSelectedHashNItem
= m_arShownList
.GetCount() - 1;
2378 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2381 int percent
=m_logEntries
.size()*100/total
+ GITLOG_START
+1;
2384 if(percent
< GITLOG_START
)
2385 percent
= GITLOG_START
+1;
2387 oldsize
= m_logEntries
.size();
2388 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2390 //if( percent > oldprecentage )
2392 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2393 oldprecentage
= percent
;
2398 g_Git
.m_critGitDllSec
.Lock();
2399 git_close_log(m_DllGitLog
);
2400 g_Git
.m_critGitDllSec
.Unlock();
2404 // restore last selected item
2405 if (lastSelectedHashNItem
>= 0)
2407 SetItemState(lastSelectedHashNItem
, LVIS_SELECTED
, LVIS_SELECTED
);
2408 EnsureVisible(lastSelectedHashNItem
, FALSE
);
2412 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2413 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2415 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2420 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2422 SafeTerminateThread();
2424 this->SetItemCountEx(0);
2429 //Update branch and Tag info
2431 //Assume Thread have exited
2432 //if(!m_bThreadRunning)
2434 m_logEntries
.clear();
2438 m_sFilterText
.Empty();
2443 InterlockedExchange(&m_bExitThread
,FALSE
);
2445 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2446 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2447 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2449 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2450 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2451 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2455 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2459 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2461 type
|= tr1::regex_constants::icase
;
2462 pat
= tr1::wregex(regexp_str
, type
);
2465 catch (exception
) {}
2468 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2471 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2474 if ((bRegex
)&&(m_bFilterWithRegex
))
2476 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2478 if(this->m_bShowBugtraqColumn
)
2480 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2482 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2483 if (regex_search(wstring(sBugIds
), pat
, flags
))
2490 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2492 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2493 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2499 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2501 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2502 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2508 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2510 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2515 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2521 if (m_SelectedFilters
& LOGFILTER_REVS
)
2523 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2524 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2530 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2532 CTGitPathList
*pathList
=NULL
;
2533 if( pRev
->m_IsDiffFiles
)
2534 pathList
= &pRev
->GetFiles(this);
2537 if(!pRev
->m_IsSimpleListReady
)
2538 pRev
->SafeGetSimpleList(&g_Git
);
2542 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2544 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2548 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2554 for(INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2556 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2565 CString find
= m_sFilterText
;
2568 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2570 if(this->m_bShowBugtraqColumn
)
2572 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2574 sBugIds
.MakeLower();
2575 if ((sBugIds
.Find(find
) >= 0))
2582 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2584 CString msg
= pRev
->GetSubject();
2586 msg
= msg
.MakeLower();
2587 if ((msg
.Find(find
) >= 0))
2593 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2595 CString msg
= pRev
->GetBody();
2597 msg
= msg
.MakeLower();
2598 if ((msg
.Find(find
) >= 0))
2604 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2606 CString msg
= pRev
->GetAuthorName();
2607 msg
= msg
.MakeLower();
2608 if ((msg
.Find(find
) >= 0))
2614 if (m_SelectedFilters
& LOGFILTER_REVS
)
2616 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2617 if ((sRev
.Find(find
) >= 0))
2623 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2625 CTGitPathList
*pathList
=NULL
;
2626 if( pRev
->m_IsDiffFiles
)
2627 pathList
= &pRev
->GetFiles(this);
2630 if(!pRev
->m_IsSimpleListReady
)
2631 pRev
->SafeGetSimpleList(&g_Git
);
2634 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
2636 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
2637 CString path
= cpath
->GetGitOldPathString();
2639 if ((path
.Find(find
)>=0))
2643 path
= cpath
->GetGitPathString();
2645 if ((path
.Find(find
)>=0))
2651 for (INT_PTR i
=0;i
<pRev
->m_SimpleFileList
.size();i
++)
2653 CString path
= pRev
->m_SimpleFileList
[i
];
2655 if ((path
.Find(find
)>=0))
2661 } // else (from if (bRegex))
2666 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
2669 pShownlist
->SafeRemoveAll();
2671 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2672 bool bRegex
= false;
2673 if (m_bFilterWithRegex
)
2674 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2676 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2678 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2680 if ((bRegex
)&&(m_bFilterWithRegex
))
2683 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2685 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2686 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2688 pShownlist
->SafeAdd(m_logEntries
[i
]);
2693 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2695 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
2696 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
2698 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2702 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2704 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
2705 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
2707 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2711 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2713 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2716 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2718 CTGitPath cpath
= pathList
[cpPathIndex
];
2719 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2721 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2725 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2727 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2731 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
2733 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2739 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2741 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
2743 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2747 if (m_SelectedFilters
& LOGFILTER_REVS
)
2749 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2750 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2752 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2759 CString find
= m_sFilterText
;
2762 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2764 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2766 sBugIDs
= sBugIDs
.MakeLower();
2767 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2769 pShownlist
->SafeAdd(m_logEntries
[i
]);
2774 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2776 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
2778 msg
= msg
.MakeLower();
2779 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2781 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2785 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2787 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
2789 msg
= msg
.MakeLower();
2790 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2792 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2796 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2798 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2801 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2803 CTGitPath cpath
= pathList
[cpPathIndex
];
2804 CString path
= cpath
.GetGitOldPathString();
2806 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2808 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2812 path
= cpath
.GetGitPathString();
2814 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2816 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2820 path
= cpath
.GetActionName();
2822 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2824 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2830 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2832 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
2833 msg
= msg
.MakeLower();
2834 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2836 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2840 if (m_SelectedFilters
& LOGFILTER_REVS
)
2842 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2843 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2845 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2849 } // else (from if (bRegex))
2850 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2854 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
2857 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2863 return time <= m_To;
2866 return time >= m_From;
2868 return ((time >= m_From)&&(time <= m_To));
2870 return TRUE
; /* git dll will filter time range */
2874 void CGitLogListBase::StartFilter()
2876 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2877 RecalculateShownList(&m_arShownList
);
2878 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2882 SetItemCountEx(ShownCountWithStopped());
2883 RedrawItems(0, ShownCountWithStopped());
2887 void CGitLogListBase::RemoveFilter()
2890 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2892 m_arShownList
.SafeRemoveAll();
2894 // reset the time filter too
2896 m_timFrom
= (__time64_t(m_tFrom
));
2897 m_timTo
= (__time64_t(m_tTo
));
2898 m_DateFrom
.SetTime(&m_timFrom
);
2899 m_DateTo
.SetTime(&m_timTo
);
2900 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
2901 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
2904 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2906 if(this->m_IsOldFirst
)
2908 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2912 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2915 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2917 SetItemCountEx(ShownCountWithStopped());
2918 RedrawItems(0, ShownCountWithStopped());
2920 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2923 void CGitLogListBase::Clear()
2925 m_arShownList
.SafeRemoveAll();
2928 m_logEntries
.ClearAll();
2932 void CGitLogListBase::OnDestroy()
2934 // save the column widths to the registry
2937 SafeTerminateThread();
2938 SafeTerminateAsyncDiffThread();
2941 while(m_LogCache
.SaveCache())
2949 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2950 // MB_YESNO) == IDNO)
2954 CHintListCtrl::OnDestroy();
2957 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
2959 UNREFERENCED_PARAMETER(lParam
);
2962 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
2963 this->InvalidateRect(rect
);
2969 * Save column widths to the registry
2971 void CGitLogListBase::SaveColumnWidths()
2973 int maxcol
= m_ColumnManager
.GetColumnCount();
2975 for (int col
= 0; col
< maxcol
; col
++)
2976 if (m_ColumnManager
.IsVisible (col
))
2977 m_ColumnManager
.ColumnResized (col
);
2979 m_ColumnManager
.WriteSettings();
2982 int CGitLogListBase::GetHeadIndex()
2984 if(m_HeadHash
.IsEmpty())
2987 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
2989 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
2992 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
2998 void CGitLogListBase::OnFind()
3002 m_pFindDialog
= new CFindDlg(this);
3003 m_pFindDialog
->Create(this);
3006 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3008 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3010 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3012 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3015 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3018 ASSERT(m_pFindDialog
!= NULL
);
3019 bool bFound
= false;
3022 if (m_pFindDialog
->IsTerminating())
3024 // invalidate the handle identifying the dialog box.
3025 m_pFindDialog
= NULL
;
3029 if(m_pFindDialog
->IsRef())
3032 str
=m_pFindDialog
->GetFindString();
3037 hash
= g_Git
.GetHash(str
);
3041 for (i
= 0; i
<m_arShownList
.GetCount(); i
++)
3043 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3044 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3054 if(m_pFindDialog
->FindNext())
3056 //read data from dialog
3057 CString FindText
= m_pFindDialog
->GetFindString();
3058 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3061 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3063 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3066 for (i
= this->m_nSearchIndex
; i
<m_arShownList
.GetCount()&&!bFound
; i
++)
3068 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3071 str
+=pLogEntry
->m_CommitHash
.ToString();
3074 for(int j
=0;j
<this->m_HashMap
[pLogEntry
->m_CommitHash
].size();j
++)
3076 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3080 str
+=pLogEntry
->GetAuthorEmail();
3082 str
+=pLogEntry
->GetAuthorName();
3084 str
+=pLogEntry
->GetBody();
3086 str
+=pLogEntry
->GetCommitterEmail();
3088 str
+=pLogEntry
->GetCommitterName();
3090 str
+=pLogEntry
->GetSubject();
3094 /*Because changed files list is loaded on demand when gui show,
3095 files will empty when files have not fetched.
3097 we can add it back by using one-way diff(with outnumber changed and rename detect.
3098 here just need changed filename list. one-way is much quicker.
3100 if(pLogEntry
->m_IsFull
)
3102 for(int i
=0;i
<pLogEntry
->GetFiles(this).GetCount();i
++)
3104 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3106 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3112 if(!pLogEntry
->m_IsSimpleListReady
)
3113 pLogEntry
->SafeGetSimpleList(&g_Git
);
3115 for(int i
=0;i
<pLogEntry
->m_SimpleFileList
.size();i
++)
3117 str
+=pLogEntry
->m_SimpleFileList
[i
];
3126 if (regex_search(wstring(str
), pat
, flags
))
3136 if (str
.Find(FindText
) >= 0)
3146 msg
= msg
.MakeLower();
3147 CString find
= FindText
.MakeLower();
3148 if (msg
.Find(find
) >= 0)
3155 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3157 } // if(m_pFindDialog->FindNext())
3158 //UpdateLogInfoLabel();
3162 this->m_nSearchIndex
= i
;
3163 EnsureVisible(i
, FALSE
);
3164 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3165 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3166 SetSelectionMark(i
);
3167 //FillLogMessageCtrl();
3170 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3171 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3177 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3179 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3184 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3186 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);