Change copyright year
[TortoiseGit.git] / src / TortoiseProc / MassiveGitTask.cpp
blob06e3dbadc33103cb82703eab1004959d9a3d598f
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.
21 #include "stdafx.h"
22 #include "TortoiseProc.h"
23 #include "MassiveGitTask.h"
24 #include "MessageBox.h"
25 #include "SysInfo.h"
27 #define MAX_COMMANDLINE_LENGTH_WINXP 1700
28 #define MAX_COMMANDLINE_LENGTH_WIN7 30000
30 static int maxCommandLineLength = SysInfo::Instance().IsWin7OrLater() ? MAX_COMMANDLINE_LENGTH_WIN7 : MAX_COMMANDLINE_LENGTH_WINXP;
32 CMassiveGitTask::CMassiveGitTask(CString gitParameters, BOOL isPath)
33 : m_bUnused(true)
34 , m_bIsPath(isPath)
35 , m_NotifyCallbackInstance(NULL)
36 , m_NotifyCallbackMethod(NULL)
37 , m_NotifyCallbackAction(git_wc_notify_add)
39 m_sParams = gitParameters;
42 CMassiveGitTask::~CMassiveGitTask(void)
46 void CMassiveGitTask::AddFile(CString filename)
48 assert(m_bUnused);
49 m_pathList.AddPath(filename);
52 void CMassiveGitTask::AddFile(CTGitPath filename)
54 assert(m_bUnused);
55 m_pathList.AddPath(filename);
58 bool CMassiveGitTask::ExecuteWithNotify(CTGitPathList *pathList, BOOL &cancel, git_wc_notify_action_t action, CGitProgressDlg * instance, NOTIFY_CALLBACK notifyMethod)
60 assert(m_bUnused);
61 m_bUnused = false;
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)
72 assert(m_bUnused);
73 m_pathList.RemoveDuplicates();
74 return ExecuteCommands(cancel);
77 bool CMassiveGitTask::ExecuteCommands(BOOL &cancel)
79 m_bUnused = false;
81 bool bErrorsOccurred = false;
82 int maxLength = 0;
83 int firstCombine = 0;
84 for(int i = 0; i < m_pathList.GetCount(); i++)
86 if (maxLength + m_pathList[i].GetGitPathString().GetLength() > maxCommandLineLength || i == m_pathList.GetCount() - 1 || cancel)
88 CString add;
89 for (int j = firstCombine; j <= i; j++)
90 add += _T(" \"") + m_pathList[j].GetGitPathString() + _T("\"");
92 CString cmd, out;
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;
98 return false;
101 if (m_NotifyCallbackInstance && m_NotifyCallbackMethod)
102 for (int j = firstCombine; j <= i; j++)
103 (*m_NotifyCallbackInstance.*m_NotifyCallbackMethod)(m_pathList[j], m_NotifyCallbackAction, 0, NULL);
105 maxLength = 0;
106 firstCombine = i+1;
108 if (cancel)
109 break;
111 else
113 maxLength += 3 + m_pathList[i].GetGitPathString().GetLength();
116 return !bErrorsOccurred;