VcsBase: Move RunFlags into separate header

It is going to be used outside of VcsCommand, too.
Use RunFlags enum as an argument to several functions
instead of unsigned.

Change-Id: I355c80a845a9b5982108fbde3412754392dce702
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-10-05 19:08:53 +02:00
parent 3811236903
commit eec0679234
20 changed files with 196 additions and 159 deletions

View File

@@ -26,6 +26,7 @@ add_qtc_plugin(VcsBase
vcsbaseplugin.cpp vcsbaseplugin.h
vcsbasesubmiteditor.cpp vcsbasesubmiteditor.h
vcscommand.cpp vcscommand.h
vcsenums.h
vcsoutputformatter.cpp vcsoutputformatter.h
vcsoutputwindow.cpp vcsoutputwindow.h
vcsplugin.cpp vcsplugin.h

View File

@@ -60,6 +60,7 @@ QtcPlugin {
"vcsbasesubmiteditor.h",
"vcscommand.cpp",
"vcscommand.h",
"vcsenums.h",
"vcsoutputformatter.cpp",
"vcsoutputformatter.h",
"vcsoutputwindow.cpp",

View File

@@ -79,9 +79,9 @@ VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
if (editor)
editor->setCommand(cmd);
if (mode == VcsWindowOutputBind) {
cmd->addFlags(VcsCommand::ShowStdOut);
cmd->addFlags(RunFlags::ShowStdOut);
if (editor) // assume that the commands output is the important thing
cmd->addFlags(VcsCommand::SilentOutput);
cmd->addFlags(RunFlags::SilentOutput);
} else if (editor) {
connect(cmd, &VcsCommand::done, editor, [editor, cmd] {
if (cmd->result() != ProcessResult::FinishedWithSuccess) {
@@ -129,13 +129,13 @@ QString VcsBaseClientImpl::stripLastNewline(const QString &in)
}
CommandResult VcsBaseClientImpl::vcsSynchronousExec(const FilePath &workingDir,
const QStringList &args, unsigned flags, int timeoutS, QTextCodec *codec) const
const QStringList &args, RunFlags flags, int timeoutS, QTextCodec *codec) const
{
return vcsSynchronousExec(workingDir, {vcsBinary(), args}, flags, timeoutS, codec);
}
CommandResult VcsBaseClientImpl::vcsSynchronousExec(const FilePath &workingDir,
const CommandLine &cmdLine, unsigned flags, int timeoutS, QTextCodec *codec) const
const CommandLine &cmdLine, RunFlags flags, int timeoutS, QTextCodec *codec) const
{
return VcsCommand::runBlocking(workingDir, processEnvironment(), cmdLine, flags,
timeoutS > 0 ? timeoutS : vcsTimeoutS(), codec);
@@ -162,7 +162,7 @@ void VcsBaseClientImpl::annotateRevisionRequested(const FilePath &workingDirecto
VcsCommand *VcsBaseClientImpl::vcsExec(const FilePath &workingDirectory,
const QStringList &arguments,
VcsBaseEditorWidget *editor, bool useOutputToWindow,
unsigned additionalFlags) const
RunFlags additionalFlags) const
{
VcsCommand *command = createCommand(workingDirectory, editor,
useOutputToWindow ? VcsWindowOutputBind : NoOutputBind);
@@ -288,7 +288,7 @@ bool VcsBaseClient::synchronousPull(const FilePath &workingDir,
{
QStringList args;
args << vcsCommandString(PullCommand) << extraOptions << srcLocation;
const unsigned flags = VcsCommand::ShowStdOut | VcsCommand::ShowSuccessMessage;
const RunFlags flags = RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage;
const bool ok = vcsSynchronousExec(workingDir, args, flags).result()
== ProcessResult::FinishedWithSuccess;
if (ok)
@@ -302,7 +302,7 @@ bool VcsBaseClient::synchronousPush(const FilePath &workingDir,
{
QStringList args;
args << vcsCommandString(PushCommand) << extraOptions << dstLocation;
const unsigned flags = VcsCommand::ShowStdOut | VcsCommand::ShowSuccessMessage;
const RunFlags flags = RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage;
return vcsSynchronousExec(workingDir, args, flags).result()
== ProcessResult::FinishedWithSuccess;
}

View File

@@ -4,6 +4,7 @@
#pragma once
#include "vcsbase_global.h"
#include "vcsenums.h"
#include "vcsbaseclientsettings.h"
@@ -77,10 +78,11 @@ public:
// Fully synchronous VCS execution (QProcess-based)
CommandResult vcsSynchronousExec(const Utils::FilePath &workingDir,
const QStringList &args, unsigned flags = 0,
const QStringList &args, RunFlags flags = RunFlags::None,
int timeoutS = -1, QTextCodec *codec = nullptr) const;
CommandResult vcsSynchronousExec(const Utils::FilePath &workingDir,
const Utils::CommandLine &cmdLine, unsigned flags = 0,
const Utils::CommandLine &cmdLine,
RunFlags flags = RunFlags::None,
int timeoutS = -1, QTextCodec *codec = nullptr) const;
// Simple helper to execute a single command using createCommand and enqueueJob.
@@ -88,7 +90,7 @@ public:
const QStringList &arguments,
VcsBaseEditorWidget *editor = nullptr,
bool useOutputToWindow = false,
unsigned additionalFlags = 0) const;
RunFlags additionalFlags = RunFlags::None) const;
protected:
void resetCachedVcsInfo(const Utils::FilePath &workingDir);

View File

@@ -134,7 +134,7 @@ VcsBaseDiffEditorController::~VcsBaseDiffEditorController()
delete d;
}
void VcsBaseDiffEditorController::runCommand(const QList<QStringList> &args, unsigned flags, QTextCodec *codec)
void VcsBaseDiffEditorController::runCommand(const QList<QStringList> &args, RunFlags flags, QTextCodec *codec)
{
// Cancel the possible ongoing reload without the commandFinished() nor
// processingFinished() notifications, as right after that

View File

@@ -4,6 +4,7 @@
#pragma once
#include "vcsbase_global.h"
#include "vcsenums.h"
#include <diffeditor/diffeditorcontroller.h>
@@ -36,7 +37,7 @@ public:
void setWorkingDirectory(const Utils::FilePath &workingDir);
protected:
void runCommand(const QList<QStringList> &args, unsigned flags, QTextCodec *codec = nullptr);
void runCommand(const QList<QStringList> &args, RunFlags flags, QTextCodec *codec = nullptr);
virtual void processCommandOutput(const QString &output);
Utils::FilePath workingDirectory() const;

View File

@@ -71,7 +71,7 @@ public:
Environment environment()
{
if (!(m_flags & VcsCommand::ForceCLocale))
if (!(m_flags & RunFlags::ForceCLocale))
return m_environment;
m_environment.set("LANG", "C");
@@ -109,7 +109,7 @@ public:
ProcessResult m_result = ProcessResult::StartFailed;
QFutureInterface<void> m_futureInterface;
unsigned m_flags = 0;
RunFlags m_flags = RunFlags::None;
bool m_progressiveOutput = false;
};
@@ -140,7 +140,7 @@ int VcsCommandPrivate::timeoutS() const
void VcsCommandPrivate::setup()
{
m_futureInterface.reportStarted();
if (m_flags & VcsCommand::ExpectRepoChanges) {
if (m_flags & RunFlags::ExpectRepoChanges) {
QMetaObject::invokeMethod(GlobalFileChangeBlocker::instance(), [] {
GlobalFileChangeBlocker::instance()->forceBlocked(true);
});
@@ -153,7 +153,7 @@ void VcsCommandPrivate::cleanup()
{
QTC_ASSERT(m_futureInterface.isRunning(), return);
m_futureInterface.reportFinished();
if (m_flags & VcsCommand::ExpectRepoChanges) {
if (m_flags & RunFlags::ExpectRepoChanges) {
QMetaObject::invokeMethod(GlobalFileChangeBlocker::instance(), [] {
GlobalFileChangeBlocker::instance()->forceBlocked(false);
});
@@ -169,12 +169,12 @@ void VcsCommandPrivate::setupProcess(QtcProcess *process, const Job &job)
process->setTimeoutS(job.timeoutS);
if (!job.workingDirectory.isEmpty())
process->setWorkingDirectory(job.workingDirectory);
if (!(m_flags & VcsCommand::SuppressCommandLogging))
if (!(m_flags & RunFlags::SuppressCommandLogging))
emit q->appendCommand(job.workingDirectory, job.command);
process->setCommand(job.command);
process->setDisableUnixTerminal();
process->setEnvironment(environment());
if (m_flags & VcsCommand::MergeOutputChannels)
if (m_flags & RunFlags::MergeOutputChannels)
process->setProcessChannelMode(QProcess::MergedChannels);
if (m_codec)
process->setCodec(m_codec);
@@ -184,24 +184,24 @@ void VcsCommandPrivate::setupProcess(QtcProcess *process, const Job &job)
void VcsCommandPrivate::installStdCallbacks(QtcProcess *process)
{
if (!(m_flags & VcsCommand::MergeOutputChannels)
&& (m_progressiveOutput || !(m_flags & VcsCommand::SuppressStdErr))) {
if (!(m_flags & RunFlags::MergeOutputChannels)
&& (m_progressiveOutput || !(m_flags & RunFlags::SuppressStdErr))) {
process->setStdErrCallback([this](const QString &text) {
if (m_progressParser)
m_progressParser->parseProgress(text);
if (!(m_flags & VcsCommand::SuppressStdErr))
if (!(m_flags & RunFlags::SuppressStdErr))
emit q->appendError(text);
if (m_progressiveOutput)
emit q->stdErrText(text);
});
}
// connect stdout to the output window if desired
if (m_progressParser || m_progressiveOutput || (m_flags & VcsCommand::ShowStdOut)) {
if (m_progressParser || m_progressiveOutput || (m_flags & RunFlags::ShowStdOut)) {
process->setStdOutCallback([this](const QString &text) {
if (m_progressParser)
m_progressParser->parseProgress(text);
if (m_flags & VcsCommand::ShowStdOut) {
if (m_flags & VcsCommand::SilentOutput)
if (m_flags & RunFlags::ShowStdOut) {
if (m_flags & RunFlags::SilentOutput)
emit q->appendSilently(text);
else
emit q->append(text);
@@ -216,7 +216,7 @@ void VcsCommandPrivate::installStdCallbacks(QtcProcess *process)
EventLoopMode VcsCommandPrivate::eventLoopMode() const
{
if ((m_flags & VcsCommand::UseEventLoop) && QThread::currentThread() == qApp->thread())
if ((m_flags & RunFlags::UseEventLoop) && QThread::currentThread() == qApp->thread())
return EventLoopMode::On;
return EventLoopMode::Off;
}
@@ -225,9 +225,9 @@ void VcsCommandPrivate::handleDone(QtcProcess *process)
{
// Success/Fail message in appropriate window?
if (process->result() == ProcessResult::FinishedWithSuccess) {
if (m_flags & VcsCommand::ShowSuccessMessage)
if (m_flags & RunFlags::ShowSuccessMessage)
emit q->appendMessage(process->exitMessage());
} else if (!(m_flags & VcsCommand::SuppressFailMessage)) {
} else if (!(m_flags & RunFlags::SuppressFailMessage)) {
emit q->appendError(process->exitMessage());
}
emit q->runCommandFinished(process->workingDirectory());
@@ -303,7 +303,7 @@ VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &envi
void VcsCommand::postRunCommand(const FilePath &workingDirectory)
{
if (!(d->m_flags & VcsCommand::ExpectRepoChanges))
if (!(d->m_flags & RunFlags::ExpectRepoChanges))
return;
// TODO tell the document manager that the directory now received all expected changes
// Core::DocumentManager::unexpectDirectoryChange(d->m_workingDirectory);
@@ -324,7 +324,7 @@ void VcsCommand::setDisplayName(const QString &name)
d->m_displayName = name;
}
void VcsCommand::addFlags(unsigned f)
void VcsCommand::addFlags(RunFlags f)
{
d->m_flags |= f;
}
@@ -345,7 +345,7 @@ void VcsCommand::start()
d->startAll();
d->m_watcher.setFuture(d->m_futureInterface.future());
if ((d->m_flags & VcsCommand::SuppressCommandLogging))
if ((d->m_flags & RunFlags::SuppressCommandLogging))
return;
const QString name = d->displayName();
@@ -385,7 +385,7 @@ ProcessResult VcsCommand::result() const
CommandResult VcsCommand::runBlocking(const Utils::FilePath &workingDirectory,
const Utils::Environment &environment,
const Utils::CommandLine &command, unsigned flags,
const Utils::CommandLine &command, RunFlags flags,
int timeoutS, QTextCodec *codec)
{
VcsCommand vcsCommand(workingDirectory, environment);

View File

@@ -4,6 +4,7 @@
#pragma once
#include "vcsbase_global.h"
#include "vcsenums.h"
#include <utils/filepath.h>
#include <utils/processenums.h>
@@ -81,21 +82,6 @@ class VCSBASE_EXPORT VcsCommand final : 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.
SilentOutput = 0x80, // Suppress user notifications about the output happening.
UseEventLoop = 0x100, // Use event loop when executed in UI thread.
ExpectRepoChanges = 0x200, // Expect changes in repository by the command
NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging
};
VcsCommand(const Utils::FilePath &workingDirectory, const Utils::Environment &environment);
~VcsCommand() override;
@@ -106,7 +92,7 @@ public:
const Utils::ExitCodeInterpreter &interpreter = {});
void start();
void addFlags(unsigned f);
void addFlags(RunFlags f);
void setCodec(QTextCodec *codec);
@@ -115,7 +101,7 @@ public:
static CommandResult runBlocking(const Utils::FilePath &workingDirectory,
const Utils::Environment &environmentconst,
const Utils::CommandLine &command, unsigned flags,
const Utils::CommandLine &command, RunFlags flags,
int timeoutS, QTextCodec *codec);
void cancel();

View File

@@ -0,0 +1,47 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "vcsbase_global.h"
namespace VcsBase {
enum class RunFlags {
None = 0, // Empty
ShowStdOut = (1 << 0), // Show standard output.
MergeOutputChannels = (1 << 1), // See QProcess: Merge stderr/stdout.
SuppressStdErr = (1 << 2), // Suppress standard error output.
SuppressFailMessage = (1 << 3), // No message about command failure.
SuppressCommandLogging = (1 << 4), // No command log entry.
ShowSuccessMessage = (1 << 5), // Show message about successful completion of command.
ForceCLocale = (1 << 6), // Force C-locale for commands whose output is parsed.
SilentOutput = (1 << 7), // Suppress user notifications about the output happening.
UseEventLoop = (1 << 8), // Use event loop when executed in UI thread.
ExpectRepoChanges = (1 << 9), // Expect changes in repository by the command
NoOutput = SuppressStdErr | SuppressFailMessage | SuppressCommandLogging
};
inline void VCSBASE_EXPORT operator|=(RunFlags &p, RunFlags r)
{
p = RunFlags(int(p) | int(r));
}
inline RunFlags VCSBASE_EXPORT operator|(RunFlags p, RunFlags r)
{
return RunFlags(int(p) | int(r));
}
inline void VCSBASE_EXPORT operator&=(RunFlags &p, RunFlags r)
{
p = RunFlags(int(p) & int(r));
}
// Note, that it returns bool, not RunFlags.
// It's only meant for testing whether a specific bit is set.
inline bool VCSBASE_EXPORT operator&(RunFlags p, RunFlags r)
{
return bool(int(p) & int(r));
}
} // namespace VcsBase