Keep the font size of 8 for the explorer property page
[TortoiseGit.git] / src / Git / MassiveGitTaskBase.cpp
blob4f468b45c7a090c883dceac911a61214e89f06f6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2016 - TortoiseGit
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 "MassiveGitTaskBase.h"
22 #include "Git.h"
23 #include <assert.h>
25 CMassiveGitTaskBase::CMassiveGitTaskBase(CString gitParameters, BOOL isPath, bool ignoreErrors)
26 : m_bUnused(true)
27 , m_bIsPath(isPath)
28 , m_bIgnoreErrors(ignoreErrors)
29 , m_sParams(gitParameters)
33 CMassiveGitTaskBase::~CMassiveGitTaskBase(void)
37 void CMassiveGitTaskBase::AddFile(const CString& filename)
39 assert(m_bUnused);
40 if (m_bIsPath)
41 m_pathList.AddPath(filename);
42 else
43 m_itemList.push_back(filename);
46 void CMassiveGitTaskBase::AddFile(const CTGitPath& filename)
48 assert(m_bUnused);
49 if (m_bIsPath)
50 m_pathList.AddPath(filename);
51 else
52 m_itemList.push_back(filename.GetGitPathString());
55 void CMassiveGitTaskBase::SetPaths(const CTGitPathList* pathList)
57 assert(m_bUnused);
58 m_bIsPath = true;
59 m_pathList.Clear();
60 m_pathList = *pathList;
63 bool CMassiveGitTaskBase::Execute(BOOL& cancel)
65 assert(m_bUnused);
66 m_pathList.RemoveDuplicates();
67 return ExecuteCommands(cancel);
70 bool CMassiveGitTaskBase::ExecuteCommands(volatile BOOL& cancel)
72 m_bUnused = false;
74 int maxLength = 0;
75 int firstCombine = 0;
76 for (int i = 0; i < GetListCount(); ++i)
78 if (maxLength + GetListItem(i).GetLength() > MAX_COMMANDLINE_LENGTH || i == GetListCount() - 1 || cancel)
80 CString add;
81 for (int j = firstCombine; j <= i; ++j)
83 add += L" \"";
84 add += GetListItem(j);
85 add += L'"';
88 CString cmd, out;
89 cmd.Format(L"git.exe %s %s%s", (LPCTSTR)m_sParams, m_bIsPath ? L"--" : L"", (LPCTSTR)add);
90 int exitCode = g_Git.Run(cmd, &out, CP_UTF8);
91 if (exitCode && !m_bIgnoreErrors)
93 ReportError(out, exitCode);
94 return false;
97 if (m_bIsPath)
99 for (int j = firstCombine; j <= i; ++j)
100 ReportProgress(m_pathList[j], j);
103 maxLength = 0;
104 firstCombine = i+1;
106 if (cancel)
108 ReportUserCanceled();
109 return false;
112 else
113 maxLength += 3 + GetListItem(i).GetLength();
115 return true;
118 void CMassiveGitTaskBase::ReportError(const CString& out, int /*exitCode*/)
120 MessageBox(nullptr, out, L"TortoiseGit", MB_OK | MB_ICONERROR);
123 int CMassiveGitTaskBase::GetListCount() const
125 return m_bIsPath ? m_pathList.GetCount() : (int)m_itemList.size();
128 bool CMassiveGitTaskBase::IsListEmpty() const
130 return m_bIsPath ? m_pathList.IsEmpty() : m_itemList.empty();
133 CString CMassiveGitTaskBase::GetListItem(int index) const
135 return m_bIsPath ? m_pathList[index].GetGitPathString() : m_itemList[index];