Fixed issue #234: First log(first commit in history) was missing...
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blob04ebca90e65b1455d2d1a28ee6f05f9a65c7024c
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"
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()
53 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
54 ,m_nSearchIndex(0)
55 ,m_bNoDispUpdates(FALSE)
56 , m_bThreadRunning(FALSE)
57 , m_bStrictStopped(false)
58 , m_pStoreSelection(NULL)
59 , m_nSelectedFilter(LOGFILTER_ALL)
60 , m_bVista(false)
61 , m_bShowWC(false)
63 // use the default GUI font, create a copy of it and
64 // change the copy to BOLD (leave the rest of the font
65 // the same)
66 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
67 LOGFONT lf = {0};
68 GetObject(hFont, sizeof(LOGFONT), &lf);
69 lf.lfWeight = FW_BOLD;
70 m_boldFont = CreateFontIndirect(&lf);
72 m_bShowBugtraqColumn=0;
74 m_IsIDReplaceAction=FALSE;
76 m_wcRev.m_CommitHash=GIT_REV_ZERO;
77 m_wcRev.m_Subject=_T("Working dir changes");
78 m_wcRev.m_ParentHash.clear();
79 m_wcRev.m_Mark=_T('-');
80 m_wcRev.m_IsUpdateing=FALSE;
81 m_wcRev.m_IsFull = TRUE;
83 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
84 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
85 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
86 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
88 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
90 g_Git.GetMapHashToFriendName(m_HashMap);
91 m_CurrentBranch=g_Git.GetCurrentBranch();
92 this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40);
94 m_From=CTime(1970,1,2,0,0,0);
95 m_To=CTime::GetCurrentTime();
96 m_ShowMask = 0;
97 m_LoadingThread = NULL;
99 m_bExitThread=FALSE;
100 m_IsOldFirst = FALSE;
101 m_IsRebaseReplaceGraph = FALSE;
104 for(int i=0;i<Lanes::COLORS_NUM;i++)
106 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
108 // get short/long datetime setting from registry
109 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
110 if ( RegUseShortDateFormat )
112 m_DateFormat = DATE_SHORTDATE;
114 else
116 m_DateFormat = DATE_LONGDATE;
118 // get relative time display setting from registry
119 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
120 m_bRelativeTimes = (regRelativeTimes != 0);
121 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
123 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
124 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
125 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
126 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
128 OSVERSIONINFOEX inf;
129 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
130 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
131 GetVersionEx((OSVERSIONINFO *)&inf);
132 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
133 m_bVista = (fullver >= 0x0600);
135 m_ColumnRegKey=_T("log");
138 CGitLogListBase::~CGitLogListBase()
140 InterlockedExchange(&m_bNoDispUpdates, TRUE);
142 DestroyIcon(m_hModifiedIcon);
143 DestroyIcon(m_hReplacedIcon);
144 DestroyIcon(m_hAddedIcon);
145 DestroyIcon(m_hDeletedIcon);
146 m_logEntries.ClearAll();
148 if (m_boldFont)
149 DeleteObject(m_boldFont);
151 if ( m_pStoreSelection )
153 delete m_pStoreSelection;
154 m_pStoreSelection = NULL;
157 if(this->m_bThreadRunning)
159 m_bExitThread=true;
160 WaitForSingleObject(m_LoadingThread->m_hThread,1000);
161 TerminateThread();
166 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
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 // arc
601 switch (type) {
602 case Lanes::JOIN:
603 case Lanes::JOIN_R:
604 case Lanes::HEAD:
605 case Lanes::HEAD_R:
607 Gdiplus::LinearGradientBrush gradient(
608 Gdiplus::Point(x1-2, h+top-2),
609 Gdiplus::Point(P_270),
610 GetGdiColor(activeColor),GetGdiColor(col));
613 Gdiplus::Pen mypen(&gradient,2);
614 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
616 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
617 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1+1,laneHeight+1,270,90);
618 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
620 break;
622 case Lanes::JOIN_L:
625 Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
628 graphics.DrawArc(&mypen,x1,top+h, x2-x1,laneHeight,270,90);
630 break;
632 case Lanes::TAIL:
633 case Lanes::TAIL_R:
636 Gdiplus::LinearGradientBrush gradient(
637 Gdiplus::Point(x1-2, h+top-2),
638 Gdiplus::Point(P_90),
639 GetGdiColor(activeColor),GetGdiColor(col));
642 Gdiplus::Pen mypen(&gradient,2);
644 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1+1,laneHeight+1,0,90);
647 #if 0
648 QConicalGradient gradient(CENTER_DR);
649 gradient.setColorAt(0.375, activeCol);
650 gradient.setColorAt(0.625, col);
651 myPen.setBrush(gradient);
652 p->setPen(myPen);
653 p->drawArc(P_CENTER, DELTA_DR);
654 #endif
655 break;
657 default:
658 break;
662 //static QPen myPen(Qt::black, 2); // fast path here
663 CPen pen;
664 pen.CreatePen(PS_SOLID,2,col);
665 //myPen.setColor(col);
666 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
668 Gdiplus::Pen myPen(GetGdiColor(col),2);
670 //p->setPen(myPen);
672 // vertical line
673 switch (type) {
674 case Lanes::ACTIVE:
675 case Lanes::NOT_ACTIVE:
676 case Lanes::MERGE_FORK:
677 case Lanes::MERGE_FORK_R:
678 case Lanes::MERGE_FORK_L:
679 case Lanes::JOIN:
680 case Lanes::JOIN_R:
681 case Lanes::JOIN_L:
682 case Lanes::CROSS:
683 //DrawLine(hdc,P_90,P_270);
684 graphics.DrawLine(&myPen,P_90,P_270);
685 //p->drawLine(P_90, P_270);
686 break;
687 case Lanes::HEAD_L:
688 case Lanes::BRANCH:
689 //DrawLine(hdc,P_CENTER,P_270);
690 graphics.DrawLine(&myPen,P_CENTER,P_270);
691 //p->drawLine(P_CENTER, P_270);
692 break;
693 case Lanes::TAIL_L:
694 case Lanes::INITIAL:
695 case Lanes::BOUNDARY:
696 case Lanes::BOUNDARY_C:
697 case Lanes::BOUNDARY_R:
698 case Lanes::BOUNDARY_L:
699 //DrawLine(hdc,P_90, P_CENTER);
700 graphics.DrawLine(&myPen,P_90,P_CENTER);
701 //p->drawLine(P_90, P_CENTER);
702 break;
703 default:
704 break;
707 myPen.SetColor(GetGdiColor(activeColor));
709 // horizontal line
710 switch (type) {
711 case Lanes::MERGE_FORK:
712 case Lanes::JOIN:
713 case Lanes::HEAD:
714 case Lanes::TAIL:
715 case Lanes::CROSS:
716 case Lanes::CROSS_EMPTY:
717 case Lanes::BOUNDARY_C:
718 //DrawLine(hdc,P_180,P_0);
719 graphics.DrawLine(&myPen,P_180,P_0);
720 //p->drawLine(P_180, P_0);
721 break;
722 case Lanes::MERGE_FORK_R:
723 case Lanes::BOUNDARY_R:
724 //DrawLine(hdc,P_180,P_CENTER);
725 graphics.DrawLine(&myPen,P_180,P_CENTER);
726 //p->drawLine(P_180, P_CENTER);
727 break;
728 case Lanes::MERGE_FORK_L:
729 case Lanes::HEAD_L:
730 case Lanes::TAIL_L:
731 case Lanes::BOUNDARY_L:
732 //DrawLine(hdc,P_CENTER,P_0);
733 graphics.DrawLine(&myPen,P_CENTER,P_0);
734 //p->drawLine(P_CENTER, P_0);
735 break;
736 default:
737 break;
740 CBrush brush;
741 brush.CreateSolidBrush(col);
742 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
743 // center symbol, e.g. rect or ellipse
744 switch (type) {
745 case Lanes::ACTIVE:
746 case Lanes::INITIAL:
747 case Lanes::BRANCH:
749 //p->setPen(Qt::NoPen);
750 //p->setBrush(col);
751 ::Ellipse(hdc, R_CENTER);
752 //p->drawEllipse(R_CENTER);
753 break;
754 case Lanes::MERGE_FORK:
755 case Lanes::MERGE_FORK_R:
756 case Lanes::MERGE_FORK_L:
757 //p->setPen(Qt::NoPen);
758 //p->setBrush(col);
759 //p->drawRect(R_CENTER);
760 Rectangle(hdc,R_CENTER);
761 break;
762 case Lanes::UNAPPLIED:
763 // Red minus sign
764 //p->setPen(Qt::NoPen);
765 //p->setBrush(Qt::red);
766 //p->drawRect(m - r, h - 1, d, 2);
767 ::Rectangle(hdc,m-r,h-1,d,2);
768 break;
769 case Lanes::APPLIED:
770 // Green plus sign
771 //p->setPen(Qt::NoPen);
772 //p->setBrush(DARK_GREEN);
773 //p->drawRect(m - r, h - 1, d, 2);
774 //p->drawRect(m - 1, h - r, 2, d);
775 ::Rectangle(hdc,m-r,h-1,d,2);
776 ::Rectangle(hdc,m-1,h-r,2,d);
777 break;
778 case Lanes::BOUNDARY:
779 //p->setBrush(back);
780 //p->drawEllipse(R_CENTER);
781 ::Ellipse(hdc, R_CENTER);
782 break;
783 case Lanes::BOUNDARY_C:
784 case Lanes::BOUNDARY_R:
785 case Lanes::BOUNDARY_L:
786 //p->setBrush(back);
787 //p->drawRect(R_CENTER);
788 ::Rectangle(hdc,R_CENTER);
789 break;
790 default:
791 break;
794 ::SelectObject(hdc,oldpen);
795 ::SelectObject(hdc,oldbrush);
796 #undef P_CENTER
797 #undef P_0
798 #undef P_90
799 #undef P_180
800 #undef P_270
801 #undef R_CENTER
804 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
806 //todo unfinished
807 // return;
808 GitRev* data = (GitRev*)m_arShownList.GetAt(index);
809 if(data->m_CommitHash.IsEmpty())
810 return;
812 CRect rt=rect;
813 LVITEM rItem;
814 SecureZeroMemory(&rItem, sizeof(LVITEM));
815 rItem.mask = LVIF_STATE;
816 rItem.iItem = index;
817 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
818 GetItem(&rItem);
821 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
825 if (data->m_Lanes.size() == 0)
826 m_logEntries.setLane(data->m_CommitHash);
828 std::vector<int>& lanes=data->m_Lanes;
829 UINT laneNum = lanes.size();
830 UINT activeLane = 0;
831 for (UINT i = 0; i < laneNum; i++)
832 if (Lanes::isMerge(lanes[i])) {
833 activeLane = i;
834 break;
837 int x1 = 0, x2 = 0;
838 int maxWidth = rect.Width();
839 int lw = 3 * rect.Height() / 4; //laneWidth()
841 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
842 //if (opt.state & QStyle::State_Selected)
843 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
846 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
849 x1 = x2;
850 x2 += lw;
852 int ln = lanes[i];
853 if (ln == Lanes::EMPTY)
854 continue;
856 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
857 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
860 #if 0
861 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
863 x1 = x2;
864 x2 += lw;
866 int ln = lanes[i];
867 if (ln == Lanes::EMPTY)
868 continue;
870 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
871 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
873 if (ln == Lanes::CROSS) {
874 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
875 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
876 } else
877 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
879 #endif
883 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
886 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
887 // Take the default processing unless we set this to something else below.
888 *pResult = CDRF_DODEFAULT;
890 if (m_bNoDispUpdates)
891 return;
895 switch (pLVCD->nmcd.dwDrawStage)
897 case CDDS_PREPAINT:
899 *pResult = CDRF_NOTIFYITEMDRAW;
900 return;
902 break;
903 case CDDS_ITEMPREPAINT:
905 // This is the prepaint stage for an item. Here's where we set the
906 // item's text color.
908 // Tell Windows to send draw notifications for each subitem.
909 *pResult = CDRF_NOTIFYSUBITEMDRAW;
911 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
913 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
915 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
916 if (data)
918 #if 0
919 if (data->bCopiedSelf)
921 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)
922 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))
923 pLVCD->clrTextBk = GetSysColor(COLOR_MENU);
926 if (data->bCopies)
927 crText = m_Colors.GetColor(CColors::Modified);
928 #endif
929 if (data->m_Action& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
930 crText = RGB(128,128,128);
932 if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)
933 pLVCD->clrTextBk = RGB(156,156,156);
934 else if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)
935 pLVCD->clrTextBk = RGB(200,200,128);
936 else
937 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
939 if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_CURRENT)
941 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
942 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
945 if(data->m_CommitHash == m_HeadHash)
947 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
948 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
951 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
952 // crText = GetSysColor(COLOR_GRAYTEXT);
954 if (data->m_CommitHash == GIT_REV_ZERO)
956 //crText = GetSysColor(RGB(200,200,0));
957 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
958 // We changed the font, so we're returning CDRF_NEWFONT. This
959 // tells the control to recalculate the extent of the text.
960 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
964 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
966 if (m_bStrictStopped)
967 crText = GetSysColor(COLOR_GRAYTEXT);
969 // Store the color back in the NMLVCUSTOMDRAW struct.
970 pLVCD->clrText = crText;
971 return;
973 break;
974 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
976 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
978 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
981 if (pLVCD->iSubItem == LOGLIST_GRAPH)
983 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
985 CRect rect;
986 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
987 if(pLVCD->iSubItem == 0)
989 CRect second;
990 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem+1, LVIR_BOUNDS, second);
991 rect.right=second.left;
994 TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
995 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
997 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
998 if( data ->m_CommitHash != GIT_REV_ZERO)
999 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1001 *pResult = CDRF_SKIPDEFAULT;
1002 return;
1007 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1009 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1011 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);
1012 //if(!data->m_IsFull)
1014 //if(data->SafeFetchFullInfo(&g_Git))
1015 // this->Invalidate();
1016 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1019 if(m_HashMap[data->m_CommitHash].size()!=0)
1021 CRect rect;
1023 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1025 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1026 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1028 *pResult = CDRF_SKIPDEFAULT;
1029 return;
1036 if (pLVCD->iSubItem == 1)
1038 if(this->m_IsIDReplaceAction)
1040 *pResult = CDRF_DODEFAULT;
1041 return;
1043 *pResult = CDRF_DODEFAULT;
1045 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1046 return;
1048 int nIcons = 0;
1049 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1050 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1052 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));
1053 CRect rect;
1054 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1055 TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1056 // Get the selected state of the
1057 // item being drawn.
1059 // Fill the background
1060 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);
1062 // Draw the icon(s) into the compatible DC
1063 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)
1064 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1065 nIcons++;
1067 if (pLogEntry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1068 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1069 nIcons++;
1071 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)
1072 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1073 nIcons++;
1075 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
1076 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1077 nIcons++;
1078 *pResult = CDRF_SKIPDEFAULT;
1079 return;
1082 break;
1084 *pResult = CDRF_DODEFAULT;
1088 // CGitLogListBase message handlers
1090 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1092 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1094 // Create a pointer to the item
1095 LV_ITEM* pItem = &(pDispInfo)->item;
1097 // Do the list need text information?
1098 if (!(pItem->mask & LVIF_TEXT))
1099 return;
1101 // By default, clear text buffer.
1102 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1104 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1106 *pResult = 0;
1107 if (m_bNoDispUpdates || bOutOfRange)
1108 return;
1110 // Which item number?
1111 int itemid = pItem->iItem;
1112 GitRev * pLogEntry = NULL;
1113 if (itemid < m_arShownList.GetCount())
1114 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));
1116 CString temp;
1117 if(m_IsOldFirst)
1119 temp.Format(_T("%d"),pItem->iItem+1);
1121 }else
1123 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1126 // Which column?
1127 switch (pItem->iSubItem)
1129 case this->LOGLIST_GRAPH: //Graphic
1130 if (pLogEntry)
1132 if(this->m_IsRebaseReplaceGraph)
1134 CTGitPath path;
1135 path.m_Action=pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1137 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1140 break;
1141 case this->LOGLIST_ACTION: //action -- no text in the column
1142 if(this->m_IsIDReplaceAction)
1143 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1144 break;
1145 case this->LOGLIST_MESSAGE: //Message
1146 if (pLogEntry)
1147 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);
1148 break;
1149 case this->LOGLIST_AUTHOR: //Author
1150 if (pLogEntry)
1151 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);
1152 break;
1153 case this->LOGLIST_DATE: //Date
1154 if (pLogEntry && pLogEntry->m_CommitHash != GIT_REV_ZERO)
1155 lstrcpyn(pItem->pszText,
1156 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
1157 pItem->cchTextMax);
1158 break;
1160 case 5:
1162 break;
1163 default:
1164 ASSERT(false);
1168 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1171 int selIndex = GetSelectionMark();
1172 if (selIndex < 0)
1173 return; // nothing selected, nothing to do with a context menu
1175 // if the user selected the info text telling about not all revisions shown due to
1176 // the "stop on copy/rename" option, we also don't show the context menu
1177 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1178 return;
1180 // if the context menu is invoked through the keyboard, we have to use
1181 // a calculated position on where to anchor the menu on
1182 if ((point.x == -1) && (point.y == -1))
1184 CRect rect;
1185 GetItemRect(selIndex, &rect, LVIR_LABEL);
1186 ClientToScreen(&rect);
1187 point = rect.CenterPoint();
1189 m_nSearchIndex = selIndex;
1190 m_bCancelled = FALSE;
1192 // calculate some information the context menu commands can use
1193 // CString pathURL = GetURLFromPath(m_path);
1195 POSITION pos = GetFirstSelectedItemPosition();
1196 int indexNext = GetNextSelectedItem(pos);
1197 if (indexNext < 0)
1198 return;
1200 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
1201 #if 0
1202 GitRev revSelected = pSelLogEntry->Rev;
1203 GitRev revPrevious = git_revnum_t(revSelected)-1;
1204 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1206 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1208 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);
1209 if (changedpath->lCopyFromRev)
1210 revPrevious = changedpath->lCopyFromRev;
1213 GitRev revSelected2;
1214 if (pos)
1216 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1217 revSelected2 = pLogEntry->Rev;
1219 bool bAllFromTheSameAuthor = true;
1220 CString firstAuthor;
1221 CLogDataVector selEntries;
1222 GitRev revLowest, revHighest;
1223 GitRevRangeArray revisionRanges;
1225 POSITION pos = GetFirstSelectedItemPosition();
1226 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1227 revisionRanges.AddRevision(pLogEntry->Rev);
1228 selEntries.push_back(pLogEntry);
1229 firstAuthor = pLogEntry->sAuthor;
1230 revLowest = pLogEntry->Rev;
1231 revHighest = pLogEntry->Rev;
1232 while (pos)
1234 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1235 revisionRanges.AddRevision(pLogEntry->Rev);
1236 selEntries.push_back(pLogEntry);
1237 if (firstAuthor.Compare(pLogEntry->sAuthor))
1238 bAllFromTheSameAuthor = false;
1239 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1240 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1244 #endif
1246 int FirstSelect=-1, LastSelect=-1;
1247 pos = GetFirstSelectedItemPosition();
1248 FirstSelect = GetNextSelectedItem(pos);
1249 while(pos)
1251 LastSelect = GetNextSelectedItem(pos);
1253 //entry is selected, now show the popup menu
1254 CIconMenu popup;
1255 CIconMenu submenu;
1256 if (popup.CreatePopupMenu())
1259 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1260 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1262 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1263 popup.AppendMenuIcon(ID_REBASE_SQUASH,IDS_REBASE_SQUASH, IDI_SQUASH);
1265 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1266 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1268 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1269 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1271 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1272 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1273 popup.AppendMenu(MF_SEPARATOR, NULL);
1275 if (GetSelectedCount() == 1)
1279 if(pSelLogEntry->m_CommitHash != GIT_REV_ZERO)
1281 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))
1282 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1283 // TODO:
1284 // TortoiseMerge could be improved to take a /blame switch
1285 // and then not 'cat' the files from a unified diff but
1286 // blame then.
1287 // But until that's implemented, the context menu entry for
1288 // this feature is commented out.
1289 //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);
1290 }else
1292 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1293 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1295 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))
1296 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1298 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1299 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1300 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1301 popup.AppendMenu(MF_SEPARATOR, NULL);
1304 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1305 // {
1306 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1307 // }
1308 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1309 // {
1310 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1311 // }
1312 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1313 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1314 // {
1315 // popup.AppendMenu(MF_SEPARATOR, NULL);
1316 // }
1318 //if (m_hasWC)
1319 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1320 //if (m_hasWC)
1321 // popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1322 //if (m_hasWC)
1323 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);
1325 CString str,format;
1326 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1327 str.Format(format,g_Git.GetCurrentBranch());
1329 if(pSelLogEntry->m_CommitHash != GIT_REV_ZERO)
1331 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))
1332 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1334 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV))
1335 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1337 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1338 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1340 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1341 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_COPY);
1343 format.LoadString(IDS_REBASE_THIS_FORMAT);
1344 str.Format(format,g_Git.GetCurrentBranch());
1346 if(pSelLogEntry->m_CommitHash != m_HeadHash)
1347 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1348 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1350 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1351 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1354 popup.AppendMenu(MF_SEPARATOR, NULL);
1359 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)
1361 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1362 popup.AppendMenuIcon(ID_STASH_APPLY,IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1363 popup.AppendMenu(MF_SEPARATOR, NULL);
1366 if (GetSelectedCount() >= 2)
1368 bool bAddSeparator = false;
1369 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1371 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))
1372 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1375 if (GetSelectedCount() == 2)
1377 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);
1378 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))
1379 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1380 bAddSeparator = true;
1383 if (m_hasWC)
1385 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1386 // if (m_hasWC)
1387 // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);
1388 bAddSeparator = true;
1390 if (bAddSeparator)
1391 popup.AppendMenu(MF_SEPARATOR, NULL);
1394 if ( GetSelectedCount() >0 && pSelLogEntry->m_CommitHash != GIT_REV_ZERO)
1396 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1398 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))
1400 CString head;
1401 int headindex;
1402 headindex = this->GetHeadIndex();
1403 if(headindex>=0)
1405 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1406 CString hash=g_Git.GetHash(head);
1407 hash=hash.Left(40);
1408 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
1409 if(pLastEntry->m_CommitHash == hash)
1410 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1414 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK))
1415 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1417 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1418 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH))
1419 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1421 popup.AppendMenu(MF_SEPARATOR, NULL);
1426 #if 0
1427 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))
1428 // {
1429 // popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);
1430 // }
1431 // if (GetSelectedCount() == 1)
1432 // {
1433 // popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);
1434 // popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"
1435 // popup.AppendMenu(MF_SEPARATOR, NULL);
1436 // }
1437 #endif
1440 if (GetSelectedCount() == 1)
1442 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
1443 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH);
1445 if (GetSelectedCount() != 0)
1447 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
1448 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);
1451 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
1452 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);
1455 if (GetSelectedCount() == 1)
1457 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1459 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1461 CString str;
1462 str.LoadString(IDS_DELETE_BRANCHTAG);
1463 if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )
1465 str+=_T(" ");
1466 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);
1467 popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE);
1469 else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )
1472 submenu.CreatePopupMenu();
1473 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1475 submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("..."));
1478 popup.AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT) submenu.m_hMenu,str);
1486 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1487 // DialogEnableWindow(IDOK, FALSE);
1488 // SetPromptApp(&theApp);
1490 this->ContextMenuAction(cmd, FirstSelect, LastSelect);
1492 // EnableOKButton();
1493 } // if (popup.CreatePopupMenu())
1497 bool CGitLogListBase::IsSelectionContinuous()
1499 if ( GetSelectedCount()==1 )
1501 // if only one revision is selected, the selection is of course
1502 // continuous
1503 return true;
1506 POSITION pos = GetFirstSelectedItemPosition();
1507 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
1508 if (bContinuous)
1510 int itemindex = GetNextSelectedItem(pos);
1511 while (pos)
1513 int nextindex = GetNextSelectedItem(pos);
1514 if (nextindex - itemindex > 1)
1516 bContinuous = false;
1517 break;
1519 itemindex = nextindex;
1522 return bContinuous;
1525 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)
1528 CString sClipdata;
1529 POSITION pos = GetFirstSelectedItemPosition();
1530 if (pos != NULL)
1532 CString sRev;
1533 sRev.LoadString(IDS_LOG_REVISION);
1534 CString sAuthor;
1535 sAuthor.LoadString(IDS_LOG_AUTHOR);
1536 CString sDate;
1537 sDate.LoadString(IDS_LOG_DATE);
1538 CString sMessage;
1539 sMessage.LoadString(IDS_LOG_MESSAGE);
1540 while (pos)
1542 CString sLogCopyText;
1543 CString sPaths;
1544 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));
1546 if(!HashOnly)
1548 //pLogEntry->m_Files
1549 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
1551 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)
1553 sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();
1554 sPaths += _T("\r\n");
1556 sPaths.Trim();
1557 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"),
1558 (LPCTSTR)sRev, pLogEntry->m_CommitHash,
1559 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,
1560 (LPCTSTR)sDate,
1561 (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),
1562 (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,
1563 (LPCTSTR)sPaths);
1564 sClipdata += sLogCopyText;
1565 }else
1567 sClipdata += pLogEntry->m_CommitHash;
1568 break;
1572 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
1577 void CGitLogListBase::DiffSelectedRevWithPrevious()
1579 if (m_bThreadRunning)
1580 return;
1582 int FirstSelect=-1, LastSelect=-1;
1583 POSITION pos = GetFirstSelectedItemPosition();
1584 FirstSelect = GetNextSelectedItem(pos);
1585 while(pos)
1587 LastSelect = GetNextSelectedItem(pos);
1590 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect);
1592 #if 0
1593 UpdateLogInfoLabel();
1594 int selIndex = m_LogList.GetSelectionMark();
1595 if (selIndex < 0)
1596 return;
1597 int selCount = m_LogList.GetSelectedCount();
1598 if (selCount != 1)
1599 return;
1601 // Find selected entry in the log list
1602 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1603 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1604 long rev1 = pLogEntry->Rev;
1605 long rev2 = rev1-1;
1606 CTGitPath path = m_path;
1608 // See how many files under the relative root were changed in selected revision
1609 int nChanged = 0;
1610 LogChangedPath * changed = NULL;
1611 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
1613 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);
1614 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1616 ++nChanged;
1617 changed = cpath;
1621 if (m_path.IsDirectory() && nChanged == 1)
1623 // We're looking at the log for a directory and only one file under dir was changed in the revision
1624 // Do diff on that file instead of whole directory
1625 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
1628 m_bCancelled = FALSE;
1629 DialogEnableWindow(IDOK, FALSE);
1630 SetPromptApp(&theApp);
1631 theApp.DoWaitCursor(1);
1633 if (PromptShown())
1635 GitDiff diff(this, m_hWnd, true);
1636 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1637 diff.SetHEADPeg(m_LogRevision);
1638 diff.ShowCompare(path, rev2, path, rev1);
1640 else
1642 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1645 theApp.DoWaitCursor(-1);
1646 EnableOKButton();
1647 #endif
1650 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1652 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
1653 *pResult = -1;
1655 if (pFindInfo->lvfi.flags & LVFI_PARAM)
1656 return;
1657 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
1658 return;
1659 if (pFindInfo->lvfi.psz == 0)
1660 return;
1661 #if 0
1662 CString sCmp = pFindInfo->lvfi.psz;
1663 CString sRev;
1664 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
1666 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
1667 sRev.Format(_T("%ld"), pLogEntry->Rev);
1668 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
1670 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
1672 *pResult = i;
1673 return;
1676 else
1678 if (sCmp.Compare(sRev)==0)
1680 *pResult = i;
1681 return;
1685 if (pFindInfo->lvfi.flags & LVFI_WRAP)
1687 for (int i=0; i<pFindInfo->iStart; ++i)
1689 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));
1690 sRev.Format(_T("%ld"), pLogEntry->Rev);
1691 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
1693 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
1695 *pResult = i;
1696 return;
1699 else
1701 if (sCmp.Compare(sRev)==0)
1703 *pResult = i;
1704 return;
1709 #endif
1710 *pResult = -1;
1713 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
1715 ClearText();
1717 this->m_logEntries.ClearAll();
1718 this->m_logEntries.ParserFromLog(path,-1,info,from,to);
1720 //this->m_logEntries.ParserFromLog();
1721 SetItemCountEx(this->m_logEntries.size());
1723 this->m_arShownList.RemoveAll();
1725 for(unsigned int i=0;i<m_logEntries.size();i++)
1727 if(m_IsOldFirst)
1729 m_logEntries[m_logEntries.size()-i-1].m_IsFull=TRUE;
1730 this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);
1732 }else
1734 m_logEntries[i].m_IsFull=TRUE;
1735 this->m_arShownList.Add(&m_logEntries[i]);
1739 if(path)
1740 m_Path=*path;
1741 return 0;
1745 int CGitLogListBase::FillGitShortLog()
1747 ClearText();
1749 this->m_logEntries.ClearAll();
1751 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
1753 CTGitPath *path;
1754 if(this->m_Path.IsEmpty())
1755 path=NULL;
1756 else
1757 path=&this->m_Path;
1759 CString hash;
1760 int mask;
1761 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
1762 // if(this->m_bAllBranch)
1763 mask |= m_ShowMask;
1765 if(m_bShowWC)
1766 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev);
1768 this->m_logEntries.FetchShortLog(path,m_StartRef,-1,mask,m_bShowWC?1:0);
1770 //this->m_logEntries.ParserFromLog();
1771 if(IsInWorkingThread())
1773 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
1775 else
1777 SetItemCountEx(this->m_logEntries.size());
1780 this->m_arShownList.RemoveAll();
1782 for(unsigned int i=0;i<m_logEntries.size();i++)
1784 if(i>0 || m_logEntries[i].m_CommitHash != GIT_REV_ZERO)
1785 m_logEntries[i].m_Subject=_T("parser...");
1787 if(this->m_IsOldFirst)
1789 this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-1-i]);
1791 }else
1793 this->m_arShownList.Add(&m_logEntries[i]);
1796 return 0;
1799 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
1801 // Skip Ctrl-C when copying text out of the log message or search filter
1802 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1803 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1805 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1807 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1809 DiffSelectedRevWithPrevious();
1810 return TRUE;
1813 #if 0
1814 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
1816 DiffSelectedFile();
1817 return TRUE;
1819 #endif
1822 #if 0
1823 if (m_hAccel && !bSkipAccelerator)
1825 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1826 if (ret)
1827 return TRUE;
1830 #endif
1831 //m_tooltips.RelayEvent(pMsg);
1832 return __super::PreTranslateMessage(pMsg);
1835 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1837 // a double click on an entry in the revision list has happened
1838 *pResult = 0;
1840 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1841 DiffSelectedRevWithPrevious();
1844 int CGitLogListBase::FetchLogAsync(void * data)
1846 m_ProcData=data;
1847 m_bExitThread=FALSE;
1848 InterlockedExchange(&m_bThreadRunning, TRUE);
1849 InterlockedExchange(&m_bNoDispUpdates, TRUE);
1850 m_LoadingThread = AfxBeginThread(LogThreadEntry, this);
1851 if (m_LoadingThread ==NULL)
1853 InterlockedExchange(&m_bThreadRunning, FALSE);
1854 InterlockedExchange(&m_bNoDispUpdates, FALSE);
1855 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1856 return -1;
1858 return 0;
1861 //this is the thread function which calls the subversion function
1862 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
1864 return ((CGitLogListBase*)pVoid)->LogThread();
1867 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
1869 //CTime time;
1870 oldest=CTime::GetCurrentTime();
1871 latest=CTime(1971,1,2,0,0,0);
1872 for(unsigned int i=0;i<m_logEntries.size();i++)
1874 if(m_logEntries[i].m_AuthorDate.GetTime() < oldest.GetTime())
1875 oldest = m_logEntries[i].m_AuthorDate.GetTime();
1877 if(m_logEntries[i].m_AuthorDate.GetTime() > latest.GetTime())
1878 latest = m_logEntries[i].m_AuthorDate.GetTime();
1883 //Helper class for FetchFullLogInfo()
1884 class CGitCall_FetchFullLogInfo : public CGitCall
1886 public:
1887 CGitCall_FetchFullLogInfo(CGitLogListBase* ploglist):m_ploglist(ploglist),m_CollectedCount(0){}
1888 virtual bool OnOutputData(const BYTE* data, size_t size)
1890 if(size==0)
1891 return m_ploglist->m_bExitThread;
1892 //Add received data to byte collector
1893 m_ByteCollector.append(data,size);
1895 //Find loginfo endmarker
1896 static const BYTE dataToFind[]={0,0,'#','<'};
1897 int found=m_ByteCollector.findData(dataToFind,4);
1898 if(found<0)
1899 return m_ploglist->m_bExitThread;//Not found
1900 found+=2;//Position after loginfo end-marker
1902 //Prepare data for OnLogInfo and call it
1903 BYTE_VECTOR logInfo;
1904 logInfo.append(&*m_ByteCollector.begin(),found);
1905 OnLogInfo(logInfo);
1907 //Remove loginfo from bytecollector
1908 m_ByteCollector.erase(m_ByteCollector.begin(),m_ByteCollector.begin()+found);
1910 return m_ploglist->m_bExitThread;
1912 virtual void OnEnd()
1914 //Rest should be a complete log line.
1915 if(!m_ByteCollector.empty())
1916 OnLogInfo(m_ByteCollector);
1920 void OnLogInfo(BYTE_VECTOR& logInfo)
1922 GitRev fullRev;
1923 fullRev.ParserFromLog(logInfo);
1924 MAP_HASH_REV::iterator itRev=m_ploglist->m_logEntries.m_HashMap.find(fullRev.m_CommitHash);
1925 if(itRev==m_ploglist->m_logEntries.m_HashMap.end())
1927 //Should not occur, only when Git-tree updated in the mean time. (Race condition)
1928 return;//Ignore
1930 //Set updating
1931 int rev=itRev->second;
1932 GitRev* revInVector=&m_ploglist->m_logEntries[rev];
1935 if(revInVector->m_IsFull)
1936 return;
1938 if(!m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev]))
1940 ++m_CollectedCount;
1941 InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsUpdateing,FALSE);
1942 InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsFull,TRUE);
1943 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);
1944 return;
1947 // fullRev.m_IsUpdateing=TRUE;
1948 // fullRev.m_IsFull=TRUE;
1951 if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE))
1952 return;//Cannot update this row now. Ignore.
1953 TCHAR oldmark=revInVector->m_Mark;
1954 GIT_REV_LIST oldlist=revInVector->m_ParentHash;
1955 // CString oldhash=m_CommitHash;
1957 //Parse new rev info
1958 revInVector->ParserFromLog(logInfo);
1960 if(oldmark!=0)
1961 revInVector->m_Mark=oldmark; //parser full log will cause old mark overwrited.
1962 //So we need keep old bound mark.
1963 revInVector->m_ParentHash=oldlist;
1965 //update cache
1966 m_ploglist->m_LogCache.AddCacheEntry(*revInVector);
1968 //Reset updating
1969 InterlockedExchange(&revInVector->m_IsFull,TRUE);
1970 InterlockedExchange(&revInVector->m_IsUpdateing,FALSE);
1972 //Notify listcontrol and update progress bar
1973 ++m_CollectedCount;
1975 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);
1977 DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30;
1978 if(percent == GITLOG_END)
1979 percent = GITLOG_END -1;
1981 ::PostMessage(m_ploglist->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
1984 CGitLogListBase* m_ploglist;
1985 BYTE_VECTOR m_ByteCollector;
1986 int m_CollectedCount;
1990 void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to)
1992 CGitCall_FetchFullLogInfo fetcher(this);
1993 int mask=
1994 CGit::LOG_INFO_FULL_DIFF|
1995 CGit::LOG_INFO_STAT|
1996 CGit::LOG_INFO_FILESTATE|
1997 CGit::LOG_INFO_DETECT_COPYRENAME|
1998 CGit::LOG_INFO_SHOW_MERGEDFILE |
1999 m_ShowMask;
2001 CTGitPath *path;
2002 if(this->m_Path.IsEmpty())
2003 path=NULL;
2004 else
2005 path=&this->m_Path;
2007 g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to);
2010 void CGitLogListBase::FetchLastLogInfo()
2012 unsigned int updated=0;
2013 int percent=0;
2014 CRect rect;
2016 for(unsigned int i=0;i<m_logEntries.size();i++)
2018 if(m_logEntries[i].m_IsFull)
2019 continue;
2021 if(m_LogCache.GetCacheData(m_logEntries[i]))
2023 if(!m_logEntries.FetchFullInfo(i))
2025 updated++;
2027 m_LogCache.AddCacheEntry(m_logEntries[i]);
2029 }else
2031 updated++;
2032 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);
2033 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);
2036 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
2038 if(m_bExitThread)
2040 InterlockedExchange(&m_bThreadRunning, FALSE);
2041 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2042 return;
2048 UINT CGitLogListBase::LogThread()
2051 // if(m_ProcCallBack)
2052 // m_ProcCallBack(m_ProcData,GITLOG_START);
2053 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2055 InterlockedExchange(&m_bThreadRunning, TRUE);
2056 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2058 //does the user force the cache to refresh (shift or control key down)?
2059 bool refresh = (GetKeyState (VK_CONTROL) < 0)
2060 || (GetKeyState (VK_SHIFT) < 0);
2062 //disable the "Get All" button while we're receiving
2063 //log messages.
2065 FillGitShortLog();
2067 if(this->m_bExitThread)
2069 InterlockedExchange(&m_bThreadRunning, FALSE);
2070 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2071 return 0;
2073 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2074 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0);
2076 int start=0; CString firstcommit,lastcommit;
2077 int update=0;
2078 for(int i=0;i<m_logEntries.size();i++)
2080 if( i==0 && m_logEntries[i].m_CommitHash == GIT_REV_ZERO)
2082 m_logEntries[i].m_Files.Clear();
2083 m_logEntries[i].m_ParentHash.clear();
2084 m_logEntries[i].m_ParentHash.push_back(m_HeadHash);
2085 g_Git.GetCommitDiffList(m_logEntries[i].m_CommitHash,this->m_HeadHash,m_logEntries[i].m_Files);
2086 m_logEntries[i].m_Action =0;
2087 for(int j=0;j< m_logEntries[i].m_Files.GetCount();j++)
2088 m_logEntries[i].m_Action |= m_logEntries[i].m_Files[j].m_Action;
2090 m_logEntries[i].m_Body.Format(_T("%d files changed"),m_logEntries[i].m_Files.GetCount());
2091 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
2092 continue;
2095 start=this->m_logEntries[i].ParserFromLog(m_logEntries.m_RawlogData,start);
2096 m_logEntries.m_HashMap[m_logEntries[i].m_CommitHash]=i;
2098 if(m_LogCache.GetCacheData(m_logEntries[i]))
2100 if(firstcommit.IsEmpty())
2101 firstcommit=m_logEntries[i].m_CommitHash;
2102 lastcommit=m_logEntries[i].m_CommitHash;
2104 }else
2106 InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);
2107 InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);
2108 update++;
2110 if(start<0)
2111 break;
2112 if(start>=m_logEntries.m_RawlogData.size())
2113 break;
2115 int percent=i*30/m_logEntries.size() + GITLOG_START+1;
2117 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0);
2118 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0);
2120 if(this->m_bExitThread)
2122 InterlockedExchange(&m_bThreadRunning, FALSE);
2123 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2124 return 0;
2127 if(!lastcommit.IsEmpty())
2128 FetchFullLogInfo(lastcommit,firstcommit);
2130 this->FetchLastLogInfo();
2132 #if 0
2133 RedrawItems(0, m_arShownList.GetCount());
2134 // SetRedraw(false);
2135 // ResizeAllListCtrlCols();
2136 // SetRedraw(true);
2138 if ( m_pStoreSelection )
2140 // Deleting the instance will restore the
2141 // selection of the CLogDlg.
2142 delete m_pStoreSelection;
2143 m_pStoreSelection = NULL;
2145 else
2147 // If no selection has been set then this must be the first time
2148 // the revisions are shown. Let's preselect the topmost revision.
2149 if ( GetItemCount()>0 )
2151 SetSelectionMark(0);
2152 SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2155 #endif
2159 //FetchFullLogInfo();
2160 //FetchFullLogInfoOrig();
2161 //RefreshCursor();
2162 // make sure the filter is applied (if any) now, after we refreshed/fetched
2163 // the log messages
2165 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2167 InterlockedExchange(&m_bThreadRunning, FALSE);
2169 return 0;
2172 void CGitLogListBase::Refresh()
2174 m_bExitThread=TRUE;
2175 if(m_LoadingThread!=NULL)
2177 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
2178 if(ret == WAIT_TIMEOUT)
2179 TerminateThread();
2182 this->SetItemCountEx(0);
2183 this->Clear();
2185 //Update branch and Tag info
2186 ReloadHashMap();
2187 //Assume Thread have exited
2188 //if(!m_bThreadRunning)
2191 m_logEntries.clear();
2192 m_bExitThread=FALSE;
2193 InterlockedExchange(&m_bThreadRunning, TRUE);
2194 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2195 if (AfxBeginThread(LogThreadEntry, this)==NULL)
2197 InterlockedExchange(&m_bThreadRunning, FALSE);
2198 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2199 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2201 m_sFilterText.Empty();
2202 m_From=CTime(1970,1,2,0,0,0);
2203 m_To=CTime::GetCurrentTime();
2206 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2210 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2211 if (!bMatchCase)
2212 type |= tr1::regex_constants::icase;
2213 pat = tr1::wregex(regexp_str, type);
2214 return true;
2216 catch (exception) {}
2217 return false;
2220 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)
2223 pShownlist->RemoveAll();
2224 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2225 bool bRegex = false;
2226 if (m_bFilterWithRegex)
2227 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2229 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2230 CString sRev;
2231 for (DWORD i=0; i<m_logEntries.size(); ++i)
2233 if ((bRegex)&&(m_bFilterWithRegex))
2235 #if 0
2236 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2238 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
2239 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
2241 pShownlist->Add(m_logEntries[i]);
2242 continue;
2245 #endif
2246 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2248 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Subject);
2249 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Subject), pat, flags)&&IsEntryInDateRange(i))
2251 pShownlist->Add(&m_logEntries[i]);
2252 continue;
2255 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries[i].m_Body);
2256 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_Body), pat, flags)&&IsEntryInDateRange(i))
2258 pShownlist->Add(&m_logEntries[i]);
2259 continue;
2262 #if 0
2263 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2265 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
2267 bool bGoing = true;
2268 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
2270 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2271 if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))
2273 pShownlist->Add(m_logEntries[i]);
2274 bGoing = false;
2275 continue;
2277 if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))
2279 pShownlist->Add(m_logEntries[i]);
2280 bGoing = false;
2281 continue;
2283 if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))
2285 pShownlist->Add(m_logEntries[i]);
2286 bGoing = false;
2287 continue;
2290 if (!bGoing)
2291 continue;
2293 #endif
2294 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2296 if (regex_search(wstring((LPCTSTR)m_logEntries[i].m_AuthorName), pat, flags)&&IsEntryInDateRange(i))
2298 pShownlist->Add(&m_logEntries[i]);
2299 continue;
2302 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2304 sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash);
2305 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
2307 pShownlist->Add(&m_logEntries[i]);
2308 continue;
2311 } // if (bRegex)
2312 else
2314 CString find = m_sFilterText;
2315 find.MakeLower();
2316 #if 0
2317 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
2319 CString sBugIDs = m_logEntries[i]->sBugIDs;
2321 sBugIDs = sBugIDs.MakeLower();
2322 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2324 pShownlist->Add(m_logEntries[i]);
2325 continue;
2328 #endif
2329 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))
2331 CString msg = m_logEntries[i].m_Subject;
2333 msg = msg.MakeLower();
2334 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2336 pShownlist->Add(&m_logEntries[i]);
2337 continue;
2339 msg = m_logEntries[i].m_Body;
2341 msg = msg.MakeLower();
2342 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2344 pShownlist->Add(&m_logEntries[i]);
2345 continue;
2348 #if 0
2349 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))
2351 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;
2353 bool bGoing = true;
2354 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)
2356 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2357 CString path = cpath->sCopyFromPath;
2358 path.MakeLower();
2359 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2361 pShownlist->Add(m_logEntries[i]);
2362 bGoing = false;
2363 continue;
2365 path = cpath->sPath;
2366 path.MakeLower();
2367 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2369 pShownlist->Add(m_logEntries[i]);
2370 bGoing = false;
2371 continue;
2373 path = cpath->GetAction();
2374 path.MakeLower();
2375 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
2377 pShownlist->Add(m_logEntries[i]);
2378 bGoing = false;
2379 continue;
2383 #endif
2384 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))
2386 CString msg = m_logEntries[i].m_AuthorName;
2387 msg = msg.MakeLower();
2388 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2390 pShownlist->Add(&m_logEntries[i]);
2391 continue;
2394 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))
2396 sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash);
2397 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
2399 pShownlist->Add(&m_logEntries[i]);
2400 continue;
2403 } // else (from if (bRegex))
2404 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
2408 BOOL CGitLogListBase::IsEntryInDateRange(int i)
2410 __time64_t time = m_logEntries[i].m_AuthorDate.GetTime();
2411 if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))
2412 return TRUE;
2414 return FALSE;
2416 // return TRUE;
2418 void CGitLogListBase::StartFilter()
2420 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2421 RecalculateShownList(&m_arShownList);
2422 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2425 DeleteAllItems();
2426 SetItemCountEx(ShownCountWithStopped());
2427 RedrawItems(0, ShownCountWithStopped());
2428 SetRedraw(false);
2429 //ResizeAllListCtrlCols();
2430 SetRedraw(true);
2431 Invalidate();
2434 void CGitLogListBase::RemoveFilter()
2437 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2439 m_arShownList.RemoveAll();
2441 // reset the time filter too
2442 #if 0
2443 m_timFrom = (__time64_t(m_tFrom));
2444 m_timTo = (__time64_t(m_tTo));
2445 m_DateFrom.SetTime(&m_timFrom);
2446 m_DateTo.SetTime(&m_timTo);
2447 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
2448 m_DateTo.SetRange(&m_timFrom, &m_timTo);
2449 #endif
2451 for (DWORD i=0; i<m_logEntries.size(); ++i)
2453 if(this->m_IsOldFirst)
2455 m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);
2456 }else
2458 m_arShownList.Add(&m_logEntries[i]);
2461 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
2462 DeleteAllItems();
2463 SetItemCountEx(ShownCountWithStopped());
2464 RedrawItems(0, ShownCountWithStopped());
2465 // SetRedraw(false);
2466 // ResizeAllListCtrlCols();
2467 // SetRedraw(true);
2469 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2472 void CGitLogListBase::Clear()
2474 m_arShownList.RemoveAll();
2475 DeleteAllItems();
2477 m_logEntries.ClearAll();
2481 void CGitLogListBase::OnDestroy()
2483 // save the column widths to the registry
2484 SaveColumnWidths();
2486 if(this->m_bThreadRunning)
2488 this->m_bExitThread=true;
2489 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);
2490 if(ret == WAIT_TIMEOUT)
2491 TerminateThread();
2493 while(m_LogCache.SaveCache())
2495 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
2496 MB_YESNO) == IDNO)
2497 break;
2499 CHintListCtrl::OnDestroy();
2502 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
2504 CRect rect;
2505 int i=(int)wParam;
2506 this->GetItemRect(i,&rect,LVIR_BOUNDS);
2507 this->InvalidateRect(rect);
2509 if(this->GetItemState(i,LVIF_STATE) & LVIS_SELECTED)
2511 int i=0;
2513 return 0;
2517 * Save column widths to the registry
2519 void CGitLogListBase::SaveColumnWidths()
2521 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
2522 if (pHdrCtrl)
2524 int numcols = pHdrCtrl->GetItemCount();
2525 for (int col = 0; col < numcols; col++)
2527 int width = GetColumnWidth( col );
2528 CString regentry;
2529 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
2530 CRegDWORD regwidth(regentry, 0);
2531 regwidth = width; // this writes it to reg
2536 int CGitLogListBase::GetHeadIndex()
2538 if(m_HeadHash.IsEmpty())
2539 return -1;
2541 for(int i=0;i<m_arShownList.GetCount();i++)
2543 GitRev *pRev = (GitRev*)m_arShownList[i];
2544 if(pRev)
2546 if(pRev->m_CommitHash == m_HeadHash )
2547 return i;
2550 return -1;