added new log filter (for subject)
[TortoiseGit.git] / src / TortoiseProc / GitLogListAction.cpp
blobe2f1f62f3c05f58a77dfb1b8f8103aee1b72a767
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2005-2007 Marco Costalba
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // GitLogList.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "GitLogList.h"
25 #include "GitRev.h"
26 //#include "VssStyle.h"
27 #include "IconMenu.h"
28 // CGitLogList
29 #include "cursor.h"
30 #include "InputDlg.h"
31 #include "GITProgressDlg.h"
32 #include "ProgressDlg.h"
33 #include "SysProgressDlg.h"
34 //#include "RepositoryBrowser.h"
35 //#include "CopyDlg.h"
36 //#include "StatGraphDlg.h"
37 #include "Logdlg.h"
38 #include "MessageBox.h"
39 #include "Registry.h"
40 #include "AppUtils.h"
41 #include "PathUtils.h"
42 #include "StringUtils.h"
43 #include "UnicodeUtils.h"
44 #include "TempFile.h"
45 //#include "GitInfo.h"
46 //#include "GitDiff.h"
47 //#include "RevisionRangeDlg.h"
48 //#include "BrowseFolder.h"
49 //#include "BlameDlg.h"
50 //#include "Blame.h"
51 //#include "GitHelpers.h"
52 #include "GitStatus.h"
53 //#include "LogDlgHelper.h"
54 //#include "CachedLogInfo.h"
55 //#include "RepositoryInfo.h"
56 //#include "EditPropertiesDlg.h"
57 #include "FileDiffDlg.h"
58 #include "CommitDlg.h"
59 #include "RebaseDlg.h"
60 #include "GitDiff.h"
62 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)
64 int CGitLogList::RevertSelectedCommits()
66 CSysProgressDlg progress;
67 int ret = -1;
69 #if 0
70 if(!g_Git.CheckCleanWorkTree())
72 CMessageBox::Show(NULL,_T("Revert requires a clean working tree"),_T("TortoiseGit"),MB_OK);
75 #endif
77 if (progress.IsValid() && (this->GetSelectedCount() > 1) )
79 progress.SetTitle(_T("Revert Commit"));
80 progress.SetAnimation(IDR_MOVEANI);
81 progress.SetTime(true);
82 progress.ShowModeless(this);
85 POSITION pos = GetFirstSelectedItemPosition();
86 int i=0;
87 while(pos)
89 int index = GetNextSelectedItem(pos);
90 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));
92 if (progress.IsValid() && (this->GetSelectedCount() > 1) )
94 progress.FormatPathLine(1, _T("Revert %s"), r1->m_CommitHash.ToString());
95 progress.FormatPathLine(2, _T("%s"), r1->GetSubject());
96 progress.SetProgress(i, this->GetSelectedCount());
98 i++;
100 if(r1->m_CommitHash.IsEmpty())
101 continue;
103 CString cmd, output;
104 cmd.Format(_T("git.exe revert --no-edit --no-commit %s"), r1->m_CommitHash.ToString());
105 if(g_Git.Run(cmd, &output, CP_ACP))
107 CString str;
108 str=_T("Revert fail\n");
109 str+= cmd;
110 str+= _T("\n")+output;
111 if( GetSelectedCount() == 1)
112 CMessageBox::Show(NULL,str, _T("TortoiseGit"),MB_OK|MB_ICONERROR);
113 else
115 if(CMessageBox::Show(NULL, str, _T("TortoiseGit"),2 , IDI_ERROR, _T("&Skip"), _T("&Abort")) == 2)
117 return ret;
121 else
123 ret =0;
126 if ((progress.IsValid())&&(progress.HasUserCancelled()))
127 break;
129 return ret;
131 int CGitLogList::CherryPickFrom(CString from, CString to)
133 CLogDataVector logs(&m_LogCache);
134 if(logs.ParserFromLog(NULL,-1,0,&from,&to))
135 return -1;
137 if(logs.size() == 0)
138 return 0;
140 CSysProgressDlg progress;
141 if (progress.IsValid())
143 progress.SetTitle(_T("Cherry Pick"));
144 progress.SetAnimation(IDR_MOVEANI);
145 progress.SetTime(true);
146 progress.ShowModeless(this);
149 for(int i=logs.size()-1;i>=0;i--)
151 if (progress.IsValid())
153 progress.FormatPathLine(1, _T("Pick up %s"), logs.GetGitRevAt(i).m_CommitHash.ToString());
154 progress.FormatPathLine(2, _T("%s"), logs.GetGitRevAt(i).GetSubject());
155 progress.SetProgress(logs.size()-i, logs.size());
157 if ((progress.IsValid())&&(progress.HasUserCancelled()))
159 //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
160 throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));
161 return -1;
163 CString cmd,out;
164 cmd.Format(_T("git.exe cherry-pick %s"),logs.GetGitRevAt(i).m_CommitHash.ToString());
165 out.Empty();
166 if(g_Git.Run(cmd,&out,CP_UTF8))
168 throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out));
169 return -1;
173 return 0;
176 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMenu *popmenu)
178 POSITION pos = GetFirstSelectedItemPosition();
179 int indexNext = GetNextSelectedItem(pos);
180 if (indexNext < 0)
181 return;
183 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
185 theApp.DoWaitCursor(1);
186 switch (cmd&0xFFFF)
188 case ID_COMMIT:
190 CTGitPathList pathlist;
191 CTGitPathList selectedlist;
192 pathlist.AddPath(this->m_Path);
193 bool bSelectFilesForCommit = !!DWORD(CRegStdDWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE));
194 CString str;
195 CAppUtils::Commit(CString(),false,str,
196 pathlist,selectedlist,bSelectFilesForCommit);
197 //this->Refresh();
198 this->GetParent()->PostMessage(WM_COMMAND,ID_LOGDLG_REFRESH,0);
200 break;
201 case ID_GNUDIFF1: // compare with WC, unified
203 CString tempfile=GetTempFile();
204 CString command;
205 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
206 if(!r1->m_CommitHash.IsEmpty())
208 CString merge;
209 CString hash2;
210 cmd >>= 16;
211 if( (cmd&0xFFFF) == 0xFFFF)
213 merge=_T("-m");
215 else if((cmd&0xFFFF) == 0xFFFE)
217 merge=_T("-c");
219 else
221 if(cmd > r1->m_ParentHash.size())
223 CString str;
224 str.Format(_T("Parent %d does not exist"), cmd);
225 CMessageBox::Show(NULL,str,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
226 return;
228 else
230 if(cmd>0)
231 hash2 = r1->m_ParentHash[cmd-1].ToString();
234 command.Format(_T("git.exe diff-tree %s -r -p --stat %s %s"), merge, hash2, r1->m_CommitHash.ToString());
236 else
237 command.Format(_T("git.exe diff -r -p --stat"));
239 g_Git.RunLogFile(command,tempfile);
240 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.ToString().Left(6)+_T(":")+r1->GetSubject());
242 break;
244 case ID_GNUDIFF2: // compare two revisions, unified
246 CString tempfile=GetTempFile();
247 CString cmd;
248 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
249 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
251 if( r1->m_CommitHash.IsEmpty()) {
252 cmd.Format(_T("git.exe diff -r -p --stat %s"),r2->m_CommitHash.ToString());
254 else if( r2->m_CommitHash.IsEmpty()) {
255 cmd.Format(_T("git.exe diff -r -p --stat %s"),r1->m_CommitHash.ToString());
257 else
259 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r2->m_CommitHash.ToString(),r1->m_CommitHash.ToString());
262 g_Git.RunLogFile(cmd,tempfile);
263 CAppUtils::StartUnifiedDiffViewer(tempfile,r2->m_CommitHash.ToString().Left(6)+_T(":")+r1->m_CommitHash.ToString().Left(6));
266 break;
268 case ID_COMPARETWO: // compare two revisions
270 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
271 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
272 CGitDiff::DiffCommit(this->m_Path, r1,r2);
275 break;
277 case ID_COMPARE: // compare revision with WC
279 GitRev * r1 = &m_wcRev;
280 GitRev * r2 = pSelLogEntry;
282 CGitDiff::DiffCommit(this->m_Path, r1,r2);
284 //user clicked on the menu item "compare with working copy"
285 //if (PromptShown())
287 // GitDiff diff(this, m_hWnd, true);
288 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
289 // diff.SetHEADPeg(m_LogRevision);
290 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
292 //else
293 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
295 break;
297 case ID_COMPAREWITHPREVIOUS:
300 CFileDiffDlg dlg;
302 if(pSelLogEntry->m_ParentHash.size()>0)
303 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
305 cmd>>=16;
306 cmd&=0xFFFF;
308 if(cmd == 0)
309 cmd=1;
311 CGitDiff::DiffCommit(this->m_Path, pSelLogEntry->m_CommitHash.ToString(),pSelLogEntry->m_ParentHash[cmd-1].ToString());
314 else
316 CMessageBox::Show(NULL,_T("No previous version"),_T("TortoiseGit"),MB_OK);
318 //if (PromptShown())
320 // GitDiff diff(this, m_hWnd, true);
321 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
322 // diff.SetHEADPeg(m_LogRevision);
323 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
325 //else
326 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
328 break;
329 case ID_COPYCLIPBOARD:
331 CopySelectionToClipBoard();
333 break;
334 case ID_COPYHASH:
336 CopySelectionToClipBoard(TRUE);
338 break;
339 case ID_EXPORT:
341 CString str=pSelLogEntry->m_CommitHash.ToString();
342 CAppUtils::Export(&str);
344 break;
345 case ID_CREATE_BRANCH:
347 CString str = pSelLogEntry->m_CommitHash.ToString();
348 CAppUtils::CreateBranchTag(FALSE,&str);
349 ReloadHashMap();
350 Invalidate();
352 break;
353 case ID_CREATE_TAG:
355 CString str = pSelLogEntry->m_CommitHash.ToString();
356 CAppUtils::CreateBranchTag(TRUE,&str);
357 ReloadHashMap();
358 Invalidate();
359 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
361 break;
362 case ID_SWITCHTOREV:
364 CString str = pSelLogEntry->m_CommitHash.ToString();
365 CAppUtils::Switch(&str);
367 ReloadHashMap();
368 Invalidate();
369 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
370 break;
371 case ID_SWITCHBRANCH:
372 if(popmenu)
374 CString *branch = (CString*)((CIconMenu*)popmenu)->GetMenuItemData(cmd);
375 if(branch)
377 CString name;
378 if(branch->Find(_T("refs/heads/")) ==0 )
379 name = branch->Mid(11);
380 else
381 name = *branch;
383 CAppUtils::PerformSwitch(name);
385 ReloadHashMap();
386 Invalidate();
387 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
389 break;
390 case ID_RESET:
392 CString str = pSelLogEntry->m_CommitHash.ToString();
393 CAppUtils::GitReset(&str);
394 ReloadHashMap();
395 Invalidate();
397 break;
398 case ID_REBASE_PICK:
399 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
400 break;
401 case ID_REBASE_EDIT:
402 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
403 break;
404 case ID_REBASE_SQUASH:
405 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
406 break;
407 case ID_REBASE_SKIP:
408 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
409 break;
410 case ID_COMBINE_COMMIT:
412 CString head;
413 CGitHash headhash;
414 CGitHash hashFirst,hashLast;
416 int headindex=GetHeadIndex();
417 if(headindex>=0) //incase show all branch, head is not the first commits.
419 head.Format(_T("HEAD~%d"),FirstSelect-headindex);
420 hashFirst=g_Git.GetHash(head);
422 head.Format(_T("HEAD~%d"),LastSelect-headindex);
423 hashLast=g_Git.GetHash(head);
426 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
427 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
428 if(pFirstEntry->m_CommitHash != hashFirst || pLastEntry->m_CommitHash != hashLast)
430 CMessageBox::Show(NULL,_T("Cannot combine commits now.\r\nMake sure you are viewing the log of your current branch and no filters are applied."),_T("TortoiseGit"),MB_OK);
431 break;
434 headhash=g_Git.GetHash(_T("HEAD"));
436 if(!g_Git.CheckCleanWorkTree())
438 CMessageBox::Show(NULL,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK);
439 break;
441 CString cmd,out;
443 //Use throw to abort this process (reset back to original HEAD)
446 cmd.Format(_T("git.exe reset --hard %s"),pFirstEntry->m_CommitHash.ToString());
447 if(g_Git.Run(cmd,&out,CP_UTF8))
449 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
450 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out));
452 cmd.Format(_T("git.exe reset --mixed %s"),hashLast.ToString());
453 if(g_Git.Run(cmd,&out,CP_UTF8))
455 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
456 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out));
459 CTGitPathList PathList;
460 /* don't why must add --stat to get action status*/
461 /* first -z will be omitted by gitdll*/
462 if(g_Git.GetDiffPath(&PathList,&pFirstEntry->m_CommitHash,&hashLast,"-z --stat -r"))
464 CMessageBox::Show(NULL,_T("Get Diff file list error"),_T("TortoiseGit"),MB_OK);
465 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not get changed file list aborting...\r\n\r\n")+out));
468 for(int i=0;i<PathList.GetCount();i++)
470 if(PathList[i].m_Action & CTGitPath::LOGACTIONS_ADDED)
472 cmd.Format(_T("git.exe add -- \"%s\""), PathList[i].GetGitPathString());
473 if(g_Git.Run(cmd,&out,CP_ACP))
475 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
476 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not add new file aborting...\r\n\r\n")+out));
480 if(PathList[i].m_Action & CTGitPath::LOGACTIONS_DELETED)
482 cmd.Format(_T("git.exe rm -- \"%s\""), PathList[i].GetGitPathString());
483 if(g_Git.Run(cmd,&out,CP_ACP))
485 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
486 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not rm file aborting...\r\n\r\n")+out));
491 CCommitDlg dlg;
492 for(int i=FirstSelect;i<=LastSelect;i++)
494 GitRev* pRev = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
495 dlg.m_sLogMessage+=pRev->GetSubject()+_T("\n")+pRev->GetBody();
496 dlg.m_sLogMessage+=_T("\n");
498 dlg.m_bWholeProject=true;
499 dlg.m_bSelectFilesForCommit = true;
500 dlg.m_bCommitAmend=true;
501 dlg.m_bNoPostActions=true;
502 dlg.m_AmendStr=dlg.m_sLogMessage;
504 if (dlg.DoModal() == IDOK)
506 if(pFirstEntry->m_CommitHash!=headhash)
508 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
509 //on top of new commit.
510 //Use the rebase --onto command for it.
512 //All this can be done in one step using the following command:
513 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
514 // pFirstEntry->m_CommitHash,
515 // headhash);
516 //But I am not sure if a '|' is going to work in a CreateProcess() call.
518 //Later the progress dialog could be used to execute these steps.
520 if(CherryPickFrom(pFirstEntry->m_CommitHash.ToString(),headhash))
522 CString msg;
523 msg.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
524 throw std::exception(CUnicodeUtils::GetUTF8(msg));
526 #if 0
527 CString currentBranch=g_Git.GetCurrentBranch();
528 cmd.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
529 currentBranch,
530 pFirstEntry->m_CommitHash,
531 headhash);
532 if(g_Git.Run(cmd,&out,CP_UTF8)!=0)
534 CString msg;
535 msg.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out);
536 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
537 g_Git.Run(_T("git.exe rebase --abort"),&out,CP_UTF8);
538 throw std::exception(CUnicodeUtils::GetUTF8(msg));
541 //HEAD is now on <no branch>.
542 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
543 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
544 //And then git checkout <original branch>
545 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
547 //Store new HEAD
548 CString newHead=g_Git.GetHash(CString(_T("HEAD")));
550 //Checkout working branch
551 cmd.Format(_T("git.exe checkout -f \"%s\""),currentBranch);
552 if(g_Git.Run(cmd,&out,CP_UTF8))
553 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out));
555 //Reset to new HEAD
556 cmd.Format(_T("git.exe reset --hard %s"),newHead);
557 if(g_Git.Run(cmd,&out,CP_UTF8))
558 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out));
559 #endif
562 else
563 throw std::exception("User aborted the combine process");
565 catch(std::exception& e)
567 CMessageBox::Show(NULL,CUnicodeUtils::GetUnicode(CStringA(e.what())),_T("TortoiseGit: Combine error"),MB_OK|MB_ICONERROR);
568 cmd.Format(_T("git.exe reset --hard %s"),headhash.ToString());
569 out.Empty();
570 if(g_Git.Run(cmd,&out,CP_UTF8))
572 CMessageBox::Show(NULL,_T("Could not reset to original HEAD\r\n\r\n")+out,_T("TortoiseGit"),MB_OK);
575 Refresh();
577 break;
579 case ID_CHERRY_PICK:
580 if(!g_Git.CheckCleanWorkTree())
582 CMessageBox::Show(NULL,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK);
585 else
587 CRebaseDlg dlg;
588 dlg.m_IsCherryPick = TRUE;
589 dlg.m_Upstream = this->m_CurrentBranch;
590 POSITION pos = GetFirstSelectedItemPosition();
591 while(pos)
593 int indexNext = GetNextSelectedItem(pos);
594 dlg.m_CommitList.m_logEntries.push_back( ((GitRev*)m_arShownList[indexNext])->m_CommitHash );
595 dlg.m_CommitList.m_LogCache.m_HashMap[((GitRev*)m_arShownList[indexNext])->m_CommitHash]=*(GitRev*)m_arShownList[indexNext];
596 dlg.m_CommitList.m_logEntries.GetGitRevAt(dlg.m_CommitList.m_logEntries.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK;
599 if(dlg.DoModal() == IDOK)
601 Refresh();
604 break;
605 case ID_REBASE_TO_VERSION:
606 if(!g_Git.CheckCleanWorkTree())
608 CMessageBox::Show(NULL,_T("Rebase requires a clean working tree"),_T("TortoiseGit"),MB_OK);
611 else
613 CRebaseDlg dlg;
614 dlg.m_Upstream = pSelLogEntry->m_CommitHash;
616 if(dlg.DoModal() == IDOK)
618 Refresh();
622 break;
624 case ID_STASH_APPLY:
625 CAppUtils::StashApply(pSelLogEntry->m_Ref);
626 break;
628 case ID_REFLOG_DEL:
630 CString ref = pSelLogEntry->m_Ref;
631 if (ref.Find(_T("refs/")) == 0)
632 ref = ref.Mid(5);
633 int pos = ref.ReverseFind('{');
634 if (pos > 0 && ref.Mid(pos, 2) != _T("@{"))
635 ref = ref.Left(pos) + _T("@")+ ref.Mid(pos);
636 CString str;
637 str.Format(_T("Warning: \"%s\" will be permanently deleted. It can <ct=0x0000FF><b>NOT</b></ct> be recovered!\r\n\r\nDo you really want to continue?"), ref);
638 if(CMessageBox::Show(NULL, str, _T("TortoiseGit"), 1, IDI_QUESTION, _T("&Delete"), _T("&Abort")) == 1)
640 CString cmd,out;
641 if (ref.Find(_T("stash")) == 0)
643 cmd.Format(_T("git.exe stash drop %s"), ref);
645 else
646 cmd.Format(_T("git.exe reflog delete %s"), ref);
647 if(g_Git.Run(cmd,&out,CP_ACP))
649 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
651 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
654 break;
655 case ID_LOG:
657 CString cmd;
658 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
659 cmd += _T(" /command:log");
660 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\" ");
661 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
662 cmd += _T(" /endrev:")+r1->m_CommitHash.ToString();
663 CAppUtils::LaunchApplication(cmd,IDS_ERR_PROC,false);
665 break;
666 case ID_CREATE_PATCH:
668 int select=this->GetSelectedCount();
669 CString cmd;
670 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
671 cmd += _T(" /command:formatpatch");
673 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\" ");
675 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
676 GitRev * r2 = NULL;
677 if(select == 1)
679 cmd += _T(" /startrev:")+r1->m_CommitHash.ToString();
681 else
683 r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
684 if( this->m_IsOldFirst )
686 cmd += _T(" /startrev:")+r1->m_CommitHash.ToString()+_T("~1");
687 cmd += _T(" /endrev:")+r2->m_CommitHash.ToString();
690 else
692 cmd += _T(" /startrev:")+r2->m_CommitHash.ToString()+_T("~1");
693 cmd += _T(" /endrev:")+r1->m_CommitHash.ToString();
698 CAppUtils::LaunchApplication(cmd,IDS_ERR_PROC,false);
700 break;
701 case ID_PUSH:
703 CString guessAssociatedBranch;
704 if (m_HashMap[pSelLogEntry->m_CommitHash].size() > 0)
705 guessAssociatedBranch = m_HashMap[pSelLogEntry->m_CommitHash].at(0);
706 if (CAppUtils::Push(guessAssociatedBranch))
707 Refresh();
709 break;
710 case ID_DELETE:
712 int index = cmd>>16;
713 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) == m_HashMap.end() )
715 CMessageBox::Show(NULL,IDS_ERROR_NOREF,IDS_APPNAME,MB_OK|MB_ICONERROR);
716 return;
718 if( index >= m_HashMap[pSelLogEntry->m_CommitHash].size())
720 CMessageBox::Show(NULL,IDS_ERROR_INDEX,IDS_APPNAME,MB_OK|MB_ICONERROR);
721 return;
723 CString ref,msg;
724 ref=m_HashMap[pSelLogEntry->m_CommitHash][index];
726 msg=CString(_T("Do you really want to <ct=0x0000FF>delete</ct> <b>"))+ref;
727 msg+=_T("</b>?");
728 if( CMessageBox::Show(NULL, msg, _T("TortoiseGit"), 2, IDI_QUESTION, _T("&Delete"), _T("&Abort")) == 1 )
730 CString shortname;
731 CString cmd;
732 if(this->GetShortName(ref,shortname,_T("refs/heads/")))
734 cmd.Format(_T("git.exe branch -D -- %s"),shortname);
737 if(this->GetShortName(ref,shortname,_T("refs/remotes/")))
739 cmd.Format(_T("git.exe branch -r -D -- %s"),shortname);
742 if(this->GetShortName(ref,shortname,_T("refs/tags/")))
744 cmd.Format(_T("git.exe tag -d -- %s"),shortname);
747 if(this->GetShortName(ref,shortname,_T("refs/stash")))
749 if(CMessageBox::Show(NULL, _T("<ct=0x0000FF>Do you really want to delete <b>ALL</b> stash?</ct>"),
750 _T("TortoiseGit"), 2, IDI_QUESTION, _T("&Delete"), _T("&Abort")) == 1)
751 cmd.Format(_T("git.exe stash clear"));
752 else
753 return;
756 CString out;
757 if(g_Git.Run(cmd,&out,CP_UTF8))
759 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
761 this->ReloadHashMap();
762 CRect rect;
763 this->GetItemRect(FirstSelect,&rect,LVIR_BOUNDS);
764 this->InvalidateRect(rect);
767 break;
769 case ID_FINDENTRY:
771 m_nSearchIndex = GetSelectionMark();
772 if (m_nSearchIndex < 0)
773 m_nSearchIndex = 0;
774 if (m_pFindDialog)
776 break;
778 else
780 m_pFindDialog = new CFindDlg();
781 m_pFindDialog->Create(this);
784 break;
785 case ID_MERGEREV:
787 CString str = pSelLogEntry->m_CommitHash.ToString();
788 if (m_HashMap[pSelLogEntry->m_CommitHash].size() > 0)
789 str = m_HashMap[pSelLogEntry->m_CommitHash].at(0);
790 // we need an URL to complete this command, so error out if we can't get an URL
791 if(CAppUtils::Merge(&str))
793 this->Refresh();
796 break;
797 case ID_REVERTREV:
799 if(!this->RevertSelectedCommits())
800 this->Refresh();
802 break;
803 case ID_EDITNOTE:
805 CAppUtils::EditNote(pSelLogEntry);
806 this->SetItemState(FirstSelect, 0, LVIS_SELECTED);
807 this->SetItemState(FirstSelect, LVIS_SELECTED, LVIS_SELECTED);
809 break;
810 default:
811 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
812 break;
813 #if 0
815 case ID_BLAMECOMPARE:
817 //user clicked on the menu item "compare with working copy"
818 //now first get the revision which is selected
819 if (PromptShown())
821 GitDiff diff(this, this->m_hWnd, true);
822 diff.SetHEADPeg(m_LogRevision);
823 diff.ShowCompare(m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), false, true);
825 else
826 CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), m_LogRevision, false, false, true);
828 break;
829 case ID_BLAMETWO:
831 //user clicked on the menu item "compare and blame revisions"
832 if (PromptShown())
834 GitDiff diff(this, this->m_hWnd, true);
835 diff.SetHEADPeg(m_LogRevision);
836 diff.ShowCompare(CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), false, true);
838 else
839 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
841 break;
842 case ID_BLAMEWITHPREVIOUS:
844 //user clicked on the menu item "Compare and Blame with previous revision"
845 if (PromptShown())
847 GitDiff diff(this, this->m_hWnd, true);
848 diff.SetHEADPeg(m_LogRevision);
849 diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), false, true);
851 else
852 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
854 break;
856 case ID_OPENWITH:
857 bOpenWith = true;
858 case ID_OPEN:
860 CProgressDlg progDlg;
861 progDlg.SetTitle(IDS_APPNAME);
862 progDlg.SetAnimation(IDR_DOWNLOAD);
863 CString sInfoLine;
864 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, m_path.GetWinPath(), (LPCTSTR)revSelected.ToString());
865 progDlg.SetLine(1, sInfoLine, true);
866 SetAndClearProgressInfo(&progDlg);
867 progDlg.ShowModeless(m_hWnd);
868 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, m_path, revSelected);
869 bool bSuccess = true;
870 if (!Cat(m_path, GitRev(GitRev::REV_HEAD), revSelected, tempfile))
872 bSuccess = false;
873 // try again, but with the selected revision as the peg revision
874 if (!Cat(m_path, revSelected, revSelected, tempfile))
876 progDlg.Stop();
877 SetAndClearProgressInfo((HWND)NULL);
878 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
879 EnableOKButton();
880 break;
882 bSuccess = true;
884 if (bSuccess)
886 progDlg.Stop();
887 SetAndClearProgressInfo((HWND)NULL);
888 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
889 int ret = 0;
890 if (!bOpenWith)
891 ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
892 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
894 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
895 cmd += tempfile.GetWinPathString() + _T(" ");
896 CAppUtils::LaunchApplication(cmd, NULL, false);
900 break;
901 case ID_BLAME:
903 CBlameDlg dlg;
904 dlg.EndRev = revSelected;
905 if (dlg.DoModal() == IDOK)
907 CBlame blame;
908 CString tempfile;
909 CString logfile;
910 tempfile = blame.BlameToTempFile(m_path, dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
911 if (!tempfile.IsEmpty())
913 if (dlg.m_bTextView)
915 //open the default text editor for the result file
916 CAppUtils::StartTextViewer(tempfile);
918 else
920 CString sParams = _T("/path:\"") + m_path.GetGitPathString() + _T("\" ");
921 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(m_path.GetFileOrDirectoryName()),sParams))
923 break;
927 else
929 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
933 break;
934 case ID_UPDATE:
936 CString sCmd;
937 CString url = _T("tgit:")+pathURL;
938 sCmd.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
939 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
940 (LPCTSTR)m_path.GetWinPath(), (LONG)revSelected);
941 CAppUtils::LaunchApplication(sCmd, NULL, false);
943 break;
945 case ID_EDITLOG:
947 EditLogMessage(selIndex);
949 break;
950 case ID_EDITAUTHOR:
952 EditAuthor(selEntries);
954 break;
955 case ID_REVPROPS:
957 CEditPropertiesDlg dlg;
958 dlg.SetProjectProperties(&m_ProjectProperties);
959 CTGitPathList escapedlist;
960 dlg.SetPathList(CTGitPathList(CTGitPath(pathURL)));
961 dlg.SetRevision(revSelected);
962 dlg.RevProps(true);
963 dlg.DoModal();
965 break;
967 case ID_EXPORT:
969 CString sCmd;
970 sCmd.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
971 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
972 (LPCTSTR)pathURL, (LONG)revSelected);
973 CAppUtils::LaunchApplication(sCmd, NULL, false);
975 break;
976 case ID_VIEWREV:
978 CString url = m_ProjectProperties.sWebViewerRev;
979 url = GetAbsoluteUrlFromRelativeUrl(url);
980 url.Replace(_T("%REVISION%"), revSelected.ToString());
981 if (!url.IsEmpty())
982 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
984 break;
985 case ID_VIEWPATHREV:
987 CString relurl = pathURL;
988 CString sRoot = GetRepositoryRoot(CTGitPath(relurl));
989 relurl = relurl.Mid(sRoot.GetLength());
990 CString url = m_ProjectProperties.sWebViewerPathRev;
991 url = GetAbsoluteUrlFromRelativeUrl(url);
992 url.Replace(_T("%REVISION%"), revSelected.ToString());
993 url.Replace(_T("%PATH%"), relurl);
994 if (!url.IsEmpty())
995 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
997 break;
998 #endif
1000 } // switch (cmd)
1002 theApp.DoWaitCursor(-1);
1005 void CGitLogList::SetSelectedAction(int action)
1007 POSITION pos = GetFirstSelectedItemPosition();
1008 int index;
1009 while(pos)
1011 index = GetNextSelectedItem(pos);
1012 ((GitRev*)m_arShownList[index])->GetAction(this) = action;
1013 CRect rect;
1014 this->GetItemRect(index,&rect,LVIR_BOUNDS);
1015 this->InvalidateRect(rect);
1019 void CGitLogList::ShiftSelectedAction()
1021 POSITION pos = GetFirstSelectedItemPosition();
1022 int index;
1023 while(pos)
1025 index = GetNextSelectedItem(pos);
1026 int action = ((GitRev*)m_arShownList[index])->GetAction(this);
1027 switch (action)
1029 case CTGitPath::LOGACTIONS_REBASE_PICK:
1030 action = CTGitPath::LOGACTIONS_REBASE_SKIP;
1031 break;
1032 case CTGitPath::LOGACTIONS_REBASE_SKIP:
1033 action= CTGitPath::LOGACTIONS_REBASE_EDIT;
1034 break;
1035 case CTGitPath::LOGACTIONS_REBASE_EDIT:
1036 action = CTGitPath::LOGACTIONS_REBASE_SQUASH;
1037 break;
1038 case CTGitPath::LOGACTIONS_REBASE_SQUASH:
1039 action= CTGitPath::LOGACTIONS_REBASE_PICK;
1040 break;
1042 ((GitRev*)m_arShownList[index])->GetAction(this) = action;
1043 CRect rect;
1044 this->GetItemRect(index, &rect, LVIR_BOUNDS);
1045 this->InvalidateRect(rect);