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
48 #include "CommitDlg.h"
\r
49 #include "RebaseDlg.h"
\r
51 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)
\r
53 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)
\r
55 POSITION pos = GetFirstSelectedItemPosition();
\r
56 int indexNext = GetNextSelectedItem(pos);
\r
60 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
\r
62 theApp.DoWaitCursor(1);
\r
63 bool bOpenWith = false;
\r
68 CString tempfile=GetTempFile();
\r
70 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
\r
71 cmd.Format(_T("git.exe diff-tree -r -p --stat %s"),r1->m_CommitHash);
\r
72 g_Git.RunLogFile(cmd,tempfile);
\r
73 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r1->m_Subject);
\r
79 CString tempfile=GetTempFile();
\r
81 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
\r
82 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
\r
83 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r1->m_CommitHash,r2->m_CommitHash);
\r
84 g_Git.RunLogFile(cmd,tempfile);
\r
85 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r2->m_CommitHash.Left(6));
\r
92 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
\r
93 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
\r
95 dlg.SetDiff(NULL,*r1,*r2);
\r
104 GitRev * r1 = &m_wcRev;
\r
105 GitRev * r2 = pSelLogEntry;
\r
107 dlg.SetDiff(NULL,*r1,*r2);
\r
110 //user clicked on the menu item "compare with working copy"
\r
111 //if (PromptShown())
\r
113 // GitDiff diff(this, m_hWnd, true);
\r
114 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
115 // diff.SetHEADPeg(m_LogRevision);
\r
116 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
\r
119 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
123 case ID_COMPAREWITHPREVIOUS:
\r
128 if(pSelLogEntry->m_ParentHash.size()>0)
\r
129 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
\r
131 dlg.SetDiff(NULL,pSelLogEntry->m_CommitHash,pSelLogEntry->m_ParentHash[0]);
\r
135 CMessageBox::Show(NULL,_T("No previous version"),_T("TortoiseGit"),MB_OK);
\r
137 //if (PromptShown())
\r
139 // GitDiff diff(this, m_hWnd, true);
\r
140 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
141 // diff.SetHEADPeg(m_LogRevision);
\r
142 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
\r
145 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
\r
148 case ID_COPYCLIPBOARD:
\r
150 CopySelectionToClipBoard();
\r
155 CopySelectionToClipBoard(TRUE);
\r
159 CAppUtils::Export(&pSelLogEntry->m_CommitHash);
\r
161 case ID_CREATE_BRANCH:
\r
162 CAppUtils::CreateBranchTag(FALSE,&pSelLogEntry->m_CommitHash);
\r
166 case ID_CREATE_TAG:
\r
167 CAppUtils::CreateBranchTag(TRUE,&pSelLogEntry->m_CommitHash);
\r
171 case ID_SWITCHTOREV:
\r
172 CAppUtils::Switch(&pSelLogEntry->m_CommitHash);
\r
177 CAppUtils::GitReset(&pSelLogEntry->m_CommitHash);
\r
181 case ID_REBASE_PICK:
\r
182 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
\r
184 case ID_REBASE_EDIT:
\r
185 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
\r
187 case ID_REBASE_SQUASH:
\r
188 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
\r
190 case ID_REBASE_SKIP:
\r
191 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
\r
193 case ID_COMBINE_COMMIT:
\r
198 head.Format(_T("HEAD~%d"),LastSelect);
\r
199 CString hash=g_Git.GetHash(head);
\r
200 hash=hash.Left(40);
\r
202 headhash=g_Git.GetHash(CString(_T("HEAD")));
\r
203 headhash=headhash.Left(40);
\r
205 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
\r
206 if(pLastEntry->m_CommitHash != hash)
\r
208 CMessageBox::Show(NULL,_T("Only combine top continuous commit"),_T("TortoiseGit"),MB_OK);
\r
210 if(!g_Git.CheckCleanWorkTree())
\r
212 CMessageBox::Show(NULL,_T("Combine need clean work tree"),_T("TortoiseGit"),MB_OK);
\r
217 cmd.Format(_T("git.exe reset --mixed %s"),hash);
\r
218 if(g_Git.Run(cmd,&out,CP_UTF8))
\r
220 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
\r
223 for(int i=FirstSelect;i<=LastSelect;i++)
\r
225 GitRev* pRev = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
\r
226 dlg.m_sLogMessage+=pRev->m_Subject+_T("\n")+pRev->m_Body;
\r
227 dlg.m_sLogMessage+=_T("\n");
\r
229 dlg.m_bWholeProject=true;
\r
230 dlg.m_bSelectFilesForCommit = true;
\r
231 dlg.m_bCommitAmend=true;
\r
232 dlg.m_AmendStr=dlg.m_sLogMessage;
\r
234 if (dlg.DoModal() == IDOK)
\r
239 cmd.Format(_T("git.exe reset --hard %s"),headhash);
\r
241 if(g_Git.Run(cmd,&out,CP_UTF8))
\r
243 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
\r
250 case ID_CHERRY_PICK:
\r
251 if(!g_Git.CheckCleanWorkTree())
\r
253 CMessageBox::Show(NULL,_T("Cherry Pick Require Clean Working Tree"),_T("TortoiseGit"),MB_OK);
\r
258 dlg.m_IsCherryPick = TRUE;
\r
259 dlg.m_Upstream = this->m_CurrentBranch;
\r
260 POSITION pos = GetFirstSelectedItemPosition();
\r
263 int indexNext = GetNextSelectedItem(pos);
\r
264 dlg.m_CommitList.m_logEntries.push_back(*(GitRev*)m_arShownList[indexNext]);
\r
265 dlg.m_CommitList.m_logEntries.at(dlg.m_CommitList.m_logEntries.size()-1).m_Action |= CTGitPath::LOGACTIONS_REBASE_PICK;
\r
268 if(dlg.DoModal() == IDOK)
\r
274 case ID_REBASE_TO_VERSION:
\r
275 if(!g_Git.CheckCleanWorkTree())
\r
277 CMessageBox::Show(NULL,_T("Rebase Require Clean Working Tree"),_T("TortoiseGit"),MB_OK);
\r
282 dlg.m_Upstream = pSelLogEntry->m_CommitHash;
\r
284 if(dlg.DoModal() == IDOK)
\r
293 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
\r
299 // we need an URL to complete this command, so error out if we can't get an URL
\r
300 if (pathURL.IsEmpty())
\r
302 CString strMessage;
\r
303 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
\r
304 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
\r
305 TRACE(_T("could not retrieve the URL of the folder!\n"));
\r
309 msg.Format(IDS_LOG_REVERT_CONFIRM, m_path.GetWinPath());
\r
310 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
\r
312 CGitProgressDlg dlg;
\r
313 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
\r
314 dlg.SetPathList(CTGitPathList(m_path));
\r
315 dlg.SetUrl(pathURL);
\r
316 dlg.SetSecondUrl(pathURL);
\r
317 revisionRanges.AdjustForMerge(true);
\r
318 dlg.SetRevisionRanges(revisionRanges);
\r
319 dlg.SetPegRevision(m_LogRevision);
\r
326 // we need an URL to complete this command, so error out if we can't get an URL
\r
327 if (pathURL.IsEmpty())
\r
329 CString strMessage;
\r
330 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
\r
331 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
\r
332 TRACE(_T("could not retrieve the URL of the folder!\n"));
\r
336 CString path = m_path.GetWinPathString();
\r
337 bool bGotSavePath = false;
\r
338 if ((GetSelectedCount() == 1)&&(!m_path.IsDirectory()))
\r
340 bGotSavePath = CAppUtils::FileOpenSave(path, NULL, IDS_LOG_MERGETO, IDS_COMMONFILEFILTER, true, GetSafeHwnd());
\r
344 CBrowseFolder folderBrowser;
\r
345 folderBrowser.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_MERGETO)));
\r
346 bGotSavePath = (folderBrowser.Show(GetSafeHwnd(), path, path) == CBrowseFolder::OK);
\r
350 CGitProgressDlg dlg;
\r
351 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
\r
352 dlg.SetPathList(CTGitPathList(CTGitPath(path)));
\r
353 dlg.SetUrl(pathURL);
\r
354 dlg.SetSecondUrl(pathURL);
\r
355 revisionRanges.AdjustForMerge(false);
\r
356 dlg.SetRevisionRanges(revisionRanges);
\r
357 dlg.SetPegRevision(m_LogRevision);
\r
362 case ID_REVERTTOREV:
\r
364 // we need an URL to complete this command, so error out if we can't get an URL
\r
365 if (pathURL.IsEmpty())
\r
367 CString strMessage;
\r
368 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
\r
369 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
\r
370 TRACE(_T("could not retrieve the URL of the folder!\n"));
\r
375 msg.Format(IDS_LOG_REVERTTOREV_CONFIRM, m_path.GetWinPath());
\r
376 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
\r
378 CGitProgressDlg dlg;
\r
379 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
\r
380 dlg.SetPathList(CTGitPathList(m_path));
\r
381 dlg.SetUrl(pathURL);
\r
382 dlg.SetSecondUrl(pathURL);
\r
383 GitRevRangeArray revarray;
\r
384 revarray.AddRevRange(GitRev::REV_HEAD, revSelected);
\r
385 dlg.SetRevisionRanges(revarray);
\r
386 dlg.SetPegRevision(m_LogRevision);
\r
394 case ID_BLAMECOMPARE:
\r
396 //user clicked on the menu item "compare with working copy"
\r
397 //now first get the revision which is selected
\r
400 GitDiff diff(this, this->m_hWnd, true);
\r
401 diff.SetHEADPeg(m_LogRevision);
\r
402 diff.ShowCompare(m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), false, true);
\r
405 CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), m_LogRevision, false, false, true);
\r
410 //user clicked on the menu item "compare and blame revisions"
\r
413 GitDiff diff(this, this->m_hWnd, true);
\r
414 diff.SetHEADPeg(m_LogRevision);
\r
415 diff.ShowCompare(CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), false, true);
\r
418 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
\r
421 case ID_BLAMEWITHPREVIOUS:
\r
423 //user clicked on the menu item "Compare and Blame with previous revision"
\r
426 GitDiff diff(this, this->m_hWnd, true);
\r
427 diff.SetHEADPeg(m_LogRevision);
\r
428 diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), false, true);
\r
431 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
\r
439 CProgressDlg progDlg;
\r
440 progDlg.SetTitle(IDS_APPNAME);
\r
441 progDlg.SetAnimation(IDR_DOWNLOAD);
\r
443 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, m_path.GetWinPath(), (LPCTSTR)revSelected.ToString());
\r
444 progDlg.SetLine(1, sInfoLine, true);
\r
445 SetAndClearProgressInfo(&progDlg);
\r
446 progDlg.ShowModeless(m_hWnd);
\r
447 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, m_path, revSelected);
\r
448 bool bSuccess = true;
\r
449 if (!Cat(m_path, GitRev(GitRev::REV_HEAD), revSelected, tempfile))
\r
452 // try again, but with the selected revision as the peg revision
\r
453 if (!Cat(m_path, revSelected, revSelected, tempfile))
\r
456 SetAndClearProgressInfo((HWND)NULL);
\r
457 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
\r
466 SetAndClearProgressInfo((HWND)NULL);
\r
467 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
\r
470 ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
\r
471 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
\r
473 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
\r
474 cmd += tempfile.GetWinPathString() + _T(" ");
\r
475 CAppUtils::LaunchApplication(cmd, NULL, false);
\r
483 dlg.EndRev = revSelected;
\r
484 if (dlg.DoModal() == IDOK)
\r
489 tempfile = blame.BlameToTempFile(m_path, dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
\r
490 if (!tempfile.IsEmpty())
\r
492 if (dlg.m_bTextView)
\r
494 //open the default text editor for the result file
\r
495 CAppUtils::StartTextViewer(tempfile);
\r
499 CString sParams = _T("/path:\"") + m_path.GetGitPathString() + _T("\" ");
\r
500 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(m_path.GetFileOrDirectoryName()),sParams))
\r
508 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
\r
516 CString url = _T("tgit:")+pathURL;
\r
517 sCmd.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
\r
518 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
519 (LPCTSTR)m_path.GetWinPath(), (LONG)revSelected);
\r
520 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
525 m_nSearchIndex = GetSelectionMark();
\r
526 if (m_nSearchIndex < 0)
\r
527 m_nSearchIndex = 0;
\r
534 m_pFindDialog = new CFindReplaceDialog();
\r
535 m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this);
\r
539 case ID_REPOBROWSE:
\r
542 sCmd.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
\r
543 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
544 (LPCTSTR)pathURL, (LPCTSTR)revSelected.ToString());
\r
546 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
551 EditLogMessage(selIndex);
\r
554 case ID_EDITAUTHOR:
\r
556 EditAuthor(selEntries);
\r
561 CEditPropertiesDlg dlg;
\r
562 dlg.SetProjectProperties(&m_ProjectProperties);
\r
563 CTGitPathList escapedlist;
\r
564 dlg.SetPathList(CTGitPathList(CTGitPath(pathURL)));
\r
565 dlg.SetRevision(revSelected);
\r
566 dlg.RevProps(true);
\r
574 sCmd.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
\r
575 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
576 (LPCTSTR)pathURL, (LONG)revSelected);
\r
577 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
583 CString url = _T("tgit:")+pathURL;
\r
584 sCmd.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
\r
585 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
\r
586 (LPCTSTR)url, (LONG)revSelected);
\r
587 CAppUtils::LaunchApplication(sCmd, NULL, false);
\r
592 CString url = m_ProjectProperties.sWebViewerRev;
\r
593 url = GetAbsoluteUrlFromRelativeUrl(url);
\r
594 url.Replace(_T("%REVISION%"), revSelected.ToString());
\r
595 if (!url.IsEmpty())
\r
596 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
\r
599 case ID_VIEWPATHREV:
\r
601 CString relurl = pathURL;
\r
602 CString sRoot = GetRepositoryRoot(CTGitPath(relurl));
\r
603 relurl = relurl.Mid(sRoot.GetLength());
\r
604 CString url = m_ProjectProperties.sWebViewerPathRev;
\r
605 url = GetAbsoluteUrlFromRelativeUrl(url);
\r
606 url.Replace(_T("%REVISION%"), revSelected.ToString());
\r
607 url.Replace(_T("%PATH%"), relurl);
\r
608 if (!url.IsEmpty())
\r
609 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
\r
616 theApp.DoWaitCursor(-1);
\r
619 void CGitLogList::SetSelectedAction(int action)
\r
621 POSITION pos = GetFirstSelectedItemPosition();
\r
625 index = GetNextSelectedItem(pos);
\r
626 ((GitRev*)m_arShownList[index])->m_Action = action;
\r
628 this->GetItemRect(index,&rect,LVIR_BOUNDS);
\r
629 this->InvalidateRect(rect);
\r