1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2012 - Sven Strickroth <email@cs-ware.de>
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 "TortoiseProc.h"
22 #include "MassiveGitTask.h"
23 #include "MessageBox.h"
25 CMassiveGitTask::CMassiveGitTask(CString gitParameters
)
27 , m_NotifyCallbackInstance(NULL
)
28 , m_NotifyCallbackMethod(NULL
)
30 m_sParams
= gitParameters
;
33 CMassiveGitTask::~CMassiveGitTask(void)
37 void CMassiveGitTask::AddFile(CString filename
)
40 m_pathList
.AddPath(filename
);
43 void CMassiveGitTask::AddFile(CTGitPath filename
)
46 m_pathList
.AddPath(filename
);
49 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList
*pathList
, BOOL
&cancel
, git_wc_notify_action_t action
, CGitProgressDlg
* instance
, NOTIFY_CALLBACK notifyMethod
)
54 m_pathList
= *pathList
;
55 m_NotifyCallbackInstance
= instance
;
56 m_NotifyCallbackMethod
= notifyMethod
;
57 m_NotifyCallbackAction
= action
;
58 return ExecuteCommands(cancel
);
61 bool CMassiveGitTask::Execute(BOOL
&cancel
)
64 m_pathList
.RemoveDuplicates();
65 return ExecuteCommands(cancel
);
68 bool CMassiveGitTask::ExecuteCommands(BOOL
&cancel
)
72 bool bErrorsOccurred
= false;
75 for(int i
= 0; i
< m_pathList
.GetCount(); i
++)
77 if (maxLength
+ m_pathList
[i
].GetGitPathString().GetLength() > MAX_COMMANDLINE_LENGTH
|| i
== m_pathList
.GetCount() - 1 || cancel
)
80 for (int j
= firstCombine
; j
<= i
; j
++)
81 add
+= _T(" \"") + m_pathList
[j
].GetGitPathString() + _T("\"");
84 cmd
.Format(_T("git.exe %s --%s"), m_sParams
, add
);
85 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
87 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
88 bErrorsOccurred
= true;
92 if (m_NotifyCallbackInstance
&& m_NotifyCallbackMethod
)
93 for (int j
= firstCombine
; j
<= i
; j
++)
94 (*m_NotifyCallbackInstance
.*m_NotifyCallbackMethod
)(m_pathList
[j
], m_NotifyCallbackAction
, 0, NULL
);
104 maxLength
+= 3 + m_pathList
[i
].GetGitPathString().GetLength();
107 return !bErrorsOccurred
;