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
)
64 , m_bFullCommitMessageOnLogLine(false)
66 // use the default GUI font, create a copy of it and
67 // change the copy to BOLD (leave the rest of the font
69 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
71 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
72 lf
.lfWeight
= FW_BOLD
;
73 m_boldFont
= CreateFontIndirect(&lf
);
74 lf
.lfWeight
= FW_DONTCARE
;
76 m_FontItalics
= CreateFontIndirect(&lf
);
77 lf
.lfWeight
= FW_BOLD
;
78 m_boldItalicsFont
= CreateFontIndirect(&lf
);
80 m_bShowBugtraqColumn
=false;
82 m_IsIDReplaceAction
=FALSE
;
84 this->m_critSec
.Init();
85 m_critSec_AsyncDiff
.Init();
88 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
89 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
90 m_hConflictedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONCONFLICTED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
91 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
92 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
93 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
95 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE
);
96 m_bFilterCaseSensitively
= !!CRegDWORD(_T("Software\\TortoiseGit\\FilterCaseSensitively"), FALSE
);
98 m_Filter
.m_NumberOfLogsScale
= (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogsScale"), CFilterData::SHOW_NO_LIMIT
);
99 if (m_Filter
.m_NumberOfLogsScale
== CFilterData::SHOW_LAST_SEL_DATE
)
102 key
.Format(_T("Software\\TortoiseGit\\History\\LogDlg_Limits\\%s\\FromDate"), (LPCTSTR
)g_Git
.m_CurrentDir
);
103 key
.Replace(_T(':'), _T('_'));
104 CString lastSelFromDate
= CRegString(key
);
105 if (lastSelFromDate
.GetLength() == 10)
107 CTime time
= CTime(_wtoi((LPCTSTR
)lastSelFromDate
.Mid(0, 4)), _wtoi((LPCTSTR
)lastSelFromDate
.Mid(5, 2)), _wtoi((LPCTSTR
)lastSelFromDate
.Mid(8, 2)), 0, 0, 0);
108 m_Filter
.m_From
= (DWORD
)time
.GetTime();
111 m_Filter
.m_NumberOfLogs
= (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\NumberOfLogs"), 1);
114 m_LoadingThread
= NULL
;
116 InterlockedExchange(&m_bExitThread
,FALSE
);
117 m_IsOldFirst
= FALSE
;
118 m_IsRebaseReplaceGraph
= FALSE
;
120 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
122 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
124 // get short/long datetime setting from registry
125 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
126 if ( RegUseShortDateFormat
)
128 m_DateFormat
= DATE_SHORTDATE
;
132 m_DateFormat
= DATE_LONGDATE
;
134 // get relative time display setting from registry
135 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
136 m_bRelativeTimes
= (regRelativeTimes
!= 0);
137 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
139 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
140 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
141 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
142 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
143 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
144 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
145 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAMEPREVIOUS
);
147 m_ColumnRegKey
=_T("log");
149 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
150 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
151 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
152 m_bFullCommitMessageOnLogLine
= !!CRegDWORD(_T("Software\\TortoiseGit\\FullCommitMessageOnLogLine"), FALSE
);
154 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
155 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
157 m_AsyncThreadExit
= FALSE
;
158 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
159 m_AsynDiffListLock
.Init();
161 hUxTheme
= AtlLoadSystemLibraryUsingFullPath(_T("UXTHEME.DLL"));
163 pfnDrawThemeTextEx
= (FNDRAWTHEMETEXTEX
)::GetProcAddress(hUxTheme
, "DrawThemeTextEx");
165 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
166 if (m_DiffingThread
==NULL
)
168 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
174 int CGitLogListBase::AsyncDiffThread()
176 m_AsyncThreadExited
= false;
177 while(!m_AsyncThreadExit
)
179 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
181 GitRevLoglist
* pRev
= nullptr;
182 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
184 m_AsynDiffListLock
.Lock();
185 pRev
= m_AsynDiffList
.back();
186 m_AsynDiffList
.pop_back();
187 m_AsynDiffListLock
.Unlock();
189 if( pRev
->m_CommitHash
.IsEmpty() )
191 if(pRev
->m_IsDiffFiles
)
194 CTGitPathList
& files
= pRev
->GetFiles(this);
196 pRev
->m_ParentHash
.clear();
197 pRev
->m_ParentHash
.push_back(m_HeadHash
);
198 g_Git
.GetWorkingTreeChanges(files
);
199 int& action
= pRev
->GetAction(this);
201 for (int j
= 0; j
< files
.GetCount(); ++j
)
202 action
|= files
[j
].m_Action
;
205 if (pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
, nullptr, &err
))
207 CMessageBox::Show(NULL
, _T("Failed to get UnRev file list\n") + err
, _T("TortoiseGit"), MB_OK
);
211 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
212 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
214 pRev
->GetBody().Format(IDS_FILESCHANGES
, files
.GetCount());
215 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
216 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
219 m_critSec_AsyncDiff
.Lock();
220 int ret
= pRev
->CheckAndDiff();
221 m_critSec_AsyncDiff
.Unlock();
223 { // fetch change file list
224 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
226 if(i
< m_arShownList
.GetCount())
228 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
229 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
231 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
237 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
239 POSITION pos
= GetFirstSelectedItemPosition();
240 int nItem
= GetNextSelectedItem(pos
);
244 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
246 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
248 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
255 m_AsyncThreadExited
= true;
258 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
262 m_ContextMenuMask
&= hideMask
;
266 m_ContextMenuMask
&= ~hideMask
;
270 CGitLogListBase::~CGitLogListBase()
272 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
273 this->m_arShownList
.SafeRemoveAll();
275 DestroyIcon(m_hModifiedIcon
);
276 DestroyIcon(m_hReplacedIcon
);
277 DestroyIcon(m_hConflictedIcon
);
278 DestroyIcon(m_hAddedIcon
);
279 DestroyIcon(m_hDeletedIcon
);
280 m_logEntries
.ClearAll();
283 DeleteObject(m_boldFont
);
286 DeleteObject(m_FontItalics
);
288 if (m_boldItalicsFont
)
289 DeleteObject(m_boldItalicsFont
);
291 if ( m_pStoreSelection
)
293 delete m_pStoreSelection
;
294 m_pStoreSelection
= NULL
;
297 SafeTerminateThread();
298 SafeTerminateAsyncDiffThread();
301 CloseHandle(m_AsyncDiffEvent
);
304 FreeLibrary(hUxTheme
);
308 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
309 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
310 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
311 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
312 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
314 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
315 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
318 ON_MESSAGE(MSG_LOADED
,OnLoad
)
320 ON_WM_MEASUREITEM_REFLECT()
321 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
322 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
323 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
324 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
325 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
326 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
327 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, &OnToolTipText
)
328 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, &OnToolTipText
)
331 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
333 //if (m_nRowHeight>0)
335 lpMeasureItemStruct
->itemHeight
= 50;
339 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
342 return CHintListCtrl::OnCreate(lpCreateStruct
);
345 void CGitLogListBase::PreSubclassWindow()
347 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
348 // load the icons for the action columns
349 // m_Theme.Open(m_hWnd, L"ListView");
350 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
351 CHintListCtrl::PreSubclassWindow();
354 CString
CGitLogListBase::GetRebaseActionName(int action
)
356 if (action
& LOGACTIONS_REBASE_EDIT
)
357 return MAKEINTRESOURCE(IDS_PATHACTIONS_EDIT
);
358 if (action
& LOGACTIONS_REBASE_SQUASH
)
359 return MAKEINTRESOURCE(IDS_PATHACTIONS_SQUASH
);
360 if (action
& LOGACTIONS_REBASE_PICK
)
361 return MAKEINTRESOURCE(IDS_PATHACTIONS_PICK
);
362 if (action
& LOGACTIONS_REBASE_SKIP
)
363 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIP
);
365 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
368 void CGitLogListBase::InsertGitColumn()
372 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
373 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
374 if (DWORD(regFullRowSelect
))
375 exStyle
|= LVS_EX_FULLROWSELECT
;
376 SetExtendedStyle(exStyle
);
378 // only load properties if we have a repository
379 if (GitAdminDir::IsWorkingTreeOrBareRepo(g_Git
.m_CurrentDir
))
380 UpdateProjectProperties();
382 static UINT normal
[] =
394 IDS_LOG_COMMIT_EMAIL
,
417 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
419 DWORD hideColumns
= 0;
420 if(this->m_IsRebaseReplaceGraph
)
422 hideColumns
|= GIT_LOG_GRAPH
;
423 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
427 hideColumns
|= GIT_LOG_REBASE
;
430 if(this->m_IsIDReplaceAction
)
432 hideColumns
|= GIT_LOG_ACTIONS
;
433 m_dwDefaultColumns
|= GIT_LOG_ID
;
434 m_dwDefaultColumns
|= GIT_LOG_HASH
;
438 hideColumns
|= GIT_LOG_ID
;
440 if(this->m_bShowBugtraqColumn
)
442 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
446 hideColumns
|= GIT_LOGLIST_BUG
;
448 if (CTGitPath(g_Git
.m_CurrentDir
).HasGitSVNDir())
449 m_dwDefaultColumns
|= GIT_LOGLIST_SVNREV
;
451 hideColumns
|= GIT_LOGLIST_SVNREV
;
454 m_ColumnManager
.SetNames(normal
, _countof(normal
));
455 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
461 * Resizes all columns in a list control to values in registry.
463 void CGitLogListBase::ResizeAllListCtrlCols()
465 // column max and min widths to allow
466 static const int nMinimumWidth
= 10;
467 static const int nMaximumWidth
= 1000;
468 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
471 int numcols
= pHdrCtrl
->GetItemCount();
472 for (int col
= 0; col
< numcols
; ++col
)
474 // get width for this col last time from registry
476 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"), (LPCTSTR
)m_ColumnRegKey
, col
);
477 CRegDWORD
regwidth(regentry
, 0);
481 // no saved value, setup sensible defaults
482 if (col
== this->LOGLIST_MESSAGE
)
484 cx
= LOGLIST_MESSAGE_MIN
;
488 cx
= ICONITEMBORDER
+16*4;
491 if (cx
< nMinimumWidth
)
495 else if (cx
> nMaximumWidth
)
500 SetColumnWidth(col
, cx
);
507 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
510 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
511 rItem
.mask
= LVIF_STATE
;
512 rItem
.iItem
= (int)Index
;
513 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
516 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(Index
);
519 if (!(rItem
.state
& LVIS_SELECTED
))
521 int action
= pLogEntry
->GetRebaseAction();
522 if (action
& LOGACTIONS_REBASE_SQUASH
)
523 brush
= ::CreateSolidBrush(RGB(156,156,156));
524 else if (action
& LOGACTIONS_REBASE_EDIT
)
525 brush
= ::CreateSolidBrush(RGB(200,200,128));
527 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
529 if (rItem
.state
& LVIS_SELECTED
)
531 if (::GetFocus() == m_hWnd
)
532 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
534 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
539 ::FillRect(hdc
, &rect
, brush
);
540 ::DeleteObject(brush
);
544 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
546 POINT point
= { 4, 4 };
548 rt2
.DeflateRect(1, 1);
549 rt2
.OffsetRect(2, 2);
551 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
552 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
553 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
554 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
555 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
557 ::SelectObject(hdc
, brush
);
558 rt2
.OffsetRect(-2, -2);
559 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
560 ::SelectObject(hdc
, oldbrush
);
561 ::SelectObject(hdc
, oldpen
);
562 ::DeleteObject(nullPen
);
563 ::DeleteObject(darkBrush
);
566 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
568 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
569 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
570 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
571 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
572 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
573 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
574 ::SelectObject(hdc
, oldpen
);
578 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
580 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
581 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
582 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
583 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
584 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
585 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
586 ::SelectObject(hdc
, oldpen
);
590 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
592 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
595 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
596 rItem
.mask
= LVIF_STATE
;
597 rItem
.iItem
= (int)index
;
598 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
604 HTHEME hTheme
= NULL
;
605 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
606 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
609 if (m_bTagsBranchesOnRightSide
)
611 HFONT oldFont
= (HFONT
)SelectObject(hdc
, (HFONT
)GetStockObject(DEFAULT_GUI_FONT
));
612 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
613 SelectObject(hdc
, oldFont
);
614 rt
.left
+= oneSpaceSize
.cx
* 2;
618 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
619 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
620 rt
.left
+= oneSpaceSize
.cx
;
623 CString msg
= MessageDisplayStr(data
);
624 int action
= data
->GetRebaseAction();
625 bool skip
= !!(action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
));
626 if (IsAppThemed() && pfnDrawThemeTextEx
)
628 int txtState
= LISS_NORMAL
;
629 if (rItem
.state
& LVIS_SELECTED
)
630 txtState
= LISS_SELECTED
;
632 DTTOPTS opts
= { 0 };
633 opts
.dwSize
= sizeof(opts
);
634 opts
.crText
= skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
);
635 opts
.dwFlags
= DTT_TEXTCOLOR
;
636 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, msg
, -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, &rt
, &opts
);
640 if ((rItem
.state
& LVIS_SELECTED
) && (::GetFocus() == m_hWnd
))
642 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_HIGHLIGHTTEXT
));
643 ::DrawText(hdc
,msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
644 ::SetTextColor(hdc
, clrOld
);
648 COLORREF clrOld
= ::SetTextColor(hdc
, skip
? RGB(128,128,128) : ::GetSysColor(COLOR_WINDOWTEXT
));
649 ::DrawText(hdc
, msg
, msg
.GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
650 ::SetTextColor(hdc
, clrOld
);
654 if (m_bTagsBranchesOnRightSide
)
657 GetTextExtentPoint32(hdc
, msg
, msg
.GetLength(), &size
);
659 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
661 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
665 CloseThemeData(hTheme
);
670 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
& W_Dc
, HTHEME hTheme
, CRect
& rect
, CRect
& rt
, LVITEM
& rItem
, GitRevLoglist
* data
, std::vector
<REFLABEL
>& refList
)
672 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
674 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
676 COLORREF colRef
= refList
[i
].color
;
677 bool singleRemote
= refList
[i
].singleRemote
;
678 bool hasTracking
= refList
[i
].hasTracking
;
679 bool sameName
= refList
[i
].sameName
;
680 bool annotatedTag
= refList
[i
].annotatedTag
;
682 //When row selected, ajust label color
683 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
685 if (rItem
.state
& LVIS_SELECTED
)
686 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
689 brush
= ::CreateSolidBrush(colRef
);
691 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
694 memset(&size
,0,sizeof(SIZE
));
695 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
697 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
700 int textpos
= DT_CENTER
;
702 if (rt
.right
> rect
.right
)
704 rt
.right
= rect
.right
;
713 textRect
.OffsetRect(8, 0);
721 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
725 //Fill interior of ref label
726 ::FillRect(hdc
, &rt
, brush
);
734 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
735 rectEdge
.DeflateRect(1, 1);
736 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
742 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
743 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
744 ::FillRgn(hdc
, hrgn
, brush
);
745 ::DeleteObject(hrgn
);
746 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
748 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
749 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
751 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
752 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
754 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
755 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
756 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
758 SelectObject(hdc
, oldpen
);
761 //Draw text inside label
762 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
763 if (!customColor
&& IsAppThemed() && pfnDrawThemeTextEx
)
765 int txtState
= LISS_NORMAL
;
766 if (rItem
.state
& LVIS_SELECTED
)
767 txtState
= LISS_SELECTED
;
769 DTTOPTS opts
= { 0 };
770 opts
.dwSize
= sizeof(opts
);
771 opts
.crText
= ::GetSysColor(COLOR_WINDOWTEXT
);
772 opts
.dwFlags
= DTT_TEXTCOLOR
;
773 pfnDrawThemeTextEx(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, &textRect
, &opts
);
777 W_Dc
.SetBkMode(TRANSPARENT
);
778 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
780 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
781 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
782 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
783 ::SetTextColor(hdc
,clrOld
);
787 COLORREF clrOld
= ::SetTextColor(hdc
, ::GetSysColor(COLOR_WINDOWTEXT
));
788 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
789 ::SetTextColor(hdc
, clrOld
);
795 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
796 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
798 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
799 DrawLightning(hdc
, newRect
, color
, bold
);
804 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
805 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
807 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
808 DrawUpTriangle(hdc
, newRect
, color
, bold
);
811 rt
.left
= rt
.right
+ 1;
814 ::DeleteObject(brush
);
816 rt
.right
= rect
.right
;
819 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
821 // Returns ((256 - amount)*col1 + amount*col2) / 256;
822 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
823 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
824 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
827 Gdiplus::Color
GetGdiColor(COLORREF col
)
829 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
831 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
832 const COLORREF
& col
,const COLORREF
& activeColor
, int top
835 int h
= laneHeight
/ 2;
836 int m
= (x1
+ x2
) / 2;
837 int r
= (x2
- x1
) * m_NodeSize
/ 30;
840 #define P_CENTER m , h+top
841 #define P_0 x2, h+top
842 #define P_90 m , 0+top-1
843 #define P_180 x1, h+top
844 #define P_270 m , 2 * h+top +1
845 #define R_CENTER m - r, h - r+top, d, d
848 #define DELTA_UR_B 2*(x1 - m), 2*h +top
849 #define DELTA_UR_E 0*16, 90*16 +top // -,
851 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
852 #define DELTA_DR_E 270*16, 90*16 +top // -'
854 #define DELTA_UL_B 2*(x2 - m), 2*h +top
855 #define DELTA_UL_E 90*16, 90*16 +top // ,-
857 #define DELTA_DL_B 2*(x2 - m),2*-h +top
858 #define DELTA_DL_E 180*16, 90*16 // '-
860 #define CENTER_UR x1, 2*h, 225
861 #define CENTER_DR x1, 0 , 135
862 #define CENTER_UL x2, 2*h, 315
863 #define CENTER_DL x2, 0 , 45
866 Gdiplus::Graphics
graphics( hdc
);
868 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
877 Gdiplus::LinearGradientBrush
gradient(
878 Gdiplus::Point(x1
-2, h
+top
-2),
879 Gdiplus::Point(P_270
),
880 GetGdiColor(activeColor
),GetGdiColor(col
));
883 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
884 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
886 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
887 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
888 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
895 Gdiplus::LinearGradientBrush
gradient(
896 Gdiplus::Point(P_270
),
897 Gdiplus::Point(x2
+1, h
+top
-1),
898 GetGdiColor(col
),GetGdiColor(activeColor
));
901 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
902 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
904 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
905 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
906 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
915 Gdiplus::LinearGradientBrush
gradient(
916 Gdiplus::Point(x1
-2, h
+top
-2),
917 Gdiplus::Point(P_90
),
918 GetGdiColor(activeColor
),GetGdiColor(col
));
920 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
922 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
925 QConicalGradient
gradient(CENTER_DR
);
926 gradient
.setColorAt(0.375, activeCol
);
927 gradient
.setColorAt(0.625, col
);
928 myPen
.setBrush(gradient
);
930 p
->drawArc(P_CENTER
, DELTA_DR
);
939 //static QPen myPen(Qt::black, 2); // fast path here
941 pen
.CreatePen(PS_SOLID
,2,col
);
942 //myPen.setColor(col);
943 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
945 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
947 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
954 case Lanes::NOT_ACTIVE
:
955 case Lanes::MERGE_FORK
:
956 case Lanes::MERGE_FORK_R
:
957 case Lanes::MERGE_FORK_L
:
962 //DrawLine(hdc,P_90,P_270);
963 graphics
.DrawLine(&myPen
,P_90
,P_270
);
964 //p->drawLine(P_90, P_270);
968 //DrawLine(hdc,P_CENTER,P_270);
969 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
970 //p->drawLine(P_CENTER, P_270);
974 case Lanes::BOUNDARY
:
975 case Lanes::BOUNDARY_C
:
976 case Lanes::BOUNDARY_R
:
977 case Lanes::BOUNDARY_L
:
978 //DrawLine(hdc,P_90, P_CENTER);
979 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
980 //p->drawLine(P_90, P_CENTER);
986 myPen
.SetColor(GetGdiColor(activeColor
));
990 case Lanes::MERGE_FORK
:
995 case Lanes::CROSS_EMPTY
:
996 case Lanes::BOUNDARY_C
:
997 //DrawLine(hdc,P_180,P_0);
998 graphics
.DrawLine(&myPen
,P_180
,P_0
);
999 //p->drawLine(P_180, P_0);
1001 case Lanes::MERGE_FORK_R
:
1002 case Lanes::BOUNDARY_R
:
1003 //DrawLine(hdc,P_180,P_CENTER);
1004 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
1005 //p->drawLine(P_180, P_CENTER);
1007 case Lanes::MERGE_FORK_L
:
1010 case Lanes::BOUNDARY_L
:
1011 //DrawLine(hdc,P_CENTER,P_0);
1012 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
1013 //p->drawLine(P_CENTER, P_0);
1019 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1022 brush
.CreateSolidBrush(col
);
1023 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
1025 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
1026 // center symbol, e.g. rect or ellipse
1029 case Lanes::INITIAL
:
1032 //p->setPen(Qt::NoPen);
1034 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1035 graphics
.FillEllipse(&myBrush
, R_CENTER
);
1036 //p->drawEllipse(R_CENTER);
1038 case Lanes::MERGE_FORK
:
1039 case Lanes::MERGE_FORK_R
:
1040 case Lanes::MERGE_FORK_L
:
1041 //p->setPen(Qt::NoPen);
1043 //p->drawRect(R_CENTER);
1044 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1045 graphics
.FillRectangle(&myBrush
, R_CENTER
);
1047 case Lanes::UNAPPLIED
:
1049 //p->setPen(Qt::NoPen);
1050 //p->setBrush(Qt::red);
1051 //p->drawRect(m - r, h - 1, d, 2);
1052 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1053 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1055 case Lanes::APPLIED
:
1057 //p->setPen(Qt::NoPen);
1058 //p->setBrush(DARK_GREEN);
1059 //p->drawRect(m - r, h - 1, d, 2);
1060 //p->drawRect(m - 1, h - r, 2, d);
1061 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1062 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1063 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1065 case Lanes::BOUNDARY
:
1066 //p->setBrush(back);
1067 //p->drawEllipse(R_CENTER);
1068 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1069 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1071 case Lanes::BOUNDARY_C
:
1072 case Lanes::BOUNDARY_R
:
1073 case Lanes::BOUNDARY_L
:
1074 //p->setBrush(back);
1075 //p->drawRect(R_CENTER);
1076 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1077 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1083 ::SelectObject(hdc
,oldpen
);
1084 ::SelectObject(hdc
,oldbrush
);
1093 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1097 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(index
);
1098 if(data
->m_CommitHash
.IsEmpty())
1103 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1104 rItem
.mask
= LVIF_STATE
;
1105 rItem
.iItem
= (int)index
;
1106 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1109 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1111 if (data
->m_Lanes
.empty())
1112 m_logEntries
.setLane(data
->m_CommitHash
);
1114 std::vector
<int>& lanes
=data
->m_Lanes
;
1115 size_t laneNum
= lanes
.size();
1116 UINT activeLane
= 0;
1117 for (UINT i
= 0; i
< laneNum
; ++i
)
1118 if (Lanes::isMerge(lanes
[i
])) {
1124 int maxWidth
= rect
.Width();
1125 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1127 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1128 //if (opt.state & QStyle::State_Selected)
1129 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1131 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1138 if (ln
== Lanes::EMPTY
)
1141 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1142 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1146 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1152 if (ln
== Lanes::EMPTY
)
1155 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1156 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1158 if (ln
== Lanes::CROSS
)
1160 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1161 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1164 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1170 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1173 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1174 // Take the default processing unless we set this to something else below.
1175 *pResult
= CDRF_DODEFAULT
;
1177 if (m_bNoDispUpdates
)
1180 switch (pLVCD
->nmcd
.dwDrawStage
)
1184 *pResult
= CDRF_NOTIFYITEMDRAW
;
1188 case CDDS_ITEMPREPAINT
:
1190 // This is the prepaint stage for an item. Here's where we set the
1191 // item's text color.
1193 // Tell Windows to send draw notifications for each subitem.
1194 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1196 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1198 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1200 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1203 HGDIOBJ hGdiObj
= nullptr;
1204 int action
= data
->GetRebaseAction();
1205 if (action
& (LOGACTIONS_REBASE_DONE
| LOGACTIONS_REBASE_SKIP
))
1206 crText
= RGB(128,128,128);
1208 if (action
& LOGACTIONS_REBASE_SQUASH
)
1209 pLVCD
->clrTextBk
= RGB(156,156,156);
1210 else if (action
& LOGACTIONS_REBASE_EDIT
)
1211 pLVCD
->clrTextBk
= RGB(200,200,128);
1213 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1215 if (action
& LOGACTIONS_REBASE_CURRENT
)
1216 hGdiObj
= m_boldFont
;
1218 BOOL isHeadHash
= data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
;
1219 BOOL isHighlight
= data
->m_CommitHash
== m_highlight
&& !m_highlight
.IsEmpty();
1220 if (isHeadHash
&& isHighlight
)
1221 hGdiObj
= m_boldItalicsFont
;
1222 else if (isHeadHash
)
1223 hGdiObj
= m_boldFont
;
1224 else if (isHighlight
)
1225 hGdiObj
= m_FontItalics
;
1229 SelectObject(pLVCD
->nmcd
.hdc
, hGdiObj
);
1230 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1233 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1234 // crText = GetSysColor(COLOR_GRAYTEXT);
1236 if (data
->m_CommitHash
.IsEmpty())
1238 //crText = GetSysColor(RGB(200,200,0));
1239 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1240 // We changed the font, so we're returning CDRF_NEWFONT. This
1241 // tells the control to recalculate the extent of the text.
1242 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1246 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1248 if (m_bStrictStopped
)
1249 crText
= GetSysColor(COLOR_GRAYTEXT
);
1251 // Store the color back in the NMLVCUSTOMDRAW struct.
1252 pLVCD
->clrText
= crText
;
1256 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1258 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1260 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1263 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& !HasFilterText() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1265 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1268 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1270 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1271 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1273 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1274 if( !data
->m_CommitHash
.IsEmpty())
1275 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1277 *pResult
= CDRF_SKIPDEFAULT
;
1282 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1284 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1286 GitRevLoglist
* data
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1288 if (!m_HashMap
[data
->m_CommitHash
].empty() && !(data
->GetRebaseAction() & LOGACTIONS_REBASE_DONE
))
1291 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1293 // BEGIN: extended redraw, HACK for issue #1618 and #2014
1294 // not in FillBackGround method, because this only affected the message subitem
1295 if (0 != pLVCD
->iStateId
) // don't know why, but this helps against loosing the focus rect
1298 int index
= (int)pLVCD
->nmcd
.dwItemSpec
;
1299 int state
= GetItemState(index
, LVIS_SELECTED
);
1300 int txtState
= LISS_NORMAL
;
1301 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater() && GetHotItem() == (int)index
)
1303 if (state
& LVIS_SELECTED
)
1304 txtState
= LISS_HOTSELECTED
;
1306 txtState
= LISS_HOT
;
1308 else if (state
& LVIS_SELECTED
)
1310 if (::GetFocus() == m_hWnd
)
1311 txtState
= LISS_SELECTED
;
1313 txtState
= LISS_SELECTEDNOTFOCUS
;
1316 HTHEME hTheme
= nullptr;
1317 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
1318 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
1320 if (hTheme
&& IsThemeBackgroundPartiallyTransparent(hTheme
, LVP_LISTDETAIL
, txtState
))
1321 DrawThemeParentBackground(m_hWnd
, pLVCD
->nmcd
.hdc
, &rect
);
1324 HBRUSH brush
= ::CreateSolidBrush(pLVCD
->clrTextBk
);
1325 ::FillRect(pLVCD
->nmcd
.hdc
, rect
, brush
);
1326 ::DeleteObject(brush
);
1331 // get rect of whole line
1332 GetItemRect(index
, rt
, LVIR_BOUNDS
);
1334 if (txtState
== LISS_NORMAL
) // avoid drawing of grey borders
1335 rect2
.DeflateRect(1, 1, 1, 1);
1337 // calculate background for rect of whole line, but limit redrawing to SubItem rect
1338 DrawThemeBackground(hTheme
, pLVCD
->nmcd
.hdc
, LVP_LISTITEM
, txtState
, rt
, rect2
);
1340 CloseThemeData(hTheme
);
1342 // END: extended redraw
1344 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1346 std::vector
<REFLABEL
> refsToShow
;
1347 STRING_VECTOR remoteTrackingList
;
1348 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1349 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1351 CString str
= refList
[i
];
1354 refLabel
.color
= RGB(255, 255, 255);
1355 refLabel
.singleRemote
= false;
1356 refLabel
.hasTracking
= false;
1357 refLabel
.sameName
= false;
1358 refLabel
.annotatedTag
= false;
1359 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1361 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1363 if (refLabel
.name
== m_CurrentBranch
)
1364 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1366 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1368 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1369 CString pullRemote
= trackingEntry
.first
;
1370 CString pullBranch
= trackingEntry
.second
;
1371 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1373 CString defaultUpstream
;
1374 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), (LPCTSTR
)pullRemote
, (LPCTSTR
)pullBranch
);
1375 refLabel
.hasTracking
= true;
1376 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1379 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1381 if (refList
[j
] == defaultUpstream
)
1390 bool sameName
= pullBranch
== refLabel
.name
;
1391 refsToShow
.push_back(refLabel
);
1392 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1393 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1394 if (m_bSymbolizeRefNames
)
1396 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1398 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1399 refLabel
.singleRemote
= true;
1402 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1403 refLabel
.sameName
= sameName
;
1405 refsToShow
.push_back(refLabel
);
1406 remoteTrackingList
.push_back(defaultUpstream
);
1412 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1414 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1418 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1420 if (remoteTrackingList
[j
] == str
)
1429 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1430 if (m_bSymbolizeRefNames
)
1432 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1434 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1435 refLabel
.singleRemote
= true;
1439 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1441 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1443 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1444 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1446 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1448 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1450 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1451 refLabel
.name
= _T("stash");
1453 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1455 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1457 if (refLabel
.name
.Find(_T("good")) == 0)
1459 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1460 refLabel
.name
= _T("good");
1462 if (refLabel
.name
.Find(_T("bad")) == 0)
1464 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1465 refLabel
.name
= _T("bad");
1471 refsToShow
.push_back(refLabel
);
1474 if (refsToShow
.empty())
1476 *pResult
= CDRF_DODEFAULT
;
1480 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1482 *pResult
= CDRF_SKIPDEFAULT
;
1490 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1492 if(this->m_IsIDReplaceAction
)
1494 *pResult
= CDRF_DODEFAULT
;
1497 *pResult
= CDRF_DODEFAULT
;
1499 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1503 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1504 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1506 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1508 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1509 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1510 // Get the selected state of the
1511 // item being drawn.
1513 // Fill the background if necessary
1514 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1516 // Draw the icon(s) into the compatible DC
1517 int action
= pLogEntry
->GetAction(this);
1518 if (!pLogEntry
->m_IsDiffFiles
)
1520 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1521 *pResult
= CDRF_SKIPDEFAULT
;
1525 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1526 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1529 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1530 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1533 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1534 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1537 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1538 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1541 if (action
& CTGitPath::LOGACTIONS_UNMERGED
)
1542 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hConflictedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1545 *pResult
= CDRF_SKIPDEFAULT
;
1551 *pResult
= CDRF_DODEFAULT
;
1554 CString
FindSVNRev(const CString
& msg
)
1558 const std::tr1::wsregex_iterator end
;
1559 std::wstring s
= msg
;
1560 std::tr1::wregex
regex1(_T("^\\s*git-svn-id:\\s+(.*)\\@(\\d+)\\s([a-f\\d\\-]+)$"));
1561 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex1
); it
!= end
; ++it
)
1563 const std::tr1::wsmatch match
= *it
;
1564 if (match
.size() == 4)
1566 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[2]).c_str());
1567 return std::wstring(match
[2]).c_str();
1570 std::tr1::wregex
regex2(_T("^\\s*git-svn-id:\\s(\\d+)\\@([a-f\\d\\-]+)$"));
1571 for (std::tr1::wsregex_iterator
it(s
.begin(), s
.end(), regex2
); it
!= end
; ++it
)
1573 const std::tr1::wsmatch match
= *it
;
1574 if (match
.size() == 3)
1576 ATLTRACE(_T("matched rev: %s\n"), std::wstring(match
[1]).c_str());
1577 return std::wstring(match
[1]).c_str();
1581 catch (std::exception
) {}
1586 CString
CGitLogListBase::MessageDisplayStr(GitRev
* pLogEntry
)
1588 if (!m_bFullCommitMessageOnLogLine
|| pLogEntry
->GetBody().IsEmpty())
1589 return pLogEntry
->GetSubject();
1592 txt
.Format(L
"%s %s", (LPCTSTR
)pLogEntry
->GetSubject(), (LPCTSTR
)pLogEntry
->GetBody());
1595 txt
.Replace(_T("\n"), _T(" "));
1596 txt
.Replace(_T("\r"), _T(" "));
1601 // CGitLogListBase message handlers
1603 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1605 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1607 // Create a pointer to the item
1608 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1610 // Do the list need text information?
1611 if (!(pItem
->mask
& LVIF_TEXT
))
1614 // By default, clear text buffer.
1615 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
- 1);
1617 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1620 if (m_bNoDispUpdates
|| bOutOfRange
)
1623 // Which item number?
1624 int itemid
= pItem
->iItem
;
1625 GitRevLoglist
* pLogEntry
= nullptr;
1626 if (itemid
< m_arShownList
.GetCount())
1627 pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1632 temp
.Format(_T("%d"),pItem
->iItem
+1);
1637 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1641 switch (pItem
->iSubItem
)
1643 case LOGLIST_GRAPH
: //Graphic
1645 case LOGLIST_REBASE
:
1647 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1648 lstrcpyn(pItem
->pszText
, GetRebaseActionName(pLogEntry
->GetRebaseAction() & LOGACTIONS_REBASE_MODE_MASK
), pItem
->cchTextMax
- 1);
1651 case LOGLIST_ACTION
: //action -- no text in the column
1655 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
- 1);
1658 if(this->m_IsIDReplaceAction
)
1659 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
- 1);
1661 case LOGLIST_MESSAGE
: //Message
1663 lstrcpyn(pItem
->pszText
, (LPCTSTR
)MessageDisplayStr(pLogEntry
), pItem
->cchTextMax
- 1);
1665 case LOGLIST_AUTHOR
: //Author
1667 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
- 1);
1669 case LOGLIST_DATE
: //Date
1670 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1671 lstrcpyn(pItem
->pszText
,
1672 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1673 pItem
->cchTextMax
- 1);
1678 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
- 1);
1681 case LOGLIST_COMMIT_NAME
: //Commit
1683 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
- 1);
1686 case LOGLIST_COMMIT_EMAIL
: //Commit Email
1688 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
- 1);
1691 case LOGLIST_COMMIT_DATE
: //Commit Date
1692 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1693 lstrcpyn(pItem
->pszText
,
1694 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1695 pItem
->cchTextMax
- 1);
1697 case LOGLIST_BUG
: //Bug ID
1699 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1701 case LOGLIST_SVNREV
: //SVN revision
1703 lstrcpyn(pItem
->pszText
, (LPCTSTR
)FindSVNRev(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
- 1);
1711 bool CGitLogListBase::IsOnStash(int index
)
1713 GitRevLoglist
* rev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
));
1718 GitRevLoglist
* preRev
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(index
- 1));
1719 if (IsStash(preRev
))
1720 return preRev
->m_ParentHash
.size() == 2 && preRev
->m_ParentHash
[1] == rev
->m_CommitHash
;
1725 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1727 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1729 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1735 void CGitLogListBase::GetParentHashes(GitRev
*pRev
, GIT_REV_LIST
&parentHash
)
1737 if (pRev
->m_ParentHash
.empty())
1739 if (pRev
->GetParentFromHash(pRev
->m_CommitHash
))
1740 MessageBox(pRev
->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR
);
1742 parentHash
= pRev
->m_ParentHash
;
1745 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1748 if (pWnd
== GetHeaderCtrl())
1750 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1753 int selIndex
= GetSelectionMark();
1755 return; // nothing selected, nothing to do with a context menu
1757 // if the user selected the info text telling about not all revisions shown due to
1758 // the "stop on copy/rename" option, we also don't show the context menu
1759 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1762 // if the context menu is invoked through the keyboard, we have to use
1763 // a calculated position on where to anchor the menu on
1764 if ((point
.x
== -1) && (point
.y
== -1))
1767 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1768 ClientToScreen(&rect
);
1769 point
= rect
.CenterPoint();
1771 m_nSearchIndex
= selIndex
;
1772 m_bCancelled
= FALSE
;
1774 // calculate some information the context menu commands can use
1775 // CString pathURL = GetURLFromPath(m_path);
1777 POSITION pos
= GetFirstSelectedItemPosition();
1778 int indexNext
= GetNextSelectedItem(pos
);
1782 GitRevLoglist
* pSelLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(indexNext
));
1783 if (pSelLogEntry
== nullptr)
1786 GitRev revSelected
= pSelLogEntry
->Rev
;
1787 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1788 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1790 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1792 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1793 if (changedpath
->lCopyFromRev
)
1794 revPrevious
= changedpath
->lCopyFromRev
;
1797 GitRev revSelected2
;
1800 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1801 revSelected2
= pLogEntry
->Rev
;
1803 bool bAllFromTheSameAuthor
= true;
1804 CString firstAuthor
;
1805 CLogDataVector selEntries
;
1806 GitRev revLowest
, revHighest
;
1807 GitRevRangeArray revisionRanges
;
1809 POSITION pos
= GetFirstSelectedItemPosition();
1810 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1811 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1812 selEntries
.push_back(pLogEntry
);
1813 firstAuthor
= pLogEntry
->sAuthor
;
1814 revLowest
= pLogEntry
->Rev
;
1815 revHighest
= pLogEntry
->Rev
;
1818 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1819 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1820 selEntries
.push_back(pLogEntry
);
1821 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1822 bAllFromTheSameAuthor
= false;
1823 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1824 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1830 bool showExtendedMenu
= (GetAsyncKeyState(VK_SHIFT
) & 0x8000) != 0;
1832 int FirstSelect
=-1, LastSelect
=-1;
1833 pos
= GetFirstSelectedItemPosition();
1834 FirstSelect
= GetNextSelectedItem(pos
);
1837 LastSelect
= GetNextSelectedItem(pos
);
1839 //entry is selected, now show the popup menu
1841 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, blamemenu
, revertmenu
;
1843 if (popup
.CreatePopupMenu())
1845 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1846 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1847 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1848 bool isStash
= IsOnStash(indexNext
);
1849 GIT_REV_LIST parentHash
;
1850 GetParentHashes(pSelLogEntry
, parentHash
);
1852 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_PICK
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1853 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1855 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SQUASH
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)) && FirstSelect
!= GetItemCount() - 1 && LastSelect
!= GetItemCount() - 1)
1856 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1858 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_EDIT
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1859 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1861 if (m_ContextMenuMask
& GetContextMenuBit(ID_REBASE_SKIP
) && !(pSelLogEntry
->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT
| LOGACTIONS_REBASE_DONE
)))
1862 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1864 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
)))
1865 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1867 if (GetSelectedCount() == 1)
1870 bool requiresSeparator
= false;
1871 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1873 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1875 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1876 requiresSeparator
= true;
1881 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1883 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1884 requiresSeparator
= true;
1886 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1888 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1889 requiresSeparator
= true;
1893 if (m_ContextMenuMask
& GetContextMenuBit(ID_BLAMEPREVIOUS
))
1895 if (parentHash
.size() == 1)
1897 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
);
1898 requiresSeparator
= true;
1900 else if (parentHash
.size() > 1)
1902 blamemenu
.CreatePopupMenu();
1903 popup
.AppendMenuIcon(ID_BLAMEPREVIOUS
, IDS_LOG_POPUP_BLAMEPREVIOUS
, IDI_BLAME
, blamemenu
.m_hMenu
);
1904 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1907 str
.Format(IDS_PARENT
, i
+ 1);
1908 blamemenu
.AppendMenuIcon(ID_BLAMEPREVIOUS
+((i
+ 1) << 16), str
);
1910 requiresSeparator
= true;
1914 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1916 if (parentHash
.size() == 1)
1918 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1919 requiresSeparator
= true;
1921 else if (parentHash
.size() > 1)
1923 gnudiffmenu
.CreatePopupMenu();
1924 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1926 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1927 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1928 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFD << 16)), CString(MAKEINTRESOURCE(IDS_DIFFWITHMERGE
)));
1930 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1933 str
.Format(IDS_PARENT
, i
+ 1);
1934 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1936 requiresSeparator
= true;
1940 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1942 if (parentHash
.size() == 1)
1944 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1945 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1946 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1947 requiresSeparator
= true;
1949 else if (parentHash
.size() > 1)
1951 diffmenu
.CreatePopupMenu();
1952 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1953 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
1956 str
.Format(IDS_PARENT
, i
+ 1);
1957 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1958 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1960 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1961 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1964 requiresSeparator
= true;
1968 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1970 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1971 requiresSeparator
= true;
1974 if (requiresSeparator
)
1975 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1977 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1979 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1980 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1983 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1985 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1986 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1988 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1989 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1991 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1994 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1996 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && !isMergeActive
)
1997 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
1999 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
2000 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
2002 if (CTGitPath(g_Git
.m_CurrentDir
).HasSubmodules() && m_ContextMenuMask
& GetContextMenuBit(ID_SUBMODULE_UPDATE
))
2003 popup
.AppendMenuIcon(ID_SUBMODULE_UPDATE
, IDS_PROC_SYNC_SUBKODULEUPDATE
, IDI_UPDATE
);
2005 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2007 if (m_ContextMenuMask
& GetContextMenuBit(ID_CLEANUP
))
2008 popup
.AppendMenuIcon(ID_CLEANUP
, IDS_MENUCLEANUP
, IDI_CLEANUP
);
2010 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2014 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
2016 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
2018 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2020 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2022 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
2023 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
2025 // popup.AppendMenu(MF_SEPARATOR, NULL);
2030 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
2032 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
2034 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
2035 GetSelectedCount() == 1)
2036 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
2038 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
2039 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
2041 str
.Format(IDS_LOG_POPUP_MERGEREV
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2043 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2044 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
2046 str
.Format(IDS_RESET_TO_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2048 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
2049 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
2052 // Add Switch Branch express Menu
2053 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
2054 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
2057 std::vector
<CString
*> branchs
;
2058 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2060 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
2061 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
2063 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2068 str2
.LoadString(IDS_SWITCH_BRANCH
);
2070 if(branchs
.size() == 1)
2073 str2
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
2074 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
);
2076 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
2079 else if(branchs
.size() > 1)
2081 subbranchmenu
.CreatePopupMenu();
2082 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
2084 if (*branchs
[i
] != currentBranch
)
2086 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
2087 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
2091 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str2
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
2095 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
2096 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
2098 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
2099 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
2101 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
2102 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
2104 str
.Format(IDS_REBASE_THIS_FORMAT
, (LPCTSTR
)g_Git
.GetCurrentBranch());
2106 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
2107 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
2108 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
2110 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
2111 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
2113 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
2115 if (parentHash
.size() == 1)
2117 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
2119 else if (parentHash
.size() > 1)
2121 revertmenu
.CreatePopupMenu();
2122 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
2124 for (size_t i
= 0; i
< parentHash
.size(); ++i
)
2127 str2
.Format(IDS_PARENT
, i
+ 1);
2128 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str2
);
2133 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
2134 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
2136 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2141 if(!pSelLogEntry
->m_Ref
.IsEmpty())
2143 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
2144 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
2145 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
2146 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2149 if (GetSelectedCount() >= 2)
2151 bool bAddSeparator
= false;
2152 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
2154 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
2155 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
2158 if (GetSelectedCount() == 2)
2160 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
2161 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
2163 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
2165 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2166 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2167 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
2169 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("..") + firstSelHash
));
2170 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
2171 menu
.Format(IDS_SHOWLOG_OF
, (LPCTSTR
)(lastSelHash
+ _T("...") + firstSelHash
));
2172 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
2175 bAddSeparator
= true;
2180 bAddSeparator
= true;
2183 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
2184 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
2187 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2190 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
2192 bool bAddSeparator
= false;
2193 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
2195 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2199 headindex
= this->GetHeadIndex();
2200 if(headindex
>=0 && LastSelect
>= headindex
&& FirstSelect
>= headindex
)
2202 head
.Format(_T("HEAD~%d"), FirstSelect
- headindex
);
2204 if (g_Git
.GetHash(hashFirst
, head
))
2205 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2206 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2208 if (g_Git
.GetHash(hash
, head
))
2209 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2210 GitRevLoglist
* pFirstEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(FirstSelect
));
2211 GitRevLoglist
* pLastEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(LastSelect
));
2212 if (pFirstEntry
->m_CommitHash
== hashFirst
&& pLastEntry
->m_CommitHash
== hash
) {
2213 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2214 bAddSeparator
= true;
2219 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2220 if (GetSelectedCount() >= 2)
2221 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2223 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2224 bAddSeparator
= true;
2227 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2228 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2229 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2230 bAddSeparator
= true;
2234 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2237 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())
2239 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
, IDI_BISECT
);
2240 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2243 if (GetSelectedCount() == 1)
2245 bool bAddSeparator
= false;
2246 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && ((!isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty()) || showExtendedMenu
))
2248 // show the push-option only if the log entry has an associated local branch
2249 bool isLocal
= false;
2250 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2252 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2255 if (isLocal
|| showExtendedMenu
)
2257 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2258 bAddSeparator
= true;
2261 if (m_ContextMenuMask
& GetContextMenuBit(ID_PULL
) && isHeadCommit
&& !isMergeActive
&& m_hasWC
)
2263 popup
.AppendMenuIcon(ID_PULL
, IDS_MENUPULL
, IDI_PULL
);
2264 bAddSeparator
= true;
2268 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2270 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2272 std::vector
<CString
*> branchs
;
2273 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2275 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2276 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2279 if (branchs
.size() == 1)
2281 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2284 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2285 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2286 bAddSeparator
= true;
2288 else if (branchs
.size() > 1)
2290 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2291 submenu
.CreatePopupMenu();
2292 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2294 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2295 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2298 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2299 bAddSeparator
= true;
2302 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2304 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2305 } // GetSelectedCount() == 1
2307 if (GetSelectedCount() != 0)
2309 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2310 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2311 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2312 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2313 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2314 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2317 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2318 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2320 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2321 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2323 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2324 // DialogEnableWindow(IDOK, FALSE);
2325 // SetPromptApp(&theApp);
2327 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2329 // EnableOKButton();
2330 } // if (popup.CreatePopupMenu())
2334 bool CGitLogListBase::IsSelectionContinuous()
2336 if ( GetSelectedCount()==1 )
2338 // if only one revision is selected, the selection is of course
2343 POSITION pos
= GetFirstSelectedItemPosition();
2344 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2347 int itemindex
= GetNextSelectedItem(pos
);
2350 int nextindex
= GetNextSelectedItem(pos
);
2351 if (nextindex
- itemindex
> 1)
2353 bContinuous
= false;
2356 itemindex
= nextindex
;
2362 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2366 POSITION pos
= GetFirstSelectedItemPosition();
2370 sRev
.LoadString(IDS_LOG_REVISION
);
2372 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2374 sDate
.LoadString(IDS_LOG_DATE
);
2376 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2380 CString sLogCopyText
;
2382 GitRevLoglist
* pLogEntry
= reinterpret_cast<GitRevLoglist
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2384 if (toCopy
== ID_COPY_ALL
)
2386 //pLogEntry->GetFiles(this)
2387 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2389 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2390 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2392 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2393 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2396 rename
.Format(from
, (LPCTSTR
)((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2397 sPaths
+= _T(" ") + rename
;
2399 sPaths
+= _T("\r\n");
2402 CString body
= pLogEntry
->GetBody();
2403 body
.Replace(_T("\n"), _T("\r\n"));
2404 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"),
2405 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2406 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2408 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2409 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2411 sClipdata
+= sLogCopyText
;
2413 else if (toCopy
== ID_COPY_MESSAGE
)
2415 CString body
= pLogEntry
->GetBody();
2416 body
.Replace(_T("\n"), _T("\r\n"));
2417 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2419 else if (toCopy
== ID_COPY_SUBJECT
)
2421 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2426 sClipdata
+= _T("\r\n");
2427 sClipdata
+= pLogEntry
->m_CommitHash
;
2432 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2437 void CGitLogListBase::DiffSelectedRevWithPrevious()
2439 if (m_bThreadRunning
)
2442 int FirstSelect
=-1, LastSelect
=-1;
2443 POSITION pos
= GetFirstSelectedItemPosition();
2444 FirstSelect
= GetNextSelectedItem(pos
);
2447 LastSelect
= GetNextSelectedItem(pos
);
2450 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2453 UpdateLogInfoLabel();
2454 int selIndex
= m_LogList
.GetSelectionMark();
2457 int selCount
= m_LogList
.GetSelectedCount();
2461 // Find selected entry in the log list
2462 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2463 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2464 long rev1
= pLogEntry
->Rev
;
2466 CTGitPath path
= m_path
;
2468 // See how many files under the relative root were changed in selected revision
2470 LogChangedPath
* changed
= NULL
;
2471 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2473 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2474 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2481 if (m_path
.IsDirectory() && nChanged
== 1)
2483 // We're looking at the log for a directory and only one file under dir was changed in the revision
2484 // Do diff on that file instead of whole directory
2485 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2488 m_bCancelled
= FALSE
;
2489 DialogEnableWindow(IDOK
, FALSE
);
2490 SetPromptApp(&theApp
);
2491 theApp
.DoWaitCursor(1);
2495 GitDiff
diff(this, m_hWnd
, true);
2496 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2497 diff
.SetHEADPeg(m_LogRevision
);
2498 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2502 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2505 theApp
.DoWaitCursor(-1);
2510 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2512 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2515 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2517 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2519 if (pFindInfo
->lvfi
.psz
== 0)
2522 CString sCmp
= pFindInfo
->lvfi
.psz
;
2524 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2526 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2527 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2528 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2530 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2538 if (sCmp
.Compare(sRev
)==0)
2545 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2547 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2549 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2550 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2551 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2553 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2561 if (sCmp
.Compare(sRev
)==0)
2573 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2577 this->m_arShownList
.SafeRemoveAll();
2579 this->m_logEntries
.ClearAll();
2580 if (this->m_logEntries
.ParserFromLog(path
, 0, info
, range
))
2583 SetItemCountEx((int)m_logEntries
.size());
2585 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2589 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2590 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2595 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2596 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2608 int CGitLogListBase::FillGitLog(std::set
<CGitHash
>& hashes
)
2612 m_arShownList
.SafeRemoveAll();
2614 m_logEntries
.ClearAll();
2615 if (m_logEntries
.Fill(hashes
))
2618 SetItemCountEx((int)m_logEntries
.size());
2620 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2624 m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1).m_IsFull
= TRUE
;
2625 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size() - i
- 1));
2629 m_logEntries
.GetGitRevAt(i
).m_IsFull
= TRUE
;
2630 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2639 int CGitLogListBase::BeginFetchLog()
2643 this->m_arShownList
.SafeRemoveAll();
2645 this->m_logEntries
.ClearAll();
2647 this->m_LogCache
.ClearAllParent();
2649 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2652 if(this->m_Path
.IsEmpty())
2658 mask
= CGit::LOG_INFO_ONLY_HASH
;
2659 if (m_bIncludeBoundaryCommits
)
2660 mask
|= CGit::LOG_INFO_BOUNDARY
;
2661 // if(this->m_bAllBranch)
2662 mask
|= m_ShowMask
;
2666 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2668 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2671 if (m_sRange
.IsEmpty())
2672 m_sRange
= _T("HEAD");
2674 #if 0 /* use tortoiegit filter */
2675 if (this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2676 data
.m_Author
= this->m_sFilterText
;
2678 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2679 data
.m_MessageFilter
= this->m_sFilterText
;
2681 data
.m_IsRegex
= m_bFilterWithRegex
;
2684 // follow does not work for directories
2685 if (!path
|| path
->IsDirectory())
2686 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2687 // follow does not work with all branches 8at least in TGit)
2688 if (mask
& CGit::LOG_INFO_FOLLOW
)
2689 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
| CGit::LOG_INFO_LOCAL_BRANCHES
;
2691 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, mask
, true, &m_Filter
);
2693 //this->m_logEntries.ParserFromLog();
2694 if(IsInWorkingThread())
2696 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2700 SetItemCountEx((int)m_logEntries
.size());
2705 [] { git_init(); } ();
2710 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2714 if (!g_Git
.CanParseRev(m_sRange
))
2716 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
) && !(mask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2719 // if show all branches, pick any ref as dummy entry ref
2721 if (g_Git
.GetRefList(list
))
2722 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2723 if (list
.size() == 0)
2726 cmd
= g_Git
.GetLogCmd(list
[0], path
, mask
, true, &m_Filter
);
2729 g_Git
.m_critGitDllSec
.Lock();
2731 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2733 g_Git
.m_critGitDllSec
.Unlock();
2739 g_Git
.m_critGitDllSec
.Unlock();
2741 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2744 g_Git
.m_critGitDllSec
.Unlock();
2749 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2751 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2753 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2755 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2757 DiffSelectedRevWithPrevious();
2762 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2769 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2771 // select all entries
2772 for (int i
=0; i
<GetItemCount(); ++i
)
2774 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2780 if (m_hAccel
&& !bSkipAccelerator
)
2782 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2788 //m_tooltips.RelayEvent(pMsg);
2789 return __super::PreTranslateMessage(pMsg
);
2792 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2794 // a double click on an entry in the revision list has happened
2797 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2798 DiffSelectedRevWithPrevious();
2801 int CGitLogListBase::FetchLogAsync(void * data
)
2805 m_bExitThread
=FALSE
;
2806 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2807 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2808 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2809 if (m_LoadingThread
==NULL
)
2811 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2812 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2813 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2819 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2821 return ((CGitLogListBase
*)pVoid
)->LogThread();
2824 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2827 oldest
=CTime::GetCurrentTime();
2828 latest
=CTime(1971,1,2,0,0,0);
2829 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2831 if(m_logEntries
[i
].IsEmpty())
2834 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() < oldest
.GetTime())
2835 oldest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2837 if (m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime() > latest
.GetTime())
2838 latest
= m_logEntries
.GetGitRevAt(i
).GetCommitterDate().GetTime();
2846 UINT
CGitLogListBase::LogThread()
2848 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2850 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2851 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2857 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2858 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2863 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2864 bool bRegex
= false;
2865 if (m_bFilterWithRegex
)
2866 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2868 TRACE(_T("\n===Begin===\n"));
2869 //Update work copy item;
2871 if (!m_logEntries
.empty())
2873 GitRevLoglist
* pRev
= &m_logEntries
.GetGitRevAt(0);
2875 m_arShownList
.SafeAdd(pRev
);
2879 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2881 // store commit number of the last selected commit/line before the refresh or -1
2882 int lastSelectedHashNItem
= -1;
2883 if (m_lastSelectedHash
.IsEmpty())
2884 lastSelectedHashNItem
= 0;
2888 bool shouldWalk
= true;
2889 if (!g_Git
.CanParseRev(m_sRange
))
2891 // walk revisions if show all branches and there exists any ref
2892 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
) && !(m_ShowMask
& CGit::LOG_INFO_LOCAL_BRANCHES
))
2897 if (g_Git
.GetRefList(list
))
2898 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2899 if (list
.size() == 0)
2906 g_Git
.m_critGitDllSec
.Lock();
2910 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2911 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2916 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2919 g_Git
.m_critGitDllSec
.Unlock();
2922 t2
=t1
=GetTickCount();
2923 int oldprecentage
= 0;
2924 size_t oldsize
= m_logEntries
.size();
2925 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2926 while (ret
== 0 && !m_bExitThread
)
2928 g_Git
.m_critGitDllSec
.Lock();
2931 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2935 g_Git
.m_critGitDllSec
.Unlock();
2937 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2940 g_Git
.m_critGitDllSec
.Unlock();
2944 if (ret
!= -2) // other than end of revision walking
2945 MessageBox((_T("Could not get next commit.\nlibgit returns:") + std::to_wstring(ret
)).c_str(), _T("TortoiseGit"), MB_ICONERROR
);
2949 if (commit
.m_ignore
== 1)
2951 git_free_commit(&commit
);
2955 //printf("%s\r\n",commit.GetSubject());
2959 CGitHash hash
= (char*)commit
.m_hash
;
2961 GitRevLoglist
* pRev
= m_LogCache
.GetCacheData(hash
);
2962 pRev
->m_GitCommit
= commit
;
2963 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2966 g_Git
.m_critGitDllSec
.Lock();
2969 git_get_notes(commit
.m_hash
, ¬e
);
2973 g_Git
.m_critGitDllSec
.Unlock();
2975 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2978 g_Git
.m_critGitDllSec
.Unlock();
2982 pRev
->m_Notes
= CUnicodeUtils::GetUnicode(note
);
2987 if(!pRev
->m_IsDiffFiles
)
2989 pRev
->m_CallDiffAsync
= DiffAsync
;
2992 pRev
->ParserParentFromCommit(&commit
);
2993 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2995 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2997 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2998 auto it
= commitChildren
.find(parentHash
);
2999 if (it
== commitChildren
.end())
3001 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
3003 it
->second
.insert(pRev
->m_CommitHash
);
3012 bool visible
= true;
3013 if (HasFilterText())
3015 if(!IsMatchFilter(bRegex
,pRev
,pat
))
3018 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
3020 this->m_critSec
.Lock();
3021 m_logEntries
.append(hash
, visible
);
3023 m_arShownList
.SafeAdd(pRev
);
3024 this->m_critSec
.Unlock();
3029 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
3030 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
3034 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
3037 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
3040 if(percent
< GITLOG_START
)
3041 percent
= GITLOG_START
+1;
3043 oldsize
= m_logEntries
.size();
3044 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3046 //if( percent > oldprecentage )
3048 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
3049 oldprecentage
= percent
;
3052 if (lastSelectedHashNItem
>= 0)
3053 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3058 g_Git
.m_critGitDllSec
.Lock();
3059 git_close_log(m_DllGitLog
);
3060 g_Git
.m_critGitDllSec
.Unlock();
3066 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3071 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
3073 if (lastSelectedHashNItem
>= 0)
3074 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
3077 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
3079 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3084 void CGitLogListBase::FetchRemoteList()
3086 STRING_VECTOR remoteList
;
3087 if (!g_Git
.GetRemoteList(remoteList
))
3088 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
3090 m_SingleRemote
= _T("");
3093 void CGitLogListBase::FetchTrackingBranchList()
3095 m_TrackingMap
.clear();
3096 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
3098 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
3101 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
3103 CString pullRemote
, pullBranch
;
3104 g_Git
.GetRemoteTrackedBranch(branchName
, pullRemote
, pullBranch
);
3105 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
3107 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
3114 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
3116 SafeTerminateThread();
3118 this->SetItemCountEx(0);
3123 // HACK to hide graph column
3124 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
3125 SetColumnWidth(0, 0);
3127 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3129 //Update branch and Tag info
3132 m_pFindDialog
->RefreshList();
3133 //Assume Thread have exited
3134 //if(!m_bThreadRunning)
3136 m_logEntries
.clear();
3140 m_sFilterText
.Empty();
3143 InterlockedExchange(&m_bExitThread
,FALSE
);
3145 InterlockedExchange(&m_bThreadRunning
, TRUE
);
3146 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3147 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
3149 InterlockedExchange(&m_bThreadRunning
, FALSE
);
3150 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3151 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
3155 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
3159 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
3161 type
|= std::tr1::regex_constants::icase
;
3162 pat
= std::tr1::wregex(regexp_str
, type
);
3165 catch (std::exception
) {}
3168 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRevLoglist
* pRev
, std::tr1::wregex
& pat
)
3171 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3174 if ((bRegex
)&&(m_bFilterWithRegex
))
3176 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3178 if(this->m_bShowBugtraqColumn
)
3180 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3182 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)sBugIds
);
3183 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
3190 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3192 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetSubject());
3193 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
3199 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3201 ATLTRACE(_T("messge = \"%s\"\n"), (LPCTSTR
)pRev
->GetBody());
3202 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
3208 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3210 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
3215 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
3221 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3223 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
3228 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
3234 if (m_SelectedFilters
& LOGFILTER_REVS
)
3236 sRev
= pRev
->m_CommitHash
.ToString();
3237 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3243 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3245 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3246 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3248 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3255 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3257 CTGitPathList
*pathList
=NULL
;
3258 if( pRev
->m_IsDiffFiles
)
3259 pathList
= &pRev
->GetFiles(this);
3262 if(!pRev
->m_IsSimpleListReady
)
3263 pRev
->SafeGetSimpleList(&g_Git
);
3267 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3269 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3273 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3279 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3281 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3290 CString find
= m_sFilterText
;
3291 if (!m_bFilterCaseSensitively
)
3293 result
= find
[0] == '!' ? FALSE
: TRUE
;
3297 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3299 if(this->m_bShowBugtraqColumn
)
3301 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3303 if (!m_bFilterCaseSensitively
)
3304 sBugIds
.MakeLower();
3305 if ((sBugIds
.Find(find
) >= 0))
3312 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3314 CString msg
= pRev
->GetSubject();
3316 if (!m_bFilterCaseSensitively
)
3317 msg
= msg
.MakeLower();
3318 if ((msg
.Find(find
) >= 0))
3324 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3326 CString msg
= pRev
->GetBody();
3328 if (!m_bFilterCaseSensitively
)
3329 msg
= msg
.MakeLower();
3330 if ((msg
.Find(find
) >= 0))
3336 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3338 CString msg
= pRev
->GetAuthorName();
3339 if (!m_bFilterCaseSensitively
)
3340 msg
= msg
.MakeLower();
3341 if ((msg
.Find(find
) >= 0))
3347 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3349 CString msg
= pRev
->GetAuthorEmail();
3350 if (!m_bFilterCaseSensitively
)
3351 msg
= msg
.MakeLower();
3352 if ((msg
.Find(find
) >= 0))
3358 if (m_SelectedFilters
& LOGFILTER_REVS
)
3360 sRev
= pRev
->m_CommitHash
.ToString();
3361 if ((sRev
.Find(find
) >= 0))
3367 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3369 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3370 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3372 if (it
->Find(find
) >= 0)
3379 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3381 CTGitPathList
*pathList
=NULL
;
3382 if( pRev
->m_IsDiffFiles
)
3383 pathList
= &pRev
->GetFiles(this);
3386 if(!pRev
->m_IsSimpleListReady
)
3387 pRev
->SafeGetSimpleList(&g_Git
);
3390 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3392 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3393 CString path
= cpath
->GetGitOldPathString();
3394 if (!m_bFilterCaseSensitively
)
3396 if ((path
.Find(find
)>=0))
3400 path
= cpath
->GetGitPathString();
3401 if (!m_bFilterCaseSensitively
)
3403 if ((path
.Find(find
)>=0))
3409 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3411 CString path
= pRev
->m_SimpleFileList
[i
];
3412 if (!m_bFilterCaseSensitively
)
3414 if ((path
.Find(find
)>=0))
3420 } // else (from if (bRegex))
3424 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3426 return str
.Left(prefix
.GetLength()) == prefix
;
3428 bool CGitLogListBase::ShouldShowFilter(GitRevLoglist
* pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>>& commitChildren
)
3430 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3433 if (m_ShowFilter
& FILTERSHOW_REFS
)
3436 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3437 for (size_t i
= 0; i
< refList
.size(); ++i
)
3439 const CString
&str
= refList
[i
];
3440 if (CStringStartsWith(str
, _T("refs/heads/")))
3442 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3445 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3447 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3450 else if (CStringStartsWith(str
, _T("refs/tags/")))
3452 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3455 else if (CStringStartsWith(str
, _T("refs/stash")))
3457 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3460 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3462 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3466 // Keep the head too.
3467 if (pRev
->m_CommitHash
== m_HeadHash
)
3471 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3473 if (pRev
->ParentsCount() > 1)
3475 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3476 if (childrenIt
!= commitChildren
.end())
3478 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3479 if (children
.size() > 1)
3486 void CGitLogListBase::ShowGraphColumn(bool bShow
)
3488 // HACK to hide graph column
3490 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3492 SetColumnWidth(0, 0);
3495 CString
CGitLogListBase::GetTagInfo(GitRev
* pLogEntry
)
3500 if (m_HashMap
.find(pLogEntry
->m_CommitHash
) != m_HashMap
.end())
3502 STRING_VECTOR
&vector
= m_HashMap
[pLogEntry
->m_CommitHash
];
3503 for (size_t i
= 0; i
< vector
.size(); ++i
)
3505 if (vector
[i
].Find(_T("refs/tags/")) == 0)
3507 CString tag
= vector
[i
];
3508 int start
= vector
[i
].Find(_T("^{}"));
3510 tag
= tag
.Left(start
);
3514 cmd
.Format(_T("git.exe cat-file tag %s"), (LPCTSTR
)tag
);
3515 if (g_Git
.Run(cmd
, &output
, nullptr, CP_UTF8
) == 0)
3516 output
.AppendChar(_T('\n'));
3524 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3527 pShownlist
->SafeRemoveAll();
3529 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3530 bool bRegex
= false;
3531 if (m_bFilterWithRegex
)
3532 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3534 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3536 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3538 if ((bRegex
)&&(m_bFilterWithRegex
))
3541 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3543 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3544 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3546 pShownlist
->SafeAdd(m_logEntries
[i
]);
3551 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3553 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3554 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3556 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3560 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3562 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3563 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3565 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3569 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3571 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3574 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3576 CTGitPath cpath
= pathList
[cpPathIndex
];
3577 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3579 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3583 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3585 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3589 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3591 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3597 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3599 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3601 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3605 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3607 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3609 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3613 if (m_SelectedFilters
& LOGFILTER_REVS
)
3615 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3616 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3618 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3622 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3624 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3625 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3627 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3629 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3637 CString find
= m_sFilterText
;
3638 if (!m_bFilterCaseSensitively
)
3641 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3643 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3645 if (!m_bFilterCaseSensitively
)
3646 sBugIDs
= sBugIDs
.MakeLower();
3647 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3649 pShownlist
->SafeAdd(m_logEntries
[i
]);
3654 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3656 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3658 if (!m_bFilterCaseSensitively
)
3659 msg
= msg
.MakeLower();
3660 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3662 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3666 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3668 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3670 if (!m_bFilterCaseSensitively
)
3671 msg
= msg
.MakeLower();
3672 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3674 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3678 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3680 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3683 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3685 CTGitPath cpath
= pathList
[cpPathIndex
];
3686 CString path
= cpath
.GetGitOldPathString();
3687 if (!m_bFilterCaseSensitively
)
3689 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3691 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3695 path
= cpath
.GetGitPathString();
3696 if (!m_bFilterCaseSensitively
)
3698 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3700 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3704 path
= cpath
.GetActionName();
3705 if (!m_bFilterCaseSensitively
)
3707 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3709 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3715 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3717 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3718 if (!m_bFilterCaseSensitively
)
3719 msg
= msg
.MakeLower();
3720 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3722 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3726 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3728 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3729 if (!m_bFilterCaseSensitively
)
3730 msg
= msg
.MakeLower();
3731 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3733 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3737 if (m_SelectedFilters
& LOGFILTER_REVS
)
3739 sRev
= m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString();
3740 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3742 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3746 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3748 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3749 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3751 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3753 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3758 } // else (from if (bRegex))
3759 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3763 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3766 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3772 return time <= m_To;
3775 return time >= m_From;
3777 return ((time >= m_From)&&(time <= m_To));
3779 return TRUE
; /* git dll will filter time range */
3783 void CGitLogListBase::StartFilter()
3785 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3786 RecalculateShownList(&m_arShownList
);
3787 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3791 SetItemCountEx(ShownCountWithStopped());
3792 RedrawItems(0, ShownCountWithStopped());
3796 void CGitLogListBase::RemoveFilter()
3799 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3801 m_arShownList
.SafeRemoveAll();
3803 // reset the time filter too
3805 m_timFrom
= (__time64_t(m_tFrom
));
3806 m_timTo
= (__time64_t(m_tTo
));
3807 m_DateFrom
.SetTime(&m_timFrom
);
3808 m_DateTo
.SetTime(&m_timTo
);
3809 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3810 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3813 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3815 if(this->m_IsOldFirst
)
3817 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3821 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3824 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3826 SetItemCountEx(ShownCountWithStopped());
3827 RedrawItems(0, ShownCountWithStopped());
3829 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3832 void CGitLogListBase::Clear()
3834 m_arShownList
.SafeRemoveAll();
3837 m_logEntries
.ClearAll();
3841 void CGitLogListBase::OnDestroy()
3843 // save the column widths to the registry
3846 SafeTerminateThread();
3847 SafeTerminateAsyncDiffThread();
3850 while(m_LogCache
.SaveCache())
3858 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3859 // MB_YESNO) == IDNO)
3863 CHintListCtrl::OnDestroy();
3866 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3870 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3871 this->InvalidateRect(rect
);
3877 * Save column widths to the registry
3879 void CGitLogListBase::SaveColumnWidths()
3881 int maxcol
= m_ColumnManager
.GetColumnCount();
3883 // HACK that graph column is always shown
3884 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3886 for (int col
= 0; col
< maxcol
; ++col
)
3887 if (m_ColumnManager
.IsVisible (col
))
3888 m_ColumnManager
.ColumnResized (col
);
3890 m_ColumnManager
.WriteSettings();
3893 int CGitLogListBase::GetHeadIndex()
3895 if(m_HeadHash
.IsEmpty())
3898 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3900 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3903 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3909 void CGitLogListBase::OnFind()
3913 m_pFindDialog
= new CFindDlg(this);
3914 m_pFindDialog
->Create(this);
3917 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3919 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3921 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3923 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3926 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3928 if (GetSelectedCount() != 0)
3931 CGitHash theSelectedHash
= m_lastSelectedHash
;
3932 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3933 m_lastSelectedHash
= theSelectedHash
;
3935 int countPerPage
= GetCountPerPage();
3936 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3937 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3938 EnsureVisible((int)itemToSelect
, FALSE
);
3941 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3944 ASSERT(m_pFindDialog
!= NULL
);
3945 bool bFound
= false;
3948 if (m_pFindDialog
->IsTerminating())
3950 // invalidate the handle identifying the dialog box.
3951 m_pFindDialog
= NULL
;
3955 INT_PTR cnt
= m_arShownList
.GetCount();
3957 if(m_pFindDialog
->IsRef())
3960 str
=m_pFindDialog
->GetFindString();
3966 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3967 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3972 for (i
= 0; i
< cnt
; ++i
)
3974 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3975 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3984 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3989 if (m_pFindDialog
->FindNext() && !bFound
)
3991 //read data from dialog
3992 CString findText
= m_pFindDialog
->GetFindString();
3993 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3995 std::tr1::wregex pat
;
3996 bool bRegex
= false;
3997 if (m_pFindDialog
->Regex())
3998 bRegex
= ValidateRegexp(findText
, pat
, bMatchCase
);
4000 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
4002 for (i
= m_nSearchIndex
+ 1; ; ++i
)
4007 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
4009 if (m_nSearchIndex
>= 0)
4011 if (i
== m_nSearchIndex
)
4013 ::MessageBeep(0xFFFFFFFF);
4014 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
4019 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(i
);
4022 str
+=pLogEntry
->m_CommitHash
.ToString();
4025 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
4027 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
4031 str
+=pLogEntry
->GetAuthorEmail();
4033 str
+=pLogEntry
->GetAuthorName();
4035 str
+=pLogEntry
->GetBody();
4037 str
+=pLogEntry
->GetCommitterEmail();
4039 str
+=pLogEntry
->GetCommitterName();
4041 str
+=pLogEntry
->GetSubject();
4043 str
+=pLogEntry
->m_Notes
;
4045 str
+=GetTagInfo(pLogEntry
);
4049 /*Because changed files list is loaded on demand when gui show,
4050 files will empty when files have not fetched.
4052 we can add it back by using one-way diff(with outnumber changed and rename detect.
4053 here just need changed filename list. one-way is much quicker.
4055 if(pLogEntry
->m_IsFull
)
4057 for (int j
= 0; j
< pLogEntry
->GetFiles(this).GetCount(); ++j
)
4059 str
+= pLogEntry
->GetFiles(this)[j
].GetWinPath();
4061 str
+= pLogEntry
->GetFiles(this)[j
].GetGitOldPathString();
4067 if(!pLogEntry
->m_IsSimpleListReady
)
4068 pLogEntry
->SafeGetSimpleList(&g_Git
);
4070 for (size_t j
= 0; j
< pLogEntry
->m_SimpleFileList
.size(); ++j
)
4072 str
+= pLogEntry
->m_SimpleFileList
[j
];
4081 if (std::regex_search(std::wstring(str
), pat
, flags
))
4091 if (str
.Find(findText
) >= 0)
4101 msg
= msg
.MakeLower();
4102 CString find
= findText
.MakeLower();
4103 if (msg
.Find(find
) >= 0)
4110 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
4112 } // if(m_pFindDialog->FindNext())
4113 //UpdateLogInfoLabel();
4118 EnsureVisible(i
, FALSE
);
4119 if ((GetAsyncKeyState(VK_SHIFT
) & 0x8000) == 0)
4121 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
4122 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
4123 SetSelectionMark(i
);
4127 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
4129 m_highlight
= pLogEntry
->m_CommitHash
;
4132 //FillLogMessageCtrl();
4139 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4141 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
4146 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
4148 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);
4153 INT_PTR
CGitLogListBase::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
4155 LVHITTESTINFO lvhitTestInfo
;
4157 lvhitTestInfo
.pt
= point
;
4159 int nItem
= ListView_SubItemHitTest(m_hWnd
, &lvhitTestInfo
);
4160 int nSubItem
= lvhitTestInfo
.iSubItem
;
4162 UINT nFlags
= lvhitTestInfo
.flags
;
4164 // nFlags is 0 if the SubItemHitTest fails
4165 // Therefore, 0 & <anything> will equal false
4166 if (nFlags
& LVHT_ONITEM
)
4168 // Get the client area occupied by this control
4170 GetClientRect(&rcClient
);
4172 // Fill in the TOOLINFO structure
4174 pTI
->uId
= (UINT
)((nItem
<<10)+(nSubItem
&0x3ff)+1);
4175 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
4176 pTI
->rect
= rcClient
;
4178 return pTI
->uId
; // By returning a unique value per listItem,
4179 // we ensure that when the mouse moves over another list item,
4180 // the tooltip will change
4184 // Otherwise, we aren't interested, so let the message propagate
4189 BOOL
CGitLogListBase::OnToolTipText(UINT
/*id*/, NMHDR
* pNMHDR
, LRESULT
* pResult
)
4191 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
4192 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
4196 // Ignore messages from the built in tooltip, we are processing them internally
4197 if ((pNMHDR
->idFrom
== (UINT_PTR
)m_hWnd
) &&
4198 (((pNMHDR
->code
== TTN_NEEDTEXTA
) && (pTTTA
->uFlags
& TTF_IDISHWND
)) ||
4199 ((pNMHDR
->code
== TTN_NEEDTEXTW
) && (pTTTW
->uFlags
& TTF_IDISHWND
))))
4202 // Get the mouse position
4203 const MSG
* pMessage
= GetCurrentMessage();
4207 ScreenToClient(&pt
);
4209 // Check if the point falls onto a list item
4210 LVHITTESTINFO lvhitTestInfo
;
4211 lvhitTestInfo
.pt
= pt
;
4213 int nItem
= SubItemHitTest(&lvhitTestInfo
);
4215 if (lvhitTestInfo
.flags
& LVHT_ONITEM
)
4217 CString strTipText
= GetToolTipText(nItem
, lvhitTestInfo
.iSubItem
);
4218 if (strTipText
.IsEmpty())
4221 // we want multiline tooltips
4222 ::SendMessage(pNMHDR
->hwndFrom
, TTM_SETMAXTIPWIDTH
, 0, INT_MAX
);
4224 wcscpy_s(m_wszTip
, strTipText
);
4225 // handle Unicode as well as non-Unicode requests
4226 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
4228 pTTTA
->hinst
= nullptr;
4229 pTTTA
->lpszText
= m_szTip
;
4230 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
4234 pTTTW
->hinst
= nullptr;
4235 pTTTW
->lpszText
= m_wszTip
;
4239 GetSubItemRect(nItem
, lvhitTestInfo
.iSubItem
, LVIR_LABEL
, rect
);
4240 ClientToScreen(rect
);
4241 ::SetWindowPos(pNMHDR
->hwndFrom
, HWND_TOP
, rect
.left
, rect
.top
, 0, 0, SWP_NOACTIVATE
|SWP_NOSIZE
|SWP_NOOWNERZORDER
);
4243 return TRUE
; // We found a tool tip,
4244 // tell the framework this message has been handled
4247 return FALSE
; // We didn't handle the message,
4248 // let the framework continue propagating the message
4251 CString
CGitLogListBase::GetToolTipText(int nItem
, int nSubItem
)
4253 if (nSubItem
== LOGLIST_MESSAGE
&& !m_bTagsBranchesOnRightSide
)
4255 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4256 if (pLogEntry
== nullptr)
4258 if (m_HashMap
[pLogEntry
->m_CommitHash
].empty())
4260 return pLogEntry
->GetSubject();
4262 else if (nSubItem
== LOGLIST_DATE
&& m_bRelativeTimes
)
4264 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4265 if (pLogEntry
== nullptr)
4267 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, false);
4269 else if (nSubItem
== LOGLIST_COMMIT_DATE
&& m_bRelativeTimes
)
4271 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4272 if (pLogEntry
== nullptr)
4274 return CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, false);
4276 else if (nSubItem
== LOGLIST_ACTION
)
4278 GitRevLoglist
* pLogEntry
= (GitRevLoglist
*)m_arShownList
.SafeGetAt(nItem
);
4279 if (pLogEntry
== nullptr)
4282 if (!pLogEntry
->m_IsDiffFiles
)
4283 return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES
));
4285 int actions
= pLogEntry
->GetAction(this);
4286 CString sToolTipText
;
4289 if (actions
& CTGitPath::LOGACTIONS_MODIFIED
)
4290 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED
);
4292 if (actions
& CTGitPath::LOGACTIONS_ADDED
)
4294 if (!actionText
.IsEmpty())
4295 actionText
+= L
"\r\n";
4296 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_ADDED
);
4299 if (actions
& CTGitPath::LOGACTIONS_DELETED
)
4301 if (!actionText
.IsEmpty())
4302 actionText
+= L
"\r\n";
4303 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_DELETED
);
4306 if (actions
& CTGitPath::LOGACTIONS_REPLACED
)
4308 if (!actionText
.IsEmpty())
4309 actionText
+= L
"\r\n";
4310 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_REPLACED
);
4313 if (actions
& CTGitPath::LOGACTIONS_UNMERGED
)
4315 if (!actionText
.IsEmpty())
4316 actionText
+= L
"\r\n";
4317 actionText
+= CTGitPath::GetActionName(CTGitPath::LOGACTIONS_UNMERGED
);
4320 if (!actionText
.IsEmpty())
4322 CString
sTitle(MAKEINTRESOURCE(IDS_LOG_ACTIONS
));
4323 sToolTipText
= sTitle
+ L
":\r\n" + actionText
;
4325 return sToolTipText
;