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
)
82 , m_bNoHightlightHead(FALSE
)
84 // use the default GUI font, create a copy of it and
85 // change the copy to BOLD (leave the rest of the font
87 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
89 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
90 lf
.lfWeight
= FW_BOLD
;
91 m_boldFont
= CreateFontIndirect(&lf
);
93 m_bShowBugtraqColumn
=false;
95 m_IsIDReplaceAction
=FALSE
;
97 this->m_critSec
.Init();
98 m_wcRev
.m_CommitHash
.Empty();
99 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
100 m_wcRev
.m_ParentHash
.clear();
101 m_wcRev
.m_Mark
=_T('-');
102 m_wcRev
.m_IsUpdateing
=FALSE
;
103 m_wcRev
.m_IsFull
= TRUE
;
105 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
106 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
107 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
108 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
109 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
111 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
113 g_Git
.GetMapHashToFriendName(m_HashMap
);
114 if (CTGitPath(g_Git
.m_CurrentDir
).HasAdminDir())
116 m_CurrentBranch
=g_Git
.GetCurrentBranch();
118 m_HeadHash
=g_Git
.GetHash(_T("HEAD"));
123 MessageBox(_T("Could not get HEAD hash. Quitting...\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
132 m_LoadingThread
= NULL
;
134 InterlockedExchange(&m_bExitThread
,FALSE
);
135 m_IsOldFirst
= FALSE
;
136 m_IsRebaseReplaceGraph
= FALSE
;
139 for(int i
=0;i
<Lanes::COLORS_NUM
;i
++)
141 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
143 // get short/long datetime setting from registry
144 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
145 if ( RegUseShortDateFormat
)
147 m_DateFormat
= DATE_SHORTDATE
;
151 m_DateFormat
= DATE_LONGDATE
;
153 // get relative time display setting from registry
154 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
155 m_bRelativeTimes
= (regRelativeTimes
!= 0);
156 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
158 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
159 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
160 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
161 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
162 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
163 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
165 m_ColumnRegKey
=_T("log");
167 m_AsyncThreadExit
= FALSE
;
168 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
169 m_AsynDiffListLock
.Init();
171 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
172 if (m_DiffingThread
==NULL
)
174 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
180 int CGitLogListBase::AsyncDiffThread()
182 m_AsyncThreadExited
= false;
183 while(!m_AsyncThreadExit
)
185 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
188 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
190 m_AsynDiffListLock
.Lock();
191 pRev
= m_AsynDiffList
.back();
192 m_AsynDiffList
.pop_back();
193 m_AsynDiffListLock
.Unlock();
195 if( pRev
->m_CommitHash
.IsEmpty() )
197 if(pRev
->m_IsDiffFiles
)
200 pRev
->GetFiles(this).Clear();
201 pRev
->m_ParentHash
.clear();
202 pRev
->m_ParentHash
.push_back(m_HeadHash
);
203 if(g_Git
.IsInitRepos())
205 g_Git
.GetInitAddList(pRev
->GetFiles(this));
210 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
212 pRev
->GetAction(this) = 0;
214 for(int j
=0;j
< pRev
->GetFiles(this).GetCount();j
++)
215 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
217 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
218 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
220 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
221 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
222 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
225 if(!pRev
->CheckAndDiff())
226 { // fetch change file list
227 for(int i
=GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex()+GetCountPerPage(); i
++)
229 if(i
< m_arShownList
.GetCount())
231 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
232 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
234 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
240 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
242 POSITION pos
= GetFirstSelectedItemPosition();
243 int nItem
= GetNextSelectedItem(pos
);
247 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
249 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
251 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
258 m_AsyncThreadExited
= true;
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
265 m_ContextMenuMask
&= hideMask
;
269 m_ContextMenuMask
&= ~hideMask
;
273 CGitLogListBase::~CGitLogListBase()
275 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
276 this->m_arShownList
.SafeRemoveAll();
278 DestroyIcon(m_hModifiedIcon
);
279 DestroyIcon(m_hReplacedIcon
);
280 DestroyIcon(m_hAddedIcon
);
281 DestroyIcon(m_hDeletedIcon
);
282 m_logEntries
.ClearAll();
285 DeleteObject(m_boldFont
);
287 if ( m_pStoreSelection
)
289 delete m_pStoreSelection
;
290 m_pStoreSelection
= NULL
;
293 SafeTerminateThread();
294 SafeTerminateAsyncDiffThread();
297 CloseHandle(m_AsyncDiffEvent
);
301 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
302 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
303 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
304 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
306 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
307 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
310 ON_MESSAGE(MSG_LOADED
,OnLoad
)
312 ON_WM_MEASUREITEM_REFLECT()
313 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
314 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
315 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
316 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
317 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
318 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
321 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
323 //if (m_nRowHeight>0)
325 lpMeasureItemStruct
->itemHeight
= 50;
329 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
332 return CHintListCtrl::OnCreate(lpCreateStruct
);
335 void CGitLogListBase::PreSubclassWindow()
337 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
338 // load the icons for the action columns
339 // m_Theme.Open(m_hWnd, L"ListView");
340 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
341 CHintListCtrl::PreSubclassWindow();
344 void CGitLogListBase::InsertGitColumn()
348 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
349 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
350 if (DWORD(regFullRowSelect
))
351 exStyle
|= LVS_EX_FULLROWSELECT
;
352 SetExtendedStyle(exStyle
);
354 UpdateProjectProperties();
356 static UINT normal
[] =
368 IDS_LOG_COMMIT_EMAIL
,
389 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
391 DWORD hideColumns
= 0;
392 if(this->m_IsRebaseReplaceGraph
)
394 hideColumns
|= GIT_LOG_GRAPH
;
395 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
399 hideColumns
|= GIT_LOG_REBASE
;
402 if(this->m_IsIDReplaceAction
)
404 hideColumns
|= GIT_LOG_ACTIONS
;
405 m_dwDefaultColumns
|= GIT_LOG_ID
;
406 m_dwDefaultColumns
|= GIT_LOG_HASH
;
410 hideColumns
|= GIT_LOG_ID
;
412 if(this->m_bShowBugtraqColumn
)
414 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
418 hideColumns
|= GIT_LOGLIST_BUG
;
422 m_ColumnManager
.SetNames(normal
, _countof(normal
));
423 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
430 * Resizes all columns in a list control to values in registry.
432 void CGitLogListBase::ResizeAllListCtrlCols()
434 // column max and min widths to allow
435 static const int nMinimumWidth
= 10;
436 static const int nMaximumWidth
= 1000;
437 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
440 int numcols
= pHdrCtrl
->GetItemCount();
441 for (int col
= 0; col
< numcols
; col
++)
443 // get width for this col last time from registry
445 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
446 CRegDWORD
regwidth(regentry
, 0);
450 // no saved value, setup sensible defaults
451 if (col
== this->LOGLIST_MESSAGE
)
453 cx
= LOGLIST_MESSAGE_MIN
;
457 cx
= ICONITEMBORDER
+16*4;
460 if (cx
< nMinimumWidth
)
464 else if (cx
> nMaximumWidth
)
469 SetColumnWidth(col
, cx
);
476 BOOL
CGitLogListBase::GetShortName(CString ref
, CString
&shortname
,CString prefix
)
478 //TRACE(_T("%s %s\r\n"),ref,prefix);
479 if(ref
.Left(prefix
.GetLength()) == prefix
)
481 shortname
= ref
.Right(ref
.GetLength()-prefix
.GetLength());
482 if(shortname
.Right(3)==_T("^{}"))
483 shortname
=shortname
.Left(shortname
.GetLength()-3);
489 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
492 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
493 rItem
.mask
= LVIF_STATE
;
494 rItem
.iItem
= (int)Index
;
495 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
498 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
501 if (!(rItem
.state
& LVIS_SELECTED
))
503 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
504 brush
= ::CreateSolidBrush(RGB(156,156,156));
505 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
506 brush
= ::CreateSolidBrush(RGB(200,200,128));
508 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
510 if (rItem
.state
& LVIS_SELECTED
)
512 if (::GetFocus() == m_hWnd
)
513 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
515 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
521 ::FillRect(hdc
, &rect
, brush
);
522 ::DeleteObject(brush
);
526 void CGitLogListBase::DrawTagBranch(HDC hdc
,CRect
&rect
,INT_PTR index
)
528 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
531 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
532 rItem
.mask
= LVIF_STATE
;
533 rItem
.iItem
= (int)index
;
534 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
540 HTHEME hTheme
= NULL
;
541 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
542 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
544 for(unsigned int i
=0;i
<m_HashMap
[data
->m_CommitHash
].size();i
++)
547 str
=m_HashMap
[data
->m_CommitHash
][i
];
554 //Determine label color
555 if(GetShortName(str
,shortname
,_T("refs/heads/")))
557 if( shortname
== m_CurrentBranch
)
558 colRef
= m_Colors
.GetColor(CColors::CurrentBranch
);
560 colRef
= m_Colors
.GetColor(CColors::LocalBranch
);
563 else if(GetShortName(str
,shortname
,_T("refs/remotes/")))
565 colRef
= m_Colors
.GetColor(CColors::RemoteBranch
);
567 else if(GetShortName(str
,shortname
,_T("refs/tags/")))
569 colRef
= m_Colors
.GetColor(CColors::Tag
);
571 else if(GetShortName(str
,shortname
,_T("refs/stash")))
573 colRef
= m_Colors
.GetColor(CColors::Stash
);
574 shortname
=_T("stash");
576 else if(GetShortName(str
,shortname
,_T("refs/bisect/")))
578 if(shortname
.Find(_T("good")) == 0)
580 colRef
= m_Colors
.GetColor(CColors::BisectGood
);
581 shortname
= _T("good");
584 if(shortname
.Find(_T("bad")) == 0)
586 colRef
= m_Colors
.GetColor(CColors::BisectBad
);
587 shortname
= _T("bad");
591 //When row selected, ajust label color
592 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
593 if (rItem
.state
& LVIS_SELECTED
)
594 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
596 brush
= ::CreateSolidBrush(colRef
);
598 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
601 memset(&size
,0,sizeof(SIZE
));
602 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
604 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
607 int textpos
= DT_CENTER
;
609 if(rt
.right
> rect
.right
)
611 rt
.right
= rect
.right
;
615 //Fill interior of ref label
616 ::FillRect(hdc
, &rt
, brush
);
622 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,100), m_Colors
.Darken(colRef
,100));
623 rectEdge
.DeflateRect(1,1);
624 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,50), m_Colors
.Darken(colRef
,50));
626 //Draw text inside label
627 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
629 int txtState
= LISS_NORMAL
;
630 if (rItem
.state
& LVIS_SELECTED
)
631 txtState
= LISS_SELECTED
;
633 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
637 W_Dc
.SetBkMode(TRANSPARENT
);
638 if (rItem
.state
& LVIS_SELECTED
)
640 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
641 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
642 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
643 ::SetTextColor(hdc
,clrOld
);
647 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,textpos
| DT_SINGLELINE
| DT_VCENTER
);
651 //::MoveToEx(hdc,rt.left,rt.top,NULL);
652 //::LineTo(hdc,rt.right,rt.top);
653 //::LineTo(hdc,rt.right,rt.bottom);
654 //::LineTo(hdc,rt.left,rt.bottom);
655 //::LineTo(hdc,rt.left,rt.top);
660 ::DeleteObject(brush
);
664 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
666 int txtState
= LISS_NORMAL
;
667 if (rItem
.state
& LVIS_SELECTED
)
668 txtState
= LISS_SELECTED
;
670 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
674 if (rItem
.state
& LVIS_SELECTED
)
676 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
677 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
678 ::SetTextColor(hdc
,clrOld
);
682 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
687 CloseThemeData(hTheme
);
692 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
694 // Returns ((256 - amount)*col1 + amount*col2) / 256;
695 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
696 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
697 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
700 Gdiplus::Color
GetGdiColor(COLORREF col
)
702 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
704 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
705 const COLORREF
& col
,const COLORREF
& activeColor
, int top
708 int h
= laneHeight
/ 2;
709 int m
= (x1
+ x2
) / 2;
710 int r
= (x2
- x1
) / 3;
713 #define P_CENTER m , h+top
714 #define P_0 x2, h+top
715 #define P_90 m , 0+top-1
716 #define P_180 x1, h+top
717 #define P_270 m , 2 * h+top +1
718 #define R_CENTER m - r, h - r+top, d, d
721 #define DELTA_UR_B 2*(x1 - m), 2*h +top
722 #define DELTA_UR_E 0*16, 90*16 +top // -,
724 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
725 #define DELTA_DR_E 270*16, 90*16 +top // -'
727 #define DELTA_UL_B 2*(x2 - m), 2*h +top
728 #define DELTA_UL_E 90*16, 90*16 +top // ,-
730 #define DELTA_DL_B 2*(x2 - m),2*-h +top
731 #define DELTA_DL_E 180*16, 90*16 // '-
733 #define CENTER_UR x1, 2*h, 225
734 #define CENTER_DR x1, 0 , 135
735 #define CENTER_UL x2, 2*h, 315
736 #define CENTER_DL x2, 0 , 45
739 Gdiplus::Graphics
graphics( hdc
);
741 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
750 Gdiplus::LinearGradientBrush
gradient(
751 Gdiplus::Point(x1
-2, h
+top
-2),
752 Gdiplus::Point(P_270
),
753 GetGdiColor(activeColor
),GetGdiColor(col
));
756 Gdiplus::Pen
mypen(&gradient
,2);
757 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
759 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
760 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
761 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
768 Gdiplus::LinearGradientBrush
gradient(
769 Gdiplus::Point(P_270
),
770 Gdiplus::Point(x2
+1, h
+top
-1),
771 GetGdiColor(col
),GetGdiColor(activeColor
));
774 Gdiplus::Pen
mypen(&gradient
,2);
775 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
777 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
778 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
779 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
788 Gdiplus::LinearGradientBrush
gradient(
789 Gdiplus::Point(x1
-2, h
+top
-2),
790 Gdiplus::Point(P_90
),
791 GetGdiColor(activeColor
),GetGdiColor(col
));
793 Gdiplus::Pen
mypen(&gradient
,2);
795 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
798 QConicalGradient
gradient(CENTER_DR
);
799 gradient
.setColorAt(0.375, activeCol
);
800 gradient
.setColorAt(0.625, col
);
801 myPen
.setBrush(gradient
);
803 p
->drawArc(P_CENTER
, DELTA_DR
);
812 //static QPen myPen(Qt::black, 2); // fast path here
814 pen
.CreatePen(PS_SOLID
,2,col
);
815 //myPen.setColor(col);
816 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
818 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
820 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
827 case Lanes::NOT_ACTIVE
:
828 case Lanes::MERGE_FORK
:
829 case Lanes::MERGE_FORK_R
:
830 case Lanes::MERGE_FORK_L
:
835 //DrawLine(hdc,P_90,P_270);
836 graphics
.DrawLine(&myPen
,P_90
,P_270
);
837 //p->drawLine(P_90, P_270);
841 //DrawLine(hdc,P_CENTER,P_270);
842 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
843 //p->drawLine(P_CENTER, P_270);
847 case Lanes::BOUNDARY
:
848 case Lanes::BOUNDARY_C
:
849 case Lanes::BOUNDARY_R
:
850 case Lanes::BOUNDARY_L
:
851 //DrawLine(hdc,P_90, P_CENTER);
852 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
853 //p->drawLine(P_90, P_CENTER);
859 myPen
.SetColor(GetGdiColor(activeColor
));
863 case Lanes::MERGE_FORK
:
868 case Lanes::CROSS_EMPTY
:
869 case Lanes::BOUNDARY_C
:
870 //DrawLine(hdc,P_180,P_0);
871 graphics
.DrawLine(&myPen
,P_180
,P_0
);
872 //p->drawLine(P_180, P_0);
874 case Lanes::MERGE_FORK_R
:
875 case Lanes::BOUNDARY_R
:
876 //DrawLine(hdc,P_180,P_CENTER);
877 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
878 //p->drawLine(P_180, P_CENTER);
880 case Lanes::MERGE_FORK_L
:
883 case Lanes::BOUNDARY_L
:
884 //DrawLine(hdc,P_CENTER,P_0);
885 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
886 //p->drawLine(P_CENTER, P_0);
892 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
895 brush
.CreateSolidBrush(col
);
896 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
898 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
899 // center symbol, e.g. rect or ellipse
905 //p->setPen(Qt::NoPen);
907 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
908 graphics
.FillEllipse(&myBrush
, R_CENTER
);
909 //p->drawEllipse(R_CENTER);
911 case Lanes::MERGE_FORK
:
912 case Lanes::MERGE_FORK_R
:
913 case Lanes::MERGE_FORK_L
:
914 //p->setPen(Qt::NoPen);
916 //p->drawRect(R_CENTER);
917 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
918 graphics
.FillRectangle(&myBrush
, R_CENTER
);
920 case Lanes::UNAPPLIED
:
922 //p->setPen(Qt::NoPen);
923 //p->setBrush(Qt::red);
924 //p->drawRect(m - r, h - 1, d, 2);
925 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
926 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
930 //p->setPen(Qt::NoPen);
931 //p->setBrush(DARK_GREEN);
932 //p->drawRect(m - r, h - 1, d, 2);
933 //p->drawRect(m - 1, h - r, 2, d);
934 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
935 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
936 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
938 case Lanes::BOUNDARY
:
940 //p->drawEllipse(R_CENTER);
941 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
942 graphics
.DrawEllipse(&myPen
, R_CENTER
);
944 case Lanes::BOUNDARY_C
:
945 case Lanes::BOUNDARY_R
:
946 case Lanes::BOUNDARY_L
:
948 //p->drawRect(R_CENTER);
949 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
950 graphics
.FillRectangle(&myBrush
,R_CENTER
);
956 ::SelectObject(hdc
,oldpen
);
957 ::SelectObject(hdc
,oldbrush
);
966 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
970 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
971 if(data
->m_CommitHash
.IsEmpty())
976 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
977 rItem
.mask
= LVIF_STATE
;
978 rItem
.iItem
= (int)index
;
979 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
982 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
984 if (data
->m_Lanes
.empty())
985 m_logEntries
.setLane(data
->m_CommitHash
);
987 std::vector
<int>& lanes
=data
->m_Lanes
;
988 size_t laneNum
= lanes
.size();
990 for (UINT i
= 0; i
< laneNum
; i
++)
991 if (Lanes::isMerge(lanes
[i
])) {
997 int maxWidth
= rect
.Width();
998 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1000 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1001 //if (opt.state & QStyle::State_Selected)
1002 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1004 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++)
1011 if (ln
== Lanes::EMPTY
)
1014 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1015 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1019 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++) {
1025 if (ln
== Lanes::EMPTY
)
1028 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1029 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1031 if (ln
== Lanes::CROSS
)
1033 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1034 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1037 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1043 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1046 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1047 // Take the default processing unless we set this to something else below.
1048 *pResult
= CDRF_DODEFAULT
;
1050 if (m_bNoDispUpdates
)
1053 switch (pLVCD
->nmcd
.dwDrawStage
)
1057 *pResult
= CDRF_NOTIFYITEMDRAW
;
1061 case CDDS_ITEMPREPAINT
:
1063 // This is the prepaint stage for an item. Here's where we set the
1064 // item's text color.
1066 // Tell Windows to send draw notifications for each subitem.
1067 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1069 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1071 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1073 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1076 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1077 crText
= RGB(128,128,128);
1079 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1080 pLVCD
->clrTextBk
= RGB(156,156,156);
1081 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1082 pLVCD
->clrTextBk
= RGB(200,200,128);
1084 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1086 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1088 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1089 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1092 if (data
->m_CommitHash
.ToString() == m_HeadHash
&& m_bNoHightlightHead
== FALSE
)
1094 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1095 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1098 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1099 // crText = GetSysColor(COLOR_GRAYTEXT);
1101 if (data
->m_CommitHash
.IsEmpty())
1103 //crText = GetSysColor(RGB(200,200,0));
1104 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1105 // We changed the font, so we're returning CDRF_NEWFONT. This
1106 // tells the control to recalculate the extent of the text.
1107 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1111 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1113 if (m_bStrictStopped
)
1114 crText
= GetSysColor(COLOR_GRAYTEXT
);
1116 // Store the color back in the NMLVCUSTOMDRAW struct.
1117 pLVCD
->clrText
= crText
;
1121 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1123 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1125 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1128 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty())
1130 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1133 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1135 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1136 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1138 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1139 if( !data
->m_CommitHash
.IsEmpty())
1140 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1142 *pResult
= CDRF_SKIPDEFAULT
;
1147 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1149 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1151 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1152 //if(!data->m_IsFull)
1154 //if(data->SafeFetchFullInfo(&g_Git))
1155 // this->Invalidate();
1156 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1159 if (!m_HashMap
[data
->m_CommitHash
].empty())
1163 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1165 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1166 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1168 *pResult
= CDRF_SKIPDEFAULT
;
1176 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1178 if(this->m_IsIDReplaceAction
)
1180 *pResult
= CDRF_DODEFAULT
;
1183 *pResult
= CDRF_DODEFAULT
;
1185 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1189 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1190 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1192 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1194 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1195 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1196 // Get the selected state of the
1197 // item being drawn.
1199 // Fill the background if necessary
1200 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1202 // Draw the icon(s) into the compatible DC
1203 pLogEntry
->GetAction(this);
1205 if (!pLogEntry
->m_IsDiffFiles
)
1206 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1208 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1209 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1212 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1213 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1216 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1217 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1220 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1221 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1223 *pResult
= CDRF_SKIPDEFAULT
;
1229 *pResult
= CDRF_DODEFAULT
;
1232 // CGitLogListBase message handlers
1234 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1236 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1238 // Create a pointer to the item
1239 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1241 // Do the list need text information?
1242 if (!(pItem
->mask
& LVIF_TEXT
))
1245 // By default, clear text buffer.
1246 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1248 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1251 if (m_bNoDispUpdates
|| bOutOfRange
)
1254 // Which item number?
1255 int itemid
= pItem
->iItem
;
1256 GitRev
* pLogEntry
= NULL
;
1257 if (itemid
< m_arShownList
.GetCount())
1258 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1263 temp
.Format(_T("%d"),pItem
->iItem
+1);
1268 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1272 switch (pItem
->iSubItem
)
1274 case this->LOGLIST_GRAPH
: //Graphic
1276 case this->LOGLIST_REBASE
:
1278 if(this->m_IsRebaseReplaceGraph
)
1281 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1282 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1286 case this->LOGLIST_ACTION
: //action -- no text in the column
1288 case this->LOGLIST_HASH
:
1290 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1292 case this->LOGLIST_ID
:
1293 if(this->m_IsIDReplaceAction
)
1294 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1296 case this->LOGLIST_MESSAGE
: //Message
1298 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1300 case this->LOGLIST_AUTHOR
: //Author
1302 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1304 case this->LOGLIST_DATE
: //Date
1305 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1306 lstrcpyn(pItem
->pszText
,
1307 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1311 case this->LOGLIST_EMAIL
:
1313 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1316 case this->LOGLIST_COMMIT_NAME
: //Commit
1318 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1321 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1323 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1326 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1327 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1328 lstrcpyn(pItem
->pszText
,
1329 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1332 case this->LOGLIST_BUG
: //Bug ID
1334 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1342 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1345 if (pWnd
== GetHeaderCtrl())
1347 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1350 int selIndex
= GetSelectionMark();
1352 return; // nothing selected, nothing to do with a context menu
1354 // if the user selected the info text telling about not all revisions shown due to
1355 // the "stop on copy/rename" option, we also don't show the context menu
1356 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1359 // if the context menu is invoked through the keyboard, we have to use
1360 // a calculated position on where to anchor the menu on
1361 if ((point
.x
== -1) && (point
.y
== -1))
1364 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1365 ClientToScreen(&rect
);
1366 point
= rect
.CenterPoint();
1368 m_nSearchIndex
= selIndex
;
1369 m_bCancelled
= FALSE
;
1371 // calculate some information the context menu commands can use
1372 // CString pathURL = GetURLFromPath(m_path);
1374 POSITION pos
= GetFirstSelectedItemPosition();
1375 int indexNext
= GetNextSelectedItem(pos
);
1379 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1381 GitRev revSelected
= pSelLogEntry
->Rev
;
1382 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1383 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1385 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1387 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1388 if (changedpath
->lCopyFromRev
)
1389 revPrevious
= changedpath
->lCopyFromRev
;
1392 GitRev revSelected2
;
1395 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1396 revSelected2
= pLogEntry
->Rev
;
1398 bool bAllFromTheSameAuthor
= true;
1399 CString firstAuthor
;
1400 CLogDataVector selEntries
;
1401 GitRev revLowest
, revHighest
;
1402 GitRevRangeArray revisionRanges
;
1404 POSITION pos
= GetFirstSelectedItemPosition();
1405 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1406 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1407 selEntries
.push_back(pLogEntry
);
1408 firstAuthor
= pLogEntry
->sAuthor
;
1409 revLowest
= pLogEntry
->Rev
;
1410 revHighest
= pLogEntry
->Rev
;
1413 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1414 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1415 selEntries
.push_back(pLogEntry
);
1416 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1417 bAllFromTheSameAuthor
= false;
1418 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1419 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1425 int FirstSelect
=-1, LastSelect
=-1;
1426 pos
= GetFirstSelectedItemPosition();
1427 FirstSelect
= GetNextSelectedItem(pos
);
1430 LastSelect
= GetNextSelectedItem(pos
);
1432 //entry is selected, now show the popup menu
1434 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, revertmenu
;
1436 if (popup
.CreatePopupMenu())
1438 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1439 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1441 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1442 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1444 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1445 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1447 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1448 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1450 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1451 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1453 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1454 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1455 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1457 if (GetSelectedCount() == 1)
1461 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1463 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1464 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1468 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1469 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1471 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1473 GitRev
*pRev
=pSelLogEntry
;
1474 if (pSelLogEntry
->m_ParentHash
.empty())
1476 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1478 if(pRev
->m_ParentHash
.size()<=1)
1480 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1485 gnudiffmenu
.CreatePopupMenu();
1486 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1488 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1489 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1491 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1494 str
.Format(IDS_PARENT
, i
+ 1);
1495 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1500 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1503 GitRev
*pRev
=pSelLogEntry
;
1504 if (pSelLogEntry
->m_ParentHash
.empty())
1506 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1508 if(pRev
->m_ParentHash
.size()<=1)
1510 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1511 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1512 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1516 diffmenu
.CreatePopupMenu();
1517 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1518 for(int i
=0;i
<pRev
->m_ParentHash
.size();i
++)
1521 str
.Format(IDS_PARENT
, i
+ 1);
1522 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1523 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1525 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1526 diffmenu
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16), FALSE
);
1532 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1533 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1535 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1536 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1538 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1540 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1541 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1544 bool isStash
= false;
1545 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1547 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1554 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1556 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1557 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1559 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1560 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1562 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1565 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1567 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1568 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1570 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1574 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1576 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1578 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1580 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1582 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1583 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1585 // popup.AppendMenu(MF_SEPARATOR, NULL);
1590 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1592 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1594 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1595 GetSelectedCount() == 1)
1596 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1598 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1599 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1601 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1602 str
.Format(format
,g_Git
.GetCurrentBranch());
1604 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
)
1605 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1607 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1608 str
.Format(format
,g_Git
.GetCurrentBranch());
1610 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1611 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1614 // Add Switch Branch express Menu
1615 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1616 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1619 std::vector
<CString
*> branchs
;
1620 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1622 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1623 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1625 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1630 str
.LoadString(IDS_SWITCH_BRANCH
);
1632 if(branchs
.size() == 1)
1635 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1636 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1638 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1641 else if(branchs
.size() > 1)
1643 subbranchmenu
.CreatePopupMenu();
1644 for(int i
=0;i
<branchs
.size();i
++)
1646 if (*branchs
[i
] != currentBranch
)
1648 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1649 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1653 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1657 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1658 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1660 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1661 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1663 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1664 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1666 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1667 str
.Format(format
,g_Git
.GetCurrentBranch());
1669 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
)
1670 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1671 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1673 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1674 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1676 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1678 GitRev
*pRev
= pSelLogEntry
;
1679 if (pSelLogEntry
->m_ParentHash
.empty())
1681 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1683 if (pRev
->m_ParentHash
.size() == 1)
1685 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1689 revertmenu
.CreatePopupMenu();
1690 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
1692 for (int i
= 0; i
< pRev
->m_ParentHash
.size(); i
++)
1695 str
.Format(IDS_PARENT
, i
+ 1);
1696 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
1701 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1702 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1704 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1709 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1711 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1712 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1713 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1714 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1717 if (GetSelectedCount() >= 2)
1719 bool bAddSeparator
= false;
1720 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1722 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1723 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1726 if (GetSelectedCount() == 2)
1728 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1729 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1730 bAddSeparator
= true;
1735 bAddSeparator
= true;
1738 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1739 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1742 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1745 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1747 bool bAddSeparator
= false;
1748 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1750 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
)
1754 headindex
= this->GetHeadIndex();
1757 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1758 CGitHash hash
=g_Git
.GetHash(head
);
1759 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1760 if(pLastEntry
->m_CommitHash
== hash
) {
1761 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1762 bAddSeparator
= true;
1767 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
) {
1768 if (GetSelectedCount() >= 2)
1769 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
1771 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1772 bAddSeparator
= true;
1775 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1776 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1777 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1778 bAddSeparator
= true;
1782 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1785 if (m_hasWC
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
1787 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
1788 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1791 if (GetSelectedCount() == 1)
1793 bool bAddSeparator
= false;
1794 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
1796 // show the push-option only if the log entry has an associated local branch
1797 bool isLocal
= false;
1798 for(int i
=0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1800 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1805 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1806 bAddSeparator
= true;
1810 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1812 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1814 std::vector
<CString
*> branchs
;
1815 for (int i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); i
++)
1817 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
1818 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1821 if (branchs
.size() == 1)
1823 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1826 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1827 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
1828 bAddSeparator
= true;
1830 else if (branchs
.size() > 1)
1832 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1833 submenu
.CreatePopupMenu();
1834 for (int i
= 0; i
< branchs
.size(); i
++)
1836 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
1837 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
1840 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
1841 bAddSeparator
= true;
1844 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
1846 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1847 } // GetSelectedCount() == 1
1849 if (GetSelectedCount() == 1)
1851 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1852 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
1854 if (GetSelectedCount() != 0)
1856 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1857 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
1858 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
1859 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
1862 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1863 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
1865 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
1866 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
1868 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1869 // DialogEnableWindow(IDOK, FALSE);
1870 // SetPromptApp(&theApp);
1872 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
1874 // EnableOKButton();
1875 } // if (popup.CreatePopupMenu())
1879 bool CGitLogListBase::IsSelectionContinuous()
1881 if ( GetSelectedCount()==1 )
1883 // if only one revision is selected, the selection is of course
1888 POSITION pos
= GetFirstSelectedItemPosition();
1889 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1892 int itemindex
= GetNextSelectedItem(pos
);
1895 int nextindex
= GetNextSelectedItem(pos
);
1896 if (nextindex
- itemindex
> 1)
1898 bContinuous
= false;
1901 itemindex
= nextindex
;
1907 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
1911 POSITION pos
= GetFirstSelectedItemPosition();
1915 sRev
.LoadString(IDS_LOG_REVISION
);
1917 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1919 sDate
.LoadString(IDS_LOG_DATE
);
1921 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1924 CString sLogCopyText
;
1926 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1928 if (toCopy
== ID_COPY_ALL
)
1930 //pLogEntry->GetFiles(this)
1931 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1933 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
1934 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
1936 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
1937 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
1940 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
1941 sPaths
+= _T(" ") + rename
;
1943 sPaths
+= _T("\r\n");
1946 CString body
= pLogEntry
->GetBody();
1947 body
.Replace(_T("\n"), _T("\r\n"));
1948 sLogCopyText
.Format(_T("%s: %s\r\n%s: %s <%s>\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
1949 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
1950 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
1952 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1953 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
1955 sClipdata
+= sLogCopyText
;
1957 else if (toCopy
== ID_COPY_MESSAGE
)
1959 CString body
= pLogEntry
->GetBody();
1960 body
.Replace(_T("\n"), _T("\r\n"));
1961 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
1963 else if (toCopy
== ID_COPY_SUBJECT
)
1965 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
1969 sClipdata
+= pLogEntry
->m_CommitHash
;
1974 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1979 void CGitLogListBase::DiffSelectedRevWithPrevious()
1981 if (m_bThreadRunning
)
1984 int FirstSelect
=-1, LastSelect
=-1;
1985 POSITION pos
= GetFirstSelectedItemPosition();
1986 FirstSelect
= GetNextSelectedItem(pos
);
1989 LastSelect
= GetNextSelectedItem(pos
);
1992 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
1995 UpdateLogInfoLabel();
1996 int selIndex
= m_LogList
.GetSelectionMark();
1999 int selCount
= m_LogList
.GetSelectedCount();
2003 // Find selected entry in the log list
2004 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2005 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2006 long rev1
= pLogEntry
->Rev
;
2008 CTGitPath path
= m_path
;
2010 // See how many files under the relative root were changed in selected revision
2012 LogChangedPath
* changed
= NULL
;
2013 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2015 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2016 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2023 if (m_path
.IsDirectory() && nChanged
== 1)
2025 // We're looking at the log for a directory and only one file under dir was changed in the revision
2026 // Do diff on that file instead of whole directory
2027 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2030 m_bCancelled
= FALSE
;
2031 DialogEnableWindow(IDOK
, FALSE
);
2032 SetPromptApp(&theApp
);
2033 theApp
.DoWaitCursor(1);
2037 GitDiff
diff(this, m_hWnd
, true);
2038 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2039 diff
.SetHEADPeg(m_LogRevision
);
2040 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2044 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2047 theApp
.DoWaitCursor(-1);
2052 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2054 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2057 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2059 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2061 if (pFindInfo
->lvfi
.psz
== 0)
2064 CString sCmp
= pFindInfo
->lvfi
.psz
;
2066 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2068 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2069 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2070 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2072 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2080 if (sCmp
.Compare(sRev
)==0)
2087 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2089 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2091 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2092 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2093 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2095 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2103 if (sCmp
.Compare(sRev
)==0)
2115 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
2119 this->m_arShownList
.SafeRemoveAll();
2121 this->m_logEntries
.ClearAll();
2122 if (this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
))
2125 //this->m_logEntries.ParserFromLog();
2126 SetItemCountEx((int)m_logEntries
.size());
2128 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2132 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2133 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2138 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2139 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2151 int CGitLogListBase::BeginFetchLog()
2155 this->m_arShownList
.SafeRemoveAll();
2157 this->m_logEntries
.ClearAll();
2159 this->m_LogCache
.ClearAllParent();
2161 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2164 if(this->m_Path
.IsEmpty())
2171 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2172 // if(this->m_bAllBranch)
2173 mask
|= m_ShowMask
;
2177 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2179 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2182 CString
*pFrom
, *pTo
;
2184 CString
head(_T("HEAD"));
2185 if(!this->m_startrev
.IsEmpty())
2187 pFrom
= &this->m_startrev
;
2188 if(!this->m_endrev
.IsEmpty())
2189 pTo
= &this->m_endrev
;
2195 data
.m_From
= m_From
;
2198 #if 0 /* use tortoiegit filter */
2199 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2200 data
.m_Author
= this->m_sFilterText
;
2202 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2203 data
.m_MessageFilter
= this->m_sFilterText
;
2205 data
.m_IsRegex
= m_bFilterWithRegex
;
2208 // follow does not work for directories
2209 if (!path
|| path
->IsDirectory())
2210 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2211 // follow does not work with all branches 8at least in TGit)
2212 if (mask
& CGit::LOG_INFO_FOLLOW
)
2213 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
;
2215 CString cmd
=g_Git
.GetLogCmd(m_StartRef
,path
,-1,mask
,pFrom
,pTo
,true,&data
);
2217 //this->m_logEntries.ParserFromLog();
2218 if(IsInWorkingThread())
2220 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2224 SetItemCountEx((int)m_logEntries
.size());
2234 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2238 if(g_Git
.IsInitRepos())
2242 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2250 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2257 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2259 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2261 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2263 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2265 DiffSelectedRevWithPrevious();
2270 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2277 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2279 // select all entries
2280 for (int i
=0; i
<GetItemCount(); ++i
)
2282 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2288 if (m_hAccel
&& !bSkipAccelerator
)
2290 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2296 //m_tooltips.RelayEvent(pMsg);
2297 return __super::PreTranslateMessage(pMsg
);
2300 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2302 // a double click on an entry in the revision list has happened
2305 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2306 DiffSelectedRevWithPrevious();
2309 int CGitLogListBase::FetchLogAsync(void * data
)
2312 m_bExitThread
=FALSE
;
2313 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2314 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2315 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2316 if (m_LoadingThread
==NULL
)
2318 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2319 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2320 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2326 //this is the thread function which calls the subversion function
2327 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2329 return ((CGitLogListBase
*)pVoid
)->LogThread();
2332 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2335 oldest
=CTime::GetCurrentTime();
2336 latest
=CTime(1971,1,2,0,0,0);
2337 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2339 if(m_logEntries
[i
].IsEmpty())
2342 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2343 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2345 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2346 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2354 UINT
CGitLogListBase::LogThread()
2356 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2358 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2359 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2365 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2366 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2371 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2372 bool bRegex
= false;
2373 if (m_bFilterWithRegex
)
2374 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2376 TRACE(_T("\n===Begin===\n"));
2377 //Update work copy item;
2379 if (!m_logEntries
.empty())
2381 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2383 m_arShownList
.SafeAdd(pRev
);
2387 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2389 // store commit number of the last selected commit/line before the refresh or -1
2390 int lastSelectedHashNItem
= -1;
2393 if(!g_Git
.IsInitRepos())
2395 g_Git
.m_critGitDllSec
.Lock();
2399 git_get_log_firstcommit(m_DllGitLog
);
2400 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2405 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2408 g_Git
.m_critGitDllSec
.Unlock();
2411 t2
=t1
=GetTickCount();
2412 int oldprecentage
= 0;
2413 size_t oldsize
= m_logEntries
.size();
2416 g_Git
.m_critGitDllSec
.Lock();
2419 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
);
2423 g_Git
.m_critGitDllSec
.Unlock();
2425 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2428 g_Git
.m_critGitDllSec
.Unlock();
2433 if (commit
.m_ignore
== 1)
2435 git_free_commit(&commit
);
2439 //printf("%s\r\n",commit.GetSubject());
2443 CGitHash hash
= (char*)commit
.m_hash
;
2445 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2446 pRev
->m_GitCommit
= commit
;
2447 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2450 g_Git
.m_critGitDllSec
.Lock();
2451 git_get_notes(commit
.m_hash
,¬e
);
2452 g_Git
.m_critGitDllSec
.Unlock();
2456 pRev
->m_Notes
.Empty();
2457 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2460 if(!pRev
->m_IsDiffFiles
)
2462 pRev
->m_CallDiffAsync
= DiffAsync
;
2465 pRev
->ParserParentFromCommit(&commit
);
2472 if(!m_sFilterText
.IsEmpty())
2474 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2477 this->m_critSec
.Lock();
2478 m_logEntries
.push_back(hash
);
2479 m_arShownList
.SafeAdd(pRev
);
2480 this->m_critSec
.Unlock();
2482 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2483 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2487 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2490 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2493 if(percent
< GITLOG_START
)
2494 percent
= GITLOG_START
+1;
2496 oldsize
= m_logEntries
.size();
2497 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2499 //if( percent > oldprecentage )
2501 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2502 oldprecentage
= percent
;
2507 g_Git
.m_critGitDllSec
.Lock();
2508 git_close_log(m_DllGitLog
);
2509 g_Git
.m_critGitDllSec
.Unlock();
2513 // restore last selected item
2514 if (lastSelectedHashNItem
>= 0)
2516 SetItemState(lastSelectedHashNItem
, LVIS_SELECTED
, LVIS_SELECTED
);
2517 EnsureVisible(lastSelectedHashNItem
, FALSE
);
2521 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2523 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2525 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2530 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2532 SafeTerminateThread();
2534 this->SetItemCountEx(0);
2539 // HACK to hide graph column
2540 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
2541 SetColumnWidth(0, 0);
2543 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
2545 //Update branch and Tag info
2547 //Assume Thread have exited
2548 //if(!m_bThreadRunning)
2550 m_logEntries
.clear();
2554 m_sFilterText
.Empty();
2559 InterlockedExchange(&m_bExitThread
,FALSE
);
2561 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2562 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2563 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2565 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2566 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2567 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2571 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2575 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2577 type
|= tr1::regex_constants::icase
;
2578 pat
= tr1::wregex(regexp_str
, type
);
2581 catch (exception
) {}
2584 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2587 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2590 if ((bRegex
)&&(m_bFilterWithRegex
))
2592 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2594 if(this->m_bShowBugtraqColumn
)
2596 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2598 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2599 if (regex_search(wstring(sBugIds
), pat
, flags
))
2606 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2608 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2609 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2615 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2617 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2618 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2624 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2626 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2631 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2637 if (m_SelectedFilters
& LOGFILTER_REVS
)
2639 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2640 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2646 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2648 CTGitPathList
*pathList
=NULL
;
2649 if( pRev
->m_IsDiffFiles
)
2650 pathList
= &pRev
->GetFiles(this);
2653 if(!pRev
->m_IsSimpleListReady
)
2654 pRev
->SafeGetSimpleList(&g_Git
);
2658 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2660 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2664 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2670 for(size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); i
++)
2672 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2681 CString find
= m_sFilterText
;
2684 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2686 if(this->m_bShowBugtraqColumn
)
2688 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2690 sBugIds
.MakeLower();
2691 if ((sBugIds
.Find(find
) >= 0))
2698 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2700 CString msg
= pRev
->GetSubject();
2702 msg
= msg
.MakeLower();
2703 if ((msg
.Find(find
) >= 0))
2709 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2711 CString msg
= pRev
->GetBody();
2713 msg
= msg
.MakeLower();
2714 if ((msg
.Find(find
) >= 0))
2720 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2722 CString msg
= pRev
->GetAuthorName();
2723 msg
= msg
.MakeLower();
2724 if ((msg
.Find(find
) >= 0))
2730 if (m_SelectedFilters
& LOGFILTER_REVS
)
2732 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2733 if ((sRev
.Find(find
) >= 0))
2739 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2741 CTGitPathList
*pathList
=NULL
;
2742 if( pRev
->m_IsDiffFiles
)
2743 pathList
= &pRev
->GetFiles(this);
2746 if(!pRev
->m_IsSimpleListReady
)
2747 pRev
->SafeGetSimpleList(&g_Git
);
2750 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
2752 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
2753 CString path
= cpath
->GetGitOldPathString();
2755 if ((path
.Find(find
)>=0))
2759 path
= cpath
->GetGitPathString();
2761 if ((path
.Find(find
)>=0))
2767 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); i
++)
2769 CString path
= pRev
->m_SimpleFileList
[i
];
2771 if ((path
.Find(find
)>=0))
2777 } // else (from if (bRegex))
2782 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
2785 pShownlist
->SafeRemoveAll();
2787 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2788 bool bRegex
= false;
2789 if (m_bFilterWithRegex
)
2790 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2792 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2794 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2796 if ((bRegex
)&&(m_bFilterWithRegex
))
2799 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2801 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2802 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2804 pShownlist
->SafeAdd(m_logEntries
[i
]);
2809 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2811 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
2812 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
2814 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2818 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2820 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
2821 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
2823 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2827 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2829 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2832 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2834 CTGitPath cpath
= pathList
[cpPathIndex
];
2835 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2837 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2841 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
2843 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2847 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
2849 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2855 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2857 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
2859 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2863 if (m_SelectedFilters
& LOGFILTER_REVS
)
2865 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2866 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2868 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2875 CString find
= m_sFilterText
;
2878 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2880 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2882 sBugIDs
= sBugIDs
.MakeLower();
2883 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2885 pShownlist
->SafeAdd(m_logEntries
[i
]);
2890 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2892 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
2894 msg
= msg
.MakeLower();
2895 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2897 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2901 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2903 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
2905 msg
= msg
.MakeLower();
2906 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2908 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2912 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2914 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
2917 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
2919 CTGitPath cpath
= pathList
[cpPathIndex
];
2920 CString path
= cpath
.GetGitOldPathString();
2922 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2924 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2928 path
= cpath
.GetGitPathString();
2930 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2932 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2936 path
= cpath
.GetActionName();
2938 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2940 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2946 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2948 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
2949 msg
= msg
.MakeLower();
2950 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2952 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2956 if (m_SelectedFilters
& LOGFILTER_REVS
)
2958 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
2959 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2961 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2965 } // else (from if (bRegex))
2966 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2970 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
2973 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2979 return time <= m_To;
2982 return time >= m_From;
2984 return ((time >= m_From)&&(time <= m_To));
2986 return TRUE
; /* git dll will filter time range */
2990 void CGitLogListBase::StartFilter()
2992 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2993 RecalculateShownList(&m_arShownList
);
2994 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2998 SetItemCountEx(ShownCountWithStopped());
2999 RedrawItems(0, ShownCountWithStopped());
3003 void CGitLogListBase::RemoveFilter()
3006 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3008 m_arShownList
.SafeRemoveAll();
3010 // reset the time filter too
3012 m_timFrom
= (__time64_t(m_tFrom
));
3013 m_timTo
= (__time64_t(m_tTo
));
3014 m_DateFrom
.SetTime(&m_timFrom
);
3015 m_DateTo
.SetTime(&m_timTo
);
3016 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3017 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3020 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3022 if(this->m_IsOldFirst
)
3024 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3028 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3031 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3033 SetItemCountEx(ShownCountWithStopped());
3034 RedrawItems(0, ShownCountWithStopped());
3036 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3039 void CGitLogListBase::Clear()
3041 m_arShownList
.SafeRemoveAll();
3044 m_logEntries
.ClearAll();
3048 void CGitLogListBase::OnDestroy()
3050 // save the column widths to the registry
3053 SafeTerminateThread();
3054 SafeTerminateAsyncDiffThread();
3057 while(m_LogCache
.SaveCache())
3065 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3066 // MB_YESNO) == IDNO)
3070 CHintListCtrl::OnDestroy();
3073 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
3075 UNREFERENCED_PARAMETER(lParam
);
3078 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3079 this->InvalidateRect(rect
);
3085 * Save column widths to the registry
3087 void CGitLogListBase::SaveColumnWidths()
3089 int maxcol
= m_ColumnManager
.GetColumnCount();
3091 // HACK that graph column is always shown
3092 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3094 for (int col
= 0; col
< maxcol
; col
++)
3095 if (m_ColumnManager
.IsVisible (col
))
3096 m_ColumnManager
.ColumnResized (col
);
3098 m_ColumnManager
.WriteSettings();
3101 int CGitLogListBase::GetHeadIndex()
3103 if(m_HeadHash
.IsEmpty())
3106 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
3108 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
3111 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3117 void CGitLogListBase::OnFind()
3121 m_pFindDialog
= new CFindDlg(this);
3122 m_pFindDialog
->Create(this);
3125 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3127 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3129 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3131 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3134 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3137 ASSERT(m_pFindDialog
!= NULL
);
3138 bool bFound
= false;
3141 if (m_pFindDialog
->IsTerminating())
3143 // invalidate the handle identifying the dialog box.
3144 m_pFindDialog
= NULL
;
3148 if(m_pFindDialog
->IsRef())
3151 str
=m_pFindDialog
->GetFindString();
3156 hash
= g_Git
.GetHash(str
+ _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3160 for (i
= 0; i
<m_arShownList
.GetCount(); i
++)
3162 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3163 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3173 if(m_pFindDialog
->FindNext())
3175 //read data from dialog
3176 CString FindText
= m_pFindDialog
->GetFindString();
3177 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3180 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3182 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3185 for (i
= this->m_nSearchIndex
; i
<m_arShownList
.GetCount()&&!bFound
; i
++)
3187 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3190 str
+=pLogEntry
->m_CommitHash
.ToString();
3193 for(int j
=0;j
<this->m_HashMap
[pLogEntry
->m_CommitHash
].size();j
++)
3195 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3199 str
+=pLogEntry
->GetAuthorEmail();
3201 str
+=pLogEntry
->GetAuthorName();
3203 str
+=pLogEntry
->GetBody();
3205 str
+=pLogEntry
->GetCommitterEmail();
3207 str
+=pLogEntry
->GetCommitterName();
3209 str
+=pLogEntry
->GetSubject();
3213 /*Because changed files list is loaded on demand when gui show,
3214 files will empty when files have not fetched.
3216 we can add it back by using one-way diff(with outnumber changed and rename detect.
3217 here just need changed filename list. one-way is much quicker.
3219 if(pLogEntry
->m_IsFull
)
3221 for(int i
=0;i
<pLogEntry
->GetFiles(this).GetCount();i
++)
3223 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3225 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3231 if(!pLogEntry
->m_IsSimpleListReady
)
3232 pLogEntry
->SafeGetSimpleList(&g_Git
);
3234 for(int i
=0;i
<pLogEntry
->m_SimpleFileList
.size();i
++)
3236 str
+=pLogEntry
->m_SimpleFileList
[i
];
3245 if (regex_search(wstring(str
), pat
, flags
))
3255 if (str
.Find(FindText
) >= 0)
3265 msg
= msg
.MakeLower();
3266 CString find
= FindText
.MakeLower();
3267 if (msg
.Find(find
) >= 0)
3274 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3276 } // if(m_pFindDialog->FindNext())
3277 //UpdateLogInfoLabel();
3281 this->m_nSearchIndex
= i
;
3282 EnsureVisible(i
, FALSE
);
3283 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3284 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3285 SetSelectionMark(i
);
3286 //FillLogMessageCtrl();
3289 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3290 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3296 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3298 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3303 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3305 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);