OSDN Git Service

Git log basic work but graph tree is wrong when scroll
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / GitLogListBase.cpp
1 // GitLogList.cpp : implementation file\r
2 //\r
3 /*\r
4         Description: qgit revision list view\r
5 \r
6         Author: Marco Costalba (C) 2005-2007\r
7 \r
8         Copyright: See COPYING file that comes with this distribution\r
9 \r
10 */\r
11 #include "stdafx.h"\r
12 #include "GitLogListBase.h"\r
13 #include "GitRev.h"\r
14 //#include "VssStyle.h"\r
15 #include "IconMenu.h"\r
16 // CGitLogListBase\r
17 #include "cursor.h"\r
18 #include "InputDlg.h"\r
19 #include "PropDlg.h"\r
20 #include "SVNProgressDlg.h"\r
21 #include "ProgressDlg.h"\r
22 //#include "RepositoryBrowser.h"\r
23 //#include "CopyDlg.h"\r
24 //#include "StatGraphDlg.h"\r
25 #include "Logdlg.h"\r
26 #include "MessageBox.h"\r
27 #include "Registry.h"\r
28 #include "AppUtils.h"\r
29 #include "PathUtils.h"\r
30 #include "StringUtils.h"\r
31 #include "UnicodeUtils.h"\r
32 #include "TempFile.h"\r
33 //#include "GitInfo.h"\r
34 //#include "GitDiff.h"\r
35 #include "IconMenu.h"\r
36 //#include "RevisionRangeDlg.h"\r
37 //#include "BrowseFolder.h"\r
38 //#include "BlameDlg.h"\r
39 //#include "Blame.h"\r
40 //#include "GitHelpers.h"\r
41 #include "GitStatus.h"\r
42 //#include "LogDlgHelper.h"\r
43 //#include "CachedLogInfo.h"\r
44 //#include "RepositoryInfo.h"\r
45 //#include "EditPropertiesDlg.h"\r
46 #include "FileDiffDlg.h"\r
47 #include "..\\TortoiseShell\\Resource.h"\r
48 \r
49 \r
50 IMPLEMENT_DYNAMIC(CGitLogListBase, CHintListCtrl)\r
51 \r
52 CGitLogListBase::CGitLogListBase():CHintListCtrl()\r
53         ,m_regMaxBugIDColWidth(_T("Software\\TortoiseGit\\MaxBugIDColWidth"), 200)\r
54         ,m_nSearchIndex(0)\r
55         ,m_bNoDispUpdates(FALSE)\r
56         , m_bThreadRunning(FALSE)\r
57         , m_bStrictStopped(false)\r
58         , m_pStoreSelection(NULL)\r
59         , m_nSelectedFilter(LOGFILTER_ALL)\r
60         , m_bVista(false)\r
61         , m_bShowWC(false)\r
62         , m_logEntries(&m_LogCache)\r
63 {\r
64         // use the default GUI font, create a copy of it and\r
65         // change the copy to BOLD (leave the rest of the font\r
66         // the same)\r
67         HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);\r
68         LOGFONT lf = {0};\r
69         GetObject(hFont, sizeof(LOGFONT), &lf);\r
70         lf.lfWeight = FW_BOLD;\r
71         m_boldFont = CreateFontIndirect(&lf);\r
72         \r
73         m_bShowBugtraqColumn=0;\r
74 \r
75         m_IsIDReplaceAction=FALSE;\r
76 \r
77         m_wcRev.m_CommitHash.Empty();\r
78         m_wcRev.m_Subject=_T("Working dir changes");\r
79         m_wcRev.m_ParentHash.clear();\r
80         m_wcRev.m_Mark=_T('-');\r
81         m_wcRev.m_IsUpdateing=FALSE;\r
82         m_wcRev.m_IsFull = TRUE;\r
83 \r
84         m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
85         m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
86         m_hAddedIcon    =  (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
87         m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);\r
88 \r
89         m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);\r
90 \r
91         g_Git.GetMapHashToFriendName(m_HashMap);\r
92         m_CurrentBranch=g_Git.GetCurrentBranch();\r
93         this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40);\r
94 \r
95         m_From=CTime(1970,1,2,0,0,0);\r
96         m_To=CTime::GetCurrentTime();\r
97     m_ShowMask = 0;\r
98         m_LoadingThread = NULL;\r
99 \r
100         m_bExitThread=FALSE;\r
101         m_IsOldFirst = FALSE;\r
102         m_IsRebaseReplaceGraph = FALSE;\r
103 \r
104 \r
105         for(int i=0;i<Lanes::COLORS_NUM;i++)\r
106         {\r
107                 m_LineColors[i] = m_Colors.GetColor((CColors::Colors)(CColors::BranchLine1+i));\r
108         }\r
109         // get short/long datetime setting from registry\r
110         DWORD RegUseShortDateFormat = CRegDWORD(_T("Software\\TortoiseGit\\LogDateFormat"), TRUE);\r
111         if ( RegUseShortDateFormat )\r
112         {\r
113                 m_DateFormat = DATE_SHORTDATE;\r
114         }\r
115         else\r
116         {\r
117                 m_DateFormat = DATE_LONGDATE;\r
118         }\r
119         // get relative time display setting from registry\r
120         DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);\r
121         m_bRelativeTimes = (regRelativeTimes != 0);\r
122         m_ContextMenuMask = 0xFFFFFFFFFFFFFFFF;\r
123 \r
124         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_PICK);\r
125         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SQUASH);\r
126         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_EDIT);\r
127         m_ContextMenuMask &= ~GetContextMenuBit(ID_REBASE_SKIP);\r
128 \r
129         OSVERSIONINFOEX inf;\r
130         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
131         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
132         GetVersionEx((OSVERSIONINFO *)&inf);\r
133         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
134         m_bVista = (fullver >= 0x0600);\r
135 \r
136         m_ColumnRegKey=_T("log");\r
137 }\r
138 \r
139 CGitLogListBase::~CGitLogListBase()\r
140 {\r
141         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
142 \r
143         DestroyIcon(m_hModifiedIcon);\r
144         DestroyIcon(m_hReplacedIcon);\r
145         DestroyIcon(m_hAddedIcon);\r
146         DestroyIcon(m_hDeletedIcon);\r
147         m_logEntries.ClearAll();\r
148 \r
149         if (m_boldFont)\r
150                 DeleteObject(m_boldFont);\r
151 \r
152         if ( m_pStoreSelection )\r
153         {\r
154                 delete m_pStoreSelection;\r
155                 m_pStoreSelection = NULL;\r
156         }\r
157 \r
158         if(this->m_bThreadRunning)\r
159         {\r
160                 m_bExitThread=true;\r
161                 WaitForSingleObject(m_LoadingThread->m_hThread,1000);\r
162                 TerminateThread();\r
163         }\r
164 }\r
165 \r
166 \r
167 BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl)\r
168         ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdrawLoglist)\r
169         ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfoLoglist)\r
170         ON_WM_CONTEXTMENU()\r
171         ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclkLoglist)\r
172         ON_NOTIFY_REFLECT(LVN_ODFINDITEM,OnLvnOdfinditemLoglist)\r
173         ON_WM_CREATE()\r
174         ON_WM_DESTROY()\r
175         ON_MESSAGE(MSG_LOADED,OnLoad)\r
176         ON_WM_MEASUREITEM()\r
177         ON_WM_MEASUREITEM_REFLECT()\r
178 END_MESSAGE_MAP()\r
179 \r
180 void CGitLogListBase::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)\r
181 {\r
182         // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ\r
183 \r
184         CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);\r
185 }\r
186 \r
187 void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)\r
188 {\r
189         //if (m_nRowHeight>0)\r
190         {\r
191                 lpMeasureItemStruct->itemHeight = 50;\r
192         }\r
193 }\r
194 \r
195 int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct)\r
196 {\r
197         PreSubclassWindow();\r
198         return CHintListCtrl::OnCreate(lpCreateStruct);\r
199 }\r
200 \r
201 void CGitLogListBase::PreSubclassWindow()\r
202 {\r
203         SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);\r
204         // load the icons for the action columns\r
205 //      m_Theme.Open(m_hWnd, L"ListView");\r
206         m_Theme.Open(m_hWnd, L"Explorer::ListView;ListView");\r
207         m_Theme.SetWindowTheme(m_hWnd, L"Explorer", NULL);\r
208         CHintListCtrl::PreSubclassWindow();\r
209 }\r
210 \r
211 void CGitLogListBase::InsertGitColumn()\r
212 {\r
213         CString temp;\r
214 \r
215         int c = GetHeaderCtrl()->GetItemCount()-1;\r
216         \r
217         while (c>=0)\r
218                 DeleteColumn(c--);\r
219         temp.LoadString(IDS_LOG_GRAPH);\r
220 \r
221         if(m_IsRebaseReplaceGraph)\r
222         {\r
223                 temp=_T("Rebase");\r
224         }\r
225         else\r
226         {\r
227                 temp.LoadString(IDS_LOG_GRAPH);\r
228         }\r
229         InsertColumn(this->LOGLIST_GRAPH, temp);\r
230         \r
231 #if 0   \r
232         // make the revision column right aligned\r
233         LVCOLUMN Column;\r
234         Column.mask = LVCF_FMT;\r
235         Column.fmt = LVCFMT_RIGHT;\r
236         SetColumn(0, &Column); \r
237 #endif  \r
238 //      CString log;\r
239 //      g_Git.GetLog(log);\r
240 \r
241         if(m_IsIDReplaceAction)\r
242         {\r
243                 temp.LoadString(IDS_LOG_ID);\r
244                 InsertColumn(this->LOGLIST_ACTION, temp);\r
245         }\r
246         else\r
247         {\r
248                 temp.LoadString(IDS_LOG_ACTIONS);\r
249                 InsertColumn(this->LOGLIST_ACTION, temp);\r
250         }\r
251         temp.LoadString(IDS_LOG_MESSAGE);\r
252         InsertColumn(this->LOGLIST_MESSAGE, temp);\r
253         \r
254         temp.LoadString(IDS_LOG_AUTHOR);\r
255         InsertColumn(this->LOGLIST_AUTHOR, temp);\r
256         \r
257         temp.LoadString(IDS_LOG_DATE);\r
258         InsertColumn(this->LOGLIST_DATE, temp);\r
259         \r
260 \r
261         if (m_bShowBugtraqColumn)\r
262         {\r
263 //              temp = m_ProjectProperties.sLabel;\r
264                 if (temp.IsEmpty())\r
265                         temp.LoadString(IDS_LOG_BUGIDS);\r
266                 InsertColumn(this->LOGLIST_BUG, temp);\r
267 \r
268         }\r
269         \r
270         SetRedraw(false);\r
271         ResizeAllListCtrlCols();\r
272         SetRedraw(true);\r
273 \r
274 }\r
275 \r
276 /**\r
277  * Resizes all columns in a list control to values in registry.\r
278  */\r
279 void CGitLogListBase::ResizeAllListCtrlCols()\r
280 {\r
281         // column max and min widths to allow\r
282         static const int nMinimumWidth = 10;\r
283         static const int nMaximumWidth = 1000;\r
284         CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
285         if (pHdrCtrl)\r
286         {\r
287                 int numcols = pHdrCtrl->GetItemCount();\r
288                 for (int col = 0; col < numcols; col++)\r
289                 {\r
290                         // get width for this col last time from registry\r
291                         CString regentry;\r
292                         regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);\r
293                         CRegDWORD regwidth(regentry, 0);\r
294                         int cx = regwidth;\r
295                         if ( cx == 0 )\r
296                         {\r
297                                 // no saved value, setup sensible defaults\r
298                                 if (col == this->LOGLIST_MESSAGE)\r
299                                 {\r
300                                         cx = LOGLIST_MESSAGE_MIN;\r
301                                 }\r
302                                 else\r
303                                 {\r
304                                         cx = ICONITEMBORDER+16*4;\r
305                                 }\r
306                         }\r
307                         if (cx < nMinimumWidth)\r
308                         {\r
309                                 cx = nMinimumWidth;\r
310                         } else if (cx > nMaximumWidth)\r
311                         {\r
312                                 cx = nMaximumWidth;\r
313                         }\r
314 \r
315                         SetColumnWidth(col, cx);\r
316                 }\r
317         }\r
318 \r
319 }\r
320 \r
321 \r
322 BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefix)\r
323 {\r
324         TRACE(_T("%s %s\r\n"),ref,prefix);\r
325         if(ref.Left(prefix.GetLength()) ==  prefix)\r
326         {\r
327                 shortname = ref.Right(ref.GetLength()-prefix.GetLength());\r
328                 if(shortname.Right(3)==_T("^{}"))\r
329                         shortname=shortname.Left(shortname.GetLength()-3);\r
330                 return TRUE;\r
331         }\r
332         return FALSE;\r
333 }\r
334 \r
335 void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect)\r
336 {       \r
337 //      HBRUSH brush;\r
338         LVITEM   rItem;\r
339         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
340         rItem.mask  = LVIF_STATE;\r
341         rItem.iItem = Index;\r
342         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
343         GetItem(&rItem);\r
344 \r
345         GitRev* pLogEntry = (GitRev*)m_arShownList.GetAt(Index);\r
346         HBRUSH brush = NULL;\r
347 \r
348         \r
349         if (m_Theme.IsAppThemed() && m_bVista)\r
350         {\r
351                 int state = LISS_NORMAL;\r
352                 if (rItem.state & LVIS_SELECTED)\r
353                 {\r
354                         if (::GetFocus() == m_hWnd)\r
355                                 state |= LISS_SELECTED;\r
356                         else\r
357                                 state |= LISS_SELECTEDNOTFOCUS;\r
358                 }\r
359                 else\r
360                 {\r
361                         if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
362                                 brush = ::CreateSolidBrush(RGB(156,156,156));\r
363                         else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)\r
364                                 brush = ::CreateSolidBrush(RGB(200,200,128));\r
365                 }\r
366 \r
367                 if (brush != NULL)\r
368                 {\r
369                         ::FillRect(hdc, &rect, brush);\r
370                         ::DeleteObject(brush);\r
371                 }\r
372                 else\r
373                 {\r
374                         if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTITEM, state))\r
375                                 m_Theme.DrawParentBackground(m_hWnd, hdc, &rect);\r
376 \r
377                         CRect rectDraw = rect;\r
378                         if(rItem.state & LVIS_SELECTED)\r
379                                 rectDraw.InflateRect(1,0);\r
380                         else\r
381                                 rectDraw.InflateRect(1,1);\r
382 \r
383                         m_Theme.DrawBackground(hdc, LVP_LISTITEM, state, rectDraw, &rect);\r
384                 }\r
385         }\r
386         else\r
387         {\r
388                 \r
389                 if (rItem.state & LVIS_SELECTED)\r
390                 {\r
391                         if (::GetFocus() == m_hWnd)\r
392                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));\r
393                         else\r
394                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE));\r
395                 }\r
396                 else\r
397                 {\r
398                         //if (pLogEntry->bCopiedSelf)\r
399                         //      brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU));\r
400                         //else\r
401                         if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
402                                 brush = ::CreateSolidBrush(RGB(156,156,156));\r
403                         else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)\r
404                                 brush = ::CreateSolidBrush(RGB(200,200,128));\r
405                         else\r
406                                 brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));\r
407                 }\r
408                 if (brush == NULL)\r
409                         return;\r
410 \r
411                 ::FillRect(hdc, &rect, brush);\r
412                 ::DeleteObject(brush);\r
413                 \r
414         }\r
415 }\r
416 \r
417 void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index)\r
418 {\r
419         GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
420         CRect rt=rect;\r
421         LVITEM   rItem;\r
422         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
423         rItem.mask  = LVIF_STATE;\r
424         rItem.iItem = index;\r
425         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
426         GetItem(&rItem);\r
427 \r
428         for(unsigned int i=0;i<m_HashMap[data->m_CommitHash].size();i++)\r
429         {\r
430                 CString str;\r
431                 str=m_HashMap[data->m_CommitHash][i];\r
432                 \r
433                 CString shortname;\r
434                 HBRUSH brush = 0;\r
435                 shortname = _T("");\r
436                 COLORREF colRef = 0;\r
437 \r
438                 //Determine label color\r
439                 if(GetShortName(str,shortname,_T("refs/heads/")))\r
440                 {\r
441                         if( shortname == m_CurrentBranch )\r
442                                 colRef = m_Colors.GetColor(CColors::CurrentBranch);\r
443                         else\r
444                                 colRef = m_Colors.GetColor(CColors::LocalBranch);\r
445 \r
446                 }else if(GetShortName(str,shortname,_T("refs/remotes/")))\r
447                 {\r
448                         colRef = m_Colors.GetColor(CColors::RemoteBranch);\r
449                 }\r
450                 else if(GetShortName(str,shortname,_T("refs/tags/")))\r
451                 {\r
452                         colRef = m_Colors.GetColor(CColors::Tag);\r
453                 }\r
454                 else if(GetShortName(str,shortname,_T("refs/stash")))\r
455                 {\r
456                         colRef = m_Colors.GetColor(CColors::Stash);\r
457                         shortname=_T("stash");\r
458                 }\r
459 \r
460                 //When row selected, ajust label color\r
461                 if (!(m_Theme.IsAppThemed() && m_bVista))\r
462                         if (rItem.state & LVIS_SELECTED)\r
463                                 colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150);\r
464 \r
465                 brush = ::CreateSolidBrush(colRef);\r
466                 \r
467 \r
468                 if(!shortname.IsEmpty())\r
469                 {\r
470                         SIZE size;\r
471                         memset(&size,0,sizeof(SIZE));\r
472                         GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size);\r
473                 \r
474                         rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom);\r
475                         rt.right+=8;\r
476 \r
477                         //Fill interior of ref label\r
478                         ::FillRect(hdc, &rt, brush);\r
479 \r
480                         //Draw edge of label\r
481                         CDC W_Dc;\r
482                         W_Dc.Attach(hdc);\r
483 \r
484                         CRect rectEdge = rt;\r
485 \r
486                         W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100));\r
487                         rectEdge.DeflateRect(1,1);\r
488                         W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50));\r
489 \r
490                         W_Dc.Detach();\r
491 \r
492                         //Draw text inside label\r
493                         if (m_Theme.IsAppThemed() && m_bVista)\r
494                         {\r
495                                 int txtState = LISS_NORMAL;\r
496                                 if (rItem.state & LVIS_SELECTED)\r
497                                         txtState = LISS_SELECTED;\r
498 \r
499                                 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, shortname, -1, DT_CENTER | DT_SINGLELINE | DT_VCENTER, 0, &rt);\r
500                         }\r
501                         else\r
502                         {\r
503                                 if (rItem.state & LVIS_SELECTED)\r
504                                 {\r
505                                         COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT);\r
506                                         COLORREF   clrOld   = ::SetTextColor(hdc,clrNew);   \r
507                                         ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);\r
508                                         ::SetTextColor(hdc,clrOld);\r
509                                 }else\r
510                                 {\r
511                                         ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER);\r
512                                 }\r
513                         }\r
514 \r
515                         \r
516                         //::MoveToEx(hdc,rt.left,rt.top,NULL);\r
517                         //::LineTo(hdc,rt.right,rt.top);\r
518                         //::LineTo(hdc,rt.right,rt.bottom);\r
519                         //::LineTo(hdc,rt.left,rt.bottom);\r
520                         //::LineTo(hdc,rt.left,rt.top);\r
521 \r
522                                 \r
523                         rt.left=rt.right+1;\r
524                 }\r
525                 if(brush)\r
526                         ::DeleteObject(brush);\r
527         }               \r
528         rt.right=rect.right;\r
529 \r
530         if (m_Theme.IsAppThemed() && m_bVista)\r
531         {\r
532                 int txtState = LISS_NORMAL;\r
533                 if (rItem.state & LVIS_SELECTED)\r
534                         txtState = LISS_SELECTED;\r
535 \r
536                 m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, data->m_Subject, -1, DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt);\r
537         }\r
538         else\r
539         {\r
540                 if (rItem.state & LVIS_SELECTED)\r
541                 {\r
542                         COLORREF   clrOld   = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT));   \r
543                         ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);\r
544                         ::SetTextColor(hdc,clrOld);   \r
545                 }else\r
546                 {\r
547                         ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER);\r
548                 }\r
549         }\r
550 }\r
551 \r
552 static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) {\r
553 \r
554         // Returns ((256 - amount)*col1 + amount*col2) / 256;\r
555         return RGB(((256 - amount)*GetRValue(col1)   + amount*GetRValue(col2)  ) / 256,\r
556                       ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256,\r
557                       ((256 - amount)*GetBValue(col1)  + amount*GetBValue(col2) ) / 256);\r
558 }\r
559 \r
560 Gdiplus::Color GetGdiColor(COLORREF col)\r
561 {\r
562         return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col));\r
563 }\r
564 void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2,\r
565                                       const COLORREF& col,const COLORREF& activeColor, int top\r
566                                                                           )  \r
567 {\r
568         int h = laneHeight / 2;\r
569         int m = (x1 + x2) / 2;\r
570         int r = (x2 - x1) / 3;\r
571         int d =  2 * r;\r
572 \r
573         #define P_CENTER m , h+top\r
574         #define P_0      x2, h+top\r
575         #define P_90     m , 0+top\r
576         #define P_180    x1, h+top\r
577         #define P_270    m , 2 * h+top\r
578         #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d\r
579 \r
580 \r
581         #define DELTA_UR_B 2*(x1 - m), 2*h +top \r
582         #define DELTA_UR_E 0*16, 90*16 +top  // -,\r
583 \r
584         #define DELTA_DR_B 2*(x1 - m), 2*-h +top\r
585         #define DELTA_DR_E 270*16, 90*16 +top  // -'\r
586 \r
587         #define DELTA_UL_B 2*(x2 - m), 2*h +top\r
588         #define DELTA_UL_E 90*16, 90*16 +top //  ,-\r
589 \r
590         #define DELTA_DL_B 2*(x2 - m),2*-h +top \r
591         #define DELTA_DL_E 180*16, 90*16  //  '-\r
592 \r
593         #define CENTER_UR x1, 2*h, 225\r
594         #define CENTER_DR x1, 0  , 135\r
595         #define CENTER_UL x2, 2*h, 315\r
596         #define CENTER_DL x2, 0  ,  45\r
597 \r
598 \r
599         Gdiplus::Graphics graphics( hdc );\r
600 \r
601         // arc\r
602         switch (type) {\r
603         case Lanes::JOIN:\r
604         case Lanes::JOIN_R:\r
605         case Lanes::HEAD:\r
606         case Lanes::HEAD_R: \r
607         {\r
608                 Gdiplus::LinearGradientBrush gradient(\r
609                                                                 Gdiplus::Point(x1-2, h+top-2),\r
610                                                                 Gdiplus::Point(P_270),\r
611                                                                 GetGdiColor(activeColor),GetGdiColor(col));\r
612 \r
613                 \r
614                 Gdiplus::Pen mypen(&gradient,2);\r
615                 //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);\r
616                 \r
617                 //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight);\r
618                 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1+1,laneHeight+1,270,90);\r
619                 //graphics.DrawLine(&mypen,x1-1,h+top,P_270);\r
620 \r
621                 break;\r
622         }\r
623         case Lanes::JOIN_L: \r
624         {\r
625         \r
626                 Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2);\r
627 \r
628                 \r
629                 graphics.DrawArc(&mypen,x1,top+h, x2-x1,laneHeight,270,90);\r
630 \r
631                 break;\r
632         }\r
633         case Lanes::TAIL:\r
634         case Lanes::TAIL_R: \r
635         {\r
636                 \r
637                 Gdiplus::LinearGradientBrush gradient(\r
638                                                                 Gdiplus::Point(x1-2, h+top-2),\r
639                                                                 Gdiplus::Point(P_90),\r
640                                                                 GetGdiColor(activeColor),GetGdiColor(col));\r
641 \r
642                 \r
643                 Gdiplus::Pen mypen(&gradient,2);\r
644 \r
645                 graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1+1,laneHeight+1,0,90);\r
646 \r
647 \r
648 #if 0\r
649                 QConicalGradient gradient(CENTER_DR);\r
650                 gradient.setColorAt(0.375, activeCol);\r
651                 gradient.setColorAt(0.625, col);\r
652                 myPen.setBrush(gradient);\r
653                 p->setPen(myPen);\r
654                 p->drawArc(P_CENTER, DELTA_DR);\r
655 #endif\r
656                 break;\r
657         }\r
658         default:\r
659                 break;\r
660         }\r
661 \r
662 \r
663         //static QPen myPen(Qt::black, 2); // fast path here\r
664         CPen pen;\r
665         pen.CreatePen(PS_SOLID,2,col);\r
666         //myPen.setColor(col);\r
667         HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen);\r
668 \r
669         Gdiplus::Pen myPen(GetGdiColor(col),2);\r
670 \r
671         //p->setPen(myPen);\r
672 \r
673         // vertical line\r
674         switch (type) {\r
675         case Lanes::ACTIVE:\r
676         case Lanes::NOT_ACTIVE:\r
677         case Lanes::MERGE_FORK:\r
678         case Lanes::MERGE_FORK_R:\r
679         case Lanes::MERGE_FORK_L:\r
680         case Lanes::JOIN:\r
681         case Lanes::JOIN_R:\r
682         case Lanes::JOIN_L:\r
683         case Lanes::CROSS:\r
684                 //DrawLine(hdc,P_90,P_270);\r
685                 graphics.DrawLine(&myPen,P_90,P_270);\r
686                 //p->drawLine(P_90, P_270);\r
687                 break;\r
688         case Lanes::HEAD_L:\r
689         case Lanes::BRANCH:\r
690                 //DrawLine(hdc,P_CENTER,P_270);\r
691                 graphics.DrawLine(&myPen,P_CENTER,P_270);\r
692                 //p->drawLine(P_CENTER, P_270);\r
693                 break;\r
694         case Lanes::TAIL_L:\r
695         case Lanes::INITIAL:\r
696         case Lanes::BOUNDARY:\r
697         case Lanes::BOUNDARY_C:\r
698         case Lanes::BOUNDARY_R:\r
699         case Lanes::BOUNDARY_L:\r
700                 //DrawLine(hdc,P_90, P_CENTER);\r
701                 graphics.DrawLine(&myPen,P_90,P_CENTER);\r
702                 //p->drawLine(P_90, P_CENTER);\r
703                 break;\r
704         default:\r
705                 break;\r
706         }\r
707 \r
708         myPen.SetColor(GetGdiColor(activeColor));\r
709 \r
710         // horizontal line\r
711         switch (type) {\r
712         case Lanes::MERGE_FORK:\r
713         case Lanes::JOIN:\r
714         case Lanes::HEAD:\r
715         case Lanes::TAIL:\r
716         case Lanes::CROSS:\r
717         case Lanes::CROSS_EMPTY:\r
718         case Lanes::BOUNDARY_C:\r
719                 //DrawLine(hdc,P_180,P_0);\r
720                 graphics.DrawLine(&myPen,P_180,P_0);\r
721                 //p->drawLine(P_180, P_0);\r
722                 break;\r
723         case Lanes::MERGE_FORK_R:\r
724         case Lanes::BOUNDARY_R:\r
725                 //DrawLine(hdc,P_180,P_CENTER);\r
726                 graphics.DrawLine(&myPen,P_180,P_CENTER);\r
727                 //p->drawLine(P_180, P_CENTER);\r
728                 break;\r
729         case Lanes::MERGE_FORK_L:\r
730         case Lanes::HEAD_L:\r
731         case Lanes::TAIL_L:\r
732         case Lanes::BOUNDARY_L:\r
733                 //DrawLine(hdc,P_CENTER,P_0);\r
734                 graphics.DrawLine(&myPen,P_CENTER,P_0);\r
735                 //p->drawLine(P_CENTER, P_0);\r
736                 break;\r
737         default:\r
738                 break;\r
739         }\r
740 \r
741         CBrush brush;\r
742         brush.CreateSolidBrush(col);\r
743         HBRUSH oldbrush=(HBRUSH)::SelectObject(hdc,(HBRUSH)brush);\r
744         // center symbol, e.g. rect or ellipse\r
745         switch (type) {\r
746         case Lanes::ACTIVE:\r
747         case Lanes::INITIAL:\r
748         case Lanes::BRANCH:\r
749 \r
750                 //p->setPen(Qt::NoPen);\r
751                 //p->setBrush(col);\r
752                 ::Ellipse(hdc, R_CENTER);\r
753                 //p->drawEllipse(R_CENTER);\r
754                 break;\r
755         case Lanes::MERGE_FORK:\r
756         case Lanes::MERGE_FORK_R:\r
757         case Lanes::MERGE_FORK_L:\r
758                 //p->setPen(Qt::NoPen);\r
759                 //p->setBrush(col);\r
760                 //p->drawRect(R_CENTER);\r
761                 Rectangle(hdc,R_CENTER);\r
762                 break;\r
763         case Lanes::UNAPPLIED:\r
764                 // Red minus sign\r
765                 //p->setPen(Qt::NoPen);\r
766                 //p->setBrush(Qt::red);\r
767                 //p->drawRect(m - r, h - 1, d, 2);\r
768                 ::Rectangle(hdc,m-r,h-1,d,2);\r
769                 break;\r
770         case Lanes::APPLIED:\r
771                 // Green plus sign\r
772                 //p->setPen(Qt::NoPen);\r
773                 //p->setBrush(DARK_GREEN);\r
774                 //p->drawRect(m - r, h - 1, d, 2);\r
775                 //p->drawRect(m - 1, h - r, 2, d);\r
776                 ::Rectangle(hdc,m-r,h-1,d,2);\r
777                 ::Rectangle(hdc,m-1,h-r,2,d);\r
778                 break;\r
779         case Lanes::BOUNDARY:\r
780                 //p->setBrush(back);\r
781                 //p->drawEllipse(R_CENTER);\r
782                 ::Ellipse(hdc, R_CENTER);\r
783                 break;\r
784         case Lanes::BOUNDARY_C:\r
785         case Lanes::BOUNDARY_R:\r
786         case Lanes::BOUNDARY_L:\r
787                 //p->setBrush(back);\r
788                 //p->drawRect(R_CENTER);\r
789                 ::Rectangle(hdc,R_CENTER);\r
790                 break;\r
791         default:\r
792                 break;\r
793         }\r
794 \r
795         ::SelectObject(hdc,oldpen);\r
796         ::SelectObject(hdc,oldbrush);\r
797         #undef P_CENTER\r
798         #undef P_0\r
799         #undef P_90\r
800         #undef P_180\r
801         #undef P_270\r
802         #undef R_CENTER\r
803 }\r
804 \r
805 void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)\r
806 {\r
807         //todo unfinished\r
808 //      return;\r
809         GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
810         if(data->m_CommitHash.IsEmpty())\r
811                 return;\r
812 \r
813         CRect rt=rect;\r
814         LVITEM   rItem;\r
815         SecureZeroMemory(&rItem, sizeof(LVITEM));\r
816         rItem.mask  = LVIF_STATE;\r
817         rItem.iItem = index;\r
818         rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;\r
819         GetItem(&rItem);\r
820 \r
821         \r
822 //      p->translate(QPoint(opt.rect.left(), opt.rect.top()));\r
823 \r
824 \r
825 \r
826         if (data->m_Lanes.size() == 0)\r
827                 m_logEntries.setLane(data->m_CommitHash);\r
828 \r
829         std::vector<int>& lanes=data->m_Lanes;\r
830         UINT laneNum = lanes.size();\r
831         UINT activeLane = 0;\r
832         for (UINT i = 0; i < laneNum; i++)\r
833                 if (Lanes::isMerge(lanes[i])) {\r
834                         activeLane = i;\r
835                         break;\r
836                 }\r
837 \r
838         int x1 = 0, x2 = 0;\r
839         int maxWidth = rect.Width();\r
840         int lw = 3 * rect.Height() / 4; //laneWidth() \r
841 \r
842         COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM];\r
843         //if (opt.state & QStyle::State_Selected)\r
844         //      activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208);\r
845         \r
846 \r
847         for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++) \r
848         {\r
849 \r
850                 x1 = x2;\r
851                 x2 += lw;\r
852 \r
853                 int ln = lanes[i];\r
854                 if (ln == Lanes::EMPTY)\r
855                         continue;\r
856 \r
857                 COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM];\r
858                 paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top);\r
859         }\r
860 \r
861 #if 0\r
862         for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) {\r
863 \r
864                 x1 = x2;\r
865                 x2 += lw;\r
866 \r
867                 int ln = lanes[i];\r
868                 if (ln == Lanes::EMPTY)\r
869                         continue;\r
870 \r
871                 UINT col = (  Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln)\r
872                             || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i;\r
873 \r
874                 if (ln == Lanes::CROSS) {\r
875                         paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);\r
876                         paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top);\r
877                 } else\r
878                         paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top);\r
879         }\r
880 #endif\r
881 \r
882 }\r
883 \r
884 void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
885 {\r
886 \r
887         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
888         // Take the default processing unless we set this to something else below.\r
889         *pResult = CDRF_DODEFAULT;\r
890 \r
891         if (m_bNoDispUpdates)\r
892                 return;\r
893 \r
894 \r
895 \r
896         switch (pLVCD->nmcd.dwDrawStage)\r
897         {\r
898         case CDDS_PREPAINT:\r
899                 {\r
900                         *pResult = CDRF_NOTIFYITEMDRAW;\r
901                         return;\r
902                 }\r
903                 break;\r
904         case CDDS_ITEMPREPAINT:\r
905                 {\r
906                         // This is the prepaint stage for an item. Here's where we set the\r
907                         // item's text color. \r
908                         \r
909                         // Tell Windows to send draw notifications for each subitem.\r
910                         *pResult = CDRF_NOTIFYSUBITEMDRAW;\r
911 \r
912                         COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);\r
913 \r
914                         if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
915                         {\r
916                                 GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
917                                 if (data)\r
918                                 {\r
919 #if 0\r
920                                         if (data->bCopiedSelf)\r
921                                         {\r
922                                                 // only change the background color if the item is not 'hot' (on vista with m_Themes enabled)\r
923                                                 if (!m_Theme.IsAppm_Themed() || !m_bVista || ((pLVCD->nmcd.uItemState & CDIS_HOT)==0))\r
924                                                         pLVCD->clrTextBk = GetSysColor(COLOR_MENU);\r
925                                         }\r
926 \r
927                                         if (data->bCopies)\r
928                                                 crText = m_Colors.GetColor(CColors::Modified);\r
929 #endif\r
930                                         if (data->m_Action& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) ) \r
931                                                 crText = RGB(128,128,128);\r
932 \r
933                                         if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH)\r
934                                                 pLVCD->clrTextBk = RGB(156,156,156);\r
935                                         else if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT)\r
936                                                 pLVCD->clrTextBk  = RGB(200,200,128);\r
937                                         else\r
938                                                 pLVCD->clrTextBk  = ::GetSysColor(COLOR_WINDOW);\r
939 \r
940                                         if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_CURRENT)\r
941                                         {\r
942                                                 SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
943                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
944                                         }\r
945 \r
946                                         if(data->m_CommitHash.ToString() == m_HeadHash)\r
947                                         {\r
948                                                 SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
949                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
950                                         }\r
951 \r
952 //                                      if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end()))\r
953 //                                              crText = GetSysColor(COLOR_GRAYTEXT);\r
954 //                                      \r
955                                         if (data->m_CommitHash.IsEmpty())\r
956                                         {\r
957                                                 //crText = GetSysColor(RGB(200,200,0));\r
958                                                 //SelectObject(pLVCD->nmcd.hdc, m_boldFont);\r
959                                                 // We changed the font, so we're returning CDRF_NEWFONT. This\r
960                                                 // tells the control to recalculate the extent of the text.\r
961                                                 *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;\r
962                                         }\r
963                                 }\r
964                         }\r
965                         if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
966                         {\r
967                                 if (m_bStrictStopped)\r
968                                         crText = GetSysColor(COLOR_GRAYTEXT);\r
969                         }\r
970                         // Store the color back in the NMLVCUSTOMDRAW struct.\r
971                         pLVCD->clrText = crText;\r
972                         return;\r
973                 }\r
974                 break;\r
975         case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM:\r
976                 {\r
977                         if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec))\r
978                         {\r
979                                 pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS);\r
980                         }\r
981 \r
982                         if (pLVCD->iSubItem == LOGLIST_GRAPH)\r
983                         {\r
984                                 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) )\r
985                                 {\r
986                                         CRect rect;\r
987                                         GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
988                                         if(pLVCD->iSubItem == 0)\r
989                                         {\r
990                                                 CRect second;\r
991                                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem+1, LVIR_BOUNDS, second);\r
992                                                 rect.right=second.left;\r
993                                         }\r
994                                         \r
995                                         TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right);\r
996                                         FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
997                                         \r
998                                         GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
999                                         if( !data ->m_CommitHash.IsEmpty())\r
1000                                                 DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);\r
1001 \r
1002                                         *pResult = CDRF_SKIPDEFAULT;\r
1003                                         return;\r
1004                                 \r
1005                                 }\r
1006                         }\r
1007 \r
1008                         if (pLVCD->iSubItem == LOGLIST_MESSAGE)\r
1009                         {\r
1010                                 if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
1011                                 {\r
1012                                         GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec);\r
1013                                         //if(!data->m_IsFull)\r
1014                                         //{\r
1015                                                 //if(data->SafeFetchFullInfo(&g_Git))\r
1016                                                 //      this->Invalidate();\r
1017                                                 //TRACE(_T("Update ... %d\r\n"),pLVCD->nmcd.dwItemSpec);\r
1018                                         //}\r
1019 \r
1020                                         if(m_HashMap[data->m_CommitHash].size()!=0)\r
1021                                         {\r
1022                                                 CRect rect;\r
1023 \r
1024                                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
1025                                         \r
1026                                                 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
1027                                                 DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec);\r
1028 \r
1029                                                 *pResult = CDRF_SKIPDEFAULT;\r
1030                                                 return;\r
1031 \r
1032                                         }\r
1033 \r
1034                                 }       \r
1035                         }\r
1036                         \r
1037                         if (pLVCD->iSubItem == 1)\r
1038                         {\r
1039                                 if(this->m_IsIDReplaceAction)\r
1040                                 {\r
1041                                         *pResult = CDRF_DODEFAULT;\r
1042                                         return;\r
1043                                 }\r
1044                                 *pResult = CDRF_DODEFAULT;\r
1045 \r
1046                                 if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec)\r
1047                                         return;\r
1048 \r
1049                                 int             nIcons = 0;\r
1050                                 int             iconwidth = ::GetSystemMetrics(SM_CXSMICON);\r
1051                                 int             iconheight = ::GetSystemMetrics(SM_CYSMICON);\r
1052 \r
1053                                 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec));\r
1054                                 CRect rect;\r
1055                                 GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect);\r
1056                                 TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right);\r
1057                                 // Get the selected state of the\r
1058                                 // item being drawn.                                                    \r
1059 \r
1060                                 // Fill the background\r
1061                                 FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect);\r
1062                                 \r
1063                                 // Draw the icon(s) into the compatible DC\r
1064                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED)\r
1065                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1066                                 nIcons++;\r
1067 \r
1068                                 if (pLogEntry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) )\r
1069                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1070                                 nIcons++;\r
1071 \r
1072                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_DELETED)\r
1073                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hDeletedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1074                                 nIcons++;\r
1075 \r
1076                                 if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_REPLACED)\r
1077                                         ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hReplacedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL);\r
1078                                 nIcons++;\r
1079                                 *pResult = CDRF_SKIPDEFAULT;\r
1080                                 return;\r
1081                         }\r
1082                 }\r
1083                 break;\r
1084         }\r
1085         *pResult = CDRF_DODEFAULT;\r
1086 \r
1087 }\r
1088 \r
1089 // CGitLogListBase message handlers\r
1090 \r
1091 void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
1092 {\r
1093         NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);\r
1094 \r
1095         // Create a pointer to the item\r
1096         LV_ITEM* pItem = &(pDispInfo)->item;\r
1097 \r
1098         // Do the list need text information?\r
1099         if (!(pItem->mask & LVIF_TEXT))\r
1100                 return;\r
1101 \r
1102         // By default, clear text buffer.\r
1103         lstrcpyn(pItem->pszText, _T(""), pItem->cchTextMax);\r
1104 \r
1105         bool bOutOfRange = pItem->iItem >= ShownCountWithStopped();\r
1106         \r
1107         *pResult = 0;\r
1108         if (m_bNoDispUpdates || bOutOfRange)\r
1109                 return;\r
1110 \r
1111         // Which item number?\r
1112         int itemid = pItem->iItem;\r
1113         GitRev * pLogEntry = NULL;\r
1114         if (itemid < m_arShownList.GetCount())\r
1115                 pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(pItem->iItem));\r
1116 \r
1117         CString temp;\r
1118         if(m_IsOldFirst)\r
1119         {\r
1120                 temp.Format(_T("%d"),pItem->iItem+1);\r
1121 \r
1122         }else\r
1123         {\r
1124                 temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem);\r
1125         }\r
1126             \r
1127         // Which column?\r
1128         switch (pItem->iSubItem)\r
1129         {\r
1130         case this->LOGLIST_GRAPH:       //Graphic\r
1131                 if (pLogEntry)\r
1132                 {\r
1133                         if(this->m_IsRebaseReplaceGraph)\r
1134                         {\r
1135                                 CTGitPath path;\r
1136                                 path.m_Action=pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_MODE_MASK;\r
1137 \r
1138                                 lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax);\r
1139                         }\r
1140                 }\r
1141                 break;\r
1142         case this->LOGLIST_ACTION: //action -- no text in the column\r
1143                 if(this->m_IsIDReplaceAction)\r
1144                         lstrcpyn(pItem->pszText, temp, pItem->cchTextMax);\r
1145                 break;\r
1146         case this->LOGLIST_MESSAGE: //Message\r
1147                 if (pLogEntry)\r
1148                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_Subject, pItem->cchTextMax);\r
1149                 break;\r
1150         case this->LOGLIST_AUTHOR: //Author\r
1151                 if (pLogEntry)\r
1152                         lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax);\r
1153                 break;\r
1154         case this->LOGLIST_DATE: //Date\r
1155                 if (!pLogEntry && pLogEntry->m_CommitHash.IsEmpty())\r
1156                         lstrcpyn(pItem->pszText,\r
1157                                 CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ), \r
1158                                 pItem->cchTextMax);\r
1159                 break;\r
1160                 \r
1161         case 5:\r
1162 \r
1163                 break;\r
1164         default:\r
1165                 ASSERT(false);\r
1166         }\r
1167 }\r
1168 \r
1169 void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point)\r
1170 {\r
1171 \r
1172         int selIndex = GetSelectionMark();\r
1173         if (selIndex < 0)\r
1174                 return; // nothing selected, nothing to do with a context menu\r
1175 \r
1176         // if the user selected the info text telling about not all revisions shown due to\r
1177         // the "stop on copy/rename" option, we also don't show the context menu\r
1178         if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount()))\r
1179                 return;\r
1180 \r
1181         // if the context menu is invoked through the keyboard, we have to use\r
1182         // a calculated position on where to anchor the menu on\r
1183         if ((point.x == -1) && (point.y == -1))\r
1184         {\r
1185                 CRect rect;\r
1186                 GetItemRect(selIndex, &rect, LVIR_LABEL);\r
1187                 ClientToScreen(&rect);\r
1188                 point = rect.CenterPoint();\r
1189         }\r
1190         m_nSearchIndex = selIndex;\r
1191         m_bCancelled = FALSE;\r
1192 \r
1193         // calculate some information the context menu commands can use\r
1194 //      CString pathURL = GetURLFromPath(m_path);\r
1195 \r
1196         POSITION pos = GetFirstSelectedItemPosition();\r
1197         int indexNext = GetNextSelectedItem(pos);\r
1198         if (indexNext < 0)\r
1199                 return;\r
1200 \r
1201         GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));\r
1202 #if 0\r
1203         GitRev revSelected = pSelLogEntry->Rev;\r
1204         GitRev revPrevious = git_revnum_t(revSelected)-1;\r
1205         if ((pSelLogEntry->pArChangedPaths)&&(pSelLogEntry->pArChangedPaths->GetCount() <= 2))\r
1206         {\r
1207                 for (int i=0; i<pSelLogEntry->pArChangedPaths->GetCount(); ++i)\r
1208                 {\r
1209                         LogChangedPath * changedpath = (LogChangedPath *)pSelLogEntry->pArChangedPaths->GetAt(i);\r
1210                         if (changedpath->lCopyFromRev)\r
1211                                 revPrevious = changedpath->lCopyFromRev;\r
1212                 }\r
1213         }\r
1214         GitRev revSelected2;\r
1215         if (pos)\r
1216         {\r
1217                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1218                 revSelected2 = pLogEntry->Rev;\r
1219         }\r
1220         bool bAllFromTheSameAuthor = true;\r
1221         CString firstAuthor;\r
1222         CLogDataVector selEntries;\r
1223         GitRev revLowest, revHighest;\r
1224         GitRevRangeArray revisionRanges;\r
1225         {\r
1226                 POSITION pos = GetFirstSelectedItemPosition();\r
1227                 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1228                 revisionRanges.AddRevision(pLogEntry->Rev);\r
1229                 selEntries.push_back(pLogEntry);\r
1230                 firstAuthor = pLogEntry->sAuthor;\r
1231                 revLowest = pLogEntry->Rev;\r
1232                 revHighest = pLogEntry->Rev;\r
1233                 while (pos)\r
1234                 {\r
1235                         pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1236                         revisionRanges.AddRevision(pLogEntry->Rev);\r
1237                         selEntries.push_back(pLogEntry);\r
1238                         if (firstAuthor.Compare(pLogEntry->sAuthor))\r
1239                                 bAllFromTheSameAuthor = false;\r
1240                         revLowest = (git_revnum_t(pLogEntry->Rev) > git_revnum_t(revLowest) ? revLowest : pLogEntry->Rev);\r
1241                         revHighest = (git_revnum_t(pLogEntry->Rev) < git_revnum_t(revHighest) ? revHighest : pLogEntry->Rev);\r
1242                 }\r
1243         }\r
1244 \r
1245 #endif\r
1246 \r
1247         int FirstSelect=-1, LastSelect=-1;\r
1248         pos = GetFirstSelectedItemPosition();\r
1249         FirstSelect = GetNextSelectedItem(pos);\r
1250         while(pos)\r
1251         {\r
1252                 LastSelect = GetNextSelectedItem(pos);\r
1253         }\r
1254         //entry is selected, now show the popup menu\r
1255         CIconMenu popup;\r
1256         CIconMenu submenu;\r
1257         if (popup.CreatePopupMenu())\r
1258         {\r
1259 \r
1260                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK))\r
1261                         popup.AppendMenuIcon(ID_REBASE_PICK,  IDS_REBASE_PICK,   IDI_PICK);\r
1262 \r
1263                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH))\r
1264                         popup.AppendMenuIcon(ID_REBASE_SQUASH,IDS_REBASE_SQUASH, IDI_SQUASH);\r
1265 \r
1266                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT))\r
1267                         popup.AppendMenuIcon(ID_REBASE_EDIT,  IDS_REBASE_EDIT,   IDI_EDIT);\r
1268 \r
1269                 if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP))\r
1270                         popup.AppendMenuIcon(ID_REBASE_SKIP,  IDS_REBASE_SKIP,   IDI_SKIP);\r
1271                 \r
1272                 if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)|\r
1273                               GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK)))\r
1274                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1275 \r
1276                 if (GetSelectedCount() == 1)\r
1277                 {\r
1278                         \r
1279                         {\r
1280                                 if( !pSelLogEntry->m_CommitHash.IsEmpty())\r
1281                                 {\r
1282                                         if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE))\r
1283                                                 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);\r
1284                                         // TODO:\r
1285                                         // TortoiseMerge could be improved to take a /blame switch\r
1286                                         // and then not 'cat' the files from a unified diff but\r
1287                                         // blame then.\r
1288                                         // But until that's implemented, the context menu entry for\r
1289                                         // this feature is commented out.\r
1290                                         //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME);\r
1291                                 }else\r
1292                                 {\r
1293                                         if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT))\r
1294                                                 popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT);\r
1295                                 }\r
1296                                 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1))\r
1297                                         popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);\r
1298 \r
1299                                 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS))\r
1300                                         popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF);\r
1301                                 //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME);\r
1302                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1303                         }\r
1304 \r
1305 //                      if (!m_ProjectProperties.sWebViewerRev.IsEmpty())\r
1306 //                      {\r
1307 //                              popup.AppendMenuIcon(ID_VIEWREV, IDS_LOG_POPUP_VIEWREV);\r
1308 //                      }\r
1309 //                      if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())\r
1310 //                      {\r
1311 //                              popup.AppendMenuIcon(ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);\r
1312 //                      }\r
1313 //                      if ((!m_ProjectProperties.sWebViewerPathRev.IsEmpty())||\r
1314 //                              (!m_ProjectProperties.sWebViewerRev.IsEmpty()))\r
1315 //                      {\r
1316 //                              popup.AppendMenu(MF_SEPARATOR, NULL);\r
1317 //                      }\r
1318 \r
1319                         //if (m_hasWC)\r
1320                         //      popup.AppendMenuIcon(ID_REVERTTOREV, IDS_LOG_POPUP_REVERTTOREV, IDI_REVERT);\r
1321                         //if (m_hasWC)\r
1322                         //      popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);\r
1323                         //if (m_hasWC)\r
1324                         //      popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE);\r
1325                         \r
1326                         CString str,format;\r
1327                         format.LoadString(IDS_RESET_TO_THIS_FORMAT);\r
1328                         str.Format(format,g_Git.GetCurrentBranch());\r
1329 \r
1330                         if(!pSelLogEntry->m_CommitHash.IsEmpty())\r
1331                         {\r
1332                                 if(m_ContextMenuMask&GetContextMenuBit(ID_RESET))\r
1333                                         popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT);\r
1334 \r
1335                                 if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV))\r
1336                                         popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH);\r
1337 \r
1338                                 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH))\r
1339                                         popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY);\r
1340 \r
1341                                 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG))\r
1342                                         popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_COPY);\r
1343                         \r
1344                                 format.LoadString(IDS_REBASE_THIS_FORMAT);\r
1345                                 str.Format(format,g_Git.GetCurrentBranch());\r
1346 \r
1347                                 if(pSelLogEntry->m_CommitHash != m_HeadHash)\r
1348                                         if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION))\r
1349                                                 popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE);                   \r
1350 \r
1351                                 if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT))\r
1352                                         popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT); \r
1353                         \r
1354 \r
1355                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1356                         }\r
1357 \r
1358                 }\r
1359 \r
1360                 if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1)\r
1361                 {\r
1362                         popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL,     IDI_DELETE);    \r
1363                         popup.AppendMenuIcon(ID_STASH_APPLY,IDS_MENUSTASHAPPLY, IDI_RELOCATE);  \r
1364                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1365                 }\r
1366         \r
1367                 if (GetSelectedCount() >= 2)\r
1368                 {\r
1369                         bool bAddSeparator = false;\r
1370                         if (IsSelectionContinuous() || (GetSelectedCount() == 2))\r
1371                         {\r
1372                                 if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO))\r
1373                                         popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF);\r
1374                         }\r
1375 \r
1376                         if (GetSelectedCount() == 2)\r
1377                         {\r
1378                                 //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME);\r
1379                                 if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2))\r
1380                                         popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF);\r
1381                                 bAddSeparator = true;\r
1382                         }\r
1383 \r
1384                         if (m_hasWC)\r
1385                         {\r
1386                                 //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT);\r
1387 //                              if (m_hasWC)\r
1388 //                                      popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREVS, IDI_MERGE);\r
1389                                 bAddSeparator = true;\r
1390                         }\r
1391                         if (bAddSeparator)\r
1392                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1393                 }\r
1394 \r
1395                 if ( GetSelectedCount() >0 && (!pSelLogEntry->m_CommitHash.IsEmpty()))\r
1396                 {\r
1397                         if ( IsSelectionContinuous() && GetSelectedCount() >= 2 )\r
1398                         {\r
1399                                 if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT))\r
1400                                 {\r
1401                                         CString head;\r
1402                                         int headindex;\r
1403                                         headindex = this->GetHeadIndex();\r
1404                                         if(headindex>=0)\r
1405                                         {\r
1406                                                 head.Format(_T("HEAD~%d"),LastSelect-headindex);\r
1407                                                 CString hash=g_Git.GetHash(head);\r
1408                                                 hash=hash.Left(40);\r
1409                                                 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));\r
1410                                                 if(pLastEntry->m_CommitHash.ToString() == hash)\r
1411                                                         popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE);\r
1412                                         }\r
1413                                 }\r
1414                         }\r
1415                         if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK))\r
1416                                 popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT);\r
1417 \r
1418                         if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0))\r
1419                                 if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH))\r
1420                                         popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH);\r
1421                         \r
1422                         popup.AppendMenu(MF_SEPARATOR, NULL);\r
1423         \r
1424                 }\r
1425 \r
1426                 \r
1427 #if 0\r
1428 //              if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor))\r
1429 //              {\r
1430 //                      popup.AppendMenuIcon(ID_EDITAUTHOR, IDS_LOG_POPUP_EDITAUTHOR);\r
1431 //              }\r
1432 //              if (GetSelectedCount() == 1)\r
1433 //              {\r
1434 //                      popup.AppendMenuIcon(ID_EDITLOG, IDS_LOG_POPUP_EDITLOG);\r
1435 //                      popup.AppendMenuIcon(ID_REVPROPS, IDS_REPOBROWSE_SHOWREVPROP, IDI_PROPERTIES); // "Show Revision Properties"\r
1436 //                      popup.AppendMenu(MF_SEPARATOR, NULL);\r
1437 //              }\r
1438 #endif\r
1439 \r
1440                 \r
1441                 if (GetSelectedCount() == 1)\r
1442                 {\r
1443                         if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH))\r
1444                                 popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH);\r
1445                 }\r
1446                 if (GetSelectedCount() != 0)\r
1447                 {\r
1448                         if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD))\r
1449                                 popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD);\r
1450                 }\r
1451 \r
1452                 if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY))\r
1453                         popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND);\r
1454 \r
1455 \r
1456                 if (GetSelectedCount() == 1)\r
1457                 {\r
1458                         if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE))\r
1459                         {\r
1460                                 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() )\r
1461                                 {\r
1462                                         CString str;\r
1463                                         str.LoadString(IDS_DELETE_BRANCHTAG);\r
1464                                         if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 )\r
1465                                         {\r
1466                                                 str+=_T(" ");\r
1467                                                 str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0);\r
1468                                                 popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE);\r
1469                                         }\r
1470                                         else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 )\r
1471                                         {\r
1472                                                 \r
1473                                                 submenu.CreatePopupMenu();\r
1474                                                 for(int i=0;i<m_HashMap[pSelLogEntry->m_CommitHash].size();i++)\r
1475                                                 {\r
1476                                                         submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("..."));\r
1477                                                 }\r
1478 \r
1479                                                 popup.AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT) submenu.m_hMenu,str); \r
1480 \r
1481                                         }\r
1482                                         \r
1483                                 }\r
1484                         }\r
1485                 }\r
1486 \r
1487                 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
1488 //              DialogEnableWindow(IDOK, FALSE);\r
1489 //              SetPromptApp(&theApp);\r
1490         \r
1491                 this->ContextMenuAction(cmd, FirstSelect, LastSelect);\r
1492                 \r
1493 //              EnableOKButton();\r
1494         } // if (popup.CreatePopupMenu())\r
1495 \r
1496 }\r
1497 \r
1498 bool CGitLogListBase::IsSelectionContinuous()\r
1499 {\r
1500         if ( GetSelectedCount()==1 )\r
1501         {\r
1502                 // if only one revision is selected, the selection is of course\r
1503                 // continuous\r
1504                 return true;\r
1505         }\r
1506 \r
1507         POSITION pos = GetFirstSelectedItemPosition();\r
1508         bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size());\r
1509         if (bContinuous)\r
1510         {\r
1511                 int itemindex = GetNextSelectedItem(pos);\r
1512                 while (pos)\r
1513                 {\r
1514                         int nextindex = GetNextSelectedItem(pos);\r
1515                         if (nextindex - itemindex > 1)\r
1516                         {\r
1517                                 bContinuous = false;\r
1518                                 break;\r
1519                         }\r
1520                         itemindex = nextindex;\r
1521                 }\r
1522         }\r
1523         return bContinuous;\r
1524 }\r
1525 \r
1526 void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly)\r
1527 {\r
1528 \r
1529         CString sClipdata;\r
1530         POSITION pos = GetFirstSelectedItemPosition();\r
1531         if (pos != NULL)\r
1532         {\r
1533                 CString sRev;\r
1534                 sRev.LoadString(IDS_LOG_REVISION);\r
1535                 CString sAuthor;\r
1536                 sAuthor.LoadString(IDS_LOG_AUTHOR);\r
1537                 CString sDate;\r
1538                 sDate.LoadString(IDS_LOG_DATE);\r
1539                 CString sMessage;\r
1540                 sMessage.LoadString(IDS_LOG_MESSAGE);\r
1541                 while (pos)\r
1542                 {\r
1543                         CString sLogCopyText;\r
1544                         CString sPaths;\r
1545                         GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_arShownList.GetAt(GetNextSelectedItem(pos)));\r
1546 \r
1547                         if(!HashOnly)\r
1548                         {\r
1549                                 //pLogEntry->m_Files\r
1550                                 //LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;\r
1551                         \r
1552                                 for (int cpPathIndex = 0; cpPathIndex<pLogEntry->m_Files.GetCount(); ++cpPathIndex)\r
1553                                 {\r
1554                                         sPaths += ((CTGitPath&)pLogEntry->m_Files[cpPathIndex]).GetActionName() + _T(" : ") + pLogEntry->m_Files[cpPathIndex].GetGitPathString();\r
1555                                         sPaths += _T("\r\n");\r
1556                                 }\r
1557                                 sPaths.Trim();\r
1558                                 sLogCopyText.Format(_T("%s: %s\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"),\r
1559                                         (LPCTSTR)sRev, pLogEntry->m_CommitHash,\r
1560                                         (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName,\r
1561                                         (LPCTSTR)sDate, \r
1562                                         (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ),\r
1563                                         (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body,\r
1564                                         (LPCTSTR)sPaths);\r
1565                                 sClipdata +=  sLogCopyText;\r
1566                         }else\r
1567                         {\r
1568                                 sClipdata += pLogEntry->m_CommitHash;\r
1569                                 break;\r
1570                         }\r
1571 \r
1572                 }\r
1573                 CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());\r
1574         }\r
1575 \r
1576 }\r
1577 \r
1578 void CGitLogListBase::DiffSelectedRevWithPrevious()\r
1579 {\r
1580         if (m_bThreadRunning)\r
1581                 return;\r
1582 \r
1583         int FirstSelect=-1, LastSelect=-1;\r
1584         POSITION pos = GetFirstSelectedItemPosition();\r
1585         FirstSelect = GetNextSelectedItem(pos);\r
1586         while(pos)\r
1587         {\r
1588                 LastSelect = GetNextSelectedItem(pos);\r
1589         }\r
1590 \r
1591         ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect);\r
1592 \r
1593 #if 0\r
1594         UpdateLogInfoLabel();\r
1595         int selIndex = m_LogList.GetSelectionMark();\r
1596         if (selIndex < 0)\r
1597                 return;\r
1598         int selCount = m_LogList.GetSelectedCount();\r
1599         if (selCount != 1)\r
1600                 return;\r
1601 \r
1602         // Find selected entry in the log list\r
1603         POSITION pos = m_LogList.GetFirstSelectedItemPosition();\r
1604         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));\r
1605         long rev1 = pLogEntry->Rev;\r
1606         long rev2 = rev1-1;\r
1607         CTGitPath path = m_path;\r
1608 \r
1609         // See how many files under the relative root were changed in selected revision\r
1610         int nChanged = 0;\r
1611         LogChangedPath * changed = NULL;\r
1612         for (INT_PTR c = 0; c < pLogEntry->pArChangedPaths->GetCount(); ++c)\r
1613         {\r
1614                 LogChangedPath * cpath = pLogEntry->pArChangedPaths->GetAt(c);\r
1615                 if (cpath  &&  cpath -> sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)\r
1616                 {\r
1617                         ++nChanged;\r
1618                         changed = cpath;\r
1619                 }\r
1620         }\r
1621 \r
1622         if (m_path.IsDirectory() && nChanged == 1) \r
1623         {\r
1624                 // We're looking at the log for a directory and only one file under dir was changed in the revision\r
1625                 // Do diff on that file instead of whole directory\r
1626                 path.AppendPathString(changed->sPath.Mid(m_sRelativeRoot.GetLength()));\r
1627         } \r
1628 \r
1629         m_bCancelled = FALSE;\r
1630         DialogEnableWindow(IDOK, FALSE);\r
1631         SetPromptApp(&theApp);\r
1632         theApp.DoWaitCursor(1);\r
1633 \r
1634         if (PromptShown())\r
1635         {\r
1636                 GitDiff diff(this, m_hWnd, true);\r
1637                 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1638                 diff.SetHEADPeg(m_LogRevision);\r
1639                 diff.ShowCompare(path, rev2, path, rev1);\r
1640         }\r
1641         else\r
1642         {\r
1643                 CAppUtils::StartShowCompare(m_hWnd, path, rev2, path, rev1, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1644         }\r
1645 \r
1646         theApp.DoWaitCursor(-1);\r
1647         EnableOKButton();\r
1648 #endif\r
1649 }\r
1650 \r
1651 void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult)\r
1652 {\r
1653         LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);\r
1654         *pResult = -1;\r
1655         \r
1656         if (pFindInfo->lvfi.flags & LVFI_PARAM)\r
1657                 return; \r
1658         if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount()))\r
1659                 return;\r
1660         if (pFindInfo->lvfi.psz == 0)\r
1661                 return;\r
1662 #if 0\r
1663         CString sCmp = pFindInfo->lvfi.psz;\r
1664         CString sRev;   \r
1665         for (int i=pFindInfo->iStart; i<m_arShownList.GetCount(); ++i)\r
1666         {\r
1667                 GitRev * pLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));\r
1668                 sRev.Format(_T("%ld"), pLogEntry->Rev);\r
1669                 if (pFindInfo->lvfi.flags & LVFI_PARTIAL)\r
1670                 {\r
1671                         if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)\r
1672                         {\r
1673                                 *pResult = i;\r
1674                                 return;\r
1675                         }\r
1676                 }\r
1677                 else\r
1678                 {\r
1679                         if (sCmp.Compare(sRev)==0)\r
1680                         {\r
1681                                 *pResult = i;\r
1682                                 return;\r
1683                         }\r
1684                 }\r
1685         }\r
1686         if (pFindInfo->lvfi.flags & LVFI_WRAP)\r
1687         {\r
1688                 for (int i=0; i<pFindInfo->iStart; ++i)\r
1689                 {\r
1690                         PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(i));\r
1691                         sRev.Format(_T("%ld"), pLogEntry->Rev);\r
1692                         if (pFindInfo->lvfi.flags & LVFI_PARTIAL)\r
1693                         {\r
1694                                 if (sCmp.Compare(sRev.Left(sCmp.GetLength()))==0)\r
1695                                 {\r
1696                                         *pResult = i;\r
1697                                         return;\r
1698                                 }\r
1699                         }\r
1700                         else\r
1701                         {\r
1702                                 if (sCmp.Compare(sRev)==0)\r
1703                                 {\r
1704                                         *pResult = i;\r
1705                                         return;\r
1706                                 }\r
1707                         }\r
1708                 }\r
1709         }\r
1710 #endif\r
1711         *pResult = -1;\r
1712 }\r
1713 \r
1714 int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to)\r
1715 {\r
1716         ClearText();\r
1717 \r
1718         this->m_logEntries.ClearAll();\r
1719         this->m_logEntries.ParserFromLog(path,-1,info,from,to);\r
1720 \r
1721         //this->m_logEntries.ParserFromLog();\r
1722         SetItemCountEx(this->m_logEntries.size());\r
1723 \r
1724         this->m_arShownList.RemoveAll();\r
1725 \r
1726         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1727         {\r
1728                 if(m_IsOldFirst)\r
1729                 {\r
1730                         m_logEntries.GetGitRevAt(m_logEntries.size()-i-1).m_IsFull=TRUE;\r
1731                         this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);\r
1732                 \r
1733                 }else\r
1734                 {\r
1735                         m_logEntries.GetGitRevAt(i).m_IsFull=TRUE;\r
1736                         this->m_arShownList.Add(&m_logEntries[i]);\r
1737                 }\r
1738         }\r
1739 \r
1740     if(path)\r
1741         m_Path=*path;\r
1742         return 0;\r
1743 \r
1744 }\r
1745 \r
1746 int CGitLogListBase::BeginFetchLog()\r
1747 {\r
1748         ClearText();\r
1749 \r
1750         this->m_logEntries.ClearAll();\r
1751         git_init();\r
1752 \r
1753         m_LogCache.FetchCacheIndex(g_Git.m_CurrentDir);\r
1754 \r
1755     CTGitPath *path;\r
1756     if(this->m_Path.IsEmpty())\r
1757         path=NULL;\r
1758     else\r
1759         path=&this->m_Path;\r
1760 \r
1761         CString hash;\r
1762         int mask;\r
1763         mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY;\r
1764 //      if(this->m_bAllBranch)\r
1765         mask |= m_ShowMask;\r
1766         \r
1767         this->m_arShownList.RemoveAll();\r
1768 \r
1769         if(m_bShowWC)\r
1770         {\r
1771                 this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev.m_CommitHash);\r
1772                 this->m_LogCache.m_HashMap[m_wcRev.m_CommitHash]=m_wcRev;\r
1773         }\r
1774 \r
1775         CString cmd=g_Git.GetLogCmd(m_StartRef,path,-1,mask,NULL,NULL,true);\r
1776 \r
1777         //this->m_logEntries.ParserFromLog();\r
1778         if(IsInWorkingThread())\r
1779         {\r
1780                 PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);\r
1781         }\r
1782         else\r
1783         {\r
1784                 SetItemCountEx(this->m_logEntries.size());\r
1785         }\r
1786         \r
1787         if(git_open_log(&m_DllGitLog,CUnicodeUtils::GetMulti(cmd,CP_ACP).GetBuffer()))\r
1788         {\r
1789                 return -1;\r
1790         }\r
1791 \r
1792         return 0;\r
1793 }\r
1794 \r
1795 BOOL CGitLogListBase::PreTranslateMessage(MSG* pMsg)\r
1796 {\r
1797         // Skip Ctrl-C when copying text out of the log message or search filter\r
1798         BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );\r
1799         if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')\r
1800         {\r
1801                 //if (GetFocus()==GetDlgItem(IDC_LOGLIST))\r
1802                 {\r
1803                         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1804                         {\r
1805                                 DiffSelectedRevWithPrevious();\r
1806                                 return TRUE;\r
1807                         }\r
1808                 }\r
1809 #if 0\r
1810                 if (GetFocus()==GetDlgItem(IDC_LOGMSG))\r
1811                 {\r
1812                         DiffSelectedFile();\r
1813                         return TRUE;\r
1814                 }\r
1815 #endif\r
1816         }\r
1817 \r
1818 #if 0\r
1819         if (m_hAccel && !bSkipAccelerator)\r
1820         {\r
1821                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
1822                 if (ret)\r
1823                         return TRUE;\r
1824         }\r
1825         \r
1826 #endif\r
1827         //m_tooltips.RelayEvent(pMsg);\r
1828         return __super::PreTranslateMessage(pMsg);\r
1829 }\r
1830 \r
1831 void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult)\r
1832 {\r
1833         // a double click on an entry in the revision list has happened\r
1834         *pResult = 0;\r
1835 \r
1836         if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))\r
1837                 DiffSelectedRevWithPrevious();\r
1838 }\r
1839 \r
1840 int CGitLogListBase::FetchLogAsync(void * data)\r
1841 {\r
1842         m_ProcData=data;\r
1843         m_bExitThread=FALSE;\r
1844         InterlockedExchange(&m_bThreadRunning, TRUE);\r
1845         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
1846         m_LoadingThread = AfxBeginThread(LogThreadEntry, this);\r
1847         if (m_LoadingThread ==NULL)\r
1848         {\r
1849                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1850                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
1851                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
1852                 return -1;\r
1853         }\r
1854         return 0;\r
1855 }\r
1856 \r
1857 //this is the thread function which calls the subversion function\r
1858 UINT CGitLogListBase::LogThreadEntry(LPVOID pVoid)\r
1859 {\r
1860         return ((CGitLogListBase*)pVoid)->LogThread();\r
1861 }\r
1862 \r
1863 void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest)\r
1864 {\r
1865         //CTime time;\r
1866         oldest=CTime::GetCurrentTime();\r
1867         latest=CTime(1971,1,2,0,0,0);\r
1868         for(unsigned int i=0;i<m_logEntries.size();i++)\r
1869         {\r
1870                 if(m_logEntries[i].IsEmpty())\r
1871                         continue;\r
1872 \r
1873                 if(m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime() < oldest.GetTime())\r
1874                         oldest = m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime();\r
1875 \r
1876                 if(m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime() > latest.GetTime())\r
1877                         latest = m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime();\r
1878 \r
1879         }\r
1880 }\r
1881 \r
1882 //Helper class for FetchFullLogInfo()\r
1883 class CGitCall_FetchFullLogInfo : public CGitCall\r
1884 {\r
1885 public:\r
1886         CGitCall_FetchFullLogInfo(CGitLogListBase* ploglist):m_ploglist(ploglist),m_CollectedCount(0){}\r
1887         virtual bool OnOutputData(const BYTE* data, size_t size)\r
1888         {\r
1889                 if(size==0)\r
1890                         return m_ploglist->m_bExitThread;\r
1891                 //Add received data to byte collector\r
1892                 m_ByteCollector.append(data,size);\r
1893 \r
1894                 //Find loginfo endmarker\r
1895                 static const BYTE dataToFind[]={0,0,'#','<'};\r
1896                 int found=m_ByteCollector.findData(dataToFind,4);\r
1897                 if(found<0)\r
1898                         return m_ploglist->m_bExitThread;//Not found\r
1899                 found+=2;//Position after loginfo end-marker\r
1900 \r
1901                 //Prepare data for OnLogInfo and call it\r
1902                 BYTE_VECTOR logInfo;\r
1903                 logInfo.append(&*m_ByteCollector.begin(),found);\r
1904                 OnLogInfo(logInfo);\r
1905 \r
1906                 //Remove loginfo from bytecollector\r
1907                 m_ByteCollector.erase(m_ByteCollector.begin(),m_ByteCollector.begin()+found);\r
1908 \r
1909                 return m_ploglist->m_bExitThread;\r
1910         }\r
1911         virtual void OnEnd()\r
1912         {\r
1913                 //Rest should be a complete log line.\r
1914                 if(!m_ByteCollector.empty())\r
1915                         OnLogInfo(m_ByteCollector);\r
1916         }\r
1917 \r
1918 \r
1919         void OnLogInfo(BYTE_VECTOR& logInfo)\r
1920         {\r
1921                 GitRev fullRev;\r
1922                 fullRev.ParserFromLog(logInfo);\r
1923                 MAP_HASH_REV::iterator itRev=m_ploglist->m_logEntries.m_HashMap.find(fullRev.m_CommitHash);\r
1924                 if(itRev==m_ploglist->m_logEntries.m_HashMap.end())\r
1925                 {\r
1926                         //Should not occur, only when Git-tree updated in the mean time. (Race condition)\r
1927                         return;//Ignore\r
1928                 }\r
1929                 //Set updating\r
1930                 int rev=itRev->second;\r
1931                 GitRev* revInVector=&m_ploglist->m_logEntries.GetGitRevAt(rev);\r
1932 \r
1933 \r
1934                 if(revInVector->m_IsFull)\r
1935                         return;\r
1936 \r
1937                 GitRev *pRev= m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev]);\r
1938                 if(pRev)\r
1939                 {\r
1940                         ++m_CollectedCount;\r
1941                         InterlockedExchange(&pRev->m_IsUpdateing,FALSE);\r
1942                         InterlockedExchange(&pRev->m_IsFull,TRUE);\r
1943                         ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);\r
1944                         return;\r
1945                 }\r
1946 \r
1947 //              fullRev.m_IsUpdateing=TRUE;\r
1948 //              fullRev.m_IsFull=TRUE;\r
1949         \r
1950 \r
1951                 if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE))\r
1952                         return;//Cannot update this row now. Ignore.\r
1953                 TCHAR oldmark=revInVector->m_Mark;\r
1954                 GIT_REV_LIST oldlist=revInVector->m_ParentHash;\r
1955 //              CString oldhash=m_CommitHash;\r
1956 \r
1957                 //Parse new rev info\r
1958                 revInVector->ParserFromLog(logInfo);\r
1959 \r
1960                 if(oldmark!=0)\r
1961                         revInVector->m_Mark=oldmark;  //parser full log will cause old mark overwrited. \r
1962                                                                //So we need keep old bound mark.\r
1963                 revInVector->m_ParentHash=oldlist;\r
1964 \r
1965                 //update cache\r
1966                 m_ploglist->m_LogCache.AddCacheEntry(*revInVector);\r
1967 \r
1968                 //Reset updating\r
1969                 InterlockedExchange(&revInVector->m_IsFull,TRUE);\r
1970                 InterlockedExchange(&revInVector->m_IsUpdateing,FALSE);\r
1971 \r
1972                 //Notify listcontrol and update progress bar\r
1973                 ++m_CollectedCount;\r
1974 \r
1975                 ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);\r
1976 \r
1977                 DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30;\r
1978                 if(percent == GITLOG_END)\r
1979                         percent = GITLOG_END -1;\r
1980                 \r
1981                 ::PostMessage(m_ploglist->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);\r
1982         }\r
1983 \r
1984         CGitLogListBase*        m_ploglist;\r
1985         BYTE_VECTOR                     m_ByteCollector;\r
1986         int                                     m_CollectedCount;\r
1987 \r
1988 };\r
1989 \r
1990 void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to)\r
1991 {\r
1992         CGitCall_FetchFullLogInfo fetcher(this);\r
1993         int mask=\r
1994                 CGit::LOG_INFO_FULL_DIFF|\r
1995                 CGit::LOG_INFO_STAT|\r
1996                 CGit::LOG_INFO_FILESTATE|\r
1997                 CGit::LOG_INFO_DETECT_COPYRENAME|\r
1998                 CGit::LOG_INFO_SHOW_MERGEDFILE |\r
1999                 m_ShowMask;\r
2000 \r
2001         CTGitPath *path;\r
2002     if(this->m_Path.IsEmpty())\r
2003         path=NULL;\r
2004     else\r
2005         path=&this->m_Path;\r
2006 \r
2007         g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to);\r
2008 }\r
2009 \r
2010 void CGitLogListBase::FetchLastLogInfo()\r
2011 {\r
2012         unsigned int updated=0;\r
2013         int percent=0;\r
2014         CRect rect;\r
2015         {\r
2016                 for(unsigned int i=0;i<m_logEntries.size();i++)\r
2017                 {\r
2018                         if(m_logEntries.GetGitRevAt(i).m_IsFull)\r
2019                                 continue;\r
2020 \r
2021                         GitRev *pRev = m_LogCache.GetCacheData(m_logEntries[i]);\r
2022                         if(pRev == NULL)\r
2023                         {\r
2024                                 if(!m_logEntries.FetchFullInfo(i))\r
2025                                 {\r
2026                                         updated++;\r
2027                                 }\r
2028                                 m_LogCache.AddCacheEntry(m_logEntries.GetGitRevAt(i));\r
2029 \r
2030                         }else\r
2031                         {\r
2032                                 updated++;\r
2033                                 InterlockedExchange(&pRev->m_IsUpdateing,FALSE);\r
2034                                 InterlockedExchange(&pRev->m_IsFull,TRUE);\r
2035                         }\r
2036                         \r
2037                         ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0);\r
2038 \r
2039                         if(m_bExitThread)\r
2040                         {\r
2041                                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
2042                                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2043                                 return;\r
2044                         }                       \r
2045                 }\r
2046         }\r
2047 }\r
2048 \r
2049 UINT CGitLogListBase::LogThread()\r
2050 {\r
2051         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);\r
2052         \r
2053         InterlockedExchange(&m_bThreadRunning, TRUE);\r
2054         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2055 \r
2056         ULONGLONG  t1,t2;\r
2057         \r
2058         if(BeginFetchLog())\r
2059                 return -1;\r
2060 \r
2061         //Update work copy item;\r
2062         if( m_logEntries.size() > 0)\r
2063         {\r
2064                 GitRev *pRev = &m_logEntries.GetGitRevAt(0);\r
2065                 \r
2066                 m_arShownList.Add(pRev);\r
2067 \r
2068                 if( pRev->m_CommitHash.IsEmpty() )\r
2069                 {\r
2070                         pRev->m_Files.Clear();\r
2071                         pRev->m_ParentHash.clear();\r
2072                         pRev->m_ParentHash.push_back(m_HeadHash);\r
2073                         g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash, pRev->m_Files);\r
2074                         pRev->m_Action =0;\r
2075                 \r
2076                         for(int j=0;j< pRev->m_Files.GetCount();j++)\r
2077                         pRev->m_Action |= pRev->m_Files[j].m_Action;\r
2078                         \r
2079                         pRev->m_Body.Format(_T("%d files changed"),m_logEntries.GetGitRevAt(0).m_Files.GetCount());\r
2080                         ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);\r
2081                 }\r
2082         }\r
2083 \r
2084         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2085 \r
2086         git_get_log_firstcommit(m_DllGitLog);\r
2087         GIT_COMMIT commit;\r
2088         t1=GetTickCount();\r
2089 \r
2090         int oldsize=m_logEntries.size();\r
2091         while( git_get_log_nextcommit(this->m_DllGitLog,&commit) == 0)\r
2092         {\r
2093                 //printf("%s\r\n",commit.m_Subject);\r
2094                 if(m_bExitThread)\r
2095                         break;\r
2096 \r
2097                 CGitHash hash = (char*)commit.m_hash ;\r
2098 \r
2099                 m_logEntries.push_back(hash);\r
2100                 \r
2101                 GitRev *pRev = m_LogCache.GetCacheData(hash);\r
2102                 \r
2103                 if(pRev == NULL || !pRev->m_IsFull)\r
2104                 {\r
2105                         pRev->ParserFromCommit(&commit);\r
2106                         pRev->ParserParentFromCommit(&commit);\r
2107 \r
2108                         pRev->SafeFetchFullInfo(&g_Git);\r
2109                         git_free_commit(&commit);\r
2110                         \r
2111                 }else\r
2112                 {\r
2113                         ASSERT(pRev->m_CommitHash == hash);\r
2114                         pRev->ParserParentFromCommit(&commit);\r
2115                 }\r
2116 \r
2117                 m_arShownList.Add(pRev);\r
2118 \r
2119                 if(t2-t1>500 && m_logEntries.size()<(oldsize+100) )\r
2120                 {\r
2121                         //update UI\r
2122                         oldsize = m_logEntries.size();\r
2123                         PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);\r
2124                         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);\r
2125                 }               \r
2126         }\r
2127         \r
2128         //Update UI;\r
2129         PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);\r
2130         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);\r
2131 \r
2132         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2133 \r
2134 #if 0\r
2135 //      if(m_ProcCallBack)\r
2136 //              m_ProcCallBack(m_ProcData,GITLOG_START);\r
2137         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START,0);\r
2138 \r
2139         InterlockedExchange(&m_bThreadRunning, TRUE);\r
2140         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2141 \r
2142     //does the user force the cache to refresh (shift or control key down)?\r
2143     bool refresh =    (GetKeyState (VK_CONTROL) < 0) \r
2144                    || (GetKeyState (VK_SHIFT) < 0);\r
2145 \r
2146         //disable the "Get All" button while we're receiving\r
2147         //log messages.\r
2148 \r
2149         FillGitShortLog();\r
2150         \r
2151         if(this->m_bExitThread)\r
2152         {\r
2153                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
2154                 InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2155                 return 0;\r
2156         }\r
2157         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2158         ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0);\r
2159 \r
2160         int start=0; CString firstcommit,lastcommit;\r
2161         int update=0;\r
2162         for(int i=0;i<m_logEntries.size();i++)\r
2163         {\r
2164                 if( i==0 && m_logEntries.GetGitRevAt(i).m_CommitHash.IsEmpty() )\r
2165                 {\r
2166                         m_logEntries.GetGitRevAt(i).m_Files.Clear();\r
2167                         m_logEntries.GetGitRevAt(i).m_ParentHash.clear();\r
2168                         m_logEntries.GetGitRevAt(i).m_ParentHash.push_back(m_HeadHash);\r
2169                         g_Git.GetCommitDiffList(m_logEntries.GetGitRevAt(i).m_CommitHash.ToString(),this->m_HeadHash,m_logEntries.GetGitRevAt(i).m_Files);\r
2170                         m_logEntries.GetGitRevAt(i).m_Action =0;\r
2171                         for(int j=0;j< m_logEntries.GetGitRevAt(i).m_Files.GetCount();j++)\r
2172                                 m_logEntries.GetGitRevAt(i).m_Action |= m_logEntries.GetGitRevAt(i).m_Files[j].m_Action;\r
2173                         \r
2174                         m_logEntries.GetGitRevAt(i).m_Body.Format(_T("%d files changed"),m_logEntries.GetGitRevAt(i).m_Files.GetCount());\r
2175                         ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0);\r
2176                         continue;\r
2177                 }\r
2178 \r
2179                 start=this->m_logEntries.GetGitRevAt(i).ParserFromLog(m_logEntries.m_RawlogData,start);\r
2180                 m_logEntries.m_HashMap[m_logEntries.GetGitRevAt(i).m_CommitHash.ToString()]=i;\r
2181 \r
2182                 if(m_LogCache.GetCacheData(m_logEntries.GetGitRevAt(i)))\r
2183                 {\r
2184                         if(firstcommit.IsEmpty())\r
2185                                 firstcommit=m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();\r
2186                         lastcommit=m_logEntries.GetGitRevAt(i).m_CommitHash.ToString();\r
2187 \r
2188                 }else\r
2189                 {\r
2190                         InterlockedExchange(&m_logEntries.GetGitRevAt(i).m_IsUpdateing,FALSE);\r
2191                         InterlockedExchange(&m_logEntries.GetGitRevAt(i).m_IsFull,TRUE);\r
2192                         update++;\r
2193                 }\r
2194                 ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0);\r
2195 \r
2196                 if(start<0)\r
2197                         break;\r
2198                 if(start>=m_logEntries.m_RawlogData.size())\r
2199                         break;\r
2200 \r
2201                 int percent=i*30/m_logEntries.size() + GITLOG_START+1;\r
2202 \r
2203                 ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0);\r
2204 \r
2205                 if(this->m_bExitThread)\r
2206                 {       \r
2207                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2208                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2209                         return 0;\r
2210                 }\r
2211         }\r
2212         if(!lastcommit.IsEmpty())\r
2213                 FetchFullLogInfo(lastcommit,firstcommit);\r
2214         \r
2215         this->FetchLastLogInfo();\r
2216         \r
2217 #if 0\r
2218         RedrawItems(0, m_arShownList.GetCount());\r
2219 //      SetRedraw(false);\r
2220 //      ResizeAllListCtrlCols();\r
2221 //      SetRedraw(true);\r
2222 \r
2223         if ( m_pStoreSelection )\r
2224         {\r
2225                 // Deleting the instance will restore the\r
2226                 // selection of the CLogDlg.\r
2227                 delete m_pStoreSelection;\r
2228                 m_pStoreSelection = NULL;\r
2229         }\r
2230         else\r
2231         {\r
2232                 // If no selection has been set then this must be the first time\r
2233                 // the revisions are shown. Let's preselect the topmost revision.\r
2234                 if ( GetItemCount()>0 )\r
2235                 {\r
2236                         SetSelectionMark(0);\r
2237                         SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);\r
2238                 }\r
2239         }\r
2240 #endif\r
2241 \r
2242 \r
2243 \r
2244         //FetchFullLogInfo();\r
2245         //FetchFullLogInfoOrig();\r
2246         //RefreshCursor();\r
2247         // make sure the filter is applied (if any) now, after we refreshed/fetched\r
2248         // the log messages\r
2249 \r
2250         ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_END,0);\r
2251 \r
2252         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2253 #endif\r
2254         return 0;\r
2255 }\r
2256 \r
2257 void CGitLogListBase::Refresh()\r
2258 {       \r
2259         m_bExitThread=TRUE;\r
2260         if(m_LoadingThread!=NULL)\r
2261         {\r
2262                 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);\r
2263                 if(ret == WAIT_TIMEOUT)\r
2264                         TerminateThread();\r
2265         }\r
2266         \r
2267         this->SetItemCountEx(0);\r
2268         this->Clear();\r
2269 \r
2270         //Update branch and Tag info\r
2271         ReloadHashMap();\r
2272         //Assume Thread have exited\r
2273         //if(!m_bThreadRunning)\r
2274         {\r
2275                 \r
2276                 m_logEntries.clear();\r
2277                 m_bExitThread=FALSE;\r
2278                 InterlockedExchange(&m_bThreadRunning, TRUE);\r
2279                 InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2280                 if (AfxBeginThread(LogThreadEntry, this)==NULL)\r
2281                 {\r
2282                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
2283                         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2284                         CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
2285                 }\r
2286                 m_sFilterText.Empty();\r
2287                 m_From=CTime(1970,1,2,0,0,0);\r
2288                 m_To=CTime::GetCurrentTime();\r
2289         }\r
2290 }\r
2291 bool CGitLogListBase::ValidateRegexp(LPCTSTR regexp_str, tr1::wregex& pat, bool bMatchCase /* = false */)\r
2292 {\r
2293         try\r
2294         {\r
2295                 tr1::regex_constants::syntax_option_type type = tr1::regex_constants::ECMAScript;\r
2296                 if (!bMatchCase)\r
2297                         type |= tr1::regex_constants::icase;\r
2298                 pat = tr1::wregex(regexp_str, type);\r
2299                 return true;\r
2300         }\r
2301         catch (exception) {}\r
2302         return false;\r
2303 }\r
2304 \r
2305 void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist)\r
2306 {\r
2307 \r
2308         pShownlist->RemoveAll();\r
2309         tr1::wregex pat;//(_T("Remove"), tr1::regex_constants::icase);\r
2310         bool bRegex = false;\r
2311         if (m_bFilterWithRegex)\r
2312                 bRegex = ValidateRegexp(m_sFilterText, pat, false);\r
2313 \r
2314         tr1::regex_constants::match_flag_type flags = tr1::regex_constants::match_any;\r
2315         CString sRev;\r
2316         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
2317         {\r
2318                 if ((bRegex)&&(m_bFilterWithRegex))\r
2319                 {\r
2320 #if 0\r
2321                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))\r
2322                         {\r
2323                                 ATLTRACE(_T("bugID = \"%s\"\n"), (LPCTSTR)m_logEntries[i]->sBugIDs);\r
2324                                 if (regex_search(wstring((LPCTSTR)m_logEntries[i]->sBugIDs), pat, flags)&&IsEntryInDateRange(i))\r
2325                                 {\r
2326                                         pShownlist->Add(m_logEntries[i]);\r
2327                                         continue;\r
2328                                 }\r
2329                         }\r
2330 #endif\r
2331                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))\r
2332                         {\r
2333                                 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).m_Subject);\r
2334                                 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).m_Subject), pat, flags)&&IsEntryInDateRange(i))\r
2335                                 {\r
2336                                         pShownlist->Add(&m_logEntries[i]);\r
2337                                         continue;\r
2338                                 }\r
2339 \r
2340                                 ATLTRACE(_T("messge = \"%s\"\n"),m_logEntries.GetGitRevAt(i).m_Body);\r
2341                                 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).m_Body), pat, flags)&&IsEntryInDateRange(i))\r
2342                                 {\r
2343                                         pShownlist->Add(&m_logEntries.GetGitRevAt(i));\r
2344                                         continue;\r
2345                                 }\r
2346                         }\r
2347 #if 0\r
2348                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))\r
2349                         {\r
2350                                 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;\r
2351 \r
2352                                 bool bGoing = true;\r
2353                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)\r
2354                                 {\r
2355                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
2356                                         if (regex_search(wstring((LPCTSTR)cpath->sCopyFromPath), pat, flags)&&IsEntryInDateRange(i))\r
2357                                         {\r
2358                                                 pShownlist->Add(m_logEntries[i]);\r
2359                                                 bGoing = false;\r
2360                                                 continue;\r
2361                                         }\r
2362                                         if (regex_search(wstring((LPCTSTR)cpath->sPath), pat, flags)&&IsEntryInDateRange(i))\r
2363                                         {\r
2364                                                 pShownlist->Add(m_logEntries[i]);\r
2365                                                 bGoing = false;\r
2366                                                 continue;\r
2367                                         }\r
2368                                         if (regex_search(wstring((LPCTSTR)cpath->GetAction()), pat, flags)&&IsEntryInDateRange(i))\r
2369                                         {\r
2370                                                 pShownlist->Add(m_logEntries[i]);\r
2371                                                 bGoing = false;\r
2372                                                 continue;\r
2373                                         }\r
2374                                 }\r
2375                                 if (!bGoing)\r
2376                                         continue;\r
2377                         }\r
2378 #endif\r
2379                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))\r
2380                         {\r
2381                                 if (regex_search(wstring((LPCTSTR)m_logEntries.GetGitRevAt(i).m_AuthorName), pat, flags)&&IsEntryInDateRange(i))\r
2382                                 {\r
2383                                         pShownlist->Add(&m_logEntries.GetGitRevAt(i));\r
2384                                         continue;\r
2385                                 }\r
2386                         }\r
2387                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))\r
2388                         {\r
2389                                 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash);\r
2390                                 if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i))\r
2391                                 {\r
2392                                         pShownlist->Add(&m_logEntries.GetGitRevAt(i));\r
2393                                         continue;\r
2394                                 }\r
2395                         }\r
2396                 } // if (bRegex)\r
2397                 else\r
2398                 {\r
2399                         CString find = m_sFilterText;\r
2400                         find.MakeLower();\r
2401 #if 0\r
2402                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_BUGID))\r
2403                         {\r
2404                                 CString sBugIDs = m_logEntries[i]->sBugIDs;\r
2405 \r
2406                                 sBugIDs = sBugIDs.MakeLower();\r
2407                                 if ((sBugIDs.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2408                                 {\r
2409                                         pShownlist->Add(m_logEntries[i]);\r
2410                                         continue;\r
2411                                 }\r
2412                         }\r
2413 #endif\r
2414                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_MESSAGES))\r
2415                         {\r
2416                                 CString msg = m_logEntries.GetGitRevAt(i).m_Subject;\r
2417 \r
2418                                 msg = msg.MakeLower();\r
2419                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2420                                 {\r
2421                                         pShownlist->Add(&m_logEntries.GetGitRevAt(i));\r
2422                                         continue;\r
2423                                 }\r
2424                                 msg = m_logEntries.GetGitRevAt(i).m_Body;\r
2425 \r
2426                                 msg = msg.MakeLower();\r
2427                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2428                                 {\r
2429                                         pShownlist->Add(&m_logEntries[i]);\r
2430                                         continue;\r
2431                                 }\r
2432                         }\r
2433 #if 0\r
2434                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_PATHS))\r
2435                         {\r
2436                                 LogChangedPathArray * cpatharray = m_logEntries[i]->pArChangedPaths;\r
2437 \r
2438                                 bool bGoing = true;\r
2439                                 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount() && bGoing; ++cpPathIndex)\r
2440                                 {\r
2441                                         LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);\r
2442                                         CString path = cpath->sCopyFromPath;\r
2443                                         path.MakeLower();\r
2444                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
2445                                         {\r
2446                                                 pShownlist->Add(m_logEntries[i]);\r
2447                                                 bGoing = false;\r
2448                                                 continue;\r
2449                                         }\r
2450                                         path = cpath->sPath;\r
2451                                         path.MakeLower();\r
2452                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
2453                                         {\r
2454                                                 pShownlist->Add(m_logEntries[i]);\r
2455                                                 bGoing = false;\r
2456                                                 continue;\r
2457                                         }\r
2458                                         path = cpath->GetAction();\r
2459                                         path.MakeLower();\r
2460                                         if ((path.Find(find)>=0)&&(IsEntryInDateRange(i)))\r
2461                                         {\r
2462                                                 pShownlist->Add(m_logEntries[i]);\r
2463                                                 bGoing = false;\r
2464                                                 continue;\r
2465                                         }\r
2466                                 }\r
2467                         }\r
2468 #endif\r
2469                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_AUTHORS))\r
2470                         {\r
2471                                 CString msg = m_logEntries.GetGitRevAt(i).m_AuthorName;\r
2472                                 msg = msg.MakeLower();\r
2473                                 if ((msg.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2474                                 {\r
2475                                         pShownlist->Add(&m_logEntries.GetGitRevAt(i));\r
2476                                         continue;\r
2477                                 }\r
2478                         }\r
2479                         if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS))\r
2480                         {\r
2481                                 sRev.Format(_T("%s"), m_logEntries.GetGitRevAt(i).m_CommitHash);\r
2482                                 if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i)))\r
2483                                 {\r
2484                                         pShownlist->Add(&m_logEntries.GetGitRevAt(i));\r
2485                                         continue;\r
2486                                 }\r
2487                         }\r
2488                 } // else (from if (bRegex))    \r
2489         } // for (DWORD i=0; i<m_logEntries.size(); ++i) \r
2490 \r
2491 }\r
2492 \r
2493 BOOL CGitLogListBase::IsEntryInDateRange(int i)\r
2494 {\r
2495         __time64_t time = m_logEntries.GetGitRevAt(i).m_AuthorDate.GetTime();\r
2496         if ((time >= m_From.GetTime())&&(time <= m_To.GetTime()))\r
2497                 return TRUE;\r
2498 \r
2499         return FALSE;\r
2500 \r
2501 //      return TRUE;\r
2502 }\r
2503 void CGitLogListBase::StartFilter()\r
2504 {\r
2505         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2506         RecalculateShownList(&m_arShownList);\r
2507         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2508 \r
2509 \r
2510         DeleteAllItems();\r
2511         SetItemCountEx(ShownCountWithStopped());\r
2512         RedrawItems(0, ShownCountWithStopped());\r
2513         SetRedraw(false);\r
2514         //ResizeAllListCtrlCols();\r
2515         SetRedraw(true);\r
2516         Invalidate();\r
2517 \r
2518 }\r
2519 void CGitLogListBase::RemoveFilter()\r
2520 {\r
2521 \r
2522         InterlockedExchange(&m_bNoDispUpdates, TRUE);\r
2523 \r
2524         m_arShownList.RemoveAll();\r
2525 \r
2526         // reset the time filter too\r
2527 #if 0\r
2528         m_timFrom = (__time64_t(m_tFrom));\r
2529         m_timTo = (__time64_t(m_tTo));\r
2530         m_DateFrom.SetTime(&m_timFrom);\r
2531         m_DateTo.SetTime(&m_timTo);\r
2532         m_DateFrom.SetRange(&m_timFrom, &m_timTo);\r
2533         m_DateTo.SetRange(&m_timFrom, &m_timTo);\r
2534 #endif\r
2535 \r
2536         for (DWORD i=0; i<m_logEntries.size(); ++i)\r
2537         {\r
2538                 if(this->m_IsOldFirst)\r
2539                 {\r
2540                         m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]);\r
2541                 }else\r
2542                 {\r
2543                         m_arShownList.Add(&m_logEntries[i]);\r
2544                 }\r
2545         }\r
2546 //      InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2547         DeleteAllItems();\r
2548         SetItemCountEx(ShownCountWithStopped());\r
2549         RedrawItems(0, ShownCountWithStopped());\r
2550 //      SetRedraw(false);\r
2551 //      ResizeAllListCtrlCols();\r
2552 //      SetRedraw(true);\r
2553 \r
2554         InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
2555 }\r
2556 \r
2557 void CGitLogListBase::Clear()\r
2558 {\r
2559         m_arShownList.RemoveAll();\r
2560         DeleteAllItems();\r
2561 \r
2562         m_logEntries.ClearAll();\r
2563 \r
2564 }\r
2565 \r
2566 void CGitLogListBase::OnDestroy()\r
2567 {\r
2568         // save the column widths to the registry\r
2569         SaveColumnWidths();\r
2570 \r
2571         if(this->m_bThreadRunning)\r
2572         {\r
2573                 this->m_bExitThread=true;\r
2574                 DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000);\r
2575                 if(ret == WAIT_TIMEOUT)\r
2576                         TerminateThread();\r
2577         }\r
2578         while(m_LogCache.SaveCache())\r
2579         {\r
2580                 if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"),\r
2581                                                         MB_YESNO) == IDNO)\r
2582                                                         break;\r
2583         }\r
2584         CHintListCtrl::OnDestroy();\r
2585 }\r
2586 \r
2587 LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam)\r
2588 {\r
2589         CRect rect;\r
2590         int i=(int)wParam;\r
2591         this->GetItemRect(i,&rect,LVIR_BOUNDS);\r
2592         this->InvalidateRect(rect);\r
2593 \r
2594         if(this->GetItemState(i,LVIF_STATE) & LVIS_SELECTED)\r
2595         {\r
2596                 int i=0;\r
2597         }\r
2598         return 0;\r
2599 }\r
2600 \r
2601 /**\r
2602  * Save column widths to the registry\r
2603  */\r
2604 void CGitLogListBase::SaveColumnWidths()\r
2605 {\r
2606         CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0));\r
2607         if (pHdrCtrl)\r
2608         {\r
2609                 int numcols = pHdrCtrl->GetItemCount();\r
2610                 for (int col = 0; col < numcols; col++)\r
2611                 {\r
2612                         int width = GetColumnWidth( col );\r
2613                         CString regentry;\r
2614                         regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col);\r
2615                         CRegDWORD regwidth(regentry, 0);\r
2616                         regwidth = width;       // this writes it to reg\r
2617                 }\r
2618         }\r
2619 }\r
2620 \r
2621 int CGitLogListBase::GetHeadIndex()\r
2622 {\r
2623         if(m_HeadHash.IsEmpty())\r
2624                 return -1;\r
2625 \r
2626         for(int i=0;i<m_arShownList.GetCount();i++)\r
2627         {\r
2628                 GitRev *pRev = (GitRev*)m_arShownList[i];\r
2629                 if(pRev)\r
2630                 {\r
2631                         if(pRev->m_CommitHash.ToString() == m_HeadHash )\r
2632                                 return i;\r
2633                 }\r
2634         }\r