forked from qt-creator/qt-creator
VcsBase: Get rid of CommandOutputBindMode
Simplify createCommand() implementation. All callers passed either non-null editor (in this case the bindMode was always NoBind) or passed a null editor and one of two values for bindMode (in this case the only effect was to add (or not) a RunFlags::ShowStdOut flag). Drop CommandOutputBindMode enum completely and pass directly RunFlags::ShowStdOut when needed (i.e. in cases we were passing CommandOutputBindMode::ToVcsWindow). Change-Id: Ic3af05818933a03f615ba02267403b9f0bd326ba 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, CommandOutputBindMode::NoBind);
|
this, commandHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
@@ -1110,7 +1110,7 @@ void GitClient::status(const FilePath &workingDirectory) const
|
|||||||
VcsOutputWindow::setRepository(workingDirectory);
|
VcsOutputWindow::setRepository(workingDirectory);
|
||||||
vcsExecWithHandler(workingDirectory, {"status", "-u"}, this, [](const CommandResult &) {
|
vcsExecWithHandler(workingDirectory, {"status", "-u"}, this, [](const CommandResult &) {
|
||||||
VcsOutputWindow::instance()->clearRepository();
|
VcsOutputWindow::instance()->clearRepository();
|
||||||
});
|
}, RunFlags::ShowStdOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList normalLogArguments()
|
static QStringList normalLogArguments()
|
||||||
@@ -1308,7 +1308,8 @@ void GitClient::archive(const FilePath &workingDirectory, QString commit)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vcsExec(workingDirectory, {"archive", commit, "-o", archive.absoluteFilePath()});
|
vcsExec(workingDirectory, {"archive", commit, "-o", archive.absoluteFilePath()},
|
||||||
|
RunFlags::ShowStdOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
VcsBaseEditorWidget *GitClient::annotate(
|
VcsBaseEditorWidget *GitClient::annotate(
|
||||||
@@ -1362,7 +1363,7 @@ void GitClient::checkout(const FilePath &workingDirectory, const QString &ref, S
|
|||||||
handler(result);
|
handler(result);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, arguments, context, commandHandler,
|
vcsExecWithHandler(workingDirectory, arguments, context, commandHandler,
|
||||||
RunFlags::ExpectRepoChanges | RunFlags::ShowSuccessMessage);
|
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges | RunFlags::ShowSuccessMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* method used to setup arguments for checkout, in case user wants to create local branch */
|
/* method used to setup arguments for checkout, in case user wants to create local branch */
|
||||||
@@ -1444,7 +1445,7 @@ void GitClient::reset(const FilePath &workingDirectory, const QString &argument,
|
|||||||
if (!commit.isEmpty())
|
if (!commit.isEmpty())
|
||||||
arguments << commit;
|
arguments << commit;
|
||||||
|
|
||||||
RunFlags flags = RunFlags::ShowSuccessMessage;
|
RunFlags flags = RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage;
|
||||||
if (argument == "--hard") {
|
if (argument == "--hard") {
|
||||||
if (gitStatus(workingDirectory, StatusMode(NoUntracked | NoSubmodules)) != StatusUnchanged) {
|
if (gitStatus(workingDirectory, StatusMode(NoUntracked | NoSubmodules)) != StatusUnchanged) {
|
||||||
if (QMessageBox::question(
|
if (QMessageBox::question(
|
||||||
@@ -1468,7 +1469,7 @@ void GitClient::removeStaleRemoteBranches(const FilePath &workingDirectory, cons
|
|||||||
GitPlugin::updateBranches(workingDirectory);
|
GitPlugin::updateBranches(workingDirectory);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||||
RunFlags::ShowSuccessMessage);
|
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::recoverDeletedFiles(const FilePath &workingDirectory)
|
void GitClient::recoverDeletedFiles(const FilePath &workingDirectory)
|
||||||
@@ -1489,7 +1490,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, CommandOutputBindMode::NoBind);
|
vcsExec(workingDirectory, {"add", fileName});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::synchronousLog(const FilePath &workingDirectory, const QStringList &arguments,
|
bool GitClient::synchronousLog(const FilePath &workingDirectory, const QStringList &arguments,
|
||||||
@@ -2297,7 +2298,7 @@ void GitClient::updateSubmodulesIfNeeded(const FilePath &workingDirectory, bool
|
|||||||
|
|
||||||
vcsExecWithHandler(workingDirectory, {"submodule", "update"},
|
vcsExecWithHandler(workingDirectory, {"submodule", "update"},
|
||||||
this, [this](const CommandResult &) { finishSubmoduleUpdate(); },
|
this, [this](const CommandResult &) { finishSubmoduleUpdate(); },
|
||||||
RunFlags::ExpectRepoChanges);
|
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::finishSubmoduleUpdate()
|
void GitClient::finishSubmoduleUpdate()
|
||||||
@@ -3082,7 +3083,7 @@ void GitClient::fetch(const FilePath &workingDirectory, const QString &remote)
|
|||||||
GitPlugin::updateBranches(workingDirectory);
|
GitPlugin::updateBranches(workingDirectory);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||||
RunFlags::ShowSuccessMessage);
|
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::executeAndHandleConflicts(const FilePath &workingDirectory,
|
bool GitClient::executeAndHandleConflicts(const FilePath &workingDirectory,
|
||||||
@@ -3234,7 +3235,7 @@ void GitClient::subversionLog(const FilePath &workingDirectory) const
|
|||||||
|
|
||||||
void GitClient::subversionDeltaCommit(const FilePath &workingDirectory) const
|
void GitClient::subversionDeltaCommit(const FilePath &workingDirectory) const
|
||||||
{
|
{
|
||||||
vcsExec(workingDirectory, {"svn", "dcommit"}, RunFlags::ShowSuccessMessage);
|
vcsExec(workingDirectory, {"svn", "dcommit"}, RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class PushFailure { Unknown, NonFastForward, NoRemoteBranch };
|
enum class PushFailure { Unknown, NonFastForward, NoRemoteBranch };
|
||||||
@@ -3291,8 +3292,10 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
|
|||||||
if (result.result() == ProcessResult::FinishedWithSuccess)
|
if (result.result() == ProcessResult::FinishedWithSuccess)
|
||||||
GitPlugin::updateCurrentBranch();
|
GitPlugin::updateCurrentBranch();
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, QStringList{"push", "--force-with-lease"} + pushArgs,
|
vcsExecWithHandler(workingDirectory,
|
||||||
this, commandHandler, RunFlags::ShowSuccessMessage);
|
QStringList{"push", "--force-with-lease"} + pushArgs,
|
||||||
|
this, commandHandler,
|
||||||
|
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// NoRemoteBranch case
|
// NoRemoteBranch case
|
||||||
@@ -3312,10 +3315,11 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
|
|||||||
GitPlugin::updateBranches(workingDirectory);
|
GitPlugin::updateBranches(workingDirectory);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, fallbackCommandParts.mid(1),
|
vcsExecWithHandler(workingDirectory, fallbackCommandParts.mid(1),
|
||||||
this, commandHandler, RunFlags::ShowSuccessMessage);
|
this, commandHandler,
|
||||||
|
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, QStringList({"push"}) + pushArgs, this, commandHandler,
|
vcsExecWithHandler(workingDirectory, QStringList({"push"}) + pushArgs, this, commandHandler,
|
||||||
RunFlags::ShowSuccessMessage);
|
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::synchronousMerge(const FilePath &workingDirectory, const QString &branch,
|
bool GitClient::synchronousMerge(const FilePath &workingDirectory, const QString &branch,
|
||||||
@@ -3368,7 +3372,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, CommandOutputBindMode::ToVcsWindow);
|
VcsCommand *command = createCommand(workingDirectory);
|
||||||
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.
|
||||||
@@ -3438,7 +3442,7 @@ void GitClient::stashPop(const FilePath &workingDirectory, const QString &stash)
|
|||||||
ConflictHandler::handleResponse(result, workingDirectory);
|
ConflictHandler::handleResponse(result, workingDirectory);
|
||||||
};
|
};
|
||||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||||
RunFlags::ExpectRepoChanges);
|
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::synchronousStashRestore(const FilePath &workingDirectory,
|
bool GitClient::synchronousStashRestore(const FilePath &workingDirectory,
|
||||||
|
@@ -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, CommandOutputBindMode::NoBind);
|
this, commandHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitPluginPrivate::stopInstantBlame()
|
void GitPluginPrivate::stopInstantBlame()
|
||||||
|
@@ -72,17 +72,11 @@ FilePath VcsBaseClientImpl::vcsBinary() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
||||||
VcsBaseEditorWidget *editor,
|
VcsBaseEditorWidget *editor) 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 == CommandOutputBindMode::ToVcsWindow) {
|
|
||||||
cmd->addFlags(RunFlags::ShowStdOut);
|
|
||||||
if (editor) // assume that the commands output is the important thing
|
|
||||||
cmd->addFlags(RunFlags::SilentOutput);
|
|
||||||
} else if (editor) {
|
|
||||||
connect(cmd, &VcsCommand::done, editor, [editor, cmd] {
|
connect(cmd, &VcsCommand::done, editor, [editor, cmd] {
|
||||||
if (cmd->result() != ProcessResult::FinishedWithSuccess) {
|
if (cmd->result() != ProcessResult::FinishedWithSuccess) {
|
||||||
editor->textDocument()->setPlainText(tr("Failed to retrieve data."));
|
editor->textDocument()->setPlainText(tr("Failed to retrieve data."));
|
||||||
@@ -92,7 +86,6 @@ VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
|||||||
editor->gotoDefaultLine();
|
editor->gotoDefaultLine();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,10 +156,9 @@ void VcsBaseClientImpl::vcsExecWithHandler(const FilePath &workingDirectory,
|
|||||||
const QStringList &arguments,
|
const QStringList &arguments,
|
||||||
const QObject *context,
|
const QObject *context,
|
||||||
const CommandHandler &handler,
|
const CommandHandler &handler,
|
||||||
RunFlags additionalFlags,
|
RunFlags additionalFlags) const
|
||||||
CommandOutputBindMode bindMode) const
|
|
||||||
{
|
{
|
||||||
VcsCommand *command = createCommand(workingDirectory, nullptr, bindMode);
|
VcsCommand *command = createCommand(workingDirectory);
|
||||||
command->addFlags(additionalFlags);
|
command->addFlags(additionalFlags);
|
||||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||||
if (handler) {
|
if (handler) {
|
||||||
@@ -180,10 +172,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) const
|
||||||
CommandOutputBindMode bindMode) const
|
|
||||||
{
|
{
|
||||||
VcsCommand *command = createCommand(workingDirectory, nullptr, bindMode);
|
VcsCommand *command = createCommand(workingDirectory);
|
||||||
command->addFlags(additionalFlags);
|
command->addFlags(additionalFlags);
|
||||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||||
command->start();
|
command->start();
|
||||||
@@ -193,7 +184,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, CommandOutputBindMode::NoBind);
|
VcsCommand *command = createCommand(workingDirectory, editor);
|
||||||
command->setCodec(editor->codec());
|
command->setCodec(editor->codec());
|
||||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||||
command->start();
|
command->start();
|
||||||
@@ -473,7 +464,8 @@ 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, CommandOutputBindMode::ToVcsWindow);
|
VcsCommand *cmd = createCommand(workingDir);
|
||||||
|
cmd->addFlags(RunFlags::ShowStdOut);
|
||||||
connect(cmd, &VcsCommand::done, VcsOutputWindow::instance(), &VcsOutputWindow::clearRepository);
|
connect(cmd, &VcsCommand::done, VcsOutputWindow::instance(), &VcsOutputWindow::clearRepository);
|
||||||
enqueueJob(cmd, args);
|
enqueueJob(cmd, args);
|
||||||
}
|
}
|
||||||
@@ -579,7 +571,8 @@ 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, CommandOutputBindMode::ToVcsWindow);
|
VcsCommand *cmd = createCommand(repositoryRoot);
|
||||||
|
cmd->addFlags(RunFlags::ShowStdOut);
|
||||||
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,11 +30,6 @@ 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
|
||||||
@@ -59,8 +54,7 @@ public:
|
|||||||
const QString &dynamicPropertyValue) const;
|
const QString &dynamicPropertyValue) const;
|
||||||
|
|
||||||
VcsCommand *createCommand(const Utils::FilePath &workingDirectory,
|
VcsCommand *createCommand(const Utils::FilePath &workingDirectory,
|
||||||
VcsBaseEditorWidget *editor = nullptr,
|
VcsBaseEditorWidget *editor = nullptr) 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;
|
||||||
@@ -91,12 +85,10 @@ public:
|
|||||||
const QStringList &arguments,
|
const QStringList &arguments,
|
||||||
const QObject *context,
|
const QObject *context,
|
||||||
const CommandHandler &handler,
|
const CommandHandler &handler,
|
||||||
RunFlags additionalFlags = RunFlags::None,
|
RunFlags additionalFlags = RunFlags::None) 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) 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