1 // GitLogList.cpp : implementation file
4 Description: qgit revision list view
6 Author: Marco Costalba (C) 2005-2007
8 Copyright: See COPYING file that comes with this distribution
12 #include "GitLogListBase.h"
14 //#include "VssStyle.h"
20 #include "SVNProgressDlg.h"
21 #include "ProgressDlg.h"
22 //#include "RepositoryBrowser.h"
23 //#include "CopyDlg.h"
24 //#include "StatGraphDlg.h"
26 #include "MessageBox.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "UnicodeUtils.h"
33 //#include "GitInfo.h"
34 //#include "GitDiff.h"
36 //#include "RevisionRangeDlg.h"
37 //#include "BrowseFolder.h"
38 //#include "BlameDlg.h"
40 //#include "GitHelpers.h"
41 #include "GitStatus.h"
42 //#include "LogDlgHelper.h"
43 //#include "CachedLogInfo.h"
44 //#include "RepositoryInfo.h"
45 //#include "EditPropertiesDlg.h"
46 #include "FileDiffDlg.h"
47 #include "..\\TortoiseShell\\Resource.h"
50 IMPLEMENT_DYNAMIC(CGitLogListBase
, CHintListCtrl
)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
55 ,m_bNoDispUpdates(FALSE
)
56 , m_bThreadRunning(FALSE
)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL
)
59 , m_nSelectedFilter(LOGFILTER_ALL
)
62 , m_logEntries(&m_LogCache
)
64 // use the default GUI font, create a copy of it and
65 // change the copy to BOLD (leave the rest of the font
67 HFONT hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
69 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
70 lf
.lfWeight
= FW_BOLD
;
71 m_boldFont
= CreateFontIndirect(&lf
);
73 m_bShowBugtraqColumn
=0;
75 m_IsIDReplaceAction
=FALSE
;
77 m_wcRev
.m_CommitHash
.Empty();
78 m_wcRev
.m_Subject
=_T("Working dir changes");
79 m_wcRev
.m_ParentHash
.clear();
80 m_wcRev
.m_Mark
=_T('-');
81 m_wcRev
.m_IsUpdateing
=FALSE
;
82 m_wcRev
.m_IsFull
= TRUE
;
84 m_hModifiedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
85 m_hReplacedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
86 m_hAddedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
87 m_hDeletedIcon
= (HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED
), IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
);
89 m_bFilterWithRegex
= !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE
);
91 g_Git
.GetMapHashToFriendName(m_HashMap
);
92 m_CurrentBranch
=g_Git
.GetCurrentBranch();
93 this->m_HeadHash
=g_Git
.GetHash(CString(_T("HEAD"))).Left(40);
95 m_From
=CTime(1970,1,2,0,0,0);
96 m_To
=CTime::GetCurrentTime();
98 m_LoadingThread
= NULL
;
101 m_IsOldFirst
= FALSE
;
102 m_IsRebaseReplaceGraph
= FALSE
;
105 for(int i
=0;i
<Lanes::COLORS_NUM
;i
++)
107 m_LineColors
[i
] = m_Colors
.GetColor((CColors::Colors
)(CColors::BranchLine1
+i
));
109 // get short/long datetime setting from registry
110 DWORD RegUseShortDateFormat
= CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE
);
111 if ( RegUseShortDateFormat
)
113 m_DateFormat
= DATE_SHORTDATE
;
117 m_DateFormat
= DATE_LONGDATE
;
119 // get relative time display setting from registry
120 DWORD regRelativeTimes
= CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE
);
121 m_bRelativeTimes
= (regRelativeTimes
!= 0);
122 m_ContextMenuMask
= 0xFFFFFFFFFFFFFFFF;
124 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_PICK
);
125 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SQUASH
);
126 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_EDIT
);
127 m_ContextMenuMask
&= ~GetContextMenuBit(ID_REBASE_SKIP
);
130 SecureZeroMemory(&inf
, sizeof(OSVERSIONINFOEX
));
131 inf
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
132 GetVersionEx((OSVERSIONINFO
*)&inf
);
133 WORD fullver
= MAKEWORD(inf
.dwMinorVersion
, inf
.dwMajorVersion
);
134 m_bVista
= (fullver
>= 0x0600);
136 m_ColumnRegKey
=_T("log");
139 CGitLogListBase::~CGitLogListBase()
141 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
143 DestroyIcon(m_hModifiedIcon
);
144 DestroyIcon(m_hReplacedIcon
);
145 DestroyIcon(m_hAddedIcon
);
146 DestroyIcon(m_hDeletedIcon
);
147 m_logEntries
.ClearAll();
150 DeleteObject(m_boldFont
);
152 if ( m_pStoreSelection
)
154 delete m_pStoreSelection
;
155 m_pStoreSelection
= NULL
;
158 if(this->m_bThreadRunning
)
161 WaitForSingleObject(m_LoadingThread
->m_hThread
,1000);
167 BEGIN_MESSAGE_MAP(CGitLogListBase
, CHintListCtrl
)
168 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdrawLoglist
)
169 ON_NOTIFY_REFLECT(LVN_GETDISPINFO
, OnLvnGetdispinfoLoglist
)
171 ON_NOTIFY_REFLECT(NM_DBLCLK
, OnNMDblclkLoglist
)
172 ON_NOTIFY_REFLECT(LVN_ODFINDITEM
,OnLvnOdfinditemLoglist
)
175 ON_MESSAGE(MSG_LOADED
,OnLoad
)
177 ON_WM_MEASUREITEM_REFLECT()
180 void CGitLogListBase::OnMeasureItem(int nIDCtl
, LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
182 // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ
184 CListCtrl::OnMeasureItem(nIDCtl
, lpMeasureItemStruct
);
187 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
189 //if (m_nRowHeight>0)
191 lpMeasureItemStruct
->itemHeight
= 50;
195 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct
)
198 return CHintListCtrl::OnCreate(lpCreateStruct
);
201 void CGitLogListBase::PreSubclassWindow()
203 SetExtendedStyle(LVS_EX_FULLROWSELECT
| LVS_EX_SUBITEMIMAGES
);
204 // load the icons for the action columns
205 // m_Theme.Open(m_hWnd, L"ListView");
206 m_Theme
.Open(m_hWnd
, L
"Explorer::ListView;ListView");
207 m_Theme
.SetWindowTheme(m_hWnd
, L
"Explorer", NULL
);
208 CHintListCtrl::PreSubclassWindow();
211 void CGitLogListBase::InsertGitColumn()
215 int c
= GetHeaderCtrl()->GetItemCount()-1;
219 temp
.LoadString(IDS_LOG_GRAPH
);
221 if(m_IsRebaseReplaceGraph
)
227 temp
.LoadString(IDS_LOG_GRAPH
);
229 InsertColumn(this->LOGLIST_GRAPH
, temp
);
232 // make the revision column right aligned
234 Column
.mask
= LVCF_FMT
;
235 Column
.fmt
= LVCFMT_RIGHT
;
236 SetColumn(0, &Column
);
239 // g_Git.GetLog(log);
241 if(m_IsIDReplaceAction
)
243 temp
.LoadString(IDS_LOG_ID
);
244 InsertColumn(this->LOGLIST_ACTION
, temp
);
248 temp
.LoadString(IDS_LOG_ACTIONS
);
249 InsertColumn(this->LOGLIST_ACTION
, temp
);
251 temp
.LoadString(IDS_LOG_MESSAGE
);
252 InsertColumn(this->LOGLIST_MESSAGE
, temp
);
254 temp
.LoadString(IDS_LOG_AUTHOR
);
255 InsertColumn(this->LOGLIST_AUTHOR
, temp
);
257 temp
.LoadString(IDS_LOG_DATE
);
258 InsertColumn(this->LOGLIST_DATE
, temp
);
261 if (m_bShowBugtraqColumn
)
263 // temp = m_ProjectProperties.sLabel;
265 temp
.LoadString(IDS_LOG_BUGIDS
);
266 InsertColumn(this->LOGLIST_BUG
, temp
);
271 ResizeAllListCtrlCols();
277 * Resizes all columns in a list control to values in registry.
279 void CGitLogListBase::ResizeAllListCtrlCols()
281 // column max and min widths to allow
282 static const int nMinimumWidth
= 10;
283 static const int nMaximumWidth
= 1000;
284 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
287 int numcols
= pHdrCtrl
->GetItemCount();
288 for (int col
= 0; col
< numcols
; col
++)
290 // get width for this col last time from registry
292 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
293 CRegDWORD
regwidth(regentry
, 0);
297 // no saved value, setup sensible defaults
298 if (col
== this->LOGLIST_MESSAGE
)
300 cx
= LOGLIST_MESSAGE_MIN
;
304 cx
= ICONITEMBORDER
+16*4;
307 if (cx
< nMinimumWidth
)
310 } else if (cx
> nMaximumWidth
)
315 SetColumnWidth(col
, cx
);
322 BOOL
CGitLogListBase::GetShortName(CString ref
, CString
&shortname
,CString prefix
)
324 TRACE(_T("%s %s\r\n"),ref
,prefix
);
325 if(ref
.Left(prefix
.GetLength()) == prefix
)
327 shortname
= ref
.Right(ref
.GetLength()-prefix
.GetLength());
328 if(shortname
.Right(3)==_T("^{}"))
329 shortname
=shortname
.Left(shortname
.GetLength()-3);
335 void CGitLogListBase::FillBackGround(HDC hdc
, int Index
,CRect
&rect
)
339 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
340 rItem
.mask
= LVIF_STATE
;
342 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
345 GitRev
* pLogEntry
= (GitRev
*)m_arShownList
.GetAt(Index
);
349 if (m_Theme
.IsAppThemed() && m_bVista
)
351 int state
= LISS_NORMAL
;
352 if (rItem
.state
& LVIS_SELECTED
)
354 if (::GetFocus() == m_hWnd
)
355 state
|= LISS_SELECTED
;
357 state
|= LISS_SELECTEDNOTFOCUS
;
361 if(pLogEntry
->m_Action
&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
362 brush
= ::CreateSolidBrush(RGB(156,156,156));
363 else if(pLogEntry
->m_Action
&CTGitPath::LOGACTIONS_REBASE_EDIT
)
364 brush
= ::CreateSolidBrush(RGB(200,200,128));
369 ::FillRect(hdc
, &rect
, brush
);
370 ::DeleteObject(brush
);
374 if (m_Theme
.IsBackgroundPartiallyTransparent(LVP_LISTITEM
, state
))
375 m_Theme
.DrawParentBackground(m_hWnd
, hdc
, &rect
);
377 CRect rectDraw
= rect
;
378 if(rItem
.state
& LVIS_SELECTED
)
379 rectDraw
.InflateRect(1,0);
381 rectDraw
.InflateRect(1,1);
383 m_Theme
.DrawBackground(hdc
, LVP_LISTITEM
, state
, rectDraw
, &rect
);
389 if (rItem
.state
& LVIS_SELECTED
)
391 if (::GetFocus() == m_hWnd
)
392 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT
));
394 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE
));
398 //if (pLogEntry->bCopiedSelf)
399 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
401 if(pLogEntry
->m_Action
&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
402 brush
= ::CreateSolidBrush(RGB(156,156,156));
403 else if(pLogEntry
->m_Action
&CTGitPath::LOGACTIONS_REBASE_EDIT
)
404 brush
= ::CreateSolidBrush(RGB(200,200,128));
406 brush
= ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW
));
411 ::FillRect(hdc
, &rect
, brush
);
412 ::DeleteObject(brush
);
417 void CGitLogListBase::DrawTagBranch(HDC hdc
,CRect
&rect
,INT_PTR index
)
419 GitRev
* data
= (GitRev
*)m_arShownList
.GetAt(index
);
422 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
423 rItem
.mask
= LVIF_STATE
;
425 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
428 for(unsigned int i
=0;i
<m_HashMap
[data
->m_CommitHash
].size();i
++)
431 str
=m_HashMap
[data
->m_CommitHash
][i
];
438 //Determine label color
439 if(GetShortName(str
,shortname
,_T("refs/heads/")))
441 if( shortname
== m_CurrentBranch
)
442 colRef
= m_Colors
.GetColor(CColors::CurrentBranch
);
444 colRef
= m_Colors
.GetColor(CColors::LocalBranch
);
446 }else if(GetShortName(str
,shortname
,_T("refs/remotes/")))
448 colRef
= m_Colors
.GetColor(CColors::RemoteBranch
);
450 else if(GetShortName(str
,shortname
,_T("refs/tags/")))
452 colRef
= m_Colors
.GetColor(CColors::Tag
);
454 else if(GetShortName(str
,shortname
,_T("refs/stash")))
456 colRef
= m_Colors
.GetColor(CColors::Stash
);
457 shortname
=_T("stash");
460 //When row selected, ajust label color
461 if (!(m_Theme
.IsAppThemed() && m_bVista
))
462 if (rItem
.state
& LVIS_SELECTED
)
463 colRef
= CColors::MixColors(colRef
, ::GetSysColor(COLOR_HIGHLIGHT
), 150);
465 brush
= ::CreateSolidBrush(colRef
);
468 if(!shortname
.IsEmpty())
471 memset(&size
,0,sizeof(SIZE
));
472 GetTextExtentPoint32(hdc
, shortname
,shortname
.GetLength(),&size
);
474 rt
.SetRect(rt
.left
,rt
.top
,rt
.left
+size
.cx
,rt
.bottom
);
477 //Fill interior of ref label
478 ::FillRect(hdc
, &rt
, brush
);
486 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,100), m_Colors
.Darken(colRef
,100));
487 rectEdge
.DeflateRect(1,1);
488 W_Dc
.Draw3dRect(rectEdge
, m_Colors
.Lighten(colRef
,50), m_Colors
.Darken(colRef
,50));
492 //Draw text inside label
493 if (m_Theme
.IsAppThemed() && m_bVista
)
495 int txtState
= LISS_NORMAL
;
496 if (rItem
.state
& LVIS_SELECTED
)
497 txtState
= LISS_SELECTED
;
499 m_Theme
.DrawText(hdc
, LVP_LISTITEM
, txtState
, shortname
, -1, DT_CENTER
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
503 if (rItem
.state
& LVIS_SELECTED
)
505 COLORREF clrNew
= ::GetSysColor(COLOR_HIGHLIGHTTEXT
);
506 COLORREF clrOld
= ::SetTextColor(hdc
,clrNew
);
507 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,DT_CENTER
| DT_SINGLELINE
| DT_VCENTER
);
508 ::SetTextColor(hdc
,clrOld
);
511 ::DrawText(hdc
,shortname
,shortname
.GetLength(),&rt
,DT_CENTER
| DT_SINGLELINE
| DT_VCENTER
);
516 //::MoveToEx(hdc,rt.left,rt.top,NULL);
517 //::LineTo(hdc,rt.right,rt.top);
518 //::LineTo(hdc,rt.right,rt.bottom);
519 //::LineTo(hdc,rt.left,rt.bottom);
520 //::LineTo(hdc,rt.left,rt.top);
526 ::DeleteObject(brush
);
530 if (m_Theme
.IsAppThemed() && m_bVista
)
532 int txtState
= LISS_NORMAL
;
533 if (rItem
.state
& LVIS_SELECTED
)
534 txtState
= LISS_SELECTED
;
536 m_Theme
.DrawText(hdc
, LVP_LISTITEM
, txtState
, data
->m_Subject
, -1, DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
, 0, &rt
);
540 if (rItem
.state
& LVIS_SELECTED
)
542 COLORREF clrOld
= ::SetTextColor(hdc
,::GetSysColor(COLOR_HIGHLIGHTTEXT
));
543 ::DrawText(hdc
,data
->m_Subject
,data
->m_Subject
.GetLength(),&rt
,DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
544 ::SetTextColor(hdc
,clrOld
);
547 ::DrawText(hdc
,data
->m_Subject
,data
->m_Subject
.GetLength(),&rt
,DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
);
552 static COLORREF
blend(const COLORREF
& col1
, const COLORREF
& col2
, int amount
= 128) {
554 // Returns ((256 - amount)*col1 + amount*col2) / 256;
555 return RGB(((256 - amount
)*GetRValue(col1
) + amount
*GetRValue(col2
) ) / 256,
556 ((256 - amount
)*GetGValue(col1
) + amount
*GetGValue(col2
) ) / 256,
557 ((256 - amount
)*GetBValue(col1
) + amount
*GetBValue(col2
) ) / 256);
560 Gdiplus::Color
GetGdiColor(COLORREF col
)
562 return Gdiplus::Color(GetRValue(col
),GetGValue(col
),GetBValue(col
));
564 void CGitLogListBase::paintGraphLane(HDC hdc
, int laneHeight
,int type
, int x1
, int x2
,
565 const COLORREF
& col
,const COLORREF
& activeColor
, int top
568 int h
= laneHeight
/ 2;
569 int m
= (x1
+ x2
) / 2;
570 int r
= (x2
- x1
) / 3;
573 #define P_CENTER m , h+top
574 #define P_0 x2, h+top
575 #define P_90 m , 0+top
576 #define P_180 x1, h+top
577 #define P_270 m , 2 * h+top
578 #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d
581 #define DELTA_UR_B 2*(x1 - m), 2*h +top
582 #define DELTA_UR_E 0*16, 90*16 +top // -,
584 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
585 #define DELTA_DR_E 270*16, 90*16 +top // -'
587 #define DELTA_UL_B 2*(x2 - m), 2*h +top
588 #define DELTA_UL_E 90*16, 90*16 +top // ,-
590 #define DELTA_DL_B 2*(x2 - m),2*-h +top
591 #define DELTA_DL_E 180*16, 90*16 // '-
593 #define CENTER_UR x1, 2*h, 225
594 #define CENTER_DR x1, 0 , 135
595 #define CENTER_UL x2, 2*h, 315
596 #define CENTER_DL x2, 0 , 45
599 Gdiplus::Graphics
graphics( hdc
);
608 Gdiplus::LinearGradientBrush
gradient(
609 Gdiplus::Point(x1
-2, h
+top
-2),
610 Gdiplus::Point(P_270
),
611 GetGdiColor(activeColor
),GetGdiColor(col
));
614 Gdiplus::Pen
mypen(&gradient
,2);
615 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
617 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
618 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
+h
-1, x2
-x1
+1,laneHeight
+1,270,90);
619 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
626 Gdiplus::Pen
mypen(Gdiplus::Color(0,0,0),2);
629 graphics
.DrawArc(&mypen
,x1
,top
+h
, x2
-x1
,laneHeight
,270,90);
637 Gdiplus::LinearGradientBrush
gradient(
638 Gdiplus::Point(x1
-2, h
+top
-2),
639 Gdiplus::Point(P_90
),
640 GetGdiColor(activeColor
),GetGdiColor(col
));
643 Gdiplus::Pen
mypen(&gradient
,2);
645 graphics
.DrawArc(&mypen
,x1
-(x2
-x1
)/2-1,top
-h
-1, x2
-x1
+1,laneHeight
+1,0,90);
649 QConicalGradient
gradient(CENTER_DR
);
650 gradient
.setColorAt(0.375, activeCol
);
651 gradient
.setColorAt(0.625, col
);
652 myPen
.setBrush(gradient
);
654 p
->drawArc(P_CENTER
, DELTA_DR
);
663 //static QPen myPen(Qt::black, 2); // fast path here
665 pen
.CreatePen(PS_SOLID
,2,col
);
666 //myPen.setColor(col);
667 HPEN oldpen
=(HPEN
)::SelectObject(hdc
,(HPEN
)pen
);
669 Gdiplus::Pen
myPen(GetGdiColor(col
),2);
676 case Lanes::NOT_ACTIVE
:
677 case Lanes::MERGE_FORK
:
678 case Lanes::MERGE_FORK_R
:
679 case Lanes::MERGE_FORK_L
:
684 //DrawLine(hdc,P_90,P_270);
685 graphics
.DrawLine(&myPen
,P_90
,P_270
);
686 //p->drawLine(P_90, P_270);
690 //DrawLine(hdc,P_CENTER,P_270);
691 graphics
.DrawLine(&myPen
,P_CENTER
,P_270
);
692 //p->drawLine(P_CENTER, P_270);
696 case Lanes::BOUNDARY
:
697 case Lanes::BOUNDARY_C
:
698 case Lanes::BOUNDARY_R
:
699 case Lanes::BOUNDARY_L
:
700 //DrawLine(hdc,P_90, P_CENTER);
701 graphics
.DrawLine(&myPen
,P_90
,P_CENTER
);
702 //p->drawLine(P_90, P_CENTER);
708 myPen
.SetColor(GetGdiColor(activeColor
));
712 case Lanes::MERGE_FORK
:
717 case Lanes::CROSS_EMPTY
:
718 case Lanes::BOUNDARY_C
:
719 //DrawLine(hdc,P_180,P_0);
720 graphics
.DrawLine(&myPen
,P_180
,P_0
);
721 //p->drawLine(P_180, P_0);
723 case Lanes::MERGE_FORK_R
:
724 case Lanes::BOUNDARY_R
:
725 //DrawLine(hdc,P_180,P_CENTER);
726 graphics
.DrawLine(&myPen
,P_180
,P_CENTER
);
727 //p->drawLine(P_180, P_CENTER);
729 case Lanes::MERGE_FORK_L
:
732 case Lanes::BOUNDARY_L
:
733 //DrawLine(hdc,P_CENTER,P_0);
734 graphics
.DrawLine(&myPen
,P_CENTER
,P_0
);
735 //p->drawLine(P_CENTER, P_0);
742 brush
.CreateSolidBrush(col
);
743 HBRUSH oldbrush
=(HBRUSH
)::SelectObject(hdc
,(HBRUSH
)brush
);
744 // center symbol, e.g. rect or ellipse
750 //p->setPen(Qt::NoPen);
752 ::Ellipse(hdc
, R_CENTER
);
753 //p->drawEllipse(R_CENTER);
755 case Lanes::MERGE_FORK
:
756 case Lanes::MERGE_FORK_R
:
757 case Lanes::MERGE_FORK_L
:
758 //p->setPen(Qt::NoPen);
760 //p->drawRect(R_CENTER);
761 Rectangle(hdc
,R_CENTER
);
763 case Lanes::UNAPPLIED
:
765 //p->setPen(Qt::NoPen);
766 //p->setBrush(Qt::red);
767 //p->drawRect(m - r, h - 1, d, 2);
768 ::Rectangle(hdc
,m
-r
,h
-1,d
,2);
772 //p->setPen(Qt::NoPen);
773 //p->setBrush(DARK_GREEN);
774 //p->drawRect(m - r, h - 1, d, 2);
775 //p->drawRect(m - 1, h - r, 2, d);
776 ::Rectangle(hdc
,m
-r
,h
-1,d
,2);
777 ::Rectangle(hdc
,m
-1,h
-r
,2,d
);
779 case Lanes::BOUNDARY
:
781 //p->drawEllipse(R_CENTER);
782 ::Ellipse(hdc
, R_CENTER
);
784 case Lanes::BOUNDARY_C
:
785 case Lanes::BOUNDARY_R
:
786 case Lanes::BOUNDARY_L
:
788 //p->drawRect(R_CENTER);
789 ::Rectangle(hdc
,R_CENTER
);
795 ::SelectObject(hdc
,oldpen
);
796 ::SelectObject(hdc
,oldbrush
);
805 void CGitLogListBase::DrawGraph(HDC hdc
,CRect
&rect
,INT_PTR index
)
809 GitRev
* data
= (GitRev
*)m_arShownList
.GetAt(index
);
810 if(data
->m_CommitHash
.IsEmpty())
815 SecureZeroMemory(&rItem
, sizeof(LVITEM
));
816 rItem
.mask
= LVIF_STATE
;
818 rItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
822 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
826 if (data
->m_Lanes
.size() == 0)
827 m_logEntries
.setLane(data
->m_CommitHash
.ToString());
829 std::vector
<int>& lanes
=data
->m_Lanes
;
830 UINT laneNum
= lanes
.size();
832 for (UINT i
= 0; i
< laneNum
; i
++)
833 if (Lanes::isMerge(lanes
[i
])) {
839 int maxWidth
= rect
.Width();
840 int lw
= 3 * rect
.Height() / 4; //laneWidth()
842 COLORREF activeColor
= m_LineColors
[activeLane
% Lanes::COLORS_NUM
];
843 //if (opt.state & QStyle::State_Selected)
844 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
847 for (unsigned int i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++)
854 if (ln
== Lanes::EMPTY
)
857 COLORREF color
= i
== activeLane
? activeColor
: m_LineColors
[i
% Lanes::COLORS_NUM
];
858 paintGraphLane(hdc
, rect
.Height(),ln
, x1
+rect
.left
, x2
+rect
.left
, color
,activeColor
, rect
.top
);
862 for (UINT i
= 0; i
< laneNum
&& x2
< maxWidth
; i
++) {
868 if (ln
== Lanes::EMPTY
)
871 UINT col
= ( Lanes:: isHead(ln
) ||Lanes:: isTail(ln
) || Lanes::isJoin(ln
)
872 || ln
==Lanes:: CROSS_EMPTY
) ? activeLane
: i
;
874 if (ln
== Lanes::CROSS
) {
875 paintGraphLane(hdc
, rect
.Height(),Lanes::NOT_ACTIVE
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
876 paintGraphLane(hdc
, rect
.Height(),Lanes::CROSS
, x1
, x2
, m_LineColors
[activeLane
% Lanes::COLORS_NUM
],rect
.top
);
878 paintGraphLane(hdc
, rect
.Height(),ln
, x1
, x2
, m_LineColors
[col
% Lanes::COLORS_NUM
],rect
.top
);
884 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
887 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
888 // Take the default processing unless we set this to something else below.
889 *pResult
= CDRF_DODEFAULT
;
891 if (m_bNoDispUpdates
)
896 switch (pLVCD
->nmcd
.dwDrawStage
)
900 *pResult
= CDRF_NOTIFYITEMDRAW
;
904 case CDDS_ITEMPREPAINT
:
906 // This is the prepaint stage for an item. Here's where we set the
907 // item's text color.
909 // Tell Windows to send draw notifications for each subitem.
910 *pResult
= CDRF_NOTIFYSUBITEMDRAW
;
912 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
914 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
916 GitRev
* data
= (GitRev
*)m_arShownList
.GetAt(pLVCD
->nmcd
.dwItemSpec
);
920 if (data
->bCopiedSelf
)
922 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
923 if (!m_Theme
.IsAppm_Themed() || !m_bVista
|| ((pLVCD
->nmcd
.uItemState
& CDIS_HOT
)==0))
924 pLVCD
->clrTextBk
= GetSysColor(COLOR_MENU
);
928 crText
= m_Colors
.GetColor(CColors::Modified
);
930 if (data
->m_Action
& (CTGitPath::LOGACTIONS_REBASE_DONE
| CTGitPath::LOGACTIONS_REBASE_SKIP
) )
931 crText
= RGB(128,128,128);
933 if(data
->m_Action
&CTGitPath::LOGACTIONS_REBASE_SQUASH
)
934 pLVCD
->clrTextBk
= RGB(156,156,156);
935 else if(data
->m_Action
&CTGitPath::LOGACTIONS_REBASE_EDIT
)
936 pLVCD
->clrTextBk
= RGB(200,200,128);
938 pLVCD
->clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
940 if(data
->m_Action
&CTGitPath::LOGACTIONS_REBASE_CURRENT
)
942 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
943 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
946 if(data
->m_CommitHash
== m_HeadHash
)
948 SelectObject(pLVCD
->nmcd
.hdc
, m_boldFont
);
949 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
952 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
953 // crText = GetSysColor(COLOR_GRAYTEXT);
955 if (data
->m_CommitHash
.IsEmpty())
957 //crText = GetSysColor(RGB(200,200,0));
958 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
959 // We changed the font, so we're returning CDRF_NEWFONT. This
960 // tells the control to recalculate the extent of the text.
961 *pResult
= CDRF_NOTIFYSUBITEMDRAW
| CDRF_NEWFONT
;
965 if (m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
967 if (m_bStrictStopped
)
968 crText
= GetSysColor(COLOR_GRAYTEXT
);
970 // Store the color back in the NMLVCUSTOMDRAW struct.
971 pLVCD
->clrText
= crText
;
975 case CDDS_ITEMPREPAINT
|CDDS_ITEM
|CDDS_SUBITEM
:
977 if ((m_bStrictStopped
)&&(m_arShownList
.GetCount() == (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
))
979 pLVCD
->nmcd
.uItemState
&= ~(CDIS_SELECTED
|CDIS_FOCUS
);
982 if (pLVCD
->iSubItem
== LOGLIST_GRAPH
)
984 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
&& (!this->m_IsRebaseReplaceGraph
) )
987 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
988 if(pLVCD
->iSubItem
== 0)
991 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
+1, LVIR_BOUNDS
, second
);
992 rect
.right
=second
.left
;
995 TRACE(_T("A Graphic left %d right %d\r\n"),rect
.left
,rect
.right
);
996 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
998 GitRev
* data
= (GitRev
*)m_arShownList
.GetAt(pLVCD
->nmcd
.dwItemSpec
);
999 if( !data
->m_CommitHash
.IsEmpty())
1000 DrawGraph(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1002 *pResult
= CDRF_SKIPDEFAULT
;
1008 if (pLVCD
->iSubItem
== LOGLIST_MESSAGE
)
1010 if (m_arShownList
.GetCount() > (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1012 GitRev
* data
= (GitRev
*)m_arShownList
.GetAt(pLVCD
->nmcd
.dwItemSpec
);
1013 //if(!data->m_IsFull)
1015 //if(data->SafeFetchFullInfo(&g_Git))
1016 // this->Invalidate();
1017 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1020 if(m_HashMap
[data
->m_CommitHash
].size()!=0)
1024 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1026 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1027 DrawTagBranch(pLVCD
->nmcd
.hdc
,rect
,pLVCD
->nmcd
.dwItemSpec
);
1029 *pResult
= CDRF_SKIPDEFAULT
;
1037 if (pLVCD
->iSubItem
== 1)
1039 if(this->m_IsIDReplaceAction
)
1041 *pResult
= CDRF_DODEFAULT
;
1044 *pResult
= CDRF_DODEFAULT
;
1046 if (m_arShownList
.GetCount() <= (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
)
1050 int iconwidth
= ::GetSystemMetrics(SM_CXSMICON
);
1051 int iconheight
= ::GetSystemMetrics(SM_CYSMICON
);
1053 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(pLVCD
->nmcd
.dwItemSpec
));
1055 GetSubItemRect(pLVCD
->nmcd
.dwItemSpec
, pLVCD
->iSubItem
, LVIR_BOUNDS
, rect
);
1056 TRACE(_T("Action left %d right %d\r\n"),rect
.left
,rect
.right
);
1057 // Get the selected state of the
1058 // item being drawn.
1060 // Fill the background
1061 FillBackGround(pLVCD
->nmcd
.hdc
, (INT_PTR
)pLVCD
->nmcd
.dwItemSpec
,rect
);
1063 // Draw the icon(s) into the compatible DC
1064 if (pLogEntry
->m_Action
& CTGitPath::LOGACTIONS_MODIFIED
)
1065 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+ ICONITEMBORDER
, rect
.top
, m_hModifiedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1068 if (pLogEntry
->m_Action
& (CTGitPath::LOGACTIONS_ADDED
|CTGitPath::LOGACTIONS_COPY
) )
1069 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hAddedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1072 if (pLogEntry
->m_Action
& CTGitPath::LOGACTIONS_DELETED
)
1073 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hDeletedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1076 if (pLogEntry
->m_Action
& CTGitPath::LOGACTIONS_REPLACED
)
1077 ::DrawIconEx(pLVCD
->nmcd
.hdc
, rect
.left
+nIcons
*iconwidth
+ ICONITEMBORDER
, rect
.top
, m_hReplacedIcon
, iconwidth
, iconheight
, 0, NULL
, DI_NORMAL
);
1079 *pResult
= CDRF_SKIPDEFAULT
;
1085 *pResult
= CDRF_DODEFAULT
;
1089 // CGitLogListBase message handlers
1091 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1093 NMLVDISPINFO
*pDispInfo
= reinterpret_cast<NMLVDISPINFO
*>(pNMHDR
);
1095 // Create a pointer to the item
1096 LV_ITEM
* pItem
= &(pDispInfo
)->item
;
1098 // Do the list need text information?
1099 if (!(pItem
->mask
& LVIF_TEXT
))
1102 // By default, clear text buffer.
1103 lstrcpyn(pItem
->pszText
, _T(""), pItem
->cchTextMax
);
1105 bool bOutOfRange
= pItem
->iItem
>= ShownCountWithStopped();
1108 if (m_bNoDispUpdates
|| bOutOfRange
)
1111 // Which item number?
1112 int itemid
= pItem
->iItem
;
1113 GitRev
* pLogEntry
= NULL
;
1114 if (itemid
< m_arShownList
.GetCount())
1115 pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(pItem
->iItem
));
1120 temp
.Format(_T("%d"),pItem
->iItem
+1);
1124 temp
.Format(_T("%d"),m_arShownList
.GetCount()-pItem
->iItem
);
1128 switch (pItem
->iSubItem
)
1130 case this->LOGLIST_GRAPH
: //Graphic
1133 if(this->m_IsRebaseReplaceGraph
)
1136 path
.m_Action
=pLogEntry
->m_Action
&CTGitPath::LOGACTIONS_REBASE_MODE_MASK
;
1138 lstrcpyn(pItem
->pszText
,path
.GetActionName(), pItem
->cchTextMax
);
1142 case this->LOGLIST_ACTION
: //action -- no text in the column
1143 if(this->m_IsIDReplaceAction
)
1144 lstrcpyn(pItem
->pszText
, temp
, pItem
->cchTextMax
);
1146 case this->LOGLIST_MESSAGE
: //Message
1148 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->m_Subject
, pItem
->cchTextMax
);
1150 case this->LOGLIST_AUTHOR
: //Author
1152 lstrcpyn(pItem
->pszText
, (LPCTSTR
)pLogEntry
->m_AuthorName
, pItem
->cchTextMax
);
1154 case this->LOGLIST_DATE
: //Date
1155 if (!pLogEntry
&& pLogEntry
->m_CommitHash
.IsEmpty())
1156 lstrcpyn(pItem
->pszText
,
1157 CAppUtils::FormatDateAndTime( pLogEntry
->m_AuthorDate
, m_DateFormat
, true, m_bRelativeTimes
),
1169 void CGitLogListBase::OnContextMenu(CWnd
* pWnd
, CPoint point
)
1172 int selIndex
= GetSelectionMark();
1174 return; // nothing selected, nothing to do with a context menu
1176 // if the user selected the info text telling about not all revisions shown due to
1177 // the "stop on copy/rename" option, we also don't show the context menu
1178 if ((m_bStrictStopped
)&&(selIndex
== m_arShownList
.GetCount()))
1181 // if the context menu is invoked through the keyboard, we have to use
1182 // a calculated position on where to anchor the menu on
1183 if ((point
.x
== -1) && (point
.y
== -1))
1186 GetItemRect(selIndex
, &rect
, LVIR_LABEL
);
1187 ClientToScreen(&rect
);
1188 point
= rect
.CenterPoint();
1190 m_nSearchIndex
= selIndex
;
1191 m_bCancelled
= FALSE
;
1193 // calculate some information the context menu commands can use
1194 // CString pathURL = GetURLFromPath(m_path);
1196 POSITION pos
= GetFirstSelectedItemPosition();
1197 int indexNext
= GetNextSelectedItem(pos
);
1201 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
1203 GitRev revSelected
= pSelLogEntry
->Rev
;
1204 GitRev revPrevious
= git_revnum_t(revSelected
)-1;
1205 if ((pSelLogEntry
->pArChangedPaths
)&&(pSelLogEntry
->pArChangedPaths
->GetCount() <= 2))
1207 for (int i
=0; i
<pSelLogEntry
->pArChangedPaths
->GetCount(); ++i
)
1209 LogChangedPath
* changedpath
= (LogChangedPath
*)pSelLogEntry
->pArChangedPaths
->GetAt(i
);
1210 if (changedpath
->lCopyFromRev
)
1211 revPrevious
= changedpath
->lCopyFromRev
;
1214 GitRev revSelected2
;
1217 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.GetAt(GetNextSelectedItem(pos
)));
1218 revSelected2
= pLogEntry
->Rev
;
1220 bool bAllFromTheSameAuthor
= true;
1221 CString firstAuthor
;
1222 CLogDataVector selEntries
;
1223 GitRev revLowest
, revHighest
;
1224 GitRevRangeArray revisionRanges
;
1226 POSITION pos
= GetFirstSelectedItemPosition();
1227 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.GetAt(GetNextSelectedItem(pos
)));
1228 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1229 selEntries
.push_back(pLogEntry
);
1230 firstAuthor
= pLogEntry
->sAuthor
;
1231 revLowest
= pLogEntry
->Rev
;
1232 revHighest
= pLogEntry
->Rev
;
1235 pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.GetAt(GetNextSelectedItem(pos
)));
1236 revisionRanges
.AddRevision(pLogEntry
->Rev
);
1237 selEntries
.push_back(pLogEntry
);
1238 if (firstAuthor
.Compare(pLogEntry
->sAuthor
))
1239 bAllFromTheSameAuthor
= false;
1240 revLowest
= (git_revnum_t(pLogEntry
->Rev
) > git_revnum_t(revLowest
) ? revLowest
: pLogEntry
->Rev
);
1241 revHighest
= (git_revnum_t(pLogEntry
->Rev
) < git_revnum_t(revHighest
) ? revHighest
: pLogEntry
->Rev
);
1247 int FirstSelect
=-1, LastSelect
=-1;
1248 pos
= GetFirstSelectedItemPosition();
1249 FirstSelect
= GetNextSelectedItem(pos
);
1252 LastSelect
= GetNextSelectedItem(pos
);
1254 //entry is selected, now show the popup menu
1257 if (popup
.CreatePopupMenu())
1260 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_PICK
))
1261 popup
.AppendMenuIcon(ID_REBASE_PICK
, IDS_REBASE_PICK
, IDI_PICK
);
1263 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SQUASH
))
1264 popup
.AppendMenuIcon(ID_REBASE_SQUASH
,IDS_REBASE_SQUASH
, IDI_SQUASH
);
1266 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_EDIT
))
1267 popup
.AppendMenuIcon(ID_REBASE_EDIT
, IDS_REBASE_EDIT
, IDI_EDIT
);
1269 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_SKIP
))
1270 popup
.AppendMenuIcon(ID_REBASE_SKIP
, IDS_REBASE_SKIP
, IDI_SKIP
);
1272 if(m_ContextMenuMask
&(GetContextMenuBit(ID_REBASE_SKIP
)|GetContextMenuBit(ID_REBASE_EDIT
)|
1273 GetContextMenuBit(ID_REBASE_SQUASH
)|GetContextMenuBit(ID_REBASE_PICK
)))
1274 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1276 if (GetSelectedCount() == 1)
1280 if( !pSelLogEntry
->m_CommitHash
.IsEmpty())
1282 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARE
))
1283 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
1285 // TortoiseMerge could be improved to take a /blame switch
1286 // and then not 'cat' the files from a unified diff but
1288 // But until that's implemented, the context menu entry for
1289 // this feature is commented out.
1290 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1293 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMMIT
))
1294 popup
.AppendMenuIcon(ID_COMMIT
, IDS_LOG_POPUP_COMMIT
, IDI_COMMIT
);
1296 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF1
))
1297 popup
.AppendMenuIcon(ID_GNUDIFF1
, IDS_LOG_POPUP_GNUDIFF_CH
, IDI_DIFF
);
1299 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPAREWITHPREVIOUS
))
1300 popup
.AppendMenuIcon(ID_COMPAREWITHPREVIOUS
, IDS_LOG_POPUP_COMPAREWITHPREVIOUS
, IDI_DIFF
);
1301 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1302 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1305 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1307 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1309 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1311 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1313 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1314 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1316 // popup.AppendMenu(MF_SEPARATOR, NULL);
1320 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1322 // popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1324 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);
1327 format
.LoadString(IDS_RESET_TO_THIS_FORMAT
);
1328 str
.Format(format
,g_Git
.GetCurrentBranch());
1330 if(!pSelLogEntry
->m_CommitHash
.IsEmpty())
1332 if(m_ContextMenuMask
&GetContextMenuBit(ID_RESET
))
1333 popup
.AppendMenuIcon(ID_RESET
,str
,IDI_REVERT
);
1335 if(m_ContextMenuMask
&GetContextMenuBit(ID_SWITCHTOREV
))
1336 popup
.AppendMenuIcon(ID_SWITCHTOREV
, IDS_SWITCH_TO_THIS
, IDI_SWITCH
);
1338 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_BRANCH
))
1339 popup
.AppendMenuIcon(ID_CREATE_BRANCH
, IDS_CREATE_BRANCH_AT_THIS
, IDI_COPY
);
1341 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_TAG
))
1342 popup
.AppendMenuIcon(ID_CREATE_TAG
,IDS_CREATE_TAG_AT_THIS
, IDI_COPY
);
1344 format
.LoadString(IDS_REBASE_THIS_FORMAT
);
1345 str
.Format(format
,g_Git
.GetCurrentBranch());
1347 if(pSelLogEntry
->m_CommitHash
!= m_HeadHash
)
1348 if(m_ContextMenuMask
&GetContextMenuBit(ID_REBASE_TO_VERSION
))
1349 popup
.AppendMenuIcon(ID_REBASE_TO_VERSION
, str
, IDI_REBASE
);
1351 if(m_ContextMenuMask
&GetContextMenuBit(ID_EXPORT
))
1352 popup
.AppendMenuIcon(ID_EXPORT
,IDS_EXPORT_TO_THIS
, IDI_EXPORT
);
1355 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1360 if(!pSelLogEntry
->m_Ref
.IsEmpty() && GetSelectedCount() == 1)
1362 popup
.AppendMenuIcon(ID_REFLOG_DEL
, IDS_REFLOG_DEL
, IDI_DELETE
);
1363 popup
.AppendMenuIcon(ID_STASH_APPLY
,IDS_MENUSTASHAPPLY
, IDI_RELOCATE
);
1364 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1367 if (GetSelectedCount() >= 2)
1369 bool bAddSeparator
= false;
1370 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1372 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMPARETWO
))
1373 popup
.AppendMenuIcon(ID_COMPARETWO
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
1376 if (GetSelectedCount() == 2)
1378 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1379 if(m_ContextMenuMask
&GetContextMenuBit(ID_GNUDIFF2
))
1380 popup
.AppendMenuIcon(ID_GNUDIFF2
, IDS_LOG_POPUP_GNUDIFF
, IDI_DIFF
);
1381 bAddSeparator
= true;
1386 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1388 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1389 bAddSeparator
= true;
1392 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1395 if ( GetSelectedCount() >0 && (!pSelLogEntry
->m_CommitHash
.IsEmpty()))
1397 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1399 if(m_ContextMenuMask
&GetContextMenuBit(ID_COMBINE_COMMIT
))
1403 headindex
= this->GetHeadIndex();
1406 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
1407 CString hash
=g_Git
.GetHash(head
);
1409 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
1410 if(pLastEntry
->m_CommitHash
== hash
)
1411 popup
.AppendMenuIcon(ID_COMBINE_COMMIT
,IDS_COMBINE_TO_ONE
,IDI_COMBINE
);
1415 if(m_ContextMenuMask
&GetContextMenuBit(ID_CHERRY_PICK
))
1416 popup
.AppendMenuIcon(ID_CHERRY_PICK
, IDS_CHERRY_PICK_VERSION
, IDI_EXPORT
);
1418 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1419 if(m_ContextMenuMask
&GetContextMenuBit(ID_CREATE_PATCH
))
1420 popup
.AppendMenuIcon(ID_CREATE_PATCH
, IDS_CREATE_PATCH
, IDI_PATCH
);
1422 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
1428 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1430 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1432 // if (GetSelectedCount() == 1)
1434 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1435 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1436 // popup.AppendMenu(MF_SEPARATOR, NULL);
1441 if (GetSelectedCount() == 1)
1443 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYHASH
))
1444 popup
.AppendMenuIcon(ID_COPYHASH
, IDS_COPY_COMMIT_HASH
);
1446 if (GetSelectedCount() != 0)
1448 if(m_ContextMenuMask
&GetContextMenuBit(ID_COPYCLIPBOARD
))
1449 popup
.AppendMenuIcon(ID_COPYCLIPBOARD
, IDS_LOG_POPUP_COPYTOCLIPBOARD
);
1452 if(m_ContextMenuMask
&GetContextMenuBit(ID_FINDENTRY
))
1453 popup
.AppendMenuIcon(ID_FINDENTRY
, IDS_LOG_POPUP_FIND
);
1456 if (GetSelectedCount() == 1)
1458 if(m_ContextMenuMask
&GetContextMenuBit(ID_DELETE
))
1460 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) != m_HashMap
.end() )
1463 str
.LoadString(IDS_DELETE_BRANCHTAG
);
1464 if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() == 1 )
1467 str
+=m_HashMap
[pSelLogEntry
->m_CommitHash
].at(0);
1468 popup
.AppendMenuIcon(ID_DELETE
,str
+_T("..."),IDI_DELETE
);
1470 else if( m_HashMap
[pSelLogEntry
->m_CommitHash
].size() > 1 )
1473 submenu
.CreatePopupMenu();
1474 for(int i
=0;i
<m_HashMap
[pSelLogEntry
->m_CommitHash
].size();i
++)
1476 submenu
.AppendMenuIcon(ID_DELETE
+(i
<<16),m_HashMap
[pSelLogEntry
->m_CommitHash
][i
]+_T("..."));
1479 popup
.AppendMenu(MF_BYPOSITION
|MF_POPUP
|MF_STRING
,(UINT
) submenu
.m_hMenu
,str
);
1487 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
1488 // DialogEnableWindow(IDOK, FALSE);
1489 // SetPromptApp(&theApp);
1491 this->ContextMenuAction(cmd
, FirstSelect
, LastSelect
);
1493 // EnableOKButton();
1494 } // if (popup.CreatePopupMenu())
1498 bool CGitLogListBase::IsSelectionContinuous()
1500 if ( GetSelectedCount()==1 )
1502 // if only one revision is selected, the selection is of course
1507 POSITION pos
= GetFirstSelectedItemPosition();
1508 bool bContinuous
= (m_arShownList
.GetCount() == (INT_PTR
)m_logEntries
.size());
1511 int itemindex
= GetNextSelectedItem(pos
);
1514 int nextindex
= GetNextSelectedItem(pos
);
1515 if (nextindex
- itemindex
> 1)
1517 bContinuous
= false;
1520 itemindex
= nextindex
;
1526 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly
)
1530 POSITION pos
= GetFirstSelectedItemPosition();
1534 sRev
.LoadString(IDS_LOG_REVISION
);
1536 sAuthor
.LoadString(IDS_LOG_AUTHOR
);
1538 sDate
.LoadString(IDS_LOG_DATE
);
1540 sMessage
.LoadString(IDS_LOG_MESSAGE
);
1543 CString sLogCopyText
;
1545 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(GetNextSelectedItem(pos
)));
1549 //pLogEntry->m_Files
1550 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1552 for (int cpPathIndex
= 0; cpPathIndex
<pLogEntry
->m_Files
.GetCount(); ++cpPathIndex
)
1554 sPaths
+= ((CTGitPath
&)pLogEntry
->m_Files
[cpPathIndex
]).GetActionName() + _T(" : ") + pLogEntry
->m_Files
[cpPathIndex
].GetGitPathString();
1555 sPaths
+= _T("\r\n");
1558 sLogCopyText
.Format(_T("%s: %s\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
1559 (LPCTSTR
)sRev
, pLogEntry
->m_CommitHash
,
1560 (LPCTSTR
)sAuthor
, (LPCTSTR
)pLogEntry
->m_AuthorName
,
1562 (LPCTSTR
)CAppUtils::FormatDateAndTime( pLogEntry
->m_AuthorDate
, m_DateFormat
, true, m_bRelativeTimes
),
1563 (LPCTSTR
)sMessage
, pLogEntry
->m_Subject
+_T("\r\n")+pLogEntry
->m_Body
,
1565 sClipdata
+= sLogCopyText
;
1568 sClipdata
+= pLogEntry
->m_CommitHash
;
1573 CStringUtils::WriteAsciiStringToClipboard(sClipdata
, GetSafeHwnd());
1578 void CGitLogListBase::DiffSelectedRevWithPrevious()
1580 if (m_bThreadRunning
)
1583 int FirstSelect
=-1, LastSelect
=-1;
1584 POSITION pos
= GetFirstSelectedItemPosition();
1585 FirstSelect
= GetNextSelectedItem(pos
);
1588 LastSelect
= GetNextSelectedItem(pos
);
1591 ContextMenuAction(ID_COMPAREWITHPREVIOUS
,FirstSelect
,LastSelect
);
1594 UpdateLogInfoLabel();
1595 int selIndex
= m_LogList
.GetSelectionMark();
1598 int selCount
= m_LogList
.GetSelectedCount();
1602 // Find selected entry in the log list
1603 POSITION pos
= m_LogList
.GetFirstSelectedItemPosition();
1604 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.GetAt(m_LogList
.GetNextSelectedItem(pos
)));
1605 long rev1
= pLogEntry
->Rev
;
1607 CTGitPath path
= m_path
;
1609 // See how many files under the relative root were changed in selected revision
1611 LogChangedPath
* changed
= NULL
;
1612 for (INT_PTR c
= 0; c
< pLogEntry
->pArChangedPaths
->GetCount(); ++c
)
1614 LogChangedPath
* cpath
= pLogEntry
->pArChangedPaths
->GetAt(c
);
1615 if (cpath
&& cpath
-> sPath
.Left(m_sRelativeRoot
.GetLength()).Compare(m_sRelativeRoot
)==0)
1622 if (m_path
.IsDirectory() && nChanged
== 1)
1624 // We're looking at the log for a directory and only one file under dir was changed in the revision
1625 // Do diff on that file instead of whole directory
1626 path
.AppendPathString(changed
->sPath
.Mid(m_sRelativeRoot
.GetLength()));
1629 m_bCancelled
= FALSE
;
1630 DialogEnableWindow(IDOK
, FALSE
);
1631 SetPromptApp(&theApp
);
1632 theApp
.DoWaitCursor(1);
1636 GitDiff
diff(this, m_hWnd
, true);
1637 diff
.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1638 diff
.SetHEADPeg(m_LogRevision
);
1639 diff
.ShowCompare(path
, rev2
, path
, rev1
);
1643 CAppUtils::StartShowCompare(m_hWnd
, path
, rev2
, path
, rev1
, GitRev(), m_LogRevision
, !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000));
1646 theApp
.DoWaitCursor(-1);
1651 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
1653 LPNMLVFINDITEM pFindInfo
= reinterpret_cast<LPNMLVFINDITEM
>(pNMHDR
);
1656 if (pFindInfo
->lvfi
.flags
& LVFI_PARAM
)
1658 if ((pFindInfo
->iStart
< 0)||(pFindInfo
->iStart
>= m_arShownList
.GetCount()))
1660 if (pFindInfo
->lvfi
.psz
== 0)
1663 CString sCmp
= pFindInfo
->lvfi
.psz
;
1665 for (int i
=pFindInfo
->iStart
; i
<m_arShownList
.GetCount(); ++i
)
1667 GitRev
* pLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
1668 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
1669 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
1671 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
1679 if (sCmp
.Compare(sRev
)==0)
1686 if (pFindInfo
->lvfi
.flags
& LVFI_WRAP
)
1688 for (int i
=0; i
<pFindInfo
->iStart
; ++i
)
1690 PLOGENTRYDATA pLogEntry
= reinterpret_cast<PLOGENTRYDATA
>(m_arShownList
.GetAt(i
));
1691 sRev
.Format(_T("%ld"), pLogEntry
->Rev
);
1692 if (pFindInfo
->lvfi
.flags
& LVFI_PARTIAL
)
1694 if (sCmp
.Compare(sRev
.Left(sCmp
.GetLength()))==0)
1702 if (sCmp
.Compare(sRev
)==0)
1714 int CGitLogListBase::FillGitLog(CTGitPath
*path
,int info
,CString
*from
,CString
*to
)
1718 this->m_logEntries
.ClearAll();
1719 this->m_logEntries
.ParserFromLog(path
,-1,info
,from
,to
);
1721 //this->m_logEntries.ParserFromLog();
1722 SetItemCountEx(this->m_logEntries
.size());
1724 this->m_arShownList
.RemoveAll();
1726 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
1730 m_logEntries
.GetGitRevAt(m_logEntries
.size()-i
-1).m_IsFull
=TRUE
;
1731 this->m_arShownList
.Add(&m_logEntries
[m_logEntries
.size()-i
-1]);
1735 m_logEntries
.GetGitRevAt(i
).m_IsFull
=TRUE
;
1736 this->m_arShownList
.Add(&m_logEntries
[i
]);
1746 int CGitLogListBase::FillGitShortLog()
1750 this->m_logEntries
.ClearAll();
1752 m_LogCache
.FetchCacheIndex(g_Git
.m_CurrentDir
);
1755 if(this->m_Path
.IsEmpty())
1762 mask
= CGit::LOG_INFO_ONLY_HASH
| CGit::LOG_INFO_BOUNDARY
;
1763 // if(this->m_bAllBranch)
1767 this->m_logEntries
.insert(m_logEntries
.begin(),this->m_wcRev
.m_CommitHash
);
1769 this->m_logEntries
.FetchShortLog(path
,m_StartRef
,-1,mask
,m_bShowWC
?1:0);
1771 //this->m_logEntries.ParserFromLog();
1772 if(IsInWorkingThread())
1774 PostMessage(LVM_SETITEMCOUNT
, (WPARAM
) this->m_logEntries
.size(),(LPARAM
) LVSICF_NOINVALIDATEALL
);
1778 SetItemCountEx(this->m_logEntries
.size());
1781 this->m_arShownList
.RemoveAll();
1783 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
1785 if(i
>0 || !m_logEntries
.GetGitRevAt(i
).m_CommitHash
.IsEmpty())
1786 m_logEntries
.GetGitRevAt(i
).m_Subject
=_T("parser...");
1788 if(this->m_IsOldFirst
)
1790 this->m_arShownList
.Add(&m_logEntries
[m_logEntries
.size()-1-i
]);
1794 this->m_arShownList
.Add(&m_logEntries
[i
]);
1800 BOOL
CGitLogListBase::PreTranslateMessage(MSG
* pMsg
)
1802 // Skip Ctrl-C when copying text out of the log message or search filter
1803 BOOL bSkipAccelerator
= ( pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW
) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT
) ) && GetKeyState(VK_CONTROL
)&0x8000 );
1804 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
=='\r')
1806 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1808 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1810 DiffSelectedRevWithPrevious();
1815 if (GetFocus()==GetDlgItem(IDC_LOGMSG
))
1824 if (m_hAccel
&& !bSkipAccelerator
)
1826 int ret
= TranslateAccelerator(m_hWnd
, m_hAccel
, pMsg
);
1832 //m_tooltips.RelayEvent(pMsg);
1833 return __super::PreTranslateMessage(pMsg
);
1836 void CGitLogListBase::OnNMDblclkLoglist(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
1838 // a double click on an entry in the revision list has happened
1841 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE
))
1842 DiffSelectedRevWithPrevious();
1845 int CGitLogListBase::FetchLogAsync(void * data
)
1848 m_bExitThread
=FALSE
;
1849 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1850 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
1851 m_LoadingThread
= AfxBeginThread(LogThreadEntry
, this);
1852 if (m_LoadingThread
==NULL
)
1854 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1855 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
1856 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1862 //this is the thread function which calls the subversion function
1863 UINT
CGitLogListBase::LogThreadEntry(LPVOID pVoid
)
1865 return ((CGitLogListBase
*)pVoid
)->LogThread();
1868 void CGitLogListBase::GetTimeRange(CTime
&oldest
, CTime
&latest
)
1871 oldest
=CTime::GetCurrentTime();
1872 latest
=CTime(1971,1,2,0,0,0);
1873 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
1875 if(m_logEntries
.GetGitRevAt(i
).m_AuthorDate
.GetTime() < oldest
.GetTime())
1876 oldest
= m_logEntries
.GetGitRevAt(i
).m_AuthorDate
.GetTime();
1878 if(m_logEntries
.GetGitRevAt(i
).m_AuthorDate
.GetTime() > latest
.GetTime())
1879 latest
= m_logEntries
.GetGitRevAt(i
).m_AuthorDate
.GetTime();
1884 //Helper class for FetchFullLogInfo()
1885 class CGitCall_FetchFullLogInfo
: public CGitCall
1888 CGitCall_FetchFullLogInfo(CGitLogListBase
* ploglist
):m_ploglist(ploglist
),m_CollectedCount(0){}
1889 virtual bool OnOutputData(const BYTE
* data
, size_t size
)
1892 return m_ploglist
->m_bExitThread
;
1893 //Add received data to byte collector
1894 m_ByteCollector
.append(data
,size
);
1896 //Find loginfo endmarker
1897 static const BYTE dataToFind
[]={0,0,'#','<'};
1898 int found
=m_ByteCollector
.findData(dataToFind
,4);
1900 return m_ploglist
->m_bExitThread
;//Not found
1901 found
+=2;//Position after loginfo end-marker
1903 //Prepare data for OnLogInfo and call it
1904 BYTE_VECTOR logInfo
;
1905 logInfo
.append(&*m_ByteCollector
.begin(),found
);
1908 //Remove loginfo from bytecollector
1909 m_ByteCollector
.erase(m_ByteCollector
.begin(),m_ByteCollector
.begin()+found
);
1911 return m_ploglist
->m_bExitThread
;
1913 virtual void OnEnd()
1915 //Rest should be a complete log line.
1916 if(!m_ByteCollector
.empty())
1917 OnLogInfo(m_ByteCollector
);
1921 void OnLogInfo(BYTE_VECTOR
& logInfo
)
1924 fullRev
.ParserFromLog(logInfo
);
1925 MAP_HASH_REV::iterator itRev
=m_ploglist
->m_logEntries
.m_HashMap
.find(fullRev
.m_CommitHash
);
1926 if(itRev
==m_ploglist
->m_logEntries
.m_HashMap
.end())
1928 //Should not occur, only when Git-tree updated in the mean time. (Race condition)
1932 int rev
=itRev
->second
;
1933 GitRev
* revInVector
=&m_ploglist
->m_logEntries
.GetGitRevAt(rev
);
1936 if(revInVector
->m_IsFull
)
1939 if(!m_ploglist
->m_LogCache
.GetCacheData(m_ploglist
->m_logEntries
.GetGitRevAt(rev
)))
1942 InterlockedExchange(&m_ploglist
->m_logEntries
.GetGitRevAt(rev
).m_IsUpdateing
,FALSE
);
1943 InterlockedExchange(&m_ploglist
->m_logEntries
.GetGitRevAt(rev
).m_IsFull
,TRUE
);
1944 ::PostMessage(m_ploglist
->m_hWnd
,MSG_LOADED
,(WPARAM
)rev
,0);
1948 // fullRev.m_IsUpdateing=TRUE;
1949 // fullRev.m_IsFull=TRUE;
1952 if(InterlockedExchange(&revInVector
->m_IsUpdateing
,TRUE
))
1953 return;//Cannot update this row now. Ignore.
1954 TCHAR oldmark
=revInVector
->m_Mark
;
1955 GIT_REV_LIST oldlist
=revInVector
->m_ParentHash
;
1956 // CString oldhash=m_CommitHash;
1958 //Parse new rev info
1959 revInVector
->ParserFromLog(logInfo
);
1962 revInVector
->m_Mark
=oldmark
; //parser full log will cause old mark overwrited.
1963 //So we need keep old bound mark.
1964 revInVector
->m_ParentHash
=oldlist
;
1967 m_ploglist
->m_LogCache
.AddCacheEntry(*revInVector
);
1970 InterlockedExchange(&revInVector
->m_IsFull
,TRUE
);
1971 InterlockedExchange(&revInVector
->m_IsUpdateing
,FALSE
);
1973 //Notify listcontrol and update progress bar
1976 ::PostMessage(m_ploglist
->m_hWnd
,MSG_LOADED
,(WPARAM
)rev
,0);
1978 DWORD percent
=m_CollectedCount
*68/m_ploglist
->m_logEntries
.size() + GITLOG_START
+1+30;
1979 if(percent
== GITLOG_END
)
1980 percent
= GITLOG_END
-1;
1982 ::PostMessage(m_ploglist
->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
,0);
1985 CGitLogListBase
* m_ploglist
;
1986 BYTE_VECTOR m_ByteCollector
;
1987 int m_CollectedCount
;
1991 void CGitLogListBase::FetchFullLogInfo(CString
&from
, CString
&to
)
1993 CGitCall_FetchFullLogInfo
fetcher(this);
1995 CGit::LOG_INFO_FULL_DIFF
|
1996 CGit::LOG_INFO_STAT
|
1997 CGit::LOG_INFO_FILESTATE
|
1998 CGit::LOG_INFO_DETECT_COPYRENAME
|
1999 CGit::LOG_INFO_SHOW_MERGEDFILE
|
2003 if(this->m_Path
.IsEmpty())
2008 g_Git
.GetLog(&fetcher
,CString(),path
,-1,mask
,&from
,&to
);
2011 void CGitLogListBase::FetchLastLogInfo()
2013 unsigned int updated
=0;
2017 for(unsigned int i
=0;i
<m_logEntries
.size();i
++)
2019 if(m_logEntries
.GetGitRevAt(i
).m_IsFull
)
2022 if(m_LogCache
.GetCacheData(m_logEntries
.GetGitRevAt(i
)))
2024 if(!m_logEntries
.FetchFullInfo(i
))
2028 m_LogCache
.AddCacheEntry(m_logEntries
.GetGitRevAt(i
));
2033 InterlockedExchange(&m_logEntries
.GetGitRevAt(i
).m_IsUpdateing
,FALSE
);
2034 InterlockedExchange(&m_logEntries
.GetGitRevAt(i
).m_IsFull
,TRUE
);
2037 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)i
,0);
2041 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2042 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2049 UINT
CGitLogListBase::LogThread()
2052 // if(m_ProcCallBack)
2053 // m_ProcCallBack(m_ProcData,GITLOG_START);
2054 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START
,0);
2056 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2057 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2059 //does the user force the cache to refresh (shift or control key down)?
2060 bool refresh
= (GetKeyState (VK_CONTROL
) < 0)
2061 || (GetKeyState (VK_SHIFT
) < 0);
2063 //disable the "Get All" button while we're receiving
2068 if(this->m_bExitThread
)
2070 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2071 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2074 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2075 ::PostMessage(GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_START_ALL
, 0);
2077 int start
=0; CString firstcommit
,lastcommit
;
2079 for(int i
=0;i
<m_logEntries
.size();i
++)
2081 if( i
==0 && m_logEntries
.GetGitRevAt(i
).m_CommitHash
.IsEmpty() )
2083 m_logEntries
.GetGitRevAt(i
).m_Files
.Clear();
2084 m_logEntries
.GetGitRevAt(i
).m_ParentHash
.clear();
2085 m_logEntries
.GetGitRevAt(i
).m_ParentHash
.push_back(m_HeadHash
);
2086 g_Git
.GetCommitDiffList(m_logEntries
.GetGitRevAt(i
).m_CommitHash
,this->m_HeadHash
,m_logEntries
.GetGitRevAt(i
).m_Files
);
2087 m_logEntries
.GetGitRevAt(i
).m_Action
=0;
2088 for(int j
=0;j
< m_logEntries
.GetGitRevAt(i
).m_Files
.GetCount();j
++)
2089 m_logEntries
.GetGitRevAt(i
).m_Action
|= m_logEntries
.GetGitRevAt(i
).m_Files
[j
].m_Action
;
2091 m_logEntries
.GetGitRevAt(i
).m_Body
.Format(_T("%d files changed"),m_logEntries
.GetGitRevAt(i
).m_Files
.GetCount());
2092 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
)0,0);
2096 start
=this->m_logEntries
.GetGitRevAt(i
).ParserFromLog(m_logEntries
.m_RawlogData
,start
);
2097 m_logEntries
.m_HashMap
[m_logEntries
[i
].m_CommitHash
]=i
;
2099 if(m_LogCache
.GetCacheData(m_logEntries
.GetGitRevAt(i
)))
2101 if(firstcommit
.IsEmpty())
2102 firstcommit
=m_logEntries
[i
].m_CommitHash
;
2103 lastcommit
=m_logEntries
[i
].m_CommitHash
;
2107 InterlockedExchange(&m_logEntries
.GetGitRevAt(i
).m_IsUpdateing
,FALSE
);
2108 InterlockedExchange(&m_logEntries
.GetGitRevAt(i
).m_IsFull
,TRUE
);
2111 ::PostMessage(m_hWnd
,MSG_LOADED
,(WPARAM
) i
, 0);
2115 if(start
>=m_logEntries
.m_RawlogData
.size())
2118 int percent
=i
*30/m_logEntries
.size() + GITLOG_START
+1;
2120 ::PostMessage(GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) percent
, 0);
2122 if(this->m_bExitThread
)
2124 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2125 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2129 if(!lastcommit
.IsEmpty())
2130 FetchFullLogInfo(lastcommit
,firstcommit
);
2132 this->FetchLastLogInfo();
2135 RedrawItems(0, m_arShownList
.GetCount());
2136 // SetRedraw(false);
2137 // ResizeAllListCtrlCols();
2140 if ( m_pStoreSelection
)
2142 // Deleting the instance will restore the
2143 // selection of the CLogDlg.
2144 delete m_pStoreSelection
;
2145 m_pStoreSelection
= NULL
;
2149 // If no selection has been set then this must be the first time
2150 // the revisions are shown. Let's preselect the topmost revision.
2151 if ( GetItemCount()>0 )
2153 SetSelectionMark(0);
2154 SetItemState(0, LVIS_SELECTED
, LVIS_SELECTED
);
2161 //FetchFullLogInfo();
2162 //FetchFullLogInfoOrig();
2164 // make sure the filter is applied (if any) now, after we refreshed/fetched
2167 ::PostMessage(this->GetParent()->m_hWnd
,MSG_LOAD_PERCENTAGE
,(WPARAM
) GITLOG_END
,0);
2169 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2174 void CGitLogListBase::Refresh()
2177 if(m_LoadingThread
!=NULL
)
2179 DWORD ret
=::WaitForSingleObject(m_LoadingThread
->m_hThread
,20000);
2180 if(ret
== WAIT_TIMEOUT
)
2184 this->SetItemCountEx(0);
2187 //Update branch and Tag info
2189 //Assume Thread have exited
2190 //if(!m_bThreadRunning)
2193 m_logEntries
.clear();
2194 m_bExitThread
=FALSE
;
2195 InterlockedExchange(&m_bThreadRunning
, TRUE
);
2196 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2197 if (AfxBeginThread(LogThreadEntry
, this)==NULL
)
2199 InterlockedExchange(&m_bThreadRunning
, FALSE
);
2200 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2201 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
2203 m_sFilterText
.Empty();
2204 m_From
=CTime(1970,1,2,0,0,0);
2205 m_To
=CTime::GetCurrentTime();
2208 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str
, tr1::wregex
& pat
, bool bMatchCase
/* = false */)
2212 tr1::regex_constants::syntax_option_type type
= tr1::regex_constants::ECMAScript
;
2214 type
|= tr1::regex_constants::icase
;
2215 pat
= tr1::wregex(regexp_str
, type
);
2218 catch (exception
) {}
2222 void CGitLogListBase::RecalculateShownList(CPtrArray
* pShownlist
)
2225 pShownlist
->RemoveAll();
2226 tr1::wregex pat
;//(_T("Remove"), tr1::regex_constants::icase);
2227 bool bRegex
= false;
2228 if (m_bFilterWithRegex
)
2229 bRegex
= ValidateRegexp(m_sFilterText
, pat
, false);
2231 tr1::regex_constants::match_flag_type flags
= tr1::regex_constants::match_any
;
2233 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2235 if ((bRegex
)&&(m_bFilterWithRegex
))
2238 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2240 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR
)m_logEntries
[i
]->sBugIDs
);
2241 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
]->sBugIDs
), pat
, flags
)&&IsEntryInDateRange(i
))
2243 pShownlist
->Add(m_logEntries
[i
]);
2248 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2250 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
[i
].m_Subject
);
2251 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
].m_Subject
), pat
, flags
)&&IsEntryInDateRange(i
))
2253 pShownlist
->Add(&m_logEntries
[i
]);
2257 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries
[i
].m_Body
);
2258 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
].m_Body
), pat
, flags
)&&IsEntryInDateRange(i
))
2260 pShownlist
->Add(&m_logEntries
[i
]);
2265 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2267 LogChangedPathArray
* cpatharray
= m_logEntries
[i
]->pArChangedPaths
;
2270 for (INT_PTR cpPathIndex
= 0; cpPathIndex
<cpatharray
->GetCount() && bGoing
; ++cpPathIndex
)
2272 LogChangedPath
* cpath
= cpatharray
->GetAt(cpPathIndex
);
2273 if (regex_search(wstring((LPCTSTR
)cpath
->sCopyFromPath
), pat
, flags
)&&IsEntryInDateRange(i
))
2275 pShownlist
->Add(m_logEntries
[i
]);
2279 if (regex_search(wstring((LPCTSTR
)cpath
->sPath
), pat
, flags
)&&IsEntryInDateRange(i
))
2281 pShownlist
->Add(m_logEntries
[i
]);
2285 if (regex_search(wstring((LPCTSTR
)cpath
->GetAction()), pat
, flags
)&&IsEntryInDateRange(i
))
2287 pShownlist
->Add(m_logEntries
[i
]);
2296 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2298 if (regex_search(wstring((LPCTSTR
)m_logEntries
[i
].m_AuthorName
), pat
, flags
)&&IsEntryInDateRange(i
))
2300 pShownlist
->Add(&m_logEntries
[i
]);
2304 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2306 sRev
.Format(_T("%s"), m_logEntries
[i
].m_CommitHash
);
2307 if (regex_search(wstring((LPCTSTR
)sRev
), pat
, flags
)&&IsEntryInDateRange(i
))
2309 pShownlist
->Add(&m_logEntries
[i
]);
2316 CString find
= m_sFilterText
;
2319 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_BUGID
))
2321 CString sBugIDs
= m_logEntries
[i
]->sBugIDs
;
2323 sBugIDs
= sBugIDs
.MakeLower();
2324 if ((sBugIDs
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2326 pShownlist
->Add(m_logEntries
[i
]);
2331 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_MESSAGES
))
2333 CString msg
= m_logEntries
[i
].m_Subject
;
2335 msg
= msg
.MakeLower();
2336 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2338 pShownlist
->Add(&m_logEntries
[i
]);
2341 msg
= m_logEntries
[i
].m_Body
;
2343 msg
= msg
.MakeLower();
2344 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2346 pShownlist
->Add(&m_logEntries
[i
]);
2351 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_PATHS
))
2353 LogChangedPathArray
* cpatharray
= m_logEntries
[i
]->pArChangedPaths
;
2356 for (INT_PTR cpPathIndex
= 0; cpPathIndex
<cpatharray
->GetCount() && bGoing
; ++cpPathIndex
)
2358 LogChangedPath
* cpath
= cpatharray
->GetAt(cpPathIndex
);
2359 CString path
= cpath
->sCopyFromPath
;
2361 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2363 pShownlist
->Add(m_logEntries
[i
]);
2367 path
= cpath
->sPath
;
2369 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2371 pShownlist
->Add(m_logEntries
[i
]);
2375 path
= cpath
->GetAction();
2377 if ((path
.Find(find
)>=0)&&(IsEntryInDateRange(i
)))
2379 pShownlist
->Add(m_logEntries
[i
]);
2386 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_AUTHORS
))
2388 CString msg
= m_logEntries
[i
].m_AuthorName
;
2389 msg
= msg
.MakeLower();
2390 if ((msg
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2392 pShownlist
->Add(&m_logEntries
[i
]);
2396 if ((m_nSelectedFilter
== LOGFILTER_ALL
)||(m_nSelectedFilter
== LOGFILTER_REVS
))
2398 sRev
.Format(_T("%s"), m_logEntries
[i
].m_CommitHash
);
2399 if ((sRev
.Find(find
) >= 0)&&(IsEntryInDateRange(i
)))
2401 pShownlist
->Add(&m_logEntries
[i
]);
2405 } // else (from if (bRegex))
2406 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2410 BOOL
CGitLogListBase::IsEntryInDateRange(int i
)
2412 __time64_t time
= m_logEntries
[i
].m_AuthorDate
.GetTime();
2413 if ((time
>= m_From
.GetTime())&&(time
<= m_To
.GetTime()))
2420 void CGitLogListBase::StartFilter()
2422 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2423 RecalculateShownList(&m_arShownList
);
2424 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2428 SetItemCountEx(ShownCountWithStopped());
2429 RedrawItems(0, ShownCountWithStopped());
2431 //ResizeAllListCtrlCols();
2436 void CGitLogListBase::RemoveFilter()
2439 InterlockedExchange(&m_bNoDispUpdates
, TRUE
);
2441 m_arShownList
.RemoveAll();
2443 // reset the time filter too
2445 m_timFrom
= (__time64_t(m_tFrom
));
2446 m_timTo
= (__time64_t(m_tTo
));
2447 m_DateFrom
.SetTime(&m_timFrom
);
2448 m_DateTo
.SetTime(&m_timTo
);
2449 m_DateFrom
.SetRange(&m_timFrom
, &m_timTo
);
2450 m_DateTo
.SetRange(&m_timFrom
, &m_timTo
);
2453 for (DWORD i
=0; i
<m_logEntries
.size(); ++i
)
2455 if(this->m_IsOldFirst
)
2457 m_arShownList
.Add(&m_logEntries
[m_logEntries
.size()-i
-1]);
2460 m_arShownList
.Add(&m_logEntries
[i
]);
2463 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2465 SetItemCountEx(ShownCountWithStopped());
2466 RedrawItems(0, ShownCountWithStopped());
2467 // SetRedraw(false);
2468 // ResizeAllListCtrlCols();
2471 InterlockedExchange(&m_bNoDispUpdates
, FALSE
);
2474 void CGitLogListBase::Clear()
2476 m_arShownList
.RemoveAll();
2479 m_logEntries
.ClearAll();
2483 void CGitLogListBase::OnDestroy()
2485 // save the column widths to the registry
2488 if(this->m_bThreadRunning
)
2490 this->m_bExitThread
=true;
2491 DWORD ret
=::WaitForSingleObject(m_LoadingThread
->m_hThread
,20000);
2492 if(ret
== WAIT_TIMEOUT
)
2495 while(m_LogCache
.SaveCache())
2497 if(CMessageBox::Show(NULL
,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2501 CHintListCtrl::OnDestroy();
2504 LRESULT
CGitLogListBase::OnLoad(WPARAM wParam
,LPARAM lParam
)
2508 this->GetItemRect(i
,&rect
,LVIR_BOUNDS
);
2509 this->InvalidateRect(rect
);
2511 if(this->GetItemState(i
,LVIF_STATE
) & LVIS_SELECTED
)
2519 * Save column widths to the registry
2521 void CGitLogListBase::SaveColumnWidths()
2523 CHeaderCtrl
* pHdrCtrl
= (CHeaderCtrl
*)(GetDlgItem(0));
2526 int numcols
= pHdrCtrl
->GetItemCount();
2527 for (int col
= 0; col
< numcols
; col
++)
2529 int width
= GetColumnWidth( col
);
2531 regentry
.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey
, col
);
2532 CRegDWORD
regwidth(regentry
, 0);
2533 regwidth
= width
; // this writes it to reg
2538 int CGitLogListBase::GetHeadIndex()
2540 if(m_HeadHash
.IsEmpty())
2543 for(int i
=0;i
<m_arShownList
.GetCount();i
++)
2545 GitRev
*pRev
= (GitRev
*)m_arShownList
[i
];
2548 if(pRev
->m_CommitHash
== m_HeadHash
)