forked from qt-creator/qt-creator
VcsBase: Reuse CommandOutputBindMode instead of bool
Reuse it inside vcsExec() and vcsExecWithHandler(). Change-Id: I6ff4044bf43e0883fc46a49718f5f44da87a7e13 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -357,7 +357,7 @@ void GitBaseDiffEditorController::updateBranchList()
|
||||
};
|
||||
m_instance->vcsExecWithHandler(baseDirectory(),
|
||||
{"branch", noColorOption, "-a", "--contains", revision},
|
||||
this, commandHandler, RunFlags::None, false);
|
||||
this, commandHandler, RunFlags::None, CommandOutputBindMode::NoBind);
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
@@ -1489,7 +1489,7 @@ void GitClient::recoverDeletedFiles(const FilePath &workingDirectory)
|
||||
|
||||
void GitClient::addFile(const FilePath &workingDirectory, const QString &fileName)
|
||||
{
|
||||
vcsExec(workingDirectory, {"add", fileName}, RunFlags::None, false);
|
||||
vcsExec(workingDirectory, {"add", fileName}, RunFlags::None, CommandOutputBindMode::NoBind);
|
||||
}
|
||||
|
||||
bool GitClient::synchronousLog(const FilePath &workingDirectory, const QStringList &arguments,
|
||||
@@ -3368,7 +3368,7 @@ VcsCommand *GitClient::vcsExecAbortable(const FilePath &workingDirectory,
|
||||
|
||||
if (abortCommand.isEmpty())
|
||||
abortCommand = arguments.at(0);
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, VcsWindowOutputBind);
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, CommandOutputBindMode::ToVcsWindow);
|
||||
command->addFlags(RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||
// For rebase, Git might request an editor (which means the process keeps running until the
|
||||
// user closes it), so run without timeout.
|
||||
|
@@ -1584,7 +1584,7 @@ void GitPluginPrivate::instantBlame()
|
||||
};
|
||||
GitClient::instance()->vcsExecWithHandler(workingDirectory,
|
||||
{"blame", "-p", "-L", lineString, "--", filePath.toString()},
|
||||
this, commandHandler, RunFlags::NoOutput, false);
|
||||
this, commandHandler, RunFlags::NoOutput, CommandOutputBindMode::NoBind);
|
||||
}
|
||||
|
||||
void GitPluginPrivate::stopInstantBlame()
|
||||
|
@@ -73,12 +73,12 @@ FilePath VcsBaseClientImpl::vcsBinary() const
|
||||
|
||||
VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
||||
VcsBaseEditorWidget *editor,
|
||||
JobOutputBindMode mode) const
|
||||
CommandOutputBindMode mode) const
|
||||
{
|
||||
auto cmd = createVcsCommand(workingDirectory, processEnvironment());
|
||||
if (editor)
|
||||
editor->setCommand(cmd);
|
||||
if (mode == VcsWindowOutputBind) {
|
||||
if (mode == CommandOutputBindMode::ToVcsWindow) {
|
||||
cmd->addFlags(RunFlags::ShowStdOut);
|
||||
if (editor) // assume that the commands output is the important thing
|
||||
cmd->addFlags(RunFlags::SilentOutput);
|
||||
@@ -164,10 +164,9 @@ void VcsBaseClientImpl::vcsExecWithHandler(const FilePath &workingDirectory,
|
||||
const QObject *context,
|
||||
const CommandHandler &handler,
|
||||
RunFlags additionalFlags,
|
||||
bool useOutputToWindow) const
|
||||
CommandOutputBindMode bindMode) const
|
||||
{
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr,
|
||||
useOutputToWindow ? VcsWindowOutputBind : NoOutputBind);
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, bindMode);
|
||||
command->addFlags(additionalFlags);
|
||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||
if (handler) {
|
||||
@@ -181,10 +180,9 @@ void VcsBaseClientImpl::vcsExecWithHandler(const FilePath &workingDirectory,
|
||||
void VcsBaseClientImpl::vcsExec(const FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
RunFlags additionalFlags,
|
||||
bool useOutputToWindow) const
|
||||
CommandOutputBindMode bindMode) const
|
||||
{
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr,
|
||||
useOutputToWindow ? VcsWindowOutputBind : NoOutputBind);
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, bindMode);
|
||||
command->addFlags(additionalFlags);
|
||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||
command->start();
|
||||
@@ -194,7 +192,7 @@ void VcsBaseClientImpl::vcsExecWithEditor(const Utils::FilePath &workingDirector
|
||||
const QStringList &arguments,
|
||||
VcsBaseEditorWidget *editor) const
|
||||
{
|
||||
VcsCommand *command = createCommand(workingDirectory, editor, NoOutputBind);
|
||||
VcsCommand *command = createCommand(workingDirectory, editor, CommandOutputBindMode::NoBind);
|
||||
command->setCodec(editor->codec());
|
||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||
command->start();
|
||||
@@ -474,7 +472,7 @@ void VcsBaseClient::status(const FilePath &workingDir,
|
||||
QStringList args(vcsCommandString(StatusCommand));
|
||||
args << extraOptions << file;
|
||||
VcsOutputWindow::setRepository(workingDir);
|
||||
VcsCommand *cmd = createCommand(workingDir, nullptr, VcsWindowOutputBind);
|
||||
VcsCommand *cmd = createCommand(workingDir, nullptr, CommandOutputBindMode::ToVcsWindow);
|
||||
connect(cmd, &VcsCommand::done, VcsOutputWindow::instance(), &VcsOutputWindow::clearRepository);
|
||||
enqueueJob(cmd, args);
|
||||
}
|
||||
@@ -580,7 +578,7 @@ void VcsBaseClient::commit(const FilePath &repositoryRoot,
|
||||
// for example)
|
||||
QStringList args(vcsCommandString(CommitCommand));
|
||||
args << extraOptions << files;
|
||||
VcsCommand *cmd = createCommand(repositoryRoot, nullptr, VcsWindowOutputBind);
|
||||
VcsCommand *cmd = createCommand(repositoryRoot, nullptr, CommandOutputBindMode::ToVcsWindow);
|
||||
if (!commitMessageFile.isEmpty())
|
||||
connect(cmd, &VcsCommand::done, [commitMessageFile] { QFile(commitMessageFile).remove(); });
|
||||
enqueueJob(cmd, args);
|
||||
|
@@ -30,6 +30,11 @@ class VcsBaseEditorConfig;
|
||||
class VcsBaseEditorWidget;
|
||||
class VcsCommand;
|
||||
|
||||
enum class CommandOutputBindMode {
|
||||
NoBind,
|
||||
ToVcsWindow
|
||||
};
|
||||
|
||||
using CommandHandler = std::function<void(const CommandResult &)>;
|
||||
|
||||
class VCSBASE_EXPORT VcsBaseClientImpl : public QObject
|
||||
@@ -45,11 +50,6 @@ public:
|
||||
virtual Utils::FilePath vcsBinary() const;
|
||||
int vcsTimeoutS() const;
|
||||
|
||||
enum JobOutputBindMode {
|
||||
NoOutputBind,
|
||||
VcsWindowOutputBind
|
||||
};
|
||||
|
||||
static VcsCommand *createVcsCommand(const Utils::FilePath &defaultWorkingDir,
|
||||
const Utils::Environment &environment);
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
VcsCommand *createCommand(const Utils::FilePath &workingDirectory,
|
||||
VcsBaseEditorWidget *editor = nullptr,
|
||||
JobOutputBindMode mode = NoOutputBind) const;
|
||||
CommandOutputBindMode mode = CommandOutputBindMode::NoBind) const;
|
||||
|
||||
void enqueueJob(VcsCommand *cmd, const QStringList &args,
|
||||
const Utils::ExitCodeInterpreter &interpreter = {}) const;
|
||||
@@ -92,11 +92,11 @@ public:
|
||||
const QObject *context,
|
||||
const CommandHandler &handler,
|
||||
RunFlags additionalFlags = RunFlags::None,
|
||||
bool useOutputToWindow = true) const;
|
||||
CommandOutputBindMode bindMode = CommandOutputBindMode::ToVcsWindow) const;
|
||||
void vcsExec(const Utils::FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
RunFlags additionalFlags = RunFlags::None,
|
||||
bool useOutputToWindow = true) const;
|
||||
CommandOutputBindMode bindMode = CommandOutputBindMode::ToVcsWindow) const;
|
||||
void vcsExecWithEditor(const Utils::FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
VcsBaseEditorWidget *editor) const;
|
||||
|
Reference in New Issue
Block a user