1 // GitLogList.cpp : implementation file
\r
4 Description: qgit revision list view
\r
6 Author: Marco Costalba (C) 2005-2007
\r
8 Copyright: See COPYING file that comes with this distribution
\r
12 #include "GitLogListBase.h"
\r
14 //#include "VssStyle.h"
\r
15 #include "IconMenu.h"
\r
18 #include "InputDlg.h"
\r
19 #include "PropDlg.h"
\r
20 #include "SVNProgressDlg.h"
\r
21 #include "ProgressDlg.h"
\r
22 //#include "RepositoryBrowser.h"
\r
23 //#include "CopyDlg.h"
\r
24 //#include "StatGraphDlg.h"
\r
26 #include "MessageBox.h"
\r
27 #include "Registry.h"
\r
28 #include "AppUtils.h"
\r
29 #include "PathUtils.h"
\r
30 #include "StringUtils.h"
\r
31 #include "UnicodeUtils.h"
\r
32 #include "TempFile.h"
\r
33 //#include "GitInfo.h"
\r
34 //#include "GitDiff.h"
\r
35 #include "IconMenu.h"
\r
36 //#include "RevisionRangeDlg.h"
\r
37 //#include "BrowseFolder.h"
\r
38 //#include "BlameDlg.h"
\r
39 //#include "Blame.h"
\r
40 //#include "GitHelpers.h"
\r
41 #include "GitStatus.h"
\r
42 //#include "LogDlgHelper.h"
\r
43 //#include "CachedLogInfo.h"
\r
44 //#include "RepositoryInfo.h"
\r
45 //#include "EditPropertiesDlg.h"
\r
46 #include "FileDiffDlg.h"
\r
47 #include "..\\TortoiseShell\\Resource.h"
\r
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
\r
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
\r
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
\r
55 ,m_bNoDispUpdates(FALSE)
\r
56 , m_bThreadRunning(FALSE)
\r
57 , m_bStrictStopped(false)
\r
58 , m_pStoreSelection(NULL)
\r
59 , m_nSelectedFilter(LOGFILTER_ALL)
\r
63 // use the default GUI font, create a copy of it and
\r
64 // change the copy to BOLD (leave the rest of the font
\r
66 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
\r
68 GetObject(hFont, sizeof(LOGFONT), &lf);
\r
69 lf.lfWeight = FW_BOLD;
\r
70 m_boldFont = CreateFontIndirect(&lf);
\r
72 m_bShowBugtraqColumn=0;
\r
74 m_IsIDReplaceAction=FALSE;
\r
76 m_wcRev.m_CommitHash=GIT_REV_ZERO;
\r
77 m_wcRev.m_Subject=_T("Working dir changes");
\r
78 m_wcRev.m_ParentHash.clear();
\r
79 m_wcRev.m_Mark=_T('-');
\r
80 m_wcRev.m_IsUpdateing=FALSE;
\r
81 m_wcRev.m_IsFull = TRUE;
\r
83 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
84 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
85 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
86 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
\r
88 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
\r
90 g_Git.GetMapHashToFriendName(m_HashMap);
\r
91 m_CurrentBranch=g_Git.GetCurrentBranch();
\r
92 this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40);
\r
94 m_From=CTime(1970,1,2,0,0,0);
\r
95 m_To=CTime::GetCurrentTime();
\r
97 m_LoadingThread = NULL;
\r
99 m_bExitThread=FALSE;
\r
100 m_IsOldFirst = FALSE;
\r
101 m_IsRebaseReplaceGraph = FALSE;
\r
104 for(int i=0;i<Lanes::COLORS_NUM;i++)
\r
106 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
\r
108 // get short/long datetime setting from registry
\r
109 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
\r
110 if ( RegUseShortDateFormat )
\r
112 m_DateFormat = DATE_SHORTDATE;
\r
116 m_DateFormat = DATE_LONGDATE;
\r
118 // get relative time display setting from registry
\r
119 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
\r
120 m_bRelativeTimes = (regRelativeTimes != 0);
\r
121 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
\r
123 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
\r
124 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
\r
125 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
\r
126 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
\r
128 OSVERSIONINFOEX inf;
\r
129 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
\r
130 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
\r
131 GetVersionEx((OSVERSIONINFO *)&inf);
\r
132 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
\r
133 m_bVista = (fullver >= 0x0600);
\r
135 m_ColumnRegKey=_T("log");
\r
138 CGitLogListBase::~CGitLogListBase()
\r
140 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
142 DestroyIcon(m_hModifiedIcon);
\r
143 DestroyIcon(m_hReplacedIcon);
\r
144 DestroyIcon(m_hAddedIcon);
\r
145 DestroyIcon(m_hDeletedIcon);
\r
146 m_logEntries.ClearAll();
\r
149 DeleteObject(m_boldFont);
\r
151 if ( m_pStoreSelection )
\r
153 delete m_pStoreSelection;
\r
154 m_pStoreSelection = NULL;
\r
157 if(this->m_bThreadRunning)
\r
159 m_bExitThread=true;
\r
160 WaitForSingleObject(m_LoadingThread->m_hThread,1000);
\r
166 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
\r
167 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
\r
168 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
\r
169 ON_WM_CONTEXTMENU()
\r
170 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
\r
171 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
\r
174 ON_MESSAGE(MSG_LOADED,OnLoad)
\r
175 ON_WM_MEASUREITEM()
\r
176 ON_WM_MEASUREITEM_REFLECT()
\r
179 void CGitLogListBase::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
\r
181 // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ
\r
183 CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
\r
186 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
\r
188 //if (m_nRowHeight>0)
\r
190 lpMeasureItemStruct->itemHeight = 50;
\r
194 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
\r
196 PreSubclassWindow();
\r
197 return CHintListCtrl::OnCreate(lpCreateStruct);
\r
200 void CGitLogListBase::PreSubclassWindow()
\r
202 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
\r
203 // load the icons for the action columns
\r
204 // m_Theme.Open(m_hWnd, L"ListView");
\r
205 m_Theme.Open(m_hWnd, L"Explorer::ListView;ListView");
\r
206 m_Theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
\r
207 CHintListCtrl::PreSubclassWindow();
\r
210 void CGitLogListBase::InsertGitColumn()
\r
214 int c = GetHeaderCtrl()->GetItemCount()-1;
\r
218 temp.LoadString(IDS_LOG_GRAPH);
\r
220 if(m_IsRebaseReplaceGraph)
\r
226 temp.LoadString(IDS_LOG_GRAPH);
\r
228 InsertColumn(this->LOGLIST_GRAPH, temp);
\r
231 // make the revision column right aligned
\r
233 Column.mask = LVCF_FMT;
\r
234 Column.fmt = LVCFMT_RIGHT;
\r
235 SetColumn(0, &Column);
\r
238 // g_Git.GetLog(log);
\r
240 if(m_IsIDReplaceAction)
\r
242 temp.LoadString(IDS_LOG_ID);
\r
243 InsertColumn(this->LOGLIST_ACTION, temp);
\r
247 temp.LoadString(IDS_LOG_ACTIONS);
\r
248 InsertColumn(this->LOGLIST_ACTION, temp);
\r
250 temp.LoadString(IDS_LOG_MESSAGE);
\r
251 InsertColumn(this->LOGLIST_MESSAGE, temp);
\r
253 temp.LoadString(IDS_LOG_AUTHOR);
\r
254 InsertColumn(this->LOGLIST_AUTHOR, temp);
\r
256 temp.LoadString(IDS_LOG_DATE);
\r
257 InsertColumn(this->LOGLIST_DATE, temp);
\r
260 if (m_bShowBugtraqColumn)
\r
262 // temp = m_ProjectProperties.sLabel;
\r
263 if (temp.IsEmpty())
\r
264 temp.LoadString(IDS_LOG_BUGIDS);
\r
265 InsertColumn(this->LOGLIST_BUG, temp);
\r
270 ResizeAllListCtrlCols();
\r
276 * Resizes all columns in a list control to values in registry.
\r
278 void CGitLogListBase::ResizeAllListCtrlCols()
\r
280 // column max and min widths to allow
\r
281 static const int nMinimumWidth = 10;
\r
282 static const int nMaximumWidth = 1000;
\r
283 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
\r
286 int numcols = pHdrCtrl->GetItemCount();
\r
287 for (int col = 0; col < numcols; col++)
\r
289 // get width for this col last time from registry
\r
291 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
\r
292 CRegDWORD regwidth(regentry, 0);
\r
296 // no saved value, setup sensible defaults
\r
297 if (col == this->LOGLIST_MESSAGE)
\r
299 cx = LOGLIST_MESSAGE_MIN;
\r
303 cx = ICONITEMBORDER+16*4;
\r
306 if (cx < nMinimumWidth)
\r
308 cx = nMinimumWidth;
\r
309 } else if (cx > nMaximumWidth)
\r
311 cx = nMaximumWidth;
\r
314 SetColumnWidth(col, cx);
\r
321 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
\r
323 TRACE(_T("%s %s\r\n"),ref,prefix);
\r
324 if(ref.Left(prefix.GetLength()) == prefix)
\r
326 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
\r
327 if(shortname.Right(3)==_T("^{}"))
\r
328 shortname=shortname.Left(shortname.GetLength()-3);
\r
334 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
\r
338 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
339 rItem.mask = LVIF_STATE;
\r
340 rItem.iItem = Index;
\r
341 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
344 GitRev* pLogEntry = (GitRev*)m_arShownList.GetAt(Index);
\r
345 HBRUSH brush = NULL;
\r
348 if (m_Theme.IsAppThemed() && m_bVista)
\r
350 int state = LISS_NORMAL;
\r
351 if (rItem.state & LVIS_SELECTED)
\r
353 if (::GetFocus() == m_hWnd)
\r
354 state |= LISS_SELECTED;
\r
356 state |= LISS_SELECTEDNOTFOCUS;
\r
360 if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
\r
361 brush = ::CreateSolidBrush(RGB(156,156,156));
\r
362 else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
\r
363 brush = ::CreateSolidBrush(RGB(200,200,128));
\r
365 if(pLogEntry->m_CommitHash == GIT_REV_ZERO)
\r
366 brush = ::CreateSolidBrush(RGB(200,200,128));
\r
371 ::FillRect(hdc, &rect, brush);
\r
372 ::DeleteObject(brush);
\r
376 if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTITEM, state))
\r
377 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);
\r
379 CRect rectDraw = rect;
\r
380 if(rItem.state & LVIS_SELECTED)
\r
381 rectDraw.InflateRect(1,0);
\r
383 rectDraw.InflateRect(1,1);
\r
385 m_Theme.DrawBackground(hdc, LVP_LISTITEM, state, rectDraw, &rect);
\r
391 if (rItem.state & LVIS_SELECTED)
\r
393 if (::GetFocus() == m_hWnd)
\r
394 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
\r
396 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
\r
400 //if (pLogEntry->bCopiedSelf)
\r
401 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
\r
403 if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
\r
404 brush = ::CreateSolidBrush(RGB(156,156,156));
\r
405 else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
\r
406 brush = ::CreateSolidBrush(RGB(200,200,128));
\r
407 else if(pLogEntry->m_CommitHash == GIT_REV_ZERO)
\r
408 brush = ::CreateSolidBrush(RGB(200,200,128));
\r
410 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
\r
415 ::FillRect(hdc, &rect, brush);
\r
416 ::DeleteObject(brush);
\r
421 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
\r
423 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
\r
426 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
427 rItem.mask = LVIF_STATE;
\r
428 rItem.iItem = index;
\r
429 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
432 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
\r
435 str=m_HashMap[data->m_CommitHash][i];
\r
439 shortname = _T("");
\r
440 COLORREF colRef = 0;
\r
442 //Determine label color
\r
443 if(GetShortName(str,shortname,_T("refs/heads/")))
\r
445 if( shortname == m_CurrentBranch )
\r
446 colRef = m_Colors.GetColor(CColors::CurrentBranch);
\r
448 colRef = m_Colors.GetColor(CColors::LocalBranch);
\r
450 }else if(GetShortName(str,shortname,_T("refs/remotes/")))
\r
452 colRef = m_Colors.GetColor(CColors::RemoteBranch);
\r
454 else if(GetShortName(str,shortname,_T("refs/tags/")))
\r
456 colRef = m_Colors.GetColor(CColors::Tag);
\r
458 else if(GetShortName(str,shortname,_T("refs/stash")))
\r
460 colRef = m_Colors.GetColor(CColors::Stash);
\r
461 shortname=_T("stash");
\r
464 //When row selected, ajust label color
\r
465 if (!(m_Theme.IsAppThemed() && m_bVista))
\r
466 if (rItem.state & LVIS_SELECTED)
\r
467 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
\r
469 brush = ::CreateSolidBrush(colRef);
\r
472 if(!shortname.IsEmpty())
\r
475 memset(&size,0,sizeof(SIZE));
\r
476 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
\r
478 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
\r
481 //Fill interior of ref label
\r
482 ::FillRect(hdc, &rt, brush);
\r
484 //Draw edge of label
\r
488 CRect rectEdge = rt;
\r
490 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
\r
491 rectEdge.DeflateRect(1,1);
\r
492 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
\r
496 //Draw text inside label
\r
497 if (m_Theme.IsAppThemed() && m_bVista)
\r
499 int txtState = LISS_NORMAL;
\r
500 if (rItem.state & LVIS_SELECTED)
\r
501 txtState = LISS_SELECTED;
\r
503 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, shortname, -1, DT_CENTER | DT_SINGLELINE | DT_VCENTER, 0, &rt);
\r
507 if (rItem.state & LVIS_SELECTED)
\r
509 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
\r
510 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
\r
511 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
\r
512 ::SetTextColor(hdc,clrOld);
\r
515 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
\r
520 //::MoveToEx(hdc,rt.left,rt.top,NULL);
\r
521 //::LineTo(hdc,rt.right,rt.top);
\r
522 //::LineTo(hdc,rt.right,rt.bottom);
\r
523 //::LineTo(hdc,rt.left,rt.bottom);
\r
524 //::LineTo(hdc,rt.left,rt.top);
\r
527 rt.left=rt.right+1;
\r
530 ::DeleteObject(brush);
\r
532 rt.right=rect.right;
\r
534 if (m_Theme.IsAppThemed() && m_bVista)
\r
536 int txtState = LISS_NORMAL;
\r
537 if (rItem.state & LVIS_SELECTED)
\r
538 txtState = LISS_SELECTED;
\r
540 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, data->m_Subject, -1, DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
\r
544 if (rItem.state & LVIS_SELECTED)
\r
546 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
\r
547 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);
\r
548 ::SetTextColor(hdc,clrOld);
\r
551 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);
\r
556 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
\r
558 // Returns ((256 - amount)*col1 + amount*col2) / 256;
\r
559 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
\r
560 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
\r
561 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
\r
564 Gdiplus::Color GetGdiColor(COLORREF col)
\r
566 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
\r
568 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
\r
569 const COLORREF& col,const COLORREF& activeColor, int top
\r
572 int h = laneHeight / 2;
\r
573 int m = (x1 + x2) / 2;
\r
574 int r = (x2 - x1) / 3;
\r
577 #define P_CENTER m , h+top
\r
578 #define P_0 x2, h+top
\r
579 #define P_90 m , 0+top
\r
580 #define P_180 x1, h+top
\r
581 #define P_270 m , 2 * h+top
\r
582 #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d
\r
585 #define DELTA_UR_B 2*(x1 - m), 2*h +top
\r
586 #define DELTA_UR_E 0*16, 90*16 +top // -,
\r
588 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
\r
589 #define DELTA_DR_E 270*16, 90*16 +top // -'
\r
591 #define DELTA_UL_B 2*(x2 - m), 2*h +top
\r
592 #define DELTA_UL_E 90*16, 90*16 +top // ,-
\r
594 #define DELTA_DL_B 2*(x2 - m),2*-h +top
\r
595 #define DELTA_DL_E 180*16, 90*16 // '-
\r
597 #define CENTER_UR x1, 2*h, 225
\r
598 #define CENTER_DR x1, 0 , 135
\r
599 #define CENTER_UL x2, 2*h, 315
\r
600 #define CENTER_DL x2, 0 , 45
\r
603 Gdiplus::Graphics graphics( hdc );
\r
608 case Lanes::JOIN_R:
\r
610 case Lanes::HEAD_R:
\r
612 Gdiplus::LinearGradientBrush gradient(
\r
613 Gdiplus::Point(x1-2, h+top-2),
\r
614 Gdiplus::Point(P_270),
\r
615 GetGdiColor(activeColor),GetGdiColor(col));
\r
618 Gdiplus::Pen mypen(&gradient,2);
\r
619 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
\r
621 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
\r
622 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1+1,laneHeight+1,270,90);
\r
623 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
\r
627 case Lanes::JOIN_L:
\r
630 Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
\r
633 graphics.DrawArc(&mypen,x1,top+h, x2-x1,laneHeight,270,90);
\r
638 case Lanes::TAIL_R:
\r
641 Gdiplus::LinearGradientBrush gradient(
\r
642 Gdiplus::Point(x1-2, h+top-2),
\r
643 Gdiplus::Point(P_90),
\r
644 GetGdiColor(activeColor),GetGdiColor(col));
\r
647 Gdiplus::Pen mypen(&gradient,2);
\r
649 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1+1,laneHeight+1,0,90);
\r
653 QConicalGradient gradient(CENTER_DR);
\r
654 gradient.setColorAt(0.375, activeCol);
\r
655 gradient.setColorAt(0.625, col);
\r
656 myPen.setBrush(gradient);
\r
658 p->drawArc(P_CENTER, DELTA_DR);
\r
667 //static QPen myPen(Qt::black, 2); // fast path here
\r
669 pen.CreatePen(PS_SOLID,2,col);
\r
670 //myPen.setColor(col);
\r
671 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
\r
673 Gdiplus::Pen myPen(GetGdiColor(col),2);
\r
675 //p->setPen(myPen);
\r
679 case Lanes::ACTIVE:
\r
680 case Lanes::NOT_ACTIVE:
\r
681 case Lanes::MERGE_FORK:
\r
682 case Lanes::MERGE_FORK_R:
\r
683 case Lanes::MERGE_FORK_L:
\r
685 case Lanes::JOIN_R:
\r
686 case Lanes::JOIN_L:
\r
688 //DrawLine(hdc,P_90,P_270);
\r
689 graphics.DrawLine(&myPen,P_90,P_270);
\r
690 //p->drawLine(P_90, P_270);
\r
692 case Lanes::HEAD_L:
\r
693 case Lanes::BRANCH:
\r
694 //DrawLine(hdc,P_CENTER,P_270);
\r
695 graphics.DrawLine(&myPen,P_CENTER,P_270);
\r
696 //p->drawLine(P_CENTER, P_270);
\r
698 case Lanes::TAIL_L:
\r
699 case Lanes::INITIAL:
\r
700 case Lanes::BOUNDARY:
\r
701 case Lanes::BOUNDARY_C:
\r
702 case Lanes::BOUNDARY_R:
\r
703 case Lanes::BOUNDARY_L:
\r
704 //DrawLine(hdc,P_90, P_CENTER);
\r
705 graphics.DrawLine(&myPen,P_90,P_CENTER);
\r
706 //p->drawLine(P_90, P_CENTER);
\r
712 myPen.SetColor(GetGdiColor(activeColor));
\r
716 case Lanes::MERGE_FORK:
\r
721 case Lanes::CROSS_EMPTY:
\r
722 case Lanes::BOUNDARY_C:
\r
723 //DrawLine(hdc,P_180,P_0);
\r
724 graphics.DrawLine(&myPen,P_180,P_0);
\r
725 //p->drawLine(P_180, P_0);
\r
727 case Lanes::MERGE_FORK_R:
\r
728 case Lanes::BOUNDARY_R:
\r
729 //DrawLine(hdc,P_180,P_CENTER);
\r
730 graphics.DrawLine(&myPen,P_180,P_CENTER);
\r
731 //p->drawLine(P_180, P_CENTER);
\r
733 case Lanes::MERGE_FORK_L:
\r
734 case Lanes::HEAD_L:
\r
735 case Lanes::TAIL_L:
\r
736 case Lanes::BOUNDARY_L:
\r
737 //DrawLine(hdc,P_CENTER,P_0);
\r
738 graphics.DrawLine(&myPen,P_CENTER,P_0);
\r
739 //p->drawLine(P_CENTER, P_0);
\r
746 brush.CreateSolidBrush(col);
\r
747 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
\r
748 // center symbol, e.g. rect or ellipse
\r
750 case Lanes::ACTIVE:
\r
751 case Lanes::INITIAL:
\r
752 case Lanes::BRANCH:
\r
754 //p->setPen(Qt::NoPen);
\r
755 //p->setBrush(col);
\r
756 ::Ellipse(hdc, R_CENTER);
\r
757 //p->drawEllipse(R_CENTER);
\r
759 case Lanes::MERGE_FORK:
\r
760 case Lanes::MERGE_FORK_R:
\r
761 case Lanes::MERGE_FORK_L:
\r
762 //p->setPen(Qt::NoPen);
\r
763 //p->setBrush(col);
\r
764 //p->drawRect(R_CENTER);
\r
765 Rectangle(hdc,R_CENTER);
\r
767 case Lanes::UNAPPLIED:
\r
769 //p->setPen(Qt::NoPen);
\r
770 //p->setBrush(Qt::red);
\r
771 //p->drawRect(m - r, h - 1, d, 2);
\r
772 ::Rectangle(hdc,m-r,h-1,d,2);
\r
774 case Lanes::APPLIED:
\r
776 //p->setPen(Qt::NoPen);
\r
777 //p->setBrush(DARK_GREEN);
\r
778 //p->drawRect(m - r, h - 1, d, 2);
\r
779 //p->drawRect(m - 1, h - r, 2, d);
\r
780 ::Rectangle(hdc,m-r,h-1,d,2);
\r
781 ::Rectangle(hdc,m-1,h-r,2,d);
\r
783 case Lanes::BOUNDARY:
\r
784 //p->setBrush(back);
\r
785 //p->drawEllipse(R_CENTER);
\r
786 ::Ellipse(hdc, R_CENTER);
\r
788 case Lanes::BOUNDARY_C:
\r
789 case Lanes::BOUNDARY_R:
\r
790 case Lanes::BOUNDARY_L:
\r
791 //p->setBrush(back);
\r
792 //p->drawRect(R_CENTER);
\r
793 ::Rectangle(hdc,R_CENTER);
\r
799 ::SelectObject(hdc,oldpen);
\r
800 ::SelectObject(hdc,oldbrush);
\r
809 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
\r
813 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
\r
814 if(data->m_CommitHash.IsEmpty())
\r
819 SecureZeroMemory(&rItem, sizeof(LVITEM));
\r
820 rItem.mask = LVIF_STATE;
\r
821 rItem.iItem = index;
\r
822 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
\r
826 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
\r
830 if (data->m_Lanes.size() == 0)
\r
831 m_logEntries.setLane(data->m_CommitHash);
\r
833 std::vector<int>& lanes=data->m_Lanes;
\r
834 UINT laneNum = lanes.size();
\r
835 UINT activeLane = 0;
\r
836 for (UINT i = 0; i < laneNum; i++)
\r
837 if (Lanes::isMerge(lanes[i])) {
\r
842 int x1 = 0, x2 = 0;
\r
843 int maxWidth = rect.Width();
\r
844 int lw = 3 * rect.Height() / 4; //laneWidth()
\r
846 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
\r
847 //if (opt.state & QStyle::State_Selected)
\r
848 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
\r
851 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
\r
858 if (ln == Lanes::EMPTY)
\r
861 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
\r
862 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
\r
866 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
\r
872 if (ln == Lanes::EMPTY)
\r
875 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
\r
876 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
\r
878 if (ln == Lanes::CROSS) {
\r
879 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
\r
880 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
\r
882 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
\r
888 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
891 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
\r
892 // Take the default processing unless we set this to something else below.
\r
893 *pResult = CDRF_DODEFAULT;
\r
895 if (m_bNoDispUpdates)
\r
900 switch (pLVCD->nmcd.dwDrawStage)
\r
902 case CDDS_PREPAINT:
\r
904 *pResult = CDRF_NOTIFYITEMDRAW;
\r
908 case CDDS_ITEMPREPAINT:
\r
910 // This is the prepaint stage for an item. Here's where we set the
\r
911 // item's text color.
\r
913 // Tell Windows to send draw notifications for each subitem.
\r
914 *pResult = CDRF_NOTIFYSUBITEMDRAW;
\r
916 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
\r
918 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
920 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
\r
924 if (data->bCopiedSelf)
\r
926 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
\r
927 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
\r
928 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
\r
932 crText = m_Colors.GetColor(CColors::Modified);
\r
934 if (data->m_Action& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
\r
935 crText = RGB(128,128,128);
\r
937 if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
\r
938 pLVCD->clrTextBk = RGB(156,156,156);
\r
939 else if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
\r
940 pLVCD->clrTextBk = RGB(200,200,128);
\r
941 else if(data->m_CommitHash == GIT_REV_ZERO)
\r
942 pLVCD->clrTextBk = RGB(200,200,128);
\r
944 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
\r
946 if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_CURRENT)
\r
948 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
\r
949 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
\r
952 if(data->m_CommitHash == m_HeadHash)
\r
954 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
\r
955 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
\r
958 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
\r
959 // crText = GetSysColor(COLOR_GRAYTEXT);
\r
961 if (data->m_CommitHash == GIT_REV_ZERO)
\r
963 //crText = GetSysColor(COLOR_GRAYTEXT);
\r
964 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
\r
965 // We changed the font, so we're returning CDRF_NEWFONT. This
\r
966 // tells the control to recalculate the extent of the text.
\r
967 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
\r
971 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
973 if (m_bStrictStopped)
\r
974 crText = GetSysColor(COLOR_GRAYTEXT);
\r
976 // Store the color back in the NMLVCUSTOMDRAW struct.
\r
977 pLVCD->clrText = crText;
\r
981 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
\r
983 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
\r
985 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
\r
988 if (pLVCD->iSubItem == LOGLIST_GRAPH)
\r
990 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
\r
993 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
994 if(pLVCD->iSubItem == 0)
\r
997 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem+1, LVIR_BOUNDS, second);
\r
998 rect.right=second.left;
\r
1001 TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
\r
1002 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
1003 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
\r
1005 *pResult = CDRF_SKIPDEFAULT;
\r
1011 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
\r
1013 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
1015 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
\r
1016 //if(!data->m_IsFull)
\r
1018 //if(data->SafeFetchFullInfo(&g_Git))
\r
1019 // this->Invalidate();
\r
1020 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
\r
1023 if(m_HashMap[data->m_CommitHash].size()!=0)
\r
1027 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
1029 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
1030 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
\r
1032 *pResult = CDRF_SKIPDEFAULT;
\r
1040 if (pLVCD->iSubItem == 1)
\r
1042 if(this->m_IsIDReplaceAction)
\r
1044 *pResult = CDRF_DODEFAULT;
\r
1047 *pResult = CDRF_DODEFAULT;
\r
1049 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
\r
1053 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
\r
1054 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
\r
1056 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
\r
1058 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
\r
1059 TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
\r
1060 // Get the selected state of the
\r
1061 // item being drawn.
\r
1063 // Fill the background
\r
1064 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
\r
1066 // Draw the icon(s) into the compatible DC
\r
1067 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
\r
1068 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
1071 if (pLogEntry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
\r
1072 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
1075 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
\r
1076 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
1079 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
\r
1080 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
\r
1082 *pResult = CDRF_SKIPDEFAULT;
\r
1088 *pResult = CDRF_DODEFAULT;
\r
1092 // CGitLogListBase message handlers
\r
1094 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
1096 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
\r
1098 // Create a pointer to the item
\r
1099 LV_ITEM* pItem = &(pDispInfo)->item;
\r
1101 // Do the list need text information?
\r
1102 if (!(pItem->mask & LVIF_TEXT))
\r
1105 // By default, clear text buffer.
\r
1106 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
\r
1108 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
\r
1111 if (m_bNoDispUpdates || bOutOfRange)
\r
1114 // Which item number?
\r
1115 int itemid = pItem->iItem;
\r
1116 GitRev * pLogEntry = NULL;
\r
1117 if (itemid < m_arShownList.GetCount())
\r
1118 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));
\r
1123 temp.Format(_T("%d"),pItem->iItem+1);
\r
1127 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
\r
1131 switch (pItem->iSubItem)
\r
1133 case this->LOGLIST_GRAPH: //Graphic
\r
1136 if(this->m_IsRebaseReplaceGraph)
\r
1139 path.m_Action=pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
\r
1141 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
\r
1145 case this->LOGLIST_ACTION: //action -- no text in the column
\r
1146 if(this->m_IsIDReplaceAction)
\r
1147 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
\r
1149 case this->LOGLIST_MESSAGE: //Message
\r
1151 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);
\r
1153 case this->LOGLIST_AUTHOR: //Author
\r
1155 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);
\r
1157 case this->LOGLIST_DATE: //Date
\r
1159 lstrcpyn(pItem->pszText,
\r
1160 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
\r
1161 pItem->cchTextMax);
\r
1172 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
\r
1175 int selIndex = GetSelectionMark();
\r
1177 return; // nothing selected, nothing to do with a context menu
\r
1179 // if the user selected the info text telling about not all revisions shown due to
\r
1180 // the "stop on copy/rename" option, we also don't show the context menu
\r
1181 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
\r
1184 // if the context menu is invoked through the keyboard, we have to use
\r
1185 // a calculated position on where to anchor the menu on
\r
1186 if ((point.x == -1) && (point.y == -1))
\r
1189 GetItemRect(selIndex, &rect, LVIR_LABEL);
\r
1190 ClientToScreen(&rect);
\r
1191 point = rect.CenterPoint();
\r
1193 m_nSearchIndex = selIndex;
\r
1194 m_bCancelled = FALSE;
\r
1196 // calculate some information the context menu commands can use
\r
1197 // CString pathURL = GetURLFromPath(m_path);
\r
1199 POSITION pos = GetFirstSelectedItemPosition();
\r
1200 int indexNext = GetNextSelectedItem(pos);
\r
1201 if (indexNext < 0)
\r
1204 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
\r
1206 GitRev revSelected = pSelLogEntry->Rev;
\r
1207 GitRev revPrevious = git_revnum_t(revSelected)-1;
\r
1208 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
\r
1210 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
\r
1212 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);
\r
1213 if (changedpath->lCopyFromRev)
\r
1214 revPrevious = changedpath->lCopyFromRev;
\r
1217 GitRev revSelected2;
\r
1220 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
1221 revSelected2 = pLogEntry->Rev;
\r
1223 bool bAllFromTheSameAuthor = true;
\r
1224 CString firstAuthor;
\r
1225 CLogDataVector selEntries;
\r
1226 GitRev revLowest, revHighest;
\r
1227 GitRevRangeArray revisionRanges;
\r
1229 POSITION pos = GetFirstSelectedItemPosition();
\r
1230 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
1231 revisionRanges.AddRevision(pLogEntry->Rev);
\r
1232 selEntries.push_back(pLogEntry);
\r
1233 firstAuthor = pLogEntry->sAuthor;
\r
1234 revLowest = pLogEntry->Rev;
\r
1235 revHighest = pLogEntry->Rev;
\r
1238 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
1239 revisionRanges.AddRevision(pLogEntry->Rev);
\r
1240 selEntries.push_back(pLogEntry);
\r
1241 if (firstAuthor.Compare(pLogEntry->sAuthor))
\r
1242 bAllFromTheSameAuthor = false;
\r
1243 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
\r
1244 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
\r
1250 int FirstSelect=-1, LastSelect=-1;
\r
1251 pos = GetFirstSelectedItemPosition();
\r
1252 FirstSelect = GetNextSelectedItem(pos);
\r
1255 LastSelect = GetNextSelectedItem(pos);
\r
1257 //entry is selected, now show the popup menu
\r
1259 CIconMenu submenu;
\r
1260 if (popup.CreatePopupMenu())
\r
1263 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
\r
1264 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
\r
1266 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
\r
1267 popup.AppendMenuIcon(ID_REBASE_SQUASH,IDS_REBASE_SQUASH, IDI_SQUASH);
\r
1269 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
\r
1270 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
\r
1272 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
\r
1273 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
\r
1275 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
\r
1276 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
\r
1277 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1279 if (GetSelectedCount() == 1)
\r
1284 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))
\r
1285 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
\r
1287 // TortoiseMerge could be improved to take a /blame switch
\r
1288 // and then not 'cat' the files from a unified diff but
\r
1290 // But until that's implemented, the context menu entry for
\r
1291 // this feature is commented out.
\r
1292 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
\r
1294 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))
\r
1295 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
\r
1297 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
\r
1298 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
\r
1299 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
\r
1300 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1303 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
\r
1305 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
\r
1307 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
\r
1309 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
\r
1311 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
\r
1312 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
\r
1314 // popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1318 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
\r
1320 // popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
\r
1322 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);
\r
1324 CString str,format;
\r
1325 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
\r
1326 str.Format(format,g_Git.GetCurrentBranch());
\r
1328 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))
\r
1329 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
\r
1331 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV))
\r
1332 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
\r
1334 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
\r
1335 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
\r
1337 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
\r
1338 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_COPY);
\r
1340 format.LoadString(IDS_REBASE_THIS_FORMAT);
\r
1341 str.Format(format,g_Git.GetCurrentBranch());
\r
1343 if(pSelLogEntry->m_CommitHash != m_HeadHash)
\r
1344 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
\r
1345 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
\r
1347 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
\r
1348 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
\r
1351 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1355 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)
\r
1357 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
\r
1358 popup.AppendMenuIcon(ID_STASH_APPLY,IDS_MENUSTASHAPPLY, IDI_RELOCATE);
\r
1359 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1362 if (GetSelectedCount() >= 2)
\r
1364 bool bAddSeparator = false;
\r
1365 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
\r
1367 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))
\r
1368 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
\r
1371 if (GetSelectedCount() == 2)
\r
1373 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
\r
1374 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))
\r
1375 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
\r
1376 bAddSeparator = true;
\r
1381 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
\r
1383 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
\r
1384 bAddSeparator = true;
\r
1386 if (bAddSeparator)
\r
1387 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1390 if ( GetSelectedCount() >0 )
\r
1392 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
\r
1394 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))
\r
1398 headindex = this->GetHeadIndex();
\r
1401 head.Format(_T("HEAD~%d"),LastSelect-headindex);
\r
1402 CString hash=g_Git.GetHash(head);
\r
1403 hash=hash.Left(40);
\r
1404 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
\r
1405 if(pLastEntry->m_CommitHash == hash)
\r
1406 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
\r
1410 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK))
\r
1411 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
\r
1413 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
\r
1414 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH))
\r
1415 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
\r
1417 popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1423 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
\r
1425 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
\r
1427 // if (GetSelectedCount() == 1)
\r
1429 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
\r
1430 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
\r
1431 // popup.AppendMenu(MF_SEPARATOR, NULL);
\r
1436 if (GetSelectedCount() == 1)
\r
1438 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
\r
1439 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH);
\r
1441 if (GetSelectedCount() != 0)
\r
1443 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
\r
1444 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);
\r
1447 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
\r
1448 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);
\r
1451 if (GetSelectedCount() == 1)
\r
1453 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
\r
1455 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
\r
1458 str.LoadString(IDS_DELETE_BRANCHTAG);
\r
1459 if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )
\r
1462 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);
\r
1463 popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE);
\r
1465 else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )
\r
1468 submenu.CreatePopupMenu();
\r
1469 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
\r
1471 submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("..."));
\r
1474 popup.AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT) submenu.m_hMenu,str);
\r
1482 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
\r
1483 // DialogEnableWindow(IDOK, FALSE);
\r
1484 // SetPromptApp(&theApp);
\r
1486 this->ContextMenuAction(cmd, FirstSelect, LastSelect);
\r
1488 // EnableOKButton();
\r
1489 } // if (popup.CreatePopupMenu())
\r
1493 bool CGitLogListBase::IsSelectionContinuous()
\r
1495 if ( GetSelectedCount()==1 )
\r
1497 // if only one revision is selected, the selection is of course
\r
1502 POSITION pos = GetFirstSelectedItemPosition();
\r
1503 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
\r
1506 int itemindex = GetNextSelectedItem(pos);
\r
1509 int nextindex = GetNextSelectedItem(pos);
\r
1510 if (nextindex - itemindex > 1)
\r
1512 bContinuous = false;
\r
1515 itemindex = nextindex;
\r
1518 return bContinuous;
\r
1521 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
\r
1524 CString sClipdata;
\r
1525 POSITION pos = GetFirstSelectedItemPosition();
\r
1529 sRev.LoadString(IDS_LOG_REVISION);
\r
1531 sAuthor.LoadString(IDS_LOG_AUTHOR);
\r
1533 sDate.LoadString(IDS_LOG_DATE);
\r
1535 sMessage.LoadString(IDS_LOG_MESSAGE);
\r
1538 CString sLogCopyText;
\r
1540 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
\r
1544 //pLogEntry->m_Files
\r
1545 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
\r
1547 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)
\r
1549 sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();
\r
1550 sPaths += _T("\r\n");
\r
1553 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"),
\r
1554 (LPCTSTR)sRev, pLogEntry->m_CommitHash,
\r
1555 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,
\r
1557 (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
\r
1558 (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,
\r
1560 sClipdata += sLogCopyText;
\r
1563 sClipdata += pLogEntry->m_CommitHash;
\r
1568 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
\r
1573 void CGitLogListBase::DiffSelectedRevWithPrevious()
\r
1575 if (m_bThreadRunning)
\r
1578 int FirstSelect=-1, LastSelect=-1;
\r
1579 POSITION pos = GetFirstSelectedItemPosition();
\r
1580 FirstSelect = GetNextSelectedItem(pos);
\r
1583 LastSelect = GetNextSelectedItem(pos);
\r
1586 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect);
\r
1589 UpdateLogInfoLabel();
\r
1590 int selIndex = m_LogList.GetSelectionMark();
\r
1593 int selCount = m_LogList.GetSelectedCount();
\r
1594 if (selCount != 1)
\r
1597 // Find selected entry in the log list
\r
1598 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
\r
1599 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
\r
1600 long rev1 = pLogEntry->Rev;
\r
1601 long rev2 = rev1-1;
\r
1602 CTGitPath path = m_path;
\r
1604 // See how many files under the relative root were changed in selected revision
\r
1606 LogChangedPath * changed = NULL;
\r
1607 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
\r
1609 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);
\r
1610 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
\r
1617 if (m_path.IsDirectory() && nChanged == 1)
\r
1619 // We're looking at the log for a directory and only one file under dir was changed in the revision
\r
1620 // Do diff on that file instead of whole directory
\r
1621 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
\r
1624 m_bCancelled = FALSE;
\r
1625 DialogEnableWindow(IDOK, FALSE);
\r
1626 SetPromptApp(&theApp);
\r
1627 theApp.DoWaitCursor(1);
\r
1629 if (PromptShown())
\r
1631 GitDiff diff(this, m_hWnd, true);
\r
1632 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
1633 diff.SetHEADPeg(m_LogRevision);
\r
1634 diff.ShowCompare(path, rev2, path, rev1);
\r
1638 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
1641 theApp.DoWaitCursor(-1);
\r
1646 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
\r
1648 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
\r
1651 if (pFindInfo->lvfi.flags & LVFI_PARAM)
\r
1653 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
\r
1655 if (pFindInfo->lvfi.psz == 0)
\r
1658 CString sCmp = pFindInfo->lvfi.psz;
\r
1660 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
\r
1662 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
\r
1663 sRev.Format(_T("%ld"), pLogEntry->Rev);
\r
1664 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
\r
1666 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
\r
1674 if (sCmp.Compare(sRev)==0)
\r
1681 if (pFindInfo->lvfi.flags & LVFI_WRAP)
\r
1683 for (int i=0; i<pFindInfo->iStart; ++i)
\r
1685 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
\r
1686 sRev.Format(_T("%ld"), pLogEntry->Rev);
\r
1687 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
\r
1689 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
\r
1697 if (sCmp.Compare(sRev)==0)
\r
1709 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
\r
1713 this->m_logEntries.ClearAll();
\r
1714 this->m_logEntries.ParserFromLog(path,-1,info,from,to);
\r
1716 //this->m_logEntries.ParserFromLog();
\r
1717 SetItemCountEx(this->m_logEntries.size());
\r
1719 this->m_arShownList.RemoveAll();
\r
1721 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1725 m_logEntries[m_logEntries.size()-i-1].m_IsFull=TRUE;
\r
1726 this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);
\r
1730 m_logEntries[i].m_IsFull=TRUE;
\r
1731 this->m_arShownList.Add(&m_logEntries[i]);
\r
1741 int CGitLogListBase::FillGitShortLog()
\r
1745 this->m_logEntries.ClearAll();
\r
1747 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
\r
1750 if(this->m_Path.IsEmpty())
\r
1753 path=&this->m_Path;
\r
1757 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
\r
1758 // if(this->m_bAllBranch)
\r
1759 mask |= m_ShowMask;
\r
1762 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev);
\r
1764 this->m_logEntries.FetchShortLog(path,m_StartRef,-1,mask);
\r
1766 //this->m_logEntries.ParserFromLog();
\r
1767 if(IsInWorkingThread())
\r
1768 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
\r
1770 SetItemCountEx(this->m_logEntries.size());
\r
1772 this->m_arShownList.RemoveAll();
\r
1774 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1776 if(i>0 || m_logEntries[i].m_CommitHash != GIT_REV_ZERO)
\r
1777 m_logEntries[i].m_Subject=_T("parser...");
\r
1779 if(this->m_IsOldFirst)
\r
1781 this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-1-i]);
\r
1785 this->m_arShownList.Add(&m_logEntries[i]);
\r
1791 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
\r
1793 // Skip Ctrl-C when copying text out of the log message or search filter
\r
1794 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
\r
1795 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
\r
1797 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
\r
1799 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
\r
1801 DiffSelectedRevWithPrevious();
\r
1806 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
\r
1808 DiffSelectedFile();
\r
1815 if (m_hAccel && !bSkipAccelerator)
\r
1817 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
\r
1823 //m_tooltips.RelayEvent(pMsg);
\r
1824 return __super::PreTranslateMessage(pMsg);
\r
1827 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
\r
1829 // a double click on an entry in the revision list has happened
\r
1832 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
\r
1833 DiffSelectedRevWithPrevious();
\r
1836 int CGitLogListBase::FetchLogAsync(void * data)
\r
1839 m_bExitThread=FALSE;
\r
1840 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
1841 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
1842 m_LoadingThread = AfxBeginThread(LogThreadEntry, this);
\r
1843 if (m_LoadingThread ==NULL)
\r
1845 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
1846 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
1847 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
1853 //this is the thread function which calls the subversion function
\r
1854 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
\r
1856 return ((CGitLogListBase*)pVoid)->LogThread();
\r
1859 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
\r
1862 oldest=CTime::GetCurrentTime();
\r
1863 latest=CTime(1971,1,2,0,0,0);
\r
1864 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
1866 if(m_logEntries[i].m_AuthorDate.GetTime() < oldest.GetTime())
\r
1867 oldest = m_logEntries[i].m_AuthorDate.GetTime();
\r
1869 if(m_logEntries[i].m_AuthorDate.GetTime() > latest.GetTime())
\r
1870 latest = m_logEntries[i].m_AuthorDate.GetTime();
\r
1875 //Helper class for FetchFullLogInfo()
\r
1876 class CGitCall_FetchFullLogInfo : public CGitCall
\r
1879 CGitCall_FetchFullLogInfo(CGitLogListBase* ploglist):m_ploglist(ploglist),m_CollectedCount(0){}
\r
1880 virtual bool OnOutputData(const BYTE* data, size_t size)
\r
1883 return m_ploglist->m_bExitThread;
\r
1884 //Add received data to byte collector
\r
1885 m_ByteCollector.append(data,size);
\r
1887 //Find loginfo endmarker
\r
1888 static const BYTE dataToFind[]={0,0,'#','<'};
\r
1889 int found=m_ByteCollector.findData(dataToFind,4);
\r
1891 return m_ploglist->m_bExitThread;//Not found
\r
1892 found+=2;//Position after loginfo end-marker
\r
1894 //Prepare data for OnLogInfo and call it
\r
1895 BYTE_VECTOR logInfo;
\r
1896 logInfo.append(&*m_ByteCollector.begin(),found);
\r
1897 OnLogInfo(logInfo);
\r
1899 //Remove loginfo from bytecollector
\r
1900 m_ByteCollector.erase(m_ByteCollector.begin(),m_ByteCollector.begin()+found);
\r
1902 return m_ploglist->m_bExitThread;
\r
1904 virtual void OnEnd()
\r
1906 //Rest should be a complete log line.
\r
1907 if(!m_ByteCollector.empty())
\r
1908 OnLogInfo(m_ByteCollector);
\r
1912 void OnLogInfo(BYTE_VECTOR& logInfo)
\r
1915 fullRev.ParserFromLog(logInfo);
\r
1916 MAP_HASH_REV::iterator itRev=m_ploglist->m_logEntries.m_HashMap.find(fullRev.m_CommitHash);
\r
1917 if(itRev==m_ploglist->m_logEntries.m_HashMap.end())
\r
1919 //Should not occur, only when Git-tree updated in the mean time. (Race condition)
\r
1923 int rev=itRev->second;
\r
1924 GitRev* revInVector=&m_ploglist->m_logEntries[rev];
\r
1927 if(revInVector->m_IsFull)
\r
1930 if(!m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev]))
\r
1932 ++m_CollectedCount;
\r
1933 InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsUpdateing,FALSE);
\r
1934 InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsFull,TRUE);
\r
1935 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);
\r
1939 // fullRev.m_IsUpdateing=TRUE;
\r
1940 // fullRev.m_IsFull=TRUE;
\r
1943 if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE))
\r
1944 return;//Cannot update this row now. Ignore.
\r
1945 TCHAR oldmark=revInVector->m_Mark;
\r
1946 GIT_REV_LIST oldlist=revInVector->m_ParentHash;
\r
1947 // CString oldhash=m_CommitHash;
\r
1949 //Parse new rev info
\r
1950 revInVector->ParserFromLog(logInfo);
\r
1953 revInVector->m_Mark=oldmark; //parser full log will cause old mark overwrited.
\r
1954 //So we need keep old bound mark.
\r
1955 revInVector->m_ParentHash=oldlist;
\r
1958 m_ploglist->m_LogCache.AddCacheEntry(*revInVector);
\r
1961 InterlockedExchange(&revInVector->m_IsFull,TRUE);
\r
1962 InterlockedExchange(&revInVector->m_IsUpdateing,FALSE);
\r
1964 //Notify listcontrol and update progress bar
\r
1965 ++m_CollectedCount;
\r
1967 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);
\r
1969 DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30;
\r
1970 if(percent == GITLOG_END)
\r
1971 percent = GITLOG_END -1;
\r
1973 ::PostMessage(m_ploglist->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
\r
1976 CGitLogListBase* m_ploglist;
\r
1977 BYTE_VECTOR m_ByteCollector;
\r
1978 int m_CollectedCount;
\r
1982 void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to)
\r
1984 CGitCall_FetchFullLogInfo fetcher(this);
\r
1986 CGit::LOG_INFO_FULL_DIFF|
\r
1987 CGit::LOG_INFO_STAT|
\r
1988 CGit::LOG_INFO_FILESTATE|
\r
1989 CGit::LOG_INFO_DETECT_COPYRENAME|
\r
1990 CGit::LOG_INFO_SHOW_MERGEDFILE |
\r
1994 if(this->m_Path.IsEmpty())
\r
1997 path=&this->m_Path;
\r
1999 g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to);
\r
2002 void CGitLogListBase::FetchLastLogInfo()
\r
2004 unsigned int updated=0;
\r
2008 for(unsigned int i=0;i<m_logEntries.size();i++)
\r
2010 if(m_logEntries[i].m_IsFull)
\r
2013 if(m_LogCache.GetCacheData(m_logEntries[i]))
\r
2015 if(!m_logEntries.FetchFullInfo(i))
\r
2019 m_LogCache.AddCacheEntry(m_logEntries[i]);
\r
2024 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);
\r
2025 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);
\r
2028 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
\r
2032 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
2033 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2040 UINT CGitLogListBase::LogThread()
\r
2043 // if(m_ProcCallBack)
\r
2044 // m_ProcCallBack(m_ProcData,GITLOG_START);
\r
2045 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
\r
2047 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
2048 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
2050 //does the user force the cache to refresh (shift or control key down)?
\r
2051 bool refresh = (GetKeyState (VK_CONTROL) < 0)
\r
2052 || (GetKeyState (VK_SHIFT) < 0);
\r
2054 //disable the "Get All" button while we're receiving
\r
2057 FillGitShortLog();
\r
2059 if(this->m_bExitThread)
\r
2061 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
2062 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2065 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2066 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0);
\r
2068 int start=0; CString firstcommit,lastcommit;
\r
2070 for(int i=0;i<m_logEntries.size();i++)
\r
2072 if( i==0 && m_logEntries[i].m_CommitHash == GIT_REV_ZERO)
\r
2075 start=this->m_logEntries[i].ParserFromLog(m_logEntries.m_RawlogData,start);
\r
2076 m_logEntries.m_HashMap[m_logEntries[i].m_CommitHash]=i;
\r
2078 if(m_LogCache.GetCacheData(m_logEntries[i]))
\r
2080 if(firstcommit.IsEmpty())
\r
2081 firstcommit=m_logEntries[i].m_CommitHash;
\r
2082 lastcommit=m_logEntries[i].m_CommitHash;
\r
2086 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);
\r
2087 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);
\r
2092 if(start>=m_logEntries.m_RawlogData.size())
\r
2095 int percent=i*30/m_logEntries.size() + GITLOG_START+1;
\r
2097 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0);
\r
2098 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0);
\r
2100 if(this->m_bExitThread)
\r
2102 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
2103 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2107 if(!lastcommit.IsEmpty())
\r
2108 FetchFullLogInfo(lastcommit,firstcommit);
\r
2110 this->FetchLastLogInfo();
\r
2113 RedrawItems(0, m_arShownList.GetCount());
\r
2114 // SetRedraw(false);
\r
2115 // ResizeAllListCtrlCols();
\r
2116 // SetRedraw(true);
\r
2118 if ( m_pStoreSelection )
\r
2120 // Deleting the instance will restore the
\r
2121 // selection of the CLogDlg.
\r
2122 delete m_pStoreSelection;
\r
2123 m_pStoreSelection = NULL;
\r
2127 // If no selection has been set then this must be the first time
\r
2128 // the revisions are shown. Let's preselect the topmost revision.
\r
2129 if ( GetItemCount()>0 )
\r
2131 SetSelectionMark(0);
\r
2132 SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
\r
2139 //FetchFullLogInfo();
\r
2140 //FetchFullLogInfoOrig();
\r
2141 //RefreshCursor();
\r
2142 // make sure the filter is applied (if any) now, after we refreshed/fetched
\r
2143 // the log messages
\r
2145 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
\r
2147 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
2152 void CGitLogListBase::Refresh()
\r
2154 m_bExitThread=TRUE;
\r
2155 if(m_LoadingThread!=NULL)
\r
2157 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
\r
2158 if(ret == WAIT_TIMEOUT)
\r
2159 TerminateThread();
\r
2164 //Update branch and Tag info
\r
2166 //Assume Thread have exited
\r
2167 //if(!m_bThreadRunning)
\r
2169 this->SetItemCountEx(0);
\r
2170 m_logEntries.clear();
\r
2171 m_bExitThread=FALSE;
\r
2172 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
2173 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
2174 if (AfxBeginThread(LogThreadEntry, this)==NULL)
\r
2176 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
2177 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2178 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
2180 m_sFilterText.Empty();
\r
2181 m_From=CTime(1970,1,2,0,0,0);
\r
2182 m_To=CTime::GetCurrentTime();
\r
2185 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
\r
2189 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
\r
2191 type |= tr1::regex_constants::icase;
\r
2192 pat = tr1::wregex(regexp_str, type);
\r
2195 catch (exception) {}
\r
2199 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)
\r
2202 pShownlist->RemoveAll();
\r
2203 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
\r
2204 bool bRegex = false;
\r
2205 if (m_bFilterWithRegex)
\r
2206 bRegex = ValidateRegexp(m_sFilterText, pat, false);
\r
2208 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
\r
2210 for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
2212 if ((bRegex)&&(m_bFilterWithRegex))
\r
2215 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
\r
2217 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
\r
2218 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
\r
2220 pShownlist->Add(m_logEntries[i]);
\r
2225 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
\r
2227 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Subject);
\r
2228 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Subject), pat, flags)&&IsEntryInDateRange(i))
\r
2230 pShownlist->Add(&m_logEntries[i]);
\r
2234 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Body);
\r
2235 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Body), pat, flags)&&IsEntryInDateRange(i))
\r
2237 pShownlist->Add(&m_logEntries[i]);
\r
2242 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
\r
2244 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
\r
2246 bool bGoing = true;
\r
2247 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
\r
2249 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
\r
2250 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))
\r
2252 pShownlist->Add(m_logEntries[i]);
\r
2256 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))
\r
2258 pShownlist->Add(m_logEntries[i]);
\r
2262 if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))
\r
2264 pShownlist->Add(m_logEntries[i]);
\r
2273 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
\r
2275 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_AuthorName), pat, flags)&&IsEntryInDateRange(i))
\r
2277 pShownlist->Add(&m_logEntries[i]);
\r
2281 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
\r
2283 sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash);
\r
2284 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
\r
2286 pShownlist->Add(&m_logEntries[i]);
\r
2293 CString find = m_sFilterText;
\r
2296 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
\r
2298 CString sBugIDs = m_logEntries[i]->sBugIDs;
\r
2300 sBugIDs = sBugIDs.MakeLower();
\r
2301 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
2303 pShownlist->Add(m_logEntries[i]);
\r
2308 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
\r
2310 CString msg = m_logEntries[i].m_Subject;
\r
2312 msg = msg.MakeLower();
\r
2313 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
2315 pShownlist->Add(&m_logEntries[i]);
\r
2318 msg = m_logEntries[i].m_Body;
\r
2320 msg = msg.MakeLower();
\r
2321 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
2323 pShownlist->Add(&m_logEntries[i]);
\r
2328 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
\r
2330 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
\r
2332 bool bGoing = true;
\r
2333 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
\r
2335 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
\r
2336 CString path = cpath->sCopyFromPath;
\r
2338 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
2340 pShownlist->Add(m_logEntries[i]);
\r
2344 path = cpath->sPath;
\r
2346 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
2348 pShownlist->Add(m_logEntries[i]);
\r
2352 path = cpath->GetAction();
\r
2354 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
\r
2356 pShownlist->Add(m_logEntries[i]);
\r
2363 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
\r
2365 CString msg = m_logEntries[i].m_AuthorName;
\r
2366 msg = msg.MakeLower();
\r
2367 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
2369 pShownlist->Add(&m_logEntries[i]);
\r
2373 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
\r
2375 sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash);
\r
2376 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
\r
2378 pShownlist->Add(&m_logEntries[i]);
\r
2382 } // else (from if (bRegex))
\r
2383 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
2387 BOOL CGitLogListBase::IsEntryInDateRange(int i)
\r
2389 __time64_t time = m_logEntries[i].m_AuthorDate.GetTime();
\r
2390 if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))
\r
2397 void CGitLogListBase::StartFilter()
\r
2399 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
2400 RecalculateShownList(&m_arShownList);
\r
2401 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2405 SetItemCountEx(ShownCountWithStopped());
\r
2406 RedrawItems(0, ShownCountWithStopped());
\r
2408 //ResizeAllListCtrlCols();
\r
2413 void CGitLogListBase::RemoveFilter()
\r
2416 InterlockedExchange(&m_bNoDispUpdates, TRUE);
\r
2418 m_arShownList.RemoveAll();
\r
2420 // reset the time filter too
\r
2422 m_timFrom = (__time64_t(m_tFrom));
\r
2423 m_timTo = (__time64_t(m_tTo));
\r
2424 m_DateFrom.SetTime(&m_timFrom);
\r
2425 m_DateTo.SetTime(&m_timTo);
\r
2426 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
\r
2427 m_DateTo.SetRange(&m_timFrom, &m_timTo);
\r
2430 for (DWORD i=0; i<m_logEntries.size(); ++i)
\r
2432 if(this->m_IsOldFirst)
\r
2434 m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);
\r
2437 m_arShownList.Add(&m_logEntries[i]);
\r
2440 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2442 SetItemCountEx(ShownCountWithStopped());
\r
2443 RedrawItems(0, ShownCountWithStopped());
\r
2444 // SetRedraw(false);
\r
2445 // ResizeAllListCtrlCols();
\r
2446 // SetRedraw(true);
\r
2448 InterlockedExchange(&m_bNoDispUpdates, FALSE);
\r
2451 void CGitLogListBase::Clear()
\r
2453 m_arShownList.RemoveAll();
\r
2456 m_logEntries.ClearAll();
\r
2460 void CGitLogListBase::OnDestroy()
\r
2462 // save the column widths to the registry
\r
2463 SaveColumnWidths();
\r
2465 if(this->m_bThreadRunning)
\r
2467 this->m_bExitThread=true;
\r
2468 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
\r
2469 if(ret == WAIT_TIMEOUT)
\r
2470 TerminateThread();
\r
2472 while(m_LogCache.SaveCache())
\r
2474 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
\r
2475 MB_YESNO) == IDNO)
\r
2478 CHintListCtrl::OnDestroy();
\r
2481 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
\r
2484 int i=(int)wParam;
\r
2485 this->GetItemRect(i,&rect,LVIR_BOUNDS);
\r
2486 this->InvalidateRect(rect);
\r
2491 * Save column widths to the registry
\r
2493 void CGitLogListBase::SaveColumnWidths()
\r
2495 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
\r
2498 int numcols = pHdrCtrl->GetItemCount();
\r
2499 for (int col = 0; col < numcols; col++)
\r
2501 int width = GetColumnWidth( col );
\r
2503 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
\r
2504 CRegDWORD regwidth(regentry, 0);
\r
2505 regwidth = width; // this writes it to reg
\r
2510 int CGitLogListBase::GetHeadIndex()
\r
2512 if(m_HeadHash.IsEmpty())
\r
2515 for(int i=0;i<m_arShownList.GetCount();i++)
\r
2517 GitRev *pRev = (GitRev*)m_arShownList[i];
\r
2520 if(pRev->m_CommitHash == m_HeadHash )
\r