Support git Notes.
[TortoiseGit.git] / src / TortoiseProc / LogDlg.cpp
blob7019c29091c3718458f1a5a019efd3e571856321
1 // TortoiseGit - a Windows shell extension for easy version control
2 // Copyright (C) 2003-2008 - TortoiseGit
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License for more details.
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software Foundation,
14 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 #include "stdafx.h"
17 #include "TortoiseProc.h"
18 #include "cursor.h"
19 #include "InputDlg.h"
20 #include "PropDlg.h"
21 #include "SVNProgressDlg.h"
22 #include "ProgressDlg.h"
23 //#include "RepositoryBrowser.h"
24 //#include "CopyDlg.h"
25 #include "StatGraphDlg.h"
26 #include "Logdlg.h"
27 #include "MessageBox.h"
28 #include "Registry.h"
29 #include "AppUtils.h"
30 #include "PathUtils.h"
31 #include "StringUtils.h"
32 #include "UnicodeUtils.h"
33 #include "TempFile.h"
34 //#include "GitInfo.h"
35 //#include "GitDiff.h"
36 #include "IconMenu.h"
37 //#include "RevisionRangeDlg.h"
38 //#include "BrowseFolder.h"
39 //#include "BlameDlg.h"
40 //#include "Blame.h"
41 //#include "GitHelpers.h"
42 #include "GitStatus.h"
43 //#include "LogDlgHelper.h"
44 //#include "CachedLogInfo.h"
45 //#include "RepositoryInfo.h"
46 //#include "EditPropertiesDlg.h"
47 #include "FileDiffDlg.h"
48 #include "BrowseRefsDlg.h"
51 IMPLEMENT_DYNAMIC(CLogDlg, CResizableStandAloneDialog)
52 CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
53 : CResizableStandAloneDialog(CLogDlg::IDD, pParent)
54 , m_logcounter(0)
55 , m_wParam(0)
56 , m_currentChangedArray(NULL)
57 , m_nSortColumn(0)
58 , m_bShowedAll(false)
59 , m_bSelect(false)
61 , m_bSelectionMustBeContinuous(false)
62 , m_bShowBugtraqColumn(false)
63 , m_lowestRev(_T(""))
65 , m_sLogInfo(_T(""))
67 , m_bCancelled(FALSE)
68 , m_pNotifyWindow(NULL)
70 , m_bAscending(FALSE)
72 , m_limit(0)
73 , m_childCounter(0)
74 , m_maxChild(0)
75 , m_bIncludeMerges(FALSE)
76 , m_hAccel(NULL)
78 m_bFilterWithRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
80 CString str;
81 str=g_Git.m_CurrentDir;
82 str.Replace(_T(":"),_T("_"));
83 str=CString(_T("Software\\TortoiseGit\\LogDialog\\AllBranch\\"))+str;
85 m_regbAllBranch=CRegDWORD(str,FALSE);
87 m_bAllBranch=m_regbAllBranch;
89 m_bFirstParent=FALSE;
90 m_bWholeProject=FALSE;
93 CLogDlg::~CLogDlg()
96 m_regbAllBranch=m_bAllBranch;
98 m_CurrentFilteredChangedArray.RemoveAll();
102 void CLogDlg::DoDataExchange(CDataExchange* pDX)
104 CResizableStandAloneDialog::DoDataExchange(pDX);
105 DDX_Control(pDX, IDC_LOGLIST, m_LogList);
106 DDX_Control(pDX, IDC_LOGMSG, m_ChangedFileListCtrl);
107 DDX_Control(pDX, IDC_PROGRESS, m_LogProgress);
108 DDX_Control(pDX, IDC_SPLITTERTOP, m_wndSplitter1);
109 DDX_Control(pDX, IDC_SPLITTERBOTTOM, m_wndSplitter2);
110 DDX_Text(pDX, IDC_SEARCHEDIT, m_LogList.m_sFilterText);
111 DDX_Control(pDX, IDC_DATEFROM, m_DateFrom);
112 DDX_Control(pDX, IDC_DATETO, m_DateTo);
113 DDX_Control(pDX, IDC_HIDEPATHS, m_cHidePaths);
114 DDX_Text(pDX, IDC_LOGINFO, m_sLogInfo);
115 DDX_Check(pDX, IDC_LOG_FIRSTPARENT, m_bFirstParent);
116 DDX_Check(pDX, IDC_LOG_ALLBRANCH,m_bAllBranch);
117 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT,m_bWholeProject);
118 DDX_Control(pDX, IDC_SEARCHEDIT, m_cFilter);
119 DDX_Control(pDX, IDC_STATIC_REF, m_staticRef);
122 BEGIN_MESSAGE_MAP(CLogDlg, CResizableStandAloneDialog)
123 //ON_BN_CLICKED(IDC_GETALL, OnBnClickedGetall)
124 //ON_NOTIFY(NM_DBLCLK, IDC_LOGMSG, OnNMDblclkChangedFileList)
125 ON_WM_CONTEXTMENU()
126 ON_WM_SETCURSOR()
127 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
128 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LOGLIST, OnLvnItemchangedLoglist)
129 ON_NOTIFY(EN_LINK, IDC_MSGVIEW, OnEnLinkMsgview)
130 ON_BN_CLICKED(IDC_STATBUTTON, OnBnClickedStatbutton)
133 ON_MESSAGE(WM_FILTEREDIT_INFOCLICKED, OnClickedInfoIcon)
134 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED, OnClickedCancelFilter)
136 ON_MESSAGE(MSG_LOAD_PERCENTAGE,OnLogListLoading)
138 ON_EN_CHANGE(IDC_SEARCHEDIT, OnEnChangeSearchedit)
139 ON_WM_TIMER()
140 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETO, OnDtnDatetimechangeDateto)
141 ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATEFROM, OnDtnDatetimechangeDatefrom)
142 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickShowWholeProject)
143 //ON_NOTIFY(NM_CUSTOMDRAW, IDC_LOGMSG, OnNMCustomdrawChangedFileList)
144 //ON_NOTIFY(LVN_GETDISPINFO, IDC_LOGMSG, OnLvnGetdispinfoChangedFileList)
145 ON_NOTIFY(LVN_COLUMNCLICK,IDC_LOGLIST , OnLvnColumnclick)
146 //ON_NOTIFY(LVN_COLUMNCLICK, IDC_LOGMSG, OnLvnColumnclickChangedFileList)
147 ON_BN_CLICKED(IDC_HIDEPATHS, OnBnClickedHidepaths)
148 ON_BN_CLICKED(IDC_LOG_ALLBRANCH,OnBnClickedAllBranch)
150 ON_NOTIFY(DTN_DROPDOWN, IDC_DATEFROM, &CLogDlg::OnDtnDropdownDatefrom)
151 ON_NOTIFY(DTN_DROPDOWN, IDC_DATETO, &CLogDlg::OnDtnDropdownDateto)
152 ON_WM_SIZE()
153 ON_BN_CLICKED(IDC_LOG_FIRSTPARENT, &CLogDlg::OnBnClickedFirstParent)
154 ON_BN_CLICKED(IDC_REFRESH, &CLogDlg::OnBnClickedRefresh)
155 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CLogDlg::OnBnClickedBrowseRef)
156 ON_STN_CLICKED(IDC_STATIC_REF, &CLogDlg::OnBnClickedBrowseRef)
157 ON_COMMAND(ID_LOGDLG_REFRESH,&CLogDlg::OnRefresh)
158 ON_COMMAND(ID_LOGDLG_FIND,&CLogDlg::OnFind)
159 ON_COMMAND(ID_LOGDLG_FOCUSFILTER,&CLogDlg::OnFocusFilter)
160 ON_COMMAND(ID_EDIT_COPY, &CLogDlg::OnEditCopy)
161 END_MESSAGE_MAP()
163 void CLogDlg::SetParams(const CTGitPath& path, CString pegrev, CString startrev, CString endrev, int limit /* = FALSE */)
165 m_path = path;
166 m_pegrev = pegrev;
167 this->m_LogList.m_startrev = startrev;
168 m_LogRevision = startrev;
169 this->m_LogList.m_endrev = endrev;
170 m_hasWC = !path.IsUrl();
171 m_limit = limit;
172 if (::IsWindow(m_hWnd))
173 UpdateData(FALSE);
176 BOOL CLogDlg::OnInitDialog()
178 CString temp;
179 CResizableStandAloneDialog::OnInitDialog();
181 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_LOGDLG));
184 // use the state of the "stop on copy/rename" option from the last time
185 UpdateData(FALSE);
187 // set the font to use in the log message view, configured in the settings dialog
188 CAppUtils::CreateFontForLogs(m_logFont);
189 GetDlgItem(IDC_MSGVIEW)->SetFont(&m_logFont);
190 // automatically detect URLs in the log message and turn them into links
191 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_AUTOURLDETECT, TRUE, NULL);
192 // make the log message rich edit control send a message when the mouse pointer is over a link
193 GetDlgItem(IDC_MSGVIEW)->SendMessage(EM_SETEVENTMASK, NULL, ENM_LINK);
194 //m_LogList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_SUBITEMIMAGES);
196 // the "hide unrelated paths" checkbox should be indeterminate
197 m_cHidePaths.SetCheck(BST_INDETERMINATE);
200 // if there is a working copy, load the project properties
201 // to get information about the bugtraq: integration
202 if (m_hasWC)
203 m_ProjectProperties.ReadProps(m_path);
205 // the bugtraq issue id column is only shown if the bugtraq:url or bugtraq:regex is set
206 if ((!m_ProjectProperties.sUrl.IsEmpty())||(!m_ProjectProperties.sCheckRe.IsEmpty()))
207 m_bShowBugtraqColumn = true;
209 //theme.SetWindowTheme(m_LogList.GetSafeHwnd(), L"Explorer", NULL);
210 //theme.SetWindowTheme(m_ChangedFileListCtrl.GetSafeHwnd(), L"Explorer", NULL);
212 // set up the columns
213 m_LogList.DeleteAllItems();
214 m_LogList.InsertGitColumn();
216 m_ChangedFileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("LogDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT)),false);
218 GetDlgItem(IDC_LOGLIST)->UpdateData(FALSE);
220 m_logcounter = 0;
221 m_sMessageBuf.Preallocate(100000);
223 // set the dialog title to "Log - path/to/whatever/we/show/the/log/for"
224 SetDlgTitle(false);
226 m_tooltips.Create(this);
227 CheckRegexpTooltip();
229 SetSplitterRange();
231 // the filter control has a 'cancel' button (the red 'X'), we need to load its bitmap
232 m_cFilter.SetCancelBitmaps(IDI_CANCELNORMAL, IDI_CANCELPRESSED);
233 m_cFilter.SetInfoIcon(IDI_LOGFILTER);
234 m_cFilter.SetValidator(this);
236 AdjustControlSize(IDC_HIDEPATHS);
237 AdjustControlSize(IDC_LOG_FIRSTPARENT);
238 AdjustControlSize(IDC_LOG_ALLBRANCH);
240 GetClientRect(m_DlgOrigRect);
241 m_LogList.GetClientRect(m_LogListOrigRect);
242 GetDlgItem(IDC_MSGVIEW)->GetClientRect(m_MsgViewOrigRect);
243 m_ChangedFileListCtrl.GetClientRect(m_ChgOrigRect);
245 m_DateFrom.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
246 m_DateTo.SendMessage(DTM_SETMCSTYLE, 0, MCS_WEEKNUMBERS|MCS_NOTODAY|MCS_NOTRAILINGDATES|MCS_NOSELCHANGEONNAV);
248 m_staticRef.SetURL(CString());
250 // resizable stuff
251 AddAnchor(IDC_STATIC_REF, TOP_LEFT);
252 //AddAnchor(IDC_BUTTON_BROWSE_REF, TOP_LEFT);
253 AddAnchor(IDC_FROMLABEL, TOP_LEFT);
254 AddAnchor(IDC_DATEFROM, TOP_LEFT);
255 AddAnchor(IDC_TOLABEL, TOP_LEFT);
256 AddAnchor(IDC_DATETO, TOP_LEFT);
258 SetFilterCueText();
259 AddAnchor(IDC_SEARCHEDIT, TOP_LEFT, TOP_RIGHT);
261 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
262 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
263 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
264 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
265 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
267 AddAnchor(IDC_LOGINFO, BOTTOM_LEFT, BOTTOM_RIGHT);
268 AddAnchor(IDC_HIDEPATHS, BOTTOM_LEFT);
269 AddAnchor(IDC_LOG_ALLBRANCH,BOTTOM_LEFT);
270 AddAnchor(IDC_LOG_FIRSTPARENT, BOTTOM_LEFT);
271 //AddAnchor(IDC_GETALL, BOTTOM_LEFT);
272 AddAnchor(IDC_SHOWWHOLEPROJECT, BOTTOM_LEFT);
273 AddAnchor(IDC_REFRESH, BOTTOM_LEFT);
274 AddAnchor(IDC_STATBUTTON, BOTTOM_RIGHT);
275 AddAnchor(IDC_PROGRESS, BOTTOM_LEFT, BOTTOM_RIGHT);
276 AddAnchor(IDOK, BOTTOM_RIGHT);
277 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
278 AddAnchor(IDHELP, BOTTOM_RIGHT);
280 if(this->m_bAllBranch)
281 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
282 else
283 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
285 // SetPromptParentWindow(m_hWnd);
287 if (hWndExplorer)
288 CenterWindow(CWnd::FromHandle(hWndExplorer));
289 EnableSaveRestore(_T("LogDlg"));
291 DWORD yPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
292 DWORD yPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
293 RECT rcDlg, rcLogList, rcChgMsg;
294 GetClientRect(&rcDlg);
295 m_LogList.GetWindowRect(&rcLogList);
296 ScreenToClient(&rcLogList);
297 m_ChangedFileListCtrl.GetWindowRect(&rcChgMsg);
298 ScreenToClient(&rcChgMsg);
299 if (yPos1)
301 RECT rectSplitter;
302 m_wndSplitter1.GetWindowRect(&rectSplitter);
303 ScreenToClient(&rectSplitter);
304 int delta = yPos1 - rectSplitter.top;
306 if ((rcLogList.bottom + delta > rcLogList.top)&&(rcLogList.bottom + delta < rcChgMsg.bottom - 30))
308 m_wndSplitter1.SetWindowPos(NULL, 0, yPos1, 0, 0, SWP_NOSIZE);
309 DoSizeV1(delta);
312 if (yPos2)
314 RECT rectSplitter;
315 m_wndSplitter2.GetWindowRect(&rectSplitter);
316 ScreenToClient(&rectSplitter);
317 int delta = yPos2 - rectSplitter.top;
319 if ((rcChgMsg.top + delta < rcChgMsg.bottom)&&(rcChgMsg.top + delta > rcLogList.top + 30))
321 m_wndSplitter2.SetWindowPos(NULL, 0, yPos2, 0, 0, SWP_NOSIZE);
322 DoSizeV2(delta);
327 if (m_bSelect)
329 // the dialog is used to select revisions
330 // enable the OK button if appropriate
331 EnableOKButton();
333 else
335 // the dialog is used to just view log messages
336 // hide the OK button and set text on Cancel button to OK
337 GetDlgItemText(IDOK, temp);
338 SetDlgItemText(IDCANCEL, temp);
339 GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
342 m_mergedRevs.clear();
344 // first start a thread to obtain the log messages without
345 // blocking the dialog
346 //m_tTo = 0;
347 //m_tFrom = (DWORD)-1;
349 m_LogList.m_Path=m_path;
350 m_LogList.m_bShowWC = true;
351 m_LogList.FetchLogAsync(this);
353 GetDlgItem(IDC_LOGLIST)->SetFocus();
355 ShowStartRef();
356 return FALSE;
359 LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/)
361 int cur=(int)wParam;
363 if( cur == GITLOG_START )
365 CString temp;
366 temp.LoadString(IDS_PROGRESSWAIT);
368 this->m_LogList.ShowText(temp, true);
370 // We use a progress bar while getting the logs
371 m_LogProgress.SetRange32(0, 100);
372 m_LogProgress.SetPos(0);
374 GetDlgItem(IDC_PROGRESS)->ShowWindow(TRUE);
376 //DialogEnableWindow(IDC_GETALL, FALSE);
377 //DialogEnableWindow(IDC_SHOWWHOLEPROJECT, FALSE);
378 //DialogEnableWindow(IDC_LOG_FIRSTPARENT, FALSE);
379 DialogEnableWindow(IDC_STATBUTTON, FALSE);
380 //DialogEnableWindow(IDC_REFRESH, FALSE);
381 DialogEnableWindow(IDC_HIDEPATHS,FALSE);
383 DialogEnableWindow(IDC_DATEFROM,FALSE);
384 DialogEnableWindow(IDC_DATETO,FALSE);
386 DialogEnableWindow(IDC_SEARCHEDIT,FALSE);
388 }else if( cur == GITLOG_END)
391 if(this->m_LogList.HasText())
393 this->m_LogList.ClearText();
396 UpdateLogInfoLabel();
399 //if (!m_bShowedAll)
400 DialogEnableWindow(IDC_SHOWWHOLEPROJECT, TRUE);
402 //DialogEnableWindow(IDC_GETALL, TRUE);
403 DialogEnableWindow(IDC_LOG_FIRSTPARENT, TRUE);
404 DialogEnableWindow(IDC_STATBUTTON, TRUE);
405 DialogEnableWindow(IDC_REFRESH, TRUE);
406 DialogEnableWindow(IDC_HIDEPATHS,TRUE);
408 DialogEnableWindow(IDC_DATEFROM,TRUE);
409 DialogEnableWindow(IDC_DATETO,TRUE);
411 DialogEnableWindow(IDC_SEARCHEDIT,TRUE);
413 // PostMessage(WM_TIMER, LOGFILTER_TIMER);
414 GetDlgItem(IDC_PROGRESS)->ShowWindow(FALSE);
415 //CTime time=m_LogList.GetOldestTime();
416 CTime begin,end;
417 m_LogList.GetTimeRange(begin,end);
418 m_DateFrom.SetTime(&begin);
419 m_DateTo.SetTime(&end);
422 }else
424 if(this->m_LogList.HasText())
426 this->m_LogList.ClearText();
427 this->m_LogList.Invalidate();
429 UpdateLogInfoLabel();
430 m_LogProgress.SetPos(cur);
432 return 0;
434 void CLogDlg::SetDlgTitle(bool bOffline)
436 if (m_sTitle.IsEmpty())
437 GetWindowText(m_sTitle);
439 if (bOffline)
441 CString sTemp;
442 if (m_path.IsUrl())
443 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetUIPathString());
444 else if (m_path.IsDirectory())
445 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetWinPathString());
446 else
447 sTemp.Format(IDS_LOG_DLGTITLEOFFLINE, (LPCTSTR)m_sTitle, (LPCTSTR)m_path.GetFilename());
448 SetWindowText(sTemp);
450 else
452 if (m_path.IsUrl())
453 SetWindowText(m_sTitle + _T(" - ") + m_path.GetUIPathString());
454 else if (m_path.IsEmpty())
455 SetWindowText(m_sTitle + _T(" - ") + CString(_T("Whole Project")));
456 else if (m_path.IsDirectory())
457 SetWindowText(m_sTitle + _T(" - ") + m_path.GetWinPathString());
458 else
459 SetWindowText(m_sTitle + _T(" - ") + m_path.GetFilename());
463 void CLogDlg::CheckRegexpTooltip()
465 CWnd *pWnd = GetDlgItem(IDC_SEARCHEDIT);
466 // Since tooltip describes regexp features, show it only if regexps are enabled.
467 if (m_bFilterWithRegex)
469 m_tooltips.AddTool(pWnd, IDS_LOG_FILTER_REGEX_TT);
471 else
472 m_tooltips.DelTool(pWnd);
475 void CLogDlg::EnableOKButton()
477 if (m_bSelect)
479 // the dialog is used to select revisions
480 if (m_bSelectionMustBeSingle)
482 // enable OK button if only a single revision is selected
483 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()==1));
485 else if (m_bSelectionMustBeContinuous)
486 DialogEnableWindow(IDOK, (m_LogList.GetSelectedCount()!=0)&&(m_LogList.IsSelectionContinuous()));
487 else
488 DialogEnableWindow(IDOK, m_LogList.GetSelectedCount()!=0);
490 else
491 DialogEnableWindow(IDOK, TRUE);
494 CString CLogDlg::GetTagInfo(GitRev* pLogEntry)
496 CString cmd;
497 CString output;
499 if(m_LogList.m_HashMap.find(pLogEntry->m_CommitHash) != m_LogList.m_HashMap.end())
501 STRING_VECTOR &vector = m_LogList.m_HashMap[pLogEntry->m_CommitHash];
502 for(int i=0;i<vector.size();i++)
504 if(vector[i].Find(_T("refs/tags/")) == 0 )
506 CString tag= vector[i];
507 int start = vector[i].Find(_T("^{}"));
508 if(start>0)
509 tag=tag.Left(start);
510 else
511 continue;
513 cmd.Format(_T("git.exe cat-file tag %s"), tag);
515 if(g_Git.Run(cmd, &output, CP_UTF8) == 0 )
516 output+=_T("\n");
521 if(!output.IsEmpty())
523 output = _T("\n*Tag Info*\n\n") + output;
526 return output;
529 void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/)
531 // we fill here the log message rich edit control,
532 // and also populate the changed files list control
533 // according to the selected revision(s).
535 CRichEditCtrl * pMsgView = (CRichEditCtrl*)GetDlgItem(IDC_MSGVIEW);
536 // empty the log message view
537 pMsgView->SetWindowText(_T(" "));
538 // empty the changed files list
539 m_ChangedFileListCtrl.SetRedraw(FALSE);
540 // InterlockedExchange(&m_bNoDispUpdates, TRUE);
541 m_currentChangedArray = NULL;
542 //m_ChangedFileListCtrl.SetExtendedStyle ( LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER );
543 m_ChangedFileListCtrl.DeleteAllItems();
545 // if we're not here to really show a selected revision, just
546 // get out of here after clearing the views, which is what is intended
547 // if that flag is not set.
548 if (!bShow)
550 // force a redraw
551 m_ChangedFileListCtrl.Invalidate();
552 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
553 m_ChangedFileListCtrl.SetRedraw(TRUE);
554 return;
557 // depending on how many revisions are selected, we have to do different
558 // tasks.
559 int selCount = m_LogList.GetSelectedCount();
560 if (selCount == 0)
562 // if nothing is selected, we have nothing more to do
563 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
564 m_ChangedFileListCtrl.SetRedraw(TRUE);
565 return;
567 else if (selCount == 1)
569 // if one revision is selected, we have to fill the log message view
570 // with the corresponding log message, and also fill the changed files
571 // list fully.
572 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
573 int selIndex = m_LogList.GetNextSelectedItem(pos);
574 if (selIndex >= m_LogList.m_arShownList.GetCount())
576 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
577 m_ChangedFileListCtrl.SetRedraw(TRUE);
578 return;
580 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));
582 if(!pLogEntry->m_IsFull)
584 pMsgView->SetWindowText(_T("load ..."));
585 }else
587 // set the log message text
588 pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash.ToString()+_T("\r\n\r\n"));
589 // turn bug ID's into links if the bugtraq: properties have been set
590 // and we can find a match of those in the log message
592 pMsgView->SetSel(-1,-1);
593 CHARFORMAT2 format;
594 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
595 format.cbSize = sizeof(CHARFORMAT2);
596 format.dwMask = CFM_BOLD;
597 format.dwEffects = CFE_BOLD;
598 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
600 CString msg=_T("* ");
601 msg+=pLogEntry->m_Subject;
602 pMsgView->ReplaceSel(msg);
604 pMsgView->SetSel(-1,-1);
605 format.dwEffects = 0;
606 pMsgView->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
608 msg=_T("\n\n");
609 msg+=pLogEntry->m_Body;
611 if(!pLogEntry->m_Notes.IsEmpty())
613 msg+= _T("\n*Notes* ");
614 msg+= pLogEntry->m_Notes;
615 msg+= _T("\n\n");
618 msg+=GetTagInfo(pLogEntry);
620 pMsgView->ReplaceSel(msg);
622 CString text;
623 pMsgView->GetWindowText(text);
624 // the rich edit control doesn't count the CR char!
625 // to be exact: CRLF is treated as one char.
626 text.Replace(_T("\r"), _T(""));
628 m_ProjectProperties.FindBugID(text, pMsgView);
629 CAppUtils::FormatTextInRichEditControl(pMsgView);
631 int HidePaths=m_cHidePaths.GetState() & 0x0003;
632 CString matchpath=this->m_path.GetGitPathString();
634 for(int i=0;i<pLogEntry->m_Files.GetCount() && (!matchpath.IsEmpty());i++)
636 if( m_bWholeProject )
637 break;
639 ((CTGitPath&)pLogEntry->m_Files[i]).m_Action &= ~(CTGitPath::LOGACTIONS_HIDE|CTGitPath::LOGACTIONS_GRAY);
641 if(pLogEntry->m_Files[i].GetGitPathString().Left(matchpath.GetLength()) != matchpath)
643 if(HidePaths==BST_CHECKED)
644 ((CTGitPath&)pLogEntry->m_Files[i]).m_Action |= CTGitPath::LOGACTIONS_HIDE;
645 if(HidePaths==BST_INDETERMINATE)
646 ((CTGitPath&)pLogEntry->m_Files[i]).m_Action |= CTGitPath::LOGACTIONS_GRAY;
650 m_ChangedFileListCtrl.UpdateWithGitPathList(pLogEntry->m_Files);
651 m_ChangedFileListCtrl.m_CurrentVersion=pLogEntry->m_CommitHash;
652 m_ChangedFileListCtrl.Show(SVNSLC_SHOWVERSIONED);
654 m_ChangedFileListCtrl.SetRedraw(TRUE);
655 return;
659 else
661 // more than one revision is selected:
662 // the log message view must be emptied
663 // the changed files list contains all the changed paths from all
664 // selected revisions, with 'doubles' removed
665 m_currentChangedPathList = GetChangedPathsFromSelectedRevisions(true);
668 // redraw the views
669 // InterlockedExchange(&m_bNoDispUpdates, FALSE);
670 #if 0
671 if (m_currentChangedArray)
673 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedArray->GetCount());
674 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedArray->GetCount());
676 else if (m_currentChangedPathList.GetCount())
678 m_ChangedFileListCtrl.SetItemCountEx(m_currentChangedPathList.GetCount());
679 m_ChangedFileListCtrl.RedrawItems(0, m_currentChangedPathList.GetCount());
681 else
683 m_ChangedFileListCtrl.SetItemCountEx(0);
684 m_ChangedFileListCtrl.Invalidate();
686 #endif
687 // sort according to the settings
688 if (m_nSortColumnPathList > 0)
689 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
690 else
691 SetSortArrow(&m_ChangedFileListCtrl, -1, false);
692 m_ChangedFileListCtrl.SetRedraw(TRUE);
696 void CLogDlg::OnBnClickedRefresh()
699 Refresh (true);
702 void CLogDlg::Refresh (bool /*autoGoOnline*/)
704 m_limit = 0;
705 m_LogList.Refresh();
706 FillLogMessageCtrl(false);
711 BOOL CLogDlg::Cancel()
713 return m_bCancelled;
716 void CLogDlg::SaveSplitterPos()
718 if (!IsIconic())
720 CRegDWORD regPos1 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer1"));
721 CRegDWORD regPos2 = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\LogDlgSizer2"));
722 RECT rectSplitter;
723 m_wndSplitter1.GetWindowRect(&rectSplitter);
724 ScreenToClient(&rectSplitter);
725 regPos1 = rectSplitter.top;
726 m_wndSplitter2.GetWindowRect(&rectSplitter);
727 ScreenToClient(&rectSplitter);
728 regPos2 = rectSplitter.top;
732 void CLogDlg::OnCancel()
734 // canceling means stopping the working thread if it's still running.
735 if (this->IsThreadRunning())
737 m_LogList.SafeTerminateThread();
739 UpdateData();
741 SaveSplitterPos();
742 __super::OnCancel();
745 CString CLogDlg::MakeShortMessage(const CString& message)
747 bool bFoundShort = true;
748 CString sShortMessage = m_ProjectProperties.GetLogSummary(message);
749 if (sShortMessage.IsEmpty())
751 bFoundShort = false;
752 sShortMessage = message;
754 // Remove newlines and tabs 'cause those are not shown nicely in the list control
755 sShortMessage.Replace(_T("\r"), _T(""));
756 sShortMessage.Replace(_T("\t"), _T(" "));
758 // Suppose the first empty line separates 'summary' from the rest of the message.
759 int found = sShortMessage.Find(_T("\n\n"));
760 // To avoid too short 'short' messages
761 // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that")
762 // only use the empty newline as a separator if it comes after at least 15 chars.
763 if ((!bFoundShort)&&(found >= 15))
765 sShortMessage = sShortMessage.Left(found);
767 sShortMessage.Replace('\n', ' ');
768 return sShortMessage;
771 BOOL CLogDlg::Log(git_revnum_t /*rev*/, const CString& /*author*/, const CString& /*date*/, const CString& /*message*/, LogChangedPathArray * /*cpaths*/, int /*filechanges*/, BOOL /*copies*/, DWORD /*actions*/, BOOL /*haschildren*/)
773 #if 0
774 if (rev == SVN_INVALID_REVNUM)
776 m_childCounter--;
777 return TRUE;
780 // this is the callback function which receives the data for every revision we ask the log for
781 // we store this information here one by one.
782 m_logcounter += 1;
783 if (m_startrev == -1)
784 m_startrev = rev;
785 if (m_limit != 0)
787 m_limitcounter--;
788 m_LogProgress.SetPos(m_limit - m_limitcounter);
790 else if (m_startrev.IsNumber() && m_startrev.IsNumber())
791 m_LogProgress.SetPos((git_revnum_t)m_startrev-rev+(git_revnum_t)m_endrev);
792 __time64_t ttime = time/1000000L;
793 if (m_tTo < (DWORD)ttime)
794 m_tTo = (DWORD)ttime;
795 if (m_tFrom > (DWORD)ttime)
796 m_tFrom = (DWORD)ttime;
797 if ((m_lowestRev > rev)||(m_lowestRev < 0))
798 m_lowestRev = rev;
799 // Add as many characters from the log message to the list control
800 PLOGENTRYDATA pLogItem = new LOGENTRYDATA;
801 pLogItem->bCopies = !!copies;
803 // find out if this item was copied in the revision
804 BOOL copiedself = FALSE;
805 if (copies)
807 for (INT_PTR cpPathIndex = 0; cpPathIndex < cpaths->GetCount(); ++cpPathIndex)
809 LogChangedPath * cpath = cpaths->GetAt(cpPathIndex);
810 if (!cpath->sCopyFromPath.IsEmpty() && (cpath->sPath.Compare(m_sSelfRelativeURL) == 0))
812 // note: this only works if the log is fetched top-to-bottom
813 // but since we do that, it shouldn't be a problem
814 m_sSelfRelativeURL = cpath->sCopyFromPath;
815 copiedself = TRUE;
816 break;
820 pLogItem->bCopiedSelf = copiedself;
821 pLogItem->tmDate = ttime;
822 pLogItem->sAuthor = author;
823 pLogItem->sDate = date;
824 pLogItem->sShortMessage = MakeShortMessage(message);
825 pLogItem->dwFileChanges = filechanges;
826 pLogItem->actions = actions;
827 pLogItem->haschildren = haschildren;
828 pLogItem->childStackDepth = m_childCounter;
829 m_maxChild = max(m_childCounter, m_maxChild);
830 if (haschildren)
831 m_childCounter++;
832 pLogItem->sBugIDs = m_ProjectProperties.FindBugID(message).Trim();
834 // split multi line log entries and concatenate them
835 // again but this time with \r\n as line separators
836 // so that the edit control recognizes them
839 if (message.GetLength()>0)
841 m_sMessageBuf = message;
842 m_sMessageBuf.Replace(_T("\n\r"), _T("\n"));
843 m_sMessageBuf.Replace(_T("\r\n"), _T("\n"));
844 if (m_sMessageBuf.Right(1).Compare(_T("\n"))==0)
845 m_sMessageBuf = m_sMessageBuf.Left(m_sMessageBuf.GetLength()-1);
847 else
848 m_sMessageBuf.Empty();
849 pLogItem->sMessage = m_sMessageBuf;
850 pLogItem->Rev = rev;
852 // move-construct path array
854 pLogItem->pArChangedPaths = new LogChangedPathArray (*cpaths);
855 cpaths->RemoveAll();
857 catch (CException * e)
859 ::MessageBox(NULL, _T("not enough memory!"), _T("TortoiseGit"), MB_ICONERROR);
860 e->Delete();
861 m_bCancelled = TRUE;
863 m_logEntries.push_back(pLogItem);
864 m_arShownList.Add(pLogItem);
865 #endif
866 return TRUE;
869 GitRev g_rev;
870 //this is the thread function which calls the subversion function
875 void CLogDlg::CopyChangedSelectionToClipBoard()
878 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
879 if (pos == NULL)
880 return; // nothing is selected, get out of here
882 CString sPaths;
884 // CGitRev* pLogEntry = reinterpret_cast<CGitRev* >(m_LogList.m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
885 // if (pos)
887 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
888 while (pos)
890 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
891 CTGitPath *path = (CTGitPath*)m_ChangedFileListCtrl.GetItemData(nItem);
892 if(path)
893 sPaths += path->GetGitPathString();
894 sPaths += _T("\r\n");
897 #if 0
898 else
900 // only one revision is selected in the log dialog top pane
901 // but multiple items could be selected in the changed items list
902 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
903 while (pos)
905 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
906 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);
908 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
910 // some items are hidden! So find out which item the user really selected
911 INT_PTR selRealIndex = -1;
912 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
914 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
915 selRealIndex++;
916 if (selRealIndex == nItem)
918 changedlogpath = pLogEntry->pArChangedPaths->GetAt(hiddenindex);
919 break;
923 if (changedlogpath)
925 sPaths += changedlogpath->sPath;
926 sPaths += _T("\r\n");
930 #endif
931 sPaths.Trim();
932 CStringUtils::WriteAsciiStringToClipboard(sPaths, GetSafeHwnd());
936 BOOL CLogDlg::IsDiffPossible(LogChangedPath * /*changedpath*/, git_revnum_t rev)
938 #if 0
939 CString added, deleted;
940 if (changedpath == NULL)
941 return false;
943 if ((rev > 1)&&(changedpath->action != LOGACTIONS_DELETED))
945 if (changedpath->action == LOGACTIONS_ADDED) // file is added
947 if (changedpath->lCopyFromRev == 0)
948 return FALSE; // but file was not added with history
950 return TRUE;
952 #endif
953 return FALSE;
956 void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point)
958 // we have two separate context menus:
959 // one shown on the log message list control,
960 // the other shown in the changed-files list control
961 int selCount = m_LogList.GetSelectedCount();
962 if (pWnd == &m_LogList)
964 //ShowContextMenuForRevisions(pWnd, point);
966 else if (pWnd == &m_ChangedFileListCtrl)
968 //ShowContextMenuForChangedpaths(pWnd, point);
970 else if ((selCount == 1)&&(pWnd == GetDlgItem(IDC_MSGVIEW)))
972 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
973 int selIndex = -1;
974 if (pos)
975 selIndex = m_LogList.GetNextSelectedItem(pos);
977 GitRev *pRev = ((GitRev*)m_LogList.m_arShownList[selIndex]);
979 if ((point.x == -1) && (point.y == -1))
981 CRect rect;
982 GetDlgItem(IDC_MSGVIEW)->GetClientRect(&rect);
983 ClientToScreen(&rect);
984 point = rect.CenterPoint();
986 CString sMenuItemText;
987 CIconMenu popup;
988 if (popup.CreatePopupMenu())
990 // add the 'default' entries
991 sMenuItemText.LoadString(IDS_SCIEDIT_COPY);
992 popup.AppendMenu(MF_STRING | MF_ENABLED, WM_COPY, sMenuItemText);
993 sMenuItemText.LoadString(IDS_SCIEDIT_SELECTALL);
994 popup.AppendMenu(MF_STRING | MF_ENABLED, EM_SETSEL, sMenuItemText);
995 sMenuItemText.LoadString(IDS_EDIT_NOTES);
996 popup.AppendMenuIcon( CGitLogList::ID_EDITNOTE, sMenuItemText, IDI_EDIT);
998 //if (selIndex >= 0)
1000 // popup.AppendMenu(MF_SEPARATOR);
1001 // sMenuItemText.LoadString(IDS_LOG_POPUP_EDITLOG);
1002 // popup.AppendMenu(MF_STRING | MF_ENABLED, CGitLogList::ID_EDITAUTHOR, sMenuItemText);
1005 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1006 switch (cmd)
1008 case 0:
1009 break; // no command selected
1010 case EM_SETSEL:
1011 case WM_COPY:
1012 ::SendMessage(GetDlgItem(IDC_MSGVIEW)->GetSafeHwnd(), cmd, 0, -1);
1013 break;
1014 case CGitLogList::ID_EDITNOTE:
1015 CAppUtils::EditNote(pRev);
1016 this->FillLogMessageCtrl(true);
1017 break;
1026 void CLogDlg::OnOK()
1028 // since the log dialog is also used to select revisions for other
1029 // dialogs, we have to do some work before closing this dialog
1030 if (GetFocus() != GetDlgItem(IDOK))
1031 return; // if the "OK" button doesn't have the focus, do nothing: this prevents closing the dialog when pressing enter
1034 if (this->IsThreadRunning())
1036 m_LogList.SafeTerminateThread();
1038 UpdateData();
1039 // check that one and only one row is selected
1040 if (m_LogList.GetSelectedCount() == 1)
1042 // get the selected row
1043 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1044 int selIndex = m_LogList.GetNextSelectedItem(pos);
1045 if (selIndex < m_LogList.m_arShownList.GetCount())
1047 // all ok, pick up the revision
1048 GitRev* pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(selIndex));
1049 // extract the hash
1050 m_sSelectedHash = pLogEntry->m_CommitHash;
1053 UpdateData(FALSE);
1054 SaveSplitterPos();
1055 __super::OnOK();
1057 #if 0
1058 if (!GetDlgItem(IDOK)->IsWindowVisible() && GetFocus() != GetDlgItem(IDCANCEL))
1059 return; // the Cancel button works as the OK button. But if the cancel button has not the focus, do nothing.
1061 CString temp;
1062 CString buttontext;
1063 GetDlgItemText(IDOK, buttontext);
1064 temp.LoadString(IDS_MSGBOX_CANCEL);
1065 if (temp.Compare(buttontext) != 0)
1066 __super::OnOK(); // only exit if the button text matches, and that will match only if the thread isn't running anymore
1067 m_bCancelled = TRUE;
1068 m_selectedRevs.Clear();
1069 m_selectedRevsOneRange.Clear();
1070 if (m_pNotifyWindow)
1072 int selIndex = m_LogList.GetSelectionMark();
1073 if (selIndex >= 0)
1075 PLOGENTRYDATA pLogEntry = NULL;
1076 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1077 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1078 m_selectedRevs.AddRevision(pLogEntry->Rev);
1079 git_revnum_t lowerRev = pLogEntry->Rev;
1080 git_revnum_t higherRev = lowerRev;
1081 while (pos)
1083 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1084 git_revnum_t rev = pLogEntry->Rev;
1085 m_selectedRevs.AddRevision(pLogEntry->Rev);
1086 if (lowerRev > rev)
1087 lowerRev = rev;
1088 if (higherRev < rev)
1089 higherRev = rev;
1091 if (m_sFilterText.IsEmpty() && m_nSortColumn == 0 && IsSelectionContinuous())
1093 m_selectedRevsOneRange.AddRevRange(lowerRev, higherRev);
1095 BOOL bSentMessage = FALSE;
1096 if (m_LogList.GetSelectedCount() == 1)
1098 // if only one revision is selected, check if the path/url with which the dialog was started
1099 // was directly affected in that revision. If it was, then check if our path was copied from somewhere.
1100 // if it was copied, use the copy from revision as lowerRev
1101 if ((pLogEntry)&&(pLogEntry->pArChangedPaths)&&(lowerRev == higherRev))
1103 CString sUrl = m_path.GetGitPathString();
1104 if (!m_path.IsUrl())
1106 sUrl = GetURLFromPath(m_path);
1108 sUrl = sUrl.Mid(m_sRepositoryRoot.GetLength());
1109 for (int cp = 0; cp < pLogEntry->pArChangedPaths->GetCount(); ++cp)
1111 LogChangedPath * pData = pLogEntry->pArChangedPaths->GetAt(cp);
1112 if (pData)
1114 if (sUrl.Compare(pData->sPath) == 0)
1116 if (!pData->sCopyFromPath.IsEmpty())
1118 lowerRev = pData->lCopyFromRev;
1119 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART), lowerRev);
1120 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND), higherRev);
1121 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1122 bSentMessage = TRUE;
1129 if ( !bSentMessage )
1131 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTSTART | MERGE_REVSELECTMINUSONE), lowerRev);
1132 m_pNotifyWindow->SendMessage(WM_REVSELECTED, m_wParam & (MERGE_REVSELECTEND | MERGE_REVSELECTMINUSONE), higherRev);
1133 m_pNotifyWindow->SendMessage(WM_REVLIST, m_selectedRevs.GetCount(), (LPARAM)&m_selectedRevs);
1134 if (m_selectedRevsOneRange.GetCount())
1135 m_pNotifyWindow->SendMessage(WM_REVLISTONERANGE, 0, (LPARAM)&m_selectedRevsOneRange);
1139 UpdateData();
1140 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\ShowAllEntry"));
1141 reg = m_btnShow.GetCurrentEntry();
1142 SaveSplitterPos();
1143 #endif
1146 void CLogDlg::OnNMDblclkChangedFileList(NMHDR * /*pNMHDR*/, LRESULT *pResult)
1148 // a double click on an entry in the changed-files list has happened
1149 *pResult = 0;
1151 DiffSelectedFile();
1154 void CLogDlg::DiffSelectedFile()
1156 #if 0
1157 if (m_bThreadRunning)
1158 return;
1159 UpdateLogInfoLabel();
1160 INT_PTR selIndex = m_ChangedFileListCtrl.GetSelectionMark();
1161 if (selIndex < 0)
1162 return;
1163 if (m_ChangedFileListCtrl.GetSelectedCount() == 0)
1164 return;
1165 // find out if there's an entry selected in the log list
1166 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
1167 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1168 git_revnum_t rev1 = pLogEntry->Rev;
1169 git_revnum_t rev2 = rev1;
1170 if (pos)
1172 while (pos)
1174 // there's at least a second entry selected in the log list: several revisions selected!
1175 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
1176 if (pLogEntry)
1178 rev1 = max(rev1,(long)pLogEntry->Rev);
1179 rev2 = min(rev2,(long)pLogEntry->Rev);
1182 rev2--;
1183 // now we have both revisions selected in the log list, so we can do a diff of the selected
1184 // entry in the changed files list with these two revisions.
1185 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1187 else
1189 rev2 = rev1-1;
1190 // nothing or only one revision selected in the log list
1191 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1193 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
1195 // some items are hidden! So find out which item the user really clicked on
1196 INT_PTR selRealIndex = -1;
1197 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
1199 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
1200 selRealIndex++;
1201 if (selRealIndex == selIndex)
1203 selIndex = hiddenindex;
1204 changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1205 break;
1210 if (IsDiffPossible(changedpath, rev1))
1212 // diffs with renamed files are possible
1213 if ((changedpath)&&(!changedpath->sCopyFromPath.IsEmpty()))
1214 rev2 = changedpath->lCopyFromRev;
1215 else
1217 // if the path was modified but the parent path was 'added with history'
1218 // then we have to use the copy from revision of the parent path
1219 CTGitPath cpath = CTGitPath(changedpath->sPath);
1220 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
1222 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);
1223 if (p.IsAncestorOf(cpath))
1225 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())
1226 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;
1230 DoDiffFromLog(selIndex, rev1, rev2, false, false);
1232 else
1234 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1235 CTGitPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(changedpath->sPath));
1236 GitRev r = rev1;
1237 // deleted files must be opened from the revision before the deletion
1238 if (changedpath->action == LOGACTIONS_DELETED)
1239 r = rev1-1;
1240 m_bCancelled = false;
1242 CProgressDlg progDlg;
1243 progDlg.SetTitle(IDS_APPNAME);
1244 progDlg.SetAnimation(IDR_DOWNLOAD);
1245 CString sInfoLine;
1246 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)(m_sRepositoryRoot + changedpath->sPath), (LPCTSTR)r.ToString());
1247 progDlg.SetLine(1, sInfoLine, true);
1248 SetAndClearProgressInfo(&progDlg);
1249 progDlg.ShowModeless(m_hWnd);
1251 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), r, r, tempfile))
1253 m_bCancelled = false;
1254 if (!Cat(CTGitPath(m_sRepositoryRoot + changedpath->sPath), GitRev::REV_HEAD, r, tempfile))
1256 progDlg.Stop();
1257 SetAndClearProgressInfo((HWND)NULL);
1258 CMessageBox::Show(m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1259 return;
1262 progDlg.Stop();
1263 SetAndClearProgressInfo((HWND)NULL);
1265 CString sName1, sName2;
1266 sName1.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1);
1267 sName2.Format(_T("%s - Revision %ld"), (LPCTSTR)CPathUtils::GetFileNameFromPath(changedpath->sPath), (git_revnum_t)rev1-1);
1268 CAppUtils::DiffFlags flags;
1269 flags.AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1270 if (changedpath->action == LOGACTIONS_DELETED)
1271 CAppUtils::StartExtDiff(tempfile, tempfile2, sName2, sName1, flags);
1272 else
1273 CAppUtils::StartExtDiff(tempfile2, tempfile, sName2, sName1, flags);
1276 #endif
1280 void CLogDlg::DoDiffFromLog(INT_PTR selIndex, GitRev* rev1, GitRev* rev2, bool blame, bool unified)
1282 DialogEnableWindow(IDOK, FALSE);
1283 // SetPromptApp(&theApp);
1284 theApp.DoWaitCursor(1);
1286 CString temppath;
1287 GetTempPath(temppath);
1289 CString file1;
1290 file1.Format(_T("%s%s_%s%s"),
1291 temppath,
1292 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1293 rev1->m_CommitHash.ToString().Left(6),
1294 (*m_currentChangedArray)[selIndex].GetFileExtension());
1296 CString file2;
1297 file2.Format(_T("%s\\%s_%s%s"),
1298 temppath,
1299 (*m_currentChangedArray)[selIndex].GetBaseFilename(),
1300 rev2->m_CommitHash.ToString().Left(6),
1301 (*m_currentChangedArray)[selIndex].GetFileExtension());
1303 CString cmd;
1305 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev1->m_CommitHash.ToString(),(*m_currentChangedArray)[selIndex].GetGitPathString());
1306 g_Git.RunLogFile(cmd,file1);
1307 cmd.Format(_T("git.exe cat-file -p %s:%s"),rev2->m_CommitHash.ToString(),(*m_currentChangedArray)[selIndex].GetGitPathString());
1308 g_Git.RunLogFile(cmd,file2);
1310 CAppUtils::DiffFlags flags;
1311 CAppUtils::StartExtDiff(file1,file2,_T("A"),_T("B"),flags);
1313 #if 0
1314 //get the filename
1315 CString filepath;
1316 if (Git::PathIsURL(m_path))
1318 filepath = m_path.GetGitPathString();
1320 else
1322 filepath = GetURLFromPath(m_path);
1323 if (filepath.IsEmpty())
1325 theApp.DoWaitCursor(-1);
1326 CString temp;
1327 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1328 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1329 TRACE(_T("could not retrieve the URL of the file!\n"));
1330 EnableOKButton();
1331 theApp.DoWaitCursor(-11);
1332 return; //exit
1335 m_bCancelled = FALSE;
1336 filepath = GetRepositoryRoot(CTGitPath(filepath));
1338 CString firstfile, secondfile;
1339 if (m_LogList.GetSelectedCount()==1)
1341 int s = m_LogList.GetSelectionMark();
1342 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(s));
1343 LogChangedPath * changedpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
1344 firstfile = changedpath->sPath;
1345 secondfile = firstfile;
1346 if ((rev2 == rev1-1)&&(changedpath->lCopyFromRev > 0)) // is it an added file with history?
1348 secondfile = changedpath->sCopyFromPath;
1349 rev2 = changedpath->lCopyFromRev;
1352 else
1354 firstfile = m_currentChangedPathList[selIndex].GetGitPathString();
1355 secondfile = firstfile;
1358 firstfile = filepath + firstfile.Trim();
1359 secondfile = filepath + secondfile.Trim();
1361 GitDiff diff(this, this->m_hWnd, true);
1362 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1363 diff.SetHEADPeg(m_LogRevision);
1364 if (unified)
1366 if (PromptShown())
1367 diff.ShowUnifiedDiff(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1);
1368 else
1369 CAppUtils::StartShowUnifiedDiff(m_hWnd, CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), m_LogRevision);
1371 else
1373 if (diff.ShowCompare(CTGitPath(secondfile), rev2, CTGitPath(firstfile), rev1, GitRev(), false, blame))
1375 if (firstfile.Compare(secondfile)==0)
1377 git_revnum_t baseRev = 0;
1378 diff.DiffProps(CTGitPath(firstfile), rev2, rev1, baseRev);
1383 #endif
1385 theApp.DoWaitCursor(-1);
1386 EnableOKButton();
1389 BOOL CLogDlg::Open(bool /*bOpenWith*/,CString changedpath, git_revnum_t rev)
1391 #if 0
1392 DialogEnableWindow(IDOK, FALSE);
1393 SetPromptApp(&theApp);
1394 theApp.DoWaitCursor(1);
1395 CString filepath;
1396 if (Git::PathIsURL(m_path))
1398 filepath = m_path.GetGitPathString();
1400 else
1402 filepath = GetURLFromPath(m_path);
1403 if (filepath.IsEmpty())
1405 theApp.DoWaitCursor(-1);
1406 CString temp;
1407 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
1408 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
1409 TRACE(_T("could not retrieve the URL of the file!\n"));
1410 EnableOKButton();
1411 return FALSE;
1414 m_bCancelled = false;
1415 filepath = GetRepositoryRoot(CTGitPath(filepath));
1416 filepath += changedpath;
1418 CProgressDlg progDlg;
1419 progDlg.SetTitle(IDS_APPNAME);
1420 progDlg.SetAnimation(IDR_DOWNLOAD);
1421 CString sInfoLine;
1422 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)GitRev(rev).ToString());
1423 progDlg.SetLine(1, sInfoLine, true);
1424 SetAndClearProgressInfo(&progDlg);
1425 progDlg.ShowModeless(m_hWnd);
1427 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, CTGitPath(filepath), rev);
1428 m_bCancelled = false;
1429 if (!Cat(CTGitPath(filepath), GitRev(rev), rev, tempfile))
1431 progDlg.Stop();
1432 SetAndClearProgressInfo((HWND)NULL);
1433 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1434 EnableOKButton();
1435 theApp.DoWaitCursor(-1);
1436 return FALSE;
1438 progDlg.Stop();
1439 SetAndClearProgressInfo((HWND)NULL);
1440 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1441 if (!bOpenWith)
1443 int ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1444 if (ret <= HINSTANCE_ERROR)
1445 bOpenWith = true;
1447 if (bOpenWith)
1449 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1450 cmd += tempfile.GetWinPathString() + _T(" ");
1451 CAppUtils::LaunchApplication(cmd, NULL, false);
1453 EnableOKButton();
1454 theApp.DoWaitCursor(-1);
1455 #endif
1456 return TRUE;
1459 void CLogDlg::EditAuthor(const CLogDataVector& /*logs*/)
1461 #if 0
1462 CString url;
1463 CString name;
1464 if (logs.size() == 0)
1465 return;
1466 DialogEnableWindow(IDOK, FALSE);
1467 SetPromptApp(&theApp);
1468 theApp.DoWaitCursor(1);
1469 if (Git::PathIsURL(m_path))
1470 url = m_path.GetGitPathString();
1471 else
1473 url = GetURLFromPath(m_path);
1475 name = Git_PROP_REVISION_AUTHOR;
1477 CString value = RevPropertyGet(name, CTGitPath(url), logs[0]->Rev);
1478 CString sOldValue = value;
1479 value.Replace(_T("\n"), _T("\r\n"));
1480 CInputDlg dlg(this);
1481 dlg.m_sHintText.LoadString(IDS_LOG_AUTHOR);
1482 dlg.m_sInputText = value;
1483 dlg.m_sTitle.LoadString(IDS_LOG_AUTHOREDITTITLE);
1484 dlg.m_pProjectProperties = &m_ProjectProperties;
1485 dlg.m_bUseLogWidth = false;
1486 if (dlg.DoModal() == IDOK)
1488 dlg.m_sInputText.Replace(_T("\r"), _T(""));
1490 LogCache::CCachedLogInfo* toUpdate
1491 = GetLogCache (CTGitPath (m_sRepositoryRoot));
1493 CProgressDlg progDlg;
1494 progDlg.SetTitle(IDS_APPNAME);
1495 progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT)));
1496 progDlg.SetTime(true);
1497 progDlg.SetShowProgressBar(true);
1498 progDlg.ShowModeless(m_hWnd);
1499 for (DWORD i=0; i<logs.size(); ++i)
1501 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), logs[i]->Rev))
1503 progDlg.Stop();
1504 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1505 break;
1507 else
1510 logs[i]->sAuthor = dlg.m_sInputText;
1511 m_LogList.Invalidate();
1513 // update the log cache
1515 if (toUpdate != NULL)
1517 // log caching is active
1519 LogCache::CCachedLogInfo newInfo;
1520 newInfo.Insert ( logs[i]->Rev
1521 , (const char*) CUnicodeUtils::GetUTF8 (logs[i]->sAuthor)
1522 , ""
1524 , LogCache::CRevisionInfoContainer::HAS_AUTHOR);
1526 toUpdate->Update (newInfo);
1529 progDlg.SetProgress64(i, logs.size());
1531 progDlg.Stop();
1533 theApp.DoWaitCursor(-1);
1534 EnableOKButton();
1535 #endif
1538 void CLogDlg::EditLogMessage(int /*index*/)
1541 #if 0
1542 CString url;
1543 CString name;
1544 DialogEnableWindow(IDOK, FALSE);
1545 SetPromptApp(&theApp);
1546 theApp.DoWaitCursor(1);
1547 if (Git::PathIsURL(m_path))
1548 url = m_path.GetGitPathString();
1549 else
1551 url = GetURLFromPath(m_path);
1553 name = Git_PROP_REVISION_LOG;
1555 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(index));
1556 m_bCancelled = FALSE;
1557 CString value = RevPropertyGet(name, CTGitPath(url), pLogEntry->Rev);
1558 CString sOldValue = value;
1559 value.Replace(_T("\n"), _T("\r\n"));
1560 CInputDlg dlg(this);
1561 dlg.m_sHintText.LoadString(IDS_LOG_MESSAGE);
1562 dlg.m_sInputText = value;
1563 dlg.m_sTitle.LoadString(IDS_LOG_MESSAGEEDITTITLE);
1564 dlg.m_pProjectProperties = &m_ProjectProperties;
1565 dlg.m_bUseLogWidth = true;
1566 if (dlg.DoModal() == IDOK)
1568 dlg.m_sInputText.Replace(_T("\r"), _T(""));
1569 if (!RevPropertySet(name, dlg.m_sInputText, sOldValue, CTGitPath(url), pLogEntry->Rev))
1571 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1573 else
1575 pLogEntry->sShortMessage = MakeShortMessage(dlg.m_sInputText);
1576 // split multi line log entries and concatenate them
1577 // again but this time with \r\n as line separators
1578 // so that the edit control recognizes them
1579 if (dlg.m_sInputText.GetLength()>0)
1581 m_sMessageBuf = dlg.m_sInputText;
1582 dlg.m_sInputText.Replace(_T("\n\r"), _T("\n"));
1583 dlg.m_sInputText.Replace(_T("\r\n"), _T("\n"));
1584 if (dlg.m_sInputText.Right(1).Compare(_T("\n"))==0)
1585 dlg.m_sInputText = dlg.m_sInputText.Left(dlg.m_sInputText.GetLength()-1);
1587 else
1588 dlg.m_sInputText.Empty();
1589 pLogEntry->sMessage = dlg.m_sInputText;
1590 pLogEntry->sBugIDs = m_ProjectProperties.FindBugID(dlg.m_sInputText);
1591 CWnd * pMsgView = GetDlgItem(IDC_MSGVIEW);
1592 pMsgView->SetWindowText(_T(" "));
1593 pMsgView->SetWindowText(dlg.m_sInputText);
1594 m_ProjectProperties.FindBugID(dlg.m_sInputText, pMsgView);
1595 m_LogList.Invalidate();
1597 // update the log cache
1599 LogCache::CCachedLogInfo* toUpdate
1600 = GetLogCache (CTGitPath (m_sRepositoryRoot));
1601 if (toUpdate != NULL)
1603 // log caching is active
1605 LogCache::CCachedLogInfo newInfo;
1606 newInfo.Insert ( pLogEntry->Rev
1607 , ""
1608 , (const char*) CUnicodeUtils::GetUTF8 (pLogEntry->sMessage)
1610 , LogCache::CRevisionInfoContainer::HAS_COMMENT);
1612 toUpdate->Update (newInfo);
1616 theApp.DoWaitCursor(-1);
1617 EnableOKButton();
1618 #endif
1621 BOOL CLogDlg::PreTranslateMessage(MSG* pMsg)
1623 // Skip Ctrl-C when copying text out of the log message or search filter
1624 BOOL bSkipAccelerator = ( pMsg->message == WM_KEYDOWN && pMsg->wParam=='C' && (GetFocus()==GetDlgItem(IDC_MSGVIEW) || GetFocus()==GetDlgItem(IDC_SEARCHEDIT) ) && GetKeyState(VK_CONTROL)&0x8000 );
1625 if (pMsg->message == WM_KEYDOWN && pMsg->wParam=='\r')
1627 if (GetFocus()==GetDlgItem(IDC_LOGLIST))
1629 if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE))
1631 m_LogList.DiffSelectedRevWithPrevious();
1632 return TRUE;
1636 if (m_hAccel && !bSkipAccelerator)
1638 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1639 if (ret)
1640 return TRUE;
1643 if(::IsWindow(m_tooltips.m_hWnd))
1644 m_tooltips.RelayEvent(pMsg);
1645 return __super::PreTranslateMessage(pMsg);
1649 BOOL CLogDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1651 //if (this->IsThreadRunning())
1652 if(m_LogList.m_bNoDispUpdates)
1654 // only show the wait cursor over the list control
1655 if ((pWnd)&&
1656 ((pWnd == GetDlgItem(IDC_LOGLIST))||
1657 (pWnd == GetDlgItem(IDC_MSGVIEW))||
1658 (pWnd == GetDlgItem(IDC_LOGMSG))))
1660 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1661 SetCursor(hCur);
1662 return TRUE;
1665 if ((pWnd) && (pWnd == GetDlgItem(IDC_MSGVIEW)))
1666 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1668 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1669 SetCursor(hCur);
1670 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1673 void CLogDlg::OnBnClickedHelp()
1675 OnHelp();
1678 void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult)
1680 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1681 *pResult = 0;
1682 //if (this->IsThreadRunning())
1683 if(m_LogList.m_bNoDispUpdates)
1684 return;
1685 if (pNMLV->iItem >= 0)
1687 this->m_LogList.m_nSearchIndex = pNMLV->iItem;
1688 if (pNMLV->iSubItem != 0)
1689 return;
1690 if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount()))
1692 // remove the selected state
1693 if (pNMLV->uChanged & LVIF_STATE)
1695 m_LogList.SetItemState(pNMLV->iItem, 0, LVIS_SELECTED);
1696 FillLogMessageCtrl();
1697 UpdateData(FALSE);
1698 UpdateLogInfoLabel();
1700 return;
1702 if (pNMLV->uChanged & LVIF_STATE)
1704 FillLogMessageCtrl();
1705 UpdateData(FALSE);
1708 else
1710 FillLogMessageCtrl();
1711 UpdateData(FALSE);
1713 EnableOKButton();
1714 UpdateLogInfoLabel();
1717 void CLogDlg::OnEnLinkMsgview(NMHDR *pNMHDR, LRESULT *pResult)
1719 ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
1720 if (pEnLink->msg == WM_LBUTTONUP)
1722 CString url, msg;
1723 GetDlgItemText(IDC_MSGVIEW, msg);
1724 msg.Replace(_T("\r\n"), _T("\n"));
1725 url = msg.Mid(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax-pEnLink->chrg.cpMin);
1726 if (!::PathIsURL(url))
1728 url = m_ProjectProperties.GetBugIDUrl(url);
1729 url = GetAbsoluteUrlFromRelativeUrl(url);
1731 if (!url.IsEmpty())
1732 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
1734 *pResult = 0;
1737 class CDateSorter
1739 public:
1740 class CCommitPointer
1742 public:
1743 CCommitPointer():m_cont(NULL){}
1744 CCommitPointer(const CCommitPointer& P_Right)
1745 : m_cont(NULL)
1747 *this = P_Right;
1750 CCommitPointer& operator = (const CCommitPointer& P_Right)
1752 if(IsPointer())
1754 (*m_cont->m_parDates)[m_place] = P_Right.GetDate();
1755 (*m_cont->m_parFileChanges)[m_place] = P_Right.GetChanges();
1756 (*m_cont->m_parAuthors)[m_place] = P_Right.GetAuthor();
1758 else
1760 m_Date = P_Right.GetDate();
1761 m_Changes = P_Right.GetChanges();
1762 m_csAuthor = P_Right.GetAuthor();
1764 return *this;
1767 void Clone(const CCommitPointer& P_Right)
1769 m_cont = P_Right.m_cont;
1770 m_place = P_Right.m_place;
1771 m_Date = P_Right.m_Date;
1772 m_Changes = P_Right.m_Changes;
1773 m_csAuthor = P_Right.m_csAuthor;
1776 DWORD GetDate() const {return IsPointer() ? (*m_cont->m_parDates)[m_place] : m_Date;}
1777 DWORD GetChanges() const {return IsPointer() ? (*m_cont->m_parFileChanges)[m_place] : m_Changes;}
1778 CString GetAuthor() const {return IsPointer() ? (*m_cont->m_parAuthors)[m_place] : m_csAuthor;}
1780 bool IsPointer() const {return m_cont != NULL;}
1781 //When pointer
1782 CDateSorter* m_cont;
1783 int m_place;
1785 //When element
1786 DWORD m_Date;
1787 DWORD m_Changes;
1788 CString m_csAuthor;
1791 class iterator : public std::iterator<std::random_access_iterator_tag, CCommitPointer>
1793 public:
1794 CCommitPointer m_ptr;
1796 iterator(){}
1797 iterator(const iterator& P_Right){*this = P_Right;}
1798 iterator& operator=(const iterator& P_Right)
1800 m_ptr.Clone(P_Right.m_ptr);
1801 return *this;
1804 CCommitPointer& operator*(){return m_ptr;}
1805 CCommitPointer* operator->(){return &m_ptr;}
1806 const CCommitPointer& operator*()const{return m_ptr;}
1807 const CCommitPointer* operator->()const{return &m_ptr;}
1809 iterator& operator+=(size_t P_iOffset){m_ptr.m_place += P_iOffset;return *this;}
1810 iterator& operator-=(size_t P_iOffset){m_ptr.m_place -= P_iOffset;return *this;}
1811 iterator operator+(size_t P_iOffset)const{iterator it(*this); it += P_iOffset;return it;}
1812 iterator operator-(size_t P_iOffset)const{iterator it(*this); it -= P_iOffset;return it;}
1814 iterator& operator++(){++m_ptr.m_place;return *this;}
1815 iterator& operator--(){--m_ptr.m_place;return *this;}
1816 iterator operator++(int){iterator it(*this);++*this;return it;}
1817 iterator operator--(int){iterator it(*this);--*this;return it;}
1819 size_t operator-(const iterator& P_itRight)const{return m_ptr.m_place - P_itRight->m_place;}
1821 bool operator<(const iterator& P_itRight)const{return m_ptr.m_place < P_itRight->m_place;}
1822 bool operator!=(const iterator& P_itRight)const{return m_ptr.m_place != P_itRight->m_place;}
1823 bool operator==(const iterator& P_itRight)const{return m_ptr.m_place == P_itRight->m_place;}
1824 bool operator>(const iterator& P_itRight)const{return m_ptr.m_place > P_itRight->m_place;}
1826 iterator begin()
1828 iterator it;
1829 it->m_place = 0;
1830 it->m_cont = this;
1831 return it;
1833 iterator end()
1835 iterator it;
1836 it->m_place = m_parDates->GetCount();
1837 it->m_cont = this;
1838 return it;
1841 CDWordArray * m_parDates;
1842 CDWordArray * m_parFileChanges;
1843 CStringArray * m_parAuthors;
1846 class CDateSorterLess
1848 public:
1849 bool operator () (const CDateSorter::CCommitPointer& P_Left, const CDateSorter::CCommitPointer& P_Right) const
1851 return P_Left.GetDate() > P_Right.GetDate(); //Last date first
1858 void CLogDlg::OnBnClickedStatbutton()
1861 if (this->IsThreadRunning())
1862 return;
1863 if (m_LogList.m_arShownList.IsEmpty())
1864 return; // nothing is shown, so no statistics.
1865 // the statistics dialog expects the log entries to be sorted by date
1866 SortByColumn(3, false);
1867 CPtrArray shownlist;
1868 m_LogList.RecalculateShownList(&shownlist);
1869 // create arrays which are aware of the current filter
1870 CStringArray m_arAuthorsFiltered;
1871 CDWordArray m_arDatesFiltered;
1872 CDWordArray m_arFileChangesFiltered;
1873 for (INT_PTR i=0; i<shownlist.GetCount(); ++i)
1875 GitRev* pLogEntry = reinterpret_cast<GitRev*>(shownlist.GetAt(i));
1876 CString strAuthor = pLogEntry->m_AuthorName;
1877 if ( strAuthor.IsEmpty() )
1879 strAuthor.LoadString(IDS_STATGRAPH_EMPTYAUTHOR);
1881 m_arAuthorsFiltered.Add(strAuthor);
1882 m_arDatesFiltered.Add(pLogEntry->m_AuthorDate.GetTime());
1883 m_arFileChangesFiltered.Add(pLogEntry->m_Files.GetCount());
1886 CDateSorter W_Sorter;
1887 W_Sorter.m_parAuthors = &m_arAuthorsFiltered;
1888 W_Sorter.m_parDates = &m_arDatesFiltered;
1889 W_Sorter.m_parFileChanges = &m_arFileChangesFiltered;
1890 std::sort(W_Sorter.begin(), W_Sorter.end(), CDateSorterLess());
1892 CStatGraphDlg dlg;
1893 dlg.m_parAuthors = &m_arAuthorsFiltered;
1894 dlg.m_parDates = &m_arDatesFiltered;
1895 dlg.m_parFileChanges = &m_arFileChangesFiltered;
1896 dlg.m_path = m_path;
1897 dlg.DoModal();
1898 // restore the previous sorting
1899 SortByColumn(m_nSortColumn, m_bAscending);
1900 OnTimer(LOGFILTER_TIMER);
1904 void CLogDlg::DoSizeV1(int delta)
1907 RemoveAnchor(IDC_LOGLIST);
1908 RemoveAnchor(IDC_SPLITTERTOP);
1909 RemoveAnchor(IDC_MSGVIEW);
1910 RemoveAnchor(IDC_SPLITTERBOTTOM);
1911 RemoveAnchor(IDC_LOGMSG);
1912 CSplitterControl::ChangeHeight(&m_LogList, delta, CW_TOPALIGN);
1913 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), -delta, CW_BOTTOMALIGN);
1914 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1915 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1916 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1917 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1918 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1919 ArrangeLayout();
1920 AdjustMinSize();
1921 SetSplitterRange();
1922 m_LogList.Invalidate();
1923 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1927 void CLogDlg::DoSizeV2(int delta)
1930 RemoveAnchor(IDC_LOGLIST);
1931 RemoveAnchor(IDC_SPLITTERTOP);
1932 RemoveAnchor(IDC_MSGVIEW);
1933 RemoveAnchor(IDC_SPLITTERBOTTOM);
1934 RemoveAnchor(IDC_LOGMSG);
1935 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MSGVIEW), delta, CW_TOPALIGN);
1936 CSplitterControl::ChangeHeight(&m_ChangedFileListCtrl, -delta, CW_BOTTOMALIGN);
1937 AddAnchor(IDC_LOGLIST, TOP_LEFT, TOP_RIGHT);
1938 AddAnchor(IDC_SPLITTERTOP, TOP_LEFT, TOP_RIGHT);
1939 AddAnchor(IDC_MSGVIEW, TOP_LEFT, BOTTOM_RIGHT);
1940 AddAnchor(IDC_SPLITTERBOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT);
1941 AddAnchor(IDC_LOGMSG, BOTTOM_LEFT, BOTTOM_RIGHT);
1942 ArrangeLayout();
1943 AdjustMinSize();
1944 SetSplitterRange();
1945 GetDlgItem(IDC_MSGVIEW)->Invalidate();
1946 m_ChangedFileListCtrl.Invalidate();
1950 void CLogDlg::AdjustMinSize()
1952 // adjust the minimum size of the dialog to prevent the resizing from
1953 // moving the list control too far down.
1954 CRect rcChgListView;
1955 m_ChangedFileListCtrl.GetClientRect(rcChgListView);
1956 CRect rcLogList;
1957 m_LogList.GetClientRect(rcLogList);
1959 SetMinTrackSize(CSize(m_DlgOrigRect.Width(),
1960 m_DlgOrigRect.Height()-m_ChgOrigRect.Height()-m_LogListOrigRect.Height()-m_MsgViewOrigRect.Height()
1961 +rcChgListView.Height()+rcLogList.Height()+60));
1964 LRESULT CLogDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1966 switch (message) {
1967 case WM_NOTIFY:
1968 if (wParam == IDC_SPLITTERTOP)
1970 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1971 DoSizeV1(pHdr->delta);
1973 else if (wParam == IDC_SPLITTERBOTTOM)
1975 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1976 DoSizeV2(pHdr->delta);
1978 break;
1981 return CResizableDialog::DefWindowProc(message, wParam, lParam);
1984 void CLogDlg::SetSplitterRange()
1986 if ((m_LogList)&&(m_ChangedFileListCtrl))
1988 CRect rcTop;
1989 m_LogList.GetWindowRect(rcTop);
1990 ScreenToClient(rcTop);
1991 CRect rcMiddle;
1992 GetDlgItem(IDC_MSGVIEW)->GetWindowRect(rcMiddle);
1993 ScreenToClient(rcMiddle);
1994 m_wndSplitter1.SetRange(rcTop.top+30, rcMiddle.bottom-20);
1995 CRect rcBottom;
1996 m_ChangedFileListCtrl.GetWindowRect(rcBottom);
1997 ScreenToClient(rcBottom);
1998 m_wndSplitter2.SetRange(rcMiddle.top+30, rcBottom.bottom-20);
2002 LRESULT CLogDlg::OnClickedInfoIcon(WPARAM /*wParam*/, LPARAM lParam)
2004 // FIXME: x64 version would get this function called with unexpected parameters.
2005 if (!lParam)
2006 return 0;
2008 RECT * rect = (LPRECT)lParam;
2009 CPoint point;
2010 CString temp;
2011 point = CPoint(rect->left, rect->bottom);
2012 #define LOGMENUFLAGS(x) (MF_STRING | MF_ENABLED | (m_LogList.m_nSelectedFilter == x ? MF_CHECKED : MF_UNCHECKED))
2013 CMenu popup;
2014 if (popup.CreatePopupMenu())
2016 temp.LoadString(IDS_LOG_FILTER_ALL);
2017 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_ALL), LOGFILTER_ALL, temp);
2019 popup.AppendMenu(MF_SEPARATOR, NULL);
2021 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2022 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_MESSAGES), LOGFILTER_MESSAGES, temp);
2023 temp.LoadString(IDS_LOG_FILTER_PATHS);
2024 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_PATHS), LOGFILTER_PATHS, temp);
2025 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2026 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_AUTHORS), LOGFILTER_AUTHORS, temp);
2027 temp.LoadString(IDS_LOG_FILTER_REVS);
2028 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_REVS), LOGFILTER_REVS, temp);
2029 temp.LoadString(IDS_LOG_FILTER_BUGIDS);
2030 popup.AppendMenu(LOGMENUFLAGS(LOGFILTER_BUGID), LOGFILTER_BUGID, temp);
2032 popup.AppendMenu(MF_SEPARATOR, NULL);
2034 temp.LoadString(IDS_LOG_FILTER_REGEX);
2035 popup.AppendMenu(MF_STRING | MF_ENABLED | (m_bFilterWithRegex ? MF_CHECKED : MF_UNCHECKED), LOGFILTER_REGEX, temp);
2037 m_tooltips.Pop();
2038 int selection = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2039 if (selection != 0)
2042 if (selection == LOGFILTER_REGEX)
2044 m_bFilterWithRegex = !m_bFilterWithRegex;
2045 CRegDWORD b = CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), TRUE);
2046 b = m_bFilterWithRegex;
2047 CheckRegexpTooltip();
2049 else
2051 m_LogList.m_nSelectedFilter = selection;
2052 SetFilterCueText();
2054 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2057 return 0L;
2060 LRESULT CLogDlg::OnClickedCancelFilter(WPARAM /*wParam*/, LPARAM /*lParam*/)
2063 KillTimer(LOGFILTER_TIMER);
2065 m_LogList.m_sFilterText.Empty();
2066 UpdateData(FALSE);
2067 theApp.DoWaitCursor(1);
2068 CStoreSelection storeselection(this);
2069 FillLogMessageCtrl(false);
2071 m_LogList.RemoveFilter();
2073 CTime begin,end;
2074 m_LogList.GetTimeRange(begin,end);
2075 m_DateFrom.SetTime(&begin);
2076 m_DateTo.SetTime(&end);
2078 theApp.DoWaitCursor(-1);
2079 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2080 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2081 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2082 UpdateLogInfoLabel();
2084 return 0L;
2088 void CLogDlg::SetFilterCueText()
2090 CString temp;
2091 switch (m_LogList.m_nSelectedFilter)
2093 case LOGFILTER_ALL:
2094 temp.LoadString(IDS_LOG_FILTER_ALL);
2095 break;
2096 case LOGFILTER_MESSAGES:
2097 temp.LoadString(IDS_LOG_FILTER_MESSAGES);
2098 break;
2099 case LOGFILTER_PATHS:
2100 temp.LoadString(IDS_LOG_FILTER_PATHS);
2101 break;
2102 case LOGFILTER_AUTHORS:
2103 temp.LoadString(IDS_LOG_FILTER_AUTHORS);
2104 break;
2105 case LOGFILTER_REVS:
2106 temp.LoadString(IDS_LOG_FILTER_REVS);
2107 break;
2109 // to make the cue banner text appear more to the right of the edit control
2110 temp = _T(" ")+temp;
2111 m_cFilter.SetCueBanner(temp);
2114 bool CLogDlg::Validate(LPCTSTR string)
2116 if (!m_bFilterWithRegex)
2117 return true;
2118 tr1::wregex pat;
2119 return m_LogList.ValidateRegexp(string, pat, false);
2123 void CLogDlg::OnTimer(UINT_PTR nIDEvent)
2125 if (nIDEvent == LOGFILTER_TIMER)
2127 if (this->IsThreadRunning())
2129 // thread still running! So just restart the timer.
2130 SetTimer(LOGFILTER_TIMER, 1000, NULL);
2131 return;
2133 CWnd * focusWnd = GetFocus();
2134 bool bSetFocusToFilterControl = ((focusWnd != GetDlgItem(IDC_DATEFROM))&&(focusWnd != GetDlgItem(IDC_DATETO))
2135 && (focusWnd != GetDlgItem(IDC_LOGLIST)));
2136 if (m_LogList.m_sFilterText.IsEmpty())
2138 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2139 // do not return here!
2140 // we also need to run the filter if the filter text is empty:
2141 // 1. to clear an existing filter
2142 // 2. to rebuild the m_arShownList after sorting
2144 theApp.DoWaitCursor(1);
2145 CStoreSelection storeselection(this);
2146 KillTimer(LOGFILTER_TIMER);
2147 FillLogMessageCtrl(false);
2149 // now start filter the log list
2150 m_LogList.StartFilter();
2152 if ( m_LogList.GetItemCount()==1 )
2154 m_LogList.SetSelectionMark(0);
2155 m_LogList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
2157 theApp.DoWaitCursor(-1);
2158 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
2159 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
2160 if (bSetFocusToFilterControl)
2161 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
2162 UpdateLogInfoLabel();
2163 } // if (nIDEvent == LOGFILTER_TIMER)
2164 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
2165 __super::OnTimer(nIDEvent);
2168 void CLogDlg::OnDtnDatetimechangeDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2172 CTime _time;
2173 m_DateTo.GetTime(_time);
2175 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 23, 59, 59);
2176 if (time.GetTime() != m_LogList.m_To.GetTime())
2178 m_LogList.m_To = (DWORD)time.GetTime();
2179 SetTimer(LOGFILTER_TIMER, 10, NULL);
2182 catch (...)
2184 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2187 *pResult = 0;
2190 void CLogDlg::OnDtnDatetimechangeDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
2195 CTime _time;
2196 m_DateFrom.GetTime(_time);
2198 CTime time(_time.GetYear(), _time.GetMonth(), _time.GetDay(), 0, 0, 0);
2199 if (time.GetTime() != m_LogList.m_From.GetTime())
2201 m_LogList.m_From = (DWORD)time.GetTime();
2202 SetTimer(LOGFILTER_TIMER, 10, NULL);
2205 catch (...)
2207 CMessageBox::Show(NULL,_T("Invalidate Parameter"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2210 *pResult = 0;
2215 CTGitPathList CLogDlg::GetChangedPathsFromSelectedRevisions(bool /*bRelativePaths*/ /* = false */, bool /*bUseFilter*/ /* = true */)
2217 CTGitPathList pathList;
2218 #if 0
2220 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2222 m_sRepositoryRoot = GetRepositoryRoot(m_path);
2224 if (m_sRepositoryRoot.IsEmpty() && (bRelativePaths == false))
2225 return pathList;
2227 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2228 if (pos != NULL)
2230 while (pos)
2232 int nextpos = m_LogList.GetNextSelectedItem(pos);
2233 if (nextpos >= m_arShownList.GetCount())
2234 continue;
2235 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(nextpos));
2236 LogChangedPathArray * cpatharray = pLogEntry->pArChangedPaths;
2237 for (INT_PTR cpPathIndex = 0; cpPathIndex<cpatharray->GetCount(); ++cpPathIndex)
2239 LogChangedPath * cpath = cpatharray->GetAt(cpPathIndex);
2240 if (cpath == NULL)
2241 continue;
2242 CTGitPath path;
2243 if (!bRelativePaths)
2244 path.SetFromGit(m_sRepositoryRoot);
2245 path.AppendPathString(cpath->sPath);
2246 if ((!bUseFilter)||
2247 ((m_cHidePaths.GetState() & 0x0003)!=BST_CHECKED)||
2248 (cpath->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0))
2249 pathList.AddPath(path);
2254 pathList.RemoveDuplicates();
2255 #endif
2256 return pathList;
2259 void CLogDlg::SortByColumn(int /*nSortColumn*/, bool /*bAscending*/)
2261 #if 0
2262 switch(nSortColumn)
2264 case 0: // Revision
2266 if(bAscending)
2267 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscRevSort());
2268 else
2269 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescRevSort());
2271 break;
2272 case 1: // action
2274 if(bAscending)
2275 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscActionSort());
2276 else
2277 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescActionSort());
2279 break;
2280 case 2: // Author
2282 if(bAscending)
2283 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscAuthorSort());
2284 else
2285 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescAuthorSort());
2287 break;
2288 case 3: // Date
2290 if(bAscending)
2291 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscDateSort());
2292 else
2293 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescDateSort());
2295 break;
2296 case 4: // Message or bug id
2297 if (m_bShowBugtraqColumn)
2299 if(bAscending)
2300 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscBugIDSort());
2301 else
2302 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescBugIDSort());
2303 break;
2305 // fall through here
2306 case 5: // Message
2308 if(bAscending)
2309 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::AscMessageSort());
2310 else
2311 std::sort(m_logEntries.begin(), m_logEntries.end(), CLogDataVector::DescMessageSort());
2313 break;
2314 default:
2315 ATLASSERT(0);
2316 break;
2318 #endif
2321 void CLogDlg::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
2323 if (this->IsThreadRunning())
2324 return; //no sorting while the arrays are filled
2325 #if 0
2326 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2327 const int nColumn = pNMLV->iSubItem;
2328 m_bAscending = nColumn == m_nSortColumn ? !m_bAscending : TRUE;
2329 m_nSortColumn = nColumn;
2330 SortByColumn(m_nSortColumn, m_bAscending);
2331 SetSortArrow(&m_LogList, m_nSortColumn, !!m_bAscending);
2332 SortShownListArray();
2333 m_LogList.Invalidate();
2334 UpdateLogInfoLabel();
2335 #endif
2336 *pResult = 0;
2339 void CLogDlg::SortShownListArray()
2341 // make sure the shown list still matches the filter after sorting.
2342 OnTimer(LOGFILTER_TIMER);
2343 // clear the selection states
2344 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2345 while (pos)
2347 m_LogList.SetItemState(m_LogList.GetNextSelectedItem(pos), 0, LVIS_SELECTED);
2349 m_LogList.SetSelectionMark(-1);
2352 void CLogDlg::SetSortArrow(CListCtrl * control, int nColumn, bool bAscending)
2354 if (control == NULL)
2355 return;
2356 // set the sort arrow
2357 CHeaderCtrl * pHeader = control->GetHeaderCtrl();
2358 HDITEM HeaderItem = {0};
2359 HeaderItem.mask = HDI_FORMAT;
2360 for (int i=0; i<pHeader->GetItemCount(); ++i)
2362 pHeader->GetItem(i, &HeaderItem);
2363 HeaderItem.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
2364 pHeader->SetItem(i, &HeaderItem);
2366 if (nColumn >= 0)
2368 pHeader->GetItem(nColumn, &HeaderItem);
2369 HeaderItem.fmt |= (bAscending ? HDF_SORTUP : HDF_SORTDOWN);
2370 pHeader->SetItem(nColumn, &HeaderItem);
2373 void CLogDlg::OnLvnColumnclickChangedFileList(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
2375 #if 0
2376 if (this->IsThreadRunning())
2377 return; //no sorting while the arrays are filled
2378 if (m_currentChangedArray == NULL)
2379 return;
2380 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
2381 const int nColumn = pNMLV->iSubItem;
2382 m_bAscendingPathList = nColumn == m_nSortColumnPathList ? !m_bAscendingPathList : TRUE;
2383 m_nSortColumnPathList = nColumn;
2384 // qsort(m_currentChangedArray->GetData(), m_currentChangedArray->GetSize(), sizeof(LogChangedPath*), (GENERICCOMPAREFN)SortCompare);
2386 SetSortArrow(&m_ChangedFileListCtrl, m_nSortColumnPathList, m_bAscendingPathList);
2387 m_ChangedFileListCtrl.Invalidate();
2388 *pResult = 0;
2389 #endif
2392 int CLogDlg::m_nSortColumnPathList = 0;
2393 bool CLogDlg::m_bAscendingPathList = false;
2395 int CLogDlg::SortCompare(const void * /*pElem1*/, const void * /*pElem2*/)
2397 #if 0
2398 LogChangedPath * cpath1 = *((LogChangedPath**)pElem1);
2399 LogChangedPath * cpath2 = *((LogChangedPath**)pElem2);
2401 if (m_bAscendingPathList)
2402 std::swap (cpath1, cpath2);
2404 int cmp = 0;
2405 switch (m_nSortColumnPathList)
2407 case 0: // action
2408 cmp = cpath2->GetAction().Compare(cpath1->GetAction());
2409 if (cmp)
2410 return cmp;
2411 // fall through
2412 case 1: // path
2413 cmp = cpath2->sPath.CompareNoCase(cpath1->sPath);
2414 if (cmp)
2415 return cmp;
2416 // fall through
2417 case 2: // copy from path
2418 cmp = cpath2->sCopyFromPath.Compare(cpath1->sCopyFromPath);
2419 if (cmp)
2420 return cmp;
2421 // fall through
2422 case 3: // copy from revision
2423 return cpath2->lCopyFromRev > cpath1->lCopyFromRev;
2425 #endif
2426 return 0;
2429 void CLogDlg::OnBnClickedHidepaths()
2431 FillLogMessageCtrl();
2432 m_ChangedFileListCtrl.Invalidate();
2437 void CLogDlg::OnBnClickedCheckStoponcopy()
2439 #if 0
2440 if (!GetDlgItem(IDC_GETALL)->IsWindowEnabled())
2441 return;
2443 // ignore old fetch limits when switching
2444 // between copy-following and stop-on-copy
2445 // (otherwise stop-on-copy will limit what
2446 // we see immediately after switching to
2447 // copy-following)
2449 m_endrev = 0;
2451 // now, restart the query
2452 #endif
2453 Refresh();
2457 void CLogDlg::UpdateLogInfoLabel()
2460 CGitHash rev1 ;
2461 CGitHash rev2 ;
2462 long selectedrevs = 0;
2463 int count =m_LogList.m_arShownList.GetCount();
2464 int start = 0;
2465 if (count)
2467 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(0)))->m_CommitHash;
2468 if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1))
2469 start = 1;
2470 rev1 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(start)))->m_CommitHash;
2471 //pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_arShownList.GetCount()-1));
2472 rev2 = (reinterpret_cast<GitRev*>(m_LogList.m_arShownList.GetAt(count-1)))->m_CommitHash;
2473 selectedrevs = m_LogList.GetSelectedCount();
2475 CString sTemp;
2476 sTemp.Format(_T("Showing %ld revision(s), from revision %s to revision %s - %ld revision(s) selected\n"),
2477 count - start,
2478 rev2.ToString().Left(6), rev1.ToString().Left(6), selectedrevs);
2480 if(selectedrevs == 1)
2482 CString str=m_ChangedFileListCtrl.GetStatisticsString(true);
2483 str.Replace(_T('\n'), _T(' '));
2484 sTemp += str;
2486 m_sLogInfo = sTemp;
2488 UpdateData(FALSE);
2491 #if 0
2492 void CLogDlg::ShowContextMenuForChangedpaths(CWnd* /*pWnd*/, CPoint point)
2495 int selIndex = m_ChangedFileListCtrl.GetSelectionMark();
2496 if ((point.x == -1) && (point.y == -1))
2498 CRect rect;
2499 m_ChangedFileListCtrl.GetItemRect(selIndex, &rect, LVIR_LABEL);
2500 m_ChangedFileListCtrl.ClientToScreen(&rect);
2501 point = rect.CenterPoint();
2503 if (selIndex < 0)
2504 return;
2505 int s = m_LogList.GetSelectionMark();
2506 if (s < 0)
2507 return;
2508 std::vector<CString> changedpaths;
2509 std::vector<LogChangedPath*> changedlogpaths;
2510 POSITION pos = m_LogList.GetFirstSelectedItemPosition();
2511 if (pos == NULL)
2512 return; // nothing is selected, get out of here
2514 bool bOneRev = true;
2515 int sel=m_LogList.GetNextSelectedItem(pos);
2516 GitRev * pLogEntry = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel));
2517 GitRev * rev1 = pLogEntry;
2518 GitRev * rev2 = reinterpret_cast<GitRev *>(m_LogList.m_arShownList.GetAt(sel+1));
2519 #if 0
2520 bool bOneRev = true;
2521 if (pos)
2523 while (pos)
2525 pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetNextSelectedItem(pos)));
2526 if (pLogEntry)
2528 rev1 = max(rev1,(git_revnum_t)pLogEntry->Rev);
2529 rev2 = min(rev2,(git_revnum_t)pLogEntry->Rev);
2530 bOneRev = false;
2533 if (!bOneRev)
2534 rev2--;
2535 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2536 while (pos)
2538 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2539 changedpaths.push_back(m_currentChangedPathList[nItem].GetGitPathString());
2542 else
2544 // only one revision is selected in the log dialog top pane
2545 // but multiple items could be selected in the changed items list
2546 rev2 = rev1-1;
2548 POSITION pos = m_ChangedFileListCtrl.GetFirstSelectedItemPosition();
2549 while (pos)
2551 int nItem = m_ChangedFileListCtrl.GetNextSelectedItem(pos);
2552 LogChangedPath * changedlogpath = pLogEntry->pArChangedPaths->GetAt(nItem);
2554 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2556 if ((changedlogpath)&&(!changedlogpath->sCopyFromPath.IsEmpty()))
2557 rev2 = changedlogpath->lCopyFromRev;
2558 else
2560 // if the path was modified but the parent path was 'added with history'
2561 // then we have to use the copy from revision of the parent path
2562 CTGitPath cpath = CTGitPath(changedlogpath->sPath);
2563 for (int flist = 0; flist < pLogEntry->pArChangedPaths->GetCount(); ++flist)
2565 CTGitPath p = CTGitPath(pLogEntry->pArChangedPaths->GetAt(flist)->sPath);
2566 if (p.IsAncestorOf(cpath))
2568 if (!pLogEntry->pArChangedPaths->GetAt(flist)->sCopyFromPath.IsEmpty())
2569 rev2 = pLogEntry->pArChangedPaths->GetAt(flist)->lCopyFromRev;
2574 if ((m_cHidePaths.GetState() & 0x0003)==BST_CHECKED)
2576 // some items are hidden! So find out which item the user really clicked on
2577 INT_PTR selRealIndex = -1;
2578 for (INT_PTR hiddenindex=0; hiddenindex<pLogEntry->pArChangedPaths->GetCount(); ++hiddenindex)
2580 if (pLogEntry->pArChangedPaths->GetAt(hiddenindex)->sPath.Left(m_sRelativeRoot.GetLength()).Compare(m_sRelativeRoot)==0)
2581 selRealIndex++;
2582 if (selRealIndex == nItem)
2584 selIndex = hiddenindex;
2585 changedlogpath = pLogEntry->pArChangedPaths->GetAt(selIndex);
2586 break;
2590 if (changedlogpath)
2592 changedpaths.push_back(changedlogpath->sPath);
2593 changedlogpaths.push_back(changedlogpath);
2597 #endif
2598 //entry is selected, now show the popup menu
2599 CIconMenu popup;
2600 if (popup.CreatePopupMenu())
2602 bool bEntryAdded = false;
2603 if (m_ChangedFileListCtrl.GetSelectedCount() == 1)
2605 // if ((!bOneRev)||(IsDiffPossible(changedlogpaths[0], rev1)))
2607 popup.AppendMenuIcon(CGitLogList::ID_DIFF, IDS_LOG_POPUP_DIFF, IDI_DIFF);
2608 popup.AppendMenuIcon(CGitLogList::ID_BLAMEDIFF, IDS_LOG_POPUP_BLAMEDIFF, IDI_BLAME);
2609 popup.SetDefaultItem(CGitLogList::ID_DIFF, FALSE);
2610 popup.AppendMenuIcon(CGitLogList::ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF);
2611 bEntryAdded = true;
2613 // if (rev2 == rev1-1)
2615 if (bEntryAdded)
2616 popup.AppendMenu(MF_SEPARATOR, NULL);
2617 popup.AppendMenuIcon(CGitLogList::ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
2618 popup.AppendMenuIcon(CGitLogList::ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
2619 popup.AppendMenuIcon(CGitLogList::ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME);
2620 popup.AppendMenu(MF_SEPARATOR, NULL);
2621 if (m_hasWC)
2622 popup.AppendMenuIcon(CGitLogList::ID_REVERTREV, IDS_LOG_POPUP_REVERTREV, IDI_REVERT);
2623 popup.AppendMenuIcon(CGitLogList::ID_POPPROPS, IDS_REPOBROWSE_SHOWPROP, IDI_PROPERTIES); // "Show Properties"
2624 popup.AppendMenuIcon(CGitLogList::ID_LOG, IDS_MENULOG, IDI_LOG); // "Show Log"
2625 popup.AppendMenuIcon(CGitLogList::ID_GETMERGELOGS, IDS_LOG_POPUP_GETMERGELOGS, IDI_LOG); // "Show merge log"
2626 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS);
2627 bEntryAdded = true;
2628 if (!m_ProjectProperties.sWebViewerPathRev.IsEmpty())
2630 popup.AppendMenu(MF_SEPARATOR, NULL);
2631 popup.AppendMenuIcon(CGitLogList::ID_VIEWPATHREV, IDS_LOG_POPUP_VIEWPATHREV);
2633 if (popup.GetDefaultItem(0,FALSE)==-1)
2634 popup.SetDefaultItem(CGitLogList::ID_OPEN, FALSE);
2637 else if (changedlogpaths.size())
2639 // more than one entry is selected
2640 popup.AppendMenuIcon(CGitLogList::ID_SAVEAS, IDS_LOG_POPUP_SAVE);
2641 bEntryAdded = true;
2644 if (!bEntryAdded)
2645 return;
2646 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
2647 bool bOpenWith = false;
2648 bool bMergeLog = false;
2649 m_bCancelled = false;
2651 switch (cmd)
2653 case CGitLogList::ID_DIFF:
2655 DoDiffFromLog(selIndex, rev1, rev2, false, false);
2657 break;
2658 #if 0
2659 case ID_BLAMEDIFF:
2661 DoDiffFromLog(selIndex, rev1, rev2, true, false);
2663 break;
2664 case ID_GNUDIFF1:
2666 DoDiffFromLog(selIndex, rev1, rev2, false, true);
2668 break;
2669 case ID_REVERTREV:
2671 SetPromptApp(&theApp);
2672 theApp.DoWaitCursor(1);
2673 CString sUrl;
2674 if (Git::PathIsURL(m_path))
2676 sUrl = m_path.GetGitPathString();
2678 else
2680 sUrl = GetURLFromPath(m_path);
2681 if (sUrl.IsEmpty())
2683 theApp.DoWaitCursor(-1);
2684 CString temp;
2685 temp.Format(IDS_ERR_NOURLOFFILE, m_path.GetWinPath());
2686 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2687 EnableOKButton();
2688 theApp.DoWaitCursor(-1);
2689 break; //exit
2692 // find the working copy path of the selected item from the URL
2693 m_bCancelled = false;
2694 CString sUrlRoot = GetRepositoryRoot(CTGitPath(sUrl));
2696 CString fileURL = changedpaths[0];
2697 fileURL = sUrlRoot + fileURL.Trim();
2698 // firstfile = (e.g.) http://mydomain.com/repos/trunk/folder/file1
2699 // sUrl = http://mydomain.com/repos/trunk/folder
2700 CString sUnescapedUrl = CPathUtils::PathUnescape(sUrl);
2701 // find out until which char the urls are identical
2702 int i=0;
2703 while ((i<fileURL.GetLength())&&(i<sUnescapedUrl.GetLength())&&(fileURL[i]==sUnescapedUrl[i]))
2704 i++;
2705 int leftcount = m_path.GetWinPathString().GetLength()-(sUnescapedUrl.GetLength()-i);
2706 CString wcPath = m_path.GetWinPathString().Left(leftcount);
2707 wcPath += fileURL.Mid(i);
2708 wcPath.Replace('/', '\\');
2709 CGitProgressDlg dlg;
2710 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2712 // a deleted path! Since the path isn't there anymore, merge
2713 // won't work. So just do a copy url->wc
2714 dlg.SetCommand(CGitProgressDlg::GitProgress_Copy);
2715 dlg.SetPathList(CTGitPathList(CTGitPath(fileURL)));
2716 dlg.SetUrl(wcPath);
2717 dlg.SetRevision(rev2);
2719 else
2721 if (!PathFileExists(wcPath))
2723 // seems the path got renamed
2724 // tell the user how to work around this.
2725 CMessageBox::Show(this->m_hWnd, IDS_LOG_REVERTREV_ERROR, IDS_APPNAME, MB_ICONERROR);
2726 EnableOKButton();
2727 theApp.DoWaitCursor(-1);
2728 break; //exit
2730 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
2731 dlg.SetPathList(CTGitPathList(CTGitPath(wcPath)));
2732 dlg.SetUrl(fileURL);
2733 dlg.SetSecondUrl(fileURL);
2734 GitRevRangeArray revarray;
2735 revarray.AddRevRange(rev1, rev2);
2736 dlg.SetRevisionRanges(revarray);
2738 CString msg;
2739 msg.Format(IDS_LOG_REVERT_CONFIRM, (LPCTSTR)wcPath);
2740 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
2742 dlg.DoModal();
2744 theApp.DoWaitCursor(-1);
2746 break;
2747 case ID_POPPROPS:
2749 DialogEnableWindow(IDOK, FALSE);
2750 SetPromptApp(&theApp);
2751 theApp.DoWaitCursor(1);
2752 CString filepath;
2753 if (Git::PathIsURL(m_path))
2755 filepath = m_path.GetGitPathString();
2757 else
2759 filepath = GetURLFromPath(m_path);
2760 if (filepath.IsEmpty())
2762 theApp.DoWaitCursor(-1);
2763 CString temp;
2764 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2765 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2766 TRACE(_T("could not retrieve the URL of the file!\n"));
2767 EnableOKButton();
2768 break;
2771 filepath = GetRepositoryRoot(CTGitPath(filepath));
2772 filepath += changedpaths[0];
2773 CPropDlg dlg;
2774 dlg.m_rev = rev1;
2775 dlg.m_Path = CTGitPath(filepath);
2776 dlg.DoModal();
2777 EnableOKButton();
2778 theApp.DoWaitCursor(-1);
2780 break;
2781 case ID_SAVEAS:
2783 DialogEnableWindow(IDOK, FALSE);
2784 SetPromptApp(&theApp);
2785 theApp.DoWaitCursor(1);
2786 CString filepath;
2787 if (Git::PathIsURL(m_path))
2789 filepath = m_path.GetGitPathString();
2791 else
2793 filepath = GetURLFromPath(m_path);
2794 if (filepath.IsEmpty())
2796 theApp.DoWaitCursor(-1);
2797 CString temp;
2798 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2799 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2800 TRACE(_T("could not retrieve the URL of the file!\n"));
2801 EnableOKButton();
2802 break;
2805 m_bCancelled = false;
2806 CString sRoot = GetRepositoryRoot(CTGitPath(filepath));
2807 // if more than one entry is selected, we save them
2808 // one by one into a folder the user has selected
2809 bool bTargetSelected = false;
2810 CTGitPath TargetPath;
2811 if (m_ChangedFileListCtrl.GetSelectedCount() > 1)
2813 CBrowseFolder browseFolder;
2814 browseFolder.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_SAVEFOLDERTOHINT)));
2815 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
2816 CString strSaveAsDirectory;
2817 if (browseFolder.Show(GetSafeHwnd(), strSaveAsDirectory) == CBrowseFolder::OK)
2819 TargetPath = CTGitPath(strSaveAsDirectory);
2820 bTargetSelected = true;
2823 else
2825 // Display the Open dialog box.
2826 CString revFilename;
2827 CString temp;
2828 temp = CPathUtils::GetFileNameFromPath(changedpaths[0]);
2829 int rfind = temp.ReverseFind('.');
2830 if (rfind > 0)
2831 revFilename.Format(_T("%s-%ld%s"), (LPCTSTR)temp.Left(rfind), rev1, (LPCTSTR)temp.Mid(rfind));
2832 else
2833 revFilename.Format(_T("%s-%ld"), (LPCTSTR)temp, rev1);
2834 bTargetSelected = CAppUtils::FileOpenSave(revFilename, NULL, IDS_LOG_POPUP_SAVE, IDS_COMMONFILEFILTER, false, m_hWnd);
2835 TargetPath.SetFromWin(revFilename);
2837 if (bTargetSelected)
2839 CProgressDlg progDlg;
2840 progDlg.SetTitle(IDS_APPNAME);
2841 progDlg.SetAnimation(IDR_DOWNLOAD);
2842 for (std::vector<LogChangedPath*>::iterator it = changedlogpaths.begin(); it!= changedlogpaths.end(); ++it)
2844 GitRev getrev = ((*it)->action == LOGACTIONS_DELETED) ? rev2 : rev1;
2846 CString sInfoLine;
2847 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, (LPCTSTR)filepath, (LPCTSTR)getrev.ToString());
2848 progDlg.SetLine(1, sInfoLine, true);
2849 SetAndClearProgressInfo(&progDlg);
2850 progDlg.ShowModeless(m_hWnd);
2852 CTGitPath tempfile = TargetPath;
2853 if (changedpaths.size() > 1)
2855 // if multiple items are selected, then the TargetPath
2856 // points to a folder and we have to append the filename
2857 // to save to to that folder.
2858 CString sName = (*it)->sPath;
2859 int slashpos = sName.ReverseFind('/');
2860 if (slashpos >= 0)
2861 sName = sName.Mid(slashpos);
2862 tempfile.AppendPathString(sName);
2863 // one problem here:
2864 // a user could have selected multiple items which
2865 // have the same filename but reside in different
2866 // directories, e.g.
2867 // /folder1/file1
2868 // /folder2/file1
2869 // in that case, the second 'file1' will overwrite
2870 // the already saved 'file1'.
2872 // we could maybe find the common root of all selected
2873 // items and then create sub folders to save those files
2874 // there.
2875 // But I think we should just leave it that way: to check
2876 // out multiple items at once, the better way is still to
2877 // use the export command from the top pane of the log dialog.
2879 filepath = sRoot + (*it)->sPath;
2880 if (!Cat(CTGitPath(filepath), getrev, getrev, tempfile))
2882 progDlg.Stop();
2883 SetAndClearProgressInfo((HWND)NULL);
2884 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2885 EnableOKButton();
2886 theApp.DoWaitCursor(-1);
2887 break;
2890 progDlg.Stop();
2891 SetAndClearProgressInfo((HWND)NULL);
2893 EnableOKButton();
2894 theApp.DoWaitCursor(-1);
2896 break;
2897 case ID_OPENWITH:
2898 bOpenWith = true;
2899 case ID_OPEN:
2901 GitRev getrev = pLogEntry->pArChangedPaths->GetAt(selIndex)->action == LOGACTIONS_DELETED ? rev2 : rev1;
2902 Open(bOpenWith,changedpaths[0],getrev);
2904 break;
2905 case ID_BLAME:
2907 CString filepath;
2908 if (Git::PathIsURL(m_path))
2910 filepath = m_path.GetGitPathString();
2912 else
2914 filepath = GetURLFromPath(m_path);
2915 if (filepath.IsEmpty())
2917 theApp.DoWaitCursor(-1);
2918 CString temp;
2919 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2920 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2921 TRACE(_T("could not retrieve the URL of the file!\n"));
2922 EnableOKButton();
2923 break;
2926 filepath = GetRepositoryRoot(CTGitPath(filepath));
2927 filepath += changedpaths[0];
2928 CBlameDlg dlg;
2929 dlg.EndRev = rev1;
2930 if (dlg.DoModal() == IDOK)
2932 CBlame blame;
2933 CString tempfile;
2934 CString logfile;
2935 tempfile = blame.BlameToTempFile(CTGitPath(filepath), dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
2936 if (!tempfile.IsEmpty())
2938 if (dlg.m_bTextView)
2940 //open the default text editor for the result file
2941 CAppUtils::StartTextViewer(tempfile);
2943 else
2945 CString sParams = _T("/path:\"") + filepath + _T("\" ");
2946 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(filepath),sParams))
2948 break;
2952 else
2954 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
2958 break;
2959 case ID_GETMERGELOGS:
2960 bMergeLog = true;
2961 // fall through
2962 case ID_LOG:
2964 DialogEnableWindow(IDOK, FALSE);
2965 SetPromptApp(&theApp);
2966 theApp.DoWaitCursor(1);
2967 CString filepath;
2968 if (Git::PathIsURL(m_path))
2970 filepath = m_path.GetGitPathString();
2972 else
2974 filepath = GetURLFromPath(m_path);
2975 if (filepath.IsEmpty())
2977 theApp.DoWaitCursor(-1);
2978 CString temp;
2979 temp.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)filepath);
2980 CMessageBox::Show(this->m_hWnd, temp, _T("TortoiseGit"), MB_ICONERROR);
2981 TRACE(_T("could not retrieve the URL of the file!\n"));
2982 EnableOKButton();
2983 break;
2986 m_bCancelled = false;
2987 filepath = GetRepositoryRoot(CTGitPath(filepath));
2988 filepath += changedpaths[0];
2989 git_revnum_t logrev = rev1;
2990 if (changedlogpaths[0]->action == LOGACTIONS_DELETED)
2992 // if the item got deleted in this revision,
2993 // fetch the log from the previous revision where it
2994 // still existed.
2995 logrev--;
2997 CString sCmd;
2998 sCmd.Format(_T("\"%s\" /command:log /path:\"%s\" /startrev:%ld"), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)filepath, logrev);
2999 if (bMergeLog)
3000 sCmd += _T(" /merge");
3001 CAppUtils::LaunchApplication(sCmd, NULL, false);
3002 EnableOKButton();
3003 theApp.DoWaitCursor(-1);
3005 break;
3006 case ID_VIEWPATHREV:
3008 PLOGENTRYDATA pLogEntry = reinterpret_cast<PLOGENTRYDATA>(m_arShownList.GetAt(m_LogList.GetSelectionMark()));
3009 GitRev rev = pLogEntry->Rev;
3010 CString relurl = changedpaths[0];
3011 CString url = m_ProjectProperties.sWebViewerPathRev;
3012 url.Replace(_T("%REVISION%"), rev.ToString());
3013 url.Replace(_T("%PATH%"), relurl);
3014 relurl = relurl.Mid(relurl.Find('/'));
3015 url.Replace(_T("%PATH1%"), relurl);
3016 if (!url.IsEmpty())
3017 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
3019 break;
3020 #endif
3021 default:
3022 break;
3023 } // switch (cmd)
3025 } // if (popup.CreatePopupMenu())
3027 #endif
3029 void CLogDlg::OnDtnDropdownDatefrom(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3031 // the date control should not show the "today" button
3032 CMonthCalCtrl * pCtrl = m_DateFrom.GetMonthCalCtrl();
3033 if (pCtrl)
3034 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3035 *pResult = 0;
3038 void CLogDlg::OnDtnDropdownDateto(NMHDR * /*pNMHDR*/, LRESULT *pResult)
3040 // the date control should not show the "today" button
3041 CMonthCalCtrl * pCtrl = m_DateTo.GetMonthCalCtrl();
3042 if (pCtrl)
3043 SetWindowLongPtr(pCtrl->GetSafeHwnd(), GWL_STYLE, LONG_PTR(pCtrl->GetStyle() | MCS_NOTODAY));
3044 *pResult = 0;
3047 void CLogDlg::OnSize(UINT nType, int cx, int cy)
3049 __super::OnSize(nType, cx, cy);
3050 //set range
3051 SetSplitterRange();
3054 void CLogDlg::OnRefresh()
3056 //if (GetDlgItem(IDC_GETALL)->IsWindowEnabled())
3057 ShowStartRef();
3059 m_limit = 0;
3060 this->m_LogProgress.SetPos(0);
3062 Refresh (true);
3068 void CLogDlg::OnFocusFilter()
3070 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3073 void CLogDlg::OnEditCopy()
3075 if (GetFocus() == &m_ChangedFileListCtrl)
3076 CopyChangedSelectionToClipBoard();
3077 else
3078 m_LogList.CopySelectionToClipBoard();
3081 CString CLogDlg::GetAbsoluteUrlFromRelativeUrl(const CString& url)
3083 // is the URL a relative one?
3084 if (url.Left(2).Compare(_T("^/")) == 0)
3086 // URL is relative to the repository root
3087 CString url1 = m_sRepositoryRoot + url.Mid(1);
3088 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3089 DWORD len = url.GetLength();
3090 if (UrlCanonicalize((LPCTSTR)url1, buf, &len, 0) == S_OK)
3091 return CString(buf, len);
3092 return url1;
3094 else if (url[0] == '/')
3096 // URL is relative to the server's hostname
3097 CString sHost;
3098 // find the server's hostname
3099 int schemepos = m_sRepositoryRoot.Find(_T("//"));
3100 if (schemepos >= 0)
3102 sHost = m_sRepositoryRoot.Left(m_sRepositoryRoot.Find('/', schemepos+3));
3103 CString url1 = sHost + url;
3104 TCHAR buf[INTERNET_MAX_URL_LENGTH];
3105 DWORD len = url.GetLength();
3106 if (UrlCanonicalize((LPCTSTR)url, buf, &len, 0) == S_OK)
3107 return CString(buf, len);
3108 return url1;
3111 return url;
3115 void CLogDlg::OnEnChangeSearchedit()
3117 UpdateData();
3118 if (m_LogList.m_sFilterText.IsEmpty())
3120 CStoreSelection storeselection(this);
3121 // clear the filter, i.e. make all entries appear
3122 theApp.DoWaitCursor(1);
3123 KillTimer(LOGFILTER_TIMER);
3124 FillLogMessageCtrl(false);
3125 m_LogList.StartFilter();
3126 #if 0
3127 InterlockedExchange(&m_bNoDispUpdates, TRUE);
3128 m_arShownList.RemoveAll();
3129 for (DWORD i=0; i<m_logEntries.size(); ++i)
3131 if (IsEntryInDateRange(i))
3132 m_arShownList.Add(m_logEntries[i]);
3134 InterlockedExchange(&m_bNoDispUpdates, FALSE);
3135 m_LogList.DeleteAllItems();
3136 m_LogList.SetItemCountEx(ShownCountWithStopped());
3137 m_LogList.RedrawItems(0, ShownCountWithStopped());
3138 m_LogList.SetRedraw(false);
3139 ResizeAllListCtrlCols();
3140 m_LogList.SetRedraw(true);
3141 #endif
3142 theApp.DoWaitCursor(-1);
3143 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE);
3144 GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW);
3145 GetDlgItem(IDC_SEARCHEDIT)->SetFocus();
3146 DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty()))));
3147 return;
3149 if (Validate(m_LogList.m_sFilterText))
3150 SetTimer(LOGFILTER_TIMER, 1000, NULL);
3151 else
3152 KillTimer(LOGFILTER_TIMER);
3156 void CLogDlg::OnBnClickedAllBranch()
3158 this->UpdateData();
3160 if(this->m_bAllBranch)
3161 m_LogList.m_ShowMask|=CGit::LOG_INFO_ALL_BRANCH;
3162 else
3163 m_LogList.m_ShowMask&=~CGit::LOG_INFO_ALL_BRANCH;
3165 OnRefresh();
3167 FillLogMessageCtrl(false);
3170 void CLogDlg::OnBnClickedBrowseRef()
3172 CString newRef = CBrowseRefsDlg::PickRef(false,m_LogList.GetStartRef());
3173 if(newRef.IsEmpty())
3174 return;
3176 SetStartRef(newRef);
3177 ((CButton*)GetDlgItem(IDC_LOG_ALLBRANCH))->SetCheck(0);
3179 OnBnClickedAllBranch();
3182 void CLogDlg::ShowStartRef()
3184 //Show ref name on top
3185 if(!::IsWindow(m_hWnd))
3186 return;
3187 if(m_bAllBranch)
3189 m_staticRef.SetWindowText(L"<All Branches>");
3190 m_staticRef.Invalidate(TRUE);
3191 return;
3194 CString showStartRef = m_LogList.GetStartRef();
3195 if(showStartRef.IsEmpty())
3197 //Ref name is HEAD
3198 if( g_Git.Run(L"git symbolic-ref HEAD",&showStartRef,CP_UTF8) )
3199 showStartRef = _T("<No branch>");
3200 showStartRef.Trim(L"\r\n\t ");
3204 if(wcsncmp(showStartRef,L"refs/",5) == 0)
3205 showStartRef = showStartRef.Mid(5);
3206 if(wcsncmp(showStartRef,L"heads/",6) == 0)
3207 showStartRef = showStartRef.Mid(6);
3209 m_staticRef.SetWindowText(showStartRef);
3210 m_staticRef.Invalidate(TRUE);
3213 void CLogDlg::SetStartRef(const CString& StartRef)
3215 m_LogList.SetStartRef(StartRef);
3217 ShowStartRef();
3222 void CLogDlg::OnBnClickedFirstParent()
3224 this->UpdateData();
3226 if(this->m_bFirstParent)
3227 m_LogList.m_ShowMask|=CGit::LOG_INFO_FIRST_PARENT;
3228 else
3229 m_LogList.m_ShowMask&=~CGit::LOG_INFO_FIRST_PARENT;
3231 OnRefresh();
3233 FillLogMessageCtrl(false);
3237 void CLogDlg::OnBnClickShowWholeProject()
3239 this->UpdateData();
3241 if(this->m_bWholeProject)
3243 m_LogList.m_Path.Reset();
3244 SetWindowText(m_sTitle + _T(" - ") + CString(_T("Whole Project")));
3246 else
3248 m_LogList.m_Path=m_path;
3249 if(!m_path.IsEmpty())
3250 SetWindowText(m_sTitle + _T(" - ") + m_path.GetGitPathString());
3253 OnRefresh();
3255 FillLogMessageCtrl(false);