From 44722553f88a83dc5d3cf9e2d6e2408ad54abb70 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Mon, 3 Oct 2011 03:50:00 +0200 Subject: [PATCH] added massive helper Signed-off-by: Sven Strickroth --- src/TortoiseProc/MassiveGitTask.cpp | 107 +++++++++++++++++++++++++++++++++++ src/TortoiseProc/MassiveGitTask.h | 47 +++++++++++++++ src/TortoiseProc/TortoiseProc.vcproj | 8 +++ 3 files changed, 162 insertions(+) create mode 100644 src/TortoiseProc/MassiveGitTask.cpp create mode 100644 src/TortoiseProc/MassiveGitTask.h diff --git a/src/TortoiseProc/MassiveGitTask.cpp b/src/TortoiseProc/MassiveGitTask.cpp new file mode 100644 index 000000000..22752b23e --- /dev/null +++ b/src/TortoiseProc/MassiveGitTask.cpp @@ -0,0 +1,107 @@ +// TortoiseGit - a Windows shell extension for easy version control + +// Copyright (C) 2011-2012 - Sven Strickroth + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// + +#include "StdAfx.h" +#include "TortoiseProc.h" +#include "MassiveGitTask.h" +#include "MessageBox.h" + +MassiveGitTask::MassiveGitTask(CString gitParameters) + : m_bUnused(true) + , m_NotifyCallbackInstance(NULL) + , m_NotifyCallbackMethod(NULL) +{ + m_sParams = gitParameters; +} + +MassiveGitTask::~MassiveGitTask(void) +{ +} + +void MassiveGitTask::AddFile(CString filename) +{ + assert(m_bUnused); + m_pathList.AddPath(filename); +} + +void MassiveGitTask::AddFile(CTGitPath filename) +{ + assert(m_bUnused); + m_pathList.AddPath(filename); +} + +bool MassiveGitTask::ExecuteWithNotify(CTGitPathList *pathList, BOOL &cancel, git_wc_notify_action_t action, CGitProgressDlg * instance, NOTIFY_CALLBACK notifyMethod) +{ + assert(m_bUnused); + m_bUnused = false; + + m_pathList = *pathList; + m_NotifyCallbackInstance = instance; + m_NotifyCallbackMethod = notifyMethod; + m_NotifyCallbackAction = action; + return ExecuteCommands(cancel); +} + +bool MassiveGitTask::Execute(BOOL &cancel) +{ + assert(m_bUnused); + return ExecuteCommands(cancel); +} + +bool MassiveGitTask::ExecuteCommands(BOOL &cancel) +{ + m_bUnused = false; + + bool bErrorsOccurred = false; + int maxLength = 0; + int firstCombine = 0; + for(int i = 0; i < m_pathList.GetCount(); i++) + { + if (maxLength + m_pathList[i].GetGitPathString().GetLength() > MAX_COMMANDLINE_LENGTH || i == m_pathList.GetCount() - 1 || cancel) + { + CString add; + for (int j = firstCombine; j <= i; j++) + add += _T(" \"") + m_pathList[j].GetGitPathString() + _T("\""); + + CString cmd, out; + cmd.Format(_T("git.exe %s --%s"), m_sParams, add); + if(g_Git.Run(cmd, &out, CP_ACP)) + { + CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR); + bErrorsOccurred = true; + return false; + } + + if (m_NotifyCallbackInstance && m_NotifyCallbackMethod) + for (int j = firstCombine; j <= i; j++) + (*m_NotifyCallbackInstance.*m_NotifyCallbackMethod)(m_pathList[j], m_NotifyCallbackAction, 0, NULL); + + maxLength = 0; + firstCombine = i+1; + + if (cancel) + break; + } + else + { + maxLength += 3 + m_pathList[i].GetGitPathString().GetLength(); + } + } + return !bErrorsOccurred; +} diff --git a/src/TortoiseProc/MassiveGitTask.h b/src/TortoiseProc/MassiveGitTask.h new file mode 100644 index 000000000..ad64f10d0 --- /dev/null +++ b/src/TortoiseProc/MassiveGitTask.h @@ -0,0 +1,47 @@ +// TortoiseGit - a Windows shell extension for easy version control + +// Copyright (C) 2011-2012 - Sven Strickroth + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// + +#pragma once +#include "GitProgressDlg.h" +#include "TGitPath.h" + +#define MAX_COMMANDLINE_LENGTH 30000 + +typedef BOOL (__cdecl CGitProgressDlg::*NOTIFY_CALLBACK)(const CTGitPath& path, git_wc_notify_action_t action, int status, CString *strErr); + +class MassiveGitTask +{ +public: + MassiveGitTask(CString params); + ~MassiveGitTask(void); + + void AddFile(CString filename); + void AddFile(CTGitPath filename); + bool ExecuteWithNotify(CTGitPathList *pathList, BOOL &cancel, git_wc_notify_action_t action, CGitProgressDlg * instance, NOTIFY_CALLBACK m_NotifyCallbackMethod); + bool Execute(BOOL &cancel); + +private: + bool ExecuteCommands(BOOL &cancel); + bool m_bUnused; + CString m_sParams; + CTGitPathList m_pathList; + CGitProgressDlg * m_NotifyCallbackInstance; + NOTIFY_CALLBACK m_NotifyCallbackMethod; + git_wc_notify_action_t m_NotifyCallbackAction; +}; diff --git a/src/TortoiseProc/TortoiseProc.vcproj b/src/TortoiseProc/TortoiseProc.vcproj index 3795465e4..4aee78ff6 100644 --- a/src/TortoiseProc/TortoiseProc.vcproj +++ b/src/TortoiseProc/TortoiseProc.vcproj @@ -417,6 +417,14 @@ > + + + + -- 2.11.4.GIT