1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2012 - 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.
22 #include "TortoiseProc.h"
23 #include "MassiveGitTask.h"
24 #include "MessageBox.h"
26 CMassiveGitTask::CMassiveGitTask(CString gitParameters
, BOOL isPath
)
29 , m_NotifyCallbackInstance(NULL
)
30 , m_NotifyCallbackMethod(NULL
)
31 , m_NotifyCallbackAction(git_wc_notify_add
)
33 m_sParams
= gitParameters
;
36 CMassiveGitTask::~CMassiveGitTask(void)
40 void CMassiveGitTask::AddFile(CString filename
)
44 m_pathList
.AddPath(filename
);
46 m_itemList
.push_back(filename
);
49 void CMassiveGitTask::AddFile(CTGitPath filename
)
53 m_pathList
.AddPath(filename
);
55 m_itemList
.push_back(filename
.GetGitPathString());
58 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList
*pathList
, BOOL
&cancel
, git_wc_notify_action_t action
, CGitProgressDlg
* instance
, NOTIFY_CALLBACK notifyMethod
)
63 m_pathList
= *pathList
;
64 m_NotifyCallbackInstance
= instance
;
65 m_NotifyCallbackMethod
= notifyMethod
;
66 m_NotifyCallbackAction
= action
;
67 return ExecuteCommands(cancel
);
70 bool CMassiveGitTask::Execute(BOOL
&cancel
)
73 m_pathList
.RemoveDuplicates();
74 return ExecuteCommands(cancel
);
77 bool CMassiveGitTask::ExecuteCommands(BOOL
&cancel
)
81 bool bErrorsOccurred
= false;
84 for(int i
= 0; i
< GetListCount(); i
++)
86 if (maxLength
+ GetListItem(i
).GetLength() > MAX_COMMANDLINE_LENGTH
|| i
== GetListCount() - 1 || cancel
)
89 for (int j
= firstCombine
; j
<= i
; j
++)
90 add
+= _T(" \"") + GetListItem(j
) + _T("\"");
93 cmd
.Format(_T("git.exe %s %s%s"), m_sParams
, m_bIsPath
? _T("--") : _T(""), add
);
94 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
96 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
97 bErrorsOccurred
= true;
102 if (m_NotifyCallbackInstance
&& m_NotifyCallbackMethod
)
103 for (int j
= firstCombine
; j
<= i
; j
++)
104 (*m_NotifyCallbackInstance
.*m_NotifyCallbackMethod
)(m_pathList
[j
], m_NotifyCallbackAction
, 0, NULL
);
114 maxLength
+= 3 + GetListItem(i
).GetLength();
117 return !bErrorsOccurred
;
120 int CMassiveGitTask::GetListCount()
122 return m_bIsPath
? m_pathList
.GetCount() : (int)m_itemList
.size();
125 CString
CMassiveGitTask::GetListItem(int index
)
127 return m_bIsPath
? m_pathList
[index
].GetGitPathString() : m_itemList
[index
];