Utils: Don't expose Utils::defaultExitCodeInterpreter

Instead, make its behavior implicit if none is given.

Change-Id: I3c1a054751a0afe22d0f40a2fed6dd00b5aef205
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-05-06 15:54:02 +02:00
parent ad5b34ab3e
commit 0c8d8c6b2a
8 changed files with 25 additions and 23 deletions

View File

@@ -112,6 +112,8 @@ public:
void slotError(QProcess::ProcessError);
void clearForRun();
SynchronousProcessResponse::Result interpretExitCode(int exitCode);
QtcProcess *q;
QTextCodec *m_codec = QTextCodec::codecForLocale();
QTimer m_timer;
@@ -120,7 +122,7 @@ public:
FilePath m_binary;
ChannelBuffer m_stdOut;
ChannelBuffer m_stdErr;
ExitCodeInterpreter m_exitCodeInterpreter = defaultExitCodeInterpreter;
ExitCodeInterpreter m_exitCodeInterpreter;
int m_hangTimerCount = 0;
int m_maxHangTimerCount = defaultMaxHangTimerCount;
@@ -142,6 +144,16 @@ void QtcProcessPrivate::clearForRun()
m_binary = {};
}
SynchronousProcessResponse::Result QtcProcessPrivate::interpretExitCode(int exitCode)
{
if (m_exitCodeInterpreter)
return m_exitCodeInterpreter(exitCode);
// default:
return exitCode ? SynchronousProcessResponse::FinishedError
: SynchronousProcessResponse::Finished;
}
} // Internal
/*!
@@ -633,12 +645,6 @@ QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const SynchronousProcessRes
return str;
}
SynchronousProcessResponse::Result defaultExitCodeInterpreter(int code)
{
return code ? SynchronousProcessResponse::FinishedError
: SynchronousProcessResponse::Finished;
}
void ChannelBuffer::clearForRun()
{
rawDataPos = 0;
@@ -732,7 +738,6 @@ void QtcProcess::setTimeOutMessageBoxEnabled(bool v)
void QtcProcess::setExitCodeInterpreter(const ExitCodeInterpreter &interpreter)
{
QTC_ASSERT(interpreter, return);
d->m_exitCodeInterpreter = interpreter;
}
@@ -867,7 +872,7 @@ SynchronousProcessResponse QtcProcess::runBlocking(const CommandLine &cmd)
if (exitStatus() != QProcess::NormalExit)
d->m_result.result = SynchronousProcessResponse::TerminatedAbnormally;
else
d->m_result.result = d->m_exitCodeInterpreter(d->m_result.exitCode);
d->m_result.result = d->interpretExitCode(d->m_result.exitCode);
}
d->m_stdOut.append(readAllStandardOutput(), false);
d->m_stdErr.append(readAllStandardError(), false);
@@ -916,7 +921,7 @@ void QtcProcessPrivate::slotFinished(int exitCode, QProcess::ExitStatus e)
switch (e) {
case QProcess::NormalExit:
m_result.result = m_exitCodeInterpreter(exitCode);
m_result.result = interpretExitCode(exitCode);
m_result.exitCode = exitCode;
break;
case QProcess::CrashExit:

View File

@@ -147,8 +147,6 @@ private:
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const SynchronousProcessResponse &);
QTCREATOR_UTILS_EXPORT SynchronousProcessResponse::Result defaultExitCodeInterpreter(int code);
class QTCREATOR_UTILS_EXPORT SynchronousProcess : public QtcProcess
{
Q_OBJECT

View File

@@ -108,10 +108,10 @@ public:
void addJob(const CommandLine &command,
const QString &workingDirectory = QString(),
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
const ExitCodeInterpreter &interpreter = {});
void addJob(const CommandLine &command, int timeoutS,
const QString &workingDirectory = QString(),
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
const ExitCodeInterpreter &interpreter = {});
void execute(); // Execute tasks asynchronously!
void abort();
bool lastExecutionSuccess() const;
@@ -145,7 +145,7 @@ public:
virtual SynchronousProcessResponse runCommand(const CommandLine &command,
int timeoutS,
const QString &workingDirectory = QString(),
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
const ExitCodeInterpreter &interpreter = {});
void cancel();
@@ -170,12 +170,12 @@ private:
SynchronousProcessResponse runFullySynchronous(const CommandLine &cmd,
QSharedPointer<OutputProxy> proxy,
int timeoutS, const QString &workingDirectory,
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
const ExitCodeInterpreter &interpreter = {});
// Run with an event loop. Signals will be delivered.
SynchronousProcessResponse runSynchronous(const CommandLine &cmd,
QSharedPointer<OutputProxy> proxy,
int timeoutS, const QString &workingDirectory,
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
const ExitCodeInterpreter &interpreter = {});
class Internal::ShellCommandPrivate *const d;
};

View File

@@ -235,7 +235,7 @@ ExitCodeInterpreter BazaarClient::exitCodeInterpreter(VcsCommandTag cmd) const
: SynchronousProcessResponse::Finished;
};
}
return Utils::defaultExitCodeInterpreter;
return {};
}
QStringList BazaarClient::revisionSpec(const QString &revision) const

View File

@@ -208,7 +208,7 @@ public:
: SynchronousProcessResponse::Finished;
};
}
return Utils::defaultExitCodeInterpreter;
return {};
}
Utils::Id vcsEditorKind(VcsCommandTag cmd) const override

View File

@@ -518,7 +518,7 @@ QString VcsBaseClient::vcsCommandString(VcsCommandTag cmd) const
ExitCodeInterpreter VcsBaseClient::exitCodeInterpreter(VcsCommandTag cmd) const
{
Q_UNUSED(cmd)
return Utils::defaultExitCodeInterpreter;
return {};
}
void VcsBaseClient::setDiffConfigCreator(ConfigCreator creator)

View File

@@ -41,7 +41,6 @@
QT_BEGIN_NAMESPACE
class QFileInfo;
class QProcessEnvironment;
class QToolBar;
QT_END_NAMESPACE
@@ -82,7 +81,7 @@ public:
void enqueueJob(VcsCommand *cmd, const QStringList &args,
const QString &workingDirectory = QString(),
const Utils::ExitCodeInterpreter &interpreter = Utils::defaultExitCodeInterpreter) const;
const Utils::ExitCodeInterpreter &interpreter = {}) const;
virtual Utils::Environment processEnvironment() const;

View File

@@ -48,7 +48,7 @@ public:
Utils::SynchronousProcessResponse runCommand(const Utils::CommandLine &command,
int timeoutS,
const QString &workDirectory = QString(),
const Utils::ExitCodeInterpreter &interpreter = Utils::defaultExitCodeInterpreter) override;
const Utils::ExitCodeInterpreter &interpreter = {}) override;
private:
void emitRepositoryChanged(const QString &workingDirectory);