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.
21 #include "MassiveGitTaskBase.h"
25 CMassiveGitTaskBase::CMassiveGitTaskBase(CString gitParameters
, BOOL isPath
, bool ignoreErrors
)
28 , m_bIgnoreErrors(ignoreErrors
)
29 , m_sParams(gitParameters
)
33 CMassiveGitTaskBase::~CMassiveGitTaskBase(void)
37 void CMassiveGitTaskBase::AddFile(const CString
& filename
)
41 m_pathList
.AddPath(filename
);
43 m_itemList
.push_back(filename
);
46 void CMassiveGitTaskBase::AddFile(const CTGitPath
& filename
)
50 m_pathList
.AddPath(filename
);
52 m_itemList
.push_back(filename
.GetGitPathString());
55 void CMassiveGitTaskBase::SetPaths(const CTGitPathList
* pathList
)
60 m_pathList
= *pathList
;
63 bool CMassiveGitTaskBase::Execute(BOOL
& cancel
)
66 m_pathList
.RemoveDuplicates();
67 return ExecuteCommands(cancel
);
70 bool CMassiveGitTaskBase::ExecuteCommands(volatile BOOL
& cancel
)
76 for (int i
= 0; i
< GetListCount(); ++i
)
78 if (maxLength
+ GetListItem(i
).GetLength() > MAX_COMMANDLINE_LENGTH
|| i
== GetListCount() - 1 || cancel
)
81 for (int j
= firstCombine
; j
<= i
; ++j
)
84 add
+= GetListItem(j
);
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
);
99 for (int j
= firstCombine
; j
<= i
; ++j
)
100 ReportProgress(m_pathList
[j
], j
);
108 ReportUserCanceled();
113 maxLength
+= 3 + GetListItem(i
).GetLength();
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
];