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"
29 #include "GitProgressDlg.h"
30 #include "ProgressDlg.h"
32 #include "MessageBox.h"
34 #include "LoglistUtils.h"
35 #include "PathUtils.h"
36 #include "StringUtils.h"
37 #include "UnicodeUtils.h"
40 #include "GitStatus.h"
41 #include "..\\TortoiseShell\\Resource.h"
45 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
46 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
47 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
49 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
51 CGitLogListBase::CGitLogListBase():CHintListCtrl()
52 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
54 ,m_bNoDispUpdates(FALSE
)
55 , m_bThreadRunning(FALSE
)
56 , m_bStrictStopped(false)
57 , m_pStoreSelection(NULL
)
58 , m_SelectedFilters(LOGFILTER_ALL
)
59 , m_ShowFilter(FILTERSHOW_ALL
)
61 , m_logEntries(&m_LogCache
)
63 , m_ColumnManager(this)
64 , m_dwDefaultColumns(0)
65 , m_arShownList(&m_critSec
)
67 , m_bNoHightlightHead(FALSE
)
68 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
70 // use the default GUI font, create a copy of it and
71 // change the copy to BOLD (leave the rest of the font
73 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
75 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
76 lf
.lfWeight
= FW_BOLD
;
77 m_boldFont
= CreateFontIndirect(&lf
);
78 lf
.lfWeight
= FW_DONTCARE
;
80 m_FontItalics
= CreateFontIndirect(&lf
);
81 lf
.lfWeight
= FW_BOLD
;
82 m_boldItalicsFont
= CreateFontIndirect(&lf
);
84 m_bShowBugtraqColumn
=false;
86 m_IsIDReplaceAction
=FALSE
;
88 this->m_critSec
.Init();
89 m_critSec_AsyncDiff
.Init();
90 m_wcRev
.m_CommitHash
.Empty();
91 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
92 m_wcRev
.m_ParentHash
.clear();
93 m_wcRev
.m_Mark
=_T('-');
94 m_wcRev
.m_IsUpdateing
=FALSE
;
95 m_wcRev
.m_IsFull
= TRUE
;
97 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
98 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
99 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
100 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
101 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
103 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE
);
104 m_bFilterCaseSensitively
= !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE
);
110 m_LoadingThread
= NULL
;
112 InterlockedExchange(&m_bExitThread
,FALSE
);
113 m_IsOldFirst
= FALSE
;
114 m_IsRebaseReplaceGraph
= FALSE
;
116 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
118 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
120 // get short/long datetime setting from registry
121 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
122 if ( RegUseShortDateFormat
)
124 m_DateFormat
= DATE_SHORTDATE
;
128 m_DateFormat
= DATE_LONGDATE
;
130 // get relative time display setting from registry
131 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
132 m_bRelativeTimes
= (regRelativeTimes
!= 0);
133 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
135 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
136 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
137 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
138 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
139 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
140 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
141 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
143 m_ColumnRegKey
=_T("log");
145 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
146 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
147 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
149 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
150 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
152 m_AsyncThreadExit
= FALSE
;
153 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
154 m_AsynDiffListLock
.Init();
156 hUxTheme
= AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
158 pfnDrawThemeTextEx
= (FNDRAWTHEMETEXTEX
)::GetProcAddress(hUxTheme
, "DrawThemeTextEx");
160 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
161 if (m_DiffingThread
==NULL
)
163 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
169 int CGitLogListBase::AsyncDiffThread()
171 m_AsyncThreadExited
= false;
172 while(!m_AsyncThreadExit
)
174 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
177 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
179 m_AsynDiffListLock
.Lock();
180 pRev
= m_AsynDiffList
.back();
181 m_AsynDiffList
.pop_back();
182 m_AsynDiffListLock
.Unlock();
184 if( pRev
->m_CommitHash
.IsEmpty() )
186 if(pRev
->m_IsDiffFiles
)
189 pRev
->GetFiles(this).Clear();
190 pRev
->m_ParentHash
.clear();
191 pRev
->m_ParentHash
.push_back(m_HeadHash
);
192 if(g_Git
.IsInitRepos())
194 if (g_Git
.GetInitAddList(pRev
->GetFiles(this)))
195 CMessageBox::Show(NULL
, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
200 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
203 int *action
= &dummyAction
;
204 SafeGetAction(pRev
, &action
);
207 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
208 *action
|= pRev
->GetFiles(this)[j
].m_Action
;
211 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
213 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
217 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
218 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
220 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
221 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
222 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
225 m_critSec_AsyncDiff
.Lock();
226 int ret
= pRev
->CheckAndDiff();
227 m_critSec_AsyncDiff
.Unlock();
229 { // fetch change file list
230 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
232 if(i
< m_arShownList
.GetCount())
234 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
235 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
237 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
243 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
245 POSITION pos
= GetFirstSelectedItemPosition();
246 int nItem
= GetNextSelectedItem(pos
);
250 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
252 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
254 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
261 m_AsyncThreadExited
= true;
264 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
268 m_ContextMenuMask
&= hideMask
;
272 m_ContextMenuMask
&= ~hideMask
;
276 CGitLogListBase::~CGitLogListBase()
278 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
279 this->m_arShownList
.SafeRemoveAll();
281 DestroyIcon(m_hModifiedIcon
);
282 DestroyIcon(m_hReplacedIcon
);
283 DestroyIcon(m_hAddedIcon
);
284 DestroyIcon(m_hDeletedIcon
);
285 m_logEntries
.ClearAll();
288 DeleteObject(m_boldFont
);
291 DeleteObject(m_FontItalics
);
293 if (m_boldItalicsFont
)
294 DeleteObject(m_boldItalicsFont
);
296 if ( m_pStoreSelection
)
298 delete m_pStoreSelection
;
299 m_pStoreSelection
= NULL
;
302 SafeTerminateThread();
303 SafeTerminateAsyncDiffThread();
306 CloseHandle(m_AsyncDiffEvent
);
309 FreeLibrary(hUxTheme
);
313 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
314 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
315 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
316 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
317 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
319 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
320 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
323 ON_MESSAGE(MSG_LOADED
,OnLoad
)
325 ON_WM_MEASUREITEM_REFLECT()
326 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
327 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
328 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
329 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
330 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
331 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
332 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
333 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
336 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
338 //if (m_nRowHeight>0)
340 lpMeasureItemStruct
->itemHeight
= 50;
344 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
347 return CHintListCtrl::OnCreate(lpCreateStruct
);
350 void CGitLogListBase::PreSubclassWindow()
352 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
353 // load the icons for the action columns
354 // m_Theme.Open(m_hWnd, L"ListView");
355 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
356 CHintListCtrl::PreSubclassWindow();
359 CString
CGitLogListBase::GetRebaseActionName(int action
)
361 if (action
& LOGACTIONS_REBASE_EDIT
)
362 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
363 if (action
& LOGACTIONS_REBASE_SQUASH
)
364 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
365 if (action
& LOGACTIONS_REBASE_PICK
)
366 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
367 if (action
& LOGACTIONS_REBASE_SKIP
)
368 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
370 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
373 void CGitLogListBase::InsertGitColumn()
377 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
378 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
379 if (DWORD(regFullRowSelect
))
380 exStyle
|= LVS_EX_FULLROWSELECT
;
381 SetExtendedStyle(exStyle
);
383 // only load properties if we have a repository
384 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
385 UpdateProjectProperties();
387 static UINT normal
[] =
399 IDS_LOG_COMMIT_EMAIL
,
422 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
424 DWORD hideColumns
= 0;
425 if(this->m_IsRebaseReplaceGraph
)
427 hideColumns
|= GIT_LOG_GRAPH
;
428 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
432 hideColumns
|= GIT_LOG_REBASE
;
435 if(this->m_IsIDReplaceAction
)
437 hideColumns
|= GIT_LOG_ACTIONS
;
438 m_dwDefaultColumns
|= GIT_LOG_ID
;
439 m_dwDefaultColumns
|= GIT_LOG_HASH
;
443 hideColumns
|= GIT_LOG_ID
;
445 if(this->m_bShowBugtraqColumn
)
447 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
451 hideColumns
|= GIT_LOGLIST_BUG
;
453 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
454 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
456 hideColumns
|= GIT_LOGLIST_SVNREV
;
459 m_ColumnManager
.SetNames(normal
, _countof(normal
));
460 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
466 * Resizes all columns in a list control to values in registry.
468 void CGitLogListBase::ResizeAllListCtrlCols()
470 // column max and min widths to allow
471 static const int nMinimumWidth
= 10;
472 static const int nMaximumWidth
= 1000;
473 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
476 int numcols
= pHdrCtrl
->GetItemCount();
477 for (int col
= 0; col
< numcols
; ++col
)
479 // get width for this col last time from registry
481 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
482 CRegDWORD
regwidth(regentry
, 0);
486 // no saved value, setup sensible defaults
487 if (col
== this->LOGLIST_MESSAGE
)
489 cx
= LOGLIST_MESSAGE_MIN
;
493 cx
= ICONITEMBORDER
+16*4;
496 if (cx
< nMinimumWidth
)
500 else if (cx
> nMaximumWidth
)
505 SetColumnWidth(col
, cx
);
512 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
515 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
516 rItem
.mask
= LVIF_STATE
;
517 rItem
.iItem
= (int)Index
;
518 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
521 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
524 if (!(rItem
.state
& LVIS_SELECTED
))
526 int action
= pLogEntry
->GetRebaseAction();
527 if (action
& LOGACTIONS_REBASE_SQUASH
)
528 brush
= ::CreateSolidBrush(RGB(156,156,156));
529 else if (action
& LOGACTIONS_REBASE_EDIT
)
530 brush
= ::CreateSolidBrush(RGB(200,200,128));
532 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
534 if (rItem
.state
& LVIS_SELECTED
)
536 if (::GetFocus() == m_hWnd
)
537 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
539 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
544 ::FillRect(hdc
, &rect
, brush
);
545 ::DeleteObject(brush
);
549 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
551 POINT point
= { 4, 4 };
553 rt2
.DeflateRect(1, 1);
554 rt2
.OffsetRect(2, 2);
556 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
557 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
558 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
559 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
560 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
562 ::SelectObject(hdc
, brush
);
563 rt2
.OffsetRect(-2, -2);
564 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
565 ::SelectObject(hdc
, oldbrush
);
566 ::SelectObject(hdc
, oldpen
);
567 ::DeleteObject(nullPen
);
568 ::DeleteObject(darkBrush
);
571 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
573 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
574 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
575 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
576 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
577 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
578 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
579 ::SelectObject(hdc
, oldpen
);
583 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
585 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
586 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
587 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
588 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
589 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
590 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
591 ::SelectObject(hdc
, oldpen
);
595 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
597 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
600 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
601 rItem
.mask
= LVIF_STATE
;
602 rItem
.iItem
= (int)index
;
603 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
609 HTHEME hTheme
= NULL
;
610 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
611 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
614 if (m_bTagsBranchesOnRightSide
)
616 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
617 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
618 SelectObject(hdc
, oldFont
);
619 rt
.left
+= oneSpaceSize
.cx
* 2;
623 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
624 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
625 rt
.left
+= oneSpaceSize
.cx
;
628 int action
= data
->GetRebaseAction();
629 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
630 if (IsAppThemed() && pfnDrawThemeTextEx
)
632 int txtState
= LISS_NORMAL
;
633 if (rItem
.state
& LVIS_SELECTED
)
634 txtState
= LISS_SELECTED
;
636 DTTOPTS opts
= { 0 };
637 opts
.dwSize
= sizeof(opts
);
638 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
639 opts
.dwFlags
= DTT_TEXTCOLOR
;
640 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
644 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
646 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
647 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
648 ::SetTextColor(hdc
, clrOld
);
652 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
653 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
654 ::SetTextColor(hdc
, clrOld
);
658 if (m_bTagsBranchesOnRightSide
)
661 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
663 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
665 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
669 CloseThemeData(hTheme
);
674 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
)
676 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
678 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
680 COLORREF colRef
= refList
[i
].color
;
681 bool singleRemote
= refList
[i
].singleRemote
;
682 bool hasTracking
= refList
[i
].hasTracking
;
683 bool sameName
= refList
[i
].sameName
;
684 bool annotatedTag
= refList
[i
].annotatedTag
;
686 //When row selected, ajust label color
687 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
689 if (rItem
.state
& LVIS_SELECTED
)
690 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
693 brush
= ::CreateSolidBrush(colRef
);
695 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
698 memset(&size
,0,sizeof(SIZE
));
699 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
701 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
704 int textpos
= DT_CENTER
;
706 if (rt
.right
> rect
.right
)
708 rt
.right
= rect
.right
;
717 textRect
.OffsetRect(8, 0);
725 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
729 //Fill interior of ref label
730 ::FillRect(hdc
, &rt
, brush
);
738 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
739 rectEdge
.DeflateRect(1, 1);
740 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
746 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
747 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
748 ::FillRgn(hdc
, hrgn
, brush
);
749 ::DeleteObject(hrgn
);
750 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
752 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
753 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
755 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
756 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
758 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
759 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
760 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
762 SelectObject(hdc
, oldpen
);
765 //Draw text inside label
766 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
767 if (!customColor
&& IsAppThemed() && pfnDrawThemeTextEx
)
769 int txtState
= LISS_NORMAL
;
770 if (rItem
.state
& LVIS_SELECTED
)
771 txtState
= LISS_SELECTED
;
773 DTTOPTS opts
= { 0 };
774 opts
.dwSize
= sizeof(opts
);
775 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
776 opts
.dwFlags
= DTT_TEXTCOLOR
;
777 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
781 W_Dc
.SetBkMode(TRANSPARENT
);
782 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
784 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
785 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
786 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
787 ::SetTextColor(hdc
,clrOld
);
791 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
792 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
793 ::SetTextColor(hdc
, clrOld
);
799 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
800 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
802 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
803 DrawLightning(hdc
, newRect
, color
, bold
);
808 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
809 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
811 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
812 DrawUpTriangle(hdc
, newRect
, color
, bold
);
815 rt
.left
= rt
.right
+ 1;
818 ::DeleteObject(brush
);
820 rt
.right
= rect
.right
;
823 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
825 // Returns ((256 - amount)*col1 + amount*col2) / 256;
826 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
827 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
828 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
831 Gdiplus::Color
GetGdiColor(COLORREF col
)
833 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
835 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
836 const COLORREF
& col
,const COLORREF
& activeColor
, int top
839 int h
= laneHeight
/ 2;
840 int m
= (x1
+ x2
) / 2;
841 int r
= (x2
- x1
) * m_NodeSize
/ 30;
844 #define P_CENTER m , h+top
845 #define P_0 x2, h+top
846 #define P_90 m , 0+top-1
847 #define P_180 x1, h+top
848 #define P_270 m , 2 * h+top +1
849 #define R_CENTER m - r, h - r+top, d, d
852 #define DELTA_UR_B 2*(x1 - m), 2*h +top
853 #define DELTA_UR_E 0*16, 90*16 +top // -,
855 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
856 #define DELTA_DR_E 270*16, 90*16 +top // -'
858 #define DELTA_UL_B 2*(x2 - m), 2*h +top
859 #define DELTA_UL_E 90*16, 90*16 +top // ,-
861 #define DELTA_DL_B 2*(x2 - m),2*-h +top
862 #define DELTA_DL_E 180*16, 90*16 // '-
864 #define CENTER_UR x1, 2*h, 225
865 #define CENTER_DR x1, 0 , 135
866 #define CENTER_UL x2, 2*h, 315
867 #define CENTER_DL x2, 0 , 45
870 Gdiplus::Graphics
graphics( hdc
);
872 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
881 Gdiplus::LinearGradientBrush
gradient(
882 Gdiplus::Point(x1
-2, h
+top
-2),
883 Gdiplus::Point(P_270
),
884 GetGdiColor(activeColor
),GetGdiColor(col
));
887 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
888 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
890 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
891 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
892 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
899 Gdiplus::LinearGradientBrush
gradient(
900 Gdiplus::Point(P_270
),
901 Gdiplus::Point(x2
+1, h
+top
-1),
902 GetGdiColor(col
),GetGdiColor(activeColor
));
905 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
906 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
908 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
909 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
910 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
919 Gdiplus::LinearGradientBrush
gradient(
920 Gdiplus::Point(x1
-2, h
+top
-2),
921 Gdiplus::Point(P_90
),
922 GetGdiColor(activeColor
),GetGdiColor(col
));
924 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
926 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
929 QConicalGradient
gradient(CENTER_DR
);
930 gradient
.setColorAt(0.375, activeCol
);
931 gradient
.setColorAt(0.625, col
);
932 myPen
.setBrush(gradient
);
934 p
->drawArc(P_CENTER
, DELTA_DR
);
943 //static QPen myPen(Qt::black, 2); // fast path here
945 pen
.CreatePen(PS_SOLID
,2,col
);
946 //myPen.setColor(col);
947 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
949 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
951 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
958 case Lanes::NOT_ACTIVE
:
959 case Lanes::MERGE_FORK
:
960 case Lanes::MERGE_FORK_R
:
961 case Lanes::MERGE_FORK_L
:
966 //DrawLine(hdc,P_90,P_270);
967 graphics
.DrawLine(&myPen
,P_90
,P_270
);
968 //p->drawLine(P_90, P_270);
972 //DrawLine(hdc,P_CENTER,P_270);
973 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
974 //p->drawLine(P_CENTER, P_270);
978 case Lanes::BOUNDARY
:
979 case Lanes::BOUNDARY_C
:
980 case Lanes::BOUNDARY_R
:
981 case Lanes::BOUNDARY_L
:
982 //DrawLine(hdc,P_90, P_CENTER);
983 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
984 //p->drawLine(P_90, P_CENTER);
990 myPen
.SetColor(GetGdiColor(activeColor
));
994 case Lanes::MERGE_FORK
:
999 case Lanes::CROSS_EMPTY
:
1000 case Lanes::BOUNDARY_C
:
1001 //DrawLine(hdc,P_180,P_0);
1002 graphics
.DrawLine(&myPen
,P_180
,P_0
);
1003 //p->drawLine(P_180, P_0);
1005 case Lanes::MERGE_FORK_R
:
1006 case Lanes::BOUNDARY_R
:
1007 //DrawLine(hdc,P_180,P_CENTER);
1008 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
1009 //p->drawLine(P_180, P_CENTER);
1011 case Lanes::MERGE_FORK_L
:
1014 case Lanes::BOUNDARY_L
:
1015 //DrawLine(hdc,P_CENTER,P_0);
1016 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
1017 //p->drawLine(P_CENTER, P_0);
1023 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1026 brush
.CreateSolidBrush(col
);
1027 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1029 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1030 // center symbol, e.g. rect or ellipse
1033 case Lanes::INITIAL
:
1036 //p->setPen(Qt::NoPen);
1038 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1039 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1040 //p->drawEllipse(R_CENTER);
1042 case Lanes::MERGE_FORK
:
1043 case Lanes::MERGE_FORK_R
:
1044 case Lanes::MERGE_FORK_L
:
1045 //p->setPen(Qt::NoPen);
1047 //p->drawRect(R_CENTER);
1048 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1049 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1051 case Lanes::UNAPPLIED
:
1053 //p->setPen(Qt::NoPen);
1054 //p->setBrush(Qt::red);
1055 //p->drawRect(m - r, h - 1, d, 2);
1056 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1057 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1059 case Lanes::APPLIED
:
1061 //p->setPen(Qt::NoPen);
1062 //p->setBrush(DARK_GREEN);
1063 //p->drawRect(m - r, h - 1, d, 2);
1064 //p->drawRect(m - 1, h - r, 2, d);
1065 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1066 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1067 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1069 case Lanes::BOUNDARY
:
1070 //p->setBrush(back);
1071 //p->drawEllipse(R_CENTER);
1072 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1073 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1075 case Lanes::BOUNDARY_C
:
1076 case Lanes::BOUNDARY_R
:
1077 case Lanes::BOUNDARY_L
:
1078 //p->setBrush(back);
1079 //p->drawRect(R_CENTER);
1080 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1081 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1087 ::SelectObject(hdc
,oldpen
);
1088 ::SelectObject(hdc
,oldbrush
);
1097 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1101 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1102 if(data
->m_CommitHash
.IsEmpty())
1107 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1108 rItem
.mask
= LVIF_STATE
;
1109 rItem
.iItem
= (int)index
;
1110 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1113 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1115 if (data
->m_Lanes
.empty())
1116 m_logEntries
.setLane(data
->m_CommitHash
);
1118 std::vector
<int>& lanes
=data
->m_Lanes
;
1119 size_t laneNum
= lanes
.size();
1120 UINT activeLane
= 0;
1121 for (UINT i
= 0; i
< laneNum
; ++i
)
1122 if (Lanes::isMerge(lanes
[i
])) {
1128 int maxWidth
= rect
.Width();
1129 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1131 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1132 //if (opt.state & QStyle::State_Selected)
1133 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1135 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1142 if (ln
== Lanes::EMPTY
)
1145 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1146 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1150 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1156 if (ln
== Lanes::EMPTY
)
1159 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1160 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1162 if (ln
== Lanes::CROSS
)
1164 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1165 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1168 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1174 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1177 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1178 // Take the default processing unless we set this to something else below.
1179 *pResult
= CDRF_DODEFAULT
;
1181 if (m_bNoDispUpdates
)
1184 switch (pLVCD
->nmcd
.dwDrawStage
)
1188 *pResult
= CDRF_NOTIFYITEMDRAW
;
1192 case CDDS_ITEMPREPAINT
:
1194 // This is the prepaint stage for an item. Here's where we set the
1195 // item's text color.
1197 // Tell Windows to send draw notifications for each subitem.
1198 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1200 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1202 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1204 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1207 HGDIOBJ hGdiObj
= nullptr;
1208 int action
= data
->GetRebaseAction();
1209 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1210 crText
= RGB(128,128,128);
1212 if (action
& LOGACTIONS_REBASE_SQUASH
)
1213 pLVCD
->clrTextBk
= RGB(156,156,156);
1214 else if (action
& LOGACTIONS_REBASE_EDIT
)
1215 pLVCD
->clrTextBk
= RGB(200,200,128);
1217 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1219 if (action
& LOGACTIONS_REBASE_CURRENT
)
1220 hGdiObj
= m_boldFont
;
1222 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1223 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1224 if (isHeadHash
&& isHighlight
)
1225 hGdiObj
= m_boldItalicsFont
;
1226 else if (isHeadHash
)
1227 hGdiObj
= m_boldFont
;
1228 else if (isHighlight
)
1229 hGdiObj
= m_FontItalics
;
1233 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1234 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1237 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1238 // crText = GetSysColor(COLOR_GRAYTEXT);
1240 if (data
->m_CommitHash
.IsEmpty())
1242 //crText = GetSysColor(RGB(200,200,0));
1243 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1244 // We changed the font, so we're returning CDRF_NEWFONT. This
1245 // tells the control to recalculate the extent of the text.
1246 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1250 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1252 if (m_bStrictStopped
)
1253 crText
= GetSysColor(COLOR_GRAYTEXT
);
1255 // Store the color back in the NMLVCUSTOMDRAW struct.
1256 pLVCD
->clrText
= crText
;
1260 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1262 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1264 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1267 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1269 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1272 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1274 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1275 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1277 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1278 if( !data
->m_CommitHash
.IsEmpty())
1279 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1281 *pResult
= CDRF_SKIPDEFAULT
;
1286 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1288 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1290 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1292 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1295 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1297 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1298 // not in FillBackGround method, because this only affected the message subitem
1299 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1302 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1303 int state
= GetItemState(index
, LVIS_SELECTED
);
1304 int txtState
= LISS_NORMAL
;
1305 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1307 if (state
& LVIS_SELECTED
)
1308 txtState
= LISS_HOTSELECTED
;
1310 txtState
= LISS_HOT
;
1312 else if (state
& LVIS_SELECTED
)
1314 if (::GetFocus() == m_hWnd
)
1315 txtState
= LISS_SELECTED
;
1317 txtState
= LISS_SELECTEDNOTFOCUS
;
1320 HTHEME hTheme
= nullptr;
1321 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1322 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1324 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1325 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1328 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1329 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1330 ::DeleteObject(brush
);
1335 // get rect of whole line
1336 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1338 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1339 rect2
.DeflateRect(1, 1, 1, 1);
1341 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1342 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1344 CloseThemeData(hTheme
);
1346 // END: extended redraw
1348 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1350 std::vector
<REFLABEL
> refsToShow
;
1351 STRING_VECTOR remoteTrackingList
;
1352 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1353 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1355 CString str
= refList
[i
];
1358 refLabel
.color
= RGB(255, 255, 255);
1359 refLabel
.singleRemote
= false;
1360 refLabel
.hasTracking
= false;
1361 refLabel
.sameName
= false;
1362 refLabel
.annotatedTag
= false;
1363 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1365 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1367 if (refLabel
.name
== m_CurrentBranch
)
1368 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1370 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1372 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1373 CString pullRemote
= trackingEntry
.first
;
1374 CString pullBranch
= trackingEntry
.second
;
1375 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1377 CString defaultUpstream
;
1378 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1379 refLabel
.hasTracking
= true;
1380 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1383 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1385 if (refList
[j
] == defaultUpstream
)
1394 bool sameName
= pullBranch
== refLabel
.name
;
1395 refsToShow
.push_back(refLabel
);
1396 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1397 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1398 if (m_bSymbolizeRefNames
)
1400 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1402 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1403 refLabel
.singleRemote
= true;
1406 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1407 refLabel
.sameName
= sameName
;
1409 refsToShow
.push_back(refLabel
);
1410 remoteTrackingList
.push_back(defaultUpstream
);
1416 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1418 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1422 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1424 if (remoteTrackingList
[j
] == str
)
1433 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1434 if (m_bSymbolizeRefNames
)
1436 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1438 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1439 refLabel
.singleRemote
= true;
1443 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1445 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1447 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1448 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1450 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1452 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1454 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1455 refLabel
.name
= _T("stash");
1457 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1459 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1461 if (refLabel
.name
.Find(_T("good")) == 0)
1463 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1464 refLabel
.name
= _T("good");
1466 if (refLabel
.name
.Find(_T("bad")) == 0)
1468 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1469 refLabel
.name
= _T("bad");
1475 refsToShow
.push_back(refLabel
);
1478 if (refsToShow
.empty())
1480 *pResult
= CDRF_DODEFAULT
;
1484 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1486 *pResult
= CDRF_SKIPDEFAULT
;
1494 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1496 if(this->m_IsIDReplaceAction
)
1498 *pResult
= CDRF_DODEFAULT
;
1501 *pResult
= CDRF_DODEFAULT
;
1503 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1507 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1508 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1510 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1512 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1513 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1514 // Get the selected state of the
1515 // item being drawn.
1517 // Fill the background if necessary
1518 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1520 // Draw the icon(s) into the compatible DC
1521 int action
= SafeGetAction(pLogEntry
);
1523 if (!pLogEntry
->m_IsDiffFiles
)
1524 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1526 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1527 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1530 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1531 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1534 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1535 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1538 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1539 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1541 *pResult
= CDRF_SKIPDEFAULT
;
1547 *pResult
= CDRF_DODEFAULT
;
1550 CString
FindSVNRev(const CString
& msg
)
1554 const std::tr1::wsregex_iterator end
;
1555 std::wstring s
= msg
;
1556 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), std::tr1::wregex(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"))); it
!= end
; ++it
)
1558 const std::tr1::wsmatch match
= *it
;
1559 if (match
.size() == 4)
1561 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1562 return std::wstring(match
[2]).c_str();
1565 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), std::tr1::wregex(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"))); it
!= end
; ++it
)
1567 const std::tr1::wsmatch match
= *it
;
1568 if (match
.size() == 3)
1570 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1571 return std::wstring(match
[1]).c_str();
1575 catch (std::exception
) {}
1580 // CGitLogListBase message handlers
1582 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1584 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1586 // Create a pointer to the item
1587 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1589 // Do the list need text information?
1590 if (!(pItem
->mask
& LVIF_TEXT
))
1593 // By default, clear text buffer.
1594 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1596 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1599 if (m_bNoDispUpdates
|| bOutOfRange
)
1602 // Which item number?
1603 int itemid
= pItem
->iItem
;
1604 GitRev
* pLogEntry
= NULL
;
1605 if (itemid
< m_arShownList
.GetCount())
1606 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1611 temp
.Format(_T("%d"),pItem
->iItem
+1);
1616 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1620 switch (pItem
->iSubItem
)
1622 case this->LOGLIST_GRAPH
: //Graphic
1624 case this->LOGLIST_REBASE
:
1626 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1627 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
);
1630 case this->LOGLIST_ACTION
: //action -- no text in the column
1632 case this->LOGLIST_HASH
:
1634 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1636 case this->LOGLIST_ID
:
1637 if(this->m_IsIDReplaceAction
)
1638 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1640 case this->LOGLIST_MESSAGE
: //Message
1642 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1644 case this->LOGLIST_AUTHOR
: //Author
1646 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1648 case this->LOGLIST_DATE
: //Date
1649 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1650 lstrcpyn(pItem
->pszText
,
1651 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1655 case this->LOGLIST_EMAIL
:
1657 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1660 case this->LOGLIST_COMMIT_NAME
: //Commit
1662 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1665 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1667 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1670 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1671 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1672 lstrcpyn(pItem
->pszText
,
1673 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1676 case this->LOGLIST_BUG
: //Bug ID
1678 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1680 case this->LOGLIST_SVNREV
: //SVN revision
1682 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1690 bool CGitLogListBase::IsOnStash(int index
)
1692 GitRev
*rev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
));
1697 GitRev
*preRev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
- 1));
1698 if (IsStash(preRev
))
1699 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1704 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1706 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1708 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1714 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1716 if (pRev
->m_ParentHash
.empty())
1720 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1722 catch (const char* msg
)
1724 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _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 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(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
)))
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
)));
1914 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1917 str
.Format(IDS_PARENT
, i
+ 1);
1918 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1920 requiresSeparator
= true;
1924 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1926 if (parentHash
.size() == 1)
1928 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1929 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1930 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1931 requiresSeparator
= true;
1933 else if (parentHash
.size() > 1)
1935 diffmenu
.CreatePopupMenu();
1936 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1937 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1940 str
.Format(IDS_PARENT
, i
+ 1);
1941 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1942 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1944 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1945 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1948 requiresSeparator
= true;
1952 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1954 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1955 requiresSeparator
= true;
1958 if (requiresSeparator
)
1959 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1961 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1963 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1964 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1967 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1969 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1970 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1972 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1973 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1975 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1978 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1980 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1981 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1983 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1984 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1986 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
1987 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1989 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1991 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1992 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1994 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1998 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2000 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2002 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2004 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2006 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2007 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2009 // popup.AppendMenu(MF_SEPARATOR, NULL);
2014 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2016 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2018 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2019 GetSelectedCount() == 1)
2020 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2022 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2023 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2025 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
2026 str
.Format(format
,g_Git
.GetCurrentBranch());
2028 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2029 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2031 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
2032 str
.Format(format
,g_Git
.GetCurrentBranch());
2034 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2035 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2038 // Add Switch Branch express Menu
2039 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2040 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2043 std::vector
<CString
*> branchs
;
2044 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2046 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2047 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2049 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2054 str
.LoadString(IDS_SWITCH_BRANCH
);
2056 if(branchs
.size() == 1)
2059 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2060 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
2062 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2065 else if(branchs
.size() > 1)
2067 subbranchmenu
.CreatePopupMenu();
2068 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2070 if (*branchs
[i
] != currentBranch
)
2072 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2073 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2077 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2081 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2082 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2084 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2085 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2087 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2088 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2090 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
2091 str
.Format(format
,g_Git
.GetCurrentBranch());
2093 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2094 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2095 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2097 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2098 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2100 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2102 if (parentHash
.size() == 1)
2104 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2106 else if (parentHash
.size() > 1)
2108 revertmenu
.CreatePopupMenu();
2109 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2111 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2114 str
.Format(IDS_PARENT
, i
+ 1);
2115 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
2120 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2121 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2123 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2128 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2130 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2131 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2132 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2133 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2136 if (GetSelectedCount() >= 2)
2138 bool bAddSeparator
= false;
2139 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2141 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2142 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2145 if (GetSelectedCount() == 2)
2147 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2148 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2150 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2152 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2153 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2154 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2156 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
2157 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2158 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
2159 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2162 bAddSeparator
= true;
2167 bAddSeparator
= true;
2170 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2171 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2174 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2177 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2179 bool bAddSeparator
= false;
2180 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2182 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2186 headindex
= this->GetHeadIndex();
2187 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2189 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2191 if (g_Git
.GetHash(hashFirst
, head
))
2192 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2193 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2195 if (g_Git
.GetHash(hash
, head
))
2196 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2197 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2198 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2199 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2200 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2201 bAddSeparator
= true;
2206 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2207 if (GetSelectedCount() >= 2)
2208 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2210 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2211 bAddSeparator
= true;
2214 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2215 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2216 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2217 bAddSeparator
= true;
2221 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2224 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
2226 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2227 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2230 if (GetSelectedCount() == 1)
2232 bool bAddSeparator
= false;
2233 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2235 // show the push-option only if the log entry has an associated local branch
2236 bool isLocal
= false;
2237 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2239 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2242 if (isLocal
|| showExtendedMenu
)
2244 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2245 bAddSeparator
= true;
2248 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2250 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2251 bAddSeparator
= true;
2255 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2257 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2259 std::vector
<CString
*> branchs
;
2260 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2262 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2263 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2266 if (branchs
.size() == 1)
2268 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2271 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2272 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2273 bAddSeparator
= true;
2275 else if (branchs
.size() > 1)
2277 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2278 submenu
.CreatePopupMenu();
2279 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2281 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2282 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2285 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2286 bAddSeparator
= true;
2289 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2291 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2292 } // GetSelectedCount() == 1
2294 if (GetSelectedCount() != 0)
2296 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2297 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2298 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2299 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2300 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2301 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2304 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2305 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2307 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2308 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2310 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2311 // DialogEnableWindow(IDOK, FALSE);
2312 // SetPromptApp(&theApp);
2314 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2316 // EnableOKButton();
2317 } // if (popup.CreatePopupMenu())
2321 bool CGitLogListBase::IsSelectionContinuous()
2323 if ( GetSelectedCount()==1 )
2325 // if only one revision is selected, the selection is of course
2330 POSITION pos
= GetFirstSelectedItemPosition();
2331 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2334 int itemindex
= GetNextSelectedItem(pos
);
2337 int nextindex
= GetNextSelectedItem(pos
);
2338 if (nextindex
- itemindex
> 1)
2340 bContinuous
= false;
2343 itemindex
= nextindex
;
2349 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2353 POSITION pos
= GetFirstSelectedItemPosition();
2357 sRev
.LoadString(IDS_LOG_REVISION
);
2359 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2361 sDate
.LoadString(IDS_LOG_DATE
);
2363 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2367 CString sLogCopyText
;
2369 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2371 if (toCopy
== ID_COPY_ALL
)
2373 //pLogEntry->GetFiles(this)
2374 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2376 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2377 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2379 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2380 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2383 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2384 sPaths
+= _T(" ") + rename
;
2386 sPaths
+= _T("\r\n");
2389 CString body
= pLogEntry
->GetBody();
2390 body
.Replace(_T("\n"), _T("\r\n"));
2391 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"),
2392 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2393 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2395 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2396 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2398 sClipdata
+= sLogCopyText
;
2400 else if (toCopy
== ID_COPY_MESSAGE
)
2402 CString body
= pLogEntry
->GetBody();
2403 body
.Replace(_T("\n"), _T("\r\n"));
2404 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2406 else if (toCopy
== ID_COPY_SUBJECT
)
2408 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2413 sClipdata
+= _T("\r\n");
2414 sClipdata
+= pLogEntry
->m_CommitHash
;
2419 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2424 void CGitLogListBase::DiffSelectedRevWithPrevious()
2426 if (m_bThreadRunning
)
2429 int FirstSelect
=-1, LastSelect
=-1;
2430 POSITION pos
= GetFirstSelectedItemPosition();
2431 FirstSelect
= GetNextSelectedItem(pos
);
2434 LastSelect
= GetNextSelectedItem(pos
);
2437 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2440 UpdateLogInfoLabel();
2441 int selIndex
= m_LogList
.GetSelectionMark();
2444 int selCount
= m_LogList
.GetSelectedCount();
2448 // Find selected entry in the log list
2449 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2450 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2451 long rev1
= pLogEntry
->Rev
;
2453 CTGitPath path
= m_path
;
2455 // See how many files under the relative root were changed in selected revision
2457 LogChangedPath
* changed
= NULL
;
2458 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2460 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2461 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2468 if (m_path
.IsDirectory() && nChanged
== 1)
2470 // We're looking at the log for a directory and only one file under dir was changed in the revision
2471 // Do diff on that file instead of whole directory
2472 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2475 m_bCancelled
= FALSE
;
2476 DialogEnableWindow(IDOK
, FALSE
);
2477 SetPromptApp(&theApp
);
2478 theApp
.DoWaitCursor(1);
2482 GitDiff
diff(this, m_hWnd
, true);
2483 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2484 diff
.SetHEADPeg(m_LogRevision
);
2485 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2489 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2492 theApp
.DoWaitCursor(-1);
2497 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2499 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2502 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2504 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2506 if (pFindInfo
->lvfi
.psz
== 0)
2509 CString sCmp
= pFindInfo
->lvfi
.psz
;
2511 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2513 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2514 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2515 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2517 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2525 if (sCmp
.Compare(sRev
)==0)
2532 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2534 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2536 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2537 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2538 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2540 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2548 if (sCmp
.Compare(sRev
)==0)
2560 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2564 this->m_arShownList
.SafeRemoveAll();
2566 this->m_logEntries
.ClearAll();
2567 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2570 SetItemCountEx((int)m_logEntries
.size());
2572 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2576 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2577 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2582 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2583 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2595 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2599 m_arShownList
.SafeRemoveAll();
2601 m_logEntries
.ClearAll();
2602 if (m_logEntries
.Fill(hashes
))
2605 SetItemCountEx((int)m_logEntries
.size());
2607 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2611 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2612 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2616 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2617 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2626 int CGitLogListBase::BeginFetchLog()
2630 this->m_arShownList
.SafeRemoveAll();
2632 this->m_logEntries
.ClearAll();
2634 this->m_LogCache
.ClearAllParent();
2636 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2639 if(this->m_Path
.IsEmpty())
2645 mask
= CGit::LOG_INFO_ONLY_HASH
;
2646 if (m_bIncludeBoundaryCommits
)
2647 mask
|= CGit::LOG_INFO_BOUNDARY
;
2648 // if(this->m_bAllBranch)
2649 mask
|= m_ShowMask
;
2653 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2655 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2658 if (m_sRange
.IsEmpty())
2659 m_sRange
= _T("HEAD");
2662 data
.m_From
= m_From
;
2665 #if 0 /* use tortoiegit filter */
2666 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2667 data
.m_Author
= this->m_sFilterText
;
2669 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2670 data
.m_MessageFilter
= this->m_sFilterText
;
2672 data
.m_IsRegex
= m_bFilterWithRegex
;
2675 // follow does not work for directories
2676 if (!path
|| path
->IsDirectory())
2677 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2678 // follow does not work with all branches 8at least in TGit)
2679 if (mask
& CGit::LOG_INFO_FOLLOW
)
2680 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2682 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2684 //this->m_logEntries.ParserFromLog();
2685 if(IsInWorkingThread())
2687 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2691 SetItemCountEx((int)m_logEntries
.size());
2696 [] { git_init(); } ();
2701 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2705 if (!g_Git
.CanParseRev(m_sRange
))
2707 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2710 // if show all branches, pick any ref as dummy entry ref
2712 if (g_Git
.GetRefList(list
))
2713 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2714 if (list
.size() == 0)
2717 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2720 g_Git
.m_critGitDllSec
.Lock();
2722 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2724 g_Git
.m_critGitDllSec
.Unlock();
2730 g_Git
.m_critGitDllSec
.Unlock();
2732 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2735 g_Git
.m_critGitDllSec
.Unlock();
2740 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2742 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2744 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2746 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2748 DiffSelectedRevWithPrevious();
2753 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2760 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2762 // select all entries
2763 for (int i
=0; i
<GetItemCount(); ++i
)
2765 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2771 if (m_hAccel
&& !bSkipAccelerator
)
2773 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2779 //m_tooltips.RelayEvent(pMsg);
2780 return __super::PreTranslateMessage(pMsg
);
2783 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2785 // a double click on an entry in the revision list has happened
2788 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2789 DiffSelectedRevWithPrevious();
2792 int CGitLogListBase::FetchLogAsync(void * data
)
2796 m_bExitThread
=FALSE
;
2797 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2798 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2799 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2800 if (m_LoadingThread
==NULL
)
2802 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2803 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2804 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2810 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2812 return ((CGitLogListBase
*)pVoid
)->LogThread();
2815 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2818 oldest
=CTime::GetCurrentTime();
2819 latest
=CTime(1971,1,2,0,0,0);
2820 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2822 if(m_logEntries
[i
].IsEmpty())
2825 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2826 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2828 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2829 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2837 UINT
CGitLogListBase::LogThread()
2839 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2841 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2842 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2848 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2849 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2854 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2855 bool bRegex
= false;
2856 if (m_bFilterWithRegex
)
2857 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2859 TRACE(_T("\n===Begin===\n"));
2860 //Update work copy item;
2862 if (!m_logEntries
.empty())
2864 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2866 m_arShownList
.SafeAdd(pRev
);
2870 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2872 // store commit number of the last selected commit/line before the refresh or -1
2873 int lastSelectedHashNItem
= -1;
2876 bool shouldWalk
= true;
2877 if (!g_Git
.CanParseRev(m_sRange
))
2879 // walk revisions if show all branches and there exists any ref
2880 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2885 if (g_Git
.GetRefList(list
))
2886 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2887 if (list
.size() == 0)
2894 g_Git
.m_critGitDllSec
.Lock();
2898 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2899 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2904 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2907 g_Git
.m_critGitDllSec
.Unlock();
2910 t2
=t1
=GetTickCount();
2911 int oldprecentage
= 0;
2912 size_t oldsize
= m_logEntries
.size();
2913 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2914 while (ret
== 0 && !m_bExitThread
)
2916 g_Git
.m_critGitDllSec
.Lock();
2919 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2923 g_Git
.m_critGitDllSec
.Unlock();
2925 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2928 g_Git
.m_critGitDllSec
.Unlock();
2932 if (ret
!= -2) // other than end of revision walking
2933 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2937 if (commit
.m_ignore
== 1)
2939 git_free_commit(&commit
);
2943 //printf("%s\r\n",commit.GetSubject());
2947 CGitHash hash
= (char*)commit
.m_hash
;
2949 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2950 pRev
->m_GitCommit
= commit
;
2951 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2954 g_Git
.m_critGitDllSec
.Lock();
2957 git_get_notes(commit
.m_hash
, ¬e
);
2961 g_Git
.m_critGitDllSec
.Unlock();
2963 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2966 g_Git
.m_critGitDllSec
.Unlock();
2970 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2975 if(!pRev
->m_IsDiffFiles
)
2977 pRev
->m_CallDiffAsync
= DiffAsync
;
2980 pRev
->ParserParentFromCommit(&commit
);
2981 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2983 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2985 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2986 auto it
= commitChildren
.find(parentHash
);
2987 if (it
== commitChildren
.end())
2989 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2991 it
->second
.insert(pRev
->m_CommitHash
);
3000 bool visible
= true;
3001 if (HasFilterText())
3003 if(!IsMatchFilter(bRegex
,pRev
,pat
))
3006 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
3008 this->m_critSec
.Lock();
3009 m_logEntries
.append(hash
, visible
);
3011 m_arShownList
.SafeAdd(pRev
);
3012 this->m_critSec
.Unlock();
3017 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3018 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3022 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3025 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3028 if(percent
< GITLOG_START
)
3029 percent
= GITLOG_START
+1;
3031 oldsize
= m_logEntries
.size();
3032 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3034 //if( percent > oldprecentage )
3036 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3037 oldprecentage
= percent
;
3040 if (lastSelectedHashNItem
>= 0)
3041 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3046 g_Git
.m_critGitDllSec
.Lock();
3047 git_close_log(m_DllGitLog
);
3048 g_Git
.m_critGitDllSec
.Unlock();
3054 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3059 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3061 if (lastSelectedHashNItem
>= 0)
3062 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3065 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3067 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3072 void CGitLogListBase::FetchRemoteList()
3074 STRING_VECTOR remoteList
;
3075 if (!g_Git
.GetRemoteList(remoteList
))
3076 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3078 m_SingleRemote
= _T("");
3081 void CGitLogListBase::FetchTrackingBranchList()
3083 m_TrackingMap
.clear();
3084 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3086 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3089 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3091 CString pullRemote
, pullBranch
;
3092 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3093 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3095 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3102 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3104 SafeTerminateThread();
3106 this->SetItemCountEx(0);
3111 // HACK to hide graph column
3112 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3113 SetColumnWidth(0, 0);
3115 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3117 //Update branch and Tag info
3120 m_pFindDialog
->RefreshList();
3121 //Assume Thread have exited
3122 //if(!m_bThreadRunning)
3124 m_logEntries
.clear();
3128 m_sFilterText
.Empty();
3133 InterlockedExchange(&m_bExitThread
,FALSE
);
3135 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3136 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3137 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3139 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3140 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3141 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3145 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3149 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3151 type
|= std::tr1::regex_constants::icase
;
3152 pat
= std::tr1::wregex(regexp_str
, type
);
3155 catch (std::exception
) {}
3158 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
)
3161 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3164 if ((bRegex
)&&(m_bFilterWithRegex
))
3166 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3168 if(this->m_bShowBugtraqColumn
)
3170 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3172 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
3173 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3180 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3182 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
3183 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3189 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3191 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
3192 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3198 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3200 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3205 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3211 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3213 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3218 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3224 if (m_SelectedFilters
& LOGFILTER_REVS
)
3226 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3227 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3233 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3235 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3236 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3238 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3245 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3247 CTGitPathList
*pathList
=NULL
;
3248 if( pRev
->m_IsDiffFiles
)
3249 pathList
= &pRev
->GetFiles(this);
3252 if(!pRev
->m_IsSimpleListReady
)
3253 pRev
->SafeGetSimpleList(&g_Git
);
3257 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3259 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3263 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3269 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3271 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3280 CString find
= m_sFilterText
;
3281 if (!m_bFilterCaseSensitively
)
3283 result
= find
[0] == '!' ? FALSE
: TRUE
;
3287 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3289 if(this->m_bShowBugtraqColumn
)
3291 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3293 if (!m_bFilterCaseSensitively
)
3294 sBugIds
.MakeLower();
3295 if ((sBugIds
.Find(find
) >= 0))
3302 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3304 CString msg
= pRev
->GetSubject();
3306 if (!m_bFilterCaseSensitively
)
3307 msg
= msg
.MakeLower();
3308 if ((msg
.Find(find
) >= 0))
3314 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3316 CString msg
= pRev
->GetBody();
3318 if (!m_bFilterCaseSensitively
)
3319 msg
= msg
.MakeLower();
3320 if ((msg
.Find(find
) >= 0))
3326 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3328 CString msg
= pRev
->GetAuthorName();
3329 if (!m_bFilterCaseSensitively
)
3330 msg
= msg
.MakeLower();
3331 if ((msg
.Find(find
) >= 0))
3337 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3339 CString msg
= pRev
->GetAuthorEmail();
3340 if (!m_bFilterCaseSensitively
)
3341 msg
= msg
.MakeLower();
3342 if ((msg
.Find(find
) >= 0))
3348 if (m_SelectedFilters
& LOGFILTER_REVS
)
3350 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3351 if ((sRev
.Find(find
) >= 0))
3357 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3359 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3360 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3362 if (it
->Find(find
) >= 0)
3369 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3371 CTGitPathList
*pathList
=NULL
;
3372 if( pRev
->m_IsDiffFiles
)
3373 pathList
= &pRev
->GetFiles(this);
3376 if(!pRev
->m_IsSimpleListReady
)
3377 pRev
->SafeGetSimpleList(&g_Git
);
3380 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3382 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3383 CString path
= cpath
->GetGitOldPathString();
3384 if (!m_bFilterCaseSensitively
)
3386 if ((path
.Find(find
)>=0))
3390 path
= cpath
->GetGitPathString();
3391 if (!m_bFilterCaseSensitively
)
3393 if ((path
.Find(find
)>=0))
3399 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3401 CString path
= pRev
->m_SimpleFileList
[i
];
3402 if (!m_bFilterCaseSensitively
)
3404 if ((path
.Find(find
)>=0))
3410 } // else (from if (bRegex))
3414 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3416 return str
.Left(prefix
.GetLength()) == prefix
;
3418 bool CGitLogListBase::ShouldShowFilter(GitRev
*pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>> &commitChildren
)
3420 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3423 if (m_ShowFilter
& FILTERSHOW_REFS
)
3426 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3427 for (size_t i
= 0; i
< refList
.size(); ++i
)
3429 const CString
&str
= refList
[i
];
3430 if (CStringStartsWith(str
, _T("refs/heads/")))
3432 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3435 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3437 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3440 else if (CStringStartsWith(str
, _T("refs/tags/")))
3442 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3445 else if (CStringStartsWith(str
, _T("refs/stash")))
3447 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3450 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3452 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3456 // Keep the head too.
3457 if (pRev
->m_CommitHash
== m_HeadHash
)
3461 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3463 if (pRev
->ParentsCount() > 1)
3465 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3466 if (childrenIt
!= commitChildren
.end())
3468 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3469 if (children
.size() > 1)
3476 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3478 // HACK to hide graph column
3480 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3482 SetColumnWidth(0, 0);
3485 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3490 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3492 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3493 for (size_t i
= 0; i
< vector
.size(); ++i
)
3495 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3497 CString tag
= vector
[i
];
3498 int start
= vector
[i
].Find(_T("^{}"));
3500 tag
= tag
.Left(start
);
3504 cmd
.Format(_T("git.exe cat-file tag %s"), tag
);
3505 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3506 output
.AppendChar(_T('\n'));
3514 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3517 pShownlist
->SafeRemoveAll();
3519 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3520 bool bRegex
= false;
3521 if (m_bFilterWithRegex
)
3522 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3524 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3526 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3528 if ((bRegex
)&&(m_bFilterWithRegex
))
3531 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3533 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3534 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3536 pShownlist
->SafeAdd(m_logEntries
[i
]);
3541 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3543 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3544 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3546 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3550 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3552 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3553 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3555 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3559 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3561 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3564 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3566 CTGitPath cpath
= pathList
[cpPathIndex
];
3567 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3569 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3573 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3575 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3579 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3581 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3587 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3589 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3591 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3595 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3597 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3599 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3603 if (m_SelectedFilters
& LOGFILTER_REVS
)
3605 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3606 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3608 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3612 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3614 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3615 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3617 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3619 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3627 CString find
= m_sFilterText
;
3628 if (!m_bFilterCaseSensitively
)
3631 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3633 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3635 if (!m_bFilterCaseSensitively
)
3636 sBugIDs
= sBugIDs
.MakeLower();
3637 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3639 pShownlist
->SafeAdd(m_logEntries
[i
]);
3644 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3646 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3648 if (!m_bFilterCaseSensitively
)
3649 msg
= msg
.MakeLower();
3650 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3652 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3656 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3658 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3660 if (!m_bFilterCaseSensitively
)
3661 msg
= msg
.MakeLower();
3662 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3664 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3668 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3670 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3673 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3675 CTGitPath cpath
= pathList
[cpPathIndex
];
3676 CString path
= cpath
.GetGitOldPathString();
3677 if (!m_bFilterCaseSensitively
)
3679 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3681 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3685 path
= cpath
.GetGitPathString();
3686 if (!m_bFilterCaseSensitively
)
3688 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3690 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3694 path
= cpath
.GetActionName();
3695 if (!m_bFilterCaseSensitively
)
3697 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3699 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3705 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3707 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3708 if (!m_bFilterCaseSensitively
)
3709 msg
= msg
.MakeLower();
3710 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3712 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3716 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3718 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3719 if (!m_bFilterCaseSensitively
)
3720 msg
= msg
.MakeLower();
3721 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3723 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3727 if (m_SelectedFilters
& LOGFILTER_REVS
)
3729 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3730 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3732 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3736 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3738 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3739 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3741 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3743 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3748 } // else (from if (bRegex))
3749 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3753 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3756 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3762 return time <= m_To;
3765 return time >= m_From;
3767 return ((time >= m_From)&&(time <= m_To));
3769 return TRUE
; /* git dll will filter time range */
3773 void CGitLogListBase::StartFilter()
3775 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3776 RecalculateShownList(&m_arShownList
);
3777 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3781 SetItemCountEx(ShownCountWithStopped());
3782 RedrawItems(0, ShownCountWithStopped());
3786 void CGitLogListBase::RemoveFilter()
3789 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3791 m_arShownList
.SafeRemoveAll();
3793 // reset the time filter too
3795 m_timFrom
= (__time64_t(m_tFrom
));
3796 m_timTo
= (__time64_t(m_tTo
));
3797 m_DateFrom
.SetTime(&m_timFrom
);
3798 m_DateTo
.SetTime(&m_timTo
);
3799 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3800 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3803 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3805 if(this->m_IsOldFirst
)
3807 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3811 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3814 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3816 SetItemCountEx(ShownCountWithStopped());
3817 RedrawItems(0, ShownCountWithStopped());
3819 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3822 void CGitLogListBase::Clear()
3824 m_arShownList
.SafeRemoveAll();
3827 m_logEntries
.ClearAll();
3831 void CGitLogListBase::OnDestroy()
3833 // save the column widths to the registry
3836 SafeTerminateThread();
3837 SafeTerminateAsyncDiffThread();
3840 while(m_LogCache
.SaveCache())
3848 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3849 // MB_YESNO) == IDNO)
3853 CHintListCtrl::OnDestroy();
3856 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3860 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3861 this->InvalidateRect(rect
);
3867 * Save column widths to the registry
3869 void CGitLogListBase::SaveColumnWidths()
3871 int maxcol
= m_ColumnManager
.GetColumnCount();
3873 // HACK that graph column is always shown
3874 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3876 for (int col
= 0; col
< maxcol
; ++col
)
3877 if (m_ColumnManager
.IsVisible (col
))
3878 m_ColumnManager
.ColumnResized (col
);
3880 m_ColumnManager
.WriteSettings();
3883 int CGitLogListBase::GetHeadIndex()
3885 if(m_HeadHash
.IsEmpty())
3888 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3890 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3893 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3899 void CGitLogListBase::OnFind()
3903 m_pFindDialog
= new CFindDlg(this);
3904 m_pFindDialog
->Create(this);
3907 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3909 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3911 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3913 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3916 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3918 if (GetSelectedCount() != 0)
3921 CGitHash theSelectedHash
= m_lastSelectedHash
;
3922 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3923 m_lastSelectedHash
= theSelectedHash
;
3925 int countPerPage
= GetCountPerPage();
3926 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3927 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3928 EnsureVisible((int)itemToSelect
, FALSE
);
3931 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3934 ASSERT(m_pFindDialog
!= NULL
);
3935 bool bFound
= false;
3938 if (m_pFindDialog
->IsTerminating())
3940 // invalidate the handle identifying the dialog box.
3941 m_pFindDialog
= NULL
;
3945 INT_PTR cnt
= m_arShownList
.GetCount();
3947 if(m_pFindDialog
->IsRef())
3950 str
=m_pFindDialog
->GetFindString();
3956 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3957 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3962 for (i
= 0; i
< cnt
; ++i
)
3964 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3965 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3974 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3979 if (m_pFindDialog
->FindNext() && !bFound
)
3981 //read data from dialog
3982 CString findText
= m_pFindDialog
->GetFindString();
3983 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3985 std::tr1::wregex pat
;
3986 bool bRegex
= false;
3987 if (m_pFindDialog
->Regex())
3988 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3990 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3992 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3997 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3999 if (m_nSearchIndex
>= 0)
4001 if (i
== m_nSearchIndex
)
4003 ::MessageBeep(0xFFFFFFFF);
4004 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4009 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4012 str
+=pLogEntry
->m_CommitHash
.ToString();
4015 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4017 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4021 str
+=pLogEntry
->GetAuthorEmail();
4023 str
+=pLogEntry
->GetAuthorName();
4025 str
+=pLogEntry
->GetBody();
4027 str
+=pLogEntry
->GetCommitterEmail();
4029 str
+=pLogEntry
->GetCommitterName();
4031 str
+=pLogEntry
->GetSubject();
4033 str
+=pLogEntry
->m_Notes
;
4035 str
+=GetTagInfo(pLogEntry
);
4039 /*Because changed files list is loaded on demand when gui show,
4040 files will empty when files have not fetched.
4042 we can add it back by using one-way diff(with outnumber changed and rename detect.
4043 here just need changed filename list. one-way is much quicker.
4045 if(pLogEntry
->m_IsFull
)
4047 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
4049 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
4051 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
4057 if(!pLogEntry
->m_IsSimpleListReady
)
4058 pLogEntry
->SafeGetSimpleList(&g_Git
);
4060 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
4062 str
+=pLogEntry
->m_SimpleFileList
[i
];
4071 if (std::regex_search(std::wstring(str
), pat
, flags
))
4081 if (str
.Find(findText
) >= 0)
4091 msg
= msg
.MakeLower();
4092 CString find
= findText
.MakeLower();
4093 if (msg
.Find(find
) >= 0)
4100 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4102 } // if(m_pFindDialog->FindNext())
4103 //UpdateLogInfoLabel();
4108 EnsureVisible(i
, FALSE
);
4109 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4111 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4112 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4113 SetSelectionMark(i
);
4117 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4119 m_highlight
= pLogEntry
->m_CommitHash
;
4122 //FillLogMessageCtrl();
4129 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4131 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4136 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4138 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4143 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4145 LVHITTESTINFO lvhitTestInfo
;
4147 lvhitTestInfo
.pt
= point
;
4149 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4150 int nSubItem
= lvhitTestInfo
.iSubItem
;
4152 UINT nFlags
= lvhitTestInfo
.flags
;
4154 // nFlags is 0 if the SubItemHitTest fails
4155 // Therefore, 0 & <anything> will equal false
4156 if (nFlags
& LVHT_ONITEM
)
4158 // Get the client area occupied by this control
4160 GetClientRect(&rcClient
);
4162 // Fill in the TOOLINFO structure
4164 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4165 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4166 pTI
->rect
= rcClient
;
4168 return pTI
->uId
; // By returning a unique value per listItem,
4169 // we ensure that when the mouse moves over another list item,
4170 // the tooltip will change
4174 // Otherwise, we aren't interested, so let the message propagate
4179 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4181 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4182 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4186 // Ignore messages from the built in tooltip, we are processing them internally
4187 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4188 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4189 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4192 // Get the mouse position
4193 const MSG
* pMessage
= GetCurrentMessage();
4197 ScreenToClient(&pt
);
4199 // Check if the point falls onto a list item
4200 LVHITTESTINFO lvhitTestInfo
;
4201 lvhitTestInfo
.pt
= pt
;
4203 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4205 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4207 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4208 if (strTipText
.IsEmpty())
4211 // we want multiline tooltips
4212 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4214 wcscpy_s(m_wszTip
, strTipText
);
4215 // handle Unicode as well as non-Unicode requests
4216 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4218 pTTTA
->hinst
= nullptr;
4219 pTTTA
->lpszText
= m_szTip
;
4220 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4224 pTTTW
->hinst
= nullptr;
4225 pTTTW
->lpszText
= m_wszTip
;
4229 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4230 ClientToScreen(rect
);
4231 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4233 return TRUE
; // We found a tool tip,
4234 // tell the framework this message has been handled
4237 return FALSE
; // We didn't handle the message,
4238 // let the framework continue propagating the message
4241 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4243 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4245 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
4246 if (pLogEntry
== nullptr)
4248 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4250 return pLogEntry
->GetSubject();
4252 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4254 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
4255 if (pLogEntry
== nullptr)
4257 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4259 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4261 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
4262 if (pLogEntry
== nullptr)
4264 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4266 else if (nSubItem
== LOGLIST_ACTION
)
4268 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
4269 if (pLogEntry
== nullptr)
4272 CString sToolTipText
;
4274 DWORD actions
= SafeGetAction(pLogEntry
);
4277 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4278 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4280 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4282 if (!actionText
.IsEmpty())
4283 actionText
+= L
"\r\n";
4284 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4287 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4289 if (!actionText
.IsEmpty())
4290 actionText
+= L
"\r\n";
4291 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4294 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4296 if (!actionText
.IsEmpty())
4297 actionText
+= L
"\r\n";
4298 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4301 if (!actionText
.IsEmpty())
4303 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4304 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4306 return sToolTipText
;