Commit 7c083ead authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Vcs: Make VcsBaseClient return stderr on fullySynchronous execution



Change-Id: I7a72a2f865148d7cf375897ec944a45f4b440818
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 60f5372b
......@@ -540,24 +540,6 @@ IEditor *locateEditor(const char *property, const QString &entry)
return 0;
}
// Return converted command output, remove '\r' read on Windows
static inline QString commandOutputFromLocal8Bit(const QByteArray &a)
{
return SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(a));
}
// Return converted command output split into lines
static inline QStringList commandOutputLinesFromLocal8Bit(const QByteArray &a)
{
QString output = commandOutputFromLocal8Bit(a);
const QChar newLine = QLatin1Char('\n');
if (output.endsWith(newLine))
output.truncate(output.size() - 1);
if (output.isEmpty())
return QStringList();
return output.split(newLine);
}
static inline QString msgRepositoryNotFound(const QString &dir)
{
return GitClient::tr("Cannot determine the repository for \"%1\".").arg(dir);
......@@ -594,7 +576,7 @@ static inline void msgCannotRun(const QStringList &args, const QString &workingD
const QString message = GitClient::tr("Cannot run \"%1 %2\" in \"%2\": %3")
.arg(QLatin1String("git ") + args.join(QLatin1Char(' ')),
QDir::toNativeSeparators(workingDirectory),
commandOutputFromLocal8Bit(error));
GitClient::commandOutputFromLocal8Bit(error));
msgCannotRun(message, errorMessage);
}
......
......@@ -244,7 +244,7 @@ QString MercurialClient::shortDescriptionSync(const QString &workingDirectory,
QByteArray outputData;
if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
return revision;
description = SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(outputData));
description = commandOutputFromLocal8Bit(outputData);
if (description.endsWith(QLatin1Char('\n')))
description.truncate(description.size() - 1);
return description;
......
......@@ -150,7 +150,7 @@ QString SubversionClient::synchronousTopic(const QString &repository)
const QString revisionString = QLatin1String("Revision: ");
// stdOut is ASCII only (at least in those areas we care about).
QString output = SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(stdOut));
QString output = commandOutputFromLocal8Bit(stdOut);
foreach (const QString &line, output.split(QLatin1Char('\n'))) {
if (line.startsWith(revisionString))
return QString::fromLatin1("r") + line.mid(revisionString.count());
......
......@@ -170,6 +170,22 @@ QProcessEnvironment VcsBaseClientImpl::processEnvironment() const
return environment;
}
QString VcsBaseClientImpl::commandOutputFromLocal8Bit(const QByteArray &a)
{
return Utils::SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(a));
}
QStringList VcsBaseClientImpl::commandOutputLinesFromLocal8Bit(const QByteArray &a)
{
QString output = commandOutputFromLocal8Bit(a);
const QChar newLine = QLatin1Char('\n');
if (output.endsWith(newLine))
output.truncate(output.size() - 1);
if (output.isEmpty())
return QStringList();
return output.split(newLine);
}
void VcsBaseClientImpl::resetCachedVcsInfo(const QString &workingDir)
{
Core::VcsManager::resetVersionControlForDirectory(workingDir);
......@@ -288,8 +304,7 @@ bool VcsBaseClient::synchronousCreateRepository(const QString &workingDirectory,
QByteArray outputData;
if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
return false;
VcsOutputWindow::append(
Utils::SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(outputData)));
VcsOutputWindow::append(commandOutputFromLocal8Bit(outputData));
resetCachedVcsInfo(workingDirectory);
......@@ -373,13 +388,15 @@ bool VcsBaseClient::synchronousPush(const QString &workingDir,
bool VcsBaseClient::vcsFullySynchronousExec(const QString &workingDir,
const QStringList &args,
QByteArray *output) const
{
QByteArray errorData;
QScopedPointer<VcsCommand> command = createCommand(workingDir);
bool result = command->runFullySynchronous(args, vcsTimeoutS(), output, &errorData);
if (!errorData.isEmpty())
VcsOutputWindow::appendError(QString::fromLocal8Bit(errorData));
QByteArray *outputData,
QByteArray *errorData) const
{
QByteArray internalErrorData;
QScopedPointer<VcsCommand> command(createCommand(workingDir));
bool result = command->runFullySynchronous(args, vcsTimeoutS(), outputData,
errorData ? errorData : &internalErrorData);
if (!internalErrorData.isEmpty())
VcsOutputWindow::appendError(commandOutputFromLocal8Bit(internalErrorData));
return result;
}
......
......@@ -100,6 +100,11 @@ public:
const QString &revision = QString(), int lineNumber = -1,
const QStringList &extraOptions = QStringList()) = 0;
// Return converted command output, remove '\r' read on Windows
static QString commandOutputFromLocal8Bit(const QByteArray &a);
// Return converted command output split into lines
static QStringList commandOutputLinesFromLocal8Bit(const QByteArray &a);
protected:
void resetCachedVcsInfo(const QString &workingDir);
virtual void annotateRevisionRequested(const QString &workingDirectory, const QString &file,
......@@ -217,7 +222,7 @@ protected:
QString vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const;
// Fully synchronous VCS execution (QProcess-based)
bool vcsFullySynchronousExec(const QString &workingDir, const QStringList &args,
QByteArray *output) const;
QByteArray *outputData, QByteArray *errorData = 0) const;
// Synchronous VCS execution using Utils::SynchronousProcess, with
// log windows updating (using VcsBasePlugin::runVcs with flags)
Utils::SynchronousProcessResponse vcsSynchronousExec(const QString &workingDir,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment