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 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
2030 str
.Format(format
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2032 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2033 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2035 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
2036 str
.Format(format
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2038 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2039 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2042 // Add Switch Branch express Menu
2043 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2044 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2047 std::vector
<CString
*> branchs
;
2048 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2050 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2051 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2053 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2058 str2
.LoadString(IDS_SWITCH_BRANCH
);
2060 if(branchs
.size() == 1)
2063 str2
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2064 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2066 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2069 else if(branchs
.size() > 1)
2071 subbranchmenu
.CreatePopupMenu();
2072 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2074 if (*branchs
[i
] != currentBranch
)
2076 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2077 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2081 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2085 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2086 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2088 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2089 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2091 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2092 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2094 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
2095 str
.Format(format
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2097 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2098 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2099 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2101 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2102 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2104 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2106 if (parentHash
.size() == 1)
2108 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2110 else if (parentHash
.size() > 1)
2112 revertmenu
.CreatePopupMenu();
2113 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2115 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2118 str2
.Format(IDS_PARENT
, i
+ 1);
2119 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2124 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2125 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2127 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2132 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2134 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2135 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2136 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2137 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2140 if (GetSelectedCount() >= 2)
2142 bool bAddSeparator
= false;
2143 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2145 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2146 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2149 if (GetSelectedCount() == 2)
2151 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2152 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2154 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2156 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2157 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2158 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2160 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("..") + firstSelHash
));
2161 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2162 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("...") + firstSelHash
));
2163 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2166 bAddSeparator
= true;
2171 bAddSeparator
= true;
2174 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2175 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2178 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2181 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2183 bool bAddSeparator
= false;
2184 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2186 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2190 headindex
= this->GetHeadIndex();
2191 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2193 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2195 if (g_Git
.GetHash(hashFirst
, head
))
2196 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2197 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2199 if (g_Git
.GetHash(hash
, head
))
2200 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2201 GitRevLoglist
* pFirstEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2202 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2203 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2204 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2205 bAddSeparator
= true;
2210 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2211 if (GetSelectedCount() >= 2)
2212 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2214 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2215 bAddSeparator
= true;
2218 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2219 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2220 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2221 bAddSeparator
= true;
2225 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2228 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())
2230 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2231 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2234 if (GetSelectedCount() == 1)
2236 bool bAddSeparator
= false;
2237 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2239 // show the push-option only if the log entry has an associated local branch
2240 bool isLocal
= false;
2241 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2243 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2246 if (isLocal
|| showExtendedMenu
)
2248 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2249 bAddSeparator
= true;
2252 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2254 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2255 bAddSeparator
= true;
2259 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2261 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2263 std::vector
<CString
*> branchs
;
2264 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2266 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2267 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2270 if (branchs
.size() == 1)
2272 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2275 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2276 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2277 bAddSeparator
= true;
2279 else if (branchs
.size() > 1)
2281 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2282 submenu
.CreatePopupMenu();
2283 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2285 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2286 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2289 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2290 bAddSeparator
= true;
2293 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2295 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2296 } // GetSelectedCount() == 1
2298 if (GetSelectedCount() != 0)
2300 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2301 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2302 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2303 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2304 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2305 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2308 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2309 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2311 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2312 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2314 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2315 // DialogEnableWindow(IDOK, FALSE);
2316 // SetPromptApp(&theApp);
2318 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2320 // EnableOKButton();
2321 } // if (popup.CreatePopupMenu())
2325 bool CGitLogListBase::IsSelectionContinuous()
2327 if ( GetSelectedCount()==1 )
2329 // if only one revision is selected, the selection is of course
2334 POSITION pos
= GetFirstSelectedItemPosition();
2335 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2338 int itemindex
= GetNextSelectedItem(pos
);
2341 int nextindex
= GetNextSelectedItem(pos
);
2342 if (nextindex
- itemindex
> 1)
2344 bContinuous
= false;
2347 itemindex
= nextindex
;
2353 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2357 POSITION pos
= GetFirstSelectedItemPosition();
2361 sRev
.LoadString(IDS_LOG_REVISION
);
2363 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2365 sDate
.LoadString(IDS_LOG_DATE
);
2367 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2371 CString sLogCopyText
;
2373 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2375 if (toCopy
== ID_COPY_ALL
)
2377 //pLogEntry->GetFiles(this)
2378 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2380 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2381 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2383 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2384 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2387 rename
.Format(from
, (LPCTSTR
)((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2388 sPaths
+= _T(" ") + rename
;
2390 sPaths
+= _T("\r\n");
2393 CString body
= pLogEntry
->GetBody();
2394 body
.Replace(_T("\n"), _T("\r\n"));
2395 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"),
2396 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2397 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2399 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2400 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2402 sClipdata
+= sLogCopyText
;
2404 else if (toCopy
== ID_COPY_MESSAGE
)
2406 CString body
= pLogEntry
->GetBody();
2407 body
.Replace(_T("\n"), _T("\r\n"));
2408 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2410 else if (toCopy
== ID_COPY_SUBJECT
)
2412 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2417 sClipdata
+= _T("\r\n");
2418 sClipdata
+= pLogEntry
->m_CommitHash
;
2423 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2428 void CGitLogListBase::DiffSelectedRevWithPrevious()
2430 if (m_bThreadRunning
)
2433 int FirstSelect
=-1, LastSelect
=-1;
2434 POSITION pos
= GetFirstSelectedItemPosition();
2435 FirstSelect
= GetNextSelectedItem(pos
);
2438 LastSelect
= GetNextSelectedItem(pos
);
2441 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2444 UpdateLogInfoLabel();
2445 int selIndex
= m_LogList
.GetSelectionMark();
2448 int selCount
= m_LogList
.GetSelectedCount();
2452 // Find selected entry in the log list
2453 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2454 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2455 long rev1
= pLogEntry
->Rev
;
2457 CTGitPath path
= m_path
;
2459 // See how many files under the relative root were changed in selected revision
2461 LogChangedPath
* changed
= NULL
;
2462 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2464 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2465 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2472 if (m_path
.IsDirectory() && nChanged
== 1)
2474 // We're looking at the log for a directory and only one file under dir was changed in the revision
2475 // Do diff on that file instead of whole directory
2476 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2479 m_bCancelled
= FALSE
;
2480 DialogEnableWindow(IDOK
, FALSE
);
2481 SetPromptApp(&theApp
);
2482 theApp
.DoWaitCursor(1);
2486 GitDiff
diff(this, m_hWnd
, true);
2487 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2488 diff
.SetHEADPeg(m_LogRevision
);
2489 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2493 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2496 theApp
.DoWaitCursor(-1);
2501 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2503 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2506 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2508 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2510 if (pFindInfo
->lvfi
.psz
== 0)
2513 CString sCmp
= pFindInfo
->lvfi
.psz
;
2515 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2517 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2518 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2519 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2521 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2529 if (sCmp
.Compare(sRev
)==0)
2536 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2538 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2540 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2541 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2542 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2544 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2552 if (sCmp
.Compare(sRev
)==0)
2564 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2568 this->m_arShownList
.SafeRemoveAll();
2570 this->m_logEntries
.ClearAll();
2571 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2574 SetItemCountEx((int)m_logEntries
.size());
2576 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2580 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2581 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2586 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2587 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2599 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2603 m_arShownList
.SafeRemoveAll();
2605 m_logEntries
.ClearAll();
2606 if (m_logEntries
.Fill(hashes
))
2609 SetItemCountEx((int)m_logEntries
.size());
2611 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2615 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2616 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2620 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2621 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2630 int CGitLogListBase::BeginFetchLog()
2634 this->m_arShownList
.SafeRemoveAll();
2636 this->m_logEntries
.ClearAll();
2638 this->m_LogCache
.ClearAllParent();
2640 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2643 if(this->m_Path
.IsEmpty())
2649 mask
= CGit::LOG_INFO_ONLY_HASH
;
2650 if (m_bIncludeBoundaryCommits
)
2651 mask
|= CGit::LOG_INFO_BOUNDARY
;
2652 // if(this->m_bAllBranch)
2653 mask
|= m_ShowMask
;
2657 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2659 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2662 if (m_sRange
.IsEmpty())
2663 m_sRange
= _T("HEAD");
2666 data
.m_From
= m_From
;
2669 #if 0 /* use tortoiegit filter */
2670 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2671 data
.m_Author
= this->m_sFilterText
;
2673 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2674 data
.m_MessageFilter
= this->m_sFilterText
;
2676 data
.m_IsRegex
= m_bFilterWithRegex
;
2679 // follow does not work for directories
2680 if (!path
|| path
->IsDirectory())
2681 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2682 // follow does not work with all branches 8at least in TGit)
2683 if (mask
& CGit::LOG_INFO_FOLLOW
)
2684 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2686 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2688 //this->m_logEntries.ParserFromLog();
2689 if(IsInWorkingThread())
2691 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2695 SetItemCountEx((int)m_logEntries
.size());
2700 [] { git_init(); } ();
2705 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2709 if (!g_Git
.CanParseRev(m_sRange
))
2711 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2714 // if show all branches, pick any ref as dummy entry ref
2716 if (g_Git
.GetRefList(list
))
2717 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2718 if (list
.size() == 0)
2721 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2724 g_Git
.m_critGitDllSec
.Lock();
2726 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2728 g_Git
.m_critGitDllSec
.Unlock();
2734 g_Git
.m_critGitDllSec
.Unlock();
2736 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2739 g_Git
.m_critGitDllSec
.Unlock();
2744 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2746 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2748 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2750 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2752 DiffSelectedRevWithPrevious();
2757 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2764 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2766 // select all entries
2767 for (int i
=0; i
<GetItemCount(); ++i
)
2769 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2775 if (m_hAccel
&& !bSkipAccelerator
)
2777 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2783 //m_tooltips.RelayEvent(pMsg);
2784 return __super::PreTranslateMessage(pMsg
);
2787 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2789 // a double click on an entry in the revision list has happened
2792 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2793 DiffSelectedRevWithPrevious();
2796 int CGitLogListBase::FetchLogAsync(void * data
)
2800 m_bExitThread
=FALSE
;
2801 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2802 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2803 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2804 if (m_LoadingThread
==NULL
)
2806 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2807 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2808 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2814 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2816 return ((CGitLogListBase
*)pVoid
)->LogThread();
2819 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2822 oldest
=CTime::GetCurrentTime();
2823 latest
=CTime(1971,1,2,0,0,0);
2824 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2826 if(m_logEntries
[i
].IsEmpty())
2829 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2830 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2832 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2833 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2841 UINT
CGitLogListBase::LogThread()
2843 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2845 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2846 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2852 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2853 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2858 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2859 bool bRegex
= false;
2860 if (m_bFilterWithRegex
)
2861 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2863 TRACE(_T("\n===Begin===\n"));
2864 //Update work copy item;
2866 if (!m_logEntries
.empty())
2868 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2870 m_arShownList
.SafeAdd(pRev
);
2874 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2876 // store commit number of the last selected commit/line before the refresh or -1
2877 int lastSelectedHashNItem
= -1;
2878 if (m_lastSelectedHash
.IsEmpty())
2879 lastSelectedHashNItem
= 0;
2883 bool shouldWalk
= true;
2884 if (!g_Git
.CanParseRev(m_sRange
))
2886 // walk revisions if show all branches and there exists any ref
2887 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2892 if (g_Git
.GetRefList(list
))
2893 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2894 if (list
.size() == 0)
2901 g_Git
.m_critGitDllSec
.Lock();
2905 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2906 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2911 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2914 g_Git
.m_critGitDllSec
.Unlock();
2917 t2
=t1
=GetTickCount();
2918 int oldprecentage
= 0;
2919 size_t oldsize
= m_logEntries
.size();
2920 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2921 while (ret
== 0 && !m_bExitThread
)
2923 g_Git
.m_critGitDllSec
.Lock();
2926 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2930 g_Git
.m_critGitDllSec
.Unlock();
2932 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2935 g_Git
.m_critGitDllSec
.Unlock();
2939 if (ret
!= -2) // other than end of revision walking
2940 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2944 if (commit
.m_ignore
== 1)
2946 git_free_commit(&commit
);
2950 //printf("%s\r\n",commit.GetSubject());
2954 CGitHash hash
= (char*)commit
.m_hash
;
2956 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2957 pRev
->m_GitCommit
= commit
;
2958 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2961 g_Git
.m_critGitDllSec
.Lock();
2964 git_get_notes(commit
.m_hash
, ¬e
);
2968 g_Git
.m_critGitDllSec
.Unlock();
2970 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2973 g_Git
.m_critGitDllSec
.Unlock();
2977 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2982 if(!pRev
->m_IsDiffFiles
)
2984 pRev
->m_CallDiffAsync
= DiffAsync
;
2987 pRev
->ParserParentFromCommit(&commit
);
2988 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2990 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2992 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2993 auto it
= commitChildren
.find(parentHash
);
2994 if (it
== commitChildren
.end())
2996 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2998 it
->second
.insert(pRev
->m_CommitHash
);
3007 bool visible
= true;
3008 if (HasFilterText())
3010 if(!IsMatchFilter(bRegex
,pRev
,pat
))
3013 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
3015 this->m_critSec
.Lock();
3016 m_logEntries
.append(hash
, visible
);
3018 m_arShownList
.SafeAdd(pRev
);
3019 this->m_critSec
.Unlock();
3024 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3025 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3029 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3032 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3035 if(percent
< GITLOG_START
)
3036 percent
= GITLOG_START
+1;
3038 oldsize
= m_logEntries
.size();
3039 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3041 //if( percent > oldprecentage )
3043 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3044 oldprecentage
= percent
;
3047 if (lastSelectedHashNItem
>= 0)
3048 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3053 g_Git
.m_critGitDllSec
.Lock();
3054 git_close_log(m_DllGitLog
);
3055 g_Git
.m_critGitDllSec
.Unlock();
3061 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3066 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3068 if (lastSelectedHashNItem
>= 0)
3069 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3072 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3074 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3079 void CGitLogListBase::FetchRemoteList()
3081 STRING_VECTOR remoteList
;
3082 if (!g_Git
.GetRemoteList(remoteList
))
3083 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3085 m_SingleRemote
= _T("");
3088 void CGitLogListBase::FetchTrackingBranchList()
3090 m_TrackingMap
.clear();
3091 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3093 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3096 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3098 CString pullRemote
, pullBranch
;
3099 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3100 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3102 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3109 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3111 SafeTerminateThread();
3113 this->SetItemCountEx(0);
3118 // HACK to hide graph column
3119 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3120 SetColumnWidth(0, 0);
3122 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3124 //Update branch and Tag info
3127 m_pFindDialog
->RefreshList();
3128 //Assume Thread have exited
3129 //if(!m_bThreadRunning)
3131 m_logEntries
.clear();
3135 m_sFilterText
.Empty();
3140 InterlockedExchange(&m_bExitThread
,FALSE
);
3142 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3143 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3144 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3146 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3147 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3148 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3152 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3156 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3158 type
|= std::tr1::regex_constants::icase
;
3159 pat
= std::tr1::wregex(regexp_str
, type
);
3162 catch (std::exception
) {}
3165 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3168 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3171 if ((bRegex
)&&(m_bFilterWithRegex
))
3173 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3175 if(this->m_bShowBugtraqColumn
)
3177 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3179 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)sBugIds
);
3180 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3187 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3189 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetSubject());
3190 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3196 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3198 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetBody());
3199 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3205 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3207 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3212 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3218 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3220 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3225 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3231 if (m_SelectedFilters
& LOGFILTER_REVS
)
3233 sRev
.Format(_T("%s"), (LPCTSTR
)pRev
->m_CommitHash
.ToString());
3234 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3240 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3242 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3243 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3245 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3252 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3254 CTGitPathList
*pathList
=NULL
;
3255 if( pRev
->m_IsDiffFiles
)
3256 pathList
= &pRev
->GetFiles(this);
3259 if(!pRev
->m_IsSimpleListReady
)
3260 pRev
->SafeGetSimpleList(&g_Git
);
3264 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3266 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3270 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3276 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3278 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3287 CString find
= m_sFilterText
;
3288 if (!m_bFilterCaseSensitively
)
3290 result
= find
[0] == '!' ? FALSE
: TRUE
;
3294 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3296 if(this->m_bShowBugtraqColumn
)
3298 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3300 if (!m_bFilterCaseSensitively
)
3301 sBugIds
.MakeLower();
3302 if ((sBugIds
.Find(find
) >= 0))
3309 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3311 CString msg
= pRev
->GetSubject();
3313 if (!m_bFilterCaseSensitively
)
3314 msg
= msg
.MakeLower();
3315 if ((msg
.Find(find
) >= 0))
3321 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3323 CString msg
= pRev
->GetBody();
3325 if (!m_bFilterCaseSensitively
)
3326 msg
= msg
.MakeLower();
3327 if ((msg
.Find(find
) >= 0))
3333 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3335 CString msg
= pRev
->GetAuthorName();
3336 if (!m_bFilterCaseSensitively
)
3337 msg
= msg
.MakeLower();
3338 if ((msg
.Find(find
) >= 0))
3344 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3346 CString msg
= pRev
->GetAuthorEmail();
3347 if (!m_bFilterCaseSensitively
)
3348 msg
= msg
.MakeLower();
3349 if ((msg
.Find(find
) >= 0))
3355 if (m_SelectedFilters
& LOGFILTER_REVS
)
3357 sRev
.Format(_T("%s"), (LPCTSTR
)pRev
->m_CommitHash
.ToString());
3358 if ((sRev
.Find(find
) >= 0))
3364 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3366 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3367 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3369 if (it
->Find(find
) >= 0)
3376 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3378 CTGitPathList
*pathList
=NULL
;
3379 if( pRev
->m_IsDiffFiles
)
3380 pathList
= &pRev
->GetFiles(this);
3383 if(!pRev
->m_IsSimpleListReady
)
3384 pRev
->SafeGetSimpleList(&g_Git
);
3387 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3389 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3390 CString path
= cpath
->GetGitOldPathString();
3391 if (!m_bFilterCaseSensitively
)
3393 if ((path
.Find(find
)>=0))
3397 path
= cpath
->GetGitPathString();
3398 if (!m_bFilterCaseSensitively
)
3400 if ((path
.Find(find
)>=0))
3406 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3408 CString path
= pRev
->m_SimpleFileList
[i
];
3409 if (!m_bFilterCaseSensitively
)
3411 if ((path
.Find(find
)>=0))
3417 } // else (from if (bRegex))
3421 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3423 return str
.Left(prefix
.GetLength()) == prefix
;
3425 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
)
3427 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3430 if (m_ShowFilter
& FILTERSHOW_REFS
)
3433 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3434 for (size_t i
= 0; i
< refList
.size(); ++i
)
3436 const CString
&str
= refList
[i
];
3437 if (CStringStartsWith(str
, _T("refs/heads/")))
3439 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3442 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3444 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3447 else if (CStringStartsWith(str
, _T("refs/tags/")))
3449 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3452 else if (CStringStartsWith(str
, _T("refs/stash")))
3454 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3457 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3459 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3463 // Keep the head too.
3464 if (pRev
->m_CommitHash
== m_HeadHash
)
3468 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3470 if (pRev
->ParentsCount() > 1)
3472 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3473 if (childrenIt
!= commitChildren
.end())
3475 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3476 if (children
.size() > 1)
3483 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3485 // HACK to hide graph column
3487 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3489 SetColumnWidth(0, 0);
3492 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3497 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3499 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3500 for (size_t i
= 0; i
< vector
.size(); ++i
)
3502 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3504 CString tag
= vector
[i
];
3505 int start
= vector
[i
].Find(_T("^{}"));
3507 tag
= tag
.Left(start
);
3511 cmd
.Format(_T("git.exe cat-file tag %s"), (LPCTSTR
)tag
);
3512 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3513 output
.AppendChar(_T('\n'));
3521 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3524 pShownlist
->SafeRemoveAll();
3526 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3527 bool bRegex
= false;
3528 if (m_bFilterWithRegex
)
3529 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3531 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3533 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3535 if ((bRegex
)&&(m_bFilterWithRegex
))
3538 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3540 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3541 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3543 pShownlist
->SafeAdd(m_logEntries
[i
]);
3548 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3550 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3551 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3553 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3557 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3559 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3560 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3562 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3566 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3568 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3571 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3573 CTGitPath cpath
= pathList
[cpPathIndex
];
3574 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3576 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3580 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3582 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3586 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3588 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3594 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3596 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3598 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3602 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3604 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3606 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3610 if (m_SelectedFilters
& LOGFILTER_REVS
)
3612 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3613 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3615 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3619 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3621 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3622 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3624 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3626 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3634 CString find
= m_sFilterText
;
3635 if (!m_bFilterCaseSensitively
)
3638 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3640 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3642 if (!m_bFilterCaseSensitively
)
3643 sBugIDs
= sBugIDs
.MakeLower();
3644 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3646 pShownlist
->SafeAdd(m_logEntries
[i
]);
3651 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3653 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3655 if (!m_bFilterCaseSensitively
)
3656 msg
= msg
.MakeLower();
3657 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3659 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3663 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3665 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3667 if (!m_bFilterCaseSensitively
)
3668 msg
= msg
.MakeLower();
3669 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3671 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3675 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3677 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3680 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3682 CTGitPath cpath
= pathList
[cpPathIndex
];
3683 CString path
= cpath
.GetGitOldPathString();
3684 if (!m_bFilterCaseSensitively
)
3686 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3688 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3692 path
= cpath
.GetGitPathString();
3693 if (!m_bFilterCaseSensitively
)
3695 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3697 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3701 path
= cpath
.GetActionName();
3702 if (!m_bFilterCaseSensitively
)
3704 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3706 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3712 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3714 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3715 if (!m_bFilterCaseSensitively
)
3716 msg
= msg
.MakeLower();
3717 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3719 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3723 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3725 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3726 if (!m_bFilterCaseSensitively
)
3727 msg
= msg
.MakeLower();
3728 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3730 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3734 if (m_SelectedFilters
& LOGFILTER_REVS
)
3736 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3737 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3739 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3743 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3745 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3746 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3748 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3750 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3755 } // else (from if (bRegex))
3756 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3760 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3763 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3769 return time <= m_To;
3772 return time >= m_From;
3774 return ((time >= m_From)&&(time <= m_To));
3776 return TRUE
; /* git dll will filter time range */
3780 void CGitLogListBase::StartFilter()
3782 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3783 RecalculateShownList(&m_arShownList
);
3784 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3788 SetItemCountEx(ShownCountWithStopped());
3789 RedrawItems(0, ShownCountWithStopped());
3793 void CGitLogListBase::RemoveFilter()
3796 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3798 m_arShownList
.SafeRemoveAll();
3800 // reset the time filter too
3802 m_timFrom
= (__time64_t(m_tFrom
));
3803 m_timTo
= (__time64_t(m_tTo
));
3804 m_DateFrom
.SetTime(&m_timFrom
);
3805 m_DateTo
.SetTime(&m_timTo
);
3806 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3807 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3810 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3812 if(this->m_IsOldFirst
)
3814 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3818 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3821 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3823 SetItemCountEx(ShownCountWithStopped());
3824 RedrawItems(0, ShownCountWithStopped());
3826 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3829 void CGitLogListBase::Clear()
3831 m_arShownList
.SafeRemoveAll();
3834 m_logEntries
.ClearAll();
3838 void CGitLogListBase::OnDestroy()
3840 // save the column widths to the registry
3843 SafeTerminateThread();
3844 SafeTerminateAsyncDiffThread();
3847 while(m_LogCache
.SaveCache())
3855 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3856 // MB_YESNO) == IDNO)
3860 CHintListCtrl::OnDestroy();
3863 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3867 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3868 this->InvalidateRect(rect
);
3874 * Save column widths to the registry
3876 void CGitLogListBase::SaveColumnWidths()
3878 int maxcol
= m_ColumnManager
.GetColumnCount();
3880 // HACK that graph column is always shown
3881 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3883 for (int col
= 0; col
< maxcol
; ++col
)
3884 if (m_ColumnManager
.IsVisible (col
))
3885 m_ColumnManager
.ColumnResized (col
);
3887 m_ColumnManager
.WriteSettings();
3890 int CGitLogListBase::GetHeadIndex()
3892 if(m_HeadHash
.IsEmpty())
3895 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3897 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3900 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3906 void CGitLogListBase::OnFind()
3910 m_pFindDialog
= new CFindDlg(this);
3911 m_pFindDialog
->Create(this);
3914 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3916 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3918 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3920 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3923 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3925 if (GetSelectedCount() != 0)
3928 CGitHash theSelectedHash
= m_lastSelectedHash
;
3929 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3930 m_lastSelectedHash
= theSelectedHash
;
3932 int countPerPage
= GetCountPerPage();
3933 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3934 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3935 EnsureVisible((int)itemToSelect
, FALSE
);
3938 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3941 ASSERT(m_pFindDialog
!= NULL
);
3942 bool bFound
= false;
3945 if (m_pFindDialog
->IsTerminating())
3947 // invalidate the handle identifying the dialog box.
3948 m_pFindDialog
= NULL
;
3952 INT_PTR cnt
= m_arShownList
.GetCount();
3954 if(m_pFindDialog
->IsRef())
3957 str
=m_pFindDialog
->GetFindString();
3963 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3964 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3969 for (i
= 0; i
< cnt
; ++i
)
3971 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3972 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3981 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3986 if (m_pFindDialog
->FindNext() && !bFound
)
3988 //read data from dialog
3989 CString findText
= m_pFindDialog
->GetFindString();
3990 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3992 std::tr1::wregex pat
;
3993 bool bRegex
= false;
3994 if (m_pFindDialog
->Regex())
3995 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3997 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3999 for (i
= m_nSearchIndex
+ 1; ; ++i
)
4004 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
4006 if (m_nSearchIndex
>= 0)
4008 if (i
== m_nSearchIndex
)
4010 ::MessageBeep(0xFFFFFFFF);
4011 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4016 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
4019 str
+=pLogEntry
->m_CommitHash
.ToString();
4022 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4024 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4028 str
+=pLogEntry
->GetAuthorEmail();
4030 str
+=pLogEntry
->GetAuthorName();
4032 str
+=pLogEntry
->GetBody();
4034 str
+=pLogEntry
->GetCommitterEmail();
4036 str
+=pLogEntry
->GetCommitterName();
4038 str
+=pLogEntry
->GetSubject();
4040 str
+=pLogEntry
->m_Notes
;
4042 str
+=GetTagInfo(pLogEntry
);
4046 /*Because changed files list is loaded on demand when gui show,
4047 files will empty when files have not fetched.
4049 we can add it back by using one-way diff(with outnumber changed and rename detect.
4050 here just need changed filename list. one-way is much quicker.
4052 if(pLogEntry
->m_IsFull
)
4054 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4056 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4058 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4064 if(!pLogEntry
->m_IsSimpleListReady
)
4065 pLogEntry
->SafeGetSimpleList(&g_Git
);
4067 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4069 str
+= pLogEntry
->m_SimpleFileList
[j
];
4078 if (std::regex_search(std::wstring(str
), pat
, flags
))
4088 if (str
.Find(findText
) >= 0)
4098 msg
= msg
.MakeLower();
4099 CString find
= findText
.MakeLower();
4100 if (msg
.Find(find
) >= 0)
4107 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4109 } // if(m_pFindDialog->FindNext())
4110 //UpdateLogInfoLabel();
4115 EnsureVisible(i
, FALSE
);
4116 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4118 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4119 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4120 SetSelectionMark(i
);
4124 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4126 m_highlight
= pLogEntry
->m_CommitHash
;
4129 //FillLogMessageCtrl();
4136 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4138 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4143 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4145 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4150 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4152 LVHITTESTINFO lvhitTestInfo
;
4154 lvhitTestInfo
.pt
= point
;
4156 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4157 int nSubItem
= lvhitTestInfo
.iSubItem
;
4159 UINT nFlags
= lvhitTestInfo
.flags
;
4161 // nFlags is 0 if the SubItemHitTest fails
4162 // Therefore, 0 & <anything> will equal false
4163 if (nFlags
& LVHT_ONITEM
)
4165 // Get the client area occupied by this control
4167 GetClientRect(&rcClient
);
4169 // Fill in the TOOLINFO structure
4171 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4172 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4173 pTI
->rect
= rcClient
;
4175 return pTI
->uId
; // By returning a unique value per listItem,
4176 // we ensure that when the mouse moves over another list item,
4177 // the tooltip will change
4181 // Otherwise, we aren't interested, so let the message propagate
4186 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4188 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4189 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4193 // Ignore messages from the built in tooltip, we are processing them internally
4194 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4195 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4196 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4199 // Get the mouse position
4200 const MSG
* pMessage
= GetCurrentMessage();
4204 ScreenToClient(&pt
);
4206 // Check if the point falls onto a list item
4207 LVHITTESTINFO lvhitTestInfo
;
4208 lvhitTestInfo
.pt
= pt
;
4210 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4212 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4214 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4215 if (strTipText
.IsEmpty())
4218 // we want multiline tooltips
4219 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4221 wcscpy_s(m_wszTip
, strTipText
);
4222 // handle Unicode as well as non-Unicode requests
4223 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4225 pTTTA
->hinst
= nullptr;
4226 pTTTA
->lpszText
= m_szTip
;
4227 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4231 pTTTW
->hinst
= nullptr;
4232 pTTTW
->lpszText
= m_wszTip
;
4236 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4237 ClientToScreen(rect
);
4238 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4240 return TRUE
; // We found a tool tip,
4241 // tell the framework this message has been handled
4244 return FALSE
; // We didn't handle the message,
4245 // let the framework continue propagating the message
4248 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4250 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4252 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4253 if (pLogEntry
== nullptr)
4255 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4257 return pLogEntry
->GetSubject();
4259 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4261 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4262 if (pLogEntry
== nullptr)
4264 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4266 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4268 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4269 if (pLogEntry
== nullptr)
4271 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4273 else if (nSubItem
== LOGLIST_ACTION
)
4275 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4276 if (pLogEntry
== nullptr)
4279 if (!pLogEntry
->m_IsDiffFiles
)
4280 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4282 int actions
= pLogEntry
->GetAction(this);
4283 CString sToolTipText
;
4286 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4287 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4289 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4291 if (!actionText
.IsEmpty())
4292 actionText
+= L
"\r\n";
4293 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4296 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4298 if (!actionText
.IsEmpty())
4299 actionText
+= L
"\r\n";
4300 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4303 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4305 if (!actionText
.IsEmpty())
4306 actionText
+= L
"\r\n";
4307 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4310 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4312 if (!actionText
.IsEmpty())
4313 actionText
+= L
"\r\n";
4314 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4317 if (!actionText
.IsEmpty())
4319 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4320 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4322 return sToolTipText
;