Process: Change signature of exitMessage()

Change the last arg to std::chrono::milliseconds type.

Change-Id: Ifb818f76ee33e03997cb5b1dd17336248f401238
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-22 17:46:37 +01:00
parent afc67468e6
commit e98f6e31e7
3 changed files with 12 additions and 13 deletions

View File

@@ -1647,8 +1647,8 @@ QString Process::readAllStandardError()
return QString::fromUtf8(readAllRawStandardError()); return QString::fromUtf8(readAllRawStandardError());
} }
QString Process::exitMessage(const CommandLine &command, ProcessResult result, int exitCode, QString Process::exitMessage(const CommandLine &command, ProcessResult result,
int timeoutInSeconds) int exitCode, milliseconds duration)
{ {
const QString cmd = command.toUserOutput(); const QString cmd = command.toUserOutput();
switch (result) { switch (result) {
@@ -1661,16 +1661,17 @@ QString Process::exitMessage(const CommandLine &command, ProcessResult result, i
case ProcessResult::StartFailed: case ProcessResult::StartFailed:
return Tr::tr("The command \"%1\" could not be started.").arg(cmd); return Tr::tr("The command \"%1\" could not be started.").arg(cmd);
case ProcessResult::Canceled: case ProcessResult::Canceled:
return Tr::tr("The command \"%1\" was canceled after (%2 s).") // TODO: We might want to format it nicely when bigger than 1 second, e.g. 1,324 s.
.arg(cmd).arg(timeoutInSeconds); // Also when it's bigger than 1 minute, 1 hour, etc...
return Tr::tr("The command \"%1\" was canceled after (%2 ms).")
.arg(cmd).arg(duration.count());
} }
return {}; return {};
} }
QString Process::exitMessage() const QString Process::exitMessage() const
{ {
return exitMessage(commandLine(), result(), exitCode(), return exitMessage(commandLine(), result(), exitCode(), processDuration());
duration_cast<seconds>(processDuration()).count());
} }
milliseconds Process::processDuration() const milliseconds Process::processDuration() const

View File

@@ -180,7 +180,7 @@ public:
const QStringList stdErrLines() const; // split, CR removed const QStringList stdErrLines() const; // split, CR removed
static QString exitMessage(const CommandLine &command, ProcessResult result, int exitCode, static QString exitMessage(const CommandLine &command, ProcessResult result, int exitCode,
int timeoutInSeconds); std::chrono::milliseconds duration);
QString exitMessage() const; QString exitMessage() const;
std::chrono::milliseconds processDuration() const; std::chrono::milliseconds processDuration() const;

View File

@@ -154,22 +154,20 @@ EventLoopMode VcsCommandPrivate::eventLoopMode() const
ProcessResult VcsCommandPrivate::handleDone(Process *process, const Job &job) const ProcessResult VcsCommandPrivate::handleDone(Process *process, const Job &job) const
{ {
ProcessResult result; ProcessResult result;
QString exitMessage;
if (job.exitCodeInterpreter && process->error() != QProcess::FailedToStart if (job.exitCodeInterpreter && process->error() != QProcess::FailedToStart
&& process->exitStatus() == QProcess::NormalExit) { && process->exitStatus() == QProcess::NormalExit) {
result = job.exitCodeInterpreter(process->exitCode()); result = job.exitCodeInterpreter(process->exitCode());
exitMessage = Process::exitMessage(process->commandLine(), m_result,
process->exitCode(), job.timeoutS);
} else { } else {
result = process->result(); result = process->result();
exitMessage = process->exitMessage();
} }
const QString message = Process::exitMessage(process->commandLine(), result,
process->exitCode(), process->processDuration());
// Success/Fail message in appropriate window? // Success/Fail message in appropriate window?
if (result == ProcessResult::FinishedWithSuccess) { if (result == ProcessResult::FinishedWithSuccess) {
if (m_flags & RunFlags::ShowSuccessMessage) if (m_flags & RunFlags::ShowSuccessMessage)
VcsOutputWindow::appendMessage(exitMessage); VcsOutputWindow::appendMessage(message);
} else if (!(m_flags & RunFlags::SuppressFailMessage)) { } else if (!(m_flags & RunFlags::SuppressFailMessage)) {
VcsOutputWindow::appendError(exitMessage); VcsOutputWindow::appendError(message);
} }
if (m_flags & RunFlags::ExpectRepoChanges) { if (m_flags & RunFlags::ExpectRepoChanges) {
// TODO tell the document manager that the directory now received all expected changes // TODO tell the document manager that the directory now received all expected changes