1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
25 #include "GitLogListBase.h"
30 #include "GitProgressDlg.h"
31 #include "ProgressDlg.h"
33 #include "MessageBox.h"
35 #include "LoglistUtils.h"
36 #include "PathUtils.h"
37 #include "StringUtils.h"
38 #include "UnicodeUtils.h"
41 #include "GitStatus.h"
42 #include "..\\TortoiseShell\\Resource.h"
46 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
47 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
48 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
50 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
55 ,m_bNoDispUpdates(FALSE
)
56 , m_bThreadRunning(FALSE
)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL
)
59 , m_SelectedFilters(LOGFILTER_ALL
)
60 , m_ShowFilter(FILTERSHOW_ALL
)
62 , m_logEntries(&m_LogCache
)
64 , m_ColumnManager(this)
65 , m_dwDefaultColumns(0)
66 , m_arShownList(&m_critSec
)
68 , m_bNoHightlightHead(FALSE
)
69 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
71 // use the default GUI font, create a copy of it and
72 // change the copy to BOLD (leave the rest of the font
74 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
76 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
77 lf
.lfWeight
= FW_BOLD
;
78 m_boldFont
= CreateFontIndirect(&lf
);
79 lf
.lfWeight
= FW_DONTCARE
;
81 m_FontItalics
= CreateFontIndirect(&lf
);
82 lf
.lfWeight
= FW_BOLD
;
83 m_boldItalicsFont
= CreateFontIndirect(&lf
);
85 m_bShowBugtraqColumn
=false;
87 m_IsIDReplaceAction
=FALSE
;
89 this->m_critSec
.Init();
90 m_critSec_AsyncDiff
.Init();
91 m_wcRev
.m_CommitHash
.Empty();
92 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
93 m_wcRev
.m_ParentHash
.clear();
94 m_wcRev
.m_Mark
=_T('-');
95 m_wcRev
.m_IsUpdateing
=FALSE
;
96 m_wcRev
.m_IsFull
= TRUE
;
98 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
99 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
100 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
101 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
102 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
104 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE
);
105 m_bFilterCaseSensitively
= !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE
);
111 m_LoadingThread
= NULL
;
113 InterlockedExchange(&m_bExitThread
,FALSE
);
114 m_IsOldFirst
= FALSE
;
115 m_IsRebaseReplaceGraph
= FALSE
;
117 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
119 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
121 // get short/long datetime setting from registry
122 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
123 if ( RegUseShortDateFormat
)
125 m_DateFormat
= DATE_SHORTDATE
;
129 m_DateFormat
= DATE_LONGDATE
;
131 // get relative time display setting from registry
132 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
133 m_bRelativeTimes
= (regRelativeTimes
!= 0);
134 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
136 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
137 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
138 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
139 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
140 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
141 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
142 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
144 m_ColumnRegKey
=_T("log");
146 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
147 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
148 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
150 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
151 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
153 m_AsyncThreadExit
= FALSE
;
154 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
155 m_AsynDiffListLock
.Init();
157 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
158 if (m_DiffingThread
==NULL
)
160 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
166 int CGitLogListBase::AsyncDiffThread()
168 m_AsyncThreadExited
= false;
169 while(!m_AsyncThreadExit
)
171 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
174 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
176 m_AsynDiffListLock
.Lock();
177 pRev
= m_AsynDiffList
.back();
178 m_AsynDiffList
.pop_back();
179 m_AsynDiffListLock
.Unlock();
181 if( pRev
->m_CommitHash
.IsEmpty() )
183 if(pRev
->m_IsDiffFiles
)
186 pRev
->GetFiles(this).Clear();
187 pRev
->m_ParentHash
.clear();
188 pRev
->m_ParentHash
.push_back(m_HeadHash
);
189 if(g_Git
.IsInitRepos())
191 if (g_Git
.GetInitAddList(pRev
->GetFiles(this)))
192 CMessageBox::Show(NULL
, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
197 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
200 int *action
= &dummyAction
;
201 SafeGetAction(pRev
, &action
);
204 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
205 *action
|= pRev
->GetFiles(this)[j
].m_Action
;
208 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
210 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
214 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
215 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
217 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
218 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
219 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
222 m_critSec_AsyncDiff
.Lock();
223 int ret
= pRev
->CheckAndDiff();
224 m_critSec_AsyncDiff
.Unlock();
226 { // fetch change file list
227 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
229 if(i
< m_arShownList
.GetCount())
231 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
232 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
234 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
240 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
242 POSITION pos
= GetFirstSelectedItemPosition();
243 int nItem
= GetNextSelectedItem(pos
);
247 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
249 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
251 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
258 m_AsyncThreadExited
= true;
261 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
265 m_ContextMenuMask
&= hideMask
;
269 m_ContextMenuMask
&= ~hideMask
;
273 CGitLogListBase::~CGitLogListBase()
275 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
276 this->m_arShownList
.SafeRemoveAll();
278 DestroyIcon(m_hModifiedIcon
);
279 DestroyIcon(m_hReplacedIcon
);
280 DestroyIcon(m_hAddedIcon
);
281 DestroyIcon(m_hDeletedIcon
);
282 m_logEntries
.ClearAll();
285 DeleteObject(m_boldFont
);
288 DeleteObject(m_FontItalics
);
290 if (m_boldItalicsFont
)
291 DeleteObject(m_boldItalicsFont
);
293 if ( m_pStoreSelection
)
295 delete m_pStoreSelection
;
296 m_pStoreSelection
= NULL
;
299 SafeTerminateThread();
300 SafeTerminateAsyncDiffThread();
303 CloseHandle(m_AsyncDiffEvent
);
307 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
308 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
309 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
310 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
311 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
313 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
314 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
317 ON_MESSAGE(MSG_LOADED
,OnLoad
)
319 ON_WM_MEASUREITEM_REFLECT()
320 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
321 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
322 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
323 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
324 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
325 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
328 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
330 //if (m_nRowHeight>0)
332 lpMeasureItemStruct
->itemHeight
= 50;
336 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
339 return CHintListCtrl::OnCreate(lpCreateStruct
);
342 void CGitLogListBase::PreSubclassWindow()
344 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
345 // load the icons for the action columns
346 // m_Theme.Open(m_hWnd, L"ListView");
347 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
348 CHintListCtrl::PreSubclassWindow();
351 CString
CGitLogListBase::GetRebaseActionName(int action
)
353 if (action
& LOGACTIONS_REBASE_EDIT
)
354 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
355 if (action
& LOGACTIONS_REBASE_SQUASH
)
356 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
357 if (action
& LOGACTIONS_REBASE_PICK
)
358 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
359 if (action
& LOGACTIONS_REBASE_SKIP
)
360 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
362 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
365 void CGitLogListBase::InsertGitColumn()
369 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
370 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
371 if (DWORD(regFullRowSelect
))
372 exStyle
|= LVS_EX_FULLROWSELECT
;
373 SetExtendedStyle(exStyle
);
375 // only load properties if we have a repository
376 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
377 UpdateProjectProperties();
379 static UINT normal
[] =
391 IDS_LOG_COMMIT_EMAIL
,
414 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
416 DWORD hideColumns
= 0;
417 if(this->m_IsRebaseReplaceGraph
)
419 hideColumns
|= GIT_LOG_GRAPH
;
420 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
424 hideColumns
|= GIT_LOG_REBASE
;
427 if(this->m_IsIDReplaceAction
)
429 hideColumns
|= GIT_LOG_ACTIONS
;
430 m_dwDefaultColumns
|= GIT_LOG_ID
;
431 m_dwDefaultColumns
|= GIT_LOG_HASH
;
435 hideColumns
|= GIT_LOG_ID
;
437 if(this->m_bShowBugtraqColumn
)
439 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
443 hideColumns
|= GIT_LOGLIST_BUG
;
445 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
446 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
448 hideColumns
|= GIT_LOGLIST_SVNREV
;
451 m_ColumnManager
.SetNames(normal
, _countof(normal
));
452 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
458 * Resizes all columns in a list control to values in registry.
460 void CGitLogListBase::ResizeAllListCtrlCols()
462 // column max and min widths to allow
463 static const int nMinimumWidth
= 10;
464 static const int nMaximumWidth
= 1000;
465 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
468 int numcols
= pHdrCtrl
->GetItemCount();
469 for (int col
= 0; col
< numcols
; ++col
)
471 // get width for this col last time from registry
473 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
474 CRegDWORD
regwidth(regentry
, 0);
478 // no saved value, setup sensible defaults
479 if (col
== this->LOGLIST_MESSAGE
)
481 cx
= LOGLIST_MESSAGE_MIN
;
485 cx
= ICONITEMBORDER
+16*4;
488 if (cx
< nMinimumWidth
)
492 else if (cx
> nMaximumWidth
)
497 SetColumnWidth(col
, cx
);
504 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
507 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
508 rItem
.mask
= LVIF_STATE
;
509 rItem
.iItem
= (int)Index
;
510 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
513 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
516 if (!(rItem
.state
& LVIS_SELECTED
))
518 int action
= pLogEntry
->GetRebaseAction();
519 if (action
& LOGACTIONS_REBASE_SQUASH
)
520 brush
= ::CreateSolidBrush(RGB(156,156,156));
521 else if (action
& LOGACTIONS_REBASE_EDIT
)
522 brush
= ::CreateSolidBrush(RGB(200,200,128));
524 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
526 if (rItem
.state
& LVIS_SELECTED
)
528 if (::GetFocus() == m_hWnd
)
529 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
531 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
536 ::FillRect(hdc
, &rect
, brush
);
537 ::DeleteObject(brush
);
541 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
543 POINT point
= { 4, 4 };
545 rt2
.DeflateRect(1, 1);
546 rt2
.OffsetRect(2, 2);
548 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
549 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
550 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
551 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
552 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
554 ::SelectObject(hdc
, brush
);
555 rt2
.OffsetRect(-2, -2);
556 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
557 ::SelectObject(hdc
, oldbrush
);
558 ::SelectObject(hdc
, oldpen
);
559 ::DeleteObject(nullPen
);
560 ::DeleteObject(darkBrush
);
563 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
565 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
566 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
567 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
568 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
569 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
570 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
571 ::SelectObject(hdc
, oldpen
);
575 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
577 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
578 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
579 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
580 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
581 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
582 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
583 ::SelectObject(hdc
, oldpen
);
587 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
589 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
592 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
593 rItem
.mask
= LVIF_STATE
;
594 rItem
.iItem
= (int)index
;
595 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
601 HTHEME hTheme
= NULL
;
602 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
603 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
606 if (m_bTagsBranchesOnRightSide
)
608 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
609 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
610 SelectObject(hdc
, oldFont
);
611 rt
.left
+= oneSpaceSize
.cx
* 2;
615 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
616 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
617 rt
.left
+= oneSpaceSize
.cx
;
620 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
622 int txtState
= LISS_NORMAL
;
623 if (rItem
.state
& LVIS_SELECTED
)
624 txtState
= LISS_SELECTED
;
626 DTTOPTS opts
= { 0 };
627 opts
.dwSize
= sizeof(opts
);
628 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
629 opts
.dwFlags
= DTT_TEXTCOLOR
;
630 DrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
634 if (rItem
.state
& LVIS_SELECTED
)
636 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
637 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
638 ::SetTextColor(hdc
, clrOld
);
642 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
643 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
644 ::SetTextColor(hdc
, clrOld
);
648 if (m_bTagsBranchesOnRightSide
)
651 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
653 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
655 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
659 CloseThemeData(hTheme
);
664 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
)
666 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
668 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
670 COLORREF colRef
= refList
[i
].color
;
671 bool singleRemote
= refList
[i
].singleRemote
;
672 bool hasTracking
= refList
[i
].hasTracking
;
673 bool sameName
= refList
[i
].sameName
;
674 bool annotatedTag
= refList
[i
].annotatedTag
;
676 //When row selected, ajust label color
677 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
679 if (rItem
.state
& LVIS_SELECTED
)
680 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
683 brush
= ::CreateSolidBrush(colRef
);
685 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
688 memset(&size
,0,sizeof(SIZE
));
689 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
691 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
694 int textpos
= DT_CENTER
;
696 if (rt
.right
> rect
.right
)
698 rt
.right
= rect
.right
;
707 textRect
.OffsetRect(8, 0);
715 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
719 //Fill interior of ref label
720 ::FillRect(hdc
, &rt
, brush
);
728 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
729 rectEdge
.DeflateRect(1, 1);
730 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
736 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
737 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
738 ::FillRgn(hdc
, hrgn
, brush
);
739 ::DeleteObject(hrgn
);
740 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
742 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
743 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
745 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
746 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
748 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
749 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
750 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
752 SelectObject(hdc
, oldpen
);
755 //Draw text inside label
756 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
757 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
759 int txtState
= LISS_NORMAL
;
760 if (rItem
.state
& LVIS_SELECTED
)
761 txtState
= LISS_SELECTED
;
763 DTTOPTS opts
= { 0 };
764 opts
.dwSize
= sizeof(opts
);
765 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
766 opts
.dwFlags
= DTT_TEXTCOLOR
;
767 DrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
771 W_Dc
.SetBkMode(TRANSPARENT
);
772 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
774 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
775 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
776 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
777 ::SetTextColor(hdc
,clrOld
);
781 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
782 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
783 ::SetTextColor(hdc
, clrOld
);
789 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
790 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
792 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
793 DrawLightning(hdc
, newRect
, color
, bold
);
798 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
799 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
801 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
802 DrawUpTriangle(hdc
, newRect
, color
, bold
);
805 rt
.left
= rt
.right
+ 1;
808 ::DeleteObject(brush
);
810 rt
.right
= rect
.right
;
813 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
815 // Returns ((256 - amount)*col1 + amount*col2) / 256;
816 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
817 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
818 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
821 Gdiplus::Color
GetGdiColor(COLORREF col
)
823 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
825 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
826 const COLORREF
& col
,const COLORREF
& activeColor
, int top
829 int h
= laneHeight
/ 2;
830 int m
= (x1
+ x2
) / 2;
831 int r
= (x2
- x1
) * m_NodeSize
/ 30;
834 #define P_CENTER m , h+top
835 #define P_0 x2, h+top
836 #define P_90 m , 0+top-1
837 #define P_180 x1, h+top
838 #define P_270 m , 2 * h+top +1
839 #define R_CENTER m - r, h - r+top, d, d
842 #define DELTA_UR_B 2*(x1 - m), 2*h +top
843 #define DELTA_UR_E 0*16, 90*16 +top // -,
845 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
846 #define DELTA_DR_E 270*16, 90*16 +top // -'
848 #define DELTA_UL_B 2*(x2 - m), 2*h +top
849 #define DELTA_UL_E 90*16, 90*16 +top // ,-
851 #define DELTA_DL_B 2*(x2 - m),2*-h +top
852 #define DELTA_DL_E 180*16, 90*16 // '-
854 #define CENTER_UR x1, 2*h, 225
855 #define CENTER_DR x1, 0 , 135
856 #define CENTER_UL x2, 2*h, 315
857 #define CENTER_DL x2, 0 , 45
860 Gdiplus::Graphics
graphics( hdc
);
862 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
871 Gdiplus::LinearGradientBrush
gradient(
872 Gdiplus::Point(x1
-2, h
+top
-2),
873 Gdiplus::Point(P_270
),
874 GetGdiColor(activeColor
),GetGdiColor(col
));
877 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
878 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
880 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
881 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
882 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
889 Gdiplus::LinearGradientBrush
gradient(
890 Gdiplus::Point(P_270
),
891 Gdiplus::Point(x2
+1, h
+top
-1),
892 GetGdiColor(col
),GetGdiColor(activeColor
));
895 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
896 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
898 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
899 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
900 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
909 Gdiplus::LinearGradientBrush
gradient(
910 Gdiplus::Point(x1
-2, h
+top
-2),
911 Gdiplus::Point(P_90
),
912 GetGdiColor(activeColor
),GetGdiColor(col
));
914 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
916 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
919 QConicalGradient
gradient(CENTER_DR
);
920 gradient
.setColorAt(0.375, activeCol
);
921 gradient
.setColorAt(0.625, col
);
922 myPen
.setBrush(gradient
);
924 p
->drawArc(P_CENTER
, DELTA_DR
);
933 //static QPen myPen(Qt::black, 2); // fast path here
935 pen
.CreatePen(PS_SOLID
,2,col
);
936 //myPen.setColor(col);
937 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
939 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
941 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
948 case Lanes::NOT_ACTIVE
:
949 case Lanes::MERGE_FORK
:
950 case Lanes::MERGE_FORK_R
:
951 case Lanes::MERGE_FORK_L
:
956 //DrawLine(hdc,P_90,P_270);
957 graphics
.DrawLine(&myPen
,P_90
,P_270
);
958 //p->drawLine(P_90, P_270);
962 //DrawLine(hdc,P_CENTER,P_270);
963 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
964 //p->drawLine(P_CENTER, P_270);
968 case Lanes::BOUNDARY
:
969 case Lanes::BOUNDARY_C
:
970 case Lanes::BOUNDARY_R
:
971 case Lanes::BOUNDARY_L
:
972 //DrawLine(hdc,P_90, P_CENTER);
973 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
974 //p->drawLine(P_90, P_CENTER);
980 myPen
.SetColor(GetGdiColor(activeColor
));
984 case Lanes::MERGE_FORK
:
989 case Lanes::CROSS_EMPTY
:
990 case Lanes::BOUNDARY_C
:
991 //DrawLine(hdc,P_180,P_0);
992 graphics
.DrawLine(&myPen
,P_180
,P_0
);
993 //p->drawLine(P_180, P_0);
995 case Lanes::MERGE_FORK_R
:
996 case Lanes::BOUNDARY_R
:
997 //DrawLine(hdc,P_180,P_CENTER);
998 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
999 //p->drawLine(P_180, P_CENTER);
1001 case Lanes::MERGE_FORK_L
:
1004 case Lanes::BOUNDARY_L
:
1005 //DrawLine(hdc,P_CENTER,P_0);
1006 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
1007 //p->drawLine(P_CENTER, P_0);
1013 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1016 brush
.CreateSolidBrush(col
);
1017 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1019 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1020 // center symbol, e.g. rect or ellipse
1023 case Lanes::INITIAL
:
1026 //p->setPen(Qt::NoPen);
1028 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1029 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1030 //p->drawEllipse(R_CENTER);
1032 case Lanes::MERGE_FORK
:
1033 case Lanes::MERGE_FORK_R
:
1034 case Lanes::MERGE_FORK_L
:
1035 //p->setPen(Qt::NoPen);
1037 //p->drawRect(R_CENTER);
1038 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1039 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1041 case Lanes::UNAPPLIED
:
1043 //p->setPen(Qt::NoPen);
1044 //p->setBrush(Qt::red);
1045 //p->drawRect(m - r, h - 1, d, 2);
1046 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1047 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1049 case Lanes::APPLIED
:
1051 //p->setPen(Qt::NoPen);
1052 //p->setBrush(DARK_GREEN);
1053 //p->drawRect(m - r, h - 1, d, 2);
1054 //p->drawRect(m - 1, h - r, 2, d);
1055 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1056 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1057 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1059 case Lanes::BOUNDARY
:
1060 //p->setBrush(back);
1061 //p->drawEllipse(R_CENTER);
1062 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1063 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1065 case Lanes::BOUNDARY_C
:
1066 case Lanes::BOUNDARY_R
:
1067 case Lanes::BOUNDARY_L
:
1068 //p->setBrush(back);
1069 //p->drawRect(R_CENTER);
1070 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1071 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1077 ::SelectObject(hdc
,oldpen
);
1078 ::SelectObject(hdc
,oldbrush
);
1087 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1091 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1092 if(data
->m_CommitHash
.IsEmpty())
1097 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1098 rItem
.mask
= LVIF_STATE
;
1099 rItem
.iItem
= (int)index
;
1100 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1103 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1105 if (data
->m_Lanes
.empty())
1106 m_logEntries
.setLane(data
->m_CommitHash
);
1108 std::vector
<int>& lanes
=data
->m_Lanes
;
1109 size_t laneNum
= lanes
.size();
1110 UINT activeLane
= 0;
1111 for (UINT i
= 0; i
< laneNum
; ++i
)
1112 if (Lanes::isMerge(lanes
[i
])) {
1118 int maxWidth
= rect
.Width();
1119 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1121 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1122 //if (opt.state & QStyle::State_Selected)
1123 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1125 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1132 if (ln
== Lanes::EMPTY
)
1135 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1136 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1140 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1146 if (ln
== Lanes::EMPTY
)
1149 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1150 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1152 if (ln
== Lanes::CROSS
)
1154 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1155 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1158 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1164 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1167 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1168 // Take the default processing unless we set this to something else below.
1169 *pResult
= CDRF_DODEFAULT
;
1171 if (m_bNoDispUpdates
)
1174 switch (pLVCD
->nmcd
.dwDrawStage
)
1178 *pResult
= CDRF_NOTIFYITEMDRAW
;
1182 case CDDS_ITEMPREPAINT
:
1184 // This is the prepaint stage for an item. Here's where we set the
1185 // item's text color.
1187 // Tell Windows to send draw notifications for each subitem.
1188 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1190 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1192 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1194 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1197 HGDIOBJ hGdiObj
= nullptr;
1198 int action
= data
->GetRebaseAction();
1199 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1200 crText
= RGB(128,128,128);
1202 if (action
& LOGACTIONS_REBASE_SQUASH
)
1203 pLVCD
->clrTextBk
= RGB(156,156,156);
1204 else if (action
& LOGACTIONS_REBASE_EDIT
)
1205 pLVCD
->clrTextBk
= RGB(200,200,128);
1207 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1209 if (action
& LOGACTIONS_REBASE_CURRENT
)
1210 hGdiObj
= m_boldFont
;
1212 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1213 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1214 if (isHeadHash
&& isHighlight
)
1215 hGdiObj
= m_boldItalicsFont
;
1216 else if (isHeadHash
)
1217 hGdiObj
= m_boldFont
;
1218 else if (isHighlight
)
1219 hGdiObj
= m_FontItalics
;
1223 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1224 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1227 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1228 // crText = GetSysColor(COLOR_GRAYTEXT);
1230 if (data
->m_CommitHash
.IsEmpty())
1232 //crText = GetSysColor(RGB(200,200,0));
1233 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1234 // We changed the font, so we're returning CDRF_NEWFONT. This
1235 // tells the control to recalculate the extent of the text.
1236 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1240 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1242 if (m_bStrictStopped
)
1243 crText
= GetSysColor(COLOR_GRAYTEXT
);
1245 // Store the color back in the NMLVCUSTOMDRAW struct.
1246 pLVCD
->clrText
= crText
;
1250 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1252 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1254 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1257 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1259 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1262 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1264 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1265 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1267 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1268 if( !data
->m_CommitHash
.IsEmpty())
1269 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1271 *pResult
= CDRF_SKIPDEFAULT
;
1276 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1278 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1280 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1282 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1285 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1287 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1288 // not in FillBackGround method, because this only affected the message subitem
1289 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1292 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1293 int state
= GetItemState(index
, LVIS_SELECTED
);
1294 int txtState
= LISS_NORMAL
;
1295 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1297 if (state
& LVIS_SELECTED
)
1298 txtState
= LISS_HOTSELECTED
;
1300 txtState
= LISS_HOT
;
1302 else if (state
& LVIS_SELECTED
)
1304 if (::GetFocus() == m_hWnd
)
1305 txtState
= LISS_SELECTED
;
1307 txtState
= LISS_SELECTEDNOTFOCUS
;
1310 HTHEME hTheme
= nullptr;
1311 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1312 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1314 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1315 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1318 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1319 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1320 ::DeleteObject(brush
);
1325 // get rect of whole line
1326 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1328 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1329 rect2
.DeflateRect(1, 1, 1, 1);
1331 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1332 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1334 CloseThemeData(hTheme
);
1336 // END: extended redraw
1338 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1340 std::vector
<REFLABEL
> refsToShow
;
1341 STRING_VECTOR remoteTrackingList
;
1342 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1343 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1345 CString str
= refList
[i
];
1348 refLabel
.color
= RGB(255, 255, 255);
1349 refLabel
.singleRemote
= false;
1350 refLabel
.hasTracking
= false;
1351 refLabel
.sameName
= false;
1352 refLabel
.annotatedTag
= false;
1353 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1355 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1357 if (refLabel
.name
== m_CurrentBranch
)
1358 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1360 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1362 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1363 CString pullRemote
= trackingEntry
.first
;
1364 CString pullBranch
= trackingEntry
.second
;
1365 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1367 CString defaultUpstream
;
1368 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1369 refLabel
.hasTracking
= true;
1370 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1373 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1375 if (refList
[j
] == defaultUpstream
)
1384 bool sameName
= pullBranch
== refLabel
.name
;
1385 refsToShow
.push_back(refLabel
);
1386 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1387 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1388 if (m_bSymbolizeRefNames
)
1390 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1392 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1393 refLabel
.singleRemote
= true;
1396 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1397 refLabel
.sameName
= sameName
;
1399 refsToShow
.push_back(refLabel
);
1400 remoteTrackingList
.push_back(defaultUpstream
);
1406 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1408 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1412 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1414 if (remoteTrackingList
[j
] == str
)
1423 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1424 if (m_bSymbolizeRefNames
)
1426 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1428 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1429 refLabel
.singleRemote
= true;
1433 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1435 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1437 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1438 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1440 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1442 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1444 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1445 refLabel
.name
= _T("stash");
1447 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1449 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1451 if (refLabel
.name
.Find(_T("good")) == 0)
1453 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1454 refLabel
.name
= _T("good");
1456 if (refLabel
.name
.Find(_T("bad")) == 0)
1458 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1459 refLabel
.name
= _T("bad");
1465 refsToShow
.push_back(refLabel
);
1468 if (refsToShow
.empty())
1470 *pResult
= CDRF_DODEFAULT
;
1474 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1476 *pResult
= CDRF_SKIPDEFAULT
;
1484 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1486 if(this->m_IsIDReplaceAction
)
1488 *pResult
= CDRF_DODEFAULT
;
1491 *pResult
= CDRF_DODEFAULT
;
1493 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1497 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1498 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1500 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1502 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1503 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1504 // Get the selected state of the
1505 // item being drawn.
1507 // Fill the background if necessary
1508 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1510 // Draw the icon(s) into the compatible DC
1511 int action
= SafeGetAction(pLogEntry
);
1513 if (!pLogEntry
->m_IsDiffFiles
)
1514 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1516 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1517 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1520 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1521 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1524 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1525 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1528 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1529 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1531 *pResult
= CDRF_SKIPDEFAULT
;
1537 *pResult
= CDRF_DODEFAULT
;
1540 CString
FindSVNRev(const CString
& msg
)
1544 const std::tr1::wsregex_iterator end
;
1545 std::wstring s
= msg
;
1546 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
)
1548 const std::tr1::wsmatch match
= *it
;
1549 if (match
.size() == 4)
1551 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1552 return std::wstring(match
[2]).c_str();
1555 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
)
1557 const std::tr1::wsmatch match
= *it
;
1558 if (match
.size() == 3)
1560 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1561 return std::wstring(match
[1]).c_str();
1565 catch (std::exception
) {}
1570 // CGitLogListBase message handlers
1572 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1574 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1576 // Create a pointer to the item
1577 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1579 // Do the list need text information?
1580 if (!(pItem
->mask
& LVIF_TEXT
))
1583 // By default, clear text buffer.
1584 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1586 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1589 if (m_bNoDispUpdates
|| bOutOfRange
)
1592 // Which item number?
1593 int itemid
= pItem
->iItem
;
1594 GitRev
* pLogEntry
= NULL
;
1595 if (itemid
< m_arShownList
.GetCount())
1596 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1601 temp
.Format(_T("%d"),pItem
->iItem
+1);
1606 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1610 switch (pItem
->iSubItem
)
1612 case this->LOGLIST_GRAPH
: //Graphic
1614 case this->LOGLIST_REBASE
:
1616 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1617 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
);
1620 case this->LOGLIST_ACTION
: //action -- no text in the column
1622 case this->LOGLIST_HASH
:
1624 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1626 case this->LOGLIST_ID
:
1627 if(this->m_IsIDReplaceAction
)
1628 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1630 case this->LOGLIST_MESSAGE
: //Message
1632 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1634 case this->LOGLIST_AUTHOR
: //Author
1636 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1638 case this->LOGLIST_DATE
: //Date
1639 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1640 lstrcpyn(pItem
->pszText
,
1641 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1645 case this->LOGLIST_EMAIL
:
1647 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1650 case this->LOGLIST_COMMIT_NAME
: //Commit
1652 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1655 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1657 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1660 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1661 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1662 lstrcpyn(pItem
->pszText
,
1663 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1666 case this->LOGLIST_BUG
: //Bug ID
1668 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1670 case this->LOGLIST_SVNREV
: //SVN revision
1672 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1680 bool CGitLogListBase::IsOnStash(int index
)
1682 GitRev
*rev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
));
1687 GitRev
*preRev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
- 1));
1688 if (IsStash(preRev
))
1689 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1694 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1696 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1698 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1704 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1706 if (pRev
->m_ParentHash
.empty())
1710 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1712 catch (const char* msg
)
1714 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1717 parentHash
= pRev
->m_ParentHash
;
1720 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1723 if (pWnd
== GetHeaderCtrl())
1725 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1728 int selIndex
= GetSelectionMark();
1730 return; // nothing selected, nothing to do with a context menu
1732 // if the user selected the info text telling about not all revisions shown due to
1733 // the "stop on copy/rename" option, we also don't show the context menu
1734 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1737 // if the context menu is invoked through the keyboard, we have to use
1738 // a calculated position on where to anchor the menu on
1739 if ((point
.x
== -1) && (point
.y
== -1))
1742 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1743 ClientToScreen(&rect
);
1744 point
= rect
.CenterPoint();
1746 m_nSearchIndex
= selIndex
;
1747 m_bCancelled
= FALSE
;
1749 // calculate some information the context menu commands can use
1750 // CString pathURL = GetURLFromPath(m_path);
1752 POSITION pos
= GetFirstSelectedItemPosition();
1753 int indexNext
= GetNextSelectedItem(pos
);
1757 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1758 if (pSelLogEntry
== nullptr)
1761 GitRev revSelected
= pSelLogEntry
->Rev
;
1762 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1763 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1765 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1767 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1768 if (changedpath
->lCopyFromRev
)
1769 revPrevious
= changedpath
->lCopyFromRev
;
1772 GitRev revSelected2
;
1775 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1776 revSelected2
= pLogEntry
->Rev
;
1778 bool bAllFromTheSameAuthor
= true;
1779 CString firstAuthor
;
1780 CLogDataVector selEntries
;
1781 GitRev revLowest
, revHighest
;
1782 GitRevRangeArray revisionRanges
;
1784 POSITION pos
= GetFirstSelectedItemPosition();
1785 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1786 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1787 selEntries
.push_back(pLogEntry
);
1788 firstAuthor
= pLogEntry
->sAuthor
;
1789 revLowest
= pLogEntry
->Rev
;
1790 revHighest
= pLogEntry
->Rev
;
1793 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1794 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1795 selEntries
.push_back(pLogEntry
);
1796 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1797 bAllFromTheSameAuthor
= false;
1798 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1799 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1805 int FirstSelect
=-1, LastSelect
=-1;
1806 pos
= GetFirstSelectedItemPosition();
1807 FirstSelect
= GetNextSelectedItem(pos
);
1810 LastSelect
= GetNextSelectedItem(pos
);
1812 //entry is selected, now show the popup menu
1814 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1816 if (popup
.CreatePopupMenu())
1818 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1819 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1820 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1821 bool isStash
= IsOnStash(indexNext
);
1822 GIT_REV_LIST parentHash
;
1823 GetParentHashes(pSelLogEntry
, parentHash
);
1825 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1826 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1828 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1829 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1831 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1832 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1834 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1835 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1837 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
)))
1838 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1840 if (GetSelectedCount() == 1)
1843 bool requiresSeparator
= false;
1844 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1846 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1848 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1849 requiresSeparator
= true;
1854 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1856 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1857 requiresSeparator
= true;
1859 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1861 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1862 requiresSeparator
= true;
1866 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1868 if (parentHash
.size() == 1)
1870 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1871 requiresSeparator
= true;
1873 else if (parentHash
.size() > 1)
1875 blamemenu
.CreatePopupMenu();
1876 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1877 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1880 str
.Format(IDS_PARENT
, i
+ 1);
1881 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1883 requiresSeparator
= true;
1887 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1889 if (parentHash
.size() == 1)
1891 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1892 requiresSeparator
= true;
1894 else if (parentHash
.size() > 1)
1896 gnudiffmenu
.CreatePopupMenu();
1897 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1899 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1900 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1902 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1905 str
.Format(IDS_PARENT
, i
+ 1);
1906 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1908 requiresSeparator
= true;
1912 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1914 if (parentHash
.size() == 1)
1916 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1917 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1918 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1919 requiresSeparator
= true;
1921 else if (parentHash
.size() > 1)
1923 diffmenu
.CreatePopupMenu();
1924 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1925 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1928 str
.Format(IDS_PARENT
, i
+ 1);
1929 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1930 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1932 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1933 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1936 requiresSeparator
= true;
1940 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1942 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1943 requiresSeparator
= true;
1946 if (requiresSeparator
)
1947 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1949 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1951 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1952 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1955 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1957 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1958 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1960 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1961 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1963 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1966 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1968 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1969 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1971 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1972 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1974 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
1975 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1977 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1979 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1980 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1982 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1986 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1988 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1990 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1992 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1994 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1995 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1997 // popup.AppendMenu(MF_SEPARATOR, NULL);
2002 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2004 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2006 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2007 GetSelectedCount() == 1)
2008 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2010 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2011 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2013 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
2014 str
.Format(format
,g_Git
.GetCurrentBranch());
2016 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2017 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2019 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
2020 str
.Format(format
,g_Git
.GetCurrentBranch());
2022 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2023 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2026 // Add Switch Branch express Menu
2027 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2028 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2031 std::vector
<CString
*> branchs
;
2032 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2034 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2035 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2037 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2042 str
.LoadString(IDS_SWITCH_BRANCH
);
2044 if(branchs
.size() == 1)
2047 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2048 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
2050 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2053 else if(branchs
.size() > 1)
2055 subbranchmenu
.CreatePopupMenu();
2056 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2058 if (*branchs
[i
] != currentBranch
)
2060 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2061 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2065 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2069 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2070 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2072 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2073 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2075 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2076 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2078 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
2079 str
.Format(format
,g_Git
.GetCurrentBranch());
2081 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2082 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2083 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2085 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2086 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2088 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2090 if (parentHash
.size() == 1)
2092 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2094 else if (parentHash
.size() > 1)
2096 revertmenu
.CreatePopupMenu();
2097 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2099 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2102 str
.Format(IDS_PARENT
, i
+ 1);
2103 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
2108 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2109 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2111 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2116 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2118 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2119 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2120 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2121 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2124 if (GetSelectedCount() >= 2)
2126 bool bAddSeparator
= false;
2127 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2129 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2130 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2133 if (GetSelectedCount() == 2)
2135 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2136 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2138 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2140 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2141 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2142 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2144 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
2145 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2146 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
2147 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2150 bAddSeparator
= true;
2155 bAddSeparator
= true;
2158 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2159 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2162 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2165 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2167 bool bAddSeparator
= false;
2168 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2170 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2174 headindex
= this->GetHeadIndex();
2175 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2177 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2179 if (g_Git
.GetHash(hashFirst
, head
))
2180 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2181 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2183 if (g_Git
.GetHash(hash
, head
))
2184 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2185 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2186 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2187 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2188 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2189 bAddSeparator
= true;
2194 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2195 if (GetSelectedCount() >= 2)
2196 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2198 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2199 bAddSeparator
= true;
2202 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2203 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2204 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2205 bAddSeparator
= true;
2209 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2212 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())
2214 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2215 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2218 if (GetSelectedCount() == 1)
2220 bool bAddSeparator
= false;
2221 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
2223 // show the push-option only if the log entry has an associated local branch
2224 bool isLocal
= false;
2225 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2227 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2232 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2233 bAddSeparator
= true;
2236 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2238 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2239 bAddSeparator
= true;
2243 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2245 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2247 std::vector
<CString
*> branchs
;
2248 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2250 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2251 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2254 if (branchs
.size() == 1)
2256 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2259 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2260 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2261 bAddSeparator
= true;
2263 else if (branchs
.size() > 1)
2265 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2266 submenu
.CreatePopupMenu();
2267 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2269 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2270 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2273 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2274 bAddSeparator
= true;
2277 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2279 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2280 } // GetSelectedCount() == 1
2282 if (GetSelectedCount() != 0)
2284 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2285 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2286 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2287 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2288 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2289 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2292 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2293 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2295 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2296 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2298 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2299 // DialogEnableWindow(IDOK, FALSE);
2300 // SetPromptApp(&theApp);
2302 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2304 // EnableOKButton();
2305 } // if (popup.CreatePopupMenu())
2309 bool CGitLogListBase::IsSelectionContinuous()
2311 if ( GetSelectedCount()==1 )
2313 // if only one revision is selected, the selection is of course
2318 POSITION pos
= GetFirstSelectedItemPosition();
2319 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2322 int itemindex
= GetNextSelectedItem(pos
);
2325 int nextindex
= GetNextSelectedItem(pos
);
2326 if (nextindex
- itemindex
> 1)
2328 bContinuous
= false;
2331 itemindex
= nextindex
;
2337 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2341 POSITION pos
= GetFirstSelectedItemPosition();
2345 sRev
.LoadString(IDS_LOG_REVISION
);
2347 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2349 sDate
.LoadString(IDS_LOG_DATE
);
2351 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2355 CString sLogCopyText
;
2357 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2359 if (toCopy
== ID_COPY_ALL
)
2361 //pLogEntry->GetFiles(this)
2362 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2364 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2365 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2367 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2368 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2371 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2372 sPaths
+= _T(" ") + rename
;
2374 sPaths
+= _T("\r\n");
2377 CString body
= pLogEntry
->GetBody();
2378 body
.Replace(_T("\n"), _T("\r\n"));
2379 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"),
2380 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2381 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2383 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2384 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2386 sClipdata
+= sLogCopyText
;
2388 else if (toCopy
== ID_COPY_MESSAGE
)
2390 CString body
= pLogEntry
->GetBody();
2391 body
.Replace(_T("\n"), _T("\r\n"));
2392 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2394 else if (toCopy
== ID_COPY_SUBJECT
)
2396 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2401 sClipdata
+= _T("\r\n");
2402 sClipdata
+= pLogEntry
->m_CommitHash
;
2407 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2412 void CGitLogListBase::DiffSelectedRevWithPrevious()
2414 if (m_bThreadRunning
)
2417 int FirstSelect
=-1, LastSelect
=-1;
2418 POSITION pos
= GetFirstSelectedItemPosition();
2419 FirstSelect
= GetNextSelectedItem(pos
);
2422 LastSelect
= GetNextSelectedItem(pos
);
2425 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2428 UpdateLogInfoLabel();
2429 int selIndex
= m_LogList
.GetSelectionMark();
2432 int selCount
= m_LogList
.GetSelectedCount();
2436 // Find selected entry in the log list
2437 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2438 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2439 long rev1
= pLogEntry
->Rev
;
2441 CTGitPath path
= m_path
;
2443 // See how many files under the relative root were changed in selected revision
2445 LogChangedPath
* changed
= NULL
;
2446 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2448 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2449 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2456 if (m_path
.IsDirectory() && nChanged
== 1)
2458 // We're looking at the log for a directory and only one file under dir was changed in the revision
2459 // Do diff on that file instead of whole directory
2460 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2463 m_bCancelled
= FALSE
;
2464 DialogEnableWindow(IDOK
, FALSE
);
2465 SetPromptApp(&theApp
);
2466 theApp
.DoWaitCursor(1);
2470 GitDiff
diff(this, m_hWnd
, true);
2471 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2472 diff
.SetHEADPeg(m_LogRevision
);
2473 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2477 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2480 theApp
.DoWaitCursor(-1);
2485 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2487 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2490 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2492 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2494 if (pFindInfo
->lvfi
.psz
== 0)
2497 CString sCmp
= pFindInfo
->lvfi
.psz
;
2499 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2501 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2502 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2503 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2505 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2513 if (sCmp
.Compare(sRev
)==0)
2520 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2522 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2524 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2525 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2526 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2528 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2536 if (sCmp
.Compare(sRev
)==0)
2548 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2552 this->m_arShownList
.SafeRemoveAll();
2554 this->m_logEntries
.ClearAll();
2555 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2558 //this->m_logEntries.ParserFromLog();
2559 SetItemCountEx((int)m_logEntries
.size());
2561 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2565 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2566 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2571 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2572 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2584 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2588 m_arShownList
.SafeRemoveAll();
2590 m_logEntries
.ClearAll();
2591 if (m_logEntries
.Fill(hashes
))
2594 SetItemCountEx((int)m_logEntries
.size());
2596 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2600 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2601 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2605 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2606 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2615 int CGitLogListBase::BeginFetchLog()
2619 this->m_arShownList
.SafeRemoveAll();
2621 this->m_logEntries
.ClearAll();
2623 this->m_LogCache
.ClearAllParent();
2625 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2628 if(this->m_Path
.IsEmpty())
2634 mask
= CGit::LOG_INFO_ONLY_HASH
;
2635 if (m_bIncludeBoundaryCommits
)
2636 mask
|= CGit::LOG_INFO_BOUNDARY
;
2637 // if(this->m_bAllBranch)
2638 mask
|= m_ShowMask
;
2642 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2644 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2647 if (m_sRange
.IsEmpty())
2648 m_sRange
= _T("HEAD");
2651 data
.m_From
= m_From
;
2654 #if 0 /* use tortoiegit filter */
2655 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2656 data
.m_Author
= this->m_sFilterText
;
2658 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2659 data
.m_MessageFilter
= this->m_sFilterText
;
2661 data
.m_IsRegex
= m_bFilterWithRegex
;
2664 // follow does not work for directories
2665 if (!path
|| path
->IsDirectory())
2666 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2667 // follow does not work with all branches 8at least in TGit)
2668 if (mask
& CGit::LOG_INFO_FOLLOW
)
2669 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2671 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2673 //this->m_logEntries.ParserFromLog();
2674 if(IsInWorkingThread())
2676 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2680 SetItemCountEx((int)m_logEntries
.size());
2685 [] { git_init(); } ();
2690 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2694 if (!g_Git
.CanParseRev(m_sRange
))
2696 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2699 // if show all branches, pick any ref as dummy entry ref
2701 if (g_Git
.GetRefList(list
))
2702 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2703 if (list
.size() == 0)
2706 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2709 g_Git
.m_critGitDllSec
.Lock();
2711 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2713 g_Git
.m_critGitDllSec
.Unlock();
2719 g_Git
.m_critGitDllSec
.Unlock();
2721 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2724 g_Git
.m_critGitDllSec
.Unlock();
2729 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2731 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2733 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2735 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2737 DiffSelectedRevWithPrevious();
2742 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2749 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2751 // select all entries
2752 for (int i
=0; i
<GetItemCount(); ++i
)
2754 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2760 if (m_hAccel
&& !bSkipAccelerator
)
2762 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2768 //m_tooltips.RelayEvent(pMsg);
2769 return __super::PreTranslateMessage(pMsg
);
2772 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2774 // a double click on an entry in the revision list has happened
2777 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2778 DiffSelectedRevWithPrevious();
2781 int CGitLogListBase::FetchLogAsync(void * data
)
2785 m_bExitThread
=FALSE
;
2786 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2787 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2788 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2789 if (m_LoadingThread
==NULL
)
2791 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2792 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2793 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2799 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2801 return ((CGitLogListBase
*)pVoid
)->LogThread();
2804 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2807 oldest
=CTime::GetCurrentTime();
2808 latest
=CTime(1971,1,2,0,0,0);
2809 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2811 if(m_logEntries
[i
].IsEmpty())
2814 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2815 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2817 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2818 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2826 UINT
CGitLogListBase::LogThread()
2828 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2830 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2831 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2837 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2838 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2843 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2844 bool bRegex
= false;
2845 if (m_bFilterWithRegex
)
2846 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2848 TRACE(_T("\n===Begin===\n"));
2849 //Update work copy item;
2851 if (!m_logEntries
.empty())
2853 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2855 m_arShownList
.SafeAdd(pRev
);
2859 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2861 // store commit number of the last selected commit/line before the refresh or -1
2862 int lastSelectedHashNItem
= -1;
2865 bool shouldWalk
= true;
2866 if (!g_Git
.CanParseRev(m_sRange
))
2868 // walk revisions if show all branches and there exists any ref
2869 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2874 if (g_Git
.GetRefList(list
))
2875 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2876 if (list
.size() == 0)
2883 g_Git
.m_critGitDllSec
.Lock();
2887 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2888 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2893 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2896 g_Git
.m_critGitDllSec
.Unlock();
2899 t2
=t1
=GetTickCount();
2900 int oldprecentage
= 0;
2901 size_t oldsize
= m_logEntries
.size();
2902 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2903 while (ret
== 0 && !m_bExitThread
)
2905 g_Git
.m_critGitDllSec
.Lock();
2908 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2912 g_Git
.m_critGitDllSec
.Unlock();
2914 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2917 g_Git
.m_critGitDllSec
.Unlock();
2921 if (ret
!= -2) // other than end of revision walking
2922 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2926 if (commit
.m_ignore
== 1)
2928 git_free_commit(&commit
);
2932 //printf("%s\r\n",commit.GetSubject());
2936 CGitHash hash
= (char*)commit
.m_hash
;
2938 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2939 pRev
->m_GitCommit
= commit
;
2940 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2943 g_Git
.m_critGitDllSec
.Lock();
2946 git_get_notes(commit
.m_hash
, ¬e
);
2950 g_Git
.m_critGitDllSec
.Unlock();
2952 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2955 g_Git
.m_critGitDllSec
.Unlock();
2959 pRev
->m_Notes
.Empty();
2960 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2965 if(!pRev
->m_IsDiffFiles
)
2967 pRev
->m_CallDiffAsync
= DiffAsync
;
2970 pRev
->ParserParentFromCommit(&commit
);
2971 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2973 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2975 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2976 auto it
= commitChildren
.find(parentHash
);
2977 if (it
== commitChildren
.end())
2979 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2981 it
->second
.insert(pRev
->m_CommitHash
);
2990 bool visible
= true;
2991 if (HasFilterText())
2993 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2996 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
2998 this->m_critSec
.Lock();
2999 m_logEntries
.append(hash
, visible
);
3001 m_arShownList
.SafeAdd(pRev
);
3002 this->m_critSec
.Unlock();
3007 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3008 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3012 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3015 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3018 if(percent
< GITLOG_START
)
3019 percent
= GITLOG_START
+1;
3021 oldsize
= m_logEntries
.size();
3022 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3024 //if( percent > oldprecentage )
3026 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3027 oldprecentage
= percent
;
3030 if (lastSelectedHashNItem
>= 0)
3031 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3036 g_Git
.m_critGitDllSec
.Lock();
3037 git_close_log(m_DllGitLog
);
3038 g_Git
.m_critGitDllSec
.Unlock();
3044 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3049 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3051 if (lastSelectedHashNItem
>= 0)
3052 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3055 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3057 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3062 void CGitLogListBase::FetchRemoteList()
3064 STRING_VECTOR remoteList
;
3065 if (!g_Git
.GetRemoteList(remoteList
))
3066 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3068 m_SingleRemote
= _T("");
3071 void CGitLogListBase::FetchTrackingBranchList()
3073 m_TrackingMap
.clear();
3074 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3076 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3079 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3081 CString pullRemote
, pullBranch
;
3082 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3083 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3085 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3092 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3094 SafeTerminateThread();
3096 this->SetItemCountEx(0);
3101 // HACK to hide graph column
3102 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3103 SetColumnWidth(0, 0);
3105 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3107 //Update branch and Tag info
3110 m_pFindDialog
->RefreshList();
3111 //Assume Thread have exited
3112 //if(!m_bThreadRunning)
3114 m_logEntries
.clear();
3118 m_sFilterText
.Empty();
3123 InterlockedExchange(&m_bExitThread
,FALSE
);
3125 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3126 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3127 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3129 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3130 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3131 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3135 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3139 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3141 type
|= std::tr1::regex_constants::icase
;
3142 pat
= std::tr1::wregex(regexp_str
, type
);
3145 catch (std::exception
) {}
3148 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
)
3151 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3154 if ((bRegex
)&&(m_bFilterWithRegex
))
3156 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3158 if(this->m_bShowBugtraqColumn
)
3160 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3162 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
3163 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3170 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3172 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
3173 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3179 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3181 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
3182 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3188 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3190 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3195 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3201 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3203 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3208 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3214 if (m_SelectedFilters
& LOGFILTER_REVS
)
3216 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3217 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3223 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3225 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3226 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3228 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3235 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3237 CTGitPathList
*pathList
=NULL
;
3238 if( pRev
->m_IsDiffFiles
)
3239 pathList
= &pRev
->GetFiles(this);
3242 if(!pRev
->m_IsSimpleListReady
)
3243 pRev
->SafeGetSimpleList(&g_Git
);
3247 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3249 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3253 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3259 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3261 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3270 CString find
= m_sFilterText
;
3271 if (!m_bFilterCaseSensitively
)
3273 result
= find
[0] == '!' ? FALSE
: TRUE
;
3277 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3279 if(this->m_bShowBugtraqColumn
)
3281 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3283 if (!m_bFilterCaseSensitively
)
3284 sBugIds
.MakeLower();
3285 if ((sBugIds
.Find(find
) >= 0))
3292 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3294 CString msg
= pRev
->GetSubject();
3296 if (!m_bFilterCaseSensitively
)
3297 msg
= msg
.MakeLower();
3298 if ((msg
.Find(find
) >= 0))
3304 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3306 CString msg
= pRev
->GetBody();
3308 if (!m_bFilterCaseSensitively
)
3309 msg
= msg
.MakeLower();
3310 if ((msg
.Find(find
) >= 0))
3316 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3318 CString msg
= pRev
->GetAuthorName();
3319 if (!m_bFilterCaseSensitively
)
3320 msg
= msg
.MakeLower();
3321 if ((msg
.Find(find
) >= 0))
3327 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3329 CString msg
= pRev
->GetAuthorEmail();
3330 if (!m_bFilterCaseSensitively
)
3331 msg
= msg
.MakeLower();
3332 if ((msg
.Find(find
) >= 0))
3338 if (m_SelectedFilters
& LOGFILTER_REVS
)
3340 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3341 if ((sRev
.Find(find
) >= 0))
3347 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3349 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3350 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3352 if (it
->Find(find
) >= 0)
3359 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3361 CTGitPathList
*pathList
=NULL
;
3362 if( pRev
->m_IsDiffFiles
)
3363 pathList
= &pRev
->GetFiles(this);
3366 if(!pRev
->m_IsSimpleListReady
)
3367 pRev
->SafeGetSimpleList(&g_Git
);
3370 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3372 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3373 CString path
= cpath
->GetGitOldPathString();
3374 if (!m_bFilterCaseSensitively
)
3376 if ((path
.Find(find
)>=0))
3380 path
= cpath
->GetGitPathString();
3381 if (!m_bFilterCaseSensitively
)
3383 if ((path
.Find(find
)>=0))
3389 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3391 CString path
= pRev
->m_SimpleFileList
[i
];
3392 if (!m_bFilterCaseSensitively
)
3394 if ((path
.Find(find
)>=0))
3400 } // else (from if (bRegex))
3404 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3406 return str
.Left(prefix
.GetLength()) == prefix
;
3408 bool CGitLogListBase::ShouldShowFilter(GitRev
*pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>> &commitChildren
)
3410 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3413 if (m_ShowFilter
& FILTERSHOW_REFS
)
3416 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3417 for (size_t i
= 0; i
< refList
.size(); ++i
)
3419 const CString
&str
= refList
[i
];
3420 if (CStringStartsWith(str
, _T("refs/heads/")))
3422 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3425 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3427 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3430 else if (CStringStartsWith(str
, _T("refs/tags/")))
3432 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3435 else if (CStringStartsWith(str
, _T("refs/stash")))
3437 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3440 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3442 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3446 // Keep the head too.
3447 if (pRev
->m_CommitHash
== m_HeadHash
)
3451 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3453 if (pRev
->ParentsCount() > 1)
3455 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3456 if (childrenIt
!= commitChildren
.end())
3458 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3459 if (children
.size() > 1)
3466 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3468 // HACK to hide graph column
3470 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3472 SetColumnWidth(0, 0);
3475 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3480 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3482 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3483 for (size_t i
= 0; i
< vector
.size(); ++i
)
3485 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3487 CString tag
= vector
[i
];
3488 int start
= vector
[i
].Find(_T("^{}"));
3490 tag
= tag
.Left(start
);
3494 cmd
.Format(_T("git.exe cat-file tag %s"), tag
);
3495 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3496 output
.AppendChar(_T('\n'));
3504 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3507 pShownlist
->SafeRemoveAll();
3509 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3510 bool bRegex
= false;
3511 if (m_bFilterWithRegex
)
3512 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3514 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3516 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3518 if ((bRegex
)&&(m_bFilterWithRegex
))
3521 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3523 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3524 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3526 pShownlist
->SafeAdd(m_logEntries
[i
]);
3531 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3533 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3534 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3536 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3540 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3542 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3543 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3545 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3549 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3551 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3554 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3556 CTGitPath cpath
= pathList
[cpPathIndex
];
3557 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3559 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3563 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3565 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3569 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3571 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3577 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3579 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3581 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3585 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3587 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3589 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3593 if (m_SelectedFilters
& LOGFILTER_REVS
)
3595 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3596 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3598 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3602 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3604 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3605 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3607 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3609 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3617 CString find
= m_sFilterText
;
3618 if (!m_bFilterCaseSensitively
)
3621 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3623 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3625 if (!m_bFilterCaseSensitively
)
3626 sBugIDs
= sBugIDs
.MakeLower();
3627 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3629 pShownlist
->SafeAdd(m_logEntries
[i
]);
3634 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3636 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3638 if (!m_bFilterCaseSensitively
)
3639 msg
= msg
.MakeLower();
3640 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3642 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3646 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3648 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3650 if (!m_bFilterCaseSensitively
)
3651 msg
= msg
.MakeLower();
3652 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3654 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3658 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3660 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3663 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3665 CTGitPath cpath
= pathList
[cpPathIndex
];
3666 CString path
= cpath
.GetGitOldPathString();
3667 if (!m_bFilterCaseSensitively
)
3669 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3671 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3675 path
= cpath
.GetGitPathString();
3676 if (!m_bFilterCaseSensitively
)
3678 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3680 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3684 path
= cpath
.GetActionName();
3685 if (!m_bFilterCaseSensitively
)
3687 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3689 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3695 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3697 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3698 if (!m_bFilterCaseSensitively
)
3699 msg
= msg
.MakeLower();
3700 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3702 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3706 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3708 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3709 if (!m_bFilterCaseSensitively
)
3710 msg
= msg
.MakeLower();
3711 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3713 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3717 if (m_SelectedFilters
& LOGFILTER_REVS
)
3719 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3720 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3722 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3726 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3728 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3729 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3731 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3733 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3738 } // else (from if (bRegex))
3739 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3743 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3746 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3752 return time <= m_To;
3755 return time >= m_From;
3757 return ((time >= m_From)&&(time <= m_To));
3759 return TRUE
; /* git dll will filter time range */
3763 void CGitLogListBase::StartFilter()
3765 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3766 RecalculateShownList(&m_arShownList
);
3767 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3771 SetItemCountEx(ShownCountWithStopped());
3772 RedrawItems(0, ShownCountWithStopped());
3776 void CGitLogListBase::RemoveFilter()
3779 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3781 m_arShownList
.SafeRemoveAll();
3783 // reset the time filter too
3785 m_timFrom
= (__time64_t(m_tFrom
));
3786 m_timTo
= (__time64_t(m_tTo
));
3787 m_DateFrom
.SetTime(&m_timFrom
);
3788 m_DateTo
.SetTime(&m_timTo
);
3789 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3790 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3793 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3795 if(this->m_IsOldFirst
)
3797 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3801 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3804 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3806 SetItemCountEx(ShownCountWithStopped());
3807 RedrawItems(0, ShownCountWithStopped());
3809 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3812 void CGitLogListBase::Clear()
3814 m_arShownList
.SafeRemoveAll();
3817 m_logEntries
.ClearAll();
3821 void CGitLogListBase::OnDestroy()
3823 // save the column widths to the registry
3826 SafeTerminateThread();
3827 SafeTerminateAsyncDiffThread();
3830 while(m_LogCache
.SaveCache())
3838 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3839 // MB_YESNO) == IDNO)
3843 CHintListCtrl::OnDestroy();
3846 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3850 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3851 this->InvalidateRect(rect
);
3857 * Save column widths to the registry
3859 void CGitLogListBase::SaveColumnWidths()
3861 int maxcol
= m_ColumnManager
.GetColumnCount();
3863 // HACK that graph column is always shown
3864 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3866 for (int col
= 0; col
< maxcol
; ++col
)
3867 if (m_ColumnManager
.IsVisible (col
))
3868 m_ColumnManager
.ColumnResized (col
);
3870 m_ColumnManager
.WriteSettings();
3873 int CGitLogListBase::GetHeadIndex()
3875 if(m_HeadHash
.IsEmpty())
3878 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3880 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3883 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3889 void CGitLogListBase::OnFind()
3893 m_pFindDialog
= new CFindDlg(this);
3894 m_pFindDialog
->Create(this);
3897 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3899 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3901 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3903 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3906 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3908 if (GetSelectedCount() != 0)
3911 CGitHash theSelectedHash
= m_lastSelectedHash
;
3912 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3913 m_lastSelectedHash
= theSelectedHash
;
3915 int countPerPage
= GetCountPerPage();
3916 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3917 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3918 EnsureVisible((int)itemToSelect
, FALSE
);
3921 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3924 ASSERT(m_pFindDialog
!= NULL
);
3925 bool bFound
= false;
3928 if (m_pFindDialog
->IsTerminating())
3930 // invalidate the handle identifying the dialog box.
3931 m_pFindDialog
= NULL
;
3935 INT_PTR cnt
= m_arShownList
.GetCount();
3937 if(m_pFindDialog
->IsRef())
3940 str
=m_pFindDialog
->GetFindString();
3946 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3947 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3952 for (i
= 0; i
< cnt
; ++i
)
3954 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3955 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3964 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3969 if (m_pFindDialog
->FindNext() && !bFound
)
3971 //read data from dialog
3972 CString findText
= m_pFindDialog
->GetFindString();
3973 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3975 std::tr1::wregex pat
;
3976 bool bRegex
= false;
3977 if (m_pFindDialog
->Regex())
3978 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3980 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3982 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3987 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3989 if (m_nSearchIndex
>= 0)
3991 if (i
== m_nSearchIndex
)
3993 ::MessageBeep(0xFFFFFFFF);
3994 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3999 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4002 str
+=pLogEntry
->m_CommitHash
.ToString();
4005 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4007 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4011 str
+=pLogEntry
->GetAuthorEmail();
4013 str
+=pLogEntry
->GetAuthorName();
4015 str
+=pLogEntry
->GetBody();
4017 str
+=pLogEntry
->GetCommitterEmail();
4019 str
+=pLogEntry
->GetCommitterName();
4021 str
+=pLogEntry
->GetSubject();
4023 str
+=pLogEntry
->m_Notes
;
4025 str
+=GetTagInfo(pLogEntry
);
4029 /*Because changed files list is loaded on demand when gui show,
4030 files will empty when files have not fetched.
4032 we can add it back by using one-way diff(with outnumber changed and rename detect.
4033 here just need changed filename list. one-way is much quicker.
4035 if(pLogEntry
->m_IsFull
)
4037 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
4039 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
4041 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
4047 if(!pLogEntry
->m_IsSimpleListReady
)
4048 pLogEntry
->SafeGetSimpleList(&g_Git
);
4050 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
4052 str
+=pLogEntry
->m_SimpleFileList
[i
];
4061 if (std::regex_search(std::wstring(str
), pat
, flags
))
4071 if (str
.Find(findText
) >= 0)
4081 msg
= msg
.MakeLower();
4082 CString find
= findText
.MakeLower();
4083 if (msg
.Find(find
) >= 0)
4090 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4092 } // if(m_pFindDialog->FindNext())
4093 //UpdateLogInfoLabel();
4098 EnsureVisible(i
, FALSE
);
4099 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4101 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4102 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4103 SetSelectionMark(i
);
4107 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4109 m_highlight
= pLogEntry
->m_CommitHash
;
4112 //FillLogMessageCtrl();
4119 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4121 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4126 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4128 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);