From 95b395c6dd89f5972f500050dc6e1b1b8c72bc03 Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Wed, 4 Nov 2015 22:09:56 +0800 Subject: [PATCH] Refactor bisect operations into CAppUtils Signed-off-by: Sup Yut Sum --- src/TortoiseProc/AppUtils.cpp | 39 ++++++++++++++++++++++++++++ src/TortoiseProc/AppUtils.h | 1 + src/TortoiseProc/Commands/BisectCommand.cpp | 40 +++++------------------------ 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index dc96d5452..49d3ef4b5 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -3542,6 +3542,45 @@ bool CAppUtils::BisectStart(const CString& lastGood, const CString& firstBad, bo return false; } +bool CAppUtils::BisectOperation(const CString& op, const CString& ref, bool bIsMainWnd) +{ + CString cmd = _T("git.exe bisect ") + op; + + if (!ref.IsEmpty()) + { + cmd += _T(" "); + cmd += ref; + } + + CProgressDlg progress; + if (bIsMainWnd) + theApp.m_pMainWnd = &progress; + progress.m_GitCmd = cmd; + + progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList) + { + if (status) + return; + + CTGitPath path = g_Git.m_CurrentDir; + if (path.HasSubmodules()) + { + postCmdList.emplace_back(IDI_UPDATE, IDS_PROC_SUBMODULESUPDATE, [] + { + CString sCmd; + sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), (LPCTSTR)g_Git.m_CurrentDir); + CAppUtils::RunTortoiseGitProc(sCmd); + }); + } + + if (op != _T("reset")) + postCmdList.emplace_back(IDS_MENUBISECTRESET, []{ CAppUtils::RunTortoiseGitProc(_T("/command:bisect /reset")); }); + }; + + INT_PTR ret = progress.DoModal(); + return ret == IDOK; +} + int CAppUtils::Git2GetUserPassword(git_cred **out, const char *url, const char *username_from_url, unsigned int /*allowed_types*/, void * /*payload*/) { CUserPassword dlg; diff --git a/src/TortoiseProc/AppUtils.h b/src/TortoiseProc/AppUtils.h index 4e62a4bdc..71b5772ee 100644 --- a/src/TortoiseProc/AppUtils.h +++ b/src/TortoiseProc/AppUtils.h @@ -211,6 +211,7 @@ public: static void MarkWindowAsUnpinnable(HWND hWnd); static bool BisectStart(const CString& lastGood, const CString& firstBad, bool bIsMainWnd = false); + static bool BisectOperation(const CString& op, const CString& ref = _T(""), bool bIsMainWnd = false); static int Git2GetUserPassword(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload); diff --git a/src/TortoiseProc/Commands/BisectCommand.cpp b/src/TortoiseProc/Commands/BisectCommand.cpp index 37790876d..300b33a9c 100644 --- a/src/TortoiseProc/Commands/BisectCommand.cpp +++ b/src/TortoiseProc/Commands/BisectCommand.cpp @@ -39,46 +39,20 @@ bool BisectCommand::Execute() } else if ((this->parser.HasKey(_T("good")) || this->parser.HasKey(_T("bad")) || this->parser.HasKey(_T("reset"))) && path.IsBisectActive()) { - CString cmd = _T("git.exe bisect "); + CString op; + CString ref; if (this->parser.HasKey(_T("good"))) - cmd += _T("good"); + op = _T("good"); else if (this->parser.HasKey(_T("bad"))) - cmd += _T("bad"); + op = _T("bad"); else if (this->parser.HasKey(_T("reset"))) - cmd += _T("reset"); + op = _T("reset"); if (this->parser.HasKey(_T("ref")) &&! this->parser.HasKey(_T("reset"))) - { - cmd += _T(" "); - cmd += this->parser.GetVal(_T("ref")); - } + ref = this->parser.GetVal(_T("ref")); - CProgressDlg progress; - theApp.m_pMainWnd = &progress; - progress.m_GitCmd = cmd; - - progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList) - { - if (status) - return; - - if (path.HasSubmodules()) - { - postCmdList.emplace_back(IDI_UPDATE, IDS_PROC_SUBMODULESUPDATE, [] - { - CString sCmd; - sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), (LPCTSTR)g_Git.m_CurrentDir); - CAppUtils::RunTortoiseGitProc(sCmd); - }); - } - - if (!this->parser.HasKey(_T("reset"))) - postCmdList.emplace_back(IDS_MENUBISECTRESET, []{ CAppUtils::RunTortoiseGitProc(_T("/command:bisect /reset")); }); - }; - - INT_PTR ret = progress.DoModal(); - return ret == IDOK; + return CAppUtils::BisectOperation(op, ref); } else { -- 2.11.4.GIT