use gitdll gethash and clean up some warning
[TortoiseGit.git] / src / TortoiseProc / GitLogListAction.cpp
blob775e67e8d88a16c32c95b37de512cd8fb3a50cbf
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"
51 #include "GitDiff.h"
53 IMPLEMENT_DYNAMIC(CGitLogList, CHintListCtrl)
55 int CGitLogList::RevertSelectedCommits()
57 CSysProgressDlg progress;
58 int ret = -1;
60 #if 0
61 if(!g_Git.CheckCleanWorkTree())
63 CMessageBox::Show(NULL,_T("Revert requires a clean working tree"),_T("TortoiseGit"),MB_OK);
66 #endif
68 if (progress.IsValid() && (this->GetSelectedCount() > 1) )
70 progress.SetTitle(_T("Revert Commit"));
71 progress.SetAnimation(IDR_MOVEANI);
72 progress.SetTime(true);
73 progress.ShowModeless(this);
76 POSITION pos = GetFirstSelectedItemPosition();
77 int i=0;
78 while(pos)
80 int index = GetNextSelectedItem(pos);
81 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(index));
83 if (progress.IsValid() && (this->GetSelectedCount() > 1) )
85 progress.FormatPathLine(1, _T("Revert %s"), r1->m_CommitHash.ToString());
86 progress.FormatPathLine(2, _T("%s"), r1->GetSubject());
87 progress.SetProgress(i, this->GetSelectedCount());
89 i++;
91 if(r1->m_CommitHash.IsEmpty())
92 continue;
94 CString cmd, output;
95 cmd.Format(_T("git.exe revert --no-edit --no-commit %s"), r1->m_CommitHash.ToString());
96 if(g_Git.Run(cmd, &output, CP_ACP))
98 CString str;
99 str=_T("Revert fail\n");
100 str+= cmd;
101 str+= _T("\n")+output;
102 if( GetSelectedCount() == 1)
103 CMessageBox::Show(NULL,str, _T("TortoiseGit"),MB_OK|MB_ICONERROR);
104 else
106 if(CMessageBox::Show(NULL, str, _T("TortoiseGit"),2, IDI_ERROR, _T("Skip"), _T("Abort")) ==2)
108 return ret;
112 else
114 ret =0;
117 if ((progress.IsValid())&&(progress.HasUserCancelled()))
118 break;
120 return ret;
122 int CGitLogList::CherryPickFrom(CString from, CString to)
124 CLogDataVector logs(&m_LogCache);
125 if(logs.ParserFromLog(NULL,-1,0,&from,&to))
126 return -1;
128 if(logs.size() == 0)
129 return 0;
131 CSysProgressDlg progress;
132 if (progress.IsValid())
134 progress.SetTitle(_T("Cherry Pick"));
135 progress.SetAnimation(IDR_MOVEANI);
136 progress.SetTime(true);
137 progress.ShowModeless(this);
140 for(int i=logs.size()-1;i>=0;i--)
142 if (progress.IsValid())
144 progress.FormatPathLine(1, _T("Pick up %s"), logs.GetGitRevAt(i).m_CommitHash.ToString());
145 progress.FormatPathLine(2, _T("%s"), logs.GetGitRevAt(i).GetSubject());
146 progress.SetProgress(logs.size()-i, logs.size());
148 if ((progress.IsValid())&&(progress.HasUserCancelled()))
150 //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
151 throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));
152 return -1;
154 CString cmd,out;
155 cmd.Format(_T("git.exe cherry-pick %s"),logs.GetGitRevAt(i).m_CommitHash.ToString());
156 out.Empty();
157 if(g_Git.Run(cmd,&out,CP_UTF8))
159 throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out));
160 return -1;
164 return 0;
167 void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMenu *popmenu)
169 POSITION pos = GetFirstSelectedItemPosition();
170 int indexNext = GetNextSelectedItem(pos);
171 if (indexNext < 0)
172 return;
174 GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext));
176 theApp.DoWaitCursor(1);
177 switch (cmd&0xFFFF)
179 case ID_COMMIT:
181 CTGitPathList pathlist;
182 CTGitPathList selectedlist;
183 pathlist.AddPath(this->m_Path);
184 bool bSelectFilesForCommit = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE));
185 CAppUtils::Commit(CString(),false,CString(),
186 pathlist,selectedlist,bSelectFilesForCommit);
187 //this->Refresh();
188 this->GetParent()->PostMessage(WM_COMMAND,ID_LOGDLG_REFRESH,0);
190 break;
191 case ID_GNUDIFF1:
193 CString tempfile=GetTempFile();
194 CString command;
195 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
196 if(!r1->m_CommitHash.IsEmpty())
198 CString merge;
199 CString hash2;
200 cmd >>= 16;
201 if( (cmd&0xFFFF) == 0xFFFF)
203 merge=_T("-m");
204 } else if((cmd&0xFFFF) == 0xFFFE)
206 merge=_T("-c");
207 }else
209 if(cmd > r1->m_ParentHash.size())
211 CString str;
212 str.Format(_T("%d parent does not exist"), cmd);
213 CMessageBox::Show(NULL,str,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
214 return;
215 }else
217 if(cmd>0)
218 hash2 = r1->m_ParentHash[cmd-1].ToString();
221 command.Format(_T("git.exe diff-tree %s -r -p --stat %s %s"),merge, r1->m_CommitHash.ToString(), hash2);
222 }else
223 command.Format(_T("git.exe diff -r -p --stat"));
225 g_Git.RunLogFile(command,tempfile);
226 CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.ToString().Left(6)+_T(":")+r1->GetSubject());
228 break;
230 case ID_GNUDIFF2:
232 CString tempfile=GetTempFile();
233 CString cmd;
234 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
235 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
237 if( r1->m_CommitHash.IsEmpty()) {
238 cmd.Format(_T("git.exe diff -r -p --stat %s"),r2->m_CommitHash.ToString());
239 }else if( r2->m_CommitHash.IsEmpty()) {
240 cmd.Format(_T("git.exe diff -r -p --stat %s"),r1->m_CommitHash.ToString());
241 }else {
242 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r2->m_CommitHash.ToString(),r1->m_CommitHash.ToString());
245 g_Git.RunLogFile(cmd,tempfile);
246 CAppUtils::StartUnifiedDiffViewer(tempfile,r2->m_CommitHash.ToString().Left(6)+_T(":")+r1->m_CommitHash.ToString().Left(6));
249 break;
251 case ID_COMPARETWO:
253 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
254 GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
255 CGitDiff::DiffCommit(this->m_Path, r1,r2);
258 break;
261 case ID_COMPARE:
263 GitRev * r1 = &m_wcRev;
264 GitRev * r2 = pSelLogEntry;
266 CGitDiff::DiffCommit(this->m_Path, r1,r2);
268 //user clicked on the menu item "compare with working copy"
269 //if (PromptShown())
271 // GitDiff diff(this, m_hWnd, true);
272 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
273 // diff.SetHEADPeg(m_LogRevision);
274 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
276 //else
277 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
279 break;
281 case ID_COMPAREWITHPREVIOUS:
284 CFileDiffDlg dlg;
286 if(pSelLogEntry->m_ParentHash.size()>0)
287 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
289 cmd>>=16;
290 cmd&=0xFFFF;
292 if(cmd == 0)
293 cmd=1;
295 CGitDiff::DiffCommit(this->m_Path, pSelLogEntry->m_CommitHash.ToString(),pSelLogEntry->m_ParentHash[cmd-1].ToString());
297 }else
299 CMessageBox::Show(NULL,_T("No previous version"),_T("TortoiseGit"),MB_OK);
301 //if (PromptShown())
303 // GitDiff diff(this, m_hWnd, true);
304 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
305 // diff.SetHEADPeg(m_LogRevision);
306 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
308 //else
309 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
311 break;
312 case ID_COPYCLIPBOARD:
314 CopySelectionToClipBoard();
316 break;
317 case ID_COPYHASH:
319 CopySelectionToClipBoard(TRUE);
321 break;
322 case ID_EXPORT:
323 CAppUtils::Export(&pSelLogEntry->m_CommitHash.ToString());
324 break;
325 case ID_CREATE_BRANCH:
326 CAppUtils::CreateBranchTag(FALSE,&pSelLogEntry->m_CommitHash.ToString());
327 ReloadHashMap();
328 Invalidate();
329 break;
330 case ID_CREATE_TAG:
331 CAppUtils::CreateBranchTag(TRUE,&pSelLogEntry->m_CommitHash.ToString());
332 ReloadHashMap();
333 Invalidate();
334 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
335 break;
336 case ID_SWITCHTOREV:
337 CAppUtils::Switch(&pSelLogEntry->m_CommitHash.ToString());
338 ReloadHashMap();
339 Invalidate();
340 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
341 break;
342 case ID_SWITCHBRANCH:
343 if(popmenu)
345 CString *branch = (CString*)((CIconMenu*)popmenu)->GetMenuItemData(cmd);
346 if(branch)
349 CProgressDlg progress;
350 CString name;
351 if(branch->Find(_T("refs/heads/")) ==0 )
352 name = branch->Mid(11);
353 else
354 name = *branch;
356 progress.m_GitCmd.Format(_T("git.exe checkout %s"), name.GetString());
357 progress.DoModal();
359 ReloadHashMap();
360 Invalidate();
361 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
363 break;
364 case ID_RESET:
365 CAppUtils::GitReset(&pSelLogEntry->m_CommitHash.ToString());
366 ReloadHashMap();
367 Invalidate();
368 break;
369 case ID_REBASE_PICK:
370 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK);
371 break;
372 case ID_REBASE_EDIT:
373 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT);
374 break;
375 case ID_REBASE_SQUASH:
376 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH);
377 break;
378 case ID_REBASE_SKIP:
379 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP);
380 break;
381 case ID_COMBINE_COMMIT:
383 CString head;
384 CGitHash headhash;
385 CGitHash hashFirst,hashLast;
387 int headindex=GetHeadIndex();
388 if(headindex>=0) //incase show all branch, head is not the first commits.
390 head.Format(_T("HEAD~%d"),FirstSelect-headindex);
391 hashFirst=g_Git.GetHash(head);
393 head.Format(_T("HEAD~%d"),LastSelect-headindex);
394 hashLast=g_Git.GetHash(head);
397 GitRev* pFirstEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
398 GitRev* pLastEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
399 if(pFirstEntry->m_CommitHash != hashFirst || pLastEntry->m_CommitHash != hashLast)
401 CMessageBox::Show(NULL,_T(
402 "Cannot combine commits now.\r\n\
403 Make sure you are viewing the log of your current branch and \
404 no filters are applied."),_T("TortoiseGit"),MB_OK);
405 break;
408 headhash=g_Git.GetHash(_T("HEAD"));
410 if(!g_Git.CheckCleanWorkTree())
412 CMessageBox::Show(NULL,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK);
413 break;
415 CString cmd,out;
417 //Use throw to abort this process (reset back to original HEAD)
420 cmd.Format(_T("git.exe reset --hard %s"),pFirstEntry->m_CommitHash.ToString());
421 if(g_Git.Run(cmd,&out,CP_UTF8))
423 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
424 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out));
426 cmd.Format(_T("git.exe reset --mixed %s"),hashLast.ToString());
427 if(g_Git.Run(cmd,&out,CP_UTF8))
429 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
430 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out));
432 CCommitDlg dlg;
433 for(int i=FirstSelect;i<=LastSelect;i++)
435 GitRev* pRev = reinterpret_cast<GitRev*>(m_arShownList.GetAt(i));
436 dlg.m_sLogMessage+=pRev->GetSubject()+_T("\n")+pRev->GetBody();
437 dlg.m_sLogMessage+=_T("\n");
439 dlg.m_bWholeProject=true;
440 dlg.m_bSelectFilesForCommit = true;
441 dlg.m_bCommitAmend=true;
442 dlg.m_AmendStr=dlg.m_sLogMessage;
444 if (dlg.DoModal() == IDOK)
446 if(pFirstEntry->m_CommitHash!=headhash)
448 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
449 //on top of new commit.
450 //Use the rebase --onto command for it.
452 //All this can be done in one step using the following command:
453 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
454 // pFirstEntry->m_CommitHash,
455 // headhash);
456 //But I am not sure if a '|' is going to work in a CreateProcess() call.
458 //Later the progress dialog could be used to execute these steps.
460 if(CherryPickFrom(pFirstEntry->m_CommitHash.ToString(),headhash))
462 CString msg;
463 msg.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
464 throw std::exception(CUnicodeUtils::GetUTF8(msg));
466 #if 0
467 CString currentBranch=g_Git.GetCurrentBranch();
468 cmd.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
469 currentBranch,
470 pFirstEntry->m_CommitHash,
471 headhash);
472 if(g_Git.Run(cmd,&out,CP_UTF8)!=0)
474 CString msg;
475 msg.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out);
476 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
477 g_Git.Run(_T("git.exe rebase --abort"),&out,CP_UTF8);
478 throw std::exception(CUnicodeUtils::GetUTF8(msg));
481 //HEAD is now on <no branch>.
482 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
483 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
484 //And then git checkout <original branch>
485 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
487 //Store new HEAD
488 CString newHead=g_Git.GetHash(CString(_T("HEAD")));
490 //Checkout working branch
491 cmd.Format(_T("git.exe checkout -f \"%s\""),currentBranch);
492 if(g_Git.Run(cmd,&out,CP_UTF8))
493 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out));
495 //Reset to new HEAD
496 cmd.Format(_T("git.exe reset --hard %s"),newHead);
497 if(g_Git.Run(cmd,&out,CP_UTF8))
498 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out));
499 #endif
502 else
503 throw std::exception("User aborted the combine process");
505 catch(std::exception& e)
507 CMessageBox::Show(NULL,CUnicodeUtils::GetUnicode(CStringA(e.what())),_T("TortoiseGit: Combine error"),MB_OK|MB_ICONERROR);
508 cmd.Format(_T("git.exe reset --hard %s"),headhash.ToString());
509 out.Empty();
510 if(g_Git.Run(cmd,&out,CP_UTF8))
512 CMessageBox::Show(NULL,_T("Could not reset to original HEAD\r\n\r\n")+out,_T("TortoiseGit"),MB_OK);
515 Refresh();
517 break;
519 case ID_CHERRY_PICK:
520 if(!g_Git.CheckCleanWorkTree())
522 CMessageBox::Show(NULL,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK);
524 }else
526 CRebaseDlg dlg;
527 dlg.m_IsCherryPick = TRUE;
528 dlg.m_Upstream = this->m_CurrentBranch;
529 POSITION pos = GetFirstSelectedItemPosition();
530 while(pos)
532 int indexNext = GetNextSelectedItem(pos);
533 dlg.m_CommitList.m_logEntries.push_back( ((GitRev*)m_arShownList[indexNext])->m_CommitHash );
534 dlg.m_CommitList.m_LogCache.m_HashMap[((GitRev*)m_arShownList[indexNext])->m_CommitHash]=*(GitRev*)m_arShownList[indexNext];
535 dlg.m_CommitList.m_logEntries.GetGitRevAt(dlg.m_CommitList.m_logEntries.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK;
538 if(dlg.DoModal() == IDOK)
540 Refresh();
543 break;
544 case ID_REBASE_TO_VERSION:
545 if(!g_Git.CheckCleanWorkTree())
547 CMessageBox::Show(NULL,_T("Rebase requires a clean working tree"),_T("TortoiseGit"),MB_OK);
549 }else
551 CRebaseDlg dlg;
552 dlg.m_Upstream = pSelLogEntry->m_CommitHash;
554 if(dlg.DoModal() == IDOK)
556 Refresh();
560 break;
562 case ID_STASH_APPLY:
563 CAppUtils::StashApply(pSelLogEntry->m_Ref);
564 break;
566 case ID_REFLOG_DEL:
568 CString str;
569 str.Format(_T("Warning: %s will be permanently deleted. It can <ct=0x0000FF><b>NOT</b></ct> be recovered!\r\n \r\n Are you sure you want to continue?"),pSelLogEntry->m_Ref);
570 if(CMessageBox::Show(NULL,str,_T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
572 CString cmd,out;
573 cmd.Format(_T("git.exe reflog delete %s"),pSelLogEntry->m_Ref);
574 if(g_Git.Run(cmd,&out,CP_ACP))
576 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
578 ::PostMessage(this->GetParent()->m_hWnd,MSG_REFLOG_CHANGED,0,0);
581 break;
582 case ID_LOG:
584 CString cmd;
585 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
586 cmd += _T(" /command:log");
587 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\" ");
588 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
589 cmd += _T(" /endrev:")+r1->m_CommitHash.ToString();
590 CAppUtils::LaunchApplication(cmd,IDS_ERR_PROC,false);
592 break;
593 case ID_CREATE_PATCH:
595 int select=this->GetSelectedCount();
596 CString cmd;
597 cmd = CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
598 cmd += _T(" /command:formatpatch");
600 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\" ");
602 GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));
603 GitRev * r2 = NULL;
604 if(select == 1)
606 cmd += _T(" /startrev:")+r1->m_CommitHash.ToString();
608 else
610 r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));
611 if( this->m_IsOldFirst )
613 cmd += _T(" /startrev:")+r1->m_CommitHash.ToString()+_T("~1");
614 cmd += _T(" /endrev:")+r2->m_CommitHash.ToString();
616 }else
618 cmd += _T(" /startrev:")+r2->m_CommitHash.ToString()+_T("~1");
619 cmd += _T(" /endrev:")+r1->m_CommitHash.ToString();
624 CAppUtils::LaunchApplication(cmd,IDS_ERR_PROC,false);
626 break;
627 case ID_DELETE:
629 int index = cmd>>16;
630 if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) == m_HashMap.end() )
632 CMessageBox::Show(NULL,IDS_ERROR_NOREF,IDS_APPNAME,MB_OK|MB_ICONERROR);
633 return;
635 if( index >= m_HashMap[pSelLogEntry->m_CommitHash].size())
637 CMessageBox::Show(NULL,IDS_ERROR_INDEX,IDS_APPNAME,MB_OK|MB_ICONERROR);
638 return;
640 CString ref,msg;
641 ref=m_HashMap[pSelLogEntry->m_CommitHash][index];
643 msg=CString(_T("<ct=0x0000FF>Delete</ct> <b>"))+ref;
644 msg+=_T("</b>\n\n Are you sure?");
645 if( CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_YESNO) == IDYES )
647 CString shortname;
648 CString cmd;
649 if(this->GetShortName(ref,shortname,_T("refs/heads/")))
651 cmd.Format(_T("git.exe branch -D %s"),shortname);
654 if(this->GetShortName(ref,shortname,_T("refs/remotes/")))
656 cmd.Format(_T("git.exe branch -r -D %s"),shortname);
659 if(this->GetShortName(ref,shortname,_T("refs/tags/")))
661 cmd.Format(_T("git.exe tag -d %s"),shortname);
664 if(this->GetShortName(ref,shortname,_T("refs/stash")))
666 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Are you sure remove <b>ALL</b> stash?</ct>"),
667 _T("TortoiseGit"),MB_YESNO)==IDYES)
668 cmd.Format(_T("git.exe stash clear"));
669 else
670 return;
673 CString out;
674 if(g_Git.Run(cmd,&out,CP_UTF8))
676 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
678 this->ReloadHashMap();
679 CRect rect;
680 this->GetItemRect(FirstSelect,&rect,LVIR_BOUNDS);
681 this->InvalidateRect(rect);
684 break;
686 case ID_FINDENTRY:
688 m_nSearchIndex = GetSelectionMark();
689 if (m_nSearchIndex < 0)
690 m_nSearchIndex = 0;
691 if (m_pFindDialog)
693 break;
695 else
697 m_pFindDialog = new CFindDlg();
698 m_pFindDialog->Create(this);
701 break;
702 case ID_MERGEREV:
704 // we need an URL to complete this command, so error out if we can't get an URL
705 if(CAppUtils::Merge(&pSelLogEntry->m_CommitHash.ToString()))
707 this->Refresh();
710 break;
711 case ID_REVERTREV:
713 if(!this->RevertSelectedCommits())
714 this->Refresh();
716 break;
717 case ID_EDITNOTE:
719 CAppUtils::EditNote(pSelLogEntry);
720 this->SetItemState(FirstSelect, 0, LVIS_SELECTED);
721 this->SetItemState(FirstSelect, LVIS_SELECTED, LVIS_SELECTED);
723 break;
724 default:
725 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
726 break;
727 #if 0
729 case ID_BLAMECOMPARE:
731 //user clicked on the menu item "compare with working copy"
732 //now first get the revision which is selected
733 if (PromptShown())
735 GitDiff diff(this, this->m_hWnd, true);
736 diff.SetHEADPeg(m_LogRevision);
737 diff.ShowCompare(m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), false, true);
739 else
740 CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_BASE, m_path, revSelected, GitRev(), m_LogRevision, false, false, true);
742 break;
743 case ID_BLAMETWO:
745 //user clicked on the menu item "compare and blame revisions"
746 if (PromptShown())
748 GitDiff diff(this, this->m_hWnd, true);
749 diff.SetHEADPeg(m_LogRevision);
750 diff.ShowCompare(CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), false, true);
752 else
753 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revSelected2, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
755 break;
756 case ID_BLAMEWITHPREVIOUS:
758 //user clicked on the menu item "Compare and Blame with previous revision"
759 if (PromptShown())
761 GitDiff diff(this, this->m_hWnd, true);
762 diff.SetHEADPeg(m_LogRevision);
763 diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), false, true);
765 else
766 CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, false, false, true);
768 break;
770 case ID_OPENWITH:
771 bOpenWith = true;
772 case ID_OPEN:
774 CProgressDlg progDlg;
775 progDlg.SetTitle(IDS_APPNAME);
776 progDlg.SetAnimation(IDR_DOWNLOAD);
777 CString sInfoLine;
778 sInfoLine.Format(IDS_PROGRESSGETFILEREVISION, m_path.GetWinPath(), (LPCTSTR)revSelected.ToString());
779 progDlg.SetLine(1, sInfoLine, true);
780 SetAndClearProgressInfo(&progDlg);
781 progDlg.ShowModeless(m_hWnd);
782 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, m_path, revSelected);
783 bool bSuccess = true;
784 if (!Cat(m_path, GitRev(GitRev::REV_HEAD), revSelected, tempfile))
786 bSuccess = false;
787 // try again, but with the selected revision as the peg revision
788 if (!Cat(m_path, revSelected, revSelected, tempfile))
790 progDlg.Stop();
791 SetAndClearProgressInfo((HWND)NULL);
792 CMessageBox::Show(this->m_hWnd, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
793 EnableOKButton();
794 break;
796 bSuccess = true;
798 if (bSuccess)
800 progDlg.Stop();
801 SetAndClearProgressInfo((HWND)NULL);
802 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
803 int ret = 0;
804 if (!bOpenWith)
805 ret = (int)ShellExecute(this->m_hWnd, NULL, tempfile.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
806 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
808 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
809 cmd += tempfile.GetWinPathString() + _T(" ");
810 CAppUtils::LaunchApplication(cmd, NULL, false);
814 break;
815 case ID_BLAME:
817 CBlameDlg dlg;
818 dlg.EndRev = revSelected;
819 if (dlg.DoModal() == IDOK)
821 CBlame blame;
822 CString tempfile;
823 CString logfile;
824 tempfile = blame.BlameToTempFile(m_path, dlg.StartRev, dlg.EndRev, dlg.EndRev, logfile, _T(""), dlg.m_bIncludeMerge, TRUE, TRUE);
825 if (!tempfile.IsEmpty())
827 if (dlg.m_bTextView)
829 //open the default text editor for the result file
830 CAppUtils::StartTextViewer(tempfile);
832 else
834 CString sParams = _T("/path:\"") + m_path.GetGitPathString() + _T("\" ");
835 if(!CAppUtils::LaunchTortoiseBlame(tempfile, logfile, CPathUtils::GetFileNameFromPath(m_path.GetFileOrDirectoryName()),sParams))
837 break;
841 else
843 CMessageBox::Show(this->m_hWnd, blame.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
847 break;
848 case ID_UPDATE:
850 CString sCmd;
851 CString url = _T("tgit:")+pathURL;
852 sCmd.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
853 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
854 (LPCTSTR)m_path.GetWinPath(), (LONG)revSelected);
855 CAppUtils::LaunchApplication(sCmd, NULL, false);
857 break;
859 case ID_REPOBROWSE:
861 CString sCmd;
862 sCmd.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
863 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
864 (LPCTSTR)pathURL, (LPCTSTR)revSelected.ToString());
866 CAppUtils::LaunchApplication(sCmd, NULL, false);
868 break;
869 case ID_EDITLOG:
871 EditLogMessage(selIndex);
873 break;
874 case ID_EDITAUTHOR:
876 EditAuthor(selEntries);
878 break;
879 case ID_REVPROPS:
881 CEditPropertiesDlg dlg;
882 dlg.SetProjectProperties(&m_ProjectProperties);
883 CTGitPathList escapedlist;
884 dlg.SetPathList(CTGitPathList(CTGitPath(pathURL)));
885 dlg.SetRevision(revSelected);
886 dlg.RevProps(true);
887 dlg.DoModal();
889 break;
891 case ID_EXPORT:
893 CString sCmd;
894 sCmd.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
895 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
896 (LPCTSTR)pathURL, (LONG)revSelected);
897 CAppUtils::LaunchApplication(sCmd, NULL, false);
899 break;
900 case ID_CHECKOUT:
902 CString sCmd;
903 CString url = _T("tgit:")+pathURL;
904 sCmd.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
905 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
906 (LPCTSTR)url, (LONG)revSelected);
907 CAppUtils::LaunchApplication(sCmd, NULL, false);
909 break;
910 case ID_VIEWREV:
912 CString url = m_ProjectProperties.sWebViewerRev;
913 url = GetAbsoluteUrlFromRelativeUrl(url);
914 url.Replace(_T("%REVISION%"), revSelected.ToString());
915 if (!url.IsEmpty())
916 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
918 break;
919 case ID_VIEWPATHREV:
921 CString relurl = pathURL;
922 CString sRoot = GetRepositoryRoot(CTGitPath(relurl));
923 relurl = relurl.Mid(sRoot.GetLength());
924 CString url = m_ProjectProperties.sWebViewerPathRev;
925 url = GetAbsoluteUrlFromRelativeUrl(url);
926 url.Replace(_T("%REVISION%"), revSelected.ToString());
927 url.Replace(_T("%PATH%"), relurl);
928 if (!url.IsEmpty())
929 ShellExecute(this->m_hWnd, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
931 break;
932 #endif
934 } // switch (cmd)
936 theApp.DoWaitCursor(-1);
939 void CGitLogList::SetSelectedAction(int action)
941 POSITION pos = GetFirstSelectedItemPosition();
942 int index;
943 while(pos)
945 index = GetNextSelectedItem(pos);
946 ((GitRev*)m_arShownList[index])->GetAction(this) = action;
947 CRect rect;
948 this->GetItemRect(index,&rect,LVIR_BOUNDS);
949 this->InvalidateRect(rect);