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"
27 //#include "VssStyle.h"
32 #include "GITProgressDlg.h"
33 #include "ProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
38 #include "MessageBox.h"
40 #include "LoglistUtils.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.h"
52 //#include "GitHelpers.h"
53 #include "GitStatus.h"
54 //#include "LogDlgHelper.h"
55 //#include "CachedLogInfo.h"
56 //#include "RepositoryInfo.h"
57 //#include "EditPropertiesDlg.h"
58 #include "FileDiffDlg.h"
59 #include "..\\TortoiseShell\\Resource.h"
63 const UINT
CGitLogListBase::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
64 const UINT
CGitLogListBase::m_ScrollToMessage
= RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
66 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
68 CGitLogListBase::CGitLogListBase():CHintListCtrl()
69 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
71 ,m_bNoDispUpdates(FALSE
)
72 , m_bThreadRunning(FALSE
)
73 , m_bStrictStopped(false)
74 , m_pStoreSelection(NULL
)
75 , m_SelectedFilters(LOGFILTER_ALL
)
77 , m_logEntries(&m_LogCache
)
79 , m_ColumnManager(this)
80 , m_dwDefaultColumns(0)
81 , m_arShownList(&m_critSec
)
83 , m_bNoHightlightHead(FALSE
)
84 , m_ShowRefMask(LOGLIST_SHOWALLREFS
)
86 // use the default GUI font, create a copy of it and
87 // change the copy to BOLD (leave the rest of the font
89 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
91 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
92 lf
.lfWeight
= FW_BOLD
;
93 m_boldFont
= CreateFontIndirect(&lf
);
95 m_bShowBugtraqColumn
=false;
97 m_IsIDReplaceAction
=FALSE
;
99 this->m_critSec
.Init();
100 m_wcRev
.m_CommitHash
.Empty();
101 m_wcRev
.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES
));
102 m_wcRev
.m_ParentHash
.clear();
103 m_wcRev
.m_Mark
=_T('-');
104 m_wcRev
.m_IsUpdateing
=FALSE
;
105 m_wcRev
.m_IsFull
= TRUE
;
107 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
108 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
109 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
110 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
111 m_hFetchIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
113 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
119 m_LoadingThread
= NULL
;
121 InterlockedExchange(&m_bExitThread
,FALSE
);
122 m_IsOldFirst
= FALSE
;
123 m_IsRebaseReplaceGraph
= FALSE
;
125 for (int i
= 0; i
< Lanes::COLORS_NUM
; ++i
)
127 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
129 // get short/long datetime setting from registry
130 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
131 if ( RegUseShortDateFormat
)
133 m_DateFormat
= DATE_SHORTDATE
;
137 m_DateFormat
= DATE_LONGDATE
;
139 // get relative time display setting from registry
140 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
141 m_bRelativeTimes
= (regRelativeTimes
!= 0);
142 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
144 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
145 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
146 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
147 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
148 m_ContextMenuMask
&= ~GetContextMenuBit(ID_LOG
);
149 m_ContextMenuMask
&= ~GetContextMenuBit(ID_BLAME
);
151 m_ColumnRegKey
=_T("log");
153 m_bSymbolizeRefNames
= !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE
);
155 m_AsyncThreadExit
= FALSE
;
156 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
157 m_AsynDiffListLock
.Init();
159 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
160 if (m_DiffingThread
==NULL
)
162 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
168 int CGitLogListBase::AsyncDiffThread()
170 m_AsyncThreadExited
= false;
171 while(!m_AsyncThreadExit
)
173 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
176 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
178 m_AsynDiffListLock
.Lock();
179 pRev
= m_AsynDiffList
.back();
180 m_AsynDiffList
.pop_back();
181 m_AsynDiffListLock
.Unlock();
183 if( pRev
->m_CommitHash
.IsEmpty() )
185 if(pRev
->m_IsDiffFiles
)
188 pRev
->GetFiles(this).Clear();
189 pRev
->m_ParentHash
.clear();
190 pRev
->m_ParentHash
.push_back(m_HeadHash
);
191 if(g_Git
.IsInitRepos())
193 g_Git
.GetInitAddList(pRev
->GetFiles(this));
198 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
200 pRev
->GetAction(this) = 0;
202 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
203 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
205 pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
);
207 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
208 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
210 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
211 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
212 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
215 if(!pRev
->CheckAndDiff())
216 { // fetch change file list
217 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
219 if(i
< m_arShownList
.GetCount())
221 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
222 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
224 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
230 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
232 POSITION pos
= GetFirstSelectedItemPosition();
233 int nItem
= GetNextSelectedItem(pos
);
237 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
239 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
241 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
248 m_AsyncThreadExited
= true;
251 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
255 m_ContextMenuMask
&= hideMask
;
259 m_ContextMenuMask
&= ~hideMask
;
263 CGitLogListBase::~CGitLogListBase()
265 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
266 this->m_arShownList
.SafeRemoveAll();
268 DestroyIcon(m_hModifiedIcon
);
269 DestroyIcon(m_hReplacedIcon
);
270 DestroyIcon(m_hAddedIcon
);
271 DestroyIcon(m_hDeletedIcon
);
272 m_logEntries
.ClearAll();
275 DeleteObject(m_boldFont
);
277 if ( m_pStoreSelection
)
279 delete m_pStoreSelection
;
280 m_pStoreSelection
= NULL
;
283 SafeTerminateThread();
284 SafeTerminateAsyncDiffThread();
287 CloseHandle(m_AsyncDiffEvent
);
291 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
292 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
293 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
294 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
295 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
297 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
298 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
301 ON_MESSAGE(MSG_LOADED
,OnLoad
)
303 ON_WM_MEASUREITEM_REFLECT()
304 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
305 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
306 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
307 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
308 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
309 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
312 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
314 //if (m_nRowHeight>0)
316 lpMeasureItemStruct
->itemHeight
= 50;
320 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
323 return CHintListCtrl::OnCreate(lpCreateStruct
);
326 void CGitLogListBase::PreSubclassWindow()
328 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
329 // load the icons for the action columns
330 // m_Theme.Open(m_hWnd, L"ListView");
331 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
332 CHintListCtrl::PreSubclassWindow();
335 void CGitLogListBase::InsertGitColumn()
339 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
340 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
341 if (DWORD(regFullRowSelect
))
342 exStyle
|= LVS_EX_FULLROWSELECT
;
343 SetExtendedStyle(exStyle
);
345 // only load properties if we have a repository
346 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
347 UpdateProjectProperties();
349 static UINT normal
[] =
361 IDS_LOG_COMMIT_EMAIL
,
382 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
384 DWORD hideColumns
= 0;
385 if(this->m_IsRebaseReplaceGraph
)
387 hideColumns
|= GIT_LOG_GRAPH
;
388 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
392 hideColumns
|= GIT_LOG_REBASE
;
395 if(this->m_IsIDReplaceAction
)
397 hideColumns
|= GIT_LOG_ACTIONS
;
398 m_dwDefaultColumns
|= GIT_LOG_ID
;
399 m_dwDefaultColumns
|= GIT_LOG_HASH
;
403 hideColumns
|= GIT_LOG_ID
;
405 if(this->m_bShowBugtraqColumn
)
407 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
411 hideColumns
|= GIT_LOGLIST_BUG
;
415 m_ColumnManager
.SetNames(normal
, _countof(normal
));
416 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
422 * Resizes all columns in a list control to values in registry.
424 void CGitLogListBase::ResizeAllListCtrlCols()
426 // column max and min widths to allow
427 static const int nMinimumWidth
= 10;
428 static const int nMaximumWidth
= 1000;
429 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
432 int numcols
= pHdrCtrl
->GetItemCount();
433 for (int col
= 0; col
< numcols
; ++col
)
435 // get width for this col last time from registry
437 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
438 CRegDWORD
regwidth(regentry
, 0);
442 // no saved value, setup sensible defaults
443 if (col
== this->LOGLIST_MESSAGE
)
445 cx
= LOGLIST_MESSAGE_MIN
;
449 cx
= ICONITEMBORDER
+16*4;
452 if (cx
< nMinimumWidth
)
456 else if (cx
> nMaximumWidth
)
461 SetColumnWidth(col
, cx
);
468 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
471 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
472 rItem
.mask
= LVIF_STATE
;
473 rItem
.iItem
= (int)Index
;
474 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
477 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
480 if (!(rItem
.state
& LVIS_SELECTED
))
482 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
483 brush
= ::CreateSolidBrush(RGB(156,156,156));
484 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
485 brush
= ::CreateSolidBrush(RGB(200,200,128));
487 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
489 if (rItem
.state
& LVIS_SELECTED
)
491 if (::GetFocus() == m_hWnd
)
492 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
494 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
500 ::FillRect(hdc
, &rect
, brush
);
501 ::DeleteObject(brush
);
505 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
507 POINT point
= { 4, 4 };
509 rt2
.DeflateRect(1, 1);
510 rt2
.OffsetRect(2, 2);
512 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
513 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
514 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
515 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
516 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
518 ::SelectObject(hdc
, brush
);
519 rt2
.OffsetRect(-2, -2);
520 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
521 ::SelectObject(hdc
, oldbrush
);
522 ::SelectObject(hdc
, oldpen
);
523 ::DeleteObject(nullPen
);
524 ::DeleteObject(darkBrush
);
527 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
529 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
530 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
531 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
532 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
533 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
534 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
535 ::SelectObject(hdc
, oldpen
);
539 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
541 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
542 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
543 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
544 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
545 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
546 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
547 ::SelectObject(hdc
, oldpen
);
551 void CGitLogListBase::DrawTagBranch(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> refList
)
553 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
556 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
557 rItem
.mask
= LVIF_STATE
;
558 rItem
.iItem
= (int)index
;
559 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
565 HTHEME hTheme
= NULL
;
566 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
567 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
569 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
571 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
573 COLORREF colRef
= refList
[i
].color
;
574 bool singleRemote
= refList
[i
].singleRemote
;
575 bool hasTracking
= refList
[i
].hasTracking
;
576 bool sameName
= refList
[i
].sameName
;
578 //When row selected, ajust label color
579 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
580 if (rItem
.state
& LVIS_SELECTED
)
581 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
583 brush
= ::CreateSolidBrush(colRef
);
585 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
588 memset(&size
,0,sizeof(SIZE
));
589 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
591 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
594 int textpos
= DT_CENTER
;
596 if(rt
.right
> rect
.right
)
598 rt
.right
= rect
.right
;
607 textRect
.OffsetRect(8, 0);
615 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
619 //Fill interior of ref label
620 ::FillRect(hdc
, &rt
, brush
);
629 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
630 rectEdge
.DeflateRect(1, 1);
631 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
634 //Draw text inside label
635 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
636 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
638 int txtState
= LISS_NORMAL
;
639 if (rItem
.state
& LVIS_SELECTED
)
640 txtState
= LISS_SELECTED
;
642 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &textRect
);
646 W_Dc
.SetBkMode(TRANSPARENT
);
647 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
649 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
650 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
651 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
652 ::SetTextColor(hdc
,clrOld
);
656 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
662 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
663 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
665 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
666 DrawLightning(hdc
, newRect
, color
, bold
);
671 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
672 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
674 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
675 DrawUpTriangle(hdc
, newRect
, color
, bold
);
678 //::MoveToEx(hdc,rt.left,rt.top,NULL);
679 //::LineTo(hdc,rt.right,rt.top);
680 //::LineTo(hdc,rt.right,rt.bottom);
681 //::LineTo(hdc,rt.left,rt.bottom);
682 //::LineTo(hdc,rt.left,rt.top);
687 ::DeleteObject(brush
);
691 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
693 int txtState
= LISS_NORMAL
;
694 if (rItem
.state
& LVIS_SELECTED
)
695 txtState
= LISS_SELECTED
;
697 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, 0, &rt
);
701 if (rItem
.state
& LVIS_SELECTED
)
703 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
704 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
705 ::SetTextColor(hdc
,clrOld
);
709 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
714 CloseThemeData(hTheme
);
719 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
721 // Returns ((256 - amount)*col1 + amount*col2) / 256;
722 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
723 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
724 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
727 Gdiplus::Color
GetGdiColor(COLORREF col
)
729 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
731 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
732 const COLORREF
& col
,const COLORREF
& activeColor
, int top
735 int h
= laneHeight
/ 2;
736 int m
= (x1
+ x2
) / 2;
737 int r
= (x2
- x1
) / 3;
740 #define P_CENTER m , h+top
741 #define P_0 x2, h+top
742 #define P_90 m , 0+top-1
743 #define P_180 x1, h+top
744 #define P_270 m , 2 * h+top +1
745 #define R_CENTER m - r, h - r+top, d, d
748 #define DELTA_UR_B 2*(x1 - m), 2*h +top
749 #define DELTA_UR_E 0*16, 90*16 +top // -,
751 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
752 #define DELTA_DR_E 270*16, 90*16 +top // -'
754 #define DELTA_UL_B 2*(x2 - m), 2*h +top
755 #define DELTA_UL_E 90*16, 90*16 +top // ,-
757 #define DELTA_DL_B 2*(x2 - m),2*-h +top
758 #define DELTA_DL_E 180*16, 90*16 // '-
760 #define CENTER_UR x1, 2*h, 225
761 #define CENTER_DR x1, 0 , 135
762 #define CENTER_UL x2, 2*h, 315
763 #define CENTER_DL x2, 0 , 45
766 Gdiplus::Graphics
graphics( hdc
);
768 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
777 Gdiplus::LinearGradientBrush
gradient(
778 Gdiplus::Point(x1
-2, h
+top
-2),
779 Gdiplus::Point(P_270
),
780 GetGdiColor(activeColor
),GetGdiColor(col
));
783 Gdiplus::Pen
mypen(&gradient
,2);
784 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
786 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
787 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
788 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
795 Gdiplus::LinearGradientBrush
gradient(
796 Gdiplus::Point(P_270
),
797 Gdiplus::Point(x2
+1, h
+top
-1),
798 GetGdiColor(col
),GetGdiColor(activeColor
));
801 Gdiplus::Pen
mypen(&gradient
,2);
802 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
804 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
805 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
806 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
815 Gdiplus::LinearGradientBrush
gradient(
816 Gdiplus::Point(x1
-2, h
+top
-2),
817 Gdiplus::Point(P_90
),
818 GetGdiColor(activeColor
),GetGdiColor(col
));
820 Gdiplus::Pen
mypen(&gradient
,2);
822 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
825 QConicalGradient
gradient(CENTER_DR
);
826 gradient
.setColorAt(0.375, activeCol
);
827 gradient
.setColorAt(0.625, col
);
828 myPen
.setBrush(gradient
);
830 p
->drawArc(P_CENTER
, DELTA_DR
);
839 //static QPen myPen(Qt::black, 2); // fast path here
841 pen
.CreatePen(PS_SOLID
,2,col
);
842 //myPen.setColor(col);
843 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
845 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
847 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
854 case Lanes::NOT_ACTIVE
:
855 case Lanes::MERGE_FORK
:
856 case Lanes::MERGE_FORK_R
:
857 case Lanes::MERGE_FORK_L
:
862 //DrawLine(hdc,P_90,P_270);
863 graphics
.DrawLine(&myPen
,P_90
,P_270
);
864 //p->drawLine(P_90, P_270);
868 //DrawLine(hdc,P_CENTER,P_270);
869 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
870 //p->drawLine(P_CENTER, P_270);
874 case Lanes::BOUNDARY
:
875 case Lanes::BOUNDARY_C
:
876 case Lanes::BOUNDARY_R
:
877 case Lanes::BOUNDARY_L
:
878 //DrawLine(hdc,P_90, P_CENTER);
879 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
880 //p->drawLine(P_90, P_CENTER);
886 myPen
.SetColor(GetGdiColor(activeColor
));
890 case Lanes::MERGE_FORK
:
895 case Lanes::CROSS_EMPTY
:
896 case Lanes::BOUNDARY_C
:
897 //DrawLine(hdc,P_180,P_0);
898 graphics
.DrawLine(&myPen
,P_180
,P_0
);
899 //p->drawLine(P_180, P_0);
901 case Lanes::MERGE_FORK_R
:
902 case Lanes::BOUNDARY_R
:
903 //DrawLine(hdc,P_180,P_CENTER);
904 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
905 //p->drawLine(P_180, P_CENTER);
907 case Lanes::MERGE_FORK_L
:
910 case Lanes::BOUNDARY_L
:
911 //DrawLine(hdc,P_CENTER,P_0);
912 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
913 //p->drawLine(P_CENTER, P_0);
919 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
922 brush
.CreateSolidBrush(col
);
923 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
925 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
926 // center symbol, e.g. rect or ellipse
932 //p->setPen(Qt::NoPen);
934 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
935 graphics
.FillEllipse(&myBrush
, R_CENTER
);
936 //p->drawEllipse(R_CENTER);
938 case Lanes::MERGE_FORK
:
939 case Lanes::MERGE_FORK_R
:
940 case Lanes::MERGE_FORK_L
:
941 //p->setPen(Qt::NoPen);
943 //p->drawRect(R_CENTER);
944 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
945 graphics
.FillRectangle(&myBrush
, R_CENTER
);
947 case Lanes::UNAPPLIED
:
949 //p->setPen(Qt::NoPen);
950 //p->setBrush(Qt::red);
951 //p->drawRect(m - r, h - 1, d, 2);
952 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
953 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
957 //p->setPen(Qt::NoPen);
958 //p->setBrush(DARK_GREEN);
959 //p->drawRect(m - r, h - 1, d, 2);
960 //p->drawRect(m - 1, h - r, 2, d);
961 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
962 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
963 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
965 case Lanes::BOUNDARY
:
967 //p->drawEllipse(R_CENTER);
968 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
969 graphics
.DrawEllipse(&myPen
, R_CENTER
);
971 case Lanes::BOUNDARY_C
:
972 case Lanes::BOUNDARY_R
:
973 case Lanes::BOUNDARY_L
:
975 //p->drawRect(R_CENTER);
976 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
977 graphics
.FillRectangle(&myBrush
,R_CENTER
);
983 ::SelectObject(hdc
,oldpen
);
984 ::SelectObject(hdc
,oldbrush
);
993 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
997 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
998 if(data
->m_CommitHash
.IsEmpty())
1003 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1004 rItem
.mask
= LVIF_STATE
;
1005 rItem
.iItem
= (int)index
;
1006 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1009 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1011 if (data
->m_Lanes
.empty())
1012 m_logEntries
.setLane(data
->m_CommitHash
);
1014 std::vector
<int>& lanes
=data
->m_Lanes
;
1015 size_t laneNum
= lanes
.size();
1016 UINT activeLane
= 0;
1017 for (UINT i
= 0; i
< laneNum
; ++i
)
1018 if (Lanes::isMerge(lanes
[i
])) {
1024 int maxWidth
= rect
.Width();
1025 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1027 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1028 //if (opt.state & QStyle::State_Selected)
1029 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1031 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1038 if (ln
== Lanes::EMPTY
)
1041 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1042 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1046 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1052 if (ln
== Lanes::EMPTY
)
1055 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1056 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1058 if (ln
== Lanes::CROSS
)
1060 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1061 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1064 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1070 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1073 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1074 // Take the default processing unless we set this to something else below.
1075 *pResult
= CDRF_DODEFAULT
;
1077 if (m_bNoDispUpdates
)
1080 switch (pLVCD
->nmcd
.dwDrawStage
)
1084 *pResult
= CDRF_NOTIFYITEMDRAW
;
1088 case CDDS_ITEMPREPAINT
:
1090 // This is the prepaint stage for an item. Here's where we set the
1091 // item's text color.
1093 // Tell Windows to send draw notifications for each subitem.
1094 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1096 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1098 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1100 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1103 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1104 crText
= RGB(128,128,128);
1106 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1107 pLVCD
->clrTextBk
= RGB(156,156,156);
1108 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1109 pLVCD
->clrTextBk
= RGB(200,200,128);
1111 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1113 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1115 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1116 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1119 if (data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
)
1121 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1122 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1125 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1126 // crText = GetSysColor(COLOR_GRAYTEXT);
1128 if (data
->m_CommitHash
.IsEmpty())
1130 //crText = GetSysColor(RGB(200,200,0));
1131 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1132 // We changed the font, so we're returning CDRF_NEWFONT. This
1133 // tells the control to recalculate the extent of the text.
1134 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1138 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1140 if (m_bStrictStopped
)
1141 crText
= GetSysColor(COLOR_GRAYTEXT
);
1143 // Store the color back in the NMLVCUSTOMDRAW struct.
1144 pLVCD
->clrText
= crText
;
1148 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1150 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1152 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1155 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty())
1157 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1160 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1162 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1163 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1165 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1166 if( !data
->m_CommitHash
.IsEmpty())
1167 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1169 *pResult
= CDRF_SKIPDEFAULT
;
1174 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1176 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1178 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1179 //if(!data->m_IsFull)
1181 //if(data->SafeFetchFullInfo(&g_Git))
1182 // this->Invalidate();
1183 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1186 if (!m_HashMap
[data
->m_CommitHash
].empty())
1190 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1192 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1194 std::vector
<REFLABEL
> refsToShow
;
1195 STRING_VECTOR remoteTrackingList
;
1196 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1197 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1199 CString str
= refList
[i
];
1202 refLabel
.color
= RGB(255, 255, 255);
1203 refLabel
.singleRemote
= false;
1204 refLabel
.hasTracking
= false;
1205 refLabel
.sameName
= false;
1206 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1208 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1210 if (refLabel
.name
== m_CurrentBranch
)
1211 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1213 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1215 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1216 CString pullRemote
= trackingEntry
.first
;
1217 CString pullBranch
= trackingEntry
.second
;
1218 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1220 CString defaultUpstream
;
1221 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1222 refLabel
.hasTracking
= true;
1223 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1226 for (int j
= i
+ 1; j
< refList
.size(); ++j
)
1228 if (refList
[j
] == defaultUpstream
)
1237 bool sameName
= pullBranch
== refLabel
.name
;
1238 refsToShow
.push_back(refLabel
);
1239 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1240 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1241 if (m_bSymbolizeRefNames
)
1243 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1245 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1246 refLabel
.singleRemote
= true;
1249 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1250 refLabel
.sameName
= sameName
;
1252 refsToShow
.push_back(refLabel
);
1253 remoteTrackingList
.push_back(defaultUpstream
);
1259 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1261 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1265 for (int j
= 0; j
< remoteTrackingList
.size(); ++j
)
1267 if (remoteTrackingList
[j
] == str
)
1276 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1277 if (m_bSymbolizeRefNames
)
1279 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1281 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1282 refLabel
.singleRemote
= true;
1286 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1288 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1290 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1292 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1294 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1296 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1297 refLabel
.name
= _T("stash");
1299 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1301 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1303 if (refLabel
.name
.Find(_T("good")) == 0)
1305 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1306 refLabel
.name
= _T("good");
1308 if (refLabel
.name
.Find(_T("bad")) == 0)
1310 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1311 refLabel
.name
= _T("bad");
1317 refsToShow
.push_back(refLabel
);
1320 if (refsToShow
.empty())
1322 *pResult
= CDRF_DODEFAULT
;
1326 DrawTagBranch(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1328 *pResult
= CDRF_SKIPDEFAULT
;
1336 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1338 if(this->m_IsIDReplaceAction
)
1340 *pResult
= CDRF_DODEFAULT
;
1343 *pResult
= CDRF_DODEFAULT
;
1345 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1349 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1350 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1352 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1354 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1355 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1356 // Get the selected state of the
1357 // item being drawn.
1359 // Fill the background if necessary
1360 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1362 // Draw the icon(s) into the compatible DC
1363 pLogEntry
->GetAction(this);
1365 if (!pLogEntry
->m_IsDiffFiles
)
1366 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1368 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1369 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1372 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1373 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1376 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1377 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1380 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1381 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1383 *pResult
= CDRF_SKIPDEFAULT
;
1389 *pResult
= CDRF_DODEFAULT
;
1392 // CGitLogListBase message handlers
1394 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1396 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1398 // Create a pointer to the item
1399 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1401 // Do the list need text information?
1402 if (!(pItem
->mask
& LVIF_TEXT
))
1405 // By default, clear text buffer.
1406 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1408 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1411 if (m_bNoDispUpdates
|| bOutOfRange
)
1414 // Which item number?
1415 int itemid
= pItem
->iItem
;
1416 GitRev
* pLogEntry
= NULL
;
1417 if (itemid
< m_arShownList
.GetCount())
1418 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1423 temp
.Format(_T("%d"),pItem
->iItem
+1);
1428 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1432 switch (pItem
->iSubItem
)
1434 case this->LOGLIST_GRAPH
: //Graphic
1436 case this->LOGLIST_REBASE
:
1438 if(this->m_IsRebaseReplaceGraph
)
1441 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1442 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1446 case this->LOGLIST_ACTION
: //action -- no text in the column
1448 case this->LOGLIST_HASH
:
1450 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1452 case this->LOGLIST_ID
:
1453 if(this->m_IsIDReplaceAction
)
1454 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1456 case this->LOGLIST_MESSAGE
: //Message
1458 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1460 case this->LOGLIST_AUTHOR
: //Author
1462 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1464 case this->LOGLIST_DATE
: //Date
1465 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1466 lstrcpyn(pItem
->pszText
,
1467 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1471 case this->LOGLIST_EMAIL
:
1473 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1476 case this->LOGLIST_COMMIT_NAME
: //Commit
1478 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1481 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1483 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1486 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1487 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1488 lstrcpyn(pItem
->pszText
,
1489 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1492 case this->LOGLIST_BUG
: //Bug ID
1494 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1502 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1505 if (pWnd
== GetHeaderCtrl())
1507 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1510 int selIndex
= GetSelectionMark();
1512 return; // nothing selected, nothing to do with a context menu
1514 // if the user selected the info text telling about not all revisions shown due to
1515 // the "stop on copy/rename" option, we also don't show the context menu
1516 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1519 // if the context menu is invoked through the keyboard, we have to use
1520 // a calculated position on where to anchor the menu on
1521 if ((point
.x
== -1) && (point
.y
== -1))
1524 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1525 ClientToScreen(&rect
);
1526 point
= rect
.CenterPoint();
1528 m_nSearchIndex
= selIndex
;
1529 m_bCancelled
= FALSE
;
1531 // calculate some information the context menu commands can use
1532 // CString pathURL = GetURLFromPath(m_path);
1534 POSITION pos
= GetFirstSelectedItemPosition();
1535 int indexNext
= GetNextSelectedItem(pos
);
1539 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1541 GitRev revSelected
= pSelLogEntry
->Rev
;
1542 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1543 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1545 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1547 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1548 if (changedpath
->lCopyFromRev
)
1549 revPrevious
= changedpath
->lCopyFromRev
;
1552 GitRev revSelected2
;
1555 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1556 revSelected2
= pLogEntry
->Rev
;
1558 bool bAllFromTheSameAuthor
= true;
1559 CString firstAuthor
;
1560 CLogDataVector selEntries
;
1561 GitRev revLowest
, revHighest
;
1562 GitRevRangeArray revisionRanges
;
1564 POSITION pos
= GetFirstSelectedItemPosition();
1565 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1566 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1567 selEntries
.push_back(pLogEntry
);
1568 firstAuthor
= pLogEntry
->sAuthor
;
1569 revLowest
= pLogEntry
->Rev
;
1570 revHighest
= pLogEntry
->Rev
;
1573 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1574 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1575 selEntries
.push_back(pLogEntry
);
1576 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1577 bAllFromTheSameAuthor
= false;
1578 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1579 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1585 int FirstSelect
=-1, LastSelect
=-1;
1586 pos
= GetFirstSelectedItemPosition();
1587 FirstSelect
= GetNextSelectedItem(pos
);
1590 LastSelect
= GetNextSelectedItem(pos
);
1592 //entry is selected, now show the popup menu
1594 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, revertmenu
;
1596 if (popup
.CreatePopupMenu())
1598 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1599 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1601 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1602 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1604 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1605 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1607 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1608 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1610 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1611 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1613 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1614 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1615 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1617 if (GetSelectedCount() == 1)
1621 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1623 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1624 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1628 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1629 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1631 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1633 GitRev
*pRev
=pSelLogEntry
;
1634 if (pSelLogEntry
->m_ParentHash
.empty())
1636 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1638 if(pRev
->m_ParentHash
.size()<=1)
1640 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1645 gnudiffmenu
.CreatePopupMenu();
1646 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1648 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1649 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1651 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1654 str
.Format(IDS_PARENT
, i
+ 1);
1655 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1660 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1663 GitRev
*pRev
=pSelLogEntry
;
1664 if (pSelLogEntry
->m_ParentHash
.empty())
1666 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1668 if(pRev
->m_ParentHash
.size()<=1)
1670 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1671 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1672 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1676 diffmenu
.CreatePopupMenu();
1677 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1678 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1681 str
.Format(IDS_PARENT
, i
+ 1);
1682 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1683 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1685 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1686 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1692 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1693 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1695 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1696 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1698 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1700 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1701 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1704 bool isStash
= false;
1705 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1707 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1714 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1716 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1717 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1719 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1720 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1722 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1725 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1727 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1728 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1730 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1734 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1736 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1738 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1740 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1742 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1743 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1745 // popup.AppendMenu(MF_SEPARATOR, NULL);
1750 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1752 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1754 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1755 GetSelectedCount() == 1)
1756 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1758 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1759 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1761 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1762 str
.Format(format
,g_Git
.GetCurrentBranch());
1764 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
)
1765 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1767 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1768 str
.Format(format
,g_Git
.GetCurrentBranch());
1770 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1771 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1774 // Add Switch Branch express Menu
1775 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1776 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1779 std::vector
<CString
*> branchs
;
1780 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1782 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1783 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1785 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1790 str
.LoadString(IDS_SWITCH_BRANCH
);
1792 if(branchs
.size() == 1)
1795 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1796 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1798 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1801 else if(branchs
.size() > 1)
1803 subbranchmenu
.CreatePopupMenu();
1804 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
1806 if (*branchs
[i
] != currentBranch
)
1808 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1809 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1813 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1817 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1818 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1820 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1821 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1823 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1824 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1826 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1827 str
.Format(format
,g_Git
.GetCurrentBranch());
1829 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
)
1830 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1831 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1833 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1834 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1836 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1838 GitRev
*pRev
= pSelLogEntry
;
1839 if (pSelLogEntry
->m_ParentHash
.empty())
1841 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1843 if (pRev
->m_ParentHash
.size() == 1)
1845 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1849 revertmenu
.CreatePopupMenu();
1850 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
1852 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1855 str
.Format(IDS_PARENT
, i
+ 1);
1856 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
1861 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1862 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1864 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1869 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1871 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1872 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1873 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1874 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1877 if (GetSelectedCount() >= 2)
1879 bool bAddSeparator
= false;
1880 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1882 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1883 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1886 if (GetSelectedCount() == 2)
1888 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1889 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1890 bAddSeparator
= true;
1895 bAddSeparator
= true;
1898 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1899 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1902 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1905 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1907 bool bAddSeparator
= false;
1908 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1910 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
)
1914 headindex
= this->GetHeadIndex();
1915 if(headindex
>=0 && LastSelect
>= headindex
)
1917 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1919 if (g_Git
.GetHash(hash
, head
))
1920 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
1921 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1922 if(pLastEntry
->m_CommitHash
== hash
) {
1923 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1924 bAddSeparator
= true;
1929 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
) {
1930 if (GetSelectedCount() >= 2)
1931 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
1933 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1934 bAddSeparator
= true;
1937 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1938 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1939 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1940 bAddSeparator
= true;
1944 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1947 if (m_hasWC
&& (m_ContextMenuMask
& GetContextMenuBit(ID_BISECTSTART
)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(FirstSelect
))->m_CommitHash
.IsEmpty() && !CTGitPath(g_Git
.m_CurrentDir
).IsBisectActive())
1949 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
1950 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1953 if (GetSelectedCount() == 1)
1955 bool bAddSeparator
= false;
1956 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
1958 // show the push-option only if the log entry has an associated local branch
1959 bool isLocal
= false;
1960 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1962 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1967 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1968 bAddSeparator
= true;
1972 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1974 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1976 std::vector
<CString
*> branchs
;
1977 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1979 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
1980 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1983 if (branchs
.size() == 1)
1985 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1988 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1989 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
1990 bAddSeparator
= true;
1992 else if (branchs
.size() > 1)
1994 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1995 submenu
.CreatePopupMenu();
1996 for (size_t i
= 0; i
< branchs
.size(); ++i
)
1998 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
1999 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2002 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2003 bAddSeparator
= true;
2006 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2008 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2009 } // GetSelectedCount() == 1
2011 if (GetSelectedCount() != 0)
2013 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2014 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2015 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2016 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2017 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2018 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2021 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2022 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2024 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2025 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2027 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2028 // DialogEnableWindow(IDOK, FALSE);
2029 // SetPromptApp(&theApp);
2031 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2033 // EnableOKButton();
2034 } // if (popup.CreatePopupMenu())
2038 bool CGitLogListBase::IsSelectionContinuous()
2040 if ( GetSelectedCount()==1 )
2042 // if only one revision is selected, the selection is of course
2047 POSITION pos
= GetFirstSelectedItemPosition();
2048 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2051 int itemindex
= GetNextSelectedItem(pos
);
2054 int nextindex
= GetNextSelectedItem(pos
);
2055 if (nextindex
- itemindex
> 1)
2057 bContinuous
= false;
2060 itemindex
= nextindex
;
2066 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2070 POSITION pos
= GetFirstSelectedItemPosition();
2074 sRev
.LoadString(IDS_LOG_REVISION
);
2076 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2078 sDate
.LoadString(IDS_LOG_DATE
);
2080 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2084 CString sLogCopyText
;
2086 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2088 if (toCopy
== ID_COPY_ALL
)
2090 //pLogEntry->GetFiles(this)
2091 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2093 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2094 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2096 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2097 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2100 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2101 sPaths
+= _T(" ") + rename
;
2103 sPaths
+= _T("\r\n");
2106 CString body
= pLogEntry
->GetBody();
2107 body
.Replace(_T("\n"), _T("\r\n"));
2108 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"),
2109 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2110 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2112 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2113 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2115 sClipdata
+= sLogCopyText
;
2117 else if (toCopy
== ID_COPY_MESSAGE
)
2119 CString body
= pLogEntry
->GetBody();
2120 body
.Replace(_T("\n"), _T("\r\n"));
2121 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2123 else if (toCopy
== ID_COPY_SUBJECT
)
2125 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2130 sClipdata
+= _T("\r\n");
2131 sClipdata
+= pLogEntry
->m_CommitHash
;
2136 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2141 void CGitLogListBase::DiffSelectedRevWithPrevious()
2143 if (m_bThreadRunning
)
2146 int FirstSelect
=-1, LastSelect
=-1;
2147 POSITION pos
= GetFirstSelectedItemPosition();
2148 FirstSelect
= GetNextSelectedItem(pos
);
2151 LastSelect
= GetNextSelectedItem(pos
);
2154 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2157 UpdateLogInfoLabel();
2158 int selIndex
= m_LogList
.GetSelectionMark();
2161 int selCount
= m_LogList
.GetSelectedCount();
2165 // Find selected entry in the log list
2166 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2167 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2168 long rev1
= pLogEntry
->Rev
;
2170 CTGitPath path
= m_path
;
2172 // See how many files under the relative root were changed in selected revision
2174 LogChangedPath
* changed
= NULL
;
2175 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2177 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2178 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2185 if (m_path
.IsDirectory() && nChanged
== 1)
2187 // We're looking at the log for a directory and only one file under dir was changed in the revision
2188 // Do diff on that file instead of whole directory
2189 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2192 m_bCancelled
= FALSE
;
2193 DialogEnableWindow(IDOK
, FALSE
);
2194 SetPromptApp(&theApp
);
2195 theApp
.DoWaitCursor(1);
2199 GitDiff
diff(this, m_hWnd
, true);
2200 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2201 diff
.SetHEADPeg(m_LogRevision
);
2202 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2206 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2209 theApp
.DoWaitCursor(-1);
2214 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2216 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2219 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2221 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2223 if (pFindInfo
->lvfi
.psz
== 0)
2226 CString sCmp
= pFindInfo
->lvfi
.psz
;
2228 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2230 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2231 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2232 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2234 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2242 if (sCmp
.Compare(sRev
)==0)
2249 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2251 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2253 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2254 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2255 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2257 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2265 if (sCmp
.Compare(sRev
)==0)
2277 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2281 this->m_arShownList
.SafeRemoveAll();
2283 this->m_logEntries
.ClearAll();
2284 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2287 //this->m_logEntries.ParserFromLog();
2288 SetItemCountEx((int)m_logEntries
.size());
2290 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2294 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2295 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2300 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2301 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2313 int CGitLogListBase::BeginFetchLog()
2317 this->m_arShownList
.SafeRemoveAll();
2319 this->m_logEntries
.ClearAll();
2321 this->m_LogCache
.ClearAllParent();
2323 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2326 if(this->m_Path
.IsEmpty())
2332 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
2333 // if(this->m_bAllBranch)
2334 mask
|= m_ShowMask
;
2338 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2340 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2343 if (m_sRange
.IsEmpty())
2344 m_sRange
= _T("HEAD");
2347 data
.m_From
= m_From
;
2350 #if 0 /* use tortoiegit filter */
2351 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2352 data
.m_Author
= this->m_sFilterText
;
2354 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2355 data
.m_MessageFilter
= this->m_sFilterText
;
2357 data
.m_IsRegex
= m_bFilterWithRegex
;
2360 // follow does not work for directories
2361 if (!path
|| path
->IsDirectory())
2362 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2363 // follow does not work with all branches 8at least in TGit)
2364 if (mask
& CGit::LOG_INFO_FOLLOW
)
2365 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
;
2367 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2369 //this->m_logEntries.ParserFromLog();
2370 if(IsInWorkingThread())
2372 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2376 SetItemCountEx((int)m_logEntries
.size());
2386 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2390 if (g_Git
.IsOrphanBranch(m_sRange
))
2392 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
))
2395 // if show all branches, pick any ref as dummy entry ref
2397 if (g_Git
.GetRefList(list
))
2398 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2399 if (list
.size() == 0)
2402 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2406 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2414 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2421 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2423 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2425 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2427 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2429 DiffSelectedRevWithPrevious();
2434 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2441 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2443 // select all entries
2444 for (int i
=0; i
<GetItemCount(); ++i
)
2446 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2452 if (m_hAccel
&& !bSkipAccelerator
)
2454 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2460 //m_tooltips.RelayEvent(pMsg);
2461 return __super::PreTranslateMessage(pMsg
);
2464 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2466 // a double click on an entry in the revision list has happened
2469 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2470 DiffSelectedRevWithPrevious();
2473 int CGitLogListBase::FetchLogAsync(void * data
)
2477 m_bExitThread
=FALSE
;
2478 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2479 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2480 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2481 if (m_LoadingThread
==NULL
)
2483 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2484 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2485 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2491 //this is the thread function which calls the subversion function
2492 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2494 return ((CGitLogListBase
*)pVoid
)->LogThread();
2497 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2500 oldest
=CTime::GetCurrentTime();
2501 latest
=CTime(1971,1,2,0,0,0);
2502 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2504 if(m_logEntries
[i
].IsEmpty())
2507 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2508 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2510 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2511 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2519 UINT
CGitLogListBase::LogThread()
2521 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2523 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2524 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2530 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2531 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2536 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2537 bool bRegex
= false;
2538 if (m_bFilterWithRegex
)
2539 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2541 TRACE(_T("\n===Begin===\n"));
2542 //Update work copy item;
2544 if (!m_logEntries
.empty())
2546 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2548 m_arShownList
.SafeAdd(pRev
);
2552 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2554 // store commit number of the last selected commit/line before the refresh or -1
2555 int lastSelectedHashNItem
= -1;
2558 bool shouldWalk
= true;
2559 if (g_Git
.IsOrphanBranch(m_sRange
))
2561 // walk revisions if show all branches and there exists any ref
2562 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
))
2567 if (g_Git
.GetRefList(list
))
2568 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2569 if (list
.size() == 0)
2576 g_Git
.m_critGitDllSec
.Lock();
2580 git_get_log_firstcommit(m_DllGitLog
);
2581 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2586 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2589 g_Git
.m_critGitDllSec
.Unlock();
2592 t2
=t1
=GetTickCount();
2593 int oldprecentage
= 0;
2594 size_t oldsize
= m_logEntries
.size();
2595 while (ret
== 0 && !m_bExitThread
)
2597 g_Git
.m_critGitDllSec
.Lock();
2600 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
);
2604 g_Git
.m_critGitDllSec
.Unlock();
2606 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2609 g_Git
.m_critGitDllSec
.Unlock();
2614 if (commit
.m_ignore
== 1)
2616 git_free_commit(&commit
);
2620 //printf("%s\r\n",commit.GetSubject());
2624 CGitHash hash
= (char*)commit
.m_hash
;
2626 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2627 pRev
->m_GitCommit
= commit
;
2628 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2631 g_Git
.m_critGitDllSec
.Lock();
2632 git_get_notes(commit
.m_hash
,¬e
);
2633 g_Git
.m_critGitDllSec
.Unlock();
2637 pRev
->m_Notes
.Empty();
2638 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2641 if(!pRev
->m_IsDiffFiles
)
2643 pRev
->m_CallDiffAsync
= DiffAsync
;
2646 pRev
->ParserParentFromCommit(&commit
);
2653 if(!m_sFilterText
.IsEmpty())
2655 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2658 this->m_critSec
.Lock();
2659 m_logEntries
.push_back(hash
);
2660 m_arShownList
.SafeAdd(pRev
);
2661 this->m_critSec
.Unlock();
2663 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2664 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2668 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2671 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2674 if(percent
< GITLOG_START
)
2675 percent
= GITLOG_START
+1;
2677 oldsize
= m_logEntries
.size();
2678 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2680 //if( percent > oldprecentage )
2682 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2683 oldprecentage
= percent
;
2688 g_Git
.m_critGitDllSec
.Lock();
2689 git_close_log(m_DllGitLog
);
2690 g_Git
.m_critGitDllSec
.Unlock();
2696 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2701 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2703 if (lastSelectedHashNItem
>= 0)
2704 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2707 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2709 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2714 void CGitLogListBase::FetchRemoteList()
2716 STRING_VECTOR remoteList
;
2717 if (!g_Git
.GetRemoteList(remoteList
))
2718 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
2720 m_SingleRemote
= _T("");
2723 void CGitLogListBase::FetchTrackingBranchList()
2725 m_TrackingMap
.clear();
2726 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
2728 for (int j
= 0; j
< it
->second
.size(); ++j
)
2731 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
2734 configName
.Format(_T("branch.%s.remote"), branchName
);
2735 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2737 configName
.Format(_T("branch.%s.merge"), branchName
);
2738 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2740 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2742 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
2749 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2751 SafeTerminateThread();
2753 this->SetItemCountEx(0);
2758 // HACK to hide graph column
2759 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
2760 SetColumnWidth(0, 0);
2762 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
2764 //Update branch and Tag info
2766 //Assume Thread have exited
2767 //if(!m_bThreadRunning)
2769 m_logEntries
.clear();
2773 m_sFilterText
.Empty();
2778 InterlockedExchange(&m_bExitThread
,FALSE
);
2780 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2781 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2782 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2784 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2785 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2786 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2790 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2794 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2796 type
|= tr1::regex_constants::icase
;
2797 pat
= tr1::wregex(regexp_str
, type
);
2800 catch (exception
) {}
2803 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2806 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2809 if ((bRegex
)&&(m_bFilterWithRegex
))
2811 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2813 if(this->m_bShowBugtraqColumn
)
2815 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2817 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2818 if (regex_search(wstring(sBugIds
), pat
, flags
))
2825 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2827 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2828 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2834 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2836 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2837 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2843 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2845 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2850 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2856 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
2858 if (regex_search(wstring(pRev
->GetAuthorEmail()), pat
, flags
))
2863 if (regex_search(wstring(pRev
->GetCommitterEmail()), pat
, flags
))
2869 if (m_SelectedFilters
& LOGFILTER_REVS
)
2871 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2872 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2878 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
2880 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
2881 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
2883 if (regex_search(wstring((LPCTSTR
)*it
), pat
, flags
))
2890 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2892 CTGitPathList
*pathList
=NULL
;
2893 if( pRev
->m_IsDiffFiles
)
2894 pathList
= &pRev
->GetFiles(this);
2897 if(!pRev
->m_IsSimpleListReady
)
2898 pRev
->SafeGetSimpleList(&g_Git
);
2902 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2904 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2908 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2914 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
2916 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2925 CString find
= m_sFilterText
;
2928 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2930 if(this->m_bShowBugtraqColumn
)
2932 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2934 sBugIds
.MakeLower();
2935 if ((sBugIds
.Find(find
) >= 0))
2942 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2944 CString msg
= pRev
->GetSubject();
2946 msg
= msg
.MakeLower();
2947 if ((msg
.Find(find
) >= 0))
2953 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2955 CString msg
= pRev
->GetBody();
2957 msg
= msg
.MakeLower();
2958 if ((msg
.Find(find
) >= 0))
2964 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2966 CString msg
= pRev
->GetAuthorName();
2967 msg
= msg
.MakeLower();
2968 if ((msg
.Find(find
) >= 0))
2974 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
2976 CString msg
= pRev
->GetAuthorEmail();
2977 msg
= msg
.MakeLower();
2978 if ((msg
.Find(find
) >= 0))
2984 if (m_SelectedFilters
& LOGFILTER_REVS
)
2986 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2987 if ((sRev
.Find(find
) >= 0))
2993 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
2995 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
2996 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
2998 if (it
->Find(find
) >= 0)
3005 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3007 CTGitPathList
*pathList
=NULL
;
3008 if( pRev
->m_IsDiffFiles
)
3009 pathList
= &pRev
->GetFiles(this);
3012 if(!pRev
->m_IsSimpleListReady
)
3013 pRev
->SafeGetSimpleList(&g_Git
);
3016 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3018 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3019 CString path
= cpath
->GetGitOldPathString();
3021 if ((path
.Find(find
)>=0))
3025 path
= cpath
->GetGitPathString();
3027 if ((path
.Find(find
)>=0))
3033 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3035 CString path
= pRev
->m_SimpleFileList
[i
];
3037 if ((path
.Find(find
)>=0))
3043 } // else (from if (bRegex))
3048 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3051 pShownlist
->SafeRemoveAll();
3053 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3054 bool bRegex
= false;
3055 if (m_bFilterWithRegex
)
3056 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3058 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
3060 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3062 if ((bRegex
)&&(m_bFilterWithRegex
))
3065 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3067 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3068 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3070 pShownlist
->SafeAdd(m_logEntries
[i
]);
3075 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3077 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3078 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3080 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3084 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3086 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3087 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3089 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3093 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3095 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3098 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3100 CTGitPath cpath
= pathList
[cpPathIndex
];
3101 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3103 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3107 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3109 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3113 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3115 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3121 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3123 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3125 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3129 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3131 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3133 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3137 if (m_SelectedFilters
& LOGFILTER_REVS
)
3139 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3140 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3142 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3146 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3148 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3149 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3151 if (regex_search(wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3153 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3161 CString find
= m_sFilterText
;
3164 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3166 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3168 sBugIDs
= sBugIDs
.MakeLower();
3169 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3171 pShownlist
->SafeAdd(m_logEntries
[i
]);
3176 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3178 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3180 msg
= msg
.MakeLower();
3181 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3183 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3187 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3189 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3191 msg
= msg
.MakeLower();
3192 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3194 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3198 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3200 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3203 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3205 CTGitPath cpath
= pathList
[cpPathIndex
];
3206 CString path
= cpath
.GetGitOldPathString();
3208 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3210 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3214 path
= cpath
.GetGitPathString();
3216 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3218 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3222 path
= cpath
.GetActionName();
3224 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3226 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3232 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3234 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3235 msg
= msg
.MakeLower();
3236 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3238 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3242 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3244 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3245 msg
= msg
.MakeLower();
3246 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3248 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3252 if (m_SelectedFilters
& LOGFILTER_REVS
)
3254 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3255 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3257 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3261 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3263 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3264 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3266 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3268 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3273 } // else (from if (bRegex))
3274 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3278 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3281 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3287 return time <= m_To;
3290 return time >= m_From;
3292 return ((time >= m_From)&&(time <= m_To));
3294 return TRUE
; /* git dll will filter time range */
3298 void CGitLogListBase::StartFilter()
3300 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3301 RecalculateShownList(&m_arShownList
);
3302 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3306 SetItemCountEx(ShownCountWithStopped());
3307 RedrawItems(0, ShownCountWithStopped());
3311 void CGitLogListBase::RemoveFilter()
3314 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3316 m_arShownList
.SafeRemoveAll();
3318 // reset the time filter too
3320 m_timFrom
= (__time64_t(m_tFrom
));
3321 m_timTo
= (__time64_t(m_tTo
));
3322 m_DateFrom
.SetTime(&m_timFrom
);
3323 m_DateTo
.SetTime(&m_timTo
);
3324 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3325 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3328 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3330 if(this->m_IsOldFirst
)
3332 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3336 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3339 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3341 SetItemCountEx(ShownCountWithStopped());
3342 RedrawItems(0, ShownCountWithStopped());
3344 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3347 void CGitLogListBase::Clear()
3349 m_arShownList
.SafeRemoveAll();
3352 m_logEntries
.ClearAll();
3356 void CGitLogListBase::OnDestroy()
3358 // save the column widths to the registry
3361 SafeTerminateThread();
3362 SafeTerminateAsyncDiffThread();
3365 while(m_LogCache
.SaveCache())
3373 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3374 // MB_YESNO) == IDNO)
3378 CHintListCtrl::OnDestroy();
3381 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3385 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3386 this->InvalidateRect(rect
);
3392 * Save column widths to the registry
3394 void CGitLogListBase::SaveColumnWidths()
3396 int maxcol
= m_ColumnManager
.GetColumnCount();
3398 // HACK that graph column is always shown
3399 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3401 for (int col
= 0; col
< maxcol
; ++col
)
3402 if (m_ColumnManager
.IsVisible (col
))
3403 m_ColumnManager
.ColumnResized (col
);
3405 m_ColumnManager
.WriteSettings();
3408 int CGitLogListBase::GetHeadIndex()
3410 if(m_HeadHash
.IsEmpty())
3413 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3415 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
3418 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3424 void CGitLogListBase::OnFind()
3428 m_pFindDialog
= new CFindDlg(this);
3429 m_pFindDialog
->Create(this);
3432 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3434 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3436 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3438 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3441 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3443 if (GetSelectedCount() != 0)
3445 SetItemState((int)itemToSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
3446 EnsureVisible((int)itemToSelect
, FALSE
);
3449 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3452 ASSERT(m_pFindDialog
!= NULL
);
3453 bool bFound
= false;
3456 if (m_pFindDialog
->IsTerminating())
3458 // invalidate the handle identifying the dialog box.
3459 m_pFindDialog
= NULL
;
3463 if(m_pFindDialog
->IsRef())
3466 str
=m_pFindDialog
->GetFindString();
3472 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3473 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3478 for (i
= 0; i
<m_arShownList
.GetCount(); ++i
)
3480 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3481 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3491 if(m_pFindDialog
->FindNext())
3493 //read data from dialog
3494 CString FindText
= m_pFindDialog
->GetFindString();
3495 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3498 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3500 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3503 for (i
= this->m_nSearchIndex
; i
< m_arShownList
.GetCount() && !bFound
; ++i
)
3505 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3508 str
+=pLogEntry
->m_CommitHash
.ToString();
3511 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
3513 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3517 str
+=pLogEntry
->GetAuthorEmail();
3519 str
+=pLogEntry
->GetAuthorName();
3521 str
+=pLogEntry
->GetBody();
3523 str
+=pLogEntry
->GetCommitterEmail();
3525 str
+=pLogEntry
->GetCommitterName();
3527 str
+=pLogEntry
->GetSubject();
3531 /*Because changed files list is loaded on demand when gui show,
3532 files will empty when files have not fetched.
3534 we can add it back by using one-way diff(with outnumber changed and rename detect.
3535 here just need changed filename list. one-way is much quicker.
3537 if(pLogEntry
->m_IsFull
)
3539 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
3541 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3543 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3549 if(!pLogEntry
->m_IsSimpleListReady
)
3550 pLogEntry
->SafeGetSimpleList(&g_Git
);
3552 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
3554 str
+=pLogEntry
->m_SimpleFileList
[i
];
3563 if (regex_search(wstring(str
), pat
, flags
))
3573 if (str
.Find(FindText
) >= 0)
3583 msg
= msg
.MakeLower();
3584 CString find
= FindText
.MakeLower();
3585 if (msg
.Find(find
) >= 0)
3592 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3594 } // if(m_pFindDialog->FindNext())
3595 //UpdateLogInfoLabel();
3599 this->m_nSearchIndex
= i
;
3600 EnsureVisible(i
, FALSE
);
3601 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3602 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3603 SetSelectionMark(i
);
3604 //FillLogMessageCtrl();
3607 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3608 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3614 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3616 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3621 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3623 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);