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
);
80 m_bShowBugtraqColumn
=false;
82 m_IsIDReplaceAction
=FALSE
;
84 this->m_critSec
.Init();
85 m_critSec_AsyncDiff
.Init();
86 m_wcRev
.m_CommitHash
.Empty();
87 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
88 m_wcRev
.m_ParentHash
.clear();
89 m_wcRev
.m_Mark
=_T('-');
90 m_wcRev
.m_IsUpdateing
=FALSE
;
91 m_wcRev
.m_IsFull
= TRUE
;
93 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
94 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
95 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
96 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
97 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
99 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
105 m_LoadingThread
= NULL
;
107 InterlockedExchange(&m_bExitThread
,FALSE
);
108 m_IsOldFirst
= FALSE
;
109 m_IsRebaseReplaceGraph
= FALSE
;
111 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
113 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
115 // get short/long datetime setting from registry
116 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
117 if ( RegUseShortDateFormat
)
119 m_DateFormat
= DATE_SHORTDATE
;
123 m_DateFormat
= DATE_LONGDATE
;
125 // get relative time display setting from registry
126 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
127 m_bRelativeTimes
= (regRelativeTimes
!= 0);
128 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
131 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
132 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
133 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
134 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
135 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
136 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
138 m_ColumnRegKey
=_T("log");
140 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
141 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
142 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
144 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
145 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
147 m_AsyncThreadExit
= FALSE
;
148 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
149 m_AsynDiffListLock
.Init();
151 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
152 if (m_DiffingThread
==NULL
)
154 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
160 int CGitLogListBase::AsyncDiffThread()
162 m_AsyncThreadExited
= false;
163 while(!m_AsyncThreadExit
)
165 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
168 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
170 m_AsynDiffListLock
.Lock();
171 pRev
= m_AsynDiffList
.back();
172 m_AsynDiffList
.pop_back();
173 m_AsynDiffListLock
.Unlock();
175 if( pRev
->m_CommitHash
.IsEmpty() )
177 if(pRev
->m_IsDiffFiles
)
180 pRev
->GetFiles(this).Clear();
181 pRev
->m_ParentHash
.clear();
182 pRev
->m_ParentHash
.push_back(m_HeadHash
);
183 if(g_Git
.IsInitRepos())
185 if (g_Git
.GetInitAddList(pRev
->GetFiles(this)))
186 CMessageBox::Show(NULL
, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
191 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
194 int *action
= &dummyAction
;
195 SafeGetAction(pRev
, &action
);
198 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
199 *action
|= pRev
->GetFiles(this)[j
].m_Action
;
202 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
204 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
208 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
209 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
211 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
212 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
213 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
216 m_critSec_AsyncDiff
.Lock();
217 int ret
= pRev
->CheckAndDiff();
218 m_critSec_AsyncDiff
.Unlock();
220 { // fetch change file list
221 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
223 if(i
< m_arShownList
.GetCount())
225 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
226 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
228 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
234 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
236 POSITION pos
= GetFirstSelectedItemPosition();
237 int nItem
= GetNextSelectedItem(pos
);
241 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
243 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
245 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
252 m_AsyncThreadExited
= true;
255 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
259 m_ContextMenuMask
&= hideMask
;
263 m_ContextMenuMask
&= ~hideMask
;
267 CGitLogListBase::~CGitLogListBase()
269 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
270 this->m_arShownList
.SafeRemoveAll();
272 DestroyIcon(m_hModifiedIcon
);
273 DestroyIcon(m_hReplacedIcon
);
274 DestroyIcon(m_hAddedIcon
);
275 DestroyIcon(m_hDeletedIcon
);
276 m_logEntries
.ClearAll();
279 DeleteObject(m_boldFont
);
281 if ( m_pStoreSelection
)
283 delete m_pStoreSelection
;
284 m_pStoreSelection
= NULL
;
287 SafeTerminateThread();
288 SafeTerminateAsyncDiffThread();
291 CloseHandle(m_AsyncDiffEvent
);
295 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
296 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
297 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
298 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
299 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
301 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
302 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
305 ON_MESSAGE(MSG_LOADED
,OnLoad
)
307 ON_WM_MEASUREITEM_REFLECT()
308 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
309 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
310 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
311 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
312 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
313 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
316 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
318 //if (m_nRowHeight>0)
320 lpMeasureItemStruct
->itemHeight
= 50;
324 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
327 return CHintListCtrl::OnCreate(lpCreateStruct
);
330 void CGitLogListBase::PreSubclassWindow()
332 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
333 // load the icons for the action columns
334 // m_Theme.Open(m_hWnd, L"ListView");
335 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
336 CHintListCtrl::PreSubclassWindow();
339 CString
CGitLogListBase::GetRebaseActionName(int action
)
341 if (action
& LOGACTIONS_REBASE_EDIT
)
342 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
343 if (action
& LOGACTIONS_REBASE_SQUASH
)
344 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
345 if (action
& LOGACTIONS_REBASE_PICK
)
346 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
347 if (action
& LOGACTIONS_REBASE_SKIP
)
348 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
350 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
353 void CGitLogListBase::InsertGitColumn()
357 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
358 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
359 if (DWORD(regFullRowSelect
))
360 exStyle
|= LVS_EX_FULLROWSELECT
;
361 SetExtendedStyle(exStyle
);
363 // only load properties if we have a repository
364 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
365 UpdateProjectProperties();
367 static UINT normal
[] =
379 IDS_LOG_COMMIT_EMAIL
,
400 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
402 DWORD hideColumns
= 0;
403 if(this->m_IsRebaseReplaceGraph
)
405 hideColumns
|= GIT_LOG_GRAPH
;
406 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
410 hideColumns
|= GIT_LOG_REBASE
;
413 if(this->m_IsIDReplaceAction
)
415 hideColumns
|= GIT_LOG_ACTIONS
;
416 m_dwDefaultColumns
|= GIT_LOG_ID
;
417 m_dwDefaultColumns
|= GIT_LOG_HASH
;
421 hideColumns
|= GIT_LOG_ID
;
423 if(this->m_bShowBugtraqColumn
)
425 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
429 hideColumns
|= GIT_LOGLIST_BUG
;
433 m_ColumnManager
.SetNames(normal
, _countof(normal
));
434 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
440 * Resizes all columns in a list control to values in registry.
442 void CGitLogListBase::ResizeAllListCtrlCols()
444 // column max and min widths to allow
445 static const int nMinimumWidth
= 10;
446 static const int nMaximumWidth
= 1000;
447 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
450 int numcols
= pHdrCtrl
->GetItemCount();
451 for (int col
= 0; col
< numcols
; ++col
)
453 // get width for this col last time from registry
455 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
456 CRegDWORD
regwidth(regentry
, 0);
460 // no saved value, setup sensible defaults
461 if (col
== this->LOGLIST_MESSAGE
)
463 cx
= LOGLIST_MESSAGE_MIN
;
467 cx
= ICONITEMBORDER
+16*4;
470 if (cx
< nMinimumWidth
)
474 else if (cx
> nMaximumWidth
)
479 SetColumnWidth(col
, cx
);
486 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
489 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
490 rItem
.mask
= LVIF_STATE
;
491 rItem
.iItem
= (int)Index
;
492 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
495 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
498 if (!(rItem
.state
& LVIS_SELECTED
))
500 int action
= pLogEntry
->GetRebaseAction();
501 if (action
& LOGACTIONS_REBASE_SQUASH
)
502 brush
= ::CreateSolidBrush(RGB(156,156,156));
503 else if (action
& LOGACTIONS_REBASE_EDIT
)
504 brush
= ::CreateSolidBrush(RGB(200,200,128));
506 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
508 if (rItem
.state
& LVIS_SELECTED
)
510 if (::GetFocus() == m_hWnd
)
511 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
513 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
518 ::FillRect(hdc
, &rect
, brush
);
519 ::DeleteObject(brush
);
523 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
525 POINT point
= { 4, 4 };
527 rt2
.DeflateRect(1, 1);
528 rt2
.OffsetRect(2, 2);
530 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
531 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
532 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
533 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
534 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
536 ::SelectObject(hdc
, brush
);
537 rt2
.OffsetRect(-2, -2);
538 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
539 ::SelectObject(hdc
, oldbrush
);
540 ::SelectObject(hdc
, oldpen
);
541 ::DeleteObject(nullPen
);
542 ::DeleteObject(darkBrush
);
545 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
547 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
548 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
549 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
550 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
551 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
552 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
553 ::SelectObject(hdc
, oldpen
);
557 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
559 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
560 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
561 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
562 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
563 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
564 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
565 ::SelectObject(hdc
, oldpen
);
569 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
571 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
574 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
575 rItem
.mask
= LVIF_STATE
;
576 rItem
.iItem
= (int)index
;
577 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
583 HTHEME hTheme
= NULL
;
584 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
585 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
588 if (m_bTagsBranchesOnRightSide
)
590 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
591 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
592 SelectObject(hdc
, oldFont
);
593 rt
.left
+= oneSpaceSize
.cx
* 2;
597 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
598 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
599 rt
.left
+= oneSpaceSize
.cx
;
602 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
604 int txtState
= LISS_NORMAL
;
605 if (rItem
.state
& LVIS_SELECTED
)
606 txtState
= LISS_SELECTED
;
608 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, 0, &rt
);
612 if (rItem
.state
& LVIS_SELECTED
)
614 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
615 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
616 ::SetTextColor(hdc
, clrOld
);
620 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
624 if (m_bTagsBranchesOnRightSide
)
627 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
629 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
631 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
635 CloseThemeData(hTheme
);
640 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
)
642 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
644 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
646 COLORREF colRef
= refList
[i
].color
;
647 bool singleRemote
= refList
[i
].singleRemote
;
648 bool hasTracking
= refList
[i
].hasTracking
;
649 bool sameName
= refList
[i
].sameName
;
650 bool annotatedTag
= refList
[i
].annotatedTag
;
652 //When row selected, ajust label color
653 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
655 if (rItem
.state
& LVIS_SELECTED
)
656 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
659 brush
= ::CreateSolidBrush(colRef
);
661 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
664 memset(&size
,0,sizeof(SIZE
));
665 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
667 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
670 int textpos
= DT_CENTER
;
672 if (rt
.right
> rect
.right
)
674 rt
.right
= rect
.right
;
683 textRect
.OffsetRect(8, 0);
691 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
695 //Fill interior of ref label
696 ::FillRect(hdc
, &rt
, brush
);
704 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
705 rectEdge
.DeflateRect(1, 1);
706 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
712 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
713 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
714 ::FillRgn(hdc
, hrgn
, brush
);
715 ::DeleteObject(hrgn
);
716 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
718 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
719 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
721 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
722 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
724 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
725 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
726 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
728 SelectObject(hdc
, oldpen
);
731 //Draw text inside label
732 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
733 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
735 int txtState
= LISS_NORMAL
;
736 if (rItem
.state
& LVIS_SELECTED
)
737 txtState
= LISS_SELECTED
;
739 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &textRect
);
743 W_Dc
.SetBkMode(TRANSPARENT
);
744 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
746 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
747 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
748 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
749 ::SetTextColor(hdc
,clrOld
);
753 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
759 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
760 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
762 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
763 DrawLightning(hdc
, newRect
, color
, bold
);
768 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
769 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
771 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
772 DrawUpTriangle(hdc
, newRect
, color
, bold
);
775 rt
.left
= rt
.right
+ 1;
778 ::DeleteObject(brush
);
780 rt
.right
= rect
.right
;
783 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
785 // Returns ((256 - amount)*col1 + amount*col2) / 256;
786 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
787 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
788 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
791 Gdiplus::Color
GetGdiColor(COLORREF col
)
793 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
795 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
796 const COLORREF
& col
,const COLORREF
& activeColor
, int top
799 int h
= laneHeight
/ 2;
800 int m
= (x1
+ x2
) / 2;
801 int r
= (x2
- x1
) * m_NodeSize
/ 30;
804 #define P_CENTER m , h+top
805 #define P_0 x2, h+top
806 #define P_90 m , 0+top-1
807 #define P_180 x1, h+top
808 #define P_270 m , 2 * h+top +1
809 #define R_CENTER m - r, h - r+top, d, d
812 #define DELTA_UR_B 2*(x1 - m), 2*h +top
813 #define DELTA_UR_E 0*16, 90*16 +top // -,
815 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
816 #define DELTA_DR_E 270*16, 90*16 +top // -'
818 #define DELTA_UL_B 2*(x2 - m), 2*h +top
819 #define DELTA_UL_E 90*16, 90*16 +top // ,-
821 #define DELTA_DL_B 2*(x2 - m),2*-h +top
822 #define DELTA_DL_E 180*16, 90*16 // '-
824 #define CENTER_UR x1, 2*h, 225
825 #define CENTER_DR x1, 0 , 135
826 #define CENTER_UL x2, 2*h, 315
827 #define CENTER_DL x2, 0 , 45
830 Gdiplus::Graphics
graphics( hdc
);
832 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
841 Gdiplus::LinearGradientBrush
gradient(
842 Gdiplus::Point(x1
-2, h
+top
-2),
843 Gdiplus::Point(P_270
),
844 GetGdiColor(activeColor
),GetGdiColor(col
));
847 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
848 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
850 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
851 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
852 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
859 Gdiplus::LinearGradientBrush
gradient(
860 Gdiplus::Point(P_270
),
861 Gdiplus::Point(x2
+1, h
+top
-1),
862 GetGdiColor(col
),GetGdiColor(activeColor
));
865 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
866 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
868 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
869 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
870 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
879 Gdiplus::LinearGradientBrush
gradient(
880 Gdiplus::Point(x1
-2, h
+top
-2),
881 Gdiplus::Point(P_90
),
882 GetGdiColor(activeColor
),GetGdiColor(col
));
884 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
886 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
889 QConicalGradient
gradient(CENTER_DR
);
890 gradient
.setColorAt(0.375, activeCol
);
891 gradient
.setColorAt(0.625, col
);
892 myPen
.setBrush(gradient
);
894 p
->drawArc(P_CENTER
, DELTA_DR
);
903 //static QPen myPen(Qt::black, 2); // fast path here
905 pen
.CreatePen(PS_SOLID
,2,col
);
906 //myPen.setColor(col);
907 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
909 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
911 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
918 case Lanes::NOT_ACTIVE
:
919 case Lanes::MERGE_FORK
:
920 case Lanes::MERGE_FORK_R
:
921 case Lanes::MERGE_FORK_L
:
926 //DrawLine(hdc,P_90,P_270);
927 graphics
.DrawLine(&myPen
,P_90
,P_270
);
928 //p->drawLine(P_90, P_270);
932 //DrawLine(hdc,P_CENTER,P_270);
933 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
934 //p->drawLine(P_CENTER, P_270);
938 case Lanes::BOUNDARY
:
939 case Lanes::BOUNDARY_C
:
940 case Lanes::BOUNDARY_R
:
941 case Lanes::BOUNDARY_L
:
942 //DrawLine(hdc,P_90, P_CENTER);
943 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
944 //p->drawLine(P_90, P_CENTER);
950 myPen
.SetColor(GetGdiColor(activeColor
));
954 case Lanes::MERGE_FORK
:
959 case Lanes::CROSS_EMPTY
:
960 case Lanes::BOUNDARY_C
:
961 //DrawLine(hdc,P_180,P_0);
962 graphics
.DrawLine(&myPen
,P_180
,P_0
);
963 //p->drawLine(P_180, P_0);
965 case Lanes::MERGE_FORK_R
:
966 case Lanes::BOUNDARY_R
:
967 //DrawLine(hdc,P_180,P_CENTER);
968 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
969 //p->drawLine(P_180, P_CENTER);
971 case Lanes::MERGE_FORK_L
:
974 case Lanes::BOUNDARY_L
:
975 //DrawLine(hdc,P_CENTER,P_0);
976 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
977 //p->drawLine(P_CENTER, P_0);
983 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
986 brush
.CreateSolidBrush(col
);
987 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
989 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
990 // center symbol, e.g. rect or ellipse
996 //p->setPen(Qt::NoPen);
998 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
999 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1000 //p->drawEllipse(R_CENTER);
1002 case Lanes::MERGE_FORK
:
1003 case Lanes::MERGE_FORK_R
:
1004 case Lanes::MERGE_FORK_L
:
1005 //p->setPen(Qt::NoPen);
1007 //p->drawRect(R_CENTER);
1008 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1009 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1011 case Lanes::UNAPPLIED
:
1013 //p->setPen(Qt::NoPen);
1014 //p->setBrush(Qt::red);
1015 //p->drawRect(m - r, h - 1, d, 2);
1016 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1017 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1019 case Lanes::APPLIED
:
1021 //p->setPen(Qt::NoPen);
1022 //p->setBrush(DARK_GREEN);
1023 //p->drawRect(m - r, h - 1, d, 2);
1024 //p->drawRect(m - 1, h - r, 2, d);
1025 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1026 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1027 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1029 case Lanes::BOUNDARY
:
1030 //p->setBrush(back);
1031 //p->drawEllipse(R_CENTER);
1032 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1033 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1035 case Lanes::BOUNDARY_C
:
1036 case Lanes::BOUNDARY_R
:
1037 case Lanes::BOUNDARY_L
:
1038 //p->setBrush(back);
1039 //p->drawRect(R_CENTER);
1040 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1041 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1047 ::SelectObject(hdc
,oldpen
);
1048 ::SelectObject(hdc
,oldbrush
);
1057 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1061 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1062 if(data
->m_CommitHash
.IsEmpty())
1067 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1068 rItem
.mask
= LVIF_STATE
;
1069 rItem
.iItem
= (int)index
;
1070 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1073 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1075 if (data
->m_Lanes
.empty())
1076 m_logEntries
.setLane(data
->m_CommitHash
);
1078 std::vector
<int>& lanes
=data
->m_Lanes
;
1079 size_t laneNum
= lanes
.size();
1080 UINT activeLane
= 0;
1081 for (UINT i
= 0; i
< laneNum
; ++i
)
1082 if (Lanes::isMerge(lanes
[i
])) {
1088 int maxWidth
= rect
.Width();
1089 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1091 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1092 //if (opt.state & QStyle::State_Selected)
1093 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1095 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1102 if (ln
== Lanes::EMPTY
)
1105 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1106 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1110 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1116 if (ln
== Lanes::EMPTY
)
1119 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1120 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1122 if (ln
== Lanes::CROSS
)
1124 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1125 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1128 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1134 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1137 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1138 // Take the default processing unless we set this to something else below.
1139 *pResult
= CDRF_DODEFAULT
;
1141 if (m_bNoDispUpdates
)
1144 switch (pLVCD
->nmcd
.dwDrawStage
)
1148 *pResult
= CDRF_NOTIFYITEMDRAW
;
1152 case CDDS_ITEMPREPAINT
:
1154 // This is the prepaint stage for an item. Here's where we set the
1155 // item's text color.
1157 // Tell Windows to send draw notifications for each subitem.
1158 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1160 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1162 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1164 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1167 int action
= data
->GetRebaseAction();
1168 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1169 crText
= RGB(128,128,128);
1171 if (action
& LOGACTIONS_REBASE_SQUASH
)
1172 pLVCD
->clrTextBk
= RGB(156,156,156);
1173 else if (action
& LOGACTIONS_REBASE_EDIT
)
1174 pLVCD
->clrTextBk
= RGB(200,200,128);
1176 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1178 if (action
& LOGACTIONS_REBASE_CURRENT
)
1180 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1181 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1184 if (data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
)
1186 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1187 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1190 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1191 // crText = GetSysColor(COLOR_GRAYTEXT);
1193 if (data
->m_CommitHash
.IsEmpty())
1195 //crText = GetSysColor(RGB(200,200,0));
1196 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1197 // We changed the font, so we're returning CDRF_NEWFONT. This
1198 // tells the control to recalculate the extent of the text.
1199 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1203 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1205 if (m_bStrictStopped
)
1206 crText
= GetSysColor(COLOR_GRAYTEXT
);
1208 // Store the color back in the NMLVCUSTOMDRAW struct.
1209 pLVCD
->clrText
= crText
;
1213 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1215 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1217 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1220 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1222 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1225 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1227 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1228 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1230 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1231 if( !data
->m_CommitHash
.IsEmpty())
1232 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1234 *pResult
= CDRF_SKIPDEFAULT
;
1239 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1241 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1243 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1245 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1248 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1250 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1251 // not in FillBackGround method, because this only affected the message subitem
1252 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1255 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1256 int state
= GetItemState(index
, LVIS_SELECTED
);
1257 int txtState
= LISS_NORMAL
;
1258 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1260 if (state
& LVIS_SELECTED
)
1261 txtState
= LISS_HOTSELECTED
;
1263 txtState
= LISS_HOT
;
1265 else if (state
& LVIS_SELECTED
)
1267 if (::GetFocus() == m_hWnd
)
1268 txtState
= LISS_SELECTED
;
1270 txtState
= LISS_SELECTEDNOTFOCUS
;
1273 HTHEME hTheme
= nullptr;
1274 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1275 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1277 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1278 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1281 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1282 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1283 ::DeleteObject(brush
);
1288 // get rect of whole line
1289 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1291 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1292 rect2
.DeflateRect(1, 1, 1, 1);
1294 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1295 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1297 CloseThemeData(hTheme
);
1299 // END: extended redraw
1301 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1303 std::vector
<REFLABEL
> refsToShow
;
1304 STRING_VECTOR remoteTrackingList
;
1305 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1306 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1308 CString str
= refList
[i
];
1311 refLabel
.color
= RGB(255, 255, 255);
1312 refLabel
.singleRemote
= false;
1313 refLabel
.hasTracking
= false;
1314 refLabel
.sameName
= false;
1315 refLabel
.annotatedTag
= false;
1316 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1318 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1320 if (refLabel
.name
== m_CurrentBranch
)
1321 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1323 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1325 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1326 CString pullRemote
= trackingEntry
.first
;
1327 CString pullBranch
= trackingEntry
.second
;
1328 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1330 CString defaultUpstream
;
1331 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1332 refLabel
.hasTracking
= true;
1333 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1336 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1338 if (refList
[j
] == defaultUpstream
)
1347 bool sameName
= pullBranch
== refLabel
.name
;
1348 refsToShow
.push_back(refLabel
);
1349 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1350 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1351 if (m_bSymbolizeRefNames
)
1353 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1355 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1356 refLabel
.singleRemote
= true;
1359 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1360 refLabel
.sameName
= sameName
;
1362 refsToShow
.push_back(refLabel
);
1363 remoteTrackingList
.push_back(defaultUpstream
);
1369 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1371 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1375 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1377 if (remoteTrackingList
[j
] == str
)
1386 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1387 if (m_bSymbolizeRefNames
)
1389 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1391 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1392 refLabel
.singleRemote
= true;
1396 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1398 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1400 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1401 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1403 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1405 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1407 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1408 refLabel
.name
= _T("stash");
1410 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1412 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1414 if (refLabel
.name
.Find(_T("good")) == 0)
1416 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1417 refLabel
.name
= _T("good");
1419 if (refLabel
.name
.Find(_T("bad")) == 0)
1421 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1422 refLabel
.name
= _T("bad");
1428 refsToShow
.push_back(refLabel
);
1431 if (refsToShow
.empty())
1433 *pResult
= CDRF_DODEFAULT
;
1437 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1439 *pResult
= CDRF_SKIPDEFAULT
;
1447 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1449 if(this->m_IsIDReplaceAction
)
1451 *pResult
= CDRF_DODEFAULT
;
1454 *pResult
= CDRF_DODEFAULT
;
1456 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1460 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1461 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1463 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1465 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1466 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1467 // Get the selected state of the
1468 // item being drawn.
1470 // Fill the background if necessary
1471 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1473 // Draw the icon(s) into the compatible DC
1474 int action
= SafeGetAction(pLogEntry
);
1476 if (!pLogEntry
->m_IsDiffFiles
)
1477 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1479 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1480 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1483 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1484 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1487 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1488 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1491 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1492 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1494 *pResult
= CDRF_SKIPDEFAULT
;
1500 *pResult
= CDRF_DODEFAULT
;
1503 // CGitLogListBase message handlers
1505 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1507 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1509 // Create a pointer to the item
1510 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1512 // Do the list need text information?
1513 if (!(pItem
->mask
& LVIF_TEXT
))
1516 // By default, clear text buffer.
1517 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1519 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1522 if (m_bNoDispUpdates
|| bOutOfRange
)
1525 // Which item number?
1526 int itemid
= pItem
->iItem
;
1527 GitRev
* pLogEntry
= NULL
;
1528 if (itemid
< m_arShownList
.GetCount())
1529 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1534 temp
.Format(_T("%d"),pItem
->iItem
+1);
1539 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1543 switch (pItem
->iSubItem
)
1545 case this->LOGLIST_GRAPH
: //Graphic
1547 case this->LOGLIST_REBASE
:
1549 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1550 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
);
1553 case this->LOGLIST_ACTION
: //action -- no text in the column
1555 case this->LOGLIST_HASH
:
1557 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1559 case this->LOGLIST_ID
:
1560 if(this->m_IsIDReplaceAction
)
1561 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1563 case this->LOGLIST_MESSAGE
: //Message
1565 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1567 case this->LOGLIST_AUTHOR
: //Author
1569 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1571 case this->LOGLIST_DATE
: //Date
1572 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1573 lstrcpyn(pItem
->pszText
,
1574 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1578 case this->LOGLIST_EMAIL
:
1580 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1583 case this->LOGLIST_COMMIT_NAME
: //Commit
1585 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1588 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1590 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1593 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1594 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1595 lstrcpyn(pItem
->pszText
,
1596 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1599 case this->LOGLIST_BUG
: //Bug ID
1601 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1609 bool CGitLogListBase::IsOnStash(int index
)
1611 GitRev
*rev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
));
1616 GitRev
*preRev
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
- 1));
1617 if (IsStash(preRev
))
1618 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1623 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1625 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1627 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1633 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1635 if (pRev
->m_ParentHash
.empty())
1639 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1641 catch (const char* msg
)
1643 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1646 parentHash
= pRev
->m_ParentHash
;
1649 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1652 if (pWnd
== GetHeaderCtrl())
1654 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1657 int selIndex
= GetSelectionMark();
1659 return; // nothing selected, nothing to do with a context menu
1661 // if the user selected the info text telling about not all revisions shown due to
1662 // the "stop on copy/rename" option, we also don't show the context menu
1663 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1666 // if the context menu is invoked through the keyboard, we have to use
1667 // a calculated position on where to anchor the menu on
1668 if ((point
.x
== -1) && (point
.y
== -1))
1671 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1672 ClientToScreen(&rect
);
1673 point
= rect
.CenterPoint();
1675 m_nSearchIndex
= selIndex
;
1676 m_bCancelled
= FALSE
;
1678 // calculate some information the context menu commands can use
1679 // CString pathURL = GetURLFromPath(m_path);
1681 POSITION pos
= GetFirstSelectedItemPosition();
1682 int indexNext
= GetNextSelectedItem(pos
);
1686 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1688 GitRev revSelected
= pSelLogEntry
->Rev
;
1689 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1690 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1692 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1694 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1695 if (changedpath
->lCopyFromRev
)
1696 revPrevious
= changedpath
->lCopyFromRev
;
1699 GitRev revSelected2
;
1702 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1703 revSelected2
= pLogEntry
->Rev
;
1705 bool bAllFromTheSameAuthor
= true;
1706 CString firstAuthor
;
1707 CLogDataVector selEntries
;
1708 GitRev revLowest
, revHighest
;
1709 GitRevRangeArray revisionRanges
;
1711 POSITION pos
= GetFirstSelectedItemPosition();
1712 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1713 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1714 selEntries
.push_back(pLogEntry
);
1715 firstAuthor
= pLogEntry
->sAuthor
;
1716 revLowest
= pLogEntry
->Rev
;
1717 revHighest
= pLogEntry
->Rev
;
1720 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1721 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1722 selEntries
.push_back(pLogEntry
);
1723 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1724 bAllFromTheSameAuthor
= false;
1725 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1726 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1732 int FirstSelect
=-1, LastSelect
=-1;
1733 pos
= GetFirstSelectedItemPosition();
1734 FirstSelect
= GetNextSelectedItem(pos
);
1737 LastSelect
= GetNextSelectedItem(pos
);
1739 //entry is selected, now show the popup menu
1741 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1743 if (popup
.CreatePopupMenu())
1745 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1746 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1747 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1748 bool isStash
= IsOnStash(indexNext
);
1749 GIT_REV_LIST parentHash
;
1750 GetParentHashes(pSelLogEntry
, parentHash
);
1752 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1753 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1755 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1756 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1758 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1759 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1761 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1762 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1764 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
)))
1765 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1767 if (GetSelectedCount() == 1)
1770 bool requiresSeparator
= false;
1771 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1773 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1775 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1776 requiresSeparator
= true;
1781 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1783 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1784 requiresSeparator
= true;
1786 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1788 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1789 requiresSeparator
= true;
1793 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1795 if (parentHash
.size() == 1)
1797 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1798 requiresSeparator
= true;
1800 else if (parentHash
.size() > 1)
1802 blamemenu
.CreatePopupMenu();
1803 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1804 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1807 str
.Format(IDS_PARENT
, i
+ 1);
1808 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1810 requiresSeparator
= true;
1814 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1816 if (parentHash
.size() == 1)
1818 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1819 requiresSeparator
= true;
1821 else if (parentHash
.size() > 1)
1823 gnudiffmenu
.CreatePopupMenu();
1824 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1826 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1827 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1829 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1832 str
.Format(IDS_PARENT
, i
+ 1);
1833 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1835 requiresSeparator
= true;
1839 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1841 if (parentHash
.size() == 1)
1843 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1844 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1845 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1846 requiresSeparator
= true;
1848 else if (parentHash
.size() > 1)
1850 diffmenu
.CreatePopupMenu();
1851 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1852 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1855 str
.Format(IDS_PARENT
, i
+ 1);
1856 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1857 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1859 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1860 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1863 requiresSeparator
= true;
1867 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1869 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1870 requiresSeparator
= true;
1873 if (requiresSeparator
)
1874 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1876 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1878 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1879 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1882 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1884 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1885 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1887 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1888 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1890 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1893 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1895 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1896 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1898 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1899 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1901 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1905 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1907 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1909 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1911 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1913 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1914 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1916 // popup.AppendMenu(MF_SEPARATOR, NULL);
1921 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1923 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1925 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1926 GetSelectedCount() == 1)
1927 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1929 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1930 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1932 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1933 str
.Format(format
,g_Git
.GetCurrentBranch());
1935 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
1936 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1938 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1939 str
.Format(format
,g_Git
.GetCurrentBranch());
1941 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
1942 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1945 // Add Switch Branch express Menu
1946 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1947 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
1950 std::vector
<CString
*> branchs
;
1951 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1953 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1954 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1956 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1961 str
.LoadString(IDS_SWITCH_BRANCH
);
1963 if(branchs
.size() == 1)
1966 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1967 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1969 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1972 else if(branchs
.size() > 1)
1974 subbranchmenu
.CreatePopupMenu();
1975 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
1977 if (*branchs
[i
] != currentBranch
)
1979 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1980 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1984 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1988 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
1989 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1991 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
1992 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1994 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
1995 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1997 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1998 str
.Format(format
,g_Git
.GetCurrentBranch());
2000 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2001 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2002 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2004 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2005 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2007 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2009 if (parentHash
.size() == 1)
2011 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2013 else if (parentHash
.size() > 1)
2015 revertmenu
.CreatePopupMenu();
2016 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2018 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2021 str
.Format(IDS_PARENT
, i
+ 1);
2022 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
2027 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2028 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2030 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2035 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2037 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2038 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2039 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2040 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2043 if (GetSelectedCount() >= 2)
2045 bool bAddSeparator
= false;
2046 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2048 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2049 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2052 if (GetSelectedCount() == 2)
2054 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2055 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2057 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2059 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2060 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2061 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2063 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
2064 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2065 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
2066 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2069 bAddSeparator
= true;
2074 bAddSeparator
= true;
2077 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2078 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2081 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2084 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2086 bool bAddSeparator
= false;
2087 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2089 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2093 headindex
= this->GetHeadIndex();
2094 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2096 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2098 if (g_Git
.GetHash(hashFirst
, head
))
2099 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2100 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2102 if (g_Git
.GetHash(hash
, head
))
2103 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2104 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2105 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2106 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2107 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2108 bAddSeparator
= true;
2113 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2114 if (GetSelectedCount() >= 2)
2115 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2117 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2118 bAddSeparator
= true;
2121 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2122 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2123 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2124 bAddSeparator
= true;
2128 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2131 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())
2133 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2134 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2137 if (GetSelectedCount() == 1)
2139 bool bAddSeparator
= false;
2140 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
2142 // show the push-option only if the log entry has an associated local branch
2143 bool isLocal
= false;
2144 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2146 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2151 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2152 bAddSeparator
= true;
2155 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
)
2157 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2158 bAddSeparator
= true;
2162 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2164 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2166 std::vector
<CString
*> branchs
;
2167 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2169 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2170 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2173 if (branchs
.size() == 1)
2175 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2178 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2179 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2180 bAddSeparator
= true;
2182 else if (branchs
.size() > 1)
2184 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2185 submenu
.CreatePopupMenu();
2186 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2188 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2189 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2192 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2193 bAddSeparator
= true;
2196 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2198 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2199 } // GetSelectedCount() == 1
2201 if (GetSelectedCount() != 0)
2203 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2204 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2205 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2206 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2207 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2208 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2211 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2212 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2214 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2215 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2217 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2218 // DialogEnableWindow(IDOK, FALSE);
2219 // SetPromptApp(&theApp);
2221 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2223 // EnableOKButton();
2224 } // if (popup.CreatePopupMenu())
2228 bool CGitLogListBase::IsSelectionContinuous()
2230 if ( GetSelectedCount()==1 )
2232 // if only one revision is selected, the selection is of course
2237 POSITION pos
= GetFirstSelectedItemPosition();
2238 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2241 int itemindex
= GetNextSelectedItem(pos
);
2244 int nextindex
= GetNextSelectedItem(pos
);
2245 if (nextindex
- itemindex
> 1)
2247 bContinuous
= false;
2250 itemindex
= nextindex
;
2256 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2260 POSITION pos
= GetFirstSelectedItemPosition();
2264 sRev
.LoadString(IDS_LOG_REVISION
);
2266 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2268 sDate
.LoadString(IDS_LOG_DATE
);
2270 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2274 CString sLogCopyText
;
2276 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2278 if (toCopy
== ID_COPY_ALL
)
2280 //pLogEntry->GetFiles(this)
2281 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2283 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2284 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2286 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2287 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2290 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2291 sPaths
+= _T(" ") + rename
;
2293 sPaths
+= _T("\r\n");
2296 CString body
= pLogEntry
->GetBody();
2297 body
.Replace(_T("\n"), _T("\r\n"));
2298 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"),
2299 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2300 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2302 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2303 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2305 sClipdata
+= sLogCopyText
;
2307 else if (toCopy
== ID_COPY_MESSAGE
)
2309 CString body
= pLogEntry
->GetBody();
2310 body
.Replace(_T("\n"), _T("\r\n"));
2311 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2313 else if (toCopy
== ID_COPY_SUBJECT
)
2315 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2320 sClipdata
+= _T("\r\n");
2321 sClipdata
+= pLogEntry
->m_CommitHash
;
2326 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2331 void CGitLogListBase::DiffSelectedRevWithPrevious()
2333 if (m_bThreadRunning
)
2336 int FirstSelect
=-1, LastSelect
=-1;
2337 POSITION pos
= GetFirstSelectedItemPosition();
2338 FirstSelect
= GetNextSelectedItem(pos
);
2341 LastSelect
= GetNextSelectedItem(pos
);
2344 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2347 UpdateLogInfoLabel();
2348 int selIndex
= m_LogList
.GetSelectionMark();
2351 int selCount
= m_LogList
.GetSelectedCount();
2355 // Find selected entry in the log list
2356 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2357 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2358 long rev1
= pLogEntry
->Rev
;
2360 CTGitPath path
= m_path
;
2362 // See how many files under the relative root were changed in selected revision
2364 LogChangedPath
* changed
= NULL
;
2365 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2367 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2368 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2375 if (m_path
.IsDirectory() && nChanged
== 1)
2377 // We're looking at the log for a directory and only one file under dir was changed in the revision
2378 // Do diff on that file instead of whole directory
2379 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2382 m_bCancelled
= FALSE
;
2383 DialogEnableWindow(IDOK
, FALSE
);
2384 SetPromptApp(&theApp
);
2385 theApp
.DoWaitCursor(1);
2389 GitDiff
diff(this, m_hWnd
, true);
2390 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2391 diff
.SetHEADPeg(m_LogRevision
);
2392 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2396 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2399 theApp
.DoWaitCursor(-1);
2404 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2406 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2409 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2411 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2413 if (pFindInfo
->lvfi
.psz
== 0)
2416 CString sCmp
= pFindInfo
->lvfi
.psz
;
2418 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2420 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2421 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2422 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2424 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2432 if (sCmp
.Compare(sRev
)==0)
2439 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2441 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2443 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2444 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2445 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2447 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2455 if (sCmp
.Compare(sRev
)==0)
2467 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2471 this->m_arShownList
.SafeRemoveAll();
2473 this->m_logEntries
.ClearAll();
2474 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2477 //this->m_logEntries.ParserFromLog();
2478 SetItemCountEx((int)m_logEntries
.size());
2480 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2484 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2485 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2490 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2491 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2503 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2507 m_arShownList
.SafeRemoveAll();
2509 m_logEntries
.ClearAll();
2510 if (m_logEntries
.Fill(hashes
))
2513 SetItemCountEx((int)m_logEntries
.size());
2515 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2519 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2520 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2524 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2525 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2534 int CGitLogListBase::BeginFetchLog()
2538 this->m_arShownList
.SafeRemoveAll();
2540 this->m_logEntries
.ClearAll();
2542 this->m_LogCache
.ClearAllParent();
2544 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2547 if(this->m_Path
.IsEmpty())
2553 mask
= CGit::LOG_INFO_ONLY_HASH
;
2554 if (m_bIncludeBoundaryCommits
)
2555 mask
|= CGit::LOG_INFO_BOUNDARY
;
2556 // if(this->m_bAllBranch)
2557 mask
|= m_ShowMask
;
2561 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2563 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2566 if (m_sRange
.IsEmpty())
2567 m_sRange
= _T("HEAD");
2570 data
.m_From
= m_From
;
2573 #if 0 /* use tortoiegit filter */
2574 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2575 data
.m_Author
= this->m_sFilterText
;
2577 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2578 data
.m_MessageFilter
= this->m_sFilterText
;
2580 data
.m_IsRegex
= m_bFilterWithRegex
;
2583 // follow does not work for directories
2584 if (!path
|| path
->IsDirectory())
2585 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2586 // follow does not work with all branches 8at least in TGit)
2587 if (mask
& CGit::LOG_INFO_FOLLOW
)
2588 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2590 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2592 //this->m_logEntries.ParserFromLog();
2593 if(IsInWorkingThread())
2595 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2599 SetItemCountEx((int)m_logEntries
.size());
2604 [] { git_init(); } ();
2609 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2613 if (!g_Git
.CanParseRev(m_sRange
))
2615 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2618 // if show all branches, pick any ref as dummy entry ref
2620 if (g_Git
.GetRefList(list
))
2621 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2622 if (list
.size() == 0)
2625 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2628 g_Git
.m_critGitDllSec
.Lock();
2630 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2632 g_Git
.m_critGitDllSec
.Unlock();
2638 g_Git
.m_critGitDllSec
.Unlock();
2640 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2643 g_Git
.m_critGitDllSec
.Unlock();
2648 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2650 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2652 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2654 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2656 DiffSelectedRevWithPrevious();
2661 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2668 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2670 // select all entries
2671 for (int i
=0; i
<GetItemCount(); ++i
)
2673 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2679 if (m_hAccel
&& !bSkipAccelerator
)
2681 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2687 //m_tooltips.RelayEvent(pMsg);
2688 return __super::PreTranslateMessage(pMsg
);
2691 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2693 // a double click on an entry in the revision list has happened
2696 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2697 DiffSelectedRevWithPrevious();
2700 int CGitLogListBase::FetchLogAsync(void * data
)
2704 m_bExitThread
=FALSE
;
2705 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2706 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2707 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2708 if (m_LoadingThread
==NULL
)
2710 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2711 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2712 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2718 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2720 return ((CGitLogListBase
*)pVoid
)->LogThread();
2723 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2726 oldest
=CTime::GetCurrentTime();
2727 latest
=CTime(1971,1,2,0,0,0);
2728 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2730 if(m_logEntries
[i
].IsEmpty())
2733 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2734 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2736 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2737 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2745 UINT
CGitLogListBase::LogThread()
2747 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2749 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2750 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2756 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2757 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2762 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2763 bool bRegex
= false;
2764 if (m_bFilterWithRegex
)
2765 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2767 TRACE(_T("\n===Begin===\n"));
2768 //Update work copy item;
2770 if (!m_logEntries
.empty())
2772 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2774 m_arShownList
.SafeAdd(pRev
);
2778 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2780 // store commit number of the last selected commit/line before the refresh or -1
2781 int lastSelectedHashNItem
= -1;
2784 bool shouldWalk
= true;
2785 if (!g_Git
.CanParseRev(m_sRange
))
2787 // walk revisions if show all branches and there exists any ref
2788 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2793 if (g_Git
.GetRefList(list
))
2794 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2795 if (list
.size() == 0)
2802 g_Git
.m_critGitDllSec
.Lock();
2806 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2807 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2812 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2815 g_Git
.m_critGitDllSec
.Unlock();
2818 t2
=t1
=GetTickCount();
2819 int oldprecentage
= 0;
2820 size_t oldsize
= m_logEntries
.size();
2821 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2822 while (ret
== 0 && !m_bExitThread
)
2824 g_Git
.m_critGitDllSec
.Lock();
2827 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2831 g_Git
.m_critGitDllSec
.Unlock();
2833 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2836 g_Git
.m_critGitDllSec
.Unlock();
2841 if (commit
.m_ignore
== 1)
2843 git_free_commit(&commit
);
2847 //printf("%s\r\n",commit.GetSubject());
2851 CGitHash hash
= (char*)commit
.m_hash
;
2853 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2854 pRev
->m_GitCommit
= commit
;
2855 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2858 g_Git
.m_critGitDllSec
.Lock();
2861 git_get_notes(commit
.m_hash
, ¬e
);
2865 g_Git
.m_critGitDllSec
.Unlock();
2867 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2870 g_Git
.m_critGitDllSec
.Unlock();
2874 pRev
->m_Notes
.Empty();
2875 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2878 if(!pRev
->m_IsDiffFiles
)
2880 pRev
->m_CallDiffAsync
= DiffAsync
;
2883 pRev
->ParserParentFromCommit(&commit
);
2884 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2886 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2888 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2889 auto it
= commitChildren
.find(parentHash
);
2890 if (it
== commitChildren
.end())
2892 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2894 it
->second
.insert(pRev
->m_CommitHash
);
2903 bool visible
= true;
2904 if (HasFilterText())
2906 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2909 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
2911 this->m_critSec
.Lock();
2912 m_logEntries
.append(hash
, visible
);
2914 m_arShownList
.SafeAdd(pRev
);
2915 this->m_critSec
.Unlock();
2920 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2921 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2925 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2928 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2931 if(percent
< GITLOG_START
)
2932 percent
= GITLOG_START
+1;
2934 oldsize
= m_logEntries
.size();
2935 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2937 //if( percent > oldprecentage )
2939 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2940 oldprecentage
= percent
;
2943 if (lastSelectedHashNItem
>= 0)
2944 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2949 g_Git
.m_critGitDllSec
.Lock();
2950 git_close_log(m_DllGitLog
);
2951 g_Git
.m_critGitDllSec
.Unlock();
2957 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2962 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2964 if (lastSelectedHashNItem
>= 0)
2965 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2968 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2970 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2975 void CGitLogListBase::FetchRemoteList()
2977 STRING_VECTOR remoteList
;
2978 if (!g_Git
.GetRemoteList(remoteList
))
2979 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
2981 m_SingleRemote
= _T("");
2984 void CGitLogListBase::FetchTrackingBranchList()
2986 m_TrackingMap
.clear();
2987 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
2989 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
2992 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
2995 configName
.Format(_T("branch.%s.remote"), branchName
);
2996 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2998 configName
.Format(_T("branch.%s.merge"), branchName
);
2999 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
3001 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3003 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3010 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3012 SafeTerminateThread();
3014 this->SetItemCountEx(0);
3019 // HACK to hide graph column
3020 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3021 SetColumnWidth(0, 0);
3023 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3025 //Update branch and Tag info
3027 //Assume Thread have exited
3028 //if(!m_bThreadRunning)
3030 m_logEntries
.clear();
3034 m_sFilterText
.Empty();
3039 InterlockedExchange(&m_bExitThread
,FALSE
);
3041 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3042 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3043 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3045 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3046 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3047 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3051 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3055 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3057 type
|= std::tr1::regex_constants::icase
;
3058 pat
= std::tr1::wregex(regexp_str
, type
);
3061 catch (std::exception
) {}
3064 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
)
3067 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3070 if ((bRegex
)&&(m_bFilterWithRegex
))
3072 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3074 if(this->m_bShowBugtraqColumn
)
3076 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3078 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
3079 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3086 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3088 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
3089 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3095 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3097 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
3098 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3104 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3106 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3111 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3117 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3119 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3124 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3130 if (m_SelectedFilters
& LOGFILTER_REVS
)
3132 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3133 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3139 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3141 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3142 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3144 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3151 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3153 CTGitPathList
*pathList
=NULL
;
3154 if( pRev
->m_IsDiffFiles
)
3155 pathList
= &pRev
->GetFiles(this);
3158 if(!pRev
->m_IsSimpleListReady
)
3159 pRev
->SafeGetSimpleList(&g_Git
);
3163 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3165 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3169 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3175 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3177 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3186 CString find
= m_sFilterText
;
3188 result
= find
[0] == '!' ? FALSE
: TRUE
;
3192 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3194 if(this->m_bShowBugtraqColumn
)
3196 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3198 sBugIds
.MakeLower();
3199 if ((sBugIds
.Find(find
) >= 0))
3206 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3208 CString msg
= pRev
->GetSubject();
3210 msg
= msg
.MakeLower();
3211 if ((msg
.Find(find
) >= 0))
3217 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3219 CString msg
= pRev
->GetBody();
3221 msg
= msg
.MakeLower();
3222 if ((msg
.Find(find
) >= 0))
3228 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3230 CString msg
= pRev
->GetAuthorName();
3231 msg
= msg
.MakeLower();
3232 if ((msg
.Find(find
) >= 0))
3238 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3240 CString msg
= pRev
->GetAuthorEmail();
3241 msg
= msg
.MakeLower();
3242 if ((msg
.Find(find
) >= 0))
3248 if (m_SelectedFilters
& LOGFILTER_REVS
)
3250 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3251 if ((sRev
.Find(find
) >= 0))
3257 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3259 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3260 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3262 if (it
->Find(find
) >= 0)
3269 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3271 CTGitPathList
*pathList
=NULL
;
3272 if( pRev
->m_IsDiffFiles
)
3273 pathList
= &pRev
->GetFiles(this);
3276 if(!pRev
->m_IsSimpleListReady
)
3277 pRev
->SafeGetSimpleList(&g_Git
);
3280 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3282 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3283 CString path
= cpath
->GetGitOldPathString();
3285 if ((path
.Find(find
)>=0))
3289 path
= cpath
->GetGitPathString();
3291 if ((path
.Find(find
)>=0))
3297 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3299 CString path
= pRev
->m_SimpleFileList
[i
];
3301 if ((path
.Find(find
)>=0))
3307 } // else (from if (bRegex))
3311 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3313 return str
.Left(prefix
.GetLength()) == prefix
;
3315 bool CGitLogListBase::ShouldShowFilter(GitRev
*pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>> &commitChildren
)
3317 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3320 if (m_ShowFilter
& FILTERSHOW_REFS
)
3323 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3324 for (size_t i
= 0; i
< refList
.size(); ++i
)
3326 const CString
&str
= refList
[i
];
3327 if (CStringStartsWith(str
, _T("refs/heads/")))
3329 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3332 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3334 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3337 else if (CStringStartsWith(str
, _T("refs/tags/")))
3339 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3342 else if (CStringStartsWith(str
, _T("refs/stash")))
3344 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3347 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3349 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3353 // Keep the head too.
3354 if (pRev
->m_CommitHash
== m_HeadHash
)
3358 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3360 if (pRev
->ParentsCount() > 1)
3362 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3363 if (childrenIt
!= commitChildren
.end())
3365 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3366 if (children
.size() > 1)
3373 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3375 // HACK to hide graph column
3377 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3379 SetColumnWidth(0, 0);
3382 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3385 pShownlist
->SafeRemoveAll();
3387 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3388 bool bRegex
= false;
3389 if (m_bFilterWithRegex
)
3390 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3392 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3394 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3396 if ((bRegex
)&&(m_bFilterWithRegex
))
3399 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3401 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3402 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3404 pShownlist
->SafeAdd(m_logEntries
[i
]);
3409 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3411 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3412 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3414 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3418 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3420 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3421 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3423 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3427 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3429 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3432 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3434 CTGitPath cpath
= pathList
[cpPathIndex
];
3435 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3437 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3441 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3443 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3447 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3449 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3455 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3457 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3459 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3463 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3465 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3467 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3471 if (m_SelectedFilters
& LOGFILTER_REVS
)
3473 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3474 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3476 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3480 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3482 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3483 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3485 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3487 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3495 CString find
= m_sFilterText
;
3498 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3500 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3502 sBugIDs
= sBugIDs
.MakeLower();
3503 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3505 pShownlist
->SafeAdd(m_logEntries
[i
]);
3510 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3512 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3514 msg
= msg
.MakeLower();
3515 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3517 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3521 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3523 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3525 msg
= msg
.MakeLower();
3526 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3528 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3532 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3534 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3537 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3539 CTGitPath cpath
= pathList
[cpPathIndex
];
3540 CString path
= cpath
.GetGitOldPathString();
3542 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3544 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3548 path
= cpath
.GetGitPathString();
3550 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3552 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3556 path
= cpath
.GetActionName();
3558 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3560 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3566 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3568 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3569 msg
= msg
.MakeLower();
3570 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3572 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3576 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3578 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3579 msg
= msg
.MakeLower();
3580 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3582 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3586 if (m_SelectedFilters
& LOGFILTER_REVS
)
3588 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3589 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3591 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3595 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3597 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3598 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3600 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3602 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3607 } // else (from if (bRegex))
3608 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3612 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3615 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3621 return time <= m_To;
3624 return time >= m_From;
3626 return ((time >= m_From)&&(time <= m_To));
3628 return TRUE
; /* git dll will filter time range */
3632 void CGitLogListBase::StartFilter()
3634 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3635 RecalculateShownList(&m_arShownList
);
3636 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3640 SetItemCountEx(ShownCountWithStopped());
3641 RedrawItems(0, ShownCountWithStopped());
3645 void CGitLogListBase::RemoveFilter()
3648 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3650 m_arShownList
.SafeRemoveAll();
3652 // reset the time filter too
3654 m_timFrom
= (__time64_t(m_tFrom
));
3655 m_timTo
= (__time64_t(m_tTo
));
3656 m_DateFrom
.SetTime(&m_timFrom
);
3657 m_DateTo
.SetTime(&m_timTo
);
3658 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3659 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3662 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3664 if(this->m_IsOldFirst
)
3666 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3670 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3673 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3675 SetItemCountEx(ShownCountWithStopped());
3676 RedrawItems(0, ShownCountWithStopped());
3678 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3681 void CGitLogListBase::Clear()
3683 m_arShownList
.SafeRemoveAll();
3686 m_logEntries
.ClearAll();
3690 void CGitLogListBase::OnDestroy()
3692 // save the column widths to the registry
3695 SafeTerminateThread();
3696 SafeTerminateAsyncDiffThread();
3699 while(m_LogCache
.SaveCache())
3707 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3708 // MB_YESNO) == IDNO)
3712 CHintListCtrl::OnDestroy();
3715 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3719 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3720 this->InvalidateRect(rect
);
3726 * Save column widths to the registry
3728 void CGitLogListBase::SaveColumnWidths()
3730 int maxcol
= m_ColumnManager
.GetColumnCount();
3732 // HACK that graph column is always shown
3733 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3735 for (int col
= 0; col
< maxcol
; ++col
)
3736 if (m_ColumnManager
.IsVisible (col
))
3737 m_ColumnManager
.ColumnResized (col
);
3739 m_ColumnManager
.WriteSettings();
3742 int CGitLogListBase::GetHeadIndex()
3744 if(m_HeadHash
.IsEmpty())
3747 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3749 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3752 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3758 void CGitLogListBase::OnFind()
3762 m_pFindDialog
= new CFindDlg(this);
3763 m_pFindDialog
->Create(this);
3766 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3768 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3770 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3772 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3775 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3777 if (GetSelectedCount() != 0)
3780 CGitHash theSelectedHash
= m_lastSelectedHash
;
3781 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3782 m_lastSelectedHash
= theSelectedHash
;
3784 int countPerPage
= GetCountPerPage();
3785 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3786 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3787 EnsureVisible((int)itemToSelect
, FALSE
);
3790 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3793 ASSERT(m_pFindDialog
!= NULL
);
3794 bool bFound
= false;
3797 if (m_pFindDialog
->IsTerminating())
3799 // invalidate the handle identifying the dialog box.
3800 m_pFindDialog
= NULL
;
3804 INT_PTR cnt
= m_arShownList
.GetCount();
3806 if(m_pFindDialog
->IsRef())
3809 str
=m_pFindDialog
->GetFindString();
3815 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3816 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3821 for (i
= 0; i
< cnt
; ++i
)
3823 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3824 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3833 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3838 if (m_pFindDialog
->FindNext() && !bFound
)
3840 //read data from dialog
3841 CString FindText
= m_pFindDialog
->GetFindString();
3842 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3844 std::tr1::wregex pat
;
3845 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3847 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3849 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3854 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3856 if (m_nSearchIndex
>= 0)
3858 if (i
== m_nSearchIndex
)
3860 ::MessageBeep(0xFFFFFFFF);
3861 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3866 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3869 str
+=pLogEntry
->m_CommitHash
.ToString();
3872 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
3874 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3878 str
+=pLogEntry
->GetAuthorEmail();
3880 str
+=pLogEntry
->GetAuthorName();
3882 str
+=pLogEntry
->GetBody();
3884 str
+=pLogEntry
->GetCommitterEmail();
3886 str
+=pLogEntry
->GetCommitterName();
3888 str
+=pLogEntry
->GetSubject();
3892 /*Because changed files list is loaded on demand when gui show,
3893 files will empty when files have not fetched.
3895 we can add it back by using one-way diff(with outnumber changed and rename detect.
3896 here just need changed filename list. one-way is much quicker.
3898 if(pLogEntry
->m_IsFull
)
3900 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
3902 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3904 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3910 if(!pLogEntry
->m_IsSimpleListReady
)
3911 pLogEntry
->SafeGetSimpleList(&g_Git
);
3913 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
3915 str
+=pLogEntry
->m_SimpleFileList
[i
];
3924 if (std::regex_search(std::wstring(str
), pat
, flags
))
3934 if (str
.Find(FindText
) >= 0)
3944 msg
= msg
.MakeLower();
3945 CString find
= FindText
.MakeLower();
3946 if (msg
.Find(find
) >= 0)
3953 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3955 } // if(m_pFindDialog->FindNext())
3956 //UpdateLogInfoLabel();
3961 EnsureVisible(i
, FALSE
);
3962 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3963 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3964 SetSelectionMark(i
);
3965 //FillLogMessageCtrl();
3972 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3974 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3979 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3981 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);