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
23 #include "TortoiseProc.h"
24 #include "GitLogList.h"
26 //#include "VssStyle.h"
32 #include "SVNProgressDlg.h"
33 #include "ProgressDlg.h"
34 #include "SysProgressDlg.h"
35 //#include "RepositoryBrowser.h"
36 //#include "CopyDlg.h"
37 //#include "StatGraphDlg.h"
39 #include "MessageBox.h"
42 #include "PathUtils.h"
43 #include "StringUtils.h"
44 #include "UnicodeUtils.h"
46 //#include "GitInfo.h"
47 //#include "GitDiff.h"
49 //#include "RevisionRangeDlg.h"
50 //#include "BrowseFolder.h"
51 //#include "BlameDlg.h"
53 //#include "GitHelpers.h"
54 #include "GitStatus.h"
55 //#include "LogDlgHelper.h"
56 //#include "CachedLogInfo.h"
57 //#include "RepositoryInfo.h"
58 //#include "EditPropertiesDlg.h"
59 #include "FileDiffDlg.h"
60 #include "CommitDlg.h"
61 #include "RebaseDlg.h"
64 IMPLEMENT_DYNAMIC(CGitLogList
, CHintListCtrl
)
66 int CGitLogList::RevertSelectedCommits()
68 CSysProgressDlg progress
;
72 if(!g_Git
.CheckCleanWorkTree())
74 CMessageBox::Show(NULL
,_T("Revert requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
79 if (progress
.IsValid() && (this->GetSelectedCount() > 1) )
81 progress
.SetTitle(_T("Revert Commit"));
82 progress
.SetAnimation(IDR_MOVEANI
);
83 progress
.SetTime(true);
84 progress
.ShowModeless(this);
87 POSITION pos
= GetFirstSelectedItemPosition();
91 int index
= GetNextSelectedItem(pos
);
92 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(index
));
94 if (progress
.IsValid() && (this->GetSelectedCount() > 1) )
96 progress
.FormatPathLine(1, _T("Revert %s"), r1
->m_CommitHash
.ToString());
97 progress
.FormatPathLine(2, _T("%s"), r1
->GetSubject());
98 progress
.SetProgress(i
, this->GetSelectedCount());
102 if(r1
->m_CommitHash
.IsEmpty())
106 cmd
.Format(_T("git.exe revert --no-edit --no-commit %s"), r1
->m_CommitHash
.ToString());
107 if(g_Git
.Run(cmd
, &output
, CP_ACP
))
110 str
=_T("Revert fail\n");
112 str
+= _T("\n")+output
;
113 if( GetSelectedCount() == 1)
114 CMessageBox::Show(NULL
,str
, _T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
117 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"),2 , IDI_ERROR
, _T("&Skip"), _T("&Abort")) == 2)
128 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
133 int CGitLogList::CherryPickFrom(CString from
, CString to
)
135 CLogDataVector
logs(&m_LogCache
);
136 if(logs
.ParserFromLog(NULL
,-1,0,&from
,&to
))
142 CSysProgressDlg progress
;
143 if (progress
.IsValid())
145 progress
.SetTitle(_T("Cherry Pick"));
146 progress
.SetAnimation(IDR_MOVEANI
);
147 progress
.SetTime(true);
148 progress
.ShowModeless(this);
151 for(int i
=logs
.size()-1;i
>=0;i
--)
153 if (progress
.IsValid())
155 progress
.FormatPathLine(1, _T("Pick up %s"), logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
156 progress
.FormatPathLine(2, _T("%s"), logs
.GetGitRevAt(i
).GetSubject());
157 progress
.SetProgress(logs
.size()-i
, logs
.size());
159 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
161 //CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
162 throw std::exception(CUnicodeUtils::GetUTF8(_T("User canceled\r\n\r\n")));
166 cmd
.Format(_T("git.exe cherry-pick %s"),logs
.GetGitRevAt(i
).m_CommitHash
.ToString());
168 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
170 throw std::exception(CUnicodeUtils::GetUTF8(CString(_T("Cherry Pick Failure\r\n\r\n"))+out
));
178 void CGitLogList::ContextMenuAction(int cmd
,int FirstSelect
, int LastSelect
, CMenu
*popmenu
)
180 POSITION pos
= GetFirstSelectedItemPosition();
181 int indexNext
= GetNextSelectedItem(pos
);
185 GitRev
* pSelLogEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(indexNext
));
187 theApp
.DoWaitCursor(1);
192 CTGitPathList pathlist
;
193 CTGitPathList selectedlist
;
194 pathlist
.AddPath(this->m_Path
);
195 bool bSelectFilesForCommit
= !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\SelectFilesForCommit"), TRUE
));
197 CAppUtils::Commit(CString(),false,str
,
198 pathlist
,selectedlist
,bSelectFilesForCommit
);
200 this->GetParent()->PostMessage(WM_COMMAND
,ID_LOGDLG_REFRESH
,0);
205 CString tempfile
=GetTempFile();
207 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
208 if(!r1
->m_CommitHash
.IsEmpty())
213 if( (cmd
&0xFFFF) == 0xFFFF)
216 } else if((cmd
&0xFFFF) == 0xFFFE)
221 if(cmd
> r1
->m_ParentHash
.size())
224 str
.Format(_T("%d parent does not exist"), cmd
);
225 CMessageBox::Show(NULL
,str
,_T("TortoiseGit"),MB_OK
|MB_ICONERROR
);
230 hash2
= r1
->m_ParentHash
[cmd
-1].ToString();
233 command
.Format(_T("git.exe diff-tree %s -r -p --stat %s %s"),merge
, r1
->m_CommitHash
.ToString(), hash2
);
235 command
.Format(_T("git.exe diff -r -p --stat"));
237 g_Git
.RunLogFile(command
,tempfile
);
238 CAppUtils::StartUnifiedDiffViewer(tempfile
,r1
->m_CommitHash
.ToString().Left(6)+_T(":")+r1
->GetSubject());
244 CString tempfile
=GetTempFile();
246 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
247 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
249 if( r1
->m_CommitHash
.IsEmpty()) {
250 cmd
.Format(_T("git.exe diff -r -p --stat %s"),r2
->m_CommitHash
.ToString());
251 }else if( r2
->m_CommitHash
.IsEmpty()) {
252 cmd
.Format(_T("git.exe diff -r -p --stat %s"),r1
->m_CommitHash
.ToString());
254 cmd
.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r2
->m_CommitHash
.ToString(),r1
->m_CommitHash
.ToString());
257 g_Git
.RunLogFile(cmd
,tempfile
);
258 CAppUtils::StartUnifiedDiffViewer(tempfile
,r2
->m_CommitHash
.ToString().Left(6)+_T(":")+r1
->m_CommitHash
.ToString().Left(6));
265 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
266 GitRev
* r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
267 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
274 GitRev
* r1
= &m_wcRev
;
275 GitRev
* r2
= pSelLogEntry
;
277 CGitDiff::DiffCommit(this->m_Path
, r1
,r2
);
279 //user clicked on the menu item "compare with working copy"
282 // GitDiff diff(this, m_hWnd, true);
283 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
284 // diff.SetHEADPeg(m_LogRevision);
285 // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected);
288 // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
292 case ID_COMPAREWITHPREVIOUS
:
297 if(pSelLogEntry
->m_ParentHash
.size()>0)
298 //if(m_logEntries.m_HashMap[pSelLogEntry->m_ParentHash[0]]>=0)
306 CGitDiff::DiffCommit(this->m_Path
, pSelLogEntry
->m_CommitHash
.ToString(),pSelLogEntry
->m_ParentHash
[cmd
-1].ToString());
310 CMessageBox::Show(NULL
,_T("No previous version"),_T("TortoiseGit"),MB_OK
);
314 // GitDiff diff(this, m_hWnd, true);
315 // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
316 // diff.SetHEADPeg(m_LogRevision);
317 // diff.ShowCompare(CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected);
320 // CAppUtils::StartShowCompare(m_hWnd, CTGitPath(pathURL), revPrevious, CTGitPath(pathURL), revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
323 case ID_COPYCLIPBOARD
:
325 CopySelectionToClipBoard();
330 CopySelectionToClipBoard(TRUE
);
335 CString str
=pSelLogEntry
->m_CommitHash
.ToString();
336 CAppUtils::Export(&str
);
339 case ID_CREATE_BRANCH
:
341 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
342 CAppUtils::CreateBranchTag(FALSE
,&str
);
349 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
350 CAppUtils::CreateBranchTag(TRUE
,&str
);
353 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
358 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
359 CAppUtils::Switch(&str
);
363 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
365 case ID_SWITCHBRANCH
:
368 CString
*branch
= (CString
*)((CIconMenu
*)popmenu
)->GetMenuItemData(cmd
);
372 CProgressDlg progress
;
374 if(branch
->Find(_T("refs/heads/")) ==0 )
375 name
= branch
->Mid(11);
379 progress
.m_GitCmd
.Format(_T("git.exe checkout %s"), name
.GetString());
384 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
389 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
390 CAppUtils::GitReset(&str
);
396 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_PICK
);
399 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_EDIT
);
401 case ID_REBASE_SQUASH
:
402 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SQUASH
);
405 SetSelectedAction(CTGitPath::LOGACTIONS_REBASE_SKIP
);
407 case ID_COMBINE_COMMIT
:
411 CGitHash hashFirst
,hashLast
;
413 int headindex
=GetHeadIndex();
414 if(headindex
>=0) //incase show all branch, head is not the first commits.
416 head
.Format(_T("HEAD~%d"),FirstSelect
-headindex
);
417 hashFirst
=g_Git
.GetHash(head
);
419 head
.Format(_T("HEAD~%d"),LastSelect
-headindex
);
420 hashLast
=g_Git
.GetHash(head
);
423 GitRev
* pFirstEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
424 GitRev
* pLastEntry
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
425 if(pFirstEntry
->m_CommitHash
!= hashFirst
|| pLastEntry
->m_CommitHash
!= hashLast
)
427 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 headhash
=g_Git
.GetHash(_T("HEAD"));
433 if(!g_Git
.CheckCleanWorkTree())
435 CMessageBox::Show(NULL
,_T("Combine needs a clean work tree"),_T("TortoiseGit"),MB_OK
);
440 //Use throw to abort this process (reset back to original HEAD)
443 cmd
.Format(_T("git.exe reset --hard %s"),pFirstEntry
->m_CommitHash
.ToString());
444 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
446 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
447 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to first commit (first step) aborting...\r\n\r\n")+out
));
449 cmd
.Format(_T("git.exe reset --mixed %s"),hashLast
.ToString());
450 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
452 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
453 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to last commit (second step) aborting...\r\n\r\n")+out
));
456 CTGitPathList PathList
;
457 /* don't why must add --stat to get action status*/
458 /* first -z will be omitted by gitdll*/
459 if(g_Git
.GetDiffPath(&PathList
,&pFirstEntry
->m_CommitHash
,&hashLast
,"-z --stat -r"))
461 CMessageBox::Show(NULL
,_T("Get Diff file list error"),_T("TortoiseGit"),MB_OK
);
462 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not get changed file list aborting...\r\n\r\n")+out
));
465 for(int i
=0;i
<PathList
.GetCount();i
++)
467 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_ADDED
)
469 cmd
.Format(_T("git.exe add -- \"%s\""), PathList
[i
].GetGitPathString());
470 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
472 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
473 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not add new file aborting...\r\n\r\n")+out
));
477 if(PathList
[i
].m_Action
& CTGitPath::LOGACTIONS_DELETED
)
479 cmd
.Format(_T("git.exe rm -- \"%s\""), PathList
[i
].GetGitPathString());
480 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
482 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
483 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not rm file aborting...\r\n\r\n")+out
));
489 for(int i
=FirstSelect
;i
<=LastSelect
;i
++)
491 GitRev
* pRev
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(i
));
492 dlg
.m_sLogMessage
+=pRev
->GetSubject()+_T("\n")+pRev
->GetBody();
493 dlg
.m_sLogMessage
+=_T("\n");
495 dlg
.m_bWholeProject
=true;
496 dlg
.m_bSelectFilesForCommit
= true;
497 dlg
.m_bCommitAmend
=true;
498 dlg
.m_bNoPostActions
=true;
499 dlg
.m_AmendStr
=dlg
.m_sLogMessage
;
501 if (dlg
.DoModal() == IDOK
)
503 if(pFirstEntry
->m_CommitHash
!=headhash
)
505 //Commitrange firstEntry..headhash (from top of combine to original head) needs to be 'cherry-picked'
506 //on top of new commit.
507 //Use the rebase --onto command for it.
509 //All this can be done in one step using the following command:
510 //cmd.Format(_T("git.exe format-patch --stdout --binary --full-index -k %s..%s | git am -k -3"),
511 // pFirstEntry->m_CommitHash,
513 //But I am not sure if a '|' is going to work in a CreateProcess() call.
515 //Later the progress dialog could be used to execute these steps.
517 if(CherryPickFrom(pFirstEntry
->m_CommitHash
.ToString(),headhash
))
520 msg
.Format(_T("Error while cherry pick commits on top of combined commits. Aborting.\r\n\r\n"));
521 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
524 CString currentBranch
=g_Git
.GetCurrentBranch();
525 cmd
.Format(_T("git.exe rebase --onto \"%s\" %s %s"),
527 pFirstEntry
->m_CommitHash
,
529 if(g_Git
.Run(cmd
,&out
,CP_UTF8
)!=0)
532 msg
.Format(_T("Error while rebasing commits on top of combined commits. Aborting.\r\n\r\n%s"),out
);
533 // CMessageBox::Show(NULL,msg,_T("TortoiseGit"),MB_OK);
534 g_Git
.Run(_T("git.exe rebase --abort"),&out
,CP_UTF8
);
535 throw std::exception(CUnicodeUtils::GetUTF8(msg
));
538 //HEAD is now on <no branch>.
539 //The following steps are to get HEAD back on the original branch and reset the branch to the new HEAD
540 //To avoid 2 working copy changes, we could use git branch -f <original branch> <hash new head>
541 //And then git checkout <original branch>
542 //But I don't know if 'git branch -f' removes tracking options. So for now, do a checkout and a reset.
545 CString newHead
=g_Git
.GetHash(CString(_T("HEAD")));
547 //Checkout working branch
548 cmd
.Format(_T("git.exe checkout -f \"%s\""),currentBranch
);
549 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
550 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not checkout original branch. Aborting...\r\n\r\n")+out
));
553 cmd
.Format(_T("git.exe reset --hard %s"),newHead
);
554 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
555 throw std::exception(CUnicodeUtils::GetUTF8(_T("Could not reset to new head. Aborting...\r\n\r\n")+out
));
560 throw std::exception("User aborted the combine process");
562 catch(std::exception
& e
)
564 CMessageBox::Show(NULL
,CUnicodeUtils::GetUnicode(CStringA(e
.what())),_T("TortoiseGit: Combine error"),MB_OK
|MB_ICONERROR
);
565 cmd
.Format(_T("git.exe reset --hard %s"),headhash
.ToString());
567 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
569 CMessageBox::Show(NULL
,_T("Could not reset to original HEAD\r\n\r\n")+out
,_T("TortoiseGit"),MB_OK
);
577 if(!g_Git
.CheckCleanWorkTree())
579 CMessageBox::Show(NULL
,_T("Cherry Pick requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
584 dlg
.m_IsCherryPick
= TRUE
;
585 dlg
.m_Upstream
= this->m_CurrentBranch
;
586 POSITION pos
= GetFirstSelectedItemPosition();
589 int indexNext
= GetNextSelectedItem(pos
);
590 dlg
.m_CommitList
.m_logEntries
.push_back( ((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
);
591 dlg
.m_CommitList
.m_LogCache
.m_HashMap
[((GitRev
*)m_arShownList
[indexNext
])->m_CommitHash
]=*(GitRev
*)m_arShownList
[indexNext
];
592 dlg
.m_CommitList
.m_logEntries
.GetGitRevAt(dlg
.m_CommitList
.m_logEntries
.size()-1).GetAction(this) |= CTGitPath::LOGACTIONS_REBASE_PICK
;
595 if(dlg
.DoModal() == IDOK
)
601 case ID_REBASE_TO_VERSION
:
602 if(!g_Git
.CheckCleanWorkTree())
604 CMessageBox::Show(NULL
,_T("Rebase requires a clean working tree"),_T("TortoiseGit"),MB_OK
);
609 dlg
.m_Upstream
= pSelLogEntry
->m_CommitHash
;
611 if(dlg
.DoModal() == IDOK
)
620 CAppUtils::StashApply(pSelLogEntry
->m_Ref
);
626 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?"),pSelLogEntry
->m_Ref
);
627 if(CMessageBox::Show(NULL
, str
, _T("TortoiseGit"), 1, IDI_QUESTION
, _T("&Delete"), _T("&Abort")) == 1)
630 cmd
.Format(_T("git.exe reflog delete %s"),pSelLogEntry
->m_Ref
);
631 if(g_Git
.Run(cmd
,&out
,CP_ACP
))
633 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
635 ::PostMessage(this->GetParent()->m_hWnd
,MSG_REFLOG_CHANGED
,0,0);
642 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
643 cmd
+= _T(" /command:log");
644 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
645 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
646 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
647 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
650 case ID_CREATE_PATCH
:
652 int select
=this->GetSelectedCount();
654 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
655 cmd
+= _T(" /command:formatpatch");
657 cmd
+= _T(" /path:\"")+g_Git
.m_CurrentDir
+_T("\" ");
659 GitRev
* r1
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(FirstSelect
));
663 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString();
667 r2
= reinterpret_cast<GitRev
*>(m_arShownList
.GetAt(LastSelect
));
668 if( this->m_IsOldFirst
)
670 cmd
+= _T(" /startrev:")+r1
->m_CommitHash
.ToString()+_T("~1");
671 cmd
+= _T(" /endrev:")+r2
->m_CommitHash
.ToString();
675 cmd
+= _T(" /startrev:")+r2
->m_CommitHash
.ToString()+_T("~1");
676 cmd
+= _T(" /endrev:")+r1
->m_CommitHash
.ToString();
681 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
687 if( this->m_HashMap
.find(pSelLogEntry
->m_CommitHash
) == m_HashMap
.end() )
689 CMessageBox::Show(NULL
,IDS_ERROR_NOREF
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
692 if( index
>= m_HashMap
[pSelLogEntry
->m_CommitHash
].size())
694 CMessageBox::Show(NULL
,IDS_ERROR_INDEX
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
698 ref
=m_HashMap
[pSelLogEntry
->m_CommitHash
][index
];
700 msg
=CString(_T("Do you really want to <ct=0x0000FF>delete</ct> <b>"))+ref
;
702 if( CMessageBox::Show(NULL
, msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, _T("&Delete"), _T("&Abort")) == 1 )
706 if(this->GetShortName(ref
,shortname
,_T("refs/heads/")))
708 cmd
.Format(_T("git.exe branch -D %s"),shortname
);
711 if(this->GetShortName(ref
,shortname
,_T("refs/remotes/")))
713 cmd
.Format(_T("git.exe branch -r -D %s"),shortname
);
716 if(this->GetShortName(ref
,shortname
,_T("refs/tags/")))
718 cmd
.Format(_T("git.exe tag -d %s"),shortname
);
721 if(this->GetShortName(ref
,shortname
,_T("refs/stash")))
723 if(CMessageBox::Show(NULL
, _T("<ct=0x0000FF>Do you really want to delete <b>ALL</b> stash?</ct>"),
724 _T("TortoiseGit"), 2, IDI_QUESTION
, _T("&Delete"), _T("&Abort")) == 2)
725 cmd
.Format(_T("git.exe stash clear"));
731 if(g_Git
.Run(cmd
,&out
,CP_UTF8
))
733 CMessageBox::Show(NULL
,out
,_T("TortoiseGit"),MB_OK
);
735 this->ReloadHashMap();
737 this->GetItemRect(FirstSelect
,&rect
,LVIR_BOUNDS
);
738 this->InvalidateRect(rect
);
745 m_nSearchIndex
= GetSelectionMark();
746 if (m_nSearchIndex
< 0)
754 m_pFindDialog
= new CFindDlg();
755 m_pFindDialog
->Create(this);
761 CString str
= pSelLogEntry
->m_CommitHash
.ToString();
762 // we need an URL to complete this command, so error out if we can't get an URL
763 if(CAppUtils::Merge(&str
))
771 if(!this->RevertSelectedCommits())
777 CAppUtils::EditNote(pSelLogEntry
);
778 this->SetItemState(FirstSelect
, 0, LVIS_SELECTED
);
779 this->SetItemState(FirstSelect
, LVIS_SELECTED
, LVIS_SELECTED
);
783 //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK);
787 case ID_BLAMECOMPARE
:
789 //user clicked on the menu item "compare with working copy"
790 //now first get the revision which is selected
793 GitDiff
diff(this, this->m_hWnd
, true);
794 diff
.SetHEADPeg(m_LogRevision
);
795 diff
.ShowCompare(m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), false, true);
798 CAppUtils::StartShowCompare(m_hWnd
, m_path
, GitRev::REV_BASE
, m_path
, revSelected
, GitRev(), m_LogRevision
, false, false, true);
803 //user clicked on the menu item "compare and blame revisions"
806 GitDiff
diff(this, this->m_hWnd
, true);
807 diff
.SetHEADPeg(m_LogRevision
);
808 diff
.ShowCompare(CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
811 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revSelected2
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
814 case ID_BLAMEWITHPREVIOUS
:
816 //user clicked on the menu item "Compare and Blame with previous revision"
819 GitDiff
diff(this, this->m_hWnd
, true);
820 diff
.SetHEADPeg(m_LogRevision
);
821 diff
.ShowCompare(CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), false, true);
824 CAppUtils::StartShowCompare(m_hWnd
, CTGitPath(pathURL
), revPrevious
, CTGitPath(pathURL
), revSelected
, GitRev(), m_LogRevision
, false, false, true);
832 CProgressDlg progDlg
;
833 progDlg
.SetTitle(IDS_APPNAME
);
834 progDlg
.SetAnimation(IDR_DOWNLOAD
);
836 sInfoLine
.Format(IDS_PROGRESSGETFILEREVISION
, m_path
.GetWinPath(), (LPCTSTR
)revSelected
.ToString());
837 progDlg
.SetLine(1, sInfoLine
, true);
838 SetAndClearProgressInfo(&progDlg
);
839 progDlg
.ShowModeless(m_hWnd
);
840 CTGitPath tempfile
= CTempFiles::Instance().GetTempFilePath(false, m_path
, revSelected
);
841 bool bSuccess
= true;
842 if (!Cat(m_path
, GitRev(GitRev::REV_HEAD
), revSelected
, tempfile
))
845 // try again, but with the selected revision as the peg revision
846 if (!Cat(m_path
, revSelected
, revSelected
, tempfile
))
849 SetAndClearProgressInfo((HWND
)NULL
);
850 CMessageBox::Show(this->m_hWnd
, GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
859 SetAndClearProgressInfo((HWND
)NULL
);
860 SetFileAttributes(tempfile
.GetWinPath(), FILE_ATTRIBUTE_READONLY
);
863 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, tempfile
.GetWinPath(), NULL
, NULL
, SW_SHOWNORMAL
);
864 if ((ret
<= HINSTANCE_ERROR
)||bOpenWith
)
866 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
867 cmd
+= tempfile
.GetWinPathString() + _T(" ");
868 CAppUtils::LaunchApplication(cmd
, NULL
, false);
876 dlg
.EndRev
= revSelected
;
877 if (dlg
.DoModal() == IDOK
)
882 tempfile
= blame
.BlameToTempFile(m_path
, dlg
.StartRev
, dlg
.EndRev
, dlg
.EndRev
, logfile
, _T(""), dlg
.m_bIncludeMerge
, TRUE
, TRUE
);
883 if (!tempfile
.IsEmpty())
887 //open the default text editor for the result file
888 CAppUtils::StartTextViewer(tempfile
);
892 CString sParams
= _T("/path:\"") + m_path
.GetGitPathString() + _T("\" ");
893 if(!CAppUtils::LaunchTortoiseBlame(tempfile
, logfile
, CPathUtils::GetFileNameFromPath(m_path
.GetFileOrDirectoryName()),sParams
))
901 CMessageBox::Show(this->m_hWnd
, blame
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
909 CString url
= _T("tgit:")+pathURL
;
910 sCmd
.Format(_T("%s /command:update /path:\"%s\" /rev:%ld"),
911 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
912 (LPCTSTR
)m_path
.GetWinPath(), (LONG
)revSelected
);
913 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
920 sCmd
.Format(_T("%s /command:repobrowser /path:\"%s\" /rev:%s"),
921 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
922 (LPCTSTR
)pathURL
, (LPCTSTR
)revSelected
.ToString());
924 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
929 EditLogMessage(selIndex
);
934 EditAuthor(selEntries
);
939 CEditPropertiesDlg dlg
;
940 dlg
.SetProjectProperties(&m_ProjectProperties
);
941 CTGitPathList escapedlist
;
942 dlg
.SetPathList(CTGitPathList(CTGitPath(pathURL
)));
943 dlg
.SetRevision(revSelected
);
952 sCmd
.Format(_T("%s /command:export /path:\"%s\" /revision:%ld"),
953 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
954 (LPCTSTR
)pathURL
, (LONG
)revSelected
);
955 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
961 CString url
= _T("tgit:")+pathURL
;
962 sCmd
.Format(_T("%s /command:checkout /url:\"%s\" /revision:%ld"),
963 (LPCTSTR
)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")),
964 (LPCTSTR
)url
, (LONG
)revSelected
);
965 CAppUtils::LaunchApplication(sCmd
, NULL
, false);
970 CString url
= m_ProjectProperties
.sWebViewerRev
;
971 url
= GetAbsoluteUrlFromRelativeUrl(url
);
972 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
974 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
979 CString relurl
= pathURL
;
980 CString sRoot
= GetRepositoryRoot(CTGitPath(relurl
));
981 relurl
= relurl
.Mid(sRoot
.GetLength());
982 CString url
= m_ProjectProperties
.sWebViewerPathRev
;
983 url
= GetAbsoluteUrlFromRelativeUrl(url
);
984 url
.Replace(_T("%REVISION%"), revSelected
.ToString());
985 url
.Replace(_T("%PATH%"), relurl
);
987 ShellExecute(this->m_hWnd
, _T("open"), url
, NULL
, NULL
, SW_SHOWDEFAULT
);
994 theApp
.DoWaitCursor(-1);
997 void CGitLogList::SetSelectedAction(int action
)
999 POSITION pos
= GetFirstSelectedItemPosition();
1003 index
= GetNextSelectedItem(pos
);
1004 ((GitRev
*)m_arShownList
[index
])->GetAction(this) = action
;
1006 this->GetItemRect(index
,&rect
,LVIR_BOUNDS
);
1007 this->InvalidateRect(rect
);