Add Merge command at log context menu
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob6ca345e2e2af1a5d8482bcf5a77faba3acc8c61f
1 // GitLogList.cpp : implementation file
2 //
3 /*
4 Description: qgit revision list view
6 Author: Marco Costalba (C) 2005-2007
8 Copyright: See COPYING file that comes with this distribution
11 #include "stdafx.h"
12 #include "GitLogListBase.h"
13 #include "GitRev.h"
14 //#include "VssStyle.h"
15 #include "IconMenu.h"
16 // CGitLogListBase
17 #include "cursor.h"
18 #include "InputDlg.h"
19 #include "PropDlg.h"
20 #include "SVNProgressDlg.h"
21 #include "ProgressDlg.h"
22 //#include "RepositoryBrowser.h"
23 //#include "CopyDlg.h"
24 //#include "StatGraphDlg.h"
25 #include "Logdlg.h"
26 #include "MessageBox.h"
27 #include "Registry.h"
28 #include "AppUtils.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "UnicodeUtils.h"
32 #include "TempFile.h"
33 //#include "GitInfo.h"
34 //#include "GitDiff.h"
35 #include "IconMenu.h"
36 //#include "RevisionRangeDlg.h"
37 //#include "BrowseFolder.h"
38 //#include "BlameDlg.h"
39 //#include "Blame.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"
49 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
51 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
53 CGitLogListBase::CGitLogListBase():CHintListCtrl()
54 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
55 ,m_nSearchIndex(0)
56 ,m_bNoDispUpdates(FALSE)
57 , m_bThreadRunning(FALSE)
58 , m_bStrictStopped(false)
59 , m_pStoreSelection(NULL)
60 , m_nSelectedFilter(LOGFILTER_ALL)
61 , m_bVista(false)
62 , m_bShowWC(false)
63 , m_logEntries(&m_LogCache)
64 , m_pFindDialog(NULL)
66 // use the default GUI font, create a copy of it and
67 // change the copy to BOLD (leave the rest of the font
68 // the same)
69 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
70 LOGFONT lf = {0};
71 GetObject(hFont, sizeof(LOGFONT), &lf);
72 lf.lfWeight = FW_BOLD;
73 m_boldFont = CreateFontIndirect(&lf);
75 m_bShowBugtraqColumn=0;
77 m_IsIDReplaceAction=FALSE;
79 this->m_critSec.Init();
80 m_wcRev.m_CommitHash.Empty();
81 m_wcRev.m_Subject=_T("Working dir changes");
82 m_wcRev.m_ParentHash.clear();
83 m_wcRev.m_Mark=_T('-');
84 m_wcRev.m_IsUpdateing=FALSE;
85 m_wcRev.m_IsFull = TRUE;
87 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
88 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
89 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
90 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
92 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
94 g_Git.GetMapHashToFriendName(m_HashMap);
95 m_CurrentBranch=g_Git.GetCurrentBranch();
96 this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40);
98 m_From=CTime(1970,1,2,0,0,0);
99 m_To=CTime::GetCurrentTime();
100 m_ShowMask = 0;
101 m_LoadingThread = NULL;
103 InterlockedExchange(&m_bExitThread,FALSE);
104 m_IsOldFirst = FALSE;
105 m_IsRebaseReplaceGraph = FALSE;
108 for(int i=0;i<Lanes::COLORS_NUM;i++)
110 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
112 // get short/long datetime setting from registry
113 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
114 if ( RegUseShortDateFormat )
116 m_DateFormat = DATE_SHORTDATE;
118 else
120 m_DateFormat = DATE_LONGDATE;
122 // get relative time display setting from registry
123 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
124 m_bRelativeTimes = (regRelativeTimes != 0);
125 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
127 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
128 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
129 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
130 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
132 OSVERSIONINFOEX inf;
133 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
134 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
135 GetVersionEx((OSVERSIONINFO *)&inf);
136 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
137 m_bVista = (fullver >= 0x0600);
139 m_ColumnRegKey=_T("log");
142 CGitLogListBase::~CGitLogListBase()
144 InterlockedExchange(&m_bNoDispUpdates, TRUE);
146 DestroyIcon(m_hModifiedIcon);
147 DestroyIcon(m_hReplacedIcon);
148 DestroyIcon(m_hAddedIcon);
149 DestroyIcon(m_hDeletedIcon);
150 m_logEntries.ClearAll();
152 if (m_boldFont)
153 DeleteObject(m_boldFont);
155 if ( m_pStoreSelection )
157 delete m_pStoreSelection;
158 m_pStoreSelection = NULL;
161 SafeTerminateThread();
165 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
166 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
167 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
168 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
169 ON_WM_CONTEXTMENU()
170 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
171 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
172 ON_WM_CREATE()
173 ON_WM_DESTROY()
174 ON_MESSAGE(MSG_LOADED,OnLoad)
175 ON_WM_MEASUREITEM()
176 ON_WM_MEASUREITEM_REFLECT()
177 END_MESSAGE_MAP()
179 void CGitLogListBase::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
181 // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ
183 CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
186 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
188 //if (m_nRowHeight>0)
190 lpMeasureItemStruct->itemHeight = 50;
194 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
196 PreSubclassWindow();
197 return CHintListCtrl::OnCreate(lpCreateStruct);
200 void CGitLogListBase::PreSubclassWindow()
202 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
203 // load the icons for the action columns
204 // m_Theme.Open(m_hWnd, L"ListView");
205 m_Theme.Open(m_hWnd, L"Explorer::ListView;ListView");
206 m_Theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);
207 CHintListCtrl::PreSubclassWindow();
210 void CGitLogListBase::InsertGitColumn()
212 CString temp;
214 int c = GetHeaderCtrl()->GetItemCount()-1;
216 while (c>=0)
217 DeleteColumn(c--);
218 temp.LoadString(IDS_LOG_GRAPH);
220 if(m_IsRebaseReplaceGraph)
222 temp=_T("Rebase");
224 else
226 temp.LoadString(IDS_LOG_GRAPH);
228 InsertColumn(this->LOGLIST_GRAPH, temp);
230 #if 0
231 // make the revision column right aligned
232 LVCOLUMN Column;
233 Column.mask = LVCF_FMT;
234 Column.fmt = LVCFMT_RIGHT;
235 SetColumn(0, &Column);
236 #endif
237 // CString log;
238 // g_Git.GetLog(log);
240 if(m_IsIDReplaceAction)
242 temp.LoadString(IDS_LOG_ID);
243 InsertColumn(this->LOGLIST_ACTION, temp);
245 else
247 temp.LoadString(IDS_LOG_ACTIONS);
248 InsertColumn(this->LOGLIST_ACTION, temp);
250 temp.LoadString(IDS_LOG_MESSAGE);
251 InsertColumn(this->LOGLIST_MESSAGE, temp);
253 temp.LoadString(IDS_LOG_AUTHOR);
254 InsertColumn(this->LOGLIST_AUTHOR, temp);
256 temp.LoadString(IDS_LOG_DATE);
257 InsertColumn(this->LOGLIST_DATE, temp);
260 if (m_bShowBugtraqColumn)
262 // temp = m_ProjectProperties.sLabel;
263 if (temp.IsEmpty())
264 temp.LoadString(IDS_LOG_BUGIDS);
265 InsertColumn(this->LOGLIST_BUG, temp);
269 SetRedraw(false);
270 ResizeAllListCtrlCols();
271 SetRedraw(true);
276 * Resizes all columns in a list control to values in registry.
278 void CGitLogListBase::ResizeAllListCtrlCols()
280 // column max and min widths to allow
281 static const int nMinimumWidth = 10;
282 static const int nMaximumWidth = 1000;
283 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
284 if (pHdrCtrl)
286 int numcols = pHdrCtrl->GetItemCount();
287 for (int col = 0; col < numcols; col++)
289 // get width for this col last time from registry
290 CString regentry;
291 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
292 CRegDWORD regwidth(regentry, 0);
293 int cx = regwidth;
294 if ( cx == 0 )
296 // no saved value, setup sensible defaults
297 if (col == this->LOGLIST_MESSAGE)
299 cx = LOGLIST_MESSAGE_MIN;
301 else
303 cx = ICONITEMBORDER+16*4;
306 if (cx < nMinimumWidth)
308 cx = nMinimumWidth;
309 } else if (cx > nMaximumWidth)
311 cx = nMaximumWidth;
314 SetColumnWidth(col, cx);
321 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)
323 //TRACE(_T("%s %s\r\n"),ref,prefix);
324 if(ref.Left(prefix.GetLength()) == prefix)
326 shortname = ref.Right(ref.GetLength()-prefix.GetLength());
327 if(shortname.Right(3)==_T("^{}"))
328 shortname=shortname.Left(shortname.GetLength()-3);
329 return TRUE;
331 return FALSE;
334 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)
336 // HBRUSH brush;
337 LVITEM rItem;
338 SecureZeroMemory(&rItem, sizeof(LVITEM));
339 rItem.mask = LVIF_STATE;
340 rItem.iItem = Index;
341 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
342 GetItem(&rItem);
344 GitRev* pLogEntry = (GitRev*)m_arShownList.GetAt(Index);
345 HBRUSH brush = NULL;
348 if (m_Theme.IsAppThemed() && m_bVista)
350 int state = LISS_NORMAL;
351 if (rItem.state & LVIS_SELECTED)
353 if (::GetFocus() == m_hWnd)
354 state |= LISS_SELECTED;
355 else
356 state |= LISS_SELECTEDNOTFOCUS;
358 else
360 if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
361 brush = ::CreateSolidBrush(RGB(156,156,156));
362 else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
363 brush = ::CreateSolidBrush(RGB(200,200,128));
366 if (brush != NULL)
368 ::FillRect(hdc, &rect, brush);
369 ::DeleteObject(brush);
371 else
373 if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTITEM, state))
374 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);
376 CRect rectDraw = rect;
377 if(rItem.state & LVIS_SELECTED)
378 rectDraw.InflateRect(1,0);
379 else
380 rectDraw.InflateRect(1,1);
382 m_Theme.DrawBackground(hdc, LVP_LISTITEM, state, rectDraw, &rect);
385 else
388 if (rItem.state & LVIS_SELECTED)
390 if (::GetFocus() == m_hWnd)
391 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
392 else
393 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
395 else
397 //if (pLogEntry->bCopiedSelf)
398 // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));
399 //else
400 if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
401 brush = ::CreateSolidBrush(RGB(156,156,156));
402 else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
403 brush = ::CreateSolidBrush(RGB(200,200,128));
404 else
405 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
407 if (brush == NULL)
408 return;
410 ::FillRect(hdc, &rect, brush);
411 ::DeleteObject(brush);
416 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)
418 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
419 CRect rt=rect;
420 LVITEM rItem;
421 SecureZeroMemory(&rItem, sizeof(LVITEM));
422 rItem.mask = LVIF_STATE;
423 rItem.iItem = index;
424 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
425 GetItem(&rItem);
427 for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)
429 CString str;
430 str=m_HashMap[data->m_CommitHash][i];
432 CString shortname;
433 HBRUSH brush = 0;
434 shortname = _T("");
435 COLORREF colRef = 0;
437 //Determine label color
438 if(GetShortName(str,shortname,_T("refs/heads/")))
440 if( shortname == m_CurrentBranch )
441 colRef = m_Colors.GetColor(CColors::CurrentBranch);
442 else
443 colRef = m_Colors.GetColor(CColors::LocalBranch);
445 }else if(GetShortName(str,shortname,_T("refs/remotes/")))
447 colRef = m_Colors.GetColor(CColors::RemoteBranch);
449 else if(GetShortName(str,shortname,_T("refs/tags/")))
451 colRef = m_Colors.GetColor(CColors::Tag);
453 else if(GetShortName(str,shortname,_T("refs/stash")))
455 colRef = m_Colors.GetColor(CColors::Stash);
456 shortname=_T("stash");
459 //When row selected, ajust label color
460 if (!(m_Theme.IsAppThemed() && m_bVista))
461 if (rItem.state & LVIS_SELECTED)
462 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
464 brush = ::CreateSolidBrush(colRef);
467 if(!shortname.IsEmpty())
469 SIZE size;
470 memset(&size,0,sizeof(SIZE));
471 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
473 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
474 rt.right+=8;
476 //Fill interior of ref label
477 ::FillRect(hdc, &rt, brush);
479 //Draw edge of label
480 CDC W_Dc;
481 W_Dc.Attach(hdc);
483 CRect rectEdge = rt;
485 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));
486 rectEdge.DeflateRect(1,1);
487 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));
489 W_Dc.Detach();
491 //Draw text inside label
492 if (m_Theme.IsAppThemed() && m_bVista)
494 int txtState = LISS_NORMAL;
495 if (rItem.state & LVIS_SELECTED)
496 txtState = LISS_SELECTED;
498 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, shortname, -1, DT_CENTER | DT_SINGLELINE | DT_VCENTER, 0, &rt);
500 else
502 if (rItem.state & LVIS_SELECTED)
504 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
505 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
506 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
507 ::SetTextColor(hdc,clrOld);
508 }else
510 ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
515 //::MoveToEx(hdc,rt.left,rt.top,NULL);
516 //::LineTo(hdc,rt.right,rt.top);
517 //::LineTo(hdc,rt.right,rt.bottom);
518 //::LineTo(hdc,rt.left,rt.bottom);
519 //::LineTo(hdc,rt.left,rt.top);
522 rt.left=rt.right+1;
524 if(brush)
525 ::DeleteObject(brush);
527 rt.right=rect.right;
529 if (m_Theme.IsAppThemed() && m_bVista)
531 int txtState = LISS_NORMAL;
532 if (rItem.state & LVIS_SELECTED)
533 txtState = LISS_SELECTED;
535 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, data->m_Subject, -1, DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);
537 else
539 if (rItem.state & LVIS_SELECTED)
541 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
542 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);
543 ::SetTextColor(hdc,clrOld);
544 }else
546 ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);
551 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
553 // Returns ((256 - amount)*col1 + amount*col2) / 256;
554 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
555 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
556 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
559 Gdiplus::Color GetGdiColor(COLORREF col)
561 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
563 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
564 const COLORREF& col,const COLORREF& activeColor, int top
567 int h = laneHeight / 2;
568 int m = (x1 + x2) / 2;
569 int r = (x2 - x1) / 3;
570 int d = 2 * r;
572 #define P_CENTER m , h+top
573 #define P_0 x2, h+top
574 #define P_90 m , 0+top
575 #define P_180 x1, h+top
576 #define P_270 m , 2 * h+top
577 #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d
580 #define DELTA_UR_B 2*(x1 - m), 2*h +top
581 #define DELTA_UR_E 0*16, 90*16 +top // -,
583 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
584 #define DELTA_DR_E 270*16, 90*16 +top // -'
586 #define DELTA_UL_B 2*(x2 - m), 2*h +top
587 #define DELTA_UL_E 90*16, 90*16 +top // ,-
589 #define DELTA_DL_B 2*(x2 - m),2*-h +top
590 #define DELTA_DL_E 180*16, 90*16 // '-
592 #define CENTER_UR x1, 2*h, 225
593 #define CENTER_DR x1, 0 , 135
594 #define CENTER_UL x2, 2*h, 315
595 #define CENTER_DL x2, 0 , 45
598 Gdiplus::Graphics graphics( hdc );
600 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeAntiAlias);
602 // arc
603 switch (type) {
604 case Lanes::JOIN:
605 case Lanes::JOIN_R:
606 case Lanes::HEAD:
607 case Lanes::HEAD_R:
609 Gdiplus::LinearGradientBrush gradient(
610 Gdiplus::Point(x1-2, h+top-2),
611 Gdiplus::Point(P_270),
612 GetGdiColor(activeColor),GetGdiColor(col));
615 Gdiplus::Pen mypen(&gradient,2);
616 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
618 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
619 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
620 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
622 break;
624 case Lanes::JOIN_L:
627 Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
630 graphics.DrawArc(&mypen,x1,top+h, x2-x1,laneHeight,270,90);
632 break;
634 case Lanes::TAIL:
635 case Lanes::TAIL_R:
638 Gdiplus::LinearGradientBrush gradient(
639 Gdiplus::Point(x1-2, h+top-2),
640 Gdiplus::Point(P_90),
641 GetGdiColor(activeColor),GetGdiColor(col));
644 Gdiplus::Pen mypen(&gradient,2);
646 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
649 #if 0
650 QConicalGradient gradient(CENTER_DR);
651 gradient.setColorAt(0.375, activeCol);
652 gradient.setColorAt(0.625, col);
653 myPen.setBrush(gradient);
654 p->setPen(myPen);
655 p->drawArc(P_CENTER, DELTA_DR);
656 #endif
657 break;
659 default:
660 break;
664 //static QPen myPen(Qt::black, 2); // fast path here
665 CPen pen;
666 pen.CreatePen(PS_SOLID,2,col);
667 //myPen.setColor(col);
668 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
670 Gdiplus::Pen myPen(GetGdiColor(col),2);
672 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeNone);
674 //p->setPen(myPen);
676 // vertical line
677 switch (type) {
678 case Lanes::ACTIVE:
679 case Lanes::NOT_ACTIVE:
680 case Lanes::MERGE_FORK:
681 case Lanes::MERGE_FORK_R:
682 case Lanes::MERGE_FORK_L:
683 case Lanes::JOIN:
684 case Lanes::JOIN_R:
685 case Lanes::JOIN_L:
686 case Lanes::CROSS:
687 //DrawLine(hdc,P_90,P_270);
688 graphics.DrawLine(&myPen,P_90,P_270);
689 //p->drawLine(P_90, P_270);
690 break;
691 case Lanes::HEAD_L:
692 case Lanes::BRANCH:
693 //DrawLine(hdc,P_CENTER,P_270);
694 graphics.DrawLine(&myPen,P_CENTER,P_270);
695 //p->drawLine(P_CENTER, P_270);
696 break;
697 case Lanes::TAIL_L:
698 case Lanes::INITIAL:
699 case Lanes::BOUNDARY:
700 case Lanes::BOUNDARY_C:
701 case Lanes::BOUNDARY_R:
702 case Lanes::BOUNDARY_L:
703 //DrawLine(hdc,P_90, P_CENTER);
704 graphics.DrawLine(&myPen,P_90,P_CENTER);
705 //p->drawLine(P_90, P_CENTER);
706 break;
707 default:
708 break;
711 myPen.SetColor(GetGdiColor(activeColor));
713 // horizontal line
714 switch (type) {
715 case Lanes::MERGE_FORK:
716 case Lanes::JOIN:
717 case Lanes::HEAD:
718 case Lanes::TAIL:
719 case Lanes::CROSS:
720 case Lanes::CROSS_EMPTY:
721 case Lanes::BOUNDARY_C:
722 //DrawLine(hdc,P_180,P_0);
723 graphics.DrawLine(&myPen,P_180,P_0);
724 //p->drawLine(P_180, P_0);
725 break;
726 case Lanes::MERGE_FORK_R:
727 case Lanes::BOUNDARY_R:
728 //DrawLine(hdc,P_180,P_CENTER);
729 graphics.DrawLine(&myPen,P_180,P_CENTER);
730 //p->drawLine(P_180, P_CENTER);
731 break;
732 case Lanes::MERGE_FORK_L:
733 case Lanes::HEAD_L:
734 case Lanes::TAIL_L:
735 case Lanes::BOUNDARY_L:
736 //DrawLine(hdc,P_CENTER,P_0);
737 graphics.DrawLine(&myPen,P_CENTER,P_0);
738 //p->drawLine(P_CENTER, P_0);
739 break;
740 default:
741 break;
744 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeAntiAlias);
746 CBrush brush;
747 brush.CreateSolidBrush(col);
748 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
749 // center symbol, e.g. rect or ellipse
750 switch (type) {
751 case Lanes::ACTIVE:
752 case Lanes::INITIAL:
753 case Lanes::BRANCH:
755 //p->setPen(Qt::NoPen);
756 //p->setBrush(col);
757 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeAntiAlias);
758 ::Ellipse(hdc, R_CENTER);
759 //p->drawEllipse(R_CENTER);
760 break;
761 case Lanes::MERGE_FORK:
762 case Lanes::MERGE_FORK_R:
763 case Lanes::MERGE_FORK_L:
764 //p->setPen(Qt::NoPen);
765 //p->setBrush(col);
766 //p->drawRect(R_CENTER);
767 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeNone);
768 Rectangle(hdc,R_CENTER);
769 break;
770 case Lanes::UNAPPLIED:
771 // Red minus sign
772 //p->setPen(Qt::NoPen);
773 //p->setBrush(Qt::red);
774 //p->drawRect(m - r, h - 1, d, 2);
775 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeNone);
776 ::Rectangle(hdc,m-r,h-1,d,2);
777 break;
778 case Lanes::APPLIED:
779 // Green plus sign
780 //p->setPen(Qt::NoPen);
781 //p->setBrush(DARK_GREEN);
782 //p->drawRect(m - r, h - 1, d, 2);
783 //p->drawRect(m - 1, h - r, 2, d);
784 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeNone);
785 ::Rectangle(hdc,m-r,h-1,d,2);
786 ::Rectangle(hdc,m-1,h-r,2,d);
787 break;
788 case Lanes::BOUNDARY:
789 //p->setBrush(back);
790 //p->drawEllipse(R_CENTER);
791 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeAntiAlias);
792 ::Ellipse(hdc, R_CENTER);
793 break;
794 case Lanes::BOUNDARY_C:
795 case Lanes::BOUNDARY_R:
796 case Lanes::BOUNDARY_L:
797 //p->setBrush(back);
798 //p->drawRect(R_CENTER);
799 graphics.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeNone);
800 ::Rectangle(hdc,R_CENTER);
801 break;
802 default:
803 break;
806 ::SelectObject(hdc,oldpen);
807 ::SelectObject(hdc,oldbrush);
808 #undef P_CENTER
809 #undef P_0
810 #undef P_90
811 #undef P_180
812 #undef P_270
813 #undef R_CENTER
816 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
818 //todo unfinished
819 // return;
820 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
821 if(data->m_CommitHash.IsEmpty())
822 return;
824 CRect rt=rect;
825 LVITEM rItem;
826 SecureZeroMemory(&rItem, sizeof(LVITEM));
827 rItem.mask = LVIF_STATE;
828 rItem.iItem = index;
829 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
830 GetItem(&rItem);
833 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
837 if (data->m_Lanes.size() == 0)
838 m_logEntries.setLane(data->m_CommitHash);
840 std::vector<int>& lanes=data->m_Lanes;
841 UINT laneNum = lanes.size();
842 UINT activeLane = 0;
843 for (UINT i = 0; i < laneNum; i++)
844 if (Lanes::isMerge(lanes[i])) {
845 activeLane = i;
846 break;
849 int x1 = 0, x2 = 0;
850 int maxWidth = rect.Width();
851 int lw = 3 * rect.Height() / 4; //laneWidth()
853 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
854 //if (opt.state & QStyle::State_Selected)
855 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
858 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
861 x1 = x2;
862 x2 += lw;
864 int ln = lanes[i];
865 if (ln == Lanes::EMPTY)
866 continue;
868 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
869 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
872 #if 0
873 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
875 x1 = x2;
876 x2 += lw;
878 int ln = lanes[i];
879 if (ln == Lanes::EMPTY)
880 continue;
882 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
883 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
885 if (ln == Lanes::CROSS) {
886 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
887 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
888 } else
889 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
891 #endif
895 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
898 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
899 // Take the default processing unless we set this to something else below.
900 *pResult = CDRF_DODEFAULT;
902 if (m_bNoDispUpdates)
903 return;
907 switch (pLVCD->nmcd.dwDrawStage)
909 case CDDS_PREPAINT:
911 *pResult = CDRF_NOTIFYITEMDRAW;
912 return;
914 break;
915 case CDDS_ITEMPREPAINT:
917 // This is the prepaint stage for an item. Here's where we set the
918 // item's text color.
920 // Tell Windows to send draw notifications for each subitem.
921 *pResult = CDRF_NOTIFYSUBITEMDRAW;
923 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
925 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
927 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
928 if (data)
930 #if 0
931 if (data->bCopiedSelf)
933 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
934 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
935 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
938 if (data->bCopies)
939 crText = m_Colors.GetColor(CColors::Modified);
940 #endif
941 if (data->m_Action& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
942 crText = RGB(128,128,128);
944 if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
945 pLVCD->clrTextBk = RGB(156,156,156);
946 else if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
947 pLVCD->clrTextBk = RGB(200,200,128);
948 else
949 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
951 if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_CURRENT)
953 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
954 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
957 if(data->m_CommitHash.ToString() == m_HeadHash)
959 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
960 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
963 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
964 // crText = GetSysColor(COLOR_GRAYTEXT);
966 if (data->m_CommitHash.IsEmpty())
968 //crText = GetSysColor(RGB(200,200,0));
969 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
970 // We changed the font, so we're returning CDRF_NEWFONT. This
971 // tells the control to recalculate the extent of the text.
972 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
976 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
978 if (m_bStrictStopped)
979 crText = GetSysColor(COLOR_GRAYTEXT);
981 // Store the color back in the NMLVCUSTOMDRAW struct.
982 pLVCD->clrText = crText;
983 return;
985 break;
986 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
988 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
990 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
993 if (pLVCD->iSubItem == LOGLIST_GRAPH)
995 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
997 CRect rect;
998 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
999 if(pLVCD->iSubItem == 0)
1001 CRect second;
1002 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem+1, LVIR_BOUNDS, second);
1003 rect.right=second.left;
1006 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1007 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1009 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
1010 if( !data ->m_CommitHash.IsEmpty())
1011 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1013 *pResult = CDRF_SKIPDEFAULT;
1014 return;
1019 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1021 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1023 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
1024 //if(!data->m_IsFull)
1026 //if(data->SafeFetchFullInfo(&g_Git))
1027 // this->Invalidate();
1028 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1031 if(m_HashMap[data->m_CommitHash].size()!=0)
1033 CRect rect;
1035 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1037 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1038 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1040 *pResult = CDRF_SKIPDEFAULT;
1041 return;
1048 if (pLVCD->iSubItem == 1)
1050 if(this->m_IsIDReplaceAction)
1052 *pResult = CDRF_DODEFAULT;
1053 return;
1055 *pResult = CDRF_DODEFAULT;
1057 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1058 return;
1060 int nIcons = 0;
1061 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1062 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1064 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
1065 CRect rect;
1066 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1067 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1068 // Get the selected state of the
1069 // item being drawn.
1071 // Fill the background
1072 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1074 // Draw the icon(s) into the compatible DC
1075 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
1076 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1077 nIcons++;
1079 if (pLogEntry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1080 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1081 nIcons++;
1083 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
1084 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1085 nIcons++;
1087 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
1088 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1089 nIcons++;
1090 *pResult = CDRF_SKIPDEFAULT;
1091 return;
1094 break;
1096 *pResult = CDRF_DODEFAULT;
1100 // CGitLogListBase message handlers
1102 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1104 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1106 // Create a pointer to the item
1107 LV_ITEM* pItem = &(pDispInfo)->item;
1109 // Do the list need text information?
1110 if (!(pItem->mask & LVIF_TEXT))
1111 return;
1113 // By default, clear text buffer.
1114 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1116 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1118 *pResult = 0;
1119 if (m_bNoDispUpdates || bOutOfRange)
1120 return;
1122 // Which item number?
1123 int itemid = pItem->iItem;
1124 GitRev * pLogEntry = NULL;
1125 if (itemid < m_arShownList.GetCount())
1126 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));
1128 CString temp;
1129 if(m_IsOldFirst)
1131 temp.Format(_T("%d"),pItem->iItem+1);
1133 }else
1135 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1138 // Which column?
1139 switch (pItem->iSubItem)
1141 case this->LOGLIST_GRAPH: //Graphic
1142 if (pLogEntry)
1144 if(this->m_IsRebaseReplaceGraph)
1146 CTGitPath path;
1147 path.m_Action=pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1149 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1152 break;
1153 case this->LOGLIST_ACTION: //action -- no text in the column
1154 if(this->m_IsIDReplaceAction)
1155 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1156 break;
1157 case this->LOGLIST_MESSAGE: //Message
1158 if (pLogEntry)
1159 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);
1160 break;
1161 case this->LOGLIST_AUTHOR: //Author
1162 if (pLogEntry)
1163 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);
1164 break;
1165 case this->LOGLIST_DATE: //Date
1166 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1167 lstrcpyn(pItem->pszText,
1168 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
1169 pItem->cchTextMax);
1170 break;
1172 case 5:
1174 break;
1175 default:
1176 ASSERT(false);
1180 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1183 int selIndex = GetSelectionMark();
1184 if (selIndex < 0)
1185 return; // nothing selected, nothing to do with a context menu
1187 // if the user selected the info text telling about not all revisions shown due to
1188 // the "stop on copy/rename" option, we also don't show the context menu
1189 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1190 return;
1192 // if the context menu is invoked through the keyboard, we have to use
1193 // a calculated position on where to anchor the menu on
1194 if ((point.x == -1) && (point.y == -1))
1196 CRect rect;
1197 GetItemRect(selIndex, &rect, LVIR_LABEL);
1198 ClientToScreen(&rect);
1199 point = rect.CenterPoint();
1201 m_nSearchIndex = selIndex;
1202 m_bCancelled = FALSE;
1204 // calculate some information the context menu commands can use
1205 // CString pathURL = GetURLFromPath(m_path);
1207 POSITION pos = GetFirstSelectedItemPosition();
1208 int indexNext = GetNextSelectedItem(pos);
1209 if (indexNext < 0)
1210 return;
1212 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
1213 #if 0
1214 GitRev revSelected = pSelLogEntry->Rev;
1215 GitRev revPrevious = git_revnum_t(revSelected)-1;
1216 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1218 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1220 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);
1221 if (changedpath->lCopyFromRev)
1222 revPrevious = changedpath->lCopyFromRev;
1225 GitRev revSelected2;
1226 if (pos)
1228 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1229 revSelected2 = pLogEntry->Rev;
1231 bool bAllFromTheSameAuthor = true;
1232 CString firstAuthor;
1233 CLogDataVector selEntries;
1234 GitRev revLowest, revHighest;
1235 GitRevRangeArray revisionRanges;
1237 POSITION pos = GetFirstSelectedItemPosition();
1238 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1239 revisionRanges.AddRevision(pLogEntry->Rev);
1240 selEntries.push_back(pLogEntry);
1241 firstAuthor = pLogEntry->sAuthor;
1242 revLowest = pLogEntry->Rev;
1243 revHighest = pLogEntry->Rev;
1244 while (pos)
1246 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1247 revisionRanges.AddRevision(pLogEntry->Rev);
1248 selEntries.push_back(pLogEntry);
1249 if (firstAuthor.Compare(pLogEntry->sAuthor))
1250 bAllFromTheSameAuthor = false;
1251 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1252 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1256 #endif
1258 int FirstSelect=-1, LastSelect=-1;
1259 pos = GetFirstSelectedItemPosition();
1260 FirstSelect = GetNextSelectedItem(pos);
1261 while(pos)
1263 LastSelect = GetNextSelectedItem(pos);
1265 //entry is selected, now show the popup menu
1266 CIconMenu popup;
1267 CIconMenu submenu;
1268 if (popup.CreatePopupMenu())
1271 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1272 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1274 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1275 popup.AppendMenuIcon(ID_REBASE_SQUASH,IDS_REBASE_SQUASH, IDI_SQUASH);
1277 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1278 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1280 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1281 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1283 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1284 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1285 popup.AppendMenu(MF_SEPARATOR, NULL);
1287 if (GetSelectedCount() == 1)
1291 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1293 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))
1294 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1295 // TODO:
1296 // TortoiseMerge could be improved to take a /blame switch
1297 // and then not 'cat' the files from a unified diff but
1298 // blame then.
1299 // But until that's implemented, the context menu entry for
1300 // this feature is commented out.
1301 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1302 }else
1304 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1305 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1307 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))
1308 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1310 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1311 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1312 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1313 popup.AppendMenu(MF_SEPARATOR, NULL);
1316 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1317 // {
1318 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1319 // }
1320 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1321 // {
1322 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1323 // }
1324 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1325 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1326 // {
1327 // popup.AppendMenu(MF_SEPARATOR, NULL);
1328 // }
1330 CString str,format;
1331 //if (m_hasWC)
1332 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1333 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV))
1334 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1336 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1337 str.Format(format,g_Git.GetCurrentBranch());
1339 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV))
1340 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1343 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1344 str.Format(format,g_Git.GetCurrentBranch());
1346 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1348 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))
1349 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1351 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV))
1352 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1354 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1355 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1357 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1358 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_COPY);
1360 format.LoadString(IDS_REBASE_THIS_FORMAT);
1361 str.Format(format,g_Git.GetCurrentBranch());
1363 if(pSelLogEntry->m_CommitHash != m_HeadHash)
1364 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1365 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1367 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1368 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1371 popup.AppendMenu(MF_SEPARATOR, NULL);
1376 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)
1378 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1379 popup.AppendMenuIcon(ID_STASH_APPLY,IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1380 popup.AppendMenu(MF_SEPARATOR, NULL);
1383 if (GetSelectedCount() >= 2)
1385 bool bAddSeparator = false;
1386 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1388 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))
1389 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1392 if (GetSelectedCount() == 2)
1394 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1395 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))
1396 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1397 bAddSeparator = true;
1400 if (m_hasWC)
1402 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1403 // if (m_hasWC)
1404 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1405 bAddSeparator = true;
1407 if (bAddSeparator)
1408 popup.AppendMenu(MF_SEPARATOR, NULL);
1411 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1413 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1415 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))
1417 CString head;
1418 int headindex;
1419 headindex = this->GetHeadIndex();
1420 if(headindex>=0)
1422 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1423 CString hash=g_Git.GetHash(head);
1424 hash=hash.Left(40);
1425 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
1426 if(pLastEntry->m_CommitHash.ToString() == hash)
1427 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1431 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK))
1432 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1434 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1435 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH))
1436 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1438 popup.AppendMenu(MF_SEPARATOR, NULL);
1443 #if 0
1444 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1445 // {
1446 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1447 // }
1448 // if (GetSelectedCount() == 1)
1449 // {
1450 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1451 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1452 // popup.AppendMenu(MF_SEPARATOR, NULL);
1453 // }
1454 #endif
1457 if (GetSelectedCount() == 1)
1459 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1460 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH);
1462 if (GetSelectedCount() != 0)
1464 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1465 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);
1468 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1469 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);
1472 if (GetSelectedCount() == 1)
1474 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1476 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1478 CString str;
1479 str.LoadString(IDS_DELETE_BRANCHTAG);
1480 if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )
1482 str+=_T(" ");
1483 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);
1484 popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE);
1486 else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )
1489 submenu.CreatePopupMenu();
1490 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1492 submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("..."));
1495 popup.AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT) submenu.m_hMenu,str);
1503 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1504 // DialogEnableWindow(IDOK, FALSE);
1505 // SetPromptApp(&theApp);
1507 this->ContextMenuAction(cmd, FirstSelect, LastSelect);
1509 // EnableOKButton();
1510 } // if (popup.CreatePopupMenu())
1514 bool CGitLogListBase::IsSelectionContinuous()
1516 if ( GetSelectedCount()==1 )
1518 // if only one revision is selected, the selection is of course
1519 // continuous
1520 return true;
1523 POSITION pos = GetFirstSelectedItemPosition();
1524 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1525 if (bContinuous)
1527 int itemindex = GetNextSelectedItem(pos);
1528 while (pos)
1530 int nextindex = GetNextSelectedItem(pos);
1531 if (nextindex - itemindex > 1)
1533 bContinuous = false;
1534 break;
1536 itemindex = nextindex;
1539 return bContinuous;
1542 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
1545 CString sClipdata;
1546 POSITION pos = GetFirstSelectedItemPosition();
1547 if (pos != NULL)
1549 CString sRev;
1550 sRev.LoadString(IDS_LOG_REVISION);
1551 CString sAuthor;
1552 sAuthor.LoadString(IDS_LOG_AUTHOR);
1553 CString sDate;
1554 sDate.LoadString(IDS_LOG_DATE);
1555 CString sMessage;
1556 sMessage.LoadString(IDS_LOG_MESSAGE);
1557 while (pos)
1559 CString sLogCopyText;
1560 CString sPaths;
1561 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1563 if(!HashOnly)
1565 //pLogEntry->m_Files
1566 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1568 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)
1570 sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();
1571 sPaths += _T("\r\n");
1573 sPaths.Trim();
1574 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"),
1575 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
1576 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,
1577 (LPCTSTR)sDate,
1578 (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
1579 (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,
1580 (LPCTSTR)sPaths);
1581 sClipdata += sLogCopyText;
1582 }else
1584 sClipdata += pLogEntry->m_CommitHash;
1585 break;
1589 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1594 void CGitLogListBase::DiffSelectedRevWithPrevious()
1596 if (m_bThreadRunning)
1597 return;
1599 int FirstSelect=-1, LastSelect=-1;
1600 POSITION pos = GetFirstSelectedItemPosition();
1601 FirstSelect = GetNextSelectedItem(pos);
1602 while(pos)
1604 LastSelect = GetNextSelectedItem(pos);
1607 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect);
1609 #if 0
1610 UpdateLogInfoLabel();
1611 int selIndex = m_LogList.GetSelectionMark();
1612 if (selIndex < 0)
1613 return;
1614 int selCount = m_LogList.GetSelectedCount();
1615 if (selCount != 1)
1616 return;
1618 // Find selected entry in the log list
1619 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1620 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1621 long rev1 = pLogEntry->Rev;
1622 long rev2 = rev1-1;
1623 CTGitPath path = m_path;
1625 // See how many files under the relative root were changed in selected revision
1626 int nChanged = 0;
1627 LogChangedPath * changed = NULL;
1628 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
1630 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);
1631 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1633 ++nChanged;
1634 changed = cpath;
1638 if (m_path.IsDirectory() && nChanged == 1)
1640 // We're looking at the log for a directory and only one file under dir was changed in the revision
1641 // Do diff on that file instead of whole directory
1642 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
1645 m_bCancelled = FALSE;
1646 DialogEnableWindow(IDOK, FALSE);
1647 SetPromptApp(&theApp);
1648 theApp.DoWaitCursor(1);
1650 if (PromptShown())
1652 GitDiff diff(this, m_hWnd, true);
1653 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1654 diff.SetHEADPeg(m_LogRevision);
1655 diff.ShowCompare(path, rev2, path, rev1);
1657 else
1659 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1662 theApp.DoWaitCursor(-1);
1663 EnableOKButton();
1664 #endif
1667 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1669 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
1670 *pResult = -1;
1672 if (pFindInfo->lvfi.flags & LVFI_PARAM)
1673 return;
1674 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
1675 return;
1676 if (pFindInfo->lvfi.psz == 0)
1677 return;
1678 #if 0
1679 CString sCmp = pFindInfo->lvfi.psz;
1680 CString sRev;
1681 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
1683 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
1684 sRev.Format(_T("%ld"), pLogEntry->Rev);
1685 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
1687 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
1689 *pResult = i;
1690 return;
1693 else
1695 if (sCmp.Compare(sRev)==0)
1697 *pResult = i;
1698 return;
1702 if (pFindInfo->lvfi.flags & LVFI_WRAP)
1704 for (int i=0; i<pFindInfo->iStart; ++i)
1706 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1707 sRev.Format(_T("%ld"), pLogEntry->Rev);
1708 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
1710 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
1712 *pResult = i;
1713 return;
1716 else
1718 if (sCmp.Compare(sRev)==0)
1720 *pResult = i;
1721 return;
1726 #endif
1727 *pResult = -1;
1730 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
1732 ClearText();
1734 this->m_logEntries.ClearAll();
1735 this->m_logEntries.ParserFromLog(path,-1,info,from,to);
1737 //this->m_logEntries.ParserFromLog();
1738 SetItemCountEx(this->m_logEntries.size());
1740 this->m_arShownList.RemoveAll();
1742 for(unsigned int i=0;i<m_logEntries.size();i++)
1744 if(m_IsOldFirst)
1746 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
1747 this->m_arShownList.Add(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
1749 }else
1751 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
1752 this->m_arShownList.Add(&m_logEntries.GetGitRevAt(i));
1756 if(path)
1757 m_Path=*path;
1758 return 0;
1762 int CGitLogListBase::BeginFetchLog()
1764 ClearText();
1766 this->m_logEntries.ClearAll();
1767 git_init();
1769 this->m_LogCache.ClearAllParent();
1771 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
1773 CTGitPath *path;
1774 if(this->m_Path.IsEmpty())
1775 path=NULL;
1776 else
1777 path=&this->m_Path;
1779 CString hash;
1780 int mask;
1781 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
1782 // if(this->m_bAllBranch)
1783 mask |= m_ShowMask ;
1785 this->m_arShownList.RemoveAll();
1787 if(m_bShowWC)
1789 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
1790 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
1793 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,NULL,NULL,true);
1795 //this->m_logEntries.ParserFromLog();
1796 if(IsInWorkingThread())
1798 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
1800 else
1802 SetItemCountEx(this->m_logEntries.size());
1805 git_init();
1807 if(g_Git.IsInitRepos())
1808 return 0;
1810 if(git_open_log(&m_DllGitLog,CUnicodeUtils::GetMulti(cmd,CP_ACP).GetBuffer()))
1812 return -1;
1815 return 0;
1818 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
1820 // Skip Ctrl-C when copying text out of the log message or search filter
1821 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1822 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1824 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1826 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1828 DiffSelectedRevWithPrevious();
1829 return TRUE;
1832 #if 0
1833 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
1835 DiffSelectedFile();
1836 return TRUE;
1838 #endif
1841 #if 0
1842 if (m_hAccel && !bSkipAccelerator)
1844 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1845 if (ret)
1846 return TRUE;
1849 #endif
1850 //m_tooltips.RelayEvent(pMsg);
1851 return __super::PreTranslateMessage(pMsg);
1854 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1856 // a double click on an entry in the revision list has happened
1857 *pResult = 0;
1859 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1860 DiffSelectedRevWithPrevious();
1863 int CGitLogListBase::FetchLogAsync(void * data)
1865 m_ProcData=data;
1866 m_bExitThread=FALSE;
1867 InterlockedExchange(&m_bThreadRunning, TRUE);
1868 InterlockedExchange(&m_bNoDispUpdates, TRUE);
1869 m_LoadingThread = AfxBeginThread(LogThreadEntry, this);
1870 if (m_LoadingThread ==NULL)
1872 InterlockedExchange(&m_bThreadRunning, FALSE);
1873 InterlockedExchange(&m_bNoDispUpdates, FALSE);
1874 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1875 return -1;
1877 return 0;
1880 //this is the thread function which calls the subversion function
1881 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
1883 return ((CGitLogListBase*)pVoid)->LogThread();
1886 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
1888 //CTime time;
1889 oldest=CTime::GetCurrentTime();
1890 latest=CTime(1971,1,2,0,0,0);
1891 for(unsigned int i=0;i<m_logEntries.size();i++)
1893 if(m_logEntries[i].IsEmpty())
1894 continue;
1896 if(m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime() < oldest.GetTime())
1897 oldest = m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime();
1899 if(m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime() > latest.GetTime())
1900 latest = m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime();
1904 if(latest<oldest)
1905 latest=oldest;
1908 //Helper class for FetchFullLogInfo()
1909 class CGitCall_FetchFullLogInfo : public CGitCall
1911 public:
1912 CGitCall_FetchFullLogInfo(CGitLogListBase* ploglist):m_ploglist(ploglist),m_CollectedCount(0){}
1913 virtual bool OnOutputData(const BYTE* data, size_t size)
1915 if(size==0)
1916 return m_ploglist->m_bExitThread;
1917 //Add received data to byte collector
1918 m_ByteCollector.append(data,size);
1920 //Find loginfo endmarker
1921 static const BYTE dataToFind[]={0,0,'#','<'};
1922 int found=m_ByteCollector.findData(dataToFind,4);
1923 if(found<0)
1924 return m_ploglist->m_bExitThread;//Not found
1925 found+=2;//Position after loginfo end-marker
1927 //Prepare data for OnLogInfo and call it
1928 BYTE_VECTOR logInfo;
1929 logInfo.append(&*m_ByteCollector.begin(),found);
1930 OnLogInfo(logInfo);
1932 //Remove loginfo from bytecollector
1933 m_ByteCollector.erase(m_ByteCollector.begin(),m_ByteCollector.begin()+found);
1935 return m_ploglist->m_bExitThread;
1937 virtual void OnEnd()
1939 //Rest should be a complete log line.
1940 if(!m_ByteCollector.empty())
1941 OnLogInfo(m_ByteCollector);
1945 void OnLogInfo(BYTE_VECTOR& logInfo)
1947 GitRev fullRev;
1948 fullRev.ParserFromLog(logInfo);
1949 MAP_HASH_REV::iterator itRev=m_ploglist->m_logEntries.m_HashMap.find(fullRev.m_CommitHash);
1950 if(itRev==m_ploglist->m_logEntries.m_HashMap.end())
1952 //Should not occur, only when Git-tree updated in the mean time. (Race condition)
1953 return;//Ignore
1955 //Set updating
1956 int rev=itRev->second;
1957 GitRev* revInVector=&m_ploglist->m_logEntries.GetGitRevAt(rev);
1960 if(revInVector->m_IsFull)
1961 return;
1963 GitRev *pRev= m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev]);
1964 if(pRev)
1966 ++m_CollectedCount;
1967 InterlockedExchange(&pRev->m_IsUpdateing,FALSE);
1968 InterlockedExchange(&pRev->m_IsFull,TRUE);
1969 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);
1970 return;
1973 // fullRev.m_IsUpdateing=TRUE;
1974 // fullRev.m_IsFull=TRUE;
1977 if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE))
1978 return;//Cannot update this row now. Ignore.
1979 TCHAR oldmark=revInVector->m_Mark;
1980 GIT_REV_LIST oldlist=revInVector->m_ParentHash;
1981 // CString oldhash=m_CommitHash;
1983 //Parse new rev info
1984 revInVector->ParserFromLog(logInfo);
1986 if(oldmark!=0)
1987 revInVector->m_Mark=oldmark; //parser full log will cause old mark overwrited.
1988 //So we need keep old bound mark.
1989 revInVector->m_ParentHash=oldlist;
1991 //update cache
1992 m_ploglist->m_LogCache.AddCacheEntry(*revInVector);
1994 //Reset updating
1995 InterlockedExchange(&revInVector->m_IsFull,TRUE);
1996 InterlockedExchange(&revInVector->m_IsUpdateing,FALSE);
1998 //Notify listcontrol and update progress bar
1999 ++m_CollectedCount;
2001 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);
2003 DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30;
2004 if(percent == GITLOG_END)
2005 percent = GITLOG_END -1;
2007 ::PostMessage(m_ploglist->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2010 CGitLogListBase* m_ploglist;
2011 BYTE_VECTOR m_ByteCollector;
2012 int m_CollectedCount;
2016 void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to)
2018 CGitCall_FetchFullLogInfo fetcher(this);
2019 int mask=
2020 CGit::LOG_INFO_FULL_DIFF|
2021 CGit::LOG_INFO_STAT|
2022 CGit::LOG_INFO_FILESTATE|
2023 CGit::LOG_INFO_DETECT_COPYRENAME|
2024 CGit::LOG_INFO_SHOW_MERGEDFILE |
2025 m_ShowMask;
2027 CTGitPath *path;
2028 if(this->m_Path.IsEmpty())
2029 path=NULL;
2030 else
2031 path=&this->m_Path;
2033 g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to);
2036 void CGitLogListBase::FetchLastLogInfo()
2038 unsigned int updated=0;
2039 int percent=0;
2040 CRect rect;
2042 for(unsigned int i=0;i<m_logEntries.size();i++)
2044 if(m_logEntries.GetGitRevAt(i).m_IsFull)
2045 continue;
2047 GitRev *pRev = m_LogCache.GetCacheData(m_logEntries[i]);
2048 if(pRev == NULL)
2050 if(!m_logEntries.FetchFullInfo(i))
2052 updated++;
2054 m_LogCache.AddCacheEntry(m_logEntries.GetGitRevAt(i));
2056 }else
2058 updated++;
2059 InterlockedExchange(&pRev->m_IsUpdateing,FALSE);
2060 InterlockedExchange(&pRev->m_IsFull,TRUE);
2063 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
2065 if(m_bExitThread)
2067 InterlockedExchange(&m_bThreadRunning, FALSE);
2068 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2069 return;
2075 UINT CGitLogListBase::LogThread()
2077 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2079 InterlockedExchange(&m_bThreadRunning, TRUE);
2080 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2082 ULONGLONG t1,t2;
2084 if(BeginFetchLog())
2085 return -1;
2087 TRACE(_T("\n===Begin===\n"));
2088 //Update work copy item;
2089 if( m_logEntries.size() > 0)
2091 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2093 m_arShownList.Add(pRev);
2095 if( pRev->m_CommitHash.IsEmpty() )
2097 pRev->m_Files.Clear();
2098 pRev->m_ParentHash.clear();
2099 pRev->m_ParentHash.push_back(m_HeadHash);
2100 if(g_Git.IsInitRepos())
2102 g_Git.GetInitAddList(pRev->m_Files);
2104 }else
2106 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->m_Files);
2108 pRev->m_Action =0;
2110 for(int j=0;j< pRev->m_Files.GetCount();j++)
2111 pRev->m_Action |= pRev->m_Files[j].m_Action;
2113 pRev->m_Body.Format(_T("%d files changed"),m_logEntries.GetGitRevAt(0).m_Files.GetCount());
2114 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
2118 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2120 if(!g_Git.IsInitRepos())
2122 git_get_log_firstcommit(m_DllGitLog);
2123 int total = git_get_log_estimate_commit_count(m_DllGitLog);
2124 GIT_COMMIT commit;
2125 t2=t1=GetTickCount();
2126 int oldprecentage = 0;
2127 int oldsize=m_logEntries.size();
2128 while( git_get_log_nextcommit(this->m_DllGitLog,&commit) == 0)
2130 //printf("%s\r\n",commit.m_Subject);
2131 if(m_bExitThread)
2132 break;
2134 CGitHash hash = (char*)commit.m_hash ;
2136 GitRev *pRev = m_LogCache.GetCacheData(hash);
2138 if(pRev == NULL || !pRev->m_IsFull)
2140 pRev->ParserFromCommit(&commit);
2141 pRev->ParserParentFromCommit(&commit);
2142 pRev->SafeFetchFullInfo(&g_Git);
2144 }else
2146 ASSERT(pRev->m_CommitHash == hash);
2147 pRev->ParserParentFromCommit(&commit);
2149 #ifdef DEBUG
2150 pRev->DbgPrint();
2151 TRACE(_T("\n"));
2152 #endif
2153 git_free_commit(&commit);
2155 this->m_critSec.Lock();
2156 m_logEntries.push_back(hash);
2157 m_arShownList.Add(pRev);
2158 this->m_critSec.Unlock();
2160 t2=GetTickCount();
2162 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2164 //update UI
2165 int percent=m_logEntries.size()*100/total + GITLOG_START+1;
2166 if(percent > 99)
2167 percent =99;
2168 if(percent < GITLOG_START)
2169 percent = GITLOG_START +1;
2171 oldsize = m_logEntries.size();
2172 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2174 //if( percent > oldprecentage )
2176 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2177 oldprecentage = percent;
2179 t1 = t2;
2184 //Update UI;
2185 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2186 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2188 InterlockedExchange(&m_bThreadRunning, FALSE);
2190 #if 0
2191 // if(m_ProcCallBack)
2192 // m_ProcCallBack(m_ProcData,GITLOG_START);
2193 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2195 InterlockedExchange(&m_bThreadRunning, TRUE);
2196 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2198 //does the user force the cache to refresh (shift or control key down)?
2199 bool refresh = (GetKeyState (VK_CONTROL) < 0)
2200 || (GetKeyState (VK_SHIFT) < 0);
2202 //disable the "Get All" button while we're receiving
2203 //log messages.
2205 FillGitShortLog();
2207 if(this->m_bExitThread)
2209 InterlockedExchange(&m_bThreadRunning, FALSE);
2210 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2211 return 0;
2213 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2214 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0);
2216 int start=0; CString firstcommit,lastcommit;
2217 int update=0;
2218 for(int i=0;i<m_logEntries.size();i++)
2220 if( i==0 && m_logEntries.GetGitRevAt(i).m_CommitHash.IsEmpty() )
2222 m_logEntries.GetGitRevAt(i).m_Files.Clear();
2223 m_logEntries.GetGitRevAt(i).m_ParentHash.clear();
2224 m_logEntries.GetGitRevAt(i).m_ParentHash.push_back(m_HeadHash);
2225 g_Git.GetCommitDiffList(m_logEntries.GetGitRevAt(i).m_CommitHash.ToString(),this->m_HeadHash,m_logEntries.GetGitRevAt(i).m_Files);
2226 m_logEntries.GetGitRevAt(i).m_Action =0;
2227 for(int j=0;j< m_logEntries.GetGitRevAt(i).m_Files.GetCount();j++)
2228 m_logEntries.GetGitRevAt(i).m_Action |= m_logEntries.GetGitRevAt(i).m_Files[j].m_Action;
2230 m_logEntries.GetGitRevAt(i).m_Body.Format(_T("%d files changed"),m_logEntries.GetGitRevAt(i).m_Files.GetCount());
2231 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
2232 continue;
2235 start=this->m_logEntries.GetGitRevAt(i).ParserFromLog(m_logEntries.m_RawlogData,start);
2236 m_logEntries.m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash.ToString()]=i;
2238 if(m_LogCache.GetCacheData(m_logEntries.GetGitRevAt(i)))
2240 if(firstcommit.IsEmpty())
2241 firstcommit=m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
2242 lastcommit=m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();
2244 }else
2246 InterlockedExchange(&m_logEntries.GetGitRevAt(i).m_IsUpdateing,FALSE);
2247 InterlockedExchange(&m_logEntries.GetGitRevAt(i).m_IsFull,TRUE);
2248 update++;
2250 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0);
2252 if(start<0)
2253 break;
2254 if(start>=m_logEntries.m_RawlogData.size())
2255 break;
2257 int percent=i*30/m_logEntries.size() + GITLOG_START+1;
2259 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0);
2261 if(this->m_bExitThread)
2263 InterlockedExchange(&m_bThreadRunning, FALSE);
2264 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2265 return 0;
2268 if(!lastcommit.IsEmpty())
2269 FetchFullLogInfo(lastcommit,firstcommit);
2271 this->FetchLastLogInfo();
2273 #if 0
2274 RedrawItems(0, m_arShownList.GetCount());
2275 // SetRedraw(false);
2276 // ResizeAllListCtrlCols();
2277 // SetRedraw(true);
2279 if ( m_pStoreSelection )
2281 // Deleting the instance will restore the
2282 // selection of the CLogDlg.
2283 delete m_pStoreSelection;
2284 m_pStoreSelection = NULL;
2286 else
2288 // If no selection has been set then this must be the first time
2289 // the revisions are shown. Let's preselect the topmost revision.
2290 if ( GetItemCount()>0 )
2292 SetSelectionMark(0);
2293 SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2296 #endif
2300 //FetchFullLogInfo();
2301 //FetchFullLogInfoOrig();
2302 //RefreshCursor();
2303 // make sure the filter is applied (if any) now, after we refreshed/fetched
2304 // the log messages
2306 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2308 InterlockedExchange(&m_bThreadRunning, FALSE);
2309 #endif
2310 return 0;
2313 void CGitLogListBase::Refresh()
2315 SafeTerminateThread();
2317 this->SetItemCountEx(0);
2318 this->Clear();
2320 //Update branch and Tag info
2321 ReloadHashMap();
2322 //Assume Thread have exited
2323 //if(!m_bThreadRunning)
2326 m_logEntries.clear();
2327 InterlockedExchange(&m_bExitThread,FALSE);
2329 InterlockedExchange(&m_bThreadRunning, TRUE);
2330 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2331 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2333 InterlockedExchange(&m_bThreadRunning, FALSE);
2334 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2335 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2337 m_sFilterText.Empty();
2338 m_From=CTime(1970,1,2,0,0,0);
2339 m_To=CTime::GetCurrentTime();
2342 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2346 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2347 if (!bMatchCase)
2348 type |= tr1::regex_constants::icase;
2349 pat = tr1::wregex(regexp_str, type);
2350 return true;
2352 catch (exception) {}
2353 return false;
2356 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)
2359 pShownlist->RemoveAll();
2360 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2361 bool bRegex = false;
2362 if (m_bFilterWithRegex)
2363 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2365 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2366 CString sRev;
2367 for (DWORD i=0; i<m_logEntries.size(); ++i)
2369 if ((bRegex)&&(m_bFilterWithRegex))
2371 #if 0
2372 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2374 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2375 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2377 pShownlist->Add(m_logEntries[i]);
2378 continue;
2381 #endif
2382 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2384 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).m_Subject);
2385 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).m_Subject), pat, flags)&&IsEntryInDateRange(i))
2387 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2388 continue;
2391 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).m_Body);
2392 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).m_Body), pat, flags)&&IsEntryInDateRange(i))
2394 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2395 continue;
2398 #if 0
2399 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2401 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
2403 bool bGoing = true;
2404 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
2406 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2407 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))
2409 pShownlist->Add(m_logEntries[i]);
2410 bGoing = false;
2411 continue;
2413 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))
2415 pShownlist->Add(m_logEntries[i]);
2416 bGoing = false;
2417 continue;
2419 if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))
2421 pShownlist->Add(m_logEntries[i]);
2422 bGoing = false;
2423 continue;
2426 if (!bGoing)
2427 continue;
2429 #endif
2430 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2432 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).m_AuthorName), pat, flags)&&IsEntryInDateRange(i))
2434 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2435 continue;
2438 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2440 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2441 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2443 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2444 continue;
2447 } // if (bRegex)
2448 else
2450 CString find = m_sFilterText;
2451 find.MakeLower();
2452 #if 0
2453 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2455 CString sBugIDs = m_logEntries[i]->sBugIDs;
2457 sBugIDs = sBugIDs.MakeLower();
2458 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2460 pShownlist->Add(m_logEntries[i]);
2461 continue;
2464 #endif
2465 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2467 CString msg = m_logEntries.GetGitRevAt(i).m_Subject;
2469 msg = msg.MakeLower();
2470 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2472 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2473 continue;
2475 msg = m_logEntries.GetGitRevAt(i).m_Body;
2477 msg = msg.MakeLower();
2478 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2480 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2481 continue;
2484 #if 0
2485 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2487 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
2489 bool bGoing = true;
2490 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
2492 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2493 CString path = cpath->sCopyFromPath;
2494 path.MakeLower();
2495 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2497 pShownlist->Add(m_logEntries[i]);
2498 bGoing = false;
2499 continue;
2501 path = cpath->sPath;
2502 path.MakeLower();
2503 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2505 pShownlist->Add(m_logEntries[i]);
2506 bGoing = false;
2507 continue;
2509 path = cpath->GetAction();
2510 path.MakeLower();
2511 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2513 pShownlist->Add(m_logEntries[i]);
2514 bGoing = false;
2515 continue;
2519 #endif
2520 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2522 CString msg = m_logEntries.GetGitRevAt(i).m_AuthorName;
2523 msg = msg.MakeLower();
2524 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2526 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2527 continue;
2530 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2532 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
2533 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2535 pShownlist->Add(&m_logEntries.GetGitRevAt(i));
2536 continue;
2539 } // else (from if (bRegex))
2540 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2544 BOOL CGitLogListBase::IsEntryInDateRange(int i)
2546 __time64_t time = m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime();
2547 if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))
2548 return TRUE;
2550 return FALSE;
2552 // return TRUE;
2554 void CGitLogListBase::StartFilter()
2556 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2557 RecalculateShownList(&m_arShownList);
2558 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2561 DeleteAllItems();
2562 SetItemCountEx(ShownCountWithStopped());
2563 RedrawItems(0, ShownCountWithStopped());
2564 SetRedraw(false);
2565 //ResizeAllListCtrlCols();
2566 SetRedraw(true);
2567 Invalidate();
2570 void CGitLogListBase::RemoveFilter()
2573 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2575 m_arShownList.RemoveAll();
2577 // reset the time filter too
2578 #if 0
2579 m_timFrom = (__time64_t(m_tFrom));
2580 m_timTo = (__time64_t(m_tTo));
2581 m_DateFrom.SetTime(&m_timFrom);
2582 m_DateTo.SetTime(&m_timTo);
2583 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2584 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2585 #endif
2587 for (DWORD i=0; i<m_logEntries.size(); ++i)
2589 if(this->m_IsOldFirst)
2591 m_arShownList.Add(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2592 }else
2594 m_arShownList.Add(&m_logEntries.GetGitRevAt(i));
2597 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2598 DeleteAllItems();
2599 SetItemCountEx(ShownCountWithStopped());
2600 RedrawItems(0, ShownCountWithStopped());
2601 // SetRedraw(false);
2602 // ResizeAllListCtrlCols();
2603 // SetRedraw(true);
2605 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2608 void CGitLogListBase::Clear()
2610 m_arShownList.RemoveAll();
2611 DeleteAllItems();
2613 m_logEntries.ClearAll();
2617 void CGitLogListBase::OnDestroy()
2619 // save the column widths to the registry
2620 SaveColumnWidths();
2622 SafeTerminateThread();
2624 while(m_LogCache.SaveCache())
2626 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2627 MB_YESNO) == IDNO)
2628 break;
2630 CHintListCtrl::OnDestroy();
2633 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
2635 CRect rect;
2636 int i=(int)wParam;
2637 this->GetItemRect(i,&rect,LVIR_BOUNDS);
2638 this->InvalidateRect(rect);
2640 if(this->GetItemState(i,LVIF_STATE) & LVIS_SELECTED)
2642 int i=0;
2644 return 0;
2648 * Save column widths to the registry
2650 void CGitLogListBase::SaveColumnWidths()
2652 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
2653 if (pHdrCtrl)
2655 int numcols = pHdrCtrl->GetItemCount();
2656 for (int col = 0; col < numcols; col++)
2658 int width = GetColumnWidth( col );
2659 CString regentry;
2660 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
2661 CRegDWORD regwidth(regentry, 0);
2662 regwidth = width; // this writes it to reg
2667 int CGitLogListBase::GetHeadIndex()
2669 if(m_HeadHash.IsEmpty())
2670 return -1;
2672 for(int i=0;i<m_arShownList.GetCount();i++)
2674 GitRev *pRev = (GitRev*)m_arShownList[i];
2675 if(pRev)
2677 if(pRev->m_CommitHash.ToString() == m_HeadHash )
2678 return i;
2681 return -1;
2683 void CGitLogListBase::OnFind()
2685 if (!m_pFindDialog)
2687 m_pFindDialog = new CFindReplaceDialog();
2688 m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this);
2692 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
2695 ASSERT(m_pFindDialog != NULL);
2697 if (m_pFindDialog->IsTerminating())
2699 // invalidate the handle identifying the dialog box.
2700 m_pFindDialog = NULL;
2701 return 0;
2704 if(m_pFindDialog->FindNext())
2706 //read data from dialog
2707 CString FindText = m_pFindDialog->GetFindString();
2708 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
2709 bool bFound = false;
2710 tr1::wregex pat;
2711 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
2713 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
2715 int i;
2716 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
2718 GitRev* pLogEntry = (GitRev*)m_arShownList.GetAt(i);
2720 CString str;
2721 str+=pLogEntry->m_CommitHash.ToString();
2722 str+=_T("\n");
2723 str+=pLogEntry->m_AuthorEmail;
2724 str+=_T("\n");
2725 str+=pLogEntry->m_AuthorName;
2726 str+=_T("\n");
2727 str+=pLogEntry->m_Body;
2728 str+=_T("\n");
2729 str+=pLogEntry->m_CommitterEmail;
2730 str+=_T("\n");
2731 str+=pLogEntry->m_CommitterName;
2732 str+=_T("\n");
2733 str+=pLogEntry->m_Subject;
2734 str+=_T("\n");
2736 for(int i=0;i<pLogEntry->m_Files.GetCount();i++)
2738 str+=pLogEntry->m_Files[i].GetWinPath();
2739 str+=_T("\n");
2740 str+=pLogEntry->m_Files[i].GetGitOldPathString();
2741 str+=_T("\n");
2744 if (bRegex)
2747 if (regex_search(wstring(str), pat, flags))
2749 bFound = true;
2750 break;
2753 else
2755 if (bMatchCase)
2757 if (str.Find(FindText) >= 0)
2759 bFound = true;
2760 break;
2764 else
2766 CString msg = str;
2767 msg = msg.MakeLower();
2768 CString find = FindText.MakeLower();
2769 if (msg.Find(find) >= 0)
2771 bFound = TRUE;
2772 break;
2776 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
2777 if (bFound)
2779 this->m_nSearchIndex = (i+1);
2780 EnsureVisible(i, FALSE);
2781 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
2782 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2783 SetSelectionMark(i);
2784 //FillLogMessageCtrl();
2785 UpdateData(FALSE);
2786 m_nSearchIndex++;
2787 if (m_nSearchIndex >= m_arShownList.GetCount())
2788 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
2790 } // if(m_pFindDialog->FindNext())
2791 //UpdateLogInfoLabel();
2793 return 0;