OSDN Git Service

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