1 // GitLogList.cpp : implementation file
\r
4 Description: qgit revision list view
\r
6 Author: Marco Costalba (C) 2005-2007
\r
8 Copyright: See COPYING file that comes with this distribution
\r
12 #include "TortoiseProc.h"
\r
13 #include "GitLogList.h"
\r
15 //#include "VssStyle.h"
\r
16 #include "IconMenu.h"
\r
19 #include "InputDlg.h"
\r
20 #include "PropDlg.h"
\r
21 #include "SVNProgressDlg.h"
\r
22 #include "ProgressDlg.h"
\r
23 //#include "RepositoryBrowser.h"
\r
24 //#include "CopyDlg.h"
\r
25 //#include "StatGraphDlg.h"
\r
27 #include "MessageBox.h"
\r
28 #include "Registry.h"
\r
29 #include "AppUtils.h"
\r
30 #include "PathUtils.h"
\r
31 #include "StringUtils.h"
\r
32 #include "UnicodeUtils.h"
\r
33 #include "TempFile.h"
\r
34 //#include "GitInfo.h"
\r
35 //#include "GitDiff.h"
\r
36 #include "IconMenu.h"
\r
37 //#include "RevisionRangeDlg.h"
\r
38 //#include "BrowseFolder.h"
\r
39 //#include "BlameDlg.h"
\r
40 //#include "Blame.h"
\r
41 //#include "GitHelpers.h"
\r
42 #include "GitStatus.h"
\r
43 //#include "LogDlgHelper.h"
\r
44 //#include "CachedLogInfo.h"
\r
45 //#include "RepositoryInfo.h"
\r
46 //#include "EditPropertiesDlg.h"
\r
47 #include "FileDiffDlg.h"
\r
49 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)
\r
51 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)
\r
53 POSITION pos = GetFirstSelectedItemPosition();
\r
54 int indexNext = GetNextSelectedItem(pos);
\r
58 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
\r
60 theApp.DoWaitCursor(1);
\r
61 bool bOpenWith = false;
\r
66 CString tempfile=GetTempFile();
\r
68 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
\r
69 cmd.Format(_T("git.exe diff-tree -r -p --stat %s"),r1->m_CommitHash);
\r
70 g_Git.RunLogFile(cmd,tempfile);
\r
71 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r1->m_Subject);
\r
77 CString tempfile=GetTempFile();
\r
79 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
\r
80 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
\r
81 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r1->m_CommitHash,r2->m_CommitHash);
\r
82 g_Git.RunLogFile(cmd,tempfile);
\r
83 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r2->m_CommitHash.Left(6));
\r
90 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
\r
91 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
\r
93 dlg.SetDiff(NULL,*r1,*r2);
\r
102 GitRev * r1 = &m_wcRev;
\r
103 GitRev * r2 = pSelLogEntry;
\r
105 dlg.SetDiff(NULL,*r1,*r2);
\r
108 //user clicked on the menu item "compare with working copy"
\r
109 //if (PromptShown())
\r
111 // GitDiff diff(this, m_hWnd, true);
\r
112 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
113 // diff.SetHEADPeg(m_LogRevision);
\r
114 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
\r
117 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
121 case ID_COMPAREWITHPREVIOUS:
\r
126 if(pSelLogEntry->m_ParentHash.size()>0)
\r
127 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
\r
129 dlg.SetDiff(NULL,pSelLogEntry->m_CommitHash,pSelLogEntry->m_ParentHash[0]);
\r
133 CMessageBox::Show(NULL,_T("No previous version"),_T("TortoiseGit"),MB_OK);
\r
135 //if (PromptShown())
\r
137 // GitDiff diff(this, m_hWnd, true);
\r
138 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
139 // diff.SetHEADPeg(m_LogRevision);
\r
140 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
\r
143 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
146 case ID_COPYCLIPBOARD:
\r
148 CopySelectionToClipBoard();
\r
153 CopySelectionToClipBoard(TRUE);
\r
157 CAppUtils::Export(&pSelLogEntry->m_CommitHash);
\r
159 case ID_CREATE_BRANCH:
\r
160 CAppUtils::CreateBranchTag(FALSE,&pSelLogEntry->m_CommitHash);
\r
164 case ID_CREATE_TAG:
\r
165 CAppUtils::CreateBranchTag(TRUE,&pSelLogEntry->m_CommitHash);
\r
169 case ID_SWITCHTOREV:
\r
170 CAppUtils::Switch(&pSelLogEntry->m_CommitHash);
\r
175 CAppUtils::GitReset(&pSelLogEntry->m_CommitHash);
\r
179 case ID_REBASE_PICK:
\r
180 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
\r
182 case ID_REBASE_EDIT:
\r
183 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
\r
185 case ID_REBASE_SQUASH:
\r
186 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
\r
188 case ID_REBASE_SKIP:
\r
189 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
\r
192 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
\r
198 // we need an URL to complete this command, so error out if we can't get an URL
\r
199 if (pathURL.IsEmpty())
\r
201 CString strMessage;
\r
202 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
\r
203 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
\r
204 TRACE(_T("could not retrieve the URL of the folder!\n"));
\r
208 msg.Format(IDS_LOG_REVERT_CONFIRM, m_path.GetWinPath());
\r
209 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
\r
211 CGitProgressDlg dlg;
\r
212 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
\r
213 dlg.SetPathList(CTGitPathList(m_path));
\r
214 dlg.SetUrl(pathURL);
\r
215 dlg.SetSecondUrl(pathURL);
\r
216 revisionRanges.AdjustForMerge(true);
\r
217 dlg.SetRevisionRanges(revisionRanges);
\r
218 dlg.SetPegRevision(m_LogRevision);
\r
225 // we need an URL to complete this command, so error out if we can't get an URL
\r
226 if (pathURL.IsEmpty())
\r
228 CString strMessage;
\r
229 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
\r
230 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
\r
231 TRACE(_T("could not retrieve the URL of the folder!\n"));
\r
235 CString path = m_path.GetWinPathString();
\r
236 bool bGotSavePath = false;
\r
237 if ((GetSelectedCount() == 1)&&(!m_path.IsDirectory()))
\r
239 bGotSavePath = CAppUtils::FileOpenSave(path, NULL, IDS_LOG_MERGETO, IDS_COMMONFILEFILTER, true, GetSafeHwnd());
\r
243 CBrowseFolder folderBrowser;
\r
244 folderBrowser.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_MERGETO)));
\r
245 bGotSavePath = (folderBrowser.Show(GetSafeHwnd(), path, path) == CBrowseFolder::OK);
\r
249 CGitProgressDlg dlg;
\r
250 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
\r
251 dlg.SetPathList(CTGitPathList(CTGitPath(path)));
\r
252 dlg.SetUrl(pathURL);
\r
253 dlg.SetSecondUrl(pathURL);
\r
254 revisionRanges.AdjustForMerge(false);
\r
255 dlg.SetRevisionRanges(revisionRanges);
\r
256 dlg.SetPegRevision(m_LogRevision);
\r
261 case ID_REVERTTOREV:
\r
263 // we need an URL to complete this command, so error out if we can't get an URL
\r
264 if (pathURL.IsEmpty())
\r
266 CString strMessage;
\r
267 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
\r
268 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
\r
269 TRACE(_T("could not retrieve the URL of the folder!\n"));
\r
274 msg.Format(IDS_LOG_REVERTTOREV_CONFIRM, m_path.GetWinPath());
\r
275 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
\r
277 CGitProgressDlg dlg;
\r
278 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
\r
279 dlg.SetPathList(CTGitPathList(m_path));
\r
280 dlg.SetUrl(pathURL);
\r
281 dlg.SetSecondUrl(pathURL);
\r
282 GitRevRangeArray revarray;
\r
283 revarray.AddRevRange(GitRev::REV_HEAD, revSelected);
\r
284 dlg.SetRevisionRanges(revarray);
\r
285 dlg.SetPegRevision(m_LogRevision);
\r
293 case ID_BLAMECOMPARE:
\r
295 //user clicked on the menu item "compare with working copy"
\r
296 //now first get the revision which is selected
\r
299 GitDiff diff(this, this->m_hWnd, true);
\r
300 diff.SetHEADPeg(m_LogRevision);
\r
301 diff.ShowCompare(m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), false, true);
\r
304 CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), m_LogRevision, false, false, true);
\r
309 //user clicked on the menu item "compare and blame revisions"
\r
312 GitDiff diff(this, this->m_hWnd, true);
\r
313 diff.SetHEADPeg(m_LogRevision);
\r
314 diff.ShowCompare(CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), false, true);
\r
317 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
\r
320 case ID_BLAMEWITHPREVIOUS:
\r
322 //user clicked on the menu item "Compare and Blame with previous revision"
\r
325 GitDiff diff(this, this->m_hWnd, true);
\r
326 diff.SetHEADPeg(m_LogRevision);
\r
327 diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), false, true);
\r
330 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
\r
338 CProgressDlg progDlg;
\r
339 progDlg.SetTitle(IDS_APPNAME);
\r
340 progDlg.SetAnimation(IDR_DOWNLOAD);
\r
342 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, m_path.GetWinPath(), (LPCTSTR)revSelected.ToString());
\r
343 progDlg.SetLine(1, sInfoLine, true);
\r
344 SetAndClearProgressInfo(&progDlg);
\r
345 progDlg.ShowModeless(m_hWnd);
\r
346 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, m_path, revSelected);
\r
347 bool bSuccess = true;
\r
348 if (!Cat(m_path, GitRev(GitRev::REV_HEAD), revSelected, tempfile))
\r
351 // try again, but with the selected revision as the peg revision
\r
352 if (!Cat(m_path, revSelected, revSelected, tempfile))
\r
355 SetAndClearProgressInfo((HWND)NULL);
\r
356 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
\r
365 SetAndClearProgressInfo((HWND)NULL);
\r
366 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
\r
369 ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
\r
370 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
\r
372 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
\r
373 cmd += tempfile.GetWinPathString() + _T(" ");
\r
374 CAppUtils::LaunchApplication(cmd, NULL, false);
\r
382 dlg.EndRev = revSelected;
\r
383 if (dlg.DoModal() == IDOK)
\r
388 tempfile = blame.BlameToTempFile(m_path, dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
\r
389 if (!tempfile.IsEmpty())
\r
391 if (dlg.m_bTextView)
\r
393 //open the default text editor for the result file
\r
394 CAppUtils::StartTextViewer(tempfile);
\r
398 CString sParams = _T("/path:\"") + m_path.GetGitPathString() + _T("\" ");
\r
399 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(m_path.GetFileOrDirectoryName()),sParams))
\r
407 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
\r
415 CString url = _T("tgit:")+pathURL;
\r
416 sCmd.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
\r
417 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
418 (LPCTSTR)m_path.GetWinPath(), (LONG)revSelected);
\r
419 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
424 m_nSearchIndex = GetSelectionMark();
\r
425 if (m_nSearchIndex < 0)
\r
426 m_nSearchIndex = 0;
\r
433 m_pFindDialog = new CFindReplaceDialog();
\r
434 m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this);
\r
438 case ID_REPOBROWSE:
\r
441 sCmd.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
\r
442 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
443 (LPCTSTR)pathURL, (LPCTSTR)revSelected.ToString());
\r
445 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
450 EditLogMessage(selIndex);
\r
453 case ID_EDITAUTHOR:
\r
455 EditAuthor(selEntries);
\r
460 CEditPropertiesDlg dlg;
\r
461 dlg.SetProjectProperties(&m_ProjectProperties);
\r
462 CTGitPathList escapedlist;
\r
463 dlg.SetPathList(CTGitPathList(CTGitPath(pathURL)));
\r
464 dlg.SetRevision(revSelected);
\r
465 dlg.RevProps(true);
\r
473 sCmd.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
\r
474 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
475 (LPCTSTR)pathURL, (LONG)revSelected);
\r
476 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
482 CString url = _T("tgit:")+pathURL;
\r
483 sCmd.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
\r
484 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
485 (LPCTSTR)url, (LONG)revSelected);
\r
486 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
491 CString url = m_ProjectProperties.sWebViewerRev;
\r
492 url = GetAbsoluteUrlFromRelativeUrl(url);
\r
493 url.Replace(_T("%REVISION%"), revSelected.ToString());
\r
494 if (!url.IsEmpty())
\r
495 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
\r
498 case ID_VIEWPATHREV:
\r
500 CString relurl = pathURL;
\r
501 CString sRoot = GetRepositoryRoot(CTGitPath(relurl));
\r
502 relurl = relurl.Mid(sRoot.GetLength());
\r
503 CString url = m_ProjectProperties.sWebViewerPathRev;
\r
504 url = GetAbsoluteUrlFromRelativeUrl(url);
\r
505 url.Replace(_T("%REVISION%"), revSelected.ToString());
\r
506 url.Replace(_T("%PATH%"), relurl);
\r
507 if (!url.IsEmpty())
\r
508 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
\r
515 theApp.DoWaitCursor(-1);
\r
518 void CGitLogList::SetSelectedAction(int action)
\r
520 POSITION pos = GetFirstSelectedItemPosition();
\r
524 index = GetNextSelectedItem(pos);
\r
525 ((GitRev*)m_arShownList[index])->m_Action = action;
\r
527 this->GetItemRect(index,&rect,LVIR_BOUNDS);
\r
528 this->InvalidateRect(rect);
\r