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_pStoreSelection(NULL
)
53 , m_SelectedFilters(LOGFILTER_ALL
)
54 , m_ShowFilter(FILTERSHOW_ALL
)
56 , m_logEntries(&m_LogCache
)
58 , m_ColumnManager(this)
59 , m_dwDefaultColumns(0)
60 , m_arShownList(&m_critSec
)
62 , m_bNoHightlightHead(FALSE
)
63 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
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();
84 m_critSec_AsyncDiff
.Init();
87 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
88 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
89 m_hConflictedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
90 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
91 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
92 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
94 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE
);
95 m_bFilterCaseSensitively
= !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE
);
101 m_LoadingThread
= NULL
;
103 InterlockedExchange(&m_bExitThread
,FALSE
);
104 m_IsOldFirst
= FALSE
;
105 m_IsRebaseReplaceGraph
= FALSE
;
107 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
109 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
111 // get short/long datetime setting from registry
112 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
113 if ( RegUseShortDateFormat
)
115 m_DateFormat
= DATE_SHORTDATE
;
119 m_DateFormat
= DATE_LONGDATE
;
121 // get relative time display setting from registry
122 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
123 m_bRelativeTimes
= (regRelativeTimes
!= 0);
124 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
126 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
127 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
128 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
129 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
131 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
132 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
134 m_ColumnRegKey
=_T("log");
136 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
137 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
138 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
140 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
141 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
143 m_AsyncThreadExit
= FALSE
;
144 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
145 m_AsynDiffListLock
.Init();
147 hUxTheme
= AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
149 pfnDrawThemeTextEx
= (FNDRAWTHEMETEXTEX
)::GetProcAddress(hUxTheme
, "DrawThemeTextEx");
151 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
152 if (m_DiffingThread
==NULL
)
154 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
160 int CGitLogListBase::AsyncDiffThread()
162 m_AsyncThreadExited
= false;
163 while(!m_AsyncThreadExit
)
165 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
167 GitRevLoglist
* pRev
= nullptr;
168 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
170 m_AsynDiffListLock
.Lock();
171 pRev
= m_AsynDiffList
.back();
172 m_AsynDiffList
.pop_back();
173 m_AsynDiffListLock
.Unlock();
175 if( pRev
->m_CommitHash
.IsEmpty() )
177 if(pRev
->m_IsDiffFiles
)
180 CTGitPathList
& files
= pRev
->GetFiles(this);
182 pRev
->m_ParentHash
.clear();
183 pRev
->m_ParentHash
.push_back(m_HeadHash
);
184 g_Git
.GetWorkingTreeChanges(files
);
185 int& action
= pRev
->GetAction(this);
187 for (int j
= 0; j
< files
.GetCount(); ++j
)
188 action
|= files
[j
].m_Action
;
191 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
193 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
197 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
198 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
200 pRev
->GetBody().Format(IDS_FILESCHANGES
, files
.GetCount());
201 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
202 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
205 m_critSec_AsyncDiff
.Lock();
206 int ret
= pRev
->CheckAndDiff();
207 m_critSec_AsyncDiff
.Unlock();
209 { // fetch change file list
210 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
212 if(i
< m_arShownList
.GetCount())
214 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
215 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
217 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
223 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
225 POSITION pos
= GetFirstSelectedItemPosition();
226 int nItem
= GetNextSelectedItem(pos
);
230 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
232 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
234 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
241 m_AsyncThreadExited
= true;
244 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
248 m_ContextMenuMask
&= hideMask
;
252 m_ContextMenuMask
&= ~hideMask
;
256 CGitLogListBase::~CGitLogListBase()
258 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
259 this->m_arShownList
.SafeRemoveAll();
261 DestroyIcon(m_hModifiedIcon
);
262 DestroyIcon(m_hReplacedIcon
);
263 DestroyIcon(m_hConflictedIcon
);
264 DestroyIcon(m_hAddedIcon
);
265 DestroyIcon(m_hDeletedIcon
);
266 m_logEntries
.ClearAll();
269 DeleteObject(m_boldFont
);
272 DeleteObject(m_FontItalics
);
274 if (m_boldItalicsFont
)
275 DeleteObject(m_boldItalicsFont
);
277 if ( m_pStoreSelection
)
279 delete m_pStoreSelection
;
280 m_pStoreSelection
= NULL
;
283 SafeTerminateThread();
284 SafeTerminateAsyncDiffThread();
287 CloseHandle(m_AsyncDiffEvent
);
290 FreeLibrary(hUxTheme
);
294 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
295 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
296 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
297 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
298 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
300 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
301 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
304 ON_MESSAGE(MSG_LOADED
,OnLoad
)
306 ON_WM_MEASUREITEM_REFLECT()
307 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
308 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
309 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
310 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
311 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
312 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
313 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
314 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
317 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
319 //if (m_nRowHeight>0)
321 lpMeasureItemStruct
->itemHeight
= 50;
325 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
328 return CHintListCtrl::OnCreate(lpCreateStruct
);
331 void CGitLogListBase::PreSubclassWindow()
333 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
334 // load the icons for the action columns
335 // m_Theme.Open(m_hWnd, L"ListView");
336 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
337 CHintListCtrl::PreSubclassWindow();
340 CString
CGitLogListBase::GetRebaseActionName(int action
)
342 if (action
& LOGACTIONS_REBASE_EDIT
)
343 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
344 if (action
& LOGACTIONS_REBASE_SQUASH
)
345 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
346 if (action
& LOGACTIONS_REBASE_PICK
)
347 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
348 if (action
& LOGACTIONS_REBASE_SKIP
)
349 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
351 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
354 void CGitLogListBase::InsertGitColumn()
358 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
359 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
360 if (DWORD(regFullRowSelect
))
361 exStyle
|= LVS_EX_FULLROWSELECT
;
362 SetExtendedStyle(exStyle
);
364 // only load properties if we have a repository
365 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
366 UpdateProjectProperties();
368 static UINT normal
[] =
380 IDS_LOG_COMMIT_EMAIL
,
403 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
405 DWORD hideColumns
= 0;
406 if(this->m_IsRebaseReplaceGraph
)
408 hideColumns
|= GIT_LOG_GRAPH
;
409 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
413 hideColumns
|= GIT_LOG_REBASE
;
416 if(this->m_IsIDReplaceAction
)
418 hideColumns
|= GIT_LOG_ACTIONS
;
419 m_dwDefaultColumns
|= GIT_LOG_ID
;
420 m_dwDefaultColumns
|= GIT_LOG_HASH
;
424 hideColumns
|= GIT_LOG_ID
;
426 if(this->m_bShowBugtraqColumn
)
428 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
432 hideColumns
|= GIT_LOGLIST_BUG
;
434 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
435 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
437 hideColumns
|= GIT_LOGLIST_SVNREV
;
440 m_ColumnManager
.SetNames(normal
, _countof(normal
));
441 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
447 * Resizes all columns in a list control to values in registry.
449 void CGitLogListBase::ResizeAllListCtrlCols()
451 // column max and min widths to allow
452 static const int nMinimumWidth
= 10;
453 static const int nMaximumWidth
= 1000;
454 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
457 int numcols
= pHdrCtrl
->GetItemCount();
458 for (int col
= 0; col
< numcols
; ++col
)
460 // get width for this col last time from registry
462 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
463 CRegDWORD
regwidth(regentry
, 0);
467 // no saved value, setup sensible defaults
468 if (col
== this->LOGLIST_MESSAGE
)
470 cx
= LOGLIST_MESSAGE_MIN
;
474 cx
= ICONITEMBORDER
+16*4;
477 if (cx
< nMinimumWidth
)
481 else if (cx
> nMaximumWidth
)
486 SetColumnWidth(col
, cx
);
493 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
496 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
497 rItem
.mask
= LVIF_STATE
;
498 rItem
.iItem
= (int)Index
;
499 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
502 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(Index
);
505 if (!(rItem
.state
& LVIS_SELECTED
))
507 int action
= pLogEntry
->GetRebaseAction();
508 if (action
& LOGACTIONS_REBASE_SQUASH
)
509 brush
= ::CreateSolidBrush(RGB(156,156,156));
510 else if (action
& LOGACTIONS_REBASE_EDIT
)
511 brush
= ::CreateSolidBrush(RGB(200,200,128));
513 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
515 if (rItem
.state
& LVIS_SELECTED
)
517 if (::GetFocus() == m_hWnd
)
518 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
520 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
525 ::FillRect(hdc
, &rect
, brush
);
526 ::DeleteObject(brush
);
530 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
532 POINT point
= { 4, 4 };
534 rt2
.DeflateRect(1, 1);
535 rt2
.OffsetRect(2, 2);
537 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
538 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
539 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
540 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
541 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
543 ::SelectObject(hdc
, brush
);
544 rt2
.OffsetRect(-2, -2);
545 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
546 ::SelectObject(hdc
, oldbrush
);
547 ::SelectObject(hdc
, oldpen
);
548 ::DeleteObject(nullPen
);
549 ::DeleteObject(darkBrush
);
552 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
554 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
555 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
556 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
557 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
558 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
559 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
560 ::SelectObject(hdc
, oldpen
);
564 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
566 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
567 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
568 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
569 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
570 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
571 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
572 ::SelectObject(hdc
, oldpen
);
576 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
578 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
581 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
582 rItem
.mask
= LVIF_STATE
;
583 rItem
.iItem
= (int)index
;
584 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
590 HTHEME hTheme
= NULL
;
591 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
592 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
595 if (m_bTagsBranchesOnRightSide
)
597 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
598 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
599 SelectObject(hdc
, oldFont
);
600 rt
.left
+= oneSpaceSize
.cx
* 2;
604 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
605 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
606 rt
.left
+= oneSpaceSize
.cx
;
609 int action
= data
->GetRebaseAction();
610 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
611 if (IsAppThemed() && pfnDrawThemeTextEx
)
613 int txtState
= LISS_NORMAL
;
614 if (rItem
.state
& LVIS_SELECTED
)
615 txtState
= LISS_SELECTED
;
617 DTTOPTS opts
= { 0 };
618 opts
.dwSize
= sizeof(opts
);
619 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
620 opts
.dwFlags
= DTT_TEXTCOLOR
;
621 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
625 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
627 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
628 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
629 ::SetTextColor(hdc
, clrOld
);
633 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
634 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
635 ::SetTextColor(hdc
, clrOld
);
639 if (m_bTagsBranchesOnRightSide
)
642 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
644 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
646 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
650 CloseThemeData(hTheme
);
655 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
)
657 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
659 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
661 COLORREF colRef
= refList
[i
].color
;
662 bool singleRemote
= refList
[i
].singleRemote
;
663 bool hasTracking
= refList
[i
].hasTracking
;
664 bool sameName
= refList
[i
].sameName
;
665 bool annotatedTag
= refList
[i
].annotatedTag
;
667 //When row selected, ajust label color
668 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
670 if (rItem
.state
& LVIS_SELECTED
)
671 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
674 brush
= ::CreateSolidBrush(colRef
);
676 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
679 memset(&size
,0,sizeof(SIZE
));
680 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
682 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
685 int textpos
= DT_CENTER
;
687 if (rt
.right
> rect
.right
)
689 rt
.right
= rect
.right
;
698 textRect
.OffsetRect(8, 0);
706 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
710 //Fill interior of ref label
711 ::FillRect(hdc
, &rt
, brush
);
719 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
720 rectEdge
.DeflateRect(1, 1);
721 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
727 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
728 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
729 ::FillRgn(hdc
, hrgn
, brush
);
730 ::DeleteObject(hrgn
);
731 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
733 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
734 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
736 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
737 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
739 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
740 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
741 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
743 SelectObject(hdc
, oldpen
);
746 //Draw text inside label
747 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
748 if (!customColor
&& IsAppThemed() && pfnDrawThemeTextEx
)
750 int txtState
= LISS_NORMAL
;
751 if (rItem
.state
& LVIS_SELECTED
)
752 txtState
= LISS_SELECTED
;
754 DTTOPTS opts
= { 0 };
755 opts
.dwSize
= sizeof(opts
);
756 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
757 opts
.dwFlags
= DTT_TEXTCOLOR
;
758 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
762 W_Dc
.SetBkMode(TRANSPARENT
);
763 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
765 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
766 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
767 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
768 ::SetTextColor(hdc
,clrOld
);
772 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
773 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
774 ::SetTextColor(hdc
, clrOld
);
780 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
781 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
783 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
784 DrawLightning(hdc
, newRect
, color
, bold
);
789 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
790 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
792 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
793 DrawUpTriangle(hdc
, newRect
, color
, bold
);
796 rt
.left
= rt
.right
+ 1;
799 ::DeleteObject(brush
);
801 rt
.right
= rect
.right
;
804 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
806 // Returns ((256 - amount)*col1 + amount*col2) / 256;
807 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
808 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
809 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
812 Gdiplus::Color
GetGdiColor(COLORREF col
)
814 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
816 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
817 const COLORREF
& col
,const COLORREF
& activeColor
, int top
820 int h
= laneHeight
/ 2;
821 int m
= (x1
+ x2
) / 2;
822 int r
= (x2
- x1
) * m_NodeSize
/ 30;
825 #define P_CENTER m , h+top
826 #define P_0 x2, h+top
827 #define P_90 m , 0+top-1
828 #define P_180 x1, h+top
829 #define P_270 m , 2 * h+top +1
830 #define R_CENTER m - r, h - r+top, d, d
833 #define DELTA_UR_B 2*(x1 - m), 2*h +top
834 #define DELTA_UR_E 0*16, 90*16 +top // -,
836 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
837 #define DELTA_DR_E 270*16, 90*16 +top // -'
839 #define DELTA_UL_B 2*(x2 - m), 2*h +top
840 #define DELTA_UL_E 90*16, 90*16 +top // ,-
842 #define DELTA_DL_B 2*(x2 - m),2*-h +top
843 #define DELTA_DL_E 180*16, 90*16 // '-
845 #define CENTER_UR x1, 2*h, 225
846 #define CENTER_DR x1, 0 , 135
847 #define CENTER_UL x2, 2*h, 315
848 #define CENTER_DL x2, 0 , 45
851 Gdiplus::Graphics
graphics( hdc
);
853 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
862 Gdiplus::LinearGradientBrush
gradient(
863 Gdiplus::Point(x1
-2, h
+top
-2),
864 Gdiplus::Point(P_270
),
865 GetGdiColor(activeColor
),GetGdiColor(col
));
868 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
869 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
871 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
872 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
873 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
880 Gdiplus::LinearGradientBrush
gradient(
881 Gdiplus::Point(P_270
),
882 Gdiplus::Point(x2
+1, h
+top
-1),
883 GetGdiColor(col
),GetGdiColor(activeColor
));
886 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
887 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
889 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
890 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
891 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
900 Gdiplus::LinearGradientBrush
gradient(
901 Gdiplus::Point(x1
-2, h
+top
-2),
902 Gdiplus::Point(P_90
),
903 GetGdiColor(activeColor
),GetGdiColor(col
));
905 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
907 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
910 QConicalGradient
gradient(CENTER_DR
);
911 gradient
.setColorAt(0.375, activeCol
);
912 gradient
.setColorAt(0.625, col
);
913 myPen
.setBrush(gradient
);
915 p
->drawArc(P_CENTER
, DELTA_DR
);
924 //static QPen myPen(Qt::black, 2); // fast path here
926 pen
.CreatePen(PS_SOLID
,2,col
);
927 //myPen.setColor(col);
928 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
930 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
932 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
939 case Lanes::NOT_ACTIVE
:
940 case Lanes::MERGE_FORK
:
941 case Lanes::MERGE_FORK_R
:
942 case Lanes::MERGE_FORK_L
:
947 //DrawLine(hdc,P_90,P_270);
948 graphics
.DrawLine(&myPen
,P_90
,P_270
);
949 //p->drawLine(P_90, P_270);
953 //DrawLine(hdc,P_CENTER,P_270);
954 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
955 //p->drawLine(P_CENTER, P_270);
959 case Lanes::BOUNDARY
:
960 case Lanes::BOUNDARY_C
:
961 case Lanes::BOUNDARY_R
:
962 case Lanes::BOUNDARY_L
:
963 //DrawLine(hdc,P_90, P_CENTER);
964 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
965 //p->drawLine(P_90, P_CENTER);
971 myPen
.SetColor(GetGdiColor(activeColor
));
975 case Lanes::MERGE_FORK
:
980 case Lanes::CROSS_EMPTY
:
981 case Lanes::BOUNDARY_C
:
982 //DrawLine(hdc,P_180,P_0);
983 graphics
.DrawLine(&myPen
,P_180
,P_0
);
984 //p->drawLine(P_180, P_0);
986 case Lanes::MERGE_FORK_R
:
987 case Lanes::BOUNDARY_R
:
988 //DrawLine(hdc,P_180,P_CENTER);
989 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
990 //p->drawLine(P_180, P_CENTER);
992 case Lanes::MERGE_FORK_L
:
995 case Lanes::BOUNDARY_L
:
996 //DrawLine(hdc,P_CENTER,P_0);
997 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
998 //p->drawLine(P_CENTER, P_0);
1004 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1007 brush
.CreateSolidBrush(col
);
1008 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1010 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1011 // center symbol, e.g. rect or ellipse
1014 case Lanes::INITIAL
:
1017 //p->setPen(Qt::NoPen);
1019 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1020 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1021 //p->drawEllipse(R_CENTER);
1023 case Lanes::MERGE_FORK
:
1024 case Lanes::MERGE_FORK_R
:
1025 case Lanes::MERGE_FORK_L
:
1026 //p->setPen(Qt::NoPen);
1028 //p->drawRect(R_CENTER);
1029 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1030 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1032 case Lanes::UNAPPLIED
:
1034 //p->setPen(Qt::NoPen);
1035 //p->setBrush(Qt::red);
1036 //p->drawRect(m - r, h - 1, d, 2);
1037 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1038 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1040 case Lanes::APPLIED
:
1042 //p->setPen(Qt::NoPen);
1043 //p->setBrush(DARK_GREEN);
1044 //p->drawRect(m - r, h - 1, d, 2);
1045 //p->drawRect(m - 1, h - r, 2, d);
1046 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1047 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1048 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1050 case Lanes::BOUNDARY
:
1051 //p->setBrush(back);
1052 //p->drawEllipse(R_CENTER);
1053 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1054 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1056 case Lanes::BOUNDARY_C
:
1057 case Lanes::BOUNDARY_R
:
1058 case Lanes::BOUNDARY_L
:
1059 //p->setBrush(back);
1060 //p->drawRect(R_CENTER);
1061 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1062 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1068 ::SelectObject(hdc
,oldpen
);
1069 ::SelectObject(hdc
,oldbrush
);
1078 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1082 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
1083 if(data
->m_CommitHash
.IsEmpty())
1088 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1089 rItem
.mask
= LVIF_STATE
;
1090 rItem
.iItem
= (int)index
;
1091 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1094 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1096 if (data
->m_Lanes
.empty())
1097 m_logEntries
.setLane(data
->m_CommitHash
);
1099 std::vector
<int>& lanes
=data
->m_Lanes
;
1100 size_t laneNum
= lanes
.size();
1101 UINT activeLane
= 0;
1102 for (UINT i
= 0; i
< laneNum
; ++i
)
1103 if (Lanes::isMerge(lanes
[i
])) {
1109 int maxWidth
= rect
.Width();
1110 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1112 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1113 //if (opt.state & QStyle::State_Selected)
1114 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1116 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1123 if (ln
== Lanes::EMPTY
)
1126 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1127 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1131 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1137 if (ln
== Lanes::EMPTY
)
1140 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1141 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1143 if (ln
== Lanes::CROSS
)
1145 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1146 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1149 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1155 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1158 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1159 // Take the default processing unless we set this to something else below.
1160 *pResult
= CDRF_DODEFAULT
;
1162 if (m_bNoDispUpdates
)
1165 switch (pLVCD
->nmcd
.dwDrawStage
)
1169 *pResult
= CDRF_NOTIFYITEMDRAW
;
1173 case CDDS_ITEMPREPAINT
:
1175 // This is the prepaint stage for an item. Here's where we set the
1176 // item's text color.
1178 // Tell Windows to send draw notifications for each subitem.
1179 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1181 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1183 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1185 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1188 HGDIOBJ hGdiObj
= nullptr;
1189 int action
= data
->GetRebaseAction();
1190 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1191 crText
= RGB(128,128,128);
1193 if (action
& LOGACTIONS_REBASE_SQUASH
)
1194 pLVCD
->clrTextBk
= RGB(156,156,156);
1195 else if (action
& LOGACTIONS_REBASE_EDIT
)
1196 pLVCD
->clrTextBk
= RGB(200,200,128);
1198 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1200 if (action
& LOGACTIONS_REBASE_CURRENT
)
1201 hGdiObj
= m_boldFont
;
1203 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1204 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1205 if (isHeadHash
&& isHighlight
)
1206 hGdiObj
= m_boldItalicsFont
;
1207 else if (isHeadHash
)
1208 hGdiObj
= m_boldFont
;
1209 else if (isHighlight
)
1210 hGdiObj
= m_FontItalics
;
1214 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1215 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1218 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1219 // crText = GetSysColor(COLOR_GRAYTEXT);
1221 if (data
->m_CommitHash
.IsEmpty())
1223 //crText = GetSysColor(RGB(200,200,0));
1224 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1225 // We changed the font, so we're returning CDRF_NEWFONT. This
1226 // tells the control to recalculate the extent of the text.
1227 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1231 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1233 if (m_bStrictStopped
)
1234 crText
= GetSysColor(COLOR_GRAYTEXT
);
1236 // Store the color back in the NMLVCUSTOMDRAW struct.
1237 pLVCD
->clrText
= crText
;
1241 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1243 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1245 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1248 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1250 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1253 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1255 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1256 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1258 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1259 if( !data
->m_CommitHash
.IsEmpty())
1260 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1262 *pResult
= CDRF_SKIPDEFAULT
;
1267 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1269 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1271 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1273 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1276 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1278 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1279 // not in FillBackGround method, because this only affected the message subitem
1280 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1283 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1284 int state
= GetItemState(index
, LVIS_SELECTED
);
1285 int txtState
= LISS_NORMAL
;
1286 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1288 if (state
& LVIS_SELECTED
)
1289 txtState
= LISS_HOTSELECTED
;
1291 txtState
= LISS_HOT
;
1293 else if (state
& LVIS_SELECTED
)
1295 if (::GetFocus() == m_hWnd
)
1296 txtState
= LISS_SELECTED
;
1298 txtState
= LISS_SELECTEDNOTFOCUS
;
1301 HTHEME hTheme
= nullptr;
1302 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1303 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1305 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1306 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1309 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1310 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1311 ::DeleteObject(brush
);
1316 // get rect of whole line
1317 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1319 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1320 rect2
.DeflateRect(1, 1, 1, 1);
1322 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1323 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1325 CloseThemeData(hTheme
);
1327 // END: extended redraw
1329 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1331 std::vector
<REFLABEL
> refsToShow
;
1332 STRING_VECTOR remoteTrackingList
;
1333 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1334 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1336 CString str
= refList
[i
];
1339 refLabel
.color
= RGB(255, 255, 255);
1340 refLabel
.singleRemote
= false;
1341 refLabel
.hasTracking
= false;
1342 refLabel
.sameName
= false;
1343 refLabel
.annotatedTag
= false;
1344 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1346 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1348 if (refLabel
.name
== m_CurrentBranch
)
1349 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1351 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1353 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1354 CString pullRemote
= trackingEntry
.first
;
1355 CString pullBranch
= trackingEntry
.second
;
1356 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1358 CString defaultUpstream
;
1359 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1360 refLabel
.hasTracking
= true;
1361 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1364 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1366 if (refList
[j
] == defaultUpstream
)
1375 bool sameName
= pullBranch
== refLabel
.name
;
1376 refsToShow
.push_back(refLabel
);
1377 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1378 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1379 if (m_bSymbolizeRefNames
)
1381 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1383 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1384 refLabel
.singleRemote
= true;
1387 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1388 refLabel
.sameName
= sameName
;
1390 refsToShow
.push_back(refLabel
);
1391 remoteTrackingList
.push_back(defaultUpstream
);
1397 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1399 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1403 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1405 if (remoteTrackingList
[j
] == str
)
1414 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1415 if (m_bSymbolizeRefNames
)
1417 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1419 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1420 refLabel
.singleRemote
= true;
1424 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1426 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1428 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1429 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1431 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1433 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1435 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1436 refLabel
.name
= _T("stash");
1438 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1440 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1442 if (refLabel
.name
.Find(_T("good")) == 0)
1444 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1445 refLabel
.name
= _T("good");
1447 if (refLabel
.name
.Find(_T("bad")) == 0)
1449 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1450 refLabel
.name
= _T("bad");
1456 refsToShow
.push_back(refLabel
);
1459 if (refsToShow
.empty())
1461 *pResult
= CDRF_DODEFAULT
;
1465 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1467 *pResult
= CDRF_SKIPDEFAULT
;
1475 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1477 if(this->m_IsIDReplaceAction
)
1479 *pResult
= CDRF_DODEFAULT
;
1482 *pResult
= CDRF_DODEFAULT
;
1484 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1488 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1489 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1491 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1493 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1494 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1495 // Get the selected state of the
1496 // item being drawn.
1498 // Fill the background if necessary
1499 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1501 // Draw the icon(s) into the compatible DC
1502 int action
= pLogEntry
->GetAction(this);
1503 if (!pLogEntry
->m_IsDiffFiles
)
1505 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1506 *pResult
= CDRF_SKIPDEFAULT
;
1510 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1511 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1514 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1515 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1518 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1519 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1522 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1523 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1526 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1527 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1530 *pResult
= CDRF_SKIPDEFAULT
;
1536 *pResult
= CDRF_DODEFAULT
;
1539 CString
FindSVNRev(const CString
& msg
)
1543 const std::tr1::wsregex_iterator end
;
1544 std::wstring s
= msg
;
1545 std::tr1::wregex
regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1546 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex1
); it
!= end
; ++it
)
1548 const std::tr1::wsmatch match
= *it
;
1549 if (match
.size() == 4)
1551 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1552 return std::wstring(match
[2]).c_str();
1555 std::tr1::wregex
regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1556 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex2
); it
!= end
; ++it
)
1558 const std::tr1::wsmatch match
= *it
;
1559 if (match
.size() == 3)
1561 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1562 return std::wstring(match
[1]).c_str();
1566 catch (std::exception
) {}
1571 // CGitLogListBase message handlers
1573 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1575 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1577 // Create a pointer to the item
1578 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1580 // Do the list need text information?
1581 if (!(pItem
->mask
& LVIF_TEXT
))
1584 // By default, clear text buffer.
1585 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
- 1);
1587 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1590 if (m_bNoDispUpdates
|| bOutOfRange
)
1593 // Which item number?
1594 int itemid
= pItem
->iItem
;
1595 GitRevLoglist
* pLogEntry
= nullptr;
1596 if (itemid
< m_arShownList
.GetCount())
1597 pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1602 temp
.Format(_T("%d"),pItem
->iItem
+1);
1607 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1611 switch (pItem
->iSubItem
)
1613 case LOGLIST_GRAPH
: //Graphic
1615 case LOGLIST_REBASE
:
1617 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1618 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1621 case LOGLIST_ACTION
: //action -- no text in the column
1625 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1628 if(this->m_IsIDReplaceAction
)
1629 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1631 case LOGLIST_MESSAGE
: //Message
1633 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
- 1);
1635 case LOGLIST_AUTHOR
: //Author
1637 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
- 1);
1639 case LOGLIST_DATE
: //Date
1640 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1641 lstrcpyn(pItem
->pszText
,
1642 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1643 pItem
->cchTextMax
- 1);
1648 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
- 1);
1651 case LOGLIST_COMMIT_NAME
: //Commit
1653 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
- 1);
1656 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1658 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
- 1);
1661 case LOGLIST_COMMIT_DATE
: //Commit Date
1662 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1663 lstrcpyn(pItem
->pszText
,
1664 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1665 pItem
->cchTextMax
- 1);
1667 case LOGLIST_BUG
: //Bug ID
1669 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1671 case LOGLIST_SVNREV
: //SVN revision
1673 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1681 bool CGitLogListBase::IsOnStash(int index
)
1683 GitRevLoglist
* rev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
));
1688 GitRevLoglist
* preRev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
- 1));
1689 if (IsStash(preRev
))
1690 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1695 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1697 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1699 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1705 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1707 if (pRev
->m_ParentHash
.empty())
1709 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1710 MessageBox(pRev
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1712 parentHash
= pRev
->m_ParentHash
;
1715 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1718 if (pWnd
== GetHeaderCtrl())
1720 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1723 int selIndex
= GetSelectionMark();
1725 return; // nothing selected, nothing to do with a context menu
1727 // if the user selected the info text telling about not all revisions shown due to
1728 // the "stop on copy/rename" option, we also don't show the context menu
1729 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1732 // if the context menu is invoked through the keyboard, we have to use
1733 // a calculated position on where to anchor the menu on
1734 if ((point
.x
== -1) && (point
.y
== -1))
1737 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1738 ClientToScreen(&rect
);
1739 point
= rect
.CenterPoint();
1741 m_nSearchIndex
= selIndex
;
1742 m_bCancelled
= FALSE
;
1744 // calculate some information the context menu commands can use
1745 // CString pathURL = GetURLFromPath(m_path);
1747 POSITION pos
= GetFirstSelectedItemPosition();
1748 int indexNext
= GetNextSelectedItem(pos
);
1752 GitRevLoglist
* pSelLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(indexNext
));
1753 if (pSelLogEntry
== nullptr)
1756 GitRev revSelected
= pSelLogEntry
->Rev
;
1757 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1758 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1760 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1762 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1763 if (changedpath
->lCopyFromRev
)
1764 revPrevious
= changedpath
->lCopyFromRev
;
1767 GitRev revSelected2
;
1770 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1771 revSelected2
= pLogEntry
->Rev
;
1773 bool bAllFromTheSameAuthor
= true;
1774 CString firstAuthor
;
1775 CLogDataVector selEntries
;
1776 GitRev revLowest
, revHighest
;
1777 GitRevRangeArray revisionRanges
;
1779 POSITION pos
= GetFirstSelectedItemPosition();
1780 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1781 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1782 selEntries
.push_back(pLogEntry
);
1783 firstAuthor
= pLogEntry
->sAuthor
;
1784 revLowest
= pLogEntry
->Rev
;
1785 revHighest
= pLogEntry
->Rev
;
1788 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1789 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1790 selEntries
.push_back(pLogEntry
);
1791 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1792 bAllFromTheSameAuthor
= false;
1793 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1794 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1800 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1802 int FirstSelect
=-1, LastSelect
=-1;
1803 pos
= GetFirstSelectedItemPosition();
1804 FirstSelect
= GetNextSelectedItem(pos
);
1807 LastSelect
= GetNextSelectedItem(pos
);
1809 //entry is selected, now show the popup menu
1811 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1813 if (popup
.CreatePopupMenu())
1815 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1816 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1817 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1818 bool isStash
= IsOnStash(indexNext
);
1819 GIT_REV_LIST parentHash
;
1820 GetParentHashes(pSelLogEntry
, parentHash
);
1822 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1823 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1825 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1)
1826 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1828 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1829 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1831 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1832 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1834 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
)))
1835 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1837 if (GetSelectedCount() == 1)
1840 bool requiresSeparator
= false;
1841 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1843 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1845 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1846 requiresSeparator
= true;
1851 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1853 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1854 requiresSeparator
= true;
1856 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1858 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1859 requiresSeparator
= true;
1863 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1865 if (parentHash
.size() == 1)
1867 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1868 requiresSeparator
= true;
1870 else if (parentHash
.size() > 1)
1872 blamemenu
.CreatePopupMenu();
1873 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1874 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1877 str
.Format(IDS_PARENT
, i
+ 1);
1878 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1880 requiresSeparator
= true;
1884 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1886 if (parentHash
.size() == 1)
1888 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1889 requiresSeparator
= true;
1891 else if (parentHash
.size() > 1)
1893 gnudiffmenu
.CreatePopupMenu();
1894 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1896 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1897 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1899 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1902 str
.Format(IDS_PARENT
, i
+ 1);
1903 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1905 requiresSeparator
= true;
1909 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1911 if (parentHash
.size() == 1)
1913 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1914 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1915 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1916 requiresSeparator
= true;
1918 else if (parentHash
.size() > 1)
1920 diffmenu
.CreatePopupMenu();
1921 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1922 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1925 str
.Format(IDS_PARENT
, i
+ 1);
1926 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1927 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1929 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1930 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1933 requiresSeparator
= true;
1937 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1939 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1940 requiresSeparator
= true;
1943 if (requiresSeparator
)
1944 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1946 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1948 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1949 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1952 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1954 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1955 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1957 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1958 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1960 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1963 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1965 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1966 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1968 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1969 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1971 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
1972 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
1974 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1976 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
1977 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
1979 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1983 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1985 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1987 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1989 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1991 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1992 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1994 // popup.AppendMenu(MF_SEPARATOR, NULL);
1999 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2001 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2003 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2004 GetSelectedCount() == 1)
2005 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2007 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2008 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2010 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
2011 str
.Format(format
,g_Git
.GetCurrentBranch());
2013 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2014 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2016 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
2017 str
.Format(format
,g_Git
.GetCurrentBranch());
2019 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2020 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2023 // Add Switch Branch express Menu
2024 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2025 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2028 std::vector
<CString
*> branchs
;
2029 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2031 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2032 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2034 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2039 str2
.LoadString(IDS_SWITCH_BRANCH
);
2041 if(branchs
.size() == 1)
2044 str2
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2045 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2047 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2050 else if(branchs
.size() > 1)
2052 subbranchmenu
.CreatePopupMenu();
2053 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2055 if (*branchs
[i
] != currentBranch
)
2057 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2058 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2062 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2066 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2067 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2069 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2070 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2072 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2073 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2075 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
2076 str
.Format(format
,g_Git
.GetCurrentBranch());
2078 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2079 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2080 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2082 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2083 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2085 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2087 if (parentHash
.size() == 1)
2089 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2091 else if (parentHash
.size() > 1)
2093 revertmenu
.CreatePopupMenu();
2094 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2096 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2099 str2
.Format(IDS_PARENT
, i
+ 1);
2100 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2105 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2106 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2108 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2113 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2115 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2116 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2117 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2118 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2121 if (GetSelectedCount() >= 2)
2123 bool bAddSeparator
= false;
2124 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2126 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2127 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2130 if (GetSelectedCount() == 2)
2132 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2133 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2135 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2137 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2138 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2139 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2141 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
2142 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2143 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
2144 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2147 bAddSeparator
= true;
2152 bAddSeparator
= true;
2155 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2156 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2159 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2162 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2164 bool bAddSeparator
= false;
2165 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2167 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2171 headindex
= this->GetHeadIndex();
2172 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2174 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2176 if (g_Git
.GetHash(hashFirst
, head
))
2177 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2178 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2180 if (g_Git
.GetHash(hash
, head
))
2181 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2182 GitRevLoglist
* pFirstEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2183 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2184 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2185 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2186 bAddSeparator
= true;
2191 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2192 if (GetSelectedCount() >= 2)
2193 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2195 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2196 bAddSeparator
= true;
2199 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2200 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2201 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2202 bAddSeparator
= true;
2206 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2209 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())
2211 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2212 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2215 if (GetSelectedCount() == 1)
2217 bool bAddSeparator
= false;
2218 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2220 // show the push-option only if the log entry has an associated local branch
2221 bool isLocal
= false;
2222 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2224 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2227 if (isLocal
|| showExtendedMenu
)
2229 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2230 bAddSeparator
= true;
2233 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2235 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2236 bAddSeparator
= true;
2240 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2242 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2244 std::vector
<CString
*> branchs
;
2245 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2247 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2248 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2251 if (branchs
.size() == 1)
2253 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2256 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2257 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2258 bAddSeparator
= true;
2260 else if (branchs
.size() > 1)
2262 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2263 submenu
.CreatePopupMenu();
2264 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2266 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2267 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2270 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2271 bAddSeparator
= true;
2274 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2276 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2277 } // GetSelectedCount() == 1
2279 if (GetSelectedCount() != 0)
2281 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2282 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2283 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2284 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2285 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2286 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2289 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2290 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2292 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2293 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2295 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2296 // DialogEnableWindow(IDOK, FALSE);
2297 // SetPromptApp(&theApp);
2299 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2301 // EnableOKButton();
2302 } // if (popup.CreatePopupMenu())
2306 bool CGitLogListBase::IsSelectionContinuous()
2308 if ( GetSelectedCount()==1 )
2310 // if only one revision is selected, the selection is of course
2315 POSITION pos
= GetFirstSelectedItemPosition();
2316 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2319 int itemindex
= GetNextSelectedItem(pos
);
2322 int nextindex
= GetNextSelectedItem(pos
);
2323 if (nextindex
- itemindex
> 1)
2325 bContinuous
= false;
2328 itemindex
= nextindex
;
2334 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2338 POSITION pos
= GetFirstSelectedItemPosition();
2342 sRev
.LoadString(IDS_LOG_REVISION
);
2344 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2346 sDate
.LoadString(IDS_LOG_DATE
);
2348 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2352 CString sLogCopyText
;
2354 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2356 if (toCopy
== ID_COPY_ALL
)
2358 //pLogEntry->GetFiles(this)
2359 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2361 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2362 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2364 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2365 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2368 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2369 sPaths
+= _T(" ") + rename
;
2371 sPaths
+= _T("\r\n");
2374 CString body
= pLogEntry
->GetBody();
2375 body
.Replace(_T("\n"), _T("\r\n"));
2376 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"),
2377 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2378 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2380 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2381 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2383 sClipdata
+= sLogCopyText
;
2385 else if (toCopy
== ID_COPY_MESSAGE
)
2387 CString body
= pLogEntry
->GetBody();
2388 body
.Replace(_T("\n"), _T("\r\n"));
2389 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2391 else if (toCopy
== ID_COPY_SUBJECT
)
2393 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2398 sClipdata
+= _T("\r\n");
2399 sClipdata
+= pLogEntry
->m_CommitHash
;
2404 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2409 void CGitLogListBase::DiffSelectedRevWithPrevious()
2411 if (m_bThreadRunning
)
2414 int FirstSelect
=-1, LastSelect
=-1;
2415 POSITION pos
= GetFirstSelectedItemPosition();
2416 FirstSelect
= GetNextSelectedItem(pos
);
2419 LastSelect
= GetNextSelectedItem(pos
);
2422 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2425 UpdateLogInfoLabel();
2426 int selIndex
= m_LogList
.GetSelectionMark();
2429 int selCount
= m_LogList
.GetSelectedCount();
2433 // Find selected entry in the log list
2434 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2435 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2436 long rev1
= pLogEntry
->Rev
;
2438 CTGitPath path
= m_path
;
2440 // See how many files under the relative root were changed in selected revision
2442 LogChangedPath
* changed
= NULL
;
2443 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2445 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2446 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2453 if (m_path
.IsDirectory() && nChanged
== 1)
2455 // We're looking at the log for a directory and only one file under dir was changed in the revision
2456 // Do diff on that file instead of whole directory
2457 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2460 m_bCancelled
= FALSE
;
2461 DialogEnableWindow(IDOK
, FALSE
);
2462 SetPromptApp(&theApp
);
2463 theApp
.DoWaitCursor(1);
2467 GitDiff
diff(this, m_hWnd
, true);
2468 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2469 diff
.SetHEADPeg(m_LogRevision
);
2470 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2474 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2477 theApp
.DoWaitCursor(-1);
2482 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2484 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2487 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2489 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2491 if (pFindInfo
->lvfi
.psz
== 0)
2494 CString sCmp
= pFindInfo
->lvfi
.psz
;
2496 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2498 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2499 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2500 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2502 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2510 if (sCmp
.Compare(sRev
)==0)
2517 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2519 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2521 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2522 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2523 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2525 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2533 if (sCmp
.Compare(sRev
)==0)
2545 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2549 this->m_arShownList
.SafeRemoveAll();
2551 this->m_logEntries
.ClearAll();
2552 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2555 SetItemCountEx((int)m_logEntries
.size());
2557 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2561 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2562 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2567 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2568 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2580 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2584 m_arShownList
.SafeRemoveAll();
2586 m_logEntries
.ClearAll();
2587 if (m_logEntries
.Fill(hashes
))
2590 SetItemCountEx((int)m_logEntries
.size());
2592 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2596 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2597 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2601 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2602 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2611 int CGitLogListBase::BeginFetchLog()
2615 this->m_arShownList
.SafeRemoveAll();
2617 this->m_logEntries
.ClearAll();
2619 this->m_LogCache
.ClearAllParent();
2621 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2624 if(this->m_Path
.IsEmpty())
2630 mask
= CGit::LOG_INFO_ONLY_HASH
;
2631 if (m_bIncludeBoundaryCommits
)
2632 mask
|= CGit::LOG_INFO_BOUNDARY
;
2633 // if(this->m_bAllBranch)
2634 mask
|= m_ShowMask
;
2638 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2640 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2643 if (m_sRange
.IsEmpty())
2644 m_sRange
= _T("HEAD");
2647 data
.m_From
= m_From
;
2650 #if 0 /* use tortoiegit filter */
2651 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2652 data
.m_Author
= this->m_sFilterText
;
2654 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2655 data
.m_MessageFilter
= this->m_sFilterText
;
2657 data
.m_IsRegex
= m_bFilterWithRegex
;
2660 // follow does not work for directories
2661 if (!path
|| path
->IsDirectory())
2662 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2663 // follow does not work with all branches 8at least in TGit)
2664 if (mask
& CGit::LOG_INFO_FOLLOW
)
2665 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2667 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2669 //this->m_logEntries.ParserFromLog();
2670 if(IsInWorkingThread())
2672 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2676 SetItemCountEx((int)m_logEntries
.size());
2681 [] { git_init(); } ();
2686 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2690 if (!g_Git
.CanParseRev(m_sRange
))
2692 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2695 // if show all branches, pick any ref as dummy entry ref
2697 if (g_Git
.GetRefList(list
))
2698 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2699 if (list
.size() == 0)
2702 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2705 g_Git
.m_critGitDllSec
.Lock();
2707 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2709 g_Git
.m_critGitDllSec
.Unlock();
2715 g_Git
.m_critGitDllSec
.Unlock();
2717 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2720 g_Git
.m_critGitDllSec
.Unlock();
2725 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2727 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2729 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2731 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2733 DiffSelectedRevWithPrevious();
2738 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2745 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2747 // select all entries
2748 for (int i
=0; i
<GetItemCount(); ++i
)
2750 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2756 if (m_hAccel
&& !bSkipAccelerator
)
2758 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2764 //m_tooltips.RelayEvent(pMsg);
2765 return __super::PreTranslateMessage(pMsg
);
2768 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2770 // a double click on an entry in the revision list has happened
2773 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2774 DiffSelectedRevWithPrevious();
2777 int CGitLogListBase::FetchLogAsync(void * data
)
2781 m_bExitThread
=FALSE
;
2782 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2783 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2784 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2785 if (m_LoadingThread
==NULL
)
2787 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2788 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2789 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2795 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2797 return ((CGitLogListBase
*)pVoid
)->LogThread();
2800 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2803 oldest
=CTime::GetCurrentTime();
2804 latest
=CTime(1971,1,2,0,0,0);
2805 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2807 if(m_logEntries
[i
].IsEmpty())
2810 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2811 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2813 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2814 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2822 UINT
CGitLogListBase::LogThread()
2824 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2826 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2827 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2833 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2834 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2839 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2840 bool bRegex
= false;
2841 if (m_bFilterWithRegex
)
2842 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2844 TRACE(_T("\n===Begin===\n"));
2845 //Update work copy item;
2847 if (!m_logEntries
.empty())
2849 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2851 m_arShownList
.SafeAdd(pRev
);
2855 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2857 // store commit number of the last selected commit/line before the refresh or -1
2858 int lastSelectedHashNItem
= -1;
2861 bool shouldWalk
= true;
2862 if (!g_Git
.CanParseRev(m_sRange
))
2864 // walk revisions if show all branches and there exists any ref
2865 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2870 if (g_Git
.GetRefList(list
))
2871 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2872 if (list
.size() == 0)
2879 g_Git
.m_critGitDllSec
.Lock();
2883 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2884 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2889 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2892 g_Git
.m_critGitDllSec
.Unlock();
2895 t2
=t1
=GetTickCount();
2896 int oldprecentage
= 0;
2897 size_t oldsize
= m_logEntries
.size();
2898 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2899 while (ret
== 0 && !m_bExitThread
)
2901 g_Git
.m_critGitDllSec
.Lock();
2904 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2908 g_Git
.m_critGitDllSec
.Unlock();
2910 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2913 g_Git
.m_critGitDllSec
.Unlock();
2917 if (ret
!= -2) // other than end of revision walking
2918 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2922 if (commit
.m_ignore
== 1)
2924 git_free_commit(&commit
);
2928 //printf("%s\r\n",commit.GetSubject());
2932 CGitHash hash
= (char*)commit
.m_hash
;
2934 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2935 pRev
->m_GitCommit
= commit
;
2936 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2939 g_Git
.m_critGitDllSec
.Lock();
2942 git_get_notes(commit
.m_hash
, ¬e
);
2946 g_Git
.m_critGitDllSec
.Unlock();
2948 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2951 g_Git
.m_critGitDllSec
.Unlock();
2955 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2960 if(!pRev
->m_IsDiffFiles
)
2962 pRev
->m_CallDiffAsync
= DiffAsync
;
2965 pRev
->ParserParentFromCommit(&commit
);
2966 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2968 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2970 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2971 auto it
= commitChildren
.find(parentHash
);
2972 if (it
== commitChildren
.end())
2974 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2976 it
->second
.insert(pRev
->m_CommitHash
);
2985 bool visible
= true;
2986 if (HasFilterText())
2988 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2991 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
2993 this->m_critSec
.Lock();
2994 m_logEntries
.append(hash
, visible
);
2996 m_arShownList
.SafeAdd(pRev
);
2997 this->m_critSec
.Unlock();
3002 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3003 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3007 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3010 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3013 if(percent
< GITLOG_START
)
3014 percent
= GITLOG_START
+1;
3016 oldsize
= m_logEntries
.size();
3017 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3019 //if( percent > oldprecentage )
3021 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3022 oldprecentage
= percent
;
3025 if (lastSelectedHashNItem
>= 0)
3026 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3031 g_Git
.m_critGitDllSec
.Lock();
3032 git_close_log(m_DllGitLog
);
3033 g_Git
.m_critGitDllSec
.Unlock();
3039 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3044 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3046 if (lastSelectedHashNItem
>= 0)
3047 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3050 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3052 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3057 void CGitLogListBase::FetchRemoteList()
3059 STRING_VECTOR remoteList
;
3060 if (!g_Git
.GetRemoteList(remoteList
))
3061 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3063 m_SingleRemote
= _T("");
3066 void CGitLogListBase::FetchTrackingBranchList()
3068 m_TrackingMap
.clear();
3069 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3071 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3074 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3076 CString pullRemote
, pullBranch
;
3077 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3078 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3080 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3087 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3089 SafeTerminateThread();
3091 this->SetItemCountEx(0);
3096 // HACK to hide graph column
3097 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3098 SetColumnWidth(0, 0);
3100 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3102 //Update branch and Tag info
3105 m_pFindDialog
->RefreshList();
3106 //Assume Thread have exited
3107 //if(!m_bThreadRunning)
3109 m_logEntries
.clear();
3113 m_sFilterText
.Empty();
3118 InterlockedExchange(&m_bExitThread
,FALSE
);
3120 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3121 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3122 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3124 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3125 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3126 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3130 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3134 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3136 type
|= std::tr1::regex_constants::icase
;
3137 pat
= std::tr1::wregex(regexp_str
, type
);
3140 catch (std::exception
) {}
3143 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3146 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3149 if ((bRegex
)&&(m_bFilterWithRegex
))
3151 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3153 if(this->m_bShowBugtraqColumn
)
3155 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3157 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
3158 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3165 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3167 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
3168 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3174 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3176 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
3177 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3183 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3185 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3190 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3196 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3198 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3203 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3209 if (m_SelectedFilters
& LOGFILTER_REVS
)
3211 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3212 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3218 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3220 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3221 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3223 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3230 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3232 CTGitPathList
*pathList
=NULL
;
3233 if( pRev
->m_IsDiffFiles
)
3234 pathList
= &pRev
->GetFiles(this);
3237 if(!pRev
->m_IsSimpleListReady
)
3238 pRev
->SafeGetSimpleList(&g_Git
);
3242 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3244 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3248 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3254 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3256 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3265 CString find
= m_sFilterText
;
3266 if (!m_bFilterCaseSensitively
)
3268 result
= find
[0] == '!' ? FALSE
: TRUE
;
3272 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3274 if(this->m_bShowBugtraqColumn
)
3276 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3278 if (!m_bFilterCaseSensitively
)
3279 sBugIds
.MakeLower();
3280 if ((sBugIds
.Find(find
) >= 0))
3287 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3289 CString msg
= pRev
->GetSubject();
3291 if (!m_bFilterCaseSensitively
)
3292 msg
= msg
.MakeLower();
3293 if ((msg
.Find(find
) >= 0))
3299 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3301 CString msg
= pRev
->GetBody();
3303 if (!m_bFilterCaseSensitively
)
3304 msg
= msg
.MakeLower();
3305 if ((msg
.Find(find
) >= 0))
3311 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3313 CString msg
= pRev
->GetAuthorName();
3314 if (!m_bFilterCaseSensitively
)
3315 msg
= msg
.MakeLower();
3316 if ((msg
.Find(find
) >= 0))
3322 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3324 CString msg
= pRev
->GetAuthorEmail();
3325 if (!m_bFilterCaseSensitively
)
3326 msg
= msg
.MakeLower();
3327 if ((msg
.Find(find
) >= 0))
3333 if (m_SelectedFilters
& LOGFILTER_REVS
)
3335 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3336 if ((sRev
.Find(find
) >= 0))
3342 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3344 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3345 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3347 if (it
->Find(find
) >= 0)
3354 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3356 CTGitPathList
*pathList
=NULL
;
3357 if( pRev
->m_IsDiffFiles
)
3358 pathList
= &pRev
->GetFiles(this);
3361 if(!pRev
->m_IsSimpleListReady
)
3362 pRev
->SafeGetSimpleList(&g_Git
);
3365 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3367 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3368 CString path
= cpath
->GetGitOldPathString();
3369 if (!m_bFilterCaseSensitively
)
3371 if ((path
.Find(find
)>=0))
3375 path
= cpath
->GetGitPathString();
3376 if (!m_bFilterCaseSensitively
)
3378 if ((path
.Find(find
)>=0))
3384 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3386 CString path
= pRev
->m_SimpleFileList
[i
];
3387 if (!m_bFilterCaseSensitively
)
3389 if ((path
.Find(find
)>=0))
3395 } // else (from if (bRegex))
3399 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3401 return str
.Left(prefix
.GetLength()) == prefix
;
3403 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
)
3405 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3408 if (m_ShowFilter
& FILTERSHOW_REFS
)
3411 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3412 for (size_t i
= 0; i
< refList
.size(); ++i
)
3414 const CString
&str
= refList
[i
];
3415 if (CStringStartsWith(str
, _T("refs/heads/")))
3417 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3420 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3422 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3425 else if (CStringStartsWith(str
, _T("refs/tags/")))
3427 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3430 else if (CStringStartsWith(str
, _T("refs/stash")))
3432 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3435 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3437 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3441 // Keep the head too.
3442 if (pRev
->m_CommitHash
== m_HeadHash
)
3446 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3448 if (pRev
->ParentsCount() > 1)
3450 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3451 if (childrenIt
!= commitChildren
.end())
3453 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3454 if (children
.size() > 1)
3461 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3463 // HACK to hide graph column
3465 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3467 SetColumnWidth(0, 0);
3470 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3475 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3477 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3478 for (size_t i
= 0; i
< vector
.size(); ++i
)
3480 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3482 CString tag
= vector
[i
];
3483 int start
= vector
[i
].Find(_T("^{}"));
3485 tag
= tag
.Left(start
);
3489 cmd
.Format(_T("git.exe cat-file tag %s"), tag
);
3490 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3491 output
.AppendChar(_T('\n'));
3499 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3502 pShownlist
->SafeRemoveAll();
3504 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3505 bool bRegex
= false;
3506 if (m_bFilterWithRegex
)
3507 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3509 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3511 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3513 if ((bRegex
)&&(m_bFilterWithRegex
))
3516 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3518 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3519 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3521 pShownlist
->SafeAdd(m_logEntries
[i
]);
3526 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3528 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3529 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3531 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3535 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3537 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3538 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3540 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3544 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3546 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3549 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3551 CTGitPath cpath
= pathList
[cpPathIndex
];
3552 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3554 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3558 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3560 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3564 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3566 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3572 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3574 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3576 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3580 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3582 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3584 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3588 if (m_SelectedFilters
& LOGFILTER_REVS
)
3590 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3591 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3593 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3597 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3599 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3600 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3602 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3604 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3612 CString find
= m_sFilterText
;
3613 if (!m_bFilterCaseSensitively
)
3616 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3618 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3620 if (!m_bFilterCaseSensitively
)
3621 sBugIDs
= sBugIDs
.MakeLower();
3622 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3624 pShownlist
->SafeAdd(m_logEntries
[i
]);
3629 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3631 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3633 if (!m_bFilterCaseSensitively
)
3634 msg
= msg
.MakeLower();
3635 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3637 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3641 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3643 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3645 if (!m_bFilterCaseSensitively
)
3646 msg
= msg
.MakeLower();
3647 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3649 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3653 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3655 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3658 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3660 CTGitPath cpath
= pathList
[cpPathIndex
];
3661 CString path
= cpath
.GetGitOldPathString();
3662 if (!m_bFilterCaseSensitively
)
3664 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3666 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3670 path
= cpath
.GetGitPathString();
3671 if (!m_bFilterCaseSensitively
)
3673 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3675 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3679 path
= cpath
.GetActionName();
3680 if (!m_bFilterCaseSensitively
)
3682 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3684 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3690 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3692 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3693 if (!m_bFilterCaseSensitively
)
3694 msg
= msg
.MakeLower();
3695 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3697 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3701 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3703 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3704 if (!m_bFilterCaseSensitively
)
3705 msg
= msg
.MakeLower();
3706 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3708 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3712 if (m_SelectedFilters
& LOGFILTER_REVS
)
3714 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3715 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3717 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3721 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3723 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3724 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3726 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3728 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3733 } // else (from if (bRegex))
3734 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3738 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3741 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3747 return time <= m_To;
3750 return time >= m_From;
3752 return ((time >= m_From)&&(time <= m_To));
3754 return TRUE
; /* git dll will filter time range */
3758 void CGitLogListBase::StartFilter()
3760 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3761 RecalculateShownList(&m_arShownList
);
3762 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3766 SetItemCountEx(ShownCountWithStopped());
3767 RedrawItems(0, ShownCountWithStopped());
3771 void CGitLogListBase::RemoveFilter()
3774 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3776 m_arShownList
.SafeRemoveAll();
3778 // reset the time filter too
3780 m_timFrom
= (__time64_t(m_tFrom
));
3781 m_timTo
= (__time64_t(m_tTo
));
3782 m_DateFrom
.SetTime(&m_timFrom
);
3783 m_DateTo
.SetTime(&m_timTo
);
3784 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3785 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3788 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3790 if(this->m_IsOldFirst
)
3792 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3796 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3799 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3801 SetItemCountEx(ShownCountWithStopped());
3802 RedrawItems(0, ShownCountWithStopped());
3804 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3807 void CGitLogListBase::Clear()
3809 m_arShownList
.SafeRemoveAll();
3812 m_logEntries
.ClearAll();
3816 void CGitLogListBase::OnDestroy()
3818 // save the column widths to the registry
3821 SafeTerminateThread();
3822 SafeTerminateAsyncDiffThread();
3825 while(m_LogCache
.SaveCache())
3833 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3834 // MB_YESNO) == IDNO)
3838 CHintListCtrl::OnDestroy();
3841 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3845 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3846 this->InvalidateRect(rect
);
3852 * Save column widths to the registry
3854 void CGitLogListBase::SaveColumnWidths()
3856 int maxcol
= m_ColumnManager
.GetColumnCount();
3858 // HACK that graph column is always shown
3859 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3861 for (int col
= 0; col
< maxcol
; ++col
)
3862 if (m_ColumnManager
.IsVisible (col
))
3863 m_ColumnManager
.ColumnResized (col
);
3865 m_ColumnManager
.WriteSettings();
3868 int CGitLogListBase::GetHeadIndex()
3870 if(m_HeadHash
.IsEmpty())
3873 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3875 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3878 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3884 void CGitLogListBase::OnFind()
3888 m_pFindDialog
= new CFindDlg(this);
3889 m_pFindDialog
->Create(this);
3892 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3894 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3896 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3898 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3901 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3903 if (GetSelectedCount() != 0)
3906 CGitHash theSelectedHash
= m_lastSelectedHash
;
3907 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3908 m_lastSelectedHash
= theSelectedHash
;
3910 int countPerPage
= GetCountPerPage();
3911 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3912 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3913 EnsureVisible((int)itemToSelect
, FALSE
);
3916 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3919 ASSERT(m_pFindDialog
!= NULL
);
3920 bool bFound
= false;
3923 if (m_pFindDialog
->IsTerminating())
3925 // invalidate the handle identifying the dialog box.
3926 m_pFindDialog
= NULL
;
3930 INT_PTR cnt
= m_arShownList
.GetCount();
3932 if(m_pFindDialog
->IsRef())
3935 str
=m_pFindDialog
->GetFindString();
3941 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3942 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3947 for (i
= 0; i
< cnt
; ++i
)
3949 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3950 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3959 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3964 if (m_pFindDialog
->FindNext() && !bFound
)
3966 //read data from dialog
3967 CString findText
= m_pFindDialog
->GetFindString();
3968 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3970 std::tr1::wregex pat
;
3971 bool bRegex
= false;
3972 if (m_pFindDialog
->Regex())
3973 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
3975 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3977 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3982 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3984 if (m_nSearchIndex
>= 0)
3986 if (i
== m_nSearchIndex
)
3988 ::MessageBeep(0xFFFFFFFF);
3989 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3994 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
3997 str
+=pLogEntry
->m_CommitHash
.ToString();
4000 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4002 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4006 str
+=pLogEntry
->GetAuthorEmail();
4008 str
+=pLogEntry
->GetAuthorName();
4010 str
+=pLogEntry
->GetBody();
4012 str
+=pLogEntry
->GetCommitterEmail();
4014 str
+=pLogEntry
->GetCommitterName();
4016 str
+=pLogEntry
->GetSubject();
4018 str
+=pLogEntry
->m_Notes
;
4020 str
+=GetTagInfo(pLogEntry
);
4024 /*Because changed files list is loaded on demand when gui show,
4025 files will empty when files have not fetched.
4027 we can add it back by using one-way diff(with outnumber changed and rename detect.
4028 here just need changed filename list. one-way is much quicker.
4030 if(pLogEntry
->m_IsFull
)
4032 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4034 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4036 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4042 if(!pLogEntry
->m_IsSimpleListReady
)
4043 pLogEntry
->SafeGetSimpleList(&g_Git
);
4045 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4047 str
+= pLogEntry
->m_SimpleFileList
[j
];
4056 if (std::regex_search(std::wstring(str
), pat
, flags
))
4066 if (str
.Find(findText
) >= 0)
4076 msg
= msg
.MakeLower();
4077 CString find
= findText
.MakeLower();
4078 if (msg
.Find(find
) >= 0)
4085 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4087 } // if(m_pFindDialog->FindNext())
4088 //UpdateLogInfoLabel();
4093 EnsureVisible(i
, FALSE
);
4094 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4096 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4097 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4098 SetSelectionMark(i
);
4102 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4104 m_highlight
= pLogEntry
->m_CommitHash
;
4107 //FillLogMessageCtrl();
4114 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4116 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4121 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4123 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4128 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4130 LVHITTESTINFO lvhitTestInfo
;
4132 lvhitTestInfo
.pt
= point
;
4134 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4135 int nSubItem
= lvhitTestInfo
.iSubItem
;
4137 UINT nFlags
= lvhitTestInfo
.flags
;
4139 // nFlags is 0 if the SubItemHitTest fails
4140 // Therefore, 0 & <anything> will equal false
4141 if (nFlags
& LVHT_ONITEM
)
4143 // Get the client area occupied by this control
4145 GetClientRect(&rcClient
);
4147 // Fill in the TOOLINFO structure
4149 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4150 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4151 pTI
->rect
= rcClient
;
4153 return pTI
->uId
; // By returning a unique value per listItem,
4154 // we ensure that when the mouse moves over another list item,
4155 // the tooltip will change
4159 // Otherwise, we aren't interested, so let the message propagate
4164 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4166 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4167 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4171 // Ignore messages from the built in tooltip, we are processing them internally
4172 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4173 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4174 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4177 // Get the mouse position
4178 const MSG
* pMessage
= GetCurrentMessage();
4182 ScreenToClient(&pt
);
4184 // Check if the point falls onto a list item
4185 LVHITTESTINFO lvhitTestInfo
;
4186 lvhitTestInfo
.pt
= pt
;
4188 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4190 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4192 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4193 if (strTipText
.IsEmpty())
4196 // we want multiline tooltips
4197 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4199 wcscpy_s(m_wszTip
, strTipText
);
4200 // handle Unicode as well as non-Unicode requests
4201 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4203 pTTTA
->hinst
= nullptr;
4204 pTTTA
->lpszText
= m_szTip
;
4205 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4209 pTTTW
->hinst
= nullptr;
4210 pTTTW
->lpszText
= m_wszTip
;
4214 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4215 ClientToScreen(rect
);
4216 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4218 return TRUE
; // We found a tool tip,
4219 // tell the framework this message has been handled
4222 return FALSE
; // We didn't handle the message,
4223 // let the framework continue propagating the message
4226 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4228 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4230 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4231 if (pLogEntry
== nullptr)
4233 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4235 return pLogEntry
->GetSubject();
4237 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4239 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4240 if (pLogEntry
== nullptr)
4242 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4244 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4246 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4247 if (pLogEntry
== nullptr)
4249 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4251 else if (nSubItem
== LOGLIST_ACTION
)
4253 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4254 if (pLogEntry
== nullptr)
4257 if (!pLogEntry
->m_IsDiffFiles
)
4258 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4260 int actions
= pLogEntry
->GetAction(this);
4261 CString sToolTipText
;
4264 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4265 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4267 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4269 if (!actionText
.IsEmpty())
4270 actionText
+= L
"\r\n";
4271 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4274 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4276 if (!actionText
.IsEmpty())
4277 actionText
+= L
"\r\n";
4278 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4281 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4283 if (!actionText
.IsEmpty())
4284 actionText
+= L
"\r\n";
4285 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4288 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4290 if (!actionText
.IsEmpty())
4291 actionText
+= L
"\r\n";
4292 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4295 if (!actionText
.IsEmpty())
4297 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4298 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4300 return sToolTipText
;