SyncDlg: Make check if local branch fast-fowards to remote branch work again
[TortoiseGit.git] / src / TortoiseProc / MassiveGitTask.cpp
blobd9839baa1164dd527ec489d7de369c14b7adee76
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.
20 #include "StdAfx.h"
21 #include "TortoiseProc.h"
22 #include "MassiveGitTask.h"
23 #include "MessageBox.h"
25 CMassiveGitTask::CMassiveGitTask(CString gitParameters)
26 : m_bUnused(true)
27 , m_NotifyCallbackInstance(NULL)
28 , m_NotifyCallbackMethod(NULL)
30 m_sParams = gitParameters;
33 CMassiveGitTask::~CMassiveGitTask(void)
37 void CMassiveGitTask::AddFile(CString filename)
39 assert(m_bUnused);
40 m_pathList.AddPath(filename);
43 void CMassiveGitTask::AddFile(CTGitPath filename)
45 assert(m_bUnused);
46 m_pathList.AddPath(filename);
49 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList *pathList, BOOL &cancel, git_wc_notify_action_t action, CGitProgressDlg * instance, NOTIFY_CALLBACK notifyMethod)
51 assert(m_bUnused);
52 m_bUnused = false;
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)
63 assert(m_bUnused);
64 m_pathList.RemoveDuplicates();
65 return ExecuteCommands(cancel);
68 bool CMassiveGitTask::ExecuteCommands(BOOL &cancel)
70 m_bUnused = false;
72 bool bErrorsOccurred = false;
73 int maxLength = 0;
74 int firstCombine = 0;
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)
79 CString add;
80 for (int j = firstCombine; j <= i; j++)
81 add += _T(" \"") + m_pathList[j].GetGitPathString() + _T("\"");
83 CString cmd, out;
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;
89 return false;
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);
96 maxLength = 0;
97 firstCombine = i+1;
99 if (cancel)
100 break;
102 else
104 maxLength += 3 + m_pathList[i].GetGitPathString().GetLength();
107 return !bErrorsOccurred;