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(),
|
||||
{"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);
|
||||
vcsExecWithHandler(workingDirectory, {"status", "-u"}, this, [](const CommandResult &) {
|
||||
VcsOutputWindow::instance()->clearRepository();
|
||||
});
|
||||
}, RunFlags::ShowStdOut);
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -1362,7 +1363,7 @@ void GitClient::checkout(const FilePath &workingDirectory, const QString &ref, S
|
||||
handler(result);
|
||||
};
|
||||
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 */
|
||||
@@ -1444,7 +1445,7 @@ void GitClient::reset(const FilePath &workingDirectory, const QString &argument,
|
||||
if (!commit.isEmpty())
|
||||
arguments << commit;
|
||||
|
||||
RunFlags flags = RunFlags::ShowSuccessMessage;
|
||||
RunFlags flags = RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage;
|
||||
if (argument == "--hard") {
|
||||
if (gitStatus(workingDirectory, StatusMode(NoUntracked | NoSubmodules)) != StatusUnchanged) {
|
||||
if (QMessageBox::question(
|
||||
@@ -1468,7 +1469,7 @@ void GitClient::removeStaleRemoteBranches(const FilePath &workingDirectory, cons
|
||||
GitPlugin::updateBranches(workingDirectory);
|
||||
};
|
||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||
RunFlags::ShowSuccessMessage);
|
||||
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
vcsExec(workingDirectory, {"add", fileName}, RunFlags::None, CommandOutputBindMode::NoBind);
|
||||
vcsExec(workingDirectory, {"add", fileName});
|
||||
}
|
||||
|
||||
bool GitClient::synchronousLog(const FilePath &workingDirectory, const QStringList &arguments,
|
||||
@@ -2297,7 +2298,7 @@ void GitClient::updateSubmodulesIfNeeded(const FilePath &workingDirectory, bool
|
||||
|
||||
vcsExecWithHandler(workingDirectory, {"submodule", "update"},
|
||||
this, [this](const CommandResult &) { finishSubmoduleUpdate(); },
|
||||
RunFlags::ExpectRepoChanges);
|
||||
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges);
|
||||
}
|
||||
|
||||
void GitClient::finishSubmoduleUpdate()
|
||||
@@ -3082,7 +3083,7 @@ void GitClient::fetch(const FilePath &workingDirectory, const QString &remote)
|
||||
GitPlugin::updateBranches(workingDirectory);
|
||||
};
|
||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||
RunFlags::ShowSuccessMessage);
|
||||
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||
}
|
||||
|
||||
bool GitClient::executeAndHandleConflicts(const FilePath &workingDirectory,
|
||||
@@ -3234,7 +3235,7 @@ void GitClient::subversionLog(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 };
|
||||
@@ -3291,8 +3292,10 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
|
||||
if (result.result() == ProcessResult::FinishedWithSuccess)
|
||||
GitPlugin::updateCurrentBranch();
|
||||
};
|
||||
vcsExecWithHandler(workingDirectory, QStringList{"push", "--force-with-lease"} + pushArgs,
|
||||
this, commandHandler, RunFlags::ShowSuccessMessage);
|
||||
vcsExecWithHandler(workingDirectory,
|
||||
QStringList{"push", "--force-with-lease"} + pushArgs,
|
||||
this, commandHandler,
|
||||
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||
return;
|
||||
}
|
||||
// NoRemoteBranch case
|
||||
@@ -3312,10 +3315,11 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
|
||||
GitPlugin::updateBranches(workingDirectory);
|
||||
};
|
||||
vcsExecWithHandler(workingDirectory, fallbackCommandParts.mid(1),
|
||||
this, commandHandler, RunFlags::ShowSuccessMessage);
|
||||
this, commandHandler,
|
||||
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||
};
|
||||
vcsExecWithHandler(workingDirectory, QStringList({"push"}) + pushArgs, this, commandHandler,
|
||||
RunFlags::ShowSuccessMessage);
|
||||
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
|
||||
}
|
||||
|
||||
bool GitClient::synchronousMerge(const FilePath &workingDirectory, const QString &branch,
|
||||
@@ -3368,7 +3372,7 @@ VcsCommand *GitClient::vcsExecAbortable(const FilePath &workingDirectory,
|
||||
|
||||
if (abortCommand.isEmpty())
|
||||
abortCommand = arguments.at(0);
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, CommandOutputBindMode::ToVcsWindow);
|
||||
VcsCommand *command = createCommand(workingDirectory);
|
||||
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.
|
||||
@@ -3438,7 +3442,7 @@ void GitClient::stashPop(const FilePath &workingDirectory, const QString &stash)
|
||||
ConflictHandler::handleResponse(result, workingDirectory);
|
||||
};
|
||||
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
|
||||
RunFlags::ExpectRepoChanges);
|
||||
RunFlags::ShowStdOut | RunFlags::ExpectRepoChanges);
|
||||
}
|
||||
|
||||
bool GitClient::synchronousStashRestore(const FilePath &workingDirectory,
|
||||
|
@@ -1584,7 +1584,7 @@ void GitPluginPrivate::instantBlame()
|
||||
};
|
||||
GitClient::instance()->vcsExecWithHandler(workingDirectory,
|
||||
{"blame", "-p", "-L", lineString, "--", filePath.toString()},
|
||||
this, commandHandler, RunFlags::NoOutput, CommandOutputBindMode::NoBind);
|
||||
this, commandHandler);
|
||||
}
|
||||
|
||||
void GitPluginPrivate::stopInstantBlame()
|
||||
|
@@ -72,17 +72,11 @@ FilePath VcsBaseClientImpl::vcsBinary() const
|
||||
}
|
||||
|
||||
VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
||||
VcsBaseEditorWidget *editor,
|
||||
CommandOutputBindMode mode) const
|
||||
VcsBaseEditorWidget *editor) const
|
||||
{
|
||||
auto cmd = createVcsCommand(workingDirectory, processEnvironment());
|
||||
if (editor)
|
||||
if (editor) {
|
||||
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] {
|
||||
if (cmd->result() != ProcessResult::FinishedWithSuccess) {
|
||||
editor->textDocument()->setPlainText(tr("Failed to retrieve data."));
|
||||
@@ -92,7 +86,6 @@ VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
|
||||
editor->gotoDefaultLine();
|
||||
});
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -163,10 +156,9 @@ void VcsBaseClientImpl::vcsExecWithHandler(const FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
const QObject *context,
|
||||
const CommandHandler &handler,
|
||||
RunFlags additionalFlags,
|
||||
CommandOutputBindMode bindMode) const
|
||||
RunFlags additionalFlags) const
|
||||
{
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, bindMode);
|
||||
VcsCommand *command = createCommand(workingDirectory);
|
||||
command->addFlags(additionalFlags);
|
||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||
if (handler) {
|
||||
@@ -180,10 +172,9 @@ void VcsBaseClientImpl::vcsExecWithHandler(const FilePath &workingDirectory,
|
||||
|
||||
void VcsBaseClientImpl::vcsExec(const FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
RunFlags additionalFlags,
|
||||
CommandOutputBindMode bindMode) const
|
||||
RunFlags additionalFlags) const
|
||||
{
|
||||
VcsCommand *command = createCommand(workingDirectory, nullptr, bindMode);
|
||||
VcsCommand *command = createCommand(workingDirectory);
|
||||
command->addFlags(additionalFlags);
|
||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||
command->start();
|
||||
@@ -193,7 +184,7 @@ void VcsBaseClientImpl::vcsExecWithEditor(const Utils::FilePath &workingDirector
|
||||
const QStringList &arguments,
|
||||
VcsBaseEditorWidget *editor) const
|
||||
{
|
||||
VcsCommand *command = createCommand(workingDirectory, editor, CommandOutputBindMode::NoBind);
|
||||
VcsCommand *command = createCommand(workingDirectory, editor);
|
||||
command->setCodec(editor->codec());
|
||||
command->addJob({vcsBinary(), arguments}, vcsTimeoutS());
|
||||
command->start();
|
||||
@@ -473,7 +464,8 @@ void VcsBaseClient::status(const FilePath &workingDir,
|
||||
QStringList args(vcsCommandString(StatusCommand));
|
||||
args << extraOptions << file;
|
||||
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);
|
||||
enqueueJob(cmd, args);
|
||||
}
|
||||
@@ -579,7 +571,8 @@ void VcsBaseClient::commit(const FilePath &repositoryRoot,
|
||||
// for example)
|
||||
QStringList args(vcsCommandString(CommitCommand));
|
||||
args << extraOptions << files;
|
||||
VcsCommand *cmd = createCommand(repositoryRoot, nullptr, CommandOutputBindMode::ToVcsWindow);
|
||||
VcsCommand *cmd = createCommand(repositoryRoot);
|
||||
cmd->addFlags(RunFlags::ShowStdOut);
|
||||
if (!commitMessageFile.isEmpty())
|
||||
connect(cmd, &VcsCommand::done, [commitMessageFile] { QFile(commitMessageFile).remove(); });
|
||||
enqueueJob(cmd, args);
|
||||
|
@@ -30,11 +30,6 @@ class VcsBaseEditorConfig;
|
||||
class VcsBaseEditorWidget;
|
||||
class VcsCommand;
|
||||
|
||||
enum class CommandOutputBindMode {
|
||||
NoBind,
|
||||
ToVcsWindow
|
||||
};
|
||||
|
||||
using CommandHandler = std::function<void(const CommandResult &)>;
|
||||
|
||||
class VCSBASE_EXPORT VcsBaseClientImpl : public QObject
|
||||
@@ -59,8 +54,7 @@ public:
|
||||
const QString &dynamicPropertyValue) const;
|
||||
|
||||
VcsCommand *createCommand(const Utils::FilePath &workingDirectory,
|
||||
VcsBaseEditorWidget *editor = nullptr,
|
||||
CommandOutputBindMode mode = CommandOutputBindMode::NoBind) const;
|
||||
VcsBaseEditorWidget *editor = nullptr) const;
|
||||
|
||||
void enqueueJob(VcsCommand *cmd, const QStringList &args,
|
||||
const Utils::ExitCodeInterpreter &interpreter = {}) const;
|
||||
@@ -91,12 +85,10 @@ public:
|
||||
const QStringList &arguments,
|
||||
const QObject *context,
|
||||
const CommandHandler &handler,
|
||||
RunFlags additionalFlags = RunFlags::None,
|
||||
CommandOutputBindMode bindMode = CommandOutputBindMode::ToVcsWindow) const;
|
||||
RunFlags additionalFlags = RunFlags::None) const;
|
||||
void vcsExec(const Utils::FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
RunFlags additionalFlags = RunFlags::None,
|
||||
CommandOutputBindMode bindMode = CommandOutputBindMode::ToVcsWindow) const;
|
||||
RunFlags additionalFlags = RunFlags::None) const;
|
||||
void vcsExecWithEditor(const Utils::FilePath &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
VcsBaseEditorWidget *editor) const;
|
||||
|
Reference in New Issue
Block a user