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(
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
);
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
);
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
));
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,
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
))
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
));
467 CString currentBranch
=g_Git
.GetCurrentBranch();
468 cmd
.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
470 pFirstEntry
->m_CommitHash
,
472 if(g_Git
.Run(cmd
,&out
,CP_UTF8
)!=0)
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.
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
));
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
));
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());
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
);
520 if(!g_Git
.CheckCleanWorkTree())
522 CMessageBox::Show(NULL
,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
527 dlg
.m_IsCherryPick
= TRUE
;
528 dlg
.m_Upstream
= this->m_CurrentBranch
;
529 POSITION pos
= GetFirstSelectedItemPosition();
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
)
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
);
552 dlg
.m_Upstream
= pSelLogEntry
->m_CommitHash
;
554 if(dlg
.DoModal() == IDOK
)
563 CAppUtils::StashApply(pSelLogEntry
->m_Ref
);
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
)
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);
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);
593 case ID_CREATE_PATCH
:
595 int select
=this->GetSelectedCount();
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
));
606 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString();
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();
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);
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
);
635 if( index
>= m_HashMap
[pSelLogEntry
->m_CommitHash
].size())
637 CMessageBox::Show(NULL
,IDS_ERROR_INDEX
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
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
)
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"));
674 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
676 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
678 this->ReloadHashMap();
680 this->GetItemRect(FirstSelect
,&rect
,LVIR_BOUNDS
);
681 this->InvalidateRect(rect
);
688 m_nSearchIndex
= GetSelectionMark();
689 if (m_nSearchIndex
< 0)
697 m_pFindDialog
= new CFindDlg();
698 m_pFindDialog
->Create(this);
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()))
713 if(!this->RevertSelectedCommits())
719 CAppUtils::EditNote(pSelLogEntry
);
720 this->SetItemState(FirstSelect
, 0, LVIS_SELECTED
);
721 this->SetItemState(FirstSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
725 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
729 case ID_BLAMECOMPARE
:
731 //user clicked on the menu item "compare with working copy"
732 //now first get the revision which is selected
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);
740 CAppUtils::StartShowCompare(m_hWnd
, m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), m_LogRevision
, false, false, true);
745 //user clicked on the menu item "compare and blame revisions"
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);
753 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
756 case ID_BLAMEWITHPREVIOUS
:
758 //user clicked on the menu item "Compare and Blame with previous revision"
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);
766 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
774 CProgressDlg progDlg
;
775 progDlg
.SetTitle(IDS_APPNAME
);
776 progDlg
.SetAnimation(IDR_DOWNLOAD
);
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
))
787 // try again, but with the selected revision as the peg revision
788 if (!Cat(m_path
, revSelected
, revSelected
, tempfile
))
791 SetAndClearProgressInfo((HWND
)NULL
);
792 CMessageBox::Show(this->m_hWnd
, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
801 SetAndClearProgressInfo((HWND
)NULL
);
802 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
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);
818 dlg
.EndRev
= revSelected
;
819 if (dlg
.DoModal() == IDOK
)
824 tempfile
= blame
.BlameToTempFile(m_path
, dlg
.StartRev
, dlg
.EndRev
, dlg
.EndRev
, logfile
, _T(""), dlg
.m_bIncludeMerge
, TRUE
, TRUE
);
825 if (!tempfile
.IsEmpty())
829 //open the default text editor for the result file
830 CAppUtils::StartTextViewer(tempfile
);
834 CString sParams
= _T("/path:\"") + m_path
.GetGitPathString() + _T("\" ");
835 if(!CAppUtils::LaunchTortoiseBlame(tempfile
, logfile
, CPathUtils::GetFileNameFromPath(m_path
.GetFileOrDirectoryName()),sParams
))
843 CMessageBox::Show(this->m_hWnd
, blame
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
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);
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);
871 EditLogMessage(selIndex
);
876 EditAuthor(selEntries
);
881 CEditPropertiesDlg dlg
;
882 dlg
.SetProjectProperties(&m_ProjectProperties
);
883 CTGitPathList escapedlist
;
884 dlg
.SetPathList(CTGitPathList(CTGitPath(pathURL
)));
885 dlg
.SetRevision(revSelected
);
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);
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);
912 CString url
= m_ProjectProperties
.sWebViewerRev
;
913 url
= GetAbsoluteUrlFromRelativeUrl(url
);
914 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
916 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
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
);
929 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
936 theApp
.DoWaitCursor(-1);
939 void CGitLogList::SetSelectedAction(int action
)
941 POSITION pos
= GetFirstSelectedItemPosition();
945 index
= GetNextSelectedItem(pos
);
946 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
948 this->GetItemRect(index
,&rect
,LVIR_BOUNDS
);
949 this->InvalidateRect(rect
);