Vcs: Split up VcsCommand

Move the biggest chunk into Utils::ShellCommand, add some Qt Creator
specific magic in Core::ShellCommand and leave the rest in
VcsBase::VcsCommand.

Change-Id: I5fe6f7076e96023ad2164bcfaacfb3b65a7ff8a8
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2015-04-27 15:03:07 +02:00
parent 1e1fee86c4
commit eec0a03212
23 changed files with 1017 additions and 763 deletions
+555
View File
@@ -0,0 +1,555 @@
/**************************************************************************
**
** Copyright (C) 2015 Brian McGillion and Hugues Delorme
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "shellcommand.h"
#include "fileutils.h"
#include "synchronousprocess.h"
#include "runextensions.h"
#include "qtcassert.h"
#include <QProcess>
#include <QProcessEnvironment>
#include <QFuture>
#include <QFutureWatcher>
#include <QtConcurrentRun>
#include <QFileInfo>
#include <QCoreApplication>
#include <QVariant>
#include <QScopedPointer>
#include <QSharedPointer>
#include <QStringList>
#include <QTextCodec>
#include <QMutex>
/*!
\fn void Utils::ProgressParser::parseProgress(const QString &text)
Reimplement to parse progress as it appears in the standard output.
If a progress string is detected, call \c setProgressAndMaximum() to update
the progress bar accordingly.
\sa Utils::ProgressParser::setProgressAndMaximum()
*/
/*!
\fn void Utils::ProgressParser::setProgressAndMaximum(int value, int maximum)
Sets progress \a value and \a maximum for current command. Called by \c parseProgress()
when a progress string is detected.
*/
namespace Utils {
namespace Internal {
class ShellCommandPrivate
{
public:
struct Job {
explicit Job(const Utils::FileName &b, const QStringList &a, int t,
Utils::ExitCodeInterpreter *interpreter = 0);
Utils::FileName binary;
QStringList arguments;
int timeoutS;
Utils::ExitCodeInterpreter *exitCodeInterpreter;
};
ShellCommandPrivate(const QString &workingDirectory, const QProcessEnvironment &environment);
~ShellCommandPrivate();
std::function<OutputProxy *()> m_proxyFactory = []() { return new OutputProxy; };
QString m_displayName;
const QString m_workingDirectory;
const QProcessEnvironment m_environment;
QVariant m_cookie;
int m_defaultTimeoutS;
unsigned m_flags;
QTextCodec *m_codec;
ProgressParser *m_progressParser;
bool m_progressiveOutput;
bool m_hadOutput;
bool m_aborted;
QFutureWatcher<void> m_watcher;
QList<Job> m_jobs;
bool m_lastExecSuccess;
int m_lastExecExitCode;
};
ShellCommandPrivate::ShellCommandPrivate(const QString &workingDirectory,
const QProcessEnvironment &environment) :
m_workingDirectory(workingDirectory),
m_environment(environment),
m_defaultTimeoutS(10),
m_flags(0),
m_codec(0),
m_progressParser(0),
m_progressiveOutput(false),
m_hadOutput(false),
m_aborted(false),
m_lastExecSuccess(false),
m_lastExecExitCode(-1)
{ }
ShellCommandPrivate::~ShellCommandPrivate()
{
delete m_progressParser;
}
ShellCommandPrivate::Job::Job(const Utils::FileName &b, const QStringList &a,
int t, Utils::ExitCodeInterpreter *interpreter) :
binary(b),
arguments(a),
timeoutS(t),
exitCodeInterpreter(interpreter)
{
// Finished cookie is emitted via queued slot, needs metatype
static const int qvMetaId = qRegisterMetaType<QVariant>();
Q_UNUSED(qvMetaId)
}
} // namespace Internal
ShellCommand::ShellCommand(const QString &workingDirectory,
const QProcessEnvironment &environment) :
d(new Internal::ShellCommandPrivate(workingDirectory, environment))
{ }
ShellCommand::~ShellCommand()
{
delete d;
}
QString ShellCommand::displayName() const
{
if (!d->m_displayName.isEmpty())
return d->m_displayName;
if (!d->m_jobs.isEmpty()) {
const Internal::ShellCommandPrivate::Job &job = d->m_jobs.at(0);
QString result = job.binary.toFileInfo().baseName();
result[0] = result.at(0).toTitleCase();
if (!job.arguments.isEmpty())
result += QLatin1Char(' ') + job.arguments.at(0);
return result;
}
return tr("Unknown");
}
void ShellCommand::setDisplayName(const QString &name)
{
d->m_displayName = name;
}
const QString &ShellCommand::workingDirectory() const
{
return d->m_workingDirectory;
}
const QProcessEnvironment ShellCommand::processEnvironment() const
{
return d->m_environment;
}
int ShellCommand::defaultTimeoutS() const
{
return d->m_defaultTimeoutS;
}
void ShellCommand::setDefaultTimeoutS(int timeout)
{
d->m_defaultTimeoutS = timeout;
}
unsigned ShellCommand::flags() const
{
return d->m_flags;
}
void ShellCommand::addFlags(unsigned f)
{
d->m_flags |= f;
}
void ShellCommand::addJob(const Utils::FileName &binary, const QStringList &arguments,
Utils::ExitCodeInterpreter *interpreter)
{
addJob(binary, arguments, defaultTimeoutS(), interpreter);
}
void ShellCommand::addJob(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
d->m_jobs.push_back(Internal::ShellCommandPrivate::Job(binary, arguments, timeoutS, interpreter));
}
void ShellCommand::execute()
{
d->m_lastExecSuccess = false;
d->m_lastExecExitCode = -1;
if (d->m_jobs.empty())
return;
// For some reason QtConcurrent::run() only works on this
QFuture<void> task = QtConcurrent::run(&ShellCommand::run, this);
d->m_watcher.setFuture(task);
connect(&d->m_watcher, &QFutureWatcher<void>::canceled, this, &ShellCommand::cancel);
addTask(task);
}
void ShellCommand::abort()
{
d->m_aborted = true;
d->m_watcher.future().cancel();
}
void ShellCommand::cancel()
{
emit terminate();
}
unsigned ShellCommand::processFlags() const
{
return 0;
}
void ShellCommand::addTask(QFuture<void> &future)
{
Q_UNUSED(future);
}
bool ShellCommand::lastExecutionSuccess() const
{
return d->m_lastExecSuccess;
}
int ShellCommand::lastExecutionExitCode() const
{
return d->m_lastExecExitCode;
}
void ShellCommand::run(QFutureInterface<void> &future)
{
// Check that the binary path is not empty
QTC_ASSERT(!d->m_jobs.isEmpty(), return);
QString stdOut;
QString stdErr;
if (d->m_progressParser)
d->m_progressParser->setFuture(&future);
else
future.setProgressRange(0, 1);
const int count = d->m_jobs.size();
d->m_lastExecExitCode = -1;
d->m_lastExecSuccess = true;
for (int j = 0; j < count; j++) {
const Internal::ShellCommandPrivate::Job &job = d->m_jobs.at(j);
Utils::SynchronousProcessResponse resp
= runCommand(job.binary, job.arguments, job.timeoutS, job.exitCodeInterpreter);
stdOut += resp.stdOut;
stdErr += resp.stdErr;
d->m_lastExecExitCode = resp.exitCode;
d->m_lastExecSuccess = resp.result == Utils::SynchronousProcessResponse::Finished;
if (!d->m_lastExecSuccess)
break;
}
if (!d->m_aborted) {
if (!d->m_progressiveOutput) {
emit output(stdOut);
if (!stdErr.isEmpty())
emit errorText(stdErr);
}
emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie());
if (d->m_lastExecSuccess)
emit success(cookie());
future.setProgressValue(future.progressMaximum());
}
if (d->m_progressParser)
d->m_progressParser->setFuture(0);
// As it is used asynchronously, we need to delete ourselves
this->deleteLater();
}
Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName &binary,
const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
Utils::SynchronousProcessResponse response;
if (binary.isEmpty()) {
response.result = Utils::SynchronousProcessResponse::StartFailed;
return response;
}
QSharedPointer<OutputProxy> proxy(d->m_proxyFactory());
if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(d->m_workingDirectory, binary, arguments);
if (d->m_flags & FullySynchronously) {
response = runSynchronous(binary, arguments, timeoutS, interpreter);
} else {
Utils::SynchronousProcess process;
process.setExitCodeInterpreter(interpreter);
connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate);
if (!d->m_workingDirectory.isEmpty())
process.setWorkingDirectory(d->m_workingDirectory);
process.setProcessEnvironment(processEnvironment());
process.setTimeoutS(timeoutS);
if (d->m_codec)
process.setCodec(d->m_codec);
process.setFlags(processFlags());
// connect stderr to the output window if desired
if (d->m_flags & MergeOutputChannels) {
process.setProcessChannelMode(QProcess::MergedChannels);
} else if (d->m_progressiveOutput
|| !(d->m_flags & SuppressStdErr)) {
process.setStdErrBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdErrBuffered,
this, [this, proxy](const QString &text)
{
if (!(d->m_flags & SuppressStdErr))
proxy->appendError(text);
if (d->m_progressiveOutput)
emit errorText(text);
});
}
// connect stdout to the output window if desired
if (d->m_progressParser || d->m_progressiveOutput
|| (d->m_flags & ShowStdOut)) {
process.setStdOutBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdOutBuffered,
this, [this, proxy](const QString &text)
{
if (d->m_progressParser)
d->m_progressParser->parseProgress(text);
if (d->m_flags & ShowStdOut)
proxy->append(text);
if (d->m_progressiveOutput) {
emit output(text);
d->m_hadOutput = true;
}
});
}
process.setTimeOutMessageBoxEnabled(true);
// Run!
response = process.run(binary.toString(), arguments);
}
if (!d->m_aborted) {
// Success/Fail message in appropriate window?
if (response.result == Utils::SynchronousProcessResponse::Finished) {
if (d->m_flags & ShowSuccessMessage)
proxy->appendMessage(response.exitMessage(binary.toUserOutput(), timeoutS));
} else if (!(d->m_flags & SuppressFailMessage)) {
proxy->appendError(response.exitMessage(binary.toUserOutput(), timeoutS));
}
}
return response;
}
Utils::SynchronousProcessResponse ShellCommand::runSynchronous(const Utils::FileName &binary,
const QStringList &arguments,
int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
Utils::SynchronousProcessResponse response;
QScopedPointer<OutputProxy> proxy(d->m_proxyFactory());
// Set up process
QSharedPointer<QProcess> process = Utils::SynchronousProcess::createProcess(processFlags());
if (!d->m_workingDirectory.isEmpty())
process->setWorkingDirectory(d->m_workingDirectory);
process->setProcessEnvironment(processEnvironment());
if (d->m_flags & MergeOutputChannels)
process->setProcessChannelMode(QProcess::MergedChannels);
// Start
process->start(binary.toString(), arguments, QIODevice::ReadOnly);
process->closeWriteChannel();
if (!process->waitForStarted()) {
response.result = Utils::SynchronousProcessResponse::StartFailed;
return response;
}
// process output
QByteArray stdOut;
QByteArray stdErr;
const bool timedOut =
!Utils::SynchronousProcess::readDataFromProcess(*process.data(), timeoutS,
&stdOut, &stdErr, true);
if (!d->m_aborted) {
if (!stdErr.isEmpty()) {
response.stdErr = Utils::SynchronousProcess::normalizeNewlines(
d->m_codec ? d->m_codec->toUnicode(stdErr) : QString::fromLocal8Bit(stdErr));
if (!(d->m_flags & SuppressStdErr))
proxy->append(response.stdErr);
}
if (!stdOut.isEmpty()) {
response.stdOut = Utils::SynchronousProcess::normalizeNewlines(
d->m_codec ? d->m_codec->toUnicode(stdOut) : QString::fromLocal8Bit(stdOut));
if (d->m_flags & ShowStdOut) {
if (d->m_flags & SilentOutput)
proxy->appendSilently(response.stdOut);
else
proxy->append(response.stdOut);
}
}
}
Utils::ExitCodeInterpreter defaultInterpreter(this);
Utils::ExitCodeInterpreter *currentInterpreter = interpreter ? interpreter : &defaultInterpreter;
// Result
if (timedOut)
response.result = Utils::SynchronousProcessResponse::Hang;
else if (process->exitStatus() != QProcess::NormalExit)
response.result = Utils::SynchronousProcessResponse::TerminatedAbnormally;
else
response.result = currentInterpreter->interpretExitCode(process->exitCode());
return response;
}
bool ShellCommand::runFullySynchronous(const Utils::FileName &binary, const QStringList &arguments,
int timeoutS, QByteArray *outputData, QByteArray *errorData)
{
QTC_ASSERT(!binary.isEmpty(), return false);
QScopedPointer<OutputProxy> proxy(d->m_proxyFactory());
if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(d->m_workingDirectory, binary, arguments);
QProcess process;
process.setWorkingDirectory(d->m_workingDirectory);
process.setProcessEnvironment(d->m_environment);
process.start(binary.toString(), arguments);
process.closeWriteChannel();
if (!process.waitForStarted()) {
if (errorData) {
const QString msg = QString::fromLatin1("Unable to execute \"%1\": %2:")
.arg(binary.toUserOutput(), process.errorString());
*errorData = msg.toLocal8Bit();
}
return false;
}
if (!Utils::SynchronousProcess::readDataFromProcess(process, timeoutS, outputData, errorData, true)) {
if (errorData)
errorData->append(tr("Error: Executable timed out after %1 s.").arg(timeoutS).toLocal8Bit());
Utils::SynchronousProcess::stopProcess(process);
return false;
}
return process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0;
}
const QVariant &ShellCommand::cookie() const
{
return d->m_cookie;
}
void ShellCommand::setCookie(const QVariant &cookie)
{
d->m_cookie = cookie;
}
QTextCodec *ShellCommand::codec() const
{
return d->m_codec;
}
void ShellCommand::setCodec(QTextCodec *codec)
{
d->m_codec = codec;
}
//! Use \a parser to parse progress data from stdout. Command takes ownership of \a parser
void ShellCommand::setProgressParser(ProgressParser *parser)
{
QTC_ASSERT(!d->m_progressParser, return);
d->m_progressParser = parser;
}
void ShellCommand::setProgressiveOutput(bool progressive)
{
d->m_progressiveOutput = progressive;
}
void ShellCommand::setOutputProxyFactory(const std::function<OutputProxy *()> &factory)
{
d->m_proxyFactory = factory;
}
ProgressParser::ProgressParser() :
m_future(0),
m_futureMutex(new QMutex)
{ }
ProgressParser::~ProgressParser()
{
delete m_futureMutex;
}
void ProgressParser::setProgressAndMaximum(int value, int maximum)
{
QMutexLocker lock(m_futureMutex);
if (!m_future)
return;
m_future->setProgressRange(0, maximum);
m_future->setProgressValue(value);
}
void ProgressParser::setFuture(QFutureInterface<void> *future)
{
QMutexLocker lock(m_futureMutex);
m_future = future;
}
} // namespace Utils
+185
View File
@@ -0,0 +1,185 @@
/**************************************************************************
**
** Copyright (C) 2015 Brian McGillion and Hugues Delorme
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef UTILS_SHELLCOMMAND_H
#define UTILS_SHELLCOMMAND_H
#include "utils_global.h"
#include <QObject>
#include <functional>
QT_BEGIN_NAMESPACE
class QMutex;
class QStringList;
class QVariant;
class QProcessEnvironment;
template <typename T>
class QFutureInterface;
template <typename T>
class QFuture;
QT_END_NAMESPACE
namespace Utils {
struct SynchronousProcessResponse;
class ExitCodeInterpreter;
class FileName;
}
namespace Utils {
namespace Internal { class ShellCommandPrivate; }
class QTCREATOR_UTILS_EXPORT ProgressParser
{
public:
ProgressParser();
virtual ~ProgressParser();
protected:
virtual void parseProgress(const QString &text) = 0;
void setProgressAndMaximum(int value, int maximum);
private:
void setFuture(QFutureInterface<void> *future);
QFutureInterface<void> *m_future;
QMutex *m_futureMutex;
friend class ShellCommand;
};
// Users of this class can either be in the GUI thread or in other threads.
// Use Qt::AutoConnection to always append in the GUI thread (directly or queued)
class QTCREATOR_UTILS_EXPORT OutputProxy : public QObject
{
Q_OBJECT
friend class ShellCommand;
signals:
void append(const QString &text);
void appendSilently(const QString &text);
void appendError(const QString &text);
void appendCommand(const QString &workingDirectory, const Utils::FileName &binary,
const QStringList &args);
void appendMessage(const QString &text);
};
class QTCREATOR_UTILS_EXPORT ShellCommand : public QObject
{
Q_OBJECT
public:
// Convenience to synchronously run commands
enum RunFlags {
ShowStdOut = 0x1, // Show standard output.
MergeOutputChannels = 0x2, // see QProcess: Merge stderr/stdout.
SuppressStdErr = 0x4, // Suppress standard error output.
SuppressFailMessage = 0x8, // No message about command failure.
SuppressCommandLogging = 0x10, // No command log entry.
ShowSuccessMessage = 0x20, // Show message about successful completion of command.
ForceCLocale = 0x40, // Force C-locale for commands whose output is parsed.
FullySynchronously = 0x80, // Suppress local event loop (in case UI actions are
// triggered by file watchers).
SilentOutput = 0x100, // Suppress user notifications about the output happening.
NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging
};
ShellCommand(const QString &workingDirectory, const QProcessEnvironment &environment);
~ShellCommand();
QString displayName() const;
void setDisplayName(const QString &name);
void addJob(const FileName &binary, const QStringList &arguments, ExitCodeInterpreter *interpreter = 0);
void addJob(const FileName &binary, const QStringList &arguments, int timeoutS,
ExitCodeInterpreter *interpreter = 0);
void execute();
void abort();
bool lastExecutionSuccess() const;
int lastExecutionExitCode() const;
const QString &workingDirectory() const;
virtual const QProcessEnvironment processEnvironment() const;
int defaultTimeoutS() const;
void setDefaultTimeoutS(int timeout);
unsigned flags() const;
void addFlags(unsigned f);
const QVariant &cookie() const;
void setCookie(const QVariant &cookie);
QTextCodec *codec() const;
void setCodec(QTextCodec *codec);
void setProgressParser(ProgressParser *parser);
void setProgressiveOutput(bool progressive);
void setOutputProxyFactory(const std::function<OutputProxy *()> &factory);
virtual SynchronousProcessResponse runCommand(const FileName &binary, const QStringList &arguments,
int timeoutS, ExitCodeInterpreter *interpreter = 0);
// Make sure to not pass through the event loop at all:
virtual bool runFullySynchronous(const FileName &binary, const QStringList &arguments,
int timeoutS, QByteArray *outputData, QByteArray *errorData);
public slots:
void cancel();
signals:
void output(const QString &);
void errorText(const QString &);
void finished(bool ok, int exitCode, const QVariant &cookie);
void success(const QVariant &cookie);
void terminate(); // Internal
protected:
virtual unsigned processFlags() const;
virtual void addTask(QFuture<void> &future);
private:
void bufferedOutput(const QString &text);
void bufferedError(const QString &text);
void run(QFutureInterface<void> &future);
SynchronousProcessResponse runSynchronous(const FileName &binary, const QStringList &arguments,
int timeoutS, ExitCodeInterpreter *interpreter = 0);
class Internal::ShellCommandPrivate *const d;
};
} // namespace Utils
#endif // UTILS_SHELLCOMMAND_H
+2
View File
@@ -12,6 +12,7 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/environmentmodel.cpp \ $$PWD/environmentmodel.cpp \
$$PWD/qtcprocess.cpp \ $$PWD/qtcprocess.cpp \
$$PWD/reloadpromptutils.cpp \ $$PWD/reloadpromptutils.cpp \
$$PWD/shellcommand.cpp \
$$PWD/settingsselector.cpp \ $$PWD/settingsselector.cpp \
$$PWD/stringutils.cpp \ $$PWD/stringutils.cpp \
$$PWD/textfieldcheckbox.cpp \ $$PWD/textfieldcheckbox.cpp \
@@ -100,6 +101,7 @@ HEADERS += \
$$PWD/utils_global.h \ $$PWD/utils_global.h \
$$PWD/reloadpromptutils.h \ $$PWD/reloadpromptutils.h \
$$PWD/settingsselector.h \ $$PWD/settingsselector.h \
$$PWD/shellcommand.h \
$$PWD/stringutils.h \ $$PWD/stringutils.h \
$$PWD/textfieldcheckbox.h \ $$PWD/textfieldcheckbox.h \
$$PWD/textfieldcombobox.h \ $$PWD/textfieldcombobox.h \
+2
View File
@@ -162,6 +162,8 @@ QtcLibrary {
"settingsselector.cpp", "settingsselector.cpp",
"settingsselector.h", "settingsselector.h",
"settingsutils.h", "settingsutils.h",
"shellcommand.cpp",
"shellcommand.h",
"sleep.cpp", "sleep.cpp",
"sleep.h", "sleep.h",
"statuslabel.cpp", "statuslabel.cpp",
+16 -11
View File
@@ -941,7 +941,7 @@ bool ClearCasePlugin::vcsUndoCheckOut(const QString &workingDir, const QString &
const ClearCaseResponse response = const ClearCaseResponse response =
runCleartool(workingDir, args, m_settings.timeOutS, runCleartool(workingDir, args, m_settings.timeOutS,
ShowStdOutInLogWindow | FullySynchronously); VcsCommand::ShowStdOut | VcsCommand::FullySynchronously);
if (!response.error) { if (!response.error) {
const QString absPath = workingDir + QLatin1Char('/') + fileName; const QString absPath = workingDir + QLatin1Char('/') + fileName;
@@ -974,7 +974,7 @@ bool ClearCasePlugin::vcsUndoHijack(const QString &workingDir, const QString &fi
const ClearCaseResponse response = const ClearCaseResponse response =
runCleartool(workingDir, args, m_settings.timeOutS, runCleartool(workingDir, args, m_settings.timeOutS,
ShowStdOutInLogWindow | FullySynchronously); VcsCommand::ShowStdOut | VcsCommand::FullySynchronously);
if (!response.error && !m_settings.disableIndexer) { if (!response.error && !m_settings.disableIndexer) {
const QString absPath = workingDir + QLatin1Char('/') + fileName; const QString absPath = workingDir + QLatin1Char('/') + fileName;
setStatus(absPath, FileStatus::CheckedIn); setStatus(absPath, FileStatus::CheckedIn);
@@ -1366,7 +1366,8 @@ void ClearCasePlugin::ccUpdate(const QString &workingDir, const QStringList &rel
if (!relativePaths.isEmpty()) if (!relativePaths.isEmpty())
args.append(relativePaths); args.append(relativePaths);
const ClearCaseResponse response = const ClearCaseResponse response =
runCleartool(workingDir, args, m_settings.longTimeOutS(), ShowStdOutInLogWindow); runCleartool(workingDir, args, m_settings.longTimeOutS(),
VcsCommand::ShowStdOut);
if (!response.error) if (!response.error)
clearCaseControl()->emitRepositoryChanged(workingDir); clearCaseControl()->emitRepositoryChanged(workingDir);
} }
@@ -1628,8 +1629,10 @@ bool ClearCasePlugin::vcsOpen(const QString &workingDir, const QString &fileName
} }
args << file; args << file;
ClearCaseResponse response = ClearCaseResponse response =
runCleartool(topLevel, args, m_settings.timeOutS, ShowStdOutInLogWindow | runCleartool(topLevel, args, m_settings.timeOutS,
SuppressStdErrInLogWindow | FullySynchronously); VcsCommand::ShowStdOut
| VcsCommand::SuppressStdErr
| VcsCommand::FullySynchronously);
if (response.error) { if (response.error) {
if (response.stdErr.contains(QLatin1String("Versions other than the selected version"))) { if (response.stdErr.contains(QLatin1String("Versions other than the selected version"))) {
VersionSelector selector(file, response.stdErr); VersionSelector selector(file, response.stdErr);
@@ -1639,7 +1642,8 @@ bool ClearCasePlugin::vcsOpen(const QString &workingDir, const QString &fileName
else else
args.removeOne(QLatin1String("-query")); args.removeOne(QLatin1String("-query"));
response = runCleartool(topLevel, args, m_settings.timeOutS, response = runCleartool(topLevel, args, m_settings.timeOutS,
ShowStdOutInLogWindow | FullySynchronously); VcsCommand::ShowStdOut
| VcsCommand::FullySynchronously);
} }
} else { } else {
VcsOutputWindow::append(response.stdOut); VcsOutputWindow::append(response.stdOut);
@@ -1674,7 +1678,7 @@ bool ClearCasePlugin::vcsSetActivity(const QString &workingDir, const QString &t
QStringList args; QStringList args;
args << QLatin1String("setactivity") << activity; args << QLatin1String("setactivity") << activity;
const ClearCaseResponse actResponse = const ClearCaseResponse actResponse =
runCleartool(workingDir, args, m_settings.timeOutS, ShowStdOutInLogWindow); runCleartool(workingDir, args, m_settings.timeOutS, VcsCommand::ShowStdOut);
if (actResponse.error) { if (actResponse.error) {
QMessageBox::warning(ICore::dialogParent(), title, QMessageBox::warning(ICore::dialogParent(), title,
tr("Set current activity failed: %1").arg(actResponse.message), QMessageBox::Ok); tr("Set current activity failed: %1").arg(actResponse.message), QMessageBox::Ok);
@@ -1718,7 +1722,8 @@ bool ClearCasePlugin::vcsCheckIn(const QString &messageFile, const QStringList &
blockers.append(fcb); blockers.append(fcb);
} }
const ClearCaseResponse response = const ClearCaseResponse response =
runCleartool(m_checkInView, args, m_settings.longTimeOutS(), ShowStdOutInLogWindow); runCleartool(m_checkInView, args, m_settings.longTimeOutS(),
VcsCommand::ShowStdOut);
QRegExp checkedIn(QLatin1String("Checked in \\\"([^\"]*)\\\"")); QRegExp checkedIn(QLatin1String("Checked in \\\"([^\"]*)\\\""));
bool anySucceeded = false; bool anySucceeded = false;
int offset = checkedIn.indexIn(response.stdOut); int offset = checkedIn.indexIn(response.stdOut);
@@ -1785,7 +1790,7 @@ bool ClearCasePlugin::ccFileOp(const QString &workingDir, const QString &title,
args << QLatin1String("checkout") << commentArg << dirName; args << QLatin1String("checkout") << commentArg << dirName;
const ClearCaseResponse coResponse = const ClearCaseResponse coResponse =
runCleartool(workingDir, args, m_settings.timeOutS, runCleartool(workingDir, args, m_settings.timeOutS,
ShowStdOutInLogWindow | FullySynchronously); VcsCommand::ShowStdOut | VcsCommand::FullySynchronously);
if (coResponse.error) { if (coResponse.error) {
if (coResponse.stdErr.contains(QLatin1String("already checked out"))) if (coResponse.stdErr.contains(QLatin1String("already checked out")))
noCheckout = true; noCheckout = true;
@@ -1800,7 +1805,7 @@ bool ClearCasePlugin::ccFileOp(const QString &workingDir, const QString &title,
args << QDir::toNativeSeparators(file2); args << QDir::toNativeSeparators(file2);
const ClearCaseResponse opResponse = const ClearCaseResponse opResponse =
runCleartool(workingDir, args, m_settings.timeOutS, runCleartool(workingDir, args, m_settings.timeOutS,
ShowStdOutInLogWindow | FullySynchronously); VcsCommand::ShowStdOut | VcsCommand::FullySynchronously);
if (opResponse.error) { if (opResponse.error) {
// on failure - undo checkout for the directory // on failure - undo checkout for the directory
if (!noCheckout) if (!noCheckout)
@@ -1814,7 +1819,7 @@ bool ClearCasePlugin::ccFileOp(const QString &workingDir, const QString &title,
args << QLatin1String("checkin") << commentArg << dirName; args << QLatin1String("checkin") << commentArg << dirName;
const ClearCaseResponse ciResponse = const ClearCaseResponse ciResponse =
runCleartool(workingDir, args, m_settings.timeOutS, runCleartool(workingDir, args, m_settings.timeOutS,
ShowStdOutInLogWindow | FullySynchronously); VcsCommand::ShowStdOut | VcsCommand::FullySynchronously);
return !ciResponse.error; return !ciResponse.error;
} }
return true; return true;
+2 -1
View File
@@ -36,6 +36,7 @@
#include <coreplugin/id.h> #include <coreplugin/id.h>
#include <vcsbase/vcsbaseplugin.h> #include <vcsbase/vcsbaseplugin.h>
#include <vcsbase/vcscommand.h>
#include <QFile> #include <QFile>
#include <QPair> #include <QPair>
@@ -119,7 +120,7 @@ class ClearCasePlugin : public VcsBase::VcsBasePlugin
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClearCase.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClearCase.json")
enum { SilentRun = NoOutput | FullySynchronously }; enum { SilentRun = VcsBase::VcsCommand::NoOutput | VcsBase::VcsCommand::FullySynchronously };
public: public:
ClearCasePlugin(); ClearCasePlugin();
+2
View File
@@ -13,6 +13,7 @@ include(../../qtcreatorplugin.pri)
win32-msvc*:QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250 win32-msvc*:QMAKE_CXXFLAGS += -wd4251 -wd4290 -wd4250
SOURCES += corejsextensions.cpp \ SOURCES += corejsextensions.cpp \
mainwindow.cpp \ mainwindow.cpp \
shellcommand.cpp \
editmode.cpp \ editmode.cpp \
iwizardfactory.cpp \ iwizardfactory.cpp \
tabpositionindicator.cpp \ tabpositionindicator.cpp \
@@ -120,6 +121,7 @@ SOURCES += corejsextensions.cpp \
HEADERS += corejsextensions.h \ HEADERS += corejsextensions.h \
mainwindow.h \ mainwindow.h \
shellcommand.h \
editmode.h \ editmode.h \
iwizardfactory.h \ iwizardfactory.h \
tabpositionindicator.h \ tabpositionindicator.h \
+1
View File
@@ -91,6 +91,7 @@ QtcPlugin {
"removefiledialog.cpp", "removefiledialog.h", "removefiledialog.ui", "removefiledialog.cpp", "removefiledialog.h", "removefiledialog.ui",
"rightpane.cpp", "rightpane.h", "rightpane.cpp", "rightpane.h",
"settingsdatabase.cpp", "settingsdatabase.h", "settingsdatabase.cpp", "settingsdatabase.h",
"shellcommand.cpp", "shellcommand.h",
"sidebar.cpp", "sidebar.h", "sidebar.cpp", "sidebar.h",
"sidebarwidget.cpp", "sidebarwidget.h", "sidebarwidget.cpp", "sidebarwidget.h",
"statusbarmanager.cpp", "statusbarmanager.h", "statusbarmanager.cpp", "statusbarmanager.h",
+56
View File
@@ -0,0 +1,56 @@
/**************************************************************************
**
** Copyright (C) 2015 Brian McGillion and Hugues Delorme
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "shellcommand.h"
#include "icore.h"
#include "progressmanager/progressmanager.h"
namespace Core {
ShellCommand::ShellCommand(const QString &workingDirectory, const QProcessEnvironment &environment) :
Utils::ShellCommand(workingDirectory, environment)
{
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose,
this, &ShellCommand::coreAboutToClose);
}
void ShellCommand::addTask(QFuture<void> &future)
{
const QString name = displayName();
Core::ProgressManager::addTask(future, name, Core::Id::fromString(name + QLatin1String(".action")));
}
void ShellCommand::coreAboutToClose()
{
abort();
}
} // namespace Core
+55
View File
@@ -0,0 +1,55 @@
/**************************************************************************
**
** Copyright (C) 2015 Brian McGillion and Hugues Delorme
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CORE_SHELLCOMMAND_H
#define CORE_SHELLCOMMAND_H
#include "core_global.h"
#include <utils/shellcommand.h>
namespace Core {
class CORE_EXPORT ShellCommand : public Utils::ShellCommand
{
Q_OBJECT
public:
ShellCommand(const QString &workingDirectory, const QProcessEnvironment &environment);
protected:
void addTask(QFuture<void> &future);
virtual void coreAboutToClose();
};
} // namespace Core
#endif // CORE_SHELLCOMMAND_H
+18 -17
View File
@@ -38,11 +38,12 @@
#include "checkoutwizard.h" #include "checkoutwizard.h"
#include <vcsbase/basevcseditorfactory.h> #include <vcsbase/basevcseditorfactory.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
#include <vcsbase/vcsbaseconstants.h> #include <vcsbase/vcsbaseconstants.h>
#include <vcsbase/vcsbaseeditor.h> #include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/basevcssubmiteditorfactory.h>
#include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcsbaseeditorparameterwidget.h> #include <vcsbase/vcsbaseeditorparameterwidget.h>
#include <vcsbase/vcscommand.h>
#include <vcsbase/vcsoutputwindow.h>
#include <texteditor/textdocument.h> #include <texteditor/textdocument.h>
@@ -621,7 +622,7 @@ void CvsPlugin::revertAll()
args << QLatin1String("update") << QLatin1String("-C") << state.topLevel(); args << QLatin1String("update") << QLatin1String("-C") << state.topLevel();
const CvsResponse revertResponse = const CvsResponse revertResponse =
runCvs(state.topLevel(), args, client()->vcsTimeoutS(), runCvs(state.topLevel(), args, client()->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
if (revertResponse.result == CvsResponse::Ok) if (revertResponse.result == CvsResponse::Ok)
cvsVersionControl()->emitRepositoryChanged(state.topLevel()); cvsVersionControl()->emitRepositoryChanged(state.topLevel());
else else
@@ -659,7 +660,7 @@ void CvsPlugin::revertCurrentFile()
args << QLatin1String("update") << QLatin1String("-C") << state.relativeCurrentFile(); args << QLatin1String("update") << QLatin1String("-C") << state.relativeCurrentFile();
const CvsResponse revertResponse = const CvsResponse revertResponse =
runCvs(state.currentFileTopLevel(), args, client()->vcsTimeoutS(), runCvs(state.currentFileTopLevel(), args, client()->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
if (revertResponse.result == CvsResponse::Ok) if (revertResponse.result == CvsResponse::Ok)
cvsVersionControl()->emitFilesChanged(QStringList(state.currentFile())); cvsVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
} }
@@ -720,7 +721,7 @@ void CvsPlugin::startCommit(const QString &workingDir, const QString &file)
// where we are, so, have stdout/stderr channels merged. // where we are, so, have stdout/stderr channels merged.
QStringList args = QStringList(QLatin1String("status")); QStringList args = QStringList(QLatin1String("status"));
const CvsResponse response = const CvsResponse response =
runCvs(workingDir, args, client()->vcsTimeoutS(), MergeOutputChannels); runCvs(workingDir, args, client()->vcsTimeoutS(), VcsCommand::MergeOutputChannels);
if (response.result != CvsResponse::Ok) if (response.result != CvsResponse::Ok)
return; return;
// Get list of added/modified/deleted files and purge out undesired ones // Get list of added/modified/deleted files and purge out undesired ones
@@ -769,7 +770,7 @@ bool CvsPlugin::commit(const QString &messageFile,
args.append(fileList); args.append(fileList);
const CvsResponse response = const CvsResponse response =
runCvs(m_commitRepository, args, 10 * client()->vcsTimeoutS(), runCvs(m_commitRepository, args, 10 * client()->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
return response.result == CvsResponse::Ok ; return response.result == CvsResponse::Ok ;
} }
@@ -807,7 +808,7 @@ void CvsPlugin::filelog(const QString &workingDir,
args.append(file); args.append(file);
const CvsResponse response = const CvsResponse response =
runCvs(workingDir, args, client()->vcsTimeoutS(), runCvs(workingDir, args, client()->vcsTimeoutS(),
SshPasswordPrompt, codec); VcsCommand::SshPasswordPrompt, codec);
if (response.result != CvsResponse::Ok) if (response.result != CvsResponse::Ok)
return; return;
@@ -848,7 +849,7 @@ bool CvsPlugin::update(const QString &topLevel, const QString &file)
args.append(file); args.append(file);
const CvsResponse response = const CvsResponse response =
runCvs(topLevel, args, 10 * client()->vcsTimeoutS(), runCvs(topLevel, args, 10 * client()->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
const bool ok = response.result == CvsResponse::Ok; const bool ok = response.result == CvsResponse::Ok;
if (ok) if (ok)
cvsVersionControl()->emitRepositoryChanged(topLevel); cvsVersionControl()->emitRepositoryChanged(topLevel);
@@ -895,7 +896,7 @@ bool CvsPlugin::edit(const QString &topLevel, const QStringList &files)
args.append(files); args.append(files);
const CvsResponse response = const CvsResponse response =
runCvs(topLevel, args, client()->vcsTimeoutS(), runCvs(topLevel, args, client()->vcsTimeoutS(),
ShowStdOutInLogWindow|SshPasswordPrompt); VcsCommand::ShowStdOut | VcsCommand::SshPasswordPrompt);
return response.result == CvsResponse::Ok; return response.result == CvsResponse::Ok;
} }
@@ -935,7 +936,7 @@ bool CvsPlugin::unedit(const QString &topLevel, const QStringList &files)
args.append(files); args.append(files);
const CvsResponse response = const CvsResponse response =
runCvs(topLevel, args, client()->vcsTimeoutS(), runCvs(topLevel, args, client()->vcsTimeoutS(),
ShowStdOutInLogWindow|SshPasswordPrompt); VcsCommand::ShowStdOut | VcsCommand::SshPasswordPrompt);
return response.result == CvsResponse::Ok; return response.result == CvsResponse::Ok;
} }
@@ -954,7 +955,7 @@ void CvsPlugin::annotate(const QString &workingDir, const QString &file,
args << file; args << file;
const CvsResponse response = const CvsResponse response =
runCvs(workingDir, args, client()->vcsTimeoutS(), runCvs(workingDir, args, client()->vcsTimeoutS(),
SshPasswordPrompt, codec); VcsCommand::SshPasswordPrompt, codec);
if (response.result != CvsResponse::Ok) if (response.result != CvsResponse::Ok)
return; return;
@@ -1065,7 +1066,7 @@ bool CvsPlugin::describe(const QString &toplevel, const QString &file, const
QStringList args; QStringList args;
args << QLatin1String("log") << (QLatin1String("-r") + changeNr) << file; args << QLatin1String("log") << (QLatin1String("-r") + changeNr) << file;
const CvsResponse logResponse = const CvsResponse logResponse =
runCvs(toplevel, args, client()->vcsTimeoutS(), SshPasswordPrompt); runCvs(toplevel, args, client()->vcsTimeoutS(), VcsCommand::SshPasswordPrompt);
if (logResponse.result != CvsResponse::Ok) { if (logResponse.result != CvsResponse::Ok) {
*errorMessage = logResponse.message; *errorMessage = logResponse.message;
return false; return false;
@@ -1087,7 +1088,7 @@ bool CvsPlugin::describe(const QString &toplevel, const QString &file, const
args << QLatin1String("log") << QLatin1String("-d") << (dateS + QLatin1Char('<') + nextDayS); args << QLatin1String("log") << QLatin1String("-d") << (dateS + QLatin1Char('<') + nextDayS);
const CvsResponse repoLogResponse = const CvsResponse repoLogResponse =
runCvs(toplevel, args, 10 * client()->vcsTimeoutS(), SshPasswordPrompt); runCvs(toplevel, args, 10 * client()->vcsTimeoutS(), VcsCommand::SshPasswordPrompt);
if (repoLogResponse.result != CvsResponse::Ok) { if (repoLogResponse.result != CvsResponse::Ok) {
*errorMessage = repoLogResponse.message; *errorMessage = repoLogResponse.message;
return false; return false;
@@ -1124,7 +1125,7 @@ bool CvsPlugin::describe(const QString &repositoryPath,
QStringList args(QLatin1String("log")); QStringList args(QLatin1String("log"));
args << (QLatin1String("-r") + it->revisions.front().revision) << it->file; args << (QLatin1String("-r") + it->revisions.front().revision) << it->file;
const CvsResponse logResponse = const CvsResponse logResponse =
runCvs(repositoryPath, args, client()->vcsTimeoutS(), SshPasswordPrompt); runCvs(repositoryPath, args, client()->vcsTimeoutS(), VcsCommand::SshPasswordPrompt);
if (logResponse.result != CvsResponse::Ok) { if (logResponse.result != CvsResponse::Ok) {
*errorMessage = logResponse.message; *errorMessage = logResponse.message;
return false; return false;
@@ -1262,7 +1263,7 @@ bool CvsPlugin::vcsAdd(const QString &workingDir, const QString &rawFileName)
args << QLatin1String("add") << rawFileName; args << QLatin1String("add") << rawFileName;
const CvsResponse response = const CvsResponse response =
runCvs(workingDir, args, client()->vcsTimeoutS(), runCvs(workingDir, args, client()->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
return response.result == CvsResponse::Ok; return response.result == CvsResponse::Ok;
} }
@@ -1272,7 +1273,7 @@ bool CvsPlugin::vcsDelete(const QString &workingDir, const QString &rawFileName)
args << QLatin1String("remove") << QLatin1String("-f") << rawFileName; args << QLatin1String("remove") << QLatin1String("-f") << rawFileName;
const CvsResponse response = const CvsResponse response =
runCvs(workingDir, args, client()->vcsTimeoutS(), runCvs(workingDir, args, client()->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
return response.result == CvsResponse::Ok; return response.result == CvsResponse::Ok;
} }
@@ -1317,7 +1318,7 @@ bool CvsPlugin::managesFile(const QString &workingDirectory, const QString &file
QStringList args; QStringList args;
args << QLatin1String("status") << fileName; args << QLatin1String("status") << fileName;
const CvsResponse response = const CvsResponse response =
runCvs(workingDirectory, args, client()->vcsTimeoutS(), SshPasswordPrompt); runCvs(workingDirectory, args, client()->vcsTimeoutS(), VcsCommand::SshPasswordPrompt);
if (response.result != CvsResponse::Ok) if (response.result != CvsResponse::Ok)
return false; return false;
return !response.stdOut.contains(QLatin1String("Status: Unknown")); return !response.stdOut.contains(QLatin1String("Status: Unknown"));
+2 -2
View File
@@ -33,7 +33,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <vcsbase/vcsoutputwindow.h> #include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcsbaseplugin.h> #include <vcsbase/vcscommand.h>
#include <QFont> #include <QFont>
@@ -724,7 +724,7 @@ QString BranchModel::toolTip(const QString &sha) const
QStringList arguments(QLatin1String("-n1")); QStringList arguments(QLatin1String("-n1"));
arguments << sha; arguments << sha;
if (!m_client->synchronousLog(m_workingDirectory, arguments, &output, &errorMessage, if (!m_client->synchronousLog(m_workingDirectory, arguments, &output, &errorMessage,
VcsBasePlugin::SuppressCommandLogging)) { VcsCommand::SuppressCommandLogging)) {
return errorMessage; return errorMessage;
} }
return output; return output;
+1 -1
View File
@@ -124,7 +124,7 @@ VcsCommand *CloneWizardPage::createCheckoutJob(Utils::FileName *checkoutPath) co
args << QLatin1String("--recursive"); args << QLatin1String("--recursive");
args << QLatin1String("--progress") << repository() << checkoutDir; args << QLatin1String("--progress") << repository() << checkoutDir;
auto command = new VcsCommand(workingDirectory, client->processEnvironment()); auto command = new VcsCommand(workingDirectory, client->processEnvironment());
command->addFlags(VcsBasePlugin::MergeOutputChannels); command->addFlags(VcsCommand::MergeOutputChannels);
command->addJob(client->vcsBinary(), args, -1); command->addJob(client->vcsBinary(), args, -1);
return command; return command;
} }
+26 -28
View File
@@ -99,11 +99,11 @@ namespace Internal {
// Suppress git diff warnings about "LF will be replaced by CRLF..." on Windows. // Suppress git diff warnings about "LF will be replaced by CRLF..." on Windows.
static unsigned diffExecutionFlags() static unsigned diffExecutionFlags()
{ {
return HostOsInfo::isWindowsHost() ? unsigned(VcsBasePlugin::SuppressStdErrInLogWindow) : 0u; return HostOsInfo::isWindowsHost() ? unsigned(VcsCommand::SuppressStdErr) : 0u;
} }
const unsigned silentFlags = unsigned(VcsBasePlugin::SuppressCommandLogging const unsigned silentFlags = unsigned(VcsCommand::SuppressCommandLogging
| VcsBasePlugin::SuppressStdErrInLogWindow); | VcsCommand::SuppressStdErr);
///////////////////////////////////// /////////////////////////////////////
@@ -475,7 +475,7 @@ public:
ConflictHandler *handler = new ConflictHandler(command->workingDirectory(), abortCommand); ConflictHandler *handler = new ConflictHandler(command->workingDirectory(), abortCommand);
handler->setParent(command); // delete when command goes out of scope handler->setParent(command); // delete when command goes out of scope
command->addFlags(VcsBasePlugin::ExpectRepoChanges); command->addFlags(VcsCommand::ExpectRepoChanges);
connect(command, &VcsCommand::output, handler, &ConflictHandler::readStdOut); connect(command, &VcsCommand::output, handler, &ConflictHandler::readStdOut);
connect(command, &VcsCommand::errorText, handler, &ConflictHandler::readStdErr); connect(command, &VcsCommand::errorText, handler, &ConflictHandler::readStdErr);
} }
@@ -965,7 +965,7 @@ bool GitClient::synchronousCheckout(const QString &workingDirectory,
QByteArray errorText; QByteArray errorText;
QStringList arguments = setupCheckoutArguments(workingDirectory, ref); QStringList arguments = setupCheckoutArguments(workingDirectory, ref);
const bool rc = vcsFullySynchronousExec(workingDirectory, arguments, &outputText, 0, const bool rc = vcsFullySynchronousExec(workingDirectory, arguments, &outputText, 0,
VcsBasePlugin::ExpectRepoChanges); VcsCommand::ExpectRepoChanges);
VcsOutputWindow::append(commandOutputFromLocal8Bit(outputText)); VcsOutputWindow::append(commandOutputFromLocal8Bit(outputText));
if (rc) if (rc)
updateSubmodulesIfNeeded(workingDirectory, true); updateSubmodulesIfNeeded(workingDirectory, true);
@@ -1044,7 +1044,7 @@ void GitClient::reset(const QString &workingDirectory, const QString &argument,
unsigned flags = 0; unsigned flags = 0;
if (argument == QLatin1String("--hard")) if (argument == QLatin1String("--hard"))
flags |= VcsBasePlugin::ExpectRepoChanges; flags |= VcsCommand::ExpectRepoChanges;
vcsExec(workingDirectory, arguments, 0, true, flags); vcsExec(workingDirectory, arguments, 0, true, flags);
} }
@@ -1180,7 +1180,7 @@ bool GitClient::synchronousCheckoutFiles(const QString &workingDirectory,
arguments << revision; arguments << revision;
arguments << QLatin1String("--") << files; arguments << QLatin1String("--") << files;
const bool rc = vcsFullySynchronousExec(workingDirectory, arguments, &outputText, &errorText, const bool rc = vcsFullySynchronousExec(workingDirectory, arguments, &outputText, &errorText,
VcsBasePlugin::ExpectRepoChanges); VcsCommand::ExpectRepoChanges);
if (!rc) { if (!rc) {
const QString fileArg = files.join(QLatin1String(", ")); const QString fileArg = files.join(QLatin1String(", "));
//: Meaning of the arguments: %1: revision, %2: files, %3: repository, //: Meaning of the arguments: %1: revision, %2: files, %3: repository,
@@ -1392,7 +1392,7 @@ QString GitClient::synchronousTopic(const QString &workingDirectory) const
QByteArray output; QByteArray output;
QStringList arguments; QStringList arguments;
arguments << QLatin1String("describe"); arguments << QLatin1String("describe");
if (vcsFullySynchronousExec(workingDirectory, arguments, &output, 0, VcsBasePlugin::NoOutput)) { if (vcsFullySynchronousExec(workingDirectory, arguments, &output, 0, VcsCommand::NoOutput)) {
const QString describeOutput = commandOutputFromLocal8Bit(output.trimmed()); const QString describeOutput = commandOutputFromLocal8Bit(output.trimmed());
if (!describeOutput.isEmpty()) if (!describeOutput.isEmpty())
return describeOutput; return describeOutput;
@@ -1586,9 +1586,9 @@ bool GitClient::executeSynchronousStash(const QString &workingDirectory,
arguments << QLatin1String("--keep-index"); arguments << QLatin1String("--keep-index");
if (!message.isEmpty()) if (!message.isEmpty())
arguments << message; arguments << message;
const unsigned flags = VcsBasePlugin::ShowStdOutInLogWindow const unsigned flags = VcsCommand::ShowStdOut
| VcsBasePlugin::ExpectRepoChanges | VcsCommand::ExpectRepoChanges
| VcsBasePlugin::ShowSuccessMessage; | VcsCommand::ShowSuccessMessage;
const SynchronousProcessResponse response = vcsSynchronousExec(workingDirectory, arguments, flags); const SynchronousProcessResponse response = vcsSynchronousExec(workingDirectory, arguments, flags);
const bool rc = response.result == SynchronousProcessResponse::Finished; const bool rc = response.result == SynchronousProcessResponse::Finished;
if (!rc) if (!rc)
@@ -1961,7 +1961,7 @@ void GitClient::updateSubmodulesIfNeeded(const QString &workingDirectory, bool p
arguments << QLatin1String("submodule") << QLatin1String("update"); arguments << QLatin1String("submodule") << QLatin1String("update");
VcsCommand *cmd = vcsExec(workingDirectory, arguments, 0, true, VcsCommand *cmd = vcsExec(workingDirectory, arguments, 0, true,
VcsBasePlugin::ExpectRepoChanges); VcsCommand::ExpectRepoChanges);
connect(cmd, &VcsCommand::finished, this, &GitClient::finishSubmoduleUpdate); connect(cmd, &VcsCommand::finished, this, &GitClient::finishSubmoduleUpdate);
} }
@@ -2160,9 +2160,9 @@ QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryUR
{ {
QStringList arguments(QLatin1String("ls-remote")); QStringList arguments(QLatin1String("ls-remote"));
arguments << repositoryURL << QLatin1String(HEAD) << QLatin1String("refs/heads/*"); arguments << repositoryURL << QLatin1String(HEAD) << QLatin1String("refs/heads/*");
const unsigned flags = VcsBasePlugin::SshPasswordPrompt const unsigned flags = VcsCommand::SshPasswordPrompt
| VcsBasePlugin::SuppressStdErrInLogWindow | VcsCommand::SuppressStdErr
| VcsBasePlugin::SuppressFailMessageInLogWindow; | VcsCommand::SuppressFailMessage;
const SynchronousProcessResponse resp = vcsSynchronousExec(workingDirectory, arguments, flags); const SynchronousProcessResponse resp = vcsSynchronousExec(workingDirectory, arguments, flags);
QStringList branches; QStringList branches;
branches << tr("<Detached HEAD>"); branches << tr("<Detached HEAD>");
@@ -2725,10 +2725,10 @@ bool GitClient::executeAndHandleConflicts(const QString &workingDirectory,
const QString &abortCommand) const const QString &abortCommand) const
{ {
// Disable UNIX terminals to suppress SSH prompting. // Disable UNIX terminals to suppress SSH prompting.
const unsigned flags = VcsBasePlugin::SshPasswordPrompt const unsigned flags = VcsCommand::SshPasswordPrompt
| VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut
| VcsBasePlugin::ExpectRepoChanges | VcsCommand::ExpectRepoChanges
| VcsBasePlugin::ShowSuccessMessage; | VcsCommand::ShowSuccessMessage;
const SynchronousProcessResponse resp = vcsSynchronousExec(workingDirectory, arguments, flags); const SynchronousProcessResponse resp = vcsSynchronousExec(workingDirectory, arguments, flags);
// Notify about changed files or abort the rebase. // Notify about changed files or abort the rebase.
const bool ok = resp.result == SynchronousProcessResponse::Finished; const bool ok = resp.result == SynchronousProcessResponse::Finished;
@@ -2768,7 +2768,7 @@ void GitClient::synchronousAbortCommand(const QString &workingDir, const QString
QStringList arguments; QStringList arguments;
arguments << abortCommand << QLatin1String("--abort"); arguments << abortCommand << QLatin1String("--abort");
QByteArray stdOut; QByteArray stdOut;
vcsFullySynchronousExec(workingDir, arguments, &stdOut, 0, VcsBasePlugin::ExpectRepoChanges); vcsFullySynchronousExec(workingDir, arguments, &stdOut, 0, VcsCommand::ExpectRepoChanges);
VcsOutputWindow::append(commandOutputFromLocal8Bit(stdOut)); VcsOutputWindow::append(commandOutputFromLocal8Bit(stdOut));
} }
@@ -2848,9 +2848,9 @@ void GitClient::synchronousSubversionFetch(const QString &workingDirectory)
QStringList args; QStringList args;
args << QLatin1String("svn") << QLatin1String("fetch"); args << QLatin1String("svn") << QLatin1String("fetch");
// Disable UNIX terminals to suppress SSH prompting. // Disable UNIX terminals to suppress SSH prompting.
const unsigned flags = VcsBasePlugin::SshPasswordPrompt const unsigned flags = VcsCommand::SshPasswordPrompt
| VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut
| VcsBasePlugin::ShowSuccessMessage; | VcsCommand::ShowSuccessMessage;
vcsSynchronousExec(workingDirectory, args, flags); vcsSynchronousExec(workingDirectory, args, flags);
} }
@@ -2999,8 +2999,7 @@ void GitClient::stashPop(const QString &workingDirectory, const QString &stash)
arguments << QLatin1String("pop"); arguments << QLatin1String("pop");
if (!stash.isEmpty()) if (!stash.isEmpty())
arguments << stash; arguments << stash;
VcsCommand *cmd = vcsExec(workingDirectory, arguments, 0, true, VcsCommand *cmd = vcsExec(workingDirectory, arguments, 0, true, VcsCommand::ExpectRepoChanges);
VcsBasePlugin::ExpectRepoChanges);
ConflictHandler::attachToCommand(cmd); ConflictHandler::attachToCommand(cmd);
} }
@@ -3083,9 +3082,8 @@ QString GitClient::readConfigValue(const QString &workingDirectory, const QStrin
bool GitClient::cloneRepository(const QString &directory,const QByteArray &url) bool GitClient::cloneRepository(const QString &directory,const QByteArray &url)
{ {
QDir workingDirectory(directory); QDir workingDirectory(directory);
const unsigned flags = VcsBasePlugin::SshPasswordPrompt const unsigned flags = VcsCommand::SshPasswordPrompt
| VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut | VcsCommand::ShowSuccessMessage;
| VcsBasePlugin::ShowSuccessMessage;
if (workingDirectory.exists()) { if (workingDirectory.exists()) {
if (!synchronousInit(workingDirectory.path())) if (!synchronousInit(workingDirectory.path()))
+2 -2
View File
@@ -33,7 +33,7 @@
#include "gitclient.h" #include "gitclient.h"
#include <vcsbase/vcsoutputwindow.h> #include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcsbaseplugin.h> #include <vcsbase/vcscommand.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -164,7 +164,7 @@ bool LogChangeWidget::populateLog(const QString &repository, const QString &comm
if (!(flags & IncludeRemotes)) if (!(flags & IncludeRemotes))
arguments << QLatin1String("--not") << QLatin1String("--remotes"); arguments << QLatin1String("--not") << QLatin1String("--remotes");
QString output; QString output;
if (!client->synchronousLog(repository, arguments, &output, 0, VcsBasePlugin::NoOutput)) if (!client->synchronousLog(repository, arguments, &output, 0, VcsCommand::NoOutput))
return false; return false;
foreach (const QString &line, output.split(QLatin1Char('\n'))) { foreach (const QString &line, output.split(QLatin1Char('\n'))) {
const int colonPos = line.indexOf(QLatin1Char(':')); const int colonPos = line.indexOf(QLatin1Char(':'));
+6 -6
View File
@@ -102,9 +102,9 @@ bool MercurialClient::synchronousClone(const QString &workingDir,
Q_UNUSED(extraOptions); Q_UNUSED(extraOptions);
QDir workingDirectory(srcLocation); QDir workingDirectory(srcLocation);
QByteArray output; QByteArray output;
const unsigned flags = VcsBasePlugin::SshPasswordPrompt | const unsigned flags = VcsCommand::SshPasswordPrompt |
VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut |
VcsBasePlugin::ShowSuccessMessage; VcsCommand::ShowSuccessMessage;
if (workingDirectory.exists()) { if (workingDirectory.exists()) {
// Let's make first init // Let's make first init
@@ -151,9 +151,9 @@ bool MercurialClient::synchronousPull(const QString &workingDir, const QString &
args << vcsCommandString(PullCommand) << extraOptions << srcLocation; args << vcsCommandString(PullCommand) << extraOptions << srcLocation;
// Disable UNIX terminals to suppress SSH prompting // Disable UNIX terminals to suppress SSH prompting
const unsigned flags = const unsigned flags =
VcsBasePlugin::SshPasswordPrompt VcsCommand::SshPasswordPrompt
| VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut
| VcsBasePlugin::ShowSuccessMessage; | VcsCommand::ShowSuccessMessage;
// cause mercurial doesn`t understand LANG // cause mercurial doesn`t understand LANG
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+2 -2
View File
@@ -88,7 +88,7 @@ VcsCommand *SubversionClient::createCommitCmd(const QString &repositoryRoot,
<< QLatin1String("--file") << commitMessageFile; << QLatin1String("--file") << commitMessageFile;
VcsCommand *cmd = createCommand(repositoryRoot); VcsCommand *cmd = createCommand(repositoryRoot);
cmd->addFlags(VcsBasePlugin::ShowStdOutInLogWindow); cmd->addFlags(VcsCommand::ShowStdOut);
QStringList args(vcsCommandString(CommitCommand)); QStringList args(vcsCommandString(CommitCommand));
cmd->addJob(vcsBinary(), args << svnExtraOptions << files); cmd->addJob(vcsBinary(), args << svnExtraOptions << files);
return cmd; return cmd;
@@ -222,7 +222,7 @@ QString DiffController::getDescription() const
const SubversionResponse logResponse = const SubversionResponse logResponse =
SubversionPlugin::instance()->runSvn(m_workingDirectory, args, SubversionPlugin::instance()->runSvn(m_workingDirectory, args,
m_client->vcsTimeoutS(), m_client->vcsTimeoutS(),
VcsBasePlugin::SshPasswordPrompt); VcsCommand::SshPasswordPrompt);
if (logResponse.error) if (logResponse.error)
return QString(); return QString();
+11 -10
View File
@@ -586,7 +586,7 @@ void SubversionPlugin::revertAll()
args << QLatin1String("--recursive") << state.topLevel(); args << QLatin1String("--recursive") << state.topLevel();
const SubversionResponse revertResponse const SubversionResponse revertResponse
= runSvn(state.topLevel(), args, m_client->vcsTimeoutS(), = runSvn(state.topLevel(), args, m_client->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
if (revertResponse.error) if (revertResponse.error)
QMessageBox::warning(ICore::dialogParent(), title, QMessageBox::warning(ICore::dialogParent(), title,
tr("Revert failed: %1").arg(revertResponse.message), QMessageBox::Ok); tr("Revert failed: %1").arg(revertResponse.message), QMessageBox::Ok);
@@ -626,7 +626,7 @@ void SubversionPlugin::revertCurrentFile()
const SubversionResponse revertResponse const SubversionResponse revertResponse
= runSvn(state.currentFileTopLevel(), args, m_client->vcsTimeoutS(), = runSvn(state.currentFileTopLevel(), args, m_client->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
if (!revertResponse.error) if (!revertResponse.error)
subVersionControl()->emitFilesChanged(QStringList(state.currentFile())); subVersionControl()->emitFilesChanged(QStringList(state.currentFile()));
@@ -768,7 +768,8 @@ void SubversionPlugin::svnStatus(const QString &workingDir, const QString &relat
if (!relativePath.isEmpty()) if (!relativePath.isEmpty())
args.append(relativePath); args.append(relativePath);
VcsOutputWindow::setRepository(workingDir); VcsOutputWindow::setRepository(workingDir);
runSvn(workingDir, args, m_client->vcsTimeoutS(), ShowStdOutInLogWindow|ShowSuccessMessage); runSvn(workingDir, args, m_client->vcsTimeoutS(),
VcsCommand::ShowStdOut | VcsCommand::ShowSuccessMessage);
VcsOutputWindow::clearRepository(); VcsOutputWindow::clearRepository();
} }
@@ -795,7 +796,7 @@ void SubversionPlugin::svnUpdate(const QString &workingDir, const QString &relat
args.append(relativePath); args.append(relativePath);
const SubversionResponse response const SubversionResponse response
= runSvn(workingDir, args, 10 * m_client->vcsTimeoutS(), = runSvn(workingDir, args, 10 * m_client->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
if (!response.error) if (!response.error)
subVersionControl()->emitRepositoryChanged(workingDir); subVersionControl()->emitRepositoryChanged(workingDir);
} }
@@ -834,7 +835,7 @@ void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &fil
const SubversionResponse response const SubversionResponse response
= runSvn(workingDir, args, m_client->vcsTimeoutS(), = runSvn(workingDir, args, m_client->vcsTimeoutS(),
SshPasswordPrompt|ForceCLocale, codec); VcsCommand::SshPasswordPrompt | VcsCommand::ForceCLocale, codec);
if (response.error) if (response.error)
return; return;
@@ -999,7 +1000,7 @@ bool SubversionPlugin::vcsAdd(const QString &workingDir, const QString &rawFileN
<< QLatin1String("--parents") << file; << QLatin1String("--parents") << file;
const SubversionResponse response const SubversionResponse response
= runSvn(workingDir, args, m_client->vcsTimeoutS(), = runSvn(workingDir, args, m_client->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
return !response.error; return !response.error;
} }
@@ -1014,7 +1015,7 @@ bool SubversionPlugin::vcsDelete(const QString &workingDir, const QString &rawFi
const SubversionResponse response const SubversionResponse response
= runSvn(workingDir, args, m_client->vcsTimeoutS(), = runSvn(workingDir, args, m_client->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut);
return !response.error; return !response.error;
} }
@@ -1025,7 +1026,8 @@ bool SubversionPlugin::vcsMove(const QString &workingDir, const QString &from, c
args << QDir::toNativeSeparators(from) << QDir::toNativeSeparators(to); args << QDir::toNativeSeparators(from) << QDir::toNativeSeparators(to);
const SubversionResponse response const SubversionResponse response
= runSvn(workingDir, args, m_client->vcsTimeoutS(), = runSvn(workingDir, args, m_client->vcsTimeoutS(),
SshPasswordPrompt|ShowStdOutInLogWindow|FullySynchronously); VcsCommand::SshPasswordPrompt | VcsCommand::ShowStdOut
| VcsCommand::FullySynchronously);
return !response.error; return !response.error;
} }
@@ -1052,8 +1054,7 @@ bool SubversionPlugin::vcsCheckout(const QString &directory, const QByteArray &u
args << QLatin1String(tempUrl.toEncoded()) << directory; args << QLatin1String(tempUrl.toEncoded()) << directory;
const SubversionResponse response const SubversionResponse response
= runSvn(directory, args, 10 * m_client->vcsTimeoutS(), = runSvn(directory, args, 10 * m_client->vcsTimeoutS(), VcsCommand::SshPasswordPrompt);
VcsBasePlugin::SshPasswordPrompt);
return !response.error; return !response.error;
} }
+9 -9
View File
@@ -144,9 +144,9 @@ VcsCommand *VcsBaseClientImpl::createCommand(const QString &workingDirectory,
if (editor) if (editor)
d->bindCommandToEditor(cmd, editor); d->bindCommandToEditor(cmd, editor);
if (mode == VcsWindowOutputBind) { if (mode == VcsWindowOutputBind) {
cmd->addFlags(VcsBasePlugin::ShowStdOutInLogWindow); cmd->addFlags(VcsCommand::ShowStdOut);
if (editor) // assume that the commands output is the important thing if (editor) // assume that the commands output is the important thing
cmd->addFlags(VcsBasePlugin::SilentOutput); cmd->addFlags(VcsCommand::SilentOutput);
} else if (editor) { } else if (editor) {
connect(cmd, &VcsCommand::output, editor, &VcsBaseEditorWidget::setPlainText); connect(cmd, &VcsCommand::output, editor, &VcsBaseEditorWidget::setPlainText);
} }
@@ -211,7 +211,7 @@ bool VcsBaseClientImpl::vcsFullySynchronousExec(const QString &workingDir, const
command->addFlags(flags); command->addFlags(flags);
bool result = command->runFullySynchronous(vcsBinary(), args, vcsTimeoutS(), outputData, bool result = command->runFullySynchronous(vcsBinary(), args, vcsTimeoutS(), outputData,
errorData ? errorData : &internalErrorData); errorData ? errorData : &internalErrorData);
if (!internalErrorData.isEmpty() && !(flags & VcsBasePlugin::SuppressStdErrInLogWindow)) if (!internalErrorData.isEmpty() && !(flags & VcsCommand::SuppressStdErr))
VcsOutputWindow::appendError(commandOutputFromLocal8Bit(internalErrorData)); VcsOutputWindow::appendError(commandOutputFromLocal8Bit(internalErrorData));
return result; return result;
} }
@@ -394,9 +394,9 @@ bool VcsBaseClient::synchronousPull(const QString &workingDir,
args << vcsCommandString(PullCommand) << extraOptions << srcLocation; args << vcsCommandString(PullCommand) << extraOptions << srcLocation;
// Disable UNIX terminals to suppress SSH prompting // Disable UNIX terminals to suppress SSH prompting
const unsigned flags = const unsigned flags =
VcsBasePlugin::SshPasswordPrompt VcsCommand::SshPasswordPrompt
| VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut
| VcsBasePlugin::ShowSuccessMessage; | VcsCommand::ShowSuccessMessage;
const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags); const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
const bool ok = resp.result == Utils::SynchronousProcessResponse::Finished; const bool ok = resp.result == Utils::SynchronousProcessResponse::Finished;
if (ok) if (ok)
@@ -412,9 +412,9 @@ bool VcsBaseClient::synchronousPush(const QString &workingDir,
args << vcsCommandString(PushCommand) << extraOptions << dstLocation; args << vcsCommandString(PushCommand) << extraOptions << dstLocation;
// Disable UNIX terminals to suppress SSH prompting // Disable UNIX terminals to suppress SSH prompting
const unsigned flags = const unsigned flags =
VcsBasePlugin::SshPasswordPrompt VcsCommand::SshPasswordPrompt
| VcsBasePlugin::ShowStdOutInLogWindow | VcsCommand::ShowStdOut
| VcsBasePlugin::ShowSuccessMessage; | VcsCommand::ShowSuccessMessage;
const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags); const Utils::SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
return resp.result == Utils::SynchronousProcessResponse::Finished; return resp.result == Utils::SynchronousProcessResponse::Finished;
} }
+1 -1
View File
@@ -812,7 +812,7 @@ SynchronousProcessResponse VcsBasePlugin::runVcs(const QString &workingDir,
VcsCommand command(workingDir, env.isEmpty() ? QProcessEnvironment::systemEnvironment() : env); VcsCommand command(workingDir, env.isEmpty() ? QProcessEnvironment::systemEnvironment() : env);
command.addFlags(flags); command.addFlags(flags);
command.setCodec(outputCodec); command.setCodec(outputCodec);
return command.runVcs(binary, arguments, timeOutS); return command.runCommand(binary, arguments, timeOutS);
} }
} // namespace VcsBase } // namespace VcsBase
-18
View File
@@ -167,24 +167,6 @@ public:
// Returns the source of editor contents. // Returns the source of editor contents.
static QString source(Core::IDocument *document); static QString source(Core::IDocument *document);
// Convenience to synchronously run VCS commands
enum RunVcsFlags {
ShowStdOutInLogWindow = 0x1, // Append standard output to VCS output window.
MergeOutputChannels = 0x2, // see QProcess: Merge stderr/stdout.
SshPasswordPrompt = 0x4, // Disable terminal on UNIX to force graphical prompt.
SuppressStdErrInLogWindow = 0x8, // No standard error output to VCS output window.
SuppressFailMessageInLogWindow = 0x10, // No message VCS about failure in VCS output window.
SuppressCommandLogging = 0x20, // No command log entry in VCS output window.
ShowSuccessMessage = 0x40, // Show message about successful completion in VCS output window.
ForceCLocale = 0x80, // Force C-locale for commands whose output is parsed.
FullySynchronously = 0x100, // Suppress local event loop (in case UI actions are
// triggered by file watchers).
ExpectRepoChanges = 0x200, // Expect changes in repository by the command
SilentOutput = 0x400, // With ShowStdOutInLogWindow - append output silently
NoOutput = SuppressStdErrInLogWindow | SuppressFailMessageInLogWindow
| SuppressCommandLogging
};
static Utils::SynchronousProcessResponse runVcs(const QString &workingDir, static Utils::SynchronousProcessResponse runVcs(const QString &workingDir,
const Utils::FileName &binary, const Utils::FileName &binary,
const QStringList &arguments, const QStringList &arguments,
+48 -563
View File
@@ -53,599 +53,84 @@
#include <QTextCodec> #include <QTextCodec>
#include <QMutex> #include <QMutex>
enum { debugExecution = 0 };
/*!
\fn void VcsBase::ProgressParser::parseProgress(const QString &text)
Reimplement to parse progress as it appears in the standard output.
If a progress string is detected, call \c setProgressAndMaximum() to update
the progress bar accordingly.
\sa VcsBase::ProgressParser::setProgressAndMaximum()
*/
/*!
\fn void VcsBase::ProgressParser::setProgressAndMaximum(int value, int maximum)
Sets progress \a value and \a maximum for current command. Called by \c parseProgress()
when a progress string is detected.
*/
namespace VcsBase { namespace VcsBase {
namespace Internal {
class VcsCommandPrivate
{
public:
struct Job {
explicit Job(const Utils::FileName &b, const QStringList &a, int t,
Utils::ExitCodeInterpreter *interpreter = 0);
Utils::FileName binary;
QStringList arguments;
int timeoutS;
Utils::ExitCodeInterpreter *exitCodeInterpreter;
};
VcsCommandPrivate(const QString &workingDirectory, const QProcessEnvironment &environment);
~VcsCommandPrivate();
QString m_displayName;
const QString m_workingDirectory;
const QProcessEnvironment m_environment;
QVariant m_cookie;
int m_defaultTimeoutS;
unsigned m_flags;
QTextCodec *m_codec;
const QString m_sshPasswordPrompt;
ProgressParser *m_progressParser;
bool m_progressiveOutput;
bool m_hadOutput;
bool m_preventRepositoryChanged;
bool m_aborted;
QFutureWatcher<void> m_watcher;
QList<Job> m_jobs;
bool m_lastExecSuccess;
int m_lastExecExitCode;
};
VcsCommandPrivate::VcsCommandPrivate(const QString &workingDirectory,
const QProcessEnvironment &environment) :
m_workingDirectory(workingDirectory),
m_environment(environment),
m_defaultTimeoutS(10),
m_flags(0),
m_codec(0),
m_sshPasswordPrompt(VcsBasePlugin::sshPrompt()),
m_progressParser(0),
m_progressiveOutput(false),
m_hadOutput(false),
m_preventRepositoryChanged(false),
m_aborted(false),
m_lastExecSuccess(false),
m_lastExecExitCode(-1)
{
}
VcsCommandPrivate::~VcsCommandPrivate()
{
delete m_progressParser;
}
VcsCommandPrivate::Job::Job(const Utils::FileName &b, const QStringList &a,
int t, Utils::ExitCodeInterpreter *interpreter) :
binary(b),
arguments(a),
timeoutS(t),
exitCodeInterpreter(interpreter)
{
// Finished cookie is emitted via queued slot, needs metatype
static const int qvMetaId = qRegisterMetaType<QVariant>();
Q_UNUSED(qvMetaId)
}
} // namespace Internal
VcsCommand::VcsCommand(const QString &workingDirectory, VcsCommand::VcsCommand(const QString &workingDirectory,
const QProcessEnvironment &environment) : const QProcessEnvironment &environment) :
d(new Internal::VcsCommandPrivate(workingDirectory, environment)) Core::ShellCommand(workingDirectory, environment),
m_preventRepositoryChanged(false)
{ {
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose, setOutputProxyFactory([]() -> Utils::OutputProxy * {
this, &VcsCommand::coreAboutToClose); auto proxy = new Utils::OutputProxy;
VcsOutputWindow *outputWindow = VcsOutputWindow::instance();
connect(proxy, &Utils::OutputProxy::append,
outputWindow, [](const QString &txt) { VcsOutputWindow::append(txt); },
Qt::QueuedConnection);
connect(proxy, &Utils::OutputProxy::appendSilently,
outputWindow, &VcsOutputWindow::appendSilently,
Qt::QueuedConnection);
connect(proxy, &Utils::OutputProxy::appendError,
outputWindow, &VcsOutputWindow::appendError,
Qt::QueuedConnection);
connect(proxy, &Utils::OutputProxy::appendCommand,
outputWindow, &VcsOutputWindow::appendCommand,
Qt::QueuedConnection);
connect(proxy, &Utils::OutputProxy::appendMessage,
outputWindow, &VcsOutputWindow::appendMessage,
Qt::QueuedConnection);
return proxy;
});
} }
VcsCommand::~VcsCommand() const QProcessEnvironment VcsCommand::processEnvironment() const
{ {
delete d; QProcessEnvironment env = Core::ShellCommand::processEnvironment();
VcsBasePlugin::setProcessEnvironment(&env, flags() & ForceCLocale, VcsBasePlugin::sshPrompt());
return env;
} }
QString VcsCommand::displayName() const Utils::SynchronousProcessResponse VcsCommand::runCommand(const Utils::FileName &binary,
const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{ {
if (!d->m_displayName.isEmpty()) Utils::SynchronousProcessResponse response
return d->m_displayName; = Core::ShellCommand::runCommand(binary, arguments, timeoutS, interpreter);
if (!d->m_jobs.isEmpty()) {
const Internal::VcsCommandPrivate::Job &job = d->m_jobs.at(0);
QString result = job.binary.toFileInfo().baseName();
result[0] = result.at(0).toTitleCase();
if (!job.arguments.isEmpty())
result += QLatin1Char(' ') + job.arguments.at(0);
return result;
}
return tr("Unknown");
}
void VcsCommand::setDisplayName(const QString &name)
{
d->m_displayName = name;
}
const QString &VcsCommand::workingDirectory() const
{
return d->m_workingDirectory;
}
const QProcessEnvironment &VcsCommand::processEnvironment() const
{
return d->m_environment;
}
int VcsCommand::defaultTimeoutS() const
{
return d->m_defaultTimeoutS;
}
void VcsCommand::setDefaultTimeoutS(int timeout)
{
d->m_defaultTimeoutS = timeout;
}
unsigned VcsCommand::flags() const
{
return d->m_flags;
}
void VcsCommand::addFlags(unsigned f)
{
d->m_flags |= f;
}
void VcsCommand::addJob(const Utils::FileName &binary, const QStringList &arguments,
Utils::ExitCodeInterpreter *interpreter)
{
addJob(binary, arguments, defaultTimeoutS(), interpreter);
}
void VcsCommand::addJob(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
d->m_jobs.push_back(Internal::VcsCommandPrivate::Job(binary, arguments, timeoutS, interpreter));
}
void VcsCommand::execute()
{
d->m_lastExecSuccess = false;
d->m_lastExecExitCode = -1;
if (d->m_jobs.empty())
return;
// For some reason QtConcurrent::run() only works on this
QFuture<void> task = QtConcurrent::run(&VcsCommand::run, this);
d->m_watcher.setFuture(task);
connect(&d->m_watcher, &QFutureWatcher<void>::canceled, this, &VcsCommand::cancel);
const QString name = displayName();
Core::ProgressManager::addTask(task, name, Core::Id::fromString(name + QLatin1String(".action")));
}
void VcsCommand::abort()
{
d->m_aborted = true;
d->m_watcher.future().cancel();
}
void VcsCommand::cancel()
{
emit terminate();
}
bool VcsCommand::lastExecutionSuccess() const
{
return d->m_lastExecSuccess;
}
int VcsCommand::lastExecutionExitCode() const
{
return d->m_lastExecExitCode;
}
void VcsCommand::run(QFutureInterface<void> &future)
{
// Check that the binary path is not empty
QTC_ASSERT(!d->m_jobs.isEmpty(), return);
QString stdOut;
QString stdErr;
if (d->m_progressParser)
d->m_progressParser->setFuture(&future);
else
future.setProgressRange(0, 1);
const int count = d->m_jobs.size();
d->m_lastExecExitCode = -1;
d->m_lastExecSuccess = true;
for (int j = 0; j < count; j++) {
const Internal::VcsCommandPrivate::Job &job = d->m_jobs.at(j);
Utils::SynchronousProcessResponse resp
= runVcs(job.binary, job.arguments, job.timeoutS, job.exitCodeInterpreter);
stdOut += resp.stdOut;
stdErr += resp.stdErr;
d->m_lastExecExitCode = resp.exitCode;
d->m_lastExecSuccess = resp.result == Utils::SynchronousProcessResponse::Finished;
if (!d->m_lastExecSuccess)
break;
}
if (!d->m_aborted) {
if (!d->m_progressiveOutput) {
emit output(stdOut);
if (!stdErr.isEmpty())
emit errorText(stdErr);
}
emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie());
if (d->m_lastExecSuccess)
emit success(cookie());
future.setProgressValue(future.progressMaximum());
}
if (d->m_progressParser)
d->m_progressParser->setFuture(0);
// As it is used asynchronously, we need to delete ourselves
this->deleteLater();
}
class OutputProxy : public QObject
{
Q_OBJECT
friend class VcsCommand;
public:
OutputProxy()
{
// Users of this class can either be in the GUI thread or in other threads.
// Use Qt::AutoConnection to always append in the GUI thread (directly or queued)
VcsOutputWindow *outputWindow = VcsOutputWindow::instance();
connect(this, &OutputProxy::append,
outputWindow, [](const QString &txt) { VcsOutputWindow::append(txt); });
connect(this, &OutputProxy::appendSilently, outputWindow, &VcsOutputWindow::appendSilently);
connect(this, &OutputProxy::appendError, outputWindow, &VcsOutputWindow::appendError);
connect(this, &OutputProxy::appendCommand, outputWindow, &VcsOutputWindow::appendCommand);
connect(this, &OutputProxy::appendMessage, outputWindow, &VcsOutputWindow::appendMessage);
}
signals:
void append(const QString &text);
void appendSilently(const QString &text);
void appendError(const QString &text);
void appendCommand(const QString &workingDirectory,
const Utils::FileName &binary,
const QStringList &args);
void appendMessage(const QString &text);
};
Utils::SynchronousProcessResponse VcsCommand::runVcs(const Utils::FileName &binary,
const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
Utils::SynchronousProcessResponse response;
OutputProxy outputProxy;
if (binary.isEmpty()) {
response.result = Utils::SynchronousProcessResponse::StartFailed;
return response;
}
if (!(d->m_flags & VcsBasePlugin::SuppressCommandLogging))
emit outputProxy.appendCommand(d->m_workingDirectory, binary, arguments);
const bool sshPromptConfigured = !d->m_sshPasswordPrompt.isEmpty();
if (debugExecution) {
QDebug nsp = qDebug().nospace();
nsp << "Command::runVcs" << d->m_workingDirectory << binary << arguments
<< timeoutS;
if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow)
nsp << "stdout";
if (d->m_flags & VcsBasePlugin::SuppressStdErrInLogWindow)
nsp << "suppress_stderr";
if (d->m_flags & VcsBasePlugin::SuppressFailMessageInLogWindow)
nsp << "suppress_fail_msg";
if (d->m_flags & VcsBasePlugin::MergeOutputChannels)
nsp << "merge_channels";
if (d->m_flags & VcsBasePlugin::SshPasswordPrompt)
nsp << "ssh (" << sshPromptConfigured << ')';
if (d->m_flags & VcsBasePlugin::SuppressCommandLogging)
nsp << "suppress_log";
if (d->m_flags & VcsBasePlugin::ForceCLocale)
nsp << "c_locale";
if (d->m_flags & VcsBasePlugin::FullySynchronously)
nsp << "fully_synchronously";
if (d->m_flags & VcsBasePlugin::ExpectRepoChanges)
nsp << "expect_repo_changes";
if (d->m_codec)
nsp << " Codec: " << d->m_codec->name();
}
// TODO tell the document manager about expected repository changes
// if (d->m_flags & ExpectRepoChanges)
// Core::DocumentManager::expectDirectoryChange(d->m_workingDirectory);
if (d->m_flags & VcsBasePlugin::FullySynchronously) {
response = runSynchronous(binary, arguments, timeoutS, interpreter);
} else {
Utils::SynchronousProcess process;
process.setExitCodeInterpreter(interpreter);
connect(this, &VcsCommand::terminate, &process, &Utils::SynchronousProcess::terminate);
if (!d->m_workingDirectory.isEmpty())
process.setWorkingDirectory(d->m_workingDirectory);
QProcessEnvironment env = d->m_environment;
VcsBasePlugin::setProcessEnvironment(&env,
(d->m_flags & VcsBasePlugin::ForceCLocale),
d->m_sshPasswordPrompt);
process.setProcessEnvironment(env);
process.setTimeoutS(timeoutS);
if (d->m_codec)
process.setCodec(d->m_codec);
// Suppress terminal on UNIX for ssh prompts if it is configured.
if (sshPromptConfigured && (d->m_flags & VcsBasePlugin::SshPasswordPrompt))
process.setFlags(Utils::SynchronousProcess::UnixTerminalDisabled);
// connect stderr to the output window if desired
if (d->m_flags & VcsBasePlugin::MergeOutputChannels) {
process.setProcessChannelMode(QProcess::MergedChannels);
} else if (d->m_progressiveOutput
|| !(d->m_flags & VcsBasePlugin::SuppressStdErrInLogWindow)) {
process.setStdErrBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdErrBuffered,
this, &VcsCommand::bufferedError);
}
// connect stdout to the output window if desired
if (d->m_progressParser || d->m_progressiveOutput
|| (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow)) {
process.setStdOutBufferedSignalsEnabled(true);
connect(&process, &Utils::SynchronousProcess::stdOutBuffered,
this, &VcsCommand::bufferedOutput);
}
process.setTimeOutMessageBoxEnabled(true);
// Run!
response = process.run(binary.toString(), arguments);
}
if (!d->m_aborted) {
// Success/Fail message in appropriate window?
if (response.result == Utils::SynchronousProcessResponse::Finished) {
if (d->m_flags & VcsBasePlugin::ShowSuccessMessage)
emit outputProxy.appendMessage(response.exitMessage(binary.toUserOutput(), timeoutS));
} else if (!(d->m_flags & VcsBasePlugin::SuppressFailMessageInLogWindow)) {
emit outputProxy.appendError(response.exitMessage(binary.toUserOutput(), timeoutS));
}
}
emitRepositoryChanged(); emitRepositoryChanged();
return response; return response;
} }
Utils::SynchronousProcessResponse VcsCommand::runSynchronous(const Utils::FileName &binary,
const QStringList &arguments,
int timeoutS,
Utils::ExitCodeInterpreter *interpreter)
{
Utils::SynchronousProcessResponse response;
// Set up process
unsigned processFlags = 0;
if (!d->m_sshPasswordPrompt.isEmpty() && (d->m_flags & VcsBasePlugin::SshPasswordPrompt))
processFlags |= Utils::SynchronousProcess::UnixTerminalDisabled;
QSharedPointer<QProcess> process = Utils::SynchronousProcess::createProcess(processFlags);
if (!d->m_workingDirectory.isEmpty())
process->setWorkingDirectory(d->m_workingDirectory);
QProcessEnvironment env = d->m_environment;
VcsBasePlugin::setProcessEnvironment(&env,
(d->m_flags & VcsBasePlugin::ForceCLocale),
d->m_sshPasswordPrompt);
process->setProcessEnvironment(env);
if (d->m_flags & VcsBasePlugin::MergeOutputChannels)
process->setProcessChannelMode(QProcess::MergedChannels);
// Start
process->start(binary.toString(), arguments, QIODevice::ReadOnly);
process->closeWriteChannel();
if (!process->waitForStarted()) {
response.result = Utils::SynchronousProcessResponse::StartFailed;
return response;
}
// process output
QByteArray stdOut;
QByteArray stdErr;
const bool timedOut =
!Utils::SynchronousProcess::readDataFromProcess(*process.data(), timeoutS,
&stdOut, &stdErr, true);
if (!d->m_aborted) {
OutputProxy outputProxy;
if (!stdErr.isEmpty()) {
response.stdErr = Utils::SynchronousProcess::normalizeNewlines(
d->m_codec ? d->m_codec->toUnicode(stdErr) : QString::fromLocal8Bit(stdErr));
if (!(d->m_flags & VcsBasePlugin::SuppressStdErrInLogWindow))
emit outputProxy.append(response.stdErr);
}
if (!stdOut.isEmpty()) {
response.stdOut = Utils::SynchronousProcess::normalizeNewlines(
d->m_codec ? d->m_codec->toUnicode(stdOut) : QString::fromLocal8Bit(stdOut));
if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow) {
if (d->m_flags & VcsBasePlugin::SilentOutput)
emit outputProxy.appendSilently(response.stdOut);
else
emit outputProxy.append(response.stdOut);
}
}
}
Utils::ExitCodeInterpreter defaultInterpreter(this);
Utils::ExitCodeInterpreter *currentInterpreter = interpreter ? interpreter : &defaultInterpreter;
// Result
if (timedOut)
response.result = Utils::SynchronousProcessResponse::Hang;
else if (process->exitStatus() != QProcess::NormalExit)
response.result = Utils::SynchronousProcessResponse::TerminatedAbnormally;
else
response.result = currentInterpreter->interpretExitCode(process->exitCode());
return response;
}
void VcsCommand::emitRepositoryChanged()
{
if (d->m_preventRepositoryChanged || !(d->m_flags & VcsBasePlugin::ExpectRepoChanges))
return;
// TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
Core::VcsManager::emitRepositoryChanged(d->m_workingDirectory);
}
bool VcsCommand::runFullySynchronous(const Utils::FileName &binary, const QStringList &arguments, bool VcsCommand::runFullySynchronous(const Utils::FileName &binary, const QStringList &arguments,
int timeoutS, QByteArray *outputData, QByteArray *errorData) int timeoutS, QByteArray *outputData, QByteArray *errorData)
{ {
QTC_ASSERT(!binary.isEmpty(), return false); bool result = Core::ShellCommand::runFullySynchronous(binary, arguments, timeoutS,
outputData, errorData);
OutputProxy outputProxy;
if (!(d->m_flags & VcsBasePlugin::SuppressCommandLogging))
emit outputProxy.appendCommand(d->m_workingDirectory, binary, arguments);
// TODO tell the document manager about expected repository changes
// if (d->m_flags & ExpectRepoChanges)
// Core::DocumentManager::expectDirectoryChange(workingDirectory);
QProcess process;
process.setWorkingDirectory(d->m_workingDirectory);
process.setProcessEnvironment(d->m_environment);
process.start(binary.toString(), arguments);
process.closeWriteChannel();
if (!process.waitForStarted()) {
if (errorData) {
const QString msg = QString::fromLatin1("Unable to execute \"%1\": %2:")
.arg(binary.toUserOutput(), process.errorString());
*errorData = msg.toLocal8Bit();
}
return false;
}
if (!Utils::SynchronousProcess::readDataFromProcess(process, timeoutS, outputData, errorData, true)) {
if (errorData)
errorData->append(tr("Error: Executable timed out after %1 s.").arg(timeoutS).toLocal8Bit());
Utils::SynchronousProcess::stopProcess(process);
return false;
}
emitRepositoryChanged(); emitRepositoryChanged();
return process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0; return result;
} }
void VcsCommand::bufferedOutput(const QString &text) void VcsCommand::emitRepositoryChanged()
{ {
if (d->m_progressParser) if (m_preventRepositoryChanged || !(flags() & VcsCommand::ExpectRepoChanges))
d->m_progressParser->parseProgress(text); return;
if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow) // TODO tell the document manager that the directory now received all expected changes
VcsOutputWindow::append(text); // Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
if (d->m_progressiveOutput) { Core::VcsManager::emitRepositoryChanged(workingDirectory());
emit output(text);
d->m_hadOutput = true;
}
} }
void VcsCommand::bufferedError(const QString &text) unsigned VcsCommand::processFlags() const
{ {
if (!(d->m_flags & VcsBasePlugin::SuppressStdErrInLogWindow)) unsigned processFlags = 0;
VcsOutputWindow::appendError(text); if (!VcsBasePlugin::sshPrompt().isEmpty() && (flags() & SshPasswordPrompt))
if (d->m_progressiveOutput) processFlags |= Utils::SynchronousProcess::UnixTerminalDisabled;
emit errorText(text); return processFlags;
} }
void VcsCommand::coreAboutToClose() void VcsCommand::coreAboutToClose()
{ {
d->m_preventRepositoryChanged = true; m_preventRepositoryChanged = true;
abort(); abort();
} }
const QVariant &VcsCommand::cookie() const
{
return d->m_cookie;
}
void VcsCommand::setCookie(const QVariant &cookie)
{
d->m_cookie = cookie;
}
QTextCodec *VcsCommand::codec() const
{
return d->m_codec;
}
void VcsCommand::setCodec(QTextCodec *codec)
{
d->m_codec = codec;
}
//! Use \a parser to parse progress data from stdout. Command takes ownership of \a parser
void VcsCommand::setProgressParser(ProgressParser *parser)
{
QTC_ASSERT(!d->m_progressParser, return);
d->m_progressParser = parser;
}
void VcsCommand::setProgressiveOutput(bool progressive)
{
d->m_progressiveOutput = progressive;
}
ProgressParser::ProgressParser() :
m_future(0),
m_futureMutex(new QMutex)
{
}
ProgressParser::~ProgressParser()
{
delete m_futureMutex;
}
void ProgressParser::setProgressAndMaximum(int value, int maximum)
{
QMutexLocker lock(m_futureMutex);
if (!m_future)
return;
m_future->setProgressRange(0, maximum);
m_future->setProgressValue(value);
}
void ProgressParser::setFuture(QFutureInterface<void> *future)
{
QMutexLocker lock(m_futureMutex);
m_future = future;
}
} // namespace VcsBase } // namespace VcsBase
#include "vcscommand.moc"
+15 -92
View File
@@ -33,114 +33,37 @@
#include "vcsbase_global.h" #include "vcsbase_global.h"
#include <QObject> #include <coreplugin/shellcommand.h>
QT_BEGIN_NAMESPACE
class QMutex;
class QStringList;
class QVariant;
class QProcessEnvironment;
template <typename T>
class QFutureInterface;
QT_END_NAMESPACE
namespace Utils {
struct SynchronousProcessResponse;
class ExitCodeInterpreter;
class FileName;
}
namespace VcsBase { namespace VcsBase {
namespace Internal { class VcsCommandPrivate; } class VCSBASE_EXPORT VcsCommand : public Core::ShellCommand
class VCSBASE_EXPORT ProgressParser
{
public:
ProgressParser();
virtual ~ProgressParser();
protected:
virtual void parseProgress(const QString &text) = 0;
void setProgressAndMaximum(int value, int maximum);
private:
void setFuture(QFutureInterface<void> *future);
QFutureInterface<void> *m_future;
QMutex *m_futureMutex;
friend class VcsCommand;
};
class VCSBASE_EXPORT VcsCommand : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
VcsCommand(const QString &workingDirectory, enum VcsRunFlags {
const QProcessEnvironment &environment); SshPasswordPrompt = 0x1000, // Disable terminal on UNIX to force graphical prompt.
~VcsCommand(); ExpectRepoChanges = 0x2000, // Expect changes in repository by the command
};
QString displayName() const; VcsCommand(const QString &workingDirectory, const QProcessEnvironment &environment);
void setDisplayName(const QString &name);
void addJob(const Utils::FileName &binary, const QStringList &arguments, Utils::ExitCodeInterpreter *interpreter = 0); const QProcessEnvironment processEnvironment() const;
void addJob(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter = 0);
void execute();
void abort();
bool lastExecutionSuccess() const;
int lastExecutionExitCode() const;
const QString &workingDirectory() const; Utils::SynchronousProcessResponse runCommand(const Utils::FileName &binary,
const QProcessEnvironment &processEnvironment() const; const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter = 0);
int defaultTimeoutS() const;
void setDefaultTimeoutS(int timeout);
unsigned flags() const;
void addFlags(unsigned f);
const QVariant &cookie() const;
void setCookie(const QVariant &cookie);
QTextCodec *codec() const;
void setCodec(QTextCodec *codec);
void setProgressParser(ProgressParser *parser);
void setProgressiveOutput(bool progressive);
Utils::SynchronousProcessResponse runVcs(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter = 0);
// Make sure to not pass through the event loop at all:
bool runFullySynchronous(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
QByteArray *outputData, QByteArray *errorData);
bool runFullySynchronous(const Utils::FileName &binary, const QStringList &arguments,
int timeoutS, QByteArray *outputData, QByteArray *errorData);
private: private:
void run(QFutureInterface<void> &future); unsigned processFlags() const;
Utils::SynchronousProcessResponse runSynchronous(const Utils::FileName &binary, const QStringList &arguments, int timeoutS,
Utils::ExitCodeInterpreter *interpreter = 0);
void emitRepositoryChanged(); void emitRepositoryChanged();
public slots:
void cancel();
signals:
void output(const QString &);
void errorText(const QString &);
void finished(bool ok, int exitCode, const QVariant &cookie);
void success(const QVariant &cookie);
private slots:
void bufferedOutput(const QString &text);
void bufferedError(const QString &text);
void coreAboutToClose(); void coreAboutToClose();
signals: bool m_preventRepositoryChanged;
void terminate(); // Internal
private:
class Internal::VcsCommandPrivate *const d;
}; };
} // namespace VcsBase } // namespace VcsBase