Fix compilation warnings
[TortoiseGit.git] / src / TortoiseProc / MassiveGitTask.cpp
blob97474242545d3ef52c354ac5e99597d35f7c382f
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, bool ignoreErrors)
27 : m_bUnused(true)
28 , m_bIsPath(isPath)
29 , m_bIgnoreErrors(ignoreErrors)
30 , m_NotifyCallbackInstance(NULL)
31 , m_NotifyCallbackAction(git_wc_notify_add)
33 m_sParams = gitParameters;
36 CMassiveGitTask::~CMassiveGitTask(void)
40 void CMassiveGitTask::AddFile(CString filename)
42 assert(m_bUnused);
43 if (m_bIsPath)
44 m_pathList.AddPath(filename);
45 else
46 m_itemList.push_back(filename);
49 void CMassiveGitTask::AddFile(CTGitPath filename)
51 assert(m_bUnused);
52 if (m_bIsPath)
53 m_pathList.AddPath(filename);
54 else
55 m_itemList.push_back(filename.GetGitPathString());
58 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList *pathList, volatile BOOL &cancel, git_wc_notify_action_t action, CGitProgressList * instance)
60 assert(m_bUnused);
61 m_bUnused = false;
63 m_pathList = *pathList;
64 m_NotifyCallbackInstance = instance;
65 m_NotifyCallbackAction = action;
66 return ExecuteCommands(cancel);
69 bool CMassiveGitTask::Execute(BOOL &cancel)
71 assert(m_bUnused);
72 m_pathList.RemoveDuplicates();
73 return ExecuteCommands(cancel);
76 bool CMassiveGitTask::ExecuteCommands(volatile BOOL &cancel)
78 m_bUnused = false;
80 int maxLength = 0;
81 int firstCombine = 0;
82 for (int i = 0; i < GetListCount(); ++i)
84 if (maxLength + GetListItem(i).GetLength() > MAX_COMMANDLINE_LENGTH || i == GetListCount() - 1 || cancel)
86 CString add;
87 for (int j = firstCombine; j <= i; ++j)
88 add += _T(" \"") + GetListItem(j) + _T("\"");
90 CString cmd, out;
91 cmd.Format(_T("git.exe %s %s%s"), m_sParams, m_bIsPath ? _T("--") : _T(""), add);
92 if (g_Git.Run(cmd, &out, CP_UTF8) && !m_bIgnoreErrors)
94 if (m_NotifyCallbackInstance)
95 m_NotifyCallbackInstance->ReportError(out);
96 else
97 CMessageBox::Show(NULL, out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
98 return false;
101 if (m_bIsPath)
102 if (m_NotifyCallbackInstance)
103 for (int j = firstCombine; j <= i; ++j)
105 m_NotifyCallbackInstance->Notify(m_pathList[j], m_NotifyCallbackAction);
106 m_NotifyCallbackInstance->SetItemProgress(j);
109 maxLength = 0;
110 firstCombine = i+1;
112 if (cancel)
114 if (m_NotifyCallbackInstance)
115 m_NotifyCallbackInstance->ReportUserCanceled();
116 return false;
119 else
121 maxLength += 3 + GetListItem(i).GetLength();
124 return true;
127 int CMassiveGitTask::GetListCount()
129 return m_bIsPath ? m_pathList.GetCount() : (int)m_itemList.size();
132 CString CMassiveGitTask::GetListItem(int index)
134 return m_bIsPath ? m_pathList[index].GetGitPathString() : m_itemList[index];