OSDN Git Service

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