forked from qt-creator/qt-creator
Code model: Update on changes from the versioning system.
Add state logic to CppCodeModelManagerInterface, making it aware whether an indexer is running, protect the update methods from another invocation while running. Add changed signals to IVersionControl and VCSManager and wire them to the update methods. Add a menu action for manually updating. Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> Reviewed-by: con <qtc-committer@nokia.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "gitconstants.h"
|
||||
#include "gitplugin.h"
|
||||
#include "gitsubmiteditor.h"
|
||||
#include "gitversioncontrol.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -43,6 +44,9 @@
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
#include <coreplugin/filemanager.h>
|
||||
#include <coreplugin/filemanager.h>
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <vcsbase/vcsbaseeditor.h>
|
||||
@@ -55,6 +59,7 @@
|
||||
#include <QtCore/QTime>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QSignalMapper>
|
||||
|
||||
#include <QtGui/QMainWindow> // for msg box parent
|
||||
#include <QtGui/QMessageBox>
|
||||
@@ -102,7 +107,8 @@ static QString formatCommand(const QString &binary, const QStringList &args)
|
||||
GitClient::GitClient(GitPlugin* plugin)
|
||||
: m_msgWait(tr("Waiting for data...")),
|
||||
m_plugin(plugin),
|
||||
m_core(Core::ICore::instance())
|
||||
m_core(Core::ICore::instance()),
|
||||
m_repositoryChangedSignalMapper(0)
|
||||
{
|
||||
if (QSettings *s = m_core->settings()) {
|
||||
m_settings.fromSettings(s);
|
||||
@@ -317,7 +323,8 @@ void GitClient::checkoutBranch(const QString &workingDirectory, const QString &b
|
||||
{
|
||||
QStringList arguments(QLatin1String("checkout"));
|
||||
arguments << branch;
|
||||
executeGit(workingDirectory, arguments, 0, true);
|
||||
GitCommand *cmd = executeGit(workingDirectory, arguments, 0, true);
|
||||
connectRepositoryChanged(workingDirectory, cmd);
|
||||
}
|
||||
|
||||
void GitClient::checkout(const QString &workingDirectory, const QString &fileName)
|
||||
@@ -341,7 +348,8 @@ void GitClient::hardReset(const QString &workingDirectory, const QString &commit
|
||||
if (!commit.isEmpty())
|
||||
arguments << commit;
|
||||
|
||||
executeGit(workingDirectory, arguments, 0, true);
|
||||
GitCommand *cmd = executeGit(workingDirectory, arguments, 0, true);
|
||||
connectRepositoryChanged(workingDirectory, cmd);
|
||||
}
|
||||
|
||||
void GitClient::addFile(const QString &workingDirectory, const QString &fileName)
|
||||
@@ -500,18 +508,19 @@ GitCommand *GitClient::createCommand(const QString &workingDirectory,
|
||||
}
|
||||
|
||||
// Execute a single command
|
||||
void GitClient::executeGit(const QString &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
VCSBase::VCSBaseEditor* editor,
|
||||
bool outputToWindow,
|
||||
GitCommand::TerminationReportMode tm,
|
||||
int editorLineNumber)
|
||||
GitCommand *GitClient::executeGit(const QString &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
VCSBase::VCSBaseEditor* editor,
|
||||
bool outputToWindow,
|
||||
GitCommand::TerminationReportMode tm,
|
||||
int editorLineNumber)
|
||||
{
|
||||
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
|
||||
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow, editorLineNumber);
|
||||
command->addJob(arguments, m_settings.timeout);
|
||||
command->setTerminationReportMode(tm);
|
||||
command->execute();
|
||||
return command;
|
||||
}
|
||||
|
||||
// Return fixed arguments required to run
|
||||
@@ -903,6 +912,8 @@ void GitClient::revert(const QStringList &files)
|
||||
QString errorMessage;
|
||||
switch (revertI(files, &isDirectory, &errorMessage)) {
|
||||
case RevertOk:
|
||||
m_plugin->versionControl()->emitFilesChanged(files);
|
||||
break;
|
||||
case RevertCanceled:
|
||||
break;
|
||||
case RevertUnchanged: {
|
||||
@@ -918,7 +929,8 @@ void GitClient::revert(const QStringList &files)
|
||||
|
||||
void GitClient::pull(const QString &workingDirectory)
|
||||
{
|
||||
executeGit(workingDirectory, QStringList(QLatin1String("pull")), 0, true, GitCommand::ReportStderr);
|
||||
GitCommand *cmd = executeGit(workingDirectory, QStringList(QLatin1String("pull")), 0, true, GitCommand::ReportStderr);
|
||||
connectRepositoryChanged(workingDirectory, cmd);
|
||||
}
|
||||
|
||||
void GitClient::push(const QString &workingDirectory)
|
||||
@@ -952,7 +964,8 @@ void GitClient::stashPop(const QString &workingDirectory)
|
||||
{
|
||||
QStringList arguments(QLatin1String("stash"));
|
||||
arguments << QLatin1String("pop");
|
||||
executeGit(workingDirectory, arguments, 0, true);
|
||||
GitCommand *cmd = executeGit(workingDirectory, arguments, 0, true);
|
||||
connectRepositoryChanged(workingDirectory, cmd);
|
||||
}
|
||||
|
||||
void GitClient::branchList(const QString &workingDirectory)
|
||||
@@ -1000,3 +1013,16 @@ void GitClient::setSettings(const GitSettings &s)
|
||||
m_binaryPath = m_settings.gitBinaryPath();
|
||||
}
|
||||
}
|
||||
|
||||
void GitClient::connectRepositoryChanged(const QString & repository, GitCommand *cmd)
|
||||
{
|
||||
// Bind command success termination with repository to changed signal
|
||||
if (!m_repositoryChangedSignalMapper) {
|
||||
m_repositoryChangedSignalMapper = new QSignalMapper(this);
|
||||
connect(m_repositoryChangedSignalMapper, SIGNAL(mapped(QString)),
|
||||
m_plugin->versionControl(), SIGNAL(repositoryChanged(QString)));
|
||||
}
|
||||
m_repositoryChangedSignalMapper->setMapping(cmd, repository);
|
||||
connect(cmd, SIGNAL(success()), m_repositoryChangedSignalMapper, SLOT(map()),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "gitsettings.h"
|
||||
#include "gitcommand.h"
|
||||
|
||||
#include <coreplugin/iversioncontrol.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
@@ -41,6 +40,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QErrorMessage;
|
||||
class QSignalMapper;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
@@ -158,12 +158,12 @@ private:
|
||||
bool outputToWindow = false,
|
||||
int editorLineNumber = -1);
|
||||
|
||||
void executeGit(const QString &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
VCSBase::VCSBaseEditor* editor = 0,
|
||||
bool outputToWindow = false,
|
||||
GitCommand::TerminationReportMode tm = GitCommand::NoReport,
|
||||
int editorLineNumber = -1);
|
||||
GitCommand *executeGit(const QString &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
VCSBase::VCSBaseEditor* editor = 0,
|
||||
bool outputToWindow = false,
|
||||
GitCommand::TerminationReportMode tm = GitCommand::NoReport,
|
||||
int editorLineNumber = -1);
|
||||
|
||||
bool synchronousGit(const QString &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
@@ -173,12 +173,14 @@ private:
|
||||
|
||||
enum RevertResult { RevertOk, RevertUnchanged, RevertCanceled, RevertFailed };
|
||||
RevertResult revertI(QStringList files, bool *isDirectory, QString *errorMessage);
|
||||
void connectRepositoryChanged(const QString & repository, GitCommand *cmd);
|
||||
|
||||
const QString m_msgWait;
|
||||
GitPlugin *m_plugin;
|
||||
Core::ICore *m_core;
|
||||
GitSettings m_settings;
|
||||
QString m_binaryPath;
|
||||
QSignalMapper *m_repositoryChangedSignalMapper;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -177,6 +177,8 @@ void GitCommand::run()
|
||||
emit errorText(error);
|
||||
|
||||
emit finished(ok, m_cookie);
|
||||
if (ok)
|
||||
emit success();
|
||||
// As it is used asynchronously, we need to delete ourselves
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ Q_SIGNALS:
|
||||
void outputData(const QByteArray&);
|
||||
void errorText(const QString&);
|
||||
void finished(bool ok, const QVariant &cookie);
|
||||
void success();
|
||||
|
||||
private:
|
||||
struct Job {
|
||||
|
||||
@@ -142,6 +142,7 @@ GitPlugin::GitPlugin() :
|
||||
m_stashListAction(0),
|
||||
m_branchListAction(0),
|
||||
m_gitClient(0),
|
||||
m_versionControl(0),
|
||||
m_changeSelectionDialog(0),
|
||||
m_submitActionTriggered(false)
|
||||
{
|
||||
@@ -215,8 +216,8 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
|
||||
addAutoReleasedObject(new GitSubmitEditorFactory(&submitParameters));
|
||||
|
||||
GitVersionControl *versionControl = new GitVersionControl(m_gitClient);
|
||||
addAutoReleasedObject(versionControl);
|
||||
m_versionControl = new GitVersionControl(m_gitClient);
|
||||
addAutoReleasedObject(m_versionControl);
|
||||
|
||||
addAutoReleasedObject(new CloneWizard);
|
||||
addAutoReleasedObject(new Gitorious::Internal::GitoriousCloneWizard);
|
||||
@@ -232,8 +233,8 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
gitContainer->menu()->setTitle(tr("&Git"));
|
||||
toolsContainer->addMenu(gitContainer);
|
||||
if (QAction *ma = gitContainer->menu()->menuAction()) {
|
||||
ma->setEnabled(versionControl->isEnabled());
|
||||
connect(versionControl, SIGNAL(enabledChanged(bool)), ma, SLOT(setVisible(bool)));
|
||||
ma->setEnabled(m_versionControl->isEnabled());
|
||||
connect(m_versionControl, SIGNAL(enabledChanged(bool)), ma, SLOT(setVisible(bool)));
|
||||
}
|
||||
|
||||
Core::Command *command;
|
||||
@@ -398,6 +399,11 @@ void GitPlugin::extensionsInitialized()
|
||||
{
|
||||
}
|
||||
|
||||
GitVersionControl *GitPlugin::versionControl() const
|
||||
{
|
||||
return m_versionControl;
|
||||
}
|
||||
|
||||
void GitPlugin::submitEditorDiff(const QStringList &unstaged, const QStringList &staged)
|
||||
{
|
||||
m_gitClient->diff(m_submitRepository, QStringList(), unstaged, staged);
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
class GitPlugin;
|
||||
class GitVersionControl;
|
||||
class GitClient;
|
||||
class ChangeSelectionDialog;
|
||||
class GitSubmitEditor;
|
||||
@@ -96,6 +97,7 @@ public:
|
||||
void setSettings(const GitSettings &s);
|
||||
|
||||
GitClient *gitClient() const;
|
||||
GitVersionControl *versionControl() const;
|
||||
|
||||
public slots:
|
||||
void updateActions();
|
||||
@@ -159,6 +161,7 @@ private:
|
||||
QAction *m_branchListAction;
|
||||
|
||||
GitClient *m_gitClient;
|
||||
GitVersionControl *m_versionControl;
|
||||
ChangeSelectionDialog *m_changeSelectionDialog;
|
||||
QString m_submitRepository;
|
||||
QStringList m_submitOrigCommitFiles;
|
||||
|
||||
@@ -96,5 +96,10 @@ QString GitVersionControl::findTopLevelForDirectory(const QString &directory) co
|
||||
return GitClient::findRepositoryForDirectory(directory);
|
||||
}
|
||||
|
||||
void GitVersionControl::emitFilesChanged(const QStringList &l)
|
||||
{
|
||||
emit filesChanged(l);
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Git
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
virtual bool vcsAdd(const QString &fileName);
|
||||
virtual bool vcsDelete(const QString &filename);
|
||||
|
||||
void emitFilesChanged(const QStringList &);
|
||||
|
||||
signals:
|
||||
void enabledChanged(bool);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user