Refactored: Do not initialize repository dependent variables in constructor
[TortoiseGit.git] / src / TortoiseProc / GitLogListBase.cpp
blobe8f254c81d837bd109801afe804f269f2a895374
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
5 // Copyright (C) 2011-2012 - Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // GitLogList.cpp : implementation file
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "GitLogListBase.h"
26 #include "GitRev.h"
27 //#include "VssStyle.h"
28 #include "IconMenu.h"
29 // CGitLogListBase
30 #include "cursor.h"
31 #include "InputDlg.h"
32 #include "GITProgressDlg.h"
33 #include "ProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
37 #include "Logdlg.h"
38 #include "MessageBox.h"
39 #include "registry.h"
40 #include "LoglistUtils.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
44 #include "TempFile.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
47 #include "IconMenu.h"
48 //#include "RevisionRangeDlg.h"
49 //#include "BrowseFolder.h"
50 //#include "BlameDlg.h"
51 //#include "Blame.h"
52 //#include "GitHelpers.h"
53 #include "GitStatus.h"
54 //#include "LogDlgHelper.h"
55 //#include "CachedLogInfo.h"
56 //#include "RepositoryInfo.h"
57 //#include "EditPropertiesDlg.h"
58 #include "FileDiffDlg.h"
59 #include "..\\TortoiseShell\\Resource.h"
60 #include "FindDlg.h"
61 #include "SysInfo.h"
63 const UINT CGitLogListBase::m_FindDialogMessage = RegisterWindowMessage(FINDMSGSTRING);
64 const UINT CGitLogListBase::m_ScrollToMessage = RegisterWindowMessage(_T("TORTOISEGIT_LOG_SCROLLTO"));
66 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)
68 CGitLogListBase::CGitLogListBase():CHintListCtrl()
69 ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)
70 ,m_nSearchIndex(0)
71 ,m_bNoDispUpdates(FALSE)
72 , m_bThreadRunning(FALSE)
73 , m_bStrictStopped(false)
74 , m_pStoreSelection(NULL)
75 , m_SelectedFilters(LOGFILTER_ALL)
76 , m_bShowWC(false)
77 , m_logEntries(&m_LogCache)
78 , m_pFindDialog(NULL)
79 , m_ColumnManager(this)
80 , m_dwDefaultColumns(0)
81 , m_arShownList(&m_critSec)
82 , m_hasWC(true)
83 , m_bNoHightlightHead(FALSE)
84 , m_ShowRefMask(LOGLIST_SHOWALLREFS)
86 // use the default GUI font, create a copy of it and
87 // change the copy to BOLD (leave the rest of the font
88 // the same)
89 HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
90 LOGFONT lf = {0};
91 GetObject(hFont, sizeof(LOGFONT), &lf);
92 lf.lfWeight = FW_BOLD;
93 m_boldFont = CreateFontIndirect(&lf);
95 m_bShowBugtraqColumn=false;
97 m_IsIDReplaceAction=FALSE;
99 this->m_critSec.Init();
100 m_wcRev.m_CommitHash.Empty();
101 m_wcRev.GetSubject() = CString(MAKEINTRESOURCE(IDS_LOG_WORKINGDIRCHANGES));
102 m_wcRev.m_ParentHash.clear();
103 m_wcRev.m_Mark=_T('-');
104 m_wcRev.m_IsUpdateing=FALSE;
105 m_wcRev.m_IsFull = TRUE;
107 m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
108 m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
109 m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
110 m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
111 m_hFetchIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONFETCHING), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
113 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
115 m_From = -1;
116 m_To = -1;
118 m_ShowMask = 0;
119 m_LoadingThread = NULL;
121 InterlockedExchange(&m_bExitThread,FALSE);
122 m_IsOldFirst = FALSE;
123 m_IsRebaseReplaceGraph = FALSE;
125 for(int i=0;i<Lanes::COLORS_NUM;i++)
127 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));
129 // get short/long datetime setting from registry
130 DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);
131 if ( RegUseShortDateFormat )
133 m_DateFormat = DATE_SHORTDATE;
135 else
137 m_DateFormat = DATE_LONGDATE;
139 // get relative time display setting from registry
140 DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);
141 m_bRelativeTimes = (regRelativeTimes != 0);
142 m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;
144 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);
145 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);
146 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);
147 m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);
148 m_ContextMenuMask &= ~GetContextMenuBit(ID_LOG);
149 m_ContextMenuMask &= ~GetContextMenuBit(ID_BLAME);
151 m_ColumnRegKey=_T("log");
153 m_bSymbolizeRefNames = !!CRegDWORD(_T("Software\\TortoiseGit\\SymbolizeRefNames"), FALSE);
155 m_AsyncThreadExit = FALSE;
156 m_AsyncDiffEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL);
157 m_AsynDiffListLock.Init();
159 m_DiffingThread = AfxBeginThread(AsyncThread, this, THREAD_PRIORITY_BELOW_NORMAL);
160 if (m_DiffingThread ==NULL)
162 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
163 return;
168 int CGitLogListBase::AsyncDiffThread()
170 m_AsyncThreadExited = false;
171 while(!m_AsyncThreadExit)
173 ::WaitForSingleObject(m_AsyncDiffEvent, INFINITE);
175 GitRev *pRev = NULL;
176 while(!m_AsyncThreadExit && !m_AsynDiffList.empty())
178 m_AsynDiffListLock.Lock();
179 pRev = m_AsynDiffList.back();
180 m_AsynDiffList.pop_back();
181 m_AsynDiffListLock.Unlock();
183 if( pRev->m_CommitHash.IsEmpty() )
185 if(pRev->m_IsDiffFiles)
186 continue;
188 pRev->GetFiles(this).Clear();
189 pRev->m_ParentHash.clear();
190 pRev->m_ParentHash.push_back(m_HeadHash);
191 if(g_Git.IsInitRepos())
193 g_Git.GetInitAddList(pRev->GetFiles(this));
196 else
198 g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this));
200 pRev->GetAction(this) = 0;
202 for(int j=0;j< pRev->GetFiles(this).GetCount();j++)
203 pRev->GetAction(this) |= pRev->GetFiles(this)[j].m_Action;
205 pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER);
207 InterlockedExchange(&pRev->m_IsDiffFiles, TRUE);
208 InterlockedExchange(&pRev->m_IsFull, TRUE);
210 pRev->GetBody().Format(IDS_FILESCHANGES, pRev->GetFiles(this).GetCount());
211 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);
212 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
215 if(!pRev->CheckAndDiff())
216 { // fetch change file list
217 for(int i=GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex()+GetCountPerPage(); i++)
219 if(i < m_arShownList.GetCount())
221 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(i);
222 if(data->m_CommitHash == pRev->m_CommitHash)
224 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);
225 break;
230 if(!m_AsyncThreadExit && GetSelectedCount() == 1)
232 POSITION pos = GetFirstSelectedItemPosition();
233 int nItem = GetNextSelectedItem(pos);
235 if(nItem>=0)
237 GitRev* data = (GitRev*)m_arShownList[nItem];
238 if(data)
239 if(data->m_CommitHash == pRev->m_CommitHash)
241 this->GetParent()->PostMessage(WM_COMMAND, MSG_FETCHED_DIFF, 0);
248 m_AsyncThreadExited = true;
249 return 0;
251 void CGitLogListBase::hideFromContextMenu(unsigned __int64 hideMask, bool exclusivelyShow)
253 if (exclusivelyShow)
255 m_ContextMenuMask &= hideMask;
257 else
259 m_ContextMenuMask &= ~hideMask;
263 CGitLogListBase::~CGitLogListBase()
265 InterlockedExchange(&m_bNoDispUpdates, TRUE);
266 this->m_arShownList.SafeRemoveAll();
268 DestroyIcon(m_hModifiedIcon);
269 DestroyIcon(m_hReplacedIcon);
270 DestroyIcon(m_hAddedIcon);
271 DestroyIcon(m_hDeletedIcon);
272 m_logEntries.ClearAll();
274 if (m_boldFont)
275 DeleteObject(m_boldFont);
277 if ( m_pStoreSelection )
279 delete m_pStoreSelection;
280 m_pStoreSelection = NULL;
283 SafeTerminateThread();
284 SafeTerminateAsyncDiffThread();
286 if(m_AsyncDiffEvent)
287 CloseHandle(m_AsyncDiffEvent);
291 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)
292 ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
293 ON_REGISTERED_MESSAGE(m_ScrollToMessage, OnScrollToMessage)
294 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)
295 ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)
296 ON_WM_CONTEXTMENU()
297 ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)
298 ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)
299 ON_WM_CREATE()
300 ON_WM_DESTROY()
301 ON_MESSAGE(MSG_LOADED,OnLoad)
302 ON_WM_MEASUREITEM()
303 ON_WM_MEASUREITEM_REFLECT()
304 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
305 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
306 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
307 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
308 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
309 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
310 END_MESSAGE_MAP()
312 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
314 //if (m_nRowHeight>0)
316 lpMeasureItemStruct->itemHeight = 50;
320 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)
322 PreSubclassWindow();
323 return CHintListCtrl::OnCreate(lpCreateStruct);
326 void CGitLogListBase::PreSubclassWindow()
328 SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
329 // load the icons for the action columns
330 // m_Theme.Open(m_hWnd, L"ListView");
331 SetWindowTheme(m_hWnd, L"Explorer", NULL);
332 CHintListCtrl::PreSubclassWindow();
335 void CGitLogListBase::InsertGitColumn()
337 CString temp;
339 CRegDWORD regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE);
340 DWORD exStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES;
341 if (DWORD(regFullRowSelect))
342 exStyle |= LVS_EX_FULLROWSELECT;
343 SetExtendedStyle(exStyle);
345 // only load properties if we have a repository
346 if (GitAdminDir().HasAdminDir(g_Git.m_CurrentDir) || GitAdminDir().IsBareRepo(g_Git.m_CurrentDir))
347 UpdateProjectProperties();
349 static UINT normal[] =
351 IDS_LOG_GRAPH,
352 IDS_LOG_REBASE,
353 IDS_LOG_ID,
354 IDS_LOG_HASH,
355 IDS_LOG_ACTIONS,
356 IDS_LOG_MESSAGE,
357 IDS_LOG_AUTHOR,
358 IDS_LOG_DATE,
359 IDS_LOG_EMAIL,
360 IDS_LOG_COMMIT_NAME,
361 IDS_LOG_COMMIT_EMAIL,
362 IDS_LOG_COMMIT_DATE,
363 IDS_LOG_BUGIDS,
366 static int with[] =
368 ICONITEMBORDER+16*4,
369 ICONITEMBORDER+16*4,
370 ICONITEMBORDER+16*4,
371 ICONITEMBORDER+16*4,
372 ICONITEMBORDER+16*4,
373 LOGLIST_MESSAGE_MIN,
374 ICONITEMBORDER+16*4,
375 ICONITEMBORDER+16*4,
376 ICONITEMBORDER+16*4,
377 ICONITEMBORDER+16*4,
378 ICONITEMBORDER+16*4,
379 ICONITEMBORDER+16*4,
380 ICONITEMBORDER+16*4,
382 m_dwDefaultColumns = GIT_LOG_GRAPH|GIT_LOG_ACTIONS|GIT_LOG_MESSAGE|GIT_LOG_AUTHOR|GIT_LOG_DATE;
384 DWORD hideColumns = 0;
385 if(this->m_IsRebaseReplaceGraph)
387 hideColumns |= GIT_LOG_GRAPH;
388 m_dwDefaultColumns |= GIT_LOG_REBASE;
390 else
392 hideColumns |= GIT_LOG_REBASE;
395 if(this->m_IsIDReplaceAction)
397 hideColumns |= GIT_LOG_ACTIONS;
398 m_dwDefaultColumns |= GIT_LOG_ID;
399 m_dwDefaultColumns |= GIT_LOG_HASH;
401 else
403 hideColumns |= GIT_LOG_ID;
405 if(this->m_bShowBugtraqColumn)
407 m_dwDefaultColumns |= GIT_LOGLIST_BUG;
409 else
411 hideColumns |= GIT_LOGLIST_BUG;
413 SetRedraw(false);
415 m_ColumnManager.SetNames(normal, _countof(normal));
416 m_ColumnManager.ReadSettings(m_dwDefaultColumns, hideColumns, m_ColumnRegKey+_T("loglist"), _countof(normal), with);
418 SetRedraw(true);
422 * Resizes all columns in a list control to values in registry.
424 void CGitLogListBase::ResizeAllListCtrlCols()
426 // column max and min widths to allow
427 static const int nMinimumWidth = 10;
428 static const int nMaximumWidth = 1000;
429 CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));
430 if (pHdrCtrl)
432 int numcols = pHdrCtrl->GetItemCount();
433 for (int col = 0; col < numcols; col++)
435 // get width for this col last time from registry
436 CString regentry;
437 regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);
438 CRegDWORD regwidth(regentry, 0);
439 int cx = regwidth;
440 if ( cx == 0 )
442 // no saved value, setup sensible defaults
443 if (col == this->LOGLIST_MESSAGE)
445 cx = LOGLIST_MESSAGE_MIN;
447 else
449 cx = ICONITEMBORDER+16*4;
452 if (cx < nMinimumWidth)
454 cx = nMinimumWidth;
456 else if (cx > nMaximumWidth)
458 cx = nMaximumWidth;
461 SetColumnWidth(col, cx);
468 void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect)
470 LVITEM rItem;
471 SecureZeroMemory(&rItem, sizeof(LVITEM));
472 rItem.mask = LVIF_STATE;
473 rItem.iItem = (int)Index;
474 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
475 GetItem(&rItem);
477 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(Index);
478 HBRUSH brush = NULL;
480 if (!(rItem.state & LVIS_SELECTED))
482 if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
483 brush = ::CreateSolidBrush(RGB(156,156,156));
484 else if(pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
485 brush = ::CreateSolidBrush(RGB(200,200,128));
487 else if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
489 if (rItem.state & LVIS_SELECTED)
491 if (::GetFocus() == m_hWnd)
492 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
493 else
494 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));
498 if (brush != NULL)
500 ::FillRect(hdc, &rect, brush);
501 ::DeleteObject(brush);
505 void DrawTrackingRoundRect(HDC hdc, CRect rect, HBRUSH brush, COLORREF darkColor)
507 POINT point = { 4, 4 };
508 CRect rt2 = rect;
509 rt2.DeflateRect(1, 1);
510 rt2.OffsetRect(2, 2);
512 HPEN nullPen = ::CreatePen(PS_NULL, 0, 0);
513 HPEN oldpen = (HPEN)::SelectObject(hdc, nullPen);
514 HBRUSH darkBrush = (HBRUSH)::CreateSolidBrush(darkColor);
515 HBRUSH oldbrush = (HBRUSH)::SelectObject(hdc, darkBrush);
516 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
518 ::SelectObject(hdc, brush);
519 rt2.OffsetRect(-2, -2);
520 ::RoundRect(hdc, rt2.left, rt2.top, rt2.right, rt2.bottom, point.x, point.y);
521 ::SelectObject(hdc, oldbrush);
522 ::SelectObject(hdc, oldpen);
523 ::DeleteObject(nullPen);
524 ::DeleteObject(darkBrush);
527 void DrawLightning(HDC hdc, CRect rect, COLORREF color, int bold)
529 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
530 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
531 ::MoveToEx(hdc, rect.left + 7, rect.top, NULL);
532 ::LineTo(hdc, rect.left + 1, (rect.top + rect.bottom) / 2);
533 ::LineTo(hdc, rect.left + 6, (rect.top + rect.bottom) / 2);
534 ::LineTo(hdc, rect.left, rect.bottom);
535 ::SelectObject(hdc, oldpen);
536 ::DeleteObject(pen);
539 void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold)
541 HPEN pen = ::CreatePen(PS_SOLID, bold, color);
542 HPEN oldpen = (HPEN)::SelectObject(hdc, pen);
543 ::MoveToEx(hdc, (rect.left + rect.right) / 2, rect.top, NULL);
544 ::LineTo(hdc, rect.left, rect.bottom);
545 ::LineTo(hdc, rect.right, rect.bottom);
546 ::LineTo(hdc, (rect.left + rect.right) / 2, rect.top);
547 ::SelectObject(hdc, oldpen);
548 ::DeleteObject(pen);
551 void CGitLogListBase::DrawTagBranch(HDC hdc, CRect &rect, INT_PTR index, std::vector<REFLABEL> refList)
553 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
554 CRect rt=rect;
555 LVITEM rItem;
556 SecureZeroMemory(&rItem, sizeof(LVITEM));
557 rItem.mask = LVIF_STATE;
558 rItem.iItem = (int)index;
559 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
560 GetItem(&rItem);
562 CDC W_Dc;
563 W_Dc.Attach(hdc);
565 HTHEME hTheme = NULL;
566 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
567 hTheme = OpenThemeData(m_hWnd, L"Explorer::ListView;ListView");
569 for (unsigned int i = 0; i < refList.size(); i++)
571 CString shortname = !refList[i].simplifiedName.IsEmpty() ? refList[i].simplifiedName : refList[i].name;
572 HBRUSH brush = 0;
573 COLORREF colRef = refList[i].color;
574 bool singleRemote = refList[i].singleRemote;
575 bool hasTracking = refList[i].hasTracking;
576 bool sameName = refList[i].sameName;
578 //When row selected, ajust label color
579 if (!(IsAppThemed() && SysInfo::Instance().IsVistaOrLater()))
580 if (rItem.state & LVIS_SELECTED)
581 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);
583 brush = ::CreateSolidBrush(colRef);
585 if(!shortname.IsEmpty() && (rt.left<rect.right) )
587 SIZE size;
588 memset(&size,0,sizeof(SIZE));
589 GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);
591 rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);
592 rt.right+=8;
594 int textpos = DT_CENTER;
596 if(rt.right > rect.right)
598 rt.right = rect.right;
599 textpos =0;
602 CRect textRect = rt;
604 if (singleRemote)
606 rt.right += 8;
607 textRect.OffsetRect(8, 0);
610 if (sameName)
611 rt.right += 8;
613 if (hasTracking)
615 DrawTrackingRoundRect(hdc, rt, brush, m_Colors.Darken(colRef, 100));
617 else
619 //Fill interior of ref label
620 ::FillRect(hdc, &rt, brush);
623 //Draw edge of label
625 CRect rectEdge = rt;
627 if (!hasTracking)
629 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 100), m_Colors.Darken(colRef, 100));
630 rectEdge.DeflateRect(1, 1);
631 W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef, 50), m_Colors.Darken(colRef, 50));
634 //Draw text inside label
635 bool customColor = (colRef & 0xff) * 30 + ((colRef >> 8) & 0xff) * 59 + ((colRef >> 16) & 0xff) * 11 <= 12800; // check if dark background
636 if (!customColor && IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
638 int txtState = LISS_NORMAL;
639 if (rItem.state & LVIS_SELECTED)
640 txtState = LISS_SELECTED;
642 DrawThemeText(hTheme, hdc, LVP_LISTITEM, txtState, shortname, -1, textpos | DT_SINGLELINE | DT_VCENTER, 0, &textRect);
644 else
646 W_Dc.SetBkMode(TRANSPARENT);
647 if (customColor || (rItem.state & LVIS_SELECTED))
649 COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
650 COLORREF clrOld = ::SetTextColor(hdc,clrNew);
651 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
652 ::SetTextColor(hdc,clrOld);
654 else
656 ::DrawText(hdc, shortname, shortname.GetLength(), &textRect, textpos | DT_SINGLELINE | DT_VCENTER);
660 if (singleRemote)
662 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
663 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
664 CRect newRect;
665 newRect.SetRect(rt.left + 4, rt.top + 4, rt.left + 8, rt.bottom - 4);
666 DrawLightning(hdc, newRect, color, bold);
669 if (sameName)
671 COLORREF color = ::GetSysColor(customColor ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
672 int bold = data->m_CommitHash == m_HeadHash ? 2 : 1;
673 CRect newRect;
674 newRect.SetRect(rt.right - 12, rt.top + 4, rt.right - 4, rt.bottom - 4);
675 DrawUpTriangle(hdc, newRect, color, bold);
678 //::MoveToEx(hdc,rt.left,rt.top,NULL);
679 //::LineTo(hdc,rt.right,rt.top);
680 //::LineTo(hdc,rt.right,rt.bottom);
681 //::LineTo(hdc,rt.left,rt.bottom);
682 //::LineTo(hdc,rt.left,rt.top);
684 rt.left=rt.right+1;
686 if(brush)
687 ::DeleteObject(brush);
689 rt.right=rect.right;
691 if (IsAppThemed() && SysInfo::Instance().IsVistaOrLater())
693 int txtState = LISS_NORMAL;
694 if (rItem.state & LVIS_SELECTED)
695 txtState = LISS_SELECTED;
697 DrawThemeText(hTheme,hdc, LVP_LISTITEM, txtState, data->GetSubject(), -1, DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS, 0, &rt);
699 else
701 if (rItem.state & LVIS_SELECTED)
703 COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));
704 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
705 ::SetTextColor(hdc,clrOld);
707 else
709 ::DrawText(hdc,data->GetSubject(),data->GetSubject().GetLength(),&rt,DT_NOPREFIX | DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
713 if (hTheme)
714 CloseThemeData(hTheme);
716 W_Dc.Detach();
719 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {
721 // Returns ((256 - amount)*col1 + amount*col2) / 256;
722 return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256,
723 ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,
724 ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256);
727 Gdiplus::Color GetGdiColor(COLORREF col)
729 return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));
731 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,
732 const COLORREF& col,const COLORREF& activeColor, int top
735 int h = laneHeight / 2;
736 int m = (x1 + x2) / 2;
737 int r = (x2 - x1) / 3;
738 int d = 2 * r;
740 #define P_CENTER m , h+top
741 #define P_0 x2, h+top
742 #define P_90 m , 0+top-1
743 #define P_180 x1, h+top
744 #define P_270 m , 2 * h+top +1
745 #define R_CENTER m - r, h - r+top, d, d
748 #define DELTA_UR_B 2*(x1 - m), 2*h +top
749 #define DELTA_UR_E 0*16, 90*16 +top // -,
751 #define DELTA_DR_B 2*(x1 - m), 2*-h +top
752 #define DELTA_DR_E 270*16, 90*16 +top // -'
754 #define DELTA_UL_B 2*(x2 - m), 2*h +top
755 #define DELTA_UL_E 90*16, 90*16 +top // ,-
757 #define DELTA_DL_B 2*(x2 - m),2*-h +top
758 #define DELTA_DL_E 180*16, 90*16 // '-
760 #define CENTER_UR x1, 2*h, 225
761 #define CENTER_DR x1, 0 , 135
762 #define CENTER_UL x2, 2*h, 315
763 #define CENTER_DL x2, 0 , 45
766 Gdiplus::Graphics graphics( hdc );
768 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
770 // arc
771 switch (type) {
772 case Lanes::JOIN:
773 case Lanes::JOIN_R:
774 case Lanes::HEAD:
775 case Lanes::HEAD_R:
777 Gdiplus::LinearGradientBrush gradient(
778 Gdiplus::Point(x1-2, h+top-2),
779 Gdiplus::Point(P_270),
780 GetGdiColor(activeColor),GetGdiColor(col));
783 Gdiplus::Pen mypen(&gradient,2);
784 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
786 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
787 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1,laneHeight,270,90);
788 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
790 break;
792 case Lanes::JOIN_L:
795 Gdiplus::LinearGradientBrush gradient(
796 Gdiplus::Point(P_270),
797 Gdiplus::Point(x2+1, h+top-1),
798 GetGdiColor(col),GetGdiColor(activeColor));
801 Gdiplus::Pen mypen(&gradient,2);
802 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);
804 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);
805 graphics.DrawArc(&mypen,x1+(x2-x1)/2,top+h-1, x2-x1,laneHeight,180,90);
806 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);
809 break;
811 case Lanes::TAIL:
812 case Lanes::TAIL_R:
815 Gdiplus::LinearGradientBrush gradient(
816 Gdiplus::Point(x1-2, h+top-2),
817 Gdiplus::Point(P_90),
818 GetGdiColor(activeColor),GetGdiColor(col));
820 Gdiplus::Pen mypen(&gradient,2);
822 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1,laneHeight,0,90);
824 #if 0
825 QConicalGradient gradient(CENTER_DR);
826 gradient.setColorAt(0.375, activeCol);
827 gradient.setColorAt(0.625, col);
828 myPen.setBrush(gradient);
829 p->setPen(myPen);
830 p->drawArc(P_CENTER, DELTA_DR);
831 #endif
832 break;
834 default:
835 break;
839 //static QPen myPen(Qt::black, 2); // fast path here
840 CPen pen;
841 pen.CreatePen(PS_SOLID,2,col);
842 //myPen.setColor(col);
843 HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);
845 Gdiplus::Pen myPen(GetGdiColor(col),2);
847 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
849 //p->setPen(myPen);
851 // vertical line
852 switch (type) {
853 case Lanes::ACTIVE:
854 case Lanes::NOT_ACTIVE:
855 case Lanes::MERGE_FORK:
856 case Lanes::MERGE_FORK_R:
857 case Lanes::MERGE_FORK_L:
858 case Lanes::JOIN:
859 case Lanes::JOIN_R:
860 case Lanes::JOIN_L:
861 case Lanes::CROSS:
862 //DrawLine(hdc,P_90,P_270);
863 graphics.DrawLine(&myPen,P_90,P_270);
864 //p->drawLine(P_90, P_270);
865 break;
866 case Lanes::HEAD_L:
867 case Lanes::BRANCH:
868 //DrawLine(hdc,P_CENTER,P_270);
869 graphics.DrawLine(&myPen,P_CENTER,P_270);
870 //p->drawLine(P_CENTER, P_270);
871 break;
872 case Lanes::TAIL_L:
873 case Lanes::INITIAL:
874 case Lanes::BOUNDARY:
875 case Lanes::BOUNDARY_C:
876 case Lanes::BOUNDARY_R:
877 case Lanes::BOUNDARY_L:
878 //DrawLine(hdc,P_90, P_CENTER);
879 graphics.DrawLine(&myPen,P_90,P_CENTER);
880 //p->drawLine(P_90, P_CENTER);
881 break;
882 default:
883 break;
886 myPen.SetColor(GetGdiColor(activeColor));
888 // horizontal line
889 switch (type) {
890 case Lanes::MERGE_FORK:
891 case Lanes::JOIN:
892 case Lanes::HEAD:
893 case Lanes::TAIL:
894 case Lanes::CROSS:
895 case Lanes::CROSS_EMPTY:
896 case Lanes::BOUNDARY_C:
897 //DrawLine(hdc,P_180,P_0);
898 graphics.DrawLine(&myPen,P_180,P_0);
899 //p->drawLine(P_180, P_0);
900 break;
901 case Lanes::MERGE_FORK_R:
902 case Lanes::BOUNDARY_R:
903 //DrawLine(hdc,P_180,P_CENTER);
904 graphics.DrawLine(&myPen,P_180,P_CENTER);
905 //p->drawLine(P_180, P_CENTER);
906 break;
907 case Lanes::MERGE_FORK_L:
908 case Lanes::HEAD_L:
909 case Lanes::TAIL_L:
910 case Lanes::BOUNDARY_L:
911 //DrawLine(hdc,P_CENTER,P_0);
912 graphics.DrawLine(&myPen,P_CENTER,P_0);
913 //p->drawLine(P_CENTER, P_0);
914 break;
915 default:
916 break;
919 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
921 CBrush brush;
922 brush.CreateSolidBrush(col);
923 HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);
925 Gdiplus::SolidBrush myBrush(GetGdiColor(col));
926 // center symbol, e.g. rect or ellipse
927 switch (type) {
928 case Lanes::ACTIVE:
929 case Lanes::INITIAL:
930 case Lanes::BRANCH:
932 //p->setPen(Qt::NoPen);
933 //p->setBrush(col);
934 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
935 graphics.FillEllipse(&myBrush, R_CENTER);
936 //p->drawEllipse(R_CENTER);
937 break;
938 case Lanes::MERGE_FORK:
939 case Lanes::MERGE_FORK_R:
940 case Lanes::MERGE_FORK_L:
941 //p->setPen(Qt::NoPen);
942 //p->setBrush(col);
943 //p->drawRect(R_CENTER);
944 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
945 graphics.FillRectangle(&myBrush, R_CENTER);
946 break;
947 case Lanes::UNAPPLIED:
948 // Red minus sign
949 //p->setPen(Qt::NoPen);
950 //p->setBrush(Qt::red);
951 //p->drawRect(m - r, h - 1, d, 2);
952 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
953 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
954 break;
955 case Lanes::APPLIED:
956 // Green plus sign
957 //p->setPen(Qt::NoPen);
958 //p->setBrush(DARK_GREEN);
959 //p->drawRect(m - r, h - 1, d, 2);
960 //p->drawRect(m - 1, h - r, 2, d);
961 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
962 graphics.FillRectangle(&myBrush,m-r,h-1,d,2);
963 graphics.FillRectangle(&myBrush,m-1,h-r,2,d);
964 break;
965 case Lanes::BOUNDARY:
966 //p->setBrush(back);
967 //p->drawEllipse(R_CENTER);
968 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
969 graphics.DrawEllipse(&myPen, R_CENTER);
970 break;
971 case Lanes::BOUNDARY_C:
972 case Lanes::BOUNDARY_R:
973 case Lanes::BOUNDARY_L:
974 //p->setBrush(back);
975 //p->drawRect(R_CENTER);
976 graphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
977 graphics.FillRectangle(&myBrush,R_CENTER);
978 break;
979 default:
980 break;
983 ::SelectObject(hdc,oldpen);
984 ::SelectObject(hdc,oldbrush);
985 #undef P_CENTER
986 #undef P_0
987 #undef P_90
988 #undef P_180
989 #undef P_270
990 #undef R_CENTER
993 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
995 // TODO: unfinished
996 // return;
997 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(index);
998 if(data->m_CommitHash.IsEmpty())
999 return;
1001 CRect rt=rect;
1002 LVITEM rItem;
1003 SecureZeroMemory(&rItem, sizeof(LVITEM));
1004 rItem.mask = LVIF_STATE;
1005 rItem.iItem = (int)index;
1006 rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1007 GetItem(&rItem);
1009 // p->translate(QPoint(opt.rect.left(), opt.rect.top()));
1011 if (data->m_Lanes.empty())
1012 m_logEntries.setLane(data->m_CommitHash);
1014 std::vector<int>& lanes=data->m_Lanes;
1015 size_t laneNum = lanes.size();
1016 UINT activeLane = 0;
1017 for (UINT i = 0; i < laneNum; i++)
1018 if (Lanes::isMerge(lanes[i])) {
1019 activeLane = i;
1020 break;
1023 int x1 = 0, x2 = 0;
1024 int maxWidth = rect.Width();
1025 int lw = 3 * rect.Height() / 4; //laneWidth()
1027 COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];
1028 //if (opt.state & QStyle::State_Selected)
1029 // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);
1031 for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++)
1034 x1 = x2;
1035 x2 += lw;
1037 int ln = lanes[i];
1038 if (ln == Lanes::EMPTY)
1039 continue;
1041 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];
1042 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);
1045 #if 0
1046 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {
1048 x1 = x2;
1049 x2 += lw;
1051 int ln = lanes[i];
1052 if (ln == Lanes::EMPTY)
1053 continue;
1055 UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)
1056 || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;
1058 if (ln == Lanes::CROSS)
1060 paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1061 paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);
1063 else
1064 paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);
1066 #endif
1070 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1073 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1074 // Take the default processing unless we set this to something else below.
1075 *pResult = CDRF_DODEFAULT;
1077 if (m_bNoDispUpdates)
1078 return;
1080 switch (pLVCD->nmcd.dwDrawStage)
1082 case CDDS_PREPAINT:
1084 *pResult = CDRF_NOTIFYITEMDRAW;
1085 return;
1087 break;
1088 case CDDS_ITEMPREPAINT:
1090 // This is the prepaint stage for an item. Here's where we set the
1091 // item's text color.
1093 // Tell Windows to send draw notifications for each subitem.
1094 *pResult = CDRF_NOTIFYSUBITEMDRAW;
1096 COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
1098 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1100 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1101 if (data)
1103 if (data->GetAction(this)& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) )
1104 crText = RGB(128,128,128);
1106 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_SQUASH)
1107 pLVCD->clrTextBk = RGB(156,156,156);
1108 else if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_EDIT)
1109 pLVCD->clrTextBk = RGB(200,200,128);
1110 else
1111 pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW);
1113 if(data->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_CURRENT)
1115 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1116 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1119 if (data->m_CommitHash == m_HeadHash && m_bNoHightlightHead == FALSE)
1121 SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1122 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1125 // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))
1126 // crText = GetSysColor(COLOR_GRAYTEXT);
1128 if (data->m_CommitHash.IsEmpty())
1130 //crText = GetSysColor(RGB(200,200,0));
1131 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);
1132 // We changed the font, so we're returning CDRF_NEWFONT. This
1133 // tells the control to recalculate the extent of the text.
1134 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;
1138 if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)
1140 if (m_bStrictStopped)
1141 crText = GetSysColor(COLOR_GRAYTEXT);
1143 // Store the color back in the NMLVCUSTOMDRAW struct.
1144 pLVCD->clrText = crText;
1145 return;
1147 break;
1148 case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:
1150 if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))
1152 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);
1155 if (pLVCD->iSubItem == LOGLIST_GRAPH && m_sFilterText.IsEmpty())
1157 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )
1159 CRect rect;
1160 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect);
1162 //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);
1163 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1165 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1166 if( !data ->m_CommitHash.IsEmpty())
1167 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);
1169 *pResult = CDRF_SKIPDEFAULT;
1170 return;
1174 if (pLVCD->iSubItem == LOGLIST_MESSAGE)
1176 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)
1178 GitRev* data = (GitRev*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec);
1179 //if(!data->m_IsFull)
1181 //if(data->SafeFetchFullInfo(&g_Git))
1182 // this->Invalidate();
1183 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);
1186 if (!m_HashMap[data->m_CommitHash].empty())
1188 CRect rect;
1190 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1192 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect);
1194 std::vector<REFLABEL> refsToShow;
1195 STRING_VECTOR remoteTrackingList;
1196 STRING_VECTOR refList = m_HashMap[data->m_CommitHash];
1197 for (unsigned int i = 0; i < refList.size(); i++)
1199 CString str = refList[i];
1201 REFLABEL refLabel;
1202 refLabel.color = RGB(255, 255, 255);
1203 refLabel.singleRemote = false;
1204 refLabel.hasTracking = false;
1205 refLabel.sameName = false;
1206 if (CGit::GetShortName(str, refLabel.name, _T("refs/heads/")))
1208 if (!(m_ShowRefMask & LOGLIST_SHOWLOCALBRANCHES))
1209 continue;
1210 if (refLabel.name == m_CurrentBranch )
1211 refLabel.color = m_Colors.GetColor(CColors::CurrentBranch);
1212 else
1213 refLabel.color = m_Colors.GetColor(CColors::LocalBranch);
1215 std::pair<CString, CString> trackingEntry = m_TrackingMap[refLabel.name];
1216 CString pullRemote = trackingEntry.first;
1217 CString pullBranch = trackingEntry.second;
1218 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
1220 CString defaultUpstream;
1221 defaultUpstream.Format(_T("refs/remotes/%s/%s"), pullRemote, pullBranch);
1222 refLabel.hasTracking = true;
1223 if (m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES)
1225 bool found = false;
1226 for (int j = i + 1; j < refList.size(); j++)
1228 if (refList[j] == defaultUpstream)
1230 found = true;
1231 break;
1235 if (found)
1237 bool sameName = pullBranch == refLabel.name;
1238 refsToShow.push_back(refLabel);
1239 CGit::GetShortName(defaultUpstream, refLabel.name, _T("refs/remotes/"));
1240 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1241 if (m_bSymbolizeRefNames)
1243 if (!m_SingleRemote.IsEmpty())
1244 refLabel.simplifiedName = _T("/") + (sameName ? CString() : pullBranch);
1245 else if (sameName)
1246 refLabel.simplifiedName = pullRemote + _T("/");
1247 refLabel.singleRemote = !m_SingleRemote.IsEmpty();
1248 refLabel.sameName = sameName;
1250 refsToShow.push_back(refLabel);
1251 remoteTrackingList.push_back(defaultUpstream);
1252 continue;
1257 else if (CGit::GetShortName(str, refLabel.name, _T("refs/remotes/")))
1259 if (!(m_ShowRefMask & LOGLIST_SHOWREMOTEBRANCHES))
1260 continue;
1262 bool found = false;
1263 for (int j = 0; j < remoteTrackingList.size(); j++)
1265 if (remoteTrackingList[j] == str)
1267 found = true;
1268 break;
1271 if (found)
1272 continue;
1274 refLabel.color = m_Colors.GetColor(CColors::RemoteBranch);
1275 if (m_bSymbolizeRefNames)
1277 if (!m_SingleRemote.IsEmpty())
1278 refLabel.simplifiedName = _T("/") + refLabel.name.Mid(m_SingleRemote.GetLength() + 1);
1279 refLabel.singleRemote = !m_SingleRemote.IsEmpty();
1282 else if (CGit::GetShortName(str, refLabel.name, _T("refs/tags/")))
1284 if (!(m_ShowRefMask & LOGLIST_SHOWTAGS))
1285 continue;
1286 refLabel.color = m_Colors.GetColor(CColors::Tag);
1288 else if (CGit::GetShortName(str, refLabel.name, _T("refs/stash")))
1290 if (!(m_ShowRefMask & LOGLIST_SHOWSTASH))
1291 continue;
1292 refLabel.color = m_Colors.GetColor(CColors::Stash);
1293 refLabel.name = _T("stash");
1295 else if (CGit::GetShortName(str, refLabel.name, _T("refs/bisect/")))
1297 if (!(m_ShowRefMask & LOGLIST_SHOWBISECT))
1298 continue;
1299 if (refLabel.name.Find(_T("good")) == 0)
1301 refLabel.color = m_Colors.GetColor(CColors::BisectGood);
1302 refLabel.name = _T("good");
1304 if (refLabel.name.Find(_T("bad")) == 0)
1306 refLabel.color = m_Colors.GetColor(CColors::BisectBad);
1307 refLabel.name = _T("bad");
1310 else
1311 continue;
1313 refsToShow.push_back(refLabel);
1316 if (refsToShow.empty())
1318 *pResult = CDRF_DODEFAULT;
1319 return;
1322 DrawTagBranch(pLVCD->nmcd.hdc, rect, pLVCD->nmcd.dwItemSpec, refsToShow);
1324 *pResult = CDRF_SKIPDEFAULT;
1325 return;
1332 if (pLVCD->iSubItem == LOGLIST_ACTION)
1334 if(this->m_IsIDReplaceAction)
1336 *pResult = CDRF_DODEFAULT;
1337 return;
1339 *pResult = CDRF_DODEFAULT;
1341 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)
1342 return;
1344 int nIcons = 0;
1345 int iconwidth = ::GetSystemMetrics(SM_CXSMICON);
1346 int iconheight = ::GetSystemMetrics(SM_CYSMICON);
1348 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec));
1349 CRect rect;
1350 GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);
1351 //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);
1352 // Get the selected state of the
1353 // item being drawn.
1355 // Fill the background if necessary
1356 FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect);
1358 // Draw the icon(s) into the compatible DC
1359 pLogEntry->GetAction(this);
1361 if (!pLogEntry->m_IsDiffFiles)
1362 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1364 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_MODIFIED)
1365 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1366 nIcons++;
1368 if (pLogEntry->GetAction(this) & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )
1369 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1370 nIcons++;
1372 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_DELETED)
1373 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1374 nIcons++;
1376 if (pLogEntry->GetAction(this) & CTGitPath::LOGACTIONS_REPLACED)
1377 ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);
1378 nIcons++;
1379 *pResult = CDRF_SKIPDEFAULT;
1380 return;
1383 break;
1385 *pResult = CDRF_DODEFAULT;
1388 // CGitLogListBase message handlers
1390 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1392 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1394 // Create a pointer to the item
1395 LV_ITEM* pItem = &(pDispInfo)->item;
1397 // Do the list need text information?
1398 if (!(pItem->mask & LVIF_TEXT))
1399 return;
1401 // By default, clear text buffer.
1402 lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);
1404 bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();
1406 *pResult = 0;
1407 if (m_bNoDispUpdates || bOutOfRange)
1408 return;
1410 // Which item number?
1411 int itemid = pItem->iItem;
1412 GitRev * pLogEntry = NULL;
1413 if (itemid < m_arShownList.GetCount())
1414 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(pItem->iItem));
1416 CString temp;
1417 if(m_IsOldFirst)
1419 temp.Format(_T("%d"),pItem->iItem+1);
1422 else
1424 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);
1427 // Which column?
1428 switch (pItem->iSubItem)
1430 case this->LOGLIST_GRAPH: //Graphic
1431 break;
1432 case this->LOGLIST_REBASE:
1434 if(this->m_IsRebaseReplaceGraph)
1436 CTGitPath path;
1437 path.m_Action=pLogEntry->GetAction(this)&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;
1438 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);
1441 break;
1442 case this->LOGLIST_ACTION: //action -- no text in the column
1443 break;
1444 case this->LOGLIST_HASH:
1445 if(pLogEntry)
1446 lstrcpyn(pItem->pszText, pLogEntry->m_CommitHash.ToString(), pItem->cchTextMax);
1447 break;
1448 case this->LOGLIST_ID:
1449 if(this->m_IsIDReplaceAction)
1450 lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);
1451 break;
1452 case this->LOGLIST_MESSAGE: //Message
1453 if (pLogEntry)
1454 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetSubject(), pItem->cchTextMax);
1455 break;
1456 case this->LOGLIST_AUTHOR: //Author
1457 if (pLogEntry)
1458 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorName(), pItem->cchTextMax);
1459 break;
1460 case this->LOGLIST_DATE: //Date
1461 if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) )
1462 lstrcpyn(pItem->pszText,
1463 CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
1464 pItem->cchTextMax);
1465 break;
1467 case this->LOGLIST_EMAIL:
1468 if (pLogEntry)
1469 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetAuthorEmail(), pItem->cchTextMax);
1470 break;
1472 case this->LOGLIST_COMMIT_NAME: //Commit
1473 if (pLogEntry)
1474 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterName(), pItem->cchTextMax);
1475 break;
1477 case this->LOGLIST_COMMIT_EMAIL: //Commit Email
1478 if (pLogEntry)
1479 lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->GetCommitterEmail(), pItem->cchTextMax);
1480 break;
1482 case this->LOGLIST_COMMIT_DATE: //Commit Date
1483 if (pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()))
1484 lstrcpyn(pItem->pszText,
1485 CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes),
1486 pItem->cchTextMax);
1487 break;
1488 case this->LOGLIST_BUG: //Bug ID
1489 if(pLogEntry)
1490 lstrcpyn(pItem->pszText, (LPCTSTR)this->m_ProjectProperties.FindBugID(pLogEntry->GetSubject() + _T("\r\n\r\n") + pLogEntry->GetBody()), pItem->cchTextMax);
1491 break;
1493 default:
1494 ASSERT(false);
1498 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)
1501 if (pWnd == GetHeaderCtrl())
1503 return m_ColumnManager.OnContextMenuHeader(pWnd,point,!!IsGroupViewEnabled());
1506 int selIndex = GetSelectionMark();
1507 if (selIndex < 0)
1508 return; // nothing selected, nothing to do with a context menu
1510 // if the user selected the info text telling about not all revisions shown due to
1511 // the "stop on copy/rename" option, we also don't show the context menu
1512 if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))
1513 return;
1515 // if the context menu is invoked through the keyboard, we have to use
1516 // a calculated position on where to anchor the menu on
1517 if ((point.x == -1) && (point.y == -1))
1519 CRect rect;
1520 GetItemRect(selIndex, &rect, LVIR_LABEL);
1521 ClientToScreen(&rect);
1522 point = rect.CenterPoint();
1524 m_nSearchIndex = selIndex;
1525 m_bCancelled = FALSE;
1527 // calculate some information the context menu commands can use
1528 // CString pathURL = GetURLFromPath(m_path);
1530 POSITION pos = GetFirstSelectedItemPosition();
1531 int indexNext = GetNextSelectedItem(pos);
1532 if (indexNext < 0)
1533 return;
1535 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(indexNext));
1536 #if 0
1537 GitRev revSelected = pSelLogEntry->Rev;
1538 GitRev revPrevious = git_revnum_t(revSelected)-1;
1539 if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))
1541 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)
1543 LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->SafeGetAt(i);
1544 if (changedpath->lCopyFromRev)
1545 revPrevious = changedpath->lCopyFromRev;
1548 GitRev revSelected2;
1549 if (pos)
1551 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1552 revSelected2 = pLogEntry->Rev;
1554 bool bAllFromTheSameAuthor = true;
1555 CString firstAuthor;
1556 CLogDataVector selEntries;
1557 GitRev revLowest, revHighest;
1558 GitRevRangeArray revisionRanges;
1560 POSITION pos = GetFirstSelectedItemPosition();
1561 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1562 revisionRanges.AddRevision(pLogEntry->Rev);
1563 selEntries.push_back(pLogEntry);
1564 firstAuthor = pLogEntry->sAuthor;
1565 revLowest = pLogEntry->Rev;
1566 revHighest = pLogEntry->Rev;
1567 while (pos)
1569 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
1570 revisionRanges.AddRevision(pLogEntry->Rev);
1571 selEntries.push_back(pLogEntry);
1572 if (firstAuthor.Compare(pLogEntry->sAuthor))
1573 bAllFromTheSameAuthor = false;
1574 revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);
1575 revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);
1579 #endif
1581 int FirstSelect=-1, LastSelect=-1;
1582 pos = GetFirstSelectedItemPosition();
1583 FirstSelect = GetNextSelectedItem(pos);
1584 while(pos)
1586 LastSelect = GetNextSelectedItem(pos);
1588 //entry is selected, now show the popup menu
1589 CIconMenu popup;
1590 CIconMenu subbranchmenu, submenu, gnudiffmenu, diffmenu, revertmenu;
1592 if (popup.CreatePopupMenu())
1594 bool isHeadCommit = (pSelLogEntry->m_CommitHash == m_HeadHash);
1595 CString currentBranch = _T("refs/heads/") + g_Git.GetCurrentBranch();
1597 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))
1598 popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK);
1600 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))
1601 popup.AppendMenuIcon(ID_REBASE_SQUASH, IDS_REBASE_SQUASH, IDI_SQUASH);
1603 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))
1604 popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT);
1606 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))
1607 popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP);
1609 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|
1610 GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))
1611 popup.AppendMenu(MF_SEPARATOR, NULL);
1613 if (GetSelectedCount() == 1)
1617 if( !pSelLogEntry->m_CommitHash.IsEmpty())
1619 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE) && m_hasWC) // compare revision with WC
1620 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1622 else
1624 if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))
1625 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);
1627 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1) && m_hasWC) // compare with WC, unified
1629 GitRev *pRev=pSelLogEntry;
1630 if (pSelLogEntry->m_ParentHash.empty())
1632 pRev->GetParentFromHash(pRev->m_CommitHash);
1634 if(pRev->m_ParentHash.size()<=1)
1636 popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
1639 else
1641 gnudiffmenu.CreatePopupMenu();
1642 popup.AppendMenuIcon(ID_GNUDIFF1,IDS_LOG_POPUP_GNUDIFF_PARENT, IDI_DIFF, gnudiffmenu.m_hMenu);
1644 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFF << 16)), CString(MAKEINTRESOURCE(IDS_ALLPARENTS)));
1645 gnudiffmenu.AppendMenuIcon((UINT_PTR)(ID_GNUDIFF1 + (0xFFFE << 16)), CString(MAKEINTRESOURCE(IDS_ONLYMERGEDFILES)));
1647 for(int i=0;i<pRev->m_ParentHash.size();i++)
1649 CString str;
1650 str.Format(IDS_PARENT, i + 1);
1651 gnudiffmenu.AppendMenuIcon(ID_GNUDIFF1+((i+1)<<16),str);
1656 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))
1659 GitRev *pRev=pSelLogEntry;
1660 if (pSelLogEntry->m_ParentHash.empty())
1662 pRev->GetParentFromHash(pRev->m_CommitHash);
1664 if(pRev->m_ParentHash.size()<=1)
1666 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);
1667 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1668 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1670 else
1672 diffmenu.CreatePopupMenu();
1673 popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF, diffmenu.m_hMenu);
1674 for(int i=0;i<pRev->m_ParentHash.size();i++)
1676 CString str;
1677 str.Format(IDS_PARENT, i + 1);
1678 diffmenu.AppendMenuIcon(ID_COMPAREWITHPREVIOUS +((i+1)<<16),str);
1679 if (i == 0 && CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1681 popup.SetDefaultItem(ID_COMPAREWITHPREVIOUS, FALSE);
1682 diffmenu.SetDefaultItem(ID_COMPAREWITHPREVIOUS +((i+1)<<16), FALSE);
1688 if(m_ContextMenuMask&GetContextMenuBit(ID_BLAME))
1689 popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
1691 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);
1692 popup.AppendMenu(MF_SEPARATOR, NULL);
1694 if (pSelLogEntry->m_CommitHash.IsEmpty())
1696 if(m_ContextMenuMask&GetContextMenuBit(ID_STASH_SAVE))
1697 popup.AppendMenuIcon(ID_STASH_SAVE, IDS_MENUSTASHSAVE, IDI_COMMIT);
1700 bool isStash = false;
1701 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1703 if (m_HashMap[pSelLogEntry->m_CommitHash][i] == _T("refs/stash"))
1705 isStash = true;
1706 break;
1710 if (CTGitPath(g_Git.m_CurrentDir).HasStashDir() && (pSelLogEntry->m_CommitHash.IsEmpty() || isStash))
1712 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_POP))
1713 popup.AppendMenuIcon(ID_STASH_POP, IDS_MENUSTASHPOP, IDI_RELOCATE);
1715 if (m_ContextMenuMask&GetContextMenuBit(ID_STASH_LIST))
1716 popup.AppendMenuIcon(ID_STASH_LIST, IDS_MENUSTASHLIST, IDI_LOG);
1718 popup.AppendMenu(MF_SEPARATOR, NULL);
1721 if (pSelLogEntry->m_CommitHash.IsEmpty())
1723 if(m_ContextMenuMask&GetContextMenuBit(ID_FETCH))
1724 popup.AppendMenuIcon(ID_FETCH, IDS_MENUFETCH, IDI_PULL);
1726 popup.AppendMenu(MF_SEPARATOR, NULL);
1730 // if (!m_ProjectProperties.sWebViewerRev.IsEmpty())
1731 // {
1732 // popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);
1733 // }
1734 // if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
1735 // {
1736 // popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
1737 // }
1738 // if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||
1739 // (!m_ProjectProperties.sWebViewerRev.IsEmpty()))
1740 // {
1741 // popup.AppendMenu(MF_SEPARATOR, NULL);
1742 // }
1744 CString str,format;
1745 //if (m_hasWC)
1746 // popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);
1748 if(!pSelLogEntry->m_CommitHash.IsEmpty())
1750 if((m_ContextMenuMask&GetContextMenuBit(ID_LOG)) &&
1751 GetSelectedCount() == 1)
1752 popup.AppendMenuIcon(ID_LOG, IDS_LOG_POPUP_LOG, IDI_LOG);
1754 if (m_ContextMenuMask&GetContextMenuBit(ID_REPOBROWSE))
1755 popup.AppendMenuIcon(ID_REPOBROWSE, IDS_LOG_BROWSEREPO, IDI_REPOBROWSE);
1757 format.LoadString(IDS_LOG_POPUP_MERGEREV);
1758 str.Format(format,g_Git.GetCurrentBranch());
1760 if (m_ContextMenuMask&GetContextMenuBit(ID_MERGEREV) && !isHeadCommit && m_hasWC)
1761 popup.AppendMenuIcon(ID_MERGEREV, str, IDI_MERGE);
1763 format.LoadString(IDS_RESET_TO_THIS_FORMAT);
1764 str.Format(format,g_Git.GetCurrentBranch());
1766 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET) && m_hasWC)
1767 popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);
1770 // Add Switch Branch express Menu
1771 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end()
1772 && (m_ContextMenuMask&GetContextMenuBit(ID_SWITCHBRANCH) && m_hasWC)
1775 std::vector<CString *> branchs;
1776 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)
1778 CString ref = m_HashMap[pSelLogEntry->m_CommitHash][i];
1779 if(ref.Find(_T("refs/heads/")) == 0 && ref != currentBranch)
1781 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1785 CString str;
1786 str.LoadString(IDS_SWITCH_BRANCH);
1788 if(branchs.size() == 1)
1790 str+=_T(" ");
1791 str+= _T('"') + branchs[0]->Mid(11) + _T('"');
1792 popup.AppendMenuIcon(ID_SWITCHBRANCH,str,IDI_SWITCH);
1794 popup.SetMenuItemData(ID_SWITCHBRANCH,(ULONG_PTR)branchs[0]);
1797 else if(branchs.size() > 1)
1799 subbranchmenu.CreatePopupMenu();
1800 for(int i=0;i<branchs.size();i++)
1802 if (*branchs[i] != currentBranch)
1804 subbranchmenu.AppendMenuIcon(ID_SWITCHBRANCH+(i<<16), branchs[i]->Mid(11));
1805 subbranchmenu.SetMenuItemData(ID_SWITCHBRANCH+(i<<16), (ULONG_PTR) branchs[i]);
1809 popup.AppendMenuIcon(ID_SWITCHBRANCH, str, IDI_SWITCH, subbranchmenu.m_hMenu);
1813 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV) && !isHeadCommit && m_hasWC)
1814 popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);
1816 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))
1817 popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);
1819 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))
1820 popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_TAG);
1822 format.LoadString(IDS_REBASE_THIS_FORMAT);
1823 str.Format(format,g_Git.GetCurrentBranch());
1825 if(pSelLogEntry->m_CommitHash != m_HeadHash && m_hasWC)
1826 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))
1827 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);
1829 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))
1830 popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT);
1832 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1834 GitRev *pRev = pSelLogEntry;
1835 if (pSelLogEntry->m_ParentHash.empty())
1837 pRev->GetParentFromHash(pRev->m_CommitHash);
1839 if (pRev->m_ParentHash.size() == 1)
1841 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
1843 else
1845 revertmenu.CreatePopupMenu();
1846 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT, revertmenu.m_hMenu);
1848 for (int i = 0; i < pRev->m_ParentHash.size(); i++)
1850 CString str;
1851 str.Format(IDS_PARENT, i + 1);
1852 revertmenu.AppendMenuIcon(ID_REVERTREV + ((i + 1) << 16), str);
1857 if (m_ContextMenuMask&GetContextMenuBit(ID_EDITNOTE))
1858 popup.AppendMenuIcon(ID_EDITNOTE, IDS_EDIT_NOTES, IDI_EDIT);
1860 popup.AppendMenu(MF_SEPARATOR, NULL);
1865 if(!pSelLogEntry->m_Ref.IsEmpty())
1867 popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE);
1868 if (GetSelectedCount() == 1 && pSelLogEntry->m_Ref.Find(_T("refs/stash")) == 0)
1869 popup.AppendMenuIcon(ID_REFLOG_STASH_APPLY, IDS_MENUSTASHAPPLY, IDI_RELOCATE);
1870 popup.AppendMenu(MF_SEPARATOR, NULL);
1873 if (GetSelectedCount() >= 2)
1875 bool bAddSeparator = false;
1876 if (IsSelectionContinuous() || (GetSelectedCount() == 2))
1878 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) // compare two revisions
1879 popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);
1882 if (GetSelectedCount() == 2)
1884 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2) && m_hasWC) // compare two revisions, unified
1885 popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);
1886 bAddSeparator = true;
1889 if (m_hasWC)
1891 bAddSeparator = true;
1894 if (m_ContextMenuMask&GetContextMenuBit(ID_REVERTREV) && m_hasWC)
1895 popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);
1897 if (bAddSeparator)
1898 popup.AppendMenu(MF_SEPARATOR, NULL);
1901 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))
1903 bool bAddSeparator = false;
1904 if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )
1906 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT) && m_hasWC)
1908 CString head;
1909 int headindex;
1910 headindex = this->GetHeadIndex();
1911 if(headindex>=0)
1913 head.Format(_T("HEAD~%d"),LastSelect-headindex);
1914 CGitHash hash=g_Git.GetHash(head);
1915 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(LastSelect));
1916 if(pLastEntry->m_CommitHash == hash) {
1917 popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);
1918 bAddSeparator = true;
1923 if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK) && !isHeadCommit && m_hasWC) {
1924 if (GetSelectedCount() >= 2)
1925 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSIONS, IDI_EXPORT);
1926 else
1927 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);
1928 bAddSeparator = true;
1931 if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))
1932 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) {
1933 popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);
1934 bAddSeparator = true;
1937 if (bAddSeparator)
1938 popup.AppendMenu(MF_SEPARATOR, NULL);
1941 if (m_hasWC && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive())
1943 popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART);
1944 popup.AppendMenu(MF_SEPARATOR, NULL);
1947 if (GetSelectedCount() == 1)
1949 bool bAddSeparator = false;
1950 if(m_ContextMenuMask&GetContextMenuBit(ID_PUSH) && !m_HashMap[pSelLogEntry->m_CommitHash].empty())
1952 // show the push-option only if the log entry has an associated local branch
1953 bool isLocal = false;
1954 for(int i=0; isLocal == false && i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1956 if (m_HashMap[pSelLogEntry->m_CommitHash][i].Find(_T("refs/heads/")) == 0)
1957 isLocal = true;
1959 if (isLocal)
1961 popup.AppendMenuIcon(ID_PUSH, IDS_LOG_PUSH, IDI_PUSH);
1962 bAddSeparator = true;
1966 if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))
1968 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )
1970 std::vector<CString *> branchs;
1971 for (int i = 0; i < m_HashMap[pSelLogEntry->m_CommitHash].size(); i++)
1973 if(m_HashMap[pSelLogEntry->m_CommitHash][i] != currentBranch)
1974 branchs.push_back(&m_HashMap[pSelLogEntry->m_CommitHash][i]);
1976 CString str;
1977 if (branchs.size() == 1)
1979 str.LoadString(IDS_DELETE_BRANCHTAG_SHORT);
1980 str+=_T(" ");
1981 str += *branchs[0];
1982 popup.AppendMenuIcon(ID_DELETE, str, IDI_DELETE);
1983 popup.SetMenuItemData(ID_DELETE, (ULONG_PTR)branchs[0]);
1984 bAddSeparator = true;
1986 else if (branchs.size() > 1)
1988 str.LoadString(IDS_DELETE_BRANCHTAG);
1989 submenu.CreatePopupMenu();
1990 for (int i = 0; i < branchs.size(); i++)
1992 submenu.AppendMenuIcon(ID_DELETE + (i << 16), *branchs[i]);
1993 submenu.SetMenuItemData(ID_DELETE + (i << 16), (ULONG_PTR)branchs[i]);
1996 popup.AppendMenuIcon(ID_DELETE,str, IDI_DELETE, submenu.m_hMenu);
1997 bAddSeparator = true;
2000 } // m_ContextMenuMask &GetContextMenuBit(ID_DELETE)
2001 if (bAddSeparator)
2002 popup.AppendMenu(MF_SEPARATOR, NULL);
2003 } // GetSelectedCount() == 1
2005 if (GetSelectedCount() != 0)
2007 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))
2008 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);
2009 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))
2010 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD, IDI_COPYCLIP);
2011 if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARDMESSAGES))
2012 popup.AppendMenuIcon(ID_COPYCLIPBOARDMESSAGES, IDS_LOG_POPUP_COPYTOCLIPBOARDMESSAGES, IDI_COPYCLIP);
2015 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))
2016 popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND, IDI_FILTEREDIT);
2018 if (GetSelectedCount() == 1 && m_ContextMenuMask & GetContextMenuBit(ID_SHOWBRANCHES) && !pSelLogEntry->m_CommitHash.IsEmpty())
2019 popup.AppendMenuIcon(ID_SHOWBRANCHES, IDS_LOG_POPUP_SHOWBRANCHES, IDI_SHOWBRANCHES);
2021 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2022 // DialogEnableWindow(IDOK, FALSE);
2023 // SetPromptApp(&theApp);
2025 this->ContextMenuAction(cmd, FirstSelect, LastSelect, &popup);
2027 // EnableOKButton();
2028 } // if (popup.CreatePopupMenu())
2032 bool CGitLogListBase::IsSelectionContinuous()
2034 if ( GetSelectedCount()==1 )
2036 // if only one revision is selected, the selection is of course
2037 // continuous
2038 return true;
2041 POSITION pos = GetFirstSelectedItemPosition();
2042 bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());
2043 if (bContinuous)
2045 int itemindex = GetNextSelectedItem(pos);
2046 while (pos)
2048 int nextindex = GetNextSelectedItem(pos);
2049 if (nextindex - itemindex > 1)
2051 bContinuous = false;
2052 break;
2054 itemindex = nextindex;
2057 return bContinuous;
2060 void CGitLogListBase::CopySelectionToClipBoard(int toCopy)
2063 CString sClipdata;
2064 POSITION pos = GetFirstSelectedItemPosition();
2065 if (pos != NULL)
2067 CString sRev;
2068 sRev.LoadString(IDS_LOG_REVISION);
2069 CString sAuthor;
2070 sAuthor.LoadString(IDS_LOG_AUTHOR);
2071 CString sDate;
2072 sDate.LoadString(IDS_LOG_DATE);
2073 CString sMessage;
2074 sMessage.LoadString(IDS_LOG_MESSAGE);
2075 bool first = true;
2076 while (pos)
2078 CString sLogCopyText;
2079 CString sPaths;
2080 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.SafeGetAt(GetNextSelectedItem(pos)));
2082 if (toCopy == ID_COPY_ALL)
2084 //pLogEntry->GetFiles(this)
2085 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2087 CString from(MAKEINTRESOURCE(IDS_STATUSLIST_FROM));
2088 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->GetFiles(this).GetCount(); ++cpPathIndex)
2090 sPaths += ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetActionName() + _T(": ") + pLogEntry->GetFiles(this)[cpPathIndex].GetGitPathString();
2091 if (((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).m_Action & (CTGitPath::LOGACTIONS_REPLACED|CTGitPath::LOGACTIONS_COPY) && !((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString().IsEmpty())
2093 CString rename;
2094 rename.Format(from, ((CTGitPath&)pLogEntry->GetFiles(this)[cpPathIndex]).GetGitOldPathString());
2095 sPaths += _T(" ") + rename;
2097 sPaths += _T("\r\n");
2099 sPaths.Trim();
2100 CString body = pLogEntry->GetBody();
2101 body.Replace(_T("\n"), _T("\r\n"));
2102 sLogCopyText.Format(_T("%s: %s\r\n%s: %s <%s>\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),
2103 (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(),
2104 (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)pLogEntry->GetAuthorEmail(),
2105 (LPCTSTR)sDate,
2106 (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes),
2107 (LPCTSTR)sMessage, (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim(),
2108 (LPCTSTR)sPaths);
2109 sClipdata += sLogCopyText;
2111 else if (toCopy == ID_COPY_MESSAGE)
2113 CString body = pLogEntry->GetBody();
2114 body.Replace(_T("\n"), _T("\r\n"));
2115 sClipdata += _T("* ") + (pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim()).Trim() + _T("\r\n\r\n");
2117 else if (toCopy == ID_COPY_SUBJECT)
2119 sClipdata += _T("* ") + pLogEntry->GetSubject().Trim() + _T("\r\n\r\n");
2121 else
2123 if (!first)
2124 sClipdata += _T("\r\n");
2125 sClipdata += pLogEntry->m_CommitHash;
2128 first = false;
2130 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());
2135 void CGitLogListBase::DiffSelectedRevWithPrevious()
2137 if (m_bThreadRunning)
2138 return;
2140 int FirstSelect=-1, LastSelect=-1;
2141 POSITION pos = GetFirstSelectedItemPosition();
2142 FirstSelect = GetNextSelectedItem(pos);
2143 while(pos)
2145 LastSelect = GetNextSelectedItem(pos);
2148 ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect, NULL);
2150 #if 0
2151 UpdateLogInfoLabel();
2152 int selIndex = m_LogList.GetSelectionMark();
2153 if (selIndex < 0)
2154 return;
2155 int selCount = m_LogList.GetSelectedCount();
2156 if (selCount != 1)
2157 return;
2159 // Find selected entry in the log list
2160 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2161 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(pos)));
2162 long rev1 = pLogEntry->Rev;
2163 long rev2 = rev1-1;
2164 CTGitPath path = m_path;
2166 // See how many files under the relative root were changed in selected revision
2167 int nChanged = 0;
2168 LogChangedPath * changed = NULL;
2169 for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)
2171 LogChangedPath * cpath = pLogEntry->pArChangedPaths->SafeGetAt(c);
2172 if (cpath && cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2174 ++nChanged;
2175 changed = cpath;
2179 if (m_path.IsDirectory() && nChanged == 1)
2181 // We're looking at the log for a directory and only one file under dir was changed in the revision
2182 // Do diff on that file instead of whole directory
2183 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));
2186 m_bCancelled = FALSE;
2187 DialogEnableWindow(IDOK, FALSE);
2188 SetPromptApp(&theApp);
2189 theApp.DoWaitCursor(1);
2191 if (PromptShown())
2193 GitDiff diff(this, m_hWnd, true);
2194 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2195 diff.SetHEADPeg(m_LogRevision);
2196 diff.ShowCompare(path, rev2, path, rev1);
2198 else
2200 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
2203 theApp.DoWaitCursor(-1);
2204 EnableOKButton();
2205 #endif
2208 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)
2210 LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);
2211 *pResult = -1;
2213 if (pFindInfo->lvfi.flags & LVFI_PARAM)
2214 return;
2215 if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))
2216 return;
2217 if (pFindInfo->lvfi.psz == 0)
2218 return;
2219 #if 0
2220 CString sCmp = pFindInfo->lvfi.psz;
2221 CString sRev;
2222 for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)
2224 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.SafeGetAt(i));
2225 sRev.Format(_T("%ld"), pLogEntry->Rev);
2226 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2228 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2230 *pResult = i;
2231 return;
2234 else
2236 if (sCmp.Compare(sRev)==0)
2238 *pResult = i;
2239 return;
2243 if (pFindInfo->lvfi.flags & LVFI_WRAP)
2245 for (int i=0; i<pFindInfo->iStart; ++i)
2247 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.SafeGetAt(i));
2248 sRev.Format(_T("%ld"), pLogEntry->Rev);
2249 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)
2251 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)
2253 *pResult = i;
2254 return;
2257 else
2259 if (sCmp.Compare(sRev)==0)
2261 *pResult = i;
2262 return;
2267 #endif
2268 *pResult = -1;
2271 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)
2273 ClearText();
2275 this->m_arShownList.SafeRemoveAll();
2277 this->m_logEntries.ClearAll();
2278 if (this->m_logEntries.ParserFromLog(path,-1,info,from,to))
2279 return -1;
2281 //this->m_logEntries.ParserFromLog();
2282 SetItemCountEx((int)m_logEntries.size());
2284 for(unsigned int i=0;i<m_logEntries.size();i++)
2286 if(m_IsOldFirst)
2288 m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;
2289 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
2292 else
2294 m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;
2295 this->m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
2299 ReloadHashMap();
2301 if(path)
2302 m_Path=*path;
2303 return 0;
2307 int CGitLogListBase::BeginFetchLog()
2309 ClearText();
2311 this->m_arShownList.SafeRemoveAll();
2313 this->m_logEntries.ClearAll();
2315 this->m_LogCache.ClearAllParent();
2317 m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);
2319 CTGitPath *path;
2320 if(this->m_Path.IsEmpty())
2321 path=NULL;
2322 else
2323 path=&this->m_Path;
2325 CString hash;
2326 int mask;
2327 mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;
2328 // if(this->m_bAllBranch)
2329 mask |= m_ShowMask ;
2331 if(m_bShowWC)
2333 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);
2334 ResetWcRev();
2335 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;
2338 CString *pFrom, *pTo;
2339 pFrom = pTo = NULL;
2340 CString head(_T("HEAD"));
2341 if(!this->m_startrev.IsEmpty())
2343 pFrom = &this->m_startrev;
2344 if(!this->m_endrev.IsEmpty())
2345 pTo = &this->m_endrev;
2346 else
2347 pTo = &head;
2350 CFilterData data;
2351 data.m_From = m_From;
2352 data.m_To =m_To;
2354 #if 0 /* use tortoiegit filter */
2355 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_AUTHORS)
2356 data.m_Author = this->m_sFilterText;
2358 if(this->m_nSelectedFilter == LOGFILTER_ALL || m_nSelectedFilter == LOGFILTER_MESSAGES)
2359 data.m_MessageFilter = this->m_sFilterText;
2361 data.m_IsRegex = m_bFilterWithRegex;
2362 #endif
2364 // follow does not work for directories
2365 if (!path || path->IsDirectory())
2366 mask &= ~CGit::LOG_INFO_FOLLOW;
2367 // follow does not work with all branches 8at least in TGit)
2368 if (mask & CGit::LOG_INFO_FOLLOW)
2369 mask &= ~CGit::LOG_INFO_ALL_BRANCH;
2371 CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,pFrom,pTo,true,&data);
2373 //this->m_logEntries.ParserFromLog();
2374 if(IsInWorkingThread())
2376 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);
2378 else
2380 SetItemCountEx((int)m_logEntries.size());
2385 git_init();
2387 catch (char* msg)
2389 CString err(msg);
2390 MessageBox(_T("Could not initialize libgit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2391 return -1;
2394 if (g_Git.IsOrphanBranch(m_StartRef))
2396 if (!(mask & CGit::LOG_INFO_ALL_BRANCH))
2397 return 0;
2399 // if show all branches, pick any ref as dummy entry ref
2400 STRING_VECTOR list;
2401 g_Git.GetRefList(list);
2402 if (list.size() == 0)
2403 return 0;
2405 cmd = g_Git.GetLogCmd(list[0], path, -1, mask, pFrom, pTo, true, &data);
2408 try {
2409 if (git_open_log(&m_DllGitLog, CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer()))
2411 return -1;
2414 catch (char* msg)
2416 CString err(msg);
2417 MessageBox(_T("Could not open log.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2418 return -1;
2421 return 0;
2424 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)
2426 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
2428 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))
2430 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2432 DiffSelectedRevWithPrevious();
2433 return TRUE;
2436 #if 0
2437 if (GetFocus()==GetDlgItem(IDC_LOGMSG))
2439 DiffSelectedFile();
2440 return TRUE;
2442 #endif
2444 else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 'A' && GetAsyncKeyState(VK_CONTROL)&0x8000)
2446 // select all entries
2447 for (int i=0; i<GetItemCount(); ++i)
2449 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
2451 return TRUE;
2454 #if 0
2455 if (m_hAccel && !bSkipAccelerator)
2457 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
2458 if (ret)
2459 return TRUE;
2462 #endif
2463 //m_tooltips.RelayEvent(pMsg);
2464 return __super::PreTranslateMessage(pMsg);
2467 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2469 // a double click on an entry in the revision list has happened
2470 *pResult = 0;
2472 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
2473 DiffSelectedRevWithPrevious();
2476 int CGitLogListBase::FetchLogAsync(void * data)
2478 ReloadHashMap();
2479 m_ProcData=data;
2480 m_bExitThread=FALSE;
2481 InterlockedExchange(&m_bThreadRunning, TRUE);
2482 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2483 m_LoadingThread = AfxBeginThread(LogThreadEntry, this, THREAD_PRIORITY_LOWEST);
2484 if (m_LoadingThread ==NULL)
2486 InterlockedExchange(&m_bThreadRunning, FALSE);
2487 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2488 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2489 return -1;
2491 return 0;
2494 //this is the thread function which calls the subversion function
2495 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)
2497 return ((CGitLogListBase*)pVoid)->LogThread();
2500 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)
2502 //CTime time;
2503 oldest=CTime::GetCurrentTime();
2504 latest=CTime(1971,1,2,0,0,0);
2505 for(unsigned int i=0;i<m_logEntries.size();i++)
2507 if(m_logEntries[i].IsEmpty())
2508 continue;
2510 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() < oldest.GetTime())
2511 oldest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2513 if(m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime() > latest.GetTime())
2514 latest = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
2518 if(latest<oldest)
2519 latest=oldest;
2522 UINT CGitLogListBase::LogThread()
2524 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);
2526 InterlockedExchange(&m_bThreadRunning, TRUE);
2527 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2529 ULONGLONG t1,t2;
2531 if(BeginFetchLog())
2533 InterlockedExchange(&m_bThreadRunning, FALSE);
2534 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2536 return 1;
2539 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
2540 bool bRegex = false;
2541 if (m_bFilterWithRegex)
2542 bRegex = ValidateRegexp(m_sFilterText, pat, false);
2544 TRACE(_T("\n===Begin===\n"));
2545 //Update work copy item;
2547 if (!m_logEntries.empty())
2549 GitRev *pRev = &m_logEntries.GetGitRevAt(0);
2551 m_arShownList.SafeAdd(pRev);
2555 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2557 // store commit number of the last selected commit/line before the refresh or -1
2558 int lastSelectedHashNItem = -1;
2559 int ret = 0;
2561 bool shouldWalk = true;
2562 if (g_Git.IsOrphanBranch(m_StartRef))
2564 // walk revisions if show all branches and there exists any ref
2565 if (!(m_ShowMask & CGit::LOG_INFO_ALL_BRANCH))
2566 shouldWalk = false;
2567 else
2569 STRING_VECTOR list;
2570 g_Git.GetRefList(list);
2571 if (list.size() == 0)
2572 shouldWalk = false;
2576 if (shouldWalk)
2578 g_Git.m_critGitDllSec.Lock();
2579 int total = 0;
2582 git_get_log_firstcommit(m_DllGitLog);
2583 total = git_get_log_estimate_commit_count(m_DllGitLog);
2585 catch (char* msg)
2587 CString err(msg);
2588 MessageBox(_T("Could not get first commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2589 ret = -1;
2591 g_Git.m_critGitDllSec.Unlock();
2593 GIT_COMMIT commit;
2594 t2=t1=GetTickCount();
2595 int oldprecentage = 0;
2596 size_t oldsize = m_logEntries.size();
2597 while (ret== 0 && !m_bExitThread)
2599 g_Git.m_critGitDllSec.Lock();
2602 ret = git_get_log_nextcommit(this->m_DllGitLog, &commit, m_ShowMask & CGit::LOG_INFO_FOLLOW);
2604 catch (char* msg)
2606 g_Git.m_critGitDllSec.Unlock();
2607 CString err(msg);
2608 MessageBox(_T("Could not get next commit.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
2609 break;
2611 g_Git.m_critGitDllSec.Unlock();
2613 if(ret)
2614 break;
2616 if (commit.m_ignore == 1)
2618 git_free_commit(&commit);
2619 continue;
2622 //printf("%s\r\n",commit.GetSubject());
2623 if(m_bExitThread)
2624 break;
2626 CGitHash hash = (char*)commit.m_hash ;
2628 GitRev *pRev = m_LogCache.GetCacheData(hash);
2629 pRev->m_GitCommit = commit;
2630 InterlockedExchange(&pRev->m_IsCommitParsed, FALSE);
2632 char *note=NULL;
2633 g_Git.m_critGitDllSec.Lock();
2634 git_get_notes(commit.m_hash,&note);
2635 g_Git.m_critGitDllSec.Unlock();
2637 if(note)
2639 pRev->m_Notes.Empty();
2640 g_Git.StringAppend(&pRev->m_Notes,(BYTE*)note);
2643 if(!pRev->m_IsDiffFiles)
2645 pRev->m_CallDiffAsync = DiffAsync;
2648 pRev->ParserParentFromCommit(&commit);
2650 #ifdef DEBUG
2651 pRev->DbgPrint();
2652 TRACE(_T("\n"));
2653 #endif
2655 if(!m_sFilterText.IsEmpty())
2657 if(!IsMatchFilter(bRegex,pRev,pat))
2658 continue;
2660 this->m_critSec.Lock();
2661 m_logEntries.push_back(hash);
2662 m_arShownList.SafeAdd(pRev);
2663 this->m_critSec.Unlock();
2665 if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash)
2666 lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1;
2668 t2=GetTickCount();
2670 if(t2-t1>500 || (m_logEntries.size()-oldsize >100))
2672 //update UI
2673 int percent = (int)m_logEntries.size() * 100 / total + GITLOG_START + 1;
2674 if(percent > 99)
2675 percent =99;
2676 if(percent < GITLOG_START)
2677 percent = GITLOG_START +1;
2679 oldsize = m_logEntries.size();
2680 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2682 //if( percent > oldprecentage )
2684 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);
2685 oldprecentage = percent;
2687 t1 = t2;
2690 g_Git.m_critGitDllSec.Lock();
2691 git_close_log(m_DllGitLog);
2692 g_Git.m_critGitDllSec.Unlock();
2696 if (m_bExitThread)
2698 InterlockedExchange(&m_bThreadRunning, FALSE);
2699 return 0;
2702 //Update UI;
2703 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL|LVSICF_NOSCROLL);
2705 if (lastSelectedHashNItem >= 0)
2706 PostMessage(m_ScrollToMessage, lastSelectedHashNItem);
2708 if (this->m_hWnd)
2709 ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);
2711 InterlockedExchange(&m_bThreadRunning, FALSE);
2713 return 0;
2716 void CGitLogListBase::FetchRemoteList()
2718 STRING_VECTOR remoteList;
2719 if (!g_Git.GetRemoteList(remoteList))
2720 m_SingleRemote = remoteList.size() == 1 ? remoteList[0] : _T("");
2721 else
2722 m_SingleRemote = _T("");
2725 void CGitLogListBase::FetchTrackingBranchList()
2727 for (MAP_HASH_NAME::iterator it = m_HashMap.begin(); it != m_HashMap.end(); ++it)
2729 for (int j = 0; j < it->second.size(); j++)
2731 CString branchName;
2732 if (CGit::GetShortName(it->second[j], branchName, _T("refs/heads/")))
2734 CString configName;
2735 configName.Format(_T("branch.%s.remote"), branchName);
2736 CString pullRemote = g_Git.GetConfigValue(configName);
2738 configName.Format(_T("branch.%s.merge"), branchName);
2739 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
2741 if (!pullRemote.IsEmpty() && !pullBranch.IsEmpty())
2743 m_TrackingMap[branchName] = std::make_pair(pullRemote, pullBranch);
2750 void CGitLogListBase::Refresh(BOOL IsCleanFilter)
2752 SafeTerminateThread();
2754 this->SetItemCountEx(0);
2755 this->Clear();
2757 ResetWcRev();
2759 // HACK to hide graph column
2760 if (m_ShowMask & CGit::LOG_INFO_FOLLOW)
2761 SetColumnWidth(0, 0);
2762 else
2763 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
2765 //Update branch and Tag info
2766 ReloadHashMap();
2767 //Assume Thread have exited
2768 //if(!m_bThreadRunning)
2770 m_logEntries.clear();
2772 if(IsCleanFilter)
2774 m_sFilterText.Empty();
2775 m_From=-1;
2776 m_To=-1;
2779 InterlockedExchange(&m_bExitThread,FALSE);
2781 InterlockedExchange(&m_bThreadRunning, TRUE);
2782 InterlockedExchange(&m_bNoDispUpdates, TRUE);
2783 if ( (m_LoadingThread=AfxBeginThread(LogThreadEntry, this)) ==NULL)
2785 InterlockedExchange(&m_bThreadRunning, FALSE);
2786 InterlockedExchange(&m_bNoDispUpdates, FALSE);
2787 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
2791 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)
2795 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;
2796 if (!bMatchCase)
2797 type |= tr1::regex_constants::icase;
2798 pat = tr1::wregex(regexp_str, type);
2799 return true;
2801 catch (exception) {}
2802 return false;
2804 BOOL CGitLogListBase::IsMatchFilter(bool bRegex, GitRev *pRev, tr1::wregex &pat)
2807 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
2808 CString sRev;
2810 if ((bRegex)&&(m_bFilterWithRegex))
2812 if (m_SelectedFilters & LOGFILTER_BUGID)
2814 if(this->m_bShowBugtraqColumn)
2816 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2818 ATLTRACE(_T("bugID = \"%s\"\n"), sBugIds);
2819 if (regex_search(wstring(sBugIds), pat, flags))
2821 return TRUE;
2826 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2828 ATLTRACE(_T("messge = \"%s\"\n"), pRev->GetSubject());
2829 if (regex_search(wstring((LPCTSTR)pRev->GetSubject()), pat, flags))
2831 return TRUE;
2835 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2837 ATLTRACE(_T("messge = \"%s\"\n"),pRev->GetBody());
2838 if (regex_search(wstring((LPCTSTR)pRev->GetBody()), pat, flags))
2840 return TRUE;
2844 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2846 if (regex_search(wstring(pRev->GetAuthorName()), pat, flags))
2848 return TRUE;
2851 if (regex_search(wstring(pRev->GetCommitterName()), pat, flags))
2853 return TRUE;
2857 if (m_SelectedFilters & LOGFILTER_REVS)
2859 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2860 if (regex_search(wstring((LPCTSTR)sRev), pat, flags))
2862 return TRUE;
2866 if (m_SelectedFilters & LOGFILTER_PATHS)
2868 CTGitPathList *pathList=NULL;
2869 if( pRev->m_IsDiffFiles)
2870 pathList = &pRev->GetFiles(this);
2871 else
2873 if(!pRev->m_IsSimpleListReady)
2874 pRev->SafeGetSimpleList(&g_Git);
2877 if(pathList)
2878 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount(); ++cpPathIndex)
2880 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitOldPathString()), pat, flags))
2882 return true;
2884 if (regex_search(wstring((LPCTSTR)pathList->m_paths.at(cpPathIndex).GetGitPathString()), pat, flags))
2886 return true;
2890 for(size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2892 if (regex_search(wstring((LPCTSTR)pRev->m_SimpleFileList[i]), pat, flags))
2894 return true;
2899 else
2901 CString find = m_sFilterText;
2902 find.MakeLower();
2904 if (m_SelectedFilters & LOGFILTER_BUGID)
2906 if(this->m_bShowBugtraqColumn)
2908 CString sBugIds = m_ProjectProperties.FindBugID(pRev->GetSubject() + _T("\r\n\r\n") + pRev->GetBody());
2910 sBugIds.MakeLower();
2911 if ((sBugIds.Find(find) >= 0))
2913 return TRUE;
2918 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
2920 CString msg = pRev->GetSubject();
2922 msg = msg.MakeLower();
2923 if ((msg.Find(find) >= 0))
2925 return TRUE;
2929 if (m_SelectedFilters & LOGFILTER_MESSAGES)
2931 CString msg = pRev->GetBody();
2933 msg = msg.MakeLower();
2934 if ((msg.Find(find) >= 0))
2936 return TRUE;
2940 if (m_SelectedFilters & LOGFILTER_AUTHORS)
2942 CString msg = pRev->GetAuthorName();
2943 msg = msg.MakeLower();
2944 if ((msg.Find(find) >= 0))
2946 return TRUE;
2950 if (m_SelectedFilters & LOGFILTER_REVS)
2952 sRev.Format(_T("%s"), pRev->m_CommitHash.ToString());
2953 if ((sRev.Find(find) >= 0))
2955 return TRUE;
2959 if (m_SelectedFilters & LOGFILTER_PATHS)
2961 CTGitPathList *pathList=NULL;
2962 if( pRev->m_IsDiffFiles)
2963 pathList = &pRev->GetFiles(this);
2964 else
2966 if(!pRev->m_IsSimpleListReady)
2967 pRev->SafeGetSimpleList(&g_Git);
2969 if(pathList)
2970 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList->GetCount() ; ++cpPathIndex)
2972 CTGitPath *cpath = &pathList->m_paths.at(cpPathIndex);
2973 CString path = cpath->GetGitOldPathString();
2974 path.MakeLower();
2975 if ((path.Find(find)>=0))
2977 return true;
2979 path = cpath->GetGitPathString();
2980 path.MakeLower();
2981 if ((path.Find(find)>=0))
2983 return true;
2987 for (size_t i = 0; i < pRev->m_SimpleFileList.size(); i++)
2989 CString path = pRev->m_SimpleFileList[i];
2990 path.MakeLower();
2991 if ((path.Find(find)>=0))
2993 return true;
2997 } // else (from if (bRegex))
2998 return FALSE;
3002 void CGitLogListBase::RecalculateShownList(CThreadSafePtrArray * pShownlist)
3005 pShownlist->SafeRemoveAll();
3007 tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);
3008 bool bRegex = false;
3009 if (m_bFilterWithRegex)
3010 bRegex = ValidateRegexp(m_sFilterText, pat, false);
3012 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;
3013 CString sRev;
3014 for (DWORD i=0; i<m_logEntries.size(); ++i)
3016 if ((bRegex)&&(m_bFilterWithRegex))
3018 #if 0
3019 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3021 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);
3022 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))
3024 pShownlist->SafeAdd(m_logEntries[i]);
3025 continue;
3028 #endif
3029 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3031 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetSubject());
3032 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetSubject()), pat, flags)&&IsEntryInDateRange(i))
3034 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3035 continue;
3038 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3040 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).GetBody());
3041 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetBody()), pat, flags)&&IsEntryInDateRange(i))
3043 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3044 continue;
3047 if (m_SelectedFilters & LOGFILTER_PATHS)
3049 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3051 bool bGoing = true;
3052 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3054 CTGitPath cpath = pathList[cpPathIndex];
3055 if (regex_search(wstring((LPCTSTR)cpath.GetGitOldPathString()), pat, flags)&&IsEntryInDateRange(i))
3057 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3058 bGoing = false;
3059 continue;
3061 if (regex_search(wstring((LPCTSTR)cpath.GetGitPathString()), pat, flags)&&IsEntryInDateRange(i))
3063 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3064 bGoing = false;
3065 continue;
3067 if (regex_search(wstring((LPCTSTR)cpath.GetActionName()), pat, flags)&&IsEntryInDateRange(i))
3069 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3070 bGoing = false;
3071 continue;
3075 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3077 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).GetAuthorName()), pat, flags)&&IsEntryInDateRange(i))
3079 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3080 continue;
3083 if (m_SelectedFilters & LOGFILTER_REVS)
3085 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3086 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))
3088 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3089 continue;
3092 } // if (bRegex)
3093 else
3095 CString find = m_sFilterText;
3096 find.MakeLower();
3097 #if 0
3098 if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))
3100 CString sBugIDs = m_logEntries[i]->sBugIDs;
3102 sBugIDs = sBugIDs.MakeLower();
3103 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3105 pShownlist->SafeAdd(m_logEntries[i]);
3106 continue;
3109 #endif
3110 if ((m_SelectedFilters & LOGFILTER_SUBJECT) || (m_SelectedFilters & LOGFILTER_MESSAGES))
3112 CString msg = m_logEntries.GetGitRevAt(i).GetSubject();
3114 msg = msg.MakeLower();
3115 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3117 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3118 continue;
3121 if (m_SelectedFilters & LOGFILTER_MESSAGES)
3123 CString msg = m_logEntries.GetGitRevAt(i).GetBody();
3125 msg = msg.MakeLower();
3126 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3128 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3129 continue;
3132 if (m_SelectedFilters & LOGFILTER_PATHS)
3134 CTGitPathList pathList = m_logEntries.GetGitRevAt(i).GetFiles(this);
3136 bool bGoing = true;
3137 for (INT_PTR cpPathIndex = 0; cpPathIndex < pathList.GetCount() && bGoing; ++cpPathIndex)
3139 CTGitPath cpath = pathList[cpPathIndex];
3140 CString path = cpath.GetGitOldPathString();
3141 path.MakeLower();
3142 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3144 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3145 bGoing = false;
3146 continue;
3148 path = cpath.GetGitPathString();
3149 path.MakeLower();
3150 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3152 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3153 bGoing = false;
3154 continue;
3156 path = cpath.GetActionName();
3157 path.MakeLower();
3158 if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))
3160 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3161 bGoing = false;
3162 continue;
3166 if (m_SelectedFilters & LOGFILTER_AUTHORS)
3168 CString msg = m_logEntries.GetGitRevAt(i).GetAuthorName();
3169 msg = msg.MakeLower();
3170 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3172 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3173 continue;
3176 if (m_SelectedFilters & LOGFILTER_REVS)
3178 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash.ToString());
3179 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))
3181 pShownlist->SafeAdd(&m_logEntries.GetGitRevAt(i));
3182 continue;
3185 } // else (from if (bRegex))
3186 } // for (DWORD i=0; i<m_logEntries.size(); ++i)
3190 BOOL CGitLogListBase::IsEntryInDateRange(int /*i*/)
3193 __time64_t time = m_logEntries.GetGitRevAt(i).GetAuthorDate().GetTime();
3195 if(m_From == -1)
3196 if(m_To == -1)
3197 return true;
3198 else
3199 return time <= m_To;
3200 else
3201 if(m_To == -1)
3202 return time >= m_From;
3203 else
3204 return ((time >= m_From)&&(time <= m_To));
3206 return TRUE; /* git dll will filter time range */
3208 // return TRUE;
3210 void CGitLogListBase::StartFilter()
3212 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3213 RecalculateShownList(&m_arShownList);
3214 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3217 DeleteAllItems();
3218 SetItemCountEx(ShownCountWithStopped());
3219 RedrawItems(0, ShownCountWithStopped());
3220 Invalidate();
3223 void CGitLogListBase::RemoveFilter()
3226 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3228 m_arShownList.SafeRemoveAll();
3230 // reset the time filter too
3231 #if 0
3232 m_timFrom = (__time64_t(m_tFrom));
3233 m_timTo = (__time64_t(m_tTo));
3234 m_DateFrom.SetTime(&m_timFrom);
3235 m_DateTo.SetTime(&m_timTo);
3236 m_DateFrom.SetRange(&m_timFrom, &m_timTo);
3237 m_DateTo.SetRange(&m_timFrom, &m_timTo);
3238 #endif
3240 for (DWORD i=0; i<m_logEntries.size(); ++i)
3242 if(this->m_IsOldFirst)
3244 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(m_logEntries.size()-i-1));
3246 else
3248 m_arShownList.SafeAdd(&m_logEntries.GetGitRevAt(i));
3251 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
3252 DeleteAllItems();
3253 SetItemCountEx(ShownCountWithStopped());
3254 RedrawItems(0, ShownCountWithStopped());
3256 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3259 void CGitLogListBase::Clear()
3261 m_arShownList.SafeRemoveAll();
3262 DeleteAllItems();
3264 m_logEntries.ClearAll();
3268 void CGitLogListBase::OnDestroy()
3270 // save the column widths to the registry
3271 SaveColumnWidths();
3273 SafeTerminateThread();
3274 SafeTerminateAsyncDiffThread();
3276 int retry = 0;
3277 while(m_LogCache.SaveCache())
3279 if(retry > 5)
3280 break;
3281 Sleep(1000);
3283 retry++;
3285 //if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),
3286 // MB_YESNO) == IDNO)
3287 // break;
3290 CHintListCtrl::OnDestroy();
3293 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)
3295 UNREFERENCED_PARAMETER(lParam);
3296 CRect rect;
3297 int i=(int)wParam;
3298 this->GetItemRect(i,&rect,LVIR_BOUNDS);
3299 this->InvalidateRect(rect);
3301 return 0;
3305 * Save column widths to the registry
3307 void CGitLogListBase::SaveColumnWidths()
3309 int maxcol = m_ColumnManager.GetColumnCount();
3311 // HACK that graph column is always shown
3312 SetColumnWidth(0, m_ColumnManager.GetWidth(0, false));
3314 for (int col = 0; col < maxcol; col++)
3315 if (m_ColumnManager.IsVisible (col))
3316 m_ColumnManager.ColumnResized (col);
3318 m_ColumnManager.WriteSettings();
3321 int CGitLogListBase::GetHeadIndex()
3323 if(m_HeadHash.IsEmpty())
3324 return -1;
3326 for(int i=0;i<m_arShownList.GetCount();i++)
3328 GitRev *pRev = (GitRev*)m_arShownList[i];
3329 if(pRev)
3331 if(pRev->m_CommitHash.ToString() == m_HeadHash )
3332 return i;
3335 return -1;
3337 void CGitLogListBase::OnFind()
3339 if (!m_pFindDialog)
3341 m_pFindDialog = new CFindDlg(this);
3342 m_pFindDialog->Create(this);
3345 void CGitLogListBase::OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult)
3347 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
3349 void CGitLogListBase::OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult)
3351 if(!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
3352 Default();
3354 LRESULT CGitLogListBase::OnScrollToMessage(WPARAM itemToSelect, LPARAM /*lParam*/)
3356 SetItemState((int)itemToSelect, LVIS_SELECTED, LVIS_SELECTED);
3357 EnsureVisible((int)itemToSelect, FALSE);
3358 return 0;
3360 LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/)
3363 ASSERT(m_pFindDialog != NULL);
3364 bool bFound = false;
3365 int i=0;
3367 if (m_pFindDialog->IsTerminating())
3369 // invalidate the handle identifying the dialog box.
3370 m_pFindDialog = NULL;
3371 return 0;
3374 if(m_pFindDialog->IsRef())
3376 CString str;
3377 str=m_pFindDialog->GetFindString();
3379 CGitHash hash;
3381 if(!str.IsEmpty())
3382 hash = g_Git.GetHash(str + _T("^{}")); // add ^{} in order to get the correct SHA-1 (especially for signed tags)
3384 if(!hash.IsEmpty())
3386 for (i = 0; i<m_arShownList.GetCount(); i++)
3388 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3389 if(pLogEntry && pLogEntry->m_CommitHash == hash)
3391 bFound = true;
3392 break;
3399 if(m_pFindDialog->FindNext())
3401 //read data from dialog
3402 CString FindText = m_pFindDialog->GetFindString();
3403 bool bMatchCase = (m_pFindDialog->MatchCase() == TRUE);
3405 tr1::wregex pat;
3406 bool bRegex = ValidateRegexp(FindText, pat, bMatchCase);
3408 tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_not_null;
3411 for (i = this->m_nSearchIndex; i<m_arShownList.GetCount()&&!bFound; i++)
3413 GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i);
3415 CString str;
3416 str+=pLogEntry->m_CommitHash.ToString();
3417 str+=_T("\n");
3419 for(int j=0;j<this->m_HashMap[pLogEntry->m_CommitHash].size();j++)
3421 str+=m_HashMap[pLogEntry->m_CommitHash][j];
3422 str+=_T("\n");
3425 str+=pLogEntry->GetAuthorEmail();
3426 str+=_T("\n");
3427 str+=pLogEntry->GetAuthorName();
3428 str+=_T("\n");
3429 str+=pLogEntry->GetBody();
3430 str+=_T("\n");
3431 str+=pLogEntry->GetCommitterEmail();
3432 str+=_T("\n");
3433 str+=pLogEntry->GetCommitterName();
3434 str+=_T("\n");
3435 str+=pLogEntry->GetSubject();
3436 str+=_T("\n");
3439 /*Because changed files list is loaded on demand when gui show,
3440 files will empty when files have not fetched.
3442 we can add it back by using one-way diff(with outnumber changed and rename detect.
3443 here just need changed filename list. one-way is much quicker.
3445 if(pLogEntry->m_IsFull)
3447 for(int i=0;i<pLogEntry->GetFiles(this).GetCount();i++)
3449 str+=pLogEntry->GetFiles(this)[i].GetWinPath();
3450 str+=_T("\n");
3451 str+=pLogEntry->GetFiles(this)[i].GetGitOldPathString();
3452 str+=_T("\n");
3455 else
3457 if(!pLogEntry->m_IsSimpleListReady)
3458 pLogEntry->SafeGetSimpleList(&g_Git);
3460 for(int i=0;i<pLogEntry->m_SimpleFileList.size();i++)
3462 str+=pLogEntry->m_SimpleFileList[i];
3463 str+=_T("\n");
3469 if (bRegex)
3471 if (regex_search(wstring(str), pat, flags))
3473 bFound = true;
3474 break;
3477 else
3479 if (bMatchCase)
3481 if (str.Find(FindText) >= 0)
3483 bFound = true;
3484 break;
3488 else
3490 CString msg = str;
3491 msg = msg.MakeLower();
3492 CString find = FindText.MakeLower();
3493 if (msg.Find(find) >= 0)
3495 bFound = TRUE;
3496 break;
3500 } // for (i = this->m_nSearchIndex; i<m_arShownList.GetItemCount()&&!bFound; i++)
3502 } // if(m_pFindDialog->FindNext())
3503 //UpdateLogInfoLabel();
3505 if (bFound)
3507 this->m_nSearchIndex = i;
3508 EnsureVisible(i, FALSE);
3509 SetItemState(GetSelectionMark(), 0, LVIS_SELECTED);
3510 SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
3511 SetSelectionMark(i);
3512 //FillLogMessageCtrl();
3513 UpdateData(FALSE);
3514 m_nSearchIndex++;
3515 if (m_nSearchIndex >= m_arShownList.GetCount())
3516 m_nSearchIndex = (int)m_arShownList.GetCount()-1;
3519 return 0;
3522 void CGitLogListBase::OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult)
3524 m_ColumnManager.OnColumnResized(pNMHDR,pResult);
3526 *pResult = FALSE;
3529 void CGitLogListBase::OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult)
3531 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
3533 Invalidate(FALSE);