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