Disable warnings and drop prebuild scripts
[TortoiseGit.git] / src / TortoiseProc / MassiveGitTask.cpp
blobfca6525589fc785d6ea053df152560b5cf31aa3b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2012 - Sven Strickroth <email@cs-ware.de>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "StdAfx.h"
21 #include "TortoiseProc.h"
22 #include "MassiveGitTask.h"
23 #include "MessageBox.h"
25 CMassiveGitTask::CMassiveGitTask(CString gitParameters)
26 : m_bUnused(true)
27 , m_NotifyCallbackInstance(NULL)
28 , m_NotifyCallbackMethod(NULL)
29 , m_NotifyCallbackAction(git_wc_notify_add)
31 m_sParams = gitParameters;
34 CMassiveGitTask::~CMassiveGitTask(void)
38 void CMassiveGitTask::AddFile(CString filename)
40 assert(m_bUnused);
41 m_pathList.AddPath(filename);
44 void CMassiveGitTask::AddFile(CTGitPath filename)
46 assert(m_bUnused);
47 m_pathList.AddPath(filename);
50 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList *pathList, BOOL &cancel, git_wc_notify_action_t action, CGitProgressDlg * instance, NOTIFY_CALLBACK notifyMethod)
52 assert(m_bUnused);
53 m_bUnused = false;
55 m_pathList = *pathList;
56 m_NotifyCallbackInstance = instance;
57 m_NotifyCallbackMethod = notifyMethod;
58 m_NotifyCallbackAction = action;
59 return ExecuteCommands(cancel);
62 bool CMassiveGitTask::Execute(BOOL &cancel)
64 assert(m_bUnused);
65 m_pathList.RemoveDuplicates();
66 return ExecuteCommands(cancel);
69 bool CMassiveGitTask::ExecuteCommands(BOOL &cancel)
71 m_bUnused = false;
73 bool bErrorsOccurred = false;
74 int maxLength = 0;
75 int firstCombine = 0;
76 for(int i = 0; i < m_pathList.GetCount(); i++)
78 if (maxLength + m_pathList[i].GetGitPathString().GetLength() > MAX_COMMANDLINE_LENGTH || i == m_pathList.GetCount() - 1 || cancel)
80 CString add;
81 for (int j = firstCombine; j <= i; j++)
82 add += _T(" \"") + m_pathList[j].GetGitPathString() + _T("\"");
84 CString cmd, out;
85 cmd.Format(_T("git.exe %s --%s"), m_sParams, add);
86 if (g_Git.Run(cmd, &out, CP_UTF8))
88 CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
89 bErrorsOccurred = true;
90 return false;
93 if (m_NotifyCallbackInstance && m_NotifyCallbackMethod)
94 for (int j = firstCombine; j <= i; j++)
95 (*m_NotifyCallbackInstance.*m_NotifyCallbackMethod)(m_pathList[j], m_NotifyCallbackAction, 0, NULL);
97 maxLength = 0;
98 firstCombine = i+1;
100 if (cancel)
101 break;
103 else
105 maxLength += 3 + m_pathList[i].GetGitPathString().GetLength();
108 return !bErrorsOccurred;