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
)
60 , m_ShowFilter(FILTERSHOW_ALL
)
62 , m_logEntries(&m_LogCache
)
64 , m_ColumnManager(this)
65 , m_dwDefaultColumns(0)
66 , m_arShownList(&m_critSec
)
68 , m_bNoHightlightHead(FALSE
)
69 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
71 // use the default GUI font, create a copy of it and
72 // change the copy to BOLD (leave the rest of the font
74 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
76 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
77 lf
.lfWeight
= FW_BOLD
;
78 m_boldFont
= CreateFontIndirect(&lf
);
80 m_bShowBugtraqColumn
=false;
82 m_IsIDReplaceAction
=FALSE
;
84 this->m_critSec
.Init();
85 m_critSec_AsyncDiff
.Init();
86 m_wcRev
.m_CommitHash
.Empty();
87 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
88 m_wcRev
.m_ParentHash
.clear();
89 m_wcRev
.m_Mark
=_T('-');
90 m_wcRev
.m_IsUpdateing
=FALSE
;
91 m_wcRev
.m_IsFull
= TRUE
;
93 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
94 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
95 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
96 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
97 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
99 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
105 m_LoadingThread
= NULL
;
107 InterlockedExchange(&m_bExitThread
,FALSE
);
108 m_IsOldFirst
= FALSE
;
109 m_IsRebaseReplaceGraph
= FALSE
;
111 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
113 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
115 // get short/long datetime setting from registry
116 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
117 if ( RegUseShortDateFormat
)
119 m_DateFormat
= DATE_SHORTDATE
;
123 m_DateFormat
= DATE_LONGDATE
;
125 // get relative time display setting from registry
126 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
127 m_bRelativeTimes
= (regRelativeTimes
!= 0);
128 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
130 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
131 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
132 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
133 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
134 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
135 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
137 m_ColumnRegKey
=_T("log");
139 m_bTagsBranchesOnRightSide
= !!CRegDWORD(_T("Software\\TortoiseGit\\DrawTagsBranchesOnRightSide"), FALSE
);
140 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
141 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
143 m_LineWidth
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogLineWidth"), 2));
144 m_NodeSize
= max(1, CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Graph\\LogNodeSize"), 10));
146 m_AsyncThreadExit
= FALSE
;
147 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
148 m_AsynDiffListLock
.Init();
150 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
151 if (m_DiffingThread
==NULL
)
153 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
159 int CGitLogListBase::AsyncDiffThread()
161 m_AsyncThreadExited
= false;
162 while(!m_AsyncThreadExit
)
164 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
167 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
169 m_AsynDiffListLock
.Lock();
170 pRev
= m_AsynDiffList
.back();
171 m_AsynDiffList
.pop_back();
172 m_AsynDiffListLock
.Unlock();
174 if( pRev
->m_CommitHash
.IsEmpty() )
176 if(pRev
->m_IsDiffFiles
)
179 pRev
->GetFiles(this).Clear();
180 pRev
->m_ParentHash
.clear();
181 pRev
->m_ParentHash
.push_back(m_HeadHash
);
182 if(g_Git
.IsInitRepos())
184 if (g_Git
.GetInitAddList(pRev
->GetFiles(this)))
185 CMessageBox::Show(NULL
, _T("Run ls-files failed!"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
190 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
193 int *action
= &dummyAction
;
194 SafeGetAction(pRev
, &action
);
197 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
198 *action
|= pRev
->GetFiles(this)[j
].m_Action
;
200 pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
);
202 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
203 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
205 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
206 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
207 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
210 m_critSec_AsyncDiff
.Lock();
211 int ret
= pRev
->CheckAndDiff();
212 m_critSec_AsyncDiff
.Unlock();
214 { // fetch change file list
215 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
217 if(i
< m_arShownList
.GetCount())
219 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
220 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
222 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
228 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
230 POSITION pos
= GetFirstSelectedItemPosition();
231 int nItem
= GetNextSelectedItem(pos
);
235 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(nItem
);
237 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
239 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
246 m_AsyncThreadExited
= true;
249 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
253 m_ContextMenuMask
&= hideMask
;
257 m_ContextMenuMask
&= ~hideMask
;
261 CGitLogListBase::~CGitLogListBase()
263 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
264 this->m_arShownList
.SafeRemoveAll();
266 DestroyIcon(m_hModifiedIcon
);
267 DestroyIcon(m_hReplacedIcon
);
268 DestroyIcon(m_hAddedIcon
);
269 DestroyIcon(m_hDeletedIcon
);
270 m_logEntries
.ClearAll();
273 DeleteObject(m_boldFont
);
275 if ( m_pStoreSelection
)
277 delete m_pStoreSelection
;
278 m_pStoreSelection
= NULL
;
281 SafeTerminateThread();
282 SafeTerminateAsyncDiffThread();
285 CloseHandle(m_AsyncDiffEvent
);
289 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
290 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
291 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
292 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
293 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
295 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
296 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
299 ON_MESSAGE(MSG_LOADED
,OnLoad
)
301 ON_WM_MEASUREITEM_REFLECT()
302 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
303 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
304 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
305 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
306 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
307 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
310 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
312 //if (m_nRowHeight>0)
314 lpMeasureItemStruct
->itemHeight
= 50;
318 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
321 return CHintListCtrl::OnCreate(lpCreateStruct
);
324 void CGitLogListBase::PreSubclassWindow()
326 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
327 // load the icons for the action columns
328 // m_Theme.Open(m_hWnd, L"ListView");
329 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
330 CHintListCtrl::PreSubclassWindow();
333 void CGitLogListBase::InsertGitColumn()
337 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
338 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
339 if (DWORD(regFullRowSelect
))
340 exStyle
|= LVS_EX_FULLROWSELECT
;
341 SetExtendedStyle(exStyle
);
343 // only load properties if we have a repository
344 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
345 UpdateProjectProperties();
347 static UINT normal
[] =
359 IDS_LOG_COMMIT_EMAIL
,
380 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
382 DWORD hideColumns
= 0;
383 if(this->m_IsRebaseReplaceGraph
)
385 hideColumns
|= GIT_LOG_GRAPH
;
386 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
390 hideColumns
|= GIT_LOG_REBASE
;
393 if(this->m_IsIDReplaceAction
)
395 hideColumns
|= GIT_LOG_ACTIONS
;
396 m_dwDefaultColumns
|= GIT_LOG_ID
;
397 m_dwDefaultColumns
|= GIT_LOG_HASH
;
401 hideColumns
|= GIT_LOG_ID
;
403 if(this->m_bShowBugtraqColumn
)
405 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
409 hideColumns
|= GIT_LOGLIST_BUG
;
413 m_ColumnManager
.SetNames(normal
, _countof(normal
));
414 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
420 * Resizes all columns in a list control to values in registry.
422 void CGitLogListBase::ResizeAllListCtrlCols()
424 // column max and min widths to allow
425 static const int nMinimumWidth
= 10;
426 static const int nMaximumWidth
= 1000;
427 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
430 int numcols
= pHdrCtrl
->GetItemCount();
431 for (int col
= 0; col
< numcols
; ++col
)
433 // get width for this col last time from registry
435 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
436 CRegDWORD
regwidth(regentry
, 0);
440 // no saved value, setup sensible defaults
441 if (col
== this->LOGLIST_MESSAGE
)
443 cx
= LOGLIST_MESSAGE_MIN
;
447 cx
= ICONITEMBORDER
+16*4;
450 if (cx
< nMinimumWidth
)
454 else if (cx
> nMaximumWidth
)
459 SetColumnWidth(col
, cx
);
466 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
469 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
470 rItem
.mask
= LVIF_STATE
;
471 rItem
.iItem
= (int)Index
;
472 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
475 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
478 if (!(rItem
.state
& LVIS_SELECTED
))
480 int action
= SafeGetAction(pLogEntry
);
481 if (action
& CTGitPath::LOGACTIONS_REBASE_SQUASH
)
482 brush
= ::CreateSolidBrush(RGB(156,156,156));
483 else if (action
& CTGitPath::LOGACTIONS_REBASE_EDIT
)
484 brush
= ::CreateSolidBrush(RGB(200,200,128));
486 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
488 if (rItem
.state
& LVIS_SELECTED
)
490 if (::GetFocus() == m_hWnd
)
491 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
493 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
496 InvalidateRect(rect
);
499 ::FillRect(hdc
, &rect
, brush
);
500 ::DeleteObject(brush
);
504 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
506 POINT point
= { 4, 4 };
508 rt2
.DeflateRect(1, 1);
509 rt2
.OffsetRect(2, 2);
511 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
512 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
513 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
514 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
515 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
517 ::SelectObject(hdc
, brush
);
518 rt2
.OffsetRect(-2, -2);
519 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
520 ::SelectObject(hdc
, oldbrush
);
521 ::SelectObject(hdc
, oldpen
);
522 ::DeleteObject(nullPen
);
523 ::DeleteObject(darkBrush
);
526 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
528 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
529 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
530 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
531 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
532 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
533 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
534 ::SelectObject(hdc
, oldpen
);
538 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
540 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
541 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
542 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
543 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
544 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
545 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
546 ::SelectObject(hdc
, oldpen
);
550 void CGitLogListBase::DrawTagBranchMessage(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> &refList
)
552 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
555 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
556 rItem
.mask
= LVIF_STATE
;
557 rItem
.iItem
= (int)index
;
558 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
564 HTHEME hTheme
= NULL
;
565 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
566 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
568 if (!m_bTagsBranchesOnRightSide
)
569 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
572 GetTextExtentPoint32(hdc
, L
" ", 1, &oneSpaceSize
);
573 rt
.left
+= oneSpaceSize
.cx
;
575 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
577 int txtState
= LISS_NORMAL
;
578 if (rItem
.state
& LVIS_SELECTED
)
579 txtState
= LISS_SELECTED
;
581 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, 0, &rt
);
585 if (rItem
.state
& LVIS_SELECTED
)
587 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
588 ::DrawText(hdc
,data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
589 ::SetTextColor(hdc
, clrOld
);
593 ::DrawText(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &rt
, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
597 if (m_bTagsBranchesOnRightSide
)
600 GetTextExtentPoint32(hdc
, data
->GetSubject(), data
->GetSubject().GetLength(), &size
);
602 rt
.left
+= oneSpaceSize
.cx
+ size
.cx
;
604 DrawTagBranch(hdc
, W_Dc
, hTheme
, rect
, rt
, rItem
, data
, refList
);
608 CloseThemeData(hTheme
);
613 void CGitLogListBase::DrawTagBranch(HDC hdc
, CDC
&W_Dc
, HTHEME hTheme
, CRect
&rect
, CRect
&rt
, LVITEM
&rItem
, GitRev
* data
, std::vector
<REFLABEL
> &refList
)
615 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
617 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
619 COLORREF colRef
= refList
[i
].color
;
620 bool singleRemote
= refList
[i
].singleRemote
;
621 bool hasTracking
= refList
[i
].hasTracking
;
622 bool sameName
= refList
[i
].sameName
;
623 bool annotatedTag
= refList
[i
].annotatedTag
;
625 //When row selected, ajust label color
626 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
628 if (rItem
.state
& LVIS_SELECTED
)
629 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
632 brush
= ::CreateSolidBrush(colRef
);
634 if (!shortname
.IsEmpty() && (rt
.left
< rect
.right
))
637 memset(&size
,0,sizeof(SIZE
));
638 GetTextExtentPoint32(hdc
, shortname
, shortname
.GetLength(), &size
);
640 rt
.SetRect(rt
.left
, rt
.top
, rt
.left
+ size
.cx
, rt
.bottom
);
643 int textpos
= DT_CENTER
;
645 if (rt
.right
> rect
.right
)
647 rt
.right
= rect
.right
;
656 textRect
.OffsetRect(8, 0);
664 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
668 //Fill interior of ref label
669 ::FillRect(hdc
, &rt
, brush
);
677 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
678 rectEdge
.DeflateRect(1, 1);
679 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
685 POINT trianglept
[3] = { { rt
.right
- 8, rt
.top
}, { rt
.right
, (rt
.top
+ rt
.bottom
) / 2 }, { rt
.right
- 8, rt
.bottom
} };
686 HRGN hrgn
= ::CreatePolygonRgn(trianglept
, 3, ALTERNATE
);
687 ::FillRgn(hdc
, hrgn
, brush
);
688 ::DeleteObject(hrgn
);
689 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
, NULL
);
691 HPEN oldpen
= (HPEN
)SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Lighten(colRef
, 50)));
692 ::LineTo(hdc
, trianglept
[1].x
- 1, trianglept
[1].y
- 1);
694 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, m_Colors
.Darken(colRef
, 50)));
695 ::LineTo(hdc
, trianglept
[2].x
- 1, trianglept
[2].y
- 1);
697 SelectObject(hdc
, pen
= ::CreatePen(PS_SOLID
, 2, colRef
));
698 ::MoveToEx(hdc
, trianglept
[0].x
- 1, trianglept
[2].y
- 3, NULL
);
699 ::LineTo(hdc
, trianglept
[0].x
- 1, trianglept
[0].y
);
701 SelectObject(hdc
, oldpen
);
704 //Draw text inside label
705 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
706 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
708 int txtState
= LISS_NORMAL
;
709 if (rItem
.state
& LVIS_SELECTED
)
710 txtState
= LISS_SELECTED
;
712 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &textRect
);
716 W_Dc
.SetBkMode(TRANSPARENT
);
717 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
719 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
720 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
721 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
722 ::SetTextColor(hdc
,clrOld
);
726 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
732 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
733 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
735 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
736 DrawLightning(hdc
, newRect
, color
, bold
);
741 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
742 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
744 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
745 DrawUpTriangle(hdc
, newRect
, color
, bold
);
748 rt
.left
= rt
.right
+ 1;
751 ::DeleteObject(brush
);
753 rt
.right
= rect
.right
;
756 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
758 // Returns ((256 - amount)*col1 + amount*col2) / 256;
759 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
760 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
761 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
764 Gdiplus::Color
GetGdiColor(COLORREF col
)
766 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
768 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
769 const COLORREF
& col
,const COLORREF
& activeColor
, int top
772 int h
= laneHeight
/ 2;
773 int m
= (x1
+ x2
) / 2;
774 int r
= (x2
- x1
) * m_NodeSize
/ 30;
777 #define P_CENTER m , h+top
778 #define P_0 x2, h+top
779 #define P_90 m , 0+top-1
780 #define P_180 x1, h+top
781 #define P_270 m , 2 * h+top +1
782 #define R_CENTER m - r, h - r+top, d, d
785 #define DELTA_UR_B 2*(x1 - m), 2*h +top
786 #define DELTA_UR_E 0*16, 90*16 +top // -,
788 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
789 #define DELTA_DR_E 270*16, 90*16 +top // -'
791 #define DELTA_UL_B 2*(x2 - m), 2*h +top
792 #define DELTA_UL_E 90*16, 90*16 +top // ,-
794 #define DELTA_DL_B 2*(x2 - m),2*-h +top
795 #define DELTA_DL_E 180*16, 90*16 // '-
797 #define CENTER_UR x1, 2*h, 225
798 #define CENTER_DR x1, 0 , 135
799 #define CENTER_UL x2, 2*h, 315
800 #define CENTER_DL x2, 0 , 45
803 Gdiplus::Graphics
graphics( hdc
);
805 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
814 Gdiplus::LinearGradientBrush
gradient(
815 Gdiplus::Point(x1
-2, h
+top
-2),
816 Gdiplus::Point(P_270
),
817 GetGdiColor(activeColor
),GetGdiColor(col
));
820 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
821 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
823 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
824 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
825 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
832 Gdiplus::LinearGradientBrush
gradient(
833 Gdiplus::Point(P_270
),
834 Gdiplus::Point(x2
+1, h
+top
-1),
835 GetGdiColor(col
),GetGdiColor(activeColor
));
838 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
839 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
841 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
842 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
843 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
852 Gdiplus::LinearGradientBrush
gradient(
853 Gdiplus::Point(x1
-2, h
+top
-2),
854 Gdiplus::Point(P_90
),
855 GetGdiColor(activeColor
),GetGdiColor(col
));
857 Gdiplus::Pen
mypen(&gradient
, (Gdiplus::REAL
)m_LineWidth
);
859 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
862 QConicalGradient
gradient(CENTER_DR
);
863 gradient
.setColorAt(0.375, activeCol
);
864 gradient
.setColorAt(0.625, col
);
865 myPen
.setBrush(gradient
);
867 p
->drawArc(P_CENTER
, DELTA_DR
);
876 //static QPen myPen(Qt::black, 2); // fast path here
878 pen
.CreatePen(PS_SOLID
,2,col
);
879 //myPen.setColor(col);
880 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
882 Gdiplus::Pen
myPen(GetGdiColor(col
), (Gdiplus::REAL
)m_LineWidth
);
884 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
891 case Lanes::NOT_ACTIVE
:
892 case Lanes::MERGE_FORK
:
893 case Lanes::MERGE_FORK_R
:
894 case Lanes::MERGE_FORK_L
:
899 //DrawLine(hdc,P_90,P_270);
900 graphics
.DrawLine(&myPen
,P_90
,P_270
);
901 //p->drawLine(P_90, P_270);
905 //DrawLine(hdc,P_CENTER,P_270);
906 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
907 //p->drawLine(P_CENTER, P_270);
911 case Lanes::BOUNDARY
:
912 case Lanes::BOUNDARY_C
:
913 case Lanes::BOUNDARY_R
:
914 case Lanes::BOUNDARY_L
:
915 //DrawLine(hdc,P_90, P_CENTER);
916 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
917 //p->drawLine(P_90, P_CENTER);
923 myPen
.SetColor(GetGdiColor(activeColor
));
927 case Lanes::MERGE_FORK
:
932 case Lanes::CROSS_EMPTY
:
933 case Lanes::BOUNDARY_C
:
934 //DrawLine(hdc,P_180,P_0);
935 graphics
.DrawLine(&myPen
,P_180
,P_0
);
936 //p->drawLine(P_180, P_0);
938 case Lanes::MERGE_FORK_R
:
939 case Lanes::BOUNDARY_R
:
940 //DrawLine(hdc,P_180,P_CENTER);
941 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
942 //p->drawLine(P_180, P_CENTER);
944 case Lanes::MERGE_FORK_L
:
947 case Lanes::BOUNDARY_L
:
948 //DrawLine(hdc,P_CENTER,P_0);
949 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
950 //p->drawLine(P_CENTER, P_0);
956 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
959 brush
.CreateSolidBrush(col
);
960 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
962 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
963 // center symbol, e.g. rect or ellipse
969 //p->setPen(Qt::NoPen);
971 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
972 graphics
.FillEllipse(&myBrush
, R_CENTER
);
973 //p->drawEllipse(R_CENTER);
975 case Lanes::MERGE_FORK
:
976 case Lanes::MERGE_FORK_R
:
977 case Lanes::MERGE_FORK_L
:
978 //p->setPen(Qt::NoPen);
980 //p->drawRect(R_CENTER);
981 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
982 graphics
.FillRectangle(&myBrush
, R_CENTER
);
984 case Lanes::UNAPPLIED
:
986 //p->setPen(Qt::NoPen);
987 //p->setBrush(Qt::red);
988 //p->drawRect(m - r, h - 1, d, 2);
989 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
990 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
994 //p->setPen(Qt::NoPen);
995 //p->setBrush(DARK_GREEN);
996 //p->drawRect(m - r, h - 1, d, 2);
997 //p->drawRect(m - 1, h - r, 2, d);
998 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
999 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
1000 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
1002 case Lanes::BOUNDARY
:
1003 //p->setBrush(back);
1004 //p->drawEllipse(R_CENTER);
1005 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
1006 graphics
.DrawEllipse(&myPen
, R_CENTER
);
1008 case Lanes::BOUNDARY_C
:
1009 case Lanes::BOUNDARY_R
:
1010 case Lanes::BOUNDARY_L
:
1011 //p->setBrush(back);
1012 //p->drawRect(R_CENTER);
1013 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
1014 graphics
.FillRectangle(&myBrush
,R_CENTER
);
1020 ::SelectObject(hdc
,oldpen
);
1021 ::SelectObject(hdc
,oldbrush
);
1030 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
1034 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
1035 if(data
->m_CommitHash
.IsEmpty())
1040 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1041 rItem
.mask
= LVIF_STATE
;
1042 rItem
.iItem
= (int)index
;
1043 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1046 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1048 if (data
->m_Lanes
.empty())
1049 m_logEntries
.setLane(data
->m_CommitHash
);
1051 std::vector
<int>& lanes
=data
->m_Lanes
;
1052 size_t laneNum
= lanes
.size();
1053 UINT activeLane
= 0;
1054 for (UINT i
= 0; i
< laneNum
; ++i
)
1055 if (Lanes::isMerge(lanes
[i
])) {
1061 int maxWidth
= rect
.Width();
1062 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1064 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1065 //if (opt.state & QStyle::State_Selected)
1066 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1068 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1075 if (ln
== Lanes::EMPTY
)
1078 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1079 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1083 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1089 if (ln
== Lanes::EMPTY
)
1092 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1093 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1095 if (ln
== Lanes::CROSS
)
1097 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1098 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1101 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1107 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1110 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1111 // Take the default processing unless we set this to something else below.
1112 *pResult
= CDRF_DODEFAULT
;
1114 if (m_bNoDispUpdates
)
1117 switch (pLVCD
->nmcd
.dwDrawStage
)
1121 *pResult
= CDRF_NOTIFYITEMDRAW
;
1125 case CDDS_ITEMPREPAINT
:
1127 // This is the prepaint stage for an item. Here's where we set the
1128 // item's text color.
1130 // Tell Windows to send draw notifications for each subitem.
1131 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1133 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1135 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1137 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1140 int action
= SafeGetAction(data
);
1141 if (action
& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
))
1142 crText
= RGB(128,128,128);
1144 if (action
& CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1145 pLVCD
->clrTextBk
= RGB(156,156,156);
1146 else if (action
& CTGitPath::LOGACTIONS_REBASE_EDIT
)
1147 pLVCD
->clrTextBk
= RGB(200,200,128);
1149 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1151 if (action
& CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1153 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1154 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1157 if (data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
)
1159 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1160 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1163 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1164 // crText = GetSysColor(COLOR_GRAYTEXT);
1166 if (data
->m_CommitHash
.IsEmpty())
1168 //crText = GetSysColor(RGB(200,200,0));
1169 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1170 // We changed the font, so we're returning CDRF_NEWFONT. This
1171 // tells the control to recalculate the extent of the text.
1172 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1176 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1178 if (m_bStrictStopped
)
1179 crText
= GetSysColor(COLOR_GRAYTEXT
);
1181 // Store the color back in the NMLVCUSTOMDRAW struct.
1182 pLVCD
->clrText
= crText
;
1186 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1188 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1190 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1193 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty() && (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
))
1195 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1198 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1200 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1201 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1203 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1204 if( !data
->m_CommitHash
.IsEmpty())
1205 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1207 *pResult
= CDRF_SKIPDEFAULT
;
1212 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1214 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1216 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1217 //if(!data->m_IsFull)
1219 //if(data->SafeFetchFullInfo(&g_Git))
1220 // this->Invalidate();
1221 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1224 if (!m_HashMap
[data
->m_CommitHash
].empty())
1228 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1230 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1232 std::vector
<REFLABEL
> refsToShow
;
1233 STRING_VECTOR remoteTrackingList
;
1234 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1235 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1237 CString str
= refList
[i
];
1240 refLabel
.color
= RGB(255, 255, 255);
1241 refLabel
.singleRemote
= false;
1242 refLabel
.hasTracking
= false;
1243 refLabel
.sameName
= false;
1244 refLabel
.annotatedTag
= false;
1245 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1247 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1249 if (refLabel
.name
== m_CurrentBranch
)
1250 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1252 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1254 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1255 CString pullRemote
= trackingEntry
.first
;
1256 CString pullBranch
= trackingEntry
.second
;
1257 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1259 CString defaultUpstream
;
1260 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1261 refLabel
.hasTracking
= true;
1262 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1265 for (size_t j
= i
+ 1; j
< refList
.size(); ++j
)
1267 if (refList
[j
] == defaultUpstream
)
1276 bool sameName
= pullBranch
== refLabel
.name
;
1277 refsToShow
.push_back(refLabel
);
1278 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1279 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1280 if (m_bSymbolizeRefNames
)
1282 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1284 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1285 refLabel
.singleRemote
= true;
1288 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1289 refLabel
.sameName
= sameName
;
1291 refsToShow
.push_back(refLabel
);
1292 remoteTrackingList
.push_back(defaultUpstream
);
1298 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1300 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1304 for (size_t j
= 0; j
< remoteTrackingList
.size(); ++j
)
1306 if (remoteTrackingList
[j
] == str
)
1315 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1316 if (m_bSymbolizeRefNames
)
1318 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1320 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1321 refLabel
.singleRemote
= true;
1325 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1327 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1329 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1330 refLabel
.annotatedTag
= str
.Right(3) == _T("^{}");
1332 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1334 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1336 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1337 refLabel
.name
= _T("stash");
1339 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1341 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1343 if (refLabel
.name
.Find(_T("good")) == 0)
1345 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1346 refLabel
.name
= _T("good");
1348 if (refLabel
.name
.Find(_T("bad")) == 0)
1350 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1351 refLabel
.name
= _T("bad");
1357 refsToShow
.push_back(refLabel
);
1360 if (refsToShow
.empty())
1362 *pResult
= CDRF_DODEFAULT
;
1366 DrawTagBranchMessage(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1368 *pResult
= CDRF_SKIPDEFAULT
;
1376 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1378 if(this->m_IsIDReplaceAction
)
1380 *pResult
= CDRF_DODEFAULT
;
1383 *pResult
= CDRF_DODEFAULT
;
1385 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1389 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1390 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1392 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1394 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1395 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1396 // Get the selected state of the
1397 // item being drawn.
1399 // Fill the background if necessary
1400 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1402 // Draw the icon(s) into the compatible DC
1403 int action
= SafeGetAction(pLogEntry
);
1405 if (!pLogEntry
->m_IsDiffFiles
)
1406 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1408 if (action
& CTGitPath::LOGACTIONS_MODIFIED
)
1409 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1412 if (action
& (CTGitPath::LOGACTIONS_ADDED
| CTGitPath::LOGACTIONS_COPY
))
1413 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1416 if (action
& CTGitPath::LOGACTIONS_DELETED
)
1417 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1420 if (action
& CTGitPath::LOGACTIONS_REPLACED
)
1421 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1423 *pResult
= CDRF_SKIPDEFAULT
;
1429 *pResult
= CDRF_DODEFAULT
;
1432 // CGitLogListBase message handlers
1434 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1436 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1438 // Create a pointer to the item
1439 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1441 // Do the list need text information?
1442 if (!(pItem
->mask
& LVIF_TEXT
))
1445 // By default, clear text buffer.
1446 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1448 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1451 if (m_bNoDispUpdates
|| bOutOfRange
)
1454 // Which item number?
1455 int itemid
= pItem
->iItem
;
1456 GitRev
* pLogEntry
= NULL
;
1457 if (itemid
< m_arShownList
.GetCount())
1458 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1463 temp
.Format(_T("%d"),pItem
->iItem
+1);
1468 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1472 switch (pItem
->iSubItem
)
1474 case this->LOGLIST_GRAPH
: //Graphic
1476 case this->LOGLIST_REBASE
:
1478 if (this->m_IsRebaseReplaceGraph
&& pLogEntry
)
1481 path
.m_Action
= SafeGetAction(pLogEntry
) & CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1482 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1486 case this->LOGLIST_ACTION
: //action -- no text in the column
1488 case this->LOGLIST_HASH
:
1490 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1492 case this->LOGLIST_ID
:
1493 if(this->m_IsIDReplaceAction
)
1494 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1496 case this->LOGLIST_MESSAGE
: //Message
1498 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1500 case this->LOGLIST_AUTHOR
: //Author
1502 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1504 case this->LOGLIST_DATE
: //Date
1505 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1506 lstrcpyn(pItem
->pszText
,
1507 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1511 case this->LOGLIST_EMAIL
:
1513 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1516 case this->LOGLIST_COMMIT_NAME
: //Commit
1518 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1521 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1523 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1526 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1527 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1528 lstrcpyn(pItem
->pszText
,
1529 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1532 case this->LOGLIST_BUG
: //Bug ID
1534 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1542 bool CGitLogListBase::IsOnStash(int index
)
1544 if (IsStash(reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
))))
1546 if (index
> 0 && IsStash(reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(index
- 1))))
1551 bool CGitLogListBase::IsStash(const GitRev
* pSelLogEntry
)
1553 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1555 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1561 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1564 if (pWnd
== GetHeaderCtrl())
1566 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1569 int selIndex
= GetSelectionMark();
1571 return; // nothing selected, nothing to do with a context menu
1573 // if the user selected the info text telling about not all revisions shown due to
1574 // the "stop on copy/rename" option, we also don't show the context menu
1575 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1578 // if the context menu is invoked through the keyboard, we have to use
1579 // a calculated position on where to anchor the menu on
1580 if ((point
.x
== -1) && (point
.y
== -1))
1583 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1584 ClientToScreen(&rect
);
1585 point
= rect
.CenterPoint();
1587 m_nSearchIndex
= selIndex
;
1588 m_bCancelled
= FALSE
;
1590 // calculate some information the context menu commands can use
1591 // CString pathURL = GetURLFromPath(m_path);
1593 POSITION pos
= GetFirstSelectedItemPosition();
1594 int indexNext
= GetNextSelectedItem(pos
);
1598 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1600 GitRev revSelected
= pSelLogEntry
->Rev
;
1601 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1602 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1604 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1606 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1607 if (changedpath
->lCopyFromRev
)
1608 revPrevious
= changedpath
->lCopyFromRev
;
1611 GitRev revSelected2
;
1614 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1615 revSelected2
= pLogEntry
->Rev
;
1617 bool bAllFromTheSameAuthor
= true;
1618 CString firstAuthor
;
1619 CLogDataVector selEntries
;
1620 GitRev revLowest
, revHighest
;
1621 GitRevRangeArray revisionRanges
;
1623 POSITION pos
= GetFirstSelectedItemPosition();
1624 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1625 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1626 selEntries
.push_back(pLogEntry
);
1627 firstAuthor
= pLogEntry
->sAuthor
;
1628 revLowest
= pLogEntry
->Rev
;
1629 revHighest
= pLogEntry
->Rev
;
1632 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1633 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1634 selEntries
.push_back(pLogEntry
);
1635 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1636 bAllFromTheSameAuthor
= false;
1637 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1638 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1644 int FirstSelect
=-1, LastSelect
=-1;
1645 pos
= GetFirstSelectedItemPosition();
1646 FirstSelect
= GetNextSelectedItem(pos
);
1649 LastSelect
= GetNextSelectedItem(pos
);
1651 //entry is selected, now show the popup menu
1653 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, revertmenu
;
1655 if (popup
.CreatePopupMenu())
1657 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1658 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1659 bool isMergeActive
= CTGitPath(g_Git
.m_CurrentDir
).IsMergeActive();
1660 bool isStash
= IsOnStash(indexNext
);
1662 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1663 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1665 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1666 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1668 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1669 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1671 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1672 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1674 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1675 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1676 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1678 if (GetSelectedCount() == 1)
1682 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1684 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1685 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1689 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1690 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1691 if (isMergeActive
&& (m_ContextMenuMask
& GetContextMenuBit(ID_MERGE_ABORT
)))
1692 popup
.AppendMenuIcon(ID_MERGE_ABORT
, IDS_MENUMERGEABORT
, IDI_MERGEABORT
);
1694 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1696 GitRev
*pRev
=pSelLogEntry
;
1697 if (pSelLogEntry
->m_ParentHash
.empty())
1701 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1703 catch (const char* msg
)
1705 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1708 if(pRev
->m_ParentHash
.size()<=1)
1710 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1715 gnudiffmenu
.CreatePopupMenu();
1716 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1718 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1719 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1721 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1724 str
.Format(IDS_PARENT
, i
+ 1);
1725 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1730 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1733 GitRev
*pRev
=pSelLogEntry
;
1734 if (pSelLogEntry
->m_ParentHash
.empty())
1738 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1740 catch (const char* msg
)
1742 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1745 if(pRev
->m_ParentHash
.size()<=1)
1747 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1748 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1749 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1753 diffmenu
.CreatePopupMenu();
1754 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1755 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1758 str
.Format(IDS_PARENT
, i
+ 1);
1759 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1760 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1762 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1763 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1769 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1770 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1772 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1773 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1775 if (pSelLogEntry
->m_CommitHash
.IsEmpty() && !isMergeActive
)
1777 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1778 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1781 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1783 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1784 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1786 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1787 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1789 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1792 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1794 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1795 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1797 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1801 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1803 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1805 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1807 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1809 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1810 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1812 // popup.AppendMenu(MF_SEPARATOR, NULL);
1817 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1819 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1821 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1822 GetSelectedCount() == 1)
1823 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1825 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1826 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1828 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1829 str
.Format(format
,g_Git
.GetCurrentBranch());
1831 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
&& !isStash
)
1832 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1834 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1835 str
.Format(format
,g_Git
.GetCurrentBranch());
1837 if (m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
&& !isStash
)
1838 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1841 // Add Switch Branch express Menu
1842 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1843 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
&& !isStash
)
1846 std::vector
<CString
*> branchs
;
1847 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1849 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1850 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1852 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1857 str
.LoadString(IDS_SWITCH_BRANCH
);
1859 if(branchs
.size() == 1)
1862 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1863 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1865 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1868 else if(branchs
.size() > 1)
1870 subbranchmenu
.CreatePopupMenu();
1871 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
1873 if (*branchs
[i
] != currentBranch
)
1875 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1876 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1880 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1884 if (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
&& !isStash
)
1885 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1887 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
) && !isStash
)
1888 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1890 if (m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
) && !isStash
)
1891 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1893 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1894 str
.Format(format
,g_Git
.GetCurrentBranch());
1896 if (pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
&& !isMergeActive
&& !isStash
)
1897 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1898 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1900 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1901 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1903 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
&& !isStash
)
1905 GitRev
*pRev
= pSelLogEntry
;
1906 if (pSelLogEntry
->m_ParentHash
.empty())
1910 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1912 catch (const char* msg
)
1914 MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg
), _T("TortoiseGit"), MB_ICONERROR
);
1917 if (pRev
->m_ParentHash
.size() == 1)
1919 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1923 revertmenu
.CreatePopupMenu();
1924 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
1926 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1929 str
.Format(IDS_PARENT
, i
+ 1);
1930 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
1935 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
) && !isStash
)
1936 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1938 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1943 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1945 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1946 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1947 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1948 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1951 if (GetSelectedCount() >= 2)
1953 bool bAddSeparator
= false;
1954 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1956 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1957 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1960 if (GetSelectedCount() == 2)
1962 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1963 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1965 if (!pSelLogEntry
->m_CommitHash
.IsEmpty())
1967 CString firstSelHash
= pSelLogEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
1968 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1969 CString lastSelHash
= pLastEntry
->m_CommitHash
.ToString().Left(g_Git
.GetShortHASHLength());
1971 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("..") + firstSelHash
);
1972 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE
, menu
, IDI_LOG
);
1973 menu
.Format(IDS_SHOWLOG_OF
, lastSelHash
+ _T("...") + firstSelHash
);
1974 popup
.AppendMenuIcon(ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE
, menu
, IDI_LOG
);
1977 bAddSeparator
= true;
1982 bAddSeparator
= true;
1985 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
&& !isMergeActive
)
1986 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1989 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1992 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1994 bool bAddSeparator
= false;
1995 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1997 if (m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
&& !isMergeActive
)
2001 headindex
= this->GetHeadIndex();
2002 if(headindex
>=0 && LastSelect
>= headindex
)
2004 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
2006 if (g_Git
.GetHash(hash
, head
))
2007 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
2008 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
2009 if(pLastEntry
->m_CommitHash
== hash
) {
2010 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
2011 bAddSeparator
= true;
2016 if (m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
&& !isMergeActive
) {
2017 if (GetSelectedCount() >= 2)
2018 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
2020 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
2021 bAddSeparator
= true;
2024 if (GetSelectedCount() <= 2 || (IsSelectionContinuous() && GetSelectedCount() > 0 && !isStash
))
2025 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
2026 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
2027 bAddSeparator
= true;
2031 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2034 if (m_hasWC
&& !isMergeActive
&& !isStash
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
2036 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
2037 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2040 if (GetSelectedCount() == 1)
2042 bool bAddSeparator
= false;
2043 if (m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !isStash
&& !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
2045 // show the push-option only if the log entry has an associated local branch
2046 bool isLocal
= false;
2047 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2049 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
2054 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
2055 bAddSeparator
= true;
2059 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
2061 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
2063 std::vector
<CString
*> branchs
;
2064 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
2066 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
2067 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
2070 if (branchs
.size() == 1)
2072 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
2075 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
2076 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
2077 bAddSeparator
= true;
2079 else if (branchs
.size() > 1)
2081 str
.LoadString(IDS_DELETE_BRANCHTAG
);
2082 submenu
.CreatePopupMenu();
2083 for (size_t i
= 0; i
< branchs
.size(); ++i
)
2085 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2086 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2089 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2090 bAddSeparator
= true;
2093 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2095 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2096 } // GetSelectedCount() == 1
2098 if (GetSelectedCount() != 0)
2100 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2101 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2102 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2103 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2104 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2105 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2108 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2109 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2111 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2112 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2114 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2115 // DialogEnableWindow(IDOK, FALSE);
2116 // SetPromptApp(&theApp);
2118 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2120 // EnableOKButton();
2121 } // if (popup.CreatePopupMenu())
2125 bool CGitLogListBase::IsSelectionContinuous()
2127 if ( GetSelectedCount()==1 )
2129 // if only one revision is selected, the selection is of course
2134 POSITION pos
= GetFirstSelectedItemPosition();
2135 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2138 int itemindex
= GetNextSelectedItem(pos
);
2141 int nextindex
= GetNextSelectedItem(pos
);
2142 if (nextindex
- itemindex
> 1)
2144 bContinuous
= false;
2147 itemindex
= nextindex
;
2153 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2157 POSITION pos
= GetFirstSelectedItemPosition();
2161 sRev
.LoadString(IDS_LOG_REVISION
);
2163 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2165 sDate
.LoadString(IDS_LOG_DATE
);
2167 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2171 CString sLogCopyText
;
2173 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2175 if (toCopy
== ID_COPY_ALL
)
2177 //pLogEntry->GetFiles(this)
2178 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2180 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2181 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2183 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2184 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2187 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2188 sPaths
+= _T(" ") + rename
;
2190 sPaths
+= _T("\r\n");
2193 CString body
= pLogEntry
->GetBody();
2194 body
.Replace(_T("\n"), _T("\r\n"));
2195 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"),
2196 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2197 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2199 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2200 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2202 sClipdata
+= sLogCopyText
;
2204 else if (toCopy
== ID_COPY_MESSAGE
)
2206 CString body
= pLogEntry
->GetBody();
2207 body
.Replace(_T("\n"), _T("\r\n"));
2208 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2210 else if (toCopy
== ID_COPY_SUBJECT
)
2212 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2217 sClipdata
+= _T("\r\n");
2218 sClipdata
+= pLogEntry
->m_CommitHash
;
2223 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2228 void CGitLogListBase::DiffSelectedRevWithPrevious()
2230 if (m_bThreadRunning
)
2233 int FirstSelect
=-1, LastSelect
=-1;
2234 POSITION pos
= GetFirstSelectedItemPosition();
2235 FirstSelect
= GetNextSelectedItem(pos
);
2238 LastSelect
= GetNextSelectedItem(pos
);
2241 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2244 UpdateLogInfoLabel();
2245 int selIndex
= m_LogList
.GetSelectionMark();
2248 int selCount
= m_LogList
.GetSelectedCount();
2252 // Find selected entry in the log list
2253 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2254 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2255 long rev1
= pLogEntry
->Rev
;
2257 CTGitPath path
= m_path
;
2259 // See how many files under the relative root were changed in selected revision
2261 LogChangedPath
* changed
= NULL
;
2262 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2264 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2265 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2272 if (m_path
.IsDirectory() && nChanged
== 1)
2274 // We're looking at the log for a directory and only one file under dir was changed in the revision
2275 // Do diff on that file instead of whole directory
2276 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2279 m_bCancelled
= FALSE
;
2280 DialogEnableWindow(IDOK
, FALSE
);
2281 SetPromptApp(&theApp
);
2282 theApp
.DoWaitCursor(1);
2286 GitDiff
diff(this, m_hWnd
, true);
2287 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2288 diff
.SetHEADPeg(m_LogRevision
);
2289 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2293 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2296 theApp
.DoWaitCursor(-1);
2301 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2303 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2306 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2308 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2310 if (pFindInfo
->lvfi
.psz
== 0)
2313 CString sCmp
= pFindInfo
->lvfi
.psz
;
2315 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2317 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2318 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2319 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2321 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2329 if (sCmp
.Compare(sRev
)==0)
2336 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2338 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2340 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2341 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2342 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2344 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2352 if (sCmp
.Compare(sRev
)==0)
2364 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2368 this->m_arShownList
.SafeRemoveAll();
2370 this->m_logEntries
.ClearAll();
2371 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2374 //this->m_logEntries.ParserFromLog();
2375 SetItemCountEx((int)m_logEntries
.size());
2377 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2381 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2382 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2387 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2388 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2400 int CGitLogListBase::BeginFetchLog()
2404 this->m_arShownList
.SafeRemoveAll();
2406 this->m_logEntries
.ClearAll();
2408 this->m_LogCache
.ClearAllParent();
2410 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2413 if(this->m_Path
.IsEmpty())
2419 mask
= CGit::LOG_INFO_ONLY_HASH
;
2420 if (m_bIncludeBoundaryCommits
)
2421 mask
|= CGit::LOG_INFO_BOUNDARY
;
2422 // if(this->m_bAllBranch)
2423 mask
|= m_ShowMask
;
2427 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2429 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2432 if (m_sRange
.IsEmpty())
2433 m_sRange
= _T("HEAD");
2436 data
.m_From
= m_From
;
2439 #if 0 /* use tortoiegit filter */
2440 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2441 data
.m_Author
= this->m_sFilterText
;
2443 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2444 data
.m_MessageFilter
= this->m_sFilterText
;
2446 data
.m_IsRegex
= m_bFilterWithRegex
;
2449 // follow does not work for directories
2450 if (!path
|| path
->IsDirectory())
2451 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2452 // follow does not work with all branches 8at least in TGit)
2453 if (mask
& CGit::LOG_INFO_FOLLOW
)
2454 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
;
2456 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2458 //this->m_logEntries.ParserFromLog();
2459 if(IsInWorkingThread())
2461 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2465 SetItemCountEx((int)m_logEntries
.size());
2470 [] { git_init(); } ();
2475 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2479 if (!g_Git
.CanParseRev(m_sRange
))
2481 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
))
2484 // if show all branches, pick any ref as dummy entry ref
2486 if (g_Git
.GetRefList(list
))
2487 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2488 if (list
.size() == 0)
2491 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2494 g_Git
.m_critGitDllSec
.Lock();
2496 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2498 g_Git
.m_critGitDllSec
.Unlock();
2504 g_Git
.m_critGitDllSec
.Unlock();
2506 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2509 g_Git
.m_critGitDllSec
.Unlock();
2514 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2516 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2518 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2520 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2522 DiffSelectedRevWithPrevious();
2527 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2534 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2536 // select all entries
2537 for (int i
=0; i
<GetItemCount(); ++i
)
2539 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2545 if (m_hAccel
&& !bSkipAccelerator
)
2547 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2553 //m_tooltips.RelayEvent(pMsg);
2554 return __super::PreTranslateMessage(pMsg
);
2557 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2559 // a double click on an entry in the revision list has happened
2562 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2563 DiffSelectedRevWithPrevious();
2566 int CGitLogListBase::FetchLogAsync(void * data
)
2570 m_bExitThread
=FALSE
;
2571 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2572 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2573 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2574 if (m_LoadingThread
==NULL
)
2576 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2577 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2578 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2584 //this is the thread function which calls the subversion function
2585 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2587 return ((CGitLogListBase
*)pVoid
)->LogThread();
2590 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2593 oldest
=CTime::GetCurrentTime();
2594 latest
=CTime(1971,1,2,0,0,0);
2595 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2597 if(m_logEntries
[i
].IsEmpty())
2600 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2601 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2603 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2604 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2612 UINT
CGitLogListBase::LogThread()
2614 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2616 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2617 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2623 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2624 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2629 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2630 bool bRegex
= false;
2631 if (m_bFilterWithRegex
)
2632 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2634 TRACE(_T("\n===Begin===\n"));
2635 //Update work copy item;
2637 if (!m_logEntries
.empty())
2639 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2641 m_arShownList
.SafeAdd(pRev
);
2645 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2647 // store commit number of the last selected commit/line before the refresh or -1
2648 int lastSelectedHashNItem
= -1;
2651 bool shouldWalk
= true;
2652 if (!g_Git
.CanParseRev(m_sRange
))
2654 // walk revisions if show all branches and there exists any ref
2655 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
))
2660 if (g_Git
.GetRefList(list
))
2661 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2662 if (list
.size() == 0)
2669 g_Git
.m_critGitDllSec
.Lock();
2673 [&] {git_get_log_firstcommit(m_DllGitLog
);}();
2674 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2679 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2682 g_Git
.m_critGitDllSec
.Unlock();
2685 t2
=t1
=GetTickCount();
2686 int oldprecentage
= 0;
2687 size_t oldsize
= m_logEntries
.size();
2688 std::map
<CGitHash
, std::set
<CGitHash
>> commitChildren
;
2689 while (ret
== 0 && !m_bExitThread
)
2691 g_Git
.m_critGitDllSec
.Lock();
2694 [&] { ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
); } ();
2698 g_Git
.m_critGitDllSec
.Unlock();
2700 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2703 g_Git
.m_critGitDllSec
.Unlock();
2708 if (commit
.m_ignore
== 1)
2710 git_free_commit(&commit
);
2714 //printf("%s\r\n",commit.GetSubject());
2718 CGitHash hash
= (char*)commit
.m_hash
;
2720 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2721 pRev
->m_GitCommit
= commit
;
2722 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2725 g_Git
.m_critGitDllSec
.Lock();
2728 git_get_notes(commit
.m_hash
, ¬e
);
2732 g_Git
.m_critGitDllSec
.Unlock();
2734 MessageBox(_T("Could not get commit notes.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2737 g_Git
.m_critGitDllSec
.Unlock();
2741 pRev
->m_Notes
.Empty();
2742 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2745 if(!pRev
->m_IsDiffFiles
)
2747 pRev
->m_CallDiffAsync
= DiffAsync
;
2750 pRev
->ParserParentFromCommit(&commit
);
2751 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
) // See also ShouldShowFilter()
2753 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
2755 const CGitHash
&parentHash
= pRev
->m_ParentHash
[i
];
2756 auto it
= commitChildren
.find(parentHash
);
2757 if (it
== commitChildren
.end())
2759 it
= commitChildren
.insert(make_pair(parentHash
, std::set
<CGitHash
>())).first
;
2761 it
->second
.insert(pRev
->m_CommitHash
);
2770 bool visible
= true;
2771 if(!m_sFilterText
.IsEmpty())
2773 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2776 if (visible
&& !ShouldShowFilter(pRev
, commitChildren
))
2778 this->m_critSec
.Lock();
2779 m_logEntries
.append(hash
, visible
);
2781 m_arShownList
.SafeAdd(pRev
);
2782 this->m_critSec
.Unlock();
2784 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2785 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2792 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2795 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2798 if(percent
< GITLOG_START
)
2799 percent
= GITLOG_START
+1;
2801 oldsize
= m_logEntries
.size();
2802 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2804 //if( percent > oldprecentage )
2806 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2807 oldprecentage
= percent
;
2810 if (lastSelectedHashNItem
>= 0)
2811 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2816 g_Git
.m_critGitDllSec
.Lock();
2817 git_close_log(m_DllGitLog
);
2818 g_Git
.m_critGitDllSec
.Unlock();
2824 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2829 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2831 if (lastSelectedHashNItem
>= 0)
2832 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2835 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2837 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2842 void CGitLogListBase::FetchRemoteList()
2844 STRING_VECTOR remoteList
;
2845 if (!g_Git
.GetRemoteList(remoteList
))
2846 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
2848 m_SingleRemote
= _T("");
2851 void CGitLogListBase::FetchTrackingBranchList()
2853 m_TrackingMap
.clear();
2854 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
2856 for (size_t j
= 0; j
< it
->second
.size(); ++j
)
2859 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
2862 configName
.Format(_T("branch.%s.remote"), branchName
);
2863 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2865 configName
.Format(_T("branch.%s.merge"), branchName
);
2866 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2868 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2870 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
2877 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2879 SafeTerminateThread();
2881 this->SetItemCountEx(0);
2886 // HACK to hide graph column
2887 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
2888 SetColumnWidth(0, 0);
2890 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
2892 //Update branch and Tag info
2894 //Assume Thread have exited
2895 //if(!m_bThreadRunning)
2897 m_logEntries
.clear();
2901 m_sFilterText
.Empty();
2906 InterlockedExchange(&m_bExitThread
,FALSE
);
2908 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2909 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2910 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2912 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2913 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2914 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2918 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, std::tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2922 std::tr1::regex_constants::syntax_option_type type
= std::tr1::regex_constants::ECMAScript
;
2924 type
|= std::tr1::regex_constants::icase
;
2925 pat
= std::tr1::wregex(regexp_str
, type
);
2928 catch (std::exception
) {}
2931 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, std::tr1::wregex
&pat
)
2934 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
2937 if ((bRegex
)&&(m_bFilterWithRegex
))
2939 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2941 if(this->m_bShowBugtraqColumn
)
2943 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2945 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2946 if (std::regex_search(std::wstring(sBugIds
), pat
, flags
))
2953 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2955 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2956 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2962 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2964 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2965 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2971 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2973 if (std::regex_search(std::wstring(pRev
->GetAuthorName()), pat
, flags
))
2978 if (std::regex_search(std::wstring(pRev
->GetCommitterName()), pat
, flags
))
2984 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
2986 if (std::regex_search(std::wstring(pRev
->GetAuthorEmail()), pat
, flags
))
2991 if (std::regex_search(std::wstring(pRev
->GetCommitterEmail()), pat
, flags
))
2997 if (m_SelectedFilters
& LOGFILTER_REVS
)
2999 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3000 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
))
3006 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3008 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3009 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3011 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
))
3018 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3020 CTGitPathList
*pathList
=NULL
;
3021 if( pRev
->m_IsDiffFiles
)
3022 pathList
= &pRev
->GetFiles(this);
3025 if(!pRev
->m_IsSimpleListReady
)
3026 pRev
->SafeGetSimpleList(&g_Git
);
3030 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
3032 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
3036 if (std::regex_search(std::wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
3042 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3044 if (std::regex_search(std::wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
3053 CString find
= m_sFilterText
;
3056 if (m_SelectedFilters
& LOGFILTER_BUGID
)
3058 if(this->m_bShowBugtraqColumn
)
3060 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
3062 sBugIds
.MakeLower();
3063 if ((sBugIds
.Find(find
) >= 0))
3070 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3072 CString msg
= pRev
->GetSubject();
3074 msg
= msg
.MakeLower();
3075 if ((msg
.Find(find
) >= 0))
3081 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3083 CString msg
= pRev
->GetBody();
3085 msg
= msg
.MakeLower();
3086 if ((msg
.Find(find
) >= 0))
3092 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3094 CString msg
= pRev
->GetAuthorName();
3095 msg
= msg
.MakeLower();
3096 if ((msg
.Find(find
) >= 0))
3102 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3104 CString msg
= pRev
->GetAuthorEmail();
3105 msg
= msg
.MakeLower();
3106 if ((msg
.Find(find
) >= 0))
3112 if (m_SelectedFilters
& LOGFILTER_REVS
)
3114 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
3115 if ((sRev
.Find(find
) >= 0))
3121 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3123 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
3124 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3126 if (it
->Find(find
) >= 0)
3133 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3135 CTGitPathList
*pathList
=NULL
;
3136 if( pRev
->m_IsDiffFiles
)
3137 pathList
= &pRev
->GetFiles(this);
3140 if(!pRev
->m_IsSimpleListReady
)
3141 pRev
->SafeGetSimpleList(&g_Git
);
3144 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3146 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3147 CString path
= cpath
->GetGitOldPathString();
3149 if ((path
.Find(find
)>=0))
3153 path
= cpath
->GetGitPathString();
3155 if ((path
.Find(find
)>=0))
3161 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3163 CString path
= pRev
->m_SimpleFileList
[i
];
3165 if ((path
.Find(find
)>=0))
3171 } // else (from if (bRegex))
3175 static bool CStringStartsWith(const CString
&str
, const CString
&prefix
)
3177 return str
.Left(prefix
.GetLength()) == prefix
;
3179 bool CGitLogListBase::ShouldShowFilter(GitRev
*pRev
, const std::map
<CGitHash
, std::set
<CGitHash
>> &commitChildren
)
3181 if (m_ShowFilter
& FILTERSHOW_ANYCOMMIT
)
3184 if (m_ShowFilter
& FILTERSHOW_REFS
)
3187 const STRING_VECTOR
&refList
= m_HashMap
[pRev
->m_CommitHash
];
3188 for (size_t i
= 0; i
< refList
.size(); ++i
)
3190 const CString
&str
= refList
[i
];
3191 if (CStringStartsWith(str
, _T("refs/heads/")))
3193 if (m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
)
3196 else if (CStringStartsWith(str
, _T("refs/remotes/")))
3198 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
3201 else if (CStringStartsWith(str
, _T("refs/tags/")))
3203 if (m_ShowRefMask
& LOGLIST_SHOWTAGS
)
3206 else if (CStringStartsWith(str
, _T("refs/stash")))
3208 if (m_ShowRefMask
& LOGLIST_SHOWSTASH
)
3211 else if (CStringStartsWith(str
, _T("refs/bisect/")))
3213 if (m_ShowRefMask
& LOGLIST_SHOWBISECT
)
3217 // Keep the head too.
3218 if (pRev
->m_CommitHash
== m_HeadHash
)
3222 if (m_ShowFilter
& FILTERSHOW_MERGEPOINTS
)
3224 if (pRev
->ParentsCount() > 1)
3226 auto childrenIt
= commitChildren
.find(pRev
->m_CommitHash
);
3227 if (childrenIt
!= commitChildren
.end())
3229 const std::set
<CGitHash
> &children
= childrenIt
->second
;
3230 if (children
.size() > 1)
3238 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3241 pShownlist
->SafeRemoveAll();
3243 std::tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3244 bool bRegex
= false;
3245 if (m_bFilterWithRegex
)
3246 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3248 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_any
;
3250 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3252 if ((bRegex
)&&(m_bFilterWithRegex
))
3255 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3257 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3258 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3260 pShownlist
->SafeAdd(m_logEntries
[i
]);
3265 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3267 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3268 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3270 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3274 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3276 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3277 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3279 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3283 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3285 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3288 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3290 CTGitPath cpath
= pathList
[cpPathIndex
];
3291 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3293 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3297 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3299 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3303 if (std::regex_search(std::wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3305 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3311 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3313 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3315 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3319 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3321 if (std::regex_search(std::wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3323 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3327 if (m_SelectedFilters
& LOGFILTER_REVS
)
3329 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3330 if (std::regex_search(std::wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3332 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3336 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3338 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3339 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3341 if (std::regex_search(std::wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3343 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3351 CString find
= m_sFilterText
;
3354 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3356 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3358 sBugIDs
= sBugIDs
.MakeLower();
3359 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3361 pShownlist
->SafeAdd(m_logEntries
[i
]);
3366 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3368 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3370 msg
= msg
.MakeLower();
3371 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3373 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3377 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3379 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3381 msg
= msg
.MakeLower();
3382 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3384 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3388 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3390 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3393 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3395 CTGitPath cpath
= pathList
[cpPathIndex
];
3396 CString path
= cpath
.GetGitOldPathString();
3398 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3400 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3404 path
= cpath
.GetGitPathString();
3406 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3408 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3412 path
= cpath
.GetActionName();
3414 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3416 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3422 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3424 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3425 msg
= msg
.MakeLower();
3426 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3428 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3432 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3434 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3435 msg
= msg
.MakeLower();
3436 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3438 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3442 if (m_SelectedFilters
& LOGFILTER_REVS
)
3444 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3445 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3447 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3451 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3453 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3454 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3456 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3458 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3463 } // else (from if (bRegex))
3464 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3468 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3471 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3477 return time <= m_To;
3480 return time >= m_From;
3482 return ((time >= m_From)&&(time <= m_To));
3484 return TRUE
; /* git dll will filter time range */
3488 void CGitLogListBase::StartFilter()
3490 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3491 RecalculateShownList(&m_arShownList
);
3492 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3496 SetItemCountEx(ShownCountWithStopped());
3497 RedrawItems(0, ShownCountWithStopped());
3501 void CGitLogListBase::RemoveFilter()
3504 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3506 m_arShownList
.SafeRemoveAll();
3508 // reset the time filter too
3510 m_timFrom
= (__time64_t(m_tFrom
));
3511 m_timTo
= (__time64_t(m_tTo
));
3512 m_DateFrom
.SetTime(&m_timFrom
);
3513 m_DateTo
.SetTime(&m_timTo
);
3514 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3515 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3518 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3520 if(this->m_IsOldFirst
)
3522 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3526 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3529 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3531 SetItemCountEx(ShownCountWithStopped());
3532 RedrawItems(0, ShownCountWithStopped());
3534 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3537 void CGitLogListBase::Clear()
3539 m_arShownList
.SafeRemoveAll();
3542 m_logEntries
.ClearAll();
3546 void CGitLogListBase::OnDestroy()
3548 // save the column widths to the registry
3551 SafeTerminateThread();
3552 SafeTerminateAsyncDiffThread();
3555 while(m_LogCache
.SaveCache())
3563 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3564 // MB_YESNO) == IDNO)
3568 CHintListCtrl::OnDestroy();
3571 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3575 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3576 this->InvalidateRect(rect
);
3582 * Save column widths to the registry
3584 void CGitLogListBase::SaveColumnWidths()
3586 int maxcol
= m_ColumnManager
.GetColumnCount();
3588 // HACK that graph column is always shown
3589 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3591 for (int col
= 0; col
< maxcol
; ++col
)
3592 if (m_ColumnManager
.IsVisible (col
))
3593 m_ColumnManager
.ColumnResized (col
);
3595 m_ColumnManager
.WriteSettings();
3598 int CGitLogListBase::GetHeadIndex()
3600 if(m_HeadHash
.IsEmpty())
3603 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3605 GitRev
*pRev
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3608 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3614 void CGitLogListBase::OnFind()
3618 m_pFindDialog
= new CFindDlg(this);
3619 m_pFindDialog
->Create(this);
3622 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3624 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3626 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3628 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3631 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3633 if (GetSelectedCount() != 0)
3636 CGitHash theSelectedHash
= m_lastSelectedHash
;
3637 SetItemState((int)itemToSelect
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3638 m_lastSelectedHash
= theSelectedHash
;
3640 int countPerPage
= GetCountPerPage();
3641 EnsureVisible(max(0, (int)itemToSelect
-countPerPage
/2), FALSE
);
3642 EnsureVisible(min(GetItemCount(), (int)itemToSelect
+countPerPage
/2), FALSE
);
3643 EnsureVisible((int)itemToSelect
, FALSE
);
3646 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3649 ASSERT(m_pFindDialog
!= NULL
);
3650 bool bFound
= false;
3653 if (m_pFindDialog
->IsTerminating())
3655 // invalidate the handle identifying the dialog box.
3656 m_pFindDialog
= NULL
;
3660 INT_PTR cnt
= m_arShownList
.GetCount();
3662 if(m_pFindDialog
->IsRef())
3665 str
=m_pFindDialog
->GetFindString();
3671 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3672 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3677 for (i
= 0; i
< cnt
; ++i
)
3679 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3680 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3689 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3694 if (m_pFindDialog
->FindNext() && !bFound
)
3696 //read data from dialog
3697 CString FindText
= m_pFindDialog
->GetFindString();
3698 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3700 std::tr1::wregex pat
;
3701 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3703 std::tr1::regex_constants::match_flag_type flags
= std::tr1::regex_constants::match_not_null
;
3705 for (i
= m_nSearchIndex
+ 1; ; ++i
)
3710 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 2, 100);
3712 if (m_nSearchIndex
>= 0)
3714 if (i
== m_nSearchIndex
)
3716 ::MessageBeep(0xFFFFFFFF);
3717 m_pFindDialog
->FlashWindowEx(FLASHW_ALL
, 3, 100);
3722 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3725 str
+=pLogEntry
->m_CommitHash
.ToString();
3728 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
3730 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3734 str
+=pLogEntry
->GetAuthorEmail();
3736 str
+=pLogEntry
->GetAuthorName();
3738 str
+=pLogEntry
->GetBody();
3740 str
+=pLogEntry
->GetCommitterEmail();
3742 str
+=pLogEntry
->GetCommitterName();
3744 str
+=pLogEntry
->GetSubject();
3748 /*Because changed files list is loaded on demand when gui show,
3749 files will empty when files have not fetched.
3751 we can add it back by using one-way diff(with outnumber changed and rename detect.
3752 here just need changed filename list. one-way is much quicker.
3754 if(pLogEntry
->m_IsFull
)
3756 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
3758 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3760 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3766 if(!pLogEntry
->m_IsSimpleListReady
)
3767 pLogEntry
->SafeGetSimpleList(&g_Git
);
3769 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
3771 str
+=pLogEntry
->m_SimpleFileList
[i
];
3780 if (std::regex_search(std::wstring(str
), pat
, flags
))
3790 if (str
.Find(FindText
) >= 0)
3800 msg
= msg
.MakeLower();
3801 CString find
= FindText
.MakeLower();
3802 if (msg
.Find(find
) >= 0)
3809 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3811 } // if(m_pFindDialog->FindNext())
3812 //UpdateLogInfoLabel();
3817 EnsureVisible(i
, FALSE
);
3818 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3819 SetItemState(i
, LVIS_SELECTED
| LVIS_FOCUSED
, LVIS_SELECTED
| LVIS_FOCUSED
);
3820 SetSelectionMark(i
);
3821 //FillLogMessageCtrl();
3828 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3830 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3835 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3837 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);