1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // GitLogList.cpp : implementation file
24 #include "GitLogListBase.h"
27 #include "GitProgressDlg.h"
28 #include "ProgressDlg.h"
29 #include "MessageBox.h"
31 #include "LoglistUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
35 #include "GitStatus.h"
36 #include "..\TortoiseShell\Resource.h"
40 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
41 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
42 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
44 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
46 CGitLogListBase::CGitLogListBase():CHintListCtrl()
47 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
49 ,m_bNoDispUpdates(FALSE
)
50 , m_bThreadRunning(FALSE
)
51 , m_bStrictStopped(false)
52 , m_pStoreSelection(NULL
)
53 , m_SelectedFilters(LOGFILTER_ALL
)
54 , m_ShowFilter(FILTERSHOW_ALL
)
56 , m_logEntries(&m_LogCache
)
58 , m_ColumnManager(this)
59 , m_dwDefaultColumns(0)
60 , m_arShownList(&m_critSec
)
62 , m_bNoHightlightHead(FALSE
)
63 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
64 , m_bFullCommitMessageOnLogLine(false)
66 // use the default GUI font, create a copy of it and
67 // change the copy to BOLD (leave the rest of the font
69 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
71 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
72 lf
.lfWeight
= FW_BOLD
;
73 m_boldFont
= CreateFontIndirect(&lf
);
74 lf
.lfWeight
= FW_DONTCARE
;
76 m_FontItalics
= CreateFontIndirect(&lf
);
77 lf
.lfWeight
= FW_BOLD
;
78 m_boldItalicsFont
= CreateFontIndirect(&lf
);
80 m_bShowBugtraqColumn
=false;
82 m_IsIDReplaceAction
=FALSE
;
84 this->m_critSec
.Init();
85 m_critSec_AsyncDiff
.Init();
88 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
89 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
90 m_hConflictedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
91 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
92 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
93 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
95 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE
);
96 m_bFilterCaseSensitively
= !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE
);
102 m_LoadingThread
= NULL
;
104 InterlockedExchange(&m_bExitThread
,FALSE
);
105 m_IsOldFirst
= FALSE
;
106 m_IsRebaseReplaceGraph
= FALSE
;
108 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
110 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
112 // get short/long datetime setting from registry
113 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
114 if ( RegUseShortDateFormat
)
116 m_DateFormat
= DATE_SHORTDATE
;
120 m_DateFormat
= DATE_LONGDATE
;
122 // get relative time display setting from registry
123 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
124 m_bRelativeTimes
= (regRelativeTimes
!= 0);
125 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
127 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
128 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
129 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
131 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
132 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
133 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
135 m_ColumnRegKey
=_T("log");
137 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
138 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
139 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
140 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE
);
142 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
143 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
145 m_AsyncThreadExit
= FALSE
;
146 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
147 m_AsynDiffListLock
.Init();
149 hUxTheme
= AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
151 pfnDrawThemeTextEx
= (FNDRAWTHEMETEXTEX
)::GetProcAddress(hUxTheme
, "DrawThemeTextEx");
153 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
154 if (m_DiffingThread
==NULL
)
156 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
162 int CGitLogListBase::AsyncDiffThread()
164 m_AsyncThreadExited
= false;
165 while(!m_AsyncThreadExit
)
167 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
169 GitRevLoglist
* pRev
= nullptr;
170 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
172 m_AsynDiffListLock
.Lock();
173 pRev
= m_AsynDiffList
.back();
174 m_AsynDiffList
.pop_back();
175 m_AsynDiffListLock
.Unlock();
177 if( pRev
->m_CommitHash
.IsEmpty() )
179 if(pRev
->m_IsDiffFiles
)
182 CTGitPathList
& files
= pRev
->GetFiles(this);
184 pRev
->m_ParentHash
.clear();
185 pRev
->m_ParentHash
.push_back(m_HeadHash
);
186 g_Git
.GetWorkingTreeChanges(files
);
187 int& action
= pRev
->GetAction(this);
189 for (int j
= 0; j
< files
.GetCount(); ++j
)
190 action
|= files
[j
].m_Action
;
193 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
195 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
199 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
200 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
202 pRev
->GetBody().Format(IDS_FILESCHANGES
, files
.GetCount());
203 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
204 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
207 m_critSec_AsyncDiff
.Lock();
208 int ret
= pRev
->CheckAndDiff();
209 m_critSec_AsyncDiff
.Unlock();
211 { // fetch change file list
212 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
214 if(i
< m_arShownList
.GetCount())
216 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
217 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
219 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
225 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
227 POSITION pos
= GetFirstSelectedItemPosition();
228 int nItem
= GetNextSelectedItem(pos
);
232 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
234 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
236 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
243 m_AsyncThreadExited
= true;
246 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
250 m_ContextMenuMask
&= hideMask
;
254 m_ContextMenuMask
&= ~hideMask
;
258 CGitLogListBase::~CGitLogListBase()
260 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
261 this->m_arShownList
.SafeRemoveAll();
263 DestroyIcon(m_hModifiedIcon
);
264 DestroyIcon(m_hReplacedIcon
);
265 DestroyIcon(m_hConflictedIcon
);
266 DestroyIcon(m_hAddedIcon
);
267 DestroyIcon(m_hDeletedIcon
);
268 m_logEntries
.ClearAll();
271 DeleteObject(m_boldFont
);
274 DeleteObject(m_FontItalics
);
276 if (m_boldItalicsFont
)
277 DeleteObject(m_boldItalicsFont
);
279 if ( m_pStoreSelection
)
281 delete m_pStoreSelection
;
282 m_pStoreSelection
= NULL
;
285 SafeTerminateThread();
286 SafeTerminateAsyncDiffThread();
289 CloseHandle(m_AsyncDiffEvent
);
292 FreeLibrary(hUxTheme
);
296 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
297 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
298 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
299 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
300 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
302 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
303 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
306 ON_MESSAGE(MSG_LOADED
,OnLoad
)
308 ON_WM_MEASUREITEM_REFLECT()
309 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
310 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
311 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
312 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
313 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
314 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
315 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
316 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
319 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
321 //if (m_nRowHeight>0)
323 lpMeasureItemStruct
->itemHeight
= 50;
327 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
330 return CHintListCtrl::OnCreate(lpCreateStruct
);
333 void CGitLogListBase::PreSubclassWindow()
335 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
336 // load the icons for the action columns
337 // m_Theme.Open(m_hWnd, L"ListView");
338 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
339 CHintListCtrl::PreSubclassWindow();
342 CString
CGitLogListBase::GetRebaseActionName(int action
)
344 if (action
& LOGACTIONS_REBASE_EDIT
)
345 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
346 if (action
& LOGACTIONS_REBASE_SQUASH
)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
348 if (action
& LOGACTIONS_REBASE_PICK
)
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
350 if (action
& LOGACTIONS_REBASE_SKIP
)
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
356 void CGitLogListBase::InsertGitColumn()
360 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
361 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
362 if (DWORD(regFullRowSelect
))
363 exStyle
|= LVS_EX_FULLROWSELECT
;
364 SetExtendedStyle(exStyle
);
366 // only load properties if we have a repository
367 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
368 UpdateProjectProperties();
370 static UINT normal
[] =
382 IDS_LOG_COMMIT_EMAIL
,
405 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
407 DWORD hideColumns
= 0;
408 if(this->m_IsRebaseReplaceGraph
)
410 hideColumns
|= GIT_LOG_GRAPH
;
411 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
415 hideColumns
|= GIT_LOG_REBASE
;
418 if(this->m_IsIDReplaceAction
)
420 hideColumns
|= GIT_LOG_ACTIONS
;
421 m_dwDefaultColumns
|= GIT_LOG_ID
;
422 m_dwDefaultColumns
|= GIT_LOG_HASH
;
426 hideColumns
|= GIT_LOG_ID
;
428 if(this->m_bShowBugtraqColumn
)
430 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
434 hideColumns
|= GIT_LOGLIST_BUG
;
436 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
437 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
439 hideColumns
|= GIT_LOGLIST_SVNREV
;
442 m_ColumnManager
.SetNames(normal
, _countof(normal
));
443 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
449 * Resizes all columns in a list control to values in registry.
451 void CGitLogListBase::ResizeAllListCtrlCols()
453 // column max and min widths to allow
454 static const int nMinimumWidth
= 10;
455 static const int nMaximumWidth
= 1000;
456 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
459 int numcols
= pHdrCtrl
->GetItemCount();
460 for (int col
= 0; col
< numcols
; ++col
)
462 // get width for this col last time from registry
464 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR
)m_ColumnRegKey
, col
);
465 CRegDWORD
regwidth(regentry
, 0);
469 // no saved value, setup sensible defaults
470 if (col
== this->LOGLIST_MESSAGE
)
472 cx
= LOGLIST_MESSAGE_MIN
;
476 cx
= ICONITEMBORDER
+16*4;
479 if (cx
< nMinimumWidth
)
483 else if (cx
> nMaximumWidth
)
488 SetColumnWidth(col
, cx
);
495 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
498 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
499 rItem
.mask
= LVIF_STATE
;
500 rItem
.iItem
= (int)Index
;
501 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
504 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(Index
);
507 if (!(rItem
.state
& LVIS_SELECTED
))
509 int action
= pLogEntry
->GetRebaseAction();
510 if (action
& LOGACTIONS_REBASE_SQUASH
)
511 brush
= ::CreateSolidBrush(RGB(156,156,156));
512 else if (action
& LOGACTIONS_REBASE_EDIT
)
513 brush
= ::CreateSolidBrush(RGB(200,200,128));
515 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
517 if (rItem
.state
& LVIS_SELECTED
)
519 if (::GetFocus() == m_hWnd
)
520 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
522 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
527 ::FillRect(hdc
, &rect
, brush
);
528 ::DeleteObject(brush
);
532 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
534 POINT point
= { 4, 4 };
536 rt2
.DeflateRect(1, 1);
537 rt2
.OffsetRect(2, 2);
539 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
540 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
541 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
542 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
543 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
545 ::SelectObject(hdc
, brush
);
546 rt2
.OffsetRect(-2, -2);
547 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
548 ::SelectObject(hdc
, oldbrush
);
549 ::SelectObject(hdc
, oldpen
);
550 ::DeleteObject(nullPen
);
551 ::DeleteObject(darkBrush
);
554 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
556 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
557 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
558 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
559 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
560 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
561 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
562 ::SelectObject(hdc
, oldpen
);
566 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
568 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
569 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
570 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
571 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
572 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
573 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
574 ::SelectObject(hdc
, oldpen
);
578 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
580 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
583 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
584 rItem
.mask
= LVIF_STATE
;
585 rItem
.iItem
= (int)index
;
586 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
592 HTHEME hTheme
= NULL
;
593 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
594 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
597 if (m_bTagsBranchesOnRightSide
)
599 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
600 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
601 SelectObject(hdc
, oldFont
);
602 rt
.left
+= oneSpaceSize
.cx
* 2;
606 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
607 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
608 rt
.left
+= oneSpaceSize
.cx
;
611 CString msg
= MessageDisplayStr(data
);
612 int action
= data
->GetRebaseAction();
613 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
614 if (IsAppThemed() && pfnDrawThemeTextEx
)
616 int txtState
= LISS_NORMAL
;
617 if (rItem
.state
& LVIS_SELECTED
)
618 txtState
= LISS_SELECTED
;
620 DTTOPTS opts
= { 0 };
621 opts
.dwSize
= sizeof(opts
);
622 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
623 opts
.dwFlags
= DTT_TEXTCOLOR
;
624 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
628 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
630 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
631 ::DrawText(hdc
,msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
632 ::SetTextColor(hdc
, clrOld
);
636 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
637 ::DrawText(hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
638 ::SetTextColor(hdc
, clrOld
);
642 if (m_bTagsBranchesOnRightSide
)
645 GetTextExtentPoint32(hdc
, msg
, msg
.GetLength(), &size
);
647 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
649 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
653 CloseThemeData(hTheme
);
658 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
)
660 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
662 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
664 COLORREF colRef
= refList
[i
].color
;
665 bool singleRemote
= refList
[i
].singleRemote
;
666 bool hasTracking
= refList
[i
].hasTracking
;
667 bool sameName
= refList
[i
].sameName
;
668 bool annotatedTag
= refList
[i
].annotatedTag
;
670 //When row selected, ajust label color
671 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
673 if (rItem
.state
& LVIS_SELECTED
)
674 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
677 brush
= ::CreateSolidBrush(colRef
);
679 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
682 memset(&size
,0,sizeof(SIZE
));
683 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
685 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
688 int textpos
= DT_CENTER
;
690 if (rt
.right
> rect
.right
)
692 rt
.right
= rect
.right
;
701 textRect
.OffsetRect(8, 0);
709 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
713 //Fill interior of ref label
714 ::FillRect(hdc
, &rt
, brush
);
722 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
723 rectEdge
.DeflateRect(1, 1);
724 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
730 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
731 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
732 ::FillRgn(hdc
, hrgn
, brush
);
733 ::DeleteObject(hrgn
);
734 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
736 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
737 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
739 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
740 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
742 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
743 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
744 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
746 SelectObject(hdc
, oldpen
);
749 //Draw text inside label
750 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
751 if (!customColor
&& IsAppThemed() && pfnDrawThemeTextEx
)
753 int txtState
= LISS_NORMAL
;
754 if (rItem
.state
& LVIS_SELECTED
)
755 txtState
= LISS_SELECTED
;
757 DTTOPTS opts
= { 0 };
758 opts
.dwSize
= sizeof(opts
);
759 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
760 opts
.dwFlags
= DTT_TEXTCOLOR
;
761 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
765 W_Dc
.SetBkMode(TRANSPARENT
);
766 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
768 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
769 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
770 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
771 ::SetTextColor(hdc
,clrOld
);
775 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
776 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
777 ::SetTextColor(hdc
, clrOld
);
783 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
784 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
786 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
787 DrawLightning(hdc
, newRect
, color
, bold
);
792 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
793 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
795 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
796 DrawUpTriangle(hdc
, newRect
, color
, bold
);
799 rt
.left
= rt
.right
+ 1;
802 ::DeleteObject(brush
);
804 rt
.right
= rect
.right
;
807 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
809 // Returns ((256 - amount)*col1 + amount*col2) / 256;
810 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
811 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
812 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
815 Gdiplus::Color
GetGdiColor(COLORREF col
)
817 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
819 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
820 const COLORREF
& col
,const COLORREF
& activeColor
, int top
823 int h
= laneHeight
/ 2;
824 int m
= (x1
+ x2
) / 2;
825 int r
= (x2
- x1
) * m_NodeSize
/ 30;
828 #define P_CENTER m , h+top
829 #define P_0 x2, h+top
830 #define P_90 m , 0+top-1
831 #define P_180 x1, h+top
832 #define P_270 m , 2 * h+top +1
833 #define R_CENTER m - r, h - r+top, d, d
836 #define DELTA_UR_B 2*(x1 - m), 2*h +top
837 #define DELTA_UR_E 0*16, 90*16 +top // -,
839 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
840 #define DELTA_DR_E 270*16, 90*16 +top // -'
842 #define DELTA_UL_B 2*(x2 - m), 2*h +top
843 #define DELTA_UL_E 90*16, 90*16 +top // ,-
845 #define DELTA_DL_B 2*(x2 - m),2*-h +top
846 #define DELTA_DL_E 180*16, 90*16 // '-
848 #define CENTER_UR x1, 2*h, 225
849 #define CENTER_DR x1, 0 , 135
850 #define CENTER_UL x2, 2*h, 315
851 #define CENTER_DL x2, 0 , 45
854 Gdiplus::Graphics
graphics( hdc
);
856 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
865 Gdiplus::LinearGradientBrush
gradient(
866 Gdiplus::Point(x1
-2, h
+top
-2),
867 Gdiplus::Point(P_270
),
868 GetGdiColor(activeColor
),GetGdiColor(col
));
871 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
872 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
874 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
875 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
876 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
883 Gdiplus::LinearGradientBrush
gradient(
884 Gdiplus::Point(P_270
),
885 Gdiplus::Point(x2
+1, h
+top
-1),
886 GetGdiColor(col
),GetGdiColor(activeColor
));
889 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
890 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
892 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
893 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
894 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
903 Gdiplus::LinearGradientBrush
gradient(
904 Gdiplus::Point(x1
-2, h
+top
-2),
905 Gdiplus::Point(P_90
),
906 GetGdiColor(activeColor
),GetGdiColor(col
));
908 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
910 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
913 QConicalGradient
gradient(CENTER_DR
);
914 gradient
.setColorAt(0.375, activeCol
);
915 gradient
.setColorAt(0.625, col
);
916 myPen
.setBrush(gradient
);
918 p
->drawArc(P_CENTER
, DELTA_DR
);
927 //static QPen myPen(Qt::black, 2); // fast path here
929 pen
.CreatePen(PS_SOLID
,2,col
);
930 //myPen.setColor(col);
931 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
933 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
935 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
942 case Lanes::NOT_ACTIVE
:
943 case Lanes::MERGE_FORK
:
944 case Lanes::MERGE_FORK_R
:
945 case Lanes::MERGE_FORK_L
:
950 //DrawLine(hdc,P_90,P_270);
951 graphics
.DrawLine(&myPen
,P_90
,P_270
);
952 //p->drawLine(P_90, P_270);
956 //DrawLine(hdc,P_CENTER,P_270);
957 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
958 //p->drawLine(P_CENTER, P_270);
962 case Lanes::BOUNDARY
:
963 case Lanes::BOUNDARY_C
:
964 case Lanes::BOUNDARY_R
:
965 case Lanes::BOUNDARY_L
:
966 //DrawLine(hdc,P_90, P_CENTER);
967 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
968 //p->drawLine(P_90, P_CENTER);
974 myPen
.SetColor(GetGdiColor(activeColor
));
978 case Lanes::MERGE_FORK
:
983 case Lanes::CROSS_EMPTY
:
984 case Lanes::BOUNDARY_C
:
985 //DrawLine(hdc,P_180,P_0);
986 graphics
.DrawLine(&myPen
,P_180
,P_0
);
987 //p->drawLine(P_180, P_0);
989 case Lanes::MERGE_FORK_R
:
990 case Lanes::BOUNDARY_R
:
991 //DrawLine(hdc,P_180,P_CENTER);
992 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
993 //p->drawLine(P_180, P_CENTER);
995 case Lanes::MERGE_FORK_L
:
998 case Lanes::BOUNDARY_L
:
999 //DrawLine(hdc,P_CENTER,P_0);
1000 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
1001 //p->drawLine(P_CENTER, P_0);
1007 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1010 brush
.CreateSolidBrush(col
);
1011 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1013 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1014 // center symbol, e.g. rect or ellipse
1017 case Lanes::INITIAL
:
1020 //p->setPen(Qt::NoPen);
1022 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1023 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1024 //p->drawEllipse(R_CENTER);
1026 case Lanes::MERGE_FORK
:
1027 case Lanes::MERGE_FORK_R
:
1028 case Lanes::MERGE_FORK_L
:
1029 //p->setPen(Qt::NoPen);
1031 //p->drawRect(R_CENTER);
1032 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1033 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1035 case Lanes::UNAPPLIED
:
1037 //p->setPen(Qt::NoPen);
1038 //p->setBrush(Qt::red);
1039 //p->drawRect(m - r, h - 1, d, 2);
1040 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1041 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1043 case Lanes::APPLIED
:
1045 //p->setPen(Qt::NoPen);
1046 //p->setBrush(DARK_GREEN);
1047 //p->drawRect(m - r, h - 1, d, 2);
1048 //p->drawRect(m - 1, h - r, 2, d);
1049 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1050 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1051 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1053 case Lanes::BOUNDARY
:
1054 //p->setBrush(back);
1055 //p->drawEllipse(R_CENTER);
1056 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1057 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1059 case Lanes::BOUNDARY_C
:
1060 case Lanes::BOUNDARY_R
:
1061 case Lanes::BOUNDARY_L
:
1062 //p->setBrush(back);
1063 //p->drawRect(R_CENTER);
1064 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1065 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1071 ::SelectObject(hdc
,oldpen
);
1072 ::SelectObject(hdc
,oldbrush
);
1081 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1085 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
1086 if(data
->m_CommitHash
.IsEmpty())
1091 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1092 rItem
.mask
= LVIF_STATE
;
1093 rItem
.iItem
= (int)index
;
1094 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1097 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1099 if (data
->m_Lanes
.empty())
1100 m_logEntries
.setLane(data
->m_CommitHash
);
1102 std::vector
<int>& lanes
=data
->m_Lanes
;
1103 size_t laneNum
= lanes
.size();
1104 UINT activeLane
= 0;
1105 for (UINT i
= 0; i
< laneNum
; ++i
)
1106 if (Lanes::isMerge(lanes
[i
])) {
1112 int maxWidth
= rect
.Width();
1113 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1115 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1116 //if (opt.state & QStyle::State_Selected)
1117 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1119 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1126 if (ln
== Lanes::EMPTY
)
1129 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1130 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1134 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1140 if (ln
== Lanes::EMPTY
)
1143 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1144 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1146 if (ln
== Lanes::CROSS
)
1148 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1149 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1152 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1158 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1161 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1162 // Take the default processing unless we set this to something else below.
1163 *pResult
= CDRF_DODEFAULT
;
1165 if (m_bNoDispUpdates
)
1168 switch (pLVCD
->nmcd
.dwDrawStage
)
1172 *pResult
= CDRF_NOTIFYITEMDRAW
;
1176 case CDDS_ITEMPREPAINT
:
1178 // This is the prepaint stage for an item. Here's where we set the
1179 // item's text color.
1181 // Tell Windows to send draw notifications for each subitem.
1182 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1184 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1186 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1188 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1191 HGDIOBJ hGdiObj
= nullptr;
1192 int action
= data
->GetRebaseAction();
1193 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1194 crText
= RGB(128,128,128);
1196 if (action
& LOGACTIONS_REBASE_SQUASH
)
1197 pLVCD
->clrTextBk
= RGB(156,156,156);
1198 else if (action
& LOGACTIONS_REBASE_EDIT
)
1199 pLVCD
->clrTextBk
= RGB(200,200,128);
1201 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1203 if (action
& LOGACTIONS_REBASE_CURRENT
)
1204 hGdiObj
= m_boldFont
;
1206 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1207 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1208 if (isHeadHash
&& isHighlight
)
1209 hGdiObj
= m_boldItalicsFont
;
1210 else if (isHeadHash
)
1211 hGdiObj
= m_boldFont
;
1212 else if (isHighlight
)
1213 hGdiObj
= m_FontItalics
;
1217 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1218 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1221 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1222 // crText = GetSysColor(COLOR_GRAYTEXT);
1224 if (data
->m_CommitHash
.IsEmpty())
1226 //crText = GetSysColor(RGB(200,200,0));
1227 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1228 // We changed the font, so we're returning CDRF_NEWFONT. This
1229 // tells the control to recalculate the extent of the text.
1230 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1234 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1236 if (m_bStrictStopped
)
1237 crText
= GetSysColor(COLOR_GRAYTEXT
);
1239 // Store the color back in the NMLVCUSTOMDRAW struct.
1240 pLVCD
->clrText
= crText
;
1244 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1246 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1248 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1251 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1253 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1256 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1258 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1259 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1261 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1262 if( !data
->m_CommitHash
.IsEmpty())
1263 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1265 *pResult
= CDRF_SKIPDEFAULT
;
1270 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1272 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1274 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1276 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1279 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1281 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1282 // not in FillBackGround method, because this only affected the message subitem
1283 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1286 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1287 int state
= GetItemState(index
, LVIS_SELECTED
);
1288 int txtState
= LISS_NORMAL
;
1289 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1291 if (state
& LVIS_SELECTED
)
1292 txtState
= LISS_HOTSELECTED
;
1294 txtState
= LISS_HOT
;
1296 else if (state
& LVIS_SELECTED
)
1298 if (::GetFocus() == m_hWnd
)
1299 txtState
= LISS_SELECTED
;
1301 txtState
= LISS_SELECTEDNOTFOCUS
;
1304 HTHEME hTheme
= nullptr;
1305 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1306 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1308 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1309 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1312 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1313 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1314 ::DeleteObject(brush
);
1319 // get rect of whole line
1320 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1322 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1323 rect2
.DeflateRect(1, 1, 1, 1);
1325 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1326 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1328 CloseThemeData(hTheme
);
1330 // END: extended redraw
1332 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1334 std::vector
<REFLABEL
> refsToShow
;
1335 STRING_VECTOR remoteTrackingList
;
1336 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1337 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1339 CString str
= refList
[i
];
1342 refLabel
.color
= RGB(255, 255, 255);
1343 refLabel
.singleRemote
= false;
1344 refLabel
.hasTracking
= false;
1345 refLabel
.sameName
= false;
1346 refLabel
.annotatedTag
= false;
1347 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1349 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1351 if (refLabel
.name
== m_CurrentBranch
)
1352 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1354 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1356 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1357 CString pullRemote
= trackingEntry
.first
;
1358 CString pullBranch
= trackingEntry
.second
;
1359 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1361 CString defaultUpstream
;
1362 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), (LPCTSTR
)pullRemote
, (LPCTSTR
)pullBranch
);
1363 refLabel
.hasTracking
= true;
1364 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1367 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1369 if (refList
[j
] == defaultUpstream
)
1378 bool sameName
= pullBranch
== refLabel
.name
;
1379 refsToShow
.push_back(refLabel
);
1380 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1381 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1382 if (m_bSymbolizeRefNames
)
1384 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1386 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1387 refLabel
.singleRemote
= true;
1390 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1391 refLabel
.sameName
= sameName
;
1393 refsToShow
.push_back(refLabel
);
1394 remoteTrackingList
.push_back(defaultUpstream
);
1400 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1402 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1406 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1408 if (remoteTrackingList
[j
] == str
)
1417 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1418 if (m_bSymbolizeRefNames
)
1420 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1422 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1423 refLabel
.singleRemote
= true;
1427 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1429 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1431 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1432 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1434 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1436 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1438 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1439 refLabel
.name
= _T("stash");
1441 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1443 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1445 if (refLabel
.name
.Find(_T("good")) == 0)
1447 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1448 refLabel
.name
= _T("good");
1450 if (refLabel
.name
.Find(_T("bad")) == 0)
1452 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1453 refLabel
.name
= _T("bad");
1459 refsToShow
.push_back(refLabel
);
1462 if (refsToShow
.empty())
1464 *pResult
= CDRF_DODEFAULT
;
1468 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1470 *pResult
= CDRF_SKIPDEFAULT
;
1478 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1480 if(this->m_IsIDReplaceAction
)
1482 *pResult
= CDRF_DODEFAULT
;
1485 *pResult
= CDRF_DODEFAULT
;
1487 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1491 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1492 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1494 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1496 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1497 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1498 // Get the selected state of the
1499 // item being drawn.
1501 // Fill the background if necessary
1502 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1504 // Draw the icon(s) into the compatible DC
1505 int action
= pLogEntry
->GetAction(this);
1506 if (!pLogEntry
->m_IsDiffFiles
)
1508 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1509 *pResult
= CDRF_SKIPDEFAULT
;
1513 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1514 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1517 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1518 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1521 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1522 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1525 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1526 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1529 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1530 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1533 *pResult
= CDRF_SKIPDEFAULT
;
1539 *pResult
= CDRF_DODEFAULT
;
1542 CString
FindSVNRev(const CString
& msg
)
1546 const std::tr1::wsregex_iterator end
;
1547 std::wstring s
= msg
;
1548 std::tr1::wregex
regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1549 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex1
); it
!= end
; ++it
)
1551 const std::tr1::wsmatch match
= *it
;
1552 if (match
.size() == 4)
1554 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1555 return std::wstring(match
[2]).c_str();
1558 std::tr1::wregex
regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1559 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex2
); it
!= end
; ++it
)
1561 const std::tr1::wsmatch match
= *it
;
1562 if (match
.size() == 3)
1564 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1565 return std::wstring(match
[1]).c_str();
1569 catch (std::exception
) {}
1574 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1576 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1577 return pLogEntry
->GetSubject();
1580 txt
.Format(L
"%s %s", (LPCTSTR
)pLogEntry
->GetSubject(), (LPCTSTR
)pLogEntry
->GetBody());
1583 txt
.Replace(_T("\n"), _T(" "));
1584 txt
.Replace(_T("\r"), _T(" "));
1589 // CGitLogListBase message handlers
1591 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1593 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1595 // Create a pointer to the item
1596 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1598 // Do the list need text information?
1599 if (!(pItem
->mask
& LVIF_TEXT
))
1602 // By default, clear text buffer.
1603 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
- 1);
1605 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1608 if (m_bNoDispUpdates
|| bOutOfRange
)
1611 // Which item number?
1612 int itemid
= pItem
->iItem
;
1613 GitRevLoglist
* pLogEntry
= nullptr;
1614 if (itemid
< m_arShownList
.GetCount())
1615 pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1620 temp
.Format(_T("%d"),pItem
->iItem
+1);
1625 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1629 switch (pItem
->iSubItem
)
1631 case LOGLIST_GRAPH
: //Graphic
1633 case LOGLIST_REBASE
:
1635 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1636 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1639 case LOGLIST_ACTION
: //action -- no text in the column
1643 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1646 if(this->m_IsIDReplaceAction
)
1647 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1649 case LOGLIST_MESSAGE
: //Message
1651 lstrcpyn(pItem
->pszText
, (LPCTSTR
)MessageDisplayStr(pLogEntry
), pItem
->cchTextMax
- 1);
1653 case LOGLIST_AUTHOR
: //Author
1655 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
- 1);
1657 case LOGLIST_DATE
: //Date
1658 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1659 lstrcpyn(pItem
->pszText
,
1660 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1661 pItem
->cchTextMax
- 1);
1666 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
- 1);
1669 case LOGLIST_COMMIT_NAME
: //Commit
1671 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
- 1);
1674 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1676 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
- 1);
1679 case LOGLIST_COMMIT_DATE
: //Commit Date
1680 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1681 lstrcpyn(pItem
->pszText
,
1682 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1683 pItem
->cchTextMax
- 1);
1685 case LOGLIST_BUG
: //Bug ID
1687 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1689 case LOGLIST_SVNREV
: //SVN revision
1691 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1699 bool CGitLogListBase::IsOnStash(int index
)
1701 GitRevLoglist
* rev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
));
1706 GitRevLoglist
* preRev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
- 1));
1707 if (IsStash(preRev
))
1708 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1713 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1715 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1717 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1723 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1725 if (pRev
->m_ParentHash
.empty())
1727 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1728 MessageBox(pRev
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1730 parentHash
= pRev
->m_ParentHash
;
1733 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1736 if (pWnd
== GetHeaderCtrl())
1738 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1741 int selIndex
= GetSelectionMark();
1743 return; // nothing selected, nothing to do with a context menu
1745 // if the user selected the info text telling about not all revisions shown due to
1746 // the "stop on copy/rename" option, we also don't show the context menu
1747 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1750 // if the context menu is invoked through the keyboard, we have to use
1751 // a calculated position on where to anchor the menu on
1752 if ((point
.x
== -1) && (point
.y
== -1))
1755 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1756 ClientToScreen(&rect
);
1757 point
= rect
.CenterPoint();
1759 m_nSearchIndex
= selIndex
;
1760 m_bCancelled
= FALSE
;
1762 // calculate some information the context menu commands can use
1763 // CString pathURL = GetURLFromPath(m_path);
1765 POSITION pos
= GetFirstSelectedItemPosition();
1766 int indexNext
= GetNextSelectedItem(pos
);
1770 GitRevLoglist
* pSelLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(indexNext
));
1771 if (pSelLogEntry
== nullptr)
1774 GitRev revSelected
= pSelLogEntry
->Rev
;
1775 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1776 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1778 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1780 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1781 if (changedpath
->lCopyFromRev
)
1782 revPrevious
= changedpath
->lCopyFromRev
;
1785 GitRev revSelected2
;
1788 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1789 revSelected2
= pLogEntry
->Rev
;
1791 bool bAllFromTheSameAuthor
= true;
1792 CString firstAuthor
;
1793 CLogDataVector selEntries
;
1794 GitRev revLowest
, revHighest
;
1795 GitRevRangeArray revisionRanges
;
1797 POSITION pos
= GetFirstSelectedItemPosition();
1798 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1799 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1800 selEntries
.push_back(pLogEntry
);
1801 firstAuthor
= pLogEntry
->sAuthor
;
1802 revLowest
= pLogEntry
->Rev
;
1803 revHighest
= pLogEntry
->Rev
;
1806 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1807 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1808 selEntries
.push_back(pLogEntry
);
1809 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1810 bAllFromTheSameAuthor
= false;
1811 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1812 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1818 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1820 int FirstSelect
=-1, LastSelect
=-1;
1821 pos
= GetFirstSelectedItemPosition();
1822 FirstSelect
= GetNextSelectedItem(pos
);
1825 LastSelect
= GetNextSelectedItem(pos
);
1827 //entry is selected, now show the popup menu
1829 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1831 if (popup
.CreatePopupMenu())
1833 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1834 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1835 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1836 bool isStash
= IsOnStash(indexNext
);
1837 GIT_REV_LIST parentHash
;
1838 GetParentHashes(pSelLogEntry
, parentHash
);
1840 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1841 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1843 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1)
1844 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1846 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1847 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1849 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1850 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1852 if (m_ContextMenuMask
& (GetContextMenuBit(ID_REBASE_SKIP
) | GetContextMenuBit(ID_REBASE_EDIT
) | GetContextMenuBit(ID_REBASE_SQUASH
) | GetContextMenuBit(ID_REBASE_PICK
)) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1853 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1855 if (GetSelectedCount() == 1)
1858 bool requiresSeparator
= false;
1859 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1861 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1863 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1864 requiresSeparator
= true;
1869 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1871 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1872 requiresSeparator
= true;
1874 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1876 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1877 requiresSeparator
= true;
1881 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1883 if (parentHash
.size() == 1)
1885 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1886 requiresSeparator
= true;
1888 else if (parentHash
.size() > 1)
1890 blamemenu
.CreatePopupMenu();
1891 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1892 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1895 str
.Format(IDS_PARENT
, i
+ 1);
1896 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1898 requiresSeparator
= true;
1902 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1904 if (parentHash
.size() == 1)
1906 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1907 requiresSeparator
= true;
1909 else if (parentHash
.size() > 1)
1911 gnudiffmenu
.CreatePopupMenu();
1912 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1914 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1915 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1916 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1918 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1921 str
.Format(IDS_PARENT
, i
+ 1);
1922 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1924 requiresSeparator
= true;
1928 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1930 if (parentHash
.size() == 1)
1932 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1933 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1934 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1935 requiresSeparator
= true;
1937 else if (parentHash
.size() > 1)
1939 diffmenu
.CreatePopupMenu();
1940 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1941 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1944 str
.Format(IDS_PARENT
, i
+ 1);
1945 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1946 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1948 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1949 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1952 requiresSeparator
= true;
1956 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1958 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1959 requiresSeparator
= true;
1962 if (requiresSeparator
)
1963 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1965 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1967 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1968 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1971 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1973 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1974 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1976 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1977 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1979 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1982 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1984 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1985 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1987 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1988 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1990 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
1991 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1993 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1995 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1996 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1998 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2002 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2004 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2006 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2008 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2010 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2011 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2013 // popup.AppendMenu(MF_SEPARATOR, NULL);
2018 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2020 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2022 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2023 GetSelectedCount() == 1)
2024 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2026 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2027 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2029 str
.Format(IDS_LOG_POPUP_MERGEREV
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2031 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2032 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2034 str
.Format(IDS_RESET_TO_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2036 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2037 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2040 // Add Switch Branch express Menu
2041 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2042 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2045 std::vector
<CString
*> branchs
;
2046 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2048 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2049 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2051 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2056 str2
.LoadString(IDS_SWITCH_BRANCH
);
2058 if(branchs
.size() == 1)
2061 str2
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2062 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2064 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2067 else if(branchs
.size() > 1)
2069 subbranchmenu
.CreatePopupMenu();
2070 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2072 if (*branchs
[i
] != currentBranch
)
2074 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2075 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2079 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2083 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2084 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2086 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2087 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2089 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2090 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2092 str
.Format(IDS_REBASE_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2094 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2095 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2096 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2098 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2099 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2101 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2103 if (parentHash
.size() == 1)
2105 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2107 else if (parentHash
.size() > 1)
2109 revertmenu
.CreatePopupMenu();
2110 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2112 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2115 str2
.Format(IDS_PARENT
, i
+ 1);
2116 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2121 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2122 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2124 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2129 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2131 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2132 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2133 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2134 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2137 if (GetSelectedCount() >= 2)
2139 bool bAddSeparator
= false;
2140 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2142 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2143 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2146 if (GetSelectedCount() == 2)
2148 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2149 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2151 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2153 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2154 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2155 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2157 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("..") + firstSelHash
));
2158 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2159 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("...") + firstSelHash
));
2160 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2163 bAddSeparator
= true;
2168 bAddSeparator
= true;
2171 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2172 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2175 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2178 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2180 bool bAddSeparator
= false;
2181 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2183 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2187 headindex
= this->GetHeadIndex();
2188 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2190 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2192 if (g_Git
.GetHash(hashFirst
, head
))
2193 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2194 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2196 if (g_Git
.GetHash(hash
, head
))
2197 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2198 GitRevLoglist
* pFirstEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2199 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2200 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2201 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2202 bAddSeparator
= true;
2207 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2208 if (GetSelectedCount() >= 2)
2209 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2211 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2212 bAddSeparator
= true;
2215 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2216 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2217 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2218 bAddSeparator
= true;
2222 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2225 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
2227 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2228 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2231 if (GetSelectedCount() == 1)
2233 bool bAddSeparator
= false;
2234 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2236 // show the push-option only if the log entry has an associated local branch
2237 bool isLocal
= false;
2238 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2240 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2243 if (isLocal
|| showExtendedMenu
)
2245 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2246 bAddSeparator
= true;
2249 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2251 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2252 bAddSeparator
= true;
2256 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2258 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2260 std::vector
<CString
*> branchs
;
2261 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2263 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2264 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2267 if (branchs
.size() == 1)
2269 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2272 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2273 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2274 bAddSeparator
= true;
2276 else if (branchs
.size() > 1)
2278 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2279 submenu
.CreatePopupMenu();
2280 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2282 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2283 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2286 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2287 bAddSeparator
= true;
2290 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2292 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2293 } // GetSelectedCount() == 1
2295 if (GetSelectedCount() != 0)
2297 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2298 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2299 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2300 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2301 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2302 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2305 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2306 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2308 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2309 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2311 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2312 // DialogEnableWindow(IDOK, FALSE);
2313 // SetPromptApp(&theApp);
2315 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2317 // EnableOKButton();
2318 } // if (popup.CreatePopupMenu())
2322 bool CGitLogListBase::IsSelectionContinuous()
2324 if ( GetSelectedCount()==1 )
2326 // if only one revision is selected, the selection is of course
2331 POSITION pos
= GetFirstSelectedItemPosition();
2332 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2335 int itemindex
= GetNextSelectedItem(pos
);
2338 int nextindex
= GetNextSelectedItem(pos
);
2339 if (nextindex
- itemindex
> 1)
2341 bContinuous
= false;
2344 itemindex
= nextindex
;
2350 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2354 POSITION pos
= GetFirstSelectedItemPosition();
2358 sRev
.LoadString(IDS_LOG_REVISION
);
2360 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2362 sDate
.LoadString(IDS_LOG_DATE
);
2364 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2368 CString sLogCopyText
;
2370 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2372 if (toCopy
== ID_COPY_ALL
)
2374 //pLogEntry->GetFiles(this)
2375 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2377 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2378 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2380 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2381 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2384 rename
.Format(from
, (LPCTSTR
)((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2385 sPaths
+= _T(" ") + rename
;
2387 sPaths
+= _T("\r\n");
2390 CString body
= pLogEntry
->GetBody();
2391 body
.Replace(_T("\n"), _T("\r\n"));
2392 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"),
2393 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2394 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2396 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2397 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2399 sClipdata
+= sLogCopyText
;
2401 else if (toCopy
== ID_COPY_MESSAGE
)
2403 CString body
= pLogEntry
->GetBody();
2404 body
.Replace(_T("\n"), _T("\r\n"));
2405 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2407 else if (toCopy
== ID_COPY_SUBJECT
)
2409 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2414 sClipdata
+= _T("\r\n");
2415 sClipdata
+= pLogEntry
->m_CommitHash
;
2420 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2425 void CGitLogListBase::DiffSelectedRevWithPrevious()
2427 if (m_bThreadRunning
)
2430 int FirstSelect
=-1, LastSelect
=-1;
2431 POSITION pos
= GetFirstSelectedItemPosition();
2432 FirstSelect
= GetNextSelectedItem(pos
);
2435 LastSelect
= GetNextSelectedItem(pos
);
2438 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2441 UpdateLogInfoLabel();
2442 int selIndex
= m_LogList
.GetSelectionMark();
2445 int selCount
= m_LogList
.GetSelectedCount();
2449 // Find selected entry in the log list
2450 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2451 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2452 long rev1
= pLogEntry
->Rev
;
2454 CTGitPath path
= m_path
;
2456 // See how many files under the relative root were changed in selected revision
2458 LogChangedPath
* changed
= NULL
;
2459 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2461 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2462 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2469 if (m_path
.IsDirectory() && nChanged
== 1)
2471 // We're looking at the log for a directory and only one file under dir was changed in the revision
2472 // Do diff on that file instead of whole directory
2473 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2476 m_bCancelled
= FALSE
;
2477 DialogEnableWindow(IDOK
, FALSE
);
2478 SetPromptApp(&theApp
);
2479 theApp
.DoWaitCursor(1);
2483 GitDiff
diff(this, m_hWnd
, true);
2484 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2485 diff
.SetHEADPeg(m_LogRevision
);
2486 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2490 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2493 theApp
.DoWaitCursor(-1);
2498 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2500 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2503 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2505 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2507 if (pFindInfo
->lvfi
.psz
== 0)
2510 CString sCmp
= pFindInfo
->lvfi
.psz
;
2512 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2514 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2515 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2516 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2518 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2526 if (sCmp
.Compare(sRev
)==0)
2533 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2535 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2537 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2538 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2539 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2541 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2549 if (sCmp
.Compare(sRev
)==0)
2561 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2565 this->m_arShownList
.SafeRemoveAll();
2567 this->m_logEntries
.ClearAll();
2568 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2571 SetItemCountEx((int)m_logEntries
.size());
2573 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2577 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2578 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2583 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2584 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2596 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2600 m_arShownList
.SafeRemoveAll();
2602 m_logEntries
.ClearAll();
2603 if (m_logEntries
.Fill(hashes
))
2606 SetItemCountEx((int)m_logEntries
.size());
2608 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2612 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2613 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2617 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2618 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2627 int CGitLogListBase::BeginFetchLog()
2631 this->m_arShownList
.SafeRemoveAll();
2633 this->m_logEntries
.ClearAll();
2635 this->m_LogCache
.ClearAllParent();
2637 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2640 if(this->m_Path
.IsEmpty())
2646 mask
= CGit::LOG_INFO_ONLY_HASH
;
2647 if (m_bIncludeBoundaryCommits
)
2648 mask
|= CGit::LOG_INFO_BOUNDARY
;
2649 // if(this->m_bAllBranch)
2650 mask
|= m_ShowMask
;
2654 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2656 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2659 if (m_sRange
.IsEmpty())
2660 m_sRange
= _T("HEAD");
2663 data
.m_From
= m_From
;
2666 #if 0 /* use tortoiegit filter */
2667 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2668 data
.m_Author
= this->m_sFilterText
;
2670 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2671 data
.m_MessageFilter
= this->m_sFilterText
;
2673 data
.m_IsRegex
= m_bFilterWithRegex
;
2676 // follow does not work for directories
2677 if (!path
|| path
->IsDirectory())
2678 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2679 // follow does not work with all branches 8at least in TGit)
2680 if (mask
& CGit::LOG_INFO_FOLLOW
)
2681 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2683 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2685 //this->m_logEntries.ParserFromLog();
2686 if(IsInWorkingThread())
2688 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2692 SetItemCountEx((int)m_logEntries
.size());
2697 [] { git_init(); } ();
2702 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2706 if (!g_Git
.CanParseRev(m_sRange
))
2708 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2711 // if show all branches, pick any ref as dummy entry ref
2713 if (g_Git
.GetRefList(list
))
2714 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2715 if (list
.size() == 0)
2718 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2721 g_Git
.m_critGitDllSec
.Lock();
2723 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2725 g_Git
.m_critGitDllSec
.Unlock();
2731 g_Git
.m_critGitDllSec
.Unlock();
2733 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2736 g_Git
.m_critGitDllSec
.Unlock();
2741 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2743 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2745 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2747 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2749 DiffSelectedRevWithPrevious();
2754 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2761 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2763 // select all entries
2764 for (int i
=0; i
<GetItemCount(); ++i
)
2766 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2772 if (m_hAccel
&& !bSkipAccelerator
)
2774 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2780 //m_tooltips.RelayEvent(pMsg);
2781 return __super::PreTranslateMessage(pMsg
);
2784 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2786 // a double click on an entry in the revision list has happened
2789 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2790 DiffSelectedRevWithPrevious();
2793 int CGitLogListBase::FetchLogAsync(void * data
)
2797 m_bExitThread
=FALSE
;
2798 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2799 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2800 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2801 if (m_LoadingThread
==NULL
)
2803 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2804 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2805 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2811 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2813 return ((CGitLogListBase
*)pVoid
)->LogThread();
2816 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2819 oldest
=CTime::GetCurrentTime();
2820 latest
=CTime(1971,1,2,0,0,0);
2821 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2823 if(m_logEntries
[i
].IsEmpty())
2826 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2827 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2829 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2830 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2838 UINT
CGitLogListBase::LogThread()
2840 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2842 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2843 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2849 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2850 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2855 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2856 bool bRegex
= false;
2857 if (m_bFilterWithRegex
)
2858 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2860 TRACE(_T("\n===Begin===\n"));
2861 //Update work copy item;
2863 if (!m_logEntries
.empty())
2865 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2867 m_arShownList
.SafeAdd(pRev
);
2871 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2873 // store commit number of the last selected commit/line before the refresh or -1
2874 int lastSelectedHashNItem
= -1;
2875 if (m_lastSelectedHash
.IsEmpty())
2876 lastSelectedHashNItem
= 0;
2880 bool shouldWalk
= true;
2881 if (!g_Git
.CanParseRev(m_sRange
))
2883 // walk revisions if show all branches and there exists any ref
2884 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2889 if (g_Git
.GetRefList(list
))
2890 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2891 if (list
.size() == 0)
2898 g_Git
.m_critGitDllSec
.Lock();
2902 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2903 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2908 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2911 g_Git
.m_critGitDllSec
.Unlock();
2914 t2
=t1
=GetTickCount();
2915 int oldprecentage
= 0;
2916 size_t oldsize
= m_logEntries
.size();
2917 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2918 while (ret
== 0 && !m_bExitThread
)
2920 g_Git
.m_critGitDllSec
.Lock();
2923 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2927 g_Git
.m_critGitDllSec
.Unlock();
2929 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2932 g_Git
.m_critGitDllSec
.Unlock();
2936 if (ret
!= -2) // other than end of revision walking
2937 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2941 if (commit
.m_ignore
== 1)
2943 git_free_commit(&commit
);
2947 //printf("%s\r\n",commit.GetSubject());
2951 CGitHash hash
= (char*)commit
.m_hash
;
2953 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2954 pRev
->m_GitCommit
= commit
;
2955 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2958 g_Git
.m_critGitDllSec
.Lock();
2961 git_get_notes(commit
.m_hash
, ¬e
);
2965 g_Git
.m_critGitDllSec
.Unlock();
2967 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2970 g_Git
.m_critGitDllSec
.Unlock();
2974 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2979 if(!pRev
->m_IsDiffFiles
)
2981 pRev
->m_CallDiffAsync
= DiffAsync
;
2984 pRev
->ParserParentFromCommit(&commit
);
2985 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2987 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2989 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2990 auto it
= commitChildren
.find(parentHash
);
2991 if (it
== commitChildren
.end())
2993 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2995 it
->second
.insert(pRev
->m_CommitHash
);
3004 bool visible
= true;
3005 if (HasFilterText())
3007 if(!IsMatchFilter(bRegex
,pRev
,pat
))
3010 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
3012 this->m_critSec
.Lock();
3013 m_logEntries
.append(hash
, visible
);
3015 m_arShownList
.SafeAdd(pRev
);
3016 this->m_critSec
.Unlock();
3021 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3022 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3026 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3029 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3032 if(percent
< GITLOG_START
)
3033 percent
= GITLOG_START
+1;
3035 oldsize
= m_logEntries
.size();
3036 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3038 //if( percent > oldprecentage )
3040 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3041 oldprecentage
= percent
;
3044 if (lastSelectedHashNItem
>= 0)
3045 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3050 g_Git
.m_critGitDllSec
.Lock();
3051 git_close_log(m_DllGitLog
);
3052 g_Git
.m_critGitDllSec
.Unlock();
3058 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3063 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3065 if (lastSelectedHashNItem
>= 0)
3066 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3069 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3071 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3076 void CGitLogListBase::FetchRemoteList()
3078 STRING_VECTOR remoteList
;
3079 if (!g_Git
.GetRemoteList(remoteList
))
3080 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3082 m_SingleRemote
= _T("");
3085 void CGitLogListBase::FetchTrackingBranchList()
3087 m_TrackingMap
.clear();
3088 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3090 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3093 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3095 CString pullRemote
, pullBranch
;
3096 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3097 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3099 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3106 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3108 SafeTerminateThread();
3110 this->SetItemCountEx(0);
3115 // HACK to hide graph column
3116 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3117 SetColumnWidth(0, 0);
3119 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3121 //Update branch and Tag info
3124 m_pFindDialog
->RefreshList();
3125 //Assume Thread have exited
3126 //if(!m_bThreadRunning)
3128 m_logEntries
.clear();
3132 m_sFilterText
.Empty();
3137 InterlockedExchange(&m_bExitThread
,FALSE
);
3139 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3140 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3141 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3143 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3144 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3145 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3149 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3153 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3155 type
|= std::tr1::regex_constants::icase
;
3156 pat
= std::tr1::wregex(regexp_str
, type
);
3159 catch (std::exception
) {}
3162 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3165 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3168 if ((bRegex
)&&(m_bFilterWithRegex
))
3170 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3172 if(this->m_bShowBugtraqColumn
)
3174 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3176 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)sBugIds
);
3177 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3184 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3186 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetSubject());
3187 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3193 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3195 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetBody());
3196 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3202 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3204 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3209 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3215 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3217 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3222 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3228 if (m_SelectedFilters
& LOGFILTER_REVS
)
3230 sRev
= pRev
->m_CommitHash
.ToString();
3231 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3237 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3239 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3240 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3242 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3249 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3251 CTGitPathList
*pathList
=NULL
;
3252 if( pRev
->m_IsDiffFiles
)
3253 pathList
= &pRev
->GetFiles(this);
3256 if(!pRev
->m_IsSimpleListReady
)
3257 pRev
->SafeGetSimpleList(&g_Git
);
3261 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3263 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3267 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3273 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3275 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3284 CString find
= m_sFilterText
;
3285 if (!m_bFilterCaseSensitively
)
3287 result
= find
[0] == '!' ? FALSE
: TRUE
;
3291 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3293 if(this->m_bShowBugtraqColumn
)
3295 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3297 if (!m_bFilterCaseSensitively
)
3298 sBugIds
.MakeLower();
3299 if ((sBugIds
.Find(find
) >= 0))
3306 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3308 CString msg
= pRev
->GetSubject();
3310 if (!m_bFilterCaseSensitively
)
3311 msg
= msg
.MakeLower();
3312 if ((msg
.Find(find
) >= 0))
3318 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3320 CString msg
= pRev
->GetBody();
3322 if (!m_bFilterCaseSensitively
)
3323 msg
= msg
.MakeLower();
3324 if ((msg
.Find(find
) >= 0))
3330 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3332 CString msg
= pRev
->GetAuthorName();
3333 if (!m_bFilterCaseSensitively
)
3334 msg
= msg
.MakeLower();
3335 if ((msg
.Find(find
) >= 0))
3341 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3343 CString msg
= pRev
->GetAuthorEmail();
3344 if (!m_bFilterCaseSensitively
)
3345 msg
= msg
.MakeLower();
3346 if ((msg
.Find(find
) >= 0))
3352 if (m_SelectedFilters
& LOGFILTER_REVS
)
3354 sRev
= pRev
->m_CommitHash
.ToString();
3355 if ((sRev
.Find(find
) >= 0))
3361 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3363 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3364 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3366 if (it
->Find(find
) >= 0)
3373 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3375 CTGitPathList
*pathList
=NULL
;
3376 if( pRev
->m_IsDiffFiles
)
3377 pathList
= &pRev
->GetFiles(this);
3380 if(!pRev
->m_IsSimpleListReady
)
3381 pRev
->SafeGetSimpleList(&g_Git
);
3384 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3386 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3387 CString path
= cpath
->GetGitOldPathString();
3388 if (!m_bFilterCaseSensitively
)
3390 if ((path
.Find(find
)>=0))
3394 path
= cpath
->GetGitPathString();
3395 if (!m_bFilterCaseSensitively
)
3397 if ((path
.Find(find
)>=0))
3403 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3405 CString path
= pRev
->m_SimpleFileList
[i
];
3406 if (!m_bFilterCaseSensitively
)
3408 if ((path
.Find(find
)>=0))
3414 } // else (from if (bRegex))
3418 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3420 return str
.Left(prefix
.GetLength()) == prefix
;
3422 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
)
3424 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3427 if (m_ShowFilter
& FILTERSHOW_REFS
)
3430 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3431 for (size_t i
= 0; i
< refList
.size(); ++i
)
3433 const CString
&str
= refList
[i
];
3434 if (CStringStartsWith(str
, _T("refs/heads/")))
3436 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3439 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3441 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3444 else if (CStringStartsWith(str
, _T("refs/tags/")))
3446 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3449 else if (CStringStartsWith(str
, _T("refs/stash")))
3451 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3454 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3456 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3460 // Keep the head too.
3461 if (pRev
->m_CommitHash
== m_HeadHash
)
3465 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3467 if (pRev
->ParentsCount() > 1)
3469 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3470 if (childrenIt
!= commitChildren
.end())
3472 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3473 if (children
.size() > 1)
3480 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3482 // HACK to hide graph column
3484 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3486 SetColumnWidth(0, 0);
3489 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3494 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3496 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3497 for (size_t i
= 0; i
< vector
.size(); ++i
)
3499 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3501 CString tag
= vector
[i
];
3502 int start
= vector
[i
].Find(_T("^{}"));
3504 tag
= tag
.Left(start
);
3508 cmd
.Format(_T("git.exe cat-file tag %s"), (LPCTSTR
)tag
);
3509 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3510 output
.AppendChar(_T('\n'));
3518 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3521 pShownlist
->SafeRemoveAll();
3523 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3524 bool bRegex
= false;
3525 if (m_bFilterWithRegex
)
3526 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3528 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3530 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3532 if ((bRegex
)&&(m_bFilterWithRegex
))
3535 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3537 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3538 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3540 pShownlist
->SafeAdd(m_logEntries
[i
]);
3545 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3547 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3548 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3550 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3554 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3556 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3557 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3559 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3563 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3565 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3568 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3570 CTGitPath cpath
= pathList
[cpPathIndex
];
3571 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3573 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3577 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3579 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3583 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3585 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3591 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3593 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3595 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3599 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3601 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3603 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3607 if (m_SelectedFilters
& LOGFILTER_REVS
)
3609 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3610 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3612 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3616 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3618 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3619 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3621 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3623 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3631 CString find
= m_sFilterText
;
3632 if (!m_bFilterCaseSensitively
)
3635 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3637 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3639 if (!m_bFilterCaseSensitively
)
3640 sBugIDs
= sBugIDs
.MakeLower();
3641 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3643 pShownlist
->SafeAdd(m_logEntries
[i
]);
3648 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3650 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3652 if (!m_bFilterCaseSensitively
)
3653 msg
= msg
.MakeLower();
3654 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3656 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3660 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3662 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3664 if (!m_bFilterCaseSensitively
)
3665 msg
= msg
.MakeLower();
3666 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3668 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3672 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3674 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3677 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3679 CTGitPath cpath
= pathList
[cpPathIndex
];
3680 CString path
= cpath
.GetGitOldPathString();
3681 if (!m_bFilterCaseSensitively
)
3683 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3685 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3689 path
= cpath
.GetGitPathString();
3690 if (!m_bFilterCaseSensitively
)
3692 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3694 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3698 path
= cpath
.GetActionName();
3699 if (!m_bFilterCaseSensitively
)
3701 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3703 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3709 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3711 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3712 if (!m_bFilterCaseSensitively
)
3713 msg
= msg
.MakeLower();
3714 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3716 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3720 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3722 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3723 if (!m_bFilterCaseSensitively
)
3724 msg
= msg
.MakeLower();
3725 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3727 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3731 if (m_SelectedFilters
& LOGFILTER_REVS
)
3733 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3734 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3736 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3740 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3742 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3743 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3745 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3747 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3752 } // else (from if (bRegex))
3753 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3757 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3760 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3766 return time <= m_To;
3769 return time >= m_From;
3771 return ((time >= m_From)&&(time <= m_To));
3773 return TRUE
; /* git dll will filter time range */
3777 void CGitLogListBase::StartFilter()
3779 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3780 RecalculateShownList(&m_arShownList
);
3781 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3785 SetItemCountEx(ShownCountWithStopped());
3786 RedrawItems(0, ShownCountWithStopped());
3790 void CGitLogListBase::RemoveFilter()
3793 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3795 m_arShownList
.SafeRemoveAll();
3797 // reset the time filter too
3799 m_timFrom
= (__time64_t(m_tFrom
));
3800 m_timTo
= (__time64_t(m_tTo
));
3801 m_DateFrom
.SetTime(&m_timFrom
);
3802 m_DateTo
.SetTime(&m_timTo
);
3803 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3804 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3807 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3809 if(this->m_IsOldFirst
)
3811 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3815 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3818 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3820 SetItemCountEx(ShownCountWithStopped());
3821 RedrawItems(0, ShownCountWithStopped());
3823 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3826 void CGitLogListBase::Clear()
3828 m_arShownList
.SafeRemoveAll();
3831 m_logEntries
.ClearAll();
3835 void CGitLogListBase::OnDestroy()
3837 // save the column widths to the registry
3840 SafeTerminateThread();
3841 SafeTerminateAsyncDiffThread();
3844 while(m_LogCache
.SaveCache())
3852 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3853 // MB_YESNO) == IDNO)
3857 CHintListCtrl::OnDestroy();
3860 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3864 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3865 this->InvalidateRect(rect
);
3871 * Save column widths to the registry
3873 void CGitLogListBase::SaveColumnWidths()
3875 int maxcol
= m_ColumnManager
.GetColumnCount();
3877 // HACK that graph column is always shown
3878 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3880 for (int col
= 0; col
< maxcol
; ++col
)
3881 if (m_ColumnManager
.IsVisible (col
))
3882 m_ColumnManager
.ColumnResized (col
);
3884 m_ColumnManager
.WriteSettings();
3887 int CGitLogListBase::GetHeadIndex()
3889 if(m_HeadHash
.IsEmpty())
3892 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3894 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3897 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3903 void CGitLogListBase::OnFind()
3907 m_pFindDialog
= new CFindDlg(this);
3908 m_pFindDialog
->Create(this);
3911 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3913 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3915 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3917 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3920 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3922 if (GetSelectedCount() != 0)
3925 CGitHash theSelectedHash
= m_lastSelectedHash
;
3926 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3927 m_lastSelectedHash
= theSelectedHash
;
3929 int countPerPage
= GetCountPerPage();
3930 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3931 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3932 EnsureVisible((int)itemToSelect
, FALSE
);
3935 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3938 ASSERT(m_pFindDialog
!= NULL
);
3939 bool bFound
= false;
3942 if (m_pFindDialog
->IsTerminating())
3944 // invalidate the handle identifying the dialog box.
3945 m_pFindDialog
= NULL
;
3949 INT_PTR cnt
= m_arShownList
.GetCount();
3951 if(m_pFindDialog
->IsRef())
3954 str
=m_pFindDialog
->GetFindString();
3960 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3961 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3966 for (i
= 0; i
< cnt
; ++i
)
3968 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3969 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3978 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3983 if (m_pFindDialog
->FindNext() && !bFound
)
3985 //read data from dialog
3986 CString findText
= m_pFindDialog
->GetFindString();
3987 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3989 std::tr1::wregex pat
;
3990 bool bRegex
= false;
3991 if (m_pFindDialog
->Regex())
3992 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3994 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3996 for (i
= m_nSearchIndex
+ 1; ; ++i
)
4001 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
4003 if (m_nSearchIndex
>= 0)
4005 if (i
== m_nSearchIndex
)
4007 ::MessageBeep(0xFFFFFFFF);
4008 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4013 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
4016 str
+=pLogEntry
->m_CommitHash
.ToString();
4019 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4021 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4025 str
+=pLogEntry
->GetAuthorEmail();
4027 str
+=pLogEntry
->GetAuthorName();
4029 str
+=pLogEntry
->GetBody();
4031 str
+=pLogEntry
->GetCommitterEmail();
4033 str
+=pLogEntry
->GetCommitterName();
4035 str
+=pLogEntry
->GetSubject();
4037 str
+=pLogEntry
->m_Notes
;
4039 str
+=GetTagInfo(pLogEntry
);
4043 /*Because changed files list is loaded on demand when gui show,
4044 files will empty when files have not fetched.
4046 we can add it back by using one-way diff(with outnumber changed and rename detect.
4047 here just need changed filename list. one-way is much quicker.
4049 if(pLogEntry
->m_IsFull
)
4051 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4053 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4055 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4061 if(!pLogEntry
->m_IsSimpleListReady
)
4062 pLogEntry
->SafeGetSimpleList(&g_Git
);
4064 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4066 str
+= pLogEntry
->m_SimpleFileList
[j
];
4075 if (std::regex_search(std::wstring(str
), pat
, flags
))
4085 if (str
.Find(findText
) >= 0)
4095 msg
= msg
.MakeLower();
4096 CString find
= findText
.MakeLower();
4097 if (msg
.Find(find
) >= 0)
4104 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4106 } // if(m_pFindDialog->FindNext())
4107 //UpdateLogInfoLabel();
4112 EnsureVisible(i
, FALSE
);
4113 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4115 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4116 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4117 SetSelectionMark(i
);
4121 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4123 m_highlight
= pLogEntry
->m_CommitHash
;
4126 //FillLogMessageCtrl();
4133 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4135 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4140 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4142 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4147 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4149 LVHITTESTINFO lvhitTestInfo
;
4151 lvhitTestInfo
.pt
= point
;
4153 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4154 int nSubItem
= lvhitTestInfo
.iSubItem
;
4156 UINT nFlags
= lvhitTestInfo
.flags
;
4158 // nFlags is 0 if the SubItemHitTest fails
4159 // Therefore, 0 & <anything> will equal false
4160 if (nFlags
& LVHT_ONITEM
)
4162 // Get the client area occupied by this control
4164 GetClientRect(&rcClient
);
4166 // Fill in the TOOLINFO structure
4168 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4169 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4170 pTI
->rect
= rcClient
;
4172 return pTI
->uId
; // By returning a unique value per listItem,
4173 // we ensure that when the mouse moves over another list item,
4174 // the tooltip will change
4178 // Otherwise, we aren't interested, so let the message propagate
4183 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4185 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4186 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4190 // Ignore messages from the built in tooltip, we are processing them internally
4191 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4192 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4193 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4196 // Get the mouse position
4197 const MSG
* pMessage
= GetCurrentMessage();
4201 ScreenToClient(&pt
);
4203 // Check if the point falls onto a list item
4204 LVHITTESTINFO lvhitTestInfo
;
4205 lvhitTestInfo
.pt
= pt
;
4207 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4209 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4211 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4212 if (strTipText
.IsEmpty())
4215 // we want multiline tooltips
4216 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4218 wcscpy_s(m_wszTip
, strTipText
);
4219 // handle Unicode as well as non-Unicode requests
4220 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4222 pTTTA
->hinst
= nullptr;
4223 pTTTA
->lpszText
= m_szTip
;
4224 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4228 pTTTW
->hinst
= nullptr;
4229 pTTTW
->lpszText
= m_wszTip
;
4233 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4234 ClientToScreen(rect
);
4235 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4237 return TRUE
; // We found a tool tip,
4238 // tell the framework this message has been handled
4241 return FALSE
; // We didn't handle the message,
4242 // let the framework continue propagating the message
4245 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4247 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4249 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4250 if (pLogEntry
== nullptr)
4252 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4254 return pLogEntry
->GetSubject();
4256 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4258 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4259 if (pLogEntry
== nullptr)
4261 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4263 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4265 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4266 if (pLogEntry
== nullptr)
4268 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4270 else if (nSubItem
== LOGLIST_ACTION
)
4272 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4273 if (pLogEntry
== nullptr)
4276 if (!pLogEntry
->m_IsDiffFiles
)
4277 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4279 int actions
= pLogEntry
->GetAction(this);
4280 CString sToolTipText
;
4283 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4284 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4286 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4288 if (!actionText
.IsEmpty())
4289 actionText
+= L
"\r\n";
4290 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4293 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4295 if (!actionText
.IsEmpty())
4296 actionText
+= L
"\r\n";
4297 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4300 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4302 if (!actionText
.IsEmpty())
4303 actionText
+= L
"\r\n";
4304 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4307 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4309 if (!actionText
.IsEmpty())
4310 actionText
+= L
"\r\n";
4311 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4314 if (!actionText
.IsEmpty())
4316 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4317 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4319 return sToolTipText
;