Fixed issue #1542: Can send pull request email
[TortoiseGit.git] / src / TortoiseProc / MassiveGitTask.cpp
blob7023d31d24cd340ac733cd34e44410dfdff5161c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2013 - Sven Strickroth <email@cs-ware.de>
4 // Copyright (C) 2013 - TortoiseGit
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.
21 #include "stdafx.h"
22 #include "TortoiseProc.h"
23 #include "MassiveGitTask.h"
24 #include "MessageBox.h"
26 CMassiveGitTask::CMassiveGitTask(CString gitParameters, BOOL isPath)
27 : m_bUnused(true)
28 , m_bIsPath(isPath)
29 , m_NotifyCallbackInstance(NULL)
30 , m_NotifyCallbackAction(git_wc_notify_add)
32 m_sParams = gitParameters;
35 CMassiveGitTask::~CMassiveGitTask(void)
39 void CMassiveGitTask::AddFile(CString filename)
41 assert(m_bUnused);
42 if (m_bIsPath)
43 m_pathList.AddPath(filename);
44 else
45 m_itemList.push_back(filename);
48 void CMassiveGitTask::AddFile(CTGitPath filename)
50 assert(m_bUnused);
51 if (m_bIsPath)
52 m_pathList.AddPath(filename);
53 else
54 m_itemList.push_back(filename.GetGitPathString());
57 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList *pathList, volatile BOOL &cancel, git_wc_notify_action_t action, CGitProgressList * instance)
59 assert(m_bUnused);
60 m_bUnused = false;
62 m_pathList = *pathList;
63 m_NotifyCallbackInstance = instance;
64 m_NotifyCallbackAction = action;
65 return ExecuteCommands(cancel);
68 bool CMassiveGitTask::Execute(BOOL &cancel)
70 assert(m_bUnused);
71 m_pathList.RemoveDuplicates();
72 return ExecuteCommands(cancel);
75 bool CMassiveGitTask::ExecuteCommands(volatile BOOL &cancel)
77 m_bUnused = false;
79 int maxLength = 0;
80 int firstCombine = 0;
81 for (int i = 0; i < GetListCount(); ++i)
83 if (maxLength + GetListItem(i).GetLength() > MAX_COMMANDLINE_LENGTH || i == GetListCount() - 1 || cancel)
85 CString add;
86 for (int j = firstCombine; j <= i; ++j)
87 add += _T(" \"") + GetListItem(j) + _T("\"");
89 CString cmd, out;
90 cmd.Format(_T("git.exe %s %s%s"), m_sParams, m_bIsPath ? _T("--") : _T(""), add);
91 if (g_Git.Run(cmd, &out, CP_UTF8))
93 if (m_NotifyCallbackInstance)
94 m_NotifyCallbackInstance->ReportError(out);
95 else
96 CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
97 return false;
100 if (m_bIsPath)
101 if (m_NotifyCallbackInstance)
102 for (int j = firstCombine; j <= i; ++j)
104 m_NotifyCallbackInstance->Notify(m_pathList[j], m_NotifyCallbackAction);
105 m_NotifyCallbackInstance->SetItemProgress(j);
108 maxLength = 0;
109 firstCombine = i+1;
111 if (cancel)
113 if (m_NotifyCallbackInstance)
114 m_NotifyCallbackInstance->ReportUserCanceled();
115 return false;
118 else
120 maxLength += 3 + GetListItem(i).GetLength();
123 return true;
126 int CMassiveGitTask::GetListCount()
128 return m_bIsPath ? m_pathList.GetCount() : (int)m_itemList.size();
131 CString CMassiveGitTask::GetListItem(int index)
133 return m_bIsPath ? m_pathList[index].GetGitPathString() : m_itemList[index];