OSDN Git Service

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