Commit 07d6757c authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Vcs: Move createCommand and enqueueJob into VcsBaseClientImpl



Change-Id: I86a4ddfd6c53a3be61c56579d8eaf5d49258a8f1
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 3f6f987d
......@@ -118,8 +118,7 @@ public:
}
};
BazaarClient::BazaarClient() :
VcsBaseClient(new BazaarSettings)
BazaarClient::BazaarClient() : VcsBaseClient(new BazaarSettings)
{
setDiffParameterWidgetCreator([this] { return new BazaarDiffParameterWidget(settings()); });
setLogParameterWidgetCreator([this] { return new BazaarLogParameterWidget(settings()); });
......
......@@ -603,7 +603,7 @@ static inline void msgCannotRun(const QStringList &args, const QString &workingD
const char *GitClient::stashNamePrefix = "stash@{";
GitClient::GitClient() : VcsBase::VcsBaseClientImpl(new GitSettings),
GitClient::GitClient() : VcsBase::VcsBaseClientImpl(this, new GitSettings),
m_cachedGitVersion(0),
m_disableEditor(false)
{
......@@ -1967,36 +1967,6 @@ bool GitClient::synchronousApplyPatch(const QString &workingDirectory,
return true;
}
// Factory function to create an asynchronous command
VcsCommand *GitClient::createCommand(const QString &workingDirectory, VcsBaseEditorWidget *editor,
JobOutputBindMode mode)
{
GitEditorWidget *gitEditor = qobject_cast<GitEditorWidget *>(editor);
auto command = new VcsCommand(vcsBinary(), workingDirectory, processEnvironment());
command->setCodec(getSourceCodec(currentDocumentPath()));
if (gitEditor) {
gitEditor->setCommand(command);
connect(command, &VcsCommand::finished,
gitEditor, &GitEditorWidget::commandFinishedGotoLine);
}
if (mode & VcsWindowOutputBind) {
command->addFlags(VcsBasePlugin::ShowStdOutInLogWindow);
command->addFlags(VcsBasePlugin::ShowSuccessMessage);
if (editor) // assume that the commands output is the important thing
command->addFlags(VcsBasePlugin::SilentOutput);
} else if (gitEditor) {
connect(command, &VcsCommand::output, gitEditor, &GitEditorWidget::setPlainTextFiltered);
}
return command;
}
void GitClient::enqueueJob(VcsCommand *cmd, const QStringList &args, ExitCodeInterpreter *interpreter)
{
cmd->addJob(args, vcsTimeout(), interpreter);
cmd->execute();
}
// Execute a single command
VcsCommand *GitClient::executeGit(const QString &workingDirectory,
const QStringList &arguments,
......@@ -2016,7 +1986,7 @@ VcsCommand *GitClient::executeGit(const QString &workingDirectory,
QProcessEnvironment GitClient::processEnvironment() const
{
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QProcessEnvironment environment = VcsBaseClientImpl::processEnvironment();
QString gitPath = settings().stringValue(GitSettings::pathKey);
if (!gitPath.isEmpty()) {
gitPath += HostOsInfo::pathListSeparator();
......@@ -2028,8 +1998,6 @@ QProcessEnvironment GitClient::processEnvironment() const
environment.insert(QLatin1String("HOME"), QDir::toNativeSeparators(QDir::homePath()));
}
environment.insert(QLatin1String("GIT_EDITOR"), m_disableEditor ? QLatin1String("true") : m_gitQtcEditor);
// Set up SSH and C locale (required by git using perl).
VcsBasePlugin::setProcessEnvironment(&environment, false);
return environment;
}
......
......@@ -376,17 +376,6 @@ private:
void requestReload(const QString &documentId, const QString &source, const QString &title,
std::function<DiffEditor::DiffEditorController *(Core::IDocument *)> factory) const;
enum JobOutputBindMode {
NoOutputBind,
VcsWindowOutputBind
};
VcsBase::VcsCommand *createCommand(const QString &workingDirectory,
VcsBase::VcsBaseEditorWidget *editor = 0,
JobOutputBindMode mode = NoOutputBind);
void enqueueJob(VcsBase::VcsCommand *cmd, const QStringList &args,
Utils::ExitCodeInterpreter *interpreter = 0);
VcsBase::VcsCommand *executeGit(const QString &workingDirectory,
const QStringList &arguments,
VcsBase::VcsBaseEditorWidget* editor = 0,
......
......@@ -197,16 +197,6 @@ void GitEditorWidget::setPlainTextFiltered(const QString &text)
textDocument()->setPlainText(modText);
}
void GitEditorWidget::commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v)
{
reportCommandFinished(ok, exitCode, v);
if (ok && v.type() == QVariant::Int) {
const int line = v.toInt();
if (line >= 0)
gotoLine(line);
}
}
void GitEditorWidget::checkoutChange()
{
GitPlugin::instance()->client()->stashAndCheckout(
......
......@@ -51,8 +51,6 @@ public:
public slots:
void setPlainTextFiltered(const QString &text);
// Matches the signature of the finished signal of GitCommand
void commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v);
private slots:
void checkoutChange();
......
......@@ -68,8 +68,7 @@ public:
}
};
MercurialClient::MercurialClient() :
VcsBaseClient(new MercurialSettings)
MercurialClient::MercurialClient() : VcsBaseClient(new MercurialSettings)
{
setDiffParameterWidgetCreator([this] { return new MercurialDiffParameterWidget(settings()); });
}
......
......@@ -82,15 +82,27 @@ namespace VcsBase {
class VcsBaseClientImplPrivate
{
public:
VcsBaseClientImplPrivate(VcsBaseClientSettings *settings);
VcsBaseClientImplPrivate(VcsBaseClientImpl *client, VcsBaseClientSettings *settings);
~VcsBaseClientImplPrivate();
void bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor);
VcsBaseClientSettings *m_clientSettings;
QSignalMapper *m_cmdFinishedMapper;
};
void VcsBaseClientImplPrivate::bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor)
{
editor->setCommand(cmd);
QObject::connect(cmd, &VcsCommand::finished,
m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
m_cmdFinishedMapper->setMapping(cmd, editor);
}
VcsBaseClientImplPrivate::VcsBaseClientImplPrivate(VcsBaseClientSettings *settings) :
m_clientSettings(settings)
VcsBaseClientImplPrivate::VcsBaseClientImplPrivate(VcsBaseClientImpl *client,
VcsBaseClientSettings *settings) :
m_clientSettings(settings),
m_cmdFinishedMapper(new QSignalMapper(client))
{
m_clientSettings->readSettings(Core::ICore::settings());
}
......@@ -100,11 +112,14 @@ VcsBaseClientImplPrivate::~VcsBaseClientImplPrivate()
delete m_clientSettings;
}
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientSettings *settings) :
d(new VcsBaseClientImplPrivate(settings))
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientImpl *client, VcsBaseClientSettings *settings) :
d(new VcsBaseClientImplPrivate(client, settings))
{
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
this, &VcsBaseClientImpl::saveSettings);
connect(d->m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)(QWidget*)>(&QSignalMapper::mapped),
this, &VcsBaseClientImpl::commandFinishedGotoLine);
}
VcsBaseClientImpl::~VcsBaseClientImpl()
......@@ -122,6 +137,40 @@ Utils::FileName VcsBaseClientImpl::vcsBinary() const
return settings().binaryPath();
}
VcsCommand *VcsBaseClientImpl::createCommand(const QString &workingDirectory,
VcsBaseEditorWidget *editor,
JobOutputBindMode mode) const
{
auto cmd = new VcsCommand(vcsBinary(), workingDirectory,
processEnvironment());
cmd->setDefaultTimeout(vcsTimeout());
if (editor)
d->bindCommandToEditor(cmd, editor);
if (mode == VcsWindowOutputBind) {
cmd->addFlags(VcsBasePlugin::ShowStdOutInLogWindow);
if (editor) // assume that the commands output is the important thing
cmd->addFlags(VcsBasePlugin::SilentOutput);
} else if (editor) {
connect(cmd, &VcsCommand::output, editor, &VcsBaseEditorWidget::setPlainText);
}
return cmd;
}
void VcsBaseClientImpl::enqueueJob(VcsCommand *cmd, const QStringList &args,
Utils::ExitCodeInterpreter *interpreter)
{
cmd->addJob(args, vcsTimeout(), interpreter);
cmd->execute();
}
QProcessEnvironment VcsBaseClientImpl::processEnvironment() const
{
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
VcsBasePlugin::setProcessEnvironment(&environment, false);
return environment;
}
int VcsBaseClientImpl::vcsTimeout() const
{
return settings().intValue(VcsBaseClientSettings::timeoutKey);
......@@ -132,34 +181,32 @@ void VcsBaseClientImpl::saveSettings()
settings().writeSettings(Core::ICore::settings());
}
void VcsBaseClientImpl::commandFinishedGotoLine(QWidget *editorObject)
{
VcsBaseEditorWidget *editor = qobject_cast<VcsBaseEditorWidget *>(editorObject);
VcsCommand *cmd = qobject_cast<VcsCommand *>(d->m_cmdFinishedMapper->mapping(editor));
if (editor && cmd) {
if (!cmd->lastExecutionSuccess()) {
editor->reportCommandFinished(false, cmd->lastExecutionExitCode(), cmd->cookie());
} else if (cmd->cookie().type() == QVariant::Int) {
const int line = cmd->cookie().toInt();
if (line >= 0)
editor->gotoLine(line);
}
d->m_cmdFinishedMapper->removeMappings(cmd);
}
}
class VcsBaseClientPrivate
{
public:
VcsBaseClientPrivate(VcsBaseClient *client);
void bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor);
VcsBaseEditorParameterWidget *createDiffEditor();
VcsBaseEditorParameterWidget *createLogEditor();
QSignalMapper *m_cmdFinishedMapper;
VcsBaseClient::ParameterWidgetCreator m_diffParamWidgetCreator;
VcsBaseClient::ParameterWidgetCreator m_logParamWidgetCreator;
};
VcsBaseClientPrivate::VcsBaseClientPrivate(VcsBaseClient *client) :
m_cmdFinishedMapper(new QSignalMapper(client))
{ }
void VcsBaseClientPrivate::bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor)
{
editor->setCommand(cmd);
QObject::connect(cmd, &VcsCommand::finished,
m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
m_cmdFinishedMapper->setMapping(cmd, editor);
}
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createDiffEditor()
{
return m_diffParamWidgetCreator ? m_diffParamWidgetCreator() : 0;
......@@ -175,12 +222,10 @@ VcsBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
{ }
VcsBaseClient::VcsBaseClient(VcsBaseClientSettings *settings) :
VcsBaseClientImpl(settings),
d(new VcsBaseClientPrivate(this))
VcsBaseClientImpl(this, settings),
d(new VcsBaseClientPrivate)
{
qRegisterMetaType<QVariant>();
connect(d->m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)(QWidget*)>(&QSignalMapper::mapped),
this, &VcsBaseClient::commandFinishedGotoLine);
}
VcsBaseClient::~VcsBaseClient()
......@@ -582,39 +627,6 @@ VcsBaseEditorWidget *VcsBaseClient::createVcsEditor(Core::Id kind, QString title
return baseEditor;
}
QProcessEnvironment VcsBaseClient::processEnvironment() const
{
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
VcsBasePlugin::setProcessEnvironment(&environment, false);
return environment;
}
VcsCommand *VcsBaseClient::createCommand(const QString &workingDirectory,
VcsBaseEditorWidget *editor,
JobOutputBindMode mode) const
{
auto cmd = new VcsCommand(vcsBinary(), workingDirectory,
processEnvironment());
cmd->setDefaultTimeout(vcsTimeout());
if (editor)
d->bindCommandToEditor(cmd, editor);
if (mode == VcsWindowOutputBind) {
cmd->addFlags(VcsBasePlugin::ShowStdOutInLogWindow);
if (editor) // assume that the commands output is the important thing
cmd->addFlags(VcsBasePlugin::SilentOutput);
} else if (editor) {
connect(cmd, &VcsCommand::output, editor, &VcsBaseEditorWidget::setPlainText);
}
return cmd;
}
void VcsBaseClient::enqueueJob(VcsCommand *cmd, const QStringList &args, Utils::ExitCodeInterpreter *interpreter)
{
cmd->addJob(args, vcsTimeout(), interpreter);
cmd->execute();
}
void VcsBaseClient::resetCachedVcsInfo(const QString &workingDir)
{
Core::VcsManager::resetVersionControlForDirectory(workingDir);
......@@ -647,22 +659,6 @@ void VcsBaseClient::annotateRevision(const QString &workingDirectory, const QSt
annotate(workingDirectory, file, changeCopy, lineNumber);
}
void VcsBaseClient::commandFinishedGotoLine(QWidget *editorObject)
{
VcsBaseEditorWidget *editor = qobject_cast<VcsBaseEditorWidget *>(editorObject);
VcsCommand *cmd = qobject_cast<VcsCommand *>(d->m_cmdFinishedMapper->mapping(editor));
if (editor && cmd) {
if (!cmd->lastExecutionSuccess()) {
editor->reportCommandFinished(false, cmd->lastExecutionExitCode(), cmd->cookie());
} else if (cmd->cookie().type() == QVariant::Int) {
const int line = cmd->cookie().toInt();
if (line >= 0)
editor->gotoLine(line);
}
d->m_cmdFinishedMapper->removeMappings(cmd);
}
}
} // namespace VcsBase
#include "moc_vcsbaseclient.cpp"
......@@ -68,7 +68,7 @@ class VCSBASE_EXPORT VcsBaseClientImpl : public QObject
Q_OBJECT
public:
explicit VcsBaseClientImpl(VcsBaseClientSettings *settings);
explicit VcsBaseClientImpl(VcsBaseClientImpl *client, VcsBaseClientSettings *settings);
~VcsBaseClientImpl();
VcsBaseClientSettings &settings() const;
......@@ -76,8 +76,23 @@ public:
virtual Utils::FileName vcsBinary() const;
int vcsTimeout() const;
enum JobOutputBindMode {
NoOutputBind,
VcsWindowOutputBind
};
VcsCommand *createCommand(const QString &workingDirectory,
VcsBaseEditorWidget *editor = 0,
JobOutputBindMode mode = NoOutputBind) const;
void enqueueJob(VcsCommand *cmd, const QStringList &args,
Utils::ExitCodeInterpreter *interpreter = 0);
virtual QProcessEnvironment processEnvironment() const;
private:
void saveSettings();
void commandFinishedGotoLine(QWidget*);
VcsBaseClientImplPrivate *d;
};
......@@ -144,8 +159,6 @@ public:
virtual QString findTopLevelForFile(const QFileInfo &file) const = 0;
virtual QProcessEnvironment processEnvironment() const;
signals:
void parsedStatus(const QList<VcsBase::VcsBaseClient::StatusItem> &statusList);
// Passes on changed signals from VcsJob to Control
......@@ -201,22 +214,11 @@ protected:
const char *registerDynamicProperty,
const QString &dynamicPropertyValue) const;
enum JobOutputBindMode {
NoOutputBind,
VcsWindowOutputBind
};
VcsCommand *createCommand(const QString &workingDirectory,
VcsBaseEditorWidget *editor = 0,
JobOutputBindMode mode = NoOutputBind) const;
void enqueueJob(VcsCommand *cmd, const QStringList &args, Utils::ExitCodeInterpreter *interpreter = 0);
void resetCachedVcsInfo(const QString &workingDir);
private:
void statusParser(const QString&);
void annotateRevision(const QString&, const QString&, const QString&, int);
void commandFinishedGotoLine(QWidget*);
friend class VcsBaseClientPrivate;
VcsBaseClientPrivate *d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment