1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // GitLogList.cpp : implementation file
24 #include "GitLogListBase.h"
27 #include "GitProgressDlg.h"
28 #include "ProgressDlg.h"
29 #include "MessageBox.h"
31 #include "LoglistUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
35 #include "GitStatus.h"
36 #include "..\TortoiseShell\Resource.h"
40 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
41 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
42 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
44 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
46 CGitLogListBase::CGitLogListBase():CHintListCtrl()
47 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
49 ,m_bNoDispUpdates(FALSE
)
50 , m_bThreadRunning(FALSE
)
51 , m_bStrictStopped(false)
52 , m_SelectedFilters(LOGFILTER_ALL
)
53 , m_ShowFilter(FILTERSHOW_ALL
)
55 , m_logEntries(&m_LogCache
)
57 , m_ColumnManager(this)
58 , m_dwDefaultColumns(0)
59 , m_arShownList(&m_critSec
)
61 , m_bNoHightlightHead(FALSE
)
62 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
63 , m_bFullCommitMessageOnLogLine(false)
65 // use the default GUI font, create a copy of it and
66 // change the copy to BOLD (leave the rest of the font
68 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
70 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
71 lf
.lfWeight
= FW_BOLD
;
72 m_boldFont
= CreateFontIndirect(&lf
);
73 lf
.lfWeight
= FW_DONTCARE
;
75 m_FontItalics
= CreateFontIndirect(&lf
);
76 lf
.lfWeight
= FW_BOLD
;
77 m_boldItalicsFont
= CreateFontIndirect(&lf
);
79 m_bShowBugtraqColumn
=false;
81 m_IsIDReplaceAction
=FALSE
;
83 this->m_critSec
.Init();
86 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
87 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
88 m_hConflictedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
89 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
90 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
91 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
93 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE
);
94 m_bFilterCaseSensitively
= !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE
);
96 m_Filter
.m_NumberOfLogsScale
= (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT
);
97 if (m_Filter
.m_NumberOfLogsScale
== CFilterData::SHOW_LAST_SEL_DATE
)
100 key
.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR
)g_Git
.m_CurrentDir
);
101 key
.Replace(_T(':'), _T('_'));
102 CString lastSelFromDate
= CRegString(key
);
103 if (lastSelFromDate
.GetLength() == 10)
105 CTime time
= CTime(_wtoi((LPCTSTR
)lastSelFromDate
.Mid(0, 4)), _wtoi((LPCTSTR
)lastSelFromDate
.Mid(5, 2)), _wtoi((LPCTSTR
)lastSelFromDate
.Mid(8, 2)), 0, 0, 0);
106 m_Filter
.m_From
= (DWORD
)time
.GetTime();
109 m_Filter
.m_NumberOfLogs
= (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
112 m_LoadingThread
= NULL
;
114 InterlockedExchange(&m_bExitThread
,FALSE
);
115 m_IsOldFirst
= FALSE
;
116 m_IsRebaseReplaceGraph
= FALSE
;
118 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
120 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
122 // get short/long datetime setting from registry
123 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
124 if ( RegUseShortDateFormat
)
126 m_DateFormat
= DATE_SHORTDATE
;
130 m_DateFormat
= DATE_LONGDATE
;
132 // get relative time display setting from registry
133 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
134 m_bRelativeTimes
= (regRelativeTimes
!= 0);
135 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
137 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
138 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
139 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
140 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
141 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
142 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
143 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
145 m_ColumnRegKey
=_T("log");
147 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
148 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
149 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
150 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE
);
152 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
153 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
155 m_AsyncThreadExit
= FALSE
;
156 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
157 m_AsynDiffListLock
.Init();
159 hUxTheme
= AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
161 pfnDrawThemeTextEx
= (FNDRAWTHEMETEXTEX
)::GetProcAddress(hUxTheme
, "DrawThemeTextEx");
163 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
, 0, CREATE_SUSPENDED
);
164 if (m_DiffingThread
==NULL
)
166 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
169 m_DiffingThread
->m_bAutoDelete
= FALSE
;
170 m_DiffingThread
->ResumeThread();
173 int CGitLogListBase::AsyncDiffThread()
175 m_AsyncThreadExited
= false;
176 while(!m_AsyncThreadExit
)
178 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
180 GitRevLoglist
* pRev
= nullptr;
181 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
183 m_AsynDiffListLock
.Lock();
184 pRev
= m_AsynDiffList
.back();
185 m_AsynDiffList
.pop_back();
186 m_AsynDiffListLock
.Unlock();
188 if( pRev
->m_CommitHash
.IsEmpty() )
190 if(pRev
->m_IsDiffFiles
)
193 CTGitPathList
& files
= pRev
->GetFiles(this);
195 pRev
->m_ParentHash
.clear();
196 pRev
->m_ParentHash
.push_back(m_HeadHash
);
197 g_Git
.GetWorkingTreeChanges(files
);
198 int& action
= pRev
->GetAction(this);
200 for (int j
= 0; j
< files
.GetCount(); ++j
)
201 action
|= files
[j
].m_Action
;
204 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
206 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
210 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
211 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
213 pRev
->GetBody().Format(IDS_FILESCHANGES
, files
.GetCount());
214 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
215 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
218 if (!pRev
->CheckAndDiff())
219 { // fetch change file list
220 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
222 if(i
< m_arShownList
.GetCount())
224 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
225 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
227 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
233 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
235 POSITION pos
= GetFirstSelectedItemPosition();
236 int nItem
= GetNextSelectedItem(pos
);
240 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
242 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
244 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
251 m_AsyncThreadExited
= true;
254 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
258 m_ContextMenuMask
&= hideMask
;
262 m_ContextMenuMask
&= ~hideMask
;
266 CGitLogListBase::~CGitLogListBase()
268 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
269 this->m_arShownList
.SafeRemoveAll();
271 DestroyIcon(m_hModifiedIcon
);
272 DestroyIcon(m_hReplacedIcon
);
273 DestroyIcon(m_hConflictedIcon
);
274 DestroyIcon(m_hAddedIcon
);
275 DestroyIcon(m_hDeletedIcon
);
276 m_logEntries
.ClearAll();
279 DeleteObject(m_boldFont
);
282 DeleteObject(m_FontItalics
);
284 if (m_boldItalicsFont
)
285 DeleteObject(m_boldItalicsFont
);
287 SafeTerminateThread();
288 SafeTerminateAsyncDiffThread();
291 CloseHandle(m_AsyncDiffEvent
);
294 FreeLibrary(hUxTheme
);
298 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
299 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
300 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
301 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
302 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
304 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
305 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
308 ON_MESSAGE(MSG_LOADED
,OnLoad
)
310 ON_WM_MEASUREITEM_REFLECT()
311 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
312 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
313 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
314 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
315 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
316 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
317 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
318 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
321 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
323 //if (m_nRowHeight>0)
325 lpMeasureItemStruct
->itemHeight
= 50;
329 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
332 return CHintListCtrl::OnCreate(lpCreateStruct
);
335 void CGitLogListBase::PreSubclassWindow()
337 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
338 // load the icons for the action columns
339 // m_Theme.Open(m_hWnd, L"ListView");
340 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
341 CHintListCtrl::PreSubclassWindow();
344 CString
CGitLogListBase::GetRebaseActionName(int action
)
346 if (action
& LOGACTIONS_REBASE_EDIT
)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
348 if (action
& LOGACTIONS_REBASE_SQUASH
)
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
350 if (action
& LOGACTIONS_REBASE_PICK
)
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
352 if (action
& LOGACTIONS_REBASE_SKIP
)
353 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
355 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
358 void CGitLogListBase::InsertGitColumn()
362 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
363 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
364 if (DWORD(regFullRowSelect
))
365 exStyle
|= LVS_EX_FULLROWSELECT
;
366 SetExtendedStyle(exStyle
);
368 // only load properties if we have a repository
369 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
370 UpdateProjectProperties();
372 static UINT normal
[] =
384 IDS_LOG_COMMIT_EMAIL
,
407 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
409 DWORD hideColumns
= 0;
410 if(this->m_IsRebaseReplaceGraph
)
412 hideColumns
|= GIT_LOG_GRAPH
;
413 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
417 hideColumns
|= GIT_LOG_REBASE
;
420 if(this->m_IsIDReplaceAction
)
422 hideColumns
|= GIT_LOG_ACTIONS
;
423 m_dwDefaultColumns
|= GIT_LOG_ID
;
424 m_dwDefaultColumns
|= GIT_LOG_HASH
;
428 hideColumns
|= GIT_LOG_ID
;
430 if(this->m_bShowBugtraqColumn
)
432 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
436 hideColumns
|= GIT_LOGLIST_BUG
;
438 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
439 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
441 hideColumns
|= GIT_LOGLIST_SVNREV
;
444 m_ColumnManager
.SetNames(normal
, _countof(normal
));
445 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
451 * Resizes all columns in a list control to values in registry.
453 void CGitLogListBase::ResizeAllListCtrlCols()
455 // column max and min widths to allow
456 static const int nMinimumWidth
= 10;
457 static const int nMaximumWidth
= 1000;
458 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
461 int numcols
= pHdrCtrl
->GetItemCount();
462 for (int col
= 0; col
< numcols
; ++col
)
464 // get width for this col last time from registry
466 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR
)m_ColumnRegKey
, col
);
467 CRegDWORD
regwidth(regentry
, 0);
471 // no saved value, setup sensible defaults
472 if (col
== this->LOGLIST_MESSAGE
)
474 cx
= LOGLIST_MESSAGE_MIN
;
478 cx
= ICONITEMBORDER
+16*4;
481 if (cx
< nMinimumWidth
)
485 else if (cx
> nMaximumWidth
)
490 SetColumnWidth(col
, cx
);
497 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
499 LVITEM rItem
= { 0 };
500 rItem
.mask
= LVIF_STATE
;
501 rItem
.iItem
= (int)Index
;
502 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
505 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(Index
);
508 if (!(rItem
.state
& LVIS_SELECTED
))
510 int action
= pLogEntry
->GetRebaseAction();
511 if (action
& LOGACTIONS_REBASE_SQUASH
)
512 brush
= ::CreateSolidBrush(RGB(156,156,156));
513 else if (action
& LOGACTIONS_REBASE_EDIT
)
514 brush
= ::CreateSolidBrush(RGB(200,200,128));
516 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
518 if (rItem
.state
& LVIS_SELECTED
)
520 if (::GetFocus() == m_hWnd
)
521 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
523 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
528 ::FillRect(hdc
, &rect
, brush
);
529 ::DeleteObject(brush
);
533 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
535 POINT point
= { 4, 4 };
537 rt2
.DeflateRect(1, 1);
538 rt2
.OffsetRect(2, 2);
540 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
541 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
542 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
543 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
544 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
546 ::SelectObject(hdc
, brush
);
547 rt2
.OffsetRect(-2, -2);
548 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
549 ::SelectObject(hdc
, oldbrush
);
550 ::SelectObject(hdc
, oldpen
);
551 ::DeleteObject(nullPen
);
552 ::DeleteObject(darkBrush
);
555 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
557 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
558 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
559 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
560 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
561 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
562 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
563 ::SelectObject(hdc
, oldpen
);
567 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
569 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
570 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
571 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
572 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
573 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
574 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
575 ::SelectObject(hdc
, oldpen
);
579 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
581 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
583 LVITEM rItem
= { 0 };
584 rItem
.mask
= LVIF_STATE
;
585 rItem
.iItem
= (int)index
;
586 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
592 HTHEME hTheme
= NULL
;
593 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
594 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
597 if (m_bTagsBranchesOnRightSide
)
599 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
600 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
601 SelectObject(hdc
, oldFont
);
602 rt
.left
+= oneSpaceSize
.cx
* 2;
606 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
607 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
608 rt
.left
+= oneSpaceSize
.cx
;
611 CString msg
= MessageDisplayStr(data
);
612 int action
= data
->GetRebaseAction();
613 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
614 if (IsAppThemed() && pfnDrawThemeTextEx
)
616 int txtState
= LISS_NORMAL
;
617 if (rItem
.state
& LVIS_SELECTED
)
618 txtState
= LISS_SELECTED
;
620 DTTOPTS opts
= { 0 };
621 opts
.dwSize
= sizeof(opts
);
622 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
623 opts
.dwFlags
= DTT_TEXTCOLOR
;
624 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
628 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
630 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
631 ::DrawText(hdc
,msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
632 ::SetTextColor(hdc
, clrOld
);
636 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
637 ::DrawText(hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
638 ::SetTextColor(hdc
, clrOld
);
642 if (m_bTagsBranchesOnRightSide
)
645 GetTextExtentPoint32(hdc
, msg
, msg
.GetLength(), &size
);
647 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
649 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
653 CloseThemeData(hTheme
);
658 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
)
660 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
662 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
664 COLORREF colRef
= refList
[i
].color
;
665 bool singleRemote
= refList
[i
].singleRemote
;
666 bool hasTracking
= refList
[i
].hasTracking
;
667 bool sameName
= refList
[i
].sameName
;
668 bool annotatedTag
= refList
[i
].annotatedTag
;
670 //When row selected, ajust label color
671 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
673 if (rItem
.state
& LVIS_SELECTED
)
674 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
677 brush
= ::CreateSolidBrush(colRef
);
679 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
682 memset(&size
,0,sizeof(SIZE
));
683 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
685 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
688 int textpos
= DT_CENTER
;
690 if (rt
.right
> rect
.right
)
692 rt
.right
= rect
.right
;
701 textRect
.OffsetRect(8, 0);
709 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
713 //Fill interior of ref label
714 ::FillRect(hdc
, &rt
, brush
);
722 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
723 rectEdge
.DeflateRect(1, 1);
724 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
730 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
731 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
732 ::FillRgn(hdc
, hrgn
, brush
);
733 ::DeleteObject(hrgn
);
734 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
736 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
737 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
739 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
740 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
742 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
743 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
744 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
746 SelectObject(hdc
, oldpen
);
749 //Draw text inside label
750 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
751 if (!customColor
&& IsAppThemed() && pfnDrawThemeTextEx
)
753 int txtState
= LISS_NORMAL
;
754 if (rItem
.state
& LVIS_SELECTED
)
755 txtState
= LISS_SELECTED
;
757 DTTOPTS opts
= { 0 };
758 opts
.dwSize
= sizeof(opts
);
759 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
760 opts
.dwFlags
= DTT_TEXTCOLOR
;
761 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
765 W_Dc
.SetBkMode(TRANSPARENT
);
766 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
768 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
769 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
770 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
771 ::SetTextColor(hdc
,clrOld
);
775 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
776 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
777 ::SetTextColor(hdc
, clrOld
);
783 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
784 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
786 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
787 DrawLightning(hdc
, newRect
, color
, bold
);
792 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
793 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
795 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
796 DrawUpTriangle(hdc
, newRect
, color
, bold
);
799 rt
.left
= rt
.right
+ 1;
802 ::DeleteObject(brush
);
804 rt
.right
= rect
.right
;
807 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
809 // Returns ((256 - amount)*col1 + amount*col2) / 256;
810 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
811 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
812 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
815 Gdiplus::Color
GetGdiColor(COLORREF col
)
817 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
819 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
820 const COLORREF
& col
,const COLORREF
& activeColor
, int top
823 int h
= laneHeight
/ 2;
824 int m
= (x1
+ x2
) / 2;
825 int r
= (x2
- x1
) * m_NodeSize
/ 30;
828 #define P_CENTER m , h+top
829 #define P_0 x2, h+top
830 #define P_90 m , 0+top-1
831 #define P_180 x1, h+top
832 #define P_270 m , 2 * h+top +1
833 #define R_CENTER m - r, h - r+top, d, d
836 #define DELTA_UR_B 2*(x1 - m), 2*h +top
837 #define DELTA_UR_E 0*16, 90*16 +top // -,
839 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
840 #define DELTA_DR_E 270*16, 90*16 +top // -'
842 #define DELTA_UL_B 2*(x2 - m), 2*h +top
843 #define DELTA_UL_E 90*16, 90*16 +top // ,-
845 #define DELTA_DL_B 2*(x2 - m),2*-h +top
846 #define DELTA_DL_E 180*16, 90*16 // '-
848 #define CENTER_UR x1, 2*h, 225
849 #define CENTER_DR x1, 0 , 135
850 #define CENTER_UL x2, 2*h, 315
851 #define CENTER_DL x2, 0 , 45
854 Gdiplus::Graphics
graphics( hdc
);
856 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
865 Gdiplus::LinearGradientBrush
gradient(
866 Gdiplus::Point(x1
-2, h
+top
-2),
867 Gdiplus::Point(P_270
),
868 GetGdiColor(activeColor
),GetGdiColor(col
));
871 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
872 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
874 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
875 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
876 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
883 Gdiplus::LinearGradientBrush
gradient(
884 Gdiplus::Point(P_270
),
885 Gdiplus::Point(x2
+1, h
+top
-1),
886 GetGdiColor(col
),GetGdiColor(activeColor
));
889 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
890 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
892 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
893 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
894 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
903 Gdiplus::LinearGradientBrush
gradient(
904 Gdiplus::Point(x1
-2, h
+top
-2),
905 Gdiplus::Point(P_90
),
906 GetGdiColor(activeColor
),GetGdiColor(col
));
908 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
910 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
913 QConicalGradient
gradient(CENTER_DR
);
914 gradient
.setColorAt(0.375, activeCol
);
915 gradient
.setColorAt(0.625, col
);
916 myPen
.setBrush(gradient
);
918 p
->drawArc(P_CENTER
, DELTA_DR
);
927 //static QPen myPen(Qt::black, 2); // fast path here
929 pen
.CreatePen(PS_SOLID
,2,col
);
930 //myPen.setColor(col);
931 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
933 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
935 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
942 case Lanes::NOT_ACTIVE
:
943 case Lanes::MERGE_FORK
:
944 case Lanes::MERGE_FORK_R
:
945 case Lanes::MERGE_FORK_L
:
950 //DrawLine(hdc,P_90,P_270);
951 graphics
.DrawLine(&myPen
,P_90
,P_270
);
952 //p->drawLine(P_90, P_270);
956 //DrawLine(hdc,P_CENTER,P_270);
957 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
958 //p->drawLine(P_CENTER, P_270);
962 case Lanes::BOUNDARY
:
963 case Lanes::BOUNDARY_C
:
964 case Lanes::BOUNDARY_R
:
965 case Lanes::BOUNDARY_L
:
966 //DrawLine(hdc,P_90, P_CENTER);
967 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
968 //p->drawLine(P_90, P_CENTER);
974 myPen
.SetColor(GetGdiColor(activeColor
));
978 case Lanes::MERGE_FORK
:
983 case Lanes::CROSS_EMPTY
:
984 case Lanes::BOUNDARY_C
:
985 //DrawLine(hdc,P_180,P_0);
986 graphics
.DrawLine(&myPen
,P_180
,P_0
);
987 //p->drawLine(P_180, P_0);
989 case Lanes::MERGE_FORK_R
:
990 case Lanes::BOUNDARY_R
:
991 //DrawLine(hdc,P_180,P_CENTER);
992 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
993 //p->drawLine(P_180, P_CENTER);
995 case Lanes::MERGE_FORK_L
:
998 case Lanes::BOUNDARY_L
:
999 //DrawLine(hdc,P_CENTER,P_0);
1000 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
1001 //p->drawLine(P_CENTER, P_0);
1007 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1010 brush
.CreateSolidBrush(col
);
1011 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1013 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1014 // center symbol, e.g. rect or ellipse
1017 case Lanes::INITIAL
:
1020 //p->setPen(Qt::NoPen);
1022 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1023 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1024 //p->drawEllipse(R_CENTER);
1026 case Lanes::MERGE_FORK
:
1027 case Lanes::MERGE_FORK_R
:
1028 case Lanes::MERGE_FORK_L
:
1029 //p->setPen(Qt::NoPen);
1031 //p->drawRect(R_CENTER);
1032 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1033 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1035 case Lanes::UNAPPLIED
:
1037 //p->setPen(Qt::NoPen);
1038 //p->setBrush(Qt::red);
1039 //p->drawRect(m - r, h - 1, d, 2);
1040 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1041 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1043 case Lanes::APPLIED
:
1045 //p->setPen(Qt::NoPen);
1046 //p->setBrush(DARK_GREEN);
1047 //p->drawRect(m - r, h - 1, d, 2);
1048 //p->drawRect(m - 1, h - r, 2, d);
1049 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1050 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1051 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1053 case Lanes::BOUNDARY
:
1054 //p->setBrush(back);
1055 //p->drawEllipse(R_CENTER);
1056 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1057 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1059 case Lanes::BOUNDARY_C
:
1060 case Lanes::BOUNDARY_R
:
1061 case Lanes::BOUNDARY_L
:
1062 //p->setBrush(back);
1063 //p->drawRect(R_CENTER);
1064 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1065 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1071 ::SelectObject(hdc
,oldpen
);
1072 ::SelectObject(hdc
,oldbrush
);
1081 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1085 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
1086 if(data
->m_CommitHash
.IsEmpty())
1090 LVITEM rItem
= { 0 };
1091 rItem
.mask
= LVIF_STATE
;
1092 rItem
.iItem
= (int)index
;
1093 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1096 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1098 if (data
->m_Lanes
.empty())
1099 m_logEntries
.setLane(data
->m_CommitHash
);
1101 std::vector
<int>& lanes
=data
->m_Lanes
;
1102 size_t laneNum
= lanes
.size();
1103 UINT activeLane
= 0;
1104 for (UINT i
= 0; i
< laneNum
; ++i
)
1105 if (Lanes::isMerge(lanes
[i
])) {
1111 int maxWidth
= rect
.Width();
1112 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1114 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1115 //if (opt.state & QStyle::State_Selected)
1116 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1118 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1125 if (ln
== Lanes::EMPTY
)
1128 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1129 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1133 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1139 if (ln
== Lanes::EMPTY
)
1142 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1143 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1145 if (ln
== Lanes::CROSS
)
1147 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1148 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1151 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1157 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1160 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1161 // Take the default processing unless we set this to something else below.
1162 *pResult
= CDRF_DODEFAULT
;
1164 if (m_bNoDispUpdates
)
1167 switch (pLVCD
->nmcd
.dwDrawStage
)
1171 *pResult
= CDRF_NOTIFYITEMDRAW
;
1175 case CDDS_ITEMPREPAINT
:
1177 // This is the prepaint stage for an item. Here's where we set the
1178 // item's text color.
1180 // Tell Windows to send draw notifications for each subitem.
1181 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1183 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1185 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1187 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1190 HGDIOBJ hGdiObj
= nullptr;
1191 int action
= data
->GetRebaseAction();
1192 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1193 crText
= RGB(128,128,128);
1195 if (action
& LOGACTIONS_REBASE_SQUASH
)
1196 pLVCD
->clrTextBk
= RGB(156,156,156);
1197 else if (action
& LOGACTIONS_REBASE_EDIT
)
1198 pLVCD
->clrTextBk
= RGB(200,200,128);
1200 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1202 if (action
& LOGACTIONS_REBASE_CURRENT
)
1203 hGdiObj
= m_boldFont
;
1205 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1206 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1207 if (isHeadHash
&& isHighlight
)
1208 hGdiObj
= m_boldItalicsFont
;
1209 else if (isHeadHash
)
1210 hGdiObj
= m_boldFont
;
1211 else if (isHighlight
)
1212 hGdiObj
= m_FontItalics
;
1216 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1217 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1220 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1221 // crText = GetSysColor(COLOR_GRAYTEXT);
1223 if (data
->m_CommitHash
.IsEmpty())
1225 //crText = GetSysColor(RGB(200,200,0));
1226 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1227 // We changed the font, so we're returning CDRF_NEWFONT. This
1228 // tells the control to recalculate the extent of the text.
1229 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1233 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1235 if (m_bStrictStopped
)
1236 crText
= GetSysColor(COLOR_GRAYTEXT
);
1238 // Store the color back in the NMLVCUSTOMDRAW struct.
1239 pLVCD
->clrText
= crText
;
1243 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1245 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1247 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1250 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1252 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1255 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1257 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1258 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1260 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1261 if( !data
->m_CommitHash
.IsEmpty())
1262 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1264 *pResult
= CDRF_SKIPDEFAULT
;
1269 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1271 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1273 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1275 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1278 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1280 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1281 // not in FillBackGround method, because this only affected the message subitem
1282 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1285 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1286 int state
= GetItemState(index
, LVIS_SELECTED
);
1287 int txtState
= LISS_NORMAL
;
1288 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1290 if (state
& LVIS_SELECTED
)
1291 txtState
= LISS_HOTSELECTED
;
1293 txtState
= LISS_HOT
;
1295 else if (state
& LVIS_SELECTED
)
1297 if (::GetFocus() == m_hWnd
)
1298 txtState
= LISS_SELECTED
;
1300 txtState
= LISS_SELECTEDNOTFOCUS
;
1303 HTHEME hTheme
= nullptr;
1304 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1305 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1307 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1308 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1311 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1312 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1313 ::DeleteObject(brush
);
1318 // get rect of whole line
1319 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1321 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1322 rect2
.DeflateRect(1, 1, 1, 1);
1324 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1325 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1327 CloseThemeData(hTheme
);
1329 // END: extended redraw
1331 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1333 std::vector
<REFLABEL
> refsToShow
;
1334 STRING_VECTOR remoteTrackingList
;
1335 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1336 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1338 CString str
= refList
[i
];
1341 refLabel
.color
= RGB(255, 255, 255);
1342 refLabel
.singleRemote
= false;
1343 refLabel
.hasTracking
= false;
1344 refLabel
.sameName
= false;
1345 refLabel
.annotatedTag
= false;
1346 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1348 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1350 if (refLabel
.name
== m_CurrentBranch
)
1351 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1353 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1355 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1356 CString pullRemote
= trackingEntry
.first
;
1357 CString pullBranch
= trackingEntry
.second
;
1358 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1360 CString defaultUpstream
;
1361 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), (LPCTSTR
)pullRemote
, (LPCTSTR
)pullBranch
);
1362 refLabel
.hasTracking
= true;
1363 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1366 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1368 if (refList
[j
] == defaultUpstream
)
1377 bool sameName
= pullBranch
== refLabel
.name
;
1378 refsToShow
.push_back(refLabel
);
1379 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1380 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1381 if (m_bSymbolizeRefNames
)
1383 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1385 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1386 refLabel
.singleRemote
= true;
1389 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1390 refLabel
.sameName
= sameName
;
1392 refsToShow
.push_back(refLabel
);
1393 remoteTrackingList
.push_back(defaultUpstream
);
1399 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1401 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1405 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1407 if (remoteTrackingList
[j
] == str
)
1416 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1417 if (m_bSymbolizeRefNames
)
1419 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1421 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1422 refLabel
.singleRemote
= true;
1426 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1428 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1430 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1431 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1433 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1435 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1437 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1438 refLabel
.name
= _T("stash");
1440 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1442 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1444 if (refLabel
.name
.Find(_T("good")) == 0)
1446 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1447 refLabel
.name
= _T("good");
1449 if (refLabel
.name
.Find(_T("bad")) == 0)
1451 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1452 refLabel
.name
= _T("bad");
1458 refsToShow
.push_back(refLabel
);
1461 if (refsToShow
.empty())
1463 *pResult
= CDRF_DODEFAULT
;
1467 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1469 *pResult
= CDRF_SKIPDEFAULT
;
1477 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1479 if(this->m_IsIDReplaceAction
)
1481 *pResult
= CDRF_DODEFAULT
;
1484 *pResult
= CDRF_DODEFAULT
;
1486 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1490 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1491 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1493 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1495 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1496 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1497 // Get the selected state of the
1498 // item being drawn.
1500 // Fill the background if necessary
1501 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1503 // Draw the icon(s) into the compatible DC
1504 int action
= pLogEntry
->GetAction(this);
1505 if (!pLogEntry
->m_IsDiffFiles
)
1507 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1508 *pResult
= CDRF_SKIPDEFAULT
;
1512 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1513 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1516 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1517 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1520 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1521 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1524 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1525 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1528 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1529 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1532 *pResult
= CDRF_SKIPDEFAULT
;
1538 *pResult
= CDRF_DODEFAULT
;
1541 CString
FindSVNRev(const CString
& msg
)
1545 const std::tr1::wsregex_iterator end
;
1546 std::wstring s
= msg
;
1547 std::tr1::wregex
regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1548 for (std::tr1::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex1
); it
!= end
; ++it
)
1550 const std::tr1::wsmatch match
= *it
;
1551 if (match
.size() == 4)
1553 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1554 return std::wstring(match
[2]).c_str();
1557 std::tr1::wregex
regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1558 for (std::tr1::wsregex_iterator
it(s
.cbegin(), s
.cend(), regex2
); it
!= end
; ++it
)
1560 const std::tr1::wsmatch match
= *it
;
1561 if (match
.size() == 3)
1563 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1564 return std::wstring(match
[1]).c_str();
1568 catch (std::exception
) {}
1573 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1575 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1576 return pLogEntry
->GetSubject();
1578 CString
txt(pLogEntry
->GetSubject());
1580 txt
+= pLogEntry
->GetBody();
1583 txt
.Replace(_T('\n'), _T(' '));
1584 txt
.Replace(_T('\r'), _T(' '));
1589 // CGitLogListBase message handlers
1591 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1593 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1595 // Create a pointer to the item
1596 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1598 // Do the list need text information?
1599 if (!(pItem
->mask
& LVIF_TEXT
))
1602 // By default, clear text buffer.
1603 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
- 1);
1605 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1608 if (m_bNoDispUpdates
|| bOutOfRange
)
1611 // Which item number?
1612 int itemid
= pItem
->iItem
;
1613 GitRevLoglist
* pLogEntry
= nullptr;
1614 if (itemid
< m_arShownList
.GetCount())
1615 pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1620 temp
.Format(_T("%d"),pItem
->iItem
+1);
1625 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1629 switch (pItem
->iSubItem
)
1631 case LOGLIST_GRAPH
: //Graphic
1633 case LOGLIST_REBASE
:
1635 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1636 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1639 case LOGLIST_ACTION
: //action -- no text in the column
1643 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1646 if(this->m_IsIDReplaceAction
)
1647 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1649 case LOGLIST_MESSAGE
: //Message
1651 lstrcpyn(pItem
->pszText
, (LPCTSTR
)MessageDisplayStr(pLogEntry
), pItem
->cchTextMax
- 1);
1653 case LOGLIST_AUTHOR
: //Author
1655 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
- 1);
1657 case LOGLIST_DATE
: //Date
1658 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1659 lstrcpyn(pItem
->pszText
,
1660 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1661 pItem
->cchTextMax
- 1);
1666 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
- 1);
1669 case LOGLIST_COMMIT_NAME
: //Commit
1671 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
- 1);
1674 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1676 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
- 1);
1679 case LOGLIST_COMMIT_DATE
: //Commit Date
1680 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1681 lstrcpyn(pItem
->pszText
,
1682 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1683 pItem
->cchTextMax
- 1);
1685 case LOGLIST_BUG
: //Bug ID
1687 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubjectBody()), pItem
->cchTextMax
- 1);
1689 case LOGLIST_SVNREV
: //SVN revision
1691 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubjectBody()), pItem
->cchTextMax
- 1);
1699 bool CGitLogListBase::IsOnStash(int index
)
1701 GitRevLoglist
* rev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
));
1706 GitRevLoglist
* preRev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
- 1));
1707 if (IsStash(preRev
))
1708 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1713 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1715 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1717 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1723 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1725 if (pRev
->m_ParentHash
.empty())
1727 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1728 MessageBox(pRev
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1730 parentHash
= pRev
->m_ParentHash
;
1733 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1736 if (pWnd
== GetHeaderCtrl())
1738 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1741 int selIndex
= GetSelectionMark();
1743 return; // nothing selected, nothing to do with a context menu
1745 // if the user selected the info text telling about not all revisions shown due to
1746 // the "stop on copy/rename" option, we also don't show the context menu
1747 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1750 // if the context menu is invoked through the keyboard, we have to use
1751 // a calculated position on where to anchor the menu on
1752 if ((point
.x
== -1) && (point
.y
== -1))
1755 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1756 ClientToScreen(&rect
);
1757 point
= rect
.CenterPoint();
1759 m_nSearchIndex
= selIndex
;
1760 m_bCancelled
= FALSE
;
1762 // calculate some information the context menu commands can use
1763 // CString pathURL = GetURLFromPath(m_path);
1765 POSITION pos
= GetFirstSelectedItemPosition();
1766 int indexNext
= GetNextSelectedItem(pos
);
1770 GitRevLoglist
* pSelLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(indexNext
));
1771 if (pSelLogEntry
== nullptr)
1774 GitRev revSelected
= pSelLogEntry
->Rev
;
1775 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1776 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1778 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1780 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1781 if (changedpath
->lCopyFromRev
)
1782 revPrevious
= changedpath
->lCopyFromRev
;
1785 GitRev revSelected2
;
1788 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1789 revSelected2
= pLogEntry
->Rev
;
1791 bool bAllFromTheSameAuthor
= true;
1792 CString firstAuthor
;
1793 CLogDataVector selEntries
;
1794 GitRev revLowest
, revHighest
;
1795 GitRevRangeArray revisionRanges
;
1797 POSITION pos
= GetFirstSelectedItemPosition();
1798 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1799 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1800 selEntries
.push_back(pLogEntry
);
1801 firstAuthor
= pLogEntry
->sAuthor
;
1802 revLowest
= pLogEntry
->Rev
;
1803 revHighest
= pLogEntry
->Rev
;
1806 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1807 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1808 selEntries
.push_back(pLogEntry
);
1809 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1810 bAllFromTheSameAuthor
= false;
1811 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1812 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1818 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1820 int FirstSelect
=-1, LastSelect
=-1;
1821 pos
= GetFirstSelectedItemPosition();
1822 FirstSelect
= GetNextSelectedItem(pos
);
1825 LastSelect
= GetNextSelectedItem(pos
);
1827 //entry is selected, now show the popup menu
1829 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1831 if (popup
.CreatePopupMenu())
1833 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1834 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1835 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1836 bool isStash
= IsOnStash(indexNext
);
1837 GIT_REV_LIST parentHash
;
1838 GetParentHashes(pSelLogEntry
, parentHash
);
1840 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1841 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1843 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1)
1844 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1846 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1847 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1849 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1850 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1852 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
)))
1853 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1855 if (GetSelectedCount() == 1)
1858 bool requiresSeparator
= false;
1859 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1861 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1863 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1864 requiresSeparator
= true;
1869 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1871 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1872 requiresSeparator
= true;
1874 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1876 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1877 requiresSeparator
= true;
1881 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1883 if (parentHash
.size() == 1)
1885 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1886 requiresSeparator
= true;
1888 else if (parentHash
.size() > 1)
1890 blamemenu
.CreatePopupMenu();
1891 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1892 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1895 str
.Format(IDS_PARENT
, i
+ 1);
1896 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1898 requiresSeparator
= true;
1902 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1904 if (parentHash
.size() == 1)
1906 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1907 requiresSeparator
= true;
1909 else if (parentHash
.size() > 1)
1911 gnudiffmenu
.CreatePopupMenu();
1912 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1914 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1915 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1916 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1918 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1921 str
.Format(IDS_PARENT
, i
+ 1);
1922 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1924 requiresSeparator
= true;
1928 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1930 if (parentHash
.size() == 1)
1932 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1933 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1934 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1935 requiresSeparator
= true;
1937 else if (parentHash
.size() > 1)
1939 diffmenu
.CreatePopupMenu();
1940 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1941 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1944 str
.Format(IDS_PARENT
, i
+ 1);
1945 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1946 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1948 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1949 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1952 requiresSeparator
= true;
1956 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1958 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1959 requiresSeparator
= true;
1962 if (requiresSeparator
)
1964 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1965 requiresSeparator
= false;
1968 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1970 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1972 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1973 requiresSeparator
= true;
1977 if ((pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
) && CTGitPath(g_Git
.m_CurrentDir
).HasStashDir())
1979 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1981 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1982 requiresSeparator
= true;
1985 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1987 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1988 requiresSeparator
= true;
1992 if (requiresSeparator
)
1994 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1995 requiresSeparator
= false;
1998 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
2000 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
2001 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2003 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
2004 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
2006 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
2007 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
2009 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2011 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
2012 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
2014 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2018 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2020 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2022 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2024 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2026 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2027 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2029 // popup.AppendMenu(MF_SEPARATOR, NULL);
2034 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2036 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2038 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2039 GetSelectedCount() == 1)
2040 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2042 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2043 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2045 str
.Format(IDS_LOG_POPUP_MERGEREV
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2047 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2048 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2050 str
.Format(IDS_RESET_TO_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2052 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2053 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2056 // Add Switch Branch express Menu
2057 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2058 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2061 std::vector
<CString
*> branchs
;
2062 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2064 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2065 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2067 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2072 str2
.LoadString(IDS_SWITCH_BRANCH
);
2074 if(branchs
.size() == 1)
2077 str2
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2078 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2080 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2083 else if(branchs
.size() > 1)
2085 subbranchmenu
.CreatePopupMenu();
2086 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2088 if (*branchs
[i
] != currentBranch
)
2090 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2091 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2095 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2099 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2100 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2102 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2103 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2105 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2106 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2108 str
.Format(IDS_REBASE_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2110 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2111 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2112 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2114 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2115 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2117 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2119 if (parentHash
.size() == 1)
2121 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2123 else if (parentHash
.size() > 1)
2125 revertmenu
.CreatePopupMenu();
2126 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2128 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2131 str2
.Format(IDS_PARENT
, i
+ 1);
2132 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2137 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2138 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2140 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2145 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2147 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2148 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2149 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2150 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2153 if (GetSelectedCount() >= 2)
2155 bool bAddSeparator
= false;
2156 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2158 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2159 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2162 if (GetSelectedCount() == 2)
2164 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2165 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2167 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2169 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2170 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2171 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2173 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("..") + firstSelHash
));
2174 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2175 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("...") + firstSelHash
));
2176 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2179 bAddSeparator
= true;
2184 bAddSeparator
= true;
2187 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2188 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2191 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2194 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2196 bool bAddSeparator
= false;
2197 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2199 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2203 headindex
= this->GetHeadIndex();
2204 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2206 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2208 if (g_Git
.GetHash(hashFirst
, head
))
2209 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2210 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2212 if (g_Git
.GetHash(hash
, head
))
2213 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2214 GitRevLoglist
* pFirstEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2215 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2216 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2217 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2218 bAddSeparator
= true;
2223 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2224 if (GetSelectedCount() >= 2)
2225 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2227 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2228 bAddSeparator
= true;
2231 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2232 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2233 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2234 bAddSeparator
= true;
2238 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2241 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
2243 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2244 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2247 if (GetSelectedCount() == 1)
2249 bool bAddSeparator
= false;
2250 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2252 // show the push-option only if the log entry has an associated local branch
2253 bool isLocal
= false;
2254 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2256 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2259 if (isLocal
|| showExtendedMenu
)
2261 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2262 bAddSeparator
= true;
2265 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2267 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2268 bAddSeparator
= true;
2272 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2274 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2276 std::vector
<CString
*> branchs
;
2277 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2279 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2280 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2283 if (branchs
.size() == 1)
2285 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2288 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2289 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2290 bAddSeparator
= true;
2292 else if (branchs
.size() > 1)
2294 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2295 submenu
.CreatePopupMenu();
2296 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2298 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2299 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2302 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2303 bAddSeparator
= true;
2306 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2308 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2309 } // GetSelectedCount() == 1
2311 if (GetSelectedCount() != 0)
2313 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2314 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2315 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2316 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2317 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2318 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2321 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2322 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2324 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2325 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2327 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2328 // DialogEnableWindow(IDOK, FALSE);
2329 // SetPromptApp(&theApp);
2331 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2333 // EnableOKButton();
2334 } // if (popup.CreatePopupMenu())
2338 bool CGitLogListBase::IsSelectionContinuous()
2340 if ( GetSelectedCount()==1 )
2342 // if only one revision is selected, the selection is of course
2347 POSITION pos
= GetFirstSelectedItemPosition();
2348 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2351 int itemindex
= GetNextSelectedItem(pos
);
2354 int nextindex
= GetNextSelectedItem(pos
);
2355 if (nextindex
- itemindex
> 1)
2357 bContinuous
= false;
2360 itemindex
= nextindex
;
2366 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2370 POSITION pos
= GetFirstSelectedItemPosition();
2374 sRev
.LoadString(IDS_LOG_REVISION
);
2376 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2378 sDate
.LoadString(IDS_LOG_DATE
);
2380 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2384 CString sLogCopyText
;
2386 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2388 if (toCopy
== ID_COPY_ALL
)
2390 //pLogEntry->GetFiles(this)
2391 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2393 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2394 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2396 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2397 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2400 rename
.Format(from
, (LPCTSTR
)((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2404 sPaths
+= _T("\r\n");
2407 CString body
= pLogEntry
->GetBody();
2408 body
.Replace(_T("\n"), _T("\r\n"));
2409 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"),
2410 (LPCTSTR
)sRev
, (LPCTSTR
)pLogEntry
->m_CommitHash
.ToString(),
2411 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2413 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2414 (LPCTSTR
)sMessage
, (LPCTSTR
)pLogEntry
->GetSubjectBody(true),
2416 sClipdata
+= sLogCopyText
;
2418 else if (toCopy
== ID_COPY_MESSAGE
)
2420 sClipdata
+= _T("* ");
2421 sClipdata
+= pLogEntry
->GetSubjectBody(true);
2422 sClipdata
+= _T("\r\n\r\n");
2424 else if (toCopy
== ID_COPY_SUBJECT
)
2426 sClipdata
+= _T("* ");
2427 sClipdata
+= pLogEntry
->GetSubject().Trim();
2428 sClipdata
+= _T("\r\n\r\n");
2433 sClipdata
+= _T("\r\n");
2434 sClipdata
+= pLogEntry
->m_CommitHash
;
2439 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2444 void CGitLogListBase::DiffSelectedRevWithPrevious()
2446 if (m_bThreadRunning
)
2449 int FirstSelect
=-1, LastSelect
=-1;
2450 POSITION pos
= GetFirstSelectedItemPosition();
2451 FirstSelect
= GetNextSelectedItem(pos
);
2454 LastSelect
= GetNextSelectedItem(pos
);
2457 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2460 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2462 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2465 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2467 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2469 if (pFindInfo
->lvfi
.psz
== 0)
2472 CString sCmp
= pFindInfo
->lvfi
.psz
;
2474 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2476 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2477 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2478 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2480 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2488 if (sCmp
.Compare(sRev
)==0)
2495 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2497 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2499 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2500 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2501 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2503 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2511 if (sCmp
.Compare(sRev
)==0)
2523 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2527 this->m_arShownList
.SafeRemoveAll();
2529 this->m_logEntries
.ClearAll();
2530 if (this->m_logEntries
.ParserFromLog(path
, 0, info
, range
))
2533 SetItemCountEx((int)m_logEntries
.size());
2535 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2539 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2540 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2545 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2546 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2558 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2562 m_arShownList
.SafeRemoveAll();
2564 m_logEntries
.ClearAll();
2565 if (m_logEntries
.Fill(hashes
))
2568 SetItemCountEx((int)m_logEntries
.size());
2570 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2574 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2575 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2579 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2580 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2589 int CGitLogListBase::BeginFetchLog()
2593 this->m_arShownList
.SafeRemoveAll();
2595 this->m_logEntries
.ClearAll();
2597 this->m_LogCache
.ClearAllParent();
2599 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2602 if(this->m_Path
.IsEmpty())
2608 mask
= CGit::LOG_INFO_ONLY_HASH
;
2609 if (m_bIncludeBoundaryCommits
)
2610 mask
|= CGit::LOG_INFO_BOUNDARY
;
2611 // if(this->m_bAllBranch)
2612 mask
|= m_ShowMask
;
2616 this->m_logEntries
.insert(m_logEntries
.cbegin(), m_wcRev
.m_CommitHash
);
2618 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2621 if (m_sRange
.IsEmpty())
2622 m_sRange
= _T("HEAD");
2624 #if 0 /* use tortoiegit filter */
2625 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2626 data
.m_Author
= this->m_sFilterText
;
2628 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2629 data
.m_MessageFilter
= this->m_sFilterText
;
2631 data
.m_IsRegex
= m_bFilterWithRegex
;
2634 // follow does not work for directories
2635 if (!path
|| path
->IsDirectory())
2636 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2637 // follow does not work with all branches 8at least in TGit)
2638 if (mask
& CGit::LOG_INFO_FOLLOW
)
2639 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2641 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, mask
, &m_Filter
);
2643 //this->m_logEntries.ParserFromLog();
2644 if(IsInWorkingThread())
2646 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2650 SetItemCountEx((int)m_logEntries
.size());
2655 [] { git_init(); } ();
2660 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2664 if (!g_Git
.CanParseRev(m_sRange
))
2666 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2669 // if show all branches, pick any ref as dummy entry ref
2671 if (g_Git
.GetRefList(list
))
2672 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2673 if (list
.size() == 0)
2676 cmd
= g_Git
.GetLogCmd(list
[0], path
, mask
, &m_Filter
);
2679 g_Git
.m_critGitDllSec
.Lock();
2681 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2683 g_Git
.m_critGitDllSec
.Unlock();
2689 g_Git
.m_critGitDllSec
.Unlock();
2691 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2694 g_Git
.m_critGitDllSec
.Unlock();
2699 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2701 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2703 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2705 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2707 DiffSelectedRevWithPrevious();
2712 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2719 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2721 // select all entries
2722 for (int i
=0; i
<GetItemCount(); ++i
)
2724 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2730 if (m_hAccel
&& !bSkipAccelerator
)
2732 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2738 //m_tooltips.RelayEvent(pMsg);
2739 return __super::PreTranslateMessage(pMsg
);
2742 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2744 // a double click on an entry in the revision list has happened
2747 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2748 DiffSelectedRevWithPrevious();
2751 int CGitLogListBase::FetchLogAsync(void * data
)
2755 m_bExitThread
=FALSE
;
2756 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2757 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2758 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2759 if (m_LoadingThread
==NULL
)
2761 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2762 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2763 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2769 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2771 return ((CGitLogListBase
*)pVoid
)->LogThread();
2774 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2777 oldest
=CTime::GetCurrentTime();
2778 latest
=CTime(1971,1,2,0,0,0);
2779 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2781 if(m_logEntries
[i
].IsEmpty())
2784 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() < oldest
.GetTime())
2785 oldest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2787 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() > latest
.GetTime())
2788 latest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2796 UINT
CGitLogListBase::LogThread()
2798 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2800 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2801 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2807 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2808 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2813 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2814 bool bRegex
= false;
2815 if (m_bFilterWithRegex
)
2816 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2818 TRACE(_T("\n===Begin===\n"));
2819 //Update work copy item;
2821 if (!m_logEntries
.empty())
2823 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2825 m_arShownList
.SafeAdd(pRev
);
2829 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2831 // store commit number of the last selected commit/line before the refresh or -1
2832 int lastSelectedHashNItem
= -1;
2833 if (m_lastSelectedHash
.IsEmpty())
2834 lastSelectedHashNItem
= 0;
2838 bool shouldWalk
= true;
2839 if (!g_Git
.CanParseRev(m_sRange
))
2841 // walk revisions if show all branches and there exists any ref
2842 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2847 if (g_Git
.GetRefList(list
))
2848 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2849 if (list
.size() == 0)
2856 g_Git
.m_critGitDllSec
.Lock();
2860 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2861 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2866 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2869 g_Git
.m_critGitDllSec
.Unlock();
2872 t2
=t1
=GetTickCount();
2873 int oldprecentage
= 0;
2874 size_t oldsize
= m_logEntries
.size();
2875 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2876 while (ret
== 0 && !m_bExitThread
)
2878 g_Git
.m_critGitDllSec
.Lock();
2881 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2885 g_Git
.m_critGitDllSec
.Unlock();
2887 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2890 g_Git
.m_critGitDllSec
.Unlock();
2894 if (ret
!= -2) // other than end of revision walking
2895 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2899 if (commit
.m_ignore
== 1)
2901 git_free_commit(&commit
);
2905 //printf("%s\r\n",commit.GetSubject());
2909 CGitHash hash
= (char*)commit
.m_hash
;
2911 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2912 pRev
->m_GitCommit
= commit
;
2913 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2916 g_Git
.m_critGitDllSec
.Lock();
2919 git_get_notes(commit
.m_hash
, ¬e
);
2923 g_Git
.m_critGitDllSec
.Unlock();
2925 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2928 g_Git
.m_critGitDllSec
.Unlock();
2932 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2937 if(!pRev
->m_IsDiffFiles
)
2939 pRev
->m_CallDiffAsync
= DiffAsync
;
2942 pRev
->ParserParentFromCommit(&commit
);
2943 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2945 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2947 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2948 auto it
= commitChildren
.find(parentHash
);
2949 if (it
== commitChildren
.end())
2951 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2953 it
->second
.insert(pRev
->m_CommitHash
);
2962 bool visible
= true;
2963 if (HasFilterText())
2965 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2968 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
2970 this->m_critSec
.Lock();
2971 m_logEntries
.append(hash
, visible
);
2973 m_arShownList
.SafeAdd(pRev
);
2974 this->m_critSec
.Unlock();
2979 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2980 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2984 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2987 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2990 if(percent
< GITLOG_START
)
2991 percent
= GITLOG_START
+1;
2993 oldsize
= m_logEntries
.size();
2994 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2996 //if( percent > oldprecentage )
2998 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2999 oldprecentage
= percent
;
3002 if (lastSelectedHashNItem
>= 0)
3003 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3008 g_Git
.m_critGitDllSec
.Lock();
3009 git_close_log(m_DllGitLog
);
3010 g_Git
.m_critGitDllSec
.Unlock();
3016 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3021 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3023 if (lastSelectedHashNItem
>= 0)
3024 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3027 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3029 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3034 void CGitLogListBase::FetchRemoteList()
3036 STRING_VECTOR remoteList
;
3037 m_SingleRemote
.Empty();
3038 if (!g_Git
.GetRemoteList(remoteList
) && remoteList
.size() == 1)
3039 m_SingleRemote
= remoteList
[0];
3042 void CGitLogListBase::FetchTrackingBranchList()
3044 m_TrackingMap
.clear();
3045 for (auto it
= m_HashMap
.cbegin(); it
!= m_HashMap
.cend(); ++it
)
3047 for (const auto& ref
: it
->second
)
3050 if (CGit::GetShortName(ref
, branchName
, _T("refs/heads/")))
3052 CString pullRemote
, pullBranch
;
3053 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3054 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3056 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3063 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3065 SafeTerminateThread();
3067 this->SetItemCountEx(0);
3072 // HACK to hide graph column
3073 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3074 SetColumnWidth(0, 0);
3076 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3078 //Update branch and Tag info
3081 m_pFindDialog
->RefreshList();
3082 //Assume Thread have exited
3083 //if(!m_bThreadRunning)
3085 m_logEntries
.clear();
3089 m_sFilterText
.Empty();
3092 InterlockedExchange(&m_bExitThread
,FALSE
);
3094 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3095 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3097 SafeTerminateAsyncDiffThread();
3098 m_AsynDiffListLock
.Lock();
3099 m_AsynDiffList
.clear();
3100 m_AsynDiffListLock
.Unlock();
3101 InterlockedExchange(&m_AsyncThreadExit
, FALSE
);
3102 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
, 0, CREATE_SUSPENDED
);
3103 if (!m_DiffingThread
)
3104 CMessageBox::Show(nullptr, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3107 m_DiffingThread
->m_bAutoDelete
= FALSE
;
3108 m_DiffingThread
->ResumeThread();
3110 if ((m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
)) == nullptr)
3112 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3113 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3114 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3118 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3122 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3124 type
|= std::tr1::regex_constants::icase
;
3125 pat
= std::tr1::wregex(regexp_str
, type
);
3128 catch (std::exception
) {}
3131 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3134 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3137 if ((bRegex
)&&(m_bFilterWithRegex
))
3139 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3141 if(this->m_bShowBugtraqColumn
)
3143 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubjectBody());
3145 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)sBugIds
);
3146 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3153 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3155 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetSubject());
3156 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3162 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3164 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetBody());
3165 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3171 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3173 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3178 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3184 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3186 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3191 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3197 if (m_SelectedFilters
& LOGFILTER_REVS
)
3199 sRev
= pRev
->m_CommitHash
.ToString();
3200 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3206 if (m_SelectedFilters
& LOGFILTER_NOTES
)
3208 if (std::regex_search(std::wstring(pRev
->m_Notes
), pat
, flags
))
3214 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3216 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3217 for (const auto& ref
: refs
)
3219 if (std::regex_search(std::wstring(ref
), pat
, flags
))
3226 if (m_SelectedFilters
& LOGFILTER_ANNOTATEDTAG
)
3228 if (std::regex_search(std::wstring(GetTagInfo(pRev
)), pat
, flags
))
3234 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3236 CTGitPathList
*pathList
=NULL
;
3237 if( pRev
->m_IsDiffFiles
)
3238 pathList
= &pRev
->GetFiles(this);
3241 if(!pRev
->m_IsSimpleListReady
)
3242 pRev
->SafeGetSimpleList(&g_Git
);
3246 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3248 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3252 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3258 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3260 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3269 CString find
= m_sFilterText
;
3270 if (!m_bFilterCaseSensitively
)
3272 result
= find
[0] == '!' ? FALSE
: TRUE
;
3276 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3278 if(this->m_bShowBugtraqColumn
)
3280 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubjectBody());
3282 if (!m_bFilterCaseSensitively
)
3283 sBugIds
.MakeLower();
3284 if ((sBugIds
.Find(find
) >= 0))
3291 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3293 CString msg
= pRev
->GetSubject();
3295 if (!m_bFilterCaseSensitively
)
3296 msg
= msg
.MakeLower();
3297 if ((msg
.Find(find
) >= 0))
3303 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3305 CString msg
= pRev
->GetBody();
3307 if (!m_bFilterCaseSensitively
)
3308 msg
= msg
.MakeLower();
3309 if ((msg
.Find(find
) >= 0))
3315 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3317 CString msg
= pRev
->GetAuthorName();
3318 if (!m_bFilterCaseSensitively
)
3319 msg
= msg
.MakeLower();
3320 if ((msg
.Find(find
) >= 0))
3326 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3328 CString msg
= pRev
->GetAuthorEmail();
3329 if (!m_bFilterCaseSensitively
)
3330 msg
= msg
.MakeLower();
3331 if ((msg
.Find(find
) >= 0))
3337 if (m_SelectedFilters
& LOGFILTER_NOTES
)
3339 CString msg
= pRev
->m_Notes
;
3340 if (!m_bFilterCaseSensitively
)
3341 msg
= msg
.MakeLower();
3342 if ((msg
.Find(find
) >= 0))
3348 if (m_SelectedFilters
& LOGFILTER_REVS
)
3350 sRev
= pRev
->m_CommitHash
.ToString();
3351 if ((sRev
.Find(find
) >= 0))
3357 if (m_SelectedFilters
& LOGFILTER_ANNOTATEDTAG
)
3359 CString msg
= GetTagInfo(pRev
);
3360 if (!m_bFilterCaseSensitively
)
3361 msg
= msg
.MakeLower();
3362 if ((msg
.Find(find
) >= 0))
3368 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3370 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3371 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3373 if (it
->Find(find
) >= 0)
3380 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3382 CTGitPathList
*pathList
=NULL
;
3383 if( pRev
->m_IsDiffFiles
)
3384 pathList
= &pRev
->GetFiles(this);
3387 if(!pRev
->m_IsSimpleListReady
)
3388 pRev
->SafeGetSimpleList(&g_Git
);
3391 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3393 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3394 CString path
= cpath
->GetGitOldPathString();
3395 if (!m_bFilterCaseSensitively
)
3397 if ((path
.Find(find
)>=0))
3401 path
= cpath
->GetGitPathString();
3402 if (!m_bFilterCaseSensitively
)
3404 if ((path
.Find(find
)>=0))
3410 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3412 CString path
= pRev
->m_SimpleFileList
[i
];
3413 if (!m_bFilterCaseSensitively
)
3415 if ((path
.Find(find
)>=0))
3421 } // else (from if (bRegex))
3425 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3427 return str
.Left(prefix
.GetLength()) == prefix
;
3429 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
)
3431 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3434 if (m_ShowFilter
& FILTERSHOW_REFS
)
3437 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3438 for (size_t i
= 0; i
< refList
.size(); ++i
)
3440 const CString
&str
= refList
[i
];
3441 if (CStringStartsWith(str
, _T("refs/heads/")))
3443 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3446 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3448 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3451 else if (CStringStartsWith(str
, _T("refs/tags/")))
3453 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3456 else if (CStringStartsWith(str
, _T("refs/stash")))
3458 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3461 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3463 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3467 // Keep the head too.
3468 if (pRev
->m_CommitHash
== m_HeadHash
)
3472 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3474 if (pRev
->ParentsCount() > 1)
3476 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3477 if (childrenIt
!= commitChildren
.end())
3479 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3480 if (children
.size() > 1)
3487 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3489 // HACK to hide graph column
3491 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3493 SetColumnWidth(0, 0);
3496 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3501 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3503 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3504 for (size_t i
= 0; i
< vector
.size(); ++i
)
3506 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3508 CString tag
= vector
[i
];
3509 int start
= vector
[i
].Find(_T("^{}"));
3511 tag
= tag
.Left(start
);
3515 cmd
.Format(_T("git.exe cat-file tag %s"), (LPCTSTR
)tag
);
3516 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3517 output
.AppendChar(_T('\n'));
3525 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3528 pShownlist
->SafeRemoveAll();
3530 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3531 bool bRegex
= false;
3532 if (m_bFilterWithRegex
)
3533 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3535 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3537 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3539 if ((bRegex
)&&(m_bFilterWithRegex
))
3542 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3544 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3545 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3547 pShownlist
->SafeAdd(m_logEntries
[i
]);
3552 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3554 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3555 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3557 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3561 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3563 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3564 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3566 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3570 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3572 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3575 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3577 CTGitPath cpath
= pathList
[cpPathIndex
];
3578 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3580 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3584 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3586 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3590 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3592 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3598 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3600 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3602 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3606 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3608 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3610 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3614 if (m_SelectedFilters
& LOGFILTER_REVS
)
3616 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3617 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3619 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3623 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3625 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3626 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3628 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3630 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3638 CString find
= m_sFilterText
;
3639 if (!m_bFilterCaseSensitively
)
3642 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3644 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3646 if (!m_bFilterCaseSensitively
)
3647 sBugIDs
= sBugIDs
.MakeLower();
3648 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3650 pShownlist
->SafeAdd(m_logEntries
[i
]);
3655 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3657 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3659 if (!m_bFilterCaseSensitively
)
3660 msg
= msg
.MakeLower();
3661 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3663 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3667 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3669 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3671 if (!m_bFilterCaseSensitively
)
3672 msg
= msg
.MakeLower();
3673 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3675 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3679 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3681 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3684 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3686 CTGitPath cpath
= pathList
[cpPathIndex
];
3687 CString path
= cpath
.GetGitOldPathString();
3688 if (!m_bFilterCaseSensitively
)
3690 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3692 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3696 path
= cpath
.GetGitPathString();
3697 if (!m_bFilterCaseSensitively
)
3699 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3701 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3705 path
= cpath
.GetActionName();
3706 if (!m_bFilterCaseSensitively
)
3708 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3710 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3716 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3718 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3719 if (!m_bFilterCaseSensitively
)
3720 msg
= msg
.MakeLower();
3721 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3723 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3727 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3729 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3730 if (!m_bFilterCaseSensitively
)
3731 msg
= msg
.MakeLower();
3732 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3734 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3738 if (m_SelectedFilters
& LOGFILTER_REVS
)
3740 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3741 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3743 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3747 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3749 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3750 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3752 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3754 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3759 } // else (from if (bRegex))
3760 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3764 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3767 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3773 return time <= m_To;
3776 return time >= m_From;
3778 return ((time >= m_From)&&(time <= m_To));
3780 return TRUE
; /* git dll will filter time range */
3784 void CGitLogListBase::StartFilter()
3786 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3787 RecalculateShownList(&m_arShownList
);
3788 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3792 SetItemCountEx(ShownCountWithStopped());
3793 RedrawItems(0, ShownCountWithStopped());
3797 void CGitLogListBase::RemoveFilter()
3800 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3802 m_arShownList
.SafeRemoveAll();
3804 // reset the time filter too
3806 m_timFrom
= (__time64_t(m_tFrom
));
3807 m_timTo
= (__time64_t(m_tTo
));
3808 m_DateFrom
.SetTime(&m_timFrom
);
3809 m_DateTo
.SetTime(&m_timTo
);
3810 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3811 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3814 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3816 if(this->m_IsOldFirst
)
3818 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3822 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3825 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3827 SetItemCountEx(ShownCountWithStopped());
3828 RedrawItems(0, ShownCountWithStopped());
3830 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3833 void CGitLogListBase::Clear()
3835 m_arShownList
.SafeRemoveAll();
3838 m_logEntries
.ClearAll();
3842 void CGitLogListBase::OnDestroy()
3844 // save the column widths to the registry
3847 SafeTerminateThread();
3848 SafeTerminateAsyncDiffThread();
3851 while(m_LogCache
.SaveCache())
3859 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3860 // MB_YESNO) == IDNO)
3864 CHintListCtrl::OnDestroy();
3867 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3871 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3872 this->InvalidateRect(rect
);
3878 * Save column widths to the registry
3880 void CGitLogListBase::SaveColumnWidths()
3882 int maxcol
= m_ColumnManager
.GetColumnCount();
3884 // HACK that graph column is always shown
3885 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3887 for (int col
= 0; col
< maxcol
; ++col
)
3888 if (m_ColumnManager
.IsVisible (col
))
3889 m_ColumnManager
.ColumnResized (col
);
3891 m_ColumnManager
.WriteSettings();
3894 int CGitLogListBase::GetHeadIndex()
3896 if(m_HeadHash
.IsEmpty())
3899 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3901 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3904 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3910 void CGitLogListBase::OnFind()
3914 m_pFindDialog
= new CFindDlg(this);
3915 m_pFindDialog
->Create(this);
3918 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3920 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3922 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3924 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3927 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3929 if (GetSelectedCount() != 0)
3932 CGitHash theSelectedHash
= m_lastSelectedHash
;
3933 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3934 m_lastSelectedHash
= theSelectedHash
;
3936 int countPerPage
= GetCountPerPage();
3937 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3938 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3939 EnsureVisible((int)itemToSelect
, FALSE
);
3942 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3945 ASSERT(m_pFindDialog
!= NULL
);
3946 bool bFound
= false;
3949 if (m_pFindDialog
->IsTerminating())
3951 // invalidate the handle identifying the dialog box.
3952 m_pFindDialog
= NULL
;
3956 INT_PTR cnt
= m_arShownList
.GetCount();
3958 if(m_pFindDialog
->IsRef())
3961 str
=m_pFindDialog
->GetFindString();
3967 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3968 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3973 for (i
= 0; i
< cnt
; ++i
)
3975 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3976 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3985 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3990 if (m_pFindDialog
->FindNext() && !bFound
)
3992 //read data from dialog
3993 CString findText
= m_pFindDialog
->GetFindString();
3994 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3996 std::tr1::wregex pat
;
3997 bool bRegex
= false;
3998 if (m_pFindDialog
->Regex())
3999 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
4001 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
4003 for (i
= m_nSearchIndex
+ 1; ; ++i
)
4008 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
4010 if (m_nSearchIndex
>= 0)
4012 if (i
== m_nSearchIndex
)
4014 ::MessageBeep(0xFFFFFFFF);
4015 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4020 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
4023 str
+=pLogEntry
->m_CommitHash
.ToString();
4026 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4028 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4032 str
+=pLogEntry
->GetAuthorEmail();
4034 str
+=pLogEntry
->GetAuthorName();
4036 str
+=pLogEntry
->GetBody();
4038 str
+=pLogEntry
->GetCommitterEmail();
4040 str
+=pLogEntry
->GetCommitterName();
4042 str
+=pLogEntry
->GetSubject();
4044 str
+=pLogEntry
->m_Notes
;
4046 str
+=GetTagInfo(pLogEntry
);
4050 /*Because changed files list is loaded on demand when gui show,
4051 files will empty when files have not fetched.
4053 we can add it back by using one-way diff(with outnumber changed and rename detect.
4054 here just need changed filename list. one-way is much quicker.
4056 if(pLogEntry
->m_IsFull
)
4058 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4060 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4062 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4068 if(!pLogEntry
->m_IsSimpleListReady
)
4069 pLogEntry
->SafeGetSimpleList(&g_Git
);
4071 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4073 str
+= pLogEntry
->m_SimpleFileList
[j
];
4082 if (std::regex_search(std::wstring(str
), pat
, flags
))
4092 if (str
.Find(findText
) >= 0)
4102 msg
= msg
.MakeLower();
4103 CString find
= findText
.MakeLower();
4104 if (msg
.Find(find
) >= 0)
4111 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4113 } // if(m_pFindDialog->FindNext())
4114 //UpdateLogInfoLabel();
4119 EnsureVisible(i
, FALSE
);
4120 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4122 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4123 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4124 SetSelectionMark(i
);
4128 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4130 m_highlight
= pLogEntry
->m_CommitHash
;
4133 //FillLogMessageCtrl();
4140 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4142 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4147 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4149 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4154 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4156 LVHITTESTINFO lvhitTestInfo
;
4158 lvhitTestInfo
.pt
= point
;
4160 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4161 int nSubItem
= lvhitTestInfo
.iSubItem
;
4163 UINT nFlags
= lvhitTestInfo
.flags
;
4165 // nFlags is 0 if the SubItemHitTest fails
4166 // Therefore, 0 & <anything> will equal false
4167 if (nFlags
& LVHT_ONITEM
)
4169 // Get the client area occupied by this control
4171 GetClientRect(&rcClient
);
4173 // Fill in the TOOLINFO structure
4175 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4176 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4177 pTI
->rect
= rcClient
;
4179 return pTI
->uId
; // By returning a unique value per listItem,
4180 // we ensure that when the mouse moves over another list item,
4181 // the tooltip will change
4185 // Otherwise, we aren't interested, so let the message propagate
4190 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4192 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4193 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4197 // Ignore messages from the built in tooltip, we are processing them internally
4198 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4199 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4200 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4203 // Get the mouse position
4204 const MSG
* pMessage
= GetCurrentMessage();
4208 ScreenToClient(&pt
);
4210 // Check if the point falls onto a list item
4211 LVHITTESTINFO lvhitTestInfo
;
4212 lvhitTestInfo
.pt
= pt
;
4214 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4216 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4218 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4219 if (strTipText
.IsEmpty())
4222 // we want multiline tooltips
4223 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4225 wcscpy_s(m_wszTip
, strTipText
);
4226 // handle Unicode as well as non-Unicode requests
4227 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4229 pTTTA
->hinst
= nullptr;
4230 pTTTA
->lpszText
= m_szTip
;
4231 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4235 pTTTW
->hinst
= nullptr;
4236 pTTTW
->lpszText
= m_wszTip
;
4240 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4241 ClientToScreen(rect
);
4242 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4244 return TRUE
; // We found a tool tip,
4245 // tell the framework this message has been handled
4248 return FALSE
; // We didn't handle the message,
4249 // let the framework continue propagating the message
4252 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4254 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4256 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4257 if (pLogEntry
== nullptr)
4259 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4261 return pLogEntry
->GetSubject();
4263 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4265 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4266 if (pLogEntry
== nullptr)
4268 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4270 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4272 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4273 if (pLogEntry
== nullptr)
4275 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4277 else if (nSubItem
== LOGLIST_ACTION
)
4279 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4280 if (pLogEntry
== nullptr)
4283 if (!pLogEntry
->m_IsDiffFiles
)
4284 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4286 int actions
= pLogEntry
->GetAction(this);
4287 CString sToolTipText
;
4290 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4291 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4293 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4295 if (!actionText
.IsEmpty())
4296 actionText
+= L
"\r\n";
4297 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4300 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4302 if (!actionText
.IsEmpty())
4303 actionText
+= L
"\r\n";
4304 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4307 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4309 if (!actionText
.IsEmpty())
4310 actionText
+= L
"\r\n";
4311 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4314 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4316 if (!actionText
.IsEmpty())
4317 actionText
+= L
"\r\n";
4318 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4321 if (!actionText
.IsEmpty())
4323 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4324 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4326 return sToolTipText
;