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
);
99 m_LoadingThread
= NULL
;
101 InterlockedExchange(&m_bExitThread
,FALSE
);
102 m_IsOldFirst
= FALSE
;
103 m_IsRebaseReplaceGraph
= FALSE
;
105 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
107 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
109 // get short/long datetime setting from registry
110 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
111 if ( RegUseShortDateFormat
)
113 m_DateFormat
= DATE_SHORTDATE
;
117 m_DateFormat
= DATE_LONGDATE
;
119 // get relative time display setting from registry
120 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
121 m_bRelativeTimes
= (regRelativeTimes
!= 0);
122 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
124 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
125 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
126 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
127 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
128 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
129 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
132 m_ColumnRegKey
=_T("log");
134 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
135 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
136 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
137 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE
);
139 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
140 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
142 m_AsyncThreadExit
= FALSE
;
143 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
144 m_AsynDiffListLock
.Init();
146 hUxTheme
= AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
148 pfnDrawThemeTextEx
= (FNDRAWTHEMETEXTEX
)::GetProcAddress(hUxTheme
, "DrawThemeTextEx");
150 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
151 if (m_DiffingThread
==NULL
)
153 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
159 int CGitLogListBase::AsyncDiffThread()
161 m_AsyncThreadExited
= false;
162 while(!m_AsyncThreadExit
)
164 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
166 GitRevLoglist
* pRev
= nullptr;
167 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
169 m_AsynDiffListLock
.Lock();
170 pRev
= m_AsynDiffList
.back();
171 m_AsynDiffList
.pop_back();
172 m_AsynDiffListLock
.Unlock();
174 if( pRev
->m_CommitHash
.IsEmpty() )
176 if(pRev
->m_IsDiffFiles
)
179 CTGitPathList
& files
= pRev
->GetFiles(this);
181 pRev
->m_ParentHash
.clear();
182 pRev
->m_ParentHash
.push_back(m_HeadHash
);
183 g_Git
.GetWorkingTreeChanges(files
);
184 int& action
= pRev
->GetAction(this);
186 for (int j
= 0; j
< files
.GetCount(); ++j
)
187 action
|= files
[j
].m_Action
;
190 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
192 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
196 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
197 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
199 pRev
->GetBody().Format(IDS_FILESCHANGES
, files
.GetCount());
200 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
201 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
204 m_critSec_AsyncDiff
.Lock();
205 int ret
= pRev
->CheckAndDiff();
206 m_critSec_AsyncDiff
.Unlock();
208 { // fetch change file list
209 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
211 if(i
< m_arShownList
.GetCount())
213 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
214 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
216 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
222 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
224 POSITION pos
= GetFirstSelectedItemPosition();
225 int nItem
= GetNextSelectedItem(pos
);
229 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
231 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
233 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
240 m_AsyncThreadExited
= true;
243 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
247 m_ContextMenuMask
&= hideMask
;
251 m_ContextMenuMask
&= ~hideMask
;
255 CGitLogListBase::~CGitLogListBase()
257 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
258 this->m_arShownList
.SafeRemoveAll();
260 DestroyIcon(m_hModifiedIcon
);
261 DestroyIcon(m_hReplacedIcon
);
262 DestroyIcon(m_hConflictedIcon
);
263 DestroyIcon(m_hAddedIcon
);
264 DestroyIcon(m_hDeletedIcon
);
265 m_logEntries
.ClearAll();
268 DeleteObject(m_boldFont
);
271 DeleteObject(m_FontItalics
);
273 if (m_boldItalicsFont
)
274 DeleteObject(m_boldItalicsFont
);
276 if ( m_pStoreSelection
)
278 delete m_pStoreSelection
;
279 m_pStoreSelection
= NULL
;
282 SafeTerminateThread();
283 SafeTerminateAsyncDiffThread();
286 CloseHandle(m_AsyncDiffEvent
);
289 FreeLibrary(hUxTheme
);
293 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
294 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
295 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
296 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
297 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
299 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
300 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
303 ON_MESSAGE(MSG_LOADED
,OnLoad
)
305 ON_WM_MEASUREITEM_REFLECT()
306 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
307 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
308 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
309 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
310 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
311 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
312 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
313 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
316 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
318 //if (m_nRowHeight>0)
320 lpMeasureItemStruct
->itemHeight
= 50;
324 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
327 return CHintListCtrl::OnCreate(lpCreateStruct
);
330 void CGitLogListBase::PreSubclassWindow()
332 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
333 // load the icons for the action columns
334 // m_Theme.Open(m_hWnd, L"ListView");
335 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
336 CHintListCtrl::PreSubclassWindow();
339 CString
CGitLogListBase::GetRebaseActionName(int action
)
341 if (action
& LOGACTIONS_REBASE_EDIT
)
342 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
343 if (action
& LOGACTIONS_REBASE_SQUASH
)
344 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
345 if (action
& LOGACTIONS_REBASE_PICK
)
346 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
347 if (action
& LOGACTIONS_REBASE_SKIP
)
348 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
350 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
353 void CGitLogListBase::InsertGitColumn()
357 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
358 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
359 if (DWORD(regFullRowSelect
))
360 exStyle
|= LVS_EX_FULLROWSELECT
;
361 SetExtendedStyle(exStyle
);
363 // only load properties if we have a repository
364 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
365 UpdateProjectProperties();
367 static UINT normal
[] =
379 IDS_LOG_COMMIT_EMAIL
,
402 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
404 DWORD hideColumns
= 0;
405 if(this->m_IsRebaseReplaceGraph
)
407 hideColumns
|= GIT_LOG_GRAPH
;
408 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
412 hideColumns
|= GIT_LOG_REBASE
;
415 if(this->m_IsIDReplaceAction
)
417 hideColumns
|= GIT_LOG_ACTIONS
;
418 m_dwDefaultColumns
|= GIT_LOG_ID
;
419 m_dwDefaultColumns
|= GIT_LOG_HASH
;
423 hideColumns
|= GIT_LOG_ID
;
425 if(this->m_bShowBugtraqColumn
)
427 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
431 hideColumns
|= GIT_LOGLIST_BUG
;
433 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
434 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
436 hideColumns
|= GIT_LOGLIST_SVNREV
;
439 m_ColumnManager
.SetNames(normal
, _countof(normal
));
440 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
446 * Resizes all columns in a list control to values in registry.
448 void CGitLogListBase::ResizeAllListCtrlCols()
450 // column max and min widths to allow
451 static const int nMinimumWidth
= 10;
452 static const int nMaximumWidth
= 1000;
453 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
456 int numcols
= pHdrCtrl
->GetItemCount();
457 for (int col
= 0; col
< numcols
; ++col
)
459 // get width for this col last time from registry
461 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR
)m_ColumnRegKey
, col
);
462 CRegDWORD
regwidth(regentry
, 0);
466 // no saved value, setup sensible defaults
467 if (col
== this->LOGLIST_MESSAGE
)
469 cx
= LOGLIST_MESSAGE_MIN
;
473 cx
= ICONITEMBORDER
+16*4;
476 if (cx
< nMinimumWidth
)
480 else if (cx
> nMaximumWidth
)
485 SetColumnWidth(col
, cx
);
492 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
495 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
496 rItem
.mask
= LVIF_STATE
;
497 rItem
.iItem
= (int)Index
;
498 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
501 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(Index
);
504 if (!(rItem
.state
& LVIS_SELECTED
))
506 int action
= pLogEntry
->GetRebaseAction();
507 if (action
& LOGACTIONS_REBASE_SQUASH
)
508 brush
= ::CreateSolidBrush(RGB(156,156,156));
509 else if (action
& LOGACTIONS_REBASE_EDIT
)
510 brush
= ::CreateSolidBrush(RGB(200,200,128));
512 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
514 if (rItem
.state
& LVIS_SELECTED
)
516 if (::GetFocus() == m_hWnd
)
517 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
519 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
524 ::FillRect(hdc
, &rect
, brush
);
525 ::DeleteObject(brush
);
529 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
531 POINT point
= { 4, 4 };
533 rt2
.DeflateRect(1, 1);
534 rt2
.OffsetRect(2, 2);
536 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
537 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
538 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
539 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
540 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
542 ::SelectObject(hdc
, brush
);
543 rt2
.OffsetRect(-2, -2);
544 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
545 ::SelectObject(hdc
, oldbrush
);
546 ::SelectObject(hdc
, oldpen
);
547 ::DeleteObject(nullPen
);
548 ::DeleteObject(darkBrush
);
551 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
553 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
554 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
555 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
556 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
557 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
558 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
559 ::SelectObject(hdc
, oldpen
);
563 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
565 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
566 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
567 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
568 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
569 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
570 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
571 ::SelectObject(hdc
, oldpen
);
575 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
577 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
580 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
581 rItem
.mask
= LVIF_STATE
;
582 rItem
.iItem
= (int)index
;
583 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
589 HTHEME hTheme
= NULL
;
590 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
591 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
594 if (m_bTagsBranchesOnRightSide
)
596 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
597 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
598 SelectObject(hdc
, oldFont
);
599 rt
.left
+= oneSpaceSize
.cx
* 2;
603 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
604 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
605 rt
.left
+= oneSpaceSize
.cx
;
608 CString msg
= MessageDisplayStr(data
);
609 int action
= data
->GetRebaseAction();
610 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
611 if (IsAppThemed() && pfnDrawThemeTextEx
)
613 int txtState
= LISS_NORMAL
;
614 if (rItem
.state
& LVIS_SELECTED
)
615 txtState
= LISS_SELECTED
;
617 DTTOPTS opts
= { 0 };
618 opts
.dwSize
= sizeof(opts
);
619 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
620 opts
.dwFlags
= DTT_TEXTCOLOR
;
621 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
625 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
627 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
628 ::DrawText(hdc
,msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
629 ::SetTextColor(hdc
, clrOld
);
633 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
634 ::DrawText(hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
635 ::SetTextColor(hdc
, clrOld
);
639 if (m_bTagsBranchesOnRightSide
)
642 GetTextExtentPoint32(hdc
, msg
, msg
.GetLength(), &size
);
644 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
646 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
650 CloseThemeData(hTheme
);
655 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
)
657 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
659 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
661 COLORREF colRef
= refList
[i
].color
;
662 bool singleRemote
= refList
[i
].singleRemote
;
663 bool hasTracking
= refList
[i
].hasTracking
;
664 bool sameName
= refList
[i
].sameName
;
665 bool annotatedTag
= refList
[i
].annotatedTag
;
667 //When row selected, ajust label color
668 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
670 if (rItem
.state
& LVIS_SELECTED
)
671 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
674 brush
= ::CreateSolidBrush(colRef
);
676 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
679 memset(&size
,0,sizeof(SIZE
));
680 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
682 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
685 int textpos
= DT_CENTER
;
687 if (rt
.right
> rect
.right
)
689 rt
.right
= rect
.right
;
698 textRect
.OffsetRect(8, 0);
706 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
710 //Fill interior of ref label
711 ::FillRect(hdc
, &rt
, brush
);
719 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
720 rectEdge
.DeflateRect(1, 1);
721 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
727 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
728 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
729 ::FillRgn(hdc
, hrgn
, brush
);
730 ::DeleteObject(hrgn
);
731 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
733 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
734 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
736 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
737 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
739 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
740 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
741 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
743 SelectObject(hdc
, oldpen
);
746 //Draw text inside label
747 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
748 if (!customColor
&& IsAppThemed() && pfnDrawThemeTextEx
)
750 int txtState
= LISS_NORMAL
;
751 if (rItem
.state
& LVIS_SELECTED
)
752 txtState
= LISS_SELECTED
;
754 DTTOPTS opts
= { 0 };
755 opts
.dwSize
= sizeof(opts
);
756 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
757 opts
.dwFlags
= DTT_TEXTCOLOR
;
758 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
762 W_Dc
.SetBkMode(TRANSPARENT
);
763 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
765 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
766 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
767 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
768 ::SetTextColor(hdc
,clrOld
);
772 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
773 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
774 ::SetTextColor(hdc
, clrOld
);
780 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
781 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
783 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
784 DrawLightning(hdc
, newRect
, color
, bold
);
789 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
790 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
792 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
793 DrawUpTriangle(hdc
, newRect
, color
, bold
);
796 rt
.left
= rt
.right
+ 1;
799 ::DeleteObject(brush
);
801 rt
.right
= rect
.right
;
804 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
806 // Returns ((256 - amount)*col1 + amount*col2) / 256;
807 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
808 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
809 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
812 Gdiplus::Color
GetGdiColor(COLORREF col
)
814 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
816 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
817 const COLORREF
& col
,const COLORREF
& activeColor
, int top
820 int h
= laneHeight
/ 2;
821 int m
= (x1
+ x2
) / 2;
822 int r
= (x2
- x1
) * m_NodeSize
/ 30;
825 #define P_CENTER m , h+top
826 #define P_0 x2, h+top
827 #define P_90 m , 0+top-1
828 #define P_180 x1, h+top
829 #define P_270 m , 2 * h+top +1
830 #define R_CENTER m - r, h - r+top, d, d
833 #define DELTA_UR_B 2*(x1 - m), 2*h +top
834 #define DELTA_UR_E 0*16, 90*16 +top // -,
836 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
837 #define DELTA_DR_E 270*16, 90*16 +top // -'
839 #define DELTA_UL_B 2*(x2 - m), 2*h +top
840 #define DELTA_UL_E 90*16, 90*16 +top // ,-
842 #define DELTA_DL_B 2*(x2 - m),2*-h +top
843 #define DELTA_DL_E 180*16, 90*16 // '-
845 #define CENTER_UR x1, 2*h, 225
846 #define CENTER_DR x1, 0 , 135
847 #define CENTER_UL x2, 2*h, 315
848 #define CENTER_DL x2, 0 , 45
851 Gdiplus::Graphics
graphics( hdc
);
853 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
862 Gdiplus::LinearGradientBrush
gradient(
863 Gdiplus::Point(x1
-2, h
+top
-2),
864 Gdiplus::Point(P_270
),
865 GetGdiColor(activeColor
),GetGdiColor(col
));
868 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
869 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
871 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
872 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
873 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
880 Gdiplus::LinearGradientBrush
gradient(
881 Gdiplus::Point(P_270
),
882 Gdiplus::Point(x2
+1, h
+top
-1),
883 GetGdiColor(col
),GetGdiColor(activeColor
));
886 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
887 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
889 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
890 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
891 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
900 Gdiplus::LinearGradientBrush
gradient(
901 Gdiplus::Point(x1
-2, h
+top
-2),
902 Gdiplus::Point(P_90
),
903 GetGdiColor(activeColor
),GetGdiColor(col
));
905 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
907 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
910 QConicalGradient
gradient(CENTER_DR
);
911 gradient
.setColorAt(0.375, activeCol
);
912 gradient
.setColorAt(0.625, col
);
913 myPen
.setBrush(gradient
);
915 p
->drawArc(P_CENTER
, DELTA_DR
);
924 //static QPen myPen(Qt::black, 2); // fast path here
926 pen
.CreatePen(PS_SOLID
,2,col
);
927 //myPen.setColor(col);
928 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
930 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
932 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
939 case Lanes::NOT_ACTIVE
:
940 case Lanes::MERGE_FORK
:
941 case Lanes::MERGE_FORK_R
:
942 case Lanes::MERGE_FORK_L
:
947 //DrawLine(hdc,P_90,P_270);
948 graphics
.DrawLine(&myPen
,P_90
,P_270
);
949 //p->drawLine(P_90, P_270);
953 //DrawLine(hdc,P_CENTER,P_270);
954 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
955 //p->drawLine(P_CENTER, P_270);
959 case Lanes::BOUNDARY
:
960 case Lanes::BOUNDARY_C
:
961 case Lanes::BOUNDARY_R
:
962 case Lanes::BOUNDARY_L
:
963 //DrawLine(hdc,P_90, P_CENTER);
964 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
965 //p->drawLine(P_90, P_CENTER);
971 myPen
.SetColor(GetGdiColor(activeColor
));
975 case Lanes::MERGE_FORK
:
980 case Lanes::CROSS_EMPTY
:
981 case Lanes::BOUNDARY_C
:
982 //DrawLine(hdc,P_180,P_0);
983 graphics
.DrawLine(&myPen
,P_180
,P_0
);
984 //p->drawLine(P_180, P_0);
986 case Lanes::MERGE_FORK_R
:
987 case Lanes::BOUNDARY_R
:
988 //DrawLine(hdc,P_180,P_CENTER);
989 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
990 //p->drawLine(P_180, P_CENTER);
992 case Lanes::MERGE_FORK_L
:
995 case Lanes::BOUNDARY_L
:
996 //DrawLine(hdc,P_CENTER,P_0);
997 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
998 //p->drawLine(P_CENTER, P_0);
1004 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1007 brush
.CreateSolidBrush(col
);
1008 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1010 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1011 // center symbol, e.g. rect or ellipse
1014 case Lanes::INITIAL
:
1017 //p->setPen(Qt::NoPen);
1019 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1020 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1021 //p->drawEllipse(R_CENTER);
1023 case Lanes::MERGE_FORK
:
1024 case Lanes::MERGE_FORK_R
:
1025 case Lanes::MERGE_FORK_L
:
1026 //p->setPen(Qt::NoPen);
1028 //p->drawRect(R_CENTER);
1029 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1030 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1032 case Lanes::UNAPPLIED
:
1034 //p->setPen(Qt::NoPen);
1035 //p->setBrush(Qt::red);
1036 //p->drawRect(m - r, h - 1, d, 2);
1037 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1038 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1040 case Lanes::APPLIED
:
1042 //p->setPen(Qt::NoPen);
1043 //p->setBrush(DARK_GREEN);
1044 //p->drawRect(m - r, h - 1, d, 2);
1045 //p->drawRect(m - 1, h - r, 2, d);
1046 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1047 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1048 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1050 case Lanes::BOUNDARY
:
1051 //p->setBrush(back);
1052 //p->drawEllipse(R_CENTER);
1053 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1054 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1056 case Lanes::BOUNDARY_C
:
1057 case Lanes::BOUNDARY_R
:
1058 case Lanes::BOUNDARY_L
:
1059 //p->setBrush(back);
1060 //p->drawRect(R_CENTER);
1061 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1062 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1068 ::SelectObject(hdc
,oldpen
);
1069 ::SelectObject(hdc
,oldbrush
);
1078 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1082 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
1083 if(data
->m_CommitHash
.IsEmpty())
1088 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1089 rItem
.mask
= LVIF_STATE
;
1090 rItem
.iItem
= (int)index
;
1091 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1094 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1096 if (data
->m_Lanes
.empty())
1097 m_logEntries
.setLane(data
->m_CommitHash
);
1099 std::vector
<int>& lanes
=data
->m_Lanes
;
1100 size_t laneNum
= lanes
.size();
1101 UINT activeLane
= 0;
1102 for (UINT i
= 0; i
< laneNum
; ++i
)
1103 if (Lanes::isMerge(lanes
[i
])) {
1109 int maxWidth
= rect
.Width();
1110 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1112 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1113 //if (opt.state & QStyle::State_Selected)
1114 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1116 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1123 if (ln
== Lanes::EMPTY
)
1126 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1127 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1131 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1137 if (ln
== Lanes::EMPTY
)
1140 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1141 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1143 if (ln
== Lanes::CROSS
)
1145 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1146 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1149 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1155 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1158 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1159 // Take the default processing unless we set this to something else below.
1160 *pResult
= CDRF_DODEFAULT
;
1162 if (m_bNoDispUpdates
)
1165 switch (pLVCD
->nmcd
.dwDrawStage
)
1169 *pResult
= CDRF_NOTIFYITEMDRAW
;
1173 case CDDS_ITEMPREPAINT
:
1175 // This is the prepaint stage for an item. Here's where we set the
1176 // item's text color.
1178 // Tell Windows to send draw notifications for each subitem.
1179 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1181 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1183 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1185 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1188 HGDIOBJ hGdiObj
= nullptr;
1189 int action
= data
->GetRebaseAction();
1190 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1191 crText
= RGB(128,128,128);
1193 if (action
& LOGACTIONS_REBASE_SQUASH
)
1194 pLVCD
->clrTextBk
= RGB(156,156,156);
1195 else if (action
& LOGACTIONS_REBASE_EDIT
)
1196 pLVCD
->clrTextBk
= RGB(200,200,128);
1198 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1200 if (action
& LOGACTIONS_REBASE_CURRENT
)
1201 hGdiObj
= m_boldFont
;
1203 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1204 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1205 if (isHeadHash
&& isHighlight
)
1206 hGdiObj
= m_boldItalicsFont
;
1207 else if (isHeadHash
)
1208 hGdiObj
= m_boldFont
;
1209 else if (isHighlight
)
1210 hGdiObj
= m_FontItalics
;
1214 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1215 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1218 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1219 // crText = GetSysColor(COLOR_GRAYTEXT);
1221 if (data
->m_CommitHash
.IsEmpty())
1223 //crText = GetSysColor(RGB(200,200,0));
1224 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1225 // We changed the font, so we're returning CDRF_NEWFONT. This
1226 // tells the control to recalculate the extent of the text.
1227 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1231 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1233 if (m_bStrictStopped
)
1234 crText
= GetSysColor(COLOR_GRAYTEXT
);
1236 // Store the color back in the NMLVCUSTOMDRAW struct.
1237 pLVCD
->clrText
= crText
;
1241 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1243 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1245 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1248 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1250 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1253 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1255 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1256 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1258 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1259 if( !data
->m_CommitHash
.IsEmpty())
1260 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1262 *pResult
= CDRF_SKIPDEFAULT
;
1267 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1269 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1271 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1273 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1276 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1278 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1279 // not in FillBackGround method, because this only affected the message subitem
1280 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1283 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1284 int state
= GetItemState(index
, LVIS_SELECTED
);
1285 int txtState
= LISS_NORMAL
;
1286 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1288 if (state
& LVIS_SELECTED
)
1289 txtState
= LISS_HOTSELECTED
;
1291 txtState
= LISS_HOT
;
1293 else if (state
& LVIS_SELECTED
)
1295 if (::GetFocus() == m_hWnd
)
1296 txtState
= LISS_SELECTED
;
1298 txtState
= LISS_SELECTEDNOTFOCUS
;
1301 HTHEME hTheme
= nullptr;
1302 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1303 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1305 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1306 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1309 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1310 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1311 ::DeleteObject(brush
);
1316 // get rect of whole line
1317 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1319 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1320 rect2
.DeflateRect(1, 1, 1, 1);
1322 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1323 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1325 CloseThemeData(hTheme
);
1327 // END: extended redraw
1329 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1331 std::vector
<REFLABEL
> refsToShow
;
1332 STRING_VECTOR remoteTrackingList
;
1333 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1334 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1336 CString str
= refList
[i
];
1339 refLabel
.color
= RGB(255, 255, 255);
1340 refLabel
.singleRemote
= false;
1341 refLabel
.hasTracking
= false;
1342 refLabel
.sameName
= false;
1343 refLabel
.annotatedTag
= false;
1344 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1346 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1348 if (refLabel
.name
== m_CurrentBranch
)
1349 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1351 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1353 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1354 CString pullRemote
= trackingEntry
.first
;
1355 CString pullBranch
= trackingEntry
.second
;
1356 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1358 CString defaultUpstream
;
1359 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), (LPCTSTR
)pullRemote
, (LPCTSTR
)pullBranch
);
1360 refLabel
.hasTracking
= true;
1361 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1364 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1366 if (refList
[j
] == defaultUpstream
)
1375 bool sameName
= pullBranch
== refLabel
.name
;
1376 refsToShow
.push_back(refLabel
);
1377 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1378 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1379 if (m_bSymbolizeRefNames
)
1381 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1383 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1384 refLabel
.singleRemote
= true;
1387 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1388 refLabel
.sameName
= sameName
;
1390 refsToShow
.push_back(refLabel
);
1391 remoteTrackingList
.push_back(defaultUpstream
);
1397 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1399 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1403 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1405 if (remoteTrackingList
[j
] == str
)
1414 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1415 if (m_bSymbolizeRefNames
)
1417 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1419 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1420 refLabel
.singleRemote
= true;
1424 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1426 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1428 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1429 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1431 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1433 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1435 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1436 refLabel
.name
= _T("stash");
1438 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1440 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1442 if (refLabel
.name
.Find(_T("good")) == 0)
1444 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1445 refLabel
.name
= _T("good");
1447 if (refLabel
.name
.Find(_T("bad")) == 0)
1449 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1450 refLabel
.name
= _T("bad");
1456 refsToShow
.push_back(refLabel
);
1459 if (refsToShow
.empty())
1461 *pResult
= CDRF_DODEFAULT
;
1465 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1467 *pResult
= CDRF_SKIPDEFAULT
;
1475 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1477 if(this->m_IsIDReplaceAction
)
1479 *pResult
= CDRF_DODEFAULT
;
1482 *pResult
= CDRF_DODEFAULT
;
1484 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1488 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1489 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1491 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1493 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1494 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1495 // Get the selected state of the
1496 // item being drawn.
1498 // Fill the background if necessary
1499 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1501 // Draw the icon(s) into the compatible DC
1502 int action
= pLogEntry
->GetAction(this);
1503 if (!pLogEntry
->m_IsDiffFiles
)
1505 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1506 *pResult
= CDRF_SKIPDEFAULT
;
1510 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1511 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1514 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1515 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1518 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1519 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1522 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1523 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1526 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1527 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1530 *pResult
= CDRF_SKIPDEFAULT
;
1536 *pResult
= CDRF_DODEFAULT
;
1539 CString
FindSVNRev(const CString
& msg
)
1543 const std::tr1::wsregex_iterator end
;
1544 std::wstring s
= msg
;
1545 std::tr1::wregex
regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1546 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex1
); it
!= end
; ++it
)
1548 const std::tr1::wsmatch match
= *it
;
1549 if (match
.size() == 4)
1551 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1552 return std::wstring(match
[2]).c_str();
1555 std::tr1::wregex
regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1556 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex2
); it
!= end
; ++it
)
1558 const std::tr1::wsmatch match
= *it
;
1559 if (match
.size() == 3)
1561 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1562 return std::wstring(match
[1]).c_str();
1566 catch (std::exception
) {}
1571 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1573 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1574 return pLogEntry
->GetSubject();
1577 txt
.Format(L
"%s %s", (LPCTSTR
)pLogEntry
->GetSubject(), (LPCTSTR
)pLogEntry
->GetBody());
1580 txt
.Replace(_T("\n"), _T(" "));
1581 txt
.Replace(_T("\r"), _T(" "));
1586 // CGitLogListBase message handlers
1588 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1590 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1592 // Create a pointer to the item
1593 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1595 // Do the list need text information?
1596 if (!(pItem
->mask
& LVIF_TEXT
))
1599 // By default, clear text buffer.
1600 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
- 1);
1602 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1605 if (m_bNoDispUpdates
|| bOutOfRange
)
1608 // Which item number?
1609 int itemid
= pItem
->iItem
;
1610 GitRevLoglist
* pLogEntry
= nullptr;
1611 if (itemid
< m_arShownList
.GetCount())
1612 pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1617 temp
.Format(_T("%d"),pItem
->iItem
+1);
1622 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1626 switch (pItem
->iSubItem
)
1628 case LOGLIST_GRAPH
: //Graphic
1630 case LOGLIST_REBASE
:
1632 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1633 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1636 case LOGLIST_ACTION
: //action -- no text in the column
1640 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1643 if(this->m_IsIDReplaceAction
)
1644 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1646 case LOGLIST_MESSAGE
: //Message
1648 lstrcpyn(pItem
->pszText
, (LPCTSTR
)MessageDisplayStr(pLogEntry
), pItem
->cchTextMax
- 1);
1650 case LOGLIST_AUTHOR
: //Author
1652 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
- 1);
1654 case LOGLIST_DATE
: //Date
1655 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1656 lstrcpyn(pItem
->pszText
,
1657 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1658 pItem
->cchTextMax
- 1);
1663 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
- 1);
1666 case LOGLIST_COMMIT_NAME
: //Commit
1668 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
- 1);
1671 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1673 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
- 1);
1676 case LOGLIST_COMMIT_DATE
: //Commit Date
1677 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1678 lstrcpyn(pItem
->pszText
,
1679 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1680 pItem
->cchTextMax
- 1);
1682 case LOGLIST_BUG
: //Bug ID
1684 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1686 case LOGLIST_SVNREV
: //SVN revision
1688 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1696 bool CGitLogListBase::IsOnStash(int index
)
1698 GitRevLoglist
* rev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
));
1703 GitRevLoglist
* preRev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
- 1));
1704 if (IsStash(preRev
))
1705 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1710 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1712 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1714 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1720 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1722 if (pRev
->m_ParentHash
.empty())
1724 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1725 MessageBox(pRev
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1727 parentHash
= pRev
->m_ParentHash
;
1730 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1733 if (pWnd
== GetHeaderCtrl())
1735 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1738 int selIndex
= GetSelectionMark();
1740 return; // nothing selected, nothing to do with a context menu
1742 // if the user selected the info text telling about not all revisions shown due to
1743 // the "stop on copy/rename" option, we also don't show the context menu
1744 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1747 // if the context menu is invoked through the keyboard, we have to use
1748 // a calculated position on where to anchor the menu on
1749 if ((point
.x
== -1) && (point
.y
== -1))
1752 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1753 ClientToScreen(&rect
);
1754 point
= rect
.CenterPoint();
1756 m_nSearchIndex
= selIndex
;
1757 m_bCancelled
= FALSE
;
1759 // calculate some information the context menu commands can use
1760 // CString pathURL = GetURLFromPath(m_path);
1762 POSITION pos
= GetFirstSelectedItemPosition();
1763 int indexNext
= GetNextSelectedItem(pos
);
1767 GitRevLoglist
* pSelLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(indexNext
));
1768 if (pSelLogEntry
== nullptr)
1771 GitRev revSelected
= pSelLogEntry
->Rev
;
1772 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1773 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1775 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1777 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1778 if (changedpath
->lCopyFromRev
)
1779 revPrevious
= changedpath
->lCopyFromRev
;
1782 GitRev revSelected2
;
1785 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1786 revSelected2
= pLogEntry
->Rev
;
1788 bool bAllFromTheSameAuthor
= true;
1789 CString firstAuthor
;
1790 CLogDataVector selEntries
;
1791 GitRev revLowest
, revHighest
;
1792 GitRevRangeArray revisionRanges
;
1794 POSITION pos
= GetFirstSelectedItemPosition();
1795 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1796 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1797 selEntries
.push_back(pLogEntry
);
1798 firstAuthor
= pLogEntry
->sAuthor
;
1799 revLowest
= pLogEntry
->Rev
;
1800 revHighest
= pLogEntry
->Rev
;
1803 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1804 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1805 selEntries
.push_back(pLogEntry
);
1806 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1807 bAllFromTheSameAuthor
= false;
1808 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1809 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1815 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1817 int FirstSelect
=-1, LastSelect
=-1;
1818 pos
= GetFirstSelectedItemPosition();
1819 FirstSelect
= GetNextSelectedItem(pos
);
1822 LastSelect
= GetNextSelectedItem(pos
);
1824 //entry is selected, now show the popup menu
1826 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1828 if (popup
.CreatePopupMenu())
1830 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1831 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1832 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1833 bool isStash
= IsOnStash(indexNext
);
1834 GIT_REV_LIST parentHash
;
1835 GetParentHashes(pSelLogEntry
, parentHash
);
1837 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1838 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1840 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1)
1841 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1843 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1844 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1846 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1847 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1849 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
)))
1850 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1852 if (GetSelectedCount() == 1)
1855 bool requiresSeparator
= false;
1856 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1858 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1860 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1861 requiresSeparator
= true;
1866 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1868 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1869 requiresSeparator
= true;
1871 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1873 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1874 requiresSeparator
= true;
1878 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1880 if (parentHash
.size() == 1)
1882 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1883 requiresSeparator
= true;
1885 else if (parentHash
.size() > 1)
1887 blamemenu
.CreatePopupMenu();
1888 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1889 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1892 str
.Format(IDS_PARENT
, i
+ 1);
1893 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1895 requiresSeparator
= true;
1899 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1901 if (parentHash
.size() == 1)
1903 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1904 requiresSeparator
= true;
1906 else if (parentHash
.size() > 1)
1908 gnudiffmenu
.CreatePopupMenu();
1909 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1911 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1912 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1913 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1915 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1918 str
.Format(IDS_PARENT
, i
+ 1);
1919 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1921 requiresSeparator
= true;
1925 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1927 if (parentHash
.size() == 1)
1929 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1930 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1931 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1932 requiresSeparator
= true;
1934 else if (parentHash
.size() > 1)
1936 diffmenu
.CreatePopupMenu();
1937 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1938 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1941 str
.Format(IDS_PARENT
, i
+ 1);
1942 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1943 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1945 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1946 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1949 requiresSeparator
= true;
1953 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1955 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1956 requiresSeparator
= true;
1959 if (requiresSeparator
)
1960 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1962 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1964 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1965 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1968 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1970 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1971 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1973 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1974 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1976 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1979 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1981 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1982 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1984 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1985 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1987 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
1988 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1990 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1992 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1993 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1995 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1999 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2001 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2003 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2005 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2007 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2008 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2010 // popup.AppendMenu(MF_SEPARATOR, NULL);
2015 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2017 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2019 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2020 GetSelectedCount() == 1)
2021 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2023 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2024 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2026 str
.Format(IDS_LOG_POPUP_MERGEREV
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2028 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2029 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2031 str
.Format(IDS_RESET_TO_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2033 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2034 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2037 // Add Switch Branch express Menu
2038 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2039 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2042 std::vector
<CString
*> branchs
;
2043 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2045 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2046 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2048 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2053 str2
.LoadString(IDS_SWITCH_BRANCH
);
2055 if(branchs
.size() == 1)
2058 str2
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2059 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2061 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2064 else if(branchs
.size() > 1)
2066 subbranchmenu
.CreatePopupMenu();
2067 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2069 if (*branchs
[i
] != currentBranch
)
2071 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2072 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2076 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2080 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2081 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2083 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2084 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2086 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2087 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2089 str
.Format(IDS_REBASE_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2091 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2092 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2093 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2095 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2096 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2098 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2100 if (parentHash
.size() == 1)
2102 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2104 else if (parentHash
.size() > 1)
2106 revertmenu
.CreatePopupMenu();
2107 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2109 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2112 str2
.Format(IDS_PARENT
, i
+ 1);
2113 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2118 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2119 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2121 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2126 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2128 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2129 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2130 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2131 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2134 if (GetSelectedCount() >= 2)
2136 bool bAddSeparator
= false;
2137 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2139 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2140 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2143 if (GetSelectedCount() == 2)
2145 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2146 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2148 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2150 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2151 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2152 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2154 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("..") + firstSelHash
));
2155 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2156 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("...") + firstSelHash
));
2157 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2160 bAddSeparator
= true;
2165 bAddSeparator
= true;
2168 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2169 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2172 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2175 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2177 bool bAddSeparator
= false;
2178 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2180 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2184 headindex
= this->GetHeadIndex();
2185 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2187 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2189 if (g_Git
.GetHash(hashFirst
, head
))
2190 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2191 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2193 if (g_Git
.GetHash(hash
, head
))
2194 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2195 GitRevLoglist
* pFirstEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2196 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2197 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2198 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2199 bAddSeparator
= true;
2204 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2205 if (GetSelectedCount() >= 2)
2206 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2208 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2209 bAddSeparator
= true;
2212 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2213 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2214 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2215 bAddSeparator
= true;
2219 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2222 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())
2224 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2225 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2228 if (GetSelectedCount() == 1)
2230 bool bAddSeparator
= false;
2231 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2233 // show the push-option only if the log entry has an associated local branch
2234 bool isLocal
= false;
2235 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2237 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2240 if (isLocal
|| showExtendedMenu
)
2242 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2243 bAddSeparator
= true;
2246 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2248 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2249 bAddSeparator
= true;
2253 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2255 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2257 std::vector
<CString
*> branchs
;
2258 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2260 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2261 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2264 if (branchs
.size() == 1)
2266 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2269 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2270 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2271 bAddSeparator
= true;
2273 else if (branchs
.size() > 1)
2275 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2276 submenu
.CreatePopupMenu();
2277 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2279 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2280 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2283 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2284 bAddSeparator
= true;
2287 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2289 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2290 } // GetSelectedCount() == 1
2292 if (GetSelectedCount() != 0)
2294 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2295 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2296 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2297 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2298 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2299 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2302 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2303 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2305 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2306 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2308 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2309 // DialogEnableWindow(IDOK, FALSE);
2310 // SetPromptApp(&theApp);
2312 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2314 // EnableOKButton();
2315 } // if (popup.CreatePopupMenu())
2319 bool CGitLogListBase::IsSelectionContinuous()
2321 if ( GetSelectedCount()==1 )
2323 // if only one revision is selected, the selection is of course
2328 POSITION pos
= GetFirstSelectedItemPosition();
2329 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2332 int itemindex
= GetNextSelectedItem(pos
);
2335 int nextindex
= GetNextSelectedItem(pos
);
2336 if (nextindex
- itemindex
> 1)
2338 bContinuous
= false;
2341 itemindex
= nextindex
;
2347 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2351 POSITION pos
= GetFirstSelectedItemPosition();
2355 sRev
.LoadString(IDS_LOG_REVISION
);
2357 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2359 sDate
.LoadString(IDS_LOG_DATE
);
2361 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2365 CString sLogCopyText
;
2367 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2369 if (toCopy
== ID_COPY_ALL
)
2371 //pLogEntry->GetFiles(this)
2372 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2374 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2375 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2377 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2378 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2381 rename
.Format(from
, (LPCTSTR
)((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2382 sPaths
+= _T(" ") + rename
;
2384 sPaths
+= _T("\r\n");
2387 CString body
= pLogEntry
->GetBody();
2388 body
.Replace(_T("\n"), _T("\r\n"));
2389 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"),
2390 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2391 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2393 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2394 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2396 sClipdata
+= sLogCopyText
;
2398 else if (toCopy
== ID_COPY_MESSAGE
)
2400 CString body
= pLogEntry
->GetBody();
2401 body
.Replace(_T("\n"), _T("\r\n"));
2402 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2404 else if (toCopy
== ID_COPY_SUBJECT
)
2406 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2411 sClipdata
+= _T("\r\n");
2412 sClipdata
+= pLogEntry
->m_CommitHash
;
2417 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2422 void CGitLogListBase::DiffSelectedRevWithPrevious()
2424 if (m_bThreadRunning
)
2427 int FirstSelect
=-1, LastSelect
=-1;
2428 POSITION pos
= GetFirstSelectedItemPosition();
2429 FirstSelect
= GetNextSelectedItem(pos
);
2432 LastSelect
= GetNextSelectedItem(pos
);
2435 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2438 UpdateLogInfoLabel();
2439 int selIndex
= m_LogList
.GetSelectionMark();
2442 int selCount
= m_LogList
.GetSelectedCount();
2446 // Find selected entry in the log list
2447 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2448 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2449 long rev1
= pLogEntry
->Rev
;
2451 CTGitPath path
= m_path
;
2453 // See how many files under the relative root were changed in selected revision
2455 LogChangedPath
* changed
= NULL
;
2456 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2458 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2459 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2466 if (m_path
.IsDirectory() && nChanged
== 1)
2468 // We're looking at the log for a directory and only one file under dir was changed in the revision
2469 // Do diff on that file instead of whole directory
2470 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2473 m_bCancelled
= FALSE
;
2474 DialogEnableWindow(IDOK
, FALSE
);
2475 SetPromptApp(&theApp
);
2476 theApp
.DoWaitCursor(1);
2480 GitDiff
diff(this, m_hWnd
, true);
2481 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2482 diff
.SetHEADPeg(m_LogRevision
);
2483 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2487 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2490 theApp
.DoWaitCursor(-1);
2495 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2497 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2500 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2502 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2504 if (pFindInfo
->lvfi
.psz
== 0)
2507 CString sCmp
= pFindInfo
->lvfi
.psz
;
2509 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2511 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2512 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2513 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2515 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2523 if (sCmp
.Compare(sRev
)==0)
2530 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2532 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2534 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2535 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2536 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2538 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2546 if (sCmp
.Compare(sRev
)==0)
2558 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2562 this->m_arShownList
.SafeRemoveAll();
2564 this->m_logEntries
.ClearAll();
2565 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2568 SetItemCountEx((int)m_logEntries
.size());
2570 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2574 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2575 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2580 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2581 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2593 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2597 m_arShownList
.SafeRemoveAll();
2599 m_logEntries
.ClearAll();
2600 if (m_logEntries
.Fill(hashes
))
2603 SetItemCountEx((int)m_logEntries
.size());
2605 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2609 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2610 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2614 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2615 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2624 int CGitLogListBase::BeginFetchLog()
2628 this->m_arShownList
.SafeRemoveAll();
2630 this->m_logEntries
.ClearAll();
2632 this->m_LogCache
.ClearAllParent();
2634 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2637 if(this->m_Path
.IsEmpty())
2643 mask
= CGit::LOG_INFO_ONLY_HASH
;
2644 if (m_bIncludeBoundaryCommits
)
2645 mask
|= CGit::LOG_INFO_BOUNDARY
;
2646 // if(this->m_bAllBranch)
2647 mask
|= m_ShowMask
;
2651 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2653 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2656 if (m_sRange
.IsEmpty())
2657 m_sRange
= _T("HEAD");
2659 #if 0 /* use tortoiegit filter */
2660 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2661 data
.m_Author
= this->m_sFilterText
;
2663 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2664 data
.m_MessageFilter
= this->m_sFilterText
;
2666 data
.m_IsRegex
= m_bFilterWithRegex
;
2669 // follow does not work for directories
2670 if (!path
|| path
->IsDirectory())
2671 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2672 // follow does not work with all branches 8at least in TGit)
2673 if (mask
& CGit::LOG_INFO_FOLLOW
)
2674 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2676 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &m_Filter
);
2678 //this->m_logEntries.ParserFromLog();
2679 if(IsInWorkingThread())
2681 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2685 SetItemCountEx((int)m_logEntries
.size());
2690 [] { git_init(); } ();
2695 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2699 if (!g_Git
.CanParseRev(m_sRange
))
2701 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2704 // if show all branches, pick any ref as dummy entry ref
2706 if (g_Git
.GetRefList(list
))
2707 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2708 if (list
.size() == 0)
2711 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &m_Filter
);
2714 g_Git
.m_critGitDllSec
.Lock();
2716 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2718 g_Git
.m_critGitDllSec
.Unlock();
2724 g_Git
.m_critGitDllSec
.Unlock();
2726 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2729 g_Git
.m_critGitDllSec
.Unlock();
2734 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2736 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2738 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2740 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2742 DiffSelectedRevWithPrevious();
2747 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2754 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2756 // select all entries
2757 for (int i
=0; i
<GetItemCount(); ++i
)
2759 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2765 if (m_hAccel
&& !bSkipAccelerator
)
2767 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2773 //m_tooltips.RelayEvent(pMsg);
2774 return __super::PreTranslateMessage(pMsg
);
2777 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2779 // a double click on an entry in the revision list has happened
2782 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2783 DiffSelectedRevWithPrevious();
2786 int CGitLogListBase::FetchLogAsync(void * data
)
2790 m_bExitThread
=FALSE
;
2791 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2792 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2793 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2794 if (m_LoadingThread
==NULL
)
2796 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2797 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2798 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2804 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2806 return ((CGitLogListBase
*)pVoid
)->LogThread();
2809 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2812 oldest
=CTime::GetCurrentTime();
2813 latest
=CTime(1971,1,2,0,0,0);
2814 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2816 if(m_logEntries
[i
].IsEmpty())
2819 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2820 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2822 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2823 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2831 UINT
CGitLogListBase::LogThread()
2833 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2835 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2836 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2842 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2843 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2848 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2849 bool bRegex
= false;
2850 if (m_bFilterWithRegex
)
2851 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2853 TRACE(_T("\n===Begin===\n"));
2854 //Update work copy item;
2856 if (!m_logEntries
.empty())
2858 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2860 m_arShownList
.SafeAdd(pRev
);
2864 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2866 // store commit number of the last selected commit/line before the refresh or -1
2867 int lastSelectedHashNItem
= -1;
2868 if (m_lastSelectedHash
.IsEmpty())
2869 lastSelectedHashNItem
= 0;
2873 bool shouldWalk
= true;
2874 if (!g_Git
.CanParseRev(m_sRange
))
2876 // walk revisions if show all branches and there exists any ref
2877 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2882 if (g_Git
.GetRefList(list
))
2883 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2884 if (list
.size() == 0)
2891 g_Git
.m_critGitDllSec
.Lock();
2895 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2896 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2901 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2904 g_Git
.m_critGitDllSec
.Unlock();
2907 t2
=t1
=GetTickCount();
2908 int oldprecentage
= 0;
2909 size_t oldsize
= m_logEntries
.size();
2910 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2911 while (ret
== 0 && !m_bExitThread
)
2913 g_Git
.m_critGitDllSec
.Lock();
2916 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2920 g_Git
.m_critGitDllSec
.Unlock();
2922 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2925 g_Git
.m_critGitDllSec
.Unlock();
2929 if (ret
!= -2) // other than end of revision walking
2930 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2934 if (commit
.m_ignore
== 1)
2936 git_free_commit(&commit
);
2940 //printf("%s\r\n",commit.GetSubject());
2944 CGitHash hash
= (char*)commit
.m_hash
;
2946 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2947 pRev
->m_GitCommit
= commit
;
2948 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2951 g_Git
.m_critGitDllSec
.Lock();
2954 git_get_notes(commit
.m_hash
, ¬e
);
2958 g_Git
.m_critGitDllSec
.Unlock();
2960 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2963 g_Git
.m_critGitDllSec
.Unlock();
2967 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2972 if(!pRev
->m_IsDiffFiles
)
2974 pRev
->m_CallDiffAsync
= DiffAsync
;
2977 pRev
->ParserParentFromCommit(&commit
);
2978 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2980 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2982 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2983 auto it
= commitChildren
.find(parentHash
);
2984 if (it
== commitChildren
.end())
2986 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2988 it
->second
.insert(pRev
->m_CommitHash
);
2997 bool visible
= true;
2998 if (HasFilterText())
3000 if(!IsMatchFilter(bRegex
,pRev
,pat
))
3003 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
3005 this->m_critSec
.Lock();
3006 m_logEntries
.append(hash
, visible
);
3008 m_arShownList
.SafeAdd(pRev
);
3009 this->m_critSec
.Unlock();
3014 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3015 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3019 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3022 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3025 if(percent
< GITLOG_START
)
3026 percent
= GITLOG_START
+1;
3028 oldsize
= m_logEntries
.size();
3029 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3031 //if( percent > oldprecentage )
3033 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3034 oldprecentage
= percent
;
3037 if (lastSelectedHashNItem
>= 0)
3038 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3043 g_Git
.m_critGitDllSec
.Lock();
3044 git_close_log(m_DllGitLog
);
3045 g_Git
.m_critGitDllSec
.Unlock();
3051 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3056 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3058 if (lastSelectedHashNItem
>= 0)
3059 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3062 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3064 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3069 void CGitLogListBase::FetchRemoteList()
3071 STRING_VECTOR remoteList
;
3072 if (!g_Git
.GetRemoteList(remoteList
))
3073 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3075 m_SingleRemote
= _T("");
3078 void CGitLogListBase::FetchTrackingBranchList()
3080 m_TrackingMap
.clear();
3081 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3083 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3086 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3088 CString pullRemote
, pullBranch
;
3089 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3090 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3092 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3099 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3101 SafeTerminateThread();
3103 this->SetItemCountEx(0);
3108 // HACK to hide graph column
3109 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3110 SetColumnWidth(0, 0);
3112 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3114 //Update branch and Tag info
3117 m_pFindDialog
->RefreshList();
3118 //Assume Thread have exited
3119 //if(!m_bThreadRunning)
3121 m_logEntries
.clear();
3125 m_sFilterText
.Empty();
3126 m_Filter
.m_From
= -1;
3130 InterlockedExchange(&m_bExitThread
,FALSE
);
3132 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3133 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3134 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3136 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3137 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3138 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3142 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3146 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3148 type
|= std::tr1::regex_constants::icase
;
3149 pat
= std::tr1::wregex(regexp_str
, type
);
3152 catch (std::exception
) {}
3155 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3158 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3161 if ((bRegex
)&&(m_bFilterWithRegex
))
3163 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3165 if(this->m_bShowBugtraqColumn
)
3167 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3169 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)sBugIds
);
3170 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3177 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3179 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetSubject());
3180 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3186 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3188 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetBody());
3189 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3195 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3197 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3202 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3208 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3210 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3215 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3221 if (m_SelectedFilters
& LOGFILTER_REVS
)
3223 sRev
= pRev
->m_CommitHash
.ToString();
3224 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3230 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3232 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3233 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3235 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3242 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3244 CTGitPathList
*pathList
=NULL
;
3245 if( pRev
->m_IsDiffFiles
)
3246 pathList
= &pRev
->GetFiles(this);
3249 if(!pRev
->m_IsSimpleListReady
)
3250 pRev
->SafeGetSimpleList(&g_Git
);
3254 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3256 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3260 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3266 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3268 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3277 CString find
= m_sFilterText
;
3278 if (!m_bFilterCaseSensitively
)
3280 result
= find
[0] == '!' ? FALSE
: TRUE
;
3284 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3286 if(this->m_bShowBugtraqColumn
)
3288 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3290 if (!m_bFilterCaseSensitively
)
3291 sBugIds
.MakeLower();
3292 if ((sBugIds
.Find(find
) >= 0))
3299 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3301 CString msg
= pRev
->GetSubject();
3303 if (!m_bFilterCaseSensitively
)
3304 msg
= msg
.MakeLower();
3305 if ((msg
.Find(find
) >= 0))
3311 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3313 CString msg
= pRev
->GetBody();
3315 if (!m_bFilterCaseSensitively
)
3316 msg
= msg
.MakeLower();
3317 if ((msg
.Find(find
) >= 0))
3323 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3325 CString msg
= pRev
->GetAuthorName();
3326 if (!m_bFilterCaseSensitively
)
3327 msg
= msg
.MakeLower();
3328 if ((msg
.Find(find
) >= 0))
3334 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3336 CString msg
= pRev
->GetAuthorEmail();
3337 if (!m_bFilterCaseSensitively
)
3338 msg
= msg
.MakeLower();
3339 if ((msg
.Find(find
) >= 0))
3345 if (m_SelectedFilters
& LOGFILTER_REVS
)
3347 sRev
= pRev
->m_CommitHash
.ToString();
3348 if ((sRev
.Find(find
) >= 0))
3354 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3356 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3357 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3359 if (it
->Find(find
) >= 0)
3366 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3368 CTGitPathList
*pathList
=NULL
;
3369 if( pRev
->m_IsDiffFiles
)
3370 pathList
= &pRev
->GetFiles(this);
3373 if(!pRev
->m_IsSimpleListReady
)
3374 pRev
->SafeGetSimpleList(&g_Git
);
3377 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3379 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3380 CString path
= cpath
->GetGitOldPathString();
3381 if (!m_bFilterCaseSensitively
)
3383 if ((path
.Find(find
)>=0))
3387 path
= cpath
->GetGitPathString();
3388 if (!m_bFilterCaseSensitively
)
3390 if ((path
.Find(find
)>=0))
3396 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3398 CString path
= pRev
->m_SimpleFileList
[i
];
3399 if (!m_bFilterCaseSensitively
)
3401 if ((path
.Find(find
)>=0))
3407 } // else (from if (bRegex))
3411 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3413 return str
.Left(prefix
.GetLength()) == prefix
;
3415 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
)
3417 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3420 if (m_ShowFilter
& FILTERSHOW_REFS
)
3423 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3424 for (size_t i
= 0; i
< refList
.size(); ++i
)
3426 const CString
&str
= refList
[i
];
3427 if (CStringStartsWith(str
, _T("refs/heads/")))
3429 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3432 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3434 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3437 else if (CStringStartsWith(str
, _T("refs/tags/")))
3439 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3442 else if (CStringStartsWith(str
, _T("refs/stash")))
3444 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3447 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3449 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3453 // Keep the head too.
3454 if (pRev
->m_CommitHash
== m_HeadHash
)
3458 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3460 if (pRev
->ParentsCount() > 1)
3462 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3463 if (childrenIt
!= commitChildren
.end())
3465 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3466 if (children
.size() > 1)
3473 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3475 // HACK to hide graph column
3477 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3479 SetColumnWidth(0, 0);
3482 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3487 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3489 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3490 for (size_t i
= 0; i
< vector
.size(); ++i
)
3492 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3494 CString tag
= vector
[i
];
3495 int start
= vector
[i
].Find(_T("^{}"));
3497 tag
= tag
.Left(start
);
3501 cmd
.Format(_T("git.exe cat-file tag %s"), (LPCTSTR
)tag
);
3502 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3503 output
.AppendChar(_T('\n'));
3511 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3514 pShownlist
->SafeRemoveAll();
3516 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3517 bool bRegex
= false;
3518 if (m_bFilterWithRegex
)
3519 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3521 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3523 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3525 if ((bRegex
)&&(m_bFilterWithRegex
))
3528 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3530 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3531 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3533 pShownlist
->SafeAdd(m_logEntries
[i
]);
3538 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3540 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3541 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3543 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3547 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3549 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3550 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3552 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3556 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3558 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3561 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3563 CTGitPath cpath
= pathList
[cpPathIndex
];
3564 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3566 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3570 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3572 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3576 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3578 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3584 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3586 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3588 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3592 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3594 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3596 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3600 if (m_SelectedFilters
& LOGFILTER_REVS
)
3602 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3603 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3605 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3609 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3611 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3612 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3614 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3616 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3624 CString find
= m_sFilterText
;
3625 if (!m_bFilterCaseSensitively
)
3628 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3630 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3632 if (!m_bFilterCaseSensitively
)
3633 sBugIDs
= sBugIDs
.MakeLower();
3634 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3636 pShownlist
->SafeAdd(m_logEntries
[i
]);
3641 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3643 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3645 if (!m_bFilterCaseSensitively
)
3646 msg
= msg
.MakeLower();
3647 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3649 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3653 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3655 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3657 if (!m_bFilterCaseSensitively
)
3658 msg
= msg
.MakeLower();
3659 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3661 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3665 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3667 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3670 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3672 CTGitPath cpath
= pathList
[cpPathIndex
];
3673 CString path
= cpath
.GetGitOldPathString();
3674 if (!m_bFilterCaseSensitively
)
3676 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3678 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3682 path
= cpath
.GetGitPathString();
3683 if (!m_bFilterCaseSensitively
)
3685 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3687 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3691 path
= cpath
.GetActionName();
3692 if (!m_bFilterCaseSensitively
)
3694 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3696 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3702 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3704 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3705 if (!m_bFilterCaseSensitively
)
3706 msg
= msg
.MakeLower();
3707 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3709 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3713 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3715 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3716 if (!m_bFilterCaseSensitively
)
3717 msg
= msg
.MakeLower();
3718 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3720 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3724 if (m_SelectedFilters
& LOGFILTER_REVS
)
3726 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3727 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3729 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3733 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3735 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3736 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3738 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3740 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3745 } // else (from if (bRegex))
3746 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3750 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3753 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3759 return time <= m_To;
3762 return time >= m_From;
3764 return ((time >= m_From)&&(time <= m_To));
3766 return TRUE
; /* git dll will filter time range */
3770 void CGitLogListBase::StartFilter()
3772 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3773 RecalculateShownList(&m_arShownList
);
3774 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3778 SetItemCountEx(ShownCountWithStopped());
3779 RedrawItems(0, ShownCountWithStopped());
3783 void CGitLogListBase::RemoveFilter()
3786 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3788 m_arShownList
.SafeRemoveAll();
3790 // reset the time filter too
3792 m_timFrom
= (__time64_t(m_tFrom
));
3793 m_timTo
= (__time64_t(m_tTo
));
3794 m_DateFrom
.SetTime(&m_timFrom
);
3795 m_DateTo
.SetTime(&m_timTo
);
3796 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3797 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3800 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3802 if(this->m_IsOldFirst
)
3804 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3808 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3811 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3813 SetItemCountEx(ShownCountWithStopped());
3814 RedrawItems(0, ShownCountWithStopped());
3816 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3819 void CGitLogListBase::Clear()
3821 m_arShownList
.SafeRemoveAll();
3824 m_logEntries
.ClearAll();
3828 void CGitLogListBase::OnDestroy()
3830 // save the column widths to the registry
3833 SafeTerminateThread();
3834 SafeTerminateAsyncDiffThread();
3837 while(m_LogCache
.SaveCache())
3845 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3846 // MB_YESNO) == IDNO)
3850 CHintListCtrl::OnDestroy();
3853 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3857 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3858 this->InvalidateRect(rect
);
3864 * Save column widths to the registry
3866 void CGitLogListBase::SaveColumnWidths()
3868 int maxcol
= m_ColumnManager
.GetColumnCount();
3870 // HACK that graph column is always shown
3871 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3873 for (int col
= 0; col
< maxcol
; ++col
)
3874 if (m_ColumnManager
.IsVisible (col
))
3875 m_ColumnManager
.ColumnResized (col
);
3877 m_ColumnManager
.WriteSettings();
3880 int CGitLogListBase::GetHeadIndex()
3882 if(m_HeadHash
.IsEmpty())
3885 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3887 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3890 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3896 void CGitLogListBase::OnFind()
3900 m_pFindDialog
= new CFindDlg(this);
3901 m_pFindDialog
->Create(this);
3904 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3906 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3908 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3910 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3913 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3915 if (GetSelectedCount() != 0)
3918 CGitHash theSelectedHash
= m_lastSelectedHash
;
3919 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3920 m_lastSelectedHash
= theSelectedHash
;
3922 int countPerPage
= GetCountPerPage();
3923 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3924 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3925 EnsureVisible((int)itemToSelect
, FALSE
);
3928 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3931 ASSERT(m_pFindDialog
!= NULL
);
3932 bool bFound
= false;
3935 if (m_pFindDialog
->IsTerminating())
3937 // invalidate the handle identifying the dialog box.
3938 m_pFindDialog
= NULL
;
3942 INT_PTR cnt
= m_arShownList
.GetCount();
3944 if(m_pFindDialog
->IsRef())
3947 str
=m_pFindDialog
->GetFindString();
3953 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3954 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3959 for (i
= 0; i
< cnt
; ++i
)
3961 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3962 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3971 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3976 if (m_pFindDialog
->FindNext() && !bFound
)
3978 //read data from dialog
3979 CString findText
= m_pFindDialog
->GetFindString();
3980 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3982 std::tr1::wregex pat
;
3983 bool bRegex
= false;
3984 if (m_pFindDialog
->Regex())
3985 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3987 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3989 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3994 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3996 if (m_nSearchIndex
>= 0)
3998 if (i
== m_nSearchIndex
)
4000 ::MessageBeep(0xFFFFFFFF);
4001 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4006 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
4009 str
+=pLogEntry
->m_CommitHash
.ToString();
4012 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4014 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4018 str
+=pLogEntry
->GetAuthorEmail();
4020 str
+=pLogEntry
->GetAuthorName();
4022 str
+=pLogEntry
->GetBody();
4024 str
+=pLogEntry
->GetCommitterEmail();
4026 str
+=pLogEntry
->GetCommitterName();
4028 str
+=pLogEntry
->GetSubject();
4030 str
+=pLogEntry
->m_Notes
;
4032 str
+=GetTagInfo(pLogEntry
);
4036 /*Because changed files list is loaded on demand when gui show,
4037 files will empty when files have not fetched.
4039 we can add it back by using one-way diff(with outnumber changed and rename detect.
4040 here just need changed filename list. one-way is much quicker.
4042 if(pLogEntry
->m_IsFull
)
4044 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4046 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4048 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4054 if(!pLogEntry
->m_IsSimpleListReady
)
4055 pLogEntry
->SafeGetSimpleList(&g_Git
);
4057 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4059 str
+= pLogEntry
->m_SimpleFileList
[j
];
4068 if (std::regex_search(std::wstring(str
), pat
, flags
))
4078 if (str
.Find(findText
) >= 0)
4088 msg
= msg
.MakeLower();
4089 CString find
= findText
.MakeLower();
4090 if (msg
.Find(find
) >= 0)
4097 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4099 } // if(m_pFindDialog->FindNext())
4100 //UpdateLogInfoLabel();
4105 EnsureVisible(i
, FALSE
);
4106 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4108 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4109 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4110 SetSelectionMark(i
);
4114 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4116 m_highlight
= pLogEntry
->m_CommitHash
;
4119 //FillLogMessageCtrl();
4126 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4128 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4133 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4135 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4140 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4142 LVHITTESTINFO lvhitTestInfo
;
4144 lvhitTestInfo
.pt
= point
;
4146 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4147 int nSubItem
= lvhitTestInfo
.iSubItem
;
4149 UINT nFlags
= lvhitTestInfo
.flags
;
4151 // nFlags is 0 if the SubItemHitTest fails
4152 // Therefore, 0 & <anything> will equal false
4153 if (nFlags
& LVHT_ONITEM
)
4155 // Get the client area occupied by this control
4157 GetClientRect(&rcClient
);
4159 // Fill in the TOOLINFO structure
4161 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4162 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4163 pTI
->rect
= rcClient
;
4165 return pTI
->uId
; // By returning a unique value per listItem,
4166 // we ensure that when the mouse moves over another list item,
4167 // the tooltip will change
4171 // Otherwise, we aren't interested, so let the message propagate
4176 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4178 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4179 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4183 // Ignore messages from the built in tooltip, we are processing them internally
4184 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4185 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4186 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4189 // Get the mouse position
4190 const MSG
* pMessage
= GetCurrentMessage();
4194 ScreenToClient(&pt
);
4196 // Check if the point falls onto a list item
4197 LVHITTESTINFO lvhitTestInfo
;
4198 lvhitTestInfo
.pt
= pt
;
4200 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4202 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4204 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4205 if (strTipText
.IsEmpty())
4208 // we want multiline tooltips
4209 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4211 wcscpy_s(m_wszTip
, strTipText
);
4212 // handle Unicode as well as non-Unicode requests
4213 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4215 pTTTA
->hinst
= nullptr;
4216 pTTTA
->lpszText
= m_szTip
;
4217 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4221 pTTTW
->hinst
= nullptr;
4222 pTTTW
->lpszText
= m_wszTip
;
4226 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4227 ClientToScreen(rect
);
4228 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4230 return TRUE
; // We found a tool tip,
4231 // tell the framework this message has been handled
4234 return FALSE
; // We didn't handle the message,
4235 // let the framework continue propagating the message
4238 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4240 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4242 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4243 if (pLogEntry
== nullptr)
4245 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4247 return pLogEntry
->GetSubject();
4249 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4251 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4252 if (pLogEntry
== nullptr)
4254 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4256 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4258 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4259 if (pLogEntry
== nullptr)
4261 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4263 else if (nSubItem
== LOGLIST_ACTION
)
4265 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4266 if (pLogEntry
== nullptr)
4269 if (!pLogEntry
->m_IsDiffFiles
)
4270 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4272 int actions
= pLogEntry
->GetAction(this);
4273 CString sToolTipText
;
4276 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4277 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4279 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4281 if (!actionText
.IsEmpty())
4282 actionText
+= L
"\r\n";
4283 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4286 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4288 if (!actionText
.IsEmpty())
4289 actionText
+= L
"\r\n";
4290 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4293 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4295 if (!actionText
.IsEmpty())
4296 actionText
+= L
"\r\n";
4297 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4300 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4302 if (!actionText
.IsEmpty())
4303 actionText
+= L
"\r\n";
4304 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4307 if (!actionText
.IsEmpty())
4309 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4310 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4312 return sToolTipText
;