Commit d3c23c33 authored by Eike Ziller's avatar Eike Ziller
Browse files

GitSubmitEditor: Simplify update of files model



Report the commit data fetch result, including success state and error
message, through the QFuture. That also removes the need for creating a
fetcher QObject and the logic to make sure it is deleted.
Also exchange QtConcurrent::run by Utils::runAsync.

Change-Id: I9c0c03eff2eaa32f577b4599ffda58b0c09de59b
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent acc2194e
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "gitsubmiteditor.h" #include "gitsubmiteditor.h"
#include "commitdata.h"
#include "gitclient.h" #include "gitclient.h"
#include "gitplugin.h" #include "gitplugin.h"
#include "gitsubmiteditorwidget.h" #include "gitsubmiteditorwidget.h"
...@@ -33,6 +32,7 @@ ...@@ -33,6 +32,7 @@
#include <coreplugin/iversioncontrol.h> #include <coreplugin/iversioncontrol.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/runextensions.h>
#include <vcsbase/submitfilemodel.h> #include <vcsbase/submitfilemodel.h>
#include <vcsbase/vcsoutputwindow.h> #include <vcsbase/vcsoutputwindow.h>
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <QStringList> #include <QStringList>
#include <QTextCodec> #include <QTextCodec>
#include <QTimer> #include <QTimer>
#include <QtConcurrentRun>
static const char TASK_UPDATE_COMMIT[] = "Git.UpdateCommit"; static const char TASK_UPDATE_COMMIT[] = "Git.UpdateCommit";
...@@ -84,36 +83,15 @@ private: ...@@ -84,36 +83,15 @@ private:
} }
}; };
class CommitDataFetcher : public QObject CommitDataFetchResult CommitDataFetchResult::fetch(CommitType commitType, const QString &workingDirectory)
{ {
Q_OBJECT CommitDataFetchResult result;
result.commitData.commitType = commitType;
public: QString commitTemplate;
CommitDataFetcher(CommitType commitType, const QString &workingDirectory) : result.success = GitPlugin::client()->getCommitData(workingDirectory, &commitTemplate,
m_commitData(commitType), result.commitData, &result.errorMessage);
m_workingDirectory(workingDirectory) return result;
{ }
}
void start()
{
QString commitTemplate;
bool success = GitPlugin::client()->getCommitData(m_workingDirectory, &commitTemplate,
m_commitData, &m_errorMessage);
emit finished(success);
}
const CommitData &commitData() const { return m_commitData; }
const QString &errorMessage() const { return m_errorMessage; }
signals:
void finished(bool result);
private:
CommitData m_commitData;
QString m_workingDirectory;
QString m_errorMessage;
};
/* The problem with git is that no diff can be obtained to for a random /* The problem with git is that no diff can be obtained to for a random
* multiselection of staged/unstaged files; it requires the --cached * multiselection of staged/unstaged files; it requires the --cached
...@@ -127,11 +105,12 @@ GitSubmitEditor::GitSubmitEditor(const VcsBaseSubmitEditorParameters *parameters ...@@ -127,11 +105,12 @@ GitSubmitEditor::GitSubmitEditor(const VcsBaseSubmitEditorParameters *parameters
connect(submitEditorWidget(), &GitSubmitEditorWidget::show, this, &GitSubmitEditor::showCommit); connect(submitEditorWidget(), &GitSubmitEditorWidget::show, this, &GitSubmitEditor::showCommit);
connect(GitPlugin::instance()->versionControl(), &Core::IVersionControl::repositoryChanged, connect(GitPlugin::instance()->versionControl(), &Core::IVersionControl::repositoryChanged,
this, &GitSubmitEditor::forceUpdateFileModel); this, &GitSubmitEditor::forceUpdateFileModel);
connect(&m_fetchWatcher, &QFutureWatcher<CommitDataFetchResult>::finished,
this, &GitSubmitEditor::commitDataRetrieved);
} }
GitSubmitEditor::~GitSubmitEditor() GitSubmitEditor::~GitSubmitEditor()
{ {
resetCommitDataFetcher();
} }
GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget() GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget()
...@@ -144,14 +123,6 @@ const GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget() const ...@@ -144,14 +123,6 @@ const GitSubmitEditorWidget *GitSubmitEditor::submitEditorWidget() const
return static_cast<GitSubmitEditorWidget *>(widget()); return static_cast<GitSubmitEditorWidget *>(widget());
} }
void GitSubmitEditor::resetCommitDataFetcher()
{
if (!m_commitDataFetcher)
return;
disconnect(m_commitDataFetcher, &CommitDataFetcher::finished, this, &GitSubmitEditor::commitDataRetrieved);
connect(m_commitDataFetcher, &CommitDataFetcher::finished, m_commitDataFetcher, &QObject::deleteLater);
}
void GitSubmitEditor::setCommitData(const CommitData &d) void GitSubmitEditor::setCommitData(const CommitData &d)
{ {
m_commitEncoding = d.commitEncoding; m_commitEncoding = d.commitEncoding;
...@@ -254,13 +225,12 @@ void GitSubmitEditor::updateFileModel() ...@@ -254,13 +225,12 @@ void GitSubmitEditor::updateFileModel()
if (w->updateInProgress() || m_workingDirectory.isEmpty()) if (w->updateInProgress() || m_workingDirectory.isEmpty())
return; return;
w->setUpdateInProgress(true); w->setUpdateInProgress(true);
resetCommitDataFetcher(); m_fetchWatcher.setFuture(Utils::runAsync(&CommitDataFetchResult::fetch,
m_commitDataFetcher = new CommitDataFetcher(m_commitType, m_workingDirectory); m_commitType, m_workingDirectory));
connect(m_commitDataFetcher, &CommitDataFetcher::finished, this, &GitSubmitEditor::commitDataRetrieved); Core::ProgressManager::addTask(m_fetchWatcher.future(), tr("Refreshing Commit Data"),
QFuture<void> future = QtConcurrent::run(m_commitDataFetcher, &CommitDataFetcher::start); TASK_UPDATE_COMMIT);
Core::ProgressManager::addTask(future, tr("Refreshing Commit Data"), TASK_UPDATE_COMMIT);
GitPlugin::client()->addFuture(future); GitPlugin::client()->addFuture(m_fetchWatcher.future());
} }
void GitSubmitEditor::forceUpdateFileModel() void GitSubmitEditor::forceUpdateFileModel()
...@@ -272,21 +242,20 @@ void GitSubmitEditor::forceUpdateFileModel() ...@@ -272,21 +242,20 @@ void GitSubmitEditor::forceUpdateFileModel()
updateFileModel(); updateFileModel();
} }
void GitSubmitEditor::commitDataRetrieved(bool success) void GitSubmitEditor::commitDataRetrieved()
{ {
CommitDataFetchResult result = m_fetchWatcher.result();
GitSubmitEditorWidget *w = submitEditorWidget(); GitSubmitEditorWidget *w = submitEditorWidget();
if (success) { if (result.success) {
setCommitData(m_commitDataFetcher->commitData()); setCommitData(result.commitData);
w->refreshLog(m_workingDirectory); w->refreshLog(m_workingDirectory);
w->setEnabled(true); w->setEnabled(true);
} else { } else {
// Nothing to commit left! // Nothing to commit left!
VcsOutputWindow::appendError(m_commitDataFetcher->errorMessage()); VcsOutputWindow::appendError(result.errorMessage);
m_model->clear(); m_model->clear();
w->setEnabled(false); w->setEnabled(false);
} }
m_commitDataFetcher->deleteLater();
m_commitDataFetcher = 0;
w->setUpdateInProgress(false); w->setUpdateInProgress(false);
} }
...@@ -316,5 +285,3 @@ QByteArray GitSubmitEditor::fileContents() const ...@@ -316,5 +285,3 @@ QByteArray GitSubmitEditor::fileContents() const
} // namespace Internal } // namespace Internal
} // namespace Git } // namespace Git
#include "gitsubmiteditor.moc"
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
#pragma once #pragma once
#include "gitsettings.h" // CommitType #include "commitdata.h"
#include <vcsbase/vcsbasesubmiteditor.h> #include <vcsbase/vcsbasesubmiteditor.h>
#include <QFutureWatcher>
#include <QStringList> #include <QStringList>
namespace VcsBase { class SubmitFileModel; } namespace VcsBase { class SubmitFileModel; }
...@@ -38,10 +39,18 @@ namespace Internal { ...@@ -38,10 +39,18 @@ namespace Internal {
class GitClient; class GitClient;
class GitSubmitEditorWidget; class GitSubmitEditorWidget;
class CommitData;
class CommitDataFetcher;
class GitSubmitEditorPanelData; class GitSubmitEditorPanelData;
class CommitDataFetchResult
{
public:
static CommitDataFetchResult fetch(CommitType commitType, const QString &workingDirectory);
QString errorMessage;
CommitData commitData;
bool success;
};
class GitSubmitEditor : public VcsBase::VcsBaseSubmitEditor class GitSubmitEditor : public VcsBase::VcsBaseSubmitEditor
{ {
Q_OBJECT Q_OBJECT
...@@ -63,11 +72,10 @@ protected: ...@@ -63,11 +72,10 @@ protected:
private: private:
void slotDiffSelected(const QList<int> &rows); void slotDiffSelected(const QList<int> &rows);
void showCommit(const QString &commit); void showCommit(const QString &commit);
void commitDataRetrieved(bool success); void commitDataRetrieved();
inline GitSubmitEditorWidget *submitEditorWidget(); inline GitSubmitEditorWidget *submitEditorWidget();
inline const GitSubmitEditorWidget *submitEditorWidget() const; inline const GitSubmitEditorWidget *submitEditorWidget() const;
void resetCommitDataFetcher();
VcsBase::SubmitFileModel *m_model = nullptr; VcsBase::SubmitFileModel *m_model = nullptr;
QTextCodec *m_commitEncoding = nullptr; QTextCodec *m_commitEncoding = nullptr;
...@@ -75,7 +83,7 @@ private: ...@@ -75,7 +83,7 @@ private:
QString m_amendSHA1; QString m_amendSHA1;
QString m_workingDirectory; QString m_workingDirectory;
bool m_firstUpdate = true; bool m_firstUpdate = true;
CommitDataFetcher *m_commitDataFetcher = nullptr; QFutureWatcher<CommitDataFetchResult> m_fetchWatcher;
}; };
} // namespace Internal } // namespace Internal
......
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