Initial version of BrowseRefsDlg
[TortoiseGit.git] / src / TortoiseProc / GitLogListAction.cpp
blob63c33cf080dad2367d8db5a4895c1b029dce998c
1 // GitLogList.cpp : implementation file
2 //
3 /*
4 Description: qgit revision list view
6 Author: Marco Costalba (C) 2005-2007
8 Copyright: See COPYING file that comes with this distribution
11 #include "stdafx.h"
12 #include "TortoiseProc.h"
13 #include "GitLogList.h"
14 #include "GitRev.h"
15 //#include "VssStyle.h"
16 #include "IconMenu.h"
17 // CGitLogList
18 #include "cursor.h"
19 #include "InputDlg.h"
20 #include "PropDlg.h"
21 #include "SVNProgressDlg.h"
22 #include "ProgressDlg.h"
23 #include "SysProgressDlg.h"
24 //#include "RepositoryBrowser.h"
25 //#include "CopyDlg.h"
26 //#include "StatGraphDlg.h"
27 #include "Logdlg.h"
28 #include "MessageBox.h"
29 #include "Registry.h"
30 #include "AppUtils.h"
31 #include "PathUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
34 #include "TempFile.h"
35 //#include "GitInfo.h"
36 //#include "GitDiff.h"
37 #include "IconMenu.h"
38 //#include "RevisionRangeDlg.h"
39 //#include "BrowseFolder.h"
40 //#include "BlameDlg.h"
41 //#include "Blame.h"
42 //#include "GitHelpers.h"
43 #include "GitStatus.h"
44 //#include "LogDlgHelper.h"
45 //#include "CachedLogInfo.h"
46 //#include "RepositoryInfo.h"
47 //#include "EditPropertiesDlg.h"
48 #include "FileDiffDlg.h"
49 #include "CommitDlg.h"
50 #include "RebaseDlg.h"
52 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)
54 int CGitLogList::CherryPickFrom(CString from, CString to)
56 CLogDataVector logs;
57 if(logs.ParserFromLog(NULL,-1,0,&from,&to))
58 return -1;
60 if(logs.size() == 0)
61 return 0;
63 CSysProgressDlg progress;
64 if (progress.IsValid())
66 progress.SetTitle(_T("Cherry Pick"));
67 progress.SetAnimation(IDR_MOVEANI);
68 progress.SetTime(true);
69 progress.ShowModeless(this);
72 for(int i=logs.size()-1;i>=0;i--)
74 if (progress.IsValid())
76 progress.FormatPathLine(1, _T("Pick up %s"), logs[i].m_CommitHash);
77 progress.FormatPathLine(2, _T("%s"), logs[i].m_Subject);
78 progress.SetProgress(logs.size()-i, logs.size());
80 if ((progress.IsValid())&&(progress.HasUserCancelled()))
82 //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
83 throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));
84 return -1;
86 CString cmd,out;
87 cmd.Format(_T("git.exe cherry-pick %s"),logs[i].m_CommitHash);
88 out.Empty();
89 if(g_Git.Run(cmd,&out,CP_UTF8))
91 throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out));
92 return -1;
96 return 0;
99 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect)
101 POSITION pos = GetFirstSelectedItemPosition();
102 int indexNext = GetNextSelectedItem(pos);
103 if (indexNext < 0)
104 return;
106 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
108 theApp.DoWaitCursor(1);
109 bool bOpenWith = false;
110 switch (cmd)
112 case ID_GNUDIFF1:
114 CString tempfile=GetTempFile();
115 CString cmd;
116 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
117 cmd.Format(_T("git.exe diff-tree -r -p --stat %s"),r1->m_CommitHash);
118 g_Git.RunLogFile(cmd,tempfile);
119 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r1->m_Subject);
121 break;
123 case ID_GNUDIFF2:
125 CString tempfile=GetTempFile();
126 CString cmd;
127 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
128 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
129 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r1->m_CommitHash,r2->m_CommitHash);
130 g_Git.RunLogFile(cmd,tempfile);
131 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r2->m_CommitHash.Left(6));
134 break;
136 case ID_COMPARETWO:
138 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
139 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
140 CFileDiffDlg dlg;
141 dlg.SetDiff(NULL,*r1,*r2);
142 dlg.DoModal();
145 break;
148 case ID_COMPARE:
150 GitRev * r1 = &m_wcRev;
151 GitRev * r2 = pSelLogEntry;
152 CFileDiffDlg dlg;
153 dlg.SetDiff(NULL,*r1,*r2);
154 dlg.DoModal();
156 //user clicked on the menu item "compare with working copy"
157 //if (PromptShown())
159 // GitDiff diff(this, m_hWnd, true);
160 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
161 // diff.SetHEADPeg(m_LogRevision);
162 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
164 //else
165 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
167 break;
169 case ID_COMPAREWITHPREVIOUS:
172 CFileDiffDlg dlg;
174 if(pSelLogEntry->m_ParentHash.size()>0)
175 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
177 dlg.SetDiff(NULL,pSelLogEntry->m_CommitHash,pSelLogEntry->m_ParentHash[0]);
178 dlg.DoModal();
179 }else
181 CMessageBox::Show(NULL,_T("No previous version"),_T("TortoiseGit"),MB_OK);
183 //if (PromptShown())
185 // GitDiff diff(this, m_hWnd, true);
186 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
187 // diff.SetHEADPeg(m_LogRevision);
188 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
190 //else
191 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
193 break;
194 case ID_COPYCLIPBOARD:
196 CopySelectionToClipBoard();
198 break;
199 case ID_COPYHASH:
201 CopySelectionToClipBoard(TRUE);
203 break;
204 case ID_EXPORT:
205 CAppUtils::Export(&pSelLogEntry->m_CommitHash);
206 break;
207 case ID_CREATE_BRANCH:
208 CAppUtils::CreateBranchTag(FALSE,&pSelLogEntry->m_CommitHash);
209 ReloadHashMap();
210 Invalidate();
211 break;
212 case ID_CREATE_TAG:
213 CAppUtils::CreateBranchTag(TRUE,&pSelLogEntry->m_CommitHash);
214 ReloadHashMap();
215 Invalidate();
216 break;
217 case ID_SWITCHTOREV:
218 CAppUtils::Switch(&pSelLogEntry->m_CommitHash);
219 ReloadHashMap();
220 Invalidate();
221 break;
222 case ID_RESET:
223 CAppUtils::GitReset(&pSelLogEntry->m_CommitHash);
224 ReloadHashMap();
225 Invalidate();
226 break;
227 case ID_REBASE_PICK:
228 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
229 break;
230 case ID_REBASE_EDIT:
231 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
232 break;
233 case ID_REBASE_SQUASH:
234 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
235 break;
236 case ID_REBASE_SKIP:
237 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
238 break;
239 case ID_COMBINE_COMMIT:
241 CString head;
242 CString headhash;
243 CString hashFirst,hashLast;
245 int headindex=GetHeadIndex();
246 if(headindex>=0) //incase show all branch, head is not the first commits.
248 head.Format(_T("HEAD~%d"),FirstSelect-headindex);
249 hashFirst=g_Git.GetHash(head);
251 head.Format(_T("HEAD~%d"),LastSelect-headindex);
252 hashLast=g_Git.GetHash(head);
255 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
256 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
257 if(pFirstEntry->m_CommitHash != hashFirst || pLastEntry->m_CommitHash != hashLast)
259 CMessageBox::Show(NULL,_T(
260 "Cannot combine commits now.\r\n\
261 Make sure you are viewing the log of your current branch and \
262 no filters are applied."),_T("TortoiseGit"),MB_OK);
263 break;
266 headhash=g_Git.GetHash(CString(_T("HEAD")));
268 if(!g_Git.CheckCleanWorkTree())
270 CMessageBox::Show(NULL,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK);
271 break;
273 CString cmd,out;
275 //Use throw to abort this process (reset back to original HEAD)
278 cmd.Format(_T("git.exe reset --hard %s"),pFirstEntry->m_CommitHash);
279 if(g_Git.Run(cmd,&out,CP_UTF8))
281 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
282 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out));
284 cmd.Format(_T("git.exe reset --mixed %s"),hashLast);
285 if(g_Git.Run(cmd,&out,CP_UTF8))
287 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
288 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out));
290 CCommitDlg dlg;
291 for(int i=FirstSelect;i<=LastSelect;i++)
293 GitRev* pRev = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
294 dlg.m_sLogMessage+=pRev->m_Subject+_T("\n")+pRev->m_Body;
295 dlg.m_sLogMessage+=_T("\n");
297 dlg.m_bWholeProject=true;
298 dlg.m_bSelectFilesForCommit = true;
299 dlg.m_bCommitAmend=true;
300 dlg.m_AmendStr=dlg.m_sLogMessage;
302 bool abort=false;
303 if (dlg.DoModal() == IDOK)
305 if(pFirstEntry->m_CommitHash!=headhash)
307 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
308 //on top of new commit.
309 //Use the rebase --onto command for it.
311 //All this can be done in one step using the following command:
312 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
313 // pFirstEntry->m_CommitHash,
314 // headhash);
315 //But I am not sure if a '|' is going to work in a CreateProcess() call.
317 //Later the progress dialog could be used to execute these steps.
319 if(CherryPickFrom(pFirstEntry->m_CommitHash,headhash))
321 CString msg;
322 msg.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
323 throw std::exception(CUnicodeUtils::GetUTF8(msg));
325 #if 0
326 CString currentBranch=g_Git.GetCurrentBranch();
327 cmd.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
328 currentBranch,
329 pFirstEntry->m_CommitHash,
330 headhash);
331 if(g_Git.Run(cmd,&out,CP_UTF8)!=0)
333 CString msg;
334 msg.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out);
335 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
336 g_Git.Run(_T("git.exe rebase --abort"),&out,CP_UTF8);
337 throw std::exception(CUnicodeUtils::GetUTF8(msg));
340 //HEAD is now on <no branch>.
341 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
342 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
343 //And then git checkout <original branch>
344 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
346 //Store new HEAD
347 CString newHead=g_Git.GetHash(CString(_T("HEAD")));
349 //Checkout working branch
350 cmd.Format(_T("git.exe checkout -f \"%s\""),currentBranch);
351 if(g_Git.Run(cmd,&out,CP_UTF8))
352 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out));
354 //Reset to new HEAD
355 cmd.Format(_T("git.exe reset --hard %s"),newHead);
356 if(g_Git.Run(cmd,&out,CP_UTF8))
357 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out));
358 #endif
361 else
362 throw std::exception("User aborted the combine process");
364 catch(std::exception& e)
366 CMessageBox::Show(NULL,CUnicodeUtils::GetUnicode(CStringA(e.what())),_T("TortoiseGit: Combine error"),MB_OK|MB_ICONERROR);
367 cmd.Format(_T("git.exe reset --hard %s"),headhash);
368 out.Empty();
369 if(g_Git.Run(cmd,&out,CP_UTF8))
371 CMessageBox::Show(NULL,_T("Could not reset to original HEAD\r\n\r\n")+out,_T("TortoiseGit"),MB_OK);
374 Refresh();
376 break;
378 case ID_CHERRY_PICK:
379 if(!g_Git.CheckCleanWorkTree())
381 CMessageBox::Show(NULL,_T("Cherry Pick Require Clean Working Tree"),_T("TortoiseGit"),MB_OK);
383 }else
385 CRebaseDlg dlg;
386 dlg.m_IsCherryPick = TRUE;
387 dlg.m_Upstream = this->m_CurrentBranch;
388 POSITION pos = GetFirstSelectedItemPosition();
389 while(pos)
391 int indexNext = GetNextSelectedItem(pos);
392 dlg.m_CommitList.m_logEntries.push_back(*(GitRev*)m_arShownList[indexNext]);
393 dlg.m_CommitList.m_logEntries.at(dlg.m_CommitList.m_logEntries.size()-1).m_Action |= CTGitPath::LOGACTIONS_REBASE_PICK;
396 if(dlg.DoModal() == IDOK)
398 Refresh();
401 break;
402 case ID_REBASE_TO_VERSION:
403 if(!g_Git.CheckCleanWorkTree())
405 CMessageBox::Show(NULL,_T("Rebase Require Clean Working Tree"),_T("TortoiseGit"),MB_OK);
407 }else
409 CRebaseDlg dlg;
410 dlg.m_Upstream = pSelLogEntry->m_CommitHash;
412 if(dlg.DoModal() == IDOK)
414 Refresh();
418 break;
420 case ID_STASH_APPLY:
421 CAppUtils::StashApply(pSelLogEntry->m_Ref);
422 break;
424 case ID_REFLOG_DEL:
426 CString str;
427 str.Format(_T("Warning: %s will be deleted. It can <ct=0x0000FF><b>NOT</b></ct> recovered,\r\n \r\n Are you sure delete these?"),pSelLogEntry->m_Ref);
428 if(CMessageBox::Show(NULL,str,_T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
430 CString cmd,out;
431 cmd.Format(_T("git.exe reflog delete %s"),pSelLogEntry->m_Ref);
432 if(g_Git.Run(cmd,&out,CP_ACP))
434 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
436 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
439 break;
440 default:
441 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
442 break;
443 #if 0
445 case ID_REVERTREV:
447 // we need an URL to complete this command, so error out if we can't get an URL
448 if (pathURL.IsEmpty())
450 CString strMessage;
451 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
452 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
453 TRACE(_T("could not retrieve the URL of the folder!\n"));
454 break; //exit
456 CString msg;
457 msg.Format(IDS_LOG_REVERT_CONFIRM, m_path.GetWinPath());
458 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
460 CGitProgressDlg dlg;
461 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
462 dlg.SetPathList(CTGitPathList(m_path));
463 dlg.SetUrl(pathURL);
464 dlg.SetSecondUrl(pathURL);
465 revisionRanges.AdjustForMerge(true);
466 dlg.SetRevisionRanges(revisionRanges);
467 dlg.SetPegRevision(m_LogRevision);
468 dlg.DoModal();
471 break;
472 case ID_MERGEREV:
474 // we need an URL to complete this command, so error out if we can't get an URL
475 if (pathURL.IsEmpty())
477 CString strMessage;
478 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
479 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
480 TRACE(_T("could not retrieve the URL of the folder!\n"));
481 break; //exit
484 CString path = m_path.GetWinPathString();
485 bool bGotSavePath = false;
486 if ((GetSelectedCount() == 1)&&(!m_path.IsDirectory()))
488 bGotSavePath = CAppUtils::FileOpenSave(path, NULL, IDS_LOG_MERGETO, IDS_COMMONFILEFILTER, true, GetSafeHwnd());
490 else
492 CBrowseFolder folderBrowser;
493 folderBrowser.SetInfo(CString(MAKEINTRESOURCE(IDS_LOG_MERGETO)));
494 bGotSavePath = (folderBrowser.Show(GetSafeHwnd(), path, path) == CBrowseFolder::OK);
496 if (bGotSavePath)
498 CGitProgressDlg dlg;
499 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
500 dlg.SetPathList(CTGitPathList(CTGitPath(path)));
501 dlg.SetUrl(pathURL);
502 dlg.SetSecondUrl(pathURL);
503 revisionRanges.AdjustForMerge(false);
504 dlg.SetRevisionRanges(revisionRanges);
505 dlg.SetPegRevision(m_LogRevision);
506 dlg.DoModal();
509 break;
510 case ID_REVERTTOREV:
512 // we need an URL to complete this command, so error out if we can't get an URL
513 if (pathURL.IsEmpty())
515 CString strMessage;
516 strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString()));
517 CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR);
518 TRACE(_T("could not retrieve the URL of the folder!\n"));
519 break; //exit
522 CString msg;
523 msg.Format(IDS_LOG_REVERTTOREV_CONFIRM, m_path.GetWinPath());
524 if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
526 CGitProgressDlg dlg;
527 dlg.SetCommand(CGitProgressDlg::GitProgress_Merge);
528 dlg.SetPathList(CTGitPathList(m_path));
529 dlg.SetUrl(pathURL);
530 dlg.SetSecondUrl(pathURL);
531 GitRevRangeArray revarray;
532 revarray.AddRevRange(GitRev::REV_HEAD, revSelected);
533 dlg.SetRevisionRanges(revarray);
534 dlg.SetPegRevision(m_LogRevision);
535 dlg.DoModal();
538 break;
542 case ID_BLAMECOMPARE:
544 //user clicked on the menu item "compare with working copy"
545 //now first get the revision which is selected
546 if (PromptShown())
548 GitDiff diff(this, this->m_hWnd, true);
549 diff.SetHEADPeg(m_LogRevision);
550 diff.ShowCompare(m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), false, true);
552 else
553 CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), m_LogRevision, false, false, true);
555 break;
556 case ID_BLAMETWO:
558 //user clicked on the menu item "compare and blame revisions"
559 if (PromptShown())
561 GitDiff diff(this, this->m_hWnd, true);
562 diff.SetHEADPeg(m_LogRevision);
563 diff.ShowCompare(CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), false, true);
565 else
566 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
568 break;
569 case ID_BLAMEWITHPREVIOUS:
571 //user clicked on the menu item "Compare and Blame with previous revision"
572 if (PromptShown())
574 GitDiff diff(this, this->m_hWnd, true);
575 diff.SetHEADPeg(m_LogRevision);
576 diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), false, true);
578 else
579 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
581 break;
583 case ID_OPENWITH:
584 bOpenWith = true;
585 case ID_OPEN:
587 CProgressDlg progDlg;
588 progDlg.SetTitle(IDS_APPNAME);
589 progDlg.SetAnimation(IDR_DOWNLOAD);
590 CString sInfoLine;
591 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, m_path.GetWinPath(), (LPCTSTR)revSelected.ToString());
592 progDlg.SetLine(1, sInfoLine, true);
593 SetAndClearProgressInfo(&progDlg);
594 progDlg.ShowModeless(m_hWnd);
595 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, m_path, revSelected);
596 bool bSuccess = true;
597 if (!Cat(m_path, GitRev(GitRev::REV_HEAD), revSelected, tempfile))
599 bSuccess = false;
600 // try again, but with the selected revision as the peg revision
601 if (!Cat(m_path, revSelected, revSelected, tempfile))
603 progDlg.Stop();
604 SetAndClearProgressInfo((HWND)NULL);
605 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
606 EnableOKButton();
607 break;
609 bSuccess = true;
611 if (bSuccess)
613 progDlg.Stop();
614 SetAndClearProgressInfo((HWND)NULL);
615 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
616 int ret = 0;
617 if (!bOpenWith)
618 ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
619 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
621 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
622 cmd += tempfile.GetWinPathString() + _T(" ");
623 CAppUtils::LaunchApplication(cmd, NULL, false);
627 break;
628 case ID_BLAME:
630 CBlameDlg dlg;
631 dlg.EndRev = revSelected;
632 if (dlg.DoModal() == IDOK)
634 CBlame blame;
635 CString tempfile;
636 CString logfile;
637 tempfile = blame.BlameToTempFile(m_path, dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
638 if (!tempfile.IsEmpty())
640 if (dlg.m_bTextView)
642 //open the default text editor for the result file
643 CAppUtils::StartTextViewer(tempfile);
645 else
647 CString sParams = _T("/path:\"") + m_path.GetGitPathString() + _T("\" ");
648 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(m_path.GetFileOrDirectoryName()),sParams))
650 break;
654 else
656 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
660 break;
661 case ID_UPDATE:
663 CString sCmd;
664 CString url = _T("tgit:")+pathURL;
665 sCmd.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
666 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
667 (LPCTSTR)m_path.GetWinPath(), (LONG)revSelected);
668 CAppUtils::LaunchApplication(sCmd, NULL, false);
670 break;
671 case ID_FINDENTRY:
673 m_nSearchIndex = GetSelectionMark();
674 if (m_nSearchIndex < 0)
675 m_nSearchIndex = 0;
676 if (m_pFindDialog)
678 break;
680 else
682 m_pFindDialog = new CFindReplaceDialog();
683 m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this);
686 break;
687 case ID_REPOBROWSE:
689 CString sCmd;
690 sCmd.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
691 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
692 (LPCTSTR)pathURL, (LPCTSTR)revSelected.ToString());
694 CAppUtils::LaunchApplication(sCmd, NULL, false);
696 break;
697 case ID_EDITLOG:
699 EditLogMessage(selIndex);
701 break;
702 case ID_EDITAUTHOR:
704 EditAuthor(selEntries);
706 break;
707 case ID_REVPROPS:
709 CEditPropertiesDlg dlg;
710 dlg.SetProjectProperties(&m_ProjectProperties);
711 CTGitPathList escapedlist;
712 dlg.SetPathList(CTGitPathList(CTGitPath(pathURL)));
713 dlg.SetRevision(revSelected);
714 dlg.RevProps(true);
715 dlg.DoModal();
717 break;
719 case ID_EXPORT:
721 CString sCmd;
722 sCmd.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
723 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
724 (LPCTSTR)pathURL, (LONG)revSelected);
725 CAppUtils::LaunchApplication(sCmd, NULL, false);
727 break;
728 case ID_CHECKOUT:
730 CString sCmd;
731 CString url = _T("tgit:")+pathURL;
732 sCmd.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
733 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
734 (LPCTSTR)url, (LONG)revSelected);
735 CAppUtils::LaunchApplication(sCmd, NULL, false);
737 break;
738 case ID_VIEWREV:
740 CString url = m_ProjectProperties.sWebViewerRev;
741 url = GetAbsoluteUrlFromRelativeUrl(url);
742 url.Replace(_T("%REVISION%"), revSelected.ToString());
743 if (!url.IsEmpty())
744 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
746 break;
747 case ID_VIEWPATHREV:
749 CString relurl = pathURL;
750 CString sRoot = GetRepositoryRoot(CTGitPath(relurl));
751 relurl = relurl.Mid(sRoot.GetLength());
752 CString url = m_ProjectProperties.sWebViewerPathRev;
753 url = GetAbsoluteUrlFromRelativeUrl(url);
754 url.Replace(_T("%REVISION%"), revSelected.ToString());
755 url.Replace(_T("%PATH%"), relurl);
756 if (!url.IsEmpty())
757 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
759 break;
760 #endif
762 } // switch (cmd)
764 theApp.DoWaitCursor(-1);
767 void CGitLogList::SetSelectedAction(int action)
769 POSITION pos = GetFirstSelectedItemPosition();
770 int index;
771 while(pos)
773 index = GetNextSelectedItem(pos);
774 ((GitRev*)m_arShownList[index])->m_Action = action;
775 CRect rect;
776 this->GetItemRect(index,&rect,LVIR_BOUNDS);
777 this->InvalidateRect(rect);