Refactor: Move ColumnManager to separate files
[TortoiseGit.git] / src / Git / MassiveGitTaskBase.cpp
blob981ba2aad62b813e60e8301dc951b563d9571acc
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-2016 - 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 "MassiveGitTaskBase.h"
23 #include "Git.h"
24 #include <assert.h>
26 CMassiveGitTaskBase::CMassiveGitTaskBase(CString gitParameters, BOOL isPath, bool ignoreErrors)
27 : m_bUnused(true)
28 , m_bIsPath(isPath)
29 , m_bIgnoreErrors(ignoreErrors)
31 m_sParams = gitParameters;
34 CMassiveGitTaskBase::~CMassiveGitTaskBase(void)
38 void CMassiveGitTaskBase::AddFile(const CString& filename)
40 assert(m_bUnused);
41 if (m_bIsPath)
42 m_pathList.AddPath(filename);
43 else
44 m_itemList.push_back(filename);
47 void CMassiveGitTaskBase::AddFile(const CTGitPath& filename)
49 assert(m_bUnused);
50 if (m_bIsPath)
51 m_pathList.AddPath(filename);
52 else
53 m_itemList.push_back(filename.GetGitPathString());
56 void CMassiveGitTaskBase::SetPaths(const CTGitPathList* pathList)
58 assert(m_bUnused);
59 m_bIsPath = true;
60 m_pathList.Clear();
61 m_pathList = *pathList;
64 bool CMassiveGitTaskBase::Execute(BOOL& cancel)
66 assert(m_bUnused);
67 m_pathList.RemoveDuplicates();
68 return ExecuteCommands(cancel);
71 bool CMassiveGitTaskBase::ExecuteCommands(volatile BOOL& cancel)
73 m_bUnused = false;
75 int maxLength = 0;
76 int firstCombine = 0;
77 for (int i = 0; i < GetListCount(); ++i)
79 if (maxLength + GetListItem(i).GetLength() > MAX_COMMANDLINE_LENGTH || i == GetListCount() - 1 || cancel)
81 CString add;
82 for (int j = firstCombine; j <= i; ++j)
84 add += _T(" \"");
85 add += GetListItem(j);
86 add += _T('"');
89 CString cmd, out;
90 cmd.Format(_T("git.exe %s %s%s"), (LPCTSTR)m_sParams, m_bIsPath ? _T("--") : _T(""), (LPCTSTR)add);
91 int exitCode = g_Git.Run(cmd, &out, CP_UTF8);
92 if (exitCode && !m_bIgnoreErrors)
94 ReportError(out, exitCode);
95 return false;
98 if (m_bIsPath)
100 for (int j = firstCombine; j <= i; ++j)
101 ReportProgress(m_pathList[j], j);
104 maxLength = 0;
105 firstCombine = i+1;
107 if (cancel)
109 ReportUserCanceled();
110 return false;
113 else
114 maxLength += 3 + GetListItem(i).GetLength();
116 return true;
119 void CMassiveGitTaskBase::ReportError(const CString& out, int /*exitCode*/)
121 MessageBox(nullptr, out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
124 int CMassiveGitTaskBase::GetListCount()
126 return m_bIsPath ? m_pathList.GetCount() : (int)m_itemList.size();
129 CString CMassiveGitTaskBase::GetListItem(int index)
131 return m_bIsPath ? m_pathList[index].GetGitPathString() : m_itemList[index];