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"), TRUE
);
110 m_LoadingThread
= NULL
;
112 InterlockedExchange(&m_bExitThread
,FALSE
);
113 m_IsOldFirst
= FALSE
;
114 m_IsRebaseReplaceGraph
= FALSE
;
116 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
118 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
120 // get short/long datetime setting from registry
121 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
122 if ( RegUseShortDateFormat
)
124 m_DateFormat
= DATE_SHORTDATE
;
128 m_DateFormat
= DATE_LONGDATE
;
130 // get relative time display setting from registry
131 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
132 m_bRelativeTimes
= (regRelativeTimes
!= 0);
133 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
135 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
136 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
137 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
138 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
139 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
140 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
141 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
143 m_ColumnRegKey
=_T("log");
145 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
146 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
147 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
149 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
150 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
152 m_AsyncThreadExit
= FALSE
;
153 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
154 m_AsynDiffListLock
.Init();
156 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
157 if (m_DiffingThread
==NULL
)
159 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
165 int CGitLogListBase::AsyncDiffThread()
167 m_AsyncThreadExited
= false;
168 while(!m_AsyncThreadExit
)
170 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
173 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
175 m_AsynDiffListLock
.Lock();
176 pRev
= m_AsynDiffList
.back();
177 m_AsynDiffList
.pop_back();
178 m_AsynDiffListLock
.Unlock();
180 if( pRev
->m_CommitHash
.IsEmpty() )
182 if(pRev
->m_IsDiffFiles
)
185 pRev
->GetFiles(this).Clear();
186 pRev
->m_ParentHash
.clear();
187 pRev
->m_ParentHash
.push_back(m_HeadHash
);
188 if(g_Git
.IsInitRepos())
190 if (g_Git
.GetInitAddList(pRev
->GetFiles(this)))
191 CMessageBox::Show(NULL
, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
196 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
199 int *action
= &dummyAction
;
200 SafeGetAction(pRev
, &action
);
203 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
204 *action
|= pRev
->GetFiles(this)[j
].m_Action
;
207 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
209 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
213 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
214 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
216 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
217 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
218 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
221 m_critSec_AsyncDiff
.Lock();
222 int ret
= pRev
->CheckAndDiff();
223 m_critSec_AsyncDiff
.Unlock();
225 { // fetch change file list
226 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
228 if(i
< m_arShownList
.GetCount())
230 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
231 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
233 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
239 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
241 POSITION pos
= GetFirstSelectedItemPosition();
242 int nItem
= GetNextSelectedItem(pos
);
246 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
248 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
250 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
257 m_AsyncThreadExited
= true;
260 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
264 m_ContextMenuMask
&= hideMask
;
268 m_ContextMenuMask
&= ~hideMask
;
272 CGitLogListBase::~CGitLogListBase()
274 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
275 this->m_arShownList
.SafeRemoveAll();
277 DestroyIcon(m_hModifiedIcon
);
278 DestroyIcon(m_hReplacedIcon
);
279 DestroyIcon(m_hAddedIcon
);
280 DestroyIcon(m_hDeletedIcon
);
281 m_logEntries
.ClearAll();
284 DeleteObject(m_boldFont
);
287 DeleteObject(m_FontItalics
);
289 if (m_boldItalicsFont
)
290 DeleteObject(m_boldItalicsFont
);
292 if ( m_pStoreSelection
)
294 delete m_pStoreSelection
;
295 m_pStoreSelection
= NULL
;
298 SafeTerminateThread();
299 SafeTerminateAsyncDiffThread();
302 CloseHandle(m_AsyncDiffEvent
);
306 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
307 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
308 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
309 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
310 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
312 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
313 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
316 ON_MESSAGE(MSG_LOADED
,OnLoad
)
318 ON_WM_MEASUREITEM_REFLECT()
319 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
320 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
321 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
322 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
323 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
324 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
327 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
329 //if (m_nRowHeight>0)
331 lpMeasureItemStruct
->itemHeight
= 50;
335 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
338 return CHintListCtrl::OnCreate(lpCreateStruct
);
341 void CGitLogListBase::PreSubclassWindow()
343 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
344 // load the icons for the action columns
345 // m_Theme.Open(m_hWnd, L"ListView");
346 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
347 CHintListCtrl::PreSubclassWindow();
350 CString
CGitLogListBase::GetRebaseActionName(int action
)
352 if (action
& LOGACTIONS_REBASE_EDIT
)
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
354 if (action
& LOGACTIONS_REBASE_SQUASH
)
355 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
356 if (action
& LOGACTIONS_REBASE_PICK
)
357 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
358 if (action
& LOGACTIONS_REBASE_SKIP
)
359 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
361 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
364 void CGitLogListBase::InsertGitColumn()
368 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
369 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
370 if (DWORD(regFullRowSelect
))
371 exStyle
|= LVS_EX_FULLROWSELECT
;
372 SetExtendedStyle(exStyle
);
374 // only load properties if we have a repository
375 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
376 UpdateProjectProperties();
378 static UINT normal
[] =
390 IDS_LOG_COMMIT_EMAIL
,
413 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
415 DWORD hideColumns
= 0;
416 if(this->m_IsRebaseReplaceGraph
)
418 hideColumns
|= GIT_LOG_GRAPH
;
419 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
423 hideColumns
|= GIT_LOG_REBASE
;
426 if(this->m_IsIDReplaceAction
)
428 hideColumns
|= GIT_LOG_ACTIONS
;
429 m_dwDefaultColumns
|= GIT_LOG_ID
;
430 m_dwDefaultColumns
|= GIT_LOG_HASH
;
434 hideColumns
|= GIT_LOG_ID
;
436 if(this->m_bShowBugtraqColumn
)
438 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
442 hideColumns
|= GIT_LOGLIST_BUG
;
444 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
445 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
447 hideColumns
|= GIT_LOGLIST_SVNREV
;
450 m_ColumnManager
.SetNames(normal
, _countof(normal
));
451 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
457 * Resizes all columns in a list control to values in registry.
459 void CGitLogListBase::ResizeAllListCtrlCols()
461 // column max and min widths to allow
462 static const int nMinimumWidth
= 10;
463 static const int nMaximumWidth
= 1000;
464 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
467 int numcols
= pHdrCtrl
->GetItemCount();
468 for (int col
= 0; col
< numcols
; ++col
)
470 // get width for this col last time from registry
472 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
473 CRegDWORD
regwidth(regentry
, 0);
477 // no saved value, setup sensible defaults
478 if (col
== this->LOGLIST_MESSAGE
)
480 cx
= LOGLIST_MESSAGE_MIN
;
484 cx
= ICONITEMBORDER
+16*4;
487 if (cx
< nMinimumWidth
)
491 else if (cx
> nMaximumWidth
)
496 SetColumnWidth(col
, cx
);
503 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
506 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
507 rItem
.mask
= LVIF_STATE
;
508 rItem
.iItem
= (int)Index
;
509 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
512 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
515 if (!(rItem
.state
& LVIS_SELECTED
))
517 int action
= pLogEntry
->GetRebaseAction();
518 if (action
& LOGACTIONS_REBASE_SQUASH
)
519 brush
= ::CreateSolidBrush(RGB(156,156,156));
520 else if (action
& LOGACTIONS_REBASE_EDIT
)
521 brush
= ::CreateSolidBrush(RGB(200,200,128));
523 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
525 if (rItem
.state
& LVIS_SELECTED
)
527 if (::GetFocus() == m_hWnd
)
528 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
530 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
535 ::FillRect(hdc
, &rect
, brush
);
536 ::DeleteObject(brush
);
540 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
542 POINT point
= { 4, 4 };
544 rt2
.DeflateRect(1, 1);
545 rt2
.OffsetRect(2, 2);
547 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
548 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
549 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
550 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
551 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
553 ::SelectObject(hdc
, brush
);
554 rt2
.OffsetRect(-2, -2);
555 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
556 ::SelectObject(hdc
, oldbrush
);
557 ::SelectObject(hdc
, oldpen
);
558 ::DeleteObject(nullPen
);
559 ::DeleteObject(darkBrush
);
562 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
564 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
565 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
566 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
567 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
568 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
569 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
570 ::SelectObject(hdc
, oldpen
);
574 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
576 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
577 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
578 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
579 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
580 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
581 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
582 ::SelectObject(hdc
, oldpen
);
586 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
588 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
591 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
592 rItem
.mask
= LVIF_STATE
;
593 rItem
.iItem
= (int)index
;
594 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
600 HTHEME hTheme
= NULL
;
601 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
602 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
605 if (m_bTagsBranchesOnRightSide
)
607 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
608 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
609 SelectObject(hdc
, oldFont
);
610 rt
.left
+= oneSpaceSize
.cx
* 2;
614 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
615 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
616 rt
.left
+= oneSpaceSize
.cx
;
619 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
621 int txtState
= LISS_NORMAL
;
622 if (rItem
.state
& LVIS_SELECTED
)
623 txtState
= LISS_SELECTED
;
625 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, 0, &rt
);
629 if (rItem
.state
& LVIS_SELECTED
)
631 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
632 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
633 ::SetTextColor(hdc
, clrOld
);
637 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
641 if (m_bTagsBranchesOnRightSide
)
644 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
646 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
648 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
652 CloseThemeData(hTheme
);
657 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
)
659 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
661 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
663 COLORREF colRef
= refList
[i
].color
;
664 bool singleRemote
= refList
[i
].singleRemote
;
665 bool hasTracking
= refList
[i
].hasTracking
;
666 bool sameName
= refList
[i
].sameName
;
667 bool annotatedTag
= refList
[i
].annotatedTag
;
669 //When row selected, ajust label color
670 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
672 if (rItem
.state
& LVIS_SELECTED
)
673 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
676 brush
= ::CreateSolidBrush(colRef
);
678 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
681 memset(&size
,0,sizeof(SIZE
));
682 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
684 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
687 int textpos
= DT_CENTER
;
689 if (rt
.right
> rect
.right
)
691 rt
.right
= rect
.right
;
700 textRect
.OffsetRect(8, 0);
708 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
712 //Fill interior of ref label
713 ::FillRect(hdc
, &rt
, brush
);
721 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
722 rectEdge
.DeflateRect(1, 1);
723 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
729 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
730 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
731 ::FillRgn(hdc
, hrgn
, brush
);
732 ::DeleteObject(hrgn
);
733 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
735 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
736 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
738 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
739 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
741 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
742 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
743 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
745 SelectObject(hdc
, oldpen
);
748 //Draw text inside label
749 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
750 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
752 int txtState
= LISS_NORMAL
;
753 if (rItem
.state
& LVIS_SELECTED
)
754 txtState
= LISS_SELECTED
;
756 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &textRect
);
760 W_Dc
.SetBkMode(TRANSPARENT
);
761 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
763 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
764 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
765 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
766 ::SetTextColor(hdc
,clrOld
);
770 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
776 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
777 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
779 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
780 DrawLightning(hdc
, newRect
, color
, bold
);
785 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
786 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
788 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
789 DrawUpTriangle(hdc
, newRect
, color
, bold
);
792 rt
.left
= rt
.right
+ 1;
795 ::DeleteObject(brush
);
797 rt
.right
= rect
.right
;
800 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
802 // Returns ((256 - amount)*col1 + amount*col2) / 256;
803 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
804 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
805 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
808 Gdiplus::Color
GetGdiColor(COLORREF col
)
810 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
812 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
813 const COLORREF
& col
,const COLORREF
& activeColor
, int top
816 int h
= laneHeight
/ 2;
817 int m
= (x1
+ x2
) / 2;
818 int r
= (x2
- x1
) * m_NodeSize
/ 30;
821 #define P_CENTER m , h+top
822 #define P_0 x2, h+top
823 #define P_90 m , 0+top-1
824 #define P_180 x1, h+top
825 #define P_270 m , 2 * h+top +1
826 #define R_CENTER m - r, h - r+top, d, d
829 #define DELTA_UR_B 2*(x1 - m), 2*h +top
830 #define DELTA_UR_E 0*16, 90*16 +top // -,
832 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
833 #define DELTA_DR_E 270*16, 90*16 +top // -'
835 #define DELTA_UL_B 2*(x2 - m), 2*h +top
836 #define DELTA_UL_E 90*16, 90*16 +top // ,-
838 #define DELTA_DL_B 2*(x2 - m),2*-h +top
839 #define DELTA_DL_E 180*16, 90*16 // '-
841 #define CENTER_UR x1, 2*h, 225
842 #define CENTER_DR x1, 0 , 135
843 #define CENTER_UL x2, 2*h, 315
844 #define CENTER_DL x2, 0 , 45
847 Gdiplus::Graphics
graphics( hdc
);
849 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
858 Gdiplus::LinearGradientBrush
gradient(
859 Gdiplus::Point(x1
-2, h
+top
-2),
860 Gdiplus::Point(P_270
),
861 GetGdiColor(activeColor
),GetGdiColor(col
));
864 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
865 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
867 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
868 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
869 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
876 Gdiplus::LinearGradientBrush
gradient(
877 Gdiplus::Point(P_270
),
878 Gdiplus::Point(x2
+1, h
+top
-1),
879 GetGdiColor(col
),GetGdiColor(activeColor
));
882 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
883 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
885 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
886 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
887 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
896 Gdiplus::LinearGradientBrush
gradient(
897 Gdiplus::Point(x1
-2, h
+top
-2),
898 Gdiplus::Point(P_90
),
899 GetGdiColor(activeColor
),GetGdiColor(col
));
901 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
903 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
906 QConicalGradient
gradient(CENTER_DR
);
907 gradient
.setColorAt(0.375, activeCol
);
908 gradient
.setColorAt(0.625, col
);
909 myPen
.setBrush(gradient
);
911 p
->drawArc(P_CENTER
, DELTA_DR
);
920 //static QPen myPen(Qt::black, 2); // fast path here
922 pen
.CreatePen(PS_SOLID
,2,col
);
923 //myPen.setColor(col);
924 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
926 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
928 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
935 case Lanes::NOT_ACTIVE
:
936 case Lanes::MERGE_FORK
:
937 case Lanes::MERGE_FORK_R
:
938 case Lanes::MERGE_FORK_L
:
943 //DrawLine(hdc,P_90,P_270);
944 graphics
.DrawLine(&myPen
,P_90
,P_270
);
945 //p->drawLine(P_90, P_270);
949 //DrawLine(hdc,P_CENTER,P_270);
950 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
951 //p->drawLine(P_CENTER, P_270);
955 case Lanes::BOUNDARY
:
956 case Lanes::BOUNDARY_C
:
957 case Lanes::BOUNDARY_R
:
958 case Lanes::BOUNDARY_L
:
959 //DrawLine(hdc,P_90, P_CENTER);
960 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
961 //p->drawLine(P_90, P_CENTER);
967 myPen
.SetColor(GetGdiColor(activeColor
));
971 case Lanes::MERGE_FORK
:
976 case Lanes::CROSS_EMPTY
:
977 case Lanes::BOUNDARY_C
:
978 //DrawLine(hdc,P_180,P_0);
979 graphics
.DrawLine(&myPen
,P_180
,P_0
);
980 //p->drawLine(P_180, P_0);
982 case Lanes::MERGE_FORK_R
:
983 case Lanes::BOUNDARY_R
:
984 //DrawLine(hdc,P_180,P_CENTER);
985 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
986 //p->drawLine(P_180, P_CENTER);
988 case Lanes::MERGE_FORK_L
:
991 case Lanes::BOUNDARY_L
:
992 //DrawLine(hdc,P_CENTER,P_0);
993 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
994 //p->drawLine(P_CENTER, P_0);
1000 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1003 brush
.CreateSolidBrush(col
);
1004 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1006 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1007 // center symbol, e.g. rect or ellipse
1010 case Lanes::INITIAL
:
1013 //p->setPen(Qt::NoPen);
1015 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1016 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1017 //p->drawEllipse(R_CENTER);
1019 case Lanes::MERGE_FORK
:
1020 case Lanes::MERGE_FORK_R
:
1021 case Lanes::MERGE_FORK_L
:
1022 //p->setPen(Qt::NoPen);
1024 //p->drawRect(R_CENTER);
1025 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1026 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1028 case Lanes::UNAPPLIED
:
1030 //p->setPen(Qt::NoPen);
1031 //p->setBrush(Qt::red);
1032 //p->drawRect(m - r, h - 1, d, 2);
1033 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1034 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1036 case Lanes::APPLIED
:
1038 //p->setPen(Qt::NoPen);
1039 //p->setBrush(DARK_GREEN);
1040 //p->drawRect(m - r, h - 1, d, 2);
1041 //p->drawRect(m - 1, h - r, 2, d);
1042 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1043 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1044 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1046 case Lanes::BOUNDARY
:
1047 //p->setBrush(back);
1048 //p->drawEllipse(R_CENTER);
1049 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1050 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1052 case Lanes::BOUNDARY_C
:
1053 case Lanes::BOUNDARY_R
:
1054 case Lanes::BOUNDARY_L
:
1055 //p->setBrush(back);
1056 //p->drawRect(R_CENTER);
1057 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1058 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1064 ::SelectObject(hdc
,oldpen
);
1065 ::SelectObject(hdc
,oldbrush
);
1074 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1078 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1079 if(data
->m_CommitHash
.IsEmpty())
1084 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1085 rItem
.mask
= LVIF_STATE
;
1086 rItem
.iItem
= (int)index
;
1087 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1090 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1092 if (data
->m_Lanes
.empty())
1093 m_logEntries
.setLane(data
->m_CommitHash
);
1095 std::vector
<int>& lanes
=data
->m_Lanes
;
1096 size_t laneNum
= lanes
.size();
1097 UINT activeLane
= 0;
1098 for (UINT i
= 0; i
< laneNum
; ++i
)
1099 if (Lanes::isMerge(lanes
[i
])) {
1105 int maxWidth
= rect
.Width();
1106 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1108 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1109 //if (opt.state & QStyle::State_Selected)
1110 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1112 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1119 if (ln
== Lanes::EMPTY
)
1122 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1123 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1127 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1133 if (ln
== Lanes::EMPTY
)
1136 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1137 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1139 if (ln
== Lanes::CROSS
)
1141 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1142 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1145 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1151 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1154 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1155 // Take the default processing unless we set this to something else below.
1156 *pResult
= CDRF_DODEFAULT
;
1158 if (m_bNoDispUpdates
)
1161 switch (pLVCD
->nmcd
.dwDrawStage
)
1165 *pResult
= CDRF_NOTIFYITEMDRAW
;
1169 case CDDS_ITEMPREPAINT
:
1171 // This is the prepaint stage for an item. Here's where we set the
1172 // item's text color.
1174 // Tell Windows to send draw notifications for each subitem.
1175 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1177 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1179 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1181 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1184 HGDIOBJ hGdiObj
= nullptr;
1185 int action
= data
->GetRebaseAction();
1186 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1187 crText
= RGB(128,128,128);
1189 if (action
& LOGACTIONS_REBASE_SQUASH
)
1190 pLVCD
->clrTextBk
= RGB(156,156,156);
1191 else if (action
& LOGACTIONS_REBASE_EDIT
)
1192 pLVCD
->clrTextBk
= RGB(200,200,128);
1194 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1196 if (action
& LOGACTIONS_REBASE_CURRENT
)
1197 hGdiObj
= m_boldFont
;
1199 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1200 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1201 if (isHeadHash
&& isHighlight
)
1202 hGdiObj
= m_boldItalicsFont
;
1203 else if (isHeadHash
)
1204 hGdiObj
= m_boldFont
;
1205 else if (isHighlight
)
1206 hGdiObj
= m_FontItalics
;
1210 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1211 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1214 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1215 // crText = GetSysColor(COLOR_GRAYTEXT);
1217 if (data
->m_CommitHash
.IsEmpty())
1219 //crText = GetSysColor(RGB(200,200,0));
1220 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1221 // We changed the font, so we're returning CDRF_NEWFONT. This
1222 // tells the control to recalculate the extent of the text.
1223 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1227 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1229 if (m_bStrictStopped
)
1230 crText
= GetSysColor(COLOR_GRAYTEXT
);
1232 // Store the color back in the NMLVCUSTOMDRAW struct.
1233 pLVCD
->clrText
= crText
;
1237 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1239 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1241 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1244 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1246 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1249 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1251 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1252 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1254 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1255 if( !data
->m_CommitHash
.IsEmpty())
1256 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1258 *pResult
= CDRF_SKIPDEFAULT
;
1263 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1265 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1267 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1269 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1272 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1274 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1275 // not in FillBackGround method, because this only affected the message subitem
1276 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1279 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1280 int state
= GetItemState(index
, LVIS_SELECTED
);
1281 int txtState
= LISS_NORMAL
;
1282 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1284 if (state
& LVIS_SELECTED
)
1285 txtState
= LISS_HOTSELECTED
;
1287 txtState
= LISS_HOT
;
1289 else if (state
& LVIS_SELECTED
)
1291 if (::GetFocus() == m_hWnd
)
1292 txtState
= LISS_SELECTED
;
1294 txtState
= LISS_SELECTEDNOTFOCUS
;
1297 HTHEME hTheme
= nullptr;
1298 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1299 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1301 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1302 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1305 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1306 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1307 ::DeleteObject(brush
);
1312 // get rect of whole line
1313 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1315 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1316 rect2
.DeflateRect(1, 1, 1, 1);
1318 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1319 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1321 CloseThemeData(hTheme
);
1323 // END: extended redraw
1325 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1327 std::vector
<REFLABEL
> refsToShow
;
1328 STRING_VECTOR remoteTrackingList
;
1329 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1330 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1332 CString str
= refList
[i
];
1335 refLabel
.color
= RGB(255, 255, 255);
1336 refLabel
.singleRemote
= false;
1337 refLabel
.hasTracking
= false;
1338 refLabel
.sameName
= false;
1339 refLabel
.annotatedTag
= false;
1340 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1342 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1344 if (refLabel
.name
== m_CurrentBranch
)
1345 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1347 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1349 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1350 CString pullRemote
= trackingEntry
.first
;
1351 CString pullBranch
= trackingEntry
.second
;
1352 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1354 CString defaultUpstream
;
1355 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1356 refLabel
.hasTracking
= true;
1357 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1360 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1362 if (refList
[j
] == defaultUpstream
)
1371 bool sameName
= pullBranch
== refLabel
.name
;
1372 refsToShow
.push_back(refLabel
);
1373 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1374 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1375 if (m_bSymbolizeRefNames
)
1377 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1379 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1380 refLabel
.singleRemote
= true;
1383 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1384 refLabel
.sameName
= sameName
;
1386 refsToShow
.push_back(refLabel
);
1387 remoteTrackingList
.push_back(defaultUpstream
);
1393 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1395 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1399 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1401 if (remoteTrackingList
[j
] == str
)
1410 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1411 if (m_bSymbolizeRefNames
)
1413 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1415 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1416 refLabel
.singleRemote
= true;
1420 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1422 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1424 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1425 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1427 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1429 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1431 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1432 refLabel
.name
= _T("stash");
1434 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1436 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1438 if (refLabel
.name
.Find(_T("good")) == 0)
1440 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1441 refLabel
.name
= _T("good");
1443 if (refLabel
.name
.Find(_T("bad")) == 0)
1445 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1446 refLabel
.name
= _T("bad");
1452 refsToShow
.push_back(refLabel
);
1455 if (refsToShow
.empty())
1457 *pResult
= CDRF_DODEFAULT
;
1461 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1463 *pResult
= CDRF_SKIPDEFAULT
;
1471 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1473 if(this->m_IsIDReplaceAction
)
1475 *pResult
= CDRF_DODEFAULT
;
1478 *pResult
= CDRF_DODEFAULT
;
1480 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1484 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1485 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1487 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1489 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1490 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1491 // Get the selected state of the
1492 // item being drawn.
1494 // Fill the background if necessary
1495 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1497 // Draw the icon(s) into the compatible DC
1498 int action
= SafeGetAction(pLogEntry
);
1500 if (!pLogEntry
->m_IsDiffFiles
)
1501 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1503 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1504 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1507 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1508 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1511 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1512 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1515 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1516 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1518 *pResult
= CDRF_SKIPDEFAULT
;
1524 *pResult
= CDRF_DODEFAULT
;
1527 CString
FindSVNRev(const CString
& msg
)
1531 const std::tr1::wsregex_iterator end
;
1532 std::wstring s
= msg
;
1533 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
)
1535 const std::tr1::wsmatch match
= *it
;
1536 if (match
.size() == 4)
1538 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1539 return std::wstring(match
[2]).c_str();
1542 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
)
1544 const std::tr1::wsmatch match
= *it
;
1545 if (match
.size() == 3)
1547 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1548 return std::wstring(match
[1]).c_str();
1552 catch (std::exception
) {}
1557 // CGitLogListBase message handlers
1559 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1561 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1563 // Create a pointer to the item
1564 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1566 // Do the list need text information?
1567 if (!(pItem
->mask
& LVIF_TEXT
))
1570 // By default, clear text buffer.
1571 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1573 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1576 if (m_bNoDispUpdates
|| bOutOfRange
)
1579 // Which item number?
1580 int itemid
= pItem
->iItem
;
1581 GitRev
* pLogEntry
= NULL
;
1582 if (itemid
< m_arShownList
.GetCount())
1583 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1588 temp
.Format(_T("%d"),pItem
->iItem
+1);
1593 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1597 switch (pItem
->iSubItem
)
1599 case this->LOGLIST_GRAPH
: //Graphic
1601 case this->LOGLIST_REBASE
:
1603 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1604 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
);
1607 case this->LOGLIST_ACTION
: //action -- no text in the column
1609 case this->LOGLIST_HASH
:
1611 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1613 case this->LOGLIST_ID
:
1614 if(this->m_IsIDReplaceAction
)
1615 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1617 case this->LOGLIST_MESSAGE
: //Message
1619 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1621 case this->LOGLIST_AUTHOR
: //Author
1623 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1625 case this->LOGLIST_DATE
: //Date
1626 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1627 lstrcpyn(pItem
->pszText
,
1628 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1632 case this->LOGLIST_EMAIL
:
1634 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1637 case this->LOGLIST_COMMIT_NAME
: //Commit
1639 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1642 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1644 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1647 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1648 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1649 lstrcpyn(pItem
->pszText
,
1650 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1653 case this->LOGLIST_BUG
: //Bug ID
1655 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1657 case this->LOGLIST_SVNREV
: //SVN revision
1659 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1667 bool CGitLogListBase::IsOnStash(int index
)
1669 GitRev
*rev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
));
1674 GitRev
*preRev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
- 1));
1675 if (IsStash(preRev
))
1676 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1681 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1683 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1685 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1691 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1693 if (pRev
->m_ParentHash
.empty())
1697 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1699 catch (const char* msg
)
1701 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1704 parentHash
= pRev
->m_ParentHash
;
1707 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1710 if (pWnd
== GetHeaderCtrl())
1712 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1715 int selIndex
= GetSelectionMark();
1717 return; // nothing selected, nothing to do with a context menu
1719 // if the user selected the info text telling about not all revisions shown due to
1720 // the "stop on copy/rename" option, we also don't show the context menu
1721 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1724 // if the context menu is invoked through the keyboard, we have to use
1725 // a calculated position on where to anchor the menu on
1726 if ((point
.x
== -1) && (point
.y
== -1))
1729 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1730 ClientToScreen(&rect
);
1731 point
= rect
.CenterPoint();
1733 m_nSearchIndex
= selIndex
;
1734 m_bCancelled
= FALSE
;
1736 // calculate some information the context menu commands can use
1737 // CString pathURL = GetURLFromPath(m_path);
1739 POSITION pos
= GetFirstSelectedItemPosition();
1740 int indexNext
= GetNextSelectedItem(pos
);
1744 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1745 if (pSelLogEntry
== nullptr)
1748 GitRev revSelected
= pSelLogEntry
->Rev
;
1749 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1750 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1752 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1754 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1755 if (changedpath
->lCopyFromRev
)
1756 revPrevious
= changedpath
->lCopyFromRev
;
1759 GitRev revSelected2
;
1762 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1763 revSelected2
= pLogEntry
->Rev
;
1765 bool bAllFromTheSameAuthor
= true;
1766 CString firstAuthor
;
1767 CLogDataVector selEntries
;
1768 GitRev revLowest
, revHighest
;
1769 GitRevRangeArray revisionRanges
;
1771 POSITION pos
= GetFirstSelectedItemPosition();
1772 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1773 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1774 selEntries
.push_back(pLogEntry
);
1775 firstAuthor
= pLogEntry
->sAuthor
;
1776 revLowest
= pLogEntry
->Rev
;
1777 revHighest
= pLogEntry
->Rev
;
1780 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1781 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1782 selEntries
.push_back(pLogEntry
);
1783 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1784 bAllFromTheSameAuthor
= false;
1785 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1786 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1792 int FirstSelect
=-1, LastSelect
=-1;
1793 pos
= GetFirstSelectedItemPosition();
1794 FirstSelect
= GetNextSelectedItem(pos
);
1797 LastSelect
= GetNextSelectedItem(pos
);
1799 //entry is selected, now show the popup menu
1801 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1803 if (popup
.CreatePopupMenu())
1805 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1806 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1807 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1808 bool isStash
= IsOnStash(indexNext
);
1809 GIT_REV_LIST parentHash
;
1810 GetParentHashes(pSelLogEntry
, parentHash
);
1812 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1813 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1815 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1816 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1818 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1819 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1821 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1822 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1824 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
)))
1825 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1827 if (GetSelectedCount() == 1)
1830 bool requiresSeparator
= false;
1831 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1833 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1835 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1836 requiresSeparator
= true;
1841 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1843 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1844 requiresSeparator
= true;
1846 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1848 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1849 requiresSeparator
= true;
1853 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1855 if (parentHash
.size() == 1)
1857 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1858 requiresSeparator
= true;
1860 else if (parentHash
.size() > 1)
1862 blamemenu
.CreatePopupMenu();
1863 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1864 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1867 str
.Format(IDS_PARENT
, i
+ 1);
1868 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1870 requiresSeparator
= true;
1874 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1876 if (parentHash
.size() == 1)
1878 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1879 requiresSeparator
= true;
1881 else if (parentHash
.size() > 1)
1883 gnudiffmenu
.CreatePopupMenu();
1884 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1886 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1887 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1889 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1892 str
.Format(IDS_PARENT
, i
+ 1);
1893 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1895 requiresSeparator
= true;
1899 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1901 if (parentHash
.size() == 1)
1903 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1904 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1905 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1906 requiresSeparator
= true;
1908 else if (parentHash
.size() > 1)
1910 diffmenu
.CreatePopupMenu();
1911 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1912 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1915 str
.Format(IDS_PARENT
, i
+ 1);
1916 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1917 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1919 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1920 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1923 requiresSeparator
= true;
1927 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1929 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1930 requiresSeparator
= true;
1933 if (requiresSeparator
)
1934 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1936 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1938 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1939 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1942 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1944 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1945 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1947 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1948 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1950 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1953 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1955 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1956 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1958 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1959 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1961 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1962 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1964 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
1965 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1967 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1971 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1973 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1975 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1977 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1979 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1980 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1982 // popup.AppendMenu(MF_SEPARATOR, NULL);
1987 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1989 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1991 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1992 GetSelectedCount() == 1)
1993 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1995 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1996 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1998 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1999 str
.Format(format
,g_Git
.GetCurrentBranch());
2001 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2002 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2004 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
2005 str
.Format(format
,g_Git
.GetCurrentBranch());
2007 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2008 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2011 // Add Switch Branch express Menu
2012 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2013 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2016 std::vector
<CString
*> branchs
;
2017 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2019 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2020 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2022 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2027 str
.LoadString(IDS_SWITCH_BRANCH
);
2029 if(branchs
.size() == 1)
2032 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2033 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
2035 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2038 else if(branchs
.size() > 1)
2040 subbranchmenu
.CreatePopupMenu();
2041 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2043 if (*branchs
[i
] != currentBranch
)
2045 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2046 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2050 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2054 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2055 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2057 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2058 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2060 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2061 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2063 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
2064 str
.Format(format
,g_Git
.GetCurrentBranch());
2066 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2067 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2068 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2070 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2071 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2073 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2075 if (parentHash
.size() == 1)
2077 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2079 else if (parentHash
.size() > 1)
2081 revertmenu
.CreatePopupMenu();
2082 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2084 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2087 str
.Format(IDS_PARENT
, i
+ 1);
2088 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
2093 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2094 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2096 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2101 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2103 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2104 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2105 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2106 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2109 if (GetSelectedCount() >= 2)
2111 bool bAddSeparator
= false;
2112 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2114 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2115 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2118 if (GetSelectedCount() == 2)
2120 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2121 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2123 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2125 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2126 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2127 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2129 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
2130 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2131 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
2132 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2135 bAddSeparator
= true;
2140 bAddSeparator
= true;
2143 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2144 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2147 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2150 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2152 bool bAddSeparator
= false;
2153 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2155 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2159 headindex
= this->GetHeadIndex();
2160 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2162 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2164 if (g_Git
.GetHash(hashFirst
, head
))
2165 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2166 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2168 if (g_Git
.GetHash(hash
, head
))
2169 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2170 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2171 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2172 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2173 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2174 bAddSeparator
= true;
2179 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2180 if (GetSelectedCount() >= 2)
2181 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2183 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2184 bAddSeparator
= true;
2187 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2188 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2189 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2190 bAddSeparator
= true;
2194 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2197 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())
2199 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2200 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2203 if (GetSelectedCount() == 1)
2205 bool bAddSeparator
= false;
2206 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
2208 // show the push-option only if the log entry has an associated local branch
2209 bool isLocal
= false;
2210 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2212 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2217 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2218 bAddSeparator
= true;
2221 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2223 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2224 bAddSeparator
= true;
2228 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2230 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2232 std::vector
<CString
*> branchs
;
2233 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2235 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2236 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2239 if (branchs
.size() == 1)
2241 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2244 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2245 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2246 bAddSeparator
= true;
2248 else if (branchs
.size() > 1)
2250 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2251 submenu
.CreatePopupMenu();
2252 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2254 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2255 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2258 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2259 bAddSeparator
= true;
2262 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2264 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2265 } // GetSelectedCount() == 1
2267 if (GetSelectedCount() != 0)
2269 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2270 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2271 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2272 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2273 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2274 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2277 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2278 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2280 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2281 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2283 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2284 // DialogEnableWindow(IDOK, FALSE);
2285 // SetPromptApp(&theApp);
2287 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2289 // EnableOKButton();
2290 } // if (popup.CreatePopupMenu())
2294 bool CGitLogListBase::IsSelectionContinuous()
2296 if ( GetSelectedCount()==1 )
2298 // if only one revision is selected, the selection is of course
2303 POSITION pos
= GetFirstSelectedItemPosition();
2304 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2307 int itemindex
= GetNextSelectedItem(pos
);
2310 int nextindex
= GetNextSelectedItem(pos
);
2311 if (nextindex
- itemindex
> 1)
2313 bContinuous
= false;
2316 itemindex
= nextindex
;
2322 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2326 POSITION pos
= GetFirstSelectedItemPosition();
2330 sRev
.LoadString(IDS_LOG_REVISION
);
2332 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2334 sDate
.LoadString(IDS_LOG_DATE
);
2336 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2340 CString sLogCopyText
;
2342 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2344 if (toCopy
== ID_COPY_ALL
)
2346 //pLogEntry->GetFiles(this)
2347 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2349 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2350 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2352 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2353 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2356 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2357 sPaths
+= _T(" ") + rename
;
2359 sPaths
+= _T("\r\n");
2362 CString body
= pLogEntry
->GetBody();
2363 body
.Replace(_T("\n"), _T("\r\n"));
2364 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"),
2365 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2366 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2368 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2369 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2371 sClipdata
+= sLogCopyText
;
2373 else if (toCopy
== ID_COPY_MESSAGE
)
2375 CString body
= pLogEntry
->GetBody();
2376 body
.Replace(_T("\n"), _T("\r\n"));
2377 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2379 else if (toCopy
== ID_COPY_SUBJECT
)
2381 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2386 sClipdata
+= _T("\r\n");
2387 sClipdata
+= pLogEntry
->m_CommitHash
;
2392 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2397 void CGitLogListBase::DiffSelectedRevWithPrevious()
2399 if (m_bThreadRunning
)
2402 int FirstSelect
=-1, LastSelect
=-1;
2403 POSITION pos
= GetFirstSelectedItemPosition();
2404 FirstSelect
= GetNextSelectedItem(pos
);
2407 LastSelect
= GetNextSelectedItem(pos
);
2410 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2413 UpdateLogInfoLabel();
2414 int selIndex
= m_LogList
.GetSelectionMark();
2417 int selCount
= m_LogList
.GetSelectedCount();
2421 // Find selected entry in the log list
2422 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2423 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2424 long rev1
= pLogEntry
->Rev
;
2426 CTGitPath path
= m_path
;
2428 // See how many files under the relative root were changed in selected revision
2430 LogChangedPath
* changed
= NULL
;
2431 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2433 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2434 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2441 if (m_path
.IsDirectory() && nChanged
== 1)
2443 // We're looking at the log for a directory and only one file under dir was changed in the revision
2444 // Do diff on that file instead of whole directory
2445 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2448 m_bCancelled
= FALSE
;
2449 DialogEnableWindow(IDOK
, FALSE
);
2450 SetPromptApp(&theApp
);
2451 theApp
.DoWaitCursor(1);
2455 GitDiff
diff(this, m_hWnd
, true);
2456 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2457 diff
.SetHEADPeg(m_LogRevision
);
2458 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2462 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2465 theApp
.DoWaitCursor(-1);
2470 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2472 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2475 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2477 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2479 if (pFindInfo
->lvfi
.psz
== 0)
2482 CString sCmp
= pFindInfo
->lvfi
.psz
;
2484 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2486 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2487 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2488 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2490 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2498 if (sCmp
.Compare(sRev
)==0)
2505 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2507 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2509 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2510 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2511 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2513 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2521 if (sCmp
.Compare(sRev
)==0)
2533 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2537 this->m_arShownList
.SafeRemoveAll();
2539 this->m_logEntries
.ClearAll();
2540 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2543 //this->m_logEntries.ParserFromLog();
2544 SetItemCountEx((int)m_logEntries
.size());
2546 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2550 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2551 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2556 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2557 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2569 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2573 m_arShownList
.SafeRemoveAll();
2575 m_logEntries
.ClearAll();
2576 if (m_logEntries
.Fill(hashes
))
2579 SetItemCountEx((int)m_logEntries
.size());
2581 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2585 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2586 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2590 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2591 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2600 int CGitLogListBase::BeginFetchLog()
2604 this->m_arShownList
.SafeRemoveAll();
2606 this->m_logEntries
.ClearAll();
2608 this->m_LogCache
.ClearAllParent();
2610 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2613 if(this->m_Path
.IsEmpty())
2619 mask
= CGit::LOG_INFO_ONLY_HASH
;
2620 if (m_bIncludeBoundaryCommits
)
2621 mask
|= CGit::LOG_INFO_BOUNDARY
;
2622 // if(this->m_bAllBranch)
2623 mask
|= m_ShowMask
;
2627 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2629 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2632 if (m_sRange
.IsEmpty())
2633 m_sRange
= _T("HEAD");
2636 data
.m_From
= m_From
;
2639 #if 0 /* use tortoiegit filter */
2640 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2641 data
.m_Author
= this->m_sFilterText
;
2643 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2644 data
.m_MessageFilter
= this->m_sFilterText
;
2646 data
.m_IsRegex
= m_bFilterWithRegex
;
2649 // follow does not work for directories
2650 if (!path
|| path
->IsDirectory())
2651 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2652 // follow does not work with all branches 8at least in TGit)
2653 if (mask
& CGit::LOG_INFO_FOLLOW
)
2654 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2656 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2658 //this->m_logEntries.ParserFromLog();
2659 if(IsInWorkingThread())
2661 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2665 SetItemCountEx((int)m_logEntries
.size());
2670 [] { git_init(); } ();
2675 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2679 if (!g_Git
.CanParseRev(m_sRange
))
2681 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2684 // if show all branches, pick any ref as dummy entry ref
2686 if (g_Git
.GetRefList(list
))
2687 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2688 if (list
.size() == 0)
2691 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2694 g_Git
.m_critGitDllSec
.Lock();
2696 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2698 g_Git
.m_critGitDllSec
.Unlock();
2704 g_Git
.m_critGitDllSec
.Unlock();
2706 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2709 g_Git
.m_critGitDllSec
.Unlock();
2714 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2716 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2718 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2720 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2722 DiffSelectedRevWithPrevious();
2727 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2734 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2736 // select all entries
2737 for (int i
=0; i
<GetItemCount(); ++i
)
2739 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2745 if (m_hAccel
&& !bSkipAccelerator
)
2747 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2753 //m_tooltips.RelayEvent(pMsg);
2754 return __super::PreTranslateMessage(pMsg
);
2757 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2759 // a double click on an entry in the revision list has happened
2762 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2763 DiffSelectedRevWithPrevious();
2766 int CGitLogListBase::FetchLogAsync(void * data
)
2770 m_bExitThread
=FALSE
;
2771 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2772 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2773 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2774 if (m_LoadingThread
==NULL
)
2776 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2777 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2778 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2784 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2786 return ((CGitLogListBase
*)pVoid
)->LogThread();
2789 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2792 oldest
=CTime::GetCurrentTime();
2793 latest
=CTime(1971,1,2,0,0,0);
2794 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2796 if(m_logEntries
[i
].IsEmpty())
2799 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2800 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2802 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2803 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2811 UINT
CGitLogListBase::LogThread()
2813 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2815 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2816 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2822 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2823 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2828 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2829 bool bRegex
= false;
2830 if (m_bFilterWithRegex
)
2831 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2833 TRACE(_T("\n===Begin===\n"));
2834 //Update work copy item;
2836 if (!m_logEntries
.empty())
2838 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2840 m_arShownList
.SafeAdd(pRev
);
2844 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2846 // store commit number of the last selected commit/line before the refresh or -1
2847 int lastSelectedHashNItem
= -1;
2850 bool shouldWalk
= true;
2851 if (!g_Git
.CanParseRev(m_sRange
))
2853 // walk revisions if show all branches and there exists any ref
2854 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2859 if (g_Git
.GetRefList(list
))
2860 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2861 if (list
.size() == 0)
2868 g_Git
.m_critGitDllSec
.Lock();
2872 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2873 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2878 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2881 g_Git
.m_critGitDllSec
.Unlock();
2884 t2
=t1
=GetTickCount();
2885 int oldprecentage
= 0;
2886 size_t oldsize
= m_logEntries
.size();
2887 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2888 while (ret
== 0 && !m_bExitThread
)
2890 g_Git
.m_critGitDllSec
.Lock();
2893 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2897 g_Git
.m_critGitDllSec
.Unlock();
2899 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2902 g_Git
.m_critGitDllSec
.Unlock();
2906 if (ret
!= -2) // other than end of revision walking
2907 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2911 if (commit
.m_ignore
== 1)
2913 git_free_commit(&commit
);
2917 //printf("%s\r\n",commit.GetSubject());
2921 CGitHash hash
= (char*)commit
.m_hash
;
2923 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2924 pRev
->m_GitCommit
= commit
;
2925 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2928 g_Git
.m_critGitDllSec
.Lock();
2931 git_get_notes(commit
.m_hash
, ¬e
);
2935 g_Git
.m_critGitDllSec
.Unlock();
2937 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2940 g_Git
.m_critGitDllSec
.Unlock();
2944 pRev
->m_Notes
.Empty();
2945 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2950 if(!pRev
->m_IsDiffFiles
)
2952 pRev
->m_CallDiffAsync
= DiffAsync
;
2955 pRev
->ParserParentFromCommit(&commit
);
2956 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2958 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2960 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2961 auto it
= commitChildren
.find(parentHash
);
2962 if (it
== commitChildren
.end())
2964 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2966 it
->second
.insert(pRev
->m_CommitHash
);
2975 bool visible
= true;
2976 if (HasFilterText())
2978 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2981 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
2983 this->m_critSec
.Lock();
2984 m_logEntries
.append(hash
, visible
);
2986 m_arShownList
.SafeAdd(pRev
);
2987 this->m_critSec
.Unlock();
2992 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2993 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2997 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3000 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3003 if(percent
< GITLOG_START
)
3004 percent
= GITLOG_START
+1;
3006 oldsize
= m_logEntries
.size();
3007 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3009 //if( percent > oldprecentage )
3011 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3012 oldprecentage
= percent
;
3015 if (lastSelectedHashNItem
>= 0)
3016 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3021 g_Git
.m_critGitDllSec
.Lock();
3022 git_close_log(m_DllGitLog
);
3023 g_Git
.m_critGitDllSec
.Unlock();
3029 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3034 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3036 if (lastSelectedHashNItem
>= 0)
3037 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3040 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3042 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3047 void CGitLogListBase::FetchRemoteList()
3049 STRING_VECTOR remoteList
;
3050 if (!g_Git
.GetRemoteList(remoteList
))
3051 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3053 m_SingleRemote
= _T("");
3056 void CGitLogListBase::FetchTrackingBranchList()
3058 m_TrackingMap
.clear();
3059 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3061 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3064 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3066 CString pullRemote
, pullBranch
;
3067 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3068 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3070 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3077 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3079 SafeTerminateThread();
3081 this->SetItemCountEx(0);
3086 // HACK to hide graph column
3087 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3088 SetColumnWidth(0, 0);
3090 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3092 //Update branch and Tag info
3094 //Assume Thread have exited
3095 //if(!m_bThreadRunning)
3097 m_logEntries
.clear();
3101 m_sFilterText
.Empty();
3106 InterlockedExchange(&m_bExitThread
,FALSE
);
3108 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3109 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3110 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3112 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3113 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3114 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3118 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3122 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3124 type
|= std::tr1::regex_constants::icase
;
3125 pat
= std::tr1::wregex(regexp_str
, type
);
3128 catch (std::exception
) {}
3131 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
)
3134 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3137 if ((bRegex
)&&(m_bFilterWithRegex
))
3139 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3141 if(this->m_bShowBugtraqColumn
)
3143 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3145 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
3146 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3153 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3155 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
3156 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3162 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3164 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
3165 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3171 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3173 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3178 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3184 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3186 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3191 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3197 if (m_SelectedFilters
& LOGFILTER_REVS
)
3199 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3200 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3206 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3208 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3209 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3211 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3218 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3220 CTGitPathList
*pathList
=NULL
;
3221 if( pRev
->m_IsDiffFiles
)
3222 pathList
= &pRev
->GetFiles(this);
3225 if(!pRev
->m_IsSimpleListReady
)
3226 pRev
->SafeGetSimpleList(&g_Git
);
3230 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3232 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3236 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3242 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3244 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3253 CString find
= m_sFilterText
;
3255 result
= find
[0] == '!' ? FALSE
: TRUE
;
3259 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3261 if(this->m_bShowBugtraqColumn
)
3263 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3265 sBugIds
.MakeLower();
3266 if ((sBugIds
.Find(find
) >= 0))
3273 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3275 CString msg
= pRev
->GetSubject();
3277 msg
= msg
.MakeLower();
3278 if ((msg
.Find(find
) >= 0))
3284 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3286 CString msg
= pRev
->GetBody();
3288 msg
= msg
.MakeLower();
3289 if ((msg
.Find(find
) >= 0))
3295 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3297 CString msg
= pRev
->GetAuthorName();
3298 msg
= msg
.MakeLower();
3299 if ((msg
.Find(find
) >= 0))
3305 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3307 CString msg
= pRev
->GetAuthorEmail();
3308 msg
= msg
.MakeLower();
3309 if ((msg
.Find(find
) >= 0))
3315 if (m_SelectedFilters
& LOGFILTER_REVS
)
3317 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3318 if ((sRev
.Find(find
) >= 0))
3324 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3326 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3327 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3329 if (it
->Find(find
) >= 0)
3336 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3338 CTGitPathList
*pathList
=NULL
;
3339 if( pRev
->m_IsDiffFiles
)
3340 pathList
= &pRev
->GetFiles(this);
3343 if(!pRev
->m_IsSimpleListReady
)
3344 pRev
->SafeGetSimpleList(&g_Git
);
3347 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3349 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3350 CString path
= cpath
->GetGitOldPathString();
3352 if ((path
.Find(find
)>=0))
3356 path
= cpath
->GetGitPathString();
3358 if ((path
.Find(find
)>=0))
3364 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3366 CString path
= pRev
->m_SimpleFileList
[i
];
3368 if ((path
.Find(find
)>=0))
3374 } // else (from if (bRegex))
3378 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3380 return str
.Left(prefix
.GetLength()) == prefix
;
3382 bool CGitLogListBase::ShouldShowFilter(GitRev
*pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>> &commitChildren
)
3384 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3387 if (m_ShowFilter
& FILTERSHOW_REFS
)
3390 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3391 for (size_t i
= 0; i
< refList
.size(); ++i
)
3393 const CString
&str
= refList
[i
];
3394 if (CStringStartsWith(str
, _T("refs/heads/")))
3396 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3399 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3401 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3404 else if (CStringStartsWith(str
, _T("refs/tags/")))
3406 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3409 else if (CStringStartsWith(str
, _T("refs/stash")))
3411 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3414 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3416 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3420 // Keep the head too.
3421 if (pRev
->m_CommitHash
== m_HeadHash
)
3425 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3427 if (pRev
->ParentsCount() > 1)
3429 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3430 if (childrenIt
!= commitChildren
.end())
3432 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3433 if (children
.size() > 1)
3440 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3442 // HACK to hide graph column
3444 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3446 SetColumnWidth(0, 0);
3449 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3454 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3456 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3457 for (size_t i
= 0; i
< vector
.size(); ++i
)
3459 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3461 CString tag
= vector
[i
];
3462 int start
= vector
[i
].Find(_T("^{}"));
3464 tag
= tag
.Left(start
);
3468 cmd
.Format(_T("git.exe cat-file tag %s"), tag
);
3469 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3470 output
.AppendChar(_T('\n'));
3478 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3481 pShownlist
->SafeRemoveAll();
3483 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3484 bool bRegex
= false;
3485 if (m_bFilterWithRegex
)
3486 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3488 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3490 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3492 if ((bRegex
)&&(m_bFilterWithRegex
))
3495 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3497 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3498 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3500 pShownlist
->SafeAdd(m_logEntries
[i
]);
3505 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3507 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3508 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3510 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3514 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3516 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3517 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3519 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3523 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3525 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3528 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3530 CTGitPath cpath
= pathList
[cpPathIndex
];
3531 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3533 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3537 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3539 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3543 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3545 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3551 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3553 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3555 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3559 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3561 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3563 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3567 if (m_SelectedFilters
& LOGFILTER_REVS
)
3569 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3570 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3572 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3576 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3578 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3579 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3581 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3583 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3591 CString find
= m_sFilterText
;
3594 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3596 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3598 sBugIDs
= sBugIDs
.MakeLower();
3599 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3601 pShownlist
->SafeAdd(m_logEntries
[i
]);
3606 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3608 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3610 msg
= msg
.MakeLower();
3611 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3613 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3617 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3619 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3621 msg
= msg
.MakeLower();
3622 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3624 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3628 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3630 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3633 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3635 CTGitPath cpath
= pathList
[cpPathIndex
];
3636 CString path
= cpath
.GetGitOldPathString();
3638 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3640 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3644 path
= cpath
.GetGitPathString();
3646 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3648 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3652 path
= cpath
.GetActionName();
3654 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3656 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3662 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3664 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3665 msg
= msg
.MakeLower();
3666 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3668 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3672 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3674 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3675 msg
= msg
.MakeLower();
3676 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3678 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3682 if (m_SelectedFilters
& LOGFILTER_REVS
)
3684 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3685 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3687 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3691 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3693 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3694 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3696 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3698 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3703 } // else (from if (bRegex))
3704 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3708 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3711 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3717 return time <= m_To;
3720 return time >= m_From;
3722 return ((time >= m_From)&&(time <= m_To));
3724 return TRUE
; /* git dll will filter time range */
3728 void CGitLogListBase::StartFilter()
3730 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3731 RecalculateShownList(&m_arShownList
);
3732 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3736 SetItemCountEx(ShownCountWithStopped());
3737 RedrawItems(0, ShownCountWithStopped());
3741 void CGitLogListBase::RemoveFilter()
3744 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3746 m_arShownList
.SafeRemoveAll();
3748 // reset the time filter too
3750 m_timFrom
= (__time64_t(m_tFrom
));
3751 m_timTo
= (__time64_t(m_tTo
));
3752 m_DateFrom
.SetTime(&m_timFrom
);
3753 m_DateTo
.SetTime(&m_timTo
);
3754 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3755 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3758 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3760 if(this->m_IsOldFirst
)
3762 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3766 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3769 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3771 SetItemCountEx(ShownCountWithStopped());
3772 RedrawItems(0, ShownCountWithStopped());
3774 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3777 void CGitLogListBase::Clear()
3779 m_arShownList
.SafeRemoveAll();
3782 m_logEntries
.ClearAll();
3786 void CGitLogListBase::OnDestroy()
3788 // save the column widths to the registry
3791 SafeTerminateThread();
3792 SafeTerminateAsyncDiffThread();
3795 while(m_LogCache
.SaveCache())
3803 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3804 // MB_YESNO) == IDNO)
3808 CHintListCtrl::OnDestroy();
3811 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3815 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3816 this->InvalidateRect(rect
);
3822 * Save column widths to the registry
3824 void CGitLogListBase::SaveColumnWidths()
3826 int maxcol
= m_ColumnManager
.GetColumnCount();
3828 // HACK that graph column is always shown
3829 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3831 for (int col
= 0; col
< maxcol
; ++col
)
3832 if (m_ColumnManager
.IsVisible (col
))
3833 m_ColumnManager
.ColumnResized (col
);
3835 m_ColumnManager
.WriteSettings();
3838 int CGitLogListBase::GetHeadIndex()
3840 if(m_HeadHash
.IsEmpty())
3843 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3845 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3848 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3854 void CGitLogListBase::OnFind()
3858 m_pFindDialog
= new CFindDlg(this);
3859 m_pFindDialog
->Create(this);
3862 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3864 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3866 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3868 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3871 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3873 if (GetSelectedCount() != 0)
3876 CGitHash theSelectedHash
= m_lastSelectedHash
;
3877 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3878 m_lastSelectedHash
= theSelectedHash
;
3880 int countPerPage
= GetCountPerPage();
3881 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3882 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3883 EnsureVisible((int)itemToSelect
, FALSE
);
3886 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3889 ASSERT(m_pFindDialog
!= NULL
);
3890 bool bFound
= false;
3893 if (m_pFindDialog
->IsTerminating())
3895 // invalidate the handle identifying the dialog box.
3896 m_pFindDialog
= NULL
;
3900 INT_PTR cnt
= m_arShownList
.GetCount();
3902 if(m_pFindDialog
->IsRef())
3905 str
=m_pFindDialog
->GetFindString();
3911 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3912 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3917 for (i
= 0; i
< cnt
; ++i
)
3919 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3920 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3929 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3934 if (m_pFindDialog
->FindNext() && !bFound
)
3936 //read data from dialog
3937 CString findText
= m_pFindDialog
->GetFindString();
3938 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3940 std::tr1::wregex pat
;
3941 bool bRegex
= false;
3942 if (m_pFindDialog
->Regex())
3943 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3945 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3947 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3952 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3954 if (m_nSearchIndex
>= 0)
3956 if (i
== m_nSearchIndex
)
3958 ::MessageBeep(0xFFFFFFFF);
3959 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3964 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3967 str
+=pLogEntry
->m_CommitHash
.ToString();
3970 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
3972 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3976 str
+=pLogEntry
->GetAuthorEmail();
3978 str
+=pLogEntry
->GetAuthorName();
3980 str
+=pLogEntry
->GetBody();
3982 str
+=pLogEntry
->GetCommitterEmail();
3984 str
+=pLogEntry
->GetCommitterName();
3986 str
+=pLogEntry
->GetSubject();
3988 str
+=pLogEntry
->m_Notes
;
3990 str
+=GetTagInfo(pLogEntry
);
3994 /*Because changed files list is loaded on demand when gui show,
3995 files will empty when files have not fetched.
3997 we can add it back by using one-way diff(with outnumber changed and rename detect.
3998 here just need changed filename list. one-way is much quicker.
4000 if(pLogEntry
->m_IsFull
)
4002 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
4004 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
4006 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
4012 if(!pLogEntry
->m_IsSimpleListReady
)
4013 pLogEntry
->SafeGetSimpleList(&g_Git
);
4015 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
4017 str
+=pLogEntry
->m_SimpleFileList
[i
];
4026 if (std::regex_search(std::wstring(str
), pat
, flags
))
4036 if (str
.Find(findText
) >= 0)
4046 msg
= msg
.MakeLower();
4047 CString find
= findText
.MakeLower();
4048 if (msg
.Find(find
) >= 0)
4055 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4057 } // if(m_pFindDialog->FindNext())
4058 //UpdateLogInfoLabel();
4063 EnsureVisible(i
, FALSE
);
4064 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4065 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4066 SetSelectionMark(i
);
4067 //FillLogMessageCtrl();
4074 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4076 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4081 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4083 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);