1 // GitLogList.cpp : implementation file
4 Description: qgit revision list view
6 Author: Marco Costalba (C) 2005-2007
8 Copyright: See COPYING file that comes with this distribution
12 #include "TortoiseProc.h"
13 #include "GitLogList.h"
15 //#include "VssStyle.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"
28 #include "MessageBox.h"
31 #include "PathUtils.h"
32 #include "StringUtils.h"
33 #include "UnicodeUtils.h"
35 //#include "GitInfo.h"
36 //#include "GitDiff.h"
38 //#include "RevisionRangeDlg.h"
39 //#include "BrowseFolder.h"
40 //#include "BlameDlg.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"
53 IMPLEMENT_DYNAMIC(CGitLogList
, CHintListCtrl
)
55 int CGitLogList::RevertSelectedCommits()
57 CSysProgressDlg progress
;
61 if(!g_Git
.CheckCleanWorkTree())
63 CMessageBox::Show(NULL
,_T("Revert requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
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();
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());
91 if(r1
->m_CommitHash
.IsEmpty())
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
))
99 str
=_T("Revert fail\n");
101 str
+= _T("\n")+output
;
102 if( GetSelectedCount() == 1)
103 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
106 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"),2, IDI_ERROR
, _T("Skip"), _T("Abort")) ==2)
117 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
122 int CGitLogList::CherryPickFrom(CString from
, CString to
)
124 CLogDataVector
logs(&m_LogCache
);
125 if(logs
.ParserFromLog(NULL
,-1,0,&from
,&to
))
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")));
155 cmd
.Format(_T("git.exe cherry-pick %s"),logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
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
));
167 void CGitLogList::ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
*popmenu
)
169 POSITION pos
= GetFirstSelectedItemPosition();
170 int indexNext
= GetNextSelectedItem(pos
);
174 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
176 theApp
.DoWaitCursor(1);
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
);
188 this->GetParent()->PostMessage(WM_COMMAND
,ID_LOGDLG_REFRESH
,0);
193 CString tempfile
=GetTempFile();
195 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
196 if(!r1
->m_CommitHash
.IsEmpty())
201 if( (cmd
&0xFFFF) == 0xFFFF)
204 } else if((cmd
&0xFFFF) == 0xFFFE)
209 if(cmd
> r1
->m_ParentHash
.size())
212 str
.Format(_T("%d parent does not exist"), cmd
);
213 CMessageBox::Show(NULL
,str
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
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
);
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());
232 CString tempfile
=GetTempFile();
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());
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));
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
);
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"
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);
277 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
281 case ID_COMPAREWITHPREVIOUS
:
286 if(pSelLogEntry
->m_ParentHash
.size()>0)
287 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
295 CGitDiff::DiffCommit(this->m_Path
, pSelLogEntry
->m_CommitHash
.ToString(),pSelLogEntry
->m_ParentHash
[cmd
-1].ToString());
299 CMessageBox::Show(NULL
,_T("No previous version"),_T("TortoiseGit"),MB_OK
);
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);
309 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
312 case ID_COPYCLIPBOARD
:
314 CopySelectionToClipBoard();
319 CopySelectionToClipBoard(TRUE
);
323 CAppUtils::Export(&pSelLogEntry
->m_CommitHash
.ToString());
325 case ID_CREATE_BRANCH
:
326 CAppUtils::CreateBranchTag(FALSE
,&pSelLogEntry
->m_CommitHash
.ToString());
331 CAppUtils::CreateBranchTag(TRUE
,&pSelLogEntry
->m_CommitHash
.ToString());
334 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
337 CAppUtils::Switch(&pSelLogEntry
->m_CommitHash
.ToString());
340 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
342 case ID_SWITCHBRANCH
:
345 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
349 CProgressDlg progress
;
351 if(branch
->Find(_T("refs/heads/")) ==0 )
352 name
= branch
->Mid(11);
356 progress
.m_GitCmd
.Format(_T("git.exe checkout %s"), name
.GetString());
361 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
365 CAppUtils::GitReset(&pSelLogEntry
->m_CommitHash
.ToString());
370 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
373 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
375 case ID_REBASE_SQUASH
:
376 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
379 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
381 case ID_COMBINE_COMMIT
:
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("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
);
405 headhash
=g_Git
.GetHash(_T("HEAD"));
407 if(!g_Git
.CheckCleanWorkTree())
409 CMessageBox::Show(NULL
,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK
);
414 //Use throw to abort this process (reset back to original HEAD)
417 cmd
.Format(_T("git.exe reset --hard %s"),pFirstEntry
->m_CommitHash
.ToString());
418 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
420 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
421 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out
));
423 cmd
.Format(_T("git.exe reset --mixed %s"),hashLast
.ToString());
424 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
426 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
427 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out
));
430 for(int i
=FirstSelect
;i
<=LastSelect
;i
++)
432 GitRev
* pRev
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
433 dlg
.m_sLogMessage
+=pRev
->GetSubject()+_T("\n")+pRev
->GetBody();
434 dlg
.m_sLogMessage
+=_T("\n");
436 dlg
.m_bWholeProject
=true;
437 dlg
.m_bSelectFilesForCommit
= true;
438 dlg
.m_bCommitAmend
=true;
439 dlg
.m_AmendStr
=dlg
.m_sLogMessage
;
441 if (dlg
.DoModal() == IDOK
)
443 if(pFirstEntry
->m_CommitHash
!=headhash
)
445 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
446 //on top of new commit.
447 //Use the rebase --onto command for it.
449 //All this can be done in one step using the following command:
450 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
451 // pFirstEntry->m_CommitHash,
453 //But I am not sure if a '|' is going to work in a CreateProcess() call.
455 //Later the progress dialog could be used to execute these steps.
457 if(CherryPickFrom(pFirstEntry
->m_CommitHash
.ToString(),headhash
))
460 msg
.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
461 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
464 CString currentBranch
=g_Git
.GetCurrentBranch();
465 cmd
.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
467 pFirstEntry
->m_CommitHash
,
469 if(g_Git
.Run(cmd
,&out
,CP_UTF8
)!=0)
472 msg
.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out
);
473 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
474 g_Git
.Run(_T("git.exe rebase --abort"),&out
,CP_UTF8
);
475 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
478 //HEAD is now on <no branch>.
479 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
480 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
481 //And then git checkout <original branch>
482 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
485 CString newHead
=g_Git
.GetHash(CString(_T("HEAD")));
487 //Checkout working branch
488 cmd
.Format(_T("git.exe checkout -f \"%s\""),currentBranch
);
489 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
490 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out
));
493 cmd
.Format(_T("git.exe reset --hard %s"),newHead
);
494 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
495 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out
));
500 throw std::exception("User aborted the combine process");
502 catch(std::exception
& e
)
504 CMessageBox::Show(NULL
,CUnicodeUtils::GetUnicode(CStringA(e
.what())),_T("TortoiseGit: Combine error"),MB_OK
|MB_ICONERROR
);
505 cmd
.Format(_T("git.exe reset --hard %s"),headhash
.ToString());
507 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
509 CMessageBox::Show(NULL
,_T("Could not reset to original HEAD\r\n\r\n")+out
,_T("TortoiseGit"),MB_OK
);
517 if(!g_Git
.CheckCleanWorkTree())
519 CMessageBox::Show(NULL
,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
524 dlg
.m_IsCherryPick
= TRUE
;
525 dlg
.m_Upstream
= this->m_CurrentBranch
;
526 POSITION pos
= GetFirstSelectedItemPosition();
529 int indexNext
= GetNextSelectedItem(pos
);
530 dlg
.m_CommitList
.m_logEntries
.push_back( ((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
);
531 dlg
.m_CommitList
.m_LogCache
.m_HashMap
[((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
]=*(GitRev
*)m_arShownList
[indexNext
];
532 dlg
.m_CommitList
.m_logEntries
.GetGitRevAt(dlg
.m_CommitList
.m_logEntries
.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK
;
535 if(dlg
.DoModal() == IDOK
)
541 case ID_REBASE_TO_VERSION
:
542 if(!g_Git
.CheckCleanWorkTree())
544 CMessageBox::Show(NULL
,_T("Rebase requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
549 dlg
.m_Upstream
= pSelLogEntry
->m_CommitHash
;
551 if(dlg
.DoModal() == IDOK
)
560 CAppUtils::StashApply(pSelLogEntry
->m_Ref
);
566 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
);
567 if(CMessageBox::Show(NULL
,str
,_T("TortoiseGit"),MB_YESNO
|MB_ICONWARNING
) == IDYES
)
570 cmd
.Format(_T("git.exe reflog delete %s"),pSelLogEntry
->m_Ref
);
571 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
573 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
575 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
582 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
583 cmd
+= _T(" /command:log");
584 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
585 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
586 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
587 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
590 case ID_CREATE_PATCH
:
592 int select
=this->GetSelectedCount();
594 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
595 cmd
+= _T(" /command:formatpatch");
597 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
599 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
603 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString();
607 r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
608 if( this->m_IsOldFirst
)
610 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString()+_T("~1");
611 cmd
+= _T(" /endrev:")+r2
->m_CommitHash
.ToString();
615 cmd
+= _T(" /startrev:")+r2
->m_CommitHash
.ToString()+_T("~1");
616 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
621 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
627 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) == m_HashMap
.end() )
629 CMessageBox::Show(NULL
,IDS_ERROR_NOREF
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
632 if( index
>= m_HashMap
[pSelLogEntry
->m_CommitHash
].size())
634 CMessageBox::Show(NULL
,IDS_ERROR_INDEX
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
638 ref
=m_HashMap
[pSelLogEntry
->m_CommitHash
][index
];
640 msg
=CString(_T("<ct=0x0000FF>Delete</ct> <b>"))+ref
;
641 msg
+=_T("</b>\n\n Are you sure?");
642 if( CMessageBox::Show(NULL
,msg
,_T("TortoiseGit"),MB_YESNO
) == IDYES
)
646 if(this->GetShortName(ref
,shortname
,_T("refs/heads/")))
648 cmd
.Format(_T("git.exe branch -D %s"),shortname
);
651 if(this->GetShortName(ref
,shortname
,_T("refs/remotes/")))
653 cmd
.Format(_T("git.exe branch -r -D %s"),shortname
);
656 if(this->GetShortName(ref
,shortname
,_T("refs/tags/")))
658 cmd
.Format(_T("git.exe tag -d %s"),shortname
);
661 if(this->GetShortName(ref
,shortname
,_T("refs/stash")))
663 if(CMessageBox::Show(NULL
,_T("<ct=0x0000FF>Are you sure remove <b>ALL</b> stash?</ct>"),
664 _T("TortoiseGit"),MB_YESNO
)==IDYES
)
665 cmd
.Format(_T("git.exe stash clear"));
671 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
673 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
675 this->ReloadHashMap();
677 this->GetItemRect(FirstSelect
,&rect
,LVIR_BOUNDS
);
678 this->InvalidateRect(rect
);
685 m_nSearchIndex
= GetSelectionMark();
686 if (m_nSearchIndex
< 0)
694 m_pFindDialog
= new CFindDlg();
695 m_pFindDialog
->Create(this);
701 // we need an URL to complete this command, so error out if we can't get an URL
702 if(CAppUtils::Merge(&pSelLogEntry
->m_CommitHash
.ToString()))
710 if(!this->RevertSelectedCommits())
716 CAppUtils::EditNote(pSelLogEntry
);
717 this->SetItemState(FirstSelect
, 0, LVIS_SELECTED
);
718 this->SetItemState(FirstSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
722 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
726 case ID_BLAMECOMPARE
:
728 //user clicked on the menu item "compare with working copy"
729 //now first get the revision which is selected
732 GitDiff
diff(this, this->m_hWnd
, true);
733 diff
.SetHEADPeg(m_LogRevision
);
734 diff
.ShowCompare(m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), false, true);
737 CAppUtils::StartShowCompare(m_hWnd
, m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), m_LogRevision
, false, false, true);
742 //user clicked on the menu item "compare and blame revisions"
745 GitDiff
diff(this, this->m_hWnd
, true);
746 diff
.SetHEADPeg(m_LogRevision
);
747 diff
.ShowCompare(CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
750 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
753 case ID_BLAMEWITHPREVIOUS
:
755 //user clicked on the menu item "Compare and Blame with previous revision"
758 GitDiff
diff(this, this->m_hWnd
, true);
759 diff
.SetHEADPeg(m_LogRevision
);
760 diff
.ShowCompare(CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
763 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
771 CProgressDlg progDlg
;
772 progDlg
.SetTitle(IDS_APPNAME
);
773 progDlg
.SetAnimation(IDR_DOWNLOAD
);
775 sInfoLine
.Format(IDS_PROGRESSGETFILEREVISION
, m_path
.GetWinPath(), (LPCTSTR
)revSelected
.ToString());
776 progDlg
.SetLine(1, sInfoLine
, true);
777 SetAndClearProgressInfo(&progDlg
);
778 progDlg
.ShowModeless(m_hWnd
);
779 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, m_path
, revSelected
);
780 bool bSuccess
= true;
781 if (!Cat(m_path
, GitRev(GitRev::REV_HEAD
), revSelected
, tempfile
))
784 // try again, but with the selected revision as the peg revision
785 if (!Cat(m_path
, revSelected
, revSelected
, tempfile
))
788 SetAndClearProgressInfo((HWND
)NULL
);
789 CMessageBox::Show(this->m_hWnd
, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
798 SetAndClearProgressInfo((HWND
)NULL
);
799 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
802 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, tempfile
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
803 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
805 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
806 cmd
+= tempfile
.GetWinPathString() + _T(" ");
807 CAppUtils::LaunchApplication(cmd
, NULL
, false);
815 dlg
.EndRev
= revSelected
;
816 if (dlg
.DoModal() == IDOK
)
821 tempfile
= blame
.BlameToTempFile(m_path
, dlg
.StartRev
, dlg
.EndRev
, dlg
.EndRev
, logfile
, _T(""), dlg
.m_bIncludeMerge
, TRUE
, TRUE
);
822 if (!tempfile
.IsEmpty())
826 //open the default text editor for the result file
827 CAppUtils::StartTextViewer(tempfile
);
831 CString sParams
= _T("/path:\"") + m_path
.GetGitPathString() + _T("\" ");
832 if(!CAppUtils::LaunchTortoiseBlame(tempfile
, logfile
, CPathUtils::GetFileNameFromPath(m_path
.GetFileOrDirectoryName()),sParams
))
840 CMessageBox::Show(this->m_hWnd
, blame
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
848 CString url
= _T("tgit:")+pathURL
;
849 sCmd
.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
850 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
851 (LPCTSTR
)m_path
.GetWinPath(), (LONG
)revSelected
);
852 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
859 sCmd
.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
860 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
861 (LPCTSTR
)pathURL
, (LPCTSTR
)revSelected
.ToString());
863 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
868 EditLogMessage(selIndex
);
873 EditAuthor(selEntries
);
878 CEditPropertiesDlg dlg
;
879 dlg
.SetProjectProperties(&m_ProjectProperties
);
880 CTGitPathList escapedlist
;
881 dlg
.SetPathList(CTGitPathList(CTGitPath(pathURL
)));
882 dlg
.SetRevision(revSelected
);
891 sCmd
.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
892 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
893 (LPCTSTR
)pathURL
, (LONG
)revSelected
);
894 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
900 CString url
= _T("tgit:")+pathURL
;
901 sCmd
.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
902 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
903 (LPCTSTR
)url
, (LONG
)revSelected
);
904 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
909 CString url
= m_ProjectProperties
.sWebViewerRev
;
910 url
= GetAbsoluteUrlFromRelativeUrl(url
);
911 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
913 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
918 CString relurl
= pathURL
;
919 CString sRoot
= GetRepositoryRoot(CTGitPath(relurl
));
920 relurl
= relurl
.Mid(sRoot
.GetLength());
921 CString url
= m_ProjectProperties
.sWebViewerPathRev
;
922 url
= GetAbsoluteUrlFromRelativeUrl(url
);
923 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
924 url
.Replace(_T("%PATH%"), relurl
);
926 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
933 theApp
.DoWaitCursor(-1);
936 void CGitLogList::SetSelectedAction(int action
)
938 POSITION pos
= GetFirstSelectedItemPosition();
942 index
= GetNextSelectedItem(pos
);
943 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
945 this->GetItemRect(index
,&rect
,LVIR_BOUNDS
);
946 this->InvalidateRect(rect
);