From e82fdcfa4b3e4611619a5674c19a8f693f26b545 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 28 Aug 2012 07:59:13 +0200 Subject: [PATCH] Moved bisect start logic to AppUtils Signed-off-by: Sven Strickroth --- src/TortoiseProc/AppUtils.cpp | 56 +++++++++++++++++++++++++++++ src/TortoiseProc/AppUtils.h | 2 ++ src/TortoiseProc/Commands/BisectCommand.cpp | 56 ++++------------------------- 3 files changed, 65 insertions(+), 49 deletions(-) diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 414ab139b..f886a9966 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -61,6 +61,7 @@ #include "IgnoreDlg.h" #include "FormatMessageWrapper.h" #include "SmartHandle.h" +#include "BisectStartDlg.h" CAppUtils::CAppUtils(void) { @@ -2599,3 +2600,58 @@ void CAppUtils::SetWindowTitle(HWND hWnd, const CString& urlorpath, const CStrin wcscat_s(pathbuf, CString(MAKEINTRESOURCE(IDS_APPNAME))); SetWindowText(hWnd, pathbuf); } + +bool CAppUtils::BisectStart(CString lastGood, CString firstBad, bool autoClose) +{ + if (!g_Git.CheckCleanWorkTree()) + { + if (CMessageBox::Show(NULL, IDS_ERROR_NOCLEAN_STASH, IDS_APPNAME, MB_YESNO|MB_ICONINFORMATION) == IDYES) + { + CString cmd, out; + cmd = _T("git.exe stash"); + if (g_Git.Run(cmd, &out, CP_UTF8)) + { + CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK); + return false; + } + } + else + return false; + } + + CBisectStartDlg bisectStartDlg; + + if (!lastGood.IsEmpty()) + bisectStartDlg.m_sLastGood = lastGood; + if (!firstBad.IsEmpty()) + bisectStartDlg.m_sFirstBad = firstBad; + + if (bisectStartDlg.DoModal() == IDOK) + { + CProgressDlg progress; + theApp.m_pMainWnd = &progress; + progress.m_bAutoCloseOnSuccess = autoClose; + progress.m_GitCmdList.push_back(_T("git.exe bisect start")); + progress.m_GitCmdList.push_back(_T("git.exe bisect good ") + bisectStartDlg.m_LastGoodRevision); + progress.m_GitCmdList.push_back(_T("git.exe bisect bad ") + bisectStartDlg.m_FirstBadRevision); + + CTGitPath path(g_Git.m_CurrentDir); + + if (path.HasSubmodules()) + progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE))); + + INT_PTR ret = progress.DoModal(); + if (path.HasSubmodules() && ret == IDC_PROGRESS_BUTTON1) + { + CString sCmd; + sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir); + + CAppUtils::RunTortoiseProc(sCmd); + return true; + } + else if (ret == IDOK) + return true; + } + + return false; +} \ No newline at end of file diff --git a/src/TortoiseProc/AppUtils.h b/src/TortoiseProc/AppUtils.h index 36bfe9749..ed9f82264 100644 --- a/src/TortoiseProc/AppUtils.h +++ b/src/TortoiseProc/AppUtils.h @@ -198,6 +198,8 @@ public: static int GetMsysgitVersion(CString *versionstring=NULL); static void MarkWindowAsUnpinnable(HWND hWnd); + static bool BisectStart(CString lastGood, CString firstBad, bool autoClose = false); + private: static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2); static bool GetMimeType(const CTGitPath& file, CString& mimetype); diff --git a/src/TortoiseProc/Commands/BisectCommand.cpp b/src/TortoiseProc/Commands/BisectCommand.cpp index dba1f8013..12bda5372 100644 --- a/src/TortoiseProc/Commands/BisectCommand.cpp +++ b/src/TortoiseProc/Commands/BisectCommand.cpp @@ -18,7 +18,6 @@ // #include "StdAfx.h" #include "BisectCommand.h" -#include "BisectStartDlg.h" #include "AppUtils.h" #include "ProgressDlg.h" #include "MessageBox.h" @@ -30,58 +29,17 @@ bool BisectCommand::Execute() if (this->parser.HasKey(_T("start")) && !path.IsBisectActive()) { - if(!g_Git.CheckCleanWorkTree()) - { - if (CMessageBox::Show(NULL, IDS_ERROR_NOCLEAN_STASH, IDS_APPNAME, MB_YESNO|MB_ICONINFORMATION) == IDYES) - { - CString cmd, out; - cmd = _T("git.exe stash"); - if (g_Git.Run(cmd, &out, CP_UTF8)) - { - CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK); - return false; - } - } - else - return false; - } - - CBisectStartDlg bisectStartDlg; + bool autoClose = false; + if (parser.HasVal(_T("closeonend"))) + autoClose = !!parser.GetLongVal(_T("closeonend")); + CString lastGood, firstBad; if (parser.HasKey(_T("good"))) - bisectStartDlg.m_sLastGood = parser.GetVal(_T("good")); + lastGood = parser.GetVal(_T("good")); if (parser.HasKey(_T("bad"))) - bisectStartDlg.m_sFirstBad = parser.GetVal(_T("bad")); - - if (bisectStartDlg.DoModal() == IDOK) - { - CProgressDlg progress; - theApp.m_pMainWnd = &progress; - if (parser.HasVal(_T("closeonend"))) - progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend")); - progress.m_GitCmdList.push_back(_T("git.exe bisect start")); - progress.m_GitCmdList.push_back(_T("git.exe bisect good ") + bisectStartDlg.m_LastGoodRevision); - progress.m_GitCmdList.push_back(_T("git.exe bisect bad ") + bisectStartDlg.m_FirstBadRevision); + firstBad = parser.GetVal(_T("bad")); - if (path.HasSubmodules()) - progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE))); - - INT_PTR ret = progress.DoModal(); - if (path.HasSubmodules() && ret == IDC_PROGRESS_BUTTON1) - { - CString sCmd; - sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir); - - CAppUtils::RunTortoiseProc(sCmd); - return true; - } - else if (ret == IDOK) - return true; - } - else - { - return false; - } + return CAppUtils::BisectStart(lastGood, firstBad, autoClose); } else if ((this->parser.HasKey(_T("good")) || this->parser.HasKey(_T("bad")) || this->parser.HasKey(_T("reset"))) && path.IsBisectActive()) { -- 2.11.4.GIT