1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
25 #include "GitLogListBase.h"
30 #include "GitProgressDlg.h"
31 #include "ProgressDlg.h"
33 #include "MessageBox.h"
35 #include "LoglistUtils.h"
36 #include "PathUtils.h"
37 #include "StringUtils.h"
38 #include "UnicodeUtils.h"
41 #include "GitStatus.h"
42 #include "..\\TortoiseShell\\Resource.h"
46 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
47 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
48 const UINT
CGitLogListBase::m_RebaseActionMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_REBASEACTION"));
50 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
55 ,m_bNoDispUpdates(FALSE
)
56 , m_bThreadRunning(FALSE
)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL
)
59 , m_SelectedFilters(LOGFILTER_ALL
)
61 , m_logEntries(&m_LogCache
)
63 , m_ColumnManager(this)
64 , m_dwDefaultColumns(0)
65 , m_arShownList(&m_critSec
)
67 , m_bNoHightlightHead(FALSE
)
68 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
70 // use the default GUI font, create a copy of it and
71 // change the copy to BOLD (leave the rest of the font
73 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
75 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
76 lf
.lfWeight
= FW_BOLD
;
77 m_boldFont
= CreateFontIndirect(&lf
);
79 m_bShowBugtraqColumn
=false;
81 m_IsIDReplaceAction
=FALSE
;
83 this->m_critSec
.Init();
84 m_critSec_AsyncDiff
.Init();
85 m_wcRev
.m_CommitHash
.Empty();
86 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
87 m_wcRev
.m_ParentHash
.clear();
88 m_wcRev
.m_Mark
=_T('-');
89 m_wcRev
.m_IsUpdateing
=FALSE
;
90 m_wcRev
.m_IsFull
= TRUE
;
92 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
93 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
94 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
95 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
96 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
98 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
104 m_LoadingThread
= NULL
;
106 InterlockedExchange(&m_bExitThread
,FALSE
);
107 m_IsOldFirst
= FALSE
;
108 m_IsRebaseReplaceGraph
= FALSE
;
110 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
112 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
114 // get short/long datetime setting from registry
115 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
116 if ( RegUseShortDateFormat
)
118 m_DateFormat
= DATE_SHORTDATE
;
122 m_DateFormat
= DATE_LONGDATE
;
124 // get relative time display setting from registry
125 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
126 m_bRelativeTimes
= (regRelativeTimes
!= 0);
127 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
129 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
131 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
132 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
133 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
134 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
136 m_ColumnRegKey
=_T("log");
138 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
139 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
140 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
142 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
143 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
145 m_AsyncThreadExit
= FALSE
;
146 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
147 m_AsynDiffListLock
.Init();
149 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
150 if (m_DiffingThread
==NULL
)
152 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
158 int CGitLogListBase::AsyncDiffThread()
160 m_AsyncThreadExited
= false;
161 while(!m_AsyncThreadExit
)
163 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
166 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
168 m_AsynDiffListLock
.Lock();
169 pRev
= m_AsynDiffList
.back();
170 m_AsynDiffList
.pop_back();
171 m_AsynDiffListLock
.Unlock();
173 if( pRev
->m_CommitHash
.IsEmpty() )
175 if(pRev
->m_IsDiffFiles
)
178 pRev
->GetFiles(this).Clear();
179 pRev
->m_ParentHash
.clear();
180 pRev
->m_ParentHash
.push_back(m_HeadHash
);
181 if(g_Git
.IsInitRepos())
183 if (g_Git
.GetInitAddList(pRev
->GetFiles(this)))
184 CMessageBox::Show(NULL
, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
189 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
192 int *action
= &dummyAction
;
193 SafeGetAction(pRev
, &action
);
196 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
197 *action
|= pRev
->GetFiles(this)[j
].m_Action
;
199 pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
);
201 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
202 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
204 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
205 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
206 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
209 m_critSec_AsyncDiff
.Lock();
210 int ret
= pRev
->CheckAndDiff();
211 m_critSec_AsyncDiff
.Unlock();
213 { // fetch change file list
214 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
216 if(i
< m_arShownList
.GetCount())
218 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
219 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
221 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
227 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
229 POSITION pos
= GetFirstSelectedItemPosition();
230 int nItem
= GetNextSelectedItem(pos
);
234 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
236 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
238 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
245 m_AsyncThreadExited
= true;
248 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
252 m_ContextMenuMask
&= hideMask
;
256 m_ContextMenuMask
&= ~hideMask
;
260 CGitLogListBase::~CGitLogListBase()
262 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
263 this->m_arShownList
.SafeRemoveAll();
265 DestroyIcon(m_hModifiedIcon
);
266 DestroyIcon(m_hReplacedIcon
);
267 DestroyIcon(m_hAddedIcon
);
268 DestroyIcon(m_hDeletedIcon
);
269 m_logEntries
.ClearAll();
272 DeleteObject(m_boldFont
);
274 if ( m_pStoreSelection
)
276 delete m_pStoreSelection
;
277 m_pStoreSelection
= NULL
;
280 SafeTerminateThread();
281 SafeTerminateAsyncDiffThread();
284 CloseHandle(m_AsyncDiffEvent
);
288 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
289 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
290 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
291 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
292 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
294 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
295 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
298 ON_MESSAGE(MSG_LOADED
,OnLoad
)
300 ON_WM_MEASUREITEM_REFLECT()
301 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
302 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
303 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
304 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
305 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
306 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
309 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
311 //if (m_nRowHeight>0)
313 lpMeasureItemStruct
->itemHeight
= 50;
317 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
320 return CHintListCtrl::OnCreate(lpCreateStruct
);
323 void CGitLogListBase::PreSubclassWindow()
325 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
326 // load the icons for the action columns
327 // m_Theme.Open(m_hWnd, L"ListView");
328 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
329 CHintListCtrl::PreSubclassWindow();
332 void CGitLogListBase::InsertGitColumn()
336 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
337 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
338 if (DWORD(regFullRowSelect
))
339 exStyle
|= LVS_EX_FULLROWSELECT
;
340 SetExtendedStyle(exStyle
);
342 // only load properties if we have a repository
343 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
344 UpdateProjectProperties();
346 static UINT normal
[] =
358 IDS_LOG_COMMIT_EMAIL
,
379 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
381 DWORD hideColumns
= 0;
382 if(this->m_IsRebaseReplaceGraph
)
384 hideColumns
|= GIT_LOG_GRAPH
;
385 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
389 hideColumns
|= GIT_LOG_REBASE
;
392 if(this->m_IsIDReplaceAction
)
394 hideColumns
|= GIT_LOG_ACTIONS
;
395 m_dwDefaultColumns
|= GIT_LOG_ID
;
396 m_dwDefaultColumns
|= GIT_LOG_HASH
;
400 hideColumns
|= GIT_LOG_ID
;
402 if(this->m_bShowBugtraqColumn
)
404 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
408 hideColumns
|= GIT_LOGLIST_BUG
;
412 m_ColumnManager
.SetNames(normal
, _countof(normal
));
413 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
419 * Resizes all columns in a list control to values in registry.
421 void CGitLogListBase::ResizeAllListCtrlCols()
423 // column max and min widths to allow
424 static const int nMinimumWidth
= 10;
425 static const int nMaximumWidth
= 1000;
426 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
429 int numcols
= pHdrCtrl
->GetItemCount();
430 for (int col
= 0; col
< numcols
; ++col
)
432 // get width for this col last time from registry
434 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
435 CRegDWORD
regwidth(regentry
, 0);
439 // no saved value, setup sensible defaults
440 if (col
== this->LOGLIST_MESSAGE
)
442 cx
= LOGLIST_MESSAGE_MIN
;
446 cx
= ICONITEMBORDER
+16*4;
449 if (cx
< nMinimumWidth
)
453 else if (cx
> nMaximumWidth
)
458 SetColumnWidth(col
, cx
);
465 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
468 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
469 rItem
.mask
= LVIF_STATE
;
470 rItem
.iItem
= (int)Index
;
471 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
474 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
477 if (!(rItem
.state
& LVIS_SELECTED
))
479 int action
= SafeGetAction(pLogEntry
);
480 if (action
& CTGitPath::LOGACTIONS_REBASE_SQUASH
)
481 brush
= ::CreateSolidBrush(RGB(156,156,156));
482 else if (action
& CTGitPath::LOGACTIONS_REBASE_EDIT
)
483 brush
= ::CreateSolidBrush(RGB(200,200,128));
485 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
487 if (rItem
.state
& LVIS_SELECTED
)
489 if (::GetFocus() == m_hWnd
)
490 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
492 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
495 InvalidateRect(rect
);
498 ::FillRect(hdc
, &rect
, brush
);
499 ::DeleteObject(brush
);
503 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
505 POINT point
= { 4, 4 };
507 rt2
.DeflateRect(1, 1);
508 rt2
.OffsetRect(2, 2);
510 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
511 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
512 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
513 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
514 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
516 ::SelectObject(hdc
, brush
);
517 rt2
.OffsetRect(-2, -2);
518 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
519 ::SelectObject(hdc
, oldbrush
);
520 ::SelectObject(hdc
, oldpen
);
521 ::DeleteObject(nullPen
);
522 ::DeleteObject(darkBrush
);
525 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
527 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
528 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
529 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
530 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
531 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
532 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
533 ::SelectObject(hdc
, oldpen
);
537 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
539 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
540 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
541 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
542 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
543 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
544 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
545 ::SelectObject(hdc
, oldpen
);
549 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
551 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
554 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
555 rItem
.mask
= LVIF_STATE
;
556 rItem
.iItem
= (int)index
;
557 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
563 HTHEME hTheme
= NULL
;
564 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
565 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
567 if (!m_bTagsBranchesOnRightSide
)
568 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
571 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
572 rt
.left
+= oneSpaceSize
.cx
;
574 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
576 int txtState
= LISS_NORMAL
;
577 if (rItem
.state
& LVIS_SELECTED
)
578 txtState
= LISS_SELECTED
;
580 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, 0, &rt
);
584 if (rItem
.state
& LVIS_SELECTED
)
586 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
587 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
588 ::SetTextColor(hdc
, clrOld
);
592 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
596 if (m_bTagsBranchesOnRightSide
)
599 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
601 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
603 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
607 CloseThemeData(hTheme
);
612 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
)
614 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
616 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
618 COLORREF colRef
= refList
[i
].color
;
619 bool singleRemote
= refList
[i
].singleRemote
;
620 bool hasTracking
= refList
[i
].hasTracking
;
621 bool sameName
= refList
[i
].sameName
;
622 bool annotatedTag
= refList
[i
].annotatedTag
;
624 //When row selected, ajust label color
625 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
627 if (rItem
.state
& LVIS_SELECTED
)
628 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
631 brush
= ::CreateSolidBrush(colRef
);
633 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
636 memset(&size
,0,sizeof(SIZE
));
637 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
639 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
642 int textpos
= DT_CENTER
;
644 if (rt
.right
> rect
.right
)
646 rt
.right
= rect
.right
;
655 textRect
.OffsetRect(8, 0);
663 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
667 //Fill interior of ref label
668 ::FillRect(hdc
, &rt
, brush
);
676 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
677 rectEdge
.DeflateRect(1, 1);
678 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
684 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
685 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
686 ::FillRgn(hdc
, hrgn
, brush
);
687 ::DeleteObject(hrgn
);
688 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
690 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
691 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
693 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
694 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
696 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
697 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
698 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
700 SelectObject(hdc
, oldpen
);
703 //Draw text inside label
704 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
705 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
707 int txtState
= LISS_NORMAL
;
708 if (rItem
.state
& LVIS_SELECTED
)
709 txtState
= LISS_SELECTED
;
711 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &textRect
);
715 W_Dc
.SetBkMode(TRANSPARENT
);
716 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
718 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
719 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
720 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
721 ::SetTextColor(hdc
,clrOld
);
725 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
731 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
732 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
734 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
735 DrawLightning(hdc
, newRect
, color
, bold
);
740 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
741 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
743 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
744 DrawUpTriangle(hdc
, newRect
, color
, bold
);
747 rt
.left
= rt
.right
+ 1;
750 ::DeleteObject(brush
);
752 rt
.right
= rect
.right
;
755 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
757 // Returns ((256 - amount)*col1 + amount*col2) / 256;
758 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
759 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
760 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
763 Gdiplus::Color
GetGdiColor(COLORREF col
)
765 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
767 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
768 const COLORREF
& col
,const COLORREF
& activeColor
, int top
771 int h
= laneHeight
/ 2;
772 int m
= (x1
+ x2
) / 2;
773 int r
= (x2
- x1
) * m_NodeSize
/ 30;
776 #define P_CENTER m , h+top
777 #define P_0 x2, h+top
778 #define P_90 m , 0+top-1
779 #define P_180 x1, h+top
780 #define P_270 m , 2 * h+top +1
781 #define R_CENTER m - r, h - r+top, d, d
784 #define DELTA_UR_B 2*(x1 - m), 2*h +top
785 #define DELTA_UR_E 0*16, 90*16 +top // -,
787 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
788 #define DELTA_DR_E 270*16, 90*16 +top // -'
790 #define DELTA_UL_B 2*(x2 - m), 2*h +top
791 #define DELTA_UL_E 90*16, 90*16 +top // ,-
793 #define DELTA_DL_B 2*(x2 - m),2*-h +top
794 #define DELTA_DL_E 180*16, 90*16 // '-
796 #define CENTER_UR x1, 2*h, 225
797 #define CENTER_DR x1, 0 , 135
798 #define CENTER_UL x2, 2*h, 315
799 #define CENTER_DL x2, 0 , 45
802 Gdiplus::Graphics
graphics( hdc
);
804 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
813 Gdiplus::LinearGradientBrush
gradient(
814 Gdiplus::Point(x1
-2, h
+top
-2),
815 Gdiplus::Point(P_270
),
816 GetGdiColor(activeColor
),GetGdiColor(col
));
819 Gdiplus::Pen
mypen(&gradient
, m_LineWidth
);
820 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
822 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
823 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
824 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
831 Gdiplus::LinearGradientBrush
gradient(
832 Gdiplus::Point(P_270
),
833 Gdiplus::Point(x2
+1, h
+top
-1),
834 GetGdiColor(col
),GetGdiColor(activeColor
));
837 Gdiplus::Pen
mypen(&gradient
, m_LineWidth
);
838 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
840 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
841 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
842 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
851 Gdiplus::LinearGradientBrush
gradient(
852 Gdiplus::Point(x1
-2, h
+top
-2),
853 Gdiplus::Point(P_90
),
854 GetGdiColor(activeColor
),GetGdiColor(col
));
856 Gdiplus::Pen
mypen(&gradient
, m_LineWidth
);
858 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
861 QConicalGradient
gradient(CENTER_DR
);
862 gradient
.setColorAt(0.375, activeCol
);
863 gradient
.setColorAt(0.625, col
);
864 myPen
.setBrush(gradient
);
866 p
->drawArc(P_CENTER
, DELTA_DR
);
875 //static QPen myPen(Qt::black, 2); // fast path here
877 pen
.CreatePen(PS_SOLID
,2,col
);
878 //myPen.setColor(col);
879 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
881 Gdiplus::Pen
myPen(GetGdiColor(col
), m_LineWidth
);
883 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
890 case Lanes::NOT_ACTIVE
:
891 case Lanes::MERGE_FORK
:
892 case Lanes::MERGE_FORK_R
:
893 case Lanes::MERGE_FORK_L
:
898 //DrawLine(hdc,P_90,P_270);
899 graphics
.DrawLine(&myPen
,P_90
,P_270
);
900 //p->drawLine(P_90, P_270);
904 //DrawLine(hdc,P_CENTER,P_270);
905 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
906 //p->drawLine(P_CENTER, P_270);
910 case Lanes::BOUNDARY
:
911 case Lanes::BOUNDARY_C
:
912 case Lanes::BOUNDARY_R
:
913 case Lanes::BOUNDARY_L
:
914 //DrawLine(hdc,P_90, P_CENTER);
915 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
916 //p->drawLine(P_90, P_CENTER);
922 myPen
.SetColor(GetGdiColor(activeColor
));
926 case Lanes::MERGE_FORK
:
931 case Lanes::CROSS_EMPTY
:
932 case Lanes::BOUNDARY_C
:
933 //DrawLine(hdc,P_180,P_0);
934 graphics
.DrawLine(&myPen
,P_180
,P_0
);
935 //p->drawLine(P_180, P_0);
937 case Lanes::MERGE_FORK_R
:
938 case Lanes::BOUNDARY_R
:
939 //DrawLine(hdc,P_180,P_CENTER);
940 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
941 //p->drawLine(P_180, P_CENTER);
943 case Lanes::MERGE_FORK_L
:
946 case Lanes::BOUNDARY_L
:
947 //DrawLine(hdc,P_CENTER,P_0);
948 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
949 //p->drawLine(P_CENTER, P_0);
955 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
958 brush
.CreateSolidBrush(col
);
959 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
961 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
962 // center symbol, e.g. rect or ellipse
968 //p->setPen(Qt::NoPen);
970 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
971 graphics
.FillEllipse(&myBrush
, R_CENTER
);
972 //p->drawEllipse(R_CENTER);
974 case Lanes::MERGE_FORK
:
975 case Lanes::MERGE_FORK_R
:
976 case Lanes::MERGE_FORK_L
:
977 //p->setPen(Qt::NoPen);
979 //p->drawRect(R_CENTER);
980 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
981 graphics
.FillRectangle(&myBrush
, R_CENTER
);
983 case Lanes::UNAPPLIED
:
985 //p->setPen(Qt::NoPen);
986 //p->setBrush(Qt::red);
987 //p->drawRect(m - r, h - 1, d, 2);
988 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
989 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
993 //p->setPen(Qt::NoPen);
994 //p->setBrush(DARK_GREEN);
995 //p->drawRect(m - r, h - 1, d, 2);
996 //p->drawRect(m - 1, h - r, 2, d);
997 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
998 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
999 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1001 case Lanes::BOUNDARY
:
1002 //p->setBrush(back);
1003 //p->drawEllipse(R_CENTER);
1004 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1005 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1007 case Lanes::BOUNDARY_C
:
1008 case Lanes::BOUNDARY_R
:
1009 case Lanes::BOUNDARY_L
:
1010 //p->setBrush(back);
1011 //p->drawRect(R_CENTER);
1012 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1013 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1019 ::SelectObject(hdc
,oldpen
);
1020 ::SelectObject(hdc
,oldbrush
);
1029 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1033 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1034 if(data
->m_CommitHash
.IsEmpty())
1039 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1040 rItem
.mask
= LVIF_STATE
;
1041 rItem
.iItem
= (int)index
;
1042 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1045 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1047 if (data
->m_Lanes
.empty())
1048 m_logEntries
.setLane(data
->m_CommitHash
);
1050 std::vector
<int>& lanes
=data
->m_Lanes
;
1051 size_t laneNum
= lanes
.size();
1052 UINT activeLane
= 0;
1053 for (UINT i
= 0; i
< laneNum
; ++i
)
1054 if (Lanes::isMerge(lanes
[i
])) {
1060 int maxWidth
= rect
.Width();
1061 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1063 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1064 //if (opt.state & QStyle::State_Selected)
1065 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1067 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1074 if (ln
== Lanes::EMPTY
)
1077 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1078 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1082 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1088 if (ln
== Lanes::EMPTY
)
1091 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1092 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1094 if (ln
== Lanes::CROSS
)
1096 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1097 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1100 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1106 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1109 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1110 // Take the default processing unless we set this to something else below.
1111 *pResult
= CDRF_DODEFAULT
;
1113 if (m_bNoDispUpdates
)
1116 switch (pLVCD
->nmcd
.dwDrawStage
)
1120 *pResult
= CDRF_NOTIFYITEMDRAW
;
1124 case CDDS_ITEMPREPAINT
:
1126 // This is the prepaint stage for an item. Here's where we set the
1127 // item's text color.
1129 // Tell Windows to send draw notifications for each subitem.
1130 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1132 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1134 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1136 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1139 int action
= SafeGetAction(data
);
1140 if (action
& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
))
1141 crText
= RGB(128,128,128);
1143 if (action
& CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1144 pLVCD
->clrTextBk
= RGB(156,156,156);
1145 else if (action
& CTGitPath::LOGACTIONS_REBASE_EDIT
)
1146 pLVCD
->clrTextBk
= RGB(200,200,128);
1148 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1150 if (action
& CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1152 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1153 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1156 if (data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
)
1158 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1159 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1162 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1163 // crText = GetSysColor(COLOR_GRAYTEXT);
1165 if (data
->m_CommitHash
.IsEmpty())
1167 //crText = GetSysColor(RGB(200,200,0));
1168 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1169 // We changed the font, so we're returning CDRF_NEWFONT. This
1170 // tells the control to recalculate the extent of the text.
1171 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1175 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1177 if (m_bStrictStopped
)
1178 crText
= GetSysColor(COLOR_GRAYTEXT
);
1180 // Store the color back in the NMLVCUSTOMDRAW struct.
1181 pLVCD
->clrText
= crText
;
1185 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1187 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1189 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1192 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty())
1194 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1197 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1199 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1200 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1202 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1203 if( !data
->m_CommitHash
.IsEmpty())
1204 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1206 *pResult
= CDRF_SKIPDEFAULT
;
1211 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1213 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1215 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1216 //if(!data->m_IsFull)
1218 //if(data->SafeFetchFullInfo(&g_Git))
1219 // this->Invalidate();
1220 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1223 if (!m_HashMap
[data
->m_CommitHash
].empty())
1227 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1229 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1231 std::vector
<REFLABEL
> refsToShow
;
1232 STRING_VECTOR remoteTrackingList
;
1233 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1234 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1236 CString str
= refList
[i
];
1239 refLabel
.color
= RGB(255, 255, 255);
1240 refLabel
.singleRemote
= false;
1241 refLabel
.hasTracking
= false;
1242 refLabel
.sameName
= false;
1243 refLabel
.annotatedTag
= false;
1244 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1246 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1248 if (refLabel
.name
== m_CurrentBranch
)
1249 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1251 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1253 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1254 CString pullRemote
= trackingEntry
.first
;
1255 CString pullBranch
= trackingEntry
.second
;
1256 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1258 CString defaultUpstream
;
1259 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1260 refLabel
.hasTracking
= true;
1261 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1264 for (int j
= i
+ 1; j
< refList
.size(); ++j
)
1266 if (refList
[j
] == defaultUpstream
)
1275 bool sameName
= pullBranch
== refLabel
.name
;
1276 refsToShow
.push_back(refLabel
);
1277 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1278 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1279 if (m_bSymbolizeRefNames
)
1281 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1283 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1284 refLabel
.singleRemote
= true;
1287 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1288 refLabel
.sameName
= sameName
;
1290 refsToShow
.push_back(refLabel
);
1291 remoteTrackingList
.push_back(defaultUpstream
);
1297 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1299 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1303 for (int j
= 0; j
< remoteTrackingList
.size(); ++j
)
1305 if (remoteTrackingList
[j
] == str
)
1314 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1315 if (m_bSymbolizeRefNames
)
1317 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1319 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1320 refLabel
.singleRemote
= true;
1324 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1326 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1328 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1329 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1331 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1333 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1335 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1336 refLabel
.name
= _T("stash");
1338 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1340 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1342 if (refLabel
.name
.Find(_T("good")) == 0)
1344 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1345 refLabel
.name
= _T("good");
1347 if (refLabel
.name
.Find(_T("bad")) == 0)
1349 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1350 refLabel
.name
= _T("bad");
1356 refsToShow
.push_back(refLabel
);
1359 if (refsToShow
.empty())
1361 *pResult
= CDRF_DODEFAULT
;
1365 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1367 *pResult
= CDRF_SKIPDEFAULT
;
1375 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1377 if(this->m_IsIDReplaceAction
)
1379 *pResult
= CDRF_DODEFAULT
;
1382 *pResult
= CDRF_DODEFAULT
;
1384 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1388 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1389 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1391 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1393 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1394 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1395 // Get the selected state of the
1396 // item being drawn.
1398 // Fill the background if necessary
1399 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1401 // Draw the icon(s) into the compatible DC
1402 int action
= SafeGetAction(pLogEntry
);
1404 if (!pLogEntry
->m_IsDiffFiles
)
1405 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1407 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1408 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1411 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1412 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1415 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1416 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1419 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1420 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1422 *pResult
= CDRF_SKIPDEFAULT
;
1428 *pResult
= CDRF_DODEFAULT
;
1431 // CGitLogListBase message handlers
1433 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1435 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1437 // Create a pointer to the item
1438 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1440 // Do the list need text information?
1441 if (!(pItem
->mask
& LVIF_TEXT
))
1444 // By default, clear text buffer.
1445 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1447 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1450 if (m_bNoDispUpdates
|| bOutOfRange
)
1453 // Which item number?
1454 int itemid
= pItem
->iItem
;
1455 GitRev
* pLogEntry
= NULL
;
1456 if (itemid
< m_arShownList
.GetCount())
1457 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1462 temp
.Format(_T("%d"),pItem
->iItem
+1);
1467 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1471 switch (pItem
->iSubItem
)
1473 case this->LOGLIST_GRAPH
: //Graphic
1475 case this->LOGLIST_REBASE
:
1477 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1480 path
.m_Action
= SafeGetAction(pLogEntry
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1481 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1485 case this->LOGLIST_ACTION
: //action -- no text in the column
1487 case this->LOGLIST_HASH
:
1489 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1491 case this->LOGLIST_ID
:
1492 if(this->m_IsIDReplaceAction
)
1493 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1495 case this->LOGLIST_MESSAGE
: //Message
1497 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1499 case this->LOGLIST_AUTHOR
: //Author
1501 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1503 case this->LOGLIST_DATE
: //Date
1504 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1505 lstrcpyn(pItem
->pszText
,
1506 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1510 case this->LOGLIST_EMAIL
:
1512 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1515 case this->LOGLIST_COMMIT_NAME
: //Commit
1517 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1520 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1522 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1525 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1526 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1527 lstrcpyn(pItem
->pszText
,
1528 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1531 case this->LOGLIST_BUG
: //Bug ID
1533 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1541 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1544 if (pWnd
== GetHeaderCtrl())
1546 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1549 int selIndex
= GetSelectionMark();
1551 return; // nothing selected, nothing to do with a context menu
1553 // if the user selected the info text telling about not all revisions shown due to
1554 // the "stop on copy/rename" option, we also don't show the context menu
1555 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1558 // if the context menu is invoked through the keyboard, we have to use
1559 // a calculated position on where to anchor the menu on
1560 if ((point
.x
== -1) && (point
.y
== -1))
1563 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1564 ClientToScreen(&rect
);
1565 point
= rect
.CenterPoint();
1567 m_nSearchIndex
= selIndex
;
1568 m_bCancelled
= FALSE
;
1570 // calculate some information the context menu commands can use
1571 // CString pathURL = GetURLFromPath(m_path);
1573 POSITION pos
= GetFirstSelectedItemPosition();
1574 int indexNext
= GetNextSelectedItem(pos
);
1578 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1580 GitRev revSelected
= pSelLogEntry
->Rev
;
1581 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1582 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1584 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1586 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1587 if (changedpath
->lCopyFromRev
)
1588 revPrevious
= changedpath
->lCopyFromRev
;
1591 GitRev revSelected2
;
1594 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1595 revSelected2
= pLogEntry
->Rev
;
1597 bool bAllFromTheSameAuthor
= true;
1598 CString firstAuthor
;
1599 CLogDataVector selEntries
;
1600 GitRev revLowest
, revHighest
;
1601 GitRevRangeArray revisionRanges
;
1603 POSITION pos
= GetFirstSelectedItemPosition();
1604 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1605 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1606 selEntries
.push_back(pLogEntry
);
1607 firstAuthor
= pLogEntry
->sAuthor
;
1608 revLowest
= pLogEntry
->Rev
;
1609 revHighest
= pLogEntry
->Rev
;
1612 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1613 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1614 selEntries
.push_back(pLogEntry
);
1615 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1616 bAllFromTheSameAuthor
= false;
1617 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1618 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1624 int FirstSelect
=-1, LastSelect
=-1;
1625 pos
= GetFirstSelectedItemPosition();
1626 FirstSelect
= GetNextSelectedItem(pos
);
1629 LastSelect
= GetNextSelectedItem(pos
);
1631 //entry is selected, now show the popup menu
1633 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, revertmenu
;
1635 if (popup
.CreatePopupMenu())
1637 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1638 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1639 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1641 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1642 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1644 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1645 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1647 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1648 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1650 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1651 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1653 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1654 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1655 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1657 if (GetSelectedCount() == 1)
1661 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1663 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1664 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1668 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1669 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1670 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1671 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1673 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1675 GitRev
*pRev
=pSelLogEntry
;
1676 if (pSelLogEntry
->m_ParentHash
.empty())
1680 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1682 catch (const char* msg
)
1684 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1687 if(pRev
->m_ParentHash
.size()<=1)
1689 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1694 gnudiffmenu
.CreatePopupMenu();
1695 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1697 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1698 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1700 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1703 str
.Format(IDS_PARENT
, i
+ 1);
1704 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1709 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1712 GitRev
*pRev
=pSelLogEntry
;
1713 if (pSelLogEntry
->m_ParentHash
.empty())
1717 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1719 catch (const char* msg
)
1721 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1724 if(pRev
->m_ParentHash
.size()<=1)
1726 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1727 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1728 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1732 diffmenu
.CreatePopupMenu();
1733 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1734 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1737 str
.Format(IDS_PARENT
, i
+ 1);
1738 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1739 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1741 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1742 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1748 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1749 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1751 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1752 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1754 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1756 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1757 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1760 bool isStash
= false;
1761 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1763 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1770 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1772 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1773 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1775 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1776 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1778 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1781 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1783 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1784 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1786 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1790 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1792 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1794 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1796 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1798 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1799 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1801 // popup.AppendMenu(MF_SEPARATOR, NULL);
1806 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1808 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1810 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1811 GetSelectedCount() == 1)
1812 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1814 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1815 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1817 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1818 str
.Format(format
,g_Git
.GetCurrentBranch());
1820 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
)
1821 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1823 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1824 str
.Format(format
,g_Git
.GetCurrentBranch());
1826 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1827 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1830 // Add Switch Branch express Menu
1831 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1832 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1835 std::vector
<CString
*> branchs
;
1836 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1838 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1839 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1841 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1846 str
.LoadString(IDS_SWITCH_BRANCH
);
1848 if(branchs
.size() == 1)
1851 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1852 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1854 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1857 else if(branchs
.size() > 1)
1859 subbranchmenu
.CreatePopupMenu();
1860 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
1862 if (*branchs
[i
] != currentBranch
)
1864 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1865 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1869 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1873 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1874 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1876 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1877 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1879 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1880 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1882 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1883 str
.Format(format
,g_Git
.GetCurrentBranch());
1885 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
)
1886 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1887 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1889 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1890 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1892 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
1894 GitRev
*pRev
= pSelLogEntry
;
1895 if (pSelLogEntry
->m_ParentHash
.empty())
1899 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1901 catch (const char* msg
)
1903 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1906 if (pRev
->m_ParentHash
.size() == 1)
1908 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1912 revertmenu
.CreatePopupMenu();
1913 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
1915 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1918 str
.Format(IDS_PARENT
, i
+ 1);
1919 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
1924 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1925 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1927 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1932 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1934 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1935 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1936 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1937 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1940 if (GetSelectedCount() >= 2)
1942 bool bAddSeparator
= false;
1943 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1945 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1946 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1949 if (GetSelectedCount() == 2)
1951 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1952 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1954 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
1956 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
1957 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1958 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
1960 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
1961 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
1962 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
1963 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
1966 bAddSeparator
= true;
1971 bAddSeparator
= true;
1974 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
1975 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1978 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1981 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1983 bool bAddSeparator
= false;
1984 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1986 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
1990 headindex
= this->GetHeadIndex();
1991 if(headindex
>=0 && LastSelect
>= headindex
)
1993 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1995 if (g_Git
.GetHash(hash
, head
))
1996 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
1997 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1998 if(pLastEntry
->m_CommitHash
== hash
) {
1999 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2000 bAddSeparator
= true;
2005 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2006 if (GetSelectedCount() >= 2)
2007 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2009 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2010 bAddSeparator
= true;
2013 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
2014 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2015 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2016 bAddSeparator
= true;
2020 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2023 if (m_hasWC
&& !isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
2025 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2026 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2029 if (GetSelectedCount() == 1)
2031 bool bAddSeparator
= false;
2032 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
2034 // show the push-option only if the log entry has an associated local branch
2035 bool isLocal
= false;
2036 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2038 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2043 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2044 bAddSeparator
= true;
2048 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2050 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2052 std::vector
<CString
*> branchs
;
2053 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2055 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2056 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2059 if (branchs
.size() == 1)
2061 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2064 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2065 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2066 bAddSeparator
= true;
2068 else if (branchs
.size() > 1)
2070 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2071 submenu
.CreatePopupMenu();
2072 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2074 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2075 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2078 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2079 bAddSeparator
= true;
2082 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2084 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2085 } // GetSelectedCount() == 1
2087 if (GetSelectedCount() != 0)
2089 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2090 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2091 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2092 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2093 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2094 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2097 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2098 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2100 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2101 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2103 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2104 // DialogEnableWindow(IDOK, FALSE);
2105 // SetPromptApp(&theApp);
2107 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2109 // EnableOKButton();
2110 } // if (popup.CreatePopupMenu())
2114 bool CGitLogListBase::IsSelectionContinuous()
2116 if ( GetSelectedCount()==1 )
2118 // if only one revision is selected, the selection is of course
2123 POSITION pos
= GetFirstSelectedItemPosition();
2124 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2127 int itemindex
= GetNextSelectedItem(pos
);
2130 int nextindex
= GetNextSelectedItem(pos
);
2131 if (nextindex
- itemindex
> 1)
2133 bContinuous
= false;
2136 itemindex
= nextindex
;
2142 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2146 POSITION pos
= GetFirstSelectedItemPosition();
2150 sRev
.LoadString(IDS_LOG_REVISION
);
2152 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2154 sDate
.LoadString(IDS_LOG_DATE
);
2156 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2160 CString sLogCopyText
;
2162 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2164 if (toCopy
== ID_COPY_ALL
)
2166 //pLogEntry->GetFiles(this)
2167 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2169 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2170 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2172 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2173 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2176 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2177 sPaths
+= _T(" ") + rename
;
2179 sPaths
+= _T("\r\n");
2182 CString body
= pLogEntry
->GetBody();
2183 body
.Replace(_T("\n"), _T("\r\n"));
2184 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"),
2185 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2186 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2188 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2189 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2191 sClipdata
+= sLogCopyText
;
2193 else if (toCopy
== ID_COPY_MESSAGE
)
2195 CString body
= pLogEntry
->GetBody();
2196 body
.Replace(_T("\n"), _T("\r\n"));
2197 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2199 else if (toCopy
== ID_COPY_SUBJECT
)
2201 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2206 sClipdata
+= _T("\r\n");
2207 sClipdata
+= pLogEntry
->m_CommitHash
;
2212 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2217 void CGitLogListBase::DiffSelectedRevWithPrevious()
2219 if (m_bThreadRunning
)
2222 int FirstSelect
=-1, LastSelect
=-1;
2223 POSITION pos
= GetFirstSelectedItemPosition();
2224 FirstSelect
= GetNextSelectedItem(pos
);
2227 LastSelect
= GetNextSelectedItem(pos
);
2230 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2233 UpdateLogInfoLabel();
2234 int selIndex
= m_LogList
.GetSelectionMark();
2237 int selCount
= m_LogList
.GetSelectedCount();
2241 // Find selected entry in the log list
2242 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2243 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2244 long rev1
= pLogEntry
->Rev
;
2246 CTGitPath path
= m_path
;
2248 // See how many files under the relative root were changed in selected revision
2250 LogChangedPath
* changed
= NULL
;
2251 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2253 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2254 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2261 if (m_path
.IsDirectory() && nChanged
== 1)
2263 // We're looking at the log for a directory and only one file under dir was changed in the revision
2264 // Do diff on that file instead of whole directory
2265 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2268 m_bCancelled
= FALSE
;
2269 DialogEnableWindow(IDOK
, FALSE
);
2270 SetPromptApp(&theApp
);
2271 theApp
.DoWaitCursor(1);
2275 GitDiff
diff(this, m_hWnd
, true);
2276 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2277 diff
.SetHEADPeg(m_LogRevision
);
2278 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2282 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2285 theApp
.DoWaitCursor(-1);
2290 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2292 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2295 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2297 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2299 if (pFindInfo
->lvfi
.psz
== 0)
2302 CString sCmp
= pFindInfo
->lvfi
.psz
;
2304 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2306 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2307 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2308 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2310 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2318 if (sCmp
.Compare(sRev
)==0)
2325 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2327 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2329 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2330 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2331 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2333 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2341 if (sCmp
.Compare(sRev
)==0)
2353 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2357 this->m_arShownList
.SafeRemoveAll();
2359 this->m_logEntries
.ClearAll();
2360 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2363 //this->m_logEntries.ParserFromLog();
2364 SetItemCountEx((int)m_logEntries
.size());
2366 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2370 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2371 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2376 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2377 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2389 int CGitLogListBase::BeginFetchLog()
2393 this->m_arShownList
.SafeRemoveAll();
2395 this->m_logEntries
.ClearAll();
2397 this->m_LogCache
.ClearAllParent();
2399 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2402 if(this->m_Path
.IsEmpty())
2408 mask
= CGit::LOG_INFO_ONLY_HASH
;
2409 if (m_bIncludeBoundaryCommits
)
2410 mask
|= CGit::LOG_INFO_BOUNDARY
;
2411 // if(this->m_bAllBranch)
2412 mask
|= m_ShowMask
;
2416 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2418 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2421 if (m_sRange
.IsEmpty())
2422 m_sRange
= _T("HEAD");
2425 data
.m_From
= m_From
;
2428 #if 0 /* use tortoiegit filter */
2429 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2430 data
.m_Author
= this->m_sFilterText
;
2432 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2433 data
.m_MessageFilter
= this->m_sFilterText
;
2435 data
.m_IsRegex
= m_bFilterWithRegex
;
2438 // follow does not work for directories
2439 if (!path
|| path
->IsDirectory())
2440 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2441 // follow does not work with all branches 8at least in TGit)
2442 if (mask
& CGit::LOG_INFO_FOLLOW
)
2443 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
;
2445 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2447 //this->m_logEntries.ParserFromLog();
2448 if(IsInWorkingThread())
2450 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2454 SetItemCountEx((int)m_logEntries
.size());
2459 [] { git_init(); } ();
2464 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2468 if (!g_Git
.CanParseRev(m_sRange
))
2470 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
))
2473 // if show all branches, pick any ref as dummy entry ref
2475 if (g_Git
.GetRefList(list
))
2476 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2477 if (list
.size() == 0)
2480 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2483 g_Git
.m_critGitDllSec
.Lock();
2485 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2487 g_Git
.m_critGitDllSec
.Unlock();
2493 g_Git
.m_critGitDllSec
.Unlock();
2495 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2498 g_Git
.m_critGitDllSec
.Unlock();
2503 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2505 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2507 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2509 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2511 DiffSelectedRevWithPrevious();
2516 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2523 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2525 // select all entries
2526 for (int i
=0; i
<GetItemCount(); ++i
)
2528 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2534 if (m_hAccel
&& !bSkipAccelerator
)
2536 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2542 //m_tooltips.RelayEvent(pMsg);
2543 return __super::PreTranslateMessage(pMsg
);
2546 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2548 // a double click on an entry in the revision list has happened
2551 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2552 DiffSelectedRevWithPrevious();
2555 int CGitLogListBase::FetchLogAsync(void * data
)
2559 m_bExitThread
=FALSE
;
2560 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2561 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2562 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2563 if (m_LoadingThread
==NULL
)
2565 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2566 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2567 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2573 //this is the thread function which calls the subversion function
2574 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2576 return ((CGitLogListBase
*)pVoid
)->LogThread();
2579 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2582 oldest
=CTime::GetCurrentTime();
2583 latest
=CTime(1971,1,2,0,0,0);
2584 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2586 if(m_logEntries
[i
].IsEmpty())
2589 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2590 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2592 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2593 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2601 UINT
CGitLogListBase::LogThread()
2603 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2605 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2606 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2612 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2613 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2618 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2619 bool bRegex
= false;
2620 if (m_bFilterWithRegex
)
2621 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2623 TRACE(_T("\n===Begin===\n"));
2624 //Update work copy item;
2626 if (!m_logEntries
.empty())
2628 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2630 m_arShownList
.SafeAdd(pRev
);
2634 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2636 // store commit number of the last selected commit/line before the refresh or -1
2637 int lastSelectedHashNItem
= -1;
2640 bool shouldWalk
= true;
2641 if (!g_Git
.CanParseRev(m_sRange
))
2643 // walk revisions if show all branches and there exists any ref
2644 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
))
2649 if (g_Git
.GetRefList(list
))
2650 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2651 if (list
.size() == 0)
2658 g_Git
.m_critGitDllSec
.Lock();
2662 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2663 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2668 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2671 g_Git
.m_critGitDllSec
.Unlock();
2674 t2
=t1
=GetTickCount();
2675 int oldprecentage
= 0;
2676 size_t oldsize
= m_logEntries
.size();
2677 while (ret
== 0 && !m_bExitThread
)
2679 g_Git
.m_critGitDllSec
.Lock();
2682 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2686 g_Git
.m_critGitDllSec
.Unlock();
2688 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2691 g_Git
.m_critGitDllSec
.Unlock();
2696 if (commit
.m_ignore
== 1)
2698 git_free_commit(&commit
);
2702 //printf("%s\r\n",commit.GetSubject());
2706 CGitHash hash
= (char*)commit
.m_hash
;
2708 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2709 pRev
->m_GitCommit
= commit
;
2710 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2713 g_Git
.m_critGitDllSec
.Lock();
2716 git_get_notes(commit
.m_hash
, ¬e
);
2720 g_Git
.m_critGitDllSec
.Unlock();
2722 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2725 g_Git
.m_critGitDllSec
.Unlock();
2729 pRev
->m_Notes
.Empty();
2730 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2733 if(!pRev
->m_IsDiffFiles
)
2735 pRev
->m_CallDiffAsync
= DiffAsync
;
2738 pRev
->ParserParentFromCommit(&commit
);
2745 if(!m_sFilterText
.IsEmpty())
2747 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2750 this->m_critSec
.Lock();
2751 m_logEntries
.push_back(hash
);
2752 m_arShownList
.SafeAdd(pRev
);
2753 this->m_critSec
.Unlock();
2755 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2756 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2760 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2763 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2766 if(percent
< GITLOG_START
)
2767 percent
= GITLOG_START
+1;
2769 oldsize
= m_logEntries
.size();
2770 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2772 //if( percent > oldprecentage )
2774 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2775 oldprecentage
= percent
;
2780 g_Git
.m_critGitDllSec
.Lock();
2781 git_close_log(m_DllGitLog
);
2782 g_Git
.m_critGitDllSec
.Unlock();
2788 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2793 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2795 if (lastSelectedHashNItem
>= 0)
2796 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2799 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2801 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2806 void CGitLogListBase::FetchRemoteList()
2808 STRING_VECTOR remoteList
;
2809 if (!g_Git
.GetRemoteList(remoteList
))
2810 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
2812 m_SingleRemote
= _T("");
2815 void CGitLogListBase::FetchTrackingBranchList()
2817 m_TrackingMap
.clear();
2818 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
2820 for (int j
= 0; j
< it
->second
.size(); ++j
)
2823 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
2826 configName
.Format(_T("branch.%s.remote"), branchName
);
2827 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2829 configName
.Format(_T("branch.%s.merge"), branchName
);
2830 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2832 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2834 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
2841 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2843 SafeTerminateThread();
2845 this->SetItemCountEx(0);
2850 // HACK to hide graph column
2851 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
2852 SetColumnWidth(0, 0);
2854 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
2856 //Update branch and Tag info
2858 //Assume Thread have exited
2859 //if(!m_bThreadRunning)
2861 m_logEntries
.clear();
2865 m_sFilterText
.Empty();
2870 InterlockedExchange(&m_bExitThread
,FALSE
);
2872 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2873 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2874 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2876 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2877 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2878 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2882 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2886 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
2888 type
|= std::tr1::regex_constants::icase
;
2889 pat
= std::tr1::wregex(regexp_str
, type
);
2892 catch (std::exception
) {}
2895 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
)
2898 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
2901 if ((bRegex
)&&(m_bFilterWithRegex
))
2903 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2905 if(this->m_bShowBugtraqColumn
)
2907 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2909 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2910 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
2917 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2919 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2920 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2926 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2928 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2929 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2935 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2937 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
2942 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
2948 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
2950 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
2955 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
2961 if (m_SelectedFilters
& LOGFILTER_REVS
)
2963 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2964 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
2970 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
2972 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
2973 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
2975 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
2982 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2984 CTGitPathList
*pathList
=NULL
;
2985 if( pRev
->m_IsDiffFiles
)
2986 pathList
= &pRev
->GetFiles(this);
2989 if(!pRev
->m_IsSimpleListReady
)
2990 pRev
->SafeGetSimpleList(&g_Git
);
2994 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2996 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3000 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3006 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3008 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3017 CString find
= m_sFilterText
;
3020 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3022 if(this->m_bShowBugtraqColumn
)
3024 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3026 sBugIds
.MakeLower();
3027 if ((sBugIds
.Find(find
) >= 0))
3034 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3036 CString msg
= pRev
->GetSubject();
3038 msg
= msg
.MakeLower();
3039 if ((msg
.Find(find
) >= 0))
3045 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3047 CString msg
= pRev
->GetBody();
3049 msg
= msg
.MakeLower();
3050 if ((msg
.Find(find
) >= 0))
3056 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3058 CString msg
= pRev
->GetAuthorName();
3059 msg
= msg
.MakeLower();
3060 if ((msg
.Find(find
) >= 0))
3066 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3068 CString msg
= pRev
->GetAuthorEmail();
3069 msg
= msg
.MakeLower();
3070 if ((msg
.Find(find
) >= 0))
3076 if (m_SelectedFilters
& LOGFILTER_REVS
)
3078 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3079 if ((sRev
.Find(find
) >= 0))
3085 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3087 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3088 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3090 if (it
->Find(find
) >= 0)
3097 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3099 CTGitPathList
*pathList
=NULL
;
3100 if( pRev
->m_IsDiffFiles
)
3101 pathList
= &pRev
->GetFiles(this);
3104 if(!pRev
->m_IsSimpleListReady
)
3105 pRev
->SafeGetSimpleList(&g_Git
);
3108 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3110 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3111 CString path
= cpath
->GetGitOldPathString();
3113 if ((path
.Find(find
)>=0))
3117 path
= cpath
->GetGitPathString();
3119 if ((path
.Find(find
)>=0))
3125 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3127 CString path
= pRev
->m_SimpleFileList
[i
];
3129 if ((path
.Find(find
)>=0))
3135 } // else (from if (bRegex))
3140 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3143 pShownlist
->SafeRemoveAll();
3145 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3146 bool bRegex
= false;
3147 if (m_bFilterWithRegex
)
3148 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3150 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3152 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3154 if ((bRegex
)&&(m_bFilterWithRegex
))
3157 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3159 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3160 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3162 pShownlist
->SafeAdd(m_logEntries
[i
]);
3167 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3169 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3170 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3172 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3176 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3178 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3179 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3181 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3185 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3187 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3190 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3192 CTGitPath cpath
= pathList
[cpPathIndex
];
3193 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3195 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3199 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3201 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3205 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3207 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3213 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3215 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3217 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3221 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3223 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3225 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3229 if (m_SelectedFilters
& LOGFILTER_REVS
)
3231 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3232 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3234 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3238 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3240 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3241 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3243 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3245 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3253 CString find
= m_sFilterText
;
3256 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3258 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3260 sBugIDs
= sBugIDs
.MakeLower();
3261 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3263 pShownlist
->SafeAdd(m_logEntries
[i
]);
3268 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3270 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3272 msg
= msg
.MakeLower();
3273 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3275 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3279 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3281 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3283 msg
= msg
.MakeLower();
3284 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3286 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3290 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3292 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3295 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3297 CTGitPath cpath
= pathList
[cpPathIndex
];
3298 CString path
= cpath
.GetGitOldPathString();
3300 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3302 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3306 path
= cpath
.GetGitPathString();
3308 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3310 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3314 path
= cpath
.GetActionName();
3316 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3318 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3324 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3326 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3327 msg
= msg
.MakeLower();
3328 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3330 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3334 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3336 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3337 msg
= msg
.MakeLower();
3338 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3340 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3344 if (m_SelectedFilters
& LOGFILTER_REVS
)
3346 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3347 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3349 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3353 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3355 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3356 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3358 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3360 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3365 } // else (from if (bRegex))
3366 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3370 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3373 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3379 return time <= m_To;
3382 return time >= m_From;
3384 return ((time >= m_From)&&(time <= m_To));
3386 return TRUE
; /* git dll will filter time range */
3390 void CGitLogListBase::StartFilter()
3392 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3393 RecalculateShownList(&m_arShownList
);
3394 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3398 SetItemCountEx(ShownCountWithStopped());
3399 RedrawItems(0, ShownCountWithStopped());
3403 void CGitLogListBase::RemoveFilter()
3406 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3408 m_arShownList
.SafeRemoveAll();
3410 // reset the time filter too
3412 m_timFrom
= (__time64_t(m_tFrom
));
3413 m_timTo
= (__time64_t(m_tTo
));
3414 m_DateFrom
.SetTime(&m_timFrom
);
3415 m_DateTo
.SetTime(&m_timTo
);
3416 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3417 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3420 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3422 if(this->m_IsOldFirst
)
3424 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3428 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3431 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3433 SetItemCountEx(ShownCountWithStopped());
3434 RedrawItems(0, ShownCountWithStopped());
3436 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3439 void CGitLogListBase::Clear()
3441 m_arShownList
.SafeRemoveAll();
3444 m_logEntries
.ClearAll();
3448 void CGitLogListBase::OnDestroy()
3450 // save the column widths to the registry
3453 SafeTerminateThread();
3454 SafeTerminateAsyncDiffThread();
3457 while(m_LogCache
.SaveCache())
3465 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3466 // MB_YESNO) == IDNO)
3470 CHintListCtrl::OnDestroy();
3473 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3477 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3478 this->InvalidateRect(rect
);
3484 * Save column widths to the registry
3486 void CGitLogListBase::SaveColumnWidths()
3488 int maxcol
= m_ColumnManager
.GetColumnCount();
3490 // HACK that graph column is always shown
3491 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3493 for (int col
= 0; col
< maxcol
; ++col
)
3494 if (m_ColumnManager
.IsVisible (col
))
3495 m_ColumnManager
.ColumnResized (col
);
3497 m_ColumnManager
.WriteSettings();
3500 int CGitLogListBase::GetHeadIndex()
3502 if(m_HeadHash
.IsEmpty())
3505 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3507 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3510 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3516 void CGitLogListBase::OnFind()
3520 m_pFindDialog
= new CFindDlg(this);
3521 m_pFindDialog
->Create(this);
3524 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3526 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3528 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3530 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3533 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3535 if (GetSelectedCount() != 0)
3537 SetItemState((int)itemToSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
3538 EnsureVisible((int)itemToSelect
, FALSE
);
3541 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3544 ASSERT(m_pFindDialog
!= NULL
);
3545 bool bFound
= false;
3548 if (m_pFindDialog
->IsTerminating())
3550 // invalidate the handle identifying the dialog box.
3551 m_pFindDialog
= NULL
;
3555 if(m_pFindDialog
->IsRef())
3558 str
=m_pFindDialog
->GetFindString();
3564 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3565 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3570 for (i
= 0; i
<m_arShownList
.GetCount(); ++i
)
3572 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3573 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3583 if(m_pFindDialog
->FindNext())
3585 //read data from dialog
3586 CString FindText
= m_pFindDialog
->GetFindString();
3587 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3589 std::tr1::wregex pat
;
3590 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3592 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3595 for (i
= this->m_nSearchIndex
; i
< m_arShownList
.GetCount() && !bFound
; ++i
)
3597 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3600 str
+=pLogEntry
->m_CommitHash
.ToString();
3603 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
3605 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3609 str
+=pLogEntry
->GetAuthorEmail();
3611 str
+=pLogEntry
->GetAuthorName();
3613 str
+=pLogEntry
->GetBody();
3615 str
+=pLogEntry
->GetCommitterEmail();
3617 str
+=pLogEntry
->GetCommitterName();
3619 str
+=pLogEntry
->GetSubject();
3623 /*Because changed files list is loaded on demand when gui show,
3624 files will empty when files have not fetched.
3626 we can add it back by using one-way diff(with outnumber changed and rename detect.
3627 here just need changed filename list. one-way is much quicker.
3629 if(pLogEntry
->m_IsFull
)
3631 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
3633 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3635 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3641 if(!pLogEntry
->m_IsSimpleListReady
)
3642 pLogEntry
->SafeGetSimpleList(&g_Git
);
3644 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
3646 str
+=pLogEntry
->m_SimpleFileList
[i
];
3655 if (std::regex_search(std::wstring(str
), pat
, flags
))
3665 if (str
.Find(FindText
) >= 0)
3675 msg
= msg
.MakeLower();
3676 CString find
= FindText
.MakeLower();
3677 if (msg
.Find(find
) >= 0)
3684 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3686 } // if(m_pFindDialog->FindNext())
3687 //UpdateLogInfoLabel();
3691 this->m_nSearchIndex
= i
;
3692 EnsureVisible(i
, FALSE
);
3693 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3694 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3695 SetSelectionMark(i
);
3696 //FillLogMessageCtrl();
3699 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3700 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3706 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3708 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3713 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3715 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);