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
);
154 m_bIncludeBoundaryCommits
= !!CRegDWORD(_T("Software\\TortoiseGit\\LogIncludeBoundaryCommits"), FALSE
);
156 m_AsyncThreadExit
= FALSE
;
157 m_AsyncDiffEvent
= ::CreateEvent(NULL
,FALSE
,TRUE
,NULL
);
158 m_AsynDiffListLock
.Init();
160 m_DiffingThread
= AfxBeginThread(AsyncThread
, this, THREAD_PRIORITY_BELOW_NORMAL
);
161 if (m_DiffingThread
==NULL
)
163 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
169 int CGitLogListBase::AsyncDiffThread()
171 m_AsyncThreadExited
= false;
172 while(!m_AsyncThreadExit
)
174 ::WaitForSingleObject(m_AsyncDiffEvent
, INFINITE
);
177 while(!m_AsyncThreadExit
&& !m_AsynDiffList
.empty())
179 m_AsynDiffListLock
.Lock();
180 pRev
= m_AsynDiffList
.back();
181 m_AsynDiffList
.pop_back();
182 m_AsynDiffListLock
.Unlock();
184 if( pRev
->m_CommitHash
.IsEmpty() )
186 if(pRev
->m_IsDiffFiles
)
189 pRev
->GetFiles(this).Clear();
190 pRev
->m_ParentHash
.clear();
191 pRev
->m_ParentHash
.push_back(m_HeadHash
);
192 if(g_Git
.IsInitRepos())
194 g_Git
.GetInitAddList(pRev
->GetFiles(this));
199 g_Git
.GetCommitDiffList(pRev
->m_CommitHash
.ToString(),this->m_HeadHash
.ToString(), pRev
->GetFiles(this));
201 pRev
->GetAction(this) = 0;
203 for (int j
= 0; j
< pRev
->GetFiles(this).GetCount(); ++j
)
204 pRev
->GetAction(this) |= pRev
->GetFiles(this)[j
].m_Action
;
206 pRev
->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER
);
208 InterlockedExchange(&pRev
->m_IsDiffFiles
, TRUE
);
209 InterlockedExchange(&pRev
->m_IsFull
, TRUE
);
211 pRev
->GetBody().Format(IDS_FILESCHANGES
, pRev
->GetFiles(this).GetCount());
212 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
213 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
216 if(!pRev
->CheckAndDiff())
217 { // fetch change file list
218 for (int i
= GetTopIndex(); !m_AsyncThreadExit
&& i
<= GetTopIndex() + GetCountPerPage(); ++i
)
220 if(i
< m_arShownList
.GetCount())
222 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
223 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
225 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
231 if(!m_AsyncThreadExit
&& GetSelectedCount() == 1)
233 POSITION pos
= GetFirstSelectedItemPosition();
234 int nItem
= GetNextSelectedItem(pos
);
238 GitRev
* data
= (GitRev
*)m_arShownList
[nItem
];
240 if(data
->m_CommitHash
== pRev
->m_CommitHash
)
242 this->GetParent()->PostMessage(WM_COMMAND
, MSG_FETCHED_DIFF
, 0);
249 m_AsyncThreadExited
= true;
252 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask
, bool exclusivelyShow
)
256 m_ContextMenuMask
&= hideMask
;
260 m_ContextMenuMask
&= ~hideMask
;
264 CGitLogListBase::~CGitLogListBase()
266 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
267 this->m_arShownList
.SafeRemoveAll();
269 DestroyIcon(m_hModifiedIcon
);
270 DestroyIcon(m_hReplacedIcon
);
271 DestroyIcon(m_hAddedIcon
);
272 DestroyIcon(m_hDeletedIcon
);
273 m_logEntries
.ClearAll();
276 DeleteObject(m_boldFont
);
278 if ( m_pStoreSelection
)
280 delete m_pStoreSelection
;
281 m_pStoreSelection
= NULL
;
284 SafeTerminateThread();
285 SafeTerminateAsyncDiffThread();
288 CloseHandle(m_AsyncDiffEvent
);
292 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
293 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
294 ON_REGISTERED_MESSAGE(m_ScrollToMessage
, OnScrollToMessage
)
295 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
296 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
298 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
299 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
302 ON_MESSAGE(MSG_LOADED
,OnLoad
)
304 ON_WM_MEASUREITEM_REFLECT()
305 ON_NOTIFY(HDN_BEGINTRACKA
, 0, OnHdnBegintrack
)
306 ON_NOTIFY(HDN_BEGINTRACKW
, 0, OnHdnBegintrack
)
307 ON_NOTIFY(HDN_ITEMCHANGINGA
, 0, OnHdnItemchanging
)
308 ON_NOTIFY(HDN_ITEMCHANGINGW
, 0, OnHdnItemchanging
)
309 ON_NOTIFY(HDN_ENDTRACK
, 0, OnColumnResized
)
310 ON_NOTIFY(HDN_ENDDRAG
, 0, OnColumnMoved
)
313 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
315 //if (m_nRowHeight>0)
317 lpMeasureItemStruct
->itemHeight
= 50;
321 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
324 return CHintListCtrl::OnCreate(lpCreateStruct
);
327 void CGitLogListBase::PreSubclassWindow()
329 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
330 // load the icons for the action columns
331 // m_Theme.Open(m_hWnd, L"ListView");
332 SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
333 CHintListCtrl::PreSubclassWindow();
336 void CGitLogListBase::InsertGitColumn()
340 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
341 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
342 if (DWORD(regFullRowSelect
))
343 exStyle
|= LVS_EX_FULLROWSELECT
;
344 SetExtendedStyle(exStyle
);
346 // only load properties if we have a repository
347 if (GitAdminDir().HasAdminDir(g_Git
.m_CurrentDir
) || GitAdminDir().IsBareRepo(g_Git
.m_CurrentDir
))
348 UpdateProjectProperties();
350 static UINT normal
[] =
362 IDS_LOG_COMMIT_EMAIL
,
383 m_dwDefaultColumns
= GIT_LOG_GRAPH
|GIT_LOG_ACTIONS
|GIT_LOG_MESSAGE
|GIT_LOG_AUTHOR
|GIT_LOG_DATE
;
385 DWORD hideColumns
= 0;
386 if(this->m_IsRebaseReplaceGraph
)
388 hideColumns
|= GIT_LOG_GRAPH
;
389 m_dwDefaultColumns
|= GIT_LOG_REBASE
;
393 hideColumns
|= GIT_LOG_REBASE
;
396 if(this->m_IsIDReplaceAction
)
398 hideColumns
|= GIT_LOG_ACTIONS
;
399 m_dwDefaultColumns
|= GIT_LOG_ID
;
400 m_dwDefaultColumns
|= GIT_LOG_HASH
;
404 hideColumns
|= GIT_LOG_ID
;
406 if(this->m_bShowBugtraqColumn
)
408 m_dwDefaultColumns
|= GIT_LOGLIST_BUG
;
412 hideColumns
|= GIT_LOGLIST_BUG
;
416 m_ColumnManager
.SetNames(normal
, _countof(normal
));
417 m_ColumnManager
.ReadSettings(m_dwDefaultColumns
, hideColumns
, m_ColumnRegKey
+_T("loglist"), _countof(normal
), with
);
423 * Resizes all columns in a list control to values in registry.
425 void CGitLogListBase::ResizeAllListCtrlCols()
427 // column max and min widths to allow
428 static const int nMinimumWidth
= 10;
429 static const int nMaximumWidth
= 1000;
430 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
433 int numcols
= pHdrCtrl
->GetItemCount();
434 for (int col
= 0; col
< numcols
; ++col
)
436 // get width for this col last time from registry
438 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
439 CRegDWORD
regwidth(regentry
, 0);
443 // no saved value, setup sensible defaults
444 if (col
== this->LOGLIST_MESSAGE
)
446 cx
= LOGLIST_MESSAGE_MIN
;
450 cx
= ICONITEMBORDER
+16*4;
453 if (cx
< nMinimumWidth
)
457 else if (cx
> nMaximumWidth
)
462 SetColumnWidth(col
, cx
);
469 void CGitLogListBase::FillBackGround(HDC hdc
, DWORD_PTR Index
, CRect
&rect
)
472 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
473 rItem
.mask
= LVIF_STATE
;
474 rItem
.iItem
= (int)Index
;
475 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
478 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(Index
);
481 if (!(rItem
.state
& LVIS_SELECTED
))
483 if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
484 brush
= ::CreateSolidBrush(RGB(156,156,156));
485 else if(pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
486 brush
= ::CreateSolidBrush(RGB(200,200,128));
488 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
490 if (rItem
.state
& LVIS_SELECTED
)
492 if (::GetFocus() == m_hWnd
)
493 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
495 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
501 ::FillRect(hdc
, &rect
, brush
);
502 ::DeleteObject(brush
);
506 void DrawTrackingRoundRect(HDC hdc
, CRect rect
, HBRUSH brush
, COLORREF darkColor
)
508 POINT point
= { 4, 4 };
510 rt2
.DeflateRect(1, 1);
511 rt2
.OffsetRect(2, 2);
513 HPEN nullPen
= ::CreatePen(PS_NULL
, 0, 0);
514 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, nullPen
);
515 HBRUSH darkBrush
= (HBRUSH
)::CreateSolidBrush(darkColor
);
516 HBRUSH oldbrush
= (HBRUSH
)::SelectObject(hdc
, darkBrush
);
517 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
519 ::SelectObject(hdc
, brush
);
520 rt2
.OffsetRect(-2, -2);
521 ::RoundRect(hdc
, rt2
.left
, rt2
.top
, rt2
.right
, rt2
.bottom
, point
.x
, point
.y
);
522 ::SelectObject(hdc
, oldbrush
);
523 ::SelectObject(hdc
, oldpen
);
524 ::DeleteObject(nullPen
);
525 ::DeleteObject(darkBrush
);
528 void DrawLightning(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
530 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
531 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
532 ::MoveToEx(hdc
, rect
.left
+ 7, rect
.top
, NULL
);
533 ::LineTo(hdc
, rect
.left
+ 1, (rect
.top
+ rect
.bottom
) / 2);
534 ::LineTo(hdc
, rect
.left
+ 6, (rect
.top
+ rect
.bottom
) / 2);
535 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
536 ::SelectObject(hdc
, oldpen
);
540 void DrawUpTriangle(HDC hdc
, CRect rect
, COLORREF color
, int bold
)
542 HPEN pen
= ::CreatePen(PS_SOLID
, bold
, color
);
543 HPEN oldpen
= (HPEN
)::SelectObject(hdc
, pen
);
544 ::MoveToEx(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
, NULL
);
545 ::LineTo(hdc
, rect
.left
, rect
.bottom
);
546 ::LineTo(hdc
, rect
.right
, rect
.bottom
);
547 ::LineTo(hdc
, (rect
.left
+ rect
.right
) / 2, rect
.top
);
548 ::SelectObject(hdc
, oldpen
);
552 void CGitLogListBase::DrawTagBranch(HDC hdc
, CRect
&rect
, INT_PTR index
, std::vector
<REFLABEL
> refList
)
554 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
557 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
558 rItem
.mask
= LVIF_STATE
;
559 rItem
.iItem
= (int)index
;
560 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
566 HTHEME hTheme
= NULL
;
567 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
568 hTheme
= OpenThemeData(m_hWnd
, L
"Explorer::ListView;ListView");
570 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
572 CString shortname
= !refList
[i
].simplifiedName
.IsEmpty() ? refList
[i
].simplifiedName
: refList
[i
].name
;
574 COLORREF colRef
= refList
[i
].color
;
575 bool singleRemote
= refList
[i
].singleRemote
;
576 bool hasTracking
= refList
[i
].hasTracking
;
577 bool sameName
= refList
[i
].sameName
;
579 //When row selected, ajust label color
580 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
581 if (rItem
.state
& LVIS_SELECTED
)
582 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
584 brush
= ::CreateSolidBrush(colRef
);
586 if(!shortname
.IsEmpty() && (rt
.left
<rect
.right
) )
589 memset(&size
,0,sizeof(SIZE
));
590 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
592 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
595 int textpos
= DT_CENTER
;
597 if(rt
.right
> rect
.right
)
599 rt
.right
= rect
.right
;
608 textRect
.OffsetRect(8, 0);
616 DrawTrackingRoundRect(hdc
, rt
, brush
, m_Colors
.Darken(colRef
, 100));
620 //Fill interior of ref label
621 ::FillRect(hdc
, &rt
, brush
);
630 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 100), m_Colors
.Darken(colRef
, 100));
631 rectEdge
.DeflateRect(1, 1);
632 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
, 50), m_Colors
.Darken(colRef
, 50));
635 //Draw text inside label
636 bool customColor
= (colRef
& 0xff) * 30 + ((colRef
>> 8) & 0xff) * 59 + ((colRef
>> 16) & 0xff) * 11 <= 12800; // check if dark background
637 if (!customColor
&& IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
639 int txtState
= LISS_NORMAL
;
640 if (rItem
.state
& LVIS_SELECTED
)
641 txtState
= LISS_SELECTED
;
643 DrawThemeText(hTheme
, hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, textpos
| DT_SINGLELINE
| DT_VCENTER
, 0, &textRect
);
647 W_Dc
.SetBkMode(TRANSPARENT
);
648 if (customColor
|| (rItem
.state
& LVIS_SELECTED
))
650 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
651 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
652 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
653 ::SetTextColor(hdc
,clrOld
);
657 ::DrawText(hdc
, shortname
, shortname
.GetLength(), &textRect
, textpos
| DT_SINGLELINE
| DT_VCENTER
);
663 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
664 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
666 newRect
.SetRect(rt
.left
+ 4, rt
.top
+ 4, rt
.left
+ 8, rt
.bottom
- 4);
667 DrawLightning(hdc
, newRect
, color
, bold
);
672 COLORREF color
= ::GetSysColor(customColor
? COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
673 int bold
= data
->m_CommitHash
== m_HeadHash
? 2 : 1;
675 newRect
.SetRect(rt
.right
- 12, rt
.top
+ 4, rt
.right
- 4, rt
.bottom
- 4);
676 DrawUpTriangle(hdc
, newRect
, color
, bold
);
679 //::MoveToEx(hdc,rt.left,rt.top,NULL);
680 //::LineTo(hdc,rt.right,rt.top);
681 //::LineTo(hdc,rt.right,rt.bottom);
682 //::LineTo(hdc,rt.left,rt.bottom);
683 //::LineTo(hdc,rt.left,rt.top);
688 ::DeleteObject(brush
);
692 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
694 int txtState
= LISS_NORMAL
;
695 if (rItem
.state
& LVIS_SELECTED
)
696 txtState
= LISS_SELECTED
;
698 DrawThemeText(hTheme
,hdc
, LVP_LISTITEM
, txtState
, data
->GetSubject(), -1, DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
, 0, &rt
);
702 if (rItem
.state
& LVIS_SELECTED
)
704 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
705 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
706 ::SetTextColor(hdc
,clrOld
);
710 ::DrawText(hdc
,data
->GetSubject(),data
->GetSubject().GetLength(),&rt
,DT_NOPREFIX
| DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_END_ELLIPSIS
);
715 CloseThemeData(hTheme
);
720 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
722 // Returns ((256 - amount)*col1 + amount*col2) / 256;
723 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
724 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
725 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
728 Gdiplus::Color
GetGdiColor(COLORREF col
)
730 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
732 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
733 const COLORREF
& col
,const COLORREF
& activeColor
, int top
736 int h
= laneHeight
/ 2;
737 int m
= (x1
+ x2
) / 2;
738 int r
= (x2
- x1
) / 3;
741 #define P_CENTER m , h+top
742 #define P_0 x2, h+top
743 #define P_90 m , 0+top-1
744 #define P_180 x1, h+top
745 #define P_270 m , 2 * h+top +1
746 #define R_CENTER m - r, h - r+top, d, d
749 #define DELTA_UR_B 2*(x1 - m), 2*h +top
750 #define DELTA_UR_E 0*16, 90*16 +top // -,
752 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
753 #define DELTA_DR_E 270*16, 90*16 +top // -'
755 #define DELTA_UL_B 2*(x2 - m), 2*h +top
756 #define DELTA_UL_E 90*16, 90*16 +top // ,-
758 #define DELTA_DL_B 2*(x2 - m),2*-h +top
759 #define DELTA_DL_E 180*16, 90*16 // '-
761 #define CENTER_UR x1, 2*h, 225
762 #define CENTER_DR x1, 0 , 135
763 #define CENTER_UL x2, 2*h, 315
764 #define CENTER_DL x2, 0 , 45
767 Gdiplus::Graphics
graphics( hdc
);
769 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
778 Gdiplus::LinearGradientBrush
gradient(
779 Gdiplus::Point(x1
-2, h
+top
-2),
780 Gdiplus::Point(P_270
),
781 GetGdiColor(activeColor
),GetGdiColor(col
));
784 Gdiplus::Pen
mypen(&gradient
,2);
785 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
787 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
788 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
,laneHeight
,270,90);
789 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
796 Gdiplus::LinearGradientBrush
gradient(
797 Gdiplus::Point(P_270
),
798 Gdiplus::Point(x2
+1, h
+top
-1),
799 GetGdiColor(col
),GetGdiColor(activeColor
));
802 Gdiplus::Pen
mypen(&gradient
,2);
803 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
805 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
806 graphics
.DrawArc(&mypen
,x1
+(x2
-x1
)/2,top
+h
-1, x2
-x1
,laneHeight
,180,90);
807 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
816 Gdiplus::LinearGradientBrush
gradient(
817 Gdiplus::Point(x1
-2, h
+top
-2),
818 Gdiplus::Point(P_90
),
819 GetGdiColor(activeColor
),GetGdiColor(col
));
821 Gdiplus::Pen
mypen(&gradient
,2);
823 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
,laneHeight
,0,90);
826 QConicalGradient
gradient(CENTER_DR
);
827 gradient
.setColorAt(0.375, activeCol
);
828 gradient
.setColorAt(0.625, col
);
829 myPen
.setBrush(gradient
);
831 p
->drawArc(P_CENTER
, DELTA_DR
);
840 //static QPen myPen(Qt::black, 2); // fast path here
842 pen
.CreatePen(PS_SOLID
,2,col
);
843 //myPen.setColor(col);
844 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
846 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
848 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
855 case Lanes::NOT_ACTIVE
:
856 case Lanes::MERGE_FORK
:
857 case Lanes::MERGE_FORK_R
:
858 case Lanes::MERGE_FORK_L
:
863 //DrawLine(hdc,P_90,P_270);
864 graphics
.DrawLine(&myPen
,P_90
,P_270
);
865 //p->drawLine(P_90, P_270);
869 //DrawLine(hdc,P_CENTER,P_270);
870 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
871 //p->drawLine(P_CENTER, P_270);
875 case Lanes::BOUNDARY
:
876 case Lanes::BOUNDARY_C
:
877 case Lanes::BOUNDARY_R
:
878 case Lanes::BOUNDARY_L
:
879 //DrawLine(hdc,P_90, P_CENTER);
880 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
881 //p->drawLine(P_90, P_CENTER);
887 myPen
.SetColor(GetGdiColor(activeColor
));
891 case Lanes::MERGE_FORK
:
896 case Lanes::CROSS_EMPTY
:
897 case Lanes::BOUNDARY_C
:
898 //DrawLine(hdc,P_180,P_0);
899 graphics
.DrawLine(&myPen
,P_180
,P_0
);
900 //p->drawLine(P_180, P_0);
902 case Lanes::MERGE_FORK_R
:
903 case Lanes::BOUNDARY_R
:
904 //DrawLine(hdc,P_180,P_CENTER);
905 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
906 //p->drawLine(P_180, P_CENTER);
908 case Lanes::MERGE_FORK_L
:
911 case Lanes::BOUNDARY_L
:
912 //DrawLine(hdc,P_CENTER,P_0);
913 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
914 //p->drawLine(P_CENTER, P_0);
920 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
923 brush
.CreateSolidBrush(col
);
924 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
926 Gdiplus::SolidBrush
myBrush(GetGdiColor(col
));
927 // center symbol, e.g. rect or ellipse
933 //p->setPen(Qt::NoPen);
935 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
936 graphics
.FillEllipse(&myBrush
, R_CENTER
);
937 //p->drawEllipse(R_CENTER);
939 case Lanes::MERGE_FORK
:
940 case Lanes::MERGE_FORK_R
:
941 case Lanes::MERGE_FORK_L
:
942 //p->setPen(Qt::NoPen);
944 //p->drawRect(R_CENTER);
945 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
946 graphics
.FillRectangle(&myBrush
, R_CENTER
);
948 case Lanes::UNAPPLIED
:
950 //p->setPen(Qt::NoPen);
951 //p->setBrush(Qt::red);
952 //p->drawRect(m - r, h - 1, d, 2);
953 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
954 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
958 //p->setPen(Qt::NoPen);
959 //p->setBrush(DARK_GREEN);
960 //p->drawRect(m - r, h - 1, d, 2);
961 //p->drawRect(m - 1, h - r, 2, d);
962 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
963 graphics
.FillRectangle(&myBrush
,m
-r
,h
-1,d
,2);
964 graphics
.FillRectangle(&myBrush
,m
-1,h
-r
,2,d
);
966 case Lanes::BOUNDARY
:
968 //p->drawEllipse(R_CENTER);
969 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
970 graphics
.DrawEllipse(&myPen
, R_CENTER
);
972 case Lanes::BOUNDARY_C
:
973 case Lanes::BOUNDARY_R
:
974 case Lanes::BOUNDARY_L
:
976 //p->drawRect(R_CENTER);
977 graphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
978 graphics
.FillRectangle(&myBrush
,R_CENTER
);
984 ::SelectObject(hdc
,oldpen
);
985 ::SelectObject(hdc
,oldbrush
);
994 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
998 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(index
);
999 if(data
->m_CommitHash
.IsEmpty())
1004 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
1005 rItem
.mask
= LVIF_STATE
;
1006 rItem
.iItem
= (int)index
;
1007 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
1010 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1012 if (data
->m_Lanes
.empty())
1013 m_logEntries
.setLane(data
->m_CommitHash
);
1015 std::vector
<int>& lanes
=data
->m_Lanes
;
1016 size_t laneNum
= lanes
.size();
1017 UINT activeLane
= 0;
1018 for (UINT i
= 0; i
< laneNum
; ++i
)
1019 if (Lanes::isMerge(lanes
[i
])) {
1025 int maxWidth
= rect
.Width();
1026 int lw
= 3 * rect
.Height() / 4; //laneWidth()
1028 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
1029 //if (opt.state & QStyle::State_Selected)
1030 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1032 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
)
1039 if (ln
== Lanes::EMPTY
)
1042 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
1043 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
1047 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; ++i
) {
1053 if (ln
== Lanes::EMPTY
)
1056 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
1057 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
1059 if (ln
== Lanes::CROSS
)
1061 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1062 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
1065 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
1071 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1074 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
1075 // Take the default processing unless we set this to something else below.
1076 *pResult
= CDRF_DODEFAULT
;
1078 if (m_bNoDispUpdates
)
1081 switch (pLVCD
->nmcd
.dwDrawStage
)
1085 *pResult
= CDRF_NOTIFYITEMDRAW
;
1089 case CDDS_ITEMPREPAINT
:
1091 // This is the prepaint stage for an item. Here's where we set the
1092 // item's text color.
1094 // Tell Windows to send draw notifications for each subitem.
1095 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
1097 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
1099 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1101 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1104 if (data
->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
1105 crText
= RGB(128,128,128);
1107 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
1108 pLVCD
->clrTextBk
= RGB(156,156,156);
1109 else if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT
)
1110 pLVCD
->clrTextBk
= RGB(200,200,128);
1112 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
1114 if(data
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
1116 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1117 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1120 if (data
->m_CommitHash
== m_HeadHash
&& m_bNoHightlightHead
== FALSE
)
1122 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
1123 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1126 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1127 // crText = GetSysColor(COLOR_GRAYTEXT);
1129 if (data
->m_CommitHash
.IsEmpty())
1131 //crText = GetSysColor(RGB(200,200,0));
1132 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1133 // We changed the font, so we're returning CDRF_NEWFONT. This
1134 // tells the control to recalculate the extent of the text.
1135 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
1139 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1141 if (m_bStrictStopped
)
1142 crText
= GetSysColor(COLOR_GRAYTEXT
);
1144 // Store the color back in the NMLVCUSTOMDRAW struct.
1145 pLVCD
->clrText
= crText
;
1149 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
1151 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
1153 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
1156 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
&& m_sFilterText
.IsEmpty())
1158 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
1161 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_LABEL
, rect
);
1163 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1164 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1166 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1167 if( !data
->m_CommitHash
.IsEmpty())
1168 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1170 *pResult
= CDRF_SKIPDEFAULT
;
1175 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1177 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1179 GitRev
* data
= (GitRev
*)m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
);
1180 //if(!data->m_IsFull)
1182 //if(data->SafeFetchFullInfo(&g_Git))
1183 // this->Invalidate();
1184 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1187 if (!m_HashMap
[data
->m_CommitHash
].empty())
1191 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1193 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
,rect
);
1195 std::vector
<REFLABEL
> refsToShow
;
1196 STRING_VECTOR remoteTrackingList
;
1197 STRING_VECTOR refList
= m_HashMap
[data
->m_CommitHash
];
1198 for (unsigned int i
= 0; i
< refList
.size(); ++i
)
1200 CString str
= refList
[i
];
1203 refLabel
.color
= RGB(255, 255, 255);
1204 refLabel
.singleRemote
= false;
1205 refLabel
.hasTracking
= false;
1206 refLabel
.sameName
= false;
1207 if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/heads/")))
1209 if (!(m_ShowRefMask
& LOGLIST_SHOWLOCALBRANCHES
))
1211 if (refLabel
.name
== m_CurrentBranch
)
1212 refLabel
.color
= m_Colors
.GetColor(CColors::CurrentBranch
);
1214 refLabel
.color
= m_Colors
.GetColor(CColors::LocalBranch
);
1216 std::pair
<CString
, CString
> trackingEntry
= m_TrackingMap
[refLabel
.name
];
1217 CString pullRemote
= trackingEntry
.first
;
1218 CString pullBranch
= trackingEntry
.second
;
1219 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
1221 CString defaultUpstream
;
1222 defaultUpstream
.Format(_T("refs/remotes/%s/%s"), pullRemote
, pullBranch
);
1223 refLabel
.hasTracking
= true;
1224 if (m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
)
1227 for (int j
= i
+ 1; j
< refList
.size(); ++j
)
1229 if (refList
[j
] == defaultUpstream
)
1238 bool sameName
= pullBranch
== refLabel
.name
;
1239 refsToShow
.push_back(refLabel
);
1240 CGit::GetShortName(defaultUpstream
, refLabel
.name
, _T("refs/remotes/"));
1241 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1242 if (m_bSymbolizeRefNames
)
1244 if (!m_SingleRemote
.IsEmpty() && m_SingleRemote
== pullRemote
)
1246 refLabel
.simplifiedName
= _T("/") + (sameName
? CString() : pullBranch
);
1247 refLabel
.singleRemote
= true;
1250 refLabel
.simplifiedName
= pullRemote
+ _T("/");
1251 refLabel
.sameName
= sameName
;
1253 refsToShow
.push_back(refLabel
);
1254 remoteTrackingList
.push_back(defaultUpstream
);
1260 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/remotes/")))
1262 if (!(m_ShowRefMask
& LOGLIST_SHOWREMOTEBRANCHES
))
1266 for (int j
= 0; j
< remoteTrackingList
.size(); ++j
)
1268 if (remoteTrackingList
[j
] == str
)
1277 refLabel
.color
= m_Colors
.GetColor(CColors::RemoteBranch
);
1278 if (m_bSymbolizeRefNames
)
1280 if (!m_SingleRemote
.IsEmpty() && refLabel
.name
.Left(m_SingleRemote
.GetLength() + 1) == m_SingleRemote
+ _T("/"))
1282 refLabel
.simplifiedName
= _T("/") + refLabel
.name
.Mid(m_SingleRemote
.GetLength() + 1);
1283 refLabel
.singleRemote
= true;
1287 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/tags/")))
1289 if (!(m_ShowRefMask
& LOGLIST_SHOWTAGS
))
1291 refLabel
.color
= m_Colors
.GetColor(CColors::Tag
);
1293 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/stash")))
1295 if (!(m_ShowRefMask
& LOGLIST_SHOWSTASH
))
1297 refLabel
.color
= m_Colors
.GetColor(CColors::Stash
);
1298 refLabel
.name
= _T("stash");
1300 else if (CGit::GetShortName(str
, refLabel
.name
, _T("refs/bisect/")))
1302 if (!(m_ShowRefMask
& LOGLIST_SHOWBISECT
))
1304 if (refLabel
.name
.Find(_T("good")) == 0)
1306 refLabel
.color
= m_Colors
.GetColor(CColors::BisectGood
);
1307 refLabel
.name
= _T("good");
1309 if (refLabel
.name
.Find(_T("bad")) == 0)
1311 refLabel
.color
= m_Colors
.GetColor(CColors::BisectBad
);
1312 refLabel
.name
= _T("bad");
1318 refsToShow
.push_back(refLabel
);
1321 if (refsToShow
.empty())
1323 *pResult
= CDRF_DODEFAULT
;
1327 DrawTagBranch(pLVCD
->nmcd
.hdc
, rect
, pLVCD
->nmcd
.dwItemSpec
, refsToShow
);
1329 *pResult
= CDRF_SKIPDEFAULT
;
1337 if (pLVCD
->iSubItem
== LOGLIST_ACTION
)
1339 if(this->m_IsIDReplaceAction
)
1341 *pResult
= CDRF_DODEFAULT
;
1344 *pResult
= CDRF_DODEFAULT
;
1346 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1350 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1351 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1353 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pLVCD
->nmcd
.dwItemSpec
));
1355 GetSubItemRect((int)pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1356 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1357 // Get the selected state of the
1358 // item being drawn.
1360 // Fill the background if necessary
1361 FillBackGround(pLVCD
->nmcd
.hdc
, pLVCD
->nmcd
.dwItemSpec
, rect
);
1363 // Draw the icon(s) into the compatible DC
1364 pLogEntry
->GetAction(this);
1366 if (!pLogEntry
->m_IsDiffFiles
)
1367 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hFetchIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1369 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED
)
1370 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1373 if (pLogEntry
->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1374 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1377 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_DELETED
)
1378 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1381 if (pLogEntry
->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED
)
1382 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1384 *pResult
= CDRF_SKIPDEFAULT
;
1390 *pResult
= CDRF_DODEFAULT
;
1393 // CGitLogListBase message handlers
1395 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1397 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1399 // Create a pointer to the item
1400 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1402 // Do the list need text information?
1403 if (!(pItem
->mask
& LVIF_TEXT
))
1406 // By default, clear text buffer.
1407 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1409 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1412 if (m_bNoDispUpdates
|| bOutOfRange
)
1415 // Which item number?
1416 int itemid
= pItem
->iItem
;
1417 GitRev
* pLogEntry
= NULL
;
1418 if (itemid
< m_arShownList
.GetCount())
1419 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(pItem
->iItem
));
1424 temp
.Format(_T("%d"),pItem
->iItem
+1);
1429 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1433 switch (pItem
->iSubItem
)
1435 case this->LOGLIST_GRAPH
: //Graphic
1437 case this->LOGLIST_REBASE
:
1439 if(this->m_IsRebaseReplaceGraph
)
1442 path
.m_Action
=pLogEntry
->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1443 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1447 case this->LOGLIST_ACTION
: //action -- no text in the column
1449 case this->LOGLIST_HASH
:
1451 lstrcpyn(pItem
->pszText
, pLogEntry
->m_CommitHash
.ToString(), pItem
->cchTextMax
);
1453 case this->LOGLIST_ID
:
1454 if(this->m_IsIDReplaceAction
)
1455 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1457 case this->LOGLIST_MESSAGE
: //Message
1459 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetSubject(), pItem
->cchTextMax
);
1461 case this->LOGLIST_AUTHOR
: //Author
1463 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorName(), pItem
->cchTextMax
);
1465 case this->LOGLIST_DATE
: //Date
1466 if ( pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()) )
1467 lstrcpyn(pItem
->pszText
,
1468 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
1472 case this->LOGLIST_EMAIL
:
1474 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetAuthorEmail(), pItem
->cchTextMax
);
1477 case this->LOGLIST_COMMIT_NAME
: //Commit
1479 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterName(), pItem
->cchTextMax
);
1482 case this->LOGLIST_COMMIT_EMAIL
: //Commit Email
1484 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->GetCommitterEmail(), pItem
->cchTextMax
);
1487 case this->LOGLIST_COMMIT_DATE
: //Commit Date
1488 if (pLogEntry
&& (!pLogEntry
->m_CommitHash
.IsEmpty()))
1489 lstrcpyn(pItem
->pszText
,
1490 CLoglistUtils::FormatDateAndTime(pLogEntry
->GetCommitterDate(), m_DateFormat
, true, m_bRelativeTimes
),
1493 case this->LOGLIST_BUG
: //Bug ID
1495 lstrcpyn(pItem
->pszText
, (LPCTSTR
)this->m_ProjectProperties
.FindBugID(pLogEntry
->GetSubject() + _T("\r\n\r\n") + pLogEntry
->GetBody()), pItem
->cchTextMax
);
1503 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1506 if (pWnd
== GetHeaderCtrl())
1508 return m_ColumnManager
.OnContextMenuHeader(pWnd
,point
,!!IsGroupViewEnabled());
1511 int selIndex
= GetSelectionMark();
1513 return; // nothing selected, nothing to do with a context menu
1515 // if the user selected the info text telling about not all revisions shown due to
1516 // the "stop on copy/rename" option, we also don't show the context menu
1517 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1520 // if the context menu is invoked through the keyboard, we have to use
1521 // a calculated position on where to anchor the menu on
1522 if ((point
.x
== -1) && (point
.y
== -1))
1525 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1526 ClientToScreen(&rect
);
1527 point
= rect
.CenterPoint();
1529 m_nSearchIndex
= selIndex
;
1530 m_bCancelled
= FALSE
;
1532 // calculate some information the context menu commands can use
1533 // CString pathURL = GetURLFromPath(m_path);
1535 POSITION pos
= GetFirstSelectedItemPosition();
1536 int indexNext
= GetNextSelectedItem(pos
);
1540 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(indexNext
));
1542 GitRev revSelected
= pSelLogEntry
->Rev
;
1543 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1544 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1546 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1548 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->SafeGetAt(i
);
1549 if (changedpath
->lCopyFromRev
)
1550 revPrevious
= changedpath
->lCopyFromRev
;
1553 GitRev revSelected2
;
1556 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1557 revSelected2
= pLogEntry
->Rev
;
1559 bool bAllFromTheSameAuthor
= true;
1560 CString firstAuthor
;
1561 CLogDataVector selEntries
;
1562 GitRev revLowest
, revHighest
;
1563 GitRevRangeArray revisionRanges
;
1565 POSITION pos
= GetFirstSelectedItemPosition();
1566 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1567 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1568 selEntries
.push_back(pLogEntry
);
1569 firstAuthor
= pLogEntry
->sAuthor
;
1570 revLowest
= pLogEntry
->Rev
;
1571 revHighest
= pLogEntry
->Rev
;
1574 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
1575 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1576 selEntries
.push_back(pLogEntry
);
1577 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1578 bAllFromTheSameAuthor
= false;
1579 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1580 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1586 int FirstSelect
=-1, LastSelect
=-1;
1587 pos
= GetFirstSelectedItemPosition();
1588 FirstSelect
= GetNextSelectedItem(pos
);
1591 LastSelect
= GetNextSelectedItem(pos
);
1593 //entry is selected, now show the popup menu
1595 CIconMenu subbranchmenu
, submenu
, gnudiffmenu
, diffmenu
, revertmenu
;
1597 if (popup
.CreatePopupMenu())
1599 bool isHeadCommit
= (pSelLogEntry
->m_CommitHash
== m_HeadHash
);
1600 CString currentBranch
= _T("refs/heads/") + g_Git
.GetCurrentBranch();
1602 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1603 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1605 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1606 popup
.AppendMenuIcon(ID_REBASE_SQUASH
, IDS_REBASE_SQUASH
, IDI_SQUASH
);
1608 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1609 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1611 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1612 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1614 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1615 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1616 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1618 if (GetSelectedCount() == 1)
1622 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1624 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
) && m_hasWC
) // compare revision with WC
1625 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1629 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1630 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1632 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
) && m_hasWC
) // compare with WC, unified
1634 GitRev
*pRev
=pSelLogEntry
;
1635 if (pSelLogEntry
->m_ParentHash
.empty())
1637 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1639 if(pRev
->m_ParentHash
.size()<=1)
1641 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1646 gnudiffmenu
.CreatePopupMenu();
1647 popup
.AppendMenuIcon(ID_GNUDIFF1
,IDS_LOG_POPUP_GNUDIFF_PARENT
, IDI_DIFF
, gnudiffmenu
.m_hMenu
);
1649 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS
)));
1650 gnudiffmenu
.AppendMenuIcon((UINT_PTR
)(ID_GNUDIFF1
+ (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES
)));
1652 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1655 str
.Format(IDS_PARENT
, i
+ 1);
1656 gnudiffmenu
.AppendMenuIcon(ID_GNUDIFF1
+((i
+1)<<16),str
);
1661 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1664 GitRev
*pRev
=pSelLogEntry
;
1665 if (pSelLogEntry
->m_ParentHash
.empty())
1667 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1669 if(pRev
->m_ParentHash
.size()<=1)
1671 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1672 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1673 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1677 diffmenu
.CreatePopupMenu();
1678 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
, diffmenu
.m_hMenu
);
1679 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1682 str
.Format(IDS_PARENT
, i
+ 1);
1683 diffmenu
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
+((i
+1)<<16),str
);
1684 if (i
== 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1686 popup
.SetDefaultItem(ID_COMPAREWITHPREVIOUS
, FALSE
);
1687 diffmenu
.SetDefaultItem((UINT
)(ID_COMPAREWITHPREVIOUS
+ ((i
+ 1) << 16)), FALSE
);
1693 if(m_ContextMenuMask
&GetContextMenuBit(ID_BLAME
))
1694 popup
.AppendMenuIcon(ID_BLAME
, IDS_LOG_POPUP_BLAME
, IDI_BLAME
);
1696 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1697 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1699 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1701 if(m_ContextMenuMask
&GetContextMenuBit(ID_STASH_SAVE
))
1702 popup
.AppendMenuIcon(ID_STASH_SAVE
, IDS_MENUSTASHSAVE
, IDI_COMMIT
);
1705 bool isStash
= false;
1706 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1708 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] == _T("refs/stash"))
1715 if (CTGitPath(g_Git
.m_CurrentDir
).HasStashDir() && (pSelLogEntry
->m_CommitHash
.IsEmpty() || isStash
))
1717 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_POP
))
1718 popup
.AppendMenuIcon(ID_STASH_POP
, IDS_MENUSTASHPOP
, IDI_RELOCATE
);
1720 if (m_ContextMenuMask
&GetContextMenuBit(ID_STASH_LIST
))
1721 popup
.AppendMenuIcon(ID_STASH_LIST
, IDS_MENUSTASHLIST
, IDI_LOG
);
1723 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1726 if (pSelLogEntry
->m_CommitHash
.IsEmpty())
1728 if(m_ContextMenuMask
&GetContextMenuBit(ID_FETCH
))
1729 popup
.AppendMenuIcon(ID_FETCH
, IDS_MENUFETCH
, IDI_PULL
);
1731 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1735 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1737 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1739 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1741 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1743 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1744 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1746 // popup.AppendMenu(MF_SEPARATOR, NULL);
1751 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1753 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1755 if((m_ContextMenuMask
&GetContextMenuBit(ID_LOG
)) &&
1756 GetSelectedCount() == 1)
1757 popup
.AppendMenuIcon(ID_LOG
, IDS_LOG_POPUP_LOG
, IDI_LOG
);
1759 if (m_ContextMenuMask
&GetContextMenuBit(ID_REPOBROWSE
))
1760 popup
.AppendMenuIcon(ID_REPOBROWSE
, IDS_LOG_BROWSEREPO
, IDI_REPOBROWSE
);
1762 format
.LoadString(IDS_LOG_POPUP_MERGEREV
);
1763 str
.Format(format
,g_Git
.GetCurrentBranch());
1765 if (m_ContextMenuMask
&GetContextMenuBit(ID_MERGEREV
) && !isHeadCommit
&& m_hasWC
)
1766 popup
.AppendMenuIcon(ID_MERGEREV
, str
, IDI_MERGE
);
1768 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1769 str
.Format(format
,g_Git
.GetCurrentBranch());
1771 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
) && m_hasWC
)
1772 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1775 // Add Switch Branch express Menu
1776 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end()
1777 && (m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHBRANCH
) && m_hasWC
)
1780 std::vector
<CString
*> branchs
;
1781 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1783 CString ref
= m_HashMap
[pSelLogEntry
->m_CommitHash
][i
];
1784 if(ref
.Find(_T("refs/heads/")) == 0 && ref
!= currentBranch
)
1786 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1791 str
.LoadString(IDS_SWITCH_BRANCH
);
1793 if(branchs
.size() == 1)
1796 str
+= _T('"') + branchs
[0]->Mid(11) + _T('"');
1797 popup
.AppendMenuIcon(ID_SWITCHBRANCH
,str
,IDI_SWITCH
);
1799 popup
.SetMenuItemData(ID_SWITCHBRANCH
,(ULONG_PTR
)branchs
[0]);
1802 else if(branchs
.size() > 1)
1804 subbranchmenu
.CreatePopupMenu();
1805 for (size_t i
= 0 ; i
< branchs
.size(); ++i
)
1807 if (*branchs
[i
] != currentBranch
)
1809 subbranchmenu
.AppendMenuIcon(ID_SWITCHBRANCH
+(i
<<16), branchs
[i
]->Mid(11));
1810 subbranchmenu
.SetMenuItemData(ID_SWITCHBRANCH
+(i
<<16), (ULONG_PTR
) branchs
[i
]);
1814 popup
.AppendMenuIcon(ID_SWITCHBRANCH
, str
, IDI_SWITCH
, subbranchmenu
.m_hMenu
);
1818 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
) && !isHeadCommit
&& m_hasWC
)
1819 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1821 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1822 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1824 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1825 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_TAG
);
1827 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1828 str
.Format(format
,g_Git
.GetCurrentBranch());
1830 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
&& m_hasWC
)
1831 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1832 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1834 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1835 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1837 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1839 GitRev
*pRev
= pSelLogEntry
;
1840 if (pSelLogEntry
->m_ParentHash
.empty())
1842 pRev
->GetParentFromHash(pRev
->m_CommitHash
);
1844 if (pRev
->m_ParentHash
.size() == 1)
1846 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
);
1850 revertmenu
.CreatePopupMenu();
1851 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREV
, IDI_REVERT
, revertmenu
.m_hMenu
);
1853 for (size_t i
= 0; i
< pRev
->m_ParentHash
.size(); ++i
)
1856 str
.Format(IDS_PARENT
, i
+ 1);
1857 revertmenu
.AppendMenuIcon(ID_REVERTREV
+ ((i
+ 1) << 16), str
);
1862 if (m_ContextMenuMask
&GetContextMenuBit(ID_EDITNOTE
))
1863 popup
.AppendMenuIcon(ID_EDITNOTE
, IDS_EDIT_NOTES
, IDI_EDIT
);
1865 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1870 if(!pSelLogEntry
->m_Ref
.IsEmpty())
1872 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1873 if (GetSelectedCount() == 1 && pSelLogEntry
->m_Ref
.Find(_T("refs/stash")) == 0)
1874 popup
.AppendMenuIcon(ID_REFLOG_STASH_APPLY
, IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1875 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1878 if (GetSelectedCount() >= 2)
1880 bool bAddSeparator
= false;
1881 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1883 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
)) // compare two revisions
1884 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1887 if (GetSelectedCount() == 2)
1889 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
) && m_hasWC
) // compare two revisions, unified
1890 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1891 bAddSeparator
= true;
1896 bAddSeparator
= true;
1899 if (m_ContextMenuMask
&GetContextMenuBit(ID_REVERTREV
) && m_hasWC
)
1900 popup
.AppendMenuIcon(ID_REVERTREV
, IDS_LOG_POPUP_REVERTREVS
, IDI_REVERT
);
1903 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1906 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1908 bool bAddSeparator
= false;
1909 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1911 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
) && m_hasWC
)
1915 headindex
= this->GetHeadIndex();
1916 if(headindex
>=0 && LastSelect
>= headindex
)
1918 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1920 if (g_Git
.GetHash(hash
, head
))
1921 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ") + head
+ _T(".")), _T("TortoiseGit"), MB_ICONERROR
);
1922 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(LastSelect
));
1923 if(pLastEntry
->m_CommitHash
== hash
) {
1924 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1925 bAddSeparator
= true;
1930 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
) && !isHeadCommit
&& m_hasWC
) {
1931 if (GetSelectedCount() >= 2)
1932 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSIONS
, IDI_EXPORT
);
1934 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1935 bAddSeparator
= true;
1938 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1939 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
)) {
1940 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1941 bAddSeparator
= true;
1945 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1948 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())
1950 popup
.AppendMenuIcon(ID_BISECTSTART
, IDS_MENUBISECTSTART
);
1951 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1954 if (GetSelectedCount() == 1)
1956 bool bAddSeparator
= false;
1957 if(m_ContextMenuMask
&GetContextMenuBit(ID_PUSH
) && !m_HashMap
[pSelLogEntry
->m_CommitHash
].empty())
1959 // show the push-option only if the log entry has an associated local branch
1960 bool isLocal
= false;
1961 for (size_t i
= 0; isLocal
== false && i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1963 if (m_HashMap
[pSelLogEntry
->m_CommitHash
][i
].Find(_T("refs/heads/")) == 0)
1968 popup
.AppendMenuIcon(ID_PUSH
, IDS_LOG_PUSH
, IDI_PUSH
);
1969 bAddSeparator
= true;
1973 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1975 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1977 std::vector
<CString
*> branchs
;
1978 for (size_t i
= 0; i
< m_HashMap
[pSelLogEntry
->m_CommitHash
].size(); ++i
)
1980 if(m_HashMap
[pSelLogEntry
->m_CommitHash
][i
] != currentBranch
)
1981 branchs
.push_back(&m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]);
1984 if (branchs
.size() == 1)
1986 str
.LoadString(IDS_DELETE_BRANCHTAG_SHORT
);
1989 popup
.AppendMenuIcon(ID_DELETE
, str
, IDI_DELETE
);
1990 popup
.SetMenuItemData(ID_DELETE
, (ULONG_PTR
)branchs
[0]);
1991 bAddSeparator
= true;
1993 else if (branchs
.size() > 1)
1995 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1996 submenu
.CreatePopupMenu();
1997 for (size_t i
= 0; i
< branchs
.size(); ++i
)
1999 submenu
.AppendMenuIcon(ID_DELETE
+ (i
<< 16), *branchs
[i
]);
2000 submenu
.SetMenuItemData(ID_DELETE
+ (i
<< 16), (ULONG_PTR
)branchs
[i
]);
2003 popup
.AppendMenuIcon(ID_DELETE
,str
, IDI_DELETE
, submenu
.m_hMenu
);
2004 bAddSeparator
= true;
2007 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2009 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
2010 } // GetSelectedCount() == 1
2012 if (GetSelectedCount() != 0)
2014 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
2015 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
, IDI_COPYCLIP
);
2016 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
2017 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
, IDI_COPYCLIP
);
2018 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES
))
2019 popup
.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES
, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES
, IDI_COPYCLIP
);
2022 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
2023 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
, IDI_FILTEREDIT
);
2025 if (GetSelectedCount() == 1 && m_ContextMenuMask
& GetContextMenuBit(ID_SHOWBRANCHES
) && !pSelLogEntry
->m_CommitHash
.IsEmpty())
2026 popup
.AppendMenuIcon(ID_SHOWBRANCHES
, IDS_LOG_POPUP_SHOWBRANCHES
, IDI_SHOWBRANCHES
);
2028 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
2029 // DialogEnableWindow(IDOK, FALSE);
2030 // SetPromptApp(&theApp);
2032 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
, &popup
);
2034 // EnableOKButton();
2035 } // if (popup.CreatePopupMenu())
2039 bool CGitLogListBase::IsSelectionContinuous()
2041 if ( GetSelectedCount()==1 )
2043 // if only one revision is selected, the selection is of course
2048 POSITION pos
= GetFirstSelectedItemPosition();
2049 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
2052 int itemindex
= GetNextSelectedItem(pos
);
2055 int nextindex
= GetNextSelectedItem(pos
);
2056 if (nextindex
- itemindex
> 1)
2058 bContinuous
= false;
2061 itemindex
= nextindex
;
2067 void CGitLogListBase::CopySelectionToClipBoard(int toCopy
)
2071 POSITION pos
= GetFirstSelectedItemPosition();
2075 sRev
.LoadString(IDS_LOG_REVISION
);
2077 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
2079 sDate
.LoadString(IDS_LOG_DATE
);
2081 sMessage
.LoadString(IDS_LOG_MESSAGE
);
2085 CString sLogCopyText
;
2087 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(GetNextSelectedItem(pos
)));
2089 if (toCopy
== ID_COPY_ALL
)
2091 //pLogEntry->GetFiles(this)
2092 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2094 CString
from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM
));
2095 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->GetFiles(this).GetCount(); ++cpPathIndex
)
2097 sPaths
+= ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetActionName() + _T(": ") + pLogEntry
->GetFiles(this)[cpPathIndex
].GetGitPathString();
2098 if (((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).m_Action
& (CTGitPath::LOGACTIONS_REPLACED
|CTGitPath::LOGACTIONS_COPY
) && !((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString().IsEmpty())
2101 rename
.Format(from
, ((CTGitPath
&)pLogEntry
->GetFiles(this)[cpPathIndex
]).GetGitOldPathString());
2102 sPaths
+= _T(" ") + rename
;
2104 sPaths
+= _T("\r\n");
2107 CString body
= pLogEntry
->GetBody();
2108 body
.Replace(_T("\n"), _T("\r\n"));
2109 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"),
2110 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
.ToString(),
2111 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->GetAuthorName(), (LPCTSTR
)pLogEntry
->GetAuthorEmail(),
2113 (LPCTSTR
)CLoglistUtils::FormatDateAndTime(pLogEntry
->GetAuthorDate(), m_DateFormat
, true, m_bRelativeTimes
),
2114 (LPCTSTR
)sMessage
, (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim(),
2116 sClipdata
+= sLogCopyText
;
2118 else if (toCopy
== ID_COPY_MESSAGE
)
2120 CString body
= pLogEntry
->GetBody();
2121 body
.Replace(_T("\n"), _T("\r\n"));
2122 sClipdata
+= _T("* ") + (pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n") + body
.Trim()).Trim() + _T("\r\n\r\n");
2124 else if (toCopy
== ID_COPY_SUBJECT
)
2126 sClipdata
+= _T("* ") + pLogEntry
->GetSubject().Trim() + _T("\r\n\r\n");
2131 sClipdata
+= _T("\r\n");
2132 sClipdata
+= pLogEntry
->m_CommitHash
;
2137 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
2142 void CGitLogListBase::DiffSelectedRevWithPrevious()
2144 if (m_bThreadRunning
)
2147 int FirstSelect
=-1, LastSelect
=-1;
2148 POSITION pos
= GetFirstSelectedItemPosition();
2149 FirstSelect
= GetNextSelectedItem(pos
);
2152 LastSelect
= GetNextSelectedItem(pos
);
2155 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
, NULL
);
2158 UpdateLogInfoLabel();
2159 int selIndex
= m_LogList
.GetSelectionMark();
2162 int selCount
= m_LogList
.GetSelectedCount();
2166 // Find selected entry in the log list
2167 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
2168 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(m_LogList
.GetNextSelectedItem(pos
)));
2169 long rev1
= pLogEntry
->Rev
;
2171 CTGitPath path
= m_path
;
2173 // See how many files under the relative root were changed in selected revision
2175 LogChangedPath
* changed
= NULL
;
2176 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
2178 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->SafeGetAt(c
);
2179 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
2186 if (m_path
.IsDirectory() && nChanged
== 1)
2188 // We're looking at the log for a directory and only one file under dir was changed in the revision
2189 // Do diff on that file instead of whole directory
2190 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
2193 m_bCancelled
= FALSE
;
2194 DialogEnableWindow(IDOK
, FALSE
);
2195 SetPromptApp(&theApp
);
2196 theApp
.DoWaitCursor(1);
2200 GitDiff
diff(this, m_hWnd
, true);
2201 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2202 diff
.SetHEADPeg(m_LogRevision
);
2203 diff
.ShowCompare(path
, rev2
, path
, rev1
);
2207 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
2210 theApp
.DoWaitCursor(-1);
2215 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
2217 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
2220 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
2222 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
2224 if (pFindInfo
->lvfi
.psz
== 0)
2227 CString sCmp
= pFindInfo
->lvfi
.psz
;
2229 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
2231 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.SafeGetAt(i
));
2232 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2233 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2235 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2243 if (sCmp
.Compare(sRev
)==0)
2250 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
2252 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
2254 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.SafeGetAt(i
));
2255 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
2256 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
2258 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
2266 if (sCmp
.Compare(sRev
)==0)
2278 int CGitLogListBase::FillGitLog(CTGitPath
*path
, CString
*range
, int info
)
2282 this->m_arShownList
.SafeRemoveAll();
2284 this->m_logEntries
.ClearAll();
2285 if (this->m_logEntries
.ParserFromLog(path
, -1, info
, range
))
2288 //this->m_logEntries.ParserFromLog();
2289 SetItemCountEx((int)m_logEntries
.size());
2291 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2295 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
2296 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
2301 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
2302 this->m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
2314 int CGitLogListBase::BeginFetchLog()
2318 this->m_arShownList
.SafeRemoveAll();
2320 this->m_logEntries
.ClearAll();
2322 this->m_LogCache
.ClearAllParent();
2324 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
2327 if(this->m_Path
.IsEmpty())
2333 mask
= CGit::LOG_INFO_ONLY_HASH
;
2334 if (m_bIncludeBoundaryCommits
)
2335 mask
|= CGit::LOG_INFO_BOUNDARY
;
2336 // if(this->m_bAllBranch)
2337 mask
|= m_ShowMask
;
2341 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
2343 this->m_LogCache
.m_HashMap
[m_wcRev
.m_CommitHash
]=m_wcRev
;
2346 if (m_sRange
.IsEmpty())
2347 m_sRange
= _T("HEAD");
2350 data
.m_From
= m_From
;
2353 #if 0 /* use tortoiegit filter */
2354 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_AUTHORS
)
2355 data
.m_Author
= this->m_sFilterText
;
2357 if(this->m_nSelectedFilter
== LOGFILTER_ALL
|| m_nSelectedFilter
== LOGFILTER_MESSAGES
)
2358 data
.m_MessageFilter
= this->m_sFilterText
;
2360 data
.m_IsRegex
= m_bFilterWithRegex
;
2363 // follow does not work for directories
2364 if (!path
|| path
->IsDirectory())
2365 mask
&= ~CGit::LOG_INFO_FOLLOW
;
2366 // follow does not work with all branches 8at least in TGit)
2367 if (mask
& CGit::LOG_INFO_FOLLOW
)
2368 mask
&= ~CGit::LOG_INFO_ALL_BRANCH
;
2370 CString cmd
= g_Git
.GetLogCmd(m_sRange
, path
, -1, mask
, true, &data
);
2372 //this->m_logEntries.ParserFromLog();
2373 if(IsInWorkingThread())
2375 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
2379 SetItemCountEx((int)m_logEntries
.size());
2389 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2393 if (!g_Git
.CanParseRev(m_sRange
))
2395 if (!(mask
& CGit::LOG_INFO_ALL_BRANCH
))
2398 // if show all branches, pick any ref as dummy entry ref
2400 if (g_Git
.GetRefList(list
))
2401 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2402 if (list
.size() == 0)
2405 cmd
= g_Git
.GetLogCmd(list
[0], path
, -1, mask
, true, &data
);
2409 if (git_open_log(&m_DllGitLog
, CUnicodeUtils::GetMulti(cmd
, CP_UTF8
).GetBuffer()))
2417 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2424 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
2426 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
2428 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2430 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2432 DiffSelectedRevWithPrevious();
2437 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
2444 else if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== 'A' && GetAsyncKeyState(VK_CONTROL
)&0x8000)
2446 // select all entries
2447 for (int i
=0; i
<GetItemCount(); ++i
)
2449 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
2455 if (m_hAccel
&& !bSkipAccelerator
)
2457 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
2463 //m_tooltips.RelayEvent(pMsg);
2464 return __super::PreTranslateMessage(pMsg
);
2467 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
2469 // a double click on an entry in the revision list has happened
2472 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
2473 DiffSelectedRevWithPrevious();
2476 int CGitLogListBase::FetchLogAsync(void * data
)
2480 m_bExitThread
=FALSE
;
2481 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2482 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2483 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this, THREAD_PRIORITY_LOWEST
);
2484 if (m_LoadingThread
==NULL
)
2486 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2487 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2488 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2494 //this is the thread function which calls the subversion function
2495 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
2497 return ((CGitLogListBase
*)pVoid
)->LogThread();
2500 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
2503 oldest
=CTime::GetCurrentTime();
2504 latest
=CTime(1971,1,2,0,0,0);
2505 for (unsigned int i
= 0; i
< m_logEntries
.size(); ++i
)
2507 if(m_logEntries
[i
].IsEmpty())
2510 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() < oldest
.GetTime())
2511 oldest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2513 if(m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime() > latest
.GetTime())
2514 latest
= m_logEntries
.GetGitRevAt(i
).GetAuthorDate().GetTime();
2522 UINT
CGitLogListBase::LogThread()
2524 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2526 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2527 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2533 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2534 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2539 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2540 bool bRegex
= false;
2541 if (m_bFilterWithRegex
)
2542 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2544 TRACE(_T("\n===Begin===\n"));
2545 //Update work copy item;
2547 if (!m_logEntries
.empty())
2549 GitRev
*pRev
= &m_logEntries
.GetGitRevAt(0);
2551 m_arShownList
.SafeAdd(pRev
);
2555 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2557 // store commit number of the last selected commit/line before the refresh or -1
2558 int lastSelectedHashNItem
= -1;
2561 bool shouldWalk
= true;
2562 if (!g_Git
.CanParseRev(m_sRange
))
2564 // walk revisions if show all branches and there exists any ref
2565 if (!(m_ShowMask
& CGit::LOG_INFO_ALL_BRANCH
))
2570 if (g_Git
.GetRefList(list
))
2571 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
2572 if (list
.size() == 0)
2579 g_Git
.m_critGitDllSec
.Lock();
2583 git_get_log_firstcommit(m_DllGitLog
);
2584 total
= git_get_log_estimate_commit_count(m_DllGitLog
);
2589 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2592 g_Git
.m_critGitDllSec
.Unlock();
2595 t2
=t1
=GetTickCount();
2596 int oldprecentage
= 0;
2597 size_t oldsize
= m_logEntries
.size();
2598 while (ret
== 0 && !m_bExitThread
)
2600 g_Git
.m_critGitDllSec
.Lock();
2603 ret
= git_get_log_nextcommit(this->m_DllGitLog
, &commit
, m_ShowMask
& CGit::LOG_INFO_FOLLOW
);
2607 g_Git
.m_critGitDllSec
.Unlock();
2609 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
2612 g_Git
.m_critGitDllSec
.Unlock();
2617 if (commit
.m_ignore
== 1)
2619 git_free_commit(&commit
);
2623 //printf("%s\r\n",commit.GetSubject());
2627 CGitHash hash
= (char*)commit
.m_hash
;
2629 GitRev
*pRev
= m_LogCache
.GetCacheData(hash
);
2630 pRev
->m_GitCommit
= commit
;
2631 InterlockedExchange(&pRev
->m_IsCommitParsed
, FALSE
);
2634 g_Git
.m_critGitDllSec
.Lock();
2635 git_get_notes(commit
.m_hash
,¬e
);
2636 g_Git
.m_critGitDllSec
.Unlock();
2640 pRev
->m_Notes
.Empty();
2641 g_Git
.StringAppend(&pRev
->m_Notes
,(BYTE
*)note
);
2644 if(!pRev
->m_IsDiffFiles
)
2646 pRev
->m_CallDiffAsync
= DiffAsync
;
2649 pRev
->ParserParentFromCommit(&commit
);
2656 if(!m_sFilterText
.IsEmpty())
2658 if(!IsMatchFilter(bRegex
,pRev
,pat
))
2661 this->m_critSec
.Lock();
2662 m_logEntries
.push_back(hash
);
2663 m_arShownList
.SafeAdd(pRev
);
2664 this->m_critSec
.Unlock();
2666 if (lastSelectedHashNItem
== -1 && hash
== m_lastSelectedHash
)
2667 lastSelectedHashNItem
= (int)m_arShownList
.GetCount() - 1;
2671 if(t2
-t1
>500 || (m_logEntries
.size()-oldsize
>100))
2674 int percent
= (int)m_logEntries
.size() * 100 / total
+ GITLOG_START
+ 1;
2677 if(percent
< GITLOG_START
)
2678 percent
= GITLOG_START
+1;
2680 oldsize
= m_logEntries
.size();
2681 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2683 //if( percent > oldprecentage )
2685 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
2686 oldprecentage
= percent
;
2691 g_Git
.m_critGitDllSec
.Lock();
2692 git_close_log(m_DllGitLog
);
2693 g_Git
.m_critGitDllSec
.Unlock();
2699 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2704 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
|LVSICF_NOSCROLL
);
2706 if (lastSelectedHashNItem
>= 0)
2707 PostMessage(m_ScrollToMessage
, lastSelectedHashNItem
);
2710 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2712 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2717 void CGitLogListBase::FetchRemoteList()
2719 STRING_VECTOR remoteList
;
2720 if (!g_Git
.GetRemoteList(remoteList
))
2721 m_SingleRemote
= remoteList
.size() == 1 ? remoteList
[0] : _T("");
2723 m_SingleRemote
= _T("");
2726 void CGitLogListBase::FetchTrackingBranchList()
2728 m_TrackingMap
.clear();
2729 for (MAP_HASH_NAME::iterator it
= m_HashMap
.begin(); it
!= m_HashMap
.end(); ++it
)
2731 for (int j
= 0; j
< it
->second
.size(); ++j
)
2734 if (CGit::GetShortName(it
->second
[j
], branchName
, _T("refs/heads/")))
2737 configName
.Format(_T("branch.%s.remote"), branchName
);
2738 CString pullRemote
= g_Git
.GetConfigValue(configName
);
2740 configName
.Format(_T("branch.%s.merge"), branchName
);
2741 CString pullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
2743 if (!pullRemote
.IsEmpty() && !pullBranch
.IsEmpty())
2745 m_TrackingMap
[branchName
] = std::make_pair(pullRemote
, pullBranch
);
2752 void CGitLogListBase::Refresh(BOOL IsCleanFilter
)
2754 SafeTerminateThread();
2756 this->SetItemCountEx(0);
2761 // HACK to hide graph column
2762 if (m_ShowMask
& CGit::LOG_INFO_FOLLOW
)
2763 SetColumnWidth(0, 0);
2765 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
2767 //Update branch and Tag info
2769 //Assume Thread have exited
2770 //if(!m_bThreadRunning)
2772 m_logEntries
.clear();
2776 m_sFilterText
.Empty();
2781 InterlockedExchange(&m_bExitThread
,FALSE
);
2783 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2784 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2785 if ( (m_LoadingThread
=AfxBeginThread(LogThreadEntry
, this)) ==NULL
)
2787 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2788 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2789 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2793 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2797 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2799 type
|= tr1::regex_constants::icase
;
2800 pat
= tr1::wregex(regexp_str
, type
);
2803 catch (exception
) {}
2806 BOOL
CGitLogListBase::IsMatchFilter(bool bRegex
, GitRev
*pRev
, tr1::wregex
&pat
)
2809 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2812 if ((bRegex
)&&(m_bFilterWithRegex
))
2814 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2816 if(this->m_bShowBugtraqColumn
)
2818 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2820 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds
);
2821 if (regex_search(wstring(sBugIds
), pat
, flags
))
2828 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2830 ATLTRACE(_T("messge = \"%s\"\n"), pRev
->GetSubject());
2831 if (regex_search(wstring((LPCTSTR
)pRev
->GetSubject()), pat
, flags
))
2837 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2839 ATLTRACE(_T("messge = \"%s\"\n"),pRev
->GetBody());
2840 if (regex_search(wstring((LPCTSTR
)pRev
->GetBody()), pat
, flags
))
2846 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2848 if (regex_search(wstring(pRev
->GetAuthorName()), pat
, flags
))
2853 if (regex_search(wstring(pRev
->GetCommitterName()), pat
, flags
))
2859 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
2861 if (regex_search(wstring(pRev
->GetAuthorEmail()), pat
, flags
))
2866 if (regex_search(wstring(pRev
->GetCommitterEmail()), pat
, flags
))
2872 if (m_SelectedFilters
& LOGFILTER_REVS
)
2874 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2875 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
))
2881 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
2883 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
2884 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
2886 if (regex_search(wstring((LPCTSTR
)*it
), pat
, flags
))
2893 if (m_SelectedFilters
& LOGFILTER_PATHS
)
2895 CTGitPathList
*pathList
=NULL
;
2896 if( pRev
->m_IsDiffFiles
)
2897 pathList
= &pRev
->GetFiles(this);
2900 if(!pRev
->m_IsSimpleListReady
)
2901 pRev
->SafeGetSimpleList(&g_Git
);
2905 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount(); ++cpPathIndex
)
2907 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitOldPathString()), pat
, flags
))
2911 if (regex_search(wstring((LPCTSTR
)pathList
->m_paths
.at(cpPathIndex
).GetGitPathString()), pat
, flags
))
2917 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
2919 if (regex_search(wstring((LPCTSTR
)pRev
->m_SimpleFileList
[i
]), pat
, flags
))
2928 CString find
= m_sFilterText
;
2931 if (m_SelectedFilters
& LOGFILTER_BUGID
)
2933 if(this->m_bShowBugtraqColumn
)
2935 CString sBugIds
= m_ProjectProperties
.FindBugID(pRev
->GetSubject() + _T("\r\n\r\n") + pRev
->GetBody());
2937 sBugIds
.MakeLower();
2938 if ((sBugIds
.Find(find
) >= 0))
2945 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
2947 CString msg
= pRev
->GetSubject();
2949 msg
= msg
.MakeLower();
2950 if ((msg
.Find(find
) >= 0))
2956 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
2958 CString msg
= pRev
->GetBody();
2960 msg
= msg
.MakeLower();
2961 if ((msg
.Find(find
) >= 0))
2967 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
2969 CString msg
= pRev
->GetAuthorName();
2970 msg
= msg
.MakeLower();
2971 if ((msg
.Find(find
) >= 0))
2977 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
2979 CString msg
= pRev
->GetAuthorEmail();
2980 msg
= msg
.MakeLower();
2981 if ((msg
.Find(find
) >= 0))
2987 if (m_SelectedFilters
& LOGFILTER_REVS
)
2989 sRev
.Format(_T("%s"), pRev
->m_CommitHash
.ToString());
2990 if ((sRev
.Find(find
) >= 0))
2996 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
2998 STRING_VECTOR refs
= m_HashMap
[pRev
->m_CommitHash
];
2999 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3001 if (it
->Find(find
) >= 0)
3008 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3010 CTGitPathList
*pathList
=NULL
;
3011 if( pRev
->m_IsDiffFiles
)
3012 pathList
= &pRev
->GetFiles(this);
3015 if(!pRev
->m_IsSimpleListReady
)
3016 pRev
->SafeGetSimpleList(&g_Git
);
3019 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
->GetCount() ; ++cpPathIndex
)
3021 CTGitPath
*cpath
= &pathList
->m_paths
.at(cpPathIndex
);
3022 CString path
= cpath
->GetGitOldPathString();
3024 if ((path
.Find(find
)>=0))
3028 path
= cpath
->GetGitPathString();
3030 if ((path
.Find(find
)>=0))
3036 for (size_t i
= 0; i
< pRev
->m_SimpleFileList
.size(); ++i
)
3038 CString path
= pRev
->m_SimpleFileList
[i
];
3040 if ((path
.Find(find
)>=0))
3046 } // else (from if (bRegex))
3051 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray
* pShownlist
)
3054 pShownlist
->SafeRemoveAll();
3056 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
3057 bool bRegex
= false;
3058 if (m_bFilterWithRegex
)
3059 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
3061 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
3063 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3065 if ((bRegex
)&&(m_bFilterWithRegex
))
3068 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3070 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
3071 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
3073 pShownlist
->SafeAdd(m_logEntries
[i
]);
3078 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3080 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetSubject());
3081 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetSubject()), pat
, flags
)&&IsEntryInDateRange(i
))
3083 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3087 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3089 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
.GetGitRevAt(i
).GetBody());
3090 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetBody()), pat
, flags
)&&IsEntryInDateRange(i
))
3092 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3096 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3098 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3101 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3103 CTGitPath cpath
= pathList
[cpPathIndex
];
3104 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitOldPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3106 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3110 if (regex_search(wstring((LPCTSTR
)cpath
.GetGitPathString()), pat
, flags
)&&IsEntryInDateRange(i
))
3112 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3116 if (regex_search(wstring((LPCTSTR
)cpath
.GetActionName()), pat
, flags
)&&IsEntryInDateRange(i
))
3118 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3124 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3126 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorName()), pat
, flags
)&&IsEntryInDateRange(i
))
3128 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3132 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3134 if (regex_search(wstring((LPCTSTR
)m_logEntries
.GetGitRevAt(i
).GetAuthorEmail()), pat
, flags
) && IsEntryInDateRange(i
))
3136 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3140 if (m_SelectedFilters
& LOGFILTER_REVS
)
3142 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3143 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
3145 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3149 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3151 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3152 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3154 if (regex_search(wstring((LPCTSTR
)*it
), pat
, flags
) && IsEntryInDateRange(i
))
3156 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3164 CString find
= m_sFilterText
;
3167 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
3169 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
3171 sBugIDs
= sBugIDs
.MakeLower();
3172 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3174 pShownlist
->SafeAdd(m_logEntries
[i
]);
3179 if ((m_SelectedFilters
& LOGFILTER_SUBJECT
) || (m_SelectedFilters
& LOGFILTER_MESSAGES
))
3181 CString msg
= m_logEntries
.GetGitRevAt(i
).GetSubject();
3183 msg
= msg
.MakeLower();
3184 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3186 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3190 if (m_SelectedFilters
& LOGFILTER_MESSAGES
)
3192 CString msg
= m_logEntries
.GetGitRevAt(i
).GetBody();
3194 msg
= msg
.MakeLower();
3195 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3197 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3201 if (m_SelectedFilters
& LOGFILTER_PATHS
)
3203 CTGitPathList pathList
= m_logEntries
.GetGitRevAt(i
).GetFiles(this);
3206 for (INT_PTR cpPathIndex
= 0; cpPathIndex
< pathList
.GetCount() && bGoing
; ++cpPathIndex
)
3208 CTGitPath cpath
= pathList
[cpPathIndex
];
3209 CString path
= cpath
.GetGitOldPathString();
3211 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3213 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3217 path
= cpath
.GetGitPathString();
3219 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3221 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3225 path
= cpath
.GetActionName();
3227 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
3229 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3235 if (m_SelectedFilters
& LOGFILTER_AUTHORS
)
3237 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorName();
3238 msg
= msg
.MakeLower();
3239 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3241 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3245 if (m_SelectedFilters
& LOGFILTER_EMAILS
)
3247 CString msg
= m_logEntries
.GetGitRevAt(i
).GetAuthorEmail();
3248 msg
= msg
.MakeLower();
3249 if ((msg
.Find(find
) >= 0) && (IsEntryInDateRange(i
)))
3251 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3255 if (m_SelectedFilters
& LOGFILTER_REVS
)
3257 sRev
.Format(_T("%s"), m_logEntries
.GetGitRevAt(i
).m_CommitHash
.ToString());
3258 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
3260 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3264 if (m_SelectedFilters
& LOGFILTER_REFNAME
)
3266 STRING_VECTOR refs
= m_HashMap
[m_logEntries
.GetGitRevAt(i
).m_CommitHash
];
3267 for (auto it
= refs
.cbegin(); it
!= refs
.cend(); ++it
)
3269 if (it
->Find(find
) >= 0 && IsEntryInDateRange(i
))
3271 pShownlist
->SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3276 } // else (from if (bRegex))
3277 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3281 BOOL
CGitLogListBase::IsEntryInDateRange(int /*i*/)
3284 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3290 return time <= m_To;
3293 return time >= m_From;
3295 return ((time >= m_From)&&(time <= m_To));
3297 return TRUE
; /* git dll will filter time range */
3301 void CGitLogListBase::StartFilter()
3303 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3304 RecalculateShownList(&m_arShownList
);
3305 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3309 SetItemCountEx(ShownCountWithStopped());
3310 RedrawItems(0, ShownCountWithStopped());
3314 void CGitLogListBase::RemoveFilter()
3317 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
3319 m_arShownList
.SafeRemoveAll();
3321 // reset the time filter too
3323 m_timFrom
= (__time64_t(m_tFrom
));
3324 m_timTo
= (__time64_t(m_tTo
));
3325 m_DateFrom
.SetTime(&m_timFrom
);
3326 m_DateTo
.SetTime(&m_timTo
);
3327 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
3328 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
3331 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
3333 if(this->m_IsOldFirst
)
3335 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1));
3339 m_arShownList
.SafeAdd(&m_logEntries
.GetGitRevAt(i
));
3342 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3344 SetItemCountEx(ShownCountWithStopped());
3345 RedrawItems(0, ShownCountWithStopped());
3347 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
3350 void CGitLogListBase::Clear()
3352 m_arShownList
.SafeRemoveAll();
3355 m_logEntries
.ClearAll();
3359 void CGitLogListBase::OnDestroy()
3361 // save the column widths to the registry
3364 SafeTerminateThread();
3365 SafeTerminateAsyncDiffThread();
3368 while(m_LogCache
.SaveCache())
3376 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3377 // MB_YESNO) == IDNO)
3381 CHintListCtrl::OnDestroy();
3384 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM
/*lParam*/)
3388 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
3389 this->InvalidateRect(rect
);
3395 * Save column widths to the registry
3397 void CGitLogListBase::SaveColumnWidths()
3399 int maxcol
= m_ColumnManager
.GetColumnCount();
3401 // HACK that graph column is always shown
3402 SetColumnWidth(0, m_ColumnManager
.GetWidth(0, false));
3404 for (int col
= 0; col
< maxcol
; ++col
)
3405 if (m_ColumnManager
.IsVisible (col
))
3406 m_ColumnManager
.ColumnResized (col
);
3408 m_ColumnManager
.WriteSettings();
3411 int CGitLogListBase::GetHeadIndex()
3413 if(m_HeadHash
.IsEmpty())
3416 for (int i
= 0; i
< m_arShownList
.GetCount(); ++i
)
3418 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
3421 if(pRev
->m_CommitHash
.ToString() == m_HeadHash
)
3427 void CGitLogListBase::OnFind()
3431 m_pFindDialog
= new CFindDlg(this);
3432 m_pFindDialog
->Create(this);
3435 void CGitLogListBase::OnHdnBegintrack(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3437 m_ColumnManager
.OnHdnBegintrack(pNMHDR
, pResult
);
3439 void CGitLogListBase::OnHdnItemchanging(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3441 if(!m_ColumnManager
.OnHdnItemchanging(pNMHDR
, pResult
))
3444 LRESULT
CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect
, LPARAM
/*lParam*/)
3446 if (GetSelectedCount() != 0)
3448 SetItemState((int)itemToSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
3449 EnsureVisible((int)itemToSelect
, FALSE
);
3452 LRESULT
CGitLogListBase::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
3455 ASSERT(m_pFindDialog
!= NULL
);
3456 bool bFound
= false;
3459 if (m_pFindDialog
->IsTerminating())
3461 // invalidate the handle identifying the dialog box.
3462 m_pFindDialog
= NULL
;
3466 if(m_pFindDialog
->IsRef())
3469 str
=m_pFindDialog
->GetFindString();
3475 if (g_Git
.GetHash(hash
, str
+ _T("^{}"))) // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3476 MessageBox(g_Git
.GetGitLastErr(_T("Could not get hash of ref \"") + str
+ _T("^{}\".")), _T("TortoiseGit"), MB_ICONERROR
);
3481 for (i
= 0; i
<m_arShownList
.GetCount(); ++i
)
3483 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3484 if(pLogEntry
&& pLogEntry
->m_CommitHash
== hash
)
3494 if(m_pFindDialog
->FindNext())
3496 //read data from dialog
3497 CString FindText
= m_pFindDialog
->GetFindString();
3498 bool bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
3501 bool bRegex
= ValidateRegexp(FindText
, pat
, bMatchCase
);
3503 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_not_null
;
3506 for (i
= this->m_nSearchIndex
; i
< m_arShownList
.GetCount() && !bFound
; ++i
)
3508 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.SafeGetAt(i
);
3511 str
+=pLogEntry
->m_CommitHash
.ToString();
3514 for (size_t j
= 0; j
< this->m_HashMap
[pLogEntry
->m_CommitHash
].size(); ++j
)
3516 str
+=m_HashMap
[pLogEntry
->m_CommitHash
][j
];
3520 str
+=pLogEntry
->GetAuthorEmail();
3522 str
+=pLogEntry
->GetAuthorName();
3524 str
+=pLogEntry
->GetBody();
3526 str
+=pLogEntry
->GetCommitterEmail();
3528 str
+=pLogEntry
->GetCommitterName();
3530 str
+=pLogEntry
->GetSubject();
3534 /*Because changed files list is loaded on demand when gui show,
3535 files will empty when files have not fetched.
3537 we can add it back by using one-way diff(with outnumber changed and rename detect.
3538 here just need changed filename list. one-way is much quicker.
3540 if(pLogEntry
->m_IsFull
)
3542 for (int i
= 0; i
< pLogEntry
->GetFiles(this).GetCount(); ++i
)
3544 str
+=pLogEntry
->GetFiles(this)[i
].GetWinPath();
3546 str
+=pLogEntry
->GetFiles(this)[i
].GetGitOldPathString();
3552 if(!pLogEntry
->m_IsSimpleListReady
)
3553 pLogEntry
->SafeGetSimpleList(&g_Git
);
3555 for (size_t i
= 0; i
< pLogEntry
->m_SimpleFileList
.size(); ++i
)
3557 str
+=pLogEntry
->m_SimpleFileList
[i
];
3566 if (regex_search(wstring(str
), pat
, flags
))
3576 if (str
.Find(FindText
) >= 0)
3586 msg
= msg
.MakeLower();
3587 CString find
= FindText
.MakeLower();
3588 if (msg
.Find(find
) >= 0)
3595 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; ++i)
3597 } // if(m_pFindDialog->FindNext())
3598 //UpdateLogInfoLabel();
3602 this->m_nSearchIndex
= i
;
3603 EnsureVisible(i
, FALSE
);
3604 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED
);
3605 SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
3606 SetSelectionMark(i
);
3607 //FillLogMessageCtrl();
3610 if (m_nSearchIndex
>= m_arShownList
.GetCount())
3611 m_nSearchIndex
= (int)m_arShownList
.GetCount()-1;
3617 void CGitLogListBase::OnColumnResized(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3619 m_ColumnManager
.OnColumnResized(pNMHDR
,pResult
);
3624 void CGitLogListBase::OnColumnMoved(NMHDR
*pNMHDR
, LRESULT
*pResult
)
3626 m_ColumnManager
.OnColumnMoved(pNMHDR
, pResult
);